ArcPyImp.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2008 Werner Mayer <wmayer[at]users.sourceforge.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 #include "PreCompiled.h"
00025 #ifndef _PreComp_
00026 # include <gp_Circ.hxx>
00027 # include <Geom_Circle.hxx>
00028 # include <gp_Elips.hxx>
00029 # include <Geom_Ellipse.hxx>
00030 # include <Geom_TrimmedCurve.hxx>
00031 # include <GC_MakeArcOfCircle.hxx>
00032 # include <GC_MakeArcOfEllipse.hxx>
00033 #endif
00034 
00035 #include "ArcPy.h"
00036 #include "ArcPy.cpp"
00037 #include "CirclePy.h"
00038 #include "EllipsePy.h"
00039 
00040 #include <Base/VectorPy.h>
00041 #include <Base/GeometryPyCXX.h>
00042 
00043 using namespace Part;
00044 
00045 extern const char* gce_ErrorStatusText(gce_ErrorType et);
00046 
00047 // returns a string which represents the object e.g. when printed in python
00048 std::string ArcPy::representation(void) const
00049 {
00050     return "<Arc object>";
00051 }
00052 
00053 PyObject *ArcPy::PyMake(struct _typeobject *, PyObject *, PyObject *)  // Python wrapper
00054 {
00055     // never create such objects with the constructor
00056     return new ArcPy(new GeomTrimmedCurve());
00057 }
00058 
00059 // constructor method
00060 int ArcPy::PyInit(PyObject* args, PyObject* /*kwd*/)
00061 {
00062     PyObject* o;
00063     double u1, u2;
00064     int sense=1;
00065     if (PyArg_ParseTuple(args, "O!dd|i", &(Part::CirclePy::Type), &o, &u1, &u2, &sense)) {
00066         try {
00067             Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast
00068                 (static_cast<CirclePy*>(o)->getGeomCirclePtr()->handle());
00069             GC_MakeArcOfCircle arc(circle->Circ(), u1, u2, sense);
00070             if (!arc.IsDone()) {
00071                 PyErr_SetString(PyExc_Exception, gce_ErrorStatusText(arc.Status()));
00072                 return -1;
00073             }
00074 
00075             getGeomTrimmedCurvePtr()->setHandle(arc.Value());
00076             return 0;
00077         }
00078         catch (Standard_Failure) {
00079             Handle_Standard_Failure e = Standard_Failure::Caught();
00080             PyErr_SetString(PyExc_Exception, e->GetMessageString());
00081             return -1;
00082         }
00083         catch (...) {
00084             PyErr_SetString(PyExc_Exception, "creation of arc failed");
00085             return -1;
00086         }
00087     }
00088 
00089     PyErr_Clear();
00090     PyObject *pV1, *pV2, *pV3;
00091     if (PyArg_ParseTuple(args, "O!O!O!", &(Base::VectorPy::Type), &pV1,
00092                                          &(Base::VectorPy::Type), &pV2,
00093                                          &(Base::VectorPy::Type), &pV3)) {
00094         Base::Vector3d v1 = static_cast<Base::VectorPy*>(pV1)->value();
00095         Base::Vector3d v2 = static_cast<Base::VectorPy*>(pV2)->value();
00096         Base::Vector3d v3 = static_cast<Base::VectorPy*>(pV3)->value();
00097 
00098         GC_MakeArcOfCircle arc(gp_Pnt(v1.x,v1.y,v1.z),
00099                                gp_Pnt(v2.x,v2.y,v2.z),
00100                                gp_Pnt(v3.x,v3.y,v3.z));
00101         if (!arc.IsDone()) {
00102             PyErr_SetString(PyExc_Exception, gce_ErrorStatusText(arc.Status()));
00103             return -1;
00104         }
00105 
00106         getGeomTrimmedCurvePtr()->setHandle(arc.Value());
00107         return 0;
00108     }
00109 
00110     PyErr_Clear();
00111     if (PyArg_ParseTuple(args, "O!dd|i", &(Part::EllipsePy::Type), &o, &u1, &u2, &sense)) {
00112         try {
00113             Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast
00114                 (static_cast<EllipsePy*>(o)->getGeomEllipsePtr()->handle());
00115             GC_MakeArcOfEllipse arc(ellipse->Elips(), u1, u2, sense);
00116             if (!arc.IsDone()) {
00117                 PyErr_SetString(PyExc_Exception, gce_ErrorStatusText(arc.Status()));
00118                 return -1;
00119             }
00120 
00121             getGeomTrimmedCurvePtr()->setHandle(arc.Value());
00122             return 0;
00123         }
00124         catch (Standard_Failure) {
00125             Handle_Standard_Failure e = Standard_Failure::Caught();
00126             PyErr_SetString(PyExc_Exception, e->GetMessageString());
00127             return -1;
00128         }
00129         catch (...) {
00130             PyErr_SetString(PyExc_Exception, "creation of arc failed");
00131             return -1;
00132         }
00133     }
00134 
00135     // All checks failed
00136     PyErr_SetString(PyExc_TypeError, "Arc constructor expects a conic curve and a parameter range");
00137     return -1;
00138 }
00139 
00140 PyObject *ArcPy::getCustomAttributes(const char* /*attr*/) const
00141 {
00142     return 0;
00143 }
00144 
00145 int ArcPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
00146 {
00147     return 0; 
00148 }

Generated on Wed Nov 23 18:59:57 2011 for FreeCAD by  doxygen 1.6.1