Implement the three major unit system schemas
This commit is contained in:
@@ -34,25 +34,86 @@
|
||||
using namespace Base;
|
||||
|
||||
|
||||
|
||||
//void UnitsSchemaImperial1::setSchemaUnits(void){
|
||||
// // here you could change the constances used by the parser (defined in Quantity.cpp)
|
||||
// Quantity::Inch = Quantity (25.4 ,Unit(1));
|
||||
// Quantity::Foot = Quantity (304.8 ,Unit(1));
|
||||
// Quantity::Thou = Quantity (0.0254 ,Unit(1));
|
||||
// Quantity::Yard = Quantity (914.4 ,Unit(1));
|
||||
// Quantity::Mile = Quantity (1609344.0 ,Unit(1));
|
||||
//}
|
||||
//
|
||||
//void UnitsSchemaImperial1::resetSchemaUnits(void){
|
||||
// // set units to US customary / Imperial units
|
||||
// Quantity::Inch = Quantity (25.4 ,Unit(1));
|
||||
// Quantity::Foot = Quantity (304.8 ,Unit(1));
|
||||
// Quantity::Thou = Quantity (0.0254 ,Unit(1));
|
||||
// Quantity::Yard = Quantity (914.4 ,Unit(1));
|
||||
// Quantity::Mile = Quantity (1609344.0 ,Unit(1));
|
||||
//}
|
||||
|
||||
QString UnitsSchemaImperial1::schemaTranslate(Base::Quantity quant,double &factor,QString &unitString)
|
||||
{
|
||||
double UnitValue = quant.getValue();
|
||||
Unit unit = quant.getUnit();
|
||||
// for imperial user/programmer mind; UnitValue is in internal system, that means
|
||||
// mm/kg/s. And all combined units have to be calculated from there!
|
||||
|
||||
return QString::fromAscii("%1 %2").arg(UnitValue).arg(QString::fromAscii(unit.getString().c_str()));
|
||||
// now do special treatment on all cases seams nececarry:
|
||||
if(unit == Unit::Length){ // Length handling ============================
|
||||
if(UnitValue < 0.00000254){// smaller then 0.001 thou -> inch and scientific notation
|
||||
unitString = QString::fromLatin1("in");
|
||||
factor = 25.4;
|
||||
}else if(UnitValue < 2.54){ // smaller then 0.1 inch -> Thou (mil)
|
||||
unitString = QString::fromLatin1("thou");
|
||||
factor = 0.0254;
|
||||
}else if(UnitValue < 304.8){
|
||||
unitString = QString::fromLatin1("in");
|
||||
factor = 25.4;
|
||||
}else if(UnitValue < 914.4){
|
||||
unitString = QString::fromLatin1("ft");
|
||||
factor = 304.8;
|
||||
}else if(UnitValue < 1609344.0){
|
||||
unitString = QString::fromLatin1("yr");
|
||||
factor = 914.4;
|
||||
}else if(UnitValue < 1609344000.0 ){
|
||||
unitString = QString::fromLatin1("mi");
|
||||
factor = 1609344.0;
|
||||
}else{ // bigger then 1000 mi -> scientific notation
|
||||
unitString = QString::fromLatin1("in");
|
||||
factor = 25.4;
|
||||
}
|
||||
}else if (unit == Unit::Area){
|
||||
// TODO Cascade for the Areas
|
||||
// default action for all cases without special treatment:
|
||||
unitString = QString::fromLatin1("in^2");
|
||||
factor = 645.16;
|
||||
}else if (unit == Unit::Volume){
|
||||
// TODO Cascade for the Volume
|
||||
// default action for all cases without special treatment:
|
||||
unitString = QString::fromLatin1("in^3");
|
||||
factor = 16387.1;
|
||||
}else if (unit == Unit::Mass){
|
||||
// TODO Cascade for the wights
|
||||
// default action for all cases without special treatment:
|
||||
unitString = QString::fromLatin1("lb");
|
||||
factor = 0.45359237;
|
||||
}else if (unit == Unit::Pressure){
|
||||
if(UnitValue < 145.038){// psi is the smallest
|
||||
unitString = QString::fromLatin1("psi");
|
||||
factor = 0.145038;
|
||||
}else if(UnitValue < 145038){
|
||||
unitString = QString::fromLatin1("ksi");
|
||||
factor = 145.038;
|
||||
}else{ // bigger then 1000 ksi -> psi + scientific notation
|
||||
unitString = QString::fromLatin1("psi");
|
||||
factor = 0.145038;
|
||||
}
|
||||
}else{
|
||||
// default action for all cases without special treatment:
|
||||
unitString = QString::fromLatin1(quant.getUnit().getString().c_str());
|
||||
factor = 1.0;
|
||||
}
|
||||
return QString::fromLatin1("%1 %2").arg(UnitValue / factor).arg(unitString);
|
||||
}
|
||||
//
|
||||
//Base::Quantity UnitsSchemaImperial1::schemaPrefUnit(const Base::Unit &unit,QString &outUnitString)
|
||||
//{
|
||||
// if(unit == Unit::Length){
|
||||
// outUnitString = QString::fromAscii("\"");
|
||||
// return Base::Quantity(1/25.40,Unit::Length);
|
||||
// }else if(unit == Unit::Mass){
|
||||
// outUnitString = QString::fromAscii("lb");
|
||||
// return Base::Quantity(1/0.45359237,Unit::Length);
|
||||
// }else{
|
||||
// outUnitString = QString::fromAscii(unit.getString().c_str());
|
||||
// return Base::Quantity(1,unit);
|
||||
// }
|
||||
//
|
||||
//}
|
||||
Reference in New Issue
Block a user