[Units]Add Meters-only schema (#7395)

- use correct unit for velocity

- typo in include guard
This commit is contained in:
wandererfan
2023-11-12 07:41:17 -05:00
committed by wwmayer
parent ca80f8eee2
commit a2e26f5002
5 changed files with 195 additions and 43 deletions

View File

@@ -198,6 +198,8 @@ SET(FreeCADBase_UNITAPI_SRCS
UnitsSchemaMmMin.cpp
UnitsSchemaFemMilliMeterNewton.h
UnitsSchemaFemMilliMeterNewton.cpp
UnitsSchemaMeterDecimal.h
UnitsSchemaMeterDecimal.cpp
Quantity.h
Quantity.cpp
QuantityPyImp.cpp

View File

@@ -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<UnitsSchemaInternal>();
case UnitSystem::SI2:
return std::make_unique<UnitsSchemaMKS>();
case UnitSystem::Imperial1:
return std::make_unique<UnitsSchemaImperial1>();
case UnitSystem::ImperialDecimal:
return std::make_unique<UnitsSchemaImperialDecimal>();
case UnitSystem::Centimeters:
return std::make_unique<UnitsSchemaCentimeters>();
case UnitSystem::ImperialBuilding:
return std::make_unique<UnitsSchemaImperialBuilding>();
case UnitSystem::MmMin:
return std::make_unique<UnitsSchemaMmMin>();
case UnitSystem::ImperialCivil:
return std::make_unique<UnitsSchemaImperialCivil>();
case UnitSystem::FemMilliMeterNewton:
return std::make_unique<UnitsSchemaFemMilliMeterNewton>();
default:
break;
case UnitSystem::SI1:
return std::make_unique<UnitsSchemaInternal>();
case UnitSystem::SI2:
return std::make_unique<UnitsSchemaMKS>();
case UnitSystem::Imperial1:
return std::make_unique<UnitsSchemaImperial1>();
case UnitSystem::ImperialDecimal:
return std::make_unique<UnitsSchemaImperialDecimal>();
case UnitSystem::Centimeters:
return std::make_unique<UnitsSchemaCentimeters>();
case UnitSystem::ImperialBuilding:
return std::make_unique<UnitsSchemaImperialBuilding>();
case UnitSystem::MmMin:
return std::make_unique<UnitsSchemaMmMin>();
case UnitSystem::ImperialCivil:
return std::make_unique<UnitsSchemaImperialCivil>();
case UnitSystem::FemMilliMeterNewton:
return std::make_unique<UnitsSchemaFemMilliMeterNewton>();
case UnitSystem::MeterDecimal:
return std::make_unique<UnitsSchemaMeterDecimal>();
default:
break;
}
return nullptr;

View File

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

View File

@@ -0,0 +1,89 @@
/***************************************************************************
* Copyright (c) WandererFan <wandererfan@gmail.com> *
* *
* 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 <unistd.h>
#endif
#include <QString>
#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);
}

View File

@@ -0,0 +1,56 @@
/***************************************************************************
* Copyright (c) 2023 WandererFan <wandererfan@gmail.com> *
* *
* 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 <QString>
#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