/////////////////////////////////////////////////////////////////////////////// // 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 "ExternalTableDataModule.h" #define STL_USING_MAP #include "OdaSTL.h" #include "daiStepFile.h" ODRX_DEFINE_DYNAMIC_MODULE(OdExternalTableDataModule); class OdExternalTableDataImpl { public: OdExternalTableDataImpl() {}; void setHostAppServices(OdStepHostAppServices* pServices) { m_pServices = pServices; } int loadDatabase(const OdAnsiString& name, const OdAnsiString& version = OdAnsiString()); OdRxObjectPtr getDatabaseObject(const OdAnsiString& objectName, int databaseId, const OdAnsiString& isKindOf = OdAnsiString()); bool unloadDatabase(int databaseId); private: OdStepHostAppServicesPtr m_pServices; std::map m_pLoadedDatabases; }; int OdExternalTableDataImpl::loadDatabase(const OdAnsiString& name, const OdAnsiString& version) { if (m_pServices.isNull()) { ODA_FAIL_M("m_pServices is null."); return -2; } OdString filePath; if (!name.isEmpty()) { OdString fileName(name); fileName.makeLower(); if (fileName.find(L".stp") < 0 && fileName.find(L".step") < 0) { fileName += L".stp"; } filePath = m_pServices->findFile(L"Cis2Database/" + OdString(fileName)); if (filePath.isEmpty() && !version.isEmpty()) { int pos = fileName.reverseFind(*L".", fileName.getLength() - 3); fileName.insert(pos, L"_" + OdString(version)); filePath = m_pServices->findFile(L"Cis2Database/" + OdString(fileName)); } } if (filePath.isEmpty()) filePath = m_pServices->findFile(L"Cis2Database/aisc-shape.stp"); if (filePath.isEmpty()) { ODA_FAIL_M("filePath is empty."); return -1; } for (const auto& it : m_pLoadedDatabases) { if (!it.second->getFileName().compare(filePath)) return it.first; } if (!filePath.isEmpty()) { OdStepFilePtr pDatabaseFile = m_pServices->readFile(filePath); if (pDatabaseFile) { static int uniqueIndex = 0; m_pLoadedDatabases.insert({ ++uniqueIndex, pDatabaseFile }); return uniqueIndex; } else { ODA_FAIL_M("OdStepFile is empty."); } } else { ODA_FAIL_M("Wrong database path"); } return -1; } OdRxObjectPtr OdExternalTableDataImpl::getDatabaseObject(const OdAnsiString& objectName, int databaseId, const OdAnsiString& isKindOf) { if (m_pLoadedDatabases.find(databaseId) == m_pLoadedDatabases.cend()) { ODA_FAIL_M("Wrong database Id"); return OdStep::OdStepCompoundPtr(); } OdDAI::ModelPtr pModel = m_pLoadedDatabases[databaseId]->getModel(); if (!isKindOf.isEmpty()) { const OdDAI::SetOfOdDAIObjectId* pExtent = pModel->getEntityExtent(isKindOf); if (pExtent && pExtent->getMemberCount()) { OdDAIObjectId id; OdAnsiString itemName; for (auto it = pExtent->createConstIterator(); it->next();) { if (it->getCurrentMember() >> id) { if (id.openObject()->getAttr("item_name") >> itemName) { if (!objectName.compare(itemName)) { return m_pLoadedDatabases[databaseId]->getCompound(id); } } } } } } else { OdAnsiString itemName; for (auto it = pModel->newIterator(); !it->done(); it->step()) { if (it->id().openObject()->getAttr("name") >> itemName) { if (!objectName.compare(itemName)) { return m_pLoadedDatabases[databaseId]->getCompound(it->id()); } } } } return OdStep::OdStepCompoundPtr(); } bool OdExternalTableDataImpl::unloadDatabase(int databaseId) { if (m_pLoadedDatabases.find(databaseId) == m_pLoadedDatabases.cend()) return false; m_pLoadedDatabases.erase(databaseId); return true; } ////////////////////////////////// void OdExternalTableDataModule::initApp() { m_pImpl = new OdExternalTableDataImpl(); } void OdExternalTableDataModule::uninitApp() { delete m_pImpl; } void OdExternalTableDataModule::setHostAppServices(OdStepHostAppServices* pServices) { m_pImpl->setHostAppServices(pServices); } int OdExternalTableDataModule::loadDatabase(const OdAnsiString& name, const OdAnsiString& version) { return m_pImpl->loadDatabase(name, version); } OdRxObjectPtr OdExternalTableDataModule::getDatabaseObject(const OdAnsiString& objectName, int databaseId, const OdAnsiString& isKindOf) { return m_pImpl->getDatabaseObject(objectName, databaseId, isKindOf); } bool OdExternalTableDataModule::unloadDatabase(int databaseId) { return m_pImpl->unloadDatabase(databaseId); }