⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bvqxfigure.m

📁 toolbox of BVQX, This is the access between BV and matlab. It will help you to analysis data from BV
💻 M
📖 第 1 页 / 共 5 页
字号:
    % check if its yet a filename
    if any(tchar == filesep | tchar == '.') && ...
       ~isrealvarname(tchar)
        error( ...
            'BVQXfigure:FileNotFound', ...
            'The figure file (%s) was not found or bad varname.', ...
            tchar ...
        );
    end
    
    % try object lookups in Tag table, iterate over lookup types
    hFigure = [];
    for olc = 1:numel(bvqxfigure_factory.objtlup)
        tTag = [bvqxfigure_factory.objtlup{olc} tchar];
        
        % is field in tag list
        if isfield(bvqxfigure_factory.tags, tTag)
            
            % get reference
            hFigure = bvqxfigure_factory.tags.(tTag);
            break;
        end
    end
    
    % error if lookup failed
    if numel(hFigure) ~= 1 || ...
      ~isBVQXfigure(hFigure, 1)
        error( ...
            'BVQXfigure:LookupFailed', ...
            'Error looking up BVQXfigure object (%s).', ...
            tchar ...
        )
    end
    
    % set other field and re-set varargin{1}
    varargin{1} = hFigure;
    
% other input type
else
    error( ...
        'BVQXfigure:BadArgument', ...
        'Invalid input argument class: %s.', ...
        class(varargin{1}) ...
    );
end

% if nothing else to do return
if nargin < 2
    varargout{1} = varargin{1};
    return;
end

% invalid action
if ~ischar(varargin{2}) || ...
    isempty(varargin{2})
    error( ...
        'BVQXfigure:CallingConvention', ...
        'Calling convention misfit.' ...
    );
end

% object field shortcuts
hFigIHnd = hFigure.ihnd;
hFigMHnd = hFigure.mhnd;
hFigType = hFigure.type;

