diff --git a/src/Base/CMakeLists.txt b/src/Base/CMakeLists.txt index 4e70b6229d..478bb59a8b 100644 --- a/src/Base/CMakeLists.txt +++ b/src/Base/CMakeLists.txt @@ -198,6 +198,8 @@ SET(FreeCADBase_UNITAPI_SRCS UnitsSchemaMmMin.cpp UnitsSchemaFemMilliMeterNewton.h UnitsSchemaFemMilliMeterNewton.cpp + UnitsSchemaMeterDecimal.h + UnitsSchemaMeterDecimal.cpp Quantity.h Quantity.cpp QuantityPyImp.cpp diff --git a/src/Base/UnitsApi.cpp b/src/Base/UnitsApi.cpp index 8f03ba28cd..2716d60cbf 100644 --- a/src/Base/UnitsApi.cpp +++ b/src/Base/UnitsApi.cpp @@ -38,6 +38,7 @@ #include "UnitsSchemaMKS.h" #include "UnitsSchemaMmMin.h" #include "UnitsSchemaFemMilliMeterNewton.h" +#include "UnitsSchemaMeterDecimal.h" #ifndef M_PI #define M_PI 3.14159265358979323846 @@ -64,52 +65,56 @@ int UnitsApi::UserPrefDecimals = 2; QString UnitsApi::getDescription(UnitSystem system) { switch (system) { - case UnitSystem::SI1: - return tr("Standard (mm, kg, s, degree)"); - case UnitSystem::SI2: - return tr("MKS (m, kg, s, degree)"); - case UnitSystem::Imperial1: - return tr("US customary (in, lb)"); - case UnitSystem::ImperialDecimal: - return tr("Imperial decimal (in, lb)"); - case UnitSystem::Centimeters: - return tr("Building Euro (cm, m², m³)"); - case UnitSystem::ImperialBuilding: - return tr("Building US (ft-in, sqft, cft)"); - case UnitSystem::MmMin: - return tr("Metric small parts & CNC(mm, mm/min)"); - case UnitSystem::ImperialCivil: - return tr("Imperial for Civil Eng (ft, ft/sec)"); - case UnitSystem::FemMilliMeterNewton: - return tr("FEM (mm, N, s)"); - default: - return tr("Unknown schema"); + case UnitSystem::SI1: + return tr("Standard (mm, kg, s, degree)"); + case UnitSystem::SI2: + return tr("MKS (m, kg, s, degree)"); + case UnitSystem::Imperial1: + return tr("US customary (in, lb)"); + case UnitSystem::ImperialDecimal: + return tr("Imperial decimal (in, lb)"); + case UnitSystem::Centimeters: + return tr("Building Euro (cm, m², m³)"); + case UnitSystem::ImperialBuilding: + return tr("Building US (ft-in, sqft, cft)"); + case UnitSystem::MmMin: + return tr("Metric small parts & CNC(mm, mm/min)"); + case UnitSystem::ImperialCivil: + return tr("Imperial for Civil Eng (ft, ft/sec)"); + case UnitSystem::FemMilliMeterNewton: + return tr("FEM (mm, N, s)"); + case UnitSystem::MeterDecimal: + return tr("Meter decimal (m, m², m³)"); + default: + return tr("Unknown schema"); } } UnitsSchemaPtr UnitsApi::createSchema(UnitSystem system) { switch (system) { - case UnitSystem::SI1: - return std::make_unique(); - case UnitSystem::SI2: - return std::make_unique(); - case UnitSystem::Imperial1: - return std::make_unique(); - case UnitSystem::ImperialDecimal: - return std::make_unique(); - case UnitSystem::Centimeters: - return std::make_unique(); - case UnitSystem::ImperialBuilding: - return std::make_unique(); - case UnitSystem::MmMin: - return std::make_unique(); - case UnitSystem::ImperialCivil: - return std::make_unique(); - case UnitSystem::FemMilliMeterNewton: - return std::make_unique(); - default: - break; + case UnitSystem::SI1: + return std::make_unique(); + case UnitSystem::SI2: + return std::make_unique(); + case UnitSystem::Imperial1: + return std::make_unique(); + case UnitSystem::ImperialDecimal: + return std::make_unique(); + case UnitSystem::Centimeters: + return std::make_unique(); + case UnitSystem::ImperialBuilding: + return std::make_unique(); + case UnitSystem::MmMin: + return std::make_unique(); + case UnitSystem::ImperialCivil: + return std::make_unique(); + case UnitSystem::FemMilliMeterNewton: + return std::make_unique(); + case UnitSystem::MeterDecimal: + return std::make_unique(); + default: + break; } return nullptr; diff --git a/src/Base/UnitsSchema.h b/src/Base/UnitsSchema.h index a2f56b9a30..e6e6c11f30 100644 --- a/src/Base/UnitsSchema.h +++ b/src/Base/UnitsSchema.h @@ -34,8 +34,7 @@ namespace Base /** Units systems */ enum class UnitSystem { - SI1 = 0, /** internal (mm,kg,s) SI system - (http://en.wikipedia.org/wiki/International_System_of_Units) */ + SI1 = 0, /** internal (mm,kg,s) SI system (http://en.wikipedia.org/wiki/International_System_of_Units) */ 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 */ @@ -44,7 +43,8 @@ enum class UnitSystem MmMin = 6, /** Lengths in mm, Speed in mm/min. Angle in degrees. Useful for small parts & CNC */ ImperialCivil = 7, /** Lengths in ft, Speed in ft/sec. Used in Civil Eng in North America */ FemMilliMeterNewton = 8, /** Lengths in mm, Mass in t, TimeSpan in s, thus force is in N */ - NumUnitSystemTypes // must be the last item! + MeterDecimal = 9, /** Lengths in metres always */ + NumUnitSystemTypes // must be the last item! }; diff --git a/src/Base/UnitsSchemaMeterDecimal.cpp b/src/Base/UnitsSchemaMeterDecimal.cpp new file mode 100644 index 0000000000..f9d2c2898b --- /dev/null +++ b/src/Base/UnitsSchemaMeterDecimal.cpp @@ -0,0 +1,89 @@ +/*************************************************************************** + * Copyright (c) WandererFan * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +/* Metric units schema intended for design of large objects + * Lengths are always in metres. + * Areas are always in square metres + * Volumes are always in cubic metres + * Angles in decimal degrees (use degree symbol) + * Velocities in m/sec + */ + +#include "PreCompiled.h" +#ifdef __GNUC__ +# include +#endif + +#include + +#include "UnitsSchemaMeterDecimal.h" + + +using namespace Base; + + +QString UnitsSchemaMeterDecimal::schemaTranslate(const Base::Quantity& quant, double &factor, QString &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; + } + else { + // default action for all cases without special treatment: + unitString = quant.getUnit().getString(); + factor = 1.0; + } + + return toLocale(quant, factor, unitString); +} diff --git a/src/Base/UnitsSchemaMeterDecimal.h b/src/Base/UnitsSchemaMeterDecimal.h new file mode 100644 index 0000000000..b7d7d0ee23 --- /dev/null +++ b/src/Base/UnitsSchemaMeterDecimal.h @@ -0,0 +1,56 @@ +/*************************************************************************** + * Copyright (c) 2023 WandererFan * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +/* Metric units schema intended for design of large objects + * Lengths are always in metres. + * Angles in degrees (use degree symbol) + * Velocities in m/sec + */ + +#ifndef BASE_UNITSSCHEMAMETERS_H +#define BASE_UNITSSCHEMAMETERS_H + +#include +#include "UnitsSchema.h" + + +namespace Base +{ + +/** + * The UnitSchema class + */ +class UnitsSchemaMeterDecimal: public UnitsSchema +{ +public: + QString + schemaTranslate(const Base::Quantity& quant, double& factor, QString& unitString) override; + + std::string getBasicLengthUnit() const override + { + return {"m"}; + } +}; + +} // namespace Base + +#endif // BASE_UNITSSCHEMAMETRES_H