www.gusucode.com > mbctools 工具箱 matlab 源码程序 > mbctools/@xregtools/@MBrowser/Show.m

    function Show(h, proj)
%SHOW Create a Model Browser GUI
%
%  h.Show(P_TP);

%  Copyright 2000-2016 The MathWorks, Inc. and Ford Global Technologies, Inc.


if h.GUIExists
   figure(h.Figure);
   % don't create another
   return   
end

h.RootNode=proj;
h.CurrentNode=proj;

% create GUI
ScPos= get(0,'ScreenSize');

minMBCDimension = [1024, 768];
if any(ScPos(3:4)<minMBCDimension)
     errordlg('The Model Browser requires a 1024x768 resolution screen','Error','modal');
    return
end

% default position
% width and height are 70% of total width/height
mbsize(3)=max(minMBCDimension(1),ScPos(3)*.7);
mbsize(4)= max(minMBCDimension(2),ScPos(4)*.7);
% center window in middle of screen
mbsize(1)= (ScPos(3)-mbsize(3))/2;
mbsize(2)= (ScPos(4)-mbsize(4))/2;

% get the stored MB size
mbprefs= getpref(mbcprefs('mbc'),'ModelBrowser');
if isempty(mbprefs.TreeSplit)
   % default splits
   mbprefs.TreeSplit=[180 mbsize(3)-180];
   mbprefs.ListSplit=[mbsize(4)-min(200,mbsize(4)/4)  min(200,mbsize(4)/4)];
   mbprefs.ToolbarSplit=[0.3 0.7];
end


fH=xregfigure('Position',mbsize,...
   'RendererMode','Manual',...
   'Renderer','painters',...
   'Visible','off',...
   'Name','Model Browser',...
   'Tag','mvModelBrowser');
xregpersistfigpos(fH,'defaultpos',mbsize);
xregmoveonscreen(fH);
mbcgui.hgclassesutil.addprop(fH,'MBH');
set(fH, 'MBH', h);

h.Figure=mbcgui.hgclassesutil.toNative(fH);


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%        Menubar         %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%FILE MENU
pH= uimenu(fH, 'Label', '&File');

Hand.Menubar.Home = uimenu(pH, 'Label','&Home','Callback',@onHome);


Labels= {'&New Project','&Open Project...','&Save Project','Save Project &As...',...
    'New X','&Export Models...','&Delete Y','Clean-up &Tree',...
    'Pre&ferences...','&Print...',...
    '','','','',...
    '&Close'};
Accelerator= {'N','O','S','',...
    '','','','',...
    '','P',...
    '','','','',...
    'W'};
CallBacks= {{@i_NewProject,h},{@i_OpenProject,h},{@i_SaveProject,h,0},{@i_SaveProject,h,1},...
    {@i_new,h},{@i_export,h},{@i_deletetv, h},'tidytree',...
    'mv_options_gui();',{@i_print,h},...
    '','','','',...
    {@i_close, h}};
hnd = gobjects(1,length(Labels));
for n=1:length(Labels)
   hnd(n)= uimenu(pH, 'Label',Labels{n},'Callback',CallBacks{n},'Accelerator',Accelerator{n});
end
set(hnd(end),'Tag','xregClose');
set(hnd(7),'Enable','off');  % Information item
set(hnd([1 5 9 10 end-4 end]),'Separator','on');
Hand.Menubar.File=pH;
Hand.Menubar.SaveAs=hnd(4);
Hand.Menubar.NewX=hnd(5);
Hand.Menubar.Export=hnd(6);
Hand.Menubar.DeleteY=hnd(7);
Hand.Menubar.TidyTree=hnd(8);
Hand.Menubar.Print=hnd(10);
Hand.Menubar.recentFiles=hnd(11:14);

% Create a tools menu if necessary
h.docreatetoolsmenu;

%WINDOW MENU
xregwinlist(fH); % initialize Window Menu

%HELP MENU
mv_helpmenu(fH);


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%        Toolbar         %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Hand.Toolbar.Panel = mbcgui.container.layoutpanel(...
    'Parent', fH, ...
    'BorderType', 'beveledin');
