/////////////////////////////////////////////////////////////////////////////// // 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 "Core/IgesModuleNames.h" #include "Core/IgesInit.h" #include "IgesExamplesCommon.h" #include "StaticRxObject.h" #include "RxDynamicModule.h" #include "ExIgesTutorial_01.h" #include "ExIgesTutorial_02.h" #include "ExIgesTutorial_03.h" #include "ExIgesTutorial_04.h" #include "ExIgesTutorial_05.h" #include "ExIgesTutorial_06.h" #include "Common/examples/daiSimpleProgramOptions.h" namespace { using IgesTutorialPtr = std::shared_ptr; struct IgesTutorialData { IgesTutorialPtr body; OdString name; }; using TutorialCollection = std::vector; const OdString applicationName = OD_T("ExIgesTutorials"); template IgesTutorialData make_tutorial(const OdString& tutorName) { IgesTutorialData data{ std::make_shared(applicationName + " " + tutorName) , OdString(tutorName).makeLower() }; return data; } #define REGISTER_TUTORIAL(ClassName) make_tutorial(#ClassName) } // // 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(OdIgesIOModule); ODRX_DECLARE_STATIC_MODULE_ENTRY_POINT(OdIgesModule); ODRX_DECLARE_STATIC_MODULE_ENTRY_POINT(OdGsModuleObject); ODRX_BEGIN_STATIC_MODULE_MAP() ODRX_DEFINE_STATIC_APPMODULE(OdSDAIModuleName, OdSDAIModule) ODRX_DEFINE_STATIC_APPMODULE(OdIgesIoModuleName, OdIgesIOModule) ODRX_DEFINE_STATIC_APPMODULE(OdIgesSchemaModuleName, OdIgesModule) ODRX_DEFINE_STATIC_APPMODULE(OdGsModuleName, OdGsModuleObject) 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("\nExIgesTutorials developed using %ls ver %ls\n"), svcs.product().c_str(), svcs.versionString().c_str()); TutorialCollection tutorialCollection = { REGISTER_TUTORIAL(Tutorial_01), // Read and dump IGES file REGISTER_TUTORIAL(Tutorial_02), // Create dummy IGES file REGISTER_TUTORIAL(Tutorial_03), // IGES CDA Walker REGISTER_TUTORIAL(Tutorial_04), // Create IGES file REGISTER_TUTORIAL(Tutorial_05), // Create IGES file with CSG instance REGISTER_TUTORIAL(Tutorial_06), // Create IGES file with CSG Boolean operations }; 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; IgesTutorialPtr currentTutorial; if (OdDAI::utils::tryParse(tutorialParam, tutorialNumber)) { if ((tutorialNumber > 0) && (tutorialCollection.size() > static_cast(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; } } ODA_ASSERT(currentTutorial != nullptr); #if !defined(_TOOLKIT_IN_DLL_) ODRX_INIT_STATIC_MODULE_MAP(); #endif /**********************************************************************/ /* Initialize ODA SDK */ /**********************************************************************/ odrxInitialize(&svcs); /**********************************************************************/ /* Initialize IGES SDK */ /**********************************************************************/ ::odrxDynamicLinker()->loadModule(L"sdai.tx", false); odIgesInitialize(true /* CDA Support */); 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 IGES SDK */ /**********************************************************************/ odIgesUninitialize(); /**********************************************************************/ /* Uninitialize ODA SDK */ /**********************************************************************/ odrxUninitialize(); return executionResult; }