主要内容

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

通过编程创建架构视图

您可以通过编程创建架构视图。本主题通过示例介绍了如何使用元素组,通过编程创建无键条目系统架构的架构视图。元素组是视图中组件的组合使用元素组以编程方式填充视图。

有关视图主题的路线图,请参阅使用架构视图库创建自定义视图

有关无钥匙进入架构的更多信息,请参阅无钥匙进入系统的架构建模

第三个示例介绍如何使用查询在 System Composer™ 模型中查找元素。

查询是用来描述模型元素需满足的某些约束或准则的一种规范使用查询以通过约束准则来搜索元素并过滤视图。

提示

要了解更多关于 System Composer 概念在系统工程设计中的应用,请参阅System Composer 概念

在 System Composer 中使用无钥匙进入系统创建架构视图

使用无钥匙进入系统架构模型,以编程方式创建视图。

通过查询导入命名空间。

import systemcomposer.query.*

打开无钥匙进入系统的 Simulink® 工程文件。

openProject("scKeylessEntrySystem");

将示例模型加载到 System Composer™ 中。

model = systemcomposer.loadModel("KeylessEntryArchitecture");

硬件组件审查状态视图

创建一个视图,选择架构模型中的所有硬件组件,并使用 ReviewStatus 属性对它们进行分组。

1.构建一个查询来选择所有硬件组件。

hwCompQuery = HasStereotype(IsStereotypeDerivedFrom("AutoProfile.HardwareComponent"));

2.使用查询创建一个视图。

model.createView("Hardware Component Review Status",...
 Select=hwCompQuery,...
 GroupBy={'AutoProfile.BaseComponent.ReviewStatus'},...
 IncludeReferenceModels=true,...
 Color="purple");

3.要打开架构视图库建模部分,请点击架构视图

model.openViews

Hardware component review status component diagram view.

FOB 定位系统供应商视图

使用 FOB Locater System 中的组件创建一个视图,并使用现有和新的视图组件对供应商进行分组。在此示例中,您将使用元素组(视图中组件的分组)以编程方式填充视图。

1.创建一个视图架构。

fobSupplierView = model.createView("FOB Locater System Supplier Breakdown",...
    Color="lightblue");

2.添加一个名为 Supplier D 的子群。将 FOB Locater Module 添加到视图元素子组。

supplierD = fobSupplierView.Root.createSubGroup("Supplier D");
supplierD.addElement("KeylessEntryArchitecture/FOB Locater System/FOB Locater Module");

3.为 Supplier A 创建一个新子群。

supplierA = fobSupplierView.Root.createSubGroup("Supplier A");

4.将每个 FOB 接收器添加到视图元素子组。

FOBLocaterSystem = model.lookup("Path","KeylessEntryArchitecture/FOB Locater System");

查找所有包含名称 Receiver 的组件。

receiverCompPaths = model.find(...
    contains(Property("Name"),"Receiver"),...
    FOBLocaterSystem.Architecture);

supplierA.addElement(receiverCompPaths)

FOB locater system supplier view component diagram.

使用查询查找模型中的元素

使用查询在 System Composer 模型中查找组件。

导入包含所有 System Composer 查询的命名空间。

import systemcomposer.query.*

打开模型。

openProject("scKeylessEntrySystem");
model = systemcomposer.loadModel("KeylessEntryArchitecture");

查找系统中的所有软件组件。

con1 = HasStereotype(Property("Name") == "SoftwareComponent");
[compPaths,compObjs] = model.find(con1)
compPaths = 5×1 cell
    {'KeylessEntryArchitecture/Door Lock//Unlock System/Door Lock Controller' }
    {'KeylessEntryArchitecture/Sound System/Sound Controller'                 }
    {'KeylessEntryArchitecture/Engine Control System/Keyless Start Controller'}
    {'KeylessEntryArchitecture/Lighting System/Lighting Controller'           }
    {'KeylessEntryArchitecture/FOB Locater System/FOB Locater Module'         }

compObjs=1×5 Component array with properties:
    IsAdapterComponent
    Architecture
    ReferenceName
    Name
    Parent
    Ports
    OwnedPorts
    OwnedArchitecture
    Parameters
    Position
    Model
    SimulinkHandle
    SimulinkModelHandle
    UUID
    ExternalUID

在搜索中包括引用模型。

softwareComps = model.find(con1,IncludeReferenceModels=true)
softwareComps = 9×1 cell
    {'KeylessEntryArchitecture/Door Lock//Unlock System/Door Lock Controller'                                 }
    {'KeylessEntryArchitecture/Sound System/Sound Controller'                                                 }
    {'KeylessEntryArchitecture/Engine Control System/Keyless Start Controller'                                }
    {'KeylessEntryArchitecture/Lighting System/Lighting Controller'                                           }
    {'KeylessEntryArchitecture/FOB Locater System/FOB Locater Module'                                         }
    {'KeylessEntryArchitecture/Door Lock//Unlock System/Front Driver Door Lock Sensor/Detect Door Lock Status'}
    {'KeylessEntryArchitecture/Door Lock//Unlock System/Rear Driver Door Lock Sensor/Detect Door Lock Status' }
    {'KeylessEntryArchitecture/Door Lock//Unlock System/Front Pass Door Lock Sensor/Detect Door Lock Status'  }
    {'KeylessEntryArchitecture/Door Lock//Unlock System/Rear Pass Door Lock Sensor/Detect Door Lock Status'   }

