www.gusucode.com > mbcdesign 工具箱 matlab 源码程序 > mbcdesign/@conbase/guiTypeLayout.m
function lyt = guiTypeLayout(con, figh,pCon,TypeString) %GUITYPELAYOUT % % [lyt, udp] = guiTypeLayout(con, figh,p) % Copyright 2008-2015 The MathWorks, Inc. and Ford Global Technologies, Inc. if isa(figh,'xregcontainer') return end T = pCon.info; fitOptions = T.fitOptions; NeedFitOptionsUpdate = false; if nargin<4 TypeString = 'Boundary model type:'; end % % Active Factors Layout % NF = nFactors(con); % Main Layout is a tab layout with active inputs and fit options TabLyt = uitabgroup('Parent',figh,... 'SelectionChangedFcn',@iChangeTab,... 'Units','pixels'); activeInputsTab = mbcgui.container.uitab('Parent',TabLyt,... 'LayoutBorder',[10 10 10 10],... 'Title','Active Inputs'); fitOptionsTab = mbcgui.container.uitab('Parent',TabLyt,... 'LayoutBorder',[10 10 10 10],... 'Title','Fit Options'); txtMessage = i_text( activeInputsTab, '' ); hListView = i_createListView( activeInputsTab, con ); % Variables used in "i_clickListView" isActive = false( NF,1 ); isActive(getActiveIndices(con)) = true; hListeners = handle.listener(hListView, 'ValueChanged',@i_clickListView); %#ok<NASGU> SC = xregGui.SystemColorsDbl; % Pop-up and label for constraint chooser classes = getconstrainttypes(xregbdrydev); [objects, names, index] = pGenerateObjectList( con, classes ); chooser = uicontrol( ... 'Parent', figh, ... 'Visible', 'off', ... 'BackgroundColor', SC.WINDOW_BG, ... 'Style', 'popupmenu', ... 'String', names, ... 'Value', index, ... 'Callback', @i_switchObject ); label = xregGui.labelcontrol( ... 'Parent', figh, ... 'Visible', 'off', ... 'String', TypeString, ... 'LabelSizeMode', 'absolute', ... 'ControlSizeMode', 'relative', ... 'LabelSize', 110, ... 'ControlSize', 1, ... 'Control', chooser ); Inputlyt = xreggridbaglayout( activeInputsTab,... 'dimension', [4, 1], ... 'rowsizes', [120 10 60 -1], ... 'gapy', 0, ... 'gapx', 10,... 'border', [0, 0, 0, 0],... 'elements', {hListView, [],txtMessage,[]}); activeInputsTab.LayoutComponent = Inputlyt; TempOptmgr = setname(xregoptmgr,getname(fitOptions)); % setup for xregoptmgr needs a separate RunTimePointer pFitOptions = xregGui.RunTimePointer( TempOptmgr ); % make with an default xregoptmgr for speed fitlyt = gui_setup(TempOptmgr, 'layout', ... {'expanded', true, 'topname', getname(fitOptions), 'basiclayout', false}, ... fitOptionsTab, pFitOptions, con); fitOptionsCard = xregcardlayout( fitOptionsTab); attach(fitOptionsCard,fitlyt,1); fitMessage = uicontrol('Parent',fitOptionsTab,... 'Style','text'); attach(fitOptionsCard,fitMessage,2); fitOptionsTab.LayoutComponent = fitOptionsCard; % set to real xregoptmgr and flag a redraw of the layout when tab is % changed pFitOptions.info = fitOptions; NeedFitOptionsUpdate = true; OptListener =handle.listener(pFitOptions,findprop(classhandle(pFitOptions),'info'),'PropertyPostSet',@iUpdateFitOptions); %#ok<NASGU> % class chooser [lyt, callback] = pCreateChooserLayout( con, figh, label, TabLyt, true ); % choose class i_switchObject( chooser, [] ); % Effective end of i_createLayout. From here on there is just % nested functions function i_clickListView( ~, ~ ) isActive = hListView.getChecks; [mn, mx] = nActiveFactorsAllowed( con ); na = nnz( isActive ); if mn <= na && na <= mx OldIndices = getActiveIndices(con); con = setActiveIndices( con, find( isActive ) ); T.constraint = con; T.isValidObject = true; pCon.info = T; if ~isequal(OldIndices(:),find( isActive(:) )) % new fit options may be required when active inputs are % selected iDefaultFitOptions; else iSetOptions end T.isValidObject = true; else % disable fit options until a valid number of factors is % specified set(fitOptionsCard,'CurrentCard',2); fitMessage.String = 'The current boundary model has an invalid number of active inputs.'; T.isValidObject = false; pCon.info = T; end i_UpdateMessage; end % of nested function i_clickListView function i_setCheckboxes hListView.Peer.setChecks(isActive); end % of nested function i_setCheckboxes function i_switchObject( ~, ~ ) index = get( chooser, 'Value' ); NewCon = objects{index}; if ~strcmp(class(T.constraint),class(NewCon)) con = NewCon; T.constraint = con; pCon.info = T; % reset options iDefaultFitOptions; end callback( con ); i_setCheckboxes; i_clickListView( [], [] ) i_UpdateMessage; end % of nested function i_switchObject function iSetOptions if TabLyt.SelectedTab == fitOptionsTab % only update if showing options gui_setup(fitOptions, 'updatelayout',... {'expanded', true, 'topname', 'Algorithm', 'basiclayout', false},... fitlyt,pFitOptions,con); else NeedFitOptionsUpdate = true; end if isnull(fitOptions) %disable fit options tab if there is nothing settable TabLyt.SelectedTab = activeInputsTab; set(fitOptionsCard,'CurrentCard',2); fitMessage.String = 'The current boundary model has no fit options.'; else % enable fit options tab set(fitOptionsCard,'CurrentCard',1); end end function iDefaultFitOptions(~,~) % get default options fitOptions = getFitOptions(con,'all'); T = pCon.info; T.fitOptions = fitOptions; pCon.info = T; % this is the copy for the fit options setup ui in Tab 2 pFitOptions.info = fitOptions; iSetOptions end function i_UpdateMessage if T.isValidObject, naf = nActiveFactors( con ); if naf == 1, msg = 'The current boundary model has 1 active input.'; else msg = sprintf( 'The current boundary model has %d active inputs.', naf ); end else msg = 'The current boundary model has an invalid number of active inputs.'; end msg = sprintf( '%s\n\n%s', i_RequiredActiveFactorsMessage, msg ); set( txtMessage, 'String', msg ); end % of the nested function i_UpdateMessage function msg = i_RequiredActiveFactorsMessage nafa = nActiveFactorsAllowed( con ); type = lower(typename(con)); if nafa(1) == nafa(2), if nafa(1) == 1, s = ''; else s = 's'; end msg = sprintf( 'A %s boundary model must have %d active input%s.', ... type, nafa(1), s ); elseif isinf( nafa(2) ), if nafa(1) == 1, msg = sprintf( 'A %s boundary model can have any number of active inputs.', ... type ); else msg = sprintf( 'A %s boundary model must have at least %d active inputs.', ... type, nafa(1) ); end else msg = sprintf( 'A %s boundary model must have between %d and %d active inputs.', ... type, nafa ); end end % of nested function i_RequiredActiveFactorsMessage function iUpdateFitOptions(~,evt) pFitOptions = evt.AffectedObject; T = pCon.info; T.fitOptions = pFitOptions.info; pCon.info = T; end function iChangeTab(h,~) if h.SelectedTab==fitOptionsTab && NeedFitOptionsUpdate T = pCon.info; fitOptions = T.fitOptions; gui_setup(T.fitOptions, 'updatelayout',... {'expanded', true, 'topname', 'Algorithm', 'basiclayout', false},... fitlyt,pFitOptions,con); NeedFitOptionsUpdate = false; end end end %-------------------------------------------------------------------------- function lvh = i_createListView( Parent, con ) % List view for choosing active inputs lvh = mbcwidgets.List( 'Parent', Parent,... 'Editable', true, ... 'SelectionMode', 'None'); text = {'Name', 'Symbol', 'Units', 'Min', 'Max'}; width = [100, 75, 75, 75, 75]; lvh.Peer.setColumnData(text); lvh.Peer.setColumnWidths(width); lvh.Peer.setDisplayChecks(true); % Fill in the table with data cif = getInputFactors( con ); NF = length(cif); Data = cell(length( cif ),length(width)); isActive = false( 1, NF ); isActive(getActiveIndices(con)) = true; for i = 1:length( cif ), Data(i,:) = {cif.Name{i},cif.Symbol{i},cif.Unit{i},cif(i).Min, cif(i).Max}; end lvh.Peer.setData(Data); lvh.Peer.setChecks(isActive); end %-------------------------------------------------------------------------- function txt = i_text( Parent, str ) txt = uicontrol( ... 'Parent', Parent,... 'HitTest', 'off',... 'Enable', 'inactive',... 'Style', 'text',... 'String', str,... 'HorizontalAlignment', 'left' ); end