当前位置: 首页>>代码示例>>C++>>正文


C++ WorkspaceObject::getExtensibleGroup方法代码示例

本文整理汇总了C++中WorkspaceObject::getExtensibleGroup方法的典型用法代码示例。如果您正苦于以下问题:C++ WorkspaceObject::getExtensibleGroup方法的具体用法?C++ WorkspaceObject::getExtensibleGroup怎么用?C++ WorkspaceObject::getExtensibleGroup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WorkspaceObject的用法示例。


在下文中一共展示了WorkspaceObject::getExtensibleGroup方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: translateConstruction

OptionalModelObject ReverseTranslator::translateConstruction( const WorkspaceObject & workspaceObject )
{
  if( workspaceObject.iddObject().type() != IddObjectType::Construction ){
    LOG(Error, "WorkspaceObject is not IddObjectType: Construction");
    return boost::none;
  }

  Construction construction(m_model);
  OS_ASSERT(construction.numLayers() == 0u);
  OptionalString optS = workspaceObject.name();
  if (optS) {
    construction.setName(*optS);
  }

  unsigned n = workspaceObject.numExtensibleGroups();
  // now we get the workspace objects and try to find them and place them in the model object
  // Loop over all the fields except the first, which is the name
  OptionalWorkspaceObject owo;
  OptionalModelObject temp;
  for( unsigned i = 0; i < n; ++i) {
    owo = workspaceObject.getExtensibleGroup(i).cast<WorkspaceExtensibleGroup>().getTarget(ConstructionExtensibleFields::Layer);
    if( owo ) {
      temp = translateAndMapWorkspaceObject( *owo );
    }
    if( ! (owo && temp) )
    {
      LOG(Error, "Finding Construction Layer in workspace failed.");
      construction.remove();
      return boost::none;
    }
    // Assuming names of materials are unique
    OptionalMaterial mat = temp->optionalCast<Material>();

    bool inserted(false);
    if (mat) {
      OptionalOpaqueMaterial opaqueMaterial = mat->optionalCast<OpaqueMaterial>();
      if(opaqueMaterial) {
        inserted = construction.insertLayer(i, *opaqueMaterial);
      }
      else {
        OptionalFenestrationMaterial fenestrationMaterial = mat->optionalCast<FenestrationMaterial>();
        if (fenestrationMaterial) {
          inserted = construction.insertLayer(i, *fenestrationMaterial );
        }
        else {
          OptionalModelPartitionMaterial modelPartitionMaterial = mat->optionalCast<ModelPartitionMaterial>();
          if (modelPartitionMaterial) {
            if (construction.numLayers() == 0u) {
              inserted = construction.setLayer(*modelPartitionMaterial);
            }
          }
        }
      }
    }

    if( !inserted ) {
      LOG(Error, "Insertion of Construction Layer failed.");
      construction.remove();
      return boost::none;
    }
  }

  return construction;
}
开发者ID:ChengXinDL,项目名称:OpenStudio,代码行数:64,代码来源:ReverseTranslateConstruction.cpp

示例2: translateEnergyManagementSystemSubroutine

