bool OSDocument::fromComponentLibrary(const OSItemId& itemId) const { bool fromCompLibrary = (itemId.sourceId() == modelToSourceId(m_compLibrary)); bool fromHVACCompLibrary = (itemId.sourceId() == modelToSourceId(m_hvacCompLibrary)); bool fromCombinedCompLibrary = (itemId.sourceId() == modelToSourceId(m_combinedCompLibrary)); bool result = (fromCompLibrary || fromHVACCompLibrary || fromCombinedCompLibrary); return result; }
boost::optional<model::ModelObject> OSDocument::getModelObject(const OSItemId& itemId) const { if (fromModel(itemId)){ Handle handle(itemId.itemId()); return m_model.getModelObject<model::ModelObject>(handle); }else if (fromComponentLibrary(itemId)){ if (itemId.sourceId() == modelToSourceId(m_compLibrary)){ Handle handle(itemId.itemId()); return m_compLibrary.getModelObject<model::ModelObject>(handle); }else if (itemId.sourceId() == modelToSourceId(m_hvacCompLibrary)){ Handle handle(itemId.itemId()); return m_hvacCompLibrary.getModelObject<model::ModelObject>(handle); }else if (itemId.sourceId() == modelToSourceId(m_combinedCompLibrary)){ Handle handle(itemId.itemId()); return m_combinedCompLibrary.getModelObject<model::ModelObject>(handle); } } return boost::none; }
boost::optional<model::Component> OSDocument::getComponent(const OSItemId& itemId) const { boost::optional<model::Component> modelComponent; if(itemId.sourceId() == OSItemId::BCL_SOURCE_ID) { boost::optional<BCLComponent> component; component = LocalBCL::instance().getComponent(itemId.itemId().toStdString()); if(component){ std::vector<std::string> oscFiles = component->files("osc"); if(oscFiles.size() == 1u){ openstudio::path oscPath = toPath(oscFiles[0]); #ifdef _WINDOWS if (oscPath.string().size() > MAX_PATH){ if (oscPath.is_complete()){ oscPath = toPath("\\\\?\\") / oscPath; } } #endif //BOOST_ASSERT(boost::filesystem::exists(oscPath)); osversion::VersionTranslator translator; modelComponent = translator.loadComponent(oscPath); } } } return modelComponent; }
bool OSDocument::fromBCL(const OSItemId& itemId) const { return (itemId.sourceId() == OSItemId::BCL_SOURCE_ID); }
bool OSDocument::fromModel(const OSItemId& itemId) const { return (itemId.sourceId() == modelToSourceId(m_model)); }