Base: UnitsSchema: return std::string
This commit is contained in:
committed by
Yorik van Havre
parent
2ea8a633ac
commit
4d6ed9d531
@@ -22,57 +22,41 @@
|
||||
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#ifdef __GNUC__
|
||||
#include <unistd.h>
|
||||
#ifndef _PreComp_
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <utility>
|
||||
#endif
|
||||
|
||||
#include <QString>
|
||||
|
||||
#include "UnitsSchemaCentimeters.h"
|
||||
|
||||
|
||||
using namespace Base;
|
||||
|
||||
|
||||
QString UnitsSchemaCentimeters::schemaTranslate(const Base::Quantity& quant,
|
||||
double& factor,
|
||||
QString& unitString)
|
||||
std::string UnitsSchemaCentimeters::schemaTranslate(const Base::Quantity& quant,
|
||||
double& factor,
|
||||
std::string& unitString)
|
||||
{
|
||||
Unit unit = quant.getUnit();
|
||||
if (unit == Unit::Length) {
|
||||
// all length units in centimeters
|
||||
unitString = QString::fromLatin1("cm");
|
||||
factor = 10.0;
|
||||
}
|
||||
else if (unit == Unit::Area) {
|
||||
// all area units in square meters
|
||||
unitString = QString::fromLatin1("m^2");
|
||||
factor = 1000000.0;
|
||||
}
|
||||
else if (unit == Unit::Volume) {
|
||||
// all area units in cubic meters
|
||||
unitString = QString::fromLatin1("m^3");
|
||||
factor = 1000000000.0;
|
||||
}
|
||||
else if (unit == Unit::Power) {
|
||||
unitString = QString::fromLatin1("W");
|
||||
factor = 1000000;
|
||||
}
|
||||
else if (unit == Unit::ElectricPotential) {
|
||||
unitString = QString::fromLatin1("V");
|
||||
factor = 1000000;
|
||||
}
|
||||
else if (unit == Unit::HeatFlux) {
|
||||
unitString = QString::fromLatin1("W/m^2");
|
||||
factor = 1.0;
|
||||
}
|
||||
else if (unit == Unit::Velocity) {
|
||||
unitString = QString::fromLatin1("mm/min");
|
||||
factor = 1.0 / 60;
|
||||
static std::array<std::pair<Unit, std::pair<std::string, double>>, 7> unitSpecs {{
|
||||
{Unit::Length, {"cm", 10.0}},
|
||||
{Unit::Area, {"m^2", 1000000.0}},
|
||||
{Unit::Volume, {"m^3", 1000000000.0}},
|
||||
{Unit::Power, {"W", 1000000.0}},
|
||||
{Unit::ElectricPotential, {"V", 1000000.0}},
|
||||
{Unit::HeatFlux, {"W/m^2", 1.0}},
|
||||
{Unit::Velocity, {"mm/min", 1.0 / 60}},
|
||||
}};
|
||||
|
||||
const auto unit = quant.getUnit();
|
||||
const auto spec = std::find_if(unitSpecs.begin(), unitSpecs.end(), [&](const auto& pair) {
|
||||
return pair.first == unit;
|
||||
});
|
||||
|
||||
if (spec != std::end(unitSpecs)) {
|
||||
unitString = spec->second.first;
|
||||
factor = spec->second.second;
|
||||
}
|
||||
else {
|
||||
// default action for all cases without special treatment:
|
||||
unitString = QString::fromStdString(quant.getUnit().getString());
|
||||
unitString = quant.getUnit().getString();
|
||||
factor = 1.0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user