STEP SDK:创建 DOMAIN_MODEL 装配文件

在某些情况下,将详细的几何描述保存在单独的文件中并通过组合它们与变换来构建最终产品会很有用。AP242 应用程序协议的 DOMAIN_MODEL 的很大一部分支持装配文件。装配文件可以链接到包含零件的 STEP 文件或其他装配文件。

创建并填充新的装配文件
 

要创建新的装配文件,请使用 StepCoreTools 模块中的 OdStpXModelFiller 类,并使用空的 OdDAI::Model 作为 DOMAIN_MODEL 模式。


  OdAnsiString workDirSchema("./Schemas/"); // Your path to .exp file
  OdDAI::SchemaPtr tutorialSchema = oddaiGetSchema(workDirSchema + "DomainModel.exp");
  if (!tutorialSchema.isNull())
  {
    OdDAI::RepositoryPtr repo = session->createRepo("StpX_Repo");
    session->openRepo(repo);

    OdDAI::ModelPtr tutorialModel = repo->createModel("Tutorial_07_Model", tutorialSchema);
    if (!tutorialModel.isNull())
    {
      tutorialModel->promoteModelToReadWrite();
      OdStpXModelFillerPtr pStpXFiller = OdStpXModelFiller::createObject(tutorialModel);

      if (pStpXFiller.isNull())
      {
        return eCreateFailed;
      }
      …
    }
  }  

要填充模型,您可以使用一系列低级 ODA SDAI 调用,但是,使用 OdStpXModelFiller(它是 SDAI 的高级包装器)可以显著减少创建完整模型所需的代码量。每个命令都会向模型添加新实例,并返回所创建类实例的 OdDAI::ApplicationInstance 的智能指针。

例如,要创建基本模型全局实例:


OdDAI::ApplicationInstancePtr pClass = pStpXFiller->createClass("exchange identification information");
OdDAI::ApplicationInstancePtr pOrganization = pStpXFiller->createOrganization("www.opendesign.com", "Open Design Alliance", OdAnsiStringArray().insertAt(0, "company"));
OdDAI::ApplicationInstancePtr pUnit = pStpXFiller->createUnit("metre", "SI system", "milli");
OdDAI::ApplicationInstancePtr pExchangeContext = pStpXFiller->createExchangeContext("AP242 BO Model XML Assembly Structure exchange", OdAnsiStringArray().insertAt(0, "en"), pUnit->id(), pOrganization->id());
OdDAI::ApplicationInstancePtr pViewContext = pStpXFiller->createViewContext("mechanical design", "design");
OdDAI::ApplicationInstancePtr pFormatProperty = pStpXFiller->createFormatProperty("ISO 8859-1", "ISO 10303-242 BO Model XML");

向模型添加零件
 

DOMAIN_MODEL 模式管理工业产品(例如零件),其数据交换至少包含一个 Part 类型的元素。

以下代码示例说明了如何向模型添加新的 Part 实例:


OdDAI::ApplicationInstancePtr pIdentifierRoot = pStpXFiller->createIdentifier("Tutorial_07", pClass->id(), pOrganization->id());
OdDAI::ApplicationInstancePtr pAssemblyDefinitionRoot = pStpXFiller->createAssemblyDefinition(pViewContext->id());

OdDAIObjectIds rootViewsIds;
rootViewsIds.push_back(pAssemblyDefinitionRoot->id());
OdDAI::ApplicationInstancePtr pPartVersionRoot = pStpXFiller->createPartVersion("/NULL", rootViewsIds);

OdDAIObjectIds rootPartVersionsIds;
rootPartVersionsIds.push_back(pPartVersionRoot->id());
OdDAI::ApplicationInstancePtr pPartRoot = pStpXFiller->createPart(pIdentifierRoot->id(), "Tutorial_07", "assembly", rootPartVersionsIds);

使用 SingleOccurrence 对于在 3D 空间中定位每个出现是必要的。如果单层或多层装配结构多次使用相同的组件零件,则会为组件的每次使用创建一个独立的 SingleOccurrence 实例。在某些 PDM 系统中,由 NextAssemblyOccurrenceUsage 在装配零件中引用的 SingleOccurrence 的每个实例都具有唯一的 ID。所有这些都在组件零件的 PartView 或 AssemblyDefinition 下定义,并且它们仅通过 NextAssemblyOccurrenceUsage 引用一次。

要在两个已创建的 PartView 零件之间进行转换操作:


OdDAI::ApplicationInstancePtr pIdentifierRoot = pStpXFiller->createIdentifier("Tutorial_07", pClass->id(), pOrganization->id());
OdDAI::ApplicationInstancePtr pAssemblyDefinitionRoot = pStpXFiller->createAssemblyDefinition(pViewContext->id());

OdDAIObjectIds rootViewsIds;
rootViewsIds.push_back(pAssemblyDefinitionRoot->id());
OdDAI::ApplicationInstancePtr pPartVersionRoot = pStpXFiller->createPartVersion("/NULL", rootViewsIds);

OdDAIObjectIds rootPartVersionsIds;
rootPartVersionsIds.push_back(pPartVersionRoot->id());
OdDAI::ApplicationInstancePtr pPartRoot = pStpXFiller->createPart(pIdentifierRoot->id(), "Tutorial_07", "assembly", rootPartVersionsIds);

将文档与零件关联

文档可以使用文档分配以特定角色与零件实例关联,文档分配表示文档与产品数据其他元素之间的关系。可以为此关联指定约束,以仅指定文档或文件的适用部分。对于包含零件几何形状的文件,需要文档分配的角色值。

以下代码示例说明了如何创建文档分配并将其与零件的 DigitalFile 实例关联:


OdDAI::ApplicationInstancePtr pDigitalFileIdentifier = pStpXFiller->createIdentifier(pAssemblyFile->fileName, pClass->id(), pOrganization->id());
OdDAI::ApplicationInstancePtr pDigitalFile = pStpXFiller->createDigitalFile(pDigitalFileIdentifier->id(), pFormatProperty->id(), "File name");
OdDAI::ApplicationInstancePtr pDocumentAssignment = pStpXFiller->createDocumentAssignment("mandatory", pDigitalFile->id(), pPartView->id());

填充结构

您可以使用辅助结构轻松填充所需的结构。例如,以下结构集可以帮助您指定对象和文件之间的关系。AssemblyPart 结构存储一个包含转换矩阵的嵌套 Parts 实例数组。每个嵌套零件可以有另一个嵌套 Parts 实例数组,或者与包含几何形状的文件关联。

struct AssemblyBase
{
  virtual ~AssemblyBase() {}
};
struct AssemblyFile : AssemblyBase
{
  AssemblyFile(const OdAnsiString& name) : fileName(name) {}
  OdAnsiString fileName;
};
struct AssemblyPart : AssemblyBase
{
  OdArray<std::pair<AssemblyBase*, OdGeMatrix3d> > assemblies;
};

装配文件应包含 Parts 实例的组合,这些实例之间存在引用。根零件引用嵌套零件,嵌套零件可以引用其他嵌套零件或与几何文件具有关系。

示例

有关创建 DOMAIN_MODEL 装配文件的示例,请参阅 ExStepTutorials 示例模块中的教程 7。教程生成的文件可以在 Open Step Viewer 中打开。

我们的文档中了解更多信息。

今天就开始行动

免费试用 ODA 软件 60 天。
无风险,无需信用卡。

免费试用