% Author: Colin Eles elesc@mcmaster.ca % Organization: McMaster Centre for Software Certification function TTdiag(varargin) % Java needs to be loaded here. Thus load it. % First find the path. path = mfilename('fullpath'); path = [path(1:size(path, 2)-6) 'Matlab2SMT/Matlab2SMT-1.0-SNAPSHOT-jar-with-dependencies.jar']; % Verify the jar isn't already in the classpath. classpath = javaclasspath; exists = 0; for i=1:size(classpath,1) if strcmp(classpath{i}, path) == 1 exists = 1; end end if exists == 0 % Not added yet, thus add it. javaaddpath(path); end orig_gcbh = gcbh; Action = varargin{1}; switch Action, case 'Open', Mode = varargin{2}; if 2 ~= nargin DAStudio.warning('improper function use'); end blockHandleTTTopMask = orig_gcbh; switch Mode, case 'Simulink' LocalOpenBlockFcn(blockHandleTTTopMask,1); case 'Matlab' LocalOpenBlockFcn([],0); end case 'Close', blockHandleTTTopMask = orig_gcbh; LocalCloseBlockFcn(blockHandleTTTopMask); case 'Copy', blockHandleTTTopMask = orig_gcbh; LocalCopyBlockFcn(blockHandleTTTopMask); case 'Load', if 2 ~= nargin DAStudio.warning('improper function use'); end file = varargin{2}; try data = importdata(file); gui = GUI([],0); gui.setData(data); gui.init(); catch exception msgbox(exception.identifier); end case 'Delete', blockHandleTTTopMask = orig_gcbh; data = get_param(blockHandleTTTopMask,'UserData'); if isempty(data) return end if ~data.valid errordlg(... DAStudio.message('Block Data has been corputed'),... 'Error', 'modal'); return end if data.open && ishandle(data.fig) delete(data.fig); data.fig = []; data.open = 0; set_param(blockHandleTTTopMask,'UserData',data); end otherwise, DAStudio.error('Simulink:dialog:UnknownAction',Action); end end function LocalCopyBlockFcn(blockHandleTTTopMask) data = get(blockHandleTTTopMask,'UserData'); if(~isempty(data)) data_new = data.clone(blockHandleTTTopMask); set_param(blockHandleTTTopMask,'UserData',data_new); end end function LocalOpenBlockFcn(blockHandleTTTopMask,mode) data = []; if (mode == 1) modelHandle = bdroot(blockHandleTTTopMask); % check if the user is trying to open the block from the library if strcmp(get_param(modelHandle,'Lock'), 'on') || strcmp(get_param(blockHandleTTTopMask,'LinkStatus'),'implicit') errordlg(... DAStudio.message('can not open Model Locked, Add to new model to use'),... 'Error', 'modal'); return end data = get_param(blockHandleTTTopMask,'UserData'); end if isempty(data) data = Data(); data.init(); else if ~data.valid errordlg(... DAStudio.message('Block Data has been corputed'),... 'Error', 'modal'); return end if data.open if ishghandle(data.fig) figure(data.fig); return end end end if mode == 1 gui = GUI(blockHandleTTTopMask,1); elseif mode == 0 gui = GUI([],0); end gui.setData(data); gui.init(); if(mode == 1) set_param(blockHandleTTTopMask,'UserData',data); set_param(blockHandleTTTopMask, 'UserDataPersistent', 'on'); end end function LocalCloseRequestBlockFcn(blockHandleTTTopMask) modelHandle = bdroot(blockHandleTTTopMask); data = get_param(blockHandleTTTopMask,'UserData'); if ~isempty(data) if data.open delete(data.fig); end end %set_param(gui.fig,'Visible','off') end