Mercurial > hg > ltpda
view 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 |
line wrap: on
line source
function g_arithmetic(currPanel,varargin) % This callback is called whenever the user selects an arithmetic block. global guiFontSize params functionName selBlocks %#ok<NUSED> panelDimens = get(currPanel, 'Position'); backColor = get(currPanel, 'BackgroundColor'); delete(findobj(gcf,'Parent',currPanel)) guiFontSize = getappdata(0, 'ltpda_gui_fontsize')-1; lineSpacing = 30 * guiFontSize/10; paramcommand = get_param(gcbh,'Description'); % noParamsReq=0; if isempty(paramcommand) paramcommand = g_RetrievePlist('arithmetic'); selBlocks = utils.prog.gcbsh; for kk=1:length(selBlocks) set_param(selBlocks(kk),'Description',paramcommand); end end eval(paramcommand) logosize = [30,30]; dimension = [panelDimens(3)-135 , 15 , logosize]; logo = axes('Parent',currPanel,'Units','pixels','Position',dimension); image(imread('buttonyes.jpg'),'Parent',logo); axis(logo,'off'); % Apply button 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'); 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'); y = nparams(params); for i=1:y 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'); 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'); % Remove input button if i>1 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'); end end % Add input button 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'); % Output name: 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'); outName = get(gcbh,'UserData'); if isempty(outName), outName = get(gcbh,'Name'); end 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'); % 'Type in the equation' text 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'); % Example edit field 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'); % 'output =' text uicontrol('Parent',currPanel,'BackgroundColor',backColor,'Units','pixels','Position',[180 panelDimens(4)-100 400 20],'String','Output =','HorizontalAlignment','left','FontSize',guiFontSize,'Visible','on','Style','text'); % Main edit field eqString = get_param(gcbh,'MaskDescription'); if numel(eqString)>16 && strcmp(eqString(1:17),'Arithmetic block:'), eqString = ''; end 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'); %---------------------------------------------------------------------- function ApplyArithCallback(varargin) % Whenever the user clicks on the 'Apply' button for the arithmetic % block. eqField = findobj(gcf,'Tag','equationField'); eq = get(eqField,'String'); if ~isempty(eq) if numel(eq)>40, eq(1:end-25) = []; eq = ['...',eq]; end for nn=1:length(selBlocks) set_param(selBlocks(nn),'MaskDescription',get(eqField,'String')); set_param(selBlocks(nn),'AttributesFormatString',eq); end else eqString = get_param(gcbh,'MaskDescription'); if numel(eqString)>16 && strcmp(eqString(1:17),'Arithmetic block:'), eqString = ''; end set(eqField,'String',eqString); end end %---------------------------------------------------------------------- end %----------------------------------------------------------------------