Code covered by the BSD License  

Highlights from
GUI for Simulink Properties

image thumbnail

GUI for Simulink Properties

by

 

GUI that allows you to browse through the parameters of your Simulink model.

simprop(varargin)
function varargout = simprop(varargin)
% SIMPROP Application M-file for simprop.fig
%    FIG = SIMPROP launch simprop GUI.
%    SIMPROP('callback_name', ...) invoke the named callback.

% Last Modified by GUIDE v2.0 01-Dec-2001 00:27:49

if nargin == 0  % LAUNCH GUI

	fig = openfig(mfilename,'reuse');

	% Generate a structure of handles to pass to callbacks, and store it. 
	handles = guihandles(fig);
	guidata(fig, handles);
    

        %%Add on
        
        set(handles.listbox3, 'String',...
                   'Not Ready');
        set(handles.listbox4, 'String',...
                   'Not Ready');

        
        
	if nargout > 0
		varargout{1} = fig;
	end

elseif ischar(varargin{1}) % INVOKE NAMED SUBFUNCTION OR CALLBACK

	try
		if (nargout)
			[varargout{1:nargout}] = feval(varargin{:}); % FEVAL switchyard
		else
			feval(varargin{:}); % FEVAL switchyard
		end
	catch
		disp(lasterr);
	end

end


% --------------------------------------------------------------------
function varargout = pushbutton1_Callback(h, eventdata, handles, varargin)


model=get_param(gcs,'Name');
eval([model,'([], [], [], ''compile'');']);


type=0;
params=get_param(gcb,'ObjectParameters');

names = fieldnames(params);
handles.names=names;
handles.type=type;
guidata(h,handles);

set(handles.listbox3, 'String',...
                    names);

eval([model,'([], [], [], ''term'');']);

% --------------------------------------------------------------------
function varargout = listbox3_Callback(h, eventdata, handles, varargin)


names= handles.names;
type=handles.type;

property=get(h,'Value');
str=names{property};
if (type==1),
    value=get_param(gcs,str);
elseif (type ==0)
    value=get_param(gcb,str);
else 
    lines=handles.lines;
    values=lines(property);
    value=fieldnames(values);
end



%%%Data Type Check %%%%

if (isnumeric(value)),
    value=num2str(value);
end
if (isempty(value)),
    value='Empty';
end

if(isstruct(value)),
    value=fieldnames(value);
end

if(iscell(value)),
    value=char(value);
end


%%%%Set Values %%%%
if (type==2),
    set(handles.listbox4, 'String',...
        value);
    
else
    
    set(handles.listbox4, 'String',...
        value);
    
end
          



% --------------------------------------------------------------------
function varargout = pushbutton3_Callback(h, eventdata, handles, varargin)


model=get_param(gcs,'Name');
eval([model,'([], [], [], ''compile'');']);


type=1;

params=get_param(gcs,'ObjectParameters');
names = fieldnames(params);
handles.names=names;
handles.type=type;
guidata(h,handles);

set(handles.listbox3, 'String',...
                    names);

eval([model,'([], [], [], ''term'');']);
% --------------------------------------------------------------------
function varargout = listbox4_Callback(h, eventdata, handles, varargin)

type=handles.type;

if (type==2),
    
    lines=handles.lines;
    sig= get(handles.listbox3,'Value');
    prop=get(handles.listbox4,'Value');
    names=fieldnames(lines);
    eval(['value=lines(sig).',names{prop},';']);

   
    if (~ischar(value)),
        
        switch names{prop}
      
        case {'Handle', 'Points'}
            value=num2str(value);
        case 'Branch'
             branches=lines(sig).Branch;
            value=num2str(length(branches));
        case {'SrcBlock', 'DstBlock','Parent'}
            eval(['value= get_param(lines(sig).',names{prop},',''Name'');']);
        otherwise
            value=value;
        end
        
    end
    
    
    set(handles.listbox5, 'String',...
        value);
else
    set(handles.listbox5, 'String',...
        'Object is not a signal');
end



% --------------------------------------------------------------------
function varargout = pushbutton7_Callback(h, eventdata, handles, varargin)


count=0;
model=get_param(gcs,'Name');
eval([model,'([], [], [], ''compile'');']);

names={};
type=2;
params=get_param(gcs,'Lines');

for i=1:length(params)
    names{end+1}= params(i).Name ;
    if (isempty(names{end})),
        count=count+1;
        names{end}=num2str(count);
    end
end

handles.lines=params;
handles.names=names;
handles.type=type;
guidata(h,handles);

set(handles.listbox3, 'String',...
                    names);

eval([model,'([], [], [], ''term'');']);

% --------------------------------------------------------------------
function varargout = listbox5_Callback(h, eventdata, handles, varargin)




% --------------------------------------------------------------------
function varargout = checkbox1_Callback(h, eventdata, handles, varargin)

type=handles.type;

if (type==2),
    
    if (get(h,'Value')==1),
        
        lines=handles.lines;
        sig= get(handles.listbox3,'Value');
        set_param(lines(sig).SrcBlock,'ForegroundColor','red');
    else 
        
        lines=handles.lines;
        sig= get(handles.listbox3,'Value');
        set_param(lines(sig).SrcBlock,'ForegroundColor','black');
        
    end
    
    
end

Contact us