主要内容

本页采用了机器翻译。点击此处可查看英文原文。

getWidgets

类: slmetric.dashboard.Group
命名空间: slmetric.dashboard

(即将删除)获取 slmetric.dashboard.Group 对象中小组件的列表

以后的版本中将会删除度量仪表板用户界面、metricdashboard 函数、slmetric 包 API 以及相应的自定义项。有关详细信息,请参阅从度量盘迁移到模型可维护性仪表盘

说明

groupList = getWidgets(group) 创建一个由 slmetric.dashboard.Group 对象中的对象组成的数组。这些对象是以下类型的小组件:

  • slmetric.dashboard.Container

  • slmetric.dashboard.CustomWidget

  • slmetric.dashboard.Widget

使用 getWidgets 方法来标识 slmetric.dashboard.Group 对象中您要修改或删除的小组件。

输入参数

全部展开

您要获取其小组件列表的 slmetric.dashboard.Group 对象。

输出参量

全部展开

slmetric.dashboard.Group 对象中的控件对象数组。

示例

全部展开

创建一个自定义度量,用于统计非虚拟块的数量。指定一个组件,在度量仪表板上显示此度量。将其添加到大小组。

通过输入以下命令打开模型 vdp

openExample('simulink_general/VanDerPolOscillatorExample')

创建自定义度量类。

className = 'nonvirtualblockcount';
slmetric.metric.createNewMetricClass(className);

通过将此代码添加到 nonvirtualblockcount.m 文件中来创建非虚拟模块计数度量。

classdef nonvirtualblockcount < slmetric.metric.Metric
    %nonvirtualblockcount calculates number of nonvirtual blocks per level.
    % BusCreator, BusSelector and BusAssign are treated as nonvirtual.
    properties
        VirtualBlockTypes = {'Demux','From','Goto','Ground', ...
            'GotoTagVisibility','Mux','SignalSpecification', ...
            'Terminator','Inport'};
    end
    
    methods
    function this = nonvirtualblockcount()
        this.ID = 'nonvirtualblockcount';
        this.Name = 'Nonvirtual Block Count';
        this.Version = 1;
        this.CompileContext = 'None';
        this.Description = 'Algorithm that counts nonvirtual blocks per level.';
        this.AggregatedValueName = 'Nonvirtual Blocks (incl. Descendants)'
        this.ValueName = 'Nonvirtual Blocks'
        this.ComponentScope = [Advisor.component.Types.Model, ...
            Advisor.component.Types.SubSystem];
        this.AggregationMode = slmetric.AggregationMode.Sum;
        this.ResultChecksumCoverage = true;
        this.SupportsResultDetails = true;
            
    end

    function res = algorithm(this, component)
        % create a result object for this component
        res = slmetric.metric.Result();	

        % set the component and metric ID
        res.ComponentID = component.ID;
        res.MetricID = this.ID;
        
        % Practice
        D1=slmetric.metric.ResultDetail('identifier 1','Name 1');
        D1.Value=0;
        D1.setGroup('Group1','Group1Name');
        D2=slmetric.metric.ResultDetail('identifier 2','Name 2');
        D2.Value=1;
        D2.setGroup('Group1','Group1Name');
        
        

        % use find_system to get all blocks inside this component
        blocks = find_system(getPath(component), ...
            'SearchDepth', 1, ...
            'Type', 'Block');

        isNonVirtual = true(size(blocks));

        for n=1:length(blocks)
            blockType = get_param(blocks{n}, 'BlockType');

            if any(strcmp(this.VirtualBlockTypes, blockType))
                isNonVirtual(n) = false;
            else
                switch blockType
                    case 'SubSystem'
                        % Virtual unless the block is conditionally executed
                        % or the Treat as atomic unit check box is selected.
                        if strcmp(get_param(blocks{n}, 'IsSubSystemVirtual'), ...
                                'on')
                            isNonVirtual(n) = false;
                        end
                    case 'Outport'
                        % Outport: Virtual when the block resides within
                        % SubSystem block (conditional or not), and 
                        % does not reside in the root (top-level) Simulink window.
                        if component.Type ~= Advisor.component.Types.Model
                            isNonVirtual(n) = false;
                        end
                    case 'Selector'
                        % Virtual only when Number of input dimensions 
                        % specifies 1 and Index Option specifies Select 
                        % all, Index vector (dialog), or Starting index (dialog).
                        nod = get_param(blocks{n}, 'NumberOfDimensions');
                        ios = get_param(blocks{n}, 'IndexOptionArray');

                        ios_settings = {'Assign all', 'Index vector (dialog)', ...
                            'Starting index (dialog)'};

                        if nod == 1 && any(strcmp(ios_settings, ios))
                            isNonVirtual(n) = false;
                        end
                    case 'Trigger'
                        % Virtual when the output port is not present.
                        if strcmp(get_param(blocks{n}, 'ShowOutputPort'), 'off')
                            isNonVirtual(n) = false;
                        end
                    case 'Enable'
                        % Virtual unless connected directly to an Outport block.
                        isNonVirtual(n) = false;

                        if strcmp(get_param(blocks{n}, 'ShowOutputPort'), 'on')
                            pc = get_param(blocks{n}, 'PortConnectivity');

                            if ~isempty(pc.DstBlock) && ...
                                    strcmp(get_param(pc.DstBlock, 'BlockType'), ...
                                    'Outport')
                                isNonVirtual(n) = true;
                            end
                        end
                end
            end
        end

        blocks = blocks(isNonVirtual);

        res.Value = length(blocks);
    end
    end
end

在度量库中注册新度量。

[id_metric,err_msg] = slmetric.metric.registerMetric(className);

首先,打开度量仪表板布局的默认配置。

conf = slmetric.dashboard.Configuration.open();

slmetric.dashboard.Configuration 对象中获取 slmetric.dashboard.Layout 对象。

layout = getDashboardLayout(conf);

获取布局对象中的控件对象。

layoutWidget = getWidgets(layout);

移除代表 Simulink 模块计数度量的小组件。

sizeGroup = layoutWidget(2); 
sizeGroupWidgets = sizeGroup.getWidgets(); 
sizeGroup.removeWidget(sizeGroupWidgets(1));

添加一个显示非虚拟模块计数度量的小组件。对于自定义小组件,默认可视化类型为单值。如果要使用不同的可视化技术,请为 VisualizationType 属性指定不同的值。

newWidget = sizeGroup.addWidget('Custom', 1);
newWidget.Title = ('Nonvirtual Block Count'); 
newWidget.setMetricIDs('nonvirtualblockcount');
newWidget.setWidths(slmetric.dashboard.Width.Medium);
newWidget.setHeight(70);

指定自定义小组件与组中其他小组件之间是否有分隔线。这些命令指定在小组件右侧有一条线。

s.top = false;
s.bottom = false;
s.left = false;
s.right = true;
newWidget.setSeparators([s, s, s, s]);

保存配置对象。此命令将 API 信息序列化为 XML 文件。

save(conf,'Filename','DashboardConfig.xml');

设置活动配置。

slmetric.dashboard.setActiveConfiguration(fullfile(pwd,'DashboardConfig.xml'));

打开模型 vdp 的度量仪表板。

metricsdashboard vdp

点击所有度量按钮以运行所有度量。

版本历史记录

在 R2018b 中推出

全部折叠