% remainder of arguments
action = lower(varargin{2}(:)');
if nargin > 2
    iStr = varargin{3};
else
    iStr = [];
end

% do initial lookups and fill more internal script vars
% * ihPos  = matrix position for input object
% * ihFPos = matrix position of parent figure
ihPos  = find(bvqxfig_ilup == hFigIHnd);
ihFPos = [];
if isempty(ihPos)
    error( ...
        'BVQXfigure:LookupFailed', ...
        'Internal handle disappeared from array. Memory glitch?' ...
    );
end

% * iObj   = object properties as struct
% * iFObj  = object properties of parent figure
iObj       = bvqxfigures(ihPos);
iFObj      = [];

% figure object
switch (hFigType), case {1}
    ihFPos = ihPos;
    iFObj  = iObj;
    mygcf  = hFigMHnd;
    
% non-root objects
case {2, 3, 4}
    
    % try to find parent figure
    mygcf  = findmlparent(hFigMHnd, 'figure');
    ihFPos = find(bvqxfig_mlup == mygcf);
    if isempty(ihFPos)
        error( ...
            'BVQXfigure:LookupFailed', ...
            'Parent figure of BVQXfigure object not in lookup matrix.' ...
        );
    end
    iFObj = bvqxfigures(ihFPos);
    
% test for root otherwise
otherwise
    if hFigType
        error( ...
            'BVQXfigure:BadObject', ...
            'Unknown object type %d.', ...
            hFigType ...
        );
    end
    mygcf = [];
end

% finally, also set mygcbf to mygcf
mygcbf = mygcf;


% ____ process the requested action ____


% switch over action
switch (action)


% adding a string (routed via multistring)
case {'addstring'}
    
    % only valid for dropdown or listbox uicontrols
    if hFigType ~= bvqxfigure_factory.objtypes.uicontrol || ...
       ~any(strcmpi(iObj.props.Style, {'popupmenu', 'listbox'}))
        error( ...
            'BVQXfigure:InvalidObjectType', ...
            'AddString is only valid for DropDown or ListBox UIControls.' ...
        );
    end
    
    % only accept valid insertions
    if ~ischar(iStr) && ...
       ~iscell(iStr)
        error( ...
            'BVQXfigure:BadArgument', ...
            'AddString requires a CHAR or CELL argument to add.' ...
        );
    end
    
    % positional argument given
    if nargin < 4
        if ischar(iStr)
            pos = ones(1, size(iStr, 1)) * Inf;
        else
            pos = ones(1, numel(iStr)) * Inf;
        end
    else
        pos = varargin{4}(:)';
    end
    
    % route through MultiString method
    try
        BVQXfigure(hFigure, 'multistring', pos, iStr, 1);
    catch
        rethrow(lasterror);
    end
    
    
% adding a uicontextmenu
case {'adduicontextmenu'}
    
    % only valid for figure and uipanel objects
    if hFigType ~= bvqxfigure_factory.objtypes.figure
        error( ...
            'BVQXfigure:InvalidObjectType', ...
            'Only figures can be parents of uicontextmenus.' ...
        );
    end
    
    % test iStr
    if ~isstruct(iStr)
        error( ...
            'BVQXfigure:BadPropertyStruct', ...
            'Uicontextmenu properties must be of type struct.' ...
        );
    end
    
    % perform some checks on struct
    iStr = checkstruct(iStr, bvqxfigure_factory.optuix);
    
    % get new OUID
    uuid = handlenew(bvqxfigure_factory.objtypes.uicontextmenu, bvqxfig_ilup);
    dfcn = sprintf('BVQXfigure(%0.0f,''Delete'');', uuid);
    
    % use tag from iStr?
    if ~isempty(iStr.Tag) && ...
        numel(iStr.Tag) < 28 && ...
        isrealvarname(iStr.Tag(:)')
        utag = iStr.Tag(:)';
    else
        iStr.Tag = sprintf('UIX_%010.0f', uuid);
        utag = ['BVQXfigure_' iStr.Tag];
    end
    
    % prepare struct for call
    oStr = struct( ...
        'Parent',        hFigMHnd, ...
        'Callback',      iStr.Callback, ...
        'DeleteFcn',     dfcn, ...
        'Interruptible', iStr.Interrupts, ...
        'Tag',           utag, ...
        'UserData',      iStr.UserData);
    
    % create object and fill/update fields as necessary
    hOut = uicontextmenu(oStr);
    cout = makeobj(uuid, hOut, bvqxfigure_factory.objtypes.uicontextmenu);
    oStr.MLHandle = hOut;
    try
        set(hFigMHnd, 'UIContextMenu', []);
    catch
        % do nothing
    end
    
    % complete object representation
    oObj = makeostruct(bvqxfigure_factory.objtypes.uicontextmenu);
    oObj.callbacks = {'', '', '', iStr.CallbackDelete};
    oObj.loadprops = iStr;
    oObj.prevprops = get(hOut);
    bvqxfig_ilup(end + 1) = uuid;
    bvqxfig_mlup(end + 1) = hOut;
    bvqxfig_type(end + 1) = cout.type;
    bvqxfigures(end + 1)  = oObj;
    
    % finally, add to global tag lookup struct
    bvqxfigure_factory.tags.(['UIX_' iStr.Tag]) = cout;
    
    % and return appropriate object
    varargout{1} = cout;
    
    
% adding a uicontrol object
case {'adduicontrol'}
    
    % only valid for figure and uipanel objects
    if hFigType ~= bvqxfigure_factory.objtypes.figure
        error( ...
            'BVQXfigure:InvalidObjectType', ...
            'Only figures can be parents of uicontrols.' ...
        );
    end
    
    % test iStr
    if ~isstruct(iStr)
        error( ...
            'BVQXfigure:BadPropertyStruct', ...
            'Uicontrol properties must be of type struct.' ...
        );
    end
    
    % perform some checks on struct
    iStr = checkstruct(iStr, bvqxfigure_factory.optuic);
    if isempty(iStr.Type) || ...
       ~isfield(bvqxfigure_factory.uictypes, lower(iStr.Type)) || ...
       ~isnumeric(iStr.Position) || ...
        isempty(iStr.Position) || ...
        numel(iStr.Position) ~= 4
        error( ...
            'BVQXfigure:BadPropertyStruct', ...
            'Bad uicontrol property struct supplied.' ...
        );
    end
    
    % get new OUID
    uuid = handlenew(bvqxfigure_factory.objtypes.uicontrol, bvqxfig_ilup);
    dfcn = sprintf('BVQXfigure(%0.0f,''Delete'');', uuid);
    
    % use tag from iStr?
    if ~isempty(iStr.Tag) && ...
        numel(iStr.Tag) < 28 && ...
        isrealvarname(iStr.Tag(:)')
        utag = iStr.Tag(:)';
    else
        iStr.Tag = sprintf('UIC_%010.0f', uuid);
        utag = ['BVQXfigure_' iStr.Tag];
    end
    
    % shortcuts to some important settings
    iCTyp = lower(iStr.Type);
    iCap  = iStr.Caption;
    iPar  = hFigMHnd;
    iPos  = iStr.Position;
    iVis  = iStr.Visible;
    
    % preset callbacks array
    iStr.Callbacks = cell(1, 4);
    if isempty(iStr.ContextMenu)
        cbclick = iStr.CallbackClick(:)';
    else
        cbclick = [ ...
            sprintf('BVQXfigure(BVQXfigure,''setcontext'',%0.0f));', uuid) ...
            iStr.CallbackClick(:)'];
    end
    
    % special type
    iRTyp = bvqxfigure_factory.uictypes.(iCTyp);
    if strcmp(iRTyp, 'BUILTIN')
        iRSpec = true;
    else
        iRSpec = false;
    end
    
    % background color
    hasBGColor = true;
    if numel(iStr.ColorBG) == 1
        iStr.ColorBG(1:3) = iStr.ColorBG;
    elseif numel(iStr.ColorBG) ~= 3
        if ~any(strcmpi(iCTyp, {'label', 'radiobutton'}))
            hasBGColor   = false;
        end
        iStr.ColorBG = get(iPar, 'Color');
    end
    iCBG = max(0, min(1, iStr.ColorBG));
    
    % foreground color
    hasFGColor = true;
    if numel(iStr.ColorFG) == 1
        iStr.ColorFG(1:3) = iStr.ColorFG;
    elseif numel(iStr.ColorFG) ~= 3
        hasFGColor   = false;
        iStr.ColorFG = [0 0 0];
    end
    iCFG = max(0, min(1, iStr.ColorFG));
    
    % fontsize
    if ischar(iStr.FontSize) && ...
       ~isempty(iStr.FontSize) && ...
        isfield(bvqxfigure_factory.fntsizes, iStr.FontSize(:)')
        iStr.FontSize = bvqxfigure_factory.fntsizes.(iStr.FontSize(:)');
    elseif ~isnumeric(iStr.FontSize) || ...
        numel(iStr.FontSize) ~= 1
        iStr.FontSize = 10;
    end
    
    % sliderstep
    if ~any(strcmp(iCTyp, {'slider', 'xprogress'})) || ...
        numel(iStr.SliderStep) < 2
        iStr.SliderStep = [];
    else
        iStr.SliderStep = iStr.SliderStep(1:2);
    end
    
    % special type requested ? 
    xchildren = [];
    if iRSpec
        
        % set default axes struct
        oStr = struct( ...
            'Parent',        iPar, ...
            'Units',         iStr.Units, ...
            'Position',      iPos, ...
            'ButtonDownFcn', cbclick, ...
            'Color',         'none', ...
            'DeleteFcn',     dfcn, ...
            'Tag',           utag, ...

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -