/////////////////////////////////////////////////////////////////////////////// // 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 Step file */ /* and save as STL geometry collection */ /************************************************************************/ #include "OdaCommon.h" #include "StaticRxObject.h" #include "RxDynamicModule.h" #include "StepExamplesCommon.h" #include "StepCore.h" #include "StepGsManager.h" #include "StepGiContext.h" #include "ExStepHostAppServices.h" #include "ExGsSimpleDevice.h" #include "RxVariantValue.h" #include "Gs/Gs.h" #include "Gs/GsBaseInclude.h" #include "ColorMapping.h" #include "AbstractViewPE.h" #include "ExPrintConsole.h" #include "StepAPFile.h" #include "StepModuleNames.h" // ${STEPGEOM_LIB} isn't linked by default //#include "Entities/StepConnectedFaceSet.h" //#include "Entities/StepCurve.h" GS_TOOLKIT_EXPORT void odgsInitialize(); GS_TOOLKIT_EXPORT void odgsUninitialize(); // // 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(OdStepCoreModule); ODRX_DECLARE_STATIC_MODULE_ENTRY_POINT(OdStepGeomModuleImpl); ODRX_DECLARE_STATIC_MODULE_ENTRY_POINT(OdStepSolidModelerModule); ODRX_DECLARE_STATIC_MODULE_ENTRY_POINT(OdStepBrepBuilderModule); ODRX_DECLARE_STATIC_MODULE_ENTRY_POINT(OdZipIOModule); ODRX_DECLARE_STATIC_MODULE_ENTRY_POINT(OdRxThreadPoolService); ODRX_BEGIN_STATIC_MODULE_MAP() ODRX_DEFINE_STATIC_APPMODULE(OdSDAIModuleName, OdSDAIModule) ODRX_DEFINE_STATIC_APPMODULE(OdStepCoreModuleName, OdStepCoreModule) ODRX_DEFINE_STATIC_APPMODULE(OdStepGeomModuleName, OdStepGeomModuleImpl) ODRX_DEFINE_STATIC_APPMODULE(OdStepSolidModelerModuleName, OdStepSolidModelerModule) ODRX_DEFINE_STATIC_APPMODULE(OdStepBrepBuilderModuleName, OdStepBrepBuilderModule) ODRX_DEFINE_STATIC_APPMODULE(OdZIPIOModuleName, OdZipIOModule) ODRX_DEFINE_STATIC_APPMODULE(OdThreadPoolModuleName, OdRxThreadPoolService) ODRX_END_STATIC_MODULE_MAP() #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"\nExStepVectorize 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: ExStepVectorize [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 StepCore */ /**********************************************************************/ odStepInitialize(false /* No CDA */, true); try { OdStepFilePtr pDatabase = svcs.readFile(szSource); if (pDatabase.isNull()) throw OdError(eCantOpenFile); OdGsDevicePtr pSimpleDevice = ExGsSimpleDevice::createObject(ExGsSimpleDevice::k3dDevice); OdGiContextForStepDatabasePtr pStepContext = OdGiContextForStepDatabase::createObject(); pStepContext->setDatabase(pDatabase); pStepContext->enableGsModel(true); const ODCOLORREF* palette = odcmAcadPalette(ODRGB(255, 255, 255)); OdArray > pPalCpy; ODCOLORREF background(ODRGB(192, 192, 192)); pSimpleDevice->setBackgroundColor(background); pStepContext->setPaletteBackground(background); pPalCpy.insert(pPalCpy.begin(), palette, palette + 256); pSimpleDevice->setLogicalPalette(pPalCpy.asArrayPtr(), 256); OdGsDevicePtr pDevice = OdStepGsManager::setupActiveLayoutViews(pSimpleDevice, pStepContext); 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. 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 StepCore */ /**********************************************************************/ odStepUninitialize(); /**********************************************************************/ /* Uninitialize ODA SDK */ /**********************************************************************/ odgsUninitialize(); odrxUninitialize(); return nRes; }