From a91c5bbae728768bb01faa06cc96b817ebeb9a7d Mon Sep 17 00:00:00 2001 From: Itai Nahshon Date: Sat, 1 Jul 2017 11:40:50 +0300 Subject: [PATCH] Add UnitsSchemaMmMin - izes are only in mm, speed in mm/munute. --- src/Base/CMakeLists.txt | 2 ++ src/Base/UnitsApi.cpp | 2 ++ src/Base/UnitsSchema.h | 3 +- src/Base/UnitsSchemaMmMin.cpp | 60 +++++++++++++++++++++++++++++++++++ src/Base/UnitsSchemaMmMin.h | 50 +++++++++++++++++++++++++++++ src/Gui/DlgSettingsUnits.ui | 5 +++ 6 files changed, 121 insertions(+), 1 deletion(-) create mode 100644 src/Base/UnitsSchemaMmMin.cpp create mode 100644 src/Base/UnitsSchemaMmMin.h diff --git a/src/Base/CMakeLists.txt b/src/Base/CMakeLists.txt index 61befd5e6d..d589d4d062 100644 --- a/src/Base/CMakeLists.txt +++ b/src/Base/CMakeLists.txt @@ -185,6 +185,8 @@ SET(FreeCADBase_UNITAPI_SRCS UnitsSchemaImperial1.cpp UnitsSchemaCentimeters.h UnitsSchemaCentimeters.cpp + UnitsSchemaMmMin.h + UnitsSchemaMmMin.cpp Quantity.h Quantity.cpp QuantityPyImp.cpp diff --git a/src/Base/UnitsApi.cpp b/src/Base/UnitsApi.cpp index 3e4cd3f7c9..934c75433d 100644 --- a/src/Base/UnitsApi.cpp +++ b/src/Base/UnitsApi.cpp @@ -33,6 +33,7 @@ #include "UnitsSchemaImperial1.h" #include "UnitsSchemaMKS.h" #include "UnitsSchemaCentimeters.h" +#include "UnitsSchemaMmMin.h" #ifndef M_PI #define M_PI 3.14159265358979323846 @@ -93,6 +94,7 @@ void UnitsApi::setSchema(UnitSystem s) case ImperialDecimal: UserPrefSystem = new UnitsSchemaImperialDecimal(); break; case Centimeters: UserPrefSystem = new UnitsSchemaCentimeters(); break; case ImperialBuilding: UserPrefSystem = new UnitsSchemaImperialBuilding(); break; + case MmMin: UserPrefSystem = new UnitsSchemaMmMin(); break; default : UserPrefSystem = new UnitsSchemaInternal(); s = SI1; break; } diff --git a/src/Base/UnitsSchema.h b/src/Base/UnitsSchema.h index 4ff7286753..1400e1691c 100644 --- a/src/Base/UnitsSchema.h +++ b/src/Base/UnitsSchema.h @@ -39,7 +39,8 @@ enum UnitSystem { Imperial1 = 2, /** the Imperial system (http://en.wikipedia.org/wiki/Imperial_units) */ ImperialDecimal = 3, /** Imperial with length in inch only */ Centimeters = 4, /** All lengths in centimeters, areas and volumes in square/cubic meters */ - ImperialBuilding = 5 /** All lengths in feet + inches + fractions */ + ImperialBuilding = 5, /** All lengths in feet + inches + fractions */ + MmMin = 6, /** All lengths in mm, Speed in mm/min. Usefull for small parts & CNN */ } ; diff --git a/src/Base/UnitsSchemaMmMin.cpp b/src/Base/UnitsSchemaMmMin.cpp new file mode 100644 index 0000000000..b2fb501da4 --- /dev/null +++ b/src/Base/UnitsSchemaMmMin.cpp @@ -0,0 +1,60 @@ +/*************************************************************************** + * Copyright (c) 2009 Juergen Riegel (FreeCAD@juergen-riegel.net) * + * * + * 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 +#include "Exception.h" +#include "UnitsApi.h" +#include "UnitsSchemaMmMin.h" +#include + + +using namespace Base; + + +QString UnitsSchemaMmMin::schemaTranslate(const Quantity &quant, double &factor, QString &unitString) +{ + Unit unit = quant.getUnit(); + if (unit == Unit::Angle) { + // TODO Cascade for the Areas + // default action for all cases without special treatment: + unitString = QString::fromUtf8("\xC2\xB0"); + factor = 1.0; + } + else if (unit == Unit::Velocity) { + unitString = QString::fromLatin1("mm/min"); + factor = 1./60.; + } + 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/UnitsSchemaMmMin.h b/src/Base/UnitsSchemaMmMin.h new file mode 100644 index 0000000000..2113abb5f9 --- /dev/null +++ b/src/Base/UnitsSchemaMmMin.h @@ -0,0 +1,50 @@ +/*************************************************************************** + * Copyright (c) 2009 Juergen Riegel (FreeCAD@juergen-riegel.net> * + * * + * 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_UNITSSCHEMAMMMIN_H +#define BASE_UNITSSCHEMAMMMIN_H + + +#include +#include +#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. + * Also it defines how the units get presented. + */ +class UnitsSchemaMmMin: public UnitsSchema +{ +public: + virtual QString schemaTranslate(const Base::Quantity& quant, double &factor, QString &unitString); +}; + + +} // namespace Base + + +#endif // BASE_UNITSSCHEMAMMMIN_H diff --git a/src/Gui/DlgSettingsUnits.ui b/src/Gui/DlgSettingsUnits.ui index b587d685eb..4d74ec8bf2 100644 --- a/src/Gui/DlgSettingsUnits.ui +++ b/src/Gui/DlgSettingsUnits.ui @@ -61,6 +61,11 @@ Building US (ft-in/sqft/cuft) + + + Metric small parts & CNC(mm, mm/min) + +