主要内容

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

find

使用查询查找架构模型元素

说明

[paths] = find(model,constraint,Name=Value) 查找从模型根架构开始的、满足 constraint 查询条件的所有元素路径,并通过一个或多个名称-值参量指定附加选项。

示例

[paths, elements] = find(___) 返回满足 constraint 查询的组件元素 elements 及其 paths。输入参量的语法如上。如果没有提供 rootArch,则函数会在模型的根架构中查找模型元素。输出参量 paths 包含 elements 中每个组件从给定根架构出发的完全限定命名路径。

示例

[elements] = find(___) 查找满足 constraint 查询条件的所有组件、端口或连接器元素 elements,以及由一个或多个名称-值参量指定的附加选项,这些参量必须包括 'Port''Connector' 以用于 'ElementType'

示例

[paths] = find(model,constraint,rootArch,Name=Value) 查找从指定根架构 rootArch 开始的、满足 constraint 查询条件的所有元素路径,并通过一个或多个名称-值参量指定附加选项。

示例

示例

全部折叠

导入模型并运行查询,根据指定的子约束选择具有构造型的架构元素。

import systemcomposer.query.*;
scKeylessEntrySystem
modelObj = systemcomposer.openModel("KeylessEntryArchitecture");
find(modelObj,HasStereotype(IsStereotypeDerivedFrom("AutoProfile.BaseComponent")),...
 Recurse=true,IncludeReferenceModels=true)

创建一个查询,查找在 Name 属性中包含字母 c 的组件。

constraint = contains(systemcomposer.query.Property("Name"),"c");
find(modelObj,constraint,Recurse=true,IncludeReferenceModels=true)

根据 System Composer™ 查询查找架构模型中的元素。

创建模型

创建一个包含两个组件的架构模型。

m = systemcomposer.createModel("exModel");
comps = m.Architecture.addComponent(["c1","c2"]);

创建配置文件和构造型

为架构模型创建配置文件和构造型。

pf = systemcomposer.profile.Profile.createProfile("mProfile");
b = pf.addStereotype("BaseComp",AppliesTo="Component",Abstract=true);
s = pf.addStereotype("sComp",Parent=b);

应用配置文件和构造型

在架构模型中应用配置文件和构造型。

m.Architecture.applyProfile(pf.Name)
comps(1).applyStereotype(s.FullyQualifiedName)

查找元素

根据查询在架构模型中查找元素。

import systemcomposer.query.*
[p, elem] = find(m, HasStereotype(IsStereotypeDerivedFrom("mProfile.BaseComp")),...
Recurse=true,IncludeReferenceModels=true)
p = 1×1 cell array
    {'exModel/c1'}

elem = 
  Component with properties:

     IsAdapterComponent: 0
           Architecture: [1×1 systemcomposer.arch.Architecture]
                   Name: 'c1'
                 Parent: [1×1 systemcomposer.arch.Architecture]
                  Ports: [0×0 systemcomposer.arch.ComponentPort]
             OwnedPorts: [0×0 systemcomposer.arch.ComponentPort]
      OwnedArchitecture: [1×1 systemcomposer.arch.Architecture]
             Parameters: [0×0 systemcomposer.arch.Parameter]
               Position: [15 15 135 115]
                  Model: [1×1 systemcomposer.arch.Model]
         SimulinkHandle: 151.0626
    SimulinkModelHandle: 149.1050
                   UUID: '5502ff5b-d92a-40ef-a60d-0acafe3f3c50'
            ExternalUID: ''

清理

移除模型和配置文件。

cleanUpFindElementsInModel

创建一个用于查询的模型,并创建两个组件。

m = systemcomposer.createModel("exModel");
comps = m.Architecture.addComponent(["c1","c2"]);
port = comps(1).Architecture.addPort("cport1","in");

创建一个查询,查找在 Name 属性中包含字母 c 的端口。

constraint = contains(systemcomposer.query.Property("Name"),"c");
find(m,constraint,Recurse=true,IncludeReferenceModels=true,ElementType="Port")
import systemcomposer.query.*;
scKeylessEntrySystem
modelObj = systemcomposer.openModel("KeylessEntryArchitecture");
find(modelObj,HasStereotype(IsStereotypeDerivedFrom("AutoProfile.BaseComponent")),...
 modelObj.Architecture,Recurse=true,IncludeReferenceModels=true)

输入参数

全部折叠

架构模型,指定为 systemcomposer.arch.Model 对象。

查询,指定为代表特定条件的 systemcomposer.query.Constraint 对象。

一个约束可以包含一个子约束,该子约束可以使用 ANDOR 与另一个约束连接。可以使用 NOT 否定约束。

查询对象和约束条件

查询对象条件
Property给定属性或构造型属性的非计算值。
PropertyValue来自 System Composer™ 对象或构造型属性的已计算属性值。
HasConnector组件具有满足给定子约束条件的连接器。
HasPort组件的端口满足给定的子约束条件。
HasInterface端口有满足给定子约束条件的接口。
HasInterfaceElement一个接口有一个满足给定子约束条件的接口元素。
HasStereotype架构元素具有满足给定子约束条件的构造型。
IsInRange属性值在给定范围内。
AnyComponent元素是一个组件,而不是端口或连接器。
IsStereotypeDerivedFrom 构造型是从给定的构造型中派生出来的。

模型的根架构,指定为 systemcomposer.arch.Architecture 对象或 systemcomposer.arch.Model 对象的 Architecture 属性。

示例: modelObj.Architecture

名称-值参数

全部折叠

将可选参量对组指定为 Name1=Value1,...,NameN=ValueN,其中 Name 是参量名称,Value 是对应的值。名称-值参量必须出现在其他参量之后,但对各个参量对组的顺序没有要求。

在 R2021a 之前,需使用逗号分隔每个名称和值,并用引号将 Name 引起来

示例: find(model,constraint,Recurse=true,IncludeReferenceModels=true)

递归搜索模型或仅搜索特定图层的选项,指定为 1 (true) 表示递归搜索或 0 (false) 表示仅搜索特定图层。

示例: find(model,constraint,Recurse=true)

数据类型: logical

搜索引用架构的选项,指定为 1 (true) 或 0 (false)。

示例: find(model,constraint,IncludeReferenceModels=true)

数据类型: logical

按类型搜索的选项,指定为以下类型之一

  • "Component" 以查找满足查询的组件

  • "Port" 以查找满足查询的端口

  • "Connector' 以找到满足查询的连接器

示例: find(model,constraint,ElementType="Port")

数据类型: char | string

输出参量

全部折叠

元素路径,以满足 constraint 的字符向量元胞数组形式返回。

数据类型: char

元素,以满足 constraintsystemcomposer.arch.Element 对象形式返回。

详细信息

全部折叠

版本历史记录

在 R2019a 中推出