Hand.Toolbar.MainBar=xregGui.uitoolbar(Hand.Toolbar.Panel,'ResourceLocation',xregrespath);
Hand.Toolbar.MainBar.setRedraw(false);

tt={'Home';'New Project';'Open Project';'Save Project';'Print';'New Node';'Delete Tree Node';'Up One Level'};
cbs= {{@onHome,h};{@i_NewProject,h}; {@i_OpenProject,h}; {@i_SaveProject,h,0};{@i_print,h}; {@i_new,h}; {@i_deletetv, h}; {@i_moveup,h}};


[~,Hand.Toolbar.buttons] = xregtoolbar(Hand.Toolbar.MainBar,...
   {'uipush';'uipush';'uipush';'uipush';'uipush';'uipush';'uipush';'uipush'},...
   'transparentcolor', [0 255 0],...
    {'imageFile'}, {'mbc_app_16.bmp';'fileNew.bmp';'fileOpen.bmp';'FileSave.bmp';'print.bmp';'newtestplan.bmp';'delete.bmp';'levelup.bmp'},...
    {'Tooltipstring'}, tt,...
    {'clickedcallback'}, cbs,...
   {'separator'},{'off';'on';'off';'off';'on';'on';'off';'off'});

Hand.Toolbar.Helpbutton=mv_helptoolbutton(Hand.Toolbar.MainBar,'xreg_modelBrowser','tooltip','Model Browser Help');

% the enable call should maybe be done as a separate method for all enables
Hand.Toolbar.MainBar.setRedraw(true);
Hand.Toolbar.MainBar.drawToolBar;
% add the toolbar layouts
Hand.Toolbar.CardObj= xregcardlayout(Hand.Toolbar.Panel,'numcards',1,'packgroup','MB_MAINGROUP');

tbsplit= xregsplitlayout(Hand.Toolbar.Panel,...
   'packgroup', 'MB_MAINGROUP',...
   'orientation','lr',...
   'minwidthunits','pixels',...
   'minwidth',[15 15],...
   'left',Hand.Toolbar.MainBar,...
   'right',Hand.Toolbar.CardObj,...
   'split',mbprefs.ToolbarSplit,...
   'dividerstyle','flat',...
   'dividerwidth',3);
Hand.Figure.TBsplit=tbsplit;
set(Hand.Toolbar.Panel, 'LayoutComponent', tbsplit);

Hand.Figure.StatusBar = xregGui.statusbar('parent', fH);
Hand.Figure.StatusBar.addMessage('Ready');

% Store Handle data
h.Hand=Hand;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%     Rest of Figure     %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% start tab components
% browser tab
browserPage = createBrowserViews(h,fH,mbprefs);
data = createFirstView(h);

homePage = mbcmodelview.project.GetStartedPane('Parent',fH,...
    'MessageService',data.MessageService,...
    'Browser',h);
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,browserPage,2);



if proj.isBlank
    % open with start tab
    selectHome(h,1);
else
    % open with browser tab
    selectHome(h,2);
end


MBcenter=xreggridlayout(fH,'correctalg','on',...
   'dimension',[3 1],...
   'rowsizes',[31 -1 20],...
   'gap',2,...
   'elements',{h.Hand.Toolbar.Panel, h.Hand.HomeCardLayout, h.Hand.Figure.StatusBar},...
   'packgroup','MB_MAINGROUP');


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%     Context menus      %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
h.DefaultTreeContext=h.makeContextMenuBase;


h.FileModified(1);

h.doEnableStatus;
h.doDrawText;
h.doDrawIcons;
h.doDrawMenus;
h.doConnectHelp;

set(fH,'CloseRequestFcn',{@i_close, h},...
   'DeleteFcn',{@i_delete, h});
fH.LayoutManager = MBcenter;
set(MBcenter,'packstatus','on');

% Execute any startup tasks in the extensions
e = mbcextensions.Extensions.Model;
for n = 1:length(e.BrowserStartupTasks)
    xregcallback(e.BrowserStartupTasks{n}, h, []);
end

set(fH,'Visible','on');
return


% 
% 
%%% Figure callbacks
% 
% 

