/////////////////////////////////////////////////////////////////////////////// // 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. /////////////////////////////////////////////////////////////////////////////// /***/ /***/ // ODA SDK includes #include #include #include // System includes #include #include // SDAI includes #include #include // IFC SDK includes #include #include #include "Common/examples/daiSimpleProgramOptions.h" /***/ // // Define module map for statically linked modules: // #if !defined(_TOOLKIT_IN_DLL_) INIT_IFC_STATIC_MODULES_NO_GEOM; #endif /***/ enum AppResult { arOk = 0, arIncorrectUsage, arFileOpenError, arEmptySectionHeader, arInvalidSchema, arUnsupportedSchema, arEmptyModel, arOdError, arUnexpectedError }; /***/ class ModelLoader { OdAnsiString m_fileName; OdIfcFilePtr m_ifcFile; bool m_internallyInitialized{ false }; OdStaticRxObject< MyServices > svcs; public: ModelLoader(OdAnsiString fileName) : m_fileName(fileName) { if (odrxDynamicLinker() == nullptr) { odrxInitialize(&svcs); odIfcInitialize(false, false); m_internallyInitialized = true; odPrintConsoleString(OD_T("\nODA IFC SDK is initialized.\n")); } } ~ModelLoader() { m_ifcFile = nullptr; if (m_internallyInitialized) { odIfcUninitialize(); odrxUninitialize(); odPrintConsoleString(OD_T("\nODA IFC SDK is uninitialized.\n")); } } OdDAI::ModelPtr load() { m_ifcFile = svcs.readFile(m_fileName); if (!m_ifcFile) { return nullptr; } return m_ifcFile->getModel(); } }; int main(int argc, char* argv[]) { setlocale(LC_TIME, ""); // set current user locale (not OD_T("C")), for strftime #if !defined(_TOOLKIT_IN_DLL_) ODRX_INIT_STATIC_MODULE_MAP(); #endif std::vector inFileNames; using namespace OdDAI::utils; argv_parser commandLineParser(OD_T("ExIfcInitUninit")); commandLineParser.add_param(std::make_shared>(inFileNames, "-filename", "input .ifc or .ifczip files.", false)); std::vector argumentList(argv + 1, argv + argc); std::stringstream executionStream; if (commandLineParser.parse(argumentList, executionStream) != OdDAI::utils::ParseResult::succeed) { odPrintConsoleString(OD_T("\nExIfcInitUninit sample program. Copyright (c) 2025, Open Design Alliance\n")); odPrintConsoleString(OdString(executionStream.str().c_str())); odPrintConsoleString(OdString(OD_T("Example command line: ExIfcInitUninit -filename=\"filename1.ifc\" -filename=\"filename1.ifc\" -filename=\"filenameN.ifc\""))); return arIncorrectUsage; } //#define _INIT_OUTSIDE #ifdef _INIT_OUTSIDE OdStaticRxObject< MyServices > svcs; odrxInitialize(&svcs); odIfcInitialize(false, false); #endif //#define _GLOBAL_RX_VALUE #ifdef _GLOBAL_RX_VALUE OdRxValue val; // Incorrect: Program will crash as OdRxValue exists longer than its OdRxValueType which is destructed on uninitialization #endif for (const OdString &fname : inFileNames) { OdAnsiString ansiFName(fname); ModelLoader loader(ansiFName); OdDAI::ModelPtr model = loader.load(); if (!model) { return arFileOpenError; } odPrintConsoleString(OD_T("\nModel loaded successfully.\n")); OdDAI::InstanceIteratorPtr it = model->newIterator(); for (; !it->done(); it->step()) { OdDAIObjectId id = it->id(); OdDAI::ApplicationInstancePtr instance = id.openObject(); OdDAI::EntityPtr entity = instance->getInstanceType(); const OdDAI::AttributeSet &attributes = entity->attributes(); for (const auto &attr : attributes.getArray()) { #ifndef _GLOBAL_RX_VALUE OdRxValue val; // Works ok as OdRxValue is destructed before uninitialization #endif val = instance->getAttr(attr->name()); } } } #ifdef _INIT_OUTSIDE odIfcUninitialize(); odrxUninitialize(); #endif return arOk; }