comparison m-toolbox/m/gui/gltpda/g_arithmetic.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 g_arithmetic(currPanel,varargin)
2 % This callback is called whenever the user selects an arithmetic block.
3
4 global guiFontSize params functionName selBlocks %#ok<NUSED>
5 panelDimens = get(currPanel, 'Position');
6 backColor = get(currPanel, 'BackgroundColor');
7
8 delete(findobj(gcf,'Parent',currPanel))
9 guiFontSize = getappdata(0, 'ltpda_gui_fontsize')-1;
10 lineSpacing = 30 * guiFontSize/10;
11
12 paramcommand = get_param(gcbh,'Description');
13 % noParamsReq=0;
14 if isempty(paramcommand)
15 paramcommand = g_RetrievePlist('arithmetic');
16 selBlocks = utils.prog.gcbsh;
17 for kk=1:length(selBlocks)
18 set_param(selBlocks(kk),'Description',paramcommand);
19 end
20 end
21 eval(paramcommand)
22
23 logosize = [30,30];
24 dimension = [panelDimens(3)-135 , 15 , logosize];
25 logo = axes('Parent',currPanel,'Units','pixels','Position',dimension);
26 image(imread('buttonyes.jpg'),'Parent',logo);
27 axis(logo,'off');
28 % Apply button
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');
30
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');
32 y = nparams(params);
33 for i=1:y
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');
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');
36 % Remove input button
37 if i>1
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');
39 end
40 end
41 % Add input button
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');
43
44 % Output name:
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');
46 outName = get(gcbh,'UserData');
47 if isempty(outName), outName = get(gcbh,'Name'); end
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');
49
50 % 'Type in the equation' text
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');
52 % Example edit field
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');
54
55 % 'output =' text
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');
57 % Main edit field
58 eqString = get_param(gcbh,'MaskDescription');
59 if numel(eqString)>16 && strcmp(eqString(1:17),'Arithmetic block:'), eqString = ''; end
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');
61
62
63 %----------------------------------------------------------------------
64 function ApplyArithCallback(varargin)
65 % Whenever the user clicks on the 'Apply' button for the arithmetic
66 % block.
67
68 eqField = findobj(gcf,'Tag','equationField');
69 eq = get(eqField,'String');
70 if ~isempty(eq)
71 if numel(eq)>40, eq(1:end-25) = []; eq = ['...',eq]; end
72 for nn=1:length(selBlocks)
73 set_param(selBlocks(nn),'MaskDescription',get(eqField,'String'));
74 set_param(selBlocks(nn),'AttributesFormatString',eq);
75 end
76 else
77 eqString = get_param(gcbh,'MaskDescription');
78 if numel(eqString)>16 && strcmp(eqString(1:17),'Arithmetic block:'), eqString = ''; end
79 set(eqField,'String',eqString);
80 end
81
82 end
83 %----------------------------------------------------------------------
84
85 end
86 %----------------------------------------------------------------------