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