function i_NewProject(~, ~, h)
PR=xregGui.PointerRepository;
ptrID=PR.stackSetPointer(h.Figure,'watch');
h.NewProject;
PR.stackRemovePointer(h.Figure,ptrID);

function i_OpenProject(~, ~, h)
PR=xregGui.PointerRepository;
ptrID=PR.stackSetPointer(h.Figure,'watch');
h.OpenProject;
PR.stackRemovePointer(h.Figure,ptrID);

function i_SaveProject(~, ~, h,flg)
PR=xregGui.PointerRepository;
ptrID=PR.stackSetPointer(h.Figure,'watch');
msg=h.SaveProject(flg);
if ~isempty(msg)
   errordlg(msg,'File Error!','modal');
end
PR.stackRemovePointer(h.Figure,ptrID);

function i_close(~, ~, h)

% 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_delete(~, ~, h)
h.Reset;

function i_print(~, ~, h)
PR=xregGui.PointerRepository;
ptrID=PR.stackSetPointer(h.Figure,'watch');
h.Print;
PR.stackRemovePointer(h.Figure,ptrID);


function i_export(~, ~, h)
PR=xregGui.PointerRepository;
ptrID=PR.stackSetPointer(h.Figure,'watch');
h.Export;
PR.stackRemovePointer(h.Figure,ptrID);


function i_new(~, ~, h)
PR=xregGui.PointerRepository;
ptrID=PR.stackSetPointer(h.Figure,'watch');
h.NewNode;
PR.stackRemovePointer(h.Figure,ptrID);


function i_deletetv(~, ~, h)
PR=xregGui.PointerRepository;
ptrID=PR.stackSetPointer(h.Figure,'watch');
h.DeleteNode;
PR.stackRemovePointer(h.Figure,ptrID);


function i_moveup(~, ~, h)
PR=xregGui.PointerRepository;
ptrID=PR.stackSetPointer(h.Figure,'watch');
h.LevelUp;
PR.stackRemovePointer(h.Figure,ptrID);


function iSelectNode(~,evd,h)

new = evd.Data.NewNode;
% now select node
SelectNode(h,new);

function iEditNode(t,e,h)
% Label Event
newstring=e.Data.NewName;
if ~isempty(strtrim(newstring))
    p = e.Data.Node;
    oldname = p.name;
    p.name(newstring);
    newname = p.name;
    if ~strcmp(newname, newstring)
        % Name was rejected by node: revert to old name
        p.name(oldname);
        wb = errordlg(sprintf(['Cannot rename %s: an item with the name %s' ...
            ' already exists.  Specify a different name.'], oldname,newstring), ...
            'Error Renaming Item', 'modal');
        waitfor(wb);
        t.update(p);
    else
        h.doDrawText;
    end
end

function iDeleteNode(~,~,h)
% Delete
h.DeleteNode;


function iInsertNode(~,~,h)

p = h.CurrentNode;
MB = p.MBsupport;
if MB.newmodel
    h.NewNode;
end

function iTreePopup(t,evt,h)

h.opencontext(t,evt.Data.Position(1),evt.Data.Position(2));


function iListKeyEvent(~,evt,h)
%iListKeyEvent react to key events in list

if ~evt.data.Modifiers
    switch evt.data.KeyCode
        case mbcgui.util.KeyCode.DELETE
            % delete key
            p = h.CurrentNode;
            if ~isnull(p)
                p_delete = p.children(evt.data.Rows);
                h.DeleteNode(p_delete);
            end
        case mbcgui.util.KeyCode.INSERT
            % insert key
            p = h.CurrentNode;
            if ~isnull(p)
                MB = p.MBsupport;
                if MB.newmodel
                    h.NewNode;
                end
            end
    end
end

function iListActionEvent(list,~,h)

rows = list.getSelectedRows;
if ~isnull(h.CurrentNode) && isscalar(rows)
    PR=xregGui.PointerRepository;
    ptrID=PR.stackSetPointer(h.Figure,'watch');
    p = h.CurrentNode.children(rows);
    if ~isempty(p)
        h.SelectNode(p);
    end
    PR.stackRemovePointer(h.Figure,ptrID);
