void RubyContinuousVariableRecord::constructRelatedRecords(const analysis::Variable& variable)
{
  analysis::RubyContinuousVariable rubyContinuousVariable = variable.cast<analysis::RubyContinuousVariable>();
  RubyContinuousVariableRecord copyOfThis(getImpl<detail::RubyContinuousVariableRecord_Impl>());
  ProjectDatabase database = projectDatabase();
  bool isNew = database.isNewRecord(copyOfThis);
  if (!isNew) {
    getImpl<detail::RubyContinuousVariableRecord_Impl>()->revertToLastRecordIds();
  }

  // Save resource RubyMeasure
  if (isNew || rubyContinuousVariable.perturbation().isDirty()) {
    RubyMeasureRecord rubyMeasureRecord(rubyContinuousVariable.measure(),database);
    getImpl<detail::RubyContinuousVariableRecord_Impl>()->setRubyMeasureRecordId(rubyMeasureRecord.id());
  }

  // Save child OSArgument
  OSArgument argument = rubyContinuousVariable.argument();
  bool saveArgument = false;
  if (!isNew) {
    {
      // see if old argument record should be removed
      OSArgumentRecord oldArgumentRecord = osArgumentRecord();
      if (oldArgumentRecord.handle() != argument.uuid()) {
        database.removeRecord(oldArgumentRecord);
        saveArgument = true;
      }
      else if (oldArgumentRecord.uuidLast() != argument.versionUUID()) {
        saveArgument = true;
      }
    }
    database.unloadUnusedCleanRecords();
  }
  if (saveArgument || isNew) {
    OSArgumentRecord osArgumentRecord(argument,copyOfThis);
  }
}
Beispiel #2
0
  QVariant toVariant(const OSArgument& argument) {
    QVariantMap argumentData;

    argumentData["uuid"] = toQString(removeBraces(argument.uuid()));
    argumentData["version_uuid"] = toQString(removeBraces(argument.versionUUID()));
    argumentData["name"] = toQString(argument.name());
    if (!argument.displayName().empty()) {
      argumentData["display_name"] = toQString(argument.displayName());
    }
    if (argument.description() && !argument.description()->empty()) {
      argumentData["description"] = toQString(argument.description().get());
    }
    OSArgumentType type = argument.type();
    if (argument.units() && !argument.units()->empty()) {
      argumentData["units"] = toQString(argument.units().get());
    }
    argumentData["type"] = toQString(type.valueName());
    argumentData["required"] = argument.required();
    argumentData["model_dependent"] = argument.modelDependent();
    if (argument.hasValue()) {
      if (type == OSArgumentType::Quantity) {
        Quantity value = argument.valueAsQuantity();
        argumentData["value"] = value.value();
        argumentData["value_units"] = toQString(value.units().standardString());
      }
      else {
        // use QVariant directly
        argumentData["value"] = argument.valueAsQVariant();
      }
    }
    if (argument.hasDefaultValue()) {
      if (type == OSArgumentType::Quantity) {
        Quantity defaultValue = argument.defaultValueAsQuantity();
        argumentData["default_value"] = defaultValue.value();
        argumentData["default_value_units"] = toQString(defaultValue.units().standardString());
      }
      else {
        // use QVariant directly
        argumentData["default_value"] = argument.defaultValueAsQVariant();
      }
    }
    argumentData["domain_type"] = toQString(argument.domainType().valueName());
    if (argument.hasDomain()) {
      QVariantList domainList;
      int index(0);
      for (const QVariant& dval : argument.domainAsQVariant()) {
        QVariantMap domainValueMap;
        domainValueMap["domain_value_index"] = index;
        if (type == OSArgumentType::Quantity) {
          Quantity q = dval.value<openstudio::Quantity>();
          domainValueMap["value"] = q.value();
          domainValueMap["units"] = toQString(q.units().standardString());
        }
        else {
          domainValueMap["value"] = dval;
        }
        domainList.push_back(domainValueMap);
        ++index;
      }
      argumentData["domain"] = domainList;
    }
    if (type == OSArgumentType::Choice) {
      QVariantList choicesList;
      StringVector displayNames = argument.choiceValueDisplayNames();
      int index(0), displayNamesN(displayNames.size());
      for (const std::string& choice : argument.choiceValues()) {
        QVariantMap choiceMap;
        choiceMap["choice_index"] = index;
        choiceMap["value"] = toQString(choice);
        if (index < displayNamesN) {
          choiceMap["display_name"] = toQString(displayNames[index]);
        }
        choicesList.push_back(choiceMap);
        ++index;
      }
      argumentData["choices"] = QVariant(choicesList);
    }
    if (type == OSArgumentType::Path) {
      argumentData["is_read"] = argument.isRead();
      argumentData["extension"] = toQString(argument.extension());
    }

    return QVariant(argumentData);
  }