www.gusucode.com > mbcview 工具箱matlab源码程序 > mbcview/@cgtools/@cgbrowser/show.m
function show(h, proj) %SHOW Create a CAGE browser GUI % % SHOW(CGB, PROJ) creates a CAGE browser GUI and displays the specified % project. % SHOW(CGB) opens a new project for display. % % If the browser window is already open, it will be brought to the front % of the screen. % Copyright 2000-2016 The MathWorks, Inc. and Ford Global Technologies, Inc. if h.GUIExists % Don't create another figure(h.Figure); return end if nargin<2 proj = cgcreateproject('Untitled'); end h.RootNode = proj; h.CurrentNode = xregpointer; % Null pointer => no selected node (valid setting) h.CurrentSubItem = xregpointer; h.SelNode = xregpointer; h.SelSubItem = xregpointer; % Find data dictionary h.DataDictionary = proj.getdd; ScPos = get(0,'ScreenSize'); % get the stored CG size browseprefs= getpref(mbcprefs('mbc'),'cgbrowser'); % default position cgsize(3)=ScPos(3)-200; cgsize(4)= ScPos(4)-200; cgsize(2)= 100; cgsize(1)= 100; fH=xregfigure(... 'Visible','off',... 'Name','CAGE Browser',... 'Tag','cgbrowser'); xregpersistfigpos(fH,'DefaultPos',cgsize); xregmoveonscreen(fH); mbcgui.hgclassesutil.addprop(fH,'CGB'); set(fH,'CGB',h); h.Figure=fH; h.Hand.Figure.FigListener=mbcgui.hgclassesutil.listener(fH,'ObjectBeingDestroyed',mbcutils.callback(@i_delfig,h)); [tbpnl] = createActions(h,fH,browseprefs); % start tab components % browser tab h.Hand.BrowserParent = mbcgui.container.layoutpanel('Parent',fH); browserPage = createBrowserViews(h,h.Hand.BrowserParent,browseprefs); h.Hand.BrowserParent.LayoutComponent = browserPage; homePage = cageview.project.GetStartedPane('Parent',fH,... 'Browser',h); % home cardlayout h.Hand.HomePage = homePage; h.Hand.BrowserPage = browserPage; h.Hand.HomeCardLayout = xregcardlayout(fH,'NumCards',2); attach(h.Hand.HomeCardLayout,homePage,1); attach(h.Hand.HomeCardLayout,h.Hand.BrowserParent,2); % add status bar message h.Hand.Figure.StatusBar= xregGui.statusbar('parent', fH); h.Hand.Figure.StatusBar.addMessage('Ready'); % main layout CGmainlyt=xreggridbaglayout(fH,'correctalg','on',... 'dimension',[3 1],... 'rowsizes',[31 -1 20],... 'gapx',2,'gapy',2,... 'elements',{tbpnl, h.Hand.HomeCardLayout, h.Hand.Figure.StatusBar},... 'packgroup','CGBROWSERGRP'); set(fH,'LayoutManager', CGmainlyt, 'CloseRequestFcn',{@i_close, h}); set(CGmainlyt,'packstatus','on'); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% Context menus %%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% h.DefaultContextMenu=h.makeContextMenuBase; h.GUIExists=true; h.doFillLists; h.doFindFirstType; h.doFindFirstNode; h.doDrawMenus; % Execute any startup tasks in the extensions e = mbcextensions.Extensions.Cage; for n = 1:length(e.BrowserStartupTasks) xregcallback(e.BrowserStartupTasks{n}, h, []); end set(fH,'Visible','on'); return % %%% Figure callbacks % function i_remnode(~, ~, h) if h.lock PR=xregGui.PointerRepository; ptrID=PR.stackSetPointer(h.Figure,'watch'); h.deletenode; PR.stackRemovePointer(h.Figure,ptrID); h.unlock; end function i_Copy(~, ~, h) if h.lock h.copy; h.unlock end function i_Paste(~, ~, h) if h.lock h.paste; h.unlock end function i_checkeditstatus(~,~,h) % Check Edit/Copy and Paste menu enable status h.doccp; function i_NewProject(~, ~, h) if h.lock PR=xregGui.PointerRepository; PR.stackSetPointer(h.Figure,'watch'); try %#ok<TRYNC> h.newproject; end PR.stackClearAndReset(h.Figure); h.unlock end function i_OpenProject(~, ~, h) if h.lock PR=xregGui.PointerRepository; PR.stackSetPointer(h.Figure,'watch'); try %#ok<TRYNC> h.openproject; end PR.stackClearAndReset(h.Figure); h.unlock end function i_SaveProject(~, ~, h,flg) if h.lock PR=xregGui.PointerRepository; PR.stackSetPointer(h.Figure,'watch'); try %#ok<TRYNC> msg=h.saveproject(flg); if ~isempty(msg) errordlg(msg,'File Error!','modal'); end end PR.stackClearAndReset(h.Figure); h.unlock end function i_close(~, ~, h) % This is the main closing call. % If we are in TESTMODE then we call forceclose to make sure we do close % the browser . if get( findpackage( 'xregGui' ), 'TESTMODE' ) forceclose(h); else close(h); end function i_delfig(~, ~, h) % This shutdown call must complete no matter what! h.reset; function i_listclick(srcobj,~,h) if h.lock % draw selection rectangle PR=xregGui.PointerRepository; ptrID=PR.stackSetPointer(h.Figure,'watch'); val=get(srcobj,'Value'); items=get(srcobj,'items'); h.CurrentType=items(val); PR.stackRemovePointer(h.Figure,ptrID); h.unlock end function i_calmanager(~,~,h) if h.lock h.openCalManager; h.unlock; end function i_surfviewer(~,~,c) if c.lock c.showSurfaceViewer; c.unlock; end function i_renamenode(~,~,h) if h.lock h.renamenode; h.unlock; end function i_dupnode(~,~,h) if h.lock PR=xregGui.PointerRepository; ptrID=PR.stackSetPointer(h.Figure,'watch'); h.duplicatenode; PR.stackRemovePointer(h.Figure,ptrID); h.unlock; end function iCreateOptim(~,~,h) PR=xregGui.PointerRepository; ptrID=PR.stackSetPointer(h.Figure,'watch'); C = cgcalsetup.OptimData(h.CurrentNode, h.CurrentType); C.wizard('Optimization') PR.stackRemovePointer(h.Figure,ptrID); function iCreateTables(~,~,h) PR=xregGui.PointerRepository; ptrID=PR.stackSetPointer(h.Figure,'watch'); C = cgcalsetup.TableData(h.CurrentNode, h.CurrentType); C.wizard('Tables') PR.stackRemovePointer(h.Figure,ptrID); function i_ExportCal(~,~,c) % whole project CAL = cgcaloutput(c.RootNode); gui_export(CAL); function iSelectTree(~,evt) objH=cgbrowser; PR=xregGui.PointerRepository; ptrID=PR.stackSetPointer(objH.Figure,'watch'); p = evt.Data.NewNode; if objH.lock objH.setnewnode(p,xregpointer); objH.unlock; end PR.stackRemovePointer(objH.Figure,ptrID); function iDeleteTree(~,~) objH=cgbrowser; if objH.lock if objH.IsDeleteEnabled objH.deletenode; end objH.unlock; end function iRenameTree(h,evt) p=evt.Data.Node; p_sub=xregpointer; newstring = evt.Data.NewName; objH=cgbrowser; if objH.HasRelabelManager % custom rename procedure ok=feval(objH.getRelabelFunction,p.info,p_sub,newstring); else % standard rename method - operates on primary item ok=p.rename(newstring); end if ~strcmp(p.name,newstring) wb = errordlg(sprintf(['Cannot rename %s: an item with the name %s' ... ' already exists or is not a valid variable name. Specify a different name.'], p.name,newstring), ... 'Error Renaming Item', 'modal'); waitfor(wb); end % some nodes such as normalizers may appear in multiple places on the tree. This updateAll will also % revert bad name changes updateAll(h); if ok % check that there are not duplicate items to rename on tree objH.doDrawText; objH.ViewNode; xregcallback(objH.getBrowserOptions('relabelcallback'), objH, []) end function iTreePopup(h,evt) % We have the coordinate from the underlying component, but we don't have % access to that component to use as a context menu reference frame. % Instead we use the parent which is an HG panel and manually adjust the % coordinates so that they are in the parent reference frame. opencontext(cgbrowser,get(h,'Parent'),evt.Data.Position(1)+1,evt.Data.Position(2)+1); function browserLyt = createBrowserViews(h,hParent,browseprefs) %createBrowserViews create main browser Tab view % get the stored tree width treew=browseprefs.treew; if isempty(treew) treew=0.25; end % get the stored list height listh=browseprefs.listh; if isempty(listh) listh=0.3; end TPlyt = createTypeChoosers(h,hParent); [TreePanel] = createTree(h,hParent); [ListPanel] = createListView(h,hParent); createViewCard(h,hParent); spl=xregsplitlayout(hParent,... 'packgroup','CGBROWSERGRP',... 'split',[listh 1-listh],... 'orientation','ud',... 'top',ListPanel',... 'bottom',h.ViewCardObj,... 'dividerstyle','flat',... 'dividerwidth',4); h.Hand.Figure.ListSplit=spl; if h.ListOn crd=2; else crd=1; end h.Hand.Figure.ListCard=xregcardlayout(hParent,'numcards',2,... 'packgroup','CGBROWSERGRP',... 'currentcard',crd,... 'drawonselect','on'); attach(h.Hand.Figure.ListCard,h.ViewCardObj,1); attach(h.Hand.Figure.ListCard,spl,2); spl=xregsplitlayout(hParent,... 'packgroup','CGBROWSERGRP',... 'split',[treew 1-treew],... 'left',TreePanel,... 'right',h.Hand.Figure.ListCard,... 'dividerstyle','flat',... 'dividerwidth',4); h.Hand.Figure.TreeSplit=spl; if h.TreeOn crd=2; else crd=1; end h.Hand.Figure.TreeCard=xregcardlayout(hParent,'numcards',2,... 'packgroup','CGBROWSERGRP',... 'currentcard',crd,... 'drawonselect','on'); attach(h.Hand.Figure.TreeCard,spl,2); attach(h.Hand.Figure.TreeCard,h.Hand.Figure.ListCard,1); set(h.Hand.Figure.ListCard,'Visible','on'); % fix an unfortunate conflict of visibility while creating browserLyt=xreggridbaglayout(hParent,'correctalg','on',... 'dimension',[1 2],... 'colsizes',[95 -1],... 'gapx',2,'gapy',2,... 'elements',{TPlyt,h.Hand.Figure.TreeCard} ); function TPlyt = createTypeChoosers(h,hParent) %createTypeChoosers type chooser panel on LHS sc=mbcgui.util.SystemColorsDbl; tpI=cgtools.cgtypecollection; cats=tpI.categoryobjects; if norm(sc.CTRL_SHADOW)<(3^0.5) fclr=[1 1 1]; else fclr=[0 0 0]; end % construct a list for each category % The lists will set the color [.498 .498 .498], or [127 127 127] % to be transparent. pnls = cell(1, tpI.Ncategories); for n=1:tpI.Ncategories pnls{n} = mbcgui.container.titlebarpanel('Parent', hParent, ... 'BarTitle', cats(n).Name); h.Hand.Types.Lists{1,n}=cats(n); h.Hand.Types.Lists{2,n}=xregGui.itemlist1('parent',pnls{n},... 'backgroundcolor',sc.CTRL_SHADOW,... 'foregroundcolor',fclr,... 'transparentcolor',[0 1 0],... 'transparentcolormode','on',... 'resourcelocation',cgrespath,... 'callback',{@i_listclick,h},... 'highlightselection','on',... 'value',0); set(pnls{n}, 'ContentHandle', h.Hand.Types.Lists{2,n}); end TPlyt=xregsplitlayout(hParent,... 'packgroup','CGBROWSERGRP',... 'orientation','ud',... 'dividerstyle','flat',... 'split', ones(1, tpI.NCategories), ... 'elements',pnls); function [TreePanel] = createTree(h,hParent) %createTree Create the tree TreePanel = mbcgui.container.titlebarpanel(... 'Parent', hParent, ... 'Tag', 'CGLIST'); h.Hand.Figure.Tree = mbctreeadapter.CageTree('Parent',TreePanel,... 'TreeEditedCallback',@iRenameTree,... 'DeletePressedCallback',@iDeleteTree,... 'SelectionChangedCallback',@iSelectTree,... 'TreePopupCallback',@iTreePopup); set(TreePanel,'ContentHandle',{h.Hand.Figure.Tree}); h.Hand.Figure.SelTPText{1} = TreePanel; function [ListPanel] = createListView(h,hParent) % Create the listview ListPanel = mbcgui.container.titlebarpanel(... 'Parent', hParent, ... 'Tag', 'CGLIST'); h.Hand.Figure.List= CageList('Parent',ListPanel,'UserData','list','Tag','CAGEList'); set(ListPanel,'ContentHandle',{h.Hand.Figure.List}); h.Hand.Figure.SelTPText{2} = ListPanel; function createViewCard(h,hParent) %createViewCard create card layout for main views sc=mbcgui.util.SystemColorsDbl; % The initial View corresponds to selecting a null xregpointer h.ViewData=xregGui.RunTimePointer; h.ViewData.LinkToObject(h.Figure); h.ViewGUIDs=' '; % this is a char matrix - much faster for subsequent matching h.ViewMenus={[]}; h.ViewCurrent=1; h.ViewCardObj= xregcardlayout(hParent,... 'numcards',1,... 'packgroup', 'CGBROWSERGRP'); % blank view to show when CurrentNode is null nullview = uipanel(... 'Parent', hParent, ... 'BackgroundColor', sc.CTRL_SHADOW, ... 'Units', 'pixels', ... 'BorderType', 'beveledin'); attach(h.ViewCardObj,nullview,1); function [tbpnl] = createActions(h,hParent,browseprefs) %createActions main menu and toolbar actions % to be converted to Actions in future. For now, all actions are created % directly as toolbar or menus %%%%%%%%%%%%%%%%%%%%%%%% %%% Construct menus %%% %%%%%%%%%%%%%%%%%%%%%%%% Hand = h.Hand; % get the stored toolbar split TB_spl=browseprefs.tbsplit; if isempty(TB_spl) TB_spl=[0.3 .7]; end % File Menu Hand.Menubar.File.File=uimenu(hParent,'Label','&File'); uimenu(Hand.Menubar.File.File,'Label','&Home','Callback',{@onHome,h}) Labels= {'&New','&Open Project...','&Save Project','Save Project &As...', ... 'Import From &Project','&Import','&Export',... 'Pre&ferences...','','','','','&Close'}; Accelerator= {'','O','S','',... '','','',... '','','','','','W'}; CallBacks= {'',{@i_OpenProject,h},{@i_SaveProject,h,0},{@i_SaveProject,h,1},... @(s,e)cgimporttool(),'','',... 'cgoptionsgui','','','','',{@i_close, h}}; hnd=cell(size(Labels)); for n=1:length(Labels) hnd{n}= uimenu(Hand.Menubar.File.File, ... 'Label',Labels{n},... 'Callback',CallBacks{n},... 'Accelerator',Accelerator{n}); end set([hnd{[1 5 8 end-4 end]}],'Separator','on') Hand.Menubar.File.New = hnd{1}; Hand.Menubar.File.Print=[]; Hand.Menubar.File.SaveAs=hnd{4}; Hand.Menubar.File.recentFiles=[hnd{end-4:end-1}]; Hand.Menubar.File.ImportProject=hnd{5}; Hand.Menubar.File.Import=hnd{6}; Hand.Menubar.File.Export=hnd{7}; Hand.Menubar.New.Project=uimenu(Hand.Menubar.File.New,... 'Label', '&Project',... 'Accelerator','N',... 'Callback',{@i_NewProject,h}); % add other new items h.docreateaddmenu(Hand.Menubar.File.New); % insert separator after Project ch=get(Hand.Menubar.File.New,'Children'); set(ch(end-1),'Separator','on'); % build import menu h.docreateimportmenu(Hand.Menubar.File.Import); % build export menu h.docreateexportmenu(Hand.Menubar.File.Export); %Edit Menu Hand.Menubar.Edit.Edit=uimenu(hParent,'Label','&Edit','Callback',{@i_checkeditstatus,h}); Labels = {'&Copy','&Paste','D&uplicate','&Delete','&Rename'}; CallBacks = {{@i_Copy,h},{@i_Paste,h},{@i_dupnode,h},{@i_remnode,h},{@i_renamenode,h}}; Accelerator = {'C','V','','',''}; hnd = cell(size(Labels)); for n=1:length(Labels) hnd{n}= uimenu(Hand.Menubar.Edit.Edit, ... 'Label',Labels{n}, ... 'Callback',CallBacks{n},... 'Accelerator',Accelerator{n}); end set(hnd{3},'Separator','on'); Hand.Menubar.Edit.Copy=hnd{1}; Hand.Menubar.Edit.Paste=hnd{2}; Hand.Menubar.Edit.Duplicate=hnd{3}; Hand.Menubar.Edit.Delete=hnd{4}; Hand.Menubar.Edit.Rename=hnd{5}; % Tools menu Hand.Menubar.Tools.Tools=uimenu(hParent,'Label','&Tools'); Hand.Menubar.Tools.CreateTables=uimenu(Hand.Menubar.Tools.Tools,'Label', 'Create &Tables from Model',... 'Callback',{@iCreateTables,h},'Enable','off'); Hand.Menubar.Tools.CreateOptim=uimenu(Hand.Menubar.Tools.Tools,'Label', 'Create &Optimization from Model',... 'Callback',{@iCreateOptim,h},'Enable','off'); Hand.Menubar.Tools.CalManager=uimenu(Hand.Menubar.Tools.Tools,'Label', '&Calibration Manager',... 'Callback',{@i_calmanager,h},'Enable','off'); Hand.Menubar.Tools.SurfViewer=uimenu(Hand.Menubar.Tools.Tools,'Label', '&Surface Viewer',... 'Callback',{@i_surfviewer,h},'Enable','off'); h.docreatetoolsmenu(Hand.Menubar.Tools.Tools); % Window menu cgwinlist(hParent); % Help menu cghelpmenu(hParent,{'&CAGE Help','CGCALIBRATE'}); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% Toolbar %%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% tbpnl = mbcgui.container.layoutpanel(... 'Parent', hParent, ... 'BorderType', 'beveledin'); Hand.Toolbar.MainBar=xregGui.uitoolbar(tbpnl); Hand.Toolbar.MainBar.setRedraw(false); Hand.Toolbar.buttons.Home = xregGui.uipushtool(Hand.Toolbar.MainBar,... 'CData',xregresload('mbc_app_16.bmp', 'BMP'),... 'TooltipString','Home',... 'ClickedCallback', {@onHome,h},... 'TransparentColor',[0 255 0],... 'Interruptible','off'); Hand.Toolbar.buttons.New=xregGui.uipushtool(Hand.Toolbar.MainBar,... 'CData',cgresload('new.bmp', 'BMP'),... 'TooltipString','New Project',... 'ClickedCallback', {@i_NewProject,h},... 'TransparentColor',[0 255 0],... 'Separator','on',... 'Interruptible','off'); Hand.Toolbar.buttons.Open=xregGui.uipushtool(Hand.Toolbar.MainBar,... 'CData',cgresload('open.bmp', 'BMP'),... 'TooltipString','Open Project',... 'ClickedCallback', {@i_OpenProject,h},... 'transparentcolor',[0 255 0],... 'Interruptible','off'); Hand.Toolbar.buttons.Save=xregGui.uipushtool(Hand.Toolbar.MainBar,... 'CData',cgresload('save.bmp', 'BMP'),... 'TooltipString','Save Project',... 'ClickedCallback', {@i_SaveProject,h,0},... 'transparentcolor',[0 255 0],... 'Interruptible','off'); Hand.Toolbar.buttons.Delete=xregGui.uipushtool(Hand.Toolbar.MainBar,... 'CData',cgresload('delete.bmp', 'BMP'),... 'TooltipString','Delete',... 'Separator','on',... 'ClickedCallback', {@i_remnode,h},... 'transparentcolor',[0 255 0],... 'Interruptible','off'); % Import From Project Hand.Toolbar.buttons.Import=xregGui.uipushtool(Hand.Toolbar.MainBar,... 'CData',cgresload('projectImport.bmp', 'BMP'),... 'TooltipString','Import items from another project',... 'ClickedCallback', @(s,e)cgimporttool(),... 'Separator','on',... 'transparentcolor',[0 255 0],... 'Interruptible','off'); Hand.Toolbar.buttons.CalManager=xregGui.uipushtool(Hand.Toolbar.MainBar,... 'CData',cgresload('calmanager.bmp', 'BMP'),... 'TooltipString','Calibration Manager',... 'ClickedCallback', {@i_calmanager,h},... 'transparentcolor',[0 255 0],... 'Interruptible','off'); Hand.Toolbar.buttons.ExportCal=xregGui.uipushtool(Hand.Toolbar.MainBar,... 'CData',cgresload('calExport.bmp', 'BMP'),... 'TooltipString','Export all calibration items',... 'ClickedCallback', {@i_ExportCal,h},... 'transparentcolor',[0 255 0],... 'Interruptible','off'); Hand.Toolbar.buttons.CreateTables=xregGui.uipushtool(Hand.Toolbar.MainBar,... 'CData',cgresload('createTablesFromModel.bmp', 'BMP'),... 'TooltipString','Create tables and a tradeoff from a model',... 'ClickedCallback', {@iCreateTables,h},... 'Separator','on',... 'transparentcolor',[0 255 0],... 'Interruptible','off'); Hand.Toolbar.buttons.CreateOptim = xregGui.uipushtool(Hand.Toolbar.MainBar,... 'CData',cgresload('createOptimFromModel.bmp', 'BMP'),... 'TooltipString','Create an optimization from a model',... 'ClickedCallback', {@iCreateOptim,h},... 'transparentcolor',[0 255 0],... 'Interruptible','off'); Hand.Toolbar.buttons.SurfViewer=xregGui.uipushtool(Hand.Toolbar.MainBar,... 'CData',cgresload('surfviewer.bmp', 'BMP'),... 'TooltipString','Surface Viewer',... 'ClickedCallback', {@i_surfviewer,h},... 'Separator','on',... 'transparentcolor',[0 255 0],... 'Interruptible','off'); Hand.Toolbar.buttons.Help=cghelptoolbutton(Hand.Toolbar.MainBar,'CGCALIBRATE','tooltip','CAGE Help'); Hand.Toolbar.MainBar.setRedraw(true); Hand.Toolbar.MainBar.drawToolBar; % add the toolbar layouts h.ViewToolbarCard=xregcardlayout(tbpnl,'numcards',1,'packgroup','CGBROWSERGRP'); tbsplit=xregsplitlayout(tbpnl,... 'packgroup','CGBROWSERGRP',... 'orientation','lr',... 'minwidthunits','picels',... 'minwidth',[15 15],... 'left',Hand.Toolbar.MainBar,... 'right',h.ViewToolbarCard,... 'split',TB_spl,... 'dividerstyle','flat',... 'dividerwidth',4); Hand.Toolbar.Split=tbsplit; Hand.Toolbar.Panel = tbpnl; set(tbpnl, 'LayoutComponent', {tbsplit}); h.Hand=Hand; function onHome(~,~,h) %onHome select home page selectHome(h,1);