Base: [skip ci] make UnitSystem an enum class
This commit is contained in:
@@ -62,7 +62,7 @@ using namespace Base;
|
||||
double UnitsApi::defaultFactor = 1.0;
|
||||
|
||||
UnitsSchema *UnitsApi::UserPrefSystem = new UnitsSchemaInternal();
|
||||
UnitSystem UnitsApi::actSystem = SI1;
|
||||
UnitSystem UnitsApi::actSystem = UnitSystem::SI1;
|
||||
|
||||
//double UnitsApi::UserPrefFactor [50];
|
||||
//QString UnitsApi::UserPrefUnit [50];
|
||||
@@ -83,21 +83,21 @@ UnitsApi::~UnitsApi()
|
||||
const char* UnitsApi::getDescription(UnitSystem system)
|
||||
{
|
||||
switch (system) {
|
||||
case SI1:
|
||||
case UnitSystem::SI1:
|
||||
return "Standard (mm/kg/s/degree)";
|
||||
case SI2:
|
||||
case UnitSystem::SI2:
|
||||
return "MKS (m/kg/s/degree)";
|
||||
case Imperial1:
|
||||
case UnitSystem::Imperial1:
|
||||
return "US customary (in/lb)";
|
||||
case ImperialDecimal:
|
||||
case UnitSystem::ImperialDecimal:
|
||||
return "Imperial decimal (in/lb)";
|
||||
case Centimeters:
|
||||
case UnitSystem::Centimeters:
|
||||
return "Building Euro (cm/m²/m³)";
|
||||
case ImperialBuilding:
|
||||
case UnitSystem::ImperialBuilding:
|
||||
return "Building US (ft-in/sqft/cuft)";
|
||||
case MmMin:
|
||||
case UnitSystem::MmMin:
|
||||
return "Metric small parts & CNC(mm, mm/min)";
|
||||
case ImperialCivil:
|
||||
case UnitSystem::ImperialCivil:
|
||||
return "Imperial for Civil Eng (ft, ft/sec)";
|
||||
default:
|
||||
return "Unknown schema";
|
||||
@@ -107,21 +107,21 @@ const char* UnitsApi::getDescription(UnitSystem system)
|
||||
UnitsSchema* UnitsApi::createSchema(UnitSystem s)
|
||||
{
|
||||
switch (s) {
|
||||
case SI1:
|
||||
case UnitSystem::SI1:
|
||||
return new UnitsSchemaInternal();
|
||||
case SI2:
|
||||
case UnitSystem::SI2:
|
||||
return new UnitsSchemaMKS();
|
||||
case Imperial1:
|
||||
case UnitSystem::Imperial1:
|
||||
return new UnitsSchemaImperial1();
|
||||
case ImperialDecimal:
|
||||
case UnitSystem::ImperialDecimal:
|
||||
return new UnitsSchemaImperialDecimal();
|
||||
case Centimeters:
|
||||
case UnitSystem::Centimeters:
|
||||
return new UnitsSchemaCentimeters();
|
||||
case ImperialBuilding:
|
||||
case UnitSystem::ImperialBuilding:
|
||||
return new UnitsSchemaImperialBuilding();
|
||||
case MmMin:
|
||||
case UnitSystem::MmMin:
|
||||
return new UnitsSchemaMmMin();
|
||||
case ImperialCivil:
|
||||
case UnitSystem::ImperialCivil:
|
||||
return new UnitsSchemaImperialCivil();
|
||||
default:
|
||||
break;
|
||||
@@ -144,7 +144,7 @@ void UnitsApi::setSchema(UnitSystem s)
|
||||
// for wrong value fall back to standard schema
|
||||
if (!UserPrefSystem) {
|
||||
UserPrefSystem = new UnitsSchemaInternal();
|
||||
actSystem = SI1;
|
||||
actSystem = UnitSystem::SI1;
|
||||
}
|
||||
|
||||
UserPrefSystem->setSchemaUnits(); // if necessary a unit schema can change the constants in Quantity (e.g. mi=1.8km rather then 1.6km).
|
||||
|
||||
@@ -169,7 +169,7 @@ PyObject* UnitsApi::sParseQuantity(PyObject * /*self*/, PyObject *args)
|
||||
PyObject* UnitsApi::sListSchemas(PyObject * /*self*/, PyObject *args)
|
||||
{
|
||||
if (PyArg_ParseTuple(args, "")) {
|
||||
int num = NumUnitSystemTypes;
|
||||
int num = static_cast<int>(UnitSystem::NumUnitSystemTypes);
|
||||
Py::Tuple tuple(num);
|
||||
for (int i=0; i<num; i++) {
|
||||
tuple.setItem(i, Py::String(UnitsApi::getDescription(static_cast<UnitSystem>(i))));
|
||||
@@ -181,7 +181,7 @@ PyObject* UnitsApi::sListSchemas(PyObject * /*self*/, PyObject *args)
|
||||
PyErr_Clear();
|
||||
int index;
|
||||
if (PyArg_ParseTuple(args, "i", &index)) {
|
||||
int num = NumUnitSystemTypes;
|
||||
int num = static_cast<int>(UnitSystem::NumUnitSystemTypes);
|
||||
if (index < 0 || index >= num) {
|
||||
PyErr_SetString(PyExc_ValueError, "invalid schema value");
|
||||
return 0;
|
||||
@@ -207,7 +207,7 @@ PyObject* UnitsApi::sSetSchema(PyObject * /*self*/, PyObject *args)
|
||||
PyErr_Clear();
|
||||
int index;
|
||||
if (PyArg_ParseTuple(args, "i", &index)) {
|
||||
int num = NumUnitSystemTypes;
|
||||
int num = static_cast<int>(UnitSystem::NumUnitSystemTypes);
|
||||
if (index < 0 || index >= num) {
|
||||
PyErr_SetString(PyExc_ValueError, "invalid schema value");
|
||||
return 0;
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
namespace Base {
|
||||
|
||||
/** Units systems */
|
||||
enum UnitSystem {
|
||||
enum class UnitSystem {
|
||||
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) */
|
||||
|
||||
@@ -57,7 +57,7 @@ DlgSettingsUnitsImp::DlgSettingsUnitsImp(QWidget* parent)
|
||||
ui->tableWidget->setVisible(false);
|
||||
//
|
||||
// Enable/disable the fractional inch option depending on system
|
||||
if( UnitsApi::getSchema() == ImperialBuilding )
|
||||
if( UnitsApi::getSchema() == UnitSystem::ImperialBuilding )
|
||||
{
|
||||
ui->comboBox_FracInch->setEnabled(true);
|
||||
}
|
||||
@@ -82,7 +82,7 @@ void DlgSettingsUnitsImp::on_comboBox_ViewSystem_currentIndexChanged(int index)
|
||||
return; // happens when clearing the combo box in retranslateUi()
|
||||
|
||||
// Enable/disable the fractional inch option depending on system
|
||||
if( (UnitSystem)index == ImperialBuilding )
|
||||
if( (UnitSystem)index == UnitSystem::ImperialBuilding )
|
||||
{
|
||||
ui->comboBox_FracInch->setEnabled(true);
|
||||
}
|
||||
|
||||
@@ -2894,20 +2894,20 @@ QString ViewProviderSketch::getPresentationString(const Constraint *constraint)
|
||||
// If this is a supported unit system then define what the base unit is.
|
||||
switch (unitSys)
|
||||
{
|
||||
case Base::SI1:
|
||||
case Base::MmMin:
|
||||
case Base::UnitSystem::SI1:
|
||||
case Base::UnitSystem::MmMin:
|
||||
baseUnitStr = QString::fromLatin1("mm");
|
||||
break;
|
||||
|
||||
case Base::SI2:
|
||||
case Base::UnitSystem::SI2:
|
||||
baseUnitStr = QString::fromLatin1("m");
|
||||
break;
|
||||
|
||||
case Base::ImperialDecimal:
|
||||
case Base::UnitSystem::ImperialDecimal:
|
||||
baseUnitStr = QString::fromLatin1("in");
|
||||
break;
|
||||
|
||||
case Base::Centimeters:
|
||||
case Base::UnitSystem::Centimeters:
|
||||
baseUnitStr = QString::fromLatin1("cm");
|
||||
break;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user