Пример #1
0
bool Relationship::setRelatedModelObject(const Component& component) {
  OptionalComponentData ocd = m_object.model().insertComponent(component);
  if (!ocd) {
    return false;
  }
  // TODO: Bad set may junk up model with unnecessary objects.
  return setRelatedModelObject(ocd->primaryComponentObject());
}
Пример #2
0
TEST_F(ModelFixture, Component_LightingSchedule_FromScratch)
{
  // create schedule component
  Model justASchedule;
  EXPECT_EQ(0u,justASchedule.numObjects()); // Version doesn't count in basic object list
  EXPECT_TRUE(justASchedule.getOptionalUniqueModelObject<Version>());
  ScheduleTypeLimits typeLimits(justASchedule);
  typeLimits.setName("Fraction");
  typeLimits.setLowerLimitValue(0.0);
  typeLimits.setUpperLimitValue(1.0);
  typeLimits.setNumericType("Continuous");
  ScheduleCompact schedule(justASchedule);
  EXPECT_TRUE(schedule.setPointer(OS_Schedule_CompactFields::ScheduleTypeLimitsName,
                                  typeLimits.handle()));
  Component scheduleComponent = schedule.createComponent();
  EXPECT_EQ(static_cast<unsigned>(2),scheduleComponent.componentData().numComponentObjects());
  EXPECT_EQ(static_cast<unsigned>(3),scheduleComponent.numObjects());
  EXPECT_TRUE(scheduleComponent.primaryObject().optionalCast<ScheduleCompact>());

  // create model with Lights objects and set schedules
  Model justLights;
  LightsDefinition lightsDefinition(justLights);
  Lights light1(lightsDefinition);
  EXPECT_EQ(static_cast<unsigned>(2),justLights.numObjects());
  OptionalComponentData ocd = justLights.insertComponent(scheduleComponent);
  EXPECT_EQ(static_cast<unsigned>(5),justLights.numObjects());
  ASSERT_TRUE(ocd);
  OptionalScheduleCompact oSchedule = ocd->primaryComponentObject().optionalCast<ScheduleCompact>();
  ASSERT_TRUE(oSchedule);
  schedule = *oSchedule;
  EXPECT_TRUE(light1.setSchedule(schedule));
  EXPECT_EQ(static_cast<unsigned>(5),justLights.numObjects());
  Lights light2(lightsDefinition);
  EXPECT_EQ(static_cast<unsigned>(6),justLights.numObjects());
  ocd = justLights.insertComponent(scheduleComponent);
  EXPECT_EQ(static_cast<unsigned>(6),justLights.numObjects());
  ASSERT_TRUE(ocd);
  ASSERT_TRUE(ocd->primaryComponentObject().optionalCast<ScheduleCompact>());
  ASSERT_TRUE(light1.schedule());
  EXPECT_EQ(ocd->primaryComponentObject().handle(), light1.schedule()->handle());
  Schedule lightingSchedule = ocd->primaryComponentObject().cast<ScheduleCompact>();
  EXPECT_TRUE(light2.setSchedule(lightingSchedule));

  // create Lights component
  Component lightsComponent = light1.createComponent();
  EXPECT_EQ(static_cast<unsigned>(4),lightsComponent.componentData().numComponentObjects());
  EXPECT_EQ(static_cast<unsigned>(5),lightsComponent.numObjects());
  EXPECT_EQ(static_cast<unsigned>(1),lightsComponent.getModelObjects<ComponentData>().size());
  EXPECT_EQ(static_cast<unsigned>(1),lightsComponent.getModelObjects<Lights>().size());
  EXPECT_EQ(static_cast<unsigned>(1),lightsComponent.getModelObjects<ScheduleTypeLimits>().size());
  EXPECT_EQ(static_cast<unsigned>(1),lightsComponent.getModelObjects<ScheduleCompact>().size());
}