/////////////////////////////////////////////////////////////////////////////// // 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 "ExIfcTutorial_06.h" #include "daiUtils/daiUtils.h" #include "daiBinary.h" #include "daiApplicationInstance.h" #include // try to extract picture from binary attribute // params [ifc_file] [instance_handle] [attribute] [output_file] Tutorial_06::Tutorial_06(const OdString& applicationName) : BaseIfcTutorial(applicationName) { m_tutorialArgsParser .add_param( std::make_shared>(m_ifcFile, "ifc_file", "input .ifc file with instance that has attribute of BINARY type.", false)); m_tutorialArgsParser .add_param( std::make_shared>(m_instanceId, "instance_id", "instance id with binary attribute (e.g. instance of IfcBlobTexture)", false)); m_tutorialArgsParser .add_param( std::make_shared>(m_binaryAttributeName, "attribute", "name of attribute with binary data (e.g. RasterCode of IfcBlobTexture)", false)); m_tutorialArgsParser .add_param( std::make_shared>(m_outputFile, "out_file", "output binary file to write (e.g. Picture.png if IfcBlobTexture.RasterFormat is 'png')", false)); m_tutorialArgsParser .add_param( std::make_shared(m_noWait, "-NoWait", "disable \"press any key\" on finish.")); //odPrintConsoleString(L"\n\nusage: ExIfcTutorials 6 [--help] [ifc_file instance_id attribute out_file]"); //odPrintConsoleString(L"\n--help - show tutorial parameters help"); //odPrintConsoleString(L"ifc_file - input .ifc file\n"); //odPrintConsoleString(L"instance_id - instance id with binary attribute\n"); //odPrintConsoleString(L"attribute - name of binary attribute\n"); //odPrintConsoleString(L"out_file - output file to save binary\n"); } int Tutorial_06::run(const MyServices& svcs, const std::vector& argumentList, std::ostream& resultStream) { auto parseResult = BaseIfcTutorial::run(svcs, argumentList, resultStream); if (parseResult != 0) { return parseResult; } OdIfcFilePtr pFile = svcs.createDatabase(); OdResult res = pFile->readFile(m_ifcFile); if (res == eOk) { odPrintConsoleString(OD_T("\nFile opened successfully.\n")); } else { odPrintConsoleString(OD_T("\nFile open error. Press any key to finish...")); if (m_noWait == false) { getchar(); } return res; } odPrintConsoleString(OD_T("\nRetrieving property information\n")); OdIfcModelPtr pModel = pFile->getModel(); if (pModel.isNull()) { odPrintConsoleString(OD_T("\nModel is not valid. Press any key to finish...\n")); if (m_noWait == false) { getchar(); } return -1; } OdDAI::ApplicationInstancePtr instance = pModel->getEntityInstance(m_instanceId).openObject(); if (instance.isNull()) { odPrintConsoleString(OD_T("\nInstance was not found. Press any key to finish...\n")); if (m_noWait == false) { getchar(); } return -1; } OdDAI::Binary* binary; if ((instance->getAttr(m_binaryAttributeName) >> binary) == false) { odPrintConsoleString(OD_T("\nCan' get binary from attribute. Press any key to finish...\n")); if (m_noWait == false) { getchar(); } return -1; } OdArray buffer; binary->getMemory(buffer); std::fstream streamToWrite; streamToWrite.open(static_cast(m_outputFile).c_str(), std::fstream::out | std::fstream::binary); streamToWrite.write(reinterpret_cast(&buffer[0]), buffer.size()); return 0; }