/////////////////////////////////////////////////////////////////////////////// // Copyright (C) 2002-2025, Open Design Alliance (the "Alliance"). // All rights reserved. // // This software and its documentation and related materials are owned by // the Alliance. The software may only be incorporated into application // programs owned by members of the Alliance, subject to a signed // Membership Agreement and Supplemental Software License Agreement with the // Alliance. The structure and organization of this software are the valuable // trade secrets of the Alliance and its suppliers. The software is also // protected by copyright law and international treaty provisions. Application // programs incorporating this software must include the following statement // with their copyright notices: // // This application incorporates Open Design Alliance software pursuant to a license // agreement with Open Design Alliance. // Open Design Alliance Copyright (C) 2002-2025 by Open Design Alliance. // All rights reserved. // // By use of this software, its documentation or related materials, you // acknowledge and accept the above terms. /////////////////////////////////////////////////////////////////////////////// #include "OdaCommon.h" #include "daiModule.h" #include "daiRepository.h" #include "daiModel.h" #include "StpXModelFiller.h" #include "ExStepHostAppServices.h" #include "ExStpXTutorial_07.h" #include "Common/examples/daiSimpleProgramOptions.h" StepTutorial::ExecutionResult Tutorial_07(const ExStepServices&, const std::vector& params, std::ostream& ouputStream) { OdString filesDir = ""; bool runtimeMode = true; OdDAI::utils::argv_parser tutorialArgsParser("Tutorial_07"); tutorialArgsParser.add_param(std::make_shared>(filesDir, "dir", "ouput files directory.")); tutorialArgsParser.add_param(std::make_shared(runtimeMode, "-runtime_schema", "Using runtime schema from schemas folder if true otherwise using schema from .txexp in same folder.")); switch (tutorialArgsParser.parse(params, ouputStream)) { case OdDAI::utils::ParseResult::showHelp: { return StepTutorial::ExecutionResult::eShowHelp; } break; case OdDAI::utils::ParseResult::failed: { return StepTutorial::ExecutionResult::eWrongParams; } break; default: break; } OdDAI::SessionPtr session = oddaiCreateSession(); OdAnsiString workDir = StepTutorial::WorkDir::getPath(); // Your path to .exp file OdDAI::SchemaPtr tutorialSchema;// if (runtimeMode) { tutorialSchema = oddaiGetSchema(workDir + "Schemas/DomainModel.exp"); } else { tutorialSchema = oddaiGetSchema(workDir + "DOMAINMODEL.txexp"); } //Base sructures for files dependences struct AssemblyBase { virtual ~AssemblyBase() {} }; struct AssemblyFile : AssemblyBase { AssemblyFile(const OdAnsiString& name) : fileName(name) {} OdAnsiString fileName; }; struct AssemblyPart : AssemblyBase { OdArray > assemblies; }; //Files structure creation OdSharedPtr pAssemblyFilePlate = new AssemblyFile("plate_20120725.134815_Rep.stp"); OdSharedPtr pAssemblyFileBracket = new AssemblyFile("l-bracket_20120725.134815_Rep.stp"); OdSharedPtr pAssemblyFileBolt = new AssemblyFile("bolt_20120725.134815_Rep.stp"); OdSharedPtr pAssemblyFileNut = new AssemblyFile("nut_20120725.134815_Rep.stp"); OdSharedPtr pAssemblyFileRod = new AssemblyFile("rod_20120725.134815_Rep.stp"); OdSharedPtr pAssemblyPartNutAndRod = new AssemblyPart(); pAssemblyPartNutAndRod->assemblies.push_back({ pAssemblyFileRod, OdGeMatrix3d().setCoordSystem(OdGePoint3d(0., 0., 0.), OdGeVector3d(1., 0., 0.), OdGeVector3d(0., 1., 0.), OdGeVector3d(0., 0., 1.)) }); pAssemblyPartNutAndRod->assemblies.push_back({ pAssemblyFileNut, OdGeMatrix3d().setCoordSystem(OdGePoint3d(-10., -7.5, 12.), OdGeVector3d(1., 0., 0.), OdGeVector3d(0., 1., 0.), OdGeVector3d(0., 0., 1.)) }); pAssemblyPartNutAndRod->assemblies.push_back({ pAssemblyFileNut, OdGeMatrix3d().setCoordSystem(OdGePoint3d(-10., -7.5, 185.), OdGeVector3d(1., 0., 0.), OdGeVector3d(0., 1., 0.), OdGeVector3d(0., 0., 1.)) }); OdSharedPtr pAssemblyPartBoltAndNut = new AssemblyPart(); pAssemblyPartBoltAndNut->assemblies.push_back({ pAssemblyFileBolt, OdGeMatrix3d().setCoordSystem(OdGePoint3d(-7.5, -10., 13.), OdGeVector3d(0., -1., 0.), OdGeVector3d(-1., 0., 0.), OdGeVector3d(0., 0., -1.)) }); pAssemblyPartBoltAndNut->assemblies.push_back({ pAssemblyFileNut, OdGeMatrix3d().setCoordSystem(OdGePoint3d(2.5, -17.5, -20.), OdGeVector3d(-1., 0., 0.), OdGeVector3d(0., 1., 0.), OdGeVector3d(0., 0., -1.)) }); OdSharedPtr pAssemblyPartBracket = new AssemblyPart(); pAssemblyPartBracket->assemblies.push_back({ pAssemblyFileBracket, OdGeMatrix3d().setCoordSystem(OdGePoint3d(0., 0., 0.), OdGeVector3d(1., 0., 0.), OdGeVector3d(0., 0., 1.), OdGeVector3d(0., -1., 0.)) }); pAssemblyPartBracket->assemblies.push_back({ pAssemblyPartBoltAndNut, OdGeMatrix3d().setCoordSystem(OdGePoint3d(27.5, -40., 0.), OdGeVector3d(1., 0., 0.), OdGeVector3d(0., 1., 0.), OdGeVector3d(0., 0., 1.)) }); pAssemblyPartBracket->assemblies.push_back({ pAssemblyPartBoltAndNut, OdGeMatrix3d().setCoordSystem(OdGePoint3d(50., -52.99038106, 0.), OdGeVector3d(1., 0., 0.), OdGeVector3d(0., 1., 0.), OdGeVector3d(0., 0., 1.)) }); pAssemblyPartBracket->assemblies.push_back({ pAssemblyPartBoltAndNut, OdGeMatrix3d().setCoordSystem(OdGePoint3d(50., -27.00961894, 0.), OdGeVector3d(1., 0., 0.), OdGeVector3d(0., 1., 0.), OdGeVector3d(0., 0., 1.)) }); OdSharedPtr pAssemblyRoot = new AssemblyPart(); pAssemblyRoot->assemblies.push_back({ pAssemblyFilePlate, OdGeMatrix3d().setCoordSystem(OdGePoint3d(0, 0, 0), OdGeVector3d(1., 0., 0.), OdGeVector3d(0., 1., 0.), OdGeVector3d(0., 0., 1.)) }); pAssemblyRoot->assemblies.push_back({ pAssemblyPartBracket, OdGeMatrix3d().setCoordSystem(OdGePoint3d(5., 125., 20.), OdGeVector3d(1., 0., 0.), OdGeVector3d(0., 1., 0.), OdGeVector3d(0., 0., 1.)) }); pAssemblyRoot->assemblies.push_back({ pAssemblyPartBracket, OdGeMatrix3d().setCoordSystem(OdGePoint3d(175., 25.,20.), OdGeVector3d(-1., 0., 0.), OdGeVector3d(0., -1., 0.), OdGeVector3d(0., 0., 1.)) }); pAssemblyRoot->assemblies.push_back({ pAssemblyPartNutAndRod, OdGeMatrix3d().setCoordSystem(OdGePoint3d(-10., 75., 60.), OdGeVector3d(0., 0., -1.), OdGeVector3d(0., -1., 0.), OdGeVector3d(1., 0., 0.)) }); //Creating Model 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 StepTutorial::ExecutionResult::eFailed; } //Default global base classes 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"); //Root PART instance creation 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); //Nested PART instances creation std::map assemblyInstances; assemblyInstances.insert({ pAssemblyRoot, pAssemblyDefinitionRoot }); int assemblyCounter = 1; int singleOccurrenceCounter = 1; std::function createAssemblies{ [&](AssemblyPart* pAssemblyPart) { for (const auto& assembly : pAssemblyPart->assemblies) { auto pAssemblyInstIt = assemblyInstances.find(assembly.first); OdDAI::ApplicationInstancePtr pAssemblyInst; if (pAssemblyInstIt == assemblyInstances.cend()) { OdDAI::ApplicationInstancePtr pIdentifier = pStpXFiller->createIdentifier(OdAnsiString().format("assembly_%d", assemblyCounter), pClass->id(), pOrganization->id()); OdDAI::ApplicationInstancePtr pPartView = pStpXFiller->createPartView(pViewContext->id()); OdDAIObjectIds viewsIds; viewsIds.push_back(pPartView->id()); OdDAI::ApplicationInstancePtr pPartVersion = pStpXFiller->createPartVersion("/NULL", viewsIds); OdDAIObjectIds partVersionsIds; partVersionsIds.push_back(pPartVersion->id()); AssemblyFile* pAssemblyFile = dynamic_cast(assembly.first); if (pAssemblyFile) { OdDAI::ApplicationInstancePtr pPart = pStpXFiller->createPart(pIdentifier->id(), OdAnsiString().format("assemblyPart_%d", assemblyCounter++), "piece part", partVersionsIds); OdDAI::ApplicationInstancePtr pDigitalFileIdentifier = pStpXFiller->createIdentifier(pAssemblyFile->fileName, pClass->id(), pOrganization->id()); OdDAI::ApplicationInstancePtr pDigitalFile = pStpXFiller->createDigitalFile(pDigitalFileIdentifier->id(), pFormatProperty->id(), pAssemblyFile->fileName); OdDAI::ApplicationInstancePtr pDocumentAssignment = pStpXFiller->createDocumentAssignment("mandatory", pDigitalFile->id(), pPartView->id()); } else OdDAI::ApplicationInstancePtr pPart = pStpXFiller->createPart(pIdentifier->id(), OdAnsiString().format("assemblyPart_%d", assemblyCounter++), "assembly", partVersionsIds); assemblyInstances.insert({ assembly.first, pPartView }); pAssemblyInst = pPartView; AssemblyPart* pAssembly = dynamic_cast(assembly.first); if (pAssembly) createAssemblies(pAssembly); } else pAssemblyInst = pAssemblyInstIt->second; OdDAI::ApplicationInstancePtr pSingleOccurrence = pStpXFiller->createSingleOccurrence(OdAnsiString().format("singleOccurrence_%d", singleOccurrenceCounter++), pAssemblyInst->id()); OdDAI::ApplicationInstancePtr pCartesianTransformation = pStpXFiller->createCartesianTransformation(assembly.second); OdDAIObjectIds matrixIds; matrixIds.push_back(pCartesianTransformation->id()); OdDAI::ApplicationInstancePtr pNextAssemblyOccurrenceUsage = pStpXFiller->createNextAssemblyOccurrenceUsage(matrixIds, assemblyInstances.at(pAssemblyPart)->id(), pSingleOccurrence->id()); } } }; createAssemblies(pAssemblyRoot); } //Save model as file repo->writeFile(filesDir + "/Tutorial_07.stp"); session->closeRepo(repo); } oddaiCloseCurrentSession(); return StepTutorial::ExecutionResult::eSucceed; }