/////////////////////////////////////////////////////////////////////////////// // 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 "ExStepHostAppServices.h" #include "ExStepTutorial_01.h" #include "Common/examples/daiSimpleProgramOptions.h" StepTutorial::ExecutionResult Tutorial_01(const ExStepServices&, const std::vector& params, std::ostream& ouputStream) { OdDAI::utils::argv_parser tutorialArgsParser("Tutorial_01"); if (tutorialArgsParser.parse(params, ouputStream) == OdDAI::utils::ParseResult::showHelp) { return StepTutorial::ExecutionResult::eShowHelp; } OdDAI::SessionPtr session = oddaiCreateSession(); OdAnsiString workDir("./Schemas/"); // Your path to .exp file OdDAI::SchemaPtr tutorialSchema = oddaiGetSchema(workDir + "TUTORIAL_SCHEMA.exp"); if (!tutorialSchema.isNull()) { OdDAI::RepositoryPtr repo = session->createRepo("TUTORIAL_01_Repo"); session->openRepo(repo); OdDAI::ModelPtr tutorialModel = repo->createModel("Tutorial_01_Model", tutorialSchema); if (!tutorialModel.isNull()) { tutorialModel->promoteModelToReadWrite(); OdDAI::Aggr *aggr = nullptr; // // Create circle // OdDAI::ApplicationInstancePtr point_0 = tutorialModel->createEntityInstance("gfpoint"); point_0->getAttr("coordinates") >> aggr; OdDAI::ListOfDouble *coordinates = static_cast(aggr); coordinates->createEmpty(); coordinates->addByIndex(0, 0.); coordinates->addByIndex(1, 0.); coordinates->addByIndex(2, 0.); OdDAIObjectId idPoint_0 = tutorialModel->appendEntityInstance(point_0); OdDAI::ApplicationInstancePtr circle_0 = tutorialModel->createEntityInstance("gfcircle"); circle_0->putAttr("name", (const char*)"Just circle"); circle_0->putAttr("center", idPoint_0); circle_0->putAttr("radius", -10.); // Radius is less than zero, wr rule will catch it tutorialModel->appendEntityInstance(circle_0); // // Create polyline // OdDAI::ApplicationInstancePtr point_1 = tutorialModel->createEntityInstance("gfpoint"); point_1->getAttr("coordinates") >> aggr; coordinates = static_cast(aggr); coordinates->createEmpty(); coordinates->addByIndex(0, 10.); coordinates->addByIndex(1, 0.); coordinates->addByIndex(2, 0.); OdDAIObjectId idPoint_1 = tutorialModel->appendEntityInstance(point_1); OdDAI::ApplicationInstancePtr point_2 = tutorialModel->createEntityInstance("gfpoint"); point_2->getAttr("coordinates") >> aggr; coordinates = static_cast(aggr); coordinates->createEmpty(); coordinates->addByIndex(0, 30.); coordinates->addByIndex(1, 0.); coordinates->addByIndex(2, 0.); OdDAIObjectId idPoint_2 = tutorialModel->appendEntityInstance(point_2); OdDAI::ApplicationInstancePtr polyline_1 = tutorialModel->createEntityInstance("gfpolyline"); polyline_1->putAttr("name", (const char*)"Just polyline"); polyline_1->getAttr("points") >> aggr; OdDAI::ListOfOdDAIObjectId *points = static_cast(aggr); points->createEmpty(); points->putByIndex(0, idPoint_1); points->putByIndex(1, idPoint_2); OdDAIObjectId idPolyline_1 = tutorialModel->appendEntityInstance(polyline_1); } if (repo->writeFile(workDir + "Tutorial_01.spf") == eOk) { OdDAI::RepositoryPtr repoLoaded = session->createRepoFromFile(workDir + "Tutorial_01.spf"); OdDAI::ModelPtr loadedModel = repoLoaded->getModel(); loadedModel->promoteModelToReadWrite(); auto circles = loadedModel->getEntityExtent("gfcircle"); auto it = circles->createConstIterator(); for (it->beginning(); it->next();) { OdDAIObjectId id; it->getCurrentMember() >> id; if (id.isValid()) { OdDAI::ApplicationInstancePtr circle = id.openObject(); OdDAI::WhereRulePtr wr_positive_radius = circle->getInstanceType()->findWhereRule("wr_positive_radius"); if (!wr_positive_radius.isNull()) { OdDAI::Logical radius_is_positive = circle->validateWhereRule(wr_positive_radius); if (radius_is_positive == OdDAI::Logical::False) { double radius = 0.; circle->getAttr("radius") >> radius; circle->putAttr("radius", fabs(radius)); } } } } repoLoaded->writeFile(workDir + "Tutorial_01_fixed.spf"); } session->closeRepo(repo); } oddaiCloseCurrentSession(); return StepTutorial::ExecutionResult::eSucceed; }