OptionalModelObject ReverseTranslator::translateEnergyManagementSystemSubroutine(const WorkspaceObject & workspaceObject)
{
  if (workspaceObject.iddObject().type() != IddObjectType::EnergyManagementSystem_Subroutine) {
    LOG(Error, "WorkspaceObject is not IddObjectType: EnergyManagementSystem_Subroutine");
    return boost::none;
  }

  OptionalString s = workspaceObject.getString(EnergyManagementSystem_SubroutineFields::Name);
  if (!s) {
    LOG(Error, "WorkspaceObject EnergyManagementSystem_Subroutine has no Name");
    return boost::none;
  }

  // Make sure we translate the objects that can be referenced here
  for (const WorkspaceObject& workspaceObject : m_workspace.objects()) {

    // Note: JM 2018-08-17
    // I think an EMS:Subroutine can reference another EMS:Subroutine, we might get problems from that:
    // The one that is being referenced would need be translated before the one that references before the name/uuid substitution happen.
    // But it's harder to control that order*, and this is really an edge case though, so not handling it.
    // * Can't add this condition without getting into a loop:
    // (workspaceObject.iddObject().type() == IddObjectType::EnergyManagementSystem_Subroutine)
    if (
        // These I'm sure we do need.
        (workspaceObject.iddObject().type() == IddObjectType::EnergyManagementSystem_Actuator)
        || (workspaceObject.iddObject().type() == IddObjectType::EnergyManagementSystem_Sensor)
        || (workspaceObject.iddObject().type() == IddObjectType::EnergyManagementSystem_ConstructionIndexVariable)
        || (workspaceObject.iddObject().type() == IddObjectType::EnergyManagementSystem_CurveOrTableIndexVariable)
        || (workspaceObject.iddObject().type() == IddObjectType::EnergyManagementSystem_GlobalVariable)
        || (workspaceObject.iddObject().type() == IddObjectType::EnergyManagementSystem_InternalVariable)
        || (workspaceObject.iddObject().type() == IddObjectType::EnergyManagementSystem_TrendVariable)
       ) {
      translateAndMapWorkspaceObject(workspaceObject);
    }
  }
  openstudio::model::EnergyManagementSystemSubroutine emsProgram(m_model);
  emsProgram.setName(*s);

  // Get all model objects that can be referenced int he EMS Program so we can do name / uid substitution
  const std::vector<IddObjectType> validIddObjectTypes{
    IddObjectType::OS_EnergyManagementSystem_Subroutine,
    IddObjectType::OS_EnergyManagementSystem_Actuator,
    IddObjectType::OS_EnergyManagementSystem_Sensor,
    IddObjectType::OS_EnergyManagementSystem_ConstructionIndexVariable,
    IddObjectType::OS_EnergyManagementSystem_CurveOrTableIndexVariable,
    IddObjectType::OS_EnergyManagementSystem_GlobalVariable,
    IddObjectType::OS_EnergyManagementSystem_InternalVariable,
    IddObjectType::OS_EnergyManagementSystem_TrendVariable
  };

  std::vector<model::ModelObject> modelObjects;
  for (const model::ModelObject& mo: m_model.modelObjects()) {
    if( std::find(validIddObjectTypes.begin(), validIddObjectTypes.end(), mo.iddObjectType()) != validIddObjectTypes.end() ) {
      modelObjects.push_back(mo);
    }
  }


  // Now, we should do the actual name/uid substitution on all lines of the program

  size_t pos, len;
  std::string newline, uid;

  unsigned n = workspaceObject.numExtensibleGroups();
  OptionalString line;

  // Loop on each line of the program
  for (unsigned i = 0; i < n; ++i) {
    line = workspaceObject.getExtensibleGroup(i).cast<WorkspaceExtensibleGroup>().getString(EnergyManagementSystem_SubroutineExtensibleFields::ProgramLine);
    if (line) {
      newline = line.get();

      // Split line to get 'tokens' and look for ModelObject names
      // splitEMSLineToTokens returns already sanitized tokens (excludes reserved keywords, blank ones, functions, removes parenthesis, etc)
      std::vector<std::string> tokens = splitEMSLineToTokens(newline);

      for (std::string& token: tokens) {
        for (const model::ModelObject& mo: modelObjects) {
          // Check if program item is the name of a model object
          boost::optional<std::string> _name = mo.name();
          if ( _name && (_name.get() == token) ) {
            // replace model object's name with its handle
            pos = newline.find(token);
            len = token.length();
            uid = toString(mo.handle());
            newline.replace(pos, len, uid);
            // Now that we have done the replacement, no need to keep looping.
            // Plus, we should break out of the nested loop and go to the next "j"
            // Otherwise pos could become giberish if there's another object named the same
            // since it won't be able to find the already-replaced string (this shouldn't happen though)
            break;
          }
        } // end loop on all modelObjects

      } // end loop on all results in line
      emsProgram.addLine(newline);
    } // end if(line)
  } // End loop on each line of the program

  return emsProgram;
//.........这里部分代码省略.........
开发者ID:NREL,项目名称:OpenStudio,代码行数:101,代码来源:ReverseTranslateEnergyManagementSystemSubroutine.cpp

示例3: table

TEST_F(EnergyPlusFixture,ForwardTranslator_TableMultiVariableLookup)
{
  {
    Model m;
    TableMultiVariableLookup table(m,1);

    ASSERT_TRUE(table.addPoint(70,0.1));
    ASSERT_TRUE(table.addPoint(72,0.3));
    ASSERT_TRUE(table.addPoint(74,0.5));
    ASSERT_TRUE(table.addPoint(76,0.7));
    ASSERT_TRUE(table.addPoint(78,0.9));

    ForwardTranslator ft;
    Workspace workspace = ft.translateModel(m);

    std::vector<WorkspaceObject> tableObjects = workspace.getObjectsByType(IddObjectType::Table_MultiVariableLookup);
    ASSERT_EQ(1u, tableObjects.size());

    WorkspaceObject idfTable = tableObjects.front();

    ASSERT_EQ(idfTable.getString(Table_MultiVariableLookupFields::InterpolationMethod).get(),"LagrangeInterpolationLinearExtrapolation");
    ASSERT_EQ(idfTable.getInt(Table_MultiVariableLookupFields::NumberofInterpolationPoints).get(),3);
    ASSERT_EQ(idfTable.getString(Table_MultiVariableLookupFields::TableDataFormat).get(),"SingleLineIndependentVariableWithMatrix");
    ASSERT_EQ(idfTable.getString(Table_MultiVariableLookupFields::X1SortOrder).get(),"Ascending");
    ASSERT_EQ(idfTable.getString(Table_MultiVariableLookupFields::X2SortOrder).get(),"Ascending");
    ASSERT_EQ(idfTable.getString(Table_MultiVariableLookupFields::InputUnitTypeforX1).get(),"Dimensionless");
    ASSERT_EQ(idfTable.getString(Table_MultiVariableLookupFields::InputUnitTypeforX2).get(),"Dimensionless");
    ASSERT_EQ(idfTable.getString(Table_MultiVariableLookupFields::InputUnitTypeforX3).get(),"Dimensionless");
    ASSERT_EQ(idfTable.getString(Table_MultiVariableLookupFields::InputUnitTypeforX4).get(),"Dimensionless");
    ASSERT_EQ(idfTable.getString(Table_MultiVariableLookupFields::InputUnitTypeforX5).get(),"Dimensionless");
    ASSERT_EQ(idfTable.getString(Table_MultiVariableLookupFields::OutputUnitType).get(),"Dimensionless");
    ASSERT_EQ(idfTable.getInt(Table_MultiVariableLookupFields::NumberofIndependentVariables).get(),1);
    ASSERT_DOUBLE_EQ(idfTable.getExtensibleGroup(0).getDouble(Table_MultiVariableLookupExtensibleFields::Data).get(),5);
    ASSERT_DOUBLE_EQ(idfTable.getExtensibleGroup(1).getDouble(Table_MultiVariableLookupExtensibleFields::Data).get(),70);
    ASSERT_DOUBLE_EQ(idfTable.getExtensibleGroup(2).getDouble(Table_MultiVariableLookupExtensibleFields::Data).get(),72);
    ASSERT_DOUBLE_EQ(idfTable.getExtensibleGroup(3).getDouble(Table_MultiVariableLookupExtensibleFields::Data).get(),74);
    ASSERT_DOUBLE_EQ(idfTable.getExtensibleGroup(4).getDouble(Table_MultiVariableLookupExtensibleFields::Data).get(),76);
    ASSERT_DOUBLE_EQ(idfTable.getExtensibleGroup(5).getDouble(Table_MultiVariableLookupExtensibleFields::Data).get(),78);
    ASSERT_DOUBLE_EQ(idfTable.getExtensibleGroup(6).getDouble(Table_MultiVariableLookupExtensibleFields::Data).get(),0.1);
    ASSERT_DOUBLE_EQ(idfTable.getExtensibleGroup(7).getDouble(Table_MultiVariableLookupExtensibleFields::Data).get(),0.3);
    ASSERT_DOUBLE_EQ(idfTable.getExtensibleGroup(8).getDouble(Table_MultiVariableLookupExtensibleFields::Data).get(),0.5);
    ASSERT_DOUBLE_EQ(idfTable.getExtensibleGroup(9).getDouble(Table_MultiVariableLookupExtensibleFields::Data).get(),0.7);
    ASSERT_DOUBLE_EQ(idfTable.getExtensibleGroup(10).getDouble(Table_MultiVariableLookupExtensibleFields::Data).get(),0.9);
  }

  {
    Model m;
    TableMultiVariableLookup table(m,2);

    ASSERT_TRUE(table.addPoint(70,32,0.1));
    ASSERT_TRUE(table.addPoint(72,32,0.3));
    ASSERT_TRUE(table.addPoint(74,32,0.5));
    ASSERT_TRUE(table.addPoint(76,32,0.7));
    ASSERT_TRUE(table.addPoint(78,32,0.9));

    ASSERT_TRUE(table.addPoint(70,45,0.2));
    ASSERT_TRUE(table.addPoint(72,45,0.4));
    ASSERT_TRUE(table.addPoint(74,45,0.6));
    ASSERT_TRUE(table.addPoint(76,45,0.8));
    ASSERT_TRUE(table.addPoint(78,45,1.0));

    ASSERT_TRUE(table.addPoint(70,68,0.3));
    ASSERT_TRUE(table.addPoint(72,68,0.5));
    ASSERT_TRUE(table.addPoint(74,68,0.7));
    ASSERT_TRUE(table.addPoint(76,68,0.9));
    ASSERT_TRUE(table.addPoint(78,68,1.1));

    ASSERT_TRUE(table.addPoint(70,81,0.4));
    ASSERT_TRUE(table.addPoint(72,81,0.6));
    ASSERT_TRUE(table.addPoint(74,81,0.8));
    ASSERT_TRUE(table.addPoint(76,81,1.0));
    ASSERT_TRUE(table.addPoint(78,81,1.2));

    ASSERT_TRUE(table.addPoint(70,94,0.5));
    ASSERT_TRUE(table.addPoint(72,94,0.7));
    ASSERT_TRUE(table.addPoint(74,94,0.9));
    ASSERT_TRUE(table.addPoint(76,94,1.1));
    ASSERT_TRUE(table.addPoint(78,94,1.3));

    ASSERT_TRUE(table.addPoint(70,107,0.6));
    ASSERT_TRUE(table.addPoint(72,107,0.8));
    ASSERT_TRUE(table.addPoint(74,107,1.0));
    ASSERT_TRUE(table.addPoint(76,107,1.2));
    ASSERT_TRUE(table.addPoint(78,107,1.4));

    ForwardTranslator ft;
    Workspace workspace = ft.translateModel(m);

    std::vector<WorkspaceObject> tableObjects = workspace.getObjectsByType(IddObjectType::Table_MultiVariableLookup);
    ASSERT_EQ(1u, tableObjects.size());

    WorkspaceObject idfTable = tableObjects.front();
    ASSERT_EQ(idfTable.getString(Table_MultiVariableLookupFields::InterpolationMethod).get(),"LagrangeInterpolationLinearExtrapolation");
    ASSERT_EQ(idfTable.getInt(Table_MultiVariableLookupFields::NumberofInterpolationPoints).get(),3);
    ASSERT_EQ(idfTable.getString(Table_MultiVariableLookupFields::TableDataFormat).get(),"SingleLineIndependentVariableWithMatrix");
    ASSERT_EQ(idfTable.getString(Table_MultiVariableLookupFields::X1SortOrder).get(),"Ascending");
    ASSERT_EQ(idfTable.getString(Table_MultiVariableLookupFields::X2SortOrder).get(),"Ascending");
    ASSERT_EQ(idfTable.getString(Table_MultiVariableLookupFields::InputUnitTypeforX1).get(),"Dimensionless");
    ASSERT_EQ(idfTable.getString(Table_MultiVariableLookupFields::InputUnitTypeforX2).get(),"Dimensionless");
    ASSERT_EQ(idfTable.getString(Table_MultiVariableLookupFields::InputUnitTypeforX3).get(),"Dimensionless");
//.........这里部分代码省略.........
开发者ID:NREL,项目名称:OpenStudio,代码行数:101,代码来源:TableMultiVariableLookup_GTest.cpp


注:本文中的WorkspaceObject::getExtensibleGroup方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。