diff --git a/@MyDaq/MyDaq.m b/@MyDaq/MyDaq.m index 7173ac8..ed184d3 100644 --- a/@MyDaq/MyDaq.m +++ b/@MyDaq/MyDaq.m @@ -1,296 +1,324 @@ classdef MyDaq < handle properties - %Contains Gui handles + %Contains GUI handles Gui; %Contains Reference trace (MyTrace object) Ref; %Contains Data trace (MyTrace object) Data; %Contains Background trace (MyTrace object) Background; %Cell containing MyInstrument objects Instruments; %Cell containing Cursor objects Cursors; %Struct containing MyFit objects Fits=struct(); %Input parser Parser; %Listeners for deletion of MyFit objects ListenersDelete; %Listeners for new fits from MyFit objects ListenersNewFit; + %Sets the colors of fits, data and reference fit_color='k'; data_color='b'; ref_color='r'; + %Properties for saving files base_dir; session_name; file_name; + + %Flag for enabling the GUI enable_gui; end properties (Dependent=true) save_dir; main_plot; end methods + %Constructor function function this=MyDaq(varargin) createParser(this); parse(this.Parser,varargin{:}); parseInputs(this); if this.enable_gui this.Gui=guihandles(eval('GuiDaq')); initGui(this); hold(this.main_plot,'on'); end initDaq(this) end + %Creates parser for constructor function function createParser(this) p=inputParser; addParameter(p,'enable_gui',1); this.Parser=p; end %Sets the class variables to the inputs from the inputParser. function parseInputs(this) for i=1:length(this.Parser.Parameters) %Takes the value from the inputParser to the appropriate %property. if isprop(this,this.Parser.Parameters{i}) this.(this.Parser.Parameters{i})=... this.Parser.Results.(this.Parser.Parameters{i}); end end end + %Initializes the class depending on the computer name function initDaq(this) - computer_name=getenv('computername'); - - switch computer_name - case 'LPQM1PCLAB2' - initRt(this); - case 'LPQM1PC18' - initUhq(this); - otherwise - %error('Please create an initialization function for this computer') - end - - %Initializes empty trace objects - this.Ref=MyTrace; - this.Data=MyTrace; - this.Background=MyTrace; + computer_name=getenv('computername'); + + switch computer_name + case 'LPQM1PCLAB2' + initRt(this); + case 'LPQM1PC18' + initUhq(this); + case 'LPQM1PC2' + %Test case for testing on Nils' computer. + otherwise + error('Please create an initialization function for this computer') + end + + %Initializes empty trace objects + this.Ref=MyTrace; + this.Data=MyTrace; + this.Background=MyTrace; end + %Sets callback functions for the GUI function initGui(this) set(this.Gui.BaseDir,'Callback',... @(hObject, eventdata) baseDirCallback(this, hObject, ... eventdata)); set(this.Gui.SessionName,'Callback',... @(hObject, eventdata) sessionNameCallback(this, hObject, ... eventdata)); set(this.Gui.FileName,'Callback',... @(hObject, eventdata) fileNameCallback(this, hObject, ... eventdata)); set(this.Gui.SaveData,'Callback',... @(hObject, eventdata) saveDataCallback(this, hObject, ... eventdata)); set(this.Gui.SaveRef,'Callback',... @(hObject, eventdata) saveRefCallback(this, hObject, ... eventdata)); set(this.Gui.ShowData,'Callback',... @(hObject, eventdata) showDataCallback(this, hObject, ... eventdata)); set(this.Gui.ShowRef,'Callback',... @(hObject, eventdata) showRefCallback(this, hObject, ... eventdata)); set(this.Gui.DataToRef,'Callback',... @(hObject, eventdata) dataToRefCallback(this, hObject, ... eventdata)); set(this.Gui.LogY,'Callback',... @(hObject, eventdata) logYCallback(this, hObject, ... eventdata)); set(this.Gui.LogX,'Callback',... @(hObject, eventdata) logXCallback(this, hObject, ... eventdata)); set(this.Gui.DataToBg,'Callback',... @(hObject, eventdata) dataToBgCallback(this, hObject, ... eventdata)); set(this.Gui.RefToBg,'Callback',... @(hObject, eventdata) refToBgCallback(this, hObject, ... eventdata)); set(this.Gui.ClearBg,'Callback',... @(hObject, eventdata) clearBgCallback(this, hObject, ... eventdata)); set(this.Gui.AnalyzeMenu,'Callback',... @(hObject, eventdata) analyzeMenuCallback(this, hObject,... eventdata)); set(this.Gui.AnalyzeMenu,'String',{'Select a routine...',... 'Linear Fit','Quadratic Fit','Exponential Fit',... 'Gaussian Fit','Lorentzian Fit'}); end + %Saves the data if the save data button is pressed. function saveDataCallback(this, ~, ~) - if get(this.Gui.AutoName,'Value') - date_time = datestr(now,'yyyy-mm-dd_HH.MM.SS'); - else - date_time=''; - end - - savefile=[this.file_name,date_time]; - save(this.Data,'save_dir',this.save_dir,'name',savefile) + save(this.Data,'save_dir',this.save_dir,'name',... + genFileName(this)) end + %Saves the reference if the save ref button is pressed. function saveRefCallback(this, ~, ~) + save(this.Ref,'save_dir',this.save_dir,'name',... + genFileName(this)) + end + + %Generates appropriate file name for the save file. + function savefile=genFileName(this) if get(this.Gui.AutoName,'Value') date_time = datestr(now,'yyyy-mm-dd_HH.MM.SS'); else date_time=''; end savefile=[this.file_name,date_time]; - save(this.Ref,'save_dir',this.save_dir,'name',savefile) end + %Generates base_dir function baseDirCallback(this, hObject, ~) - %Modify this at some point to use uiputfile instead this.base_dir=get(hObject,'String'); end + %Toggle button callback for showing the data trace. function showDataCallback(this, hObject, ~) if get(hObject,'Value') set(hObject, 'BackGroundColor',[0,1,.2]); setVisible(this.Data,this.main_plot,1); else set(hObject, 'BackGroundColor',[0.941,0.941,0.941]); setVisible(this.Data,this.main_plot,0); end end + %Toggle button callback for showing the ref trace function showRefCallback(this, hObject, ~) if get(hObject,'Value') set(hObject, 'BackGroundColor',[0,1,0.2]); setVisible(this.Ref,this.main_plot,1); else set(hObject, 'BackGroundColor',[0.941,0.941,0.941]); setVisible(this.Ref,this.main_plot,0); end end + %Callback for moving the data to reference. function dataToRefCallback(this, hObject, ~) - set(hObject, 'BackGroundColor',[0,1,.2]); this.Ref.x=this.Data.x; this.Ref.y=this.Data.y; this.Ref.plotTrace(this.main_plot); this.Ref.setVisible(this.main_plot,1); set(this.Gui.ShowRef,'Value',1); set(this.Gui.ShowRef, 'BackGroundColor',[0,1,.2]); - set(hObject, 'BackGroundColor',[0.941,0.941,0.941]); end - function refToBgCallback(this, hObject, ~) - set(hObject, 'BackGroundColor',[0,1,.2]); + %Callback for ref to bg button. Sends the reference to background + function refToBgCallback(this, ~, ~) this.Background.x=this.Ref.x; this.Background.y=this.Ref.y; this.Background.plotTrace(this.main_plot); this.Background.setVisible(this.main_plot,1); - set(hObject, 'BackGroundColor',[0.941,0.941,0.941]); end - function dataToBgCallback(this, hObject, ~) - set(hObject, 'BackGroundColor',[0,1,.2]); + %Callback for data to bg button. Sends the data to background + function dataToBgCallback(this, ~, ~) this.Background.x=this.Data.x; this.Background.y=this.Data.y; this.Background.plotTrace(this.main_plot); this.Background.setVisible(this.main_plot,1); - set(hObject, 'BackGroundColor',[0.941,0.941,0.941]); end + %Callback for clear background button. Clears the background function clearBgCallback(this, hObject, ~) - set(hObject, 'BackGroundColor',[0,1,.2]); this.Background.x=[]; this.Background.y=[]; this.Background.setVisible(this.main_plot,0); - set(hObject, 'BackGroundColor',[0.941,0.941,0.941]); end + %Callback for LogY button. Sets the YScale to log/lin function logYCallback(this, hObject, ~) if get(hObject,'Value') set(this.main_plot,'YScale','Log'); set(hObject, 'BackGroundColor',[0,1,.2]); else set(this.main_plot,'YScale','Linear'); set(hObject, 'BackGroundColor',[0.941,0.941,0.941]); end end + %Callback for LogX button. Sets the XScale to log/lin function logXCallback(this, hObject, ~) if get(hObject,'Value') set(this.main_plot,'XScale','Log'); set(hObject, 'BackGroundColor',[0,1,.2]); else set(this.main_plot,'XScale','Linear'); set(hObject, 'BackGroundColor',[0.941,0.941,0.941]); end end + %Callback for the analyze menu (popup menu for selecting fits). + %Opens the correct MyFit object. function analyzeMenuCallback(this, hObject, ~) analyze_list=get(hObject,'String'); analyze_ind=get(hObject,'Value'); %Finds the correct fit name analyze_name=analyze_list{analyze_ind}; analyze_name=analyze_name(1:(strfind(analyze_name,' ')-1)); analyze_name=[upper(analyze_name(1)),analyze_name(2:end)]; %Sees if the fit object is already open, if it is, changes the %focus to it, if not, opens it. if ismember(analyze_name,fieldnames(this.Fits)) + %Changes focus to the relevant fit window figure(this.Fits.(analyze_name).Gui.Window); elseif analyze_ind~=1 + %Makes an instance of MyFit with correct parameters. this.Fits.(analyze_name)=MyFit('fit_name',analyze_name,... - 'enable_plot',1,'plot_handle',this.main_plot); - this.Fits.(analyze_name).Data=this.Data; + 'enable_plot',1,'plot_handle',this.main_plot,... + 'Data',this.Data); + %Sets up a listener for the BeingDeleted event, which + %removes the MyFit object from the Fits structure if it is + %deleted. this.ListenersDelete.(analyze_name)=... addlistener(this.Fits.(analyze_name),'BeingDeleted',... @(src, eventdata) deleteFit(this, src, eventdata)); + %Sets up a listener for the NewFit. Callback plots the fit + %on the main plot. this.ListenersNewFit.(analyze_name)=... addlistener(this.Fits.(analyze_name),'NewFit',... @(src, eventdata) plotNewFit(this, src, eventdata)); end end - + + %Callback for session name edit box. Sets the session name. function sessionNameCallback(this, hObject, ~) this.session_name=get(hObject,'String'); end + %Callback for filename edit box. Sets the file name. function fileNameCallback(this, hObject,~) this.file_name=get(hObject,'String'); end - function save_dir=get.save_dir(this) - save_dir=[this.base_dir,datestr(now,'yyyy-mm-dd '),... - this.session_name,'\']; + %Callback function for NewFit listener. Plots the fit in the + %window using the plotFit function of the MyFit object + function plotNewFit(this, src, ~) + src.plotFit('Color',this.fit_color); end + %Callback function for BeingDeleted listener. Removes the relevant + %field from the Fits struct. function deleteFit(this, src, ~) if ismember(src.fit_name, fieldnames(this.Fits)) this.Fits=rmfield(this.Fits,src.fit_name); end end - function plotNewFit(this, src, ~) - src.plotFit('Color',this.fit_color); + %Get function from save directory + function save_dir=get.save_dir(this) + save_dir=[this.base_dir,datestr(now,'yyyy-mm-dd '),... + this.session_name,'\']; end + %Get function for the plot handles function main_plot=get.main_plot(this) if this.enable_gui main_plot=this.Gui.figure1.CurrentAxes; else main_plot=[]; end end end end \ No newline at end of file