www.gusucode.com > mbcview 工具箱matlab源码程序 > mbcview/@cgfeaturenode/private/pGetFeatureLibraries.m

    function libraries = pGetFeatureLibraries
%PGETFEATURELIBRARIES Return information about Simulink libraries
%
%  LIB_INFO = PGETFEATURELIBRARIES

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


persistent library_store;

% return the persistent copy
if ~isempty(library_store)
    libraries = library_store;
    return;
end

% the default libraries
libraries(1,1:3) = {'&Simulink Calibration Library', iGetCalFunctions, {'separator','on'}};
libraries(2,1:3) = {'&Project Library', iGetBranchFunctions, {}};

% get the extensions
ext=mbcextensions.Extensions.Cage;
exlibraries = ext.cgFeatureLibraries;

% exlibraries is a {nx3} cell array
% {LibraryLabel, {functions}, {otherargs}}
% LibraryLabel - the label to appear on the menu
% {functions} - cell array of callbacks {@open, @close, @isopen}
%               open - function called to open the library
%               close - function called to close the library
%               isopen - function called to determine whether the library is open or not
%                        (returns 1/0)
%               All these function should accept 1 argument - the CurrentNode.
% otherargs = a cellarray of property/value pairs to pass to uimenu e.g. {'separator','on'}

libraries = [libraries; exlibraries];
library_store = libraries;

end


function Fcns = iGetCalFunctions
IsOpen = false;
Fcns = {@i_SLLibOpen, @i_SLLibClose, @i_SLLibIsOpen};

    function i_SLLibOpen(~)
        % shows the calibration library
        sys = 'cgeqlib';
        [slPos, calLibWidth] = pcalcSLPosition;
        libleft = slPos(3) + 10;
        libright = libleft + calLibWidth;
        load_system(sys);
        set_param(sys,'lock','off');
        open_system(sys);
        set_param(sys,'location',[libleft, slPos(2), libright ,slPos(4)]);
        IsOpen = true;
    end

    function i_SLLibClose(node)
        % hides the calibration library
        sys = 'cgeqlib';
        if i_SLLibIsOpen(node)
            bdclose( sys );
            IsOpen = false;
        end
    end

    function ret = i_SLLibIsOpen(~)
        % ask if the calibration library is currently open, but only if it
        % has been opened
        ret = IsOpen && ~isempty(find_system('type','block_diagram','name','cgeqlib'));
    end
end


function Fcns = iGetBranchFunctions
IsOpen = false;
Fcns = {@i_BranchLibOpen,@i_BranchLibClose, @i_BranchLibIsOpen};

    function i_BranchLibOpen(node)
        % shows the Project library
        makeProjectLibrary( node );
        IsOpen = true;
    end

    function i_BranchLibClose(node)
        % hides the Project library
        if i_BranchLibIsOpen(node)
            bdclose('CAGE_Project');
            IsOpen = false;
        end
    end

    function ret = i_BranchLibIsOpen(~)
        ret = IsOpen && ~isempty(find_system('name', 'CAGE_Project', 'type','block_diagram'));
    end
end