主要内容

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

slmetric.dashboard.CustomWidget 类

命名空间: slmetric.dashboard

(待移除)用于保存自定义度量仪表板小组件的对象

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

描述

对于自定义指标或已交付的度量,请使用 slmetric.dashboard.CustomWidget 对象在度量仪表板中可视化度量数据。选择单值、径向仪表、条形图或分布热图方法。

构造

对于 slmetric.dashboard.Layoutslmetric.dashboard.Containerslmetric.dashboard.Group 对象,可以使用 addWidgetremoveWidget 方法从度量仪表板中添加或删除 slmetric.dashboard.CustomWidget 对象。

度量仪表板布局划分为 12 个大小相等的列。使用 slmetric.dashboard.CustomWidget 方法指定控件大小。

要指定小组件显示的度量数据,请使用 setMetricIDs 方法为小组件分配度量 ID。自定义小组件会自动缩放以适应您指定的度量 ID 数量。例如,如果您创建一个自定义条形图小组件并指定两个度量 ID,则条形图小组件将在条形图中用两个条形来显示度量结果。

属性

全部展开

要在度量仪表板中添加、删除或修改的 slmetric.dashboard.CustomWidget 对象类型。此属性是可读取/写入的。请从以下组件类型中选择:

  • 条形图

  • 单个值

  • 径向仪表

  • 分布热图

Examples of each widget type

有关如何使用不同可视化类型的示例,请参阅 创建带有自定义度量的布局

数据类型: char

为自定义小组件添加标签。此属性仅适用于 BarChart VisualizationType 属性,因此您可以为每个单独的条形添加标签。此属性是可读取/写入的。

数据类型: char

为自定义小组件指定标题。对于径向量规,字符数限制为 16 个。此属性是可读取/写入的。

数据类型: char

slmetric.dashboard.CustomWidget 对象的类型。此属性是只读的。

数据类型: char

方法

getHeight(待移除)获取度量仪表板自定义小组件的高度
getMetricIDs(待移除)获取自定义度量仪表板小组件的度量标识符
getPosition(待移除)获取度量板中的自定义小组件位置
getSeparators(待移除)确定度量仪表板自定义小组件两侧是否存在线条。
getWidths(待移除)获取度量仪表板自定义小组件的宽度
setHeight(待移除)指定度量仪表板自定义小组件的高度
setMetricIDs(待移除)设置自定义度量仪表板小组件的度量标识符
setPosition(待移除)在度量板中设置自定义小组件位置
setSeparators(待移除)在度量仪表板自定义小组件侧面指定线条
setWidths(待移除)为度量仪表板自定义小组件指定多种宽度

示例

全部折叠

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

通过输入以下命令打开模型 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 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 中推出

全部折叠