void ComponentWatcher_Impl::relationshipChange(int index,Handle newHandle,Handle oldHandle) {
   OS_ASSERT(newHandle != oldHandle);
   // if oldHandle is in the Component nullify the component
   HandleVector hs = getHandles<ModelObject>(m_componentObjects);
   if (std::find(hs.begin(),hs.end(),oldHandle) != hs.end()) {
     mf_removeComponent();
     return;
   }
   // otherwise, change version
   mf_changeComponentVersion();
   return;
 }
// Test in context of Workspace, since order needs objectGetter.
TEST_F(IdfFixture,WorkspaceObjectOrder) {
  Workspace workspace(IdfFixture::epIdfFile,openstudio::StrictnessLevel::Draft);

  WorkspaceObjectOrder wsOrder = workspace.order();

  EXPECT_TRUE(wsOrder.inOrder(workspace.objects()[0].handle()));

  // save current order
  OptionalHandleVector workspaceOrder = wsOrder.directOrder();
  ASSERT_TRUE(workspaceOrder);

  // order by enum
  wsOrder.setOrderByIddEnum();
  WorkspaceObjectVector objects = workspace.objects(true);
  for (WorkspaceObjectVector::const_iterator it = objects.begin(), itEnd = objects.end() - 1;
       it != itEnd; ++ it) {
    WorkspaceObjectVector::const_iterator nxt = it; ++nxt;
    EXPECT_TRUE(it->iddObject().type() <= nxt->iddObject().type());
  }

  // restore order
  wsOrder.setDirectOrder(*workspaceOrder);
  HandleVector handles = workspace.handles(true);
  // handles does not include version object, while direct order does
  HandleVector tempOrder = *workspaceOrder;
  HandleVector::iterator it = std::find(tempOrder.begin(),tempOrder.end(),workspace.versionObject()->handle());
  tempOrder.erase(it);
  EXPECT_TRUE(tempOrder == handles);

  // move objects directly
  wsOrder.insert(handles[32],handles[12]);
  HandleVector newOrder = workspace.handles(true);
  EXPECT_EQ(handles.size(),newOrder.size());
  EXPECT_TRUE(handles[32] == newOrder[12]);
  EXPECT_TRUE(handles[12] == newOrder[13]);

  wsOrder.swap(handles[80],handles[100]);
  newOrder = workspace.handles(true);
  EXPECT_EQ(handles.size(),newOrder.size());
  EXPECT_TRUE(handles[80] == newOrder[100]);
  EXPECT_TRUE(handles[100] == newOrder[80]);
}
Пример #3
0
TEST_F(ModelFixture, MeterFromModel)
{
  Model model;

  IdfObjectVector idfObjects;

  idfObjects.push_back(IdfObject(IddObjectType::OS_Meter));
  idfObjects.back().setString(OS_MeterFields::Name,"Electricity:Facility");
  idfObjects.back().setString(OS_MeterFields::ReportingFrequency,"monthly");
  idfObjects.back().setString(OS_MeterFields::MeterFileOnly,"false");

  LOG(Debug,"Meter text: " << std::endl << idfObjects.back());

  idfObjects.push_back(IdfObject(IddObjectType::OS_Meter));
  idfObjects.back().setString(OS_MeterFields::Name,"Gas:Building");
  idfObjects.back().setString(OS_MeterFields::ReportingFrequency,"hourly");

  idfObjects.push_back(IdfObject(IddObjectType::OS_Meter));
  idfObjects.back().setString(OS_MeterFields::Name,"InteriorLights:Electricity");
  idfObjects.back().setString(OS_MeterFields::ReportingFrequency,"runperiod");
  idfObjects.back().setString(OS_MeterFields::MeterFileOnly,"false");
  idfObjects.back().setString(OS_MeterFields::Cumulative,"true");

  idfObjects.push_back(IdfObject(IddObjectType::OS_Meter));
  idfObjects.back().setString(OS_MeterFields::Name,"General:InteriorLights:Electricity:Zone:North Zone");
  idfObjects.back().setString(OS_MeterFields::ReportingFrequency,"daily");
  idfObjects.back().setString(OS_MeterFields::Cumulative,"true");

  EXPECT_EQ(static_cast<unsigned>(4), idfObjects.size());

  HandleVector handles = getHandles(model.addObjects(idfObjects));
  ASSERT_EQ(static_cast<unsigned>(4), handles.size());
  EXPECT_EQ(static_cast<unsigned>(4), model.getModelObjects<Meter>().size());

  //"Output:Meter,Electricity:Facility,monthly;"
  OptionalMeter meter = model.getModelObject<Meter>(handles[0]);
  ASSERT_TRUE(meter);
  EXPECT_EQ("Electricity:Facility", meter->name());
  EXPECT_FALSE(meter->cumulative());
  EXPECT_FALSE(meter->specificEndUse());
  EXPECT_FALSE(meter->endUseType());
  ASSERT_TRUE(meter->fuelType());
  EXPECT_EQ(FuelType::Electricity, meter->fuelType().get().value());
  ASSERT_TRUE(meter->installLocationType());
  EXPECT_EQ(InstallLocationType::Facility, meter->installLocationType().get().value());
  EXPECT_FALSE(meter->specificInstallLocation());

  //"Output:Meter:MeterFileOnly,Gas:Building,hourly;"
  meter = model.getModelObject<Meter>(handles[1]);
  ASSERT_TRUE(meter);
  EXPECT_EQ("Gas:Building", meter->name());
  EXPECT_FALSE(meter->cumulative());
  EXPECT_FALSE(meter->specificEndUse());
  EXPECT_FALSE(meter->endUseType());
  ASSERT_TRUE(meter->fuelType());
  EXPECT_EQ(FuelType::Gas, meter->fuelType().get().value());
  ASSERT_TRUE(meter->installLocationType());
  EXPECT_EQ(InstallLocationType::Building, meter->installLocationType().get().value());
  EXPECT_FALSE(meter->specificInstallLocation());

  //"Output:Meter:Cumulative,InteriorLights:Electricity,runperiod;"
  meter = model.getModelObject<Meter>(handles[2]);
  ASSERT_TRUE(meter);
  EXPECT_EQ("InteriorLights:Electricity", meter->name());
  EXPECT_TRUE(meter->cumulative());
  EXPECT_FALSE(meter->specificEndUse());
  ASSERT_TRUE(meter->endUseType());
  EXPECT_EQ(EndUseType::InteriorLights, meter->endUseType().get().value());
  ASSERT_TRUE(meter->fuelType());
  EXPECT_EQ(FuelType::Electricity, meter->fuelType().get().value());
  EXPECT_FALSE(meter->installLocationType());
  EXPECT_FALSE(meter->specificInstallLocation());

  //"Output:Meter:Cumulative:MeterFileOnly,General:InteriorLights:Electricity:Zone:North Zone,daily;"
  meter = model.getModelObject<Meter>(handles[3]);
  ASSERT_TRUE(meter);
  EXPECT_EQ("General:InteriorLights:Electricity:Zone:North Zone", meter->name());
  EXPECT_TRUE(meter->cumulative());
  ASSERT_TRUE(meter->specificEndUse());
  EXPECT_EQ("General", meter->specificEndUse().get());
  ASSERT_TRUE(meter->endUseType());
  EXPECT_EQ(EndUseType::InteriorLights, meter->endUseType().get().value());
  ASSERT_TRUE(meter->fuelType());
  EXPECT_EQ(FuelType::Electricity, meter->fuelType().get().value());
  ASSERT_TRUE(meter->installLocationType());
  EXPECT_EQ(InstallLocationType::Zone, meter->installLocationType().get().value());
  ASSERT_TRUE(meter->specificInstallLocation());
  EXPECT_EQ("North Zone", meter->specificInstallLocation().get());
}