end

function lyt = createBrowserViews(h,ViewParent,mbprefs)
%createBrowserViews create browser page
%   All Models | titlebar
%   Tree       | View
%              | List

% Panel that views appear in
h.Hand.Figure.ViewPanel = mbcgui.container.layoutpanel(...
    'Parent', ViewParent,...
    'BorderType', 'beveledin');

% Title Bar for main panel
hTitlePanel= mbcgui.container.layoutpanel(...
    'Parent', h.Hand.Figure.ViewPanel,...
    'BorderType', 'beveledout', ...
    'LayoutBorder', [5 0 0 0]);
h.Hand.Figure.Text(2)=mbcgui.widget.Label('Parent',hTitlePanel,...
    'FontSize',10,...
    'HorizontalAlignment','left');
h.Hand.Figure.IconIm=mbcgui.widget.Image('Parent',hTitlePanel);

grd=xreggridbaglayout(hTitlePanel,...
   'packgroup', 'MB_MAINGROUP',...
   'packstatus', 'off', ...
   'dimension',[3 2],...
   'rowsizes',[-1 16 -1],...
   'colsizes',[16 -1],...
   'gapx',5,...
   'mergeblock',{[1 3],[2 2]},...
   'elements',{[],h.Hand.Figure.IconIm,[],h.Hand.Figure.Text(2)});
set(hTitlePanel, 'LayoutComponent', {grd});

% tree panel on LHS
treePanel = mbcgui.container.layoutpanel(...
    'Parent', ViewParent, ...
    'BorderType', 'beveledin');
% Title Bar for model tree
hTreeTitle= mbcgui.container.layoutpanel(...
    'Parent', treePanel,...
    'BorderType', 'beveledout', ...
    'LayoutBorder', [5 0 0 0]);
h.Hand.Figure.Text(1)=mbcgui.widget.Label('Parent',hTreeTitle,...
    'UseTooltip', false, ...
    'FontSize',10,...
    'HorizontalAlignment','left',...
    'String','All Models');
set(hTreeTitle, 'LayoutComponent', {h.Hand.Figure.Text(1)});

% Make TreeView Control
CallBacks = {'SelectionChangedCallback', {@iSelectNode,h},...
    'TreeEditedCallback', {@iEditNode,h},...
    'DeletePressedCallback', {@iDeleteNode,h},...
    'InsertPressedCallback', {@iInsertNode,h},...
    'TreePopupCallback',{@iTreePopup,h}};
h.Hand.Figure.TreeView= h.RootNode.treeview('create',...
   [1 1 20 20],...
   treePanel,CallBacks,4);
Bleft=xreggridlayout(treePanel,...
   'correctalg','on',...
   'dimension',[2 1],...
   'rowsizes',[20 -1],...
   'elements',{hTreeTitle,h.Hand.Figure.TreeView},...
   'packgroup','MB_MAINGROUP');
set(treePanel, 'LayoutComponent', {Bleft});

% List view
listPanel = mbcgui.container.layoutpanel(...
    'Parent', h.Hand.Figure.ViewPanel, ...
    'BorderType', 'beveledin');

hListTitle= mbcgui.container.layoutpanel(...
    'Parent', listPanel,...
    'BorderType', 'beveledout', ...
    'LayoutBorder', [5 0 0 0]);
h.Hand.Figure.ListText=mbcgui.widget.Label('Parent',hListTitle,...
    'FontSize',10,...
    'HorizontalAlignment','left');
h.Hand.Figure.ChildImage=mbcgui.widget.Image('Parent',hListTitle);
grd=xreggridbaglayout(hListTitle,...
   'packgroup', 'MB_MAINGROUP',...
   'packstatus', 'off', ...
   'dimension',[3 2],...
   'rowsizes',[-1 16 -1],...
   'colsizes',[16 -1],...
   'gapx',5,...
   'mergeblock',{[1 3],[2 2]},...
   'elements',{[],h.Hand.Figure.ChildImage,[],h.Hand.Figure.ListText});
set(hListTitle, 'LayoutComponent', {grd});

