0
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1 function methName = g_setmethod(varargin)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2 % GUI callback, to support the hollow block - ie. the block with no
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
3 % function name. This function will popup the small figure to set it.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
4 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
5 % $Id: g_setmethod.m,v 1.3 2009/02/01 17:20:03 nicola Exp $
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
6
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
7 global selBlocks
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
8
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
9 guiFontSize = getappdata(0, 'ltpda_gui_fontsize');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
10 screenSize = get(0,'ScreenSize');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
11 backColor = [1 1 1];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
12 close(findobj('Tag','setMethod'))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
13 [meth,clas] = strtok(get(gcbh,'Tag'));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
14 if ~strcmp(meth,'method'), warning('*** This block didn''t contain a valid LTPDA method.'); delete_block(gcbh); return; end %#ok<WNTAG>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
15 clas = strtrim(clas);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
16 methName = '';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
17
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
18 position = [(screenSize(3)-250)/2 (screenSize(4)-70)/2 250 70];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
19 setMethFig = figure('Position',position,'Name','Which function?','Tag','setMethod','Resize','off','NumberTitle','off','Toolbar','none','Menubar','none');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
20 set(setMethFig,'CloseRequestFcn','delete_block(gcbh);uiresume;closereq');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
21 % Class text
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
22 uicontrol('Parent',setMethFig,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[10 position(4)-25 100 20],'String','Class:','FontName','Times New Roman','FontSize',guiFontSize,'FontWeight','normal','Visible','on','Style','text');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
23 % Method text
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
24 uicontrol('Parent',setMethFig,'BackgroundColor',backColor,'HorizontalAlignment','left','Position',[120 position(4)-25 140 20],'String','Method:','FontName','Times New Roman','FontSize',guiFontSize,'FontWeight','normal','Visible','on','Style','text');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
25 % Class edit field
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
26 clasEdit = uicontrol('Parent',setMethFig,'Tag','clasEdit','BackgroundColor',backColor,'HorizontalAlignment','left','Position',[10 position(4)-45 100 20],'String',clas,'FontName','Times New Roman','FontSize',guiFontSize+1,'FontWeight','normal','Visible','on','Callback',@editMethodCbk,'Style','edit');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
27 % Method edit field
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
28 methEdit = uicontrol('Parent',setMethFig,'Tag','methEdit','BackgroundColor',backColor,'HorizontalAlignment','left','Position',[120 position(4)-45 120 20],'String','','FontName','Times New Roman','FontSize',guiFontSize+1,'FontWeight','normal','Visible','on','Callback',@editMethodCbk,'Style','edit');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
29
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
30 uicontrol(methEdit)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
31 uiwait
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
32
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
33 %----------------------------------------------------------------------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
34 function editMethodCbk(varargin)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
35
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
36 clasName = get(clasEdit,'String');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
37 methName = get(methEdit,'String');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
38
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
39 if isempty(clasName) || ~ismember(clasName,utils.helper.ltpda_classes) % empty or not a valid LTPDA class
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
40 set(clasEdit,'String','')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
41 delete(findobj(gcf,'Tag','invalidmethod'))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
42 uicontrol('Parent',gcf,'Tag','invalidclass','BackgroundColor',backColor,'HorizontalAlignment','left','Position',[10 3 140 15],'String','* Invalid class','FontName','Times New Roman','FontSize',guiFontSize-1,'FontWeight','normal','Visible','on','Style','text');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
43 uicontrol(clasEdit);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
44 return;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
45 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
46 if isempty(methName) || ~ismethod(clasName,methName)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
47 set(methEdit,'String','')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
48 delete(findobj(gcf,'Tag','invalidclass'))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
49 uicontrol('Parent',gcf,'Tag','invalidmethod','BackgroundColor',backColor,'HorizontalAlignment','left','Position',[120 3 140 15],'String','* Invalid method','FontName','Times New Roman','FontSize',guiFontSize-1,'FontWeight','normal','Visible','on','Style','text');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
50 uicontrol(methEdit);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
51 return;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
52 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
53
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
54 blockName = methName;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
55 ii = 1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
56 while ~isempty(find_system(gcs,'SearchDepth',1,'Name',[blockName,num2str(ii)])), ii=ii+1; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
57 blockName = [blockName,num2str(ii)];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
58
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
59 set(gcbh,'LinkStatus','inactive','Name',blockName,'MaskDisplay',['disp(''',methName,''')'],'Tag',['method ',clasName],'AncestorBlock','')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
60 set(utils.prog.find_in_models(gcbh,'LookUnderMasks','all','BlockType','M-S-Function','FunctionName','ltpdasim'),'Tag',methName,'Name',methName);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
61
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
62 % Check if it's a copied block:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
63 prevMeth = get(gcbh,'UserData');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
64 if ~isempty(prevMeth)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
65 set(gcbh,'UserData','');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
66 [funcName,blkHdl] = strtok(prevMeth,'-');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
67 if strcmp(funcName,methName)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
68 blkHdl = str2double(blkHdl(2:end));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
69 newBlk = replace_block(gcs,'Name',get(gcbh,'Name'),getfullname(blkHdl),'noprompt');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
70 GUIprefs = getappdata(0, 'GUIpreferences');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
71 GUIprefs.Copied = 0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
72 setappdata(0, 'GUIpreferences',GUIprefs);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
73 set_param(newBlk{1},'Selected','on');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
74 selBlocks = get_param(newBlk{1},'Handle');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
75 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
76 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
77
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
78 minfoObj = eval([clasName,'.getInfo(''',methName,''');']);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
79 category = minfoObj.mcategory;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
80 minInput = minfoObj.argsmin;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
81 if strcmp(category,'Constructor')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
82 lineHandles = get(gcbh,'LineHandles');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
83 if lineHandles.Inport~=-1, delete_line(lineHandles.Inport); end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
84 setInports(gcbh,0)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
85 set(gcbh,'BackgroundColor','green')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
86 elseif strcmp(category,'Output')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
87 replace_block(gcb,'Outport','Terminator','noprompt');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
88 set(gcbh,'BackgroundColor','lightBlue')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
89 elseif minInput>1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
90 setInports(gcbh,minInput)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
91 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
92
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
93 closereq
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
94 uiresume
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
95
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
96 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
97 %----------------------------------------------------------------------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
98
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
99 %----------------------------------------------------------------------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
100 function setInports(varargin)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
101 % Called whenever the block to be added has argsmin>1, so it needs
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
102 % multiple data inputs:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
103
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
104 load_system('simulink')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
105 currBlock = varargin{1};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
106 newInports = varargin{2};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
107 prevInport = find_system(currBlock,'SearchDepth',1,'LookUnderMasks','all','BlockType','Inport');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
108
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
109 % To remove previous data inport and line:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
110 try %#ok<ALIGN>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
111 blockLines = get_param(prevInport,'LineHandles');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
112 if (blockLines.Outport(1)~=-1 && ~isempty(blockLines.Outport(1))), delete_line(blockLines.Outport(1)); end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
113 delete_block(prevInport);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
114 catch end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
115
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
116 % To add new inports, mux and lines:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
117 if newInports>1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
118 muxblock = add_block('built-in/Mux', [getfullname(currBlock),'/Mux']);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
119 set(muxblock,'Position',[70 , 10 , 73 , 150])
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
120 set(muxblock,'Inputs',num2str(newInports))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
121 for ii=1:newInports
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
122 newBlock = add_block('built-in/Inport', [getfullname(currBlock),'/Inport1'],'MakeNameUnique','on');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
123 set_param(newBlock,'Port',num2str(ii));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
124 newBlock = get_param(newBlock,'Handle');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
125 set(newBlock,'Position',[10 , 10+30*(ii-1) , 30 , 30+30*(ii-1)])
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
126 set(newBlock,'Tag',num2str(ii))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
127 add_line(currBlock,[get(newBlock,'Name'),'/1'],[get(muxblock,'Name'),'/',num2str(ii)]);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
128 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
129
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
130 funcBlock = find_system(currBlock,'SearchDepth',1,'LookUnderMasks','all','BlockType','M-S-Function');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
131 funcBlock = get_param(funcBlock,'Name');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
132 add_line(currBlock,[get(muxblock,'Name'),'/1'],[funcBlock,'/1']);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
133
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
134 else % no inputs
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
135 groundBlk = add_block('simulink/Sources/Ground', [gcb,'/Ground'],'MakeNameUnique','on');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
136 funcBlock = find_system(currBlock,'SearchDepth',1,'LookUnderMasks','all','BlockType','M-S-Function');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
137 funcBlock = get_param(funcBlock,'Name');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
138 add_line(currBlock,[get(groundBlk,'Name'),'/1'],[funcBlock,'/1']);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
139 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
140
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
141 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
142 %----------------------------------------------------------------------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
143
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
144 end |