Base: add new unit schema for mm and N for use in FEM

This commit is contained in:
Bernd Hahnebach
2020-07-15 07:55:30 +02:00
committed by wwmayer
parent 15d04447d5
commit 0c9e6c6158
6 changed files with 120 additions and 0 deletions

View File

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

View File

@@ -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<UnitsSchemaMmMin>();
case UnitSystem::ImperialCivil:
return std::make_unique<UnitsSchemaImperialCivil>();
case UnitSystem::FemMilliMeterNewton:
return std::make_unique<UnitsSchemaFemMilliMeterNewton>();
default:
break;
}

View File

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

View File

@@ -0,0 +1,59 @@
/***************************************************************************
* Copyright (c) 2009 Jürgen Riegel <FreeCAD@juergen-riegel.net> *
* Copyright (c) 2020 Bernd Hahnebach <bernd@bimstatik.org> *
* *
* 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 <unistd.h>
#endif
#include <QString>
#include "Exception.h"
#include "UnitsApi.h"
#include "UnitsSchemaFemMilliMeterNewton.h"
#include <cmath>
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);
}

View File

@@ -0,0 +1,52 @@
/***************************************************************************
* Copyright (c) 2009 Jürgen Riegel <FreeCAD@juergen-riegel.net> *
* Copyright (c) 2020 Bernd Hahnebach <bernd@bimstatik.org> *
* *
* 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 <string>
#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.
* 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

View File

@@ -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
/**