Added new units schema: US building (feet + inches + fraction)
This commit is contained in:
parent
966ce79207
commit
ad92a2df25
|
@ -92,6 +92,7 @@ void UnitsApi::setSchema(UnitSystem s)
|
|||
case Imperial1: UserPrefSystem = new UnitsSchemaImperial1(); break;
|
||||
case ImperialDecimal: UserPrefSystem = new UnitsSchemaImperialDecimal(); break;
|
||||
case Centimeters: UserPrefSystem = new UnitsSchemaCentimeters(); break;
|
||||
case ImperialBuilding: UserPrefSystem = new UnitsSchemaImperialBuilding(); break;
|
||||
default : UserPrefSystem = new UnitsSchemaInternal(); s = SI1; break;
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,8 @@ enum UnitSystem {
|
|||
SI2 = 1 , /** MKS (m,kg,s) SI system */
|
||||
Imperial1 = 2, /** the Imperial system (http://en.wikipedia.org/wiki/Imperial_units) */
|
||||
ImperialDecimal = 3, /** Imperial with length in inch only */
|
||||
Centimeters = 4 /** All lengths in centimeters, areas and volumes in square/cubic meters */
|
||||
Centimeters = 4, /** All lengths in centimeters, areas and volumes in square/cubic meters */
|
||||
ImperialBuilding = 5 /** All lengths in feet + inches + fractions */
|
||||
} ;
|
||||
|
||||
|
||||
|
|
|
@ -21,7 +21,10 @@
|
|||
***************************************************************************/
|
||||
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
# include <sstream>
|
||||
#endif
|
||||
#ifdef __GNUC__
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
@ -58,7 +61,7 @@ using namespace Base;
|
|||
QString UnitsSchemaImperial1::schemaTranslate(Base::Quantity quant,double &factor,QString &unitString)
|
||||
{
|
||||
double UnitValue = std::abs(quant.getValue());
|
||||
Unit unit = quant.getUnit();
|
||||
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!
|
||||
|
||||
|
@ -117,7 +120,7 @@ QString UnitsSchemaImperial1::schemaTranslate(Base::Quantity quant,double &facto
|
|||
unitString = quant.getUnit().getString();
|
||||
factor = 1.0;
|
||||
}
|
||||
return QString::fromLatin1("%L1 %2").arg(quant.getValue() / factor).arg(unitString);
|
||||
return QString::fromLatin1("%L1 %2").arg(quant.getValue() / factor).arg(unitString);
|
||||
}
|
||||
|
||||
|
||||
|
@ -126,7 +129,7 @@ QString UnitsSchemaImperial1::schemaTranslate(Base::Quantity quant,double &facto
|
|||
QString UnitsSchemaImperialDecimal::schemaTranslate(Base::Quantity quant,double &factor,QString &unitString)
|
||||
{
|
||||
double UnitValue = std::abs(quant.getValue());
|
||||
Unit unit = quant.getUnit();
|
||||
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!
|
||||
|
||||
|
@ -176,6 +179,77 @@ QString UnitsSchemaImperialDecimal::schemaTranslate(Base::Quantity quant,double
|
|||
QLocale Lc = QLocale::system();
|
||||
Lc.setNumberOptions(Lc.OmitGroupSeparator | Lc.RejectGroupSeparator);
|
||||
QString Ln = Lc.toString(quant.getValue() / factor);
|
||||
return QString::fromLatin1("%1 %2").arg(Ln).arg(unitString);
|
||||
//return QString::fromLatin1("%L1 %2").arg(quant.getValue() / factor).arg(unitString);
|
||||
return QString::fromLatin1("%1 %2").arg(Ln).arg(unitString);
|
||||
//return QString::fromLatin1("%L1 %2").arg(quant.getValue() / factor).arg(unitString);
|
||||
}
|
||||
|
||||
|
||||
|
||||
QString UnitsSchemaImperialBuilding::schemaTranslate(Base::Quantity quant,double &factor,QString &unitString)
|
||||
{
|
||||
// this schema expresses distances in feet + inches + fractions
|
||||
// ex: 3'- 4 1/4"
|
||||
Unit unit = quant.getUnit();
|
||||
if(unit == Unit::Length){
|
||||
unitString = QString::fromLatin1("in");
|
||||
factor = 25.4;
|
||||
double inchValue = quant.getValue()/25.4;
|
||||
int feet = inchValue/12;
|
||||
double inchPart = inchValue - (double)feet*12;
|
||||
int inches = (int)inchPart;
|
||||
double fraction = inchPart - (int)inchPart;
|
||||
if (fraction > 0.9375) {
|
||||
inches++;
|
||||
fraction = 0.0;
|
||||
}
|
||||
// if the quantity is too small it is rounded to zero
|
||||
if (quant.getValue() <= 1.5875)
|
||||
return QString::fromLatin1("0");
|
||||
// build representation
|
||||
std::stringstream output;
|
||||
// feet
|
||||
if (feet > 0) {
|
||||
output << feet << "'";
|
||||
if ( (inches > 0) || (fraction > 0.0625) )
|
||||
output << " - ";
|
||||
}
|
||||
// inches
|
||||
if (inches > 0) {
|
||||
output << inches;
|
||||
if (fraction > 0.0625)
|
||||
output << " ";
|
||||
else
|
||||
output << "\"";
|
||||
}
|
||||
// fraction
|
||||
if (fraction <= 0.0625) {}
|
||||
else if (fraction > 0.8125)
|
||||
output << "7/8\"";
|
||||
else if (fraction > 0.6875)
|
||||
output << "3/4\"";
|
||||
else if (fraction > 0.5625)
|
||||
output << "5/8\"";
|
||||
else if (fraction > 0.4375)
|
||||
output << "1/2\"";
|
||||
else if (fraction > 0.3125)
|
||||
output << "3/8\"";
|
||||
else if (fraction > 0.1875)
|
||||
output << "1/4\"";
|
||||
else
|
||||
output << "1/8\"";
|
||||
return QString::fromLatin1(output.str().c_str());
|
||||
}else if (unit == Unit::Area){
|
||||
unitString = QString::fromLatin1("sqft");
|
||||
factor = 92903.04;
|
||||
}else if (unit == Unit::Volume){
|
||||
unitString = QString::fromLatin1("cuft");
|
||||
factor = 28316846.592;
|
||||
}else{
|
||||
unitString = quant.getUnit().getString();
|
||||
factor = 1.0;
|
||||
}
|
||||
QLocale Lc = QLocale::system();
|
||||
Lc.setNumberOptions(Lc.OmitGroupSeparator | Lc.RejectGroupSeparator);
|
||||
QString Ln = Lc.toString(quant.getValue() / factor);
|
||||
return QString::fromLatin1("%1 %2").arg(Ln).arg(unitString);
|
||||
}
|
||||
|
|
|
@ -58,6 +58,19 @@ public:
|
|||
|
||||
};
|
||||
|
||||
/** The schema class for the imperial unit system
|
||||
* Here are the definiton for the imperial unit system.
|
||||
* It also defines how the value/units get printed.
|
||||
*/
|
||||
class UnitsSchemaImperialBuilding: public UnitsSchema
|
||||
{
|
||||
public:
|
||||
//virtual void setSchemaUnits(void);
|
||||
//virtual void resetSchemaUnits(void);
|
||||
virtual QString schemaTranslate(Base::Quantity quant,double &factor,QString &unitString);
|
||||
|
||||
};
|
||||
|
||||
|
||||
} // namespace Base
|
||||
|
||||
|
|
|
@ -56,6 +56,11 @@
|
|||
<string>Building Euro (cm/m²/m³)</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Building US (ft-in/sqft/cuft)</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
|
|
Loading…
Reference in New Issue
Block a user