/////////////////////////////////////////////////////////////////////////////// // 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 "StaticRxObject.h" #include "RxDynamicModule.h" #include "OdPerfTimer.h" #include "IfcCore.h" #include "IfcExamplesCommon.h" #include "daiSimpleProgramOptions.h" #include "daiErrorEventListOutput.h" // // Define module map for statically linked modules: // #if !defined(_TOOLKIT_IN_DLL_) INIT_IFC_STATIC_MODULES_NO_GEOM; #endif #include #include namespace { const OdString logErrorKeyword = OD_T("readErrorLogIsOn"); } /************************************************************************/ /* 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("\nExIfcReadFile developed using %ls ver %ls"), svcs.product().c_str(), svcs.versionString().c_str()); OdString ifcInFileName; OdString ifcOutFileName; bool readErrorLogOn = false; bool noWait = false; bool isDebugMode = false; bool noProgress = false; using namespace OdDAI::utils; argv_parser commandLineParser(OD_T("ExIfcReadFile")); commandLineParser.add_param(std::make_shared>(ifcInFileName, "-inFile", "input .ifc or .ifczip file.", false)); commandLineParser.add_param(std::make_shared>(ifcOutFileName, "-outFile", "output .ifc or .ifczip file.", true)); commandLineParser.add_param(std::make_shared(readErrorLogOn, "-readErrorLogIsOn", "turn on error log during file reading.")); commandLineParser.add_param(std::make_shared(noWait, "-noWait", "-disable \"press any key\" on finish.")); commandLineParser.add_param(std::make_shared(isDebugMode, "-isDebug", "Waiting press any key on start process.")); commandLineParser.add_param(std::make_shared(noProgress, "-noProgress", "Disable progress meter output.")); std::vector argumentList(argv + 1, argv + argc); std::stringstream executionStream; if (commandLineParser.parse(argumentList, executionStream) != OdDAI::utils::ParseResult::succeed) { odPrintConsoleString(OD_T("\nExIfcReadFile sample program. Copyright (c) 2025, Open Design Alliance\n")); odPrintConsoleString(OdString(executionStream.str().c_str())); odPrintConsoleString(OD_T("\nPress ENTER to continue...\n")); return ::Utils::res_INVALID_ARGUMENTS.first; } if (isDebugMode == true) { odPrintConsoleString(OD_T("\nDebug mode: Attach to process and then press ENTER to continue.\n")); int removeWarn = getchar(); } if (noProgress) { svcs.disableProgressMeterOutput(true); } /**********************************************************************/ /* Parse Command Line inputs */ /**********************************************************************/ #if !defined(_TOOLKIT_IN_DLL_) ODRX_INIT_STATIC_MODULE_MAP(); #endif /**********************************************************************/ /* Initialize ODA SDK */ /**********************************************************************/ if (odrxInitialize(&svcs) == false) { return ::Utils::res_CAN_NOT_LOAD_SDAI.first; } /**********************************************************************/ /* Initialize IfcCore */ /**********************************************************************/ odIfcInitialize(false /* No CDA */, false /* No geometry calculation needed */); int nRes = ::Utils::res_OK.first; try { OdIfcFilePtr pDatabase; { OdDAI::SessionPtr session = oddaiCreateSession(); if (session.isNull() == true) { throw ::Utils::res_CAN_NOT_CREATE_SESSION; } pDatabase = svcs.createDatabase(); OdDAI::List* errorsList = nullptr; if (readErrorLogOn) { odPrintConsoleString(OD_T("\n%s - error events recording is active: \n"), ::Utils::actionNameEventParamRead.c_str()); session->startEventRecording(); odPrintConsoleString(OD_T("%s - is turned on \n"), ::Utils::actionNameSessionEventRec.c_str()); if (session->getAttrCaseInsensitive("errors") >> errorsList && errorsList) { odPrintConsoleString(OD_T("%s - the list was get successfuly. Lets check this list on errors before read.\n"), ::Utils::actionNameErrorEventList.c_str()); ::Utils::errorEventListOutput(errorsList); } else { odPrintConsoleString(OD_T("%s - cant get list. Error events recording is not available.\n"), ::Utils::actionNameErrorEventList.c_str()); } } OdPerfTimerWrapper timerWrapper; timerWrapper.getTimer()->start(); OdResult res = pDatabase->readFile(ifcInFileName); timerWrapper.getTimer()->stop(); if (readErrorLogOn && errorsList != nullptr) { odPrintConsoleString(OD_T("%s - the file reading was finished. Lets check for new errors after read:\n"), ::Utils::actionNameErrorEventList.c_str()); ::Utils::errorEventListOutput(errorsList); } if (res == eOk) { odPrintConsoleString(OD_T("\nFile opened successfully.")); } else { odPrintConsoleString(OD_T("\nFile reading error: %s"), OdError(res).description().c_str()); } odPrintConsoleString(OD_T("\nOpening time: %d msec"), timerWrapper.getTimer()->countedMSec()); } if (!ifcOutFileName.isEmpty()) { OdPerfTimerWrapper timerWrapper; timerWrapper.getTimer()->start(); OdResult res = pDatabase->writeFile(ifcOutFileName); timerWrapper.getTimer()->stop(); if (res == eOk) { odPrintConsoleString(OD_T("\nFile written successfully.")); } else { odPrintConsoleString(OD_T("\nFile writing error.")); nRes = ::Utils::res_ERROR.first; } odPrintConsoleString(OD_T("\nWriting time: %d msec"), timerWrapper.getTimer()->countedMSec()); } if (noWait == false) { odPrintConsoleString(OD_T("\nPress any key.\n")); int removeWarn = getchar(); } } catch(OdError& e) { odPrintConsoleString(OD_T("\n\nInternal error thrown: %ls"), e.description().c_str()); nRes = ::Utils::res_ERROR.first; } catch(...) { odPrintConsoleString(OD_T("\n\nUnexpected error.")); nRes = ::Utils::res_UNEXPECTED_ERROR.first; } /**********************************************************************/ /* Uninitialize IfcCore */ /**********************************************************************/ odIfcUninitialize(); /**********************************************************************/ /* Uninitialize ODA SDK */ /**********************************************************************/ odrxUninitialize(); return nRes; }