/////////////////////////////////////////////////////////////////////////////// // 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. /////////////////////////////////////////////////////////////////////////////// /************************************************************************/ /* Simple application to load a IGES file */ /* and save it as STL geometry collection */ /************************************************************************/ #include "OdaCommon.h" #include "RxModule.h" #include "StaticRxObject.h" #include "RxDynamicModule.h" #include "Core/IgesModuleNames.h" #include "Core/IgesInit.h" #include "Core/IgesGsManager.h" #include "Core/IgesGiContext.h" #include "Core/IgesFile.h" #include "IgesExamplesCommon.h" #include "ExIgesHostAppServices.h" #include "ExGsSimpleDevice.h" #include "RxVariantValue.h" #include "Gs/Gs.h" #include "Gs/GsBaseInclude.h" #include "ColorMapping.h" #include "AbstractViewPE.h" #include "ExPrintConsole.h" GS_TOOLKIT_EXPORT void odgsInitialize(); GS_TOOLKIT_EXPORT void odgsUninitialize(); // // Define module map for statically linked modules: // #if !defined(_TOOLKIT_IN_DLL_) INIT_IGES_STATIC_MODULES #endif /************************************************************************/ /* Main */ /************************************************************************/ #if defined(OD_USE_WMAIN) int wmain(int argc, wchar_t* argv[]) #else int main(int argc, char* argv[]) #endif { int nRes = 0; // Return value for the function #ifdef OD_HAVE_CCOMMAND_FUNC argc = ccommand(&argv); #endif /********************************************************************/ /* Create a Services object */ /********************************************************************/ OdStaticRxObject svcs; /**********************************************************************/ /* Display the Product and Version that created the executable */ /**********************************************************************/ odPrintConsoleString(L"\nExIgesVectorize developed using %ls ver %ls", svcs.product().c_str(), svcs.versionString().c_str()); /**********************************************************************/ /* Parse Command Line inputs */ /**********************************************************************/ bool bInvalidArgs = (argc < 2); if (bInvalidArgs) { bInvalidArgs = true; nRes = 1; } if (bInvalidArgs) { odPrintConsoleString(L"\n\tusage: ExIgesVectorize [stlFilename] [-DO]"); odPrintConsoleString(L"\n\t-DO disables progress meter output.\n"); return nRes; } svcs.setPathToExecutableFromArgv(argv[0]); OdString szSource = argv[1]; OdString strStlFilename = OdString::kEmpty; if (argc > 2) { strStlFilename = argv[2]; if (strStlFilename == L"-DO") strStlFilename = OdString::kEmpty; } #if !defined(_TOOLKIT_IN_DLL_) ODRX_INIT_STATIC_MODULE_MAP(); #endif /**********************************************************************/ /* Initialize ODA SDK */ /**********************************************************************/ odrxInitialize(&svcs); odgsInitialize(); /**********************************************************************/ /* Initialize IGES SDK */ /**********************************************************************/ ::odrxDynamicLinker()->loadModule(L"sdai.tx", false); if (OdResult res = odIgesInitialize(false)) throw OdError(res); try { IgesFilePtr pDatabase = svcs.readFile(szSource); if (pDatabase.isNull()) throw OdError(eCantOpenFile); OdGsDevicePtr pSimpleDevice = ExGsSimpleDevice::createObject(ExGsSimpleDevice::k3dDevice); OdGiContextForIgesDatabasePtr pIgesContext = OdGiContextForIgesDatabase::createObject(); pIgesContext->setDatabase(pDatabase); pIgesContext->enableGsModel(true); const ODCOLORREF* palette = odcmAcadPalette(ODRGB(255, 255, 255)); OdArray > pPalCpy; ODCOLORREF background(ODRGB(192, 192, 192)); pSimpleDevice->setBackgroundColor(background); pIgesContext->setPaletteBackground(background); pPalCpy.insert(pPalCpy.begin(), palette, palette + 256); pSimpleDevice->setLogicalPalette(pPalCpy.asArrayPtr(), 256); OdGsDevicePtr pDevice = OdIgesGsManager::setupActiveLayoutViews(pSimpleDevice, pIgesContext); OdGsView* pView = pDevice->viewAt(0); pView->setMode(OdGsView::kGouraudShaded); pView->setView(OdGePoint3d(1, 1, 1), OdGePoint3d(0, 0, 0), OdGeVector3d::kZAxis, 1000, 1000); OdGsDCRect screenRect(OdGsDCPoint(0, 0), OdGsDCPoint(1024, 768)); pDevice->onSize(screenRect); OdAbstractViewPEPtr(pView)->zoomExtents(pView); pDevice->update(); // Write triangle data to stl. Works only for boundary_representation objects of IGES if (!strStlFilename.isEmpty()) OdGiDumper::writeFaceDataToStlFile(strStlFilename, OdGiDumper::getStlTriangles()); OdGiDumper::clearStlTriangles(); } catch (OdError& e) { odPrintConsoleString(L"\n\nError: %ls", e.description().c_str()); nRes = -1; } catch (...) { odPrintConsoleString(L"\n\nUnexpected error."); nRes = -1; throw; } /**********************************************************************/ /* Uninitialize IGES SDK */ /**********************************************************************/ odIgesUninitialize(); /**********************************************************************/ /* Uninitialize ODA SDK */ /**********************************************************************/ odgsUninitialize(); odrxUninitialize(); return nRes; }