主要内容

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

slmetric.dashboard.Group 类

命名空间: slmetric.dashboard

(待移除)度量板上用于存放 slmetric.dashboard.Containerslmetric.dashboard.Widgetslmetric.dashboard.CustomWidget 对象的组件

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

描述

slmetric.dashboard.Group 对象可以包含 slmetric.dashboard.Containerslmetric.dashboard.Widgetslmetric.dashboard.CustomWidget 对象。您可以使用 slmetric.dashboard.Group 方法和属性来指定组的大小、宽度和标题。

例如,下图是默认的度量板布局。度量仪表板的这部分包含一个标题为 Sizeslmetric.dashboard.Group 小组件。此组包含三个 slmetric.dashboard.Container 小组件。左侧和右侧的容器每个都包含一个 slmetric.dashboard.Widget 对象。中间的容器包含两个 slmetric.dashboard.Widget 对象。

Size metrics in the default Metrics Dashboard layout

构造

group = slmetric.dashboard.Group 创建 slmetric.dashboard.Group 对象的句柄。

属性

全部展开

为一组 slmetric.dashboard.Widgetslmetric.dashboard.CustomWidget 对象指定标题。标题必须概括该组中组件的类型。例如,标题为 Size 的组包含与模型尺寸相关的组件。此属性是可读取/写入的。

此组件类型为组。此属性是只读的。

如果为 true,则在度量仪表板中 slmetric.dashboard.Group 对象的周围有一个边框。此属性是可读取/写入的。

方法

addWidget(即将删除)向 slmetric.dashboard.Group 对象中添加小组件
getMargin(即将删除)获取从组边缘到内容的距离
getPosition(即将删除)获取度量仪表板中组的位置
getSeparators(待删除)确定“度量仪表板”组的侧边是否有线条
getWidgets(即将删除)获取 slmetric.dashboard.Group 对象中小组件的列表
getWidths(待移除)获取度量仪表板组的宽度
removeWidget(即将删除)从 slmetric.dashboard.Group 对象中删除小组件
setMargin(即将删除)指定从组边缘到其内容的距离
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 中推出

全部折叠