查找系统中的所有基本组件。

con2 = HasStereotype(IsStereotypeDerivedFrom("AutoProfile.BaseComponent"));
baseComps = model.find(con2)
baseComps = 18×1 cell
    {'KeylessEntryArchitecture/Door Lock//Unlock System/Door Lock Controller'           }
    {'KeylessEntryArchitecture/Sound System/Sound Controller'                           }
    {'KeylessEntryArchitecture/Engine Control System/Keyless Start Controller'          }
    {'KeylessEntryArchitecture/Lighting System/Lighting Controller'                     }
    {'KeylessEntryArchitecture/FOB Locater System/FOB Locater Module'                   }
    {'KeylessEntryArchitecture/Door Lock//Unlock System/Front Pass Door Lock Sensor'    }
    {'KeylessEntryArchitecture/FOB Locater System/Front Receiver'                       }
    {'KeylessEntryArchitecture/Sound System/Dashboard Speaker'                          }
    {'KeylessEntryArchitecture/Door Lock//Unlock System/Rear Pass Door Lock Sensor'     }
    {'KeylessEntryArchitecture/Door Lock//Unlock System/Front Driver Door Lock Actuator'}
    {'KeylessEntryArchitecture/Door Lock//Unlock System/Front Pass Door Lock Actuator'  }
    {'KeylessEntryArchitecture/Door Lock//Unlock System/Rear Driver Door Lock Sensor'   }
    {'KeylessEntryArchitecture/Door Lock//Unlock System/Rear Driver Door Lock Actuator' }
    {'KeylessEntryArchitecture/FOB Locater System/Rear Receiver'                        }
    {'KeylessEntryArchitecture/FOB Locater System/Center Receiver'                      }
    {'KeylessEntryArchitecture/Door Lock//Unlock System/Front Driver Door Lock Sensor'  }
    {'KeylessEntryArchitecture/Door Lock//Unlock System/Rear Pass Door Lock Actuator'   }
    {'KeylessEntryArchitecture/Engine Control System/Start//Stop Button'                }

查找使用接口 KeyFOBPosition 的所有组件。

con3 = HasPort(HasInterface(Property("Name") == "KeyFOBPosition"));
con3_a = HasPort(Property("InterfaceName") == "KeyFOBPosition");
keyFOBPosComps = model.find(con3)
keyFOBPosComps = 10×1 cell
    {'KeylessEntryArchitecture/Door Lock//Unlock System/Door Lock Controller' }
    {'KeylessEntryArchitecture/Sound System/Sound Controller'                 }
    {'KeylessEntryArchitecture/Engine Control System/Keyless Start Controller'}
    {'KeylessEntryArchitecture/Lighting System/Lighting Controller'           }
    {'KeylessEntryArchitecture/FOB Locater System/FOB Locater Module'         }
    {'KeylessEntryArchitecture/FOB Locater System'                            }
    {'KeylessEntryArchitecture/Door Lock//Unlock System'                      }
    {'KeylessEntryArchitecture/Lighting System'                               }
    {'KeylessEntryArchitecture/Engine Control System'                         }
    {'KeylessEntryArchitecture/Sound System'                                  }

查找 WCET 小于或等于 5 ms 的所有组件。

con4 = PropertyValue("AutoProfile.SoftwareComponent.WCET") <= 5;
model.find(con4)
ans = 1×1 cell array
    {'KeylessEntryArchitecture/Sound System/Sound Controller'}

您可以为自动单位转换指定单位。

con5 = PropertyValue("AutoProfile.SoftwareComponent.WCET") <= Value(5,'ms');
query1Comps = model.find(con5)
query1Comps = 3×1 cell
    {'KeylessEntryArchitecture/Sound System/Sound Controller'        }
    {'KeylessEntryArchitecture/Lighting System/Lighting Controller'  }
    {'KeylessEntryArchitecture/FOB Locater System/FOB Locater Module'}

查找所有 WCET 大于 1 ms 或成本大于 10 USD 的组件。

con6 = PropertyValue("AutoProfile.SoftwareComponent.WCET") > Value(1,'ms') | PropertyValue("AutoProfile.Base.Cost") > Value(10,'USD');
query2Comps = model.find(con6)
query2Comps = 2×1 cell
    {'KeylessEntryArchitecture/Door Lock//Unlock System/Door Lock Controller' }
    {'KeylessEntryArchitecture/Engine Control System/Keyless Start Controller'}

另请参阅

工具

函数

对象

主题