# 模型属性查找


模型属性查找为在模型中查找相关属性,如查找模型中所有组件 key 的列表等。

函数名 简介
LookupCompAndTypeEx 查找模型中组件类型的 key
LookupConnectionsOfPort 查找端口连线

# LookupCompAndTypeEx

获取组件及其类型 key(应用重声明)。

# 语法

/**
  * @brief  通过模型的类型全名查找模型key(应用重声明)
  * @param  [in]main_key                 主模型
  * @param  [in]compo_name           所在实例全名
  * @param  [in]class_type      类型全名
  * @return 查找到的key
  */ 
MWint MwMoHandler::LookupCompAndTypeEx(MWint main_key, const std::list<std::string>& compo_name, MWint* class_key);

# 说明

通过传入模型 key,在 compo_name 中传入组件名称,将获取到该组件对应的类型 key。 例如 Real a;a 为组件名,Real 为类型名,都有对应的 key,a 的 key 为组件 key,Real 为类型 key。

# 示例

MwClassManager* classMgr = new MwClassManager();
classMgr->Initialize();
String model_name = "Modelica.Blocks.Examples.PID_Controller";
MWint model_key = classMgr->GetMoHandler()->GetKeyByTypeName(model_name.toStdString());
MWint type_key = 0;
MwStrList name_nodes;
name_nodes.push_back("PI");
classMgr->GetMoHandler()->LookupCompAndTypeEx(model_key, name_nodes, &type_key);

# LookupConnectionsOfPort

获得指定连接器相连的连接线。

# 语法

/**
  * @brief 获得指定连接器相连的连接线
  * @param  [in]key                 主模型
  * @param  [in]port_key             端口的键值
  * @return 查找到该端口所有的连线key列表
  */
std::vector<MWint> MwMoHandler::LookupConnectionsOfPort(MWint key, const std::string& port_key);

# 说明

获得指定连接器相连的连接线。

# 示例

MwClassManager* classMgr = new MwClassManager();
classMgr->Initialize();
String model_name = "Modelica.Blocks.Examples.PID_Controller";
MWint model_key = classMgr->GetMoHandler()->GetKeyByTypeName(model_name.toStdString());
auto vecList = classMgr->GetMoHandler()->LookupConnectionsOfPort(model_key, "PI");
获得指定端口相连的连接线