/////////////////////////////////////////////////////////////////////////////// // 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 "IfcExamplesCommon.h" #include "IfcCore.h" #include "StaticRxObject.h" #include "RxDynamicModule.h" #include "ExIfcTutorial_01.h" #include "ExIfcTutorial_02.h" #include "ExIfcTutorial_03.h" #include "ExIfcTutorial_04.h" #include "ExIfcTutorial_05.h" #include "ExIfcTutorial_06.h" #include "ExIfcTutorial_07.h" #include "ExIfcTutorial_ModelOpsFloor.h" #include "ExIfcTutorial_ModelOpsProduct.h" #include "ExIfcTutorial_ModelOpsSite.h" #include "ExIfcTutorial_ModelOpsCombine.h" #include "ExIfcTutorial_IfcTunnel.h" #include "ExIfcTutorial_Ifc2MulObj.h" #include "ExIfcTutorial_IfcType2Obj.h" #include "ExIfcTutorial_IfcLayer2Bmp.h" #include "ExIfcTutorial_IfcLayerAssignment.h" #include "ExIfcPsdQtoTutorials.h" #include "ExIfcTutorial_COBie.h" #include "ExBcfTutorials.h" #include "ExIfcModelFromBufferTutorial.h" #include "ExIfcTutorial_ParametricSleeper.h" #include "ExIfcTutorial_ParametricPole.h" #include "ExIfcTutorial_IDSFileCreation_LowLevel.h" #include "ExIfcTutorial_IDSFileCreation_HighLevel.h" #include "ExIfcTutorial_Signature.h" #include "ExIfcTutorial_ExtractGeometry.h" #include "ExIfcTutorial_RelAssocMaterial.h" #include "ExIfcTutorial_RelAssocMaterial_EarlyBound.h" #include "ExIfcTutorial_ScheduleCreation.h" #include "Common/examples/daiSimpleProgramOptions.h" namespace { using IfcTutorialPtr = std::shared_ptr; struct IfcTutorialData { IfcTutorialPtr body; OdString name; }; using TutorialCollection = std::vector; const OdString applicationName = OD_T("ExIfcTutorials"); template IfcTutorialData make_tutorial(const OdString& tutorName) { IfcTutorialData data{ std::make_shared(applicationName + " " + tutorName) , OdString(tutorName).makeLower() }; return data; } #define REGISTER_TUTORIAL(ClassName) make_tutorial(#ClassName) } int undocumentedCall(MyServices& svcs, const std::vector& argv); // // Define module map for statically linked modules: // #if !defined(_TOOLKIT_IN_DLL_) ODRX_DECLARE_STATIC_MODULE_ENTRY_POINT(OdSDAIModule); ODRX_DECLARE_STATIC_MODULE_ENTRY_POINT(OdIfcCoreModule); ODRX_DECLARE_STATIC_MODULE_ENTRY_POINT(OdIfc2x3Module); ODRX_DECLARE_STATIC_MODULE_ENTRY_POINT(OdIfc4Module); ODRX_DECLARE_STATIC_MODULE_ENTRY_POINT(OdIfc4x3Module); ODRX_DECLARE_STATIC_MODULE_ENTRY_POINT(OdRxThreadPoolService); ODRX_DECLARE_STATIC_MODULE_ENTRY_POINT_XMLIO; ODRX_DECLARE_STATIC_MODULE_ENTRY_POINT(OdBcfCommonModule); ODRX_DECLARE_STATIC_MODULE_ENTRY_POINT(OdBcf_2_1Module); ODRX_DECLARE_STATIC_MODULE_ENTRY_POINT(OdBcf_3_0Module); ODRX_DECLARE_STATIC_MODULE_ENTRY_POINT(OdBcfToolsModule); #if defined(COBIE_SUPPORT) ODRX_DECLARE_STATIC_MODULE_ENTRY_POINT(OdCOBieModule); #endif ODRX_BEGIN_STATIC_MODULE_MAP() ODRX_DEFINE_STATIC_APPMODULE(OdSDAIModuleName, OdSDAIModule) ODRX_DEFINE_STATIC_APPMODULE(OdIfcCoreModuleName, OdIfcCoreModule) ODRX_DEFINE_STATIC_APPMODULE(OdIfc2x3ModuleName, OdIfc2x3Module) ODRX_DEFINE_STATIC_APPMODULE(OdIfc4ModuleName, OdIfc4Module) ODRX_DEFINE_STATIC_APPMODULE(OdIfc4x3ModuleName, OdIfc4x3Module) ODRX_DEFINE_STATIC_APPMODULE(OdThreadPoolModuleName, OdRxThreadPoolService) ODRX_DEFINE_STATIC_APPMODULE_XMLIO ODRX_DEFINE_STATIC_APPMODULE(OdBcfCommonModuleName, OdBcfCommonModule) ODRX_DEFINE_STATIC_APPMODULE(OdBcf_2_1ModuleName, OdBcf_2_1Module) ODRX_DEFINE_STATIC_APPMODULE(OdBcf_3_0ModuleName, OdBcf_3_0Module) ODRX_DEFINE_STATIC_APPMODULE(OdBcfToolsModuleName, OdBcfToolsModule) #if defined(COBIE_SUPPORT) ODRX_DEFINE_STATIC_APPMODULE(OdCOBieModuleName, OdCOBieModule) #endif ODRX_END_STATIC_MODULE_MAP() #endif #include #include void showTutorialHelp(TutorialCollection& tutorialCollection, std::stringstream& executionStream) { executionStream << "\n\nList of available tutorials and its parameters descriptions: "; int tutorialNumber = 1; for (auto& tutorial : tutorialCollection) { executionStream << std::endl << tutorialNumber << ". Tutorial: \n"; tutorial.body->help(executionStream); ++tutorialNumber; } odPrintConsoleString(OdString(executionStream.str().c_str())); } /************************************************************************/ /* Main */ /************************************************************************/ #if defined(OD_USE_WMAIN) int wmain(int argc, wchar_t* argv[]) #else int main(int argc, char* argv[]) #endif { #if defined(TARGET_OS_MAC) && !defined(__MACH__) argc = ccommand(&argv); #endif setlocale(LC_TIME, ""); // set current user locale (not OD_T("C")), for strftime /**********************************************************************/ /* Create a Services object */ /**********************************************************************/ OdStaticRxObject svcs; /**********************************************************************/ /* Display the Product and Version that created the executable */ /**********************************************************************/ odPrintConsoleString(OD_T("\nExIfcTutorials developed using %ls ver %ls\n"), svcs.product().c_str(), svcs.versionString().c_str()); TutorialCollection tutorialCollection = { REGISTER_TUTORIAL(Tutorial_01), REGISTER_TUTORIAL(Tutorial_02), REGISTER_TUTORIAL(Tutorial_03), REGISTER_TUTORIAL(Tutorial_04), REGISTER_TUTORIAL(Tutorial_05), REGISTER_TUTORIAL(Tutorial_06), REGISTER_TUTORIAL(Tutorial_07), REGISTER_TUTORIAL(BcfTutorial_Dump), // 8 REGISTER_TUTORIAL(BcfTutorial_CreateProject), // 9 REGISTER_TUTORIAL(BcfTutorial_Load), // 10 REGISTER_TUTORIAL(ModelFromBufferTutorial), // 11 REGISTER_TUTORIAL(Tutorial_ModelOpsFloor), // 12 REGISTER_TUTORIAL(Tutorial_ModelOpsProduct), // 13 REGISTER_TUTORIAL(Tutorial_ModelOpsSite), // 14 REGISTER_TUTORIAL(Tutorial_ModelOpsCombine), // 15 REGISTER_TUTORIAL(Tutorial_IfcTunnel_Deployment), // 16 (IFC4X4) REGISTER_TUTORIAL(Tutorial_IfcCOBie), // 17 (IfcToCOBie) REGISTER_TUTORIAL(Ifc2MulObjTutorial),// 18 REGISTER_TUTORIAL(IfcType2ObjTutorial),// 19 REGISTER_TUTORIAL(Tutorial_ParametricSleeper),// 20 REGISTER_TUTORIAL(Tutorial_ParametricPole),// 21 REGISTER_TUTORIAL(IfcLayer2BmpTutorial),// 22 REGISTER_TUTORIAL(IfcLayerAssignmentTutorial),// 23 REGISTER_TUTORIAL(Tutorial_IDSFileCreation_LowLevel),// 24 REGISTER_TUTORIAL(Tutorial_IDSFileCreation_HighLevel),// 25 REGISTER_TUTORIAL(Tutorial_SignatureValidation),// 26 REGISTER_TUTORIAL(Tutorial_SignatureSign),// 27 REGISTER_TUTORIAL(Tutorial_ExtractGeometry),// 28 REGISTER_TUTORIAL(Tutorial_RelAssocMaterial),// 29 REGISTER_TUTORIAL(Tutorial_RelAssocMaterial_EarlyBound),// 30 REGISTER_TUTORIAL(Tutorial_ScheduleCreation),// 31 }; using namespace OdDAI::utils; OdString tutorialParam; argv_parser commandLineParser(applicationName); commandLineParser.add_param(std::make_shared>(tutorialParam, "tutorial", "tutorial number or name.")); commandLineParser.add_param(std::make_shared("tutorial_parameter_collection", "tutorial parameters collection.")); std::vector argumentList(argv + 1, argv + argc); std::stringstream executionStream; bool showHelp = false; switch(commandLineParser.parse(argumentList, executionStream)) { case ParseResult::failed: { odPrintConsoleString(OD_T("\nPress ENTER to continue...\n")); return 1; } break; case ParseResult::showHelp: { showTutorialHelp(tutorialCollection, executionStream); return 0; } break; case ParseResult::succeed: break; } int tutorialNumber = -1; IfcTutorialPtr currentTutorial; if (OdDAI::utils::tryParse(tutorialParam, tutorialNumber)) { if (tutorialNumber == 100) { return undocumentedCall(svcs, argumentList); } if ((tutorialNumber > 0) && (tutorialCollection.size() > tutorialNumber - 1)) { currentTutorial = tutorialCollection[tutorialNumber - 1].body; } else { odPrintConsoleString(OD_T("\n\nTutorial wrong number.")); showTutorialHelp(tutorialCollection, executionStream); return -2; } } else { for (auto& data : tutorialCollection) { if (data.name == OdString(tutorialParam).makeLower()) { currentTutorial = data.body; break; } } if(currentTutorial == nullptr) { odPrintConsoleString(OD_T("\n\nTutorial wrong name.")); showTutorialHelp(tutorialCollection, executionStream); return -2; } } bool needsGeometry{ false }; if ((tutorialNumber == 28 || tutorialParam == "Tutorial_ExtractGeometry") ||(tutorialNumber == 31 || tutorialParam == "Tutorial_ScheduleCreation")) { needsGeometry = true; } ODA_ASSERT(currentTutorial != nullptr); #if !defined(_TOOLKIT_IN_DLL_) ODRX_INIT_STATIC_MODULE_MAP(); #endif /**********************************************************************/ /* Initialize ODA SDK */ /**********************************************************************/ odrxInitialize(&svcs); /**********************************************************************/ /* Initialize IfcCore */ /**********************************************************************/ odIfcInitialize(false /* No CDA */, needsGeometry /* Is geometry calculation needed */); int executionResult = 0; // Return value for main try { std::vector tutorialArgs(argumentList.begin() + 1, argumentList.end()); executionResult = currentTutorial->run(svcs, tutorialArgs, executionStream); } catch (OdError& e) { odPrintConsoleString(OD_T("\n\nError: %ls"), e.description().c_str()); executionResult = -1; } odPrintConsoleString(OdString(executionStream.str().c_str()).c_str()); /**********************************************************************/ /* Uninitialize IfcCore */ /**********************************************************************/ odIfcUninitialize(); /**********************************************************************/ /* Uninitialize ODA SDK */ /**********************************************************************/ odrxUninitialize(); return executionResult; } int undocumentedCall(MyServices& svcs, const std::vector& argv) { odrxInitialize(&svcs); odIfcInitialize(false /* No CDA */, false /* No geometry calculation needed */); auto executionResult = PsdQtoTutorial_01(argv, svcs); std::cout << "\nPress any key."; getchar(); odIfcUninitialize(); odrxUninitialize(); return executionResult; }