www.gusucode.com > mbcdesign 工具箱 matlab 源码程序 > mbcdesign/@conbase/guiTypeAndFactorsChooser.m
function [returnObj, returnFitObj,ok,HasChanged] = guiTypeAndFactorsChooser(obj, fitOptions,classes, varargin) %#ok<INUSL> %GUITYPEANDFACTORSCHOOSER Dialog for selecting a constraint type and active inputs % % [OBJ, OK,HASCHANGED] = GUITYPEANDFACTORSCHOOSER(OBJ, CLASSES, VARARGIN) % % This GUI allows the user to choose the class of the constraint and also % to choose which inputs should be active. % % Example: % classes = {@conlinear, @contable1, @contable2}; % con = guiTypeAndFactorsChooser( tExample( contable1 ), classes ) % % See also CONBASE, CONBASE/GUITYPECHOOSER. % Copyright 2005-2015 The MathWorks, Inc. and Ford Global Technologies, Inc. TITLE = 'Boundary Model Setup'; isValidObject = true; returnObj = obj; returnFitObj = fitOptions; HasChanged= false; T.isValidObject = true; T.fitOptions = fitOptions; T.constraint = obj; pConData = xregGui.RunTimePointer(T); hDialog = mbcgui.dialog.StandardDialog(obj, ... 'PageInfoFunction', @i_generateEditorPages, ... 'DisplaySinglePageAsTab', false, ... 'Title', TITLE, ... varargin{:}); % add listener to local constraint ConListener=handle.listener(pConData,findprop(classhandle(pConData),'info'),'PropertyPostSet',@iUpdate); %#ok<NASGU> while true ok = hDialog.show; if ok && ~isValidObject waitfor( xregerror( TITLE, i_RequiredActiveFactorsMessage ) ); else break end end if ok HasChanged= ~strcmp(class(returnObj),class(obj)) || ... ~isequal(getActiveFactors(returnObj),getActiveFactors(obj)) || ... ~isequal(returnFitObj,fitOptions); % Ideally we should check whether the constraint has changed before % applying the new constraint. However, this is may be more complicated than % just checking the class as parameters within the class may have % changed. We don't have a case for this at present. returnObj = obj; returnFitObj = fitOptions; end delete(hDialog); function hInfo = i_generateEditorPages(obj, hPageGroup) %#ok<INUSL> hInfo = mbcgui.dialog.PageInfo( ... 'PageGroup', hPageGroup, ... 'Name', 'Base Editor', ... 'PreferredWidth', 580, ... 'PreferredHeight', 500, ... 'HelpHandler', 'mv_helptool', ... 'HelpCode', 'xreg_bdrymodeleditor', ... 'CreateCallback', @i_createLayout); end % of nested function i_generateEditorPages function i_createLayout(hInfo, ~) hParent = hInfo.Parent; lyt = guiTypeLayout(obj, hParent,pConData); hInfo.setUI( lyt ); end function msg = i_RequiredActiveFactorsMessage nafa = nActiveFactorsAllowed( obj ); 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.', ... typename( obj ), nafa(1), s ); elseif isinf( nafa(2) ), if nafa(1) == 1, msg = sprintf( 'A %s boundary model can have any number of active inputs.', ... typename( obj ) ); else msg = sprintf( 'A %s boundary model must have at least %d active inputs.', ... typename( obj ), nafa(1) ); end else msg = sprintf( 'A %s boundary model must have between %d and %d active inputs.', ... typename( obj ), nafa ); end end % of nested function i_RequiredActiveFactorsMessage function iUpdate(prop,evt) pConData = evt.AffectedObject; T = pConData.info; obj = T.constraint; fitOptions = T.fitOptions; isValidObject = T.isValidObject; if isValidObject enableOK(hDialog,'on') else enableOK(hDialog,'off') end end end