0
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1 function g_arithmetic(currPanel,varargin)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2 % This callback is called whenever the user selects an arithmetic block.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
3
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
4 global guiFontSize params functionName selBlocks %#ok<NUSED>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
5 panelDimens = get(currPanel, 'Position');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
6 backColor = get(currPanel, 'BackgroundColor');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
7
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
8 delete(findobj(gcf,'Parent',currPanel))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
9 guiFontSize = getappdata(0, 'ltpda_gui_fontsize')-1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
10 lineSpacing = 30 * guiFontSize/10;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
11
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
12 paramcommand = get_param(gcbh,'Description');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
13 % noParamsReq=0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
14 if isempty(paramcommand)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
15 paramcommand = g_RetrievePlist('arithmetic');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
16 selBlocks = utils.prog.gcbsh;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
17 for kk=1:length(selBlocks)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
18 set_param(selBlocks(kk),'Description',paramcommand);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
19 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
20 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
21 eval(paramcommand)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
22
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
23 logosize = [30,30];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
24 dimension = [panelDimens(3)-135 , 15 , logosize];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
25 logo = axes('Parent',currPanel,'Units','pixels','Position',dimension);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
26 image(imread('buttonyes.jpg'),'Parent',logo);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
27 axis(logo,'off');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
28 % Apply button
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
29 uicontrol('Parent',currPanel,'Units','pixels','Position',[panelDimens(3)-100 20 80 guiFontSize*20/10],'HorizontalAlignment','right','FontSize',guiFontSize,'String','Apply','Visible','on','Callback', @ApplyArithCallback,'DeleteFcn',{@ApplyArithCallback,0},'Tag','apply','Enable','off','Style','pushbutton');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
30
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
31 uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','Position',[20 panelDimens(4)-55 100 20],'String','List of input:','HorizontalAlignment','left','FontSize',guiFontSize,'Visible','on','Style','text');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
32 y = nparams(params);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
33 for i=1:y
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
34 uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','Position',[7 panelDimens(4)-lineSpacing*(i+2)-4 8 20],'String','>','FontSize',guiFontSize,'FontWeight','Bold','Visible','on','Style','text');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
35 uicontrol('Parent',currPanel,'Units','pixels','Position',[20 panelDimens(4)-lineSpacing*(i+2) 100 20],'String',lower(params.params(i).key),'FontSize',guiFontSize,'Visible','on','Enable','on','UserData',i,'Callback',@g_editNameCallback,'Style','edit');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
36 % Remove input button
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
37 if i>1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
38 uicontrol('Parent',currPanel,'Units','pixels','Position',[125 panelDimens(4)-lineSpacing*(i+2) 20 20],'String','-','Visible','on','Enable','on','Callback', @g_RemParamCallback,'UserData',i,'Style','pushbutton');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
39 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
40 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
41 % Add input button
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
42 uicontrol('Parent',currPanel,'Units','pixels','Position',[20 panelDimens(4)-40-lineSpacing*(y+2) 20 20],'String','+','Visible','on','Enable','on','Callback', @g_AddParamCallback,'UserData','input','Style','pushbutton');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
43
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
44 % Output name:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
45 uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','Position',[20 panelDimens(4)-47-lineSpacing*(y+3) 140 20],'String','Output name:','HorizontalAlignment','left','FontSize',guiFontSize,'Visible','on','Style','text');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
46 outName = get(gcbh,'UserData');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
47 if isempty(outName), outName = get(gcbh,'Name'); end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
48 uicontrol('Parent',currPanel,'Units','pixels','Position',[20 panelDimens(4)-40-lineSpacing*(y+4) 100 20],'String',outName,'FontSize',guiFontSize,'Visible','on','Enable','on','UserData',i,'Callback','set(gcbh,''UserData'',get(gco,''String''));set(gcbh,''UserDataPersistent'',''on'')','Style','edit');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
49
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
50 % 'Type in the equation' text
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
51 uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','Position',[180 panelDimens(4)-50 400 20],'String','Type in the equation, using as an example:','HorizontalAlignment','left','FontSize',guiFontSize,'Visible','on','Style','text');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
52 % Example edit field
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
53 uicontrol('Parent',currPanel,'TooltipString','This in an example of how to type in an equation','BackgroundColor',[0.97 0.97 0.97],'Units','pixels','Position',[180 panelDimens(4)-72 500 20],'String','(alpha+beta)/2+alpha^2','FontSize',guiFontSize,'Visible','on','Enable','on','Callback','set(gco,''String'',''(alpha+beta)/2+alpha^2'')','Style','edit');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
54
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
55 % 'output =' text
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
56 uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','Position',[180 panelDimens(4)-100 400 20],'String','Output =','HorizontalAlignment','left','FontSize',guiFontSize,'Visible','on','Style','text');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
57 % Main edit field
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
58 eqString = get_param(gcbh,'MaskDescription');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
59 if numel(eqString)>16 && strcmp(eqString(1:17),'Arithmetic block:'), eqString = ''; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
60 uicontrol('Parent',currPanel,'BackgroundColor',[0.9 0.9 0.9],'Units','pixels','Position',[180 panelDimens(4)-300 500 200],'String',eqString,'Max',2,'FontSize',guiFontSize,'Visible','on','Enable','on','Tag','equationField','Callback','set(findobj(''Tag'',''apply''),''Enable'',''on'');','Style','edit');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
61
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
62
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
63 %----------------------------------------------------------------------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
64 function ApplyArithCallback(varargin)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
65 % Whenever the user clicks on the 'Apply' button for the arithmetic
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
66 % block.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
67
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
68 eqField = findobj(gcf,'Tag','equationField');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
69 eq = get(eqField,'String');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
70 if ~isempty(eq)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
71 if numel(eq)>40, eq(1:end-25) = []; eq = ['...',eq]; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
72 for nn=1:length(selBlocks)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
73 set_param(selBlocks(nn),'MaskDescription',get(eqField,'String'));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
74 set_param(selBlocks(nn),'AttributesFormatString',eq);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
75 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
76 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
77 eqString = get_param(gcbh,'MaskDescription');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
78 if numel(eqString)>16 && strcmp(eqString(1:17),'Arithmetic block:'), eqString = ''; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
79 set(eqField,'String',eqString);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
80 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
81
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
82 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
83 %----------------------------------------------------------------------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
84
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
85 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
86 %----------------------------------------------------------------------
|