| 1 |
// SPDX-License-Identifier: LGPL-2.1-or-later |
| 2 |
|
| 3 |
/*************************************************************************** |
| 4 |
* Copyright (c) 2009 Jürgen Riegel <[email protected]> * |
| 5 |
* * |
| 6 |
* This file is part of the FreeCAD CAx development system. * |
| 7 |
* * |
| 8 |
* This library is free software; you can redistribute it and/or * |
| 9 |
* modify it under the terms of the GNU Library General Public * |
| 10 |
* License as published by the Free Software Foundation; either * |
| 11 |
* version 2 of the License, or (at your option) any later version. * |
| 12 |
* * |
| 13 |
* This library is distributed in the hope that it will be useful, * |
| 14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 16 |
* GNU Library General Public License for more details. * |
| 17 |
* * |
| 18 |
* You should have received a copy of the GNU Library General Public * |
| 19 |
* License along with this library; see the file COPYING.LIB. If not, * |
| 20 |
* write to the Free Software Foundation, Inc., 59 Temple Place, * |
| 21 |
* Suite 330, Boston, MA 02111-1307, USA * |
| 22 |
* * |
| 23 |
***************************************************************************/ |
| 24 |
|
| 25 |
#ifndef BASE_UNITSAPI_H |
| 26 |
#define BASE_UNITSAPI_H |
| 27 |
|
| 28 |
#include "UnitsSchema.h" |
| 29 |
#include "UnitsSchemas.h" |
| 30 |
#include "UnitsSchemasData.h" |
| 31 |
#include "Quantity.h" |
| 32 |
|
| 33 |
|
| 34 |
class QString; |
| 35 |
|
| 36 |
using PyObject = struct _object; |
| 37 |
using PyMethodDef = struct PyMethodDef; |
| 38 |
|
| 39 |
namespace Base |
| 40 |
{ |
| 41 |
|
| 42 |
|
| 43 |
class BaseExport UnitsApi |
| 44 |
{ |
| 45 |
public: |
| 46 |
static std::unique_ptr<UnitsSchema> createSchema(std::size_t num); |
| 47 |
static void setSchema(const std::string& name); |
| 48 |
static void setSchema(std::size_t num); |
| 49 |
|
| 50 |
static std::string schemaTranslate(const Quantity& quant, double& factor, std::string& unitString); |
| 51 |
|
| 52 |
static std::string schemaTranslate(const Quantity& quant); |
| 53 |
|
| 54 |
static double toDouble(PyObject* args, const Base::Unit& u = Base::Unit()); |
| 55 |
|
| 56 |
static void setDecimals(int); |
| 57 |
static int getDecimals(); |
| 58 |
|
| 59 |
static void setDenominator(int); |
| 60 |
static int getDenominator(); |
| 61 |
|
| 62 |
static std::vector<std::string> getDescriptions(); |
| 63 |
static std::vector<std::string> getNames(); |
| 64 |
|
| 65 |
static std::size_t count(); |
| 66 |
|
| 67 |
static bool isMultiUnitAngle(); |
| 68 |
static bool isMultiUnitLength(); |
| 69 |
static std::string getBasicLengthUnit(); |
| 70 |
|
| 71 |
static std::size_t getDefSchemaNum() |
| 72 |
{ |
| 73 |
return schemas->spec().num; |
| 74 |
} |
| 75 |
// Python interface |
| 76 |
static PyMethodDef Methods[]; |
| 77 |
|
| 78 |
protected: |
| 79 |
static inline auto schemas = std::make_unique<UnitsSchemas>(UnitsSchemasData::unitSchemasDataPack); |
| 80 |
static inline int decimals {-1}; |
| 81 |
static inline int denominator {-1}; |
| 82 |
|
| 83 |
// the python API wrapper methods |
| 84 |
static PyObject* sParseQuantity(PyObject* self, PyObject* args); |
| 85 |
static PyObject* sListSchemas(PyObject* self, PyObject* args); |
| 86 |
static PyObject* sGetSchema(PyObject* self, PyObject* args); |
| 87 |
static PyObject* sSetSchema(PyObject* self, PyObject* args); |
| 88 |
static PyObject* sSchemaTranslate(PyObject* self, PyObject* args); |
| 89 |
static PyObject* sToNumber(PyObject* self, PyObject* args); |
| 90 |
}; |
| 91 |
|
| 92 |
} // namespace Base |
| 93 |
|
| 94 |
#endif // BASE_UNITSAPI_H |