/////////////////////////////////////////////////////////////////////////////// // 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 "OdString.h" #include "RxVariantValue.h" #include "ExSystemServices.h" #include "ExHostAppServices.h" #include "IgesExamplesCommon.h" #include "Core/IgesInit.h" #include "StaticRxObject.h" #include "OdPerfTimer.h" #include "ExPrintConsole.h" #include "Core/IgesModuleNames.h" #include "IgesExport.h" using namespace TD_IGES_EXPORT; class DbServices : public ExSystemServices, public ExHostAppServices { protected: ODRX_USING_HEAP_OPERATORS(ExSystemServices); virtual void warning(const char*, const OdString& msg) ODRX_OVERRIDE { odPrintConsoleString(OD_T("Exception: ")); odPrintConsoleString(msg.c_str()); odPrintConsoleString(OD_T("\n")); } }; OdString getModuleWorkDir(OdString moduleDir) { int pos = moduleDir.reverseFind('\\'); if (pos < 0) { pos = moduleDir.reverseFind('/'); } if (pos > 0) { moduleDir = moduleDir.mid(0, pos + 1); } return moduleDir; } // // Define module map for statically linked modules: // #if !defined(_TOOLKIT_IN_DLL_) ODRX_DECLARE_IGES2DWG_STATIC_MODULES_ENTRY_POINTS() ODRX_DECLARE_STATIC_MODULE_ENTRY_POINT(OdRecomputeDimBlockModule); ODRX_DECLARE_STATIC_MODULE_ENTRY_POINT(OdRxThreadPoolService); ODRX_BEGIN_STATIC_MODULE_MAP() ODRX_DEFINE_IGES2DWG_STATIC_APPMODULES() ODRX_DEFINE_STATIC_APPMODULE(OdRecomputeDimBlockModuleName, OdRecomputeDimBlockModule) ODRX_DEFINE_STATIC_APPMODULE(OdThreadPoolModuleName, OdRxThreadPoolService) ODRX_END_STATIC_MODULE_MAP() #endif #include #include /************************************************************************/ /* Main */ /************************************************************************/ #if defined(OD_USE_WMAIN) int wmain(int argc, wchar_t* argv[]) #else int main(int argc, char* argv[]) #endif { ::odSetAssertFunc(MyAssert); int nRes = 0; // Return value for main #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 dbSvcs; OdStaticRxObject igesSvcs; /**********************************************************************/ /* Display the Product and Version that created the executable */ /**********************************************************************/ odPrintConsoleString(OD_T("\nExIges2Dwg example developed using %ls ver %ls"), igesSvcs.product().c_str(), igesSvcs.versionString().c_str()); /**********************************************************************/ /* Parse Command Line inputs */ /**********************************************************************/ bool bInvalidArgs = (argc < 2); if (bInvalidArgs) { bInvalidArgs = true; nRes = 1; } if (bInvalidArgs) { odPrintConsoleString(OD_T("\n\nusage: ExIges2Dwg [out filename] [-saveAsBlockInsertion] ...")); odPrintConsoleString(OD_T("\n - input .iges or .igs file\n")); odPrintConsoleString(OD_T("\n[out filename] - output .dwg file, optional\n")); odPrintConsoleString(OD_T("\nExport settings:\n")); odPrintConsoleString(OD_T("\n[-saveAsBlockInsertion] - saves all iges solid objects as blocks. If this object uses in assembly several times, it will be saved only once, optional\n")); odPrintConsoleString(OD_T("\n[-asSubDMesh] - Export non-brep 3D geometry as subDMeshes. If not - as polyface mesh, optional\n")); odPrintConsoleString(OD_T("\n[-noSolidBodies] - Export all objects as mashes, optional\n")); odPrintConsoleString(OD_T("\n[-dwgBodiesValidation] - Validate brep before OdDbSolid3d entity creation, bodies with errors won't be converted into .dwg solids, optional\n")); odPrintConsoleString(OD_T("\n[-errorsHandling] - Handling conversion errors, this option turns on -dwgValidation option automatically, optional\n")); odPrintConsoleString(OD_T("\n[-logToConsole] - Output conversion log data to the console, optional\n")); odPrintConsoleString(OD_T("\n[-logToFile=log_file_name] - Output conversion log data to the file with log_file_name name , optional\n")); return nRes; } #if !defined(_TOOLKIT_IN_DLL_) ODRX_INIT_STATIC_MODULE_MAP(); #endif /**********************************************************************/ /* Initialize ODA SDK */ /**********************************************************************/ odrxInitialize(&dbSvcs); /**********************************************************************/ /* Initialize Drawings SDK */ /**********************************************************************/ odInitialize(&dbSvcs); /**********************************************************************/ /* Initialize IGES SDK */ /**********************************************************************/ // 1. Conversion can be done using just abstract OdIgesExportPtr interface, // so IGES SDK initialization can be skipped here. In this case it is // performed inside Iges2Dwg module. // 2. igesSvcs is also optional, if it isn't provided, internal implementation // will be used. ::odrxDynamicLinker()->loadModule(OdSDAIModuleName, false); odIgesInitialize(false /* No CDA */); try { OdString igesInFileName(argv[1]); OdString dwgOutFileName; OdString logFilePath; OdInt16 exportModeFlag = TD_IGES_EXPORT::kGenerateSolidBodies; if (argc > 2) { for (int i = 2; i < argc; ++i) { OdString argvi(argv[i]); argvi.makeLower(); if (odStrICmp(argvi, OD_T("-saveasblockinsertion")) == 0) exportModeFlag |= TD_IGES_EXPORT::kSaveAsBlockInsertion; else if (odStrICmp(argvi, OD_T("-assubdmesh")) == 0) exportModeFlag |= TD_IGES_EXPORT::kAsSubDMesh; else if (odStrICmp(argvi, OD_T("-nosolidbodies")) == 0) exportModeFlag &= ~TD_IGES_EXPORT::kGenerateSolidBodies; else if (odStrICmp(argvi, OD_T("-dwgbodiesvalidation")) == 0) exportModeFlag |= TD_IGES_EXPORT::kEnableDwgBodiesValidation; else if (odStrICmp(argvi, OD_T("-errorsHandling")) == 0) exportModeFlag |= TD_IGES_EXPORT::kEnableDwgBodiesValidation | TD_IGES_EXPORT::kEnableErrorsHandling; else if (odStrICmp(argvi, OD_T("-logtoconsole")) == 0) exportModeFlag |= TD_IGES_EXPORT::kEnableConsoleLog; else if (odStrICmp(argvi.left(10), OD_T("-logtofile")) == 0) { exportModeFlag |= TD_IGES_EXPORT::kEnableFileLog; logFilePath = argvi.right(OdString(argv[i]).getLength() - 11); } else dwgOutFileName = argv[i]; } } igesSvcs.setFilesDir(getModuleWorkDir(argv[0])); // OdRxModulePtr pDbModule = ::odrxDynamicLinker()->loadApp(OdModelerGeometryModuleName, false); OdIges2DwgModulePtr pIges2DwgModule = ::odrxDynamicLinker()->loadApp(OdIges2DwgModuleName, false); if (!pIges2DwgModule.isNull()) { OdIgesExportPtr Exporter = pIges2DwgModule->create(); Exporter->properties()->putAt(OD_T("OdDbServices"), static_cast(&dbSvcs)); Exporter->properties()->putAt(OD_T("IgesServices"), static_cast(&igesSvcs)); // Optional Exporter->properties()->putAt(OD_T("IgesFilePath"), OdRxVariantValue(igesInFileName)); Exporter->properties()->putAt(OD_T("ZoomExtents"), OdRxVariantValue(true)); Exporter->properties()->putAt(OD_T("ExportMode"), OdRxVariantValue(exportModeFlag)); if (GETBIT(exportModeFlag, TD_IGES_EXPORT::kEnableFileLog)) Exporter->properties()->putAt(OD_T("LogFilePath"), OdRxVariantValue(logFilePath)); OdPerfTimerWrapper timerWrapper; timerWrapper.getTimer()->start(); // Start conversion OdIgesExport::ExportResult res = Exporter->run(); timerWrapper.getTimer()->stop(); odPrintConsoleString(OD_T("\nIges2Dwg: iges reading time is %d msec"), timerWrapper.getTimer()->countedMSec()); OdDbDatabasePtr pDb; if (res == OdIgesExport::success) { odPrintConsoleString(OD_T("\nIges2Dwg: successful conversion")); pDb = Exporter->properties()->getAt(OD_T("Database")); // Created inside of Iges2Dwg module if wasn't provided before. OdRxObjectPtr pFile = Exporter->properties()->getAt(OD_T("IgesFile")); OdIgesConnectionMapPtr pMap = Exporter->properties()->getAt(OD_T("IgesConnectionMap")); OdRxObjectPtr pMapAssignedFile = pMap->getIgesFile(); ODA_ASSERT(pFile.get() == pMapAssignedFile.get()); if (!dwgOutFileName.isEmpty()) { odPrintConsoleString(OD_T("\nIges2Dwg: writing .dwg file %s"), dwgOutFileName.c_str()); pDb->writeFile(dwgOutFileName, OdDb::kDwg, OdDb::vAC32); } } else { switch (res) { case OdIgesExport::bad_database: odPrintConsoleString(OD_T("\nIges2Dwg: bad database\n")); break; case OdIgesExport::bad_file: odPrintConsoleString(OD_T("\nIges2Dwg: bad iges file\n")); break; case OdIgesExport::fail: odPrintConsoleString(OD_T("\nIges2Dwg: unknown conversion error\n")); break; default: break; } } } // Unload Iges2Dwg module pIges2DwgModule = nullptr; odrxDynamicLinker()->unloadModule(OdIges2DwgModuleName); //pDbModule = nullptr; //odrxDynamicLinker()->unloadModule(OdModelerGeometryModuleName); //odPrintConsoleString(L"\nPress any key.\n"); //getchar(); } catch(OdError& e) { odPrintConsoleString(OD_T("\n\nError: %ls"), e.description().c_str()); nRes = -1; } catch(...) { odPrintConsoleString(OD_T("\n\nUnexpected error.")); nRes = -1; } /**********************************************************************/ /* Uninitialize IGES SDK */ /**********************************************************************/ odIgesUninitialize(); /**********************************************************************/ /* Uninitialize Drawings SDK */ /**********************************************************************/ odUninitialize(); /**********************************************************************/ /* Uninitialize ODA SDK */ /**********************************************************************/ odrxUninitialize(); return nRes; }