PyObject* MatrixPy::rotateZ(PyObject * args)
{
    double angle = 0;
    do {
        PyObject *object;
        if (PyArg_ParseTuple(args,"O!",&(Base::QuantityPy::Type), &object)) {
            Quantity *q = static_cast<Base::QuantityPy*>(object)->getQuantityPtr();
            if (q->getUnit() == Base::Unit::Angle) {
                angle = q->getValueAs(Base::Quantity::Radian);
                break;
            }
        }

        PyErr_Clear();
        if (PyArg_ParseTuple(args, "d: angle to rotate (double) needed", &angle)) {
            break;
        }

        PyErr_SetString(PyExc_TypeError, "For angle either float or Quantity expected");
        return 0;
    }
    while (false);

    PY_TRY {
        getMatrixPtr()->rotZ(angle);
    }
    PY_CATCH;

    Py_Return;
}
void InputField::newInput(const QString & text)
{
    Quantity res;
    try{
        res = Quantity::parse(text);
    }catch(Base::Exception &e){
        ErrorText = e.what();
        this->setToolTip(QString::fromAscii(ErrorText.c_str()));
        QPixmap pixmap = BitmapFactory().pixmapFromSvg(":/icons/button_invalid.svg", QSize(sizeHint().height(),sizeHint().height()));
        iconLabel->setPixmap(pixmap);
        parseError(QString::fromAscii(ErrorText.c_str()));
        return;
    }

    QPixmap pixmap = BitmapFactory().pixmapFromSvg(":/icons/button_valid.svg", QSize(sizeHint().height(),sizeHint().height()));
    iconLabel->setPixmap(pixmap);

    ErrorText = "";
    this->setToolTip(QString::fromAscii(ErrorText.c_str()));
    actQuantity = res;
    double dFactor;
    res.getUserString(dFactor,actUnitStr);
    // calculate the number shown 
    actUnitValue = res.getValue()/dFactor; 
    // signaling 
    valueChanged(res);

}
void InputField::newInput(const QString & text)
{
    Quantity res;
    try{
        res = Quantity::parse(text);
    }catch(Base::Exception &e){
        ErrorText = e.what();
        this->setToolTip(QString::fromAscii(ErrorText.c_str()));
        QPalette palette;
        palette.setColor(QPalette::Base,QColor(255,200,200));
        setPalette(palette);
        parseError(QString::fromAscii(ErrorText.c_str()));
        return;
    }
    QPalette palette;
    palette.setColor(QPalette::Base,QColor(200,255,200));
    setPalette(palette);
    ErrorText = "";
    this->setToolTip(QString::fromAscii(ErrorText.c_str()));
    actQuantity = res;
    double dFactor;
    res.getUserString(dFactor,actUnitStr);
    // calculate the number shown 
    actUnitValue = res.getValue()/dFactor; 
    // signaling 
    valueChanged(res);

}
void QuantityManager::read(const std::string & data) {
	std::stringstream strm(data);
	std::string line;
	while (getline(strm,line)) {
		IBK::trim(line);
		if (line.empty() || line[0] == '#') continue;
		Quantity qd;
		try {
			qd.read(line);
		}
		catch (IBK::Exception & ex) {
			throw IBK::Exception(ex, IBK::FormatString("Cannot read quantity definition from line '%1'.")
				.arg(line), "[QuantityManager::read]");
		}
		// check if we already have such a quantity
		int idx = index(qd);
		if (idx != -1) {
			// replace quantity
			IBK::IBK_Message(IBK::FormatString("Replacing quantity '%1::%2' with new definition.\n")
							 .arg(Quantity::type2string(qd.m_type))
							 .arg(qd.m_name), IBK::MSG_PROGRESS, "QuantityManager::read" ,1);
			m_quantities[idx] = qd;
		}
		else {
			// add quantity to list
			m_quantities.push_back(qd);
			// add new reference to global index map
			m_globalIndexMap[ std::make_pair(qd.m_type, qd.m_name)]= m_quantities.size()-1;
		}
	}
}
 Quantity UnitOfMeasureConversion::convert(const Quantity& quantity) const {
     switch (data_->type) {
       case Direct:
         if (quantity.unitOfMeasure() == data_->source)
             return Quantity(quantity.commodityType(),
                             data_->target,
                             quantity.amount()*data_->conversionFactor);
         else if (quantity.unitOfMeasure() == data_->target)
             return Quantity(quantity.commodityType(),
                             data_->source,
                             quantity.amount()/data_->conversionFactor);
         else
             QL_FAIL("direct conversion not applicable");
       case Derived:
         if (quantity.unitOfMeasure()
             == data_->conversionFactorChain.first->source() ||
             quantity.unitOfMeasure()
             == data_->conversionFactorChain.first->target())
             return data_->conversionFactorChain.second->convert(
                    data_->conversionFactorChain.first->convert(quantity));
         else if (quantity.unitOfMeasure()
                  == data_->conversionFactorChain.second->source() ||
                  quantity.unitOfMeasure()
                  == data_->conversionFactorChain.second->target())
             return data_->conversionFactorChain.first->convert(
                   data_->conversionFactorChain.second->convert(quantity));
         else
             QL_FAIL("derived conversion factor not applicable");
       default:
         QL_FAIL("unknown conversion-factor type");
     }
 }
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());
}
Exemple #7
0
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;
}
void QuantitySpinBox::updateText(const Quantity &quant)
{
    Q_D(QuantitySpinBox);

    double dFactor;
    QString txt = quant.getUserString(dFactor,d->unitStr);
    d->unitValue = quant.getValue()/dFactor;
    lineEdit()->setText(txt);
}
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());
}
Exemple #10
0
Quantity Constraint::getPresentationValue() const
{
    Quantity quantity;
    switch (Type) {
    case Distance:
    case Radius:
    case DistanceX:
    case DistanceY:
        quantity.setValue(Value);
        quantity.setUnit(Unit::Length);
        break;
    case Angle:
        quantity.setValue(toDegrees<double>(Value));
        quantity.setUnit(Unit::Angle);
        break;
    case SnellsLaw:
        quantity.setValue(Value);
        break;
    default:
        quantity.setValue(Value);
        break;
    }

    QuantityFormat format = quantity.getFormat();
    format.option = QuantityFormat::None;
    format.format = QuantityFormat::Default;
    format.precision = 6; // QString's default
    quantity.setFormat(format);
    return quantity;
}
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());
}
Exemple #12
0
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());
}
Exemple #13
0
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,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,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,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,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,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,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,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());
}
Exemple #22
0
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,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,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,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,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,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,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,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,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());
}