UnitsApi.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2009 Juergen Riegel  (FreeCAD@juergen-riegel.net>              *
00003  *                                                                         *
00004  *   This file is part of the FreeCAD CAx development system.              *
00005  *                                                                         *
00006  *   This library is free software; you can redistribute it and/or         *
00007  *   modify it under the terms of the GNU Library General Public           *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2 of the License, or (at your option) any later version.      *
00010  *                                                                         *
00011  *   This library  is distributed in the hope that it will be useful,      *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00014  *   GNU Library General Public License for more details.                  *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Library General Public     *
00017  *   License along with this library; see the file COPYING.LIB. If not,    *
00018  *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
00019  *   Suite 330, Boston, MA  02111-1307, USA                                *
00020  *                                                                         *
00021  ***************************************************************************/
00022 
00023 
00024 #ifndef BASE_UNITSAPI_H
00025 #define BASE_UNITSAPI_H
00026 
00027 // (re-)defined in pyconfig.h
00028 #if defined (_POSIX_C_SOURCE)
00029 #   undef    _POSIX_C_SOURCE
00030 #endif
00031 #if defined (_XOPEN_SOURCE)
00032 #   undef    _XOPEN_SOURCE
00033 #endif
00034 
00035 #include <string>
00036 #include <Python.h>
00037 #include <QString>
00038 #include "UnitsSchema.h"
00039 
00040 namespace Base {
00041     
00042 
00046 class BaseExport UnitsApi 
00047 {
00048 
00049 public:
00051     UnitsApi(const char* filter);
00052     UnitsApi(const std::string& filter);
00053     virtual ~UnitsApi();
00054 
00061     static void setSchema(UnitSystem s);
00062 
00063 
00065     static double translateUnit(const char*);
00066     static double translateUnit(const QString &);
00067 
00068 
00071 
00072     static QString toStrWithUserPrefs(QuantityType t,double Value);
00074     static void toStrWithUserPrefs(QuantityType t,double Value,QString &outValue,QString &outUnit);
00076     static PyObject *toPyWithUserPrefs(QuantityType t,double Value);
00078 
00084 
00085     static double toDblWithUserPrefs(QuantityType t,const QString & Str);
00087     static double toDblWithUserPrefs(QuantityType t,const char* Str);
00089     static double toDblWithUserPrefs(QuantityType t,double UserVal);
00091     static double toDblWithUserPrefs(QuantityType t,PyObject *ArgObj);
00093 
00096 
00097     static void setPrefOf(QuantityType t,const char* Str);
00099     static const QString & getPrefUnitOf(QuantityType t);
00101     static const QString getQuantityName(QuantityType t);
00103     static const double getPrefFactorOf(QuantityType t);
00105     static void setDefaults(void);
00107 
00108     double Result;
00109 
00110     // Python interface
00111     static PyMethodDef    Methods[];
00112 
00113 
00114 protected:
00115     // not used at the moment
00116     static UnitsSchema *  UserPrefSystem;
00117 
00119     static double   UserPrefFactor [50] ;
00121     static QString  UserPrefUnit   [50] ;
00122 
00123     // do the real work
00124     static double parse(const char*,bool &UsedUnit);
00125 
00126 protected: // the python API wrapper methodes
00127     static PyObject *sTranslateUnit   (PyObject *self,PyObject *args,PyObject *kwd);
00128     static PyObject *sGetWithPrefs    (PyObject *self,PyObject *args,PyObject *kwd);
00129 };
00130 
00131 } // namespace Base
00132 
00133 
00134 #endif // BASE_UNITSAPI_H

Generated on Wed Nov 23 19:00:56 2011 for FreeCAD by  doxygen 1.6.1