h.Hand.Figure.ListPanel = listPanel;
CallBacks= {'ActionPerformedCallback',{@iListActionEvent,h},...
        'KeyTypedCallback',{@iListKeyEvent,h}};
h.Hand.Figure.ListView= listview(h.RootNode.info,...
    [1 1 20 20],...
    listPanel,CallBacks,h.Hand.Figure.TreeView);
h.ListView = h.Hand.Figure.ListView;

h.Hand.Figure.BestMdlTxt=uicontrol('Parent',listPanel,...
   'Style','text',...
   'Enable','inactive',...
   'String','',...
   'HorizontalAlignment','left');

listGrid = xreggridbaglayout(listPanel, ...
    'packgroup','MB_MAINGROUP',...
    'dimension', [3 1], ...
    'rowsizes', [-1 21,3], ...
    'elements', {h.Hand.Figure.ListView, h.Hand.Figure.BestMdlTxt,[]});
ListView = xreggridbaglayout(listPanel, ...
    'packgroup','MB_MAINGROUP',...
    'dimension', [2 1], ...
    'rowsizes', [20 -1], ...
    'elements', {hListTitle,listGrid});
set(listPanel, 'LayoutComponent', {ListView});


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%    Assemble Layouts    %%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

h.ViewCardObj= xregcardlayout(h.Hand.Figure.ViewPanel,...
    'numcards',1,...
   'packgroup', 'MB_MAINGROUP');

spLyt= xregsnapsplitlayout(h.Hand.Figure.ViewPanel,...
    'packgroup', 'MB_MAINGROUP',...
    'orientation','ud',...
    'barstyle', 1,...
    'bottom',listPanel,...
    'top',h.ViewCardObj,...
    'minwidth',[435,150],...
    'split',[0.98,0.02],...
    'style','tobottom');

% add titlebar 
ViewLyt = xreggridbaglayout(h.Hand.Figure.ViewPanel, ...
    'packgroup','MB_MAINGROUP',...
    'dimension', [2 1], ...
    'rowsizes', [20 -1], ...
    'elements', {hTitlePanel,spLyt}); 

set(h.Hand.Figure.ViewPanel, 'LayoutComponent', {ViewLyt});

h.Hand.Figure.UDsplit=spLyt;
h.Hand.Figure.LRsplit= xregsplitlayout(ViewParent,...
    'packgroup', 'MB_MAINGROUP',...
    'orientation','lr',...
    'minwidthunits','pixels',...
    'minwidth',[120 680],...
    'left',treePanel,...
    'right',h.Hand.Figure.ViewPanel,...
    'split',mbprefs.TreeSplit,...
    'dividerstyle','flat',...
    'dividerwidth',4);
lyt = h.Hand.Figure.LRsplit;

function data = createFirstView(h)
% Create the structure for sub-view data etc
View.Data=xregGui.RunTimePointer;
View.Data.LinkToObject(h.Figure);
View.GUIDs={};
View.ToolsMenus=[];
View.ViewMenus=[];
View.Current=1;

h.GUIExists=true;

% Create First View here (call create on testplan)
View.GUIDs(1)= {h.RootNode.guid};
info.ViewIndex= 1;
info.Figure= h.Figure;
info.ViewParent = h.Hand.Figure.ViewPanel;
info.ToolbarParent = h.Hand.Toolbar.Panel;

h.ViewData=View.Data;
h.ViewGUIDs=View.GUIDs;
h.ViewMenus={[]};
h.ViewCurrent=View.Current;

[lyt, tblyt, data]= creategui(h.RootNode.info, info);
attach(h.ViewCardObj, lyt, 1);

attach(h.Hand.Toolbar.CardObj, tblyt, 1);
Nnew=length(h.ViewMenus{1});
set([h.ViewMenus{1} ],...
   {'Visible'}, repmat({'on'},Nnew,1),...
   {'Position'}, num2cell((2:1+Nnew)'));


data=h.RootNode.show(h,data);
data=h.RootNode.view(h,data);
h.ViewData(1).info=data;


function onHome(~,~,h)
% select home page

selectHome(h,1);