00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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
00048 std::string ArcPy::representation(void) const
00049 {
00050 return "<Arc object>";
00051 }
00052
00053 PyObject *ArcPy::PyMake(struct _typeobject *, PyObject *, PyObject *)
00054 {
00055
00056 return new ArcPy(new GeomTrimmedCurve());
00057 }
00058
00059
00060 int ArcPy::PyInit(PyObject* args, PyObject* )
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
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* ) const
00141 {
00142 return 0;
00143 }
00144
00145 int ArcPy::setCustomAttributes(const char* , PyObject* )
00146 {
00147 return 0;
00148 }