boost::optional<IdfObject> ForwardTranslator::translateScheduleWeek( ScheduleWeek & modelObject )
{
  IdfObject scheduleWeek( openstudio::IddObjectType::Schedule_Week_Daily );

  m_idfObjects.push_back(scheduleWeek);

  scheduleWeek.setName(modelObject.name().get());

  // all fields in scheduleWeek are required, attempt to make sure they are all set
  if (!modelObject.holidaySchedule()){
    if (modelObject.sundaySchedule()){
      modelObject.setHolidaySchedule(modelObject.sundaySchedule().get());
    }
  }
  if (!modelObject.customDay1Schedule()){
    if (modelObject.holidaySchedule()){
      modelObject.setCustomDay1Schedule(modelObject.holidaySchedule().get());
    }
  }
  if (!modelObject.customDay2Schedule()){
    if (modelObject.holidaySchedule()){
      modelObject.setCustomDay2Schedule(modelObject.holidaySchedule().get());
    }
  }

  bool test = true;
  MAP_SCHEDULE(scheduleWeek, Schedule_Week_DailyFields::SundaySchedule_DayName, modelObject.sundaySchedule());
  MAP_SCHEDULE(scheduleWeek, Schedule_Week_DailyFields::MondaySchedule_DayName, modelObject.mondaySchedule());
  MAP_SCHEDULE(scheduleWeek, Schedule_Week_DailyFields::TuesdaySchedule_DayName, modelObject.tuesdaySchedule());
  MAP_SCHEDULE(scheduleWeek, Schedule_Week_DailyFields::WednesdaySchedule_DayName, modelObject.wednesdaySchedule());
  MAP_SCHEDULE(scheduleWeek, Schedule_Week_DailyFields::ThursdaySchedule_DayName, modelObject.thursdaySchedule());
  MAP_SCHEDULE(scheduleWeek, Schedule_Week_DailyFields::FridaySchedule_DayName, modelObject.fridaySchedule());
  MAP_SCHEDULE(scheduleWeek, Schedule_Week_DailyFields::SaturdaySchedule_DayName, modelObject.saturdaySchedule());
  MAP_SCHEDULE(scheduleWeek, Schedule_Week_DailyFields::HolidaySchedule_DayName, modelObject.holidaySchedule());
  MAP_SCHEDULE(scheduleWeek, Schedule_Week_DailyFields::SummerDesignDaySchedule_DayName, modelObject.summerDesignDaySchedule());
  MAP_SCHEDULE(scheduleWeek, Schedule_Week_DailyFields::WinterDesignDaySchedule_DayName, modelObject.winterDesignDaySchedule());
  MAP_SCHEDULE(scheduleWeek, Schedule_Week_DailyFields::CustomDay1Schedule_DayName, modelObject.customDay1Schedule());
  MAP_SCHEDULE(scheduleWeek, Schedule_Week_DailyFields::CustomDay2Schedule_DayName, modelObject.customDay2Schedule());

  if (!test){
    LOG(Warn, "ScheduleWeek '" << modelObject.name().get() << "' is missing required fields");
  }

  return scheduleWeek;
}
boost::optional<IdfObject> ForwardTranslator::translateScheduleWeek( ScheduleWeek & modelObject )
{
  IdfObject scheduleWeek( openstudio::IddObjectType::Schedule_Week_Daily );

  m_idfObjects.push_back(scheduleWeek);

  scheduleWeek.setName(modelObject.name().get());

  MAP_SCHEDULE(scheduleWeek, Schedule_Week_DailyFields::SundaySchedule_DayName, modelObject.sundaySchedule());
  MAP_SCHEDULE(scheduleWeek, Schedule_Week_DailyFields::MondaySchedule_DayName, modelObject.mondaySchedule());
  MAP_SCHEDULE(scheduleWeek, Schedule_Week_DailyFields::TuesdaySchedule_DayName, modelObject.tuesdaySchedule());
  MAP_SCHEDULE(scheduleWeek, Schedule_Week_DailyFields::WednesdaySchedule_DayName, modelObject.wednesdaySchedule());
  MAP_SCHEDULE(scheduleWeek, Schedule_Week_DailyFields::ThursdaySchedule_DayName, modelObject.thursdaySchedule());
  MAP_SCHEDULE(scheduleWeek, Schedule_Week_DailyFields::FridaySchedule_DayName, modelObject.fridaySchedule());
  MAP_SCHEDULE(scheduleWeek, Schedule_Week_DailyFields::SaturdaySchedule_DayName, modelObject.saturdaySchedule());
  MAP_SCHEDULE(scheduleWeek, Schedule_Week_DailyFields::HolidaySchedule_DayName, modelObject.holidaySchedule());
  MAP_SCHEDULE(scheduleWeek, Schedule_Week_DailyFields::SummerDesignDaySchedule_DayName, modelObject.summerDesignDaySchedule());
  MAP_SCHEDULE(scheduleWeek, Schedule_Week_DailyFields::WinterDesignDaySchedule_DayName, modelObject.winterDesignDaySchedule());
  MAP_SCHEDULE(scheduleWeek, Schedule_Week_DailyFields::CustomDay1Schedule_DayName, modelObject.customDay1Schedule());
  MAP_SCHEDULE(scheduleWeek, Schedule_Week_DailyFields::CustomDay2Schedule_DayName, modelObject.customDay2Schedule());

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

  // create the schedule
  ScheduleWeek scheduleWeek(m_model);

  OptionalString s = workspaceObject.name();
  if (s){
    scheduleWeek.setName(*s);
  }

  OptionalWorkspaceObject target = workspaceObject.getTarget(Schedule_Week_DailyFields::SundaySchedule_DayName);
  if (target){
    OptionalModelObject modelObject = translateAndMapWorkspaceObject(*target);
    if (modelObject){
      if (modelObject->optionalCast<ScheduleDay>()){
        scheduleWeek.setSundaySchedule(modelObject->cast<ScheduleDay>());
      }
    }
  }

  target = workspaceObject.getTarget(Schedule_Week_DailyFields::MondaySchedule_DayName);
  if (target){
    OptionalModelObject modelObject = translateAndMapWorkspaceObject(*target);
    if (modelObject){
      if (modelObject->optionalCast<ScheduleDay>()){
        scheduleWeek.setMondaySchedule(modelObject->cast<ScheduleDay>());
      }
    }
  }

  target = workspaceObject.getTarget(Schedule_Week_DailyFields::TuesdaySchedule_DayName);
  if (target){
    OptionalModelObject modelObject = translateAndMapWorkspaceObject(*target);
    if (modelObject){
      if (modelObject->optionalCast<ScheduleDay>()){
        scheduleWeek.setTuesdaySchedule(modelObject->cast<ScheduleDay>());
      }
    }
  }

  target = workspaceObject.getTarget(Schedule_Week_DailyFields::WednesdaySchedule_DayName);
  if (target){
    OptionalModelObject modelObject = translateAndMapWorkspaceObject(*target);
    if (modelObject){
      if (modelObject->optionalCast<ScheduleDay>()){
        scheduleWeek.setWednesdaySchedule(modelObject->cast<ScheduleDay>());
      }
    }
  }
  
  target = workspaceObject.getTarget(Schedule_Week_DailyFields::ThursdaySchedule_DayName);
  if (target){
    OptionalModelObject modelObject = translateAndMapWorkspaceObject(*target);
    if (modelObject){
      if (modelObject->optionalCast<ScheduleDay>()){
        scheduleWeek.setThursdaySchedule(modelObject->cast<ScheduleDay>());
      }
    }
  }

  target = workspaceObject.getTarget(Schedule_Week_DailyFields::FridaySchedule_DayName);
  if (target){
    OptionalModelObject modelObject = translateAndMapWorkspaceObject(*target);
    if (modelObject){
      if (modelObject->optionalCast<ScheduleDay>()){
        scheduleWeek.setFridaySchedule(modelObject->cast<ScheduleDay>());
      }
    }
  }

  target = workspaceObject.getTarget(Schedule_Week_DailyFields::SaturdaySchedule_DayName);
  if (target){
    OptionalModelObject modelObject = translateAndMapWorkspaceObject(*target);
    if (modelObject){
      if (modelObject->optionalCast<ScheduleDay>()){
        scheduleWeek.setSaturdaySchedule(modelObject->cast<ScheduleDay>());
      }
    }
  }

  target = workspaceObject.getTarget(Schedule_Week_DailyFields::HolidaySchedule_DayName);
  if (target){
    OptionalModelObject modelObject = translateAndMapWorkspaceObject(*target);
    if (modelObject){
      if (modelObject->optionalCast<ScheduleDay>()){
        scheduleWeek.setHolidaySchedule(modelObject->cast<ScheduleDay>());
      }
    }
  }

  target = workspaceObject.getTarget(Schedule_Week_DailyFields::SummerDesignDaySchedule_DayName);
  if (target){
    OptionalModelObject modelObject = translateAndMapWorkspaceObject(*target);
    if (modelObject){
      if (modelObject->optionalCast<ScheduleDay>()){
        scheduleWeek.setSummerDesignDaySchedule(modelObject->cast<ScheduleDay>());
      }
    }
  }

  target = workspaceObject.getTarget(Schedule_Week_DailyFields::WinterDesignDaySchedule_DayName);
  if (target){
    OptionalModelObject modelObject = translateAndMapWorkspaceObject(*target);
    if (modelObject){
      if (modelObject->optionalCast<ScheduleDay>()){
        scheduleWeek.setWinterDesignDaySchedule(modelObject->cast<ScheduleDay>());
      }
    }
  }

  target = workspaceObject.getTarget(Schedule_Week_DailyFields::CustomDay1Schedule_DayName);
  if (target){
    OptionalModelObject modelObject = translateAndMapWorkspaceObject(*target);
    if (modelObject){
      if (modelObject->optionalCast<ScheduleDay>()){
        scheduleWeek.setCustomDay1Schedule(modelObject->cast<ScheduleDay>());
      }
    }
  }

  target = workspaceObject.getTarget(Schedule_Week_DailyFields::CustomDay2Schedule_DayName);
  if (target){
    OptionalModelObject modelObject = translateAndMapWorkspaceObject(*target);
    if (modelObject){
      if (modelObject->optionalCast<ScheduleDay>()){
        scheduleWeek.setCustomDay2Schedule(modelObject->cast<ScheduleDay>());
      }
    }
  }

  return scheduleWeek;
}
Пример #4
0
  boost::optional<openstudio::model::ModelObject> ReverseTranslator::translateScheduleWeek(const QDomElement& element, const QDomDocument& doc, openstudio::model::Model& model)
  {
    QDomElement nameElement = element.firstChildElement("Name");
    QDomElement typeElement = element.firstChildElement("Type");
    QDomElement schDaySunRefElement = element.firstChildElement("SchDaySunRef");
    QDomElement schDayMonRefElement = element.firstChildElement("SchDayMonRef");
    QDomElement schDayTueRefElement = element.firstChildElement("SchDayTueRef");
    QDomElement schDayWedRefElement = element.firstChildElement("SchDayWedRef");
    QDomElement schDayThuRefElement = element.firstChildElement("SchDayThuRef");
    QDomElement schDayFriRefElement = element.firstChildElement("SchDayFriRef");
    QDomElement schDaySatRefElement = element.firstChildElement("SchDaySatRef");
    QDomElement schDayHolRefElement = element.firstChildElement("SchDayHolRef");
    QDomElement schDayClgDDRefElement = element.firstChildElement("SchDayClgDDRef");
    QDomElement schDayHtgDDRefElement = element.firstChildElement("SchDayHtgDDRef");

    OS_ASSERT(!nameElement.isNull());
    std::string name = escapeName(nameElement.text());

    model::ScheduleWeek scheduleWeek(model);
    scheduleWeek.setName(name);

    OS_ASSERT(!typeElement.isNull());
    std::string type = escapeName(typeElement.text());
    boost::optional<model::ScheduleTypeLimits> scheduleTypeLimits = model.getModelObjectByName<model::ScheduleTypeLimits>(type);
    if (scheduleTypeLimits){
      //scheduleWeek.setScheduleTypeLimits(*scheduleTypeLimits);
    }

    if (!schDaySunRefElement.isNull()){
      boost::optional<model::ScheduleDay> scheduleDay = model.getModelObjectByName<model::ScheduleDay>(escapeName(schDaySunRefElement.text()));
      if (scheduleDay){
        scheduleWeek.setSundaySchedule(*scheduleDay);
      }else{
        LOG(Error, "No Sunday schedule found for week schedule '" << name << "'");
      }
    }

    if (!schDayMonRefElement.isNull()){
      boost::optional<model::ScheduleDay> scheduleDay = model.getModelObjectByName<model::ScheduleDay>(escapeName(schDayMonRefElement.text()));
      if (scheduleDay){
        scheduleWeek.setMondaySchedule(*scheduleDay);
      }else{
        LOG(Error, "No Monday schedule found for week schedule '" << name << "'");
      }
    }

    if (!schDayTueRefElement.isNull()){
      boost::optional<model::ScheduleDay> scheduleDay = model.getModelObjectByName<model::ScheduleDay>(escapeName(schDayTueRefElement.text()));
      if (scheduleDay){
        scheduleWeek.setTuesdaySchedule(*scheduleDay);
      }else{
        LOG(Error, "No Tuesday schedule found for week schedule '" << name << "'");
      }
    }

    if (!schDayWedRefElement.isNull()){
      boost::optional<model::ScheduleDay> scheduleDay = model.getModelObjectByName<model::ScheduleDay>(escapeName(schDayWedRefElement.text()));
      if (scheduleDay){
        scheduleWeek.setWednesdaySchedule(*scheduleDay);
      }else{
        LOG(Error, "No Wednesday schedule found for week schedule '" << name << "'");
      }
    }

    if (!schDayThuRefElement.isNull()){
      boost::optional<model::ScheduleDay> scheduleDay = model.getModelObjectByName<model::ScheduleDay>(escapeName(schDayThuRefElement.text()));
      if (scheduleDay){
        scheduleWeek.setThursdaySchedule(*scheduleDay);
      }else{
        LOG(Error, "No Thursday schedule found for week schedule '" << name << "'");
      }
    }

    if (!schDayFriRefElement.isNull()){
      boost::optional<model::ScheduleDay> scheduleDay = model.getModelObjectByName<model::ScheduleDay>(escapeName(schDayFriRefElement.text()));
      if (scheduleDay){
        scheduleWeek.setFridaySchedule(*scheduleDay);
      }else{
        LOG(Error, "No Friday schedule found for week schedule '" << name << "'");
      }
    }

    if (!schDaySatRefElement.isNull()){
      boost::optional<model::ScheduleDay> scheduleDay = model.getModelObjectByName<model::ScheduleDay>(escapeName(schDaySatRefElement.text()));
      if (scheduleDay){
        scheduleWeek.setSaturdaySchedule(*scheduleDay);
      }else{
        LOG(Error, "No Saturday schedule found for week schedule '" << name << "'");
      }
    }
   
    if (!schDayHolRefElement.isNull()){
      boost::optional<model::ScheduleDay> scheduleDay = model.getModelObjectByName<model::ScheduleDay>(escapeName(schDayHolRefElement.text()));
      if (scheduleDay){
        scheduleWeek.setHolidaySchedule(*scheduleDay);
        scheduleWeek.setCustomDay1Schedule(*scheduleDay);
        scheduleWeek.setCustomDay2Schedule(*scheduleDay);
      }else{
        LOG(Error, "No Holiday schedule found for week schedule '" << name << "'");
      }
    }

    if (!schDayClgDDRefElement.isNull()){
      boost::optional<model::ScheduleDay> scheduleDay = model.getModelObjectByName<model::ScheduleDay>(escapeName(schDayClgDDRefElement.text()));
      if (scheduleDay){
        scheduleWeek.setSummerDesignDaySchedule(*scheduleDay);
      }else{
        LOG(Error, "No Summer Design Day schedule found for week schedule '" << name << "'");
      }
    }

    if (!schDayHtgDDRefElement.isNull()){
      boost::optional<model::ScheduleDay> scheduleDay = model.getModelObjectByName<model::ScheduleDay>(escapeName(schDayHtgDDRefElement.text()));
      if (scheduleDay){
        scheduleWeek.setWinterDesignDaySchedule(*scheduleDay);
      }else{
        LOG(Error, "No Winter Design Day schedule found for week schedule '" << name << "'");
      }
    }

    return scheduleWeek;
  }