Base: UnitsSchema: return std::string

This commit is contained in:
Ladislav Michl
2024-07-13 17:19:27 +02:00
committed by Yorik van Havre
parent 2ea8a633ac
commit 4d6ed9d531
25 changed files with 493 additions and 589 deletions

View File

@@ -239,19 +239,13 @@ Quantity Quantity::operator-() const
std::string Quantity::getUserString(double& factor, std::string& unitString) const
{
QString str = QString::fromStdString(unitString);
QString ret = Base::UnitsApi::schemaTranslate(*this, factor, str);
unitString = str.toStdString();
return ret.toStdString();
return Base::UnitsApi::schemaTranslate(*this, factor, unitString);
}
std::string
Quantity::getUserString(UnitsSchema* schema, double& factor, std::string& unitString) const
{
QString str = QString::fromStdString(unitString);
QString ret = schema->schemaTranslate(*this, factor, str);
unitString = str.toStdString();
return ret.toStdString();
return schema->schemaTranslate(*this, factor, unitString);
}
std::string Quantity::getSafeUserString() const

View File

@@ -176,7 +176,8 @@ std::string UnitsApi::getBasicLengthUnit()
// === static translation methods ==========================================
QString UnitsApi::schemaTranslate(const Base::Quantity& quant, double& factor, QString& unitString)
std::string
UnitsApi::schemaTranslate(const Base::Quantity& quant, double& factor, std::string& unitString)
{
return UserPrefSystem->schemaTranslate(quant, factor, unitString);
}

View File

@@ -60,12 +60,12 @@ public:
/// Returns a brief description of a schema
static QString getDescription(UnitSystem);
static QString
schemaTranslate(const Base::Quantity& quant, double& factor, QString& unitString);
static QString schemaTranslate(const Base::Quantity& quant)
static std::string
schemaTranslate(const Base::Quantity& quant, double& factor, std::string& unitString);
static std::string schemaTranslate(const Base::Quantity& quant)
{ // to satisfy GCC
double dummy1 {};
QString dummy2;
std::string dummy2;
return UnitsApi::schemaTranslate(quant, dummy1, dummy2);
}

View File

@@ -174,13 +174,13 @@ PyObject* UnitsApi::sSchemaTranslate(PyObject* /*self*/, PyObject* args)
}
double factor {};
QString uus;
QString uss = schema->schemaTranslate(quant, factor, uus);
std::string uus;
std::string uss = schema->schemaTranslate(quant, factor, uus);
Py::Tuple res(3);
res[0] = Py::String(uss.toUtf8(), "utf-8");
res[0] = Py::String(uss, "utf-8");
res[1] = Py::Float(factor);
res[2] = Py::String(uus.toUtf8(), "utf-8");
res[2] = Py::String(uus, "utf-8");
return Py::new_reference_to(res);
}

View File

@@ -20,7 +20,6 @@
* *
***************************************************************************/
#include "PreCompiled.h"
#ifdef __GNUC__
#include <unistd.h>
@@ -31,11 +30,11 @@
#include "UnitsSchema.h"
using namespace Base;
QString
UnitsSchema::toLocale(const Base::Quantity& quant, double factor, const QString& unitString) const
std::string UnitsSchema::toLocale(const Base::Quantity& quant,
double factor,
const std::string& unitString) const
{
QLocale Lc;
const QuantityFormat& format = quant.getFormat();
@@ -45,5 +44,7 @@ UnitsSchema::toLocale(const Base::Quantity& quant, double factor, const QString&
}
QString Ln = Lc.toString((quant.getValue() / factor), format.toFormat(), format.precision);
return QString::fromUtf8("%1 %2").arg(Ln, unitString);
return QString::fromStdString("%1 %2")
.arg(Ln, QString::fromStdString(unitString))
.toStdString();
}

View File

@@ -20,14 +20,12 @@
* *
***************************************************************************/
#ifndef BASE_UNITSSCHEMA_H
#define BASE_UNITSSCHEMA_H
#include <QString>
#include <string>
#include <Base/Quantity.h>
namespace Base
{
@@ -73,10 +71,11 @@ public:
{}
/// This method translates the quantity in a string as the user may expect it.
virtual QString
schemaTranslate(const Base::Quantity& quant, double& factor, QString& unitString) = 0;
virtual std::string
schemaTranslate(const Base::Quantity& quant, double& factor, std::string& unitString) = 0;
QString toLocale(const Base::Quantity& quant, double factor, const QString& unitString) const;
std::string
toLocale(const Base::Quantity& quant, double factor, const std::string& unitString) const;
// return true if this schema uses multiple units for length (ex. Ft/In)
virtual bool isMultiUnitLength() const
@@ -97,8 +96,6 @@ public:
}
};
} // namespace Base
#endif // BASE_UNITSSCHEMA_H

View File

@@ -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;
}

View File

