/////////////////////////////////////////////////////////////////////////////// // 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_07.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_07::Tutorial_07(const OdString& applicationName) : BaseIfcTutorial(applicationName) { m_tutorialArgsParser .add_param( std::make_shared>(m_ifcFile, "ifc_file", ".ifc file where binary data should be inserted", 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 attribute of IfcBlobTexture) to place binary data", false)); m_tutorialArgsParser .add_param( std::make_shared>(m_inputFile, "input_file", "binary file to assign into attribute (e.g. *.png file with picture)", false)); m_tutorialArgsParser .add_param( std::make_shared(m_noWait, "-NoWait", "disable \"press any key\" on finish.")); //odPrintConsoleString(L"\n\nusage: ExIfcTutorials 7 [--help] [ifc_file instance_id attribute input_file]"); //odPrintConsoleString(L"\n--help - show tutorial parameters help"); //odPrintConsoleString(L"ifc_file - .ifc file where we should insert binary value\n"); //odPrintConsoleString(L"instance_id - instance id with binary attribute\n"); //odPrintConsoleString(L"attribute - name of binary attribute\n"); //odPrintConsoleString(L"input_file - file with data for binary value\n"); } int Tutorial_07::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't get binary from attribute. Press any key to finish...\n")); if (m_noWait == false) { getchar(); } return -1; } try { std::ifstream streamToRead; streamToRead.open(static_cast(m_inputFile).c_str(), std::ifstream::ate | std::ifstream::binary); std::streampos sizeOfFile = streamToRead.tellg(); streamToRead.seekg(0, std::ios_base::beg); OdArray buffer; buffer.resize(static_cast(sizeOfFile)); streamToRead.read(reinterpret_cast(&buffer[0]), buffer.size()); binary->setMemory(buffer); pFile->writeFile(m_ifcFile); } catch (...) { return -1; } return 0; }