PropertyUnits.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) Jürgen Riegel          (juergen.riegel@web.de) 2010     *
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 #include "PreCompiled.h"
00025 
00026 #ifndef _PreComp_
00027 # include <boost/version.hpp>
00028 # include <boost/filesystem/path.hpp>
00029 #endif
00030 
00032 
00033 #include <Base/Exception.h>
00034 #include <Base/Reader.h>
00035 #include <Base/Writer.h>
00036 #include <Base/Stream.h>
00037 #include <Base/UnitsApi.h>
00038 
00039 #include "PropertyUnits.h"
00040 #include <Base/PyObjectBase.h>
00041 
00042 #define new DEBUG_CLIENTBLOCK
00043 using namespace App;
00044 using namespace Base;
00045 using namespace std;
00046 
00047 
00048 
00049 
00050 
00051 //**************************************************************************
00052 //**************************************************************************
00053 // PropertyDistance
00054 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00055 
00056 TYPESYSTEM_SOURCE(App::PropertyDistance, App::PropertyFloat);
00057 
00058 //**************************************************************************
00059 //**************************************************************************
00060 // PropertySpeed
00061 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00062 
00063 TYPESYSTEM_SOURCE(App::PropertySpeed, App::PropertyFloat);
00064 
00065 //**************************************************************************
00066 //**************************************************************************
00067 // PropertyAcceleration
00068 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00069 
00070 TYPESYSTEM_SOURCE(App::PropertyAcceleration, App::PropertyFloat);
00071 
00072 //**************************************************************************
00073 //**************************************************************************
00074 // PropertyLength
00075 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00076 
00077 TYPESYSTEM_SOURCE(App::PropertyLength, App::PropertyFloat);
00078 
00079 const char* PropertyLength::getEditorName(void) const
00080 { 
00081 #ifdef UseUnitsInGui
00082     return "Gui::PropertyEditor::PropertyUnitItem";
00083 #else
00084     return "Gui::PropertyEditor::PropertyFloatItem"; 
00085 #endif
00086 }
00087 
00088 
00089 void PropertyLength::setPyObject(PyObject *value)
00090 {
00091 #ifdef UseUnitsInGui
00092     setValue(UnitsApi::toDblWithUserPrefs(Length,value));
00093  
00094 #else   
00095    float val=0.0f;
00096     if (PyFloat_Check(value)) {
00097         val = (float) PyFloat_AsDouble(value);
00098     }
00099     else if(PyInt_Check(value)) {
00100         val = (float) PyInt_AsLong(value);
00101     }
00102     else {
00103         std::string error = std::string("type must be float or int, not ");
00104         error += value->ob_type->tp_name;
00105         throw Py::TypeError(error);
00106     }
00107 
00108     if (val < 0.0f)
00109         throw Py::ValueError("value must be nonnegative");
00110 
00111     setValue(val);
00112 #endif
00113 }
00114 
00115 //**************************************************************************
00116 //**************************************************************************
00117 // PropertyAngle
00118 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00119 
00120 TYPESYSTEM_SOURCE(App::PropertyAngle, App::PropertyFloatConstraint);
00121 
00122 
00123 
00124 

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