-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUnitsApi.h
More file actions
136 lines (115 loc) · 5.7 KB
/
UnitsApi.h
File metadata and controls
136 lines (115 loc) · 5.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/***************************************************************************
* Copyright (c) 2009 Jürgen 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_UNITSAPI_H
#define BASE_UNITSAPI_H
#if FC_BUILD_PYTHON
#include <CXX/WrapPython.h>
#endif
#include <memory>
#include <string>
#include <QString>
#include "UnitsSchema.h"
#include "Quantity.h"
namespace Base {
typedef std::unique_ptr<UnitsSchema> UnitsSchemaPtr;
/**
* The UnitsApi
*/
class BaseExport UnitsApi
{
public:
/** Constructs a UnitsApi object. */
UnitsApi(const char* filter);
UnitsApi(const std::string& filter);
virtual ~UnitsApi();
/** set Schema
* set the UnitsSchema of the Application
* this a represented by a class of type UnitSchema which
* defines a set of standard units for that schema and rules
* for representative strings.
*/
static void setSchema(UnitSystem s);
/// return the active schema
static UnitSystem getSchema(void){return actSystem;}
/// Returns a brief description of a schema
static const char* getDescription(UnitSystem);
static QString schemaTranslate(const Base::Quantity& quant, double &factor, QString &unitString);
static QString schemaTranslate(const Base::Quantity& quant) { // to satisfy GCC
double dummy1;
QString dummy2;
return UnitsApi::schemaTranslate(quant, dummy1, dummy2);
}
/** Get a number as string for a quantity of a given format.
* The string is a number in C locale (i.e. the decimal separator is always a dot) and if
* needed represented in scientific notation. The string also includes the unit of the quantity.
*/
static QString toString(const Base::Quantity& q, const QuantityFormat& f = QuantityFormat(QuantityFormat::Default));
/** Get a number as string for a quantity of a given format.
* The string is a number in C locale (i.e. the decimal separator is always a dot) and if
* needed represented in scientific notation. The string doesn't include the unit of the quantity.
*/
static QString toNumber(const Base::Quantity& q, const QuantityFormat& f = QuantityFormat(QuantityFormat::Default));
/** Get a number as string for a double of a given format.
* The string is a number in C locale (i.e. the decimal separator is always a dot) and if
* needed represented in scientific notation. The string doesn't include the unit of the quantity.
*/
static QString toNumber(double d, const QuantityFormat& f = QuantityFormat(QuantityFormat::Default));
#if FC_BUILD_PYTHON
// Python interface
static PyMethodDef Methods[];
/// generate a value for a quantity with default user preferred system
static double toDbl(PyObject *ArgObj,const Base::Unit &u=Base::Unit());
/// generate a value for a quantity with default user preferred system
static Quantity toQuantity(PyObject *ArgObj,const Base::Unit &u=Base::Unit());
#endif
// set the number of decimals
static void setDecimals(int);
// get the number of decimals
static int getDecimals();
/// set the application defaults
//static void setDefaults(void);
//@}
//double Result;
static double defaultFactor;
/// return an instance of the given enum value
static UnitsSchemaPtr createSchema(UnitSystem s);
protected:
// not used at the moment
static UnitsSchemaPtr UserPrefSystem;
static UnitSystem actSystem;
/// number of decimals for floats
static int UserPrefDecimals;
// do the real work
//static double parse(const char*,bool &UsedUnit);
#if FC_BUILD_PYTHON
protected: // the python API wrapper methods
//static PyObject *sTranslateUnit (PyObject *self,PyObject *args);
//static PyObject *sGetWithPrefs (PyObject *self,PyObject *args);
static PyObject *sParseQuantity (PyObject *self,PyObject *args);
static PyObject *sListSchemas (PyObject *self,PyObject *args);
static PyObject *sGetSchema (PyObject *self,PyObject *args);
static PyObject *sSetSchema (PyObject *self,PyObject *args);
static PyObject *sSchemaTranslate (PyObject *self,PyObject *args);
#endif
};
} // namespace Base
#endif // BASE_UNITSAPI_H