Exemplo n.º 1
0
OSItem* OSItem::makeItem(const OSItemId& itemId, OSItemType osItemType)
{
  OSItem* result = nullptr;

  OSAppBase* app = OSAppBase::instance();

  if(itemId.sourceId() == OSItemId::BCL_SOURCE_ID)
  {
    boost::optional<BCLComponent> comp = LocalBCL::instance().getComponent(itemId.itemId().toStdString());
    if( comp )
    {
      result = new BCLComponentItem(comp.get(),osItemType);
    }
  }
  else
  {
    boost::optional<model::ModelObject> modelObject = app->currentDocument()->getModelObject(itemId);
    if (modelObject){
      result = new ModelObjectItem(*modelObject,itemId.isDefaulted(),osItemType);
    } else {
      openstudio::path p = openstudio::toPath(itemId.itemId());
      if (openstudio::filesystem::exists(p))
      {
        result = new ScriptItem(p, osItemType);
      }
    }
  }
  return result;
}
void ConstructionObjectVectorController::onRemoveItem(OSItem * item)
{
  if(m_modelObject){
    model::LayeredConstruction construction = m_modelObject->cast<model::LayeredConstruction>();
    std::vector<model::Material> layers = construction.layers();
    OSAppBase * app = OSAppBase::instance();
    unsigned idx = 0;
    for (model::Material layer : layers){
      boost::optional<model::ModelObject> modelObject = app->currentDocument()->getModelObject(item->itemId());
      if(modelObject){
        if(modelObject->handle() == layer.handle()){
          construction.eraseLayer(idx);
          break;
        }
        idx++;
      }
    }
  }
}