@@ -20,14 +20,11 @@
* *
***************************************************************************/
#ifndef BASE_UNITSSCHEMACENTIMETERS_H
#define BASE_UNITSSCHEMACENTIMETERS_H
#include <QString>
#include "UnitsSchema.h"
namespace Base
{
@@ -37,8 +34,8 @@ namespace Base
class UnitsSchemaCentimeters: public UnitsSchema
{
public:
QString
schemaTranslate(const Base::Quantity& quant, double& factor, QString& unitString) override;
std::string
schemaTranslate(const Base::Quantity& quant, double& factor, std::string& unitString) override;
std::string getBasicLengthUnit() const override
{

View File

@@ -23,37 +23,38 @@
#include "PreCompiled.h"
#ifdef __GNUC__
#include <unistd.h>
#ifndef _PreComp_
#include <algorithm>
#include <array>
#include <utility>
#endif
#include <QString>
#include "UnitsSchemaFemMilliMeterNewton.h"
using namespace Base;
QString UnitsSchemaFemMilliMeterNewton::schemaTranslate(const Quantity& quant,
double& factor,
QString& unitString)
std::string UnitsSchemaFemMilliMeterNewton::schemaTranslate(const Quantity& quant,
double& factor,
std::string& unitString)
{
Unit unit = quant.getUnit();
if (unit == Unit::Length) {
// all length units in millimeters
unitString = QString::fromLatin1("mm");
factor = 1.0;
}
else if (unit == Unit::Mass) {
// all mass units in t
unitString = QString::fromUtf8("t");
factor = 1e3;
static std::array<std::pair<Unit, std::pair<std::string, double>>, 2> unitSpecs {{
{Unit::Length, {"mm", 1.0}},
{Unit::Mass, {"t", 1e3}},
}};
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;
}
return toLocale(quant, factor, unitString);
}

View File

@@ -21,18 +21,14 @@
* *
***************************************************************************/
#ifndef BASE_UNITSSCHEMAFEMMLLIMETERNEWTON_H
#define BASE_UNITSSCHEMAFEMMLLIMETERNEWTON_H
#include <QString>
#include "UnitsSchema.h"
namespace Base
{
/* Milli metric / Newton / Seconds unit schema for use in FEM.
* Lengths are always in mm.
* Mass is in t.
@@ -42,12 +38,10 @@ namespace Base
class UnitsSchemaFemMilliMeterNewton: public UnitsSchema
{
public:
QString
schemaTranslate(const Base::Quantity& quant, double& factor, QString& unitString) override;
std::string
schemaTranslate(const Base::Quantity& quant, double& factor, std::string& unitString) override;
};
} // namespace Base
#endif // BASE_UNITSSCHEMAFEMMLLIMETERNEWTON_H

View File

@@ -30,16 +30,13 @@
#include <unistd.h>
#endif
#include <QString>
#include "UnitsSchemaImperial1.h"
using namespace Base;
QString
UnitsSchemaImperial1::schemaTranslate(const Quantity& quant, double& factor, QString& unitString)
std::string UnitsSchemaImperial1::schemaTranslate(const Quantity& quant,
double& factor,
std::string& unitString)
{
double UnitValue = std::abs(quant.getValue());
Unit unit = quant.getUnit();
@@ -49,157 +46,156 @@ UnitsSchemaImperial1::schemaTranslate(const Quantity& quant, double& factor, QSt
// now do special treatment on all cases seems necessary:
if (unit == Unit::Length) { // Length handling ============================
if (UnitValue < 0.00000254) { // smaller then 0.001 thou -> inch and scientific notation
unitString = QString::fromLatin1("in");
unitString = "in";
factor = 25.4;
}
else if (UnitValue < 2.54) { // smaller then 0.1 inch -> Thou (mil)
unitString = QString::fromLatin1("thou");
unitString = "thou";
factor = 0.0254;
}
else if (UnitValue < 304.8) {
unitString = QString::fromLatin1("\"");
unitString = "\"";
factor = 25.4;
}
else if (UnitValue < 914.4) {
unitString = QString::fromLatin1("\'");
unitString = "\'";
factor = 304.8;
}
else if (UnitValue < 1609344.0) {
unitString = QString::fromLatin1("yd");
unitString = "yd";
factor = 914.4;
}
else if (UnitValue < 1609344000.0) {
unitString = QString::fromLatin1("mi");
unitString = "mi";
factor = 1609344.0;
}
else { // bigger then 1000 mi -> scientific notation
unitString = QString::fromLatin1("in");
unitString = "in";
factor = 25.4;
}
}
else if (unit == Unit::Angle) {
unitString = QString::fromUtf8("\xC2\xB0");
unitString = "\xC2\xB0";
factor = 1.0;
}
else if (unit == Unit::Area) {
// TODO: Cascade for the Areas
// default action for all cases without special treatment:
unitString = QString::fromLatin1("in^2");
unitString = "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");
unitString = "in^3";
factor = 16387.064;
}
else if (unit == Unit::Mass) {
// TODO: Cascade for the weights
// default action for all cases without special treatment:
unitString = QString::fromLatin1("lb");
unitString = "lb";
factor = 0.45359237;
}
else if (unit == Unit::Pressure) {
if (UnitValue < 6894.744) { // psi is the smallest
unitString = QString::fromLatin1("psi");
unitString = "psi";
factor = 6.894744825494;
}
else if (UnitValue < 6894744.825) {
unitString = QString::fromLatin1("ksi");
unitString = "ksi";
factor = 6894.744825494;
}
else { // bigger then 1000 ksi -> psi + scientific notation
unitString = QString::fromLatin1("psi");
unitString = "psi";
factor = 6.894744825494;
}
}
else if (unit == Unit::Stiffness) { // Conversion to lbf/in
unitString = QString::fromLatin1("lbf/in");
unitString = "lbf/in";
factor = 4.448222 / 0.0254;
}
else if (unit == Unit::Velocity) {
unitString = QString::fromLatin1("in/min");
unitString = "in/min";
factor = 25.4 / 60;
}
else {
// default action for all cases without special treatment:
unitString = QString::fromStdString(quant.getUnit().getString());
unitString = quant.getUnit().getString();
factor = 1.0;
}
return toLocale(quant, factor, unitString);
}
QString UnitsSchemaImperialDecimal::schemaTranslate(const Base::Quantity& quant,
double& factor,
QString& unitString)
std::string UnitsSchemaImperialDecimal::schemaTranslate(const Base::Quantity& quant,
double& factor,
std::string& unitString)
{
// double UnitValue = std::abs(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!
// now do special treatment on all cases seems necessary:
if (unit == Unit::Length) { // Length handling ============================
unitString = QString::fromLatin1("in");
unitString = "in";
factor = 25.4;
}
else if (unit == Unit::Angle) {
unitString = QString::fromUtf8("\xC2\xB0");
unitString = "\xC2\xB0";
factor = 1.0;
}
else if (unit == Unit::Area) {
// TODO: Cascade for the Areas
// default action for all cases without special treatment:
unitString = QString::fromLatin1("in^2");
unitString = "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");
unitString = "in^3";
factor = 16387.064;
}
else if (unit == Unit::Mass) {
// TODO: Cascade for the weights
// default action for all cases without special treatment:
unitString = QString::fromLatin1("lb");
unitString = "lb";
factor = 0.45359237;
}
else if (unit == Unit::Pressure) {
unitString = QString::fromLatin1("psi");
unitString = "psi";
factor = 6.894744825494;
}
else if (unit == Unit::Stiffness) {
unitString = QString::fromLatin1("lbf/in");
unitString = "lbf/in";
factor = 4.448222 / 0.0254;
}
else if (unit == Unit::Velocity) {
unitString = QString::fromLatin1("in/min");
unitString = "in/min";
factor = 25.4 / 60;
}
else if (unit == Unit::Acceleration) {
unitString = QString::fromLatin1("in/min^2");
unitString = "in/min^2";
factor = 25.4 / 3600;
}
else {
// default action for all cases without special treatment:
unitString = QString::fromStdString(quant.getUnit().getString());
unitString = quant.getUnit().getString();
factor = 1.0;
}
return toLocale(quant, factor, unitString);
}
QString UnitsSchemaImperialBuilding::schemaTranslate(const Quantity& quant,
double& factor,
QString& unitString)
std::string UnitsSchemaImperialBuilding::schemaTranslate(const Quantity& quant,
double& factor,
std::string& unitString)
{
// this schema expresses distances in feet + inches + fractions
// ex: 3'- 4 1/4" with proper rounding
Unit unit = quant.getUnit();
if (unit == Unit::Length) {
unitString = QString::fromLatin1("in");
unitString = "in";
factor = 25.4;
// Total number of inches to format
@@ -227,7 +223,7 @@ QString UnitsSchemaImperialBuilding::schemaTranslate(const Quantity& quant,
// If this is zero, nothing to do but return
if (ntot == 0) {
return QString::fromLatin1("0");
return "0";
}
// Compute the whole number of feet and remaining units
@@ -293,77 +289,76 @@ QString UnitsSchemaImperialBuilding::schemaTranslate(const Quantity& quant,
}
// Done!
return QString::fromLatin1(output.str().c_str());
return output.str();
}
else if (unit == Unit::Angle) {
unitString = QString::fromUtf8("\xC2\xB0");
unitString = "\xC2\xB0";
factor = 1.0;
}
else if (unit == Unit::Area) {
unitString = QString::fromLatin1("sqft");
unitString = "sqft";
factor = 92903.04;
}
else if (unit == Unit::Volume) {
unitString = QString::fromLatin1("cft");
unitString = "cft";
factor = 28316846.592;
}
else if (unit == Unit::Velocity) {
unitString = QString::fromLatin1("in/min");
unitString = "in/min";
factor = 25.4 / 60;
}
else {
unitString = QString::fromStdString(quant.getUnit().getString());
unitString = quant.getUnit().getString();
factor = 1.0;
}
return toLocale(quant, factor, unitString);
}
QString UnitsSchemaImperialCivil::schemaTranslate(const Base::Quantity& quant,
double& factor,
QString& unitString)
std::string UnitsSchemaImperialCivil::schemaTranslate(const Base::Quantity& quant,
double& factor,
std::string& unitString)
{
// double UnitValue = std::abs(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!
// now do special treatment on all cases seems necessary:
if (unit == Unit::Length) { // Length handling ============================
unitString = QString::fromLatin1("ft"); // always ft
factor = 304.8; // 12 * 25.4
if (unit == Unit::Length) { // Length handling ============================
unitString = "ft"; // always ft
factor = 304.8; // 12 * 25.4
}
else if (unit == Unit::Area) {
unitString = QString::fromLatin1("ft^2"); // always sq.ft
unitString = "ft^2"; // always sq.ft
factor = 92903.04;
}
else if (unit == Unit::Volume) {
unitString = QString::fromLatin1("ft^3"); // always cu. ft
unitString = "ft^3"; // always cu. ft
factor = 28316846.592;
}
else if (unit == Unit::Mass) {
unitString = QString::fromLatin1("lb"); // always lbs.
unitString = "lb"; // always lbs.
factor = 0.45359237;
}
else if (unit == Unit::Pressure) {
unitString = QString::fromLatin1("psi");
unitString = "psi";
factor = 6.894744825494;
}
else if (unit == Unit::Stiffness) {
unitString = QString::fromLatin1("lbf/in");
unitString = "lbf/in";
factor = 4.448222 / 0.0254;
}
else if (unit == Unit::Velocity) {
unitString = QString::fromLatin1("mph");
unitString = "mph";
factor = 447.04; // 1mm/sec => mph
}
// this schema expresses angles in degrees + minutes + seconds
else if (unit == Unit::Angle) {
unitString = QString::fromUtf8("deg");
QString degreeString = QString::fromUtf8("\xC2\xB0"); // degree symbol
QString minuteString = QString::fromUtf8("\xE2\x80\xB2"); // prime symbol
QString secondString = QString::fromUtf8("\xE2\x80\xB3"); // double prime symbol
factor = 1.0; // 1deg = 1"\xC2\xB0 "
unitString = "deg";
std::string degreeString = "\xC2\xB0"; // degree symbol
std::string minuteString = "\xE2\x80\xB2"; // prime symbol
std::string secondString = "\xE2\x80\xB3"; // double prime symbol
factor = 1.0; // 1deg = 1"\xC2\xB0 "
double totalDegrees = quant.getValue() / factor;
double wholeDegrees = std::floor(totalDegrees);
@@ -378,12 +373,12 @@ QString UnitsSchemaImperialCivil::schemaTranslate(const Base::Quantity& quant,
int outSec = static_cast<int>(std::round(rawSeconds));
std::stringstream output;
output << outDeg << degreeString.toUtf8().constData();
output << outDeg << degreeString;
if ((outMin > 0) || (outSec > 0)) {
output << outMin << minuteString.toUtf8().constData();
output << outMin << minuteString;
}
if (outSec > 0) {
output << outSec << secondString.toUtf8().constData();
output << outSec << secondString;
}
// uncomment this for decimals on seconds
// if (remainSeconds < (1.0 * pow(10.0,-Base::UnitsApi::getDecimals())) ) {
@@ -392,11 +387,11 @@ QString UnitsSchemaImperialCivil::schemaTranslate(const Base::Quantity& quant,
// output << std::setprecision(Base::UnitsApi::getDecimals()) << std::fixed <<
// rawSeconds << secondString.toStdString();
// }
return QString::fromStdString(output.str());
return output.str();
}
else {
// default action for all cases without special treatment:
unitString = QString::fromStdString(quant.getUnit().getString());
unitString = quant.getUnit().getString();
factor = 1.0;
}

View File

@@ -20,18 +20,14 @@
* *
***************************************************************************/
#ifndef BASE_UNITSSCHEMAIMPERIAL1_H
#define BASE_UNITSSCHEMAIMPERIAL1_H
#include <QString>
#include "UnitsSchema.h"
namespace Base
{
/** The schema class for the imperial unit system
* Here are the definitions for the imperial unit system.
* It also defines how the value/units get printed.
@@ -39,10 +35,8 @@ namespace Base
class UnitsSchemaImperial1: public UnitsSchema
{
public:
// virtual void setSchemaUnits(void);
// virtual void resetSchemaUnits(void);
QString
schemaTranslate(const Base::Quantity& quant, double& factor, QString& unitString) override;
std::string
schemaTranslate(const Base::Quantity& quant, double& factor, std::string& unitString) override;
std::string getBasicLengthUnit() const override
{
return {"in"};
@@ -56,10 +50,8 @@ public:
class UnitsSchemaImperialDecimal: public UnitsSchema
{
public:
// virtual void setSchemaUnits(void);
// virtual void resetSchemaUnits(void);
QString
schemaTranslate(const Base::Quantity& quant, double& factor, QString& unitString) override;
std::string
schemaTranslate(const Base::Quantity& quant, double& factor, std::string& unitString) override;
std::string getBasicLengthUnit() const override
{
return {"in"};
@@ -73,10 +65,8 @@ public:
class UnitsSchemaImperialBuilding: public UnitsSchema
{
public:
// virtual void setSchemaUnits(void);
// virtual void resetSchemaUnits(void);
QString
schemaTranslate(const Base::Quantity& quant, double& factor, QString& unitString) override;
std::string
schemaTranslate(const Base::Quantity& quant, double& factor, std::string& unitString) override;
std::string getBasicLengthUnit() const override
{
return {"ft"};
@@ -96,10 +86,8 @@ public:
class UnitsSchemaImperialCivil: public UnitsSchema
{
public:
// virtual void setSchemaUnits(void);
// virtual void resetSchemaUnits(void);
QString
schemaTranslate(const Base::Quantity& quant, double& factor, QString& unitString) override;
std::string
schemaTranslate(const Base::Quantity& quant, double& factor, std::string& unitString) override;
std::string getBasicLengthUnit() const override
{
return {"ft"};
@@ -112,8 +100,6 @@ public:
}
};
} // namespace Base
#endif // BASE_UNITSSCHEMAIMPERIAL1_H

View File

@@ -26,17 +26,13 @@
#include <unistd.h>
#endif
#include <QString>
#include "UnitsSchemaInternal.h"
#include <cmath>
using namespace Base;
QString
UnitsSchemaInternal::schemaTranslate(const Quantity& quant, double& factor, QString& unitString)
std::string
UnitsSchemaInternal::schemaTranslate(const Quantity& quant, double& factor, std::string& unitString)
{
double UnitValue = std::abs(quant.getValue());
Unit unit = quant.getUnit();
@@ -52,585 +48,585 @@ UnitsSchemaInternal::schemaTranslate(const Quantity& quant, double& factor, QStr
// now do special treatment on all cases seems necessary:
if (unit == Unit::Length) { // Length handling ============================
if (UnitValue < 1e-6) { // smaller than 0.001 nm -> scientific notation
unitString = QString::fromLatin1("mm");
unitString = "mm";
factor = 1.0;
}
else if (UnitValue < 1e-3) {
unitString = QString::fromLatin1("nm");
unitString = "nm";
factor = 1e-6;
}
else if (UnitValue < 0.1) {
unitString = QString::fromUtf8("\xC2\xB5m");
unitString = "\xC2\xB5m";
factor = 1e-3;
}
else if (UnitValue < 1e4) {
unitString = QString::fromLatin1("mm");
unitString = "mm";
factor = 1.0;
}
else if (UnitValue < 1e7) {
unitString = QString::fromLatin1("m");
unitString = "m";
factor = 1e3;
}
else if (UnitValue < 1e10) {
unitString = QString::fromLatin1("km");
unitString = "km";
factor = 1e6;
}
else { // bigger than 1000 km -> scientific notation
unitString = QString::fromLatin1("m");
unitString = "m";
factor = 1e3;
}
}
else if (unit == Unit::Area) {
if (UnitValue < 100) {
unitString = QString::fromLatin1("mm^2");
unitString = "mm^2";
factor = 1.0;
}
else if (UnitValue < 1e6) {
unitString = QString::fromLatin1("cm^2");
unitString = "cm^2";
factor = 100;
}
else if (UnitValue < 1e12) {
unitString = QString::fromLatin1("m^2");
unitString = "m^2";
factor = 1e6;
}
else { // bigger than 1 square kilometer
unitString = QString::fromLatin1("km^2");
unitString = "km^2";
factor = 1e12;
}
}
else if (unit == Unit::Volume) {
if (UnitValue < 1e3) { // smaller than 1 ul
unitString = QString::fromLatin1("mm^3");
unitString = "mm^3";
factor = 1.0;
}
else if (UnitValue < 1e6) {
unitString = QString::fromLatin1("ml");
unitString = "ml";
factor = 1e3;
}
else if (UnitValue < 1e9) {
unitString = QString::fromLatin1("l");
unitString = "l";
factor = 1e6;
}
else { // bigger than 1000 l
unitString = QString::fromLatin1("m^3");
unitString = "m^3";
factor = 1e9;
}
}
else if (unit == Unit::Angle) {
// TODO: Cascade for the Areas
// default action for all cases without special treatment:
unitString = QString::fromUtf8("\xC2\xB0");
unitString = "\xC2\xB0";
factor = 1.0;
}
else if (unit == Unit::Mass) {
if (UnitValue < 1e-6) {
unitString = QString::fromUtf8("\xC2\xB5g");
unitString = "\xC2\xB5g";
factor = 1e-9;
}
else if (UnitValue < 1e-3) {
unitString = QString::fromLatin1("mg");
unitString = "mg";
factor = 1e-6;
}
else if (UnitValue < 1.0) {
unitString = QString::fromLatin1("g");
unitString = "g";
factor = 1e-3;
}
else if (UnitValue < 1e3) {
unitString = QString::fromLatin1("kg");
unitString = "kg";
factor = 1.0;
}
else {
unitString = QString::fromLatin1("t");
unitString = "t";
factor = 1e3;
}
}
else if (unit == Unit::Density) {
if (UnitValue < 0.0001) {
unitString = QString::fromLatin1("kg/m^3");
unitString = "kg/m^3";
factor = 1e-9;
}
else if (UnitValue < 1.0) {
unitString = QString::fromLatin1("kg/cm^3");
unitString = "kg/cm^3";
factor = 0.001;
}
else {
unitString = QString::fromLatin1("kg/mm^3");
unitString = "kg/mm^3";
factor = 1.0;
}
}
else if (unit == Unit::ThermalConductivity) {
if (UnitValue > 1e6) {
unitString = QString::fromLatin1("W/mm/K");
unitString = "W/mm/K";
factor = 1e6;
}
else {
unitString = QString::fromLatin1("W/m/K");
unitString = "W/m/K";
factor = 1000.0;
}
}
else if (unit == Unit::ThermalExpansionCoefficient) {
if (UnitValue < 0.001) {
unitString = QString::fromUtf8("\xC2\xB5m/m/K"); // micro-meter/meter/K
unitString = "\xC2\xB5m/m/K"; // micro-meter/meter/K
factor = 1e-6;
}
else {
unitString = QString::fromLatin1("mm/mm/K");
unitString = "mm/mm/K";
factor = 1.0;
}
}
else if (unit == Unit::VolumetricThermalExpansionCoefficient) {
if (UnitValue < 0.001) {
unitString = QString::fromUtf8("mm^3/m^3/K");
unitString = "mm^3/m^3/K";
factor = 1e-9;
}
else {
unitString = QString::fromLatin1("m^3/m^3/K");
unitString = "m^3/m^3/K";
factor = 1.0;
}
}
else if (unit == Unit::SpecificHeat) {
unitString = QString::fromLatin1("J/kg/K");
unitString = "J/kg/K";
factor = 1e6;
}
else if (unit == Unit::ThermalTransferCoefficient) {
unitString = QString::fromLatin1("W/m^2/K");
unitString = "W/m^2/K";
factor = 1.0;
}
else if ((unit == Unit::Pressure) || (unit == Unit::Stress)) {
if (UnitValue < 10.0) { // Pa is the smallest
unitString = QString::fromLatin1("Pa");
unitString = "Pa";
factor = 0.001;
}
else if (UnitValue < 10000.0) {
unitString = QString::fromLatin1("kPa");
unitString = "kPa";
factor = 1.0;
}
else if (UnitValue < 10000000.0) {
unitString = QString::fromLatin1("MPa");
unitString = "MPa";
factor = 1000.0;
}
else if (UnitValue < 10000000000.0) {
unitString = QString::fromLatin1("GPa");
unitString = "GPa";
factor = 1e6;
}
else { // bigger -> scientific notation
unitString = QString::fromLatin1("Pa");
unitString = "Pa";
factor = 0.001;
}
}
else if ((unit == Unit::Stiffness)) {
if (UnitValue < 1) { // mN/m is the smallest
unitString = QString::fromLatin1("mN/m");
unitString = "mN/m";
factor = 1e-3;
}
else if (UnitValue < 1e3) {
unitString = QString::fromLatin1("N/m");
unitString = "N/m";
factor = 1.0;
}
else if (UnitValue < 1e6) {
unitString = QString::fromLatin1("kN/m");
unitString = "kN/m";
factor = 1e3;
}
else {
unitString = QString::fromLatin1("MN/m");
unitString = "MN/m";
factor = 1e6;
}
}
else if ((unit == Unit::StiffnessDensity)) {
if (UnitValue < 1e-3) {
unitString = QString::fromLatin1("Pa/m");
unitString = "Pa/m";
factor = 1e-6;
}
else if (UnitValue < 1) {
unitString = QString::fromLatin1("kPa/m");
unitString = "kPa/m";
factor = 1e-3;
}
else if (UnitValue < 1e3) {
unitString = QString::fromLatin1("MPa/m");
unitString = "MPa/m";
factor = 1.0;
}
else {
unitString = QString::fromLatin1("GPa/m");
unitString = "GPa/m";
factor = 1e3;
}
}
else if (unit == Unit::Force) {
if (UnitValue < 1e3) {
unitString = QString::fromLatin1("mN");
unitString = "mN";
factor = 1.0;
}
else if (UnitValue < 1e6) {
unitString = QString::fromLatin1("N");
unitString = "N";
factor = 1e3;
}
else if (UnitValue < 1e9) {
unitString = QString::fromLatin1("kN");
unitString = "kN";
factor = 1e6;
}
else {
unitString = QString::fromLatin1("MN");
unitString = "MN";
factor = 1e9;
}
}
// else if (unit == Unit::Moment) {
// if (UnitValue < 1e6) {
// unitString = QString::fromLatin1("mNm");
// unitString = "mNm";
// factor = 1e3;
// }
// else if (UnitValue < 1e9) {
// unitString = QString::fromLatin1("Nm");
// unitString = "Nm";
// factor = 1e6;
// }
// else if (UnitValue < 1e12) {
// unitString = QString::fromLatin1("kNm");
// unitString = "kNm";
// factor = 1e9;
// }
// else {
// unitString = QString::fromLatin1("MNm");
// unitString = "MNm";
// factor = 1e12;
// }
// }
else if (unit == Unit::Power) {
if (UnitValue < 1e6) {
unitString = QString::fromLatin1("mW");
unitString = "mW";
factor = 1e3;
}
else if (UnitValue < 1e9) {
unitString = QString::fromLatin1("W");
unitString = "W";
factor = 1e6;
}
else {
unitString = QString::fromLatin1("kW");
unitString = "kW";
factor = 1e9;
}
}
else if (unit == Unit::ElectricPotential) {
if (UnitValue < 1e6) {
unitString = QString::fromLatin1("mV");
unitString = "mV";
factor = 1e3;
}
else if (UnitValue < 1e9) {
unitString = QString::fromLatin1("V");
unitString = "V";
factor = 1e6;
}
else if (UnitValue < 1e12) {
unitString = QString::fromLatin1("kV");
unitString = "kV";
factor = 1e9;
}
else { // > 1000 kV scientificc notation
unitString = QString::fromLatin1("V");
unitString = "V";
factor = 1e6;
}
}
else if (unit == Unit::Work) {
if (UnitValue < 1.602176634e-10) {
unitString = QString::fromLatin1("eV");
unitString = "eV";
factor = 1.602176634e-13;
}
else if (UnitValue < 1.602176634e-7) {
unitString = QString::fromLatin1("keV");
unitString = "keV";
factor = 1.602176634e-10;
}
else if (UnitValue < 1.602176634e-4) {
unitString = QString::fromLatin1("MeV");
unitString = "MeV";
factor = 1.602176634e-7;
}
else if (UnitValue < 1e6) {
unitString = QString::fromLatin1("mJ");
unitString = "mJ";
factor = 1e3;
}
else if (UnitValue < 1e9) {
unitString = QString::fromLatin1("J");
unitString = "J";
factor = 1e6;
}
else if (UnitValue < 1e12) {
unitString = QString::fromLatin1("kJ");
unitString = "kJ";
factor = 1e9;
}
else if (UnitValue < 3.6e+15) {
unitString = QString::fromLatin1("kWh");
unitString = "kWh";
factor = 3.6e+12;
}
else { // bigger than 1000 kWh -> scientific notation
unitString = QString::fromLatin1("J");
unitString = "J";
factor = 1e6;
}
}
else if (unit == Unit::SpecificEnergy) {
unitString = QString::fromLatin1("m^2/s^2");
unitString = "m^2/s^2";
factor = 1e6;
}
else if (unit == Unit::HeatFlux) {
unitString = QString::fromLatin1("W/m^2");
unitString = "W/m^2";
factor = 1; // unit signature (0,1,-3,0,0) is length independent
}
else if (unit == Unit::ElectricCharge) {
unitString = QString::fromLatin1("C");
unitString = "C";
factor = 1.0;
}
else if (unit == Unit::CurrentDensity) {
if (UnitValue <= 1e3) {
unitString = QString::fromLatin1("A/m^2");
unitString = "A/m^2";
factor = 1e-6;
}
else {
unitString = QString::fromLatin1("A/mm^2");
unitString = "A/mm^2";
factor = 1;
}
}
else if (unit == Unit::MagneticFluxDensity) {
if (UnitValue <= 1e-3) {
unitString = QString::fromLatin1("G");
unitString = "G";
factor = 1e-4;
}
else {
unitString = QString::fromLatin1("T");
unitString = "T";
factor = 1.0;
}
}
else if (unit == Unit::MagneticFieldStrength) {
unitString = QString::fromLatin1("A/m");
unitString = "A/m";
factor = 1e-3;
}
else if (unit == Unit::MagneticFlux) {
unitString = QString::fromLatin1("Wb");
unitString = "Wb";
factor = 1e6;
}
else if (unit == Unit::Magnetization) {
unitString = QString::fromLatin1("A/m");
unitString = "A/m";
factor = 1e-3;
}
else if (unit == Unit::ElectromagneticPotential) {
unitString = QString::fromLatin1("Wb/m");
unitString = "Wb/m";
factor = 1e3;
}
else if (unit == Unit::ElectricalConductance) {
if (UnitValue < 1e-9) {
unitString = QString::fromUtf8("\xC2\xB5S");
unitString = "\xC2\xB5S";
factor = 1e-12;
}
else if (UnitValue < 1e-6) {
unitString = QString::fromLatin1("mS");
unitString = "mS";
factor = 1e-9;
}
else {
unitString = QString::fromLatin1("S");
unitString = "S";
factor = 1e-6;
}
}
else if (unit == Unit::ElectricalResistance) {
if (UnitValue < 1e9) {
unitString = QString::fromLatin1("Ohm");
unitString = "Ohm";
factor = 1e6;
}
else if (UnitValue < 1e12) {
unitString = QString::fromLatin1("kOhm");
unitString = "kOhm";
factor = 1e9;
}
else {
unitString = QString::fromLatin1("MOhm");
unitString = "MOhm";
factor = 1e12;
}
}
else if (unit == Unit::ElectricalConductivity) {
if (UnitValue < 1e-3) {
unitString = QString::fromLatin1("mS/m");
unitString = "mS/m";
factor = 1e-12;
}
else if (UnitValue < 1.0) {
unitString = QString::fromLatin1("S/m");
unitString = "S/m";
factor = 1e-9;
}
else if (UnitValue < 1e3) {
unitString = QString::fromLatin1("kS/m");
unitString = "kS/m";
factor = 1e-6;
}
else {
unitString = QString::fromLatin1("MS/m");
unitString = "MS/m";
factor = 1e-3;
}
}
else if (unit == Unit::ElectricalCapacitance) {
if (UnitValue < 1e-15) {
unitString = QString::fromLatin1("pF");
unitString = "pF";
factor = 1e-18;
}
else if (UnitValue < 1e-12) {
unitString = QString::fromLatin1("nF");
unitString = "nF";
factor = 1e-15;
}
else if (UnitValue < 1e-9) {
// \x reads everything to the end, therefore split
unitString = QString::fromUtf8("\xC2\xB5"
"F");
unitString = "\xC2\xB5"
"F";
factor = 1e-12;
}
else if (UnitValue < 1e-6) {
unitString = QString::fromLatin1("mF");
unitString = "mF";
factor = 1e-9;
}
else {
unitString = QString::fromLatin1("F");
unitString = "F";
factor = 1e-6;
}
}
else if (unit == Unit::ElectricalInductance) {
if (UnitValue < 1.0) {
unitString = QString::fromLatin1("nH");
unitString = "nH";
factor = 1e-3;
}
else if (UnitValue < 1e3) {
unitString = QString::fromUtf8("\xC2\xB5H");
unitString = "\xC2\xB5H";
factor = 1.0;
}
else if (UnitValue < 1e6) {
unitString = QString::fromLatin1("mH");
unitString = "mH";
factor = 1e3;
}
else {
unitString = QString::fromLatin1("H");
unitString = "H";
factor = 1e6;
}
}
else if (unit == Unit::VacuumPermittivity) {
unitString = QString::fromLatin1("F/m");
unitString = "F/m";
factor = 1e-9;
}
else if (unit == Unit::Frequency) {
if (UnitValue < 1e3) {
unitString = QString::fromLatin1("Hz");
unitString = "Hz";
factor = 1.0;
}
else if (UnitValue < 1e6) {
unitString = QString::fromLatin1("kHz");
unitString = "kHz";
factor = 1e3;
}
else if (UnitValue < 1e9) {
unitString = QString::fromLatin1("MHz");
unitString = "MHz";
factor = 1e6;
}
else if (UnitValue < 1e12) {
unitString = QString::fromLatin1("GHz");
unitString = "GHz";
factor = 1e9;
}
else {
unitString = QString::fromLatin1("THz");
unitString = "THz";
factor = 1e12;
}
}
else if (unit == Unit::Velocity) {
unitString = QString::fromLatin1("mm/s");
unitString = "mm/s";
factor = 1.0;
}
else if (unit == Unit::DynamicViscosity) {
unitString = QString::fromLatin1("Pa*s");
unitString = "Pa*s";
factor = 0.001;
}
else if (unit == Unit::KinematicViscosity) {
if (UnitValue < 1e3) {
unitString = QString::fromLatin1("mm^2/s");
unitString = "mm^2/s";
factor = 1.0;
}
else {
unitString = QString::fromLatin1("m^2/s");
unitString = "m^2/s";
factor = 1e6;
}
}
else if (unit == Unit::VolumeFlowRate) {
if (UnitValue < 1e3) {
unitString = QString::fromLatin1("mm^3/s");
unitString = "mm^3/s";
factor = 1.0;
}
else if (UnitValue < 1e6) {
unitString = QString::fromLatin1("ml/s");
unitString = "ml/s";
factor = 1e3;
}
else if (UnitValue < 1e9) {
unitString = QString::fromLatin1("l/s");
unitString = "l/s";
factor = 1e6;
}
else {
unitString = QString::fromLatin1("m^3/s");
unitString = "m^3/s";
factor = 1e9;
}
}
else if (unit == Unit::DissipationRate) {
unitString = QString::fromLatin1("W/kg");
unitString = "W/kg";
factor = 1e6;
}
else if (unit == Unit::InverseLength) {
if (UnitValue < 1e-6) { // smaller than 0.001 1/km -> scientific notation
unitString = QString::fromLatin1("1/m");
unitString = "1/m";
factor = 1e-3;
}
else if (UnitValue < 1e-3) {
unitString = QString::fromLatin1("1/km");
unitString = "1/km";
factor = 1e-6;
}
else if (UnitValue < 1.0) {
unitString = QString::fromLatin1("1/m");
unitString = "1/m";
factor = 1e-3;
}
else if (UnitValue < 1e3) {
unitString = QString::fromLatin1("1/mm");
unitString = "1/mm";
factor = 1.0;
}
else if (UnitValue < 1e6) {
unitString = QString::fromUtf8("1/\xC2\xB5m");
unitString = "1/\xC2\xB5m";
factor = 1e3;
}
else if (UnitValue < 1e9) {
unitString = QString::fromLatin1("1/nm");
unitString = "1/nm";
factor = 1e6;
}
else { // larger -> scientific notation
unitString = QString::fromLatin1("1/m");
unitString = "1/m";
factor = 1e-3;
}
}
else if (unit == Unit::InverseArea) {
if (UnitValue < 1e-12) { // smaller than 0.001 1/km^2 -> scientific notation
unitString = QString::fromLatin1("1/m^2");
unitString = "1/m^2";
factor = 1e-6;
}
else if (UnitValue < 1e-6) {
unitString = QString::fromLatin1("1/km^2");
unitString = "1/km^2";
factor = 1e-12;
}
else if (UnitValue < 1.0) {
unitString = QString::fromLatin1("1/m^2");
unitString = "1/m^2";
factor = 1e-6;
}
else if (UnitValue < 1e2) {
unitString = QString::fromLatin1("1/cm^2");
unitString = "1/cm^2";
factor = 1e-2;
}
else {
unitString = QString::fromLatin1("1/mm^2");
unitString = "1/mm^2";
factor = 1.0;
}
}
else if (unit == Unit::InverseVolume) {
if (UnitValue < 1e-6) {
unitString = QString::fromLatin1("1/m^3");
unitString = "1/m^3";
factor = 1e-9;
}
else if (UnitValue < 1e-3) {
unitString = QString::fromLatin1("1/l");
unitString = "1/l";
factor = 1e-6;
}
else if (UnitValue < 1.0) {
unitString = QString::fromLatin1("1/ml");
unitString = "1/ml";
factor = 1e-3;
}
else {
unitString = QString::fromLatin1("1/mm^3");
unitString = "1/mm^3";
factor = 1.0;
}
}
else {
// default action for all cases without special treatment:
unitString = QString::fromStdString(quant.getUnit().getString());
unitString = quant.getUnit().getString();
factor = 1.0;
}

View File

@@ -20,18 +20,14 @@
* *
***************************************************************************/
#ifndef BASE_UNITSSCHEMAINTERNAL_H
#define BASE_UNITSSCHEMAINTERNAL_H
#include <QString>
#include "UnitsSchema.h"
namespace Base
{
/** The standard units schema
* Here is defined what internal (base) units FreeCAD uses.
* FreeCAD uses a mm/kg/deg scala.
@@ -40,12 +36,10 @@ namespace Base
class UnitsSchemaInternal: public UnitsSchema
{
public:
QString
schemaTranslate(const Base::Quantity& quant, double& factor, QString& unitString) override;
std::string
schemaTranslate(const Base::Quantity& quant, double& factor, std::string& unitString) override;
};
} // namespace Base
#endif // BASE_UNITSSCHEMAINTERNAL_H

View File

@@ -26,16 +26,13 @@
#include <unistd.h>
#endif
#include <QString>
#include "UnitsSchemaMKS.h"
#include <cmath>
using namespace Base;
QString UnitsSchemaMKS::schemaTranslate(const Quantity& quant, double& factor, QString& unitString)
std::string
UnitsSchemaMKS::schemaTranslate(const Quantity& quant, double& factor, std::string& unitString)
{
double UnitValue = std::abs(quant.getValue());
Unit unit = quant.getUnit();
@@ -43,581 +40,581 @@ QString UnitsSchemaMKS::schemaTranslate(const Quantity& quant, double& factor, Q
// now do special treatment on all cases seems necessary:
if (unit == Unit::Length) { // Length handling ============================
if (UnitValue < 1e-6) { // smaller than 0.001 nm -> scientific notation
unitString = QString::fromLatin1("mm");
unitString = "mm";
factor = 1.0;
}
else if (UnitValue < 1e-3) {
unitString = QString::fromLatin1("nm");
unitString = "nm";
factor = 1e-6;
}
else if (UnitValue < 0.1) {
unitString = QString::fromUtf8("\xC2\xB5m");
unitString = "\xC2\xB5m";
factor = 1e-3;
}
else if (UnitValue < 1e4) {
unitString = QString::fromLatin1("mm");
unitString = "mm";
factor = 1.0;
}
else if (UnitValue < 1e7) {
unitString = QString::fromLatin1("m");
unitString = "m";
factor = 1e3;
}
else if (UnitValue < 1e10) {
unitString = QString::fromLatin1("km");
unitString = "km";
factor = 1e6;
}
else { // bigger than 1000 km -> scientific notation
unitString = QString::fromLatin1("m");
unitString = "m";
factor = 1e3;
}
}
else if (unit == Unit::Area) {
if (UnitValue < 100) {
unitString = QString::fromLatin1("mm^2");
unitString = "mm^2";
factor = 1.0;
}
else if (UnitValue < 1e6) {
unitString = QString::fromLatin1("cm^2");
unitString = "cm^2";
factor = 100;
}
else if (UnitValue < 1e12) {
unitString = QString::fromLatin1("m^2");
unitString = "m^2";
factor = 1e6;
}
else { // bigger than 1 square kilometer
unitString = QString::fromLatin1("km^2");
unitString = "km^2";
factor = 1e12;
}
}
else if (unit == Unit::Volume) {
if (UnitValue < 1e3) { // smaller than 1 ul
unitString = QString::fromLatin1("mm^3");
unitString = "mm^3";
factor = 1.0;
}
else if (UnitValue < 1e6) {
unitString = QString::fromLatin1("ml");
unitString = "ml";
factor = 1e3;
}
else if (UnitValue < 1e9) {
unitString = QString::fromLatin1("l");
unitString = "l";
factor = 1e6;
}
else { // bigger than 1000 l
unitString = QString::fromLatin1("m^3");
unitString = "m^3";
factor = 1e9;
}
}
else if (unit == Unit::Mass) {
if (UnitValue < 1e-6) {
unitString = QString::fromUtf8("\xC2\xB5g");
unitString = "\xC2\xB5g";
factor = 1e-9;
}
else if (UnitValue < 1e-3) {
unitString = QString::fromLatin1("mg");
unitString = "mg";
factor = 1e-6;
}
else if (UnitValue < 1.0) {
unitString = QString::fromLatin1("g");
unitString = "g";
factor = 1e-3;
}
else if (UnitValue < 1e3) {
unitString = QString::fromLatin1("kg");
unitString = "kg";
factor = 1.0;
}
else {
unitString = QString::fromLatin1("t");
unitString = "t";
factor = 1e3;
}
}
else if (unit == Unit::Density) {
if (UnitValue < 0.0001) {
unitString = QString::fromLatin1("kg/m^3");
unitString = "kg/m^3";
factor = 0.000000001;
}
else if (UnitValue < 1.0) {
unitString = QString::fromLatin1("kg/cm^3");
unitString = "kg/cm^3";
factor = 0.001;
}
else {
unitString = QString::fromLatin1("kg/mm^3");
unitString = "kg/mm^3";
factor = 1.0;
}
}
else if (unit == Unit::Acceleration) {
unitString = QString::fromLatin1("m/s^2");
unitString = "m/s^2";
factor = 1000.0;
}
else if ((unit == Unit::Pressure) || (unit == Unit::Stress)) {
if (UnitValue < 10.0) { // Pa is the smallest
unitString = QString::fromLatin1("Pa");
unitString = "Pa";
factor = 0.001;
}
else if (UnitValue < 10000.0) {
unitString = QString::fromLatin1("kPa");
unitString = "kPa";
factor = 1.0;
}
else if (UnitValue < 10000000.0) {
unitString = QString::fromLatin1("MPa");
unitString = "MPa";
factor = 1000.0;
}
else if (UnitValue < 10000000000.0) {
unitString = QString::fromLatin1("GPa");
unitString = "GPa";
factor = 1000000.0;
}
else { // bigger then 1000 GPa -> scientific notation
unitString = QString::fromLatin1("Pa");
unitString = "Pa";
factor = 0.001;
}
}
else if ((unit == Unit::Stiffness)) {
if (UnitValue < 1) { // mN/m is the smallest
unitString = QString::fromLatin1("mN/m");
unitString = "mN/m";
factor = 1e-3;
}
else if (UnitValue < 1e3) {
unitString = QString::fromLatin1("N/m");
unitString = "N/m";
factor = 1.0;
}
else if (UnitValue < 1e6) {
unitString = QString::fromLatin1("kN/m");
unitString = "kN/m";
factor = 1e3;
}
else {
unitString = QString::fromLatin1("MN/m");
unitString = "MN/m";
factor = 1e6;
}
}
else if ((unit == Unit::StiffnessDensity)) {
if (UnitValue < 1e-3) {
unitString = QString::fromLatin1("Pa/m");
unitString = "Pa/m";
factor = 1e-6;
}
else if (UnitValue < 1) {
unitString = QString::fromLatin1("kPa/m");
unitString = "kPa/m";
factor = 1e-3;
}
else if (UnitValue < 1e3) {
unitString = QString::fromLatin1("MPa/m");
unitString = "MPa/m";
factor = 1.0;
}
else {
unitString = QString::fromLatin1("GPa/m");
unitString = "GPa/m";
factor = 1e3;
}
}
else if (unit == Unit::ThermalConductivity) {
if (UnitValue > 1000000) {
unitString = QString::fromLatin1("W/mm/K");
unitString = "W/mm/K";
factor = 1000000.0;
}
else {
unitString = QString::fromLatin1("W/m/K");
unitString = "W/m/K";
factor = 1000.0;
}
}
else if (unit == Unit::ThermalExpansionCoefficient) {
if (UnitValue < 0.001) {
unitString = QString::fromUtf8("\xC2\xB5m/m/K");
unitString = "\xC2\xB5m/m/K";
factor = 0.000001;
}
else {
unitString = QString::fromLatin1("m/m/K");
unitString = "m/m/K";
factor = 1.0;
}
}
else if (unit == Unit::VolumetricThermalExpansionCoefficient) {
if (UnitValue < 0.001) {
unitString = QString::fromUtf8("mm^3/m^3/K");
unitString = "mm^3/m^3/K";
factor = 1e-9;
}
else {
unitString = QString::fromLatin1("m^3/m^3/K");
unitString = "m^3/m^3/K";
factor = 1.0;
}
}
else if (unit == Unit::SpecificHeat) {
unitString = QString::fromLatin1("J/kg/K");
unitString = "J/kg/K";
factor = 1000000.0;
}
else if (unit == Unit::ThermalTransferCoefficient) {
unitString = QString::fromLatin1("W/m^2/K");
unitString = "W/m^2/K";
factor = 1.0;
}
else if (unit == Unit::Force) {
if (UnitValue < 1e3) {
unitString = QString::fromLatin1("mN");
unitString = "mN";
factor = 1.0;
}
else if (UnitValue < 1e6) {
unitString = QString::fromLatin1("N");
unitString = "N";
factor = 1e3;
}
else if (UnitValue < 1e9) {
unitString = QString::fromLatin1("kN");
unitString = "kN";
factor = 1e6;
}
else {
unitString = QString::fromLatin1("MN");
unitString = "MN";
factor = 1e9;
}
}
// else if (unit == Unit::Moment) {
// if (UnitValue < 1e6) {
// unitString = QString::fromLatin1("mNm");
// unitString = "mNm";
// factor = 1e3;
// }
// else if (UnitValue < 1e9) {
// unitString = QString::fromLatin1("Nm");
// unitString = "Nm";
// factor = 1e6;
// }
// else if (UnitValue < 1e12) {
// unitString = QString::fromLatin1("kNm");
// unitString = "kNm";
// factor = 1e9;
// }
// else {
// unitString = QString::fromLatin1("MNm");
// unitString = "MNm";
// factor = 1e12;
// }
// }
else if (unit == Unit::Power) {
if (UnitValue < 1e6) {
unitString = QString::fromLatin1("mW");
unitString = "mW";
factor = 1e3;
}
else if (UnitValue < 1e9) {
unitString = QString::fromLatin1("W");
unitString = "W";
factor = 1e6;
}
else {
unitString = QString::fromLatin1("kW");
unitString = "kW";
factor = 1e9;
}
}
else if (unit == Unit::ElectricPotential) {
if (UnitValue < 1e6) {
unitString = QString::fromLatin1("mV");
unitString = "mV";
factor = 1e3;
}
else if (UnitValue < 1e9) {
unitString = QString::fromLatin1("V");
unitString = "V";
factor = 1e6;
}
else if (UnitValue < 1e12) {
unitString = QString::fromLatin1("kV");
unitString = "kV";
factor = 1e9;
}
else { // > 1000 kV scientificc notation
unitString = QString::fromLatin1("V");
unitString = "V";
factor = 1e6;
}
}
else if (unit == Unit::ElectricCharge) {
unitString = QString::fromLatin1("C");
unitString = "C";
factor = 1.0;
}
else if (unit == Unit::CurrentDensity) {
if (UnitValue <= 1e3) {
unitString = QString::fromLatin1("A/m^2");
unitString = "A/m^2";
factor = 1e-6;
}
else {
unitString = QString::fromLatin1("A/mm^2");
unitString = "A/mm^2";
factor = 1;
}
}
else if (unit == Unit::MagneticFluxDensity) {
if (UnitValue <= 1e-3) {
unitString = QString::fromLatin1("G");
unitString = "G";
factor = 1e-4;
}
else {
unitString = QString::fromLatin1("T");
unitString = "T";
factor = 1.0;
}
}
else if (unit == Unit::MagneticFieldStrength) {
unitString = QString::fromLatin1("A/m");
unitString = "A/m";
factor = 1e-3;
}
else if (unit == Unit::MagneticFlux) {
unitString = QString::fromLatin1("Wb");
unitString = "Wb";
factor = 1e6;
}
else if (unit == Unit::Magnetization) {
unitString = QString::fromLatin1("A/m");
unitString = "A/m";
factor = 1e-3;
}
else if (unit == Unit::ElectromagneticPotential) {
unitString = QString::fromLatin1("Wb/m");
unitString = "Wb/m";
factor = 1e3;
}
else if (unit == Unit::ElectricalConductance) {
if (UnitValue < 1e-9) {
unitString = QString::fromUtf8("\xC2\xB5S");
unitString = "\xC2\xB5S";
factor = 1e-12;
}
else if (UnitValue < 1e-6) {
unitString = QString::fromLatin1("mS");
unitString = "mS";
factor = 1e-9;
}
else {
unitString = QString::fromLatin1("S");
unitString = "S";
factor = 1e-6;
}
}
else if (unit == Unit::ElectricalResistance) {
if (UnitValue < 1e9) {
unitString = QString::fromLatin1("Ohm");
unitString = "Ohm";
factor = 1e6;
}
else if (UnitValue < 1e12) {
unitString = QString::fromLatin1("kOhm");
unitString = "kOhm";
factor = 1e9;
}
else {
unitString = QString::fromLatin1("MOhm");
unitString = "MOhm";
factor = 1e12;
}
}
else if (unit == Unit::ElectricalConductivity) {
if (UnitValue < 1e-3) {
unitString = QString::fromLatin1("mS/m");
unitString = "mS/m";
factor = 1e-12;
}
else if (UnitValue < 1.0) {
unitString = QString::fromLatin1("S/m");
unitString = "S/m";
factor = 1e-9;
}
else if (UnitValue < 1e3) {
unitString = QString::fromLatin1("kS/m");
unitString = "kS/m";
factor = 1e-6;
}
else {
unitString = QString::fromLatin1("MS/m");
unitString = "MS/m";
factor = 1e-3;
}
}
else if (unit == Unit::ElectricalCapacitance) {
if (UnitValue < 1e-15) {
unitString = QString::fromLatin1("pF");
unitString = "pF";
factor = 1e-18;
}
else if (UnitValue < 1e-12) {
unitString = QString::fromLatin1("nF");
unitString = "nF";
factor = 1e-15;
}
else if (UnitValue < 1e-9) {
// \x reads everything to the end, therefore split
unitString = QString::fromUtf8("\xC2\xB5"
"F");
unitString = "\xC2\xB5"
"F";
factor = 1e-12;
}
else if (UnitValue < 1e-6) {
unitString = QString::fromLatin1("mF");
unitString = "mF";
factor = 1e-9;
}
else {
unitString = QString::fromLatin1("F");
unitString = "F";
factor = 1e-6;
}
}
else if (unit == Unit::ElectricalInductance) {
if (UnitValue < 1e-6) {
unitString = QString::fromLatin1("nH");
unitString = "nH";
factor = 1e-3;
}
else if (UnitValue < 1e-3) {
unitString = QString::fromUtf8("\xC2\xB5H");
unitString = "\xC2\xB5H";
factor = 1.0;
}
else if (UnitValue < 1.0) {
unitString = QString::fromLatin1("mH");
unitString = "mH";
factor = 1e3;
}
else {
unitString = QString::fromLatin1("H");
unitString = "H";
factor = 1e6;
}
}
else if (unit == Unit::VacuumPermittivity) {
unitString = QString::fromLatin1("F/m");
unitString = "F/m";
factor = 1e-9;
}
else if (unit == Unit::Work) {
if (UnitValue < 1.602176634e-10) {
unitString = QString::fromLatin1("eV");
unitString = "eV";
factor = 1.602176634e-13;
}
else if (UnitValue < 1.602176634e-7) {
unitString = QString::fromLatin1("keV");
unitString = "keV";
factor = 1.602176634e-10;
}
else if (UnitValue < 1.602176634e-4) {
unitString = QString::fromLatin1("MeV");
unitString = "MeV";
factor = 1.602176634e-7;
}
else if (UnitValue < 1e6) {
unitString = QString::fromLatin1("mJ");
unitString = "mJ";
factor = 1e3;
}
else if (UnitValue < 1e9) {
unitString = QString::fromLatin1("J");
unitString = "J";
factor = 1e6;
}
else if (UnitValue < 1e12) {
unitString = QString::fromLatin1("kJ");
unitString = "kJ";
factor = 1e9;
}
else if (UnitValue < 3.6e+15) {
unitString = QString::fromLatin1("kWh");
unitString = "kWh";
factor = 3.6e+12;
}
else { // bigger than 1000 kWh -> scientific notation
unitString = QString::fromLatin1("J");
unitString = "J";
factor = 1e6;
}
}
else if (unit == Unit::SpecificEnergy) {
unitString = QString::fromLatin1("m^2/s^2");
unitString = "m^2/s^2";
factor = 1000000;
}
else if (unit == Unit::HeatFlux) {
unitString = QString::fromLatin1("W/m^2");
unitString = "W/m^2";
factor = 1.0;
}
else if (unit == Unit::Frequency) {
if (UnitValue < 1e3) {
unitString = QString::fromLatin1("Hz");
unitString = "Hz";
factor = 1.0;
}
else if (UnitValue < 1e6) {
unitString = QString::fromLatin1("kHz");
unitString = "kHz";
factor = 1e3;
}
else if (UnitValue < 1e9) {
unitString = QString::fromLatin1("MHz");
unitString = "MHz";
factor = 1e6;
}
else if (UnitValue < 1e12) {
unitString = QString::fromLatin1("GHz");
unitString = "GHz";
factor = 1e9;
}
else {
unitString = QString::fromLatin1("THz");
unitString = "THz";
factor = 1e12;
}
}
else if (unit == Unit::Velocity) {
unitString = QString::fromLatin1("m/s");
unitString = "m/s";
factor = 1000.0;
}
else if (unit == Unit::DynamicViscosity) {
unitString = QString::fromLatin1("Pa*s");
unitString = "Pa*s";
factor = 0.001;
}
else if (unit == Unit::KinematicViscosity) {
unitString = QString::fromLatin1("m^2/s");
unitString = "m^2/s";
factor = 1e6;
}
else if (unit == Unit::VolumeFlowRate) {
if (UnitValue < 1e-3) { // smaller than 0.001 mm^3/s -> scientific notation
unitString = QString::fromLatin1("m^3/s");
unitString = "m^3/s";
factor = 1e9;
}
else if (UnitValue < 1e3) {
unitString = QString::fromLatin1("mm^3/s");
unitString = "mm^3/s";
factor = 1.0;
}
else if (UnitValue < 1e6) {
unitString = QString::fromLatin1("ml/s");
unitString = "ml/s";
factor = 1e3;
}
else if (UnitValue < 1e9) {
unitString = QString::fromLatin1("l/s");
unitString = "l/s";
factor = 1e6;
}
else {
unitString = QString::fromLatin1("m^3/s");
unitString = "m^3/s";
factor = 1e9;
}
}
else if (unit == Unit::DissipationRate) {
unitString = QString::fromLatin1("W/kg");
unitString = "W/kg";
factor = 1e6;
}
else if (unit == Unit::InverseLength) {
if (UnitValue < 1e-6) { // smaller than 0.001 1/km -> scientific notation
unitString = QString::fromLatin1("1/m");
unitString = "1/m";
factor = 1e-3;
}
else if (UnitValue < 1e-3) {
unitString = QString::fromLatin1("1/km");
unitString = "1/km";
factor = 1e-6;
}
else if (UnitValue < 1.0) {
unitString = QString::fromLatin1("1/m");
unitString = "1/m";
factor = 1e-3;
}
else if (UnitValue < 1e3) {
unitString = QString::fromLatin1("1/mm");
unitString = "1/mm";
factor = 1.0;
}
else if (UnitValue < 1e6) {
unitString = QString::fromUtf8("1/\xC2\xB5m");
unitString = "1/\xC2\xB5m";
factor = 1e3;
}
else if (UnitValue < 1e9) {
unitString = QString::fromLatin1("1/nm");
unitString = "1/nm";
factor = 1e6;
}
else { // larger -> scientific notation
unitString = QString::fromLatin1("1/m");
unitString = "1/m";
factor = 1e-3;
}
}
else if (unit == Unit::InverseArea) {
if (UnitValue < 1e-12) { // smaller than 0.001 1/km^2 -> scientific notation
unitString = QString::fromLatin1("1/m^2");
unitString = "1/m^2";
factor = 1e-6;
}
else if (UnitValue < 1e-6) {
unitString = QString::fromLatin1("1/km^2");
unitString = "1/km^2";
factor = 1e-12;
}
else if (UnitValue < 1.0) {
unitString = QString::fromLatin1("1/m^2");
unitString = "1/m^2";
factor = 1e-6;
}
else if (UnitValue < 1e2) {
unitString = QString::fromLatin1("1/cm^2");
unitString = "1/cm^2";
factor = 1e-2;
}
else {
unitString = QString::fromLatin1("1/mm^2");
unitString = "1/mm^2";
factor = 1.0;
}
}
else if (unit == Unit::InverseVolume) {
if (UnitValue < 1e-6) {
unitString = QString::fromLatin1("1/m^3");
unitString = "1/m^3";
factor = 1e-9;
}
else if (UnitValue < 1e-3) {
unitString = QString::fromLatin1("1/l");
unitString = "1/l";
factor = 1e-6;
}
else if (UnitValue < 1.0) {
unitString = QString::fromLatin1("1/ml");
unitString = "1/ml";
factor = 1e-3;
}
else {
unitString = QString::fromLatin1("1/mm^3");
unitString = "1/mm^3";
factor = 1.0;
}
}
else {
// default action for all cases without special treatment:
unitString = QString::fromStdString(quant.getUnit().getString());
unitString = quant.getUnit().getString();
factor = 1.0;
}

View File

@@ -20,30 +20,24 @@
* *
***************************************************************************/
#ifndef BASE_UNITSSCHEMAMKS_H
#define BASE_UNITSSCHEMAMKS_H
#include <QString>
#include "UnitsSchema.h"
namespace Base
{
/**
* The UnitSchema class
*/
class UnitsSchemaMKS: public UnitsSchema
{
public:
QString
schemaTranslate(const Base::Quantity& quant, double& factor, QString& unitString) override;
std::string
schemaTranslate(const Base::Quantity& quant, double& factor, std::string& unitString) override;
};
} // namespace Base
#endif // BASE_UNITSSCHEMAMKS_H

View File

@@ -29,61 +29,41 @@
*/
#include "PreCompiled.h"
#ifdef __GNUC__
#include <unistd.h>
#ifndef _PreComp_
#include <algorithm>
#include <array>
#include <utility>
#endif
#include <QString>
#include "UnitsSchemaMeterDecimal.h"
using namespace Base;
QString UnitsSchemaMeterDecimal::schemaTranslate(const Base::Quantity& quant,
double& factor,
QString& unitString)
std::string UnitsSchemaMeterDecimal::schemaTranslate(const Base::Quantity& quant,
double& factor,
std::string& unitString)
{
Unit unit = quant.getUnit();
if (unit == Unit::Length) {
// all length units in metres
unitString = QString::fromLatin1("m");
factor = 1e3;
}
else if (unit == Unit::Area) {
// all area units in square meters
unitString = QString::fromLatin1("m^2");
factor = 1e6;
}
else if (unit == Unit::Volume) {
// all area units in cubic meters
unitString = QString::fromLatin1("m^3");
factor = 1e9;
}
else if (unit == Unit::Power) {
// watts
unitString = QString::fromLatin1("W");
factor = 1000000;
}
else if (unit == Unit::ElectricPotential) {
// volts
unitString = QString::fromLatin1("V");
factor = 1000000;
}
else if (unit == Unit::HeatFlux) {
// watts per square metre
unitString = QString::fromLatin1("W/m^2");
factor = 1.0;
}
else if (unit == Unit::Velocity) {
// metres per second
unitString = QString::fromLatin1("m/s");
factor = 1e3;
static std::array<std::pair<Unit, std::pair<std::string, double>>, 7> unitSpecs {{
{Unit::Length, {"m", 1e0}},
{Unit::Area, {"m^2", 1e6}},
{Unit::Volume, {"m^3", 1e9}},
{Unit::Power, {"W", 1000000}},
{Unit::ElectricPotential, {"V", 1000000}},
{Unit::HeatFlux, {"W/m^2", 1.0}},
{Unit::Velocity, {"m/s", 1e3}},
}};
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;
}

View File

@@ -29,10 +29,8 @@
#ifndef BASE_UNITSSCHEMAMETERS_H
#define BASE_UNITSSCHEMAMETERS_H
#include <QString>
#include "UnitsSchema.h"
namespace Base
{
@@ -42,8 +40,8 @@ namespace Base
class UnitsSchemaMeterDecimal: public UnitsSchema
{
public:
QString
schemaTranslate(const Base::Quantity& quant, double& factor, QString& unitString) override;
std::string
schemaTranslate(const Base::Quantity& quant, double& factor, std::string& unitString) override;
std::string getBasicLengthUnit() const override
{

View File

@@ -22,37 +22,36 @@
#include "PreCompiled.h"
#ifdef __GNUC__
#include <unistd.h>
#ifndef _PreComp_
#include <algorithm>
#include <array>
#include <utility>
#endif
#include <QString>
#include "UnitsSchemaMmMin.h"
using namespace Base;
QString
UnitsSchemaMmMin::schemaTranslate(const Quantity& quant, double& factor, QString& unitString)
std::string
UnitsSchemaMmMin::schemaTranslate(const Quantity& quant, double& factor, std::string& unitString)
{
Unit unit = quant.getUnit();
if (unit == Unit::Length) {
unitString = QString::fromLatin1("mm");
factor = 1.0;
}
else if (unit == Unit::Angle) {
unitString = QString::fromUtf8("\xC2\xB0");
factor = 1.0;
}
else if (unit == Unit::Velocity) {
unitString = QString::fromLatin1("mm/min");
factor = 1. / 60.;
static std::array<std::pair<Unit, std::pair<std::string, double>>, 3> unitSpecs {{
{Unit::Length, {"mm", 1.0}},
{Unit::Angle, {"\xC2\xB0", 1.0}},
{Unit::Velocity, {"mm/min", 1.0 / 60.0}},
}};
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;
}

View File

@@ -20,18 +20,14 @@
* *
***************************************************************************/
#ifndef BASE_UNITSSCHEMAMMMIN_H
#define BASE_UNITSSCHEMAMMMIN_H
#include <QString>
#include "UnitsSchema.h"
namespace Base
{
/* Metric units schema intended for design of small parts and for CNC
* Lengths are always in mm.
* Angles in degrees (use degree symbol)
@@ -40,12 +36,10 @@ namespace Base
class UnitsSchemaMmMin: public UnitsSchema
{
public:
QString
schemaTranslate(const Base::Quantity& quant, double& factor, QString& unitString) override;
std::string
schemaTranslate(const Base::Quantity& quant, double& factor, std::string& unitString) override;
};
} // namespace Base
#endif // BASE_UNITSSCHEMAMMMIN_H

View File

@@ -120,7 +120,7 @@ public:
result = quantity;
// Now translate the quantity into its string representation using the user-defined unit system
input = Base::UnitsApi::schemaTranslate(result);
input = QString::fromStdString(Base::UnitsApi::schemaTranslate(result));
}
}

View File

@@ -702,7 +702,7 @@ std::array<std::pair<double, std::string>, 3> schemaTranslatePoint(double x, dou
mmz.setValue(fabs(z) > precision ? z : 0.0);
double xfactor, yfactor, zfactor;
QString xunit, yunit, zunit;
std::string xunit, yunit, zunit;
Base::UnitsApi::schemaTranslate(mmx, xfactor, xunit);
Base::UnitsApi::schemaTranslate(mmy, yfactor, yunit);
@@ -712,9 +712,9 @@ std::array<std::pair<double, std::string>, 3> schemaTranslatePoint(double x, dou
double yuser = fabs(y) > precision ? y / yfactor : 0.0;
double zuser = fabs(z) > precision ? z / zfactor : 0.0;
std::array<std::pair<double, std::string>, 3> ret = {std::make_pair(xuser, xunit.toUtf8().constBegin()),
std::make_pair(yuser, yunit.toUtf8().constBegin()),
std::make_pair(zuser, zunit.toUtf8().constBegin())};
std::array<std::pair<double, std::string>, 3> ret = {std::make_pair(xuser, xunit),
std::make_pair(yuser, yunit),
std::make_pair(zuser, zunit)};
return ret;
}

View File

@@ -35,6 +35,8 @@
# include <GL/glu.h>
# endif
# include <fmt/format.h>
# include <Inventor/SbBox.h>
# include <Inventor/SoEventManager.h>
# include <Inventor/SoPickedPoint.h>
@@ -2510,7 +2512,7 @@ void View3DInventorViewer::printDimension() const
float fWidth = -1.0;
getDimensions(fHeight, fWidth);
QString dim;
std::string dim;
if (fWidth >= 0.0 && fHeight >= 0.0) {
// Translate screen units into user's unit schema
@@ -2518,14 +2520,14 @@ void View3DInventorViewer::printDimension() const
Base::Quantity qHeight(Base::Quantity::MilliMetre);
qWidth.setValue(fWidth);
qHeight.setValue(fHeight);
QString wStr = Base::UnitsApi::schemaTranslate(qWidth);
QString hStr = Base::UnitsApi::schemaTranslate(qHeight);
auto wStr = Base::UnitsApi::schemaTranslate(qWidth);
auto hStr = Base::UnitsApi::schemaTranslate(qHeight);
// Create final string and update window
dim = QString::fromLatin1("%1 x %2").arg(wStr, hStr);
dim = fmt::format("{} x {}", wStr, hStr);
}
getMainWindow()->setPaneText(2, dim);
getMainWindow()->setPaneText(2, QString::fromStdString(dim));
}
void View3DInventorViewer::selectAll()

View File

@@ -727,9 +727,9 @@ std::string SketcherGui::lengthToDisplayFormat(double value, int digits)
// find the unit of measure
double factor = 1.0;
QString qUnitString;
QString qtranslate = Base::UnitsApi::schemaTranslate(asQuantity, factor, qUnitString);
QString unitPart = QString::fromUtf8(" ") + qUnitString;
std::string unitString;
std::string translate = Base::UnitsApi::schemaTranslate(asQuantity, factor, unitString);
std::string unitPart = " " + unitString;
// get the numeric part of the user string
QRegularExpression rxNoUnits(
@@ -745,7 +745,7 @@ std::string SketcherGui::lengthToDisplayFormat(double value, int digits)
if (dpPos < 0) {
// no decimal separator (ie an integer), return all the digits
if (!hideUnits()) {
smatched.append(unitPart.toStdString());
smatched.append(unitPart);
}
return smatched;
}
@@ -764,7 +764,7 @@ std::string SketcherGui::lengthToDisplayFormat(double value, int digits)
}
auto numericPart = matched.left(requiredLength).toStdString();
if (!hideUnits()) {
numericPart.append(unitPart.toStdString());
numericPart.append(unitPart);
}
return numericPart;
}

View File

@@ -190,10 +190,10 @@ TEST_F(Quantity, TestSchemeImperialTwo)
Base::Quantity quantity {1.0, Base::Unit::Length};
double factor {};
QString unitString;
std::string unitString;
auto scheme = Base::UnitsApi::createSchema(Base::UnitSystem::ImperialDecimal);
QString result = scheme->schemaTranslate(quantity, factor, unitString);
EXPECT_EQ(result.toStdString(), "0.04 in");
std::string result = scheme->schemaTranslate(quantity, factor, unitString);
EXPECT_EQ(result, "0.04 in");
}
TEST_F(Quantity, TestSchemeImperialOne)
@@ -205,11 +205,11 @@ TEST_F(Quantity, TestSchemeImperialOne)
quantity.setFormat(format);
double factor {};
QString unitString;
std::string unitString;
auto scheme = Base::UnitsApi::createSchema(Base::UnitSystem::ImperialDecimal);
QString result = scheme->schemaTranslate(quantity, factor, unitString);
std::string result = scheme->schemaTranslate(quantity, factor, unitString);
EXPECT_EQ(result.toStdString(), "0.0 in");
EXPECT_EQ(result, "0.0 in");
}
TEST_F(Quantity, TestSafeUserString)