bool operator==(const Quantity& lQuantity,const Quantity& rQuantity) { if ((lQuantity.system() == rQuantity.system()) && (lQuantity.units() == rQuantity.units())) { Quantity wl(lQuantity), wr(rQuantity); wl.setScale(0); wr.setScale(0); return equal(wl.value(),wr.value()); } return false; }
TEST_F(ModelFixture,ZoneHVACFourPipeFanCoil_MediumSpeedSupplyAirFlowRatio_Quantity) { Model model; EXPECT_EQ(0u,model.objects().size()); EXPECT_TRUE(model.versionObject()); // need schedule ScheduleConstant sched(model); EXPECT_EQ(1u,model.objects().size()); sched.setValue(1.0); // Always on // need fan FanConstantVolume fan(model,sched); // need cooling and heating coils CoilCoolingWater coolingCoil(model,sched); CoilHeatingWater heatingCoil(model,sched); // construct object ZoneHVACFourPipeFanCoil zoneHVACFourPipeFanCoil(model,sched,fan,coolingCoil,heatingCoil); EXPECT_EQ(6u,model.objects().size()); Unit units = zoneHVACFourPipeFanCoil.getMediumSpeedSupplyAirFlowRatio(true).units(); // Get IP units. double value(0.66); Quantity testQ(value,units); EXPECT_TRUE(zoneHVACFourPipeFanCoil.setMediumSpeedSupplyAirFlowRatio(testQ)); Quantity q = zoneHVACFourPipeFanCoil.getMediumSpeedSupplyAirFlowRatio(true); EXPECT_NEAR(value,q.value(),1.0E-8); EXPECT_EQ(units.standardString(),q.units().standardString()); }
void OSQuantityVector::push_back(Quantity q) { if (!(q.units() == units())) { LOG_AND_THROW("Quantity " << q << " is incompatible with this OSQuantityVector, which has " "units " << units() << "."); } else if (q.scale() != scale()) { q.setScale(scale().exponent); } m_values.push_back(q.value()); }
TEST_F(ModelFixture,HeatExchangerAirToAirSensibleAndLatent_LatentEffectivenessat75CoolingAirFlow_Quantity) { Model model; HeatExchangerAirToAirSensibleAndLatent heatExchangerAirToAirSensibleAndLatent(model); Unit units = heatExchangerAirToAirSensibleAndLatent.getLatentEffectivenessat75CoolingAirFlow(true).units(); // Get IP units. double value(1.0); Quantity testQ(value,units); EXPECT_TRUE(heatExchangerAirToAirSensibleAndLatent.setLatentEffectivenessat75CoolingAirFlow(testQ)); Quantity q = heatExchangerAirToAirSensibleAndLatent.getLatentEffectivenessat75CoolingAirFlow(true); EXPECT_NEAR(value,q.value(),1.0E-8); EXPECT_EQ(units.standardString(),q.units().standardString()); }
TEST_F(ModelFixture,HeatExchangerAirToAirSensibleAndLatent_ThresholdTemperature_Quantity) { Model model; HeatExchangerAirToAirSensibleAndLatent heatExchangerAirToAirSensibleAndLatent(model); Unit units = heatExchangerAirToAirSensibleAndLatent.getThresholdTemperature(true).units(); // Get IP units. double value(1.0); Quantity testQ(value,units); EXPECT_TRUE(heatExchangerAirToAirSensibleAndLatent.setThresholdTemperature(testQ)); Quantity q = heatExchangerAirToAirSensibleAndLatent.getThresholdTemperature(true); EXPECT_NEAR(value,q.value(),1.0E-8); EXPECT_EQ(units.standardString(),q.units().standardString()); }
TEST_F(ModelFixture,ThermalZone_FractionofZoneControlledbySecondaryDaylightingControl_Quantity) { Model model; ThermalZone thermalZone(model); Unit units = thermalZone.getFractionofZoneControlledbySecondaryDaylightingControl(true).units(); // Get IP units. double value(0.0); Quantity testQ(value,units); EXPECT_TRUE(thermalZone.setFractionofZoneControlledbySecondaryDaylightingControl(testQ)); Quantity q = thermalZone.getFractionofZoneControlledbySecondaryDaylightingControl(true); EXPECT_NEAR(value,q.value(),1.0E-8); EXPECT_EQ(units.standardString(),q.units().standardString()); }
TEST_F(ModelFixture,PeopleDefinition_CarbonDioxideGenerationRate_Quantity) { Model model; PeopleDefinition peopleDefinition(model); Unit units = peopleDefinition.getCarbonDioxideGenerationRate(true).units(); // Get IP units. double value(1.0E-7); Quantity testQ(value,units); EXPECT_TRUE(peopleDefinition.setCarbonDioxideGenerationRate(testQ)); Quantity q = peopleDefinition.getCarbonDioxideGenerationRate(true); EXPECT_NEAR(value,q.value(),1.0E-15); EXPECT_EQ(units.standardString(),q.units().standardString()); }
TEST_F(ModelFixture,PeopleDefinition_FractionRadiant_Quantity) { Model model; PeopleDefinition peopleDefinition(model); Unit units = peopleDefinition.getFractionRadiant(true).units(); // Get IP units. double value(0.5); Quantity testQ(value,units); EXPECT_TRUE(peopleDefinition.setFractionRadiant(testQ)); Quantity q = peopleDefinition.getFractionRadiant(true); EXPECT_NEAR(value,q.value(),1.0E-8); EXPECT_EQ(units.standardString(),q.units().standardString()); }
TEST_F(ModelFixture,ZoneCapacitanceMultiplierResearchSpecial_TemperatureCapacityMultiplier_Quantity) { Model model; // TODO: Check constructor. ZoneCapacitanceMultiplierResearchSpecial zoneCapacitanceMultiplierResearchSpecial = model.getUniqueModelObject<ZoneCapacitanceMultiplierResearchSpecial>(); Unit units = zoneCapacitanceMultiplierResearchSpecial.getTemperatureCapacityMultiplier(true).units(); // Get IP units. // TODO: Check that value is appropriate (within bounds) double value(1.0); Quantity testQ(value,units); EXPECT_TRUE(zoneCapacitanceMultiplierResearchSpecial.setTemperatureCapacityMultiplier(testQ)); Quantity q = zoneCapacitanceMultiplierResearchSpecial.getTemperatureCapacityMultiplier(true); EXPECT_NEAR(value,q.value(),1.0E-8); EXPECT_EQ(units.standardString(),q.units().standardString()); }
TEST_F(ModelFixture,SizingZone_ZoneHeatingDesignSupplyAirHumidityRatio_Quantity) { Model model; ThermalZone zone(model); SizingZone sizingZone(model,zone); Unit units = sizingZone.getZoneHeatingDesignSupplyAirHumidityRatio(true).units(); // Get IP units. // TODO: Check that value is appropriate (within bounds) double value(1.0); Quantity testQ(value,units); EXPECT_TRUE(sizingZone.setZoneHeatingDesignSupplyAirHumidityRatio(testQ)); Quantity q = sizingZone.getZoneHeatingDesignSupplyAirHumidityRatio(true); EXPECT_NEAR(value,q.value(),1.0E-8); EXPECT_EQ(units.standardString(),q.units().standardString()); }
TEST_F(ModelFixture,SizingZone_DesignZoneAirDistributionEffectivenessinHeatingMode_Quantity) { Model model; ThermalZone zone(model); SizingZone sizingZone(model,zone); Unit units = sizingZone.getDesignZoneAirDistributionEffectivenessinHeatingMode(true).units(); // Get IP units. // TODO: Check that value is appropriate (within bounds) double value(1.0); Quantity testQ(value,units); EXPECT_TRUE(sizingZone.setDesignZoneAirDistributionEffectivenessinHeatingMode(testQ)); Quantity q = sizingZone.getDesignZoneAirDistributionEffectivenessinHeatingMode(true); EXPECT_NEAR(value,q.value(),1.0E-8); EXPECT_EQ(units.standardString(),q.units().standardString()); }
TEST_F(ModelFixture,SizingZone_HeatingMaximumAirFlowperZoneFloorArea_Quantity) { Model model; ThermalZone zone(model); SizingZone sizingZone(model,zone); Unit units = sizingZone.getHeatingMaximumAirFlowperZoneFloorArea(true).units(); // Get IP units. // TODO: Check that value is appropriate (within bounds) double value(1.0); Quantity testQ(value,units); EXPECT_TRUE(sizingZone.setHeatingMaximumAirFlowperZoneFloorArea(testQ)); Quantity q = sizingZone.getHeatingMaximumAirFlowperZoneFloorArea(true); EXPECT_NEAR(value,q.value(),1.0E-8); EXPECT_EQ(units.standardString(),q.units().standardString()); }
TEST_F(ModelFixture,SimulationControl_TemperatureConvergenceToleranceValue_Quantity) { Model model; SimulationControl simulationControl = model.getUniqueModelObject<SimulationControl>(); Unit units = simulationControl.getTemperatureConvergenceToleranceValue(true).units(); // Get IP units. double value(0.3); Quantity testQ(value,units); EXPECT_TRUE(simulationControl.setTemperatureConvergenceToleranceValue(testQ)); Quantity q = simulationControl.getTemperatureConvergenceToleranceValue(true); EXPECT_NEAR(value,q.value(),1.0E-8); EXPECT_EQ(units.standardString(),q.units().standardString()); }
TEST_F(ModelFixture,MasslessOpaqueMaterial_SolarAbsorptance_Quantity) { Model model; // TODO: Check constructor. MasslessOpaqueMaterial masslessOpaqueMaterial(model); Unit units = masslessOpaqueMaterial.getSolarAbsorptance(true).units(); // Get IP units. // TODO: Check that value is appropriate (within bounds) double value(1.0); Quantity testQ(value,units); EXPECT_TRUE(masslessOpaqueMaterial.setSolarAbsorptance(testQ)); Quantity q = masslessOpaqueMaterial.getSolarAbsorptance(true); EXPECT_NEAR(value,q.value(),1.0E-8); EXPECT_EQ(units.standardString(),q.units().standardString()); }
TEST_F(ModelFixture,RoofVegetation_LeafEmissivity_Quantity) { Model model; // TODO: Check constructor. RoofVegetation roofVegetation(model); Unit units = roofVegetation.getLeafEmissivity(true).units(); // Get IP units. // TODO: Check that value is appropriate (within bounds) double value(1.0); Quantity testQ(value,units); EXPECT_TRUE(roofVegetation.setLeafEmissivity(testQ)); Quantity q = roofVegetation.getLeafEmissivity(true); EXPECT_NEAR(value,q.value(),1.0E-8); EXPECT_EQ(units.standardString(),q.units().standardString()); }
TEST_F(ModelFixture,RadianceParameters_DirectPretest_Quantity) { Model model; // TODO: Check constructor. RadianceParameters radianceParameters = model.getUniqueModelObject<RadianceParameters>(); Unit units = radianceParameters.getDirectPretest(true).units(); // Get IP units. // TODO: Check that value is appropriate (within bounds) double value(1.0); Quantity testQ(value,units); EXPECT_TRUE(radianceParameters.setDirectPretest(testQ)); Quantity q = radianceParameters.getDirectPretest(true); EXPECT_NEAR(value,q.value(),1.0E-8); EXPECT_EQ(units.standardString(),q.units().standardString()); }
TEST_F(ModelFixture,BoilerSteam_SizingFactor_Quantity) { Model model; // TODO: Check constructor. BoilerSteam boilerSteam(model); Unit units = boilerSteam.getSizingFactor(true).units(); // Get IP units. // TODO: Check that value is appropriate (within bounds) double value(1.0); Quantity testQ(value,units); EXPECT_TRUE(boilerSteam.setSizingFactor(testQ)); Quantity q = boilerSteam.getSizingFactor(true); EXPECT_NEAR(value,q.value(),1.0E-8); EXPECT_EQ(units.standardString(),q.units().standardString()); }
TEST_F(ModelFixture,StandardGlazing_DirtCorrectionFactorforSolarandVisibleTransmittance_Quantity) { Model model; // TODO: Check constructor. StandardGlazing standardGlazing(model); Unit units = standardGlazing.getDirtCorrectionFactorforSolarandVisibleTransmittance(true).units(); // Get IP units. // TODO: Check that value is appropriate (within bounds) double value(1.0); Quantity testQ(value,units); EXPECT_TRUE(standardGlazing.setDirtCorrectionFactorforSolarandVisibleTransmittance(testQ)); Quantity q = standardGlazing.getDirtCorrectionFactorforSolarandVisibleTransmittance(true); EXPECT_NEAR(value,q.value(),1.0E-8); EXPECT_EQ(units.standardString(),q.units().standardString()); }
TEST_F(ModelFixture,ZoneHVACIdealLoadsAirSystem_LatentHeatRecoveryEffectiveness_Quantity) { Model model; // TODO: Check constructor. ZoneHVACIdealLoadsAirSystem zoneHVACIdealLoadsAirSystem(model); Unit units = zoneHVACIdealLoadsAirSystem.getLatentHeatRecoveryEffectiveness(true).units(); // Get IP units. // TODO: Check that value is appropriate (within bounds) double value(1.0); Quantity testQ(value,units); EXPECT_TRUE(zoneHVACIdealLoadsAirSystem.setLatentHeatRecoveryEffectiveness(testQ)); Quantity q = zoneHVACIdealLoadsAirSystem.getLatentHeatRecoveryEffectiveness(true); EXPECT_NEAR(value,q.value(),1.0E-8); EXPECT_EQ(units.standardString(),q.units().standardString()); }
TEST_F(ModelFixture,StandardGlazing_Thickness_Quantity) { Model model; // TODO: Check constructor. StandardGlazing standardGlazing(model); Unit units = standardGlazing.getThickness(true).units(); // Get IP units. // TODO: Check that value is appropriate (within bounds) double value(1.0); Quantity testQ(value,units); EXPECT_TRUE(standardGlazing.setThickness(testQ)); Quantity q = standardGlazing.getThickness(true); EXPECT_NEAR(value,q.value(),1.0E-8); EXPECT_EQ(units.standardString(),q.units().standardString()); }
TEST_F(ModelFixture,ZoneHVACIdealLoadsAirSystem_MinimumCoolingSupplyAirHumidityRatio_Quantity) { Model model; // TODO: Check constructor. ZoneHVACIdealLoadsAirSystem zoneHVACIdealLoadsAirSystem(model); Unit units = zoneHVACIdealLoadsAirSystem.getMinimumCoolingSupplyAirHumidityRatio(true).units(); // Get IP units. // TODO: Check that value is appropriate (within bounds) double value(1.0); Quantity testQ(value,units); EXPECT_TRUE(zoneHVACIdealLoadsAirSystem.setMinimumCoolingSupplyAirHumidityRatio(testQ)); Quantity q = zoneHVACIdealLoadsAirSystem.getMinimumCoolingSupplyAirHumidityRatio(true); EXPECT_NEAR(value,q.value(),1.0E-8); EXPECT_EQ(units.standardString(),q.units().standardString()); }
TEST_F(ModelFixture,SiteGroundReflectance_MayGroundReflectance_Quantity) { Model model; // TODO: Check constructor. SiteGroundReflectance siteGroundReflectance(model); Unit units = siteGroundReflectance.getMayGroundReflectance(true).units(); // Get IP units. // TODO: Check that value is appropriate (within bounds) double value(1.0); Quantity testQ(value,units); EXPECT_TRUE(siteGroundReflectance.setMayGroundReflectance(testQ)); Quantity q = siteGroundReflectance.getMayGroundReflectance(true); EXPECT_NEAR(value,q.value(),1.0E-8); EXPECT_EQ(units.standardString(),q.units().standardString()); }
TEST_F(ModelFixture,GasMixture_Gas2Fraction_Quantity) { Model model; // TODO: Check constructor. GasMixture gasMixture(model); Unit units = gasMixture.getGas2Fraction(true).units(); // Get IP units. // TODO: Check that value is appropriate (within bounds) double value(1.0); Quantity testQ(value,units); EXPECT_TRUE(gasMixture.setGas2Fraction(testQ)); Quantity q = gasMixture.getGas2Fraction(true); EXPECT_NEAR(value,q.value(),1.0E-8); EXPECT_EQ(units.standardString(),q.units().standardString()); }
TEST_F(ModelFixture,RefractionExtinctionGlazing_SolarExtinctionCoefficient_Quantity) { Model model; // TODO: Check constructor. RefractionExtinctionGlazing refractionExtinctionGlazing(model); Unit units = refractionExtinctionGlazing.getSolarExtinctionCoefficient(true).units(); // Get IP units. // TODO: Check that value is appropriate (within bounds) double value(1.0); Quantity testQ(value,units); EXPECT_TRUE(refractionExtinctionGlazing.setSolarExtinctionCoefficient(testQ)); Quantity q = refractionExtinctionGlazing.getSolarExtinctionCoefficient(true); EXPECT_NEAR(value,q.value(),1.0E-8); EXPECT_EQ(units.standardString(),q.units().standardString()); }
TEST_F(ModelFixture,Blind_SlatConductivity_Quantity) { Model model; // TODO: Check constructor. Blind blind(model); Unit units = blind.getSlatConductivity(true).units(); // Get IP units. // TODO: Check that value is appropriate (within bounds) double value(1.0); Quantity testQ(value,units); EXPECT_TRUE(blind.setSlatConductivity(testQ)); Quantity q = blind.getSlatConductivity(true); EXPECT_NEAR(value,q.value(),1.0E-8); EXPECT_EQ(units.standardString(),q.units().standardString()); }
TEST_F(ModelFixture,MasslessOpaqueMaterial_VisibleAbsorptance_Quantity) { Model model; // TODO: Check constructor. MasslessOpaqueMaterial masslessOpaqueMaterial(model); Unit units = masslessOpaqueMaterial.getVisibleAbsorptance(true).units(); // Get IP units. // Bounds: 0.0 <= value <= 1.0 double value(1.0); Quantity testQ(value,units); EXPECT_TRUE(masslessOpaqueMaterial.setVisibleAbsorptance(testQ)); Quantity q = masslessOpaqueMaterial.getVisibleAbsorptance(true); EXPECT_NEAR(value,q.value(),1.0E-8); EXPECT_EQ(units.standardString(),q.units().standardString()); }
boost::optional<double> ScheduleTypeLimits_Impl::getDoubleFromQuantity(unsigned index, Quantity q) const { OptionalUnit siUnits = ScheduleTypeLimits::units(unitType(),false); if (siUnits) { if (q.units() == siUnits) { return q.value(); } else { OptionalQuantity converted = convert(q,*siUnits); if (converted) { return q.value(); } } } return boost::none; }
Quantity::Quantity(const Quantity &q) : m_value(q.value()), m_units(q.units()) {}
bool OSRunner::validateUserArguments(const std::vector<OSArgument>& script_arguments, const std::map<std::string, OSArgument>& user_arguments) { bool result(true); std::stringstream ss; AttributeVector argumentValueAttributes; for (const OSArgument& script_argument : script_arguments) { auto it = user_arguments.find(script_argument.name()); if (it == user_arguments.end()) { // script_argument is not in user_arguments // this is only okay for purely optional arguments if (script_argument.required() || script_argument.hasDefaultValue()) { ss << "Argument " << script_argument.name() << " is required or has a default value, "; ss << "but is not in user_arguments."; registerError(ss.str()); ss.str(""); result = false; } } else { // script_argument is in user_arguments OSArgument user_argument = it->second; // check that names still match if (user_argument.name() != script_argument.name()) { ss << "User argument name '" << user_argument.name() << "' does not match map key "; ss << script_argument.name() << "."; registerWarning(ss.str()); ss.str(""); } // check that types still match if (user_argument.type() != script_argument.type()) { ss << "User argument type " << user_argument.type().valueName() << " does not match "; ss << "script argument type " << script_argument.type().valueName() << "."; registerError(ss.str()); ss.str(""); result = false; } // check that we have values if ((script_argument.required()) && !(user_argument.hasValue() || user_argument.hasDefaultValue())) { ss << "Script argument '" << script_argument.name() << "' is required, "; ss << "but the user argument does not have a value or default value set."; registerError(ss.str()); ss.str(""); result = false; } // check for default value mismatch if (script_argument.hasDefaultValue() && !user_argument.hasDefaultValue()) { ss << "Script argument '" << script_argument.name() << "' has a default value, but the "; ss << "user-supplied version does not."; registerWarning(ss.str()); ss.str(""); } if (!script_argument.hasDefaultValue() && user_argument.hasDefaultValue()) { ss << "Script argument '" << script_argument.name() << "' does not have a default value, "; ss << "but the user-supplied version does."; registerWarning(ss.str()); ss.str(""); } if (script_argument.hasDefaultValue() && user_argument.hasDefaultValue() && (user_argument.type() == script_argument.type())) { ss << "The default value of script argument " << std::endl << script_argument << std::endl; ss << "does not match that of the corresponding user argument " << std::endl << user_argument << "."; switch (script_argument.type().value()) { case OSArgumentType::Boolean : if (user_argument.defaultValueAsBool() != script_argument.defaultValueAsBool()) { registerWarning(ss.str()); } break; case OSArgumentType::Double : if (user_argument.defaultValueAsDouble() != script_argument.defaultValueAsDouble()) { registerWarning(ss.str()); } break; case OSArgumentType::Quantity : if (user_argument.defaultValueAsQuantity() != script_argument.defaultValueAsQuantity()) { registerWarning(ss.str()); } break; case OSArgumentType::Integer : if (user_argument.defaultValueAsInteger() != script_argument.defaultValueAsInteger()) { registerWarning(ss.str()); } break; case OSArgumentType::String : case OSArgumentType::Choice : case OSArgumentType::Path : if (user_argument.defaultValueAsString() != script_argument.defaultValueAsString()) { registerWarning(ss.str()); } break; default : OS_ASSERT(false); } ss.str(""); } // check for domain mismatch if (script_argument.hasDomain() && !user_argument.hasDomain()) { ss << "Script argument '" << script_argument.name() << "' has a specified domain, but the "; ss << "user-supplied version does not."; registerWarning(ss.str()); ss.str(""); } if (!script_argument.hasDomain() && user_argument.hasDomain()) { ss << "Script argument '" << script_argument.name() << "' does not have a specified domain, "; ss << "but the user-supplied version does."; registerWarning(ss.str()); ss.str(""); } if (script_argument.hasDomain() && user_argument.hasDomain() && (user_argument.type() == script_argument.type())) { ss << "The domain of script argument " << std::endl << script_argument << std::endl; ss << "does not match that of the corresponding user argument " << std::endl << user_argument << "."; switch (script_argument.type().value()) { case OSArgumentType::Boolean: // DLM: should bool's even have domains? if (user_argument.domainAsBool() != script_argument.domainAsBool()) { registerWarning(ss.str()); } break; case OSArgumentType::Double: if (user_argument.domainAsDouble() != script_argument.domainAsDouble()) { registerWarning(ss.str()); } break; case OSArgumentType::Quantity: // DLM: deprecated forget about getting this to compile //if (user_argument.domainAsQuantity() != script_argument.domainAsQuantity()) { // registerWarning(ss.str()); //} break; case OSArgumentType::Integer: if (user_argument.domainAsInteger() != script_argument.domainAsInteger()) { registerWarning(ss.str()); } break; case OSArgumentType::String: case OSArgumentType::Choice: case OSArgumentType::Path: if (user_argument.domainAsString() != script_argument.domainAsString()) { registerWarning(ss.str()); } break; default: OS_ASSERT(false); } ss.str(""); } // success, set the values if (result) { Quantity q; switch(user_argument.type().value()) { case OSArgumentType::Boolean : if (user_argument.hasValue()) { argumentValueAttributes.push_back(Attribute(user_argument.name(),user_argument.valueAsBool())); } else if (user_argument.hasDefaultValue()) { argumentValueAttributes.push_back(Attribute(user_argument.name(),user_argument.defaultValueAsBool())); } break; case OSArgumentType::Double : if (user_argument.hasValue()) { argumentValueAttributes.push_back(Attribute(user_argument.name(),user_argument.valueAsDouble())); } else if (user_argument.hasDefaultValue()) { argumentValueAttributes.push_back(Attribute(user_argument.name(),user_argument.defaultValueAsDouble())); } break; case OSArgumentType::Quantity : if (user_argument.hasValue()) { q = user_argument.valueAsQuantity(); } else if (user_argument.hasDefaultValue()) { q = user_argument.defaultValueAsQuantity(); } argumentValueAttributes.push_back(Attribute(user_argument.name(),q.value(),q.units().print())); break; case OSArgumentType::Integer : if (user_argument.hasValue()) { argumentValueAttributes.push_back(Attribute(user_argument.name(),user_argument.valueAsInteger())); } else if (user_argument.hasDefaultValue()) { argumentValueAttributes.push_back(Attribute(user_argument.name(),user_argument.defaultValueAsInteger())); } break; case OSArgumentType::String : case OSArgumentType::Choice : case OSArgumentType::Path : if (user_argument.hasValue()) { argumentValueAttributes.push_back(Attribute(user_argument.name(),user_argument.valueAsString())); } else if (user_argument.hasDefaultValue()) { argumentValueAttributes.push_back(Attribute(user_argument.name(),user_argument.defaultValueAsString())); } break; default: OS_ASSERT(false); } } } } if (result) { for (Attribute& attribute : argumentValueAttributes) { registerAttribute(attribute); } } return result; }
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); }