diff --git a/src/Base/CMakeLists.txt b/src/Base/CMakeLists.txt index 60e632d752..286d7fa336 100644 --- a/src/Base/CMakeLists.txt +++ b/src/Base/CMakeLists.txt @@ -201,6 +201,8 @@ SET(FreeCADBase_UNITAPI_SRCS UnitsSchemaCentimeters.cpp UnitsSchemaMmMin.h UnitsSchemaMmMin.cpp + UnitsSchemaFemMilliMeterNewton.h + UnitsSchemaFemMilliMeterNewton.cpp Quantity.h Quantity.cpp QuantityPyImp.cpp diff --git a/src/Base/UnitsApi.cpp b/src/Base/UnitsApi.cpp index 933d19bf32..fa573b006b 100644 --- a/src/Base/UnitsApi.cpp +++ b/src/Base/UnitsApi.cpp @@ -34,6 +34,7 @@ #include "UnitsSchemaMKS.h" #include "UnitsSchemaCentimeters.h" #include "UnitsSchemaMmMin.h" +#include "UnitsSchemaFemMilliMeterNewton.h" #include "StdStlTools.h" #ifndef M_PI @@ -100,6 +101,8 @@ const char* UnitsApi::getDescription(UnitSystem system) return "Metric small parts & CNC(mm, mm/min)"; case UnitSystem::ImperialCivil: return "Imperial for Civil Eng (ft, ft/sec)"; + case UnitSystem::FemMilliMeterNewton: + return "FEM (mm, N, s)"; default: return "Unknown schema"; } @@ -124,6 +127,8 @@ UnitsSchemaPtr UnitsApi::createSchema(UnitSystem s) return std::make_unique(); case UnitSystem::ImperialCivil: return std::make_unique(); + case UnitSystem::FemMilliMeterNewton: + return std::make_unique(); default: break; } diff --git a/src/Base/UnitsSchema.h b/src/Base/UnitsSchema.h index 4174e496e1..61477b699d 100644 --- a/src/Base/UnitsSchema.h +++ b/src/Base/UnitsSchema.h @@ -42,6 +42,7 @@ enum class UnitSystem { ImperialBuilding = 5, /** All lengths in feet + inches + fractions */ 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! }; diff --git a/src/Base/UnitsSchemaFemMilliMeterNewton.cpp b/src/Base/UnitsSchemaFemMilliMeterNewton.cpp new file mode 100644 index 0000000000..4371e99b85 --- /dev/null +++ b/src/Base/UnitsSchemaFemMilliMeterNewton.cpp @@ -0,0 +1,59 @@ +/*************************************************************************** + * Copyright (c) 2009 Jürgen Riegel * + * Copyright (c) 2020 Bernd Hahnebach * + * * + * 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 * + * * + ***************************************************************************/ + + +#include "PreCompiled.h" +#ifdef __GNUC__ +# include +#endif + +#include +#include "Exception.h" +#include "UnitsApi.h" +#include "UnitsSchemaFemMilliMeterNewton.h" +#include + + +using namespace Base; + + +QString UnitsSchemaFemMilliMeterNewton::schemaTranslate(const Quantity &quant, double &factor, QString &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; + } + 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/UnitsSchemaFemMilliMeterNewton.h b/src/Base/UnitsSchemaFemMilliMeterNewton.h new file mode 100644 index 0000000000..47fc842ee9 --- /dev/null +++ b/src/Base/UnitsSchemaFemMilliMeterNewton.h @@ -0,0 +1,52 @@ +/*************************************************************************** + * Copyright (c) 2009 Jürgen Riegel * + * Copyright (c) 2020 Bernd Hahnebach * + * * + * 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 * + * * + ***************************************************************************/ + + +#ifndef BASE_UNITSSCHEMAFEMMLLIMETERNEWTON_H +#define BASE_UNITSSCHEMAFEMMLLIMETERNEWTON_H + + +#include +#include +#include "UnitsSchema.h" + +namespace Base { + + +/* Milli metric / Newton / Seconds unit schema for use in FEM. + * Lengths are always in mm. + * Mass is in t. + * TimeSpann in S. + * Thus the Force is in Newton + */ +class UnitsSchemaFemMilliMeterNewton: public UnitsSchema +{ +public: + virtual QString schemaTranslate(const Base::Quantity& quant, double &factor, QString &unitString); +}; + + +} // namespace Base + + +#endif // BASE_UNITSSCHEMAFEMMLLIMETERNEWTON_H diff --git a/src/Gui/DlgSettingsUnitsImp.cpp b/src/Gui/DlgSettingsUnitsImp.cpp index 0873b3d46f..51a14120b4 100644 --- a/src/Gui/DlgSettingsUnitsImp.cpp +++ b/src/Gui/DlgSettingsUnitsImp.cpp @@ -53,6 +53,7 @@ using namespace Base; qApp->translate("Gui::Dialog::DlgSettingsUnits", "Building US (ft-in/sqft/cft)"); qApp->translate("Gui::Dialog::DlgSettingsUnits", "Metric small parts & CNC(mm, mm/min)"); qApp->translate("Gui::Dialog::DlgSettingsUnits", "Imperial for Civil Eng (ft, ft/sec)"); + qApp->translate("Gui::Dialog::DlgSettingsUnits", "FEM (mm, N, sec)"); #endif /**