www.gusucode.com > mbctools 工具箱 matlab 源码程序 > mbctools/@modeldev/EXMdialog.m
function OK = EXMdialog(mdev, models) %EXMDIALOG Export model to CAGE % % OK = EXMDIALOG( MDEV ) % OK = EXMDIALOG( MDEV, EXPORTINFO,DoConstraints ) % Copyright 2000-2011 The MathWorks, Inc. and Ford Global Technologies, Inc. OK = false; % Get the base model out of this modeldev object, and count its inputs mbase = model(mdev); if isa(mbase,'localmod') mbase = peval('model',Parent(mdev)); end % Get the current CAGE project, opening the CAGE browser if necessary. cgb = cgbrowser; proj = cgb.RootNode; if isempty(proj) answer = questdlg(['The CAGE browser is not open. It must be open before you can '... 'export a model to it. Open the CAGE browser now?'], 'Open CAGE Browser',... 'Yes','No','Cancel','Yes'); if strcmp(answer,'Yes') cage; cgb = cgbrowser; proj = cgb.RootNode; end if isempty(proj) % No, Cancel, failure to start CAGE browser return; end end % Get list of CAGE models pModExprs = proj.getmodels; tmpExm = getBestExportModel(mdev); canReplace = parrayeval( pModExprs, @canModelBeReplacedBy, {tmpExm}, mbclogical ); pModExprs = pModExprs(canReplace); cgnames = parrayeval( pModExprs, @getname ); cgicons = parrayeval( pModExprs, @(n)cgrespath( iconfile( n ) ) ); % Find any existing model which has the same name as the one we are % about to export. mname = varname(mbase); P = com.mathworks.toolbox.mbc.gui.peer.ModelTransferDialogPeer; hDlg = mbcwidgets.javawindow(P); hDlg.setTitle( 'Export to CAGE' ); hDlg.setSize([350, 275]); hDlg.centerWindow; % set the info to show in the dialog P.setModelList( cgnames, cgicons, mname ); hDlg.blockingShow; OK = P.getOK; if OK replace = ~P.isAddNewModel; model_names = cellstr( char( P.getModelNames ) ); for n = 1:length( model_names ) try pNode = ImportMBCModel( info(proj),models{n},model_names{n},replace,true); OK(n) = ~isnull(pNode); catch ME OK(n) = false; errordlg( ME.message,'Export Error' ); end end if any( OK ) ch = cgbrowser; ch.doDrawTree; ch.doDrawList; ch.ShowNode; ch.ViewNode; end end