/////////////////////////////////////////////////////////////////////////////// // 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 "RxValue.h" #include "daiModule.h" #include "daiRepository.h" #include "daiModel.h" #include "daiUtils/daiUtils.h" #include "ExStepHostAppServices.h" #include "ExStepTutorial_03.h" #include "Common/examples/daiSimpleProgramOptions.h" // Tutorial_03 shows the process of complex instances creation StepTutorial::ExecutionResult Tutorial_03(const ExStepServices&, const std::vector& params, std::ostream& ouputStream) { OdDAI::utils::argv_parser tutorialArgsParser("Tutorial_03"); if (tutorialArgsParser.parse(params, ouputStream) == OdDAI::utils::ParseResult::showHelp) { return StepTutorial::ExecutionResult::eShowHelp; } OdDAI::SessionPtr session = oddaiCreateSession(); OdAnsiString workDir = StepTutorial::WorkDir::getPath(); OdDAI::SchemaPtr scmAP214E3 = oddaiGetSchema(workDir + "Schemas/AP214E3_2010.exp"); if (!scmAP214E3.isNull()) { OdDAI::RepositoryPtr repo = session->createRepo("TUTORIAL_03_Repo"); session->openRepo(repo); OdDAI::ModelPtr tutorialModel = repo->createModel("Tutorial_03_Model", scmAP214E3); if ((tutorialModel = repo->getModel(tutorialModel))) { tutorialModel->promoteModelToReadWrite(); OdDAI::Aggr *aggr{ nullptr }; //#define _CREATE_COMPLEX_ENTITIES_BY_NAME // Create Complex Entity by string which collects entity names separated by "+" // #1 = (CONVERSION_BASED_UNIT('INCH', $)LENGTH_UNIT()NAMED_UNIT($)); OdDAI::EntityPtr ent_named_unit = scmAP214E3->find("named_unit"); OdDAI::EntityPtr ent_conversion_based_unit = scmAP214E3->find("conversion_based_unit"); OdDAI::EntityPtr ent_length_unit = scmAP214E3->find("length_unit"); OdDAI::List entityList_units; entityList_units.createEmpty(); entityList_units.addByIndex(0, ent_named_unit); entityList_units.addByIndex(1, ent_conversion_based_unit); entityList_units.addByIndex(2, ent_length_unit); #ifdef _CREATE_COMPLEX_ENTITIES_BY_NAME OdDAI::EntityPtr complexEntity_Units = scmAP214E3->getComplexEntity("named_unit+conversion_based_unit+length_unit"); #else OdDAI::EntityPtr complexEntity_Units = scmAP214E3->getComplexEntity(entityList_units); #endif OdDAI::ApplicationInstancePtr complexInstance_Units = tutorialModel->createEntityInstance(complexEntity_Units); complexInstance_Units->putAttr("name", (const char *)"INCH"); OdDAIObjectId idComplexInstance_Units = tutorialModel->appendEntityInstance(complexInstance_Units); OdDAI::EntityPtr complexEntity_Units_The_Same = scmAP214E3->getComplexEntity(entityList_units); ODA_ASSERT_ONCE(complexEntity_Units == complexEntity_Units_The_Same); // #2 = UNCERTAINTY_MEASURE_WITH_UNIT($,$,'Name of uncertainty measure with unit','Just description') OdDAI::ApplicationInstancePtr uncertainty_measure_with_unit = tutorialModel->createEntityInstance("uncertainty_measure_with_unit"); OdDAIObjectId id_uncertainty_measure_with_unit = tutorialModel->appendEntityInstance(uncertainty_measure_with_unit); uncertainty_measure_with_unit->putAttr("name", (OdAnsiString)"Name of uncertainty measure with unit"); uncertainty_measure_with_unit->putAttr("description", (OdAnsiString)"Just description"); // #3 = (GEOMETRIC_REPRESENTATION_CONTEXT(3)GLOBAL_UNCERTAINTY_ASSIGNED_CONTEXT((#2)) // GLOBAL_UNIT_ASSIGNED_CONTEXT((#1))REPRESENTATION_CONTEXT('Just Identifier', 'Just Context Type')); #ifdef _CREATE_COMPLEX_ENTITIES_BY_NAME OdDAI::EntityPtr ent_complex_context = scmAP214E3->getComplexEntity("representation_context+global_unit_assigned_context+global_uncertainty_assigned_context+geometric_representation_context"); #else OdDAI::EntityPtr ent_representation_context = scmAP214E3->find("representation_context"); OdDAI::EntityPtr ent_global_unit_assigned_context = scmAP214E3->find("global_unit_assigned_context"); OdDAI::EntityPtr ent_global_uncertainty_assigned_context = scmAP214E3->find("global_uncertainty_assigned_context"); OdDAI::EntityPtr ent_geometric_representation_context = scmAP214E3->find("geometric_representation_context"); OdDAI::List entityList; entityList.createEmpty(); entityList.addByIndex(0, ent_representation_context); entityList.addByIndex(1, ent_global_unit_assigned_context); entityList.addByIndex(2, ent_global_uncertainty_assigned_context); entityList.addByIndex(3, ent_geometric_representation_context); OdDAI::EntityPtr ent_complex_context = scmAP214E3->getComplexEntity(entityList); #endif OdDAI::ApplicationInstancePtr complex_context = tutorialModel->createEntityInstance(ent_complex_context); OdDAIObjectId id_complex_context = tutorialModel->appendEntityInstance(complex_context); bool is_representation_context = complex_context->isKindOf("representation_context"); bool is_global_unit_assigned_context = complex_context->isKindOf("global_unit_assigned_context"); bool is_global_uncertainty_assigned_context = complex_context->isKindOf("global_uncertainty_assigned_context"); bool is_ent_geometric_representation_context = complex_context->isKindOf("geometric_representation_context"); complex_context->putAttr("context_identifier", (const char *)"Just Identifier"); complex_context->putAttr("context_type", (const char *)"Just Context Type"); complex_context->putAttr("coordinate_space_dimension", 3); complex_context->getAttr("uncertainty") >> aggr; OdDAI::Set *uncertainty = static_cast*>(aggr); uncertainty->createEmpty(); uncertainty->Add(id_uncertainty_measure_with_unit); complex_context->getAttr("units") >> aggr; OdDAI::Set *units = static_cast*>(aggr); units->createEmpty(); units->Add(OdRxValue(idComplexInstance_Units)); OdAnsiString stepLine(OdDAI::Utils::getStepLine(complex_context)); odPrintConsoleString(L"\n%hs", stepLine.c_str()); } if (repo->writeFile(workDir + "Tutorial_03.stp") == eOk) { OdDAI::RepositoryPtr repoLoaded = session->createRepoFromFile(workDir + "Tutorial_03.stp"); OdDAI::ModelPtr loadedModel = repoLoaded->getModel(); auto representation_contexts = loadedModel->getEntityExtent("representation_context"); auto it = representation_contexts->createConstIterator(); for (it->beginning(); it->next();) { OdDAIObjectId id; it->getCurrentMember() >> id; if (id.isValid()) { OdDAI::ApplicationInstancePtr representation_context = id.openObject(); OdAnsiString stepLine(OdDAI::Utils::getStepLine(representation_context)); odPrintConsoleString(L"\n%hs", stepLine.c_str()); } } repoLoaded->writeFile(workDir + "Tutorial_03_resaved.stp"); } session->closeRepo(repo); odPrintConsoleString(L"\n"); } oddaiCloseCurrentSession(); return StepTutorial::ExecutionResult::eSucceed; }