From 9bdad96a6932088ddd8303fdd54b855aea55c889 Mon Sep 17 00:00:00 2001 From: wmayer Date: Tue, 22 Nov 2016 14:09:19 +0100 Subject: [PATCH 1/2] add Python wrappers for Geom2d classes --- src/Base/GeometryPyCXX.cpp | 16 + src/Base/GeometryPyCXX.h | 2 + src/Mod/Part/App/AppPart.cpp | 117 +- src/Mod/Part/App/CMakeLists.txt | 55 + src/Mod/Part/App/Geom2d/ArcOfCircle2dPy.xml | 44 + .../Part/App/Geom2d/ArcOfCircle2dPyImp.cpp | 231 +++ src/Mod/Part/App/Geom2d/ArcOfConic2dPy.xml | 38 + src/Mod/Part/App/Geom2d/ArcOfConic2dPyImp.cpp | 217 +++ src/Mod/Part/App/Geom2d/ArcOfEllipse2dPy.xml | 56 + .../Part/App/Geom2d/ArcOfEllipse2dPyImp.cpp | 241 +++ .../Part/App/Geom2d/ArcOfHyperbola2dPy.xml | 56 + .../Part/App/Geom2d/ArcOfHyperbola2dPyImp.cpp | 241 +++ src/Mod/Part/App/Geom2d/ArcOfParabola2dPy.xml | 50 + .../Part/App/Geom2d/ArcOfParabola2dPyImp.cpp | 229 +++ src/Mod/Part/App/Geom2d/BSplineCurve2dPy.xml | 445 ++++++ .../Part/App/Geom2d/BSplineCurve2dPyImp.cpp | 1319 +++++++++++++++++ src/Mod/Part/App/Geom2d/BezierCurve2dPy.xml | 146 ++ .../Part/App/Geom2d/BezierCurve2dPyImp.cpp | 404 +++++ src/Mod/Part/App/Geom2d/Circle2dPy.xml | 66 + src/Mod/Part/App/Geom2d/Circle2dPyImp.cpp | 328 ++++ src/Mod/Part/App/Geom2d/Conic2dPy.xml | 60 + src/Mod/Part/App/Geom2d/Conic2dPyImp.cpp | 315 ++++ src/Mod/Part/App/Geom2d/Curve2dPy.xml | 160 ++ src/Mod/Part/App/Geom2d/Curve2dPyImp.cpp | 691 +++++++++ src/Mod/Part/App/Geom2d/Ellipse2dPy.xml | 99 ++ src/Mod/Part/App/Geom2d/Ellipse2dPyImp.cpp | 290 ++++ src/Mod/Part/App/Geom2d/Geometry2dPy.xml | 54 + src/Mod/Part/App/Geom2d/Geometry2dPyImp.cpp | 201 +++ src/Mod/Part/App/Geom2d/Hyperbola2dPy.xml | 99 ++ src/Mod/Part/App/Geom2d/Hyperbola2dPyImp.cpp | 290 ++++ src/Mod/Part/App/Geom2d/Line2dSegmentPy.xml | 52 + .../Part/App/Geom2d/Line2dSegmentPyImp.cpp | 332 +++++ src/Mod/Part/App/Geom2d/OffsetCurve2dPy.xml | 44 + .../Part/App/Geom2d/OffsetCurve2dPyImp.cpp | 165 +++ src/Mod/Part/App/Geom2d/Parabola2dPy.xml | 69 + src/Mod/Part/App/Geom2d/Parabola2dPyImp.cpp | 228 +++ src/Mod/Part/App/Geometry2d.cpp | 895 ++++------- src/Mod/Part/App/Geometry2d.h | 114 +- 38 files changed, 7766 insertions(+), 693 deletions(-) create mode 100644 src/Mod/Part/App/Geom2d/ArcOfCircle2dPy.xml create mode 100644 src/Mod/Part/App/Geom2d/ArcOfCircle2dPyImp.cpp create mode 100644 src/Mod/Part/App/Geom2d/ArcOfConic2dPy.xml create mode 100644 src/Mod/Part/App/Geom2d/ArcOfConic2dPyImp.cpp create mode 100644 src/Mod/Part/App/Geom2d/ArcOfEllipse2dPy.xml create mode 100644 src/Mod/Part/App/Geom2d/ArcOfEllipse2dPyImp.cpp create mode 100644 src/Mod/Part/App/Geom2d/ArcOfHyperbola2dPy.xml create mode 100644 src/Mod/Part/App/Geom2d/ArcOfHyperbola2dPyImp.cpp create mode 100644 src/Mod/Part/App/Geom2d/ArcOfParabola2dPy.xml create mode 100644 src/Mod/Part/App/Geom2d/ArcOfParabola2dPyImp.cpp create mode 100644 src/Mod/Part/App/Geom2d/BSplineCurve2dPy.xml create mode 100644 src/Mod/Part/App/Geom2d/BSplineCurve2dPyImp.cpp create mode 100644 src/Mod/Part/App/Geom2d/BezierCurve2dPy.xml create mode 100644 src/Mod/Part/App/Geom2d/BezierCurve2dPyImp.cpp create mode 100644 src/Mod/Part/App/Geom2d/Circle2dPy.xml create mode 100644 src/Mod/Part/App/Geom2d/Circle2dPyImp.cpp create mode 100644 src/Mod/Part/App/Geom2d/Conic2dPy.xml create mode 100644 src/Mod/Part/App/Geom2d/Conic2dPyImp.cpp create mode 100644 src/Mod/Part/App/Geom2d/Curve2dPy.xml create mode 100644 src/Mod/Part/App/Geom2d/Curve2dPyImp.cpp create mode 100644 src/Mod/Part/App/Geom2d/Ellipse2dPy.xml create mode 100644 src/Mod/Part/App/Geom2d/Ellipse2dPyImp.cpp create mode 100644 src/Mod/Part/App/Geom2d/Geometry2dPy.xml create mode 100644 src/Mod/Part/App/Geom2d/Geometry2dPyImp.cpp create mode 100644 src/Mod/Part/App/Geom2d/Hyperbola2dPy.xml create mode 100644 src/Mod/Part/App/Geom2d/Hyperbola2dPyImp.cpp create mode 100644 src/Mod/Part/App/Geom2d/Line2dSegmentPy.xml create mode 100644 src/Mod/Part/App/Geom2d/Line2dSegmentPyImp.cpp create mode 100644 src/Mod/Part/App/Geom2d/OffsetCurve2dPy.xml create mode 100644 src/Mod/Part/App/Geom2d/OffsetCurve2dPyImp.cpp create mode 100644 src/Mod/Part/App/Geom2d/Parabola2dPy.xml create mode 100644 src/Mod/Part/App/Geom2d/Parabola2dPyImp.cpp diff --git a/src/Base/GeometryPyCXX.cpp b/src/Base/GeometryPyCXX.cpp index 67e9212079d7..184d1acec4a2 100644 --- a/src/Base/GeometryPyCXX.cpp +++ b/src/Base/GeometryPyCXX.cpp @@ -94,6 +94,22 @@ Vector2dPy::Vector2dPy(Py::PythonClassInstance *self, Py::Tuple &args, Py::Dict { } +Vector2dPy::Vector2dPy() + : Py::PythonClass::PythonClass + (reinterpret_cast + (Vector2dPy::type_object()), Py::Tuple(), Py::Dict()) +{ +} + +Vector2dPy::Vector2dPy(double x, double y) + : Py::PythonClass::PythonClass + (reinterpret_cast + (Vector2dPy::type_object()), Py::Tuple(), Py::Dict()) +{ + v.x = x; + v.y = y; +} + Vector2dPy::~Vector2dPy() { } diff --git a/src/Base/GeometryPyCXX.h b/src/Base/GeometryPyCXX.h index 188cd7b44ba5..58804f0280ff 100644 --- a/src/Base/GeometryPyCXX.h +++ b/src/Base/GeometryPyCXX.h @@ -51,6 +51,8 @@ class BaseExport Vector2dPy : public Py::PythonClass { public: Vector2dPy(Py::PythonClassInstance *self, Py::Tuple &args, Py::Dict &kwds); + Vector2dPy(); + Vector2dPy(double, double); virtual ~Vector2dPy(); static void init_type(void); diff --git a/src/Mod/Part/App/AppPart.cpp b/src/Mod/Part/App/AppPart.cpp index 4fe2bac01bde..4d1d08de71a1 100644 --- a/src/Mod/Part/App/AppPart.cpp +++ b/src/Mod/Part/App/AppPart.cpp @@ -57,44 +57,60 @@ #include "CustomFeature.h" #include "Geometry.h" #include "Geometry2d.h" -#include "TopoShapePy.h" -#include "TopoShapeVertexPy.h" -#include "TopoShapeFacePy.h" -#include "TopoShapeWirePy.h" -#include "TopoShapeEdgePy.h" -#include "TopoShapeSolidPy.h" -#include "TopoShapeCompoundPy.h" -#include "TopoShapeCompSolidPy.h" -#include "TopoShapeShellPy.h" -#include "LinePy.h" -#include "PointPy.h" -#include "CirclePy.h" -#include "EllipsePy.h" -#include "ArcPy.h" -#include "ArcOfCirclePy.h" -#include "ArcOfEllipsePy.h" -#include "ArcOfParabolaPy.h" -#include "ArcOfHyperbolaPy.h" -#include "BezierCurvePy.h" -#include "BSplineCurvePy.h" -#include "HyperbolaPy.h" -#include "OffsetCurvePy.h" -#include "ParabolaPy.h" -#include "BezierSurfacePy.h" -#include "BSplineSurfacePy.h" -#include "ConePy.h" -#include "CylinderPy.h" -#include "OffsetSurfacePy.h" -#include "PlateSurfacePy.h" -#include "PlanePy.h" -#include "RectangularTrimmedSurfacePy.h" -#include "SpherePy.h" -#include "SurfaceOfExtrusionPy.h" -#include "SurfaceOfRevolutionPy.h" -#include "ToroidPy.h" -#include "BRepOffsetAPI_MakePipeShellPy.h" -#include "PartFeaturePy.h" -#include "AttachEnginePy.h" +#include "Mod/Part/App/TopoShapePy.h" +#include "Mod/Part/App/TopoShapeVertexPy.h" +#include "Mod/Part/App/TopoShapeFacePy.h" +#include "Mod/Part/App/TopoShapeWirePy.h" +#include "Mod/Part/App/TopoShapeEdgePy.h" +#include "Mod/Part/App/TopoShapeSolidPy.h" +#include "Mod/Part/App/TopoShapeCompoundPy.h" +#include "Mod/Part/App/TopoShapeCompSolidPy.h" +#include "Mod/Part/App/TopoShapeShellPy.h" +#include "Mod/Part/App/LinePy.h" +#include "Mod/Part/App/PointPy.h" +#include "Mod/Part/App/CirclePy.h" +#include "Mod/Part/App/EllipsePy.h" +#include "Mod/Part/App/ArcPy.h" +#include "Mod/Part/App/ArcOfCirclePy.h" +#include "Mod/Part/App/ArcOfEllipsePy.h" +#include "Mod/Part/App/ArcOfParabolaPy.h" +#include "Mod/Part/App/ArcOfHyperbolaPy.h" +#include "Mod/Part/App/BezierCurvePy.h" +#include "Mod/Part/App/BSplineCurvePy.h" +#include "Mod/Part/App/HyperbolaPy.h" +#include "Mod/Part/App/OffsetCurvePy.h" +#include "Mod/Part/App/ParabolaPy.h" +#include "Mod/Part/App/BezierSurfacePy.h" +#include "Mod/Part/App/BSplineSurfacePy.h" +#include "Mod/Part/App/ConePy.h" +#include "Mod/Part/App/CylinderPy.h" +#include "Mod/Part/App/OffsetSurfacePy.h" +#include "Mod/Part/App/PlateSurfacePy.h" +#include "Mod/Part/App/PlanePy.h" +#include "Mod/Part/App/RectangularTrimmedSurfacePy.h" +#include "Mod/Part/App/SpherePy.h" +#include "Mod/Part/App/SurfaceOfExtrusionPy.h" +#include "Mod/Part/App/SurfaceOfRevolutionPy.h" +#include "Mod/Part/App/ToroidPy.h" +#include "Mod/Part/App/BRepOffsetAPI_MakePipeShellPy.h" +#include "Mod/Part/App/PartFeaturePy.h" +#include "Mod/Part/App/AttachEnginePy.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include "PropertyGeometryList.h" #include "DatumFeature.h" #include "Attacher.h" @@ -227,7 +243,28 @@ PyMODINIT_FUNC initPart() PyModule_AddObject(partModule, "BRepOffsetAPI", brepModule); Base::Interpreter().addType(&Part::BRepOffsetAPI_MakePipeShellPy::Type,brepModule,"MakePipeShell"); - try{ + // Geom2d package + PyObject* geom2dModule = Py_InitModule3("Geom2d", 0, "Geom2d"); + Py_INCREF(geom2dModule); + PyModule_AddObject(partModule, "Geom2d", geom2dModule); + Base::Interpreter().addType(&Part::Geometry2dPy::Type,geom2dModule,"Geometry2d"); + Base::Interpreter().addType(&Part::Curve2dPy::Type,geom2dModule,"Curve2d"); + Base::Interpreter().addType(&Part::Conic2dPy::Type,geom2dModule,"Conic2d"); + Base::Interpreter().addType(&Part::Circle2dPy::Type,geom2dModule,"Circle2d"); + Base::Interpreter().addType(&Part::Ellipse2dPy::Type,geom2dModule,"Ellipse2d"); + Base::Interpreter().addType(&Part::Hyperbola2dPy::Type,geom2dModule,"Hyperbola2d"); + Base::Interpreter().addType(&Part::Parabola2dPy::Type,geom2dModule,"Parabola2d"); + Base::Interpreter().addType(&Part::ArcOfConic2dPy::Type,geom2dModule,"ArcOfConic2d"); + Base::Interpreter().addType(&Part::ArcOfCircle2dPy::Type,geom2dModule,"ArcOfCircle2d"); + Base::Interpreter().addType(&Part::ArcOfEllipse2dPy::Type,geom2dModule,"ArcOfEllipse2d"); + Base::Interpreter().addType(&Part::ArcOfHyperbola2dPy::Type,geom2dModule,"ArcOfHyperbola2d"); + Base::Interpreter().addType(&Part::ArcOfParabola2dPy::Type,geom2dModule,"ArcOfParabola2d"); + Base::Interpreter().addType(&Part::BezierCurve2dPy::Type,geom2dModule,"BezierCurve2d"); + Base::Interpreter().addType(&Part::BSplineCurve2dPy::Type,geom2dModule,"BSplineCurve2d"); + Base::Interpreter().addType(&Part::Line2dSegmentPy::Type,geom2dModule,"Line2dSegment"); + Base::Interpreter().addType(&Part::OffsetCurve2dPy::Type,geom2dModule,"OffsetCurve2d"); + + try { //import all submodules of BOPTools, to make them easy to browse in Py console. //It's done in this weird manner instead of bt.caMemberFunction("importAll"), //because the latter crashed when importAll failed with exception. @@ -355,6 +392,8 @@ PyMODINIT_FUNC initPart() Part::Geom2dCurve ::init(); Part::Geom2dBezierCurve ::init(); Part::Geom2dBSplineCurve ::init(); + Part::Geom2dConic ::init(); + Part::Geom2dArcOfConic ::init(); Part::Geom2dCircle ::init(); Part::Geom2dArcOfCircle ::init(); Part::Geom2dEllipse ::init(); diff --git a/src/Mod/Part/App/CMakeLists.txt b/src/Mod/Part/App/CMakeLists.txt index 890f1d1fcf78..078bd1d989ed 100644 --- a/src/Mod/Part/App/CMakeLists.txt +++ b/src/Mod/Part/App/CMakeLists.txt @@ -13,6 +13,7 @@ include_directories( ${CMAKE_BINARY_DIR}/src ${CMAKE_SOURCE_DIR}/src ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_CURRENT_SOURCE_DIR} ${Boost_INCLUDE_DIRS} ${OCC_INCLUDE_DIR} ${PYTHON_INCLUDE_DIRS} @@ -82,6 +83,22 @@ generate_from_xml(TopoShapeSolidPy) generate_from_xml(TopoShapeVertexPy) generate_from_xml(TopoShapeWirePy) generate_from_xml(BRepOffsetAPI_MakePipeShellPy) +generate_from_xml(Geom2d/ArcOfCircle2dPy) +generate_from_xml(Geom2d/ArcOfConic2dPy) +generate_from_xml(Geom2d/ArcOfEllipse2dPy) +generate_from_xml(Geom2d/ArcOfHyperbola2dPy) +generate_from_xml(Geom2d/ArcOfParabola2dPy) +generate_from_xml(Geom2d/BezierCurve2dPy) +generate_from_xml(Geom2d/BSplineCurve2dPy) +generate_from_xml(Geom2d/Circle2dPy) +generate_from_xml(Geom2d/Conic2dPy) +generate_from_xml(Geom2d/Ellipse2dPy) +generate_from_xml(Geom2d/Geometry2dPy) +generate_from_xml(Geom2d/Hyperbola2dPy) +generate_from_xml(Geom2d/Curve2dPy) +generate_from_xml(Geom2d/Line2dSegmentPy) +generate_from_xml(Geom2d/OffsetCurve2dPy) +generate_from_xml(Geom2d/Parabola2dPy) SET(Features_SRCS FeaturePartBoolean.cpp @@ -249,10 +266,48 @@ SET(Python_SRCS ) SOURCE_GROUP("Python" FILES ${Python_SRCS}) +# Geom2d wrappers +SET(Geom2dPy_SRCS + Geom2d/ArcOfCircle2dPy.xml + Geom2d/ArcOfCircle2dPyImp.cpp + Geom2d/ArcOfConic2dPy.xml + Geom2d/ArcOfConic2dPyImp.cpp + Geom2d/ArcOfEllipse2dPy.xml + Geom2d/ArcOfEllipse2dPyImp.cpp + Geom2d/ArcOfHyperbola2dPy.xml + Geom2d/ArcOfHyperbola2dPyImp.cpp + Geom2d/ArcOfParabola2dPy.xml + Geom2d/ArcOfParabola2dPyImp.cpp + Geom2d/BezierCurve2dPy.xml + Geom2d/BezierCurve2dPyImp.cpp + Geom2d/BSplineCurve2dPy.xml + Geom2d/BSplineCurve2dPyImp.cpp + Geom2d/Circle2dPy.xml + Geom2d/Circle2dPyImp.cpp + Geom2d/Conic2dPy.xml + Geom2d/Conic2dPyImp.cpp + Geom2d/Ellipse2dPy.xml + Geom2d/Ellipse2dPyImp.cpp + Geom2d/Geometry2dPy.xml + Geom2d/Geometry2dPyImp.cpp + Geom2d/Curve2dPy.xml + Geom2d/Curve2dPyImp.cpp + Geom2d/Hyperbola2dPy.xml + Geom2d/Hyperbola2dPyImp.cpp + Geom2d/Line2dSegmentPy.xml + Geom2d/Line2dSegmentPyImp.cpp + Geom2d/OffsetCurve2dPy.xml + Geom2d/OffsetCurve2dPyImp.cpp + Geom2d/Parabola2dPy.xml + Geom2d/Parabola2dPyImp.cpp +) +SOURCE_GROUP("Geom2d" FILES ${Geom2dPy_SRCS}) + SET(Part_SRCS ${Features_SRCS} ${Properties_SRCS} ${Python_SRCS} + ${Geom2dPy_SRCS} Attacher.cpp Attacher.h AppPart.cpp diff --git a/src/Mod/Part/App/Geom2d/ArcOfCircle2dPy.xml b/src/Mod/Part/App/Geom2d/ArcOfCircle2dPy.xml new file mode 100644 index 000000000000..4e319f71f72f --- /dev/null +++ b/src/Mod/Part/App/Geom2d/ArcOfCircle2dPy.xml @@ -0,0 +1,44 @@ + + + + + + Describes a portion of a circle + + + + diff --git a/src/Mod/Part/App/Geom2d/ArcOfCircle2dPyImp.cpp b/src/Mod/Part/App/Geom2d/ArcOfCircle2dPyImp.cpp new file mode 100644 index 000000000000..33cbc02916be --- /dev/null +++ b/src/Mod/Part/App/Geom2d/ArcOfCircle2dPyImp.cpp @@ -0,0 +1,231 @@ +/*************************************************************************** + * Copyright (c) 2011 Werner Mayer * + * * + * 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 * + * * + ***************************************************************************/ + + +#include "PreCompiled.h" +#ifndef _PreComp_ +# include +# include +# include +# include +# include +#endif + +#include +#include +#include +//#include "CirclePy.h" +//#include "OCCError.h" + +#include +#include + +using namespace Part; + +extern const char* gce_ErrorStatusText(gce_ErrorType et); + +// returns a string which represents the object e.g. when printed in python +std::string ArcOfCircle2dPy::representation(void) const +{ +#if 0 + Handle_Geom_TrimmedCurve trim = Handle_Geom_TrimmedCurve::DownCast + (getGeomArcOfCirclePtr()->handle()); + Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(trim->BasisCurve()); + + gp_Ax1 axis = circle->Axis(); + gp_Dir dir = axis.Direction(); + gp_Pnt loc = axis.Location(); + Standard_Real fRad = circle->Radius(); + Standard_Real u1 = trim->FirstParameter(); + Standard_Real u2 = trim->LastParameter(); + + std::stringstream str; + str << "ArcOfCircle ("; + str << "Radius : " << fRad << ", "; + str << "Position : (" << loc.X() << ", "<< loc.Y() << ", "<< loc.Z() << "), "; + str << "Direction : (" << dir.X() << ", "<< dir.Y() << ", "<< dir.Z() << "), "; + str << "Parameter : (" << u1 << ", " << u2 << ")"; + str << ")"; + + return str.str(); +#else + return ""; +#endif +} + +PyObject *ArcOfCircle2dPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper +{ + // create a new instance of ArcOfCirclePy and the Twin object + return new ArcOfCircle2dPy(new Geom2dArcOfCircle); +} + +// constructor method +int ArcOfCircle2dPy::PyInit(PyObject* args, PyObject* /*kwds*/) +{ +#if 1 + return 0; +#else + PyObject* o; + double u1, u2; + PyObject *sense=Py_True; + if (PyArg_ParseTuple(args, "O!dd|O!", &(Part::CirclePy::Type), &o, &u1, &u2, &PyBool_Type, &sense)) { + try { + Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast + (static_cast(o)->getGeomCirclePtr()->handle()); + GC_MakeArcOfCircle arc(circle->Circ(), u1, u2, PyObject_IsTrue(sense) ? Standard_True : Standard_False); + if (!arc.IsDone()) { + PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(arc.Status())); + return -1; + } + + getGeomArcOfCirclePtr()->setHandle(arc.Value()); + return 0; + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); + return -1; + } + catch (...) { + PyErr_SetString(PartExceptionOCCError, "creation of arc failed"); + return -1; + } + } + + PyErr_Clear(); + PyObject *pV1, *pV2, *pV3; + if (PyArg_ParseTuple(args, "O!O!O!", &(Base::VectorPy::Type), &pV1, + &(Base::VectorPy::Type), &pV2, + &(Base::VectorPy::Type), &pV3)) { + Base::Vector3d v1 = static_cast(pV1)->value(); + Base::Vector3d v2 = static_cast(pV2)->value(); + Base::Vector3d v3 = static_cast(pV3)->value(); + + GC_MakeArcOfCircle arc(gp_Pnt(v1.x,v1.y,v1.z), + gp_Pnt(v2.x,v2.y,v2.z), + gp_Pnt(v3.x,v3.y,v3.z)); + if (!arc.IsDone()) { + PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(arc.Status())); + return -1; + } + + getGeomArcOfCirclePtr()->setHandle(arc.Value()); + return 0; + } + + // All checks failed + PyErr_SetString(PyExc_TypeError, + "ArcOfCircle constructor expects a circle curve and a parameter range or three points"); + return -1; +#endif +} +#if 0 +Py::Float ArcOfCircle2dPy::getRadius(void) const +{ + return Py::Float(getGeomArcOfCirclePtr()->getRadius()); +} + +void ArcOfCircle2dPy::setRadius(Py::Float arg) +{ + getGeomArcOfCirclePtr()->setRadius((double)arg); +} + +Py::Object ArcOfCircle2dPy::getCenter(void) const +{ + return Py::Vector(getGeomArcOfCirclePtr()->getCenter()); +} + +void ArcOfCircle2dPy::setCenter(Py::Object arg) +{ + PyObject* p = arg.ptr(); + if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) { + Base::Vector3d loc = static_cast(p)->value(); + getGeomArcOfCirclePtr()->setCenter(loc); + } + else if (PyObject_TypeCheck(p, &PyTuple_Type)) { + Base::Vector3d loc = Base::getVectorFromTuple(p); + getGeomArcOfCirclePtr()->setCenter(loc); + } + else { + std::string error = std::string("type must be 'Vector', not "); + error += p->ob_type->tp_name; + throw Py::TypeError(error); + } +} + +Py::Object ArcOfCircle2dPy::getAxis(void) const +{ + Handle_Geom_TrimmedCurve trim = Handle_Geom_TrimmedCurve::DownCast + (getGeomArcOfCirclePtr()->handle()); + Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(trim->BasisCurve()); + gp_Ax1 axis = circle->Axis(); + gp_Dir dir = axis.Direction(); + return Py::Vector(Base::Vector3d(dir.X(), dir.Y(), dir.Z())); +} + +void ArcOfCircle2dPy::setAxis(Py::Object arg) +{ + PyObject* p = arg.ptr(); + Base::Vector3d val; + if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) { + val = static_cast(p)->value(); + } + else if (PyTuple_Check(p)) { + val = Base::getVectorFromTuple(p); + } + else { + std::string error = std::string("type must be 'Vector', not "); + error += p->ob_type->tp_name; + throw Py::TypeError(error); + } + + Handle_Geom_TrimmedCurve trim = Handle_Geom_TrimmedCurve::DownCast + (getGeomArcOfCirclePtr()->handle()); + Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(trim->BasisCurve()); + try { + gp_Ax1 axis; + axis.SetLocation(circle->Location()); + axis.SetDirection(gp_Dir(val.x, val.y, val.z)); + circle->SetAxis(axis); + } + catch (Standard_Failure) { + throw Py::Exception("cannot set axis"); + } +} + +Py::Object ArcOfCircle2dPy::getCircle(void) const +{ + Handle_Geom_TrimmedCurve trim = Handle_Geom_TrimmedCurve::DownCast + (getGeomArcOfCirclePtr()->handle()); + Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(trim->BasisCurve()); + return Py::Object(new CirclePy(new GeomCircle(circle)), true); +} +#endif +PyObject *ArcOfCircle2dPy::getCustomAttributes(const char* ) const +{ + return 0; +} + +int ArcOfCircle2dPy::setCustomAttributes(const char* , PyObject *) +{ + return 0; +} diff --git a/src/Mod/Part/App/Geom2d/ArcOfConic2dPy.xml b/src/Mod/Part/App/Geom2d/ArcOfConic2dPy.xml new file mode 100644 index 000000000000..2ec3f35c3763 --- /dev/null +++ b/src/Mod/Part/App/Geom2d/ArcOfConic2dPy.xml @@ -0,0 +1,38 @@ + + + + + + Describes a portion of a circle + + + + diff --git a/src/Mod/Part/App/Geom2d/ArcOfConic2dPyImp.cpp b/src/Mod/Part/App/Geom2d/ArcOfConic2dPyImp.cpp new file mode 100644 index 000000000000..97ad399efbb4 --- /dev/null +++ b/src/Mod/Part/App/Geom2d/ArcOfConic2dPyImp.cpp @@ -0,0 +1,217 @@ +/*************************************************************************** + * Copyright (c) 2011 Werner Mayer * + * * + * 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 * + * * + ***************************************************************************/ + + +#include "PreCompiled.h" +#ifndef _PreComp_ +# include +# include +# include +# include +# include +#endif + +#include +#include +#include +#include + +#include +#include + +using namespace Part; + +extern const char* gce_ErrorStatusText(gce_ErrorType et); + +// returns a string which represents the object e.g. when printed in python +std::string ArcOfConic2dPy::representation(void) const +{ +#if 0 + Handle_Geom_TrimmedCurve trim = Handle_Geom_TrimmedCurve::DownCast + (getGeomArcOfCirclePtr()->handle()); + Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(trim->BasisCurve()); + + gp_Ax1 axis = circle->Axis(); + gp_Dir dir = axis.Direction(); + gp_Pnt loc = axis.Location(); + Standard_Real fRad = circle->Radius(); + Standard_Real u1 = trim->FirstParameter(); + Standard_Real u2 = trim->LastParameter(); + + std::stringstream str; + str << "ArcOfCircle ("; + str << "Radius : " << fRad << ", "; + str << "Position : (" << loc.X() << ", "<< loc.Y() << ", "<< loc.Z() << "), "; + str << "Direction : (" << dir.X() << ", "<< dir.Y() << ", "<< dir.Z() << "), "; + str << "Parameter : (" << u1 << ", " << u2 << ")"; + str << ")"; + + return str.str(); +#else + return ""; +#endif +} + +PyObject *ArcOfConic2dPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper +{ + return 0; +} + +// constructor method +int ArcOfConic2dPy::PyInit(PyObject* args, PyObject* /*kwds*/) +{ +#if 0 + PyObject* o; + double u1, u2; + PyObject *sense=Py_True; + if (PyArg_ParseTuple(args, "O!dd|O!", &(Part::CirclePy::Type), &o, &u1, &u2, &PyBool_Type, &sense)) { + try { + Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast + (static_cast(o)->getGeomCirclePtr()->handle()); + GC_MakeArcOfCircle arc(circle->Circ(), u1, u2, PyObject_IsTrue(sense) ? Standard_True : Standard_False); + if (!arc.IsDone()) { + PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(arc.Status())); + return -1; + } + + getGeomArcOfCirclePtr()->setHandle(arc.Value()); + return 0; + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); + return -1; + } + catch (...) { + PyErr_SetString(PartExceptionOCCError, "creation of arc failed"); + return -1; + } + } + + PyErr_Clear(); + PyObject *pV1, *pV2, *pV3; + if (PyArg_ParseTuple(args, "O!O!O!", &(Base::VectorPy::Type), &pV1, + &(Base::VectorPy::Type), &pV2, + &(Base::VectorPy::Type), &pV3)) { + Base::Vector3d v1 = static_cast(pV1)->value(); + Base::Vector3d v2 = static_cast(pV2)->value(); + Base::Vector3d v3 = static_cast(pV3)->value(); + + GC_MakeArcOfCircle arc(gp_Pnt(v1.x,v1.y,v1.z), + gp_Pnt(v2.x,v2.y,v2.z), + gp_Pnt(v3.x,v3.y,v3.z)); + if (!arc.IsDone()) { + PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(arc.Status())); + return -1; + } + + getGeomArcOfCirclePtr()->setHandle(arc.Value()); + return 0; + } + + // All checks failed + PyErr_SetString(PyExc_TypeError, + "ArcOfCircle constructor expects a circle curve and a parameter range or three points"); +#endif + return -1; +} +#if 0 +Py::Object ArcOfConic2dPy::getCenter(void) const +{ + return Py::Vector(getGeomArcOfCirclePtr()->getCenter()); +} + +void ArcOfConic2dPy::setCenter(Py::Object arg) +{ + PyObject* p = arg.ptr(); + if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) { + Base::Vector3d loc = static_cast(p)->value(); + getGeomArcOfCirclePtr()->setCenter(loc); + } + else if (PyObject_TypeCheck(p, &PyTuple_Type)) { + Base::Vector3d loc = Base::getVectorFromTuple(p); + getGeomArcOfCirclePtr()->setCenter(loc); + } + else { + std::string error = std::string("type must be 'Vector', not "); + error += p->ob_type->tp_name; + throw Py::TypeError(error); + } +} + +Py::Object ArcOfConic2dPy::getAxis(void) const +{ + Handle_Geom_TrimmedCurve trim = Handle_Geom_TrimmedCurve::DownCast + (getGeomArcOfCirclePtr()->handle()); + Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(trim->BasisCurve()); + gp_Ax1 axis = circle->Axis(); + gp_Dir dir = axis.Direction(); + return Py::Vector(Base::Vector3d(dir.X(), dir.Y(), dir.Z())); +} + +void ArcOfConic2dPy::setAxis(Py::Object arg) +{ + PyObject* p = arg.ptr(); + Base::Vector3d val; + if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) { + val = static_cast(p)->value(); + } + else if (PyTuple_Check(p)) { + val = Base::getVectorFromTuple(p); + } + else { + std::string error = std::string("type must be 'Vector', not "); + error += p->ob_type->tp_name; + throw Py::TypeError(error); + } + + Handle_Geom_TrimmedCurve trim = Handle_Geom_TrimmedCurve::DownCast + (getGeomArcOfCirclePtr()->handle()); + Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(trim->BasisCurve()); + try { + gp_Ax1 axis; + axis.SetLocation(circle->Location()); + axis.SetDirection(gp_Dir(val.x, val.y, val.z)); + circle->SetAxis(axis); + } + catch (Standard_Failure) { + throw Py::Exception("cannot set axis"); + } +} + +Py::Object ArcOfConic2dPy::getCircle(void) const +{ + Handle_Geom_TrimmedCurve trim = Handle_Geom_TrimmedCurve::DownCast + (getGeomArcOfCirclePtr()->handle()); + Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(trim->BasisCurve()); + return Py::Object(new CirclePy(new GeomCircle(circle)), true); +} +#endif +PyObject *ArcOfConic2dPy::getCustomAttributes(const char* ) const +{ + return 0; +} + +int ArcOfConic2dPy::setCustomAttributes(const char* , PyObject *) +{ + return 0; +} diff --git a/src/Mod/Part/App/Geom2d/ArcOfEllipse2dPy.xml b/src/Mod/Part/App/Geom2d/ArcOfEllipse2dPy.xml new file mode 100644 index 000000000000..54ab57055752 --- /dev/null +++ b/src/Mod/Part/App/Geom2d/ArcOfEllipse2dPy.xml @@ -0,0 +1,56 @@ + + + + + + Describes a portion of an ellipse + + + + diff --git a/src/Mod/Part/App/Geom2d/ArcOfEllipse2dPyImp.cpp b/src/Mod/Part/App/Geom2d/ArcOfEllipse2dPyImp.cpp new file mode 100644 index 000000000000..d80d1c3cc02b --- /dev/null +++ b/src/Mod/Part/App/Geom2d/ArcOfEllipse2dPyImp.cpp @@ -0,0 +1,241 @@ +/*************************************************************************** + * Copyright (c) 2014 Abdullah Tahiri +# include +# include +# include +# include +#endif + +#include +#include +#include +#include +#include + +#include +#include + +using namespace Part; + +extern const char* gce_ErrorStatusText(gce_ErrorType et); + +// returns a string which represents the object e.g. when printed in python +std::string ArcOfEllipse2dPy::representation(void) const +{ +#if 0 + Handle_Geom_TrimmedCurve trim = Handle_Geom_TrimmedCurve::DownCast + (getGeomArcOfEllipsePtr()->handle()); + Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast(trim->BasisCurve()); + + gp_Ax1 axis = ellipse->Axis(); + gp_Dir dir = axis.Direction(); + gp_Pnt loc = axis.Location(); + Standard_Real fMajRad = ellipse->MajorRadius(); + Standard_Real fMinRad = ellipse->MinorRadius(); + Standard_Real u1 = trim->FirstParameter(); + Standard_Real u2 = trim->LastParameter(); + + gp_Dir normal = ellipse->Axis().Direction(); + gp_Dir xdir = ellipse->XAxis().Direction(); + + gp_Ax2 xdirref(loc, normal); // this is a reference XY for the ellipse + + Standard_Real fAngleXU = -xdir.AngleWithRef(xdirref.XDirection(),normal); + + + std::stringstream str; + str << "ArcOfEllipse ("; + str << "MajorRadius : " << fMajRad << ", "; + str << "MinorRadius : " << fMinRad << ", "; + str << "AngleXU : " << fAngleXU << ", "; + str << "Position : (" << loc.X() << ", "<< loc.Y() << ", "<< loc.Z() << "), "; + str << "Direction : (" << dir.X() << ", "<< dir.Y() << ", "<< dir.Z() << "), "; + str << "Parameter : (" << u1 << ", " << u2 << ")"; + str << ")"; + + return str.str(); +#else + return ""; +#endif +} + +PyObject *ArcOfEllipse2dPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper +{ + // create a new instance of ArcOfEllipse2dPy and the Twin object + return new ArcOfEllipse2dPy(new Geom2dArcOfEllipse); +} + +// constructor method +int ArcOfEllipse2dPy::PyInit(PyObject* args, PyObject* /*kwds*/) +{ +#if 1 + return 0; +#else + PyObject* o; + double u1, u2; + PyObject *sense=Py_True; + if (PyArg_ParseTuple(args, "O!dd|O!", &(Part::EllipsePy::Type), &o, &u1, &u2, &PyBool_Type, &sense)) { + try { + Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast + (static_cast(o)->getGeomEllipsePtr()->handle()); + GC_MakeArcOfEllipse arc(ellipse->Elips(), u1, u2, PyObject_IsTrue(sense) ? Standard_True : Standard_False); + if (!arc.IsDone()) { + PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(arc.Status())); + return -1; + } + + getGeomArcOfEllipsePtr()->setHandle(arc.Value()); + return 0; + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); + return -1; + } + catch (...) { + PyErr_SetString(PartExceptionOCCError, "creation of arc failed"); + return -1; + } + } + + // All checks failed + PyErr_SetString(PyExc_TypeError, + "ArcOfEllipse constructor expects an ellipse curve and a parameter range"); + return -1; +#endif +} +#if 0 +Py::Float ArcOfEllipse2dPy::getMajorRadius(void) const +{ + return Py::Float(getGeomArcOfEllipsePtr()->getMajorRadius()); +} + +void ArcOfEllipse2dPy::setMajorRadius(Py::Float arg) +{ + getGeomArcOfEllipsePtr()->setMajorRadius((double)arg); +} + +Py::Float ArcOfEllipse2dPy::getMinorRadius(void) const +{ + return Py::Float(getGeomArcOfEllipsePtr()->getMinorRadius()); +} + +void ArcOfEllipse2dPy::setMinorRadius(Py::Float arg) +{ + getGeomArcOfEllipsePtr()->setMinorRadius((double)arg); +} + +Py::Float ArcOfEllipse2dPy::getAngleXU(void) const +{ + return Py::Float(getGeomArcOfEllipsePtr()->getAngleXU()); +} + +void ArcOfEllipse2dPy::setAngleXU(Py::Float arg) +{ + getGeomArcOfEllipsePtr()->setAngleXU((double)arg); +} + +Py::Object ArcOfEllipse2dPy::getCenter(void) const +{ + return Py::Vector(getGeomArcOfEllipsePtr()->getCenter()); +} + +void ArcOfEllipse2dPy::setCenter(Py::Object arg) +{ + PyObject* p = arg.ptr(); + if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) { + Base::Vector3d loc = static_cast(p)->value(); + getGeomArcOfEllipsePtr()->setCenter(loc); + } + else if (PyObject_TypeCheck(p, &PyTuple_Type)) { + Base::Vector3d loc = Base::getVectorFromTuple(p); + getGeomArcOfEllipsePtr()->setCenter(loc); + } + else { + std::string error = std::string("type must be 'Vector', not "); + error += p->ob_type->tp_name; + throw Py::TypeError(error); + } +} + +Py::Object ArcOfEllipse2dPy::getAxis(void) const +{ + Handle_Geom_TrimmedCurve trim = Handle_Geom_TrimmedCurve::DownCast + (getGeomArcOfEllipsePtr()->handle()); + Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast(trim->BasisCurve()); + gp_Ax1 axis = ellipse->Axis(); + gp_Dir dir = axis.Direction(); + return Py::Vector(Base::Vector3d(dir.X(), dir.Y(), dir.Z())); +} + +void ArcOfEllipse2dPy::setAxis(Py::Object arg) +{ + PyObject* p = arg.ptr(); + Base::Vector3d val; + if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) { + val = static_cast(p)->value(); + } + else if (PyTuple_Check(p)) { + val = Base::getVectorFromTuple(p); + } + else { + std::string error = std::string("type must be 'Vector', not "); + error += p->ob_type->tp_name; + throw Py::TypeError(error); + } + + Handle_Geom_TrimmedCurve trim = Handle_Geom_TrimmedCurve::DownCast + (getGeomArcOfEllipsePtr()->handle()); + Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast(trim->BasisCurve()); + try { + gp_Ax1 axis; + axis.SetLocation(ellipse->Location()); + axis.SetDirection(gp_Dir(val.x, val.y, val.z)); + ellipse->SetAxis(axis); + } + catch (Standard_Failure) { + throw Py::Exception("cannot set axis"); + } +} + +Py::Object ArcOfEllipse2dPy::getEllipse(void) const +{ + Handle_Geom_TrimmedCurve trim = Handle_Geom_TrimmedCurve::DownCast + (getGeomArcOfEllipsePtr()->handle()); + Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast(trim->BasisCurve()); + return Py::Object(new EllipsePy(new GeomEllipse(ellipse)), true); +} +#endif +PyObject *ArcOfEllipse2dPy::getCustomAttributes(const char* ) const +{ + return 0; +} + +int ArcOfEllipse2dPy::setCustomAttributes(const char* , PyObject *) +{ + return 0; +} diff --git a/src/Mod/Part/App/Geom2d/ArcOfHyperbola2dPy.xml b/src/Mod/Part/App/Geom2d/ArcOfHyperbola2dPy.xml new file mode 100644 index 000000000000..0ee3836cdc48 --- /dev/null +++ b/src/Mod/Part/App/Geom2d/ArcOfHyperbola2dPy.xml @@ -0,0 +1,56 @@ + + + + + + Describes a portion of an hyperbola + + + + diff --git a/src/Mod/Part/App/Geom2d/ArcOfHyperbola2dPyImp.cpp b/src/Mod/Part/App/Geom2d/ArcOfHyperbola2dPyImp.cpp new file mode 100644 index 000000000000..30ce6c3eee8f --- /dev/null +++ b/src/Mod/Part/App/Geom2d/ArcOfHyperbola2dPyImp.cpp @@ -0,0 +1,241 @@ +/*************************************************************************** + * Copyright (c) 2014 Abdullah Tahiri +# include +# include +# include +# include +#endif + +#include +#include +#include +#include +#include + +#include +#include + +using namespace Part; + +extern const char* gce_ErrorStatusText(gce_ErrorType et); + +// returns a string which represents the object e.g. when printed in python +std::string ArcOfHyperbola2dPy::representation(void) const +{ +#if 0 + Handle_Geom_TrimmedCurve trim = Handle_Geom_TrimmedCurve::DownCast + (getGeomArcOfHyperbolaPtr()->handle()); + Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(trim->BasisCurve()); + + gp_Ax1 axis = hyperbola->Axis(); + gp_Dir dir = axis.Direction(); + gp_Pnt loc = axis.Location(); + Standard_Real fMajRad = hyperbola->MajorRadius(); + Standard_Real fMinRad = hyperbola->MinorRadius(); + Standard_Real u1 = trim->FirstParameter(); + Standard_Real u2 = trim->LastParameter(); + + gp_Dir normal = hyperbola->Axis().Direction(); + gp_Dir xdir = hyperbola->XAxis().Direction(); + + gp_Ax2 xdirref(loc, normal); // this is a reference XY for the hyperbola + + Standard_Real fAngleXU = -xdir.AngleWithRef(xdirref.XDirection(),normal); + + + std::stringstream str; + str << "ArcOfHyperbola ("; + str << "MajorRadius : " << fMajRad << ", "; + str << "MinorRadius : " << fMinRad << ", "; + str << "AngleXU : " << fAngleXU << ", "; + str << "Position : (" << loc.X() << ", "<< loc.Y() << ", "<< loc.Z() << "), "; + str << "Direction : (" << dir.X() << ", "<< dir.Y() << ", "<< dir.Z() << "), "; + str << "Parameter : (" << u1 << ", " << u2 << ")"; + str << ")"; + + return str.str(); +#else + return ""; +#endif +} + +PyObject *ArcOfHyperbola2dPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper +{ + // create a new instance of ArcOfHyperbola2dPy and the Twin object + return new ArcOfHyperbola2dPy(new Geom2dArcOfHyperbola); +} + +// constructor method +int ArcOfHyperbola2dPy::PyInit(PyObject* args, PyObject* /*kwds*/) +{ +#if 1 + return 0; +#else + PyObject* o; + double u1, u2; + PyObject *sense=Py_True; + if (PyArg_ParseTuple(args, "O!dd|O!", &(Part::HyperbolaPy::Type), &o, &u1, &u2, &PyBool_Type, &sense)) { + try { + Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast + (static_cast(o)->getGeomHyperbolaPtr()->handle()); + GC_MakeArcOfHyperbola arc(hyperbola->Hypr(), u1, u2, PyObject_IsTrue(sense) ? Standard_True : Standard_False); + if (!arc.IsDone()) { + PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(arc.Status())); + return -1; + } + + getGeomArcOfHyperbolaPtr()->setHandle(arc.Value()); + return 0; + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); + return -1; + } + catch (...) { + PyErr_SetString(PartExceptionOCCError, "creation of arc failed"); + return -1; + } + } + + // All checks failed + PyErr_SetString(PyExc_TypeError, + "ArcOfHyperbola constructor expects an hyperbola curve and a parameter range"); + return -1; +#endif +} +#if 0 +Py::Float ArcOfHyperbola2dPy::getMajorRadius(void) const +{ + return Py::Float(getGeomArcOfHyperbolaPtr()->getMajorRadius()); +} + +void ArcOfHyperbola2dPy::setMajorRadius(Py::Float arg) +{ + getGeomArcOfHyperbolaPtr()->setMajorRadius((double)arg); +} + +Py::Float ArcOfHyperbola2dPy::getMinorRadius(void) const +{ + return Py::Float(getGeomArcOfHyperbolaPtr()->getMinorRadius()); +} + +void ArcOfHyperbola2dPy::setMinorRadius(Py::Float arg) +{ + getGeomArcOfHyperbolaPtr()->setMinorRadius((double)arg); +} + +Py::Float ArcOfHyperbola2dPy::getAngleXU(void) const +{ + return Py::Float(getGeomArcOfHyperbolaPtr()->getAngleXU()); +} + +void ArcOfHyperbola2dPy::setAngleXU(Py::Float arg) +{ + getGeomArcOfHyperbolaPtr()->setAngleXU((double)arg); +} + +Py::Object ArcOfHyperbola2dPy::getCenter(void) const +{ + return Py::Vector(getGeomArcOfHyperbolaPtr()->getCenter()); +} + +void ArcOfHyperbola2dPy::setCenter(Py::Object arg) +{ + PyObject* p = arg.ptr(); + if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) { + Base::Vector3d loc = static_cast(p)->value(); + getGeomArcOfHyperbolaPtr()->setCenter(loc); + } + else if (PyObject_TypeCheck(p, &PyTuple_Type)) { + Base::Vector3d loc = Base::getVectorFromTuple(p); + getGeomArcOfHyperbolaPtr()->setCenter(loc); + } + else { + std::string error = std::string("type must be 'Vector', not "); + error += p->ob_type->tp_name; + throw Py::TypeError(error); + } +} + +Py::Object ArcOfHyperbola2dPy::getAxis(void) const +{ + Handle_Geom_TrimmedCurve trim = Handle_Geom_TrimmedCurve::DownCast + (getGeomArcOfHyperbolaPtr()->handle()); + Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(trim->BasisCurve()); + gp_Ax1 axis = hyperbola->Axis(); + gp_Dir dir = axis.Direction(); + return Py::Vector(Base::Vector3d(dir.X(), dir.Y(), dir.Z())); +} + +void ArcOfHyperbola2dPy::setAxis(Py::Object arg) +{ + PyObject* p = arg.ptr(); + Base::Vector3d val; + if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) { + val = static_cast(p)->value(); + } + else if (PyTuple_Check(p)) { + val = Base::getVectorFromTuple(p); + } + else { + std::string error = std::string("type must be 'Vector', not "); + error += p->ob_type->tp_name; + throw Py::TypeError(error); + } + + Handle_Geom_TrimmedCurve trim = Handle_Geom_TrimmedCurve::DownCast + (getGeomArcOfHyperbolaPtr()->handle()); + Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(trim->BasisCurve()); + try { + gp_Ax1 axis; + axis.SetLocation(hyperbola->Location()); + axis.SetDirection(gp_Dir(val.x, val.y, val.z)); + hyperbola->SetAxis(axis); + } + catch (Standard_Failure) { + throw Py::Exception("cannot set axis"); + } +} + +Py::Object ArcOfHyperbola2dPy::getHyperbola(void) const +{ + Handle_Geom_TrimmedCurve trim = Handle_Geom_TrimmedCurve::DownCast + (getGeomArcOfHyperbolaPtr()->handle()); + Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(trim->BasisCurve()); + return Py::Object(new HyperbolaPy(new GeomHyperbola(hyperbola)), true); +} +#endif +PyObject *ArcOfHyperbola2dPy::getCustomAttributes(const char* ) const +{ + return 0; +} + +int ArcOfHyperbola2dPy::setCustomAttributes(const char* , PyObject *) +{ + return 0; +} diff --git a/src/Mod/Part/App/Geom2d/ArcOfParabola2dPy.xml b/src/Mod/Part/App/Geom2d/ArcOfParabola2dPy.xml new file mode 100644 index 000000000000..5ebc34b74340 --- /dev/null +++ b/src/Mod/Part/App/Geom2d/ArcOfParabola2dPy.xml @@ -0,0 +1,50 @@ + + + + + + Describes a portion of an parabola + + + + diff --git a/src/Mod/Part/App/Geom2d/ArcOfParabola2dPyImp.cpp b/src/Mod/Part/App/Geom2d/ArcOfParabola2dPyImp.cpp new file mode 100644 index 000000000000..be73be224c58 --- /dev/null +++ b/src/Mod/Part/App/Geom2d/ArcOfParabola2dPyImp.cpp @@ -0,0 +1,229 @@ +/*************************************************************************** + * Copyright (c) 2014 Abdullah Tahiri +# include +# include +# include +# include +#endif + +#include +#include +#include +#include +#include + +#include +#include + +using namespace Part; + +extern const char* gce_ErrorStatusText(gce_ErrorType et); + +// returns a string which represents the object e.g. when printed in python +std::string ArcOfParabola2dPy::representation(void) const +{ +#if 0 + Handle_Geom_TrimmedCurve trim = Handle_Geom_TrimmedCurve::DownCast + (getGeomArcOfParabolaPtr()->handle()); + Handle_Geom_Parabola parabola = Handle_Geom_Parabola::DownCast(trim->BasisCurve()); + + gp_Ax1 axis = parabola->Axis(); + gp_Dir dir = axis.Direction(); + gp_Pnt loc = axis.Location(); + Standard_Real fFocal = parabola->Focal(); + Standard_Real u1 = trim->FirstParameter(); + Standard_Real u2 = trim->LastParameter(); + + gp_Dir normal = parabola->Axis().Direction(); + gp_Dir xdir = parabola->XAxis().Direction(); + + gp_Ax2 xdirref(loc, normal); // this is a reference XY for the parabola + + Standard_Real fAngleXU = -xdir.AngleWithRef(xdirref.XDirection(),normal); + + + std::stringstream str; + str << "ArcOfParabola ("; + str << "Focal : " << fFocal << ", "; + str << "AngleXU : " << fAngleXU << ", "; + str << "Position : (" << loc.X() << ", "<< loc.Y() << ", "<< loc.Z() << "), "; + str << "Direction : (" << dir.X() << ", "<< dir.Y() << ", "<< dir.Z() << "), "; + str << "Parameter : (" << u1 << ", " << u2 << ")"; + str << ")"; + + return str.str(); +#else + return ""; +#endif +} + +PyObject *ArcOfParabola2dPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper +{ + // create a new instance of ArcOfParabola2dPy and the Twin object + return new ArcOfParabola2dPy(new Geom2dArcOfParabola); +} + +// constructor method +int ArcOfParabola2dPy::PyInit(PyObject* args, PyObject* /*kwds*/) +{ +#if 1 + return 0; +#else + PyObject* o; + double u1, u2; + PyObject *sense=Py_True; + if (PyArg_ParseTuple(args, "O!dd|O!", &(Part::ParabolaPy::Type), &o, &u1, &u2, &PyBool_Type, &sense)) { + try { + Handle_Geom_Parabola parabola = Handle_Geom_Parabola::DownCast + (static_cast(o)->getGeomParabolaPtr()->handle()); + GC_MakeArcOfParabola arc(parabola->Parab(), u1, u2, PyObject_IsTrue(sense) ? Standard_True : Standard_False); + if (!arc.IsDone()) { + PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(arc.Status())); + return -1; + } + + getGeomArcOfParabolaPtr()->setHandle(arc.Value()); + return 0; + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); + return -1; + } + catch (...) { + PyErr_SetString(PartExceptionOCCError, "creation of arc failed"); + return -1; + } + } + + // All checks failed + PyErr_SetString(PyExc_TypeError, + "ArcOfParabola constructor expects an parabola curve and a parameter range"); + return -1; +#endif +} +#if 0 +Py::Float ArcOfParabola2dPy::getFocal(void) const +{ + return Py::Float(getGeomArcOfParabolaPtr()->getFocal()); +} + +void ArcOfParabola2dPy::setFocal(Py::Float arg) +{ + getGeomArcOfParabolaPtr()->setFocal((double)arg); +} + +Py::Float ArcOfParabola2dPy::getAngleXU(void) const +{ + return Py::Float(getGeomArcOfParabolaPtr()->getAngleXU()); +} + +void ArcOfParabola2dPy::setAngleXU(Py::Float arg) +{ + getGeomArcOfParabolaPtr()->setAngleXU((double)arg); +} + +Py::Object ArcOfParabola2dPy::getCenter(void) const +{ + return Py::Vector(getGeomArcOfParabolaPtr()->getCenter()); +} + +void ArcOfParabola2dPy::setCenter(Py::Object arg) +{ + PyObject* p = arg.ptr(); + if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) { + Base::Vector3d loc = static_cast(p)->value(); + getGeomArcOfParabolaPtr()->setCenter(loc); + } + else if (PyObject_TypeCheck(p, &PyTuple_Type)) { + Base::Vector3d loc = Base::getVectorFromTuple(p); + getGeomArcOfParabolaPtr()->setCenter(loc); + } + else { + std::string error = std::string("type must be 'Vector', not "); + error += p->ob_type->tp_name; + throw Py::TypeError(error); + } +} + +Py::Object ArcOfParabola2dPy::getAxis(void) const +{ + Handle_Geom_TrimmedCurve trim = Handle_Geom_TrimmedCurve::DownCast + (getGeomArcOfParabolaPtr()->handle()); + Handle_Geom_Parabola parabola = Handle_Geom_Parabola::DownCast(trim->BasisCurve()); + gp_Ax1 axis = parabola->Axis(); + gp_Dir dir = axis.Direction(); + return Py::Vector(Base::Vector3d(dir.X(), dir.Y(), dir.Z())); +} + +void ArcOfParabola2dPy::setAxis(Py::Object arg) +{ + PyObject* p = arg.ptr(); + Base::Vector3d val; + if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) { + val = static_cast(p)->value(); + } + else if (PyTuple_Check(p)) { + val = Base::getVectorFromTuple(p); + } + else { + std::string error = std::string("type must be 'Vector', not "); + error += p->ob_type->tp_name; + throw Py::TypeError(error); + } + + Handle_Geom_TrimmedCurve trim = Handle_Geom_TrimmedCurve::DownCast + (getGeomArcOfParabolaPtr()->handle()); + Handle_Geom_Parabola parabola = Handle_Geom_Parabola::DownCast(trim->BasisCurve()); + try { + gp_Ax1 axis; + axis.SetLocation(parabola->Location()); + axis.SetDirection(gp_Dir(val.x, val.y, val.z)); + parabola->SetAxis(axis); + } + catch (Standard_Failure) { + throw Py::Exception("cannot set axis"); + } +} + +Py::Object ArcOfParabola2dPy::getParabola(void) const +{ + Handle_Geom_TrimmedCurve trim = Handle_Geom_TrimmedCurve::DownCast + (getGeomArcOfParabolaPtr()->handle()); + Handle_Geom_Parabola parabola = Handle_Geom_Parabola::DownCast(trim->BasisCurve()); + return Py::Object(new ParabolaPy(new GeomParabola(parabola)), true); +} +#endif +PyObject *ArcOfParabola2dPy::getCustomAttributes(const char* ) const +{ + return 0; +} + +int ArcOfParabola2dPy::setCustomAttributes(const char* , PyObject *) +{ + return 0; +} diff --git a/src/Mod/Part/App/Geom2d/BSplineCurve2dPy.xml b/src/Mod/Part/App/Geom2d/BSplineCurve2dPy.xml new file mode 100644 index 000000000000..33f563b46371 --- /dev/null +++ b/src/Mod/Part/App/Geom2d/BSplineCurve2dPy.xml @@ -0,0 +1,445 @@ + + + + + + Describes a B-Spline curve in 3D space + + + + diff --git a/src/Mod/Part/App/Geom2d/BSplineCurve2dPyImp.cpp b/src/Mod/Part/App/Geom2d/BSplineCurve2dPyImp.cpp new file mode 100644 index 000000000000..477d4c63685f --- /dev/null +++ b/src/Mod/Part/App/Geom2d/BSplineCurve2dPyImp.cpp @@ -0,0 +1,1319 @@ +/*************************************************************************** + * Copyright (c) 2008 Werner Mayer * + * * + * 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 * + * * + ***************************************************************************/ + + +#include "PreCompiled.h" +#ifndef _PreComp_ +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include + +# include +#endif + +#include +#include + +#include +#include +#include +#include +#include + +using namespace Part; + +// returns a string which represents the object e.g. when printed in python +std::string BSplineCurve2dPy::representation(void) const +{ + return ""; +} + +PyObject *BSplineCurve2dPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper +{ + // create a new instance of BSplineCurve2dPy and the Twin object + return new BSplineCurve2dPy(new Geom2dBSplineCurve); +} + +// constructor method +int BSplineCurve2dPy::PyInit(PyObject* args, PyObject* /*kwd*/) +{ + if (PyArg_ParseTuple(args, "")) { + return 0; + } + + PyErr_SetString(PyExc_TypeError, "B-Spline constructor accepts:\n" + "-- empty parameter list\n"); + return -1; +} +#if 0 +PyObject* BSplineCurve2dPy::isRational(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) + return 0; + Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast + (getGeometryPtr()->handle()); + Standard_Boolean val = curve->IsRational(); + return PyBool_FromLong(val ? 1 : 0); +} + +PyObject* BSplineCurve2dPy::isPeriodic(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) + return 0; + Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast + (getGeometryPtr()->handle()); + Standard_Boolean val = curve->IsPeriodic(); + return PyBool_FromLong(val ? 1 : 0); +} + +PyObject* BSplineCurve2dPy::isClosed(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) + return 0; + Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast + (getGeometryPtr()->handle()); + Standard_Boolean val = curve->IsClosed(); + return PyBool_FromLong(val ? 1 : 0); +} + +PyObject* BSplineCurve2dPy::increaseDegree(PyObject * args) +{ + int degree; + if (!PyArg_ParseTuple(args, "i", °ree)) + return 0; + PY_TRY { + Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast + (getGeometryPtr()->handle()); + curve->IncreaseDegree(degree); + Py_Return; + } PY_CATCH_OCC ; +} + +PyObject* BSplineCurve2dPy::increaseMultiplicity(PyObject * args) +{ + int mult=-1; + int start, end; + if (!PyArg_ParseTuple(args, "ii|i", &start, &end, &mult)) + return 0; + + Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast + (getGeometryPtr()->handle()); + if (mult == -1) { + mult = end; + curve->IncreaseMultiplicity(start, mult); + } + else { + curve->IncreaseMultiplicity(start, end, mult); + } + + Py_Return; +} + +PyObject* BSplineCurve2dPy::incrementMultiplicity(PyObject * args) +{ + int start, end, mult; + if (!PyArg_ParseTuple(args, "iii", &start, &end, &mult)) + return 0; + + try { + Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast + (getGeometryPtr()->handle()); + curve->IncrementMultiplicity(start, end, mult); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); + return 0; + } + + Py_Return; +} + +PyObject* BSplineCurve2dPy::insertKnot(PyObject * args) +{ + double U, tol = 0.0; + int M=1; + PyObject* add = Py_True; + if (!PyArg_ParseTuple(args, "d|idO!", &U, &M, &tol, &PyBool_Type, &add)) + return 0; + + try { + Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast + (getGeometryPtr()->handle()); + curve->InsertKnot(U,M,tol,PyObject_IsTrue(add) ? Standard_True : Standard_False); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); + return 0; + } + + Py_Return; +} + +PyObject* BSplineCurve2dPy::insertKnots(PyObject * args) +{ + double tol = 0.0; + PyObject* add = Py_True; + PyObject* obj1; + PyObject* obj2; + if (!PyArg_ParseTuple(args, "OO|dO!", &obj1, + &obj2, + &tol, &PyBool_Type, &add)) + return 0; + + try { + Py::Sequence knots(obj1); + TColStd_Array1OfReal k(1,knots.size()); + int index=1; + for (Py::Sequence::iterator it = knots.begin(); it != knots.end(); ++it) { + Py::Float val(*it); + k(index++) = (double)val; + } + Py::Sequence mults(obj2); + TColStd_Array1OfInteger m(1,mults.size()); + index=1; + for (Py::Sequence::iterator it = mults.begin(); it != mults.end(); ++it) { + Py::Int val(*it); + m(index++) = (int)val; + } + + Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast + (getGeometryPtr()->handle()); + curve->InsertKnots(k,m,tol,PyObject_IsTrue(add) ? Standard_True : Standard_False); + Py_Return; + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); + return 0; + } + + Py_Return; +} + +PyObject* BSplineCurve2dPy::removeKnot(PyObject * args) +{ + double tol; + int Index,M; + if (!PyArg_ParseTuple(args, "iid", &Index, &M, &tol)) + return 0; + + try { + Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast + (getGeometryPtr()->handle()); + Standard_Boolean ok = curve->RemoveKnot(Index,M,tol); + return PyBool_FromLong(ok ? 1 : 0); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); + return 0; + } +} + +PyObject* BSplineCurve2dPy::segment(PyObject * args) +{ + double u1,u2; + if (!PyArg_ParseTuple(args, "dd", &u1,&u2)) + return 0; + try { + Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast + (getGeometryPtr()->handle()); + curve->Segment(u1,u2); + Py_Return; + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); + return 0; + } +} + +PyObject* BSplineCurve2dPy::setKnot(PyObject * args) +{ + int Index, M=-1; + double K; + if (!PyArg_ParseTuple(args, "id|i", &Index, &K, &M)) + return 0; + + Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast + (getGeometryPtr()->handle()); + if (M == -1) { + curve->SetKnot(Index, K); + } + else { + curve->SetKnot(Index, K, M); + } + + Py_Return; +} + +PyObject* BSplineCurve2dPy::getKnot(PyObject * args) +{ + int Index; + if (!PyArg_ParseTuple(args, "i", &Index)) + return 0; + + Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast + (getGeometryPtr()->handle()); + double M = curve->Knot(Index); + + return Py_BuildValue("d",M); +} + +PyObject* BSplineCurve2dPy::setKnots(PyObject * args) +{ + PyObject* obj; + if (!PyArg_ParseTuple(args, "O", &obj)) + return 0; + try { + Py::Sequence list(obj); + TColStd_Array1OfReal k(1,list.size()); + int index=1; + for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) { + Py::Float val(*it); + k(index++) = (double)val; + } + + Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast + (getGeometryPtr()->handle()); + curve->SetKnots(k); + Py_Return; + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); + return 0; + } +} + +PyObject* BSplineCurve2dPy::getKnots(PyObject * args) +{ + if (!PyArg_ParseTuple(args, "")) + return 0; + try { + Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast + (getGeometryPtr()->handle()); + TColStd_Array1OfReal w(1,curve->NbKnots()); + curve->Knots(w); + Py::List knots; + for (Standard_Integer i=w.Lower(); i<=w.Upper(); i++) { + knots.append(Py::Float(w(i))); + } + return Py::new_reference_to(knots); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); + return 0; + } +} + +PyObject* BSplineCurve2dPy::setPole(PyObject * args) +{ + int index; + double weight=-1.0; + PyObject* p; + if (!PyArg_ParseTuple(args, "iO!|d", &index, &(Base::VectorPy::Type), &p, &weight)) + return 0; + Base::Vector3d vec = static_cast(p)->value(); + gp_Pnt pnt(vec.x, vec.y, vec.z); + try { + Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast + (getGeometryPtr()->handle()); + if (weight < 0.0) + curve->SetPole(index,pnt); + else + curve->SetPole(index,pnt,weight); + Py_Return; + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); + return 0; + } +} + +PyObject* BSplineCurve2dPy::getPole(PyObject * args) +{ + int index; + if (!PyArg_ParseTuple(args, "i", &index)) + return 0; + try { + Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast + (getGeometryPtr()->handle()); + Standard_OutOfRange_Raise_if + (index < 1 || index > curve->NbPoles(), "Pole index out of range"); + gp_Pnt pnt = curve->Pole(index); + Base::VectorPy* vec = new Base::VectorPy(Base::Vector3d( + pnt.X(), pnt.Y(), pnt.Z())); + return vec; + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); + return 0; + } +} + +PyObject* BSplineCurve2dPy::getPoles(PyObject * args) +{ + if (!PyArg_ParseTuple(args, "")) + return 0; + try { + Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast + (getGeometryPtr()->handle()); + TColgp_Array1OfPnt p(1,curve->NbPoles()); + curve->Poles(p); + Py::List poles; + for (Standard_Integer i=p.Lower(); i<=p.Upper(); i++) { + gp_Pnt pnt = p(i); + Base::VectorPy* vec = new Base::VectorPy(Base::Vector3d( + pnt.X(), pnt.Y(), pnt.Z())); + poles.append(Py::Object(vec)); + } + return Py::new_reference_to(poles); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); + return 0; + } +} + +PyObject* BSplineCurve2dPy::getPolesAndWeights(PyObject * args) +{ + if (!PyArg_ParseTuple(args, "")) + return 0; + try { + Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast + (getGeometryPtr()->handle()); + TColgp_Array1OfPnt p(1,curve->NbPoles()); + curve->Poles(p); + TColStd_Array1OfReal w(1,curve->NbPoles()); + curve->Weights(w); + + Py::List poles; + for (Standard_Integer i=p.Lower(); i<=p.Upper(); i++) { + gp_Pnt pnt = p(i); + double weight = w(i); + Py::Tuple t(4); + t.setItem(0, Py::Float(pnt.X())); + t.setItem(1, Py::Float(pnt.Y())); + t.setItem(2, Py::Float(pnt.Z())); + t.setItem(3, Py::Float(weight)); + poles.append(t); + } + return Py::new_reference_to(poles); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); + return 0; + } +} + +PyObject* BSplineCurve2dPy::setWeight(PyObject * args) +{ + int index; + double weight; + if (!PyArg_ParseTuple(args, "id", &index,&weight)) + return 0; + try { + Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast + (getGeometryPtr()->handle()); + curve->SetWeight(index,weight); + Py_Return; + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); + return 0; + } +} + +PyObject* BSplineCurve2dPy::getWeight(PyObject * args) +{ + int index; + if (!PyArg_ParseTuple(args, "i", &index)) + return 0; + try { + Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast + (getGeometryPtr()->handle()); + Standard_OutOfRange_Raise_if + (index < 1 || index > curve->NbPoles() , "Weight index out of range"); + double weight = curve->Weight(index); + return Py_BuildValue("d", weight); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); + return 0; + } +} + +PyObject* BSplineCurve2dPy::getWeights(PyObject * args) +{ + if (!PyArg_ParseTuple(args, "")) + return 0; + try { + Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast + (getGeometryPtr()->handle()); + TColStd_Array1OfReal w(1,curve->NbPoles()); + curve->Weights(w); + Py::List weights; + for (Standard_Integer i=w.Lower(); i<=w.Upper(); i++) { + weights.append(Py::Float(w(i))); + } + return Py::new_reference_to(weights); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); + return 0; + } +} + +PyObject* BSplineCurve2dPy::getResolution(PyObject * args) +{ + double tol; + if (!PyArg_ParseTuple(args, "d", &tol)) + return 0; + try { + Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast + (getGeometryPtr()->handle()); + double utol; + curve->Resolution(tol,utol); + return Py_BuildValue("d",utol); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); + return 0; + } +} + +PyObject* BSplineCurve2dPy::movePoint(PyObject * args) +{ + double U; + int index1, index2; + PyObject* pnt; + if (!PyArg_ParseTuple(args, "dO!ii", &U, &(Base::VectorPy::Type),&pnt, &index1, &index2)) + return 0; + try { + Base::Vector3d p = static_cast(pnt)->value(); + Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast + (getGeometryPtr()->handle()); + int first, last; + curve->MovePoint(U, gp_Pnt(p.x,p.y,p.z), index1, index2, first, last); + return Py_BuildValue("(ii)",first, last); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); + return 0; + } +} + +PyObject* BSplineCurve2dPy::setNotPeriodic(PyObject * args) +{ + if (!PyArg_ParseTuple(args, "")) + return 0; + try { + Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast + (getGeometryPtr()->handle()); + curve->SetNotPeriodic(); + Py_Return; + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); + return 0; + } +} + +PyObject* BSplineCurve2dPy::setPeriodic(PyObject * args) +{ + if (!PyArg_ParseTuple(args, "")) + return 0; + try { + Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast + (getGeometryPtr()->handle()); + curve->SetPeriodic(); + Py_Return; + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); + return 0; + } +} + +PyObject* BSplineCurve2dPy::setOrigin(PyObject * args) +{ + int index; + if (!PyArg_ParseTuple(args, "i", &index)) + return 0; + try { + Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast + (getGeometryPtr()->handle()); + curve->SetOrigin(index); + Py_Return; + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); + return 0; + } +} + +PyObject* BSplineCurve2dPy::getMultiplicity(PyObject * args) +{ + int index; + if (!PyArg_ParseTuple(args, "i", &index)) + return 0; + try { + Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast + (getGeometryPtr()->handle()); + int mult = curve->Multiplicity(index); + return Py_BuildValue("i", mult); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); + return 0; + } +} + +PyObject* BSplineCurve2dPy::getMultiplicities(PyObject * args) +{ + if (!PyArg_ParseTuple(args, "")) + return 0; + try { + Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast + (getGeometryPtr()->handle()); + TColStd_Array1OfInteger m(1,curve->NbKnots()); + curve->Multiplicities(m); + Py::List mults; + for (Standard_Integer i=m.Lower(); i<=m.Upper(); i++) { + mults.append(Py::Int(m(i))); + } + return Py::new_reference_to(mults); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); + return 0; + } +} + +Py::Int BSplineCurve2dPy::getDegree(void) const +{ + Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast + (getGeometryPtr()->handle()); + return Py::Int(curve->Degree()); +} + +Py::Int BSplineCurve2dPy::getMaxDegree(void) const +{ + Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast + (getGeometryPtr()->handle()); + return Py::Int(curve->MaxDegree()); +} + +Py::Int BSplineCurve2dPy::getNbPoles(void) const +{ + Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast + (getGeometryPtr()->handle()); + return Py::Int(curve->NbPoles()); +} + +Py::Int BSplineCurve2dPy::getNbKnots(void) const +{ + Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast + (getGeometryPtr()->handle()); + return Py::Int(curve->NbKnots()); +} + +Py::Object BSplineCurve2dPy::getStartPoint(void) const +{ + Handle_Geom_BSplineCurve c = Handle_Geom_BSplineCurve::DownCast + (getGeometryPtr()->handle()); + gp_Pnt pnt = c->StartPoint(); + return Py::Vector(Base::Vector3d(pnt.X(), pnt.Y(), pnt.Z())); +} + +Py::Object BSplineCurve2dPy::getEndPoint(void) const +{ + Handle_Geom_BSplineCurve c = Handle_Geom_BSplineCurve::DownCast + (getGeometryPtr()->handle()); + gp_Pnt pnt = c->EndPoint(); + return Py::Vector(Base::Vector3d(pnt.X(), pnt.Y(), pnt.Z())); +} + +Py::Object BSplineCurve2dPy::getFirstUKnotIndex(void) const +{ + Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast + (getGeometryPtr()->handle()); + return Py::Int(curve->FirstUKnotIndex()); +} + +Py::Object BSplineCurve2dPy::getLastUKnotIndex(void) const +{ + Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast + (getGeometryPtr()->handle()); + return Py::Int(curve->LastUKnotIndex()); +} + +Py::List BSplineCurve2dPy::getKnotSequence(void) const +{ + Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast + (getGeometryPtr()->handle()); + Standard_Integer m = 0; + if (curve->IsPeriodic()) { + // knots=poles+2*degree-mult(1)+2 + m = curve->NbPoles() + 2*curve->Degree() - curve->Multiplicity(1) + 2; + } + else { + // knots=poles+degree+1 + for (int i=1; i<= curve->NbKnots(); i++) + m += curve->Multiplicity(i); + } + + TColStd_Array1OfReal k(1,m); + curve->KnotSequence(k); + Py::List list; + for (Standard_Integer i=k.Lower(); i<=k.Upper(); i++) { + list.append(Py::Float(k(i))); + } + return list; +} + +PyObject* BSplineCurve2dPy::toBiArcs(PyObject * args) +{ + double tolerance = 0.001; + if (!PyArg_ParseTuple(args, "d", &tolerance)) + return 0; + try { + GeomBSplineCurve* curve = getGeomBSplineCurvePtr(); + std::list arcs; + arcs = curve->toBiArcs(tolerance); + + Py::List list; + for (std::list::iterator it = arcs.begin(); it != arcs.end(); ++it) { + list.append(Py::asObject((*it)->getPyObject())); + delete (*it); + } + + return Py::new_reference_to(list); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); + return 0; + } +} + +PyObject* BSplineCurve2dPy::approximate(PyObject *args, PyObject *kwds) +{ + PyObject* obj; + Standard_Integer degMin=3; + Standard_Integer degMax=8; + char* continuity = "C2"; + double tol3d = 1e-3; + char* parType = "ChordLength"; + PyObject* par = 0; + double weight1 = 0; + double weight2 = 0; + double weight3 = 0; + + static char* kwds_interp[] = {"Points", "DegMax", "Continuity", "Tolerance", "DegMin", "ParamType", "Parameters", + "LengthWeight", "CurvatureWeight", "TorsionWeight", NULL}; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|isdisOddd",kwds_interp, + &obj, °Max, + &continuity, &tol3d, °Min, + &parType, &par, + &weight1, &weight2, &weight3)) + return 0; + + try { + Py::Sequence list(obj); + TColgp_Array1OfPnt pnts(1,list.size()); + Standard_Integer index = 1; + for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) { + Base::Vector3d vec = Py::Vector(*it).toVector(); + pnts(index++) = gp_Pnt(vec.x,vec.y,vec.z); + } + + if (degMin > degMax) { + Standard_Failure::Raise("DegMin must be lower or equal to DegMax"); + } + + GeomAbs_Shape c; + std::string str = continuity; + if (str == "C0") + c = GeomAbs_C0; + else if (str == "G1") + c = GeomAbs_G1; + else if (str == "C1") + c = GeomAbs_C1; + else if (str == "G2") + c = GeomAbs_G2; + else if (str == "C2") + c = GeomAbs_C2; + else if (str == "C3") + c = GeomAbs_C3; + else if (str == "CN") + c = GeomAbs_CN; + else + c = GeomAbs_C2; + + if (weight1 || weight2 || weight3) { + // It seems that this function only works with Continuity = C0, C1 or C2 + if (!(c == GeomAbs_C0 || c == GeomAbs_C1 || c == GeomAbs_C2)) { + c = GeomAbs_C2; + } + GeomAPI_PointsToBSpline fit(pnts, weight1, weight2, weight3, degMax, c, tol3d); + Handle_Geom_BSplineCurve spline = fit.Curve(); + if (!spline.IsNull()) { + this->getGeomBSplineCurvePtr()->setHandle(spline); + Py_Return; + } + else { + Standard_Failure::Raise("Smoothing approximation failed"); + return 0; // goes to the catch block + } + } + + if (par) { + Py::Sequence plist(par); + TColStd_Array1OfReal parameters(1,plist.size()); + Standard_Integer index = 1; + for (Py::Sequence::iterator it = plist.begin(); it != plist.end(); ++it) { + Py::Float f(*it); + parameters(index++) = static_cast(f); + } + + GeomAPI_PointsToBSpline fit(pnts, parameters, degMin, degMax, c, tol3d); + Handle_Geom_BSplineCurve spline = fit.Curve(); + if (!spline.IsNull()) { + this->getGeomBSplineCurvePtr()->setHandle(spline); + Py_Return; + } + else { + Standard_Failure::Raise("Approximation with parameters failed"); + return 0; // goes to the catch block + } + } + + Approx_ParametrizationType pt; + std::string pstr = parType; + if (pstr == "Uniform") + pt = Approx_IsoParametric; + else if (pstr == "Centripetal") + pt = Approx_Centripetal; + else + pt = Approx_ChordLength; + + GeomAPI_PointsToBSpline fit(pnts, pt, degMin, degMax, c, tol3d); + Handle_Geom_BSplineCurve spline = fit.Curve(); + if (!spline.IsNull()) { + this->getGeomBSplineCurvePtr()->setHandle(spline); + Py_Return; + } + else { + Standard_Failure::Raise("failed to approximate points"); + return 0; // goes to the catch block + } + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); + return 0; + } +} + +PyObject* BSplineCurve2dPy::getCardinalSplineTangents(PyObject *args, PyObject *kwds) +{ + PyObject* pts; + PyObject* tgs; + double parameter; + + static char* kwds_interp1[] = {"Points", "Parameter", NULL}; + if (PyArg_ParseTupleAndKeywords(args, kwds, "Od",kwds_interp1, &pts, ¶meter)) { + Py::Sequence list(pts); + std::vector interpPoints; + interpPoints.reserve(list.size()); + for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) { + Py::Vector v(*it); + Base::Vector3d pnt = v.toVector(); + interpPoints.push_back(gp_Pnt(pnt.x,pnt.y,pnt.z)); + } + + GeomBSplineCurve* bspline = this->getGeomBSplineCurvePtr(); + std::vector tangents; + bspline->getCardinalSplineTangents(interpPoints, parameter, tangents); + + Py::List vec; + for (gp_Vec it : tangents) + vec.append(Py::Vector(Base::Vector3d(it.X(), it.Y(), it.Z()))); + return Py::new_reference_to(vec); + } + + PyErr_Clear(); + static char* kwds_interp2[] = {"Points", "Parameters", NULL}; + if (PyArg_ParseTupleAndKeywords(args, kwds, "OO",kwds_interp2, &pts, &tgs)) { + Py::Sequence list(pts); + std::vector interpPoints; + interpPoints.reserve(list.size()); + for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) { + Py::Vector v(*it); + Base::Vector3d pnt = v.toVector(); + interpPoints.push_back(gp_Pnt(pnt.x,pnt.y,pnt.z)); + } + + Py::Sequence list2(tgs); + std::vector parameters; + parameters.reserve(list2.size()); + for (Py::Sequence::iterator it = list2.begin(); it != list2.end(); ++it) { + Py::Float p(*it); + parameters.push_back(static_cast(p)); + } + + GeomBSplineCurve* bspline = this->getGeomBSplineCurvePtr(); + std::vector tangents; + bspline->getCardinalSplineTangents(interpPoints, parameters, tangents); + + Py::List vec; + for (gp_Vec it : tangents) + vec.append(Py::Vector(Base::Vector3d(it.X(), it.Y(), it.Z()))); + return Py::new_reference_to(vec); + } + + return 0; +} + +PyObject* BSplineCurve2dPy::interpolate(PyObject *args, PyObject *kwds) +{ + PyObject* obj; + PyObject* par = 0; + double tol3d = Precision::Approximation(); + PyObject* periodic = Py_False; + PyObject* t1 = 0; PyObject* t2 = 0; + PyObject* ts = 0; PyObject* fl = 0; + PyObject* scale = Py_True; + + static char* kwds_interp[] = {"Points", "PeriodicFlag", "Tolerance", "InitialTangent", "FinalTangent", + "Tangents", "TangentFlags", "Parameters", "Scale", NULL}; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O!dO!O!OOOO!",kwds_interp, + &obj, &PyBool_Type, &periodic, &tol3d, + &Base::VectorPy::Type, &t1, + &Base::VectorPy::Type, &t2, + &ts, &fl, &par, &PyBool_Type, &scale)) + return 0; + + try { + Py::Sequence list(obj); + Handle_TColgp_HArray1OfPnt interpolationPoints = new TColgp_HArray1OfPnt(1, list.size()); + Standard_Integer index = 1; + for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) { + Py::Vector v(*it); + Base::Vector3d pnt = v.toVector(); + interpolationPoints->SetValue(index++, gp_Pnt(pnt.x,pnt.y,pnt.z)); + } + + if (interpolationPoints->Length() < 2) { + Standard_Failure::Raise("not enough points given"); + } + + Handle_TColStd_HArray1OfReal parameters; + if (par) { + Py::Sequence plist(par); + parameters = new TColStd_HArray1OfReal(1, plist.size()); + Standard_Integer pindex = 1; + for (Py::Sequence::iterator it = plist.begin(); it != plist.end(); ++it) { + Py::Float f(*it); + parameters->SetValue(pindex++, static_cast(f)); + } + } + + std::unique_ptr aBSplineInterpolation; + if (parameters.IsNull()) { + aBSplineInterpolation.reset(new GeomAPI_Interpolate(interpolationPoints, + PyObject_IsTrue(periodic) ? Standard_True : Standard_False, tol3d)); + } + else { + aBSplineInterpolation.reset(new GeomAPI_Interpolate(interpolationPoints, parameters, + PyObject_IsTrue(periodic) ? Standard_True : Standard_False, tol3d)); + } + + if (t1 && t2) { + Base::Vector3d v1 = Py::Vector(t1,false).toVector(); + Base::Vector3d v2 = Py::Vector(t2,false).toVector(); + gp_Vec initTangent(v1.x,v1.y,v1.z), finalTangent(v2.x,v2.y,v2.z); + aBSplineInterpolation->Load(initTangent, finalTangent, PyObject_IsTrue(scale) + ? Standard_True : Standard_False); + } + else if (ts && fl) { + Py::Sequence tlist(ts); + TColgp_Array1OfVec tangents(1, tlist.size()); + Standard_Integer index = 1; + for (Py::Sequence::iterator it = tlist.begin(); it != tlist.end(); ++it) { + Py::Vector v(*it); + Base::Vector3d vec = v.toVector(); + tangents.SetValue(index++, gp_Vec(vec.x,vec.y,vec.z)); + } + + Py::Sequence flist(fl); + Handle_TColStd_HArray1OfBoolean tangentFlags = new TColStd_HArray1OfBoolean(1, flist.size()); + Standard_Integer findex = 1; + for (Py::Sequence::iterator it = flist.begin(); it != flist.end(); ++it) { + Py::Boolean flag(*it); + tangentFlags->SetValue(findex++, static_cast(flag) ? Standard_True : Standard_False); + } + + aBSplineInterpolation->Load(tangents, tangentFlags, PyObject_IsTrue(scale) + ? Standard_True : Standard_False); + } + + aBSplineInterpolation->Perform(); + if (aBSplineInterpolation->IsDone()) { + Handle_Geom_BSplineCurve aBSplineCurve(aBSplineInterpolation->Curve()); + this->getGeomBSplineCurvePtr()->setHandle(aBSplineCurve); + Py_Return; + } + else { + Standard_Failure::Raise("failed to interpolate points"); + return 0; // goes to the catch block + } + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + std::string err = e->GetMessageString(); + if (err.empty()) err = e->DynamicType()->Name(); + PyErr_SetString(PartExceptionOCCError, err.c_str()); + return 0; + } +} + +PyObject* BSplineCurve2dPy::buildFromPoles(PyObject *args) +{ + PyObject* obj; + int degree = 3; + PyObject* periodic = Py_False; + PyObject* interpolate = Py_False; + if (!PyArg_ParseTuple(args, "O|O!iO!",&obj, &PyBool_Type, &periodic, °ree, &PyBool_Type, interpolate)) + return 0; + try { + Py::Sequence list(obj); + TColgp_Array1OfPnt poles(1, list.size()); + Standard_Integer index = 1; + for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) { + Py::Vector v(*it); + Base::Vector3d pnt = v.toVector(); + poles(index++) = gp_Pnt(pnt.x,pnt.y,pnt.z); + } + + if (poles.Length() <= degree) + degree = poles.Length()-1; + + if (PyObject_IsTrue(periodic)) { + int mult; + int len; + if (PyObject_IsTrue(interpolate)) { + mult = degree; + len = poles.Length() - mult + 2; + } + else { + mult = 1; + len = poles.Length() + 1; + } + TColStd_Array1OfReal knots(1, len); + TColStd_Array1OfInteger mults(1, len); + for (int i=1; i<=knots.Length(); i++){ + knots.SetValue(i,(double)(i-1)/(knots.Length()-1)); + mults.SetValue(i,1); + } + mults.SetValue(1, mult); + mults.SetValue(knots.Length(), mult); + + Handle_Geom_BSplineCurve spline = new Geom_BSplineCurve(poles, knots, mults, degree, Standard_True); + if (!spline.IsNull()) { + this->getGeomBSplineCurvePtr()->setHandle(spline); + Py_Return; + } + else { + Standard_Failure::Raise("failed to create spline"); + return 0; // goes to the catch block + } + } + else { + TColStd_Array1OfReal knots(1, poles.Length()+degree+1-2*(degree)); + TColStd_Array1OfInteger mults(1, poles.Length()+degree+1-2*(degree)); + for (int i=1; i<=knots.Length(); i++){ + knots.SetValue(i,(double)(i-1)/(knots.Length()-1)); + mults.SetValue(i,1); + } + mults.SetValue(1, degree+1); + mults.SetValue(knots.Length(), degree+1); + + Handle_Geom_BSplineCurve spline = new Geom_BSplineCurve(poles, knots, mults, degree, Standard_False); + if (!spline.IsNull()) { + this->getGeomBSplineCurvePtr()->setHandle(spline); + Py_Return; + } + else { + Standard_Failure::Raise("failed to create spline"); + return 0; // goes to the catch block + } + } + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); + return 0; + } +} + +PyObject* BSplineCurve2dPy::buildFromPolesMultsKnots(PyObject *args, PyObject *keywds) +{ + static char *kwlist[] = {"poles", "mults", "knots", "periodic", "degree", "weights", "CheckRational", NULL}; + PyObject* periodic = Py_False; + PyObject* CheckRational = Py_True; + PyObject* poles = Py_None; + PyObject* mults = Py_None; + PyObject* knots = Py_None; + PyObject* weights = Py_None; + int degree = 3; + int number_of_poles = 0; + int number_of_knots = 0; + int sum_of_mults = 0; + if (!PyArg_ParseTupleAndKeywords(args, keywds, "O|OOO!iOO!", kwlist, + &poles, &mults, &knots, + &PyBool_Type, &periodic, + °ree, &weights, + &PyBool_Type, &CheckRational)) + return 0; + try { + // poles have to be present + Py::Sequence list(poles); + + number_of_poles = list.size(); + if ((number_of_poles) < 2) { + Standard_Failure::Raise("need two or more poles"); + return 0; + } + TColgp_Array1OfPnt occpoles(1, number_of_poles); + Standard_Integer index = 1; + for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) { + Py::Vector v(*it); + Base::Vector3d pnt = v.toVector(); + occpoles(index++) = gp_Pnt(pnt.x,pnt.y,pnt.z); + } + //Calculate the number of knots + if (mults != Py_None && knots != Py_None) { + number_of_knots = PyObject_Length(mults); + if (PyObject_Length(knots) != number_of_knots) { + Standard_Failure::Raise("number of knots and mults mismatch"); + return 0; + } + } + else { + if (mults != Py_None) { + number_of_knots = PyObject_Length(mults); + } + else { + if (knots != Py_None) { number_of_knots = PyObject_Length(knots); } + else { //guess number of knots + if (PyObject_IsTrue(periodic)) { + if (number_of_poles < degree) {degree = number_of_poles+1;} + number_of_knots = number_of_poles+1; + } + else { + if (number_of_poles <= degree) {degree = number_of_poles-1;} + number_of_knots = number_of_poles-degree+1; + } + } + } + } + TColStd_Array1OfInteger occmults(1,number_of_knots); + TColStd_Array1OfReal occknots(1,number_of_knots); + TColStd_Array1OfReal occweights(1,number_of_poles); + if (mults != Py_None) { //mults are given + Py::Sequence multssq(mults); + Standard_Integer index = 1; + for (Py::Sequence::iterator it = multssq.begin(); it != multssq.end() && index <= occmults.Length(); ++it) { + Py::Int mult(*it); + if (index < occmults.Length() || PyObject_Not(periodic)) { + sum_of_mults += mult; //sum up the mults to compare them against the number of poles later + } + occmults(index++) = mult; + } + } + else { //mults are 1 or degree+1 at the ends + for (int i=1; i<=occmults.Length(); i++){ + occmults.SetValue(i,1); + } + if (PyObject_Not(periodic) && occmults.Length() > 0) { + occmults.SetValue(1, degree+1); + occmults.SetValue(occmults.Length(), degree+1); + sum_of_mults = occmults.Length()+2*degree; + } + else { sum_of_mults = occmults.Length()-1;} + } + if (knots != Py_None) { //knots are given + Py::Sequence knotssq(knots); + index = 1; + for (Py::Sequence::iterator it = knotssq.begin(); it != knotssq.end() && index <= occknots.Length(); ++it) { + Py::Float knot(*it); + occknots(index++) = knot; + } + } + else { // knotes are uniformly spaced 0..1 if not given + for (int i=1; i<=occknots.Length(); i++){ + occknots.SetValue(i,(double)(i-1)/(occknots.Length()-1)); + } + } + if (weights != Py_None) { //weights are given + if (PyObject_Length(weights) != number_of_poles) { + Standard_Failure::Raise("number of poles and weights mismatch"); + return 0; + } //complain about mismatch + Py::Sequence weightssq(weights); + Standard_Integer index = 1; + for (Py::Sequence::iterator it = weightssq.begin(); it != weightssq.end(); ++it) { + Py::Float weight(*it); + occweights(index++) = weight; + } + } + else { // weights are 1.0 + for (int i=1; i<=occweights.Length(); i++){ + occweights.SetValue(i,1.0); + } + } + // check if the numer of poles matches the sum of mults + if ((PyObject_IsTrue(periodic) && sum_of_mults != number_of_poles) || + (PyObject_Not(periodic) && sum_of_mults - degree -1 != number_of_poles)) { + Standard_Failure::Raise("number of poles and sum of mults mismatch"); + return(0); + } + + Handle_Geom_BSplineCurve spline = new Geom_BSplineCurve(occpoles,occweights,occknots,occmults,degree, + PyObject_IsTrue(periodic) ? Standard_True : Standard_False, + PyObject_IsTrue(CheckRational) ? Standard_True : Standard_False); + if (!spline.IsNull()) { + this->getGeomBSplineCurvePtr()->setHandle(spline); + Py_Return; + } + else { + Standard_Failure::Raise("failed to create spline"); + return 0; // goes to the catch block + } + } + catch (const Standard_Failure & ) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + Standard_CString msg = e->GetMessageString(); + PyErr_SetString(PartExceptionOCCError, msg ? msg : ""); + return 0; + } +} + + +PyObject* BSplineCurve2dPy::toBezier(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) + return 0; + + Handle_Geom_BSplineCurve spline = Handle_Geom_BSplineCurve::DownCast + (this->getGeomBSplineCurvePtr()->handle()); + GeomConvert_BSplineCurveToBezierCurve crt(spline); + + Py::List list; + Standard_Integer arcs = crt.NbArcs(); + for (Standard_Integer i=1; i<=arcs; i++) { + Handle_Geom_BezierCurve bezier = crt.Arc(i); + list.append(Py::asObject(new BezierCurvePy(new GeomBezierCurve(bezier)))); + } + + return Py::new_reference_to(list); +} + +PyObject* BSplineCurve2dPy::join(PyObject *args) +{ + PyObject* c; + if (!PyArg_ParseTuple(args, "O!", &BSplineCurve2dPy::Type, &c)) + return 0; + + GeomBSplineCurve* curve1 = this->getGeomBSplineCurvePtr(); + BSplineCurve2dPy* curve2 = static_cast(c); + Handle_Geom_BSplineCurve spline = Handle_Geom_BSplineCurve::DownCast + (curve2->getGeomBSplineCurvePtr()->handle()); + + bool ok = curve1->join(spline); + + return PyBool_FromLong(ok ? 1 : 0); +} + +PyObject* BSplineCurve2dPy::makeC1Continuous(PyObject *args) +{ + double tol = Precision::Approximation(); + double ang_tol = 1.0e-7; + if (!PyArg_ParseTuple(args, "|dd", &tol, &ang_tol)) + return 0; + + try { + GeomBSplineCurve* spline = this->getGeomBSplineCurvePtr(); + spline->makeC1Continuous(tol, ang_tol); + Py_Return; + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + std::string err = e->GetMessageString(); + if (err.empty()) err = e->DynamicType()->Name(); + PyErr_SetString(PartExceptionOCCError, err.c_str()); + return 0; + } +} +#endif +PyObject* BSplineCurve2dPy::getCustomAttributes(const char* /*attr*/) const +{ + return 0; +} + +int BSplineCurve2dPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) +{ + return 0; +} diff --git a/src/Mod/Part/App/Geom2d/BezierCurve2dPy.xml b/src/Mod/Part/App/Geom2d/BezierCurve2dPy.xml new file mode 100644 index 000000000000..40b03221d4f2 --- /dev/null +++ b/src/Mod/Part/App/Geom2d/BezierCurve2dPy.xml @@ -0,0 +1,146 @@ + + + + + + + Describes a rational or non-rational Bezier curve: + -- a non-rational Bezier curve is defined by a table of poles (also called control points) + -- a rational Bezier curve is defined by a table of poles with varying weights + + + + + diff --git a/src/Mod/Part/App/Geom2d/BezierCurve2dPyImp.cpp b/src/Mod/Part/App/Geom2d/BezierCurve2dPyImp.cpp new file mode 100644 index 000000000000..388d2a70e98e --- /dev/null +++ b/src/Mod/Part/App/Geom2d/BezierCurve2dPyImp.cpp @@ -0,0 +1,404 @@ +/*************************************************************************** + * Copyright (c) 2008 Werner Mayer * + * * + * 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 * + * * + ***************************************************************************/ + + +#include "PreCompiled.h" +#ifndef _PreComp_ +# include +# include +# include +# include +#endif + +#include +#include + +#include +#include +#include +#include + +using namespace Part; + +// returns a string which represents the object e.g. when printed in python +std::string BezierCurve2dPy::representation(void) const +{ + return ""; +} + +PyObject *BezierCurve2dPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper +{ + // create a new instance of BezierCurve2dPy and the Twin object + return new BezierCurve2dPy(new Geom2dBezierCurve); +} + +// constructor method +int BezierCurve2dPy::PyInit(PyObject* /*args*/, PyObject* /*kwd*/) +{ + return 0; +} +#if 0 +PyObject* BezierCurve2dPy::isRational(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) + return 0; + Handle_Geom_BezierCurve curve = Handle_Geom_BezierCurve::DownCast + (getGeometryPtr()->handle()); + Standard_Boolean val = curve->IsRational(); + return PyBool_FromLong(val ? 1 : 0); +} + +PyObject* BezierCurve2dPy::isPeriodic(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) + return 0; + Handle_Geom_BezierCurve curve = Handle_Geom_BezierCurve::DownCast + (getGeometryPtr()->handle()); + Standard_Boolean val = curve->IsPeriodic(); + return PyBool_FromLong(val ? 1 : 0); +} + +PyObject* BezierCurve2dPy::isClosed(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) + return 0; + Handle_Geom_BezierCurve curve = Handle_Geom_BezierCurve::DownCast + (getGeometryPtr()->handle()); + Standard_Boolean val = curve->IsClosed(); + return PyBool_FromLong(val ? 1 : 0); +} + +PyObject* BezierCurve2dPy::increase(PyObject * args) +{ + int degree; + if (!PyArg_ParseTuple(args, "i", °ree)) + return 0; + Handle_Geom_BezierCurve curve = Handle_Geom_BezierCurve::DownCast + (getGeometryPtr()->handle()); + curve->Increase(degree); + Py_Return; +} + +PyObject* BezierCurve2dPy::insertPoleAfter(PyObject * args) +{ + int index; + double weight=1.0; + PyObject* p; + if (!PyArg_ParseTuple(args, "iO!|d", &index, &(Base::VectorPy::Type), &p, &weight)) + return 0; + Base::Vector3d vec = static_cast(p)->value(); + gp_Pnt pnt(vec.x, vec.y, vec.z); + try { + Handle_Geom_BezierCurve curve = Handle_Geom_BezierCurve::DownCast + (getGeometryPtr()->handle()); + curve->InsertPoleAfter(index,pnt,weight); + Py_Return; + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); + return 0; + } +} + +PyObject* BezierCurve2dPy::insertPoleBefore(PyObject * args) +{ + int index; + double weight=1.0; + PyObject* p; + if (!PyArg_ParseTuple(args, "iO!|d", &index, &(Base::VectorPy::Type), &p, &weight)) + return 0; + Base::Vector3d vec = static_cast(p)->value(); + gp_Pnt pnt(vec.x, vec.y, vec.z); + try { + Handle_Geom_BezierCurve curve = Handle_Geom_BezierCurve::DownCast + (getGeometryPtr()->handle()); + curve->InsertPoleBefore(index,pnt,weight); + Py_Return; + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); + return 0; + } +} + +PyObject* BezierCurve2dPy::removePole(PyObject * args) +{ + int index; + if (!PyArg_ParseTuple(args, "i", &index)) + return 0; + try { + Handle_Geom_BezierCurve curve = Handle_Geom_BezierCurve::DownCast + (getGeometryPtr()->handle()); + curve->RemovePole(index); + Py_Return; + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); + return 0; + } +} + +PyObject* BezierCurve2dPy::segment(PyObject * args) +{ + double u1,u2; + if (!PyArg_ParseTuple(args, "dd", &u1,&u2)) + return 0; + try { + Handle_Geom_BezierCurve curve = Handle_Geom_BezierCurve::DownCast + (getGeometryPtr()->handle()); + curve->Segment(u1,u2); + Py_Return; + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); + return 0; + } +} + +PyObject* BezierCurve2dPy::setPole(PyObject * args) +{ + int index; + double weight=-1.0; + PyObject* p; + if (!PyArg_ParseTuple(args, "iO!|d", &index, &(Base::VectorPy::Type), &p, &weight)) + return 0; + Base::Vector3d vec = static_cast(p)->value(); + gp_Pnt pnt(vec.x, vec.y, vec.z); + try { + Handle_Geom_BezierCurve curve = Handle_Geom_BezierCurve::DownCast + (getGeometryPtr()->handle()); + if (weight < 0.0) + curve->SetPole(index,pnt); + else + curve->SetPole(index,pnt,weight); + Py_Return; + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); + return 0; + } +} + +PyObject* BezierCurve2dPy::getPole(PyObject * args) +{ + int index; + if (!PyArg_ParseTuple(args, "i", &index)) + return 0; + try { + Handle_Geom_BezierCurve curve = Handle_Geom_BezierCurve::DownCast + (getGeometryPtr()->handle()); + Standard_OutOfRange_Raise_if + (index < 1 || index > curve->NbPoles(), "Pole index out of range"); + gp_Pnt pnt = curve->Pole(index); + Base::VectorPy* vec = new Base::VectorPy(Base::Vector3d( + pnt.X(), pnt.Y(), pnt.Z())); + return vec; + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); + return 0; + } +} + +PyObject* BezierCurve2dPy::getPoles(PyObject * args) +{ + if (!PyArg_ParseTuple(args, "")) + return 0; + try { + Handle_Geom_BezierCurve curve = Handle_Geom_BezierCurve::DownCast + (getGeometryPtr()->handle()); + TColgp_Array1OfPnt p(1,curve->NbPoles()); + curve->Poles(p); + Py::List poles; + for (Standard_Integer i=p.Lower(); i<=p.Upper(); i++) { + gp_Pnt pnt = p(i); + Base::VectorPy* vec = new Base::VectorPy(Base::Vector3d( + pnt.X(), pnt.Y(), pnt.Z())); + poles.append(Py::Object(vec)); + } + return Py::new_reference_to(poles); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); + return 0; + } +} + +PyObject* BezierCurve2dPy::setPoles(PyObject * args) +{ + PyObject* plist; + if (!PyArg_ParseTuple(args, "O", &plist)) + return 0; + try { + Py::Sequence list(plist); + TColgp_Array1OfPnt poles(1,list.size()); + int index = poles.Lower(); + for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) { + Py::Vector v(*it); + Base::Vector3d pole = v.toVector(); + poles.SetValue(index++, gp_Pnt(pole.x,pole.y,pole.z)); + } + + Handle_Geom_BezierCurve bezier = new Geom_BezierCurve(poles); + this->getGeomBezierCurvePtr()->setHandle(bezier); + Py_Return; + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); + return 0; + } +} + +PyObject* BezierCurve2dPy::setWeight(PyObject * args) +{ + int index; + double weight; + if (!PyArg_ParseTuple(args, "id", &index,&weight)) + return 0; + try { + Handle_Geom_BezierCurve curve = Handle_Geom_BezierCurve::DownCast + (getGeometryPtr()->handle()); + curve->SetWeight(index,weight); + Py_Return; + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); + return 0; + } +} + +PyObject* BezierCurve2dPy::getWeight(PyObject * args) +{ + int index; + if (!PyArg_ParseTuple(args, "i", &index)) + return 0; + try { + Handle_Geom_BezierCurve curve = Handle_Geom_BezierCurve::DownCast + (getGeometryPtr()->handle()); + Standard_OutOfRange_Raise_if + (index < 1 || index > curve->NbPoles() , "Weight index out of range"); + double weight = curve->Weight(index); + return Py_BuildValue("d", weight); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); + return 0; + } +} + +PyObject* BezierCurve2dPy::getWeights(PyObject * args) +{ + if (!PyArg_ParseTuple(args, "")) + return 0; + try { + Handle_Geom_BezierCurve curve = Handle_Geom_BezierCurve::DownCast + (getGeometryPtr()->handle()); + TColStd_Array1OfReal w(1,curve->NbPoles()); + curve->Weights(w); + Py::List weights; + for (Standard_Integer i=w.Lower(); i<=w.Upper(); i++) { + weights.append(Py::Float(w(i))); + } + return Py::new_reference_to(weights); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); + return 0; + } +} + +PyObject* BezierCurve2dPy::getResolution(PyObject* args) +{ + double tol; + if (!PyArg_ParseTuple(args, "d", &tol)) + return 0; + try { + Handle_Geom_BezierCurve curve = Handle_Geom_BezierCurve::DownCast + (getGeometryPtr()->handle()); + double utol; + curve->Resolution(tol,utol); + return Py_BuildValue("d",utol); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); + return 0; + } +} + +Py::Int BezierCurve2dPy::getDegree(void) const +{ + Handle_Geom_BezierCurve curve = Handle_Geom_BezierCurve::DownCast + (getGeometryPtr()->handle()); + return Py::Int(curve->Degree()); +} + +Py::Int BezierCurve2dPy::getMaxDegree(void) const +{ + Handle_Geom_BezierCurve curve = Handle_Geom_BezierCurve::DownCast + (getGeometryPtr()->handle()); + return Py::Int(curve->MaxDegree()); +} + +Py::Int BezierCurve2dPy::getNbPoles(void) const +{ + Handle_Geom_BezierCurve curve = Handle_Geom_BezierCurve::DownCast + (getGeometryPtr()->handle()); + return Py::Int(curve->NbPoles()); +} + +Py::Object BezierCurve2dPy::getStartPoint(void) const +{ + Handle_Geom_BezierCurve c = Handle_Geom_BezierCurve::DownCast + (getGeometryPtr()->handle()); + gp_Pnt pnt = c->StartPoint(); + return Py::Vector(Base::Vector3d(pnt.X(), pnt.Y(), pnt.Z())); +} + +Py::Object BezierCurve2dPy::getEndPoint(void) const +{ + Handle_Geom_BezierCurve c = Handle_Geom_BezierCurve::DownCast + (getGeometryPtr()->handle()); + gp_Pnt pnt = c->EndPoint(); + return Py::Vector(Base::Vector3d(pnt.X(), pnt.Y(), pnt.Z())); +} +#endif +PyObject *BezierCurve2dPy::getCustomAttributes(const char* /*attr*/) const +{ + return 0; +} + +int BezierCurve2dPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) +{ + return 0; +} diff --git a/src/Mod/Part/App/Geom2d/Circle2dPy.xml b/src/Mod/Part/App/Geom2d/Circle2dPy.xml new file mode 100644 index 000000000000..c32d66d1790e --- /dev/null +++ b/src/Mod/Part/App/Geom2d/Circle2dPy.xml @@ -0,0 +1,66 @@ + + + + + + Describes a circle in 3D space +To create a circle there are several ways: +Part.Circle() + Creates a default circle with center (0,0,0) and radius 1 + +Part.Circle(Circle) + Creates a copy of the given circle + +Part.Circle(Circle, Distance) + Creates a circle parallel to given circle at a certain distance + +Part.Circle(Center,Normal,Radius) + Creates a circle defined by center, normal direction and radius + +Part.Circle(Point1,Point2,Point3) + Creates a circle defined by three non-linear points + + + + + diff --git a/src/Mod/Part/App/Geom2d/Circle2dPyImp.cpp b/src/Mod/Part/App/Geom2d/Circle2dPyImp.cpp new file mode 100644 index 000000000000..604f4b31d3bc --- /dev/null +++ b/src/Mod/Part/App/Geom2d/Circle2dPyImp.cpp @@ -0,0 +1,328 @@ +/*************************************************************************** + * Copyright (c) 2008 Werner Mayer * + * * + * 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 * + * * + ***************************************************************************/ + + +#include "PreCompiled.h" +#ifndef _PreComp_ +# include +# include +# include +#endif + +#include +#include +#include + +#include +#include + +using namespace Part; + +extern const char* gce_ErrorStatusText(gce_ErrorType et); + +// returns a string which represents the object e.g. when printed in python +std::string Circle2dPy::representation(void) const +{ +#if 0 + Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(getGeomCirclePtr()->handle()); + gp_Ax1 axis = circle->Axis(); + gp_Dir dir = axis.Direction(); + gp_Pnt loc = axis.Location(); + Standard_Real fRad = circle->Radius(); + + std::stringstream str; + str << "Circle ("; + str << "Radius : " << fRad << ", "; + str << "Position : (" << loc.X() << ", "<< loc.Y() << ", "<< loc.Z() << "), "; + str << "Direction : (" << dir.X() << ", "<< dir.Y() << ", "<< dir.Z() << ")"; + str << ")"; + + return str.str(); +#else + return ""; +#endif +} + +PyObject *Circle2dPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper +{ +#if 1 + return 0; +#else + // create a new instance of Circle2dPy and the Twin object + Handle_Geom_Circle circle = new Geom_Circle(gp_Circ()); + return new Circle2dPy(new GeomCircle(circle)); +#endif +} + +// constructor method +int Circle2dPy::PyInit(PyObject* args, PyObject* kwds) +{ + return 0; +#if 0 + // circle and distance for offset + PyObject *pCirc; + double dist; + static char* keywords_cd[] = {"Circle","Distance",NULL}; + if (PyArg_ParseTupleAndKeywords(args, kwds, "O!d", keywords_cd, &(Circle2dPy::Type), &pCirc, &dist)) { + Circle2dPy* pcCircle = static_cast(pCirc); + Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast + (pcCircle->getGeomCirclePtr()->handle()); + GC_MakeCircle mc(circle->Circ(), dist); + if (!mc.IsDone()) { + PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(mc.Status())); + return -1; + } + + Handle_Geom_Circle circ = Handle_Geom_Circle::DownCast(getGeomCirclePtr()->handle()); + circ->SetCirc(mc.Value()->Circ()); + return 0; + } + + // center, normal and radius + PyObject *pV1, *pV2, *pV3; + static char* keywords_cnr[] = {"Center","Normal","Radius",NULL}; + PyErr_Clear(); + if (PyArg_ParseTupleAndKeywords(args, kwds, "O!O!d", keywords_cnr, + &(Base::VectorPy::Type), &pV1, + &(Base::VectorPy::Type), &pV2, + &dist)) { + Base::Vector3d v1 = static_cast(pV1)->value(); + Base::Vector3d v2 = static_cast(pV2)->value(); + GC_MakeCircle mc(gp_Pnt(v1.x,v1.y,v1.z), + gp_Dir(v2.x,v2.y,v2.z), + dist); + if (!mc.IsDone()) { + PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(mc.Status())); + return -1; + } + + Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(getGeomCirclePtr()->handle()); + circle->SetCirc(mc.Value()->Circ()); + return 0; + } + + static char* keywords_c[] = {"Circle",NULL}; + PyErr_Clear(); + if (PyArg_ParseTupleAndKeywords(args, kwds, "O!", keywords_c, &(Circle2dPy::Type), &pCirc)) { + Circle2dPy* pcCircle = static_cast(pCirc); + Handle_Geom_Circle circ1 = Handle_Geom_Circle::DownCast + (pcCircle->getGeomCirclePtr()->handle()); + Handle_Geom_Circle circ2 = Handle_Geom_Circle::DownCast + (this->getGeomCirclePtr()->handle()); + circ2->SetCirc(circ1->Circ()); + return 0; + } + + static char* keywords_ppp[] = {"Point1","Point2","Point3",NULL}; + PyErr_Clear(); + if (PyArg_ParseTupleAndKeywords(args, kwds, "O!O!O!", keywords_ppp, + &(Base::VectorPy::Type), &pV1, + &(Base::VectorPy::Type), &pV2, + &(Base::VectorPy::Type), &pV3)) { + Base::Vector3d v1 = static_cast(pV1)->value(); + Base::Vector3d v2 = static_cast(pV2)->value(); + Base::Vector3d v3 = static_cast(pV3)->value(); + GC_MakeCircle mc(gp_Pnt(v1.x,v1.y,v1.z), + gp_Pnt(v2.x,v2.y,v2.z), + gp_Pnt(v3.x,v3.y,v3.z)); + if (!mc.IsDone()) { + PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(mc.Status())); + return -1; + } + + Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(getGeomCirclePtr()->handle()); + circle->SetCirc(mc.Value()->Circ()); + return 0; + } + + // default circle + static char* keywords_n[] = {NULL}; + PyErr_Clear(); + if (PyArg_ParseTupleAndKeywords(args, kwds, "", keywords_n)) { + Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(getGeomCirclePtr()->handle()); + circle->SetRadius(1.0); + return 0; + } + + PyErr_SetString(PyExc_TypeError, "Circle constructor accepts:\n" + "-- empty parameter list\n" + "-- Circle\n" + "-- Circle, Distance\n" + "-- Center, Normal, Radius\n" + "-- Point1, Point2, Point3"); + return -1; +#endif +} +#if 0 +Py::Float Circle2dPy::getRadius(void) const +{ + Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(getGeomCirclePtr()->handle()); + return Py::Float(circle->Radius()); +} + +void Circle2dPy::setRadius(Py::Float arg) +{ + Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(getGeomCirclePtr()->handle()); + circle->SetRadius((double)arg); +} + +Py::Object Circle2dPy::getCenter(void) const +{ + Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(getGeomCirclePtr()->handle()); + gp_Pnt loc = circle->Location(); + return Py::Vector(Base::Vector3d(loc.X(), loc.Y(), loc.Z())); +} + +void Circle2dPy::setCenter(Py::Object arg) +{ + PyObject* p = arg.ptr(); + if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) { + Base::Vector3d loc = static_cast(p)->value(); + getGeomCirclePtr()->setCenter(loc); + } + else if (PyObject_TypeCheck(p, &PyTuple_Type)) { + Base::Vector3d loc = Base::getVectorFromTuple(p); + getGeomCirclePtr()->setCenter(loc); + } else { + std::string error = std::string("type must be 'Vector', not "); + error += p->ob_type->tp_name; + throw Py::TypeError(error); + } +} + +Py::Object Circle2dPy::getAxis(void) const +{ + Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(getGeomCirclePtr()->handle()); + gp_Ax1 axis = circle->Axis(); + gp_Dir dir = axis.Direction(); + return Py::Vector(Base::Vector3d(dir.X(), dir.Y(), dir.Z())); +} + +void Circle2dPy::setAxis(Py::Object arg) +{ + PyObject* p = arg.ptr(); + Base::Vector3d val; + if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) { + val = static_cast(p)->value(); + } + else if (PyTuple_Check(p)) { + val = Base::getVectorFromTuple(p); + } + else { + std::string error = std::string("type must be 'Vector', not "); + error += p->ob_type->tp_name; + throw Py::TypeError(error); + } + + Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(getGeomCirclePtr()->handle()); + try { + gp_Ax1 axis; + axis.SetLocation(circle->Location()); + axis.SetDirection(gp_Dir(val.x, val.y, val.z)); + circle->SetAxis(axis); + } + catch (Standard_Failure) { + throw Py::Exception("cannot set axis"); + } +} + +Py::Object Circle2dPy::getXAxis(void) const +{ + Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(getGeomCirclePtr()->handle()); + gp_Ax1 axis = circle->XAxis(); + gp_Dir dir = axis.Direction(); + return Py::Vector(Base::Vector3d(dir.X(), dir.Y(), dir.Z())); +} + +void Circle2dPy::setXAxis(Py::Object arg) +{ + PyObject* p = arg.ptr(); + Base::Vector3d val; + if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) { + val = static_cast(p)->value(); + } + else if (PyTuple_Check(p)) { + val = Base::getVectorFromTuple(p); + } + else { + std::string error = std::string("type must be 'Vector', not "); + error += p->ob_type->tp_name; + throw Py::TypeError(error); + } + + Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(getGeomCirclePtr()->handle()); + try { + gp_Ax2 pos; + pos = circle->Position(); + pos.SetXDirection(gp_Dir(val.x, val.y, val.z)); + circle->SetPosition(pos); + } + catch (Standard_Failure) { + throw Py::Exception("cannot set X axis"); + } +} + +Py::Object Circle2dPy::getYAxis(void) const +{ + Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(getGeomCirclePtr()->handle()); + gp_Ax1 axis = circle->YAxis(); + gp_Dir dir = axis.Direction(); + return Py::Vector(Base::Vector3d(dir.X(), dir.Y(), dir.Z())); +} + +void Circle2dPy::setYAxis(Py::Object arg) +{ + PyObject* p = arg.ptr(); + Base::Vector3d val; + if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) { + val = static_cast(p)->value(); + } + else if (PyTuple_Check(p)) { + val = Base::getVectorFromTuple(p); + } + else { + std::string error = std::string("type must be 'Vector', not "); + error += p->ob_type->tp_name; + throw Py::TypeError(error); + } + + Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(getGeomCirclePtr()->handle()); + try { + gp_Ax2 pos; + pos = circle->Position(); + pos.SetYDirection(gp_Dir(val.x, val.y, val.z)); + circle->SetPosition(pos); + } + catch (Standard_Failure) { + throw Py::Exception("cannot set Y axis"); + } +} +#endif +PyObject *Circle2dPy::getCustomAttributes(const char* ) const +{ + return 0; +} + +int Circle2dPy::setCustomAttributes(const char* , PyObject *) +{ + return 0; +} diff --git a/src/Mod/Part/App/Geom2d/Conic2dPy.xml b/src/Mod/Part/App/Geom2d/Conic2dPy.xml new file mode 100644 index 000000000000..abca8de7f8ae --- /dev/null +++ b/src/Mod/Part/App/Geom2d/Conic2dPy.xml @@ -0,0 +1,60 @@ + + + + + + Describes a circle in 3D space +To create a circle there are several ways: +Part.Circle() + Creates a default circle with center (0,0,0) and radius 1 + +Part.Circle(Circle) + Creates a copy of the given circle + +Part.Circle(Circle, Distance) + Creates a circle parallel to given circle at a certain distance + +Part.Circle(Center,Normal,Radius) + Creates a circle defined by center, normal direction and radius + +Part.Circle(Point1,Point2,Point3) + Creates a circle defined by three non-linear points + + + + + diff --git a/src/Mod/Part/App/Geom2d/Conic2dPyImp.cpp b/src/Mod/Part/App/Geom2d/Conic2dPyImp.cpp new file mode 100644 index 000000000000..14feb33282fe --- /dev/null +++ b/src/Mod/Part/App/Geom2d/Conic2dPyImp.cpp @@ -0,0 +1,315 @@ +/*************************************************************************** + * Copyright (c) 2008 Werner Mayer * + * * + * 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 * + * * + ***************************************************************************/ + + +#include "PreCompiled.h" +#ifndef _PreComp_ +# include +# include +# include +#endif + +#include +#include +#include + +#include +#include + +using namespace Part; + +extern const char* gce_ErrorStatusText(gce_ErrorType et); + +// returns a string which represents the object e.g. when printed in python +std::string Conic2dPy::representation(void) const +{ +#if 0 + Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(getGeomCirclePtr()->handle()); + gp_Ax1 axis = circle->Axis(); + gp_Dir dir = axis.Direction(); + gp_Pnt loc = axis.Location(); + Standard_Real fRad = circle->Radius(); + + std::stringstream str; + str << "Circle ("; + str << "Radius : " << fRad << ", "; + str << "Position : (" << loc.X() << ", "<< loc.Y() << ", "<< loc.Z() << "), "; + str << "Direction : (" << dir.X() << ", "<< dir.Y() << ", "<< dir.Z() << ")"; + str << ")"; + + return str.str(); +#else + return ""; +#endif +} + +PyObject *Conic2dPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper +{ + return 0; +#if 0 + // create a new instance of Conic2dPy and the Twin object + Handle_Geom_Circle circle = new Geom_Circle(gp_Circ()); + return new Conic2dPy(new GeomCircle(circle)); +#endif +} + +// constructor method +int Conic2dPy::PyInit(PyObject* args, PyObject* kwds) +{ + return -1; +#if 0 + // circle and distance for offset + PyObject *pCirc; + double dist; + static char* keywords_cd[] = {"Circle","Distance",NULL}; + if (PyArg_ParseTupleAndKeywords(args, kwds, "O!d", keywords_cd, &(Conic2dPy::Type), &pCirc, &dist)) { + Conic2dPy* pcCircle = static_cast(pCirc); + Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast + (pcCircle->getGeomCirclePtr()->handle()); + GC_MakeCircle mc(circle->Circ(), dist); + if (!mc.IsDone()) { + PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(mc.Status())); + return -1; + } + + Handle_Geom_Circle circ = Handle_Geom_Circle::DownCast(getGeomCirclePtr()->handle()); + circ->SetCirc(mc.Value()->Circ()); + return 0; + } + + // center, normal and radius + PyObject *pV1, *pV2, *pV3; + static char* keywords_cnr[] = {"Center","Normal","Radius",NULL}; + PyErr_Clear(); + if (PyArg_ParseTupleAndKeywords(args, kwds, "O!O!d", keywords_cnr, + &(Base::VectorPy::Type), &pV1, + &(Base::VectorPy::Type), &pV2, + &dist)) { + Base::Vector3d v1 = static_cast(pV1)->value(); + Base::Vector3d v2 = static_cast(pV2)->value(); + GC_MakeCircle mc(gp_Pnt(v1.x,v1.y,v1.z), + gp_Dir(v2.x,v2.y,v2.z), + dist); + if (!mc.IsDone()) { + PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(mc.Status())); + return -1; + } + + Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(getGeomCirclePtr()->handle()); + circle->SetCirc(mc.Value()->Circ()); + return 0; + } + + static char* keywords_c[] = {"Circle",NULL}; + PyErr_Clear(); + if (PyArg_ParseTupleAndKeywords(args, kwds, "O!", keywords_c, &(Conic2dPy::Type), &pCirc)) { + Conic2dPy* pcCircle = static_cast(pCirc); + Handle_Geom_Circle circ1 = Handle_Geom_Circle::DownCast + (pcCircle->getGeomCirclePtr()->handle()); + Handle_Geom_Circle circ2 = Handle_Geom_Circle::DownCast + (this->getGeomCirclePtr()->handle()); + circ2->SetCirc(circ1->Circ()); + return 0; + } + + static char* keywords_ppp[] = {"Point1","Point2","Point3",NULL}; + PyErr_Clear(); + if (PyArg_ParseTupleAndKeywords(args, kwds, "O!O!O!", keywords_ppp, + &(Base::VectorPy::Type), &pV1, + &(Base::VectorPy::Type), &pV2, + &(Base::VectorPy::Type), &pV3)) { + Base::Vector3d v1 = static_cast(pV1)->value(); + Base::Vector3d v2 = static_cast(pV2)->value(); + Base::Vector3d v3 = static_cast(pV3)->value(); + GC_MakeCircle mc(gp_Pnt(v1.x,v1.y,v1.z), + gp_Pnt(v2.x,v2.y,v2.z), + gp_Pnt(v3.x,v3.y,v3.z)); + if (!mc.IsDone()) { + PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(mc.Status())); + return -1; + } + + Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(getGeomCirclePtr()->handle()); + circle->SetCirc(mc.Value()->Circ()); + return 0; + } + + // default circle + static char* keywords_n[] = {NULL}; + PyErr_Clear(); + if (PyArg_ParseTupleAndKeywords(args, kwds, "", keywords_n)) { + Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(getGeomCirclePtr()->handle()); + circle->SetRadius(1.0); + return 0; + } + + PyErr_SetString(PyExc_TypeError, "Circle constructor accepts:\n" + "-- empty parameter list\n" + "-- Circle\n" + "-- Circle, Distance\n" + "-- Center, Normal, Radius\n" + "-- Point1, Point2, Point3"); + return -1; +#endif +} +#if 0 +Py::Object Conic2dPy::getCenter(void) const +{ + Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(getGeomCirclePtr()->handle()); + gp_Pnt loc = circle->Location(); + return Py::Vector(Base::Vector3d(loc.X(), loc.Y(), loc.Z())); +} + +void Conic2dPy::setCenter(Py::Object arg) +{ + PyObject* p = arg.ptr(); + if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) { + Base::Vector3d loc = static_cast(p)->value(); + getGeomCirclePtr()->setCenter(loc); + } + else if (PyObject_TypeCheck(p, &PyTuple_Type)) { + Base::Vector3d loc = Base::getVectorFromTuple(p); + getGeomCirclePtr()->setCenter(loc); + } else { + std::string error = std::string("type must be 'Vector', not "); + error += p->ob_type->tp_name; + throw Py::TypeError(error); + } +} + +Py::Object Conic2dPy::getAxis(void) const +{ + Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(getGeomCirclePtr()->handle()); + gp_Ax1 axis = circle->Axis(); + gp_Dir dir = axis.Direction(); + return Py::Vector(Base::Vector3d(dir.X(), dir.Y(), dir.Z())); +} + +void Conic2dPy::setAxis(Py::Object arg) +{ + PyObject* p = arg.ptr(); + Base::Vector3d val; + if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) { + val = static_cast(p)->value(); + } + else if (PyTuple_Check(p)) { + val = Base::getVectorFromTuple(p); + } + else { + std::string error = std::string("type must be 'Vector', not "); + error += p->ob_type->tp_name; + throw Py::TypeError(error); + } + + Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(getGeomCirclePtr()->handle()); + try { + gp_Ax1 axis; + axis.SetLocation(circle->Location()); + axis.SetDirection(gp_Dir(val.x, val.y, val.z)); + circle->SetAxis(axis); + } + catch (Standard_Failure) { + throw Py::Exception("cannot set axis"); + } +} + +Py::Object Conic2dPy::getXAxis(void) const +{ + Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(getGeomCirclePtr()->handle()); + gp_Ax1 axis = circle->XAxis(); + gp_Dir dir = axis.Direction(); + return Py::Vector(Base::Vector3d(dir.X(), dir.Y(), dir.Z())); +} + +void Conic2dPy::setXAxis(Py::Object arg) +{ + PyObject* p = arg.ptr(); + Base::Vector3d val; + if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) { + val = static_cast(p)->value(); + } + else if (PyTuple_Check(p)) { + val = Base::getVectorFromTuple(p); + } + else { + std::string error = std::string("type must be 'Vector', not "); + error += p->ob_type->tp_name; + throw Py::TypeError(error); + } + + Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(getGeomCirclePtr()->handle()); + try { + gp_Ax2 pos; + pos = circle->Position(); + pos.SetXDirection(gp_Dir(val.x, val.y, val.z)); + circle->SetPosition(pos); + } + catch (Standard_Failure) { + throw Py::Exception("cannot set X axis"); + } +} + +Py::Object Conic2dPy::getYAxis(void) const +{ + Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(getGeomCirclePtr()->handle()); + gp_Ax1 axis = circle->YAxis(); + gp_Dir dir = axis.Direction(); + return Py::Vector(Base::Vector3d(dir.X(), dir.Y(), dir.Z())); +} + +void Conic2dPy::setYAxis(Py::Object arg) +{ + PyObject* p = arg.ptr(); + Base::Vector3d val; + if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) { + val = static_cast(p)->value(); + } + else if (PyTuple_Check(p)) { + val = Base::getVectorFromTuple(p); + } + else { + std::string error = std::string("type must be 'Vector', not "); + error += p->ob_type->tp_name; + throw Py::TypeError(error); + } + + Handle_Geom_Circle circle = Handle_Geom_Circle::DownCast(getGeomCirclePtr()->handle()); + try { + gp_Ax2 pos; + pos = circle->Position(); + pos.SetYDirection(gp_Dir(val.x, val.y, val.z)); + circle->SetPosition(pos); + } + catch (Standard_Failure) { + throw Py::Exception("cannot set Y axis"); + } +} +#endif +PyObject *Conic2dPy::getCustomAttributes(const char* ) const +{ + return 0; +} + +int Conic2dPy::setCustomAttributes(const char* , PyObject *) +{ + return 0; +} diff --git a/src/Mod/Part/App/Geom2d/Curve2dPy.xml b/src/Mod/Part/App/Geom2d/Curve2dPy.xml new file mode 100644 index 000000000000..dd5ad20f4e10 --- /dev/null +++ b/src/Mod/Part/App/Geom2d/Curve2dPy.xml @@ -0,0 +1,160 @@ + + + + + + + The abstract class GeometryCurve is the root class of all curve objects. + + + + + diff --git a/src/Mod/Part/App/Geom2d/Curve2dPyImp.cpp b/src/Mod/Part/App/Geom2d/Curve2dPyImp.cpp new file mode 100644 index 000000000000..13e36d153a35 --- /dev/null +++ b/src/Mod/Part/App/Geom2d/Curve2dPyImp.cpp @@ -0,0 +1,691 @@ +/*************************************************************************** + * Copyright (c) 2016 Werner Mayer * + * * + * 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 * + * * + ***************************************************************************/ + + +#include "PreCompiled.h" +#ifndef _PreComp_ +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +#endif + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +namespace Part { +extern const Py::Object makeGeometryCurvePy(const Handle_Geom_Curve& c); +} + +using namespace Part; + +// returns a string which represents the object e.g. when printed in python +std::string Curve2dPy::representation(void) const +{ + return ""; +} + +PyObject *Curve2dPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper +{ + // never create such objects with the constructor + PyErr_SetString(PyExc_RuntimeError, + "You cannot create an instance of the abstract class 'GeometryCurve'."); + return 0; +} + +// constructor method +int Curve2dPy::PyInit(PyObject* /*args*/, PyObject* /*kwd*/) +{ + return 0; +} +#if 0 +PyObject* Curve2dPy::toShape(PyObject *args) +{ + try { + TopoDS_Shape sh = getGeometry2dPtr()->toShape(Handle_Geom_Surface()); + return new TopoShapeEdgePy(new TopoShape(sh)); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); + return 0; + } + + PyErr_SetString(PartExceptionOCCError, "Geometry is not a curve"); + return 0; +} + +PyObject* Curve2dPy::discretize(PyObject *args, PyObject *kwds) +{ + try { + Handle_Geom2d_Geometry g = getGeometry2dPtr()->handle(); + Handle_Geom2d_Curve c = Handle_Geom2d_Curve::DownCast(g); + if (c.IsNull()) { + PyErr_SetString(PartExceptionOCCError, "Geometry is not a curve"); + return 0; + } + + Geom2dAdaptor_Curve adapt(c); + bool uniformAbscissaPoints = false; + bool uniformAbscissaDistance = false; + int numPoints = -1; + double distance = -1; + double first = adapt.FirstParameter(); + double last = adapt.LastParameter(); + + // use no kwds + PyObject* dist_or_num; + if (PyArg_ParseTuple(args, "O", &dist_or_num)) { + if (PyInt_Check(dist_or_num)) { + numPoints = PyInt_AsLong(dist_or_num); + uniformAbscissaPoints = true; + } + else if (PyFloat_Check(dist_or_num)) { + distance = PyFloat_AsDouble(dist_or_num); + uniformAbscissaDistance = true; + } + else { + PyErr_SetString(PyExc_TypeError, "Either int or float expected"); + return 0; + } + } + else { + // use Number kwds + static char* kwds_numPoints[] = {"Number","First","Last",NULL}; + PyErr_Clear(); + if (PyArg_ParseTupleAndKeywords(args, kwds, "i|dd", kwds_numPoints, &numPoints, &first, &last)) { + uniformAbscissaPoints = true; + } + else { + // use Abscissa kwds + static char* kwds_Distance[] = {"Distance","First","Last",NULL}; + PyErr_Clear(); + if (PyArg_ParseTupleAndKeywords(args, kwds, "d|dd", kwds_Distance, &distance, &first, &last)) { + uniformAbscissaDistance = true; + } + } + } + + if (uniformAbscissaPoints || uniformAbscissaDistance) { + GCPnts_UniformAbscissa discretizer; + if (uniformAbscissaPoints) + discretizer.Initialize (adapt, numPoints, first, last); + else + discretizer.Initialize (adapt, distance, first, last); + + if (discretizer.IsDone () && discretizer.NbPoints () > 0) { + Py::List points; + int nbPoints = discretizer.NbPoints (); + for (int i=1; i<=nbPoints; i++) { + gp_Pnt2d p = adapt.Value (discretizer.Parameter (i)); + points.append(Py::asObject(new Base::Vector2dPy(p.X(),p.Y()))); + } + + return Py::new_reference_to(points); + } + else { + PyErr_SetString(PartExceptionOCCError, "Discretization of curve failed"); + return 0; + } + } + + // use Deflection kwds + static char* kwds_Deflection[] = {"Deflection","First","Last",NULL}; + PyErr_Clear(); + double deflection; + if (PyArg_ParseTupleAndKeywords(args, kwds, "d|dd", kwds_Deflection, &deflection, &first, &last)) { + GCPnts_UniformDeflection discretizer(adapt, deflection, first, last); + if (discretizer.IsDone () && discretizer.NbPoints () > 0) { + Py::List points; + int nbPoints = discretizer.NbPoints (); + for (int i=1; i<=nbPoints; i++) { + gp_Pnt p = discretizer.Value (i); + points.append(Py::Vector(Base::Vector3d(p.X(),p.Y(),p.Z()))); + } + + return Py::new_reference_to(points); + } + else { + PyErr_SetString(PartExceptionOCCError, "Discretization of curve failed"); + return 0; + } + } + + // use TangentialDeflection kwds + static char* kwds_TangentialDeflection[] = {"Angular","Curvature","First","Last","Minimum",NULL}; + PyErr_Clear(); + double angular; + double curvature; + int minimumPoints = 2; + if (PyArg_ParseTupleAndKeywords(args, kwds, "dd|ddi", kwds_TangentialDeflection, &angular, &curvature, &first, &last, &minimumPoints)) { + GCPnts_TangentialDeflection discretizer(adapt, first, last, angular, curvature, minimumPoints); + if (discretizer.NbPoints () > 0) { + Py::List points; + int nbPoints = discretizer.NbPoints (); + for (int i=1; i<=nbPoints; i++) { + gp_Pnt p = discretizer.Value (i); + points.append(Py::Vector(Base::Vector3d(p.X(),p.Y(),p.Z()))); + } + + return Py::new_reference_to(points); + } + else { + PyErr_SetString(PartExceptionOCCError, "Discretization of curve failed"); + return 0; + } + } + + // use QuasiNumber kwds + static char* kwds_QuasiNumPoints[] = {"QuasiNumber","First","Last",NULL}; + PyErr_Clear(); + int quasiNumPoints; + if (PyArg_ParseTupleAndKeywords(args, kwds, "i|dd", kwds_QuasiNumPoints, &quasiNumPoints, &first, &last)) { + GCPnts_QuasiUniformAbscissa discretizer(adapt, quasiNumPoints, first, last); + if (discretizer.NbPoints () > 0) { + Py::List points; + int nbPoints = discretizer.NbPoints (); + for (int i=1; i<=nbPoints; i++) { + gp_Pnt2d p = adapt.Value (discretizer.Parameter (i)); + points.append(Py::asObject(new Base::Vector2dPy(p.X(),p.Y()))); + } + + return Py::new_reference_to(points); + } + else { + PyErr_SetString(PartExceptionOCCError, "Discretization of curve failed"); + return 0; + } + } + + // use QuasiDeflection kwds + static char* kwds_QuasiDeflection[] = {"QuasiDeflection","First","Last",NULL}; + PyErr_Clear(); + double quasiDeflection; + if (PyArg_ParseTupleAndKeywords(args, kwds, "d|dd", kwds_QuasiDeflection, &quasiDeflection, &first, &last)) { + GCPnts_QuasiUniformDeflection discretizer(adapt, quasiDeflection, first, last); + if (discretizer.NbPoints () > 0) { + Py::List points; + int nbPoints = discretizer.NbPoints (); + for (int i=1; i<=nbPoints; i++) { + gp_Pnt p = discretizer.Value (i); + points.append(Py::Vector(Base::Vector3d(p.X(),p.Y(),p.Z()))); + } + + return Py::new_reference_to(points); + } + else { + PyErr_SetString(PartExceptionOCCError, "Discretization of curve failed"); + return 0; + } + } + } + catch (const Base::Exception& e) { + PyErr_SetString(PartExceptionOCCError, e.what()); + return 0; + } + + PyErr_SetString(PartExceptionOCCError,"Wrong arguments"); + return 0; +} + +PyObject* Curve2dPy::length(PyObject *args) +{ + Handle_Geom2d_Geometry g = getGeometry2dPtr()->handle(); + Handle_Geom_Curve c = Handle_Geom_Curve::DownCast(g); + try { + if (!c.IsNull()) { + double u=c->FirstParameter(); + double v=c->LastParameter(); + double t=Precision::Confusion(); + if (!PyArg_ParseTuple(args, "|ddd", &u,&v,&t)) + return 0; + GeomAdaptor_Curve adapt(c); + double len = GCPnts_AbscissaPoint::Length(adapt,u,v,t); + return PyFloat_FromDouble(len); + } + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); + return 0; + } + + PyErr_SetString(PartExceptionOCCError, "Geometry is not a curve"); + return 0; +} + +PyObject* Curve2dPy::parameterAtDistance(PyObject *args) +{ + Handle_Geom2d_Geometry g = getGeometry2dPtr()->handle(); + Handle_Geom_Curve c = Handle_Geom_Curve::DownCast(g); + try { + if (!c.IsNull()) { + double abscissa; + double u = 0; + if (!PyArg_ParseTuple(args, "d|d", &abscissa,&u)) + return 0; + GeomAdaptor_Curve adapt(c); + GCPnts_AbscissaPoint abscissaPoint(adapt,abscissa,u); + double parm = abscissaPoint.Parameter(); + return PyFloat_FromDouble(parm); + } + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); + return 0; + } + + PyErr_SetString(PartExceptionOCCError, "Geometry is not a curve"); + return 0; +} + +PyObject* Curve2dPy::value(PyObject *args) +{ + Handle_Geom2d_Geometry g = getGeometry2dPtr()->handle(); + Handle_Geom_Curve c = Handle_Geom_Curve::DownCast(g); + try { + if (!c.IsNull()) { + double u; + if (!PyArg_ParseTuple(args, "d", &u)) + return 0; + gp_Pnt p = c->Value(u); + return new Base::VectorPy(Base::Vector3d(p.X(),p.Y(),p.Z())); + } + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); + return 0; + } + + PyErr_SetString(PartExceptionOCCError, "Geometry is not a curve"); + return 0; +} + +PyObject* Curve2dPy::tangent(PyObject *args) +{ + Handle_Geom2d_Geometry g = getGeometry2dPtr()->handle(); + Handle_Geom_Curve c = Handle_Geom_Curve::DownCast(g); + try { + if (!c.IsNull()) { + double u; + if (!PyArg_ParseTuple(args, "d", &u)) + return 0; + gp_Dir dir; + Py::Tuple tuple(1); + GeomLProp_CLProps prop(c,u,2,Precision::Confusion()); + if (prop.IsTangentDefined()) { + prop.Tangent(dir); + tuple.setItem(0, Py::Vector(Base::Vector3d(dir.X(),dir.Y(),dir.Z()))); + } + + return Py::new_reference_to(tuple); + } + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); + return 0; + } + + PyErr_SetString(PartExceptionOCCError, "Geometry is not a curve"); + return 0; +} + +PyObject* Curve2dPy::normal(PyObject *args) +{ + Handle_Geom2d_Geometry g = getGeometry2dPtr()->handle(); + Handle_Geom_Curve c = Handle_Geom_Curve::DownCast(g); + try { + if (!c.IsNull()) { + double u; + if (!PyArg_ParseTuple(args, "d", &u)) + return 0; + gp_Dir dir; + GeomLProp_CLProps prop(c,u,2,Precision::Confusion()); + prop.Normal(dir); + return new Base::VectorPy(new Base::Vector3d(dir.X(),dir.Y(),dir.Z())); + } + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); + return 0; + } + + PyErr_SetString(PartExceptionOCCError, "Geometry is not a curve"); + return 0; +} + +PyObject* Curve2dPy::curvature(PyObject *args) +{ + Handle_Geom2d_Geometry g = getGeometry2dPtr()->handle(); + Handle_Geom_Curve c = Handle_Geom_Curve::DownCast(g); + try { + if (!c.IsNull()) { + double u; + if (!PyArg_ParseTuple(args, "d", &u)) + return 0; + GeomLProp_CLProps prop(c,u,2,Precision::Confusion()); + double C = prop.Curvature(); + return Py::new_reference_to(Py::Float(C)); + } + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); + return 0; + } + + PyErr_SetString(PartExceptionOCCError, "Geometry is not a curve"); + return 0; +} + +PyObject* Curve2dPy::centerOfCurvature(PyObject *args) +{ + Handle_Geom2d_Geometry g = getGeometry2dPtr()->handle(); + Handle_Geom_Curve c = Handle_Geom_Curve::DownCast(g); + try { + if (!c.IsNull()) { + double u; + if (!PyArg_ParseTuple(args, "d", &u)) + return 0; + GeomLProp_CLProps prop(c,u,2,Precision::Confusion()); + gp_Pnt V ; + prop.CentreOfCurvature(V); + return new Base::VectorPy(new Base::Vector3d(V.X(),V.Y(),V.Z())); + } + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); + return 0; + } + + PyErr_SetString(PartExceptionOCCError, "Geometry is not a curve"); + return 0; +} + +PyObject* Curve2dPy::parameter(PyObject *args) +{ + Handle_Geom2d_Geometry g = getGeometry2dPtr()->handle(); + Handle_Geom_Curve c = Handle_Geom_Curve::DownCast(g); + try { + if (!c.IsNull()) { + PyObject *p; + if (!PyArg_ParseTuple(args, "O!", &(Base::VectorPy::Type), &p)) + return 0; + Base::Vector3d v = Py::Vector(p, false).toVector(); + gp_Pnt pnt(v.x,v.y,v.z); + GeomAPI_ProjectPointOnCurve ppc(pnt, c); + double val = ppc.LowerDistanceParameter(); + return Py::new_reference_to(Py::Float(val)); + } + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); + return 0; + } + + PyErr_SetString(PartExceptionOCCError, "Geometry is not a curve"); + return 0; +} + +PyObject* Curve2dPy::toBSpline(PyObject * args) +{ + Handle_Geom2d_Geometry g = getGeometry2dPtr()->handle(); + Handle_Geom_Curve c = Handle_Geom_Curve::DownCast(g); + try { + if (!c.IsNull()) { + double u,v; + u=c->FirstParameter(); + v=c->LastParameter(); + if (!PyArg_ParseTuple(args, "|dd", &u,&v)) + return 0; + ShapeConstruct_Curve scc; + Handle_Geom_BSplineCurve spline = scc.ConvertToBSpline(c, u, v, Precision::Confusion()); + if (spline.IsNull()) + Standard_NullValue::Raise("Conversion to B-Spline failed"); + return new BSplineCurvePy(new GeomBSplineCurve(spline)); + } + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); + return 0; + } + + PyErr_SetString(PartExceptionOCCError, "Geometry is not a curve"); + return 0; +} + +PyObject* Curve2dPy::approximateBSpline(PyObject *args) +{ + double tolerance; + int maxSegment, maxDegree; + char* order = "C2"; + if (!PyArg_ParseTuple(args, "dii|s", &tolerance, &maxSegment, &maxDegree, &order)) + return 0; + + GeomAbs_Shape absShape; + std::string str = order; + if (str == "C0") + absShape = GeomAbs_C0; + else if (str == "G1") + absShape = GeomAbs_G1; + else if (str == "C1") + absShape = GeomAbs_C1; + else if (str == "G2") + absShape = GeomAbs_G2; + else if (str == "C2") + absShape = GeomAbs_C2; + else if (str == "C3") + absShape = GeomAbs_C3; + else if (str == "CN") + absShape = GeomAbs_CN; + else + absShape = GeomAbs_C2; + + try { + Handle_Geom_Curve self = Handle_Geom_Curve::DownCast(getGeometry2dPtr()->handle()); + GeomConvert_ApproxCurve approx(self, tolerance, absShape, maxSegment, maxDegree); + if (approx.IsDone()) { + return new BSplineCurvePy(new GeomBSplineCurve(approx.Curve())); + } + else if (approx.HasResult()) { + std::stringstream str; + str << "Maximum error (" << approx.MaxError() << ") is outside tolerance"; + PyErr_SetString(PyExc_RuntimeError, str.str().c_str()); + return 0; + } + else { + PyErr_SetString(PyExc_RuntimeError, "Approximation of curve failed"); + return 0; + } + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); + return 0; + } +} + +Py::String Curve2dPy::getContinuity(void) const +{ + GeomAbs_Shape c = Handle_Geom_Curve::DownCast + (getGeometry2dPtr()->handle())->Continuity(); + std::string str; + switch (c) { + case GeomAbs_C0: + str = "C0"; + break; + case GeomAbs_G1: + str = "G1"; + break; + case GeomAbs_C1: + str = "C1"; + break; + case GeomAbs_G2: + str = "G2"; + break; + case GeomAbs_C2: + str = "C2"; + break; + case GeomAbs_C3: + str = "C3"; + break; + case GeomAbs_CN: + str = "CN"; + break; + default: + str = "Unknown"; + break; + } + return Py::String(str); +} + +Py::Float Curve2dPy::getFirstParameter(void) const +{ + return Py::Float(Handle_Geom_Curve::DownCast + (getGeometry2dPtr()->handle())->FirstParameter()); +} + +Py::Float Curve2dPy::getLastParameter(void) const +{ + return Py::Float(Handle_Geom_Curve::DownCast + (getGeometry2dPtr()->handle())->LastParameter()); +} +#endif +PyObject *Curve2dPy::getCustomAttributes(const char* /*attr*/) const +{ + return 0; +} + +int Curve2dPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) +{ + return 0; +} +#if 0 +PyObject* Curve2dPy::intersectCC(PyObject *args) +{ + Handle_Geom2d_Curve curve1 = Handle_Geom2d_Curve::DownCast(getGeometry2dPtr()->handle()); + try { + if (!curve1.IsNull()) { + PyObject *p; + double prec = Precision::Confusion(); + if (!PyArg_ParseTuple(args, "O!|d", &(Part::GeometrySurfacePy::Type), &p, &prec)) + return 0; + Handle_Geom2d_Curve curve2 = Handle_Geom2d_Curve::DownCast(static_cast(p)->getGeometry2dPtr()->handle()); + Geom2dAPI_ExtremaCurveCurve intersector(curve1, curve2, + curve1->FirstParameter(), + curve1->LastParameter(), + curve2->FirstParameter(), + curve2->LastParameter()); + if (intersector.LowerDistance() > Precision::Confusion()) { + // No intersection + return Py::new_reference_to(Py::List()); + } + + Py::List points; + for (int i = 1; i <= intersector.NbExtrema(); i++) { + if (intersector.Distance(i) > Precision::Confusion()) + continue; + gp_Pnt2d p1, p2; + intersector.Points(i, p1, p2); + points.append(Py::asObject(new Base::Vector2dPy(p1.X(), p1.Y()))); + } + + return Py::new_reference_to(points); + } + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PyExc_Exception, e->GetMessageString()); + return 0; + } + + PyErr_SetString(PyExc_Exception, "Geometry is not a curve"); + return 0; +} + +// General intersection function + +PyObject* Curve2dPy::intersect(PyObject *args) +{ + Handle_Geom_Curve curve = Handle_Geom_Curve::DownCast(getGeometry2dPtr()->handle()); + try { + if (!curve.IsNull()) { + PyObject *p; + double prec = Precision::Confusion(); + if (PyArg_ParseTuple(args, "O!|d", &(Part::GeometryCurvePy::Type), &p, &prec)) + return intersectCC(args); + } + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PyExc_Exception, e->GetMessageString()); + return 0; + } + + PyErr_SetString(PyExc_Exception, "Geometry is not a curve"); + return 0; +} +#endif diff --git a/src/Mod/Part/App/Geom2d/Ellipse2dPy.xml b/src/Mod/Part/App/Geom2d/Ellipse2dPy.xml new file mode 100644 index 000000000000..150fb143f4d5 --- /dev/null +++ b/src/Mod/Part/App/Geom2d/Ellipse2dPy.xml @@ -0,0 +1,99 @@ + + + + + + Describes an ellipse in 3D space + To create an ellipse there are several ways: + Part.Ellipse() + Creates an ellipse with major radius 2 and minor radius 1 with the + center in (0,0,0) + + Part.Ellipse(Ellipse) + Create a copy of the given ellipse + + Part.Ellipse(S1,S2,Center) + Creates an ellipse centered on the point Center, where + the plane of the ellipse is defined by Center, S1 and S2, + its major axis is defined by Center and S1, + its major radius is the distance between Center and S1, and + its minor radius is the distance between S2 and the major axis. + + Part.Ellipse(Center,MajorRadius,MinorRadius) + Creates an ellipse with major and minor radii MajorRadius and + MinorRadius, and located in the plane defined by Center and + the normal (0,0,1) + + + + + diff --git a/src/Mod/Part/App/Geom2d/Ellipse2dPyImp.cpp b/src/Mod/Part/App/Geom2d/Ellipse2dPyImp.cpp new file mode 100644 index 000000000000..9ccf7daff3b2 --- /dev/null +++ b/src/Mod/Part/App/Geom2d/Ellipse2dPyImp.cpp @@ -0,0 +1,290 @@ +/*************************************************************************** + * Copyright (c) 2008 Werner Mayer * + * * + * 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 * + * * + ***************************************************************************/ + + +#include "PreCompiled.h" +#ifndef _PreComp_ +# include +# include +# include +#endif + +#include +#include + +#include +#include +#include +#include + +using namespace Part; + +extern const char* gce_ErrorStatusText(gce_ErrorType et); + +// returns a string which represents the object e.g. when printed in python +std::string Ellipse2dPy::representation(void) const +{ + return ""; +} + +PyObject *Ellipse2dPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper +{ + // create a new instance of Ellipse2dPy and the Twin object + return new Ellipse2dPy(new Geom2dEllipse); +} + +// constructor method +int Ellipse2dPy::PyInit(PyObject* args, PyObject* kwds) +{ + return 0; +#if 0 + char* keywords_n[] = {NULL}; + if (PyArg_ParseTupleAndKeywords(args, kwds, "", keywords_n)) { + Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast(getGeomEllipsePtr()->handle()); + ellipse->SetMajorRadius(2.0); + ellipse->SetMinorRadius(1.0); + return 0; + } + + char* keywords_e[] = {"Ellipse",NULL}; + PyErr_Clear(); + PyObject *pElips; + if (PyArg_ParseTupleAndKeywords(args, kwds, "O!",keywords_e, &(Ellipse2dPy::Type), &pElips)) { + Ellipse2dPy* pEllipse = static_cast(pElips); + Handle_Geom_Ellipse Elips1 = Handle_Geom_Ellipse::DownCast + (pEllipse->getGeomEllipsePtr()->handle()); + Handle_Geom_Ellipse Elips2 = Handle_Geom_Ellipse::DownCast + (this->getGeomEllipsePtr()->handle()); + Elips2->SetElips(Elips1->Elips()); + return 0; + } + + char* keywords_ssc[] = {"S1","S2","Center",NULL}; + PyErr_Clear(); + PyObject *pV1, *pV2, *pV3; + if (PyArg_ParseTupleAndKeywords(args, kwds, "O!O!O!", keywords_ssc, + &(Base::VectorPy::Type), &pV1, + &(Base::VectorPy::Type), &pV2, + &(Base::VectorPy::Type), &pV3)) { + Base::Vector3d v1 = static_cast(pV1)->value(); + Base::Vector3d v2 = static_cast(pV2)->value(); + Base::Vector3d v3 = static_cast(pV3)->value(); + GC_MakeEllipse me(gp_Pnt(v1.x,v1.y,v1.z), + gp_Pnt(v2.x,v2.y,v2.z), + gp_Pnt(v3.x,v3.y,v3.z)); + if (!me.IsDone()) { + PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(me.Status())); + return -1; + } + + Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast(getGeomEllipsePtr()->handle()); + ellipse->SetElips(me.Value()->Elips()); + return 0; + } + + char* keywords_cmm[] = {"Center","MajorRadius","MinorRadius",NULL}; + PyErr_Clear(); + PyObject *pV; + double major, minor; + if (PyArg_ParseTupleAndKeywords(args, kwds, "O!dd", keywords_cmm, + &(Base::VectorPy::Type), &pV, + &major, &minor)) { + Base::Vector3d c = static_cast(pV)->value(); + GC_MakeEllipse me(gp_Ax2(gp_Pnt(c.x,c.y,c.z), gp_Dir(0.0,0.0,1.0)), + major, minor); + if (!me.IsDone()) { + PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(me.Status())); + return -1; + } + + Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast(getGeomEllipsePtr()->handle()); + ellipse->SetElips(me.Value()->Elips()); + return 0; + } + + PyErr_SetString(PyExc_TypeError, "Ellipse constructor accepts:\n" + "-- empty parameter list\n" + "-- Ellipse\n" + "-- Point, double, double\n" + "-- Point, Point, Point"); + return -1; +#endif +} +#if 0 +Py::Float Ellipse2dPy::getMajorRadius(void) const +{ + Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast(getGeomEllipsePtr()->handle()); + return Py::Float(ellipse->MajorRadius()); +} + +void Ellipse2dPy::setMajorRadius(Py::Float arg) +{ + Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast(getGeomEllipsePtr()->handle()); + ellipse->SetMajorRadius((double)arg); +} + +Py::Float Ellipse2dPy::getMinorRadius(void) const +{ + Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast(getGeomEllipsePtr()->handle()); + return Py::Float(ellipse->MinorRadius()); +} + +void Ellipse2dPy::setMinorRadius(Py::Float arg) +{ + Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast(getGeomEllipsePtr()->handle()); + ellipse->SetMinorRadius((double)arg); +} + +Py::Float Ellipse2dPy::getAngleXU(void) const +{ + Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast(getGeomEllipsePtr()->handle()); + + gp_Pnt center = ellipse->Axis().Location(); + gp_Dir normal = ellipse->Axis().Direction(); + gp_Dir xdir = ellipse->XAxis().Direction(); + + gp_Ax2 xdirref(center, normal); // this is a reference system, might be CCW or CW depending on the creation method + + return Py::Float(-xdir.AngleWithRef(xdirref.XDirection(),normal)); + +} + +void Ellipse2dPy::setAngleXU(Py::Float arg) +{ + Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast(getGeomEllipsePtr()->handle()); + + + gp_Pnt center = ellipse->Axis().Location(); + gp_Dir normal = ellipse->Axis().Direction(); + + gp_Ax1 normaxis(center, normal); + + gp_Ax2 xdirref(center, normal); + + xdirref.Rotate(normaxis,arg); + + ellipse->SetPosition(xdirref); + +} + +Py::Float Ellipse2dPy::getEccentricity(void) const +{ + Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast(getGeomEllipsePtr()->handle()); + return Py::Float(ellipse->Eccentricity()); +} + +Py::Float Ellipse2dPy::getFocal(void) const +{ + Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast(getGeomEllipsePtr()->handle()); + return Py::Float(ellipse->Focal()); +} + +Py::Object Ellipse2dPy::getFocus1(void) const +{ + Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast(getGeomEllipsePtr()->handle()); + gp_Pnt loc = ellipse->Focus1(); + return Py::Vector(Base::Vector3d(loc.X(), loc.Y(), loc.Z())); +} + +Py::Object Ellipse2dPy::getFocus2(void) const +{ + Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast(getGeomEllipsePtr()->handle()); + gp_Pnt loc = ellipse->Focus2(); + return Py::Vector(Base::Vector3d(loc.X(), loc.Y(), loc.Z())); +} + +Py::Object Ellipse2dPy::getCenter(void) const +{ + Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast(getGeomEllipsePtr()->handle()); + gp_Pnt loc = ellipse->Location(); + return Py::Vector(Base::Vector3d(loc.X(), loc.Y(), loc.Z())); +} + +void Ellipse2dPy::setCenter(Py::Object arg) +{ + PyObject* p = arg.ptr(); + if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) { + Base::Vector3d loc = static_cast(p)->value(); + Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast(getGeomEllipsePtr()->handle()); + ellipse->SetLocation(gp_Pnt(loc.x, loc.y, loc.z)); + } + else if (PyTuple_Check(p)) { + Py::Tuple tuple(arg); + gp_Pnt loc; + loc.SetX((double)Py::Float(tuple.getItem(0))); + loc.SetY((double)Py::Float(tuple.getItem(1))); + loc.SetZ((double)Py::Float(tuple.getItem(2))); + Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast(getGeomEllipsePtr()->handle()); + ellipse->SetLocation(loc); + } + else { + std::string error = std::string("type must be 'Vector', not "); + error += p->ob_type->tp_name; + throw Py::TypeError(error); + } +} + +Py::Object Ellipse2dPy::getAxis(void) const +{ + Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast(getGeomEllipsePtr()->handle()); + gp_Ax1 axis = ellipse->Axis(); + gp_Dir dir = axis.Direction(); + return Py::Vector(Base::Vector3d(dir.X(), dir.Y(), dir.Z())); +} + +void Ellipse2dPy::setAxis(Py::Object arg) +{ + PyObject* p = arg.ptr(); + Base::Vector3d val; + if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) { + val = static_cast(p)->value(); + } + else if (PyTuple_Check(p)) { + val = Base::getVectorFromTuple(p); + } + else { + std::string error = std::string("type must be 'Vector', not "); + error += p->ob_type->tp_name; + throw Py::TypeError(error); + } + + Handle_Geom_Ellipse ellipse = Handle_Geom_Ellipse::DownCast(getGeomEllipsePtr()->handle()); + try { + gp_Ax1 axis; + axis.SetLocation(ellipse->Location()); + axis.SetDirection(gp_Dir(val.x, val.y, val.z)); + ellipse->SetAxis(axis); + } + catch (Standard_Failure) { + throw Py::Exception("cannot set axis"); + } +} +#endif +PyObject *Ellipse2dPy::getCustomAttributes(const char* /*attr*/) const +{ + return 0; +} + +int Ellipse2dPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) +{ + return 0; +} diff --git a/src/Mod/Part/App/Geom2d/Geometry2dPy.xml b/src/Mod/Part/App/Geom2d/Geometry2dPy.xml new file mode 100644 index 000000000000..47281bb9f90e --- /dev/null +++ b/src/Mod/Part/App/Geom2d/Geometry2dPy.xml @@ -0,0 +1,54 @@ + + + + + + The abstract class Geometry for 2D space is the root class of all geometric objects. +It describes the common behavior of these objects when: +- applying geometric transformations to objects, and +- constructing objects by geometric transformation (including copying). + + + + diff --git a/src/Mod/Part/App/Geom2d/Geometry2dPyImp.cpp b/src/Mod/Part/App/Geom2d/Geometry2dPyImp.cpp new file mode 100644 index 000000000000..b650b5f044d6 --- /dev/null +++ b/src/Mod/Part/App/Geom2d/Geometry2dPyImp.cpp @@ -0,0 +1,201 @@ +/*************************************************************************** + * Copyright (c) 2016 Werner Mayer * + * * + * 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 * + * * + ***************************************************************************/ + + +#include "PreCompiled.h" +#ifndef _PreComp_ +# include +# include +# include +# include +# include +# include +# include +# include +#endif + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include + +using namespace Part; + +// returns a string which represents the object e.g. when printed in python +std::string Geometry2dPy::representation(void) const +{ + return ""; +} + +PyObject *Geometry2dPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper +{ + // never create such objects with the constructor + PyErr_SetString(PyExc_RuntimeError, + "You cannot create an instance of the abstract class 'Geometry'."); + return 0; +} + +// constructor method +int Geometry2dPy::PyInit(PyObject* /*args*/, PyObject* /*kwd*/) +{ + return 0; +} +#if 0 +PyObject* Geometry2dPy::mirror(PyObject *args) +{ + PyObject* o; + if (PyArg_ParseTuple(args, "O!", Base::Vector2dPy::type_object(),&o)) { + Base::Vector2d vec = static_cast(o)->getValue(); + gp_Pnt2d pnt(vec.x, vec.y); + getGeometry2dPtr()->handle()->Mirror(pnt); + Py_Return; + } + + PyErr_Clear(); + PyObject* axis; + if (PyArg_ParseTuple(args, "O!O!", Base::Vector2dPy::type_object(),&o, + Base::Vector2dPy::type_object(),&axis)) { + Base::Vector2d pnt = static_cast(o)->getValue(); + Base::Vector2d dir = static_cast(axis)->getValue(); + gp_Ax2d ax1(gp_Pnt2d(pnt.x,pnt.y), gp_Dir2d(dir.x,dir.y)); + getGeometry2dPtr()->handle()->Mirror(ax1); + Py_Return; + } + + PyErr_SetString(PartExceptionOCCError, "either a point (vector) or axis (vector, vector) must be given"); + return 0; +} + +PyObject* Geometry2dPy::rotate(PyObject *args) +{ + PyObject* o; + if (!PyArg_ParseTuple(args, "O!", &(Base::PlacementPy::Type),&o)) + return 0; + + Base::Placement* plm = static_cast(o)->getPlacementPtr(); + Base::Rotation rot(plm->getRotation()); + Base::Vector3d pnt, dir; + double angle; + + rot.getValue(dir, angle); + pnt = plm->getPosition(); + + getGeometry2dPtr()->handle()->Rotate(gp_Pnt2d(pnt.x,pnt.y), angle); + Py_Return; +} + +PyObject* Geometry2dPy::scale(PyObject *args) +{ + PyObject* o; + double scale; + Base::Vector2d vec; + if (PyArg_ParseTuple(args, "O!d", Base::Vector2dPy::type_object(),&o, &scale)) { + vec = static_cast(o)->getValue(); + gp_Pnt2d pnt(vec.x, vec.y); + getGeometry2dPtr()->handle()->Scale(pnt, scale); + Py_Return; + } + + PyErr_SetString(PartExceptionOCCError, "either vector or tuple and float expected"); + return 0; +} + +PyObject* Geometry2dPy::transform(PyObject *args) +{ + PyObject* o; + if (!PyArg_ParseTuple(args, "O!", &(Base::MatrixPy::Type),&o)) + return 0; + Base::Matrix4D mat = static_cast(o)->value(); + gp_Trsf trf; + trf.SetValues(mat[0][0],mat[0][1],mat[0][2],mat[0][3], + mat[1][0],mat[1][1],mat[1][2],mat[1][3], + mat[2][0],mat[2][1],mat[2][2],mat[2][3] +#if OCC_VERSION_HEX < 0x060800 + , 0.00001,0.00001 +#endif + ); //precision was removed in OCCT CR0025194 + getGeometry2dPtr()->handle()->Transform(trf); + Py_Return; +} + +PyObject* Geometry2dPy::translate(PyObject *args) +{ + PyObject* o; + Base::Vector2d vec; + if (PyArg_ParseTuple(args, "O!", Base::Vector2dPy::type_object(),&o)) { + vec = static_cast(o)->getValue(); + gp_Vec2d trl(vec.x, vec.y); + getGeometry2dPtr()->handle()->Translate(trl); + Py_Return; + } + + PyErr_SetString(PartExceptionOCCError, "either vector or tuple expected"); + return 0; +} + +PyObject* Geometry2dPy::copy(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) + return NULL; + + Part::Geometry2d* geom = this->getGeometry2dPtr(); + PyTypeObject* type = this->GetType(); + PyObject* cpy = 0; + // let the type object decide + if (type->tp_new) + cpy = type->tp_new(type, this, 0); + if (!cpy) { + PyErr_SetString(PyExc_TypeError, "failed to create copy of geometry"); + return 0; + } + + Part::Geometry2dPy* geompy = static_cast(cpy); + // the PyMake function must have created the corresponding instance of the 'Geometry' subclass + // so delete it now to avoid a memory leak + if (geompy->_pcTwinPointer) { + Part::Geometry2d* clone = static_cast(geompy->_pcTwinPointer); + delete clone; + } + geompy->_pcTwinPointer = geom->clone(); + return cpy; +} +#endif +PyObject *Geometry2dPy::getCustomAttributes(const char* /*attr*/) const +{ + return 0; +} + +int Geometry2dPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) +{ + return 0; +} diff --git a/src/Mod/Part/App/Geom2d/Hyperbola2dPy.xml b/src/Mod/Part/App/Geom2d/Hyperbola2dPy.xml new file mode 100644 index 000000000000..d5f5be6118a6 --- /dev/null +++ b/src/Mod/Part/App/Geom2d/Hyperbola2dPy.xml @@ -0,0 +1,99 @@ + + + + + + Describes an hyperbola in 3D space + To create an hyperbola there are several ways: + Part.Hyperbola() + Creates an hyperbola with major radius 2 and minor radius 1 with the + center in (0,0,0) + + Part.Hyperbola(Hyperbola) + Create a copy of the given hyperbola + + Part.Hyperbola(S1,S2,Center) + Creates an hyperbola centered on the point Center, where + the plane of the hyperbola is defined by Center, S1 and S2, + its major axis is defined by Center and S1, + its major radius is the distance between Center and S1, and + its minor radius is the distance between S2 and the major axis. + + Part.Hyperbola(Center,MajorRadius,MinorRadius) + Creates an hyperbola with major and minor radii MajorRadius and + MinorRadius, and located in the plane defined by Center and + the normal (0,0,1) + + + + + diff --git a/src/Mod/Part/App/Geom2d/Hyperbola2dPyImp.cpp b/src/Mod/Part/App/Geom2d/Hyperbola2dPyImp.cpp new file mode 100644 index 000000000000..dd35130ceed3 --- /dev/null +++ b/src/Mod/Part/App/Geom2d/Hyperbola2dPyImp.cpp @@ -0,0 +1,290 @@ +/*************************************************************************** + * Copyright (c) 2008 Werner Mayer * + * * + * 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 * + * * + ***************************************************************************/ + + +#include "PreCompiled.h" +#ifndef _PreComp_ +# include +# include +# include +#endif + +#include +#include + +#include +#include +#include +#include + +using namespace Part; + +extern const char* gce_ErrorStatusText(gce_ErrorType et); + +// returns a string which represents the object e.g. when printed in python +std::string Hyperbola2dPy::representation(void) const +{ + return ""; +} + +PyObject *Hyperbola2dPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper +{ + // create a new instance of Hyperbola2dPy and the Twin object + return new Hyperbola2dPy(new Geom2dHyperbola); +} + +// constructor method +int Hyperbola2dPy::PyInit(PyObject* args, PyObject* kwds) +{ + return 0; +#if 0 + char* keywords_n[] = {NULL}; + if (PyArg_ParseTupleAndKeywords(args, kwds, "", keywords_n)) { + Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(getGeomHyperbolaPtr()->handle()); + hyperbola->SetMajorRadius(2.0); + hyperbola->SetMinorRadius(1.0); + return 0; + } + + char* keywords_e[] = {"Hyperbola",NULL}; + PyErr_Clear(); + PyObject *pHypr; + if (PyArg_ParseTupleAndKeywords(args, kwds, "O!",keywords_e, &(Hyperbola2dPy::Type), &pHypr)) { + Hyperbola2dPy* pHyperbola = static_cast(pHypr); + Handle_Geom_Hyperbola Hypr1 = Handle_Geom_Hyperbola::DownCast + (pHyperbola->getGeomHyperbolaPtr()->handle()); + Handle_Geom_Hyperbola Hypr2 = Handle_Geom_Hyperbola::DownCast + (this->getGeomHyperbolaPtr()->handle()); + Hypr2->SetHypr(Hypr1->Hypr()); + return 0; + } + + char* keywords_ssc[] = {"S1","S2","Center",NULL}; + PyErr_Clear(); + PyObject *pV1, *pV2, *pV3; + if (PyArg_ParseTupleAndKeywords(args, kwds, "O!O!O!", keywords_ssc, + &(Base::VectorPy::Type), &pV1, + &(Base::VectorPy::Type), &pV2, + &(Base::VectorPy::Type), &pV3)) { + Base::Vector3d v1 = static_cast(pV1)->value(); + Base::Vector3d v2 = static_cast(pV2)->value(); + Base::Vector3d v3 = static_cast(pV3)->value(); + GC_MakeHyperbola me(gp_Pnt(v1.x,v1.y,v1.z), + gp_Pnt(v2.x,v2.y,v2.z), + gp_Pnt(v3.x,v3.y,v3.z)); + if (!me.IsDone()) { + PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(me.Status())); + return -1; + } + + Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(getGeomHyperbolaPtr()->handle()); + hyperbola->SetHypr(me.Value()->Hypr()); + return 0; + } + + char* keywords_cmm[] = {"Center","MajorRadius","MinorRadius",NULL}; + PyErr_Clear(); + PyObject *pV; + double major, minor; + if (PyArg_ParseTupleAndKeywords(args, kwds, "O!dd", keywords_cmm, + &(Base::VectorPy::Type), &pV, + &major, &minor)) { + Base::Vector3d c = static_cast(pV)->value(); + GC_MakeHyperbola me(gp_Ax2(gp_Pnt(c.x,c.y,c.z), gp_Dir(0.0,0.0,1.0)), + major, minor); + if (!me.IsDone()) { + PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(me.Status())); + return -1; + } + + Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(getGeomHyperbolaPtr()->handle()); + hyperbola->SetHypr(me.Value()->Hypr()); + return 0; + } + + PyErr_SetString(PyExc_TypeError, "Hyperbola constructor accepts:\n" + "-- empty parameter list\n" + "-- Hyperbola\n" + "-- Point, double, double\n" + "-- Point, Point, Point"); + return -1; +#endif +} +#if 0 +Py::Float Hyperbola2dPy::getMajorRadius(void) const +{ + Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(getGeomHyperbolaPtr()->handle()); + return Py::Float(hyperbola->MajorRadius()); +} + +void Hyperbola2dPy::setMajorRadius(Py::Float arg) +{ + Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(getGeomHyperbolaPtr()->handle()); + hyperbola->SetMajorRadius((double)arg); +} + +Py::Float Hyperbola2dPy::getMinorRadius(void) const +{ + Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(getGeomHyperbolaPtr()->handle()); + return Py::Float(hyperbola->MinorRadius()); +} + +void Hyperbola2dPy::setMinorRadius(Py::Float arg) +{ + Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(getGeomHyperbolaPtr()->handle()); + hyperbola->SetMinorRadius((double)arg); +} + +Py::Float Hyperbola2dPy::getAngleXU(void) const +{ + Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(getGeomHyperbolaPtr()->handle()); + + gp_Pnt center = hyperbola->Axis().Location(); + gp_Dir normal = hyperbola->Axis().Direction(); + gp_Dir xdir = hyperbola->XAxis().Direction(); + + gp_Ax2 xdirref(center, normal); // this is a reference system, might be CCW or CW depending on the creation method + + return Py::Float(-xdir.AngleWithRef(xdirref.XDirection(),normal)); + +} + +void Hyperbola2dPy::setAngleXU(Py::Float arg) +{ + Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(getGeomHyperbolaPtr()->handle()); + + + gp_Pnt center = hyperbola->Axis().Location(); + gp_Dir normal = hyperbola->Axis().Direction(); + + gp_Ax1 normaxis(center, normal); + + gp_Ax2 xdirref(center, normal); + + xdirref.Rotate(normaxis,arg); + + hyperbola->SetPosition(xdirref); + +} + +Py::Float Hyperbola2dPy::getEccentricity(void) const +{ + Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(getGeomHyperbolaPtr()->handle()); + return Py::Float(hyperbola->Eccentricity()); +} + +Py::Float Hyperbola2dPy::getFocal(void) const +{ + Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(getGeomHyperbolaPtr()->handle()); + return Py::Float(hyperbola->Focal()); +} + +Py::Object Hyperbola2dPy::getFocus1(void) const +{ + Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(getGeomHyperbolaPtr()->handle()); + gp_Pnt loc = hyperbola->Focus1(); + return Py::Vector(Base::Vector3d(loc.X(), loc.Y(), loc.Z())); +} + +Py::Object Hyperbola2dPy::getFocus2(void) const +{ + Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(getGeomHyperbolaPtr()->handle()); + gp_Pnt loc = hyperbola->Focus2(); + return Py::Vector(Base::Vector3d(loc.X(), loc.Y(), loc.Z())); +} + +Py::Object Hyperbola2dPy::getCenter(void) const +{ + Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(getGeomHyperbolaPtr()->handle()); + gp_Pnt loc = hyperbola->Location(); + return Py::Vector(Base::Vector3d(loc.X(), loc.Y(), loc.Z())); +} + +void Hyperbola2dPy::setCenter(Py::Object arg) +{ + PyObject* p = arg.ptr(); + if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) { + Base::Vector3d loc = static_cast(p)->value(); + Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(getGeomHyperbolaPtr()->handle()); + hyperbola->SetLocation(gp_Pnt(loc.x, loc.y, loc.z)); + } + else if (PyTuple_Check(p)) { + Py::Tuple tuple(arg); + gp_Pnt loc; + loc.SetX((double)Py::Float(tuple.getItem(0))); + loc.SetY((double)Py::Float(tuple.getItem(1))); + loc.SetZ((double)Py::Float(tuple.getItem(2))); + Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(getGeomHyperbolaPtr()->handle()); + hyperbola->SetLocation(loc); + } + else { + std::string error = std::string("type must be 'Vector', not "); + error += p->ob_type->tp_name; + throw Py::TypeError(error); + } +} + +Py::Object Hyperbola2dPy::getAxis(void) const +{ + Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(getGeomHyperbolaPtr()->handle()); + gp_Ax1 axis = hyperbola->Axis(); + gp_Dir dir = axis.Direction(); + return Py::Vector(Base::Vector3d(dir.X(), dir.Y(), dir.Z())); +} + +void Hyperbola2dPy::setAxis(Py::Object arg) +{ + PyObject* p = arg.ptr(); + Base::Vector3d val; + if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) { + val = static_cast(p)->value(); + } + else if (PyTuple_Check(p)) { + val = Base::getVectorFromTuple(p); + } + else { + std::string error = std::string("type must be 'Vector', not "); + error += p->ob_type->tp_name; + throw Py::TypeError(error); + } + + Handle_Geom_Hyperbola hyperbola = Handle_Geom_Hyperbola::DownCast(getGeomHyperbolaPtr()->handle()); + try { + gp_Ax1 axis; + axis.SetLocation(hyperbola->Location()); + axis.SetDirection(gp_Dir(val.x, val.y, val.z)); + hyperbola->SetAxis(axis); + } + catch (Standard_Failure) { + throw Py::Exception("cannot set axis"); + } +} +#endif +PyObject *Hyperbola2dPy::getCustomAttributes(const char* /*attr*/) const +{ + return 0; +} + +int Hyperbola2dPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) +{ + return 0; +} diff --git a/src/Mod/Part/App/Geom2d/Line2dSegmentPy.xml b/src/Mod/Part/App/Geom2d/Line2dSegmentPy.xml new file mode 100644 index 000000000000..9a13cb2fb4ac --- /dev/null +++ b/src/Mod/Part/App/Geom2d/Line2dSegmentPy.xml @@ -0,0 +1,52 @@ + + + + + + Describes an infinite line +To create a line there are several ways: +Part.Line() + Creates a default line + +Part.Line(Line) + Creates a copy of the given line + +Part.Line(Point1,Point2) + Creates a line that goes through two given points + + + + diff --git a/src/Mod/Part/App/Geom2d/Line2dSegmentPyImp.cpp b/src/Mod/Part/App/Geom2d/Line2dSegmentPyImp.cpp new file mode 100644 index 000000000000..07f16d50bb92 --- /dev/null +++ b/src/Mod/Part/App/Geom2d/Line2dSegmentPyImp.cpp @@ -0,0 +1,332 @@ +/*************************************************************************** + * Copyright (c) 2016 Werner Mayer * + * * + * 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 * + * * + ***************************************************************************/ + + +#include "PreCompiled.h" +#ifndef _PreComp_ +# include +# include +# include +# include +# include +# include +# include +#endif + +#include +#include + +#include +#include +#include +#include + +using namespace Part; + +extern const char* gce_ErrorStatusText(gce_ErrorType et); + +// returns a string which represents the object e.g. when printed in python +std::string Line2dSegmentPy::representation(void) const +{ + std::stringstream str; + //if(Infinite) + // str << ""; + //else { + Base::Vector2d start = getGeom2dLineSegmentPtr()->getStartPoint(); + Base::Vector2d end = getGeom2dLineSegmentPtr()->getEndPoint(); + str << ""; + //} + + return str.str(); +} + +PyObject *Line2dSegmentPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper +{ + // create a new instance of Line2dSegmentPy and the Twin object + return new Line2dSegmentPy(new Geom2dLineSegment); +} + +// constructor method +int Line2dSegmentPy::PyInit(PyObject* args, PyObject* /*kwd*/) +{ +#if 1 + return 0; +#else + if (PyArg_ParseTuple(args, "")) { + // default line + Infinite=false; + return 0; + } + + PyErr_Clear(); + PyObject *pLine; + if (PyArg_ParseTuple(args, "O!", &(Line2dSegmentPy::Type), &pLine)) { + // Copy line + Line2dSegmentPy* pcLine = static_cast(pLine); + // get Geom_Line of line segment + Handle_Geom_TrimmedCurve that_curv = Handle_Geom_TrimmedCurve::DownCast + (pcLine->getGeom2dLineSegmentPtr()->handle()); + Handle_Geom_Line that_line = Handle_Geom_Line::DownCast + (that_curv->BasisCurve()); + // get Geom_Line of line segment + Handle_Geom_TrimmedCurve this_curv = Handle_Geom_TrimmedCurve::DownCast + (this->getGeom2dLineSegmentPtr()->handle()); + Handle_Geom_Line this_line = Handle_Geom_Line::DownCast + (this_curv->BasisCurve()); + + Infinite = pcLine->Infinite; + + // Assign the lines + this_line->SetLin(that_line->Lin()); + this_curv->SetTrim(that_curv->FirstParameter(), that_curv->LastParameter()); + return 0; + } + + PyErr_Clear(); + double first, last; + if (PyArg_ParseTuple(args, "O!dd", &(Line2dSegmentPy::Type), &pLine, &first, &last)) { + // Copy line + Line2dSegmentPy* pcLine = static_cast(pLine); + // get Geom_Line of line segment + Handle_Geom_TrimmedCurve that_curv = Handle_Geom_TrimmedCurve::DownCast + (pcLine->getGeom2dLineSegmentPtr()->handle()); + Handle_Geom_Line that_line = Handle_Geom_Line::DownCast + (that_curv->BasisCurve()); + // get Geom_Line of line segment + Handle_Geom_TrimmedCurve this_curv = Handle_Geom_TrimmedCurve::DownCast + (this->getGeom2dLineSegmentPtr()->handle()); + Handle_Geom_Line this_line = Handle_Geom_Line::DownCast + (this_curv->BasisCurve()); + + Infinite = pcLine->Infinite; + + // Assign the lines + this_line->SetLin(that_line->Lin()); + this_curv->SetTrim(first, last); + return 0; + } + + PyErr_Clear(); + PyObject *pV1, *pV2; + if (PyArg_ParseTuple(args, "O!O!", &(Base::VectorPy::Type), &pV1, + &(Base::VectorPy::Type), &pV2)) { + Base::Vector3d v1 = static_cast(pV1)->value(); + Base::Vector3d v2 = static_cast(pV2)->value(); + try { + // Create line out of two points + double distance = Base::Distance(v1, v2); + if (distance < gp::Resolution()) + Standard_Failure::Raise("Both points are equal"); + GC_MakeSegment ms(gp_Pnt(v1.x,v1.y,v1.z), + gp_Pnt(v2.x,v2.y,v2.z)); + if (!ms.IsDone()) { + PyErr_SetString(PartExceptionOCCError, gce_ErrorStatusText(ms.Status())); + return -1; + } + + // get Geom_Line of line segment + Handle_Geom_TrimmedCurve this_curv = Handle_Geom_TrimmedCurve::DownCast + (this->getGeom2dLineSegmentPtr()->handle()); + Handle_Geom_Line this_line = Handle_Geom_Line::DownCast + (this_curv->BasisCurve()); + Handle_Geom_TrimmedCurve that_curv = ms.Value(); + Handle_Geom_Line that_line = Handle_Geom_Line::DownCast(that_curv->BasisCurve()); + this_line->SetLin(that_line->Lin()); + this_curv->SetTrim(that_curv->FirstParameter(), that_curv->LastParameter()); + + Infinite = false; + return 0; + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); + return -1; + } + catch (...) { + PyErr_SetString(PartExceptionOCCError, "creation of line failed"); + return -1; + } + } + + PyErr_SetString(PyExc_TypeError, "Line constructor accepts:\n" + "-- empty parameter list\n" + "-- Line\n" + "-- Point, Point"); + return -1; +#endif +} +#if 0 +PyObject* Line2dSegmentPy::setParameterRange(PyObject *args) +{ + double first, last; + if (!PyArg_ParseTuple(args, "dd", &first, &last)) + return NULL; + + try { + Handle_Geom_TrimmedCurve this_curve = Handle_Geom_TrimmedCurve::DownCast + (this->getGeom2dLineSegmentPtr()->handle()); + this_curve->SetTrim(first, last); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); + return NULL; + } + + Py_Return; +} + +Py::Object Line2dSegmentPy::getStartPoint(void) const +{ + Handle_Geom_TrimmedCurve this_curve = Handle_Geom_TrimmedCurve::DownCast + (this->getGeom2dLineSegmentPtr()->handle()); + gp_Pnt pnt = this_curve->StartPoint(); + return Py::Vector(Base::Vector3d(pnt.X(), pnt.Y(), pnt.Z())); +} + +void Line2dSegmentPy::setStartPoint(Py::Object arg) +{ + gp_Pnt p1, p2; + Handle_Geom_TrimmedCurve this_curv = Handle_Geom_TrimmedCurve::DownCast + (this->getGeom2dLineSegmentPtr()->handle()); + p2 = this_curv->EndPoint(); + + PyObject *p = arg.ptr(); + if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) { + Base::Vector3d v = static_cast(p)->value(); + p1.SetX(v.x); + p1.SetY(v.y); + p1.SetZ(v.z); + } + else if (PyTuple_Check(p)) { + Py::Tuple tuple(arg); + p1.SetX((double)Py::Float(tuple.getItem(0))); + p1.SetY((double)Py::Float(tuple.getItem(1))); + p1.SetZ((double)Py::Float(tuple.getItem(2))); + } + else { + std::string error = std::string("type must be 'Vector' or tuple, not "); + error += p->ob_type->tp_name; + throw Py::TypeError(error); + } + + try { + // Create line out of two points + if (p1.Distance(p2) < gp::Resolution()) + Standard_Failure::Raise("Both points are equal"); + GC_MakeSegment ms(p1, p2); + if (!ms.IsDone()) { + throw Py::Exception(gce_ErrorStatusText(ms.Status())); + } + + // get Geom_Line of line segment + Handle_Geom_Line this_line = Handle_Geom_Line::DownCast + (this_curv->BasisCurve()); + Handle_Geom_TrimmedCurve that_curv = ms.Value(); + Handle_Geom_Line that_line = Handle_Geom_Line::DownCast(that_curv->BasisCurve()); + this_line->SetLin(that_line->Lin()); + this_curv->SetTrim(that_curv->FirstParameter(), that_curv->LastParameter()); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + throw Py::Exception(e->GetMessageString()); + } +} + +Py::Object Line2dSegmentPy::getEndPoint(void) const +{ + Handle_Geom_TrimmedCurve this_curve = Handle_Geom_TrimmedCurve::DownCast + (this->getGeom2dLineSegmentPtr()->handle()); + gp_Pnt pnt = this_curve->EndPoint(); + return Py::Vector(Base::Vector3d(pnt.X(), pnt.Y(), pnt.Z())); +} + +void Line2dSegmentPy::setEndPoint(Py::Object arg) +{ + gp_Pnt p1, p2; + Handle_Geom_TrimmedCurve this_curv = Handle_Geom_TrimmedCurve::DownCast + (this->getGeom2dLineSegmentPtr()->handle()); + p1 = this_curv->StartPoint(); + + PyObject *p = arg.ptr(); + if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) { + Base::Vector3d v = static_cast(p)->value(); + p2.SetX(v.x); + p2.SetY(v.y); + p2.SetZ(v.z); + } + else if (PyTuple_Check(p)) { + Py::Tuple tuple(arg); + p2.SetX((double)Py::Float(tuple.getItem(0))); + p2.SetY((double)Py::Float(tuple.getItem(1))); + p2.SetZ((double)Py::Float(tuple.getItem(2))); + } + else { + std::string error = std::string("type must be 'Vector' or tuple, not "); + error += p->ob_type->tp_name; + throw Py::TypeError(error); + } + + try { + // Create line out of two points + if (p1.Distance(p2) < gp::Resolution()) + Standard_Failure::Raise("Both points are equal"); + GC_MakeSegment ms(p1, p2); + if (!ms.IsDone()) { + throw Py::Exception(gce_ErrorStatusText(ms.Status())); + } + + // get Geom_Line of line segment + Handle_Geom_Line this_line = Handle_Geom_Line::DownCast + (this_curv->BasisCurve()); + Handle_Geom_TrimmedCurve that_curv = ms.Value(); + Handle_Geom_Line that_line = Handle_Geom_Line::DownCast(that_curv->BasisCurve()); + this_line->SetLin(that_line->Lin()); + this_curv->SetTrim(that_curv->FirstParameter(), that_curv->LastParameter()); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + throw Py::Exception(e->GetMessageString()); + } +} + +Py::Boolean Line2dSegmentPy::getInfinite(void) const +{ + return Py::Boolean(Infinite); +} + +void Line2dSegmentPy::setInfinite(Py::Boolean arg) +{ + Infinite = arg; +} +#endif +PyObject *Line2dSegmentPy::getCustomAttributes(const char* /*attr*/) const +{ + return 0; +} + +int Line2dSegmentPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) +{ + return 0; +} diff --git a/src/Mod/Part/App/Geom2d/OffsetCurve2dPy.xml b/src/Mod/Part/App/Geom2d/OffsetCurve2dPy.xml new file mode 100644 index 000000000000..7a10f5c79fd2 --- /dev/null +++ b/src/Mod/Part/App/Geom2d/OffsetCurve2dPy.xml @@ -0,0 +1,44 @@ + + + + + + + + + + diff --git a/src/Mod/Part/App/Geom2d/OffsetCurve2dPyImp.cpp b/src/Mod/Part/App/Geom2d/OffsetCurve2dPyImp.cpp new file mode 100644 index 000000000000..ef424604b626 --- /dev/null +++ b/src/Mod/Part/App/Geom2d/OffsetCurve2dPyImp.cpp @@ -0,0 +1,165 @@ +/*************************************************************************** + * Copyright (c) 2008 Werner Mayer * + * * + * 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 * + * * + ***************************************************************************/ + + +#include "PreCompiled.h" +#ifndef _PreComp_ +# include +#endif + +#include +#include +#include +#include + +#include +#include +#include + +using namespace Part; + +// returns a string which represents the object e.g. when printed in python +std::string OffsetCurve2dPy::representation(void) const +{ + return ""; +} + +PyObject *OffsetCurve2dPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper +{ + // create a new instance of OffsetCurve2dPy and the Twin object + return new OffsetCurve2dPy(new Geom2dOffsetCurve); +} + +// constructor method +int OffsetCurve2dPy::PyInit(PyObject* args, PyObject* /*kwd*/) +{ + return 0; +#if 0 + PyObject* pGeom; + PyObject* pDir; + double offset; + if (!PyArg_ParseTuple(args, "O!dO!", + &(GeometryPy::Type), &pGeom, + &offset, + &(Base::VectorPy::Type),&pDir)) + return -1; + + GeometryPy* pcGeo = static_cast(pGeom); + Handle_Geom_Curve curve = Handle_Geom_Curve::DownCast + (pcGeo->getGeometryPtr()->handle()); + if (curve.IsNull()) { + PyErr_SetString(PyExc_TypeError, "geometry is not a curve"); + return -1; + } + + try { + Base::Vector3d dir = static_cast(pDir)->value(); + Handle_Geom_OffsetCurve curve2 = new Geom_OffsetCurve(curve, offset, gp_Dir(dir.x,dir.y,dir.z)); + getGeomOffsetCurvePtr()->setHandle(curve2); + return 0; + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); + return -1; + } +#endif +} +#if 0 +Py::Float OffsetCurve2dPy::getOffsetValue(void) const +{ + Handle_Geom_OffsetCurve curve = Handle_Geom_OffsetCurve::DownCast(getGeometryPtr()->handle()); + return Py::Float(curve->Offset()); +} + +void OffsetCurve2dPy::setOffsetValue(Py::Float arg) +{ + Handle_Geom_OffsetCurve curve = Handle_Geom_OffsetCurve::DownCast(getGeometryPtr()->handle()); + curve->SetOffsetValue((double)arg); +} + +Py::Object OffsetCurve2dPy::getOffsetDirection(void) const +{ + Handle_Geom_OffsetCurve curve = Handle_Geom_OffsetCurve::DownCast(getGeometryPtr()->handle()); + const gp_Dir& dir = curve->Direction(); + return Py::Vector(Base::Vector3d(dir.X(),dir.Y(),dir.Z())); +} + +void OffsetCurve2dPy::setOffsetDirection(Py::Object arg) +{ + PyObject* p = arg.ptr(); + if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) { + Base::Vector3d dir = static_cast(p)->value(); + Handle_Geom_OffsetCurve curve = Handle_Geom_OffsetCurve::DownCast(getGeometryPtr()->handle()); + curve->SetDirection(gp_Dir(dir.x,dir.y,dir.z)); + } + else if (PyObject_TypeCheck(p, &PyTuple_Type)) { + Base::Vector3d dir = Base::getVectorFromTuple(p); + Handle_Geom_OffsetCurve curve = Handle_Geom_OffsetCurve::DownCast(getGeometryPtr()->handle()); + curve->SetDirection(gp_Dir(dir.x,dir.y,dir.z)); + } + else { + std::string error = std::string("type must be 'Vector', not "); + error += p->ob_type->tp_name; + throw Py::TypeError(error); + } +} + +Py::Object OffsetCurve2dPy::getBasisCurve(void) const +{ + Handle_Geom_OffsetCurve curve = Handle_Geom_OffsetCurve::DownCast(getGeometryPtr()->handle()); + Handle_Geom_Curve basis = curve->BasisCurve(); + throw Py::Exception(PyExc_NotImplementedError, "Not yet implemented"); +} + +void OffsetCurve2dPy::setBasisCurve(Py::Object arg) +{ + PyObject* p = arg.ptr(); + if (PyObject_TypeCheck(p, &(GeometryPy::Type))) { + GeometryPy* pcGeo = static_cast(p); + Handle_Geom_Curve curve = Handle_Geom_Curve::DownCast + (pcGeo->getGeometryPtr()->handle()); + if (curve.IsNull()) { + throw Py::TypeError("geometry is not a curve"); + } + + try { + Handle_Geom_OffsetCurve curve2 = Handle_Geom_OffsetCurve::DownCast + (getGeometryPtr()->handle()); + curve2->SetBasisCurve(curve); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + throw Py::Exception(e->GetMessageString()); + } + } +} +#endif +PyObject *OffsetCurve2dPy::getCustomAttributes(const char* /*attr*/) const +{ + return 0; +} + +int OffsetCurve2dPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) +{ + return 0; +} diff --git a/src/Mod/Part/App/Geom2d/Parabola2dPy.xml b/src/Mod/Part/App/Geom2d/Parabola2dPy.xml new file mode 100644 index 000000000000..7f9fe6e0a05e --- /dev/null +++ b/src/Mod/Part/App/Geom2d/Parabola2dPy.xml @@ -0,0 +1,69 @@ + + + + + + Describes a parabola in 3D space + + + + diff --git a/src/Mod/Part/App/Geom2d/Parabola2dPyImp.cpp b/src/Mod/Part/App/Geom2d/Parabola2dPyImp.cpp new file mode 100644 index 000000000000..4b34b2002c72 --- /dev/null +++ b/src/Mod/Part/App/Geom2d/Parabola2dPyImp.cpp @@ -0,0 +1,228 @@ +/*************************************************************************** + * Copyright (c) 2008 Werner Mayer * + * * + * 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 * + * * + ***************************************************************************/ + + +#include "PreCompiled.h" +#ifndef _PreComp_ +# include +#endif + +#include +#include + +#include +#include +#include +#include + +using namespace Part; + +// returns a string which represents the object e.g. when printed in python +std::string Parabola2dPy::representation(void) const +{ + return ""; +} + +PyObject *Parabola2dPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper +{ + // create a new instance of Parabola2dPy and the Twin object + return new Parabola2dPy(new Geom2dParabola); +} + +// constructor method +int Parabola2dPy::PyInit(PyObject* args, PyObject* /*kwd*/) +{ + if (PyArg_ParseTuple(args, "")) { + Handle_Geom2d_Parabola c = Handle_Geom2d_Parabola::DownCast + (getGeometry2dPtr()->handle()); + c->SetFocal(1.0); + return 0; + } + + return -1; +} +#if 0 +PyObject* Parabola2dPy::compute(PyObject *args) +{ + PyObject *p1, *p2, *p3; + if (!PyArg_ParseTuple(args, "O!O!O!", + &Base::VectorPy::Type,&p1, + &Base::VectorPy::Type,&p2, + &Base::VectorPy::Type,&p3)) + return 0; + Base::Vector3d v1 = Py::Vector(p1,false).toVector(); + Base::Vector3d v2 = Py::Vector(p2,false).toVector(); + Base::Vector3d v3 = Py::Vector(p3,false).toVector(); + Base::Vector3d c = (v1-v2) % (v3-v2); + double zValue = v1.z; + if (fabs(c.Length()) < 0.0001) { + PyErr_SetString(PartExceptionOCCError, "Points are collinear"); + return 0; + } + + Base::Matrix4D m; + Base::Vector3d v; + m[0][0] = v1.y * v1.y; + m[0][1] = v1.y; + m[0][2] = 1; + m[1][0] = v2.y * v2.y; + m[1][1] = v2.y; + m[1][2] = 1; + m[2][0] = v3.y * v3.y; + m[2][1] = v3.y; + m[2][2] = 1.0; + v.x = v1.x; + v.y = v2.x; + v.z = v3.x; + m.inverseGauss(); + v = m * v; + double a22 = v.x; + double a10 = -0.5; + double a20 = v.y/2.0; + double a00 = v.z; + Handle_Geom_Parabola curve = Handle_Geom_Parabola::DownCast(getGeometryPtr()->handle()); + curve->SetFocal(0.5*fabs(a10/a22)); + curve->SetLocation(gp_Pnt((a20*a20-a22*a00)/(2*a22*a10), -a20/a22, zValue)); + + Py_Return; +} + +Py::Float Parabola2dPy::getEccentricity(void) const +{ + Handle_Geom_Parabola curve = Handle_Geom_Parabola::DownCast(getGeometryPtr()->handle()); + return Py::Float(curve->Eccentricity()); +} + +Py::Float Parabola2dPy::getFocal(void) const +{ + Handle_Geom_Parabola curve = Handle_Geom_Parabola::DownCast(getGeometryPtr()->handle()); + return Py::Float(curve->Focal()); +} + +void Parabola2dPy::setFocal(Py::Float arg) +{ + Handle_Geom_Parabola curve = Handle_Geom_Parabola::DownCast(getGeometryPtr()->handle()); + curve->SetFocal((double)arg); +} + +Py::Object Parabola2dPy::getFocus(void) const +{ + Handle_Geom_Parabola c = Handle_Geom_Parabola::DownCast + (getGeometryPtr()->handle()); + gp_Pnt loc = c->Focus(); + return Py::Vector(Base::Vector3d(loc.X(), loc.Y(), loc.Z())); +} + +Py::Float Parabola2dPy::getParameter(void) const +{ + Handle_Geom_Parabola curve = Handle_Geom_Parabola::DownCast(getGeometryPtr()->handle()); + return Py::Float(curve->Parameter()); +} + +Py::Object Parabola2dPy::getLocation(void) const +{ + Handle_Geom_Parabola c = Handle_Geom_Parabola::DownCast + (getGeometryPtr()->handle()); + gp_Pnt loc = c->Location(); + return Py::Vector(Base::Vector3d(loc.X(), loc.Y(), loc.Z())); +} + +void Parabola2dPy::setLocation(Py::Object arg) +{ + PyObject* p = arg.ptr(); + if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) { + Base::Vector3d loc = static_cast(p)->value(); + Handle_Geom_Parabola c = Handle_Geom_Parabola::DownCast + (getGeometryPtr()->handle()); + c->SetLocation(gp_Pnt(loc.x, loc.y, loc.z)); + } + else if (PyTuple_Check(p)) { + Py::Tuple tuple(arg); + gp_Pnt loc; + loc.SetX((double)Py::Float(tuple.getItem(0))); + loc.SetY((double)Py::Float(tuple.getItem(1))); + loc.SetZ((double)Py::Float(tuple.getItem(2))); + Handle_Geom_Parabola c = Handle_Geom_Parabola::DownCast + (getGeometryPtr()->handle()); + c->SetLocation(loc); + } + else { + std::string error = std::string("type must be 'Vector', not "); + error += p->ob_type->tp_name; + throw Py::TypeError(error); + } +} + +Py::Object Parabola2dPy::getAxis(void) const +{ + Handle_Geom_Parabola c = Handle_Geom_Parabola::DownCast + (getGeometryPtr()->handle()); + gp_Dir dir = c->Axis().Direction(); + return Py::Vector(Base::Vector3d(dir.X(), dir.Y(), dir.Z())); +} + +void Parabola2dPy::setAxis(Py::Object arg) +{ + Standard_Real dir_x, dir_y, dir_z; + PyObject *p = arg.ptr(); + if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) { + Base::Vector3d v = static_cast(p)->value(); + dir_x = v.x; + dir_y = v.y; + dir_z = v.z; + } + else if (PyTuple_Check(p)) { + Py::Tuple tuple(arg); + dir_x = (double)Py::Float(tuple.getItem(0)); + dir_y = (double)Py::Float(tuple.getItem(1)); + dir_z = (double)Py::Float(tuple.getItem(2)); + } + else { + std::string error = std::string("type must be 'Vector' or tuple, not "); + error += p->ob_type->tp_name; + throw Py::TypeError(error); + } + + try { + Handle_Geom_Parabola this_curv = Handle_Geom_Parabola::DownCast + (this->getGeometryPtr()->handle()); + gp_Ax1 axis; + axis.SetLocation(this_curv->Location()); + axis.SetDirection(gp_Dir(dir_x, dir_y, dir_z)); + this_curv->SetAxis(axis); + } + catch (Standard_Failure) { + throw Py::Exception("cannot set axis"); + } +} +#endif +PyObject *Parabola2dPy::getCustomAttributes(const char* /*attr*/) const +{ + return 0; +} + +int Parabola2dPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) +{ + return 0; +} + + diff --git a/src/Mod/Part/App/Geometry2d.cpp b/src/Mod/Part/App/Geometry2d.cpp index b7b44339490b..c14ceb83ce68 100644 --- a/src/Mod/Part/App/Geometry2d.cpp +++ b/src/Mod/Part/App/Geometry2d.cpp @@ -577,54 +577,110 @@ PyObject *Geom2dBSplineCurve::getPyObject(void) // ------------------------------------------------- -TYPESYSTEM_SOURCE(Part::Geom2dCircle, Part::Geom2dCurve) +TYPESYSTEM_SOURCE_ABSTRACT(Part::Geom2dConic, Part::Geom2dCurve) -Geom2dCircle::Geom2dCircle() +Geom2dConic::Geom2dConic() { - Handle_Geom2d_Circle c = new Geom2d_Circle(gp_Circ2d()); - this->myCurve = c; } -Geom2dCircle::Geom2dCircle(const Handle_Geom2d_Circle& c) +Geom2dConic::~Geom2dConic() { - this->myCurve = Handle_Geom2d_Circle::DownCast(c->Copy()); } -Geom2dCircle::~Geom2dCircle() +Base::Vector2d Geom2dConic::getCenter(void) const { + Handle_Geom2d_Conic conic = Handle_Geom2d_Conic::DownCast(handle()); + const gp_Pnt2d& loc = conic->Location(); + return Base::Vector2d(loc.X(),loc.Y()); } -const Handle_Geom2d_Geometry& Geom2dCircle::handle() const +void Geom2dConic::setCenter(const Base::Vector2d& Center) { - return myCurve; + gp_Pnt2d p1(Center.x,Center.y); + Handle_Geom2d_Conic conic = Handle_Geom2d_Conic::DownCast(handle()); + + try { + conic->SetLocation(p1); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + throw Base::Exception(e->GetMessageString()); + } } -Geometry2d *Geom2dCircle::clone(void) const +bool Geom2dConic::isReversed() const { - Geom2dCircle *newCirc = new Geom2dCircle(myCurve); - return newCirc; + Handle_Geom2d_Conic conic = Handle_Geom2d_Conic::DownCast(handle()); + gp_Dir2d xdir = conic->XAxis().Direction(); + gp_Dir2d ydir = conic->YAxis().Direction(); + + Base::Vector3d xd(xdir.X(), xdir.Y(), 0); + Base::Vector3d yd(ydir.X(), ydir.Y(), 0); + Base::Vector3d zd = xd.Cross(yd); + return zd.z < 0; } -Base::Vector2d Geom2dCircle::getCenter(void) const +void Geom2dConic::SaveAxis(Base::Writer& writer, const gp_Ax22d& axis) const { - Handle_Geom2d_Circle circle = Handle_Geom2d_Circle::DownCast(handle()); - const gp_Pnt2d& loc = circle->Location(); - return Base::Vector2d(loc.X(),loc.Y()); + gp_Pnt2d center = axis.Location(); + gp_Dir2d xdir = axis.XDirection(); + gp_Dir2d ydir = axis.YDirection(); + writer.Stream() + << "CenterX=\"" << center.X() << "\" " + << "CenterY=\"" << center.Y() << "\" " + << "XAxisX=\"" << xdir.X() << "\" " + << "XAxisY=\"" << xdir.Y() << "\" " + << "YAxisX=\"" << ydir.X() << "\" " + << "YAxisY=\"" << ydir.Y() << "\" "; } -double Geom2dCircle::getRadius(void) const +void Geom2dConic::RestoreAxis(Base::XMLReader& reader, gp_Ax22d& axis) { - Handle_Geom2d_Circle circle = Handle_Geom2d_Circle::DownCast(handle()); - return circle->Radius(); + double CenterX,CenterY,XdirX,XdirY,YdirX,YdirY; + CenterX = reader.getAttributeAsFloat("CenterX"); + CenterY = reader.getAttributeAsFloat("CenterY"); + XdirX = reader.getAttributeAsFloat("XAxisX"); + XdirY = reader.getAttributeAsFloat("XAxisY"); + YdirX = reader.getAttributeAsFloat("YAxisX"); + YdirY = reader.getAttributeAsFloat("YAxisY"); + + // set the read geometry + gp_Pnt2d p1(CenterX,CenterY); + gp_Dir2d xdir(XdirX,XdirY); + gp_Dir2d ydir(YdirX,YdirY); + axis.SetLocation(p1); + axis.SetXDirection(xdir); + axis.SetYDirection(ydir); +} + +// ------------------------------------------------- + +TYPESYSTEM_SOURCE_ABSTRACT(Part::Geom2dArcOfConic, Part::Geom2dCurve) + +Geom2dArcOfConic::Geom2dArcOfConic() +{ +} + +Geom2dArcOfConic::~Geom2dArcOfConic() +{ +} + +Base::Vector2d Geom2dArcOfConic::getCenter(void) const +{ + Handle_Geom2d_TrimmedCurve curve = Handle_Geom2d_TrimmedCurve::DownCast(handle()); + Handle_Geom2d_Conic conic = Handle_Geom2d_Conic::DownCast(curve->BasisCurve()); + const gp_Pnt2d& loc = conic->Location(); + return Base::Vector2d(loc.X(),loc.Y()); } -void Geom2dCircle::setCenter(const Base::Vector2d& Center) +void Geom2dArcOfConic::setCenter(const Base::Vector2d& Center) { gp_Pnt2d p1(Center.x,Center.y); - Handle_Geom2d_Circle circle = Handle_Geom2d_Circle::DownCast(handle()); + Handle_Geom2d_TrimmedCurve curve = Handle_Geom2d_TrimmedCurve::DownCast(handle()); + Handle_Geom2d_Conic conic = Handle_Geom2d_Conic::DownCast(curve->BasisCurve()); try { - circle->SetLocation(p1); + conic->SetLocation(p1); } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); @@ -632,14 +688,63 @@ void Geom2dCircle::setCenter(const Base::Vector2d& Center) } } -void Geom2dCircle::setRadius(double Radius) +bool Geom2dArcOfConic::isReversed() const { - Handle_Geom2d_Circle circle = Handle_Geom2d_Circle::DownCast(handle()); + Handle_Geom2d_TrimmedCurve curve = Handle_Geom2d_TrimmedCurve::DownCast(handle()); + Handle_Geom2d_Conic conic = Handle_Geom2d_Conic::DownCast(curve->BasisCurve()); + gp_Dir2d xdir = conic->XAxis().Direction(); + gp_Dir2d ydir = conic->YAxis().Direction(); + + Base::Vector3d xd(xdir.X(), xdir.Y(), 0); + Base::Vector3d yd(ydir.X(), ydir.Y(), 0); + Base::Vector3d zd = xd.Cross(yd); + return zd.z < 0; +} + +/*! + * \brief Geom2dArcOfConic::getStartPoint + * \return XY of the arc's starting point. + */ +Base::Vector2d Geom2dArcOfConic::getStartPoint() const +{ + Handle_Geom2d_TrimmedCurve curve = Handle_Geom2d_TrimmedCurve::DownCast(handle()); + gp_Pnt2d pnt = curve->StartPoint(); + return Base::Vector2d(pnt.X(), pnt.Y()); +} + +/*! + * \brief Geom2dArcOfConic::getEndPoint + * \return XY of the arc's ending point. + */ +Base::Vector2d Geom2dArcOfConic::getEndPoint() const +{ + Handle_Geom2d_TrimmedCurve curve = Handle_Geom2d_TrimmedCurve::DownCast(handle()); + gp_Pnt2d pnt = curve->EndPoint(); + return Base::Vector2d(pnt.X(), pnt.Y()); +} + +/*! + * \brief Geom2dArcOfConic::getRange + * \param u [out] start angle of the arc, in radians. + * \param v [out] end angle of the arc, in radians. + */ +void Geom2dArcOfConic::getRange(double& u, double& v) const +{ + Handle_Geom2d_TrimmedCurve curve = Handle_Geom2d_TrimmedCurve::DownCast(handle()); + u = curve->FirstParameter(); + v = curve->LastParameter(); +} +/*! + * \brief Geom2dArcOfConic::setRange + * \param u [in] start angle of the arc, in radians. + * \param v [in] end angle of the arc, in radians. + */ +void Geom2dArcOfConic::setRange(double u, double v) +{ try { - gp_Circ2d c = circle->Circ2d(); - c.SetRadius(Radius); - circle->SetCirc2d(c); + Handle_Geom2d_TrimmedCurve curve = Handle_Geom2d_TrimmedCurve::DownCast(handle()); + curve->SetTrim(u, v); } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); @@ -647,18 +752,92 @@ void Geom2dCircle::setRadius(double Radius) } } -bool Geom2dCircle::isReversed() const +void Geom2dArcOfConic::SaveAxis(Base::Writer& writer, const gp_Ax22d& axis, double u, double v) const +{ + gp_Pnt2d center = axis.Location(); + gp_Dir2d xdir = axis.XDirection(); + gp_Dir2d ydir = axis.YDirection(); + writer.Stream() + << "CenterX=\"" << center.X() << "\" " + << "CenterY=\"" << center.Y() << "\" " + << "XAxisX=\"" << xdir.X() << "\" " + << "XAxisY=\"" << xdir.Y() << "\" " + << "YAxisX=\"" << ydir.X() << "\" " + << "YAxisY=\"" << ydir.Y() << "\" " + << "FirstParameter=\"" << u << "\" " + << "LastParameter=\"" << v << "\" "; +} + +void Geom2dArcOfConic::RestoreAxis(Base::XMLReader& reader, gp_Ax22d& axis, double& u, double &v) +{ + double CenterX,CenterY,XdirX,XdirY,YdirX,YdirY; + CenterX = reader.getAttributeAsFloat("CenterX"); + CenterY = reader.getAttributeAsFloat("CenterY"); + XdirX = reader.getAttributeAsFloat("XAxisX"); + XdirY = reader.getAttributeAsFloat("XAxisY"); + YdirX = reader.getAttributeAsFloat("YAxisX"); + YdirY = reader.getAttributeAsFloat("YAxisY"); + u = reader.getAttributeAsFloat("FirstParameter"); + v = reader.getAttributeAsFloat("LastParameter"); + + // set the read geometry + gp_Pnt2d p1(CenterX,CenterY); + gp_Dir2d xdir(XdirX,XdirY); + gp_Dir2d ydir(YdirX,YdirY); + axis.SetLocation(p1); + axis.SetXDirection(xdir); + axis.SetYDirection(ydir); +} + +// ------------------------------------------------- + +TYPESYSTEM_SOURCE(Part::Geom2dCircle, Part::Geom2dConic) + +Geom2dCircle::Geom2dCircle() +{ + Handle_Geom2d_Circle c = new Geom2d_Circle(gp_Circ2d()); + this->myCurve = c; +} + +Geom2dCircle::Geom2dCircle(const Handle_Geom2d_Circle& c) +{ + this->myCurve = Handle_Geom2d_Circle::DownCast(c->Copy()); +} + +Geom2dCircle::~Geom2dCircle() +{ +} + +const Handle_Geom2d_Geometry& Geom2dCircle::handle() const +{ + return myCurve; +} + +Geometry2d *Geom2dCircle::clone(void) const +{ + Geom2dCircle *newCirc = new Geom2dCircle(myCurve); + return newCirc; +} + +double Geom2dCircle::getRadius(void) const { Handle_Geom2d_Circle circle = Handle_Geom2d_Circle::DownCast(handle()); - gp_Circ2d c = circle->Circ2d(); - gp_Ax22d loc = c.Axis(); - gp_Dir2d xdir = loc.XDirection(); - gp_Dir2d ydir = loc.YDirection(); + return circle->Radius(); +} - Base::Vector3d xd(xdir.X(), xdir.Y(), 0); - Base::Vector3d yd(ydir.X(), ydir.Y(), 0); - Base::Vector3d zd = xd.Cross(yd); - return zd.z < 0; +void Geom2dCircle::setRadius(double Radius) +{ + Handle_Geom2d_Circle circle = Handle_Geom2d_Circle::DownCast(handle()); + + try { + gp_Circ2d c = circle->Circ2d(); + c.SetRadius(Radius); + circle->SetCirc2d(c); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + throw Base::Exception(e->GetMessageString()); + } } unsigned int Geom2dCircle::getMemSize (void) const @@ -673,20 +852,13 @@ void Geom2dCircle::Save(Base::Writer& writer) const Handle_Geom2d_Circle circle = Handle_Geom2d_Circle::DownCast(handle()); gp_Circ2d c = circle->Circ2d(); - gp_Ax22d loc = c.Axis(); - gp_Pnt2d center = loc.Location(); - gp_Dir2d xdir = loc.XDirection(); - gp_Dir2d ydir = loc.YDirection(); + gp_Ax22d axis = c.Axis(); writer.Stream() << writer.ind() - << "" << endl; } @@ -696,25 +868,16 @@ void Geom2dCircle::Restore(Base::XMLReader& reader) // read the attributes of the father class Geom2dCurve::Restore(reader); - double CenterX,CenterY,XdirX,XdirY,YdirX,YdirY,Radius; + double Radius; + gp_Ax22d axis; // read my Element reader.readElement("Geom2dCircle"); // get the value of my Attribute - CenterX = reader.getAttributeAsFloat("CenterX"); - CenterY = reader.getAttributeAsFloat("CenterY"); - XdirX = reader.getAttributeAsFloat("XAxisX"); - XdirY = reader.getAttributeAsFloat("XAxisY"); - YdirX = reader.getAttributeAsFloat("YAxisX"); - YdirY = reader.getAttributeAsFloat("YAxisY"); + RestoreAxis(reader, axis); Radius = reader.getAttributeAsFloat("Radius"); - // set the read geometry - gp_Pnt2d p1(CenterX,CenterY); - gp_Dir2d xdir(XdirX,XdirY); - gp_Dir2d ydir(YdirX,YdirY); try { - gp_Ax22d loc(p1, xdir, ydir); - GCE2d_MakeCircle mc(loc, Radius); + GCE2d_MakeCircle mc(axis, Radius); if (!mc.IsDone()) throw Base::Exception(gce_ErrorStatusText(mc.Status())); @@ -734,7 +897,7 @@ PyObject *Geom2dCircle::getPyObject(void) // ------------------------------------------------- -TYPESYSTEM_SOURCE(Part::Geom2dArcOfCircle, Part::Geom2dCurve) +TYPESYSTEM_SOURCE(Part::Geom2dArcOfCircle, Part::Geom2dArcOfConic) Geom2dArcOfCircle::Geom2dArcOfCircle() { @@ -771,53 +934,12 @@ Geometry2d *Geom2dArcOfCircle::clone(void) const return copy; } -/*! - * \brief Geom2dArcOfCircle::getStartPoint - * \return XY of the arc's starting point. - */ -Base::Vector2d Geom2dArcOfCircle::getStartPoint() const -{ - gp_Pnt2d pnt = this->myCurve->StartPoint(); - return Base::Vector2d(pnt.X(), pnt.Y()); -} - -/*! - * \brief Geom2dArcOfCircle::getEndPoint - * \return XY of the arc's ending point. - */ -Base::Vector2d Geom2dArcOfCircle::getEndPoint() const -{ - gp_Pnt2d pnt = this->myCurve->EndPoint(); - return Base::Vector2d(pnt.X(), pnt.Y()); -} - -Base::Vector2d Geom2dArcOfCircle::getCenter(void) const -{ - Handle_Geom2d_Circle circle = Handle_Geom2d_Circle::DownCast(myCurve->BasisCurve()); - const gp_Pnt2d& loc = circle->Location(); - return Base::Vector2d(loc.X(),loc.Y()); -} - double Geom2dArcOfCircle::getRadius(void) const { Handle_Geom2d_Circle circle = Handle_Geom2d_Circle::DownCast(myCurve->BasisCurve()); return circle->Radius(); } -void Geom2dArcOfCircle::setCenter(const Base::Vector2d& Center) -{ - gp_Pnt2d p1(Center.x,Center.y); - Handle_Geom2d_Circle circle = Handle_Geom2d_Circle::DownCast(myCurve->BasisCurve()); - - try { - circle->SetLocation(p1); - } - catch (Standard_Failure) { - Handle_Standard_Failure e = Standard_Failure::Caught(); - throw Base::Exception(e->GetMessageString()); - } -} - void Geom2dArcOfCircle::setRadius(double Radius) { Handle_Geom2d_Circle circle = Handle_Geom2d_Circle::DownCast(myCurve->BasisCurve()); @@ -833,55 +955,6 @@ void Geom2dArcOfCircle::setRadius(double Radius) } } -/*! - * \brief Geom2dArcOfCircle::getRange - * \param u [out] start angle of the arc, in radians. - * \param v [out] end angle of the arc, in radians. - */ -void Geom2dArcOfCircle::getRange(double& u, double& v) const -{ - u = myCurve->FirstParameter(); - v = myCurve->LastParameter(); -} - -/*! - * \brief Geom2dArcOfCircle::setRange - * \param u [in] start angle of the arc, in radians. - * \param v [in] end angle of the arc, in radians. - */ -void Geom2dArcOfCircle::setRange(double u, double v) -{ - - try { - myCurve->SetTrim(u, v); - } - catch (Standard_Failure) { - Handle_Standard_Failure e = Standard_Failure::Caught(); - throw Base::Exception(e->GetMessageString()); - } -} - -/*! - * \brief Geom2dArcOfCircle::isReversedInXY - * \return tests if an arc that lies in XY plane is reversed (i.e. drawn from - * startpoint to endpoint in CW direction instead of CCW.). Returns True if the - * arc is CW and false if CCW. - */ -bool Geom2dArcOfCircle::isReversed() const -{ - Handle_Geom2d_Circle circle = Handle_Geom2d_Circle::DownCast(myCurve->BasisCurve()); - assert(!circle.IsNull()); - gp_Circ2d c = circle->Circ2d(); - gp_Ax22d loc = c.Axis(); - gp_Dir2d xdir = loc.XDirection(); - gp_Dir2d ydir = loc.YDirection(); - - Base::Vector3d xd(xdir.X(), xdir.Y(), 0); - Base::Vector3d yd(ydir.X(), ydir.Y(), 0); - Base::Vector3d zd = xd.Cross(yd); - return zd.z < 0; -} - unsigned int Geom2dArcOfCircle::getMemSize (void) const { return sizeof(Geom2d_Circle) + 2 *sizeof(double); @@ -895,23 +968,16 @@ void Geom2dArcOfCircle::Save(Base::Writer &writer) const Handle_Geom2d_Circle circle = Handle_Geom2d_Circle::DownCast(this->myCurve->BasisCurve()); gp_Circ2d c = circle->Circ2d(); - gp_Ax22d loc = c.Axis(); - gp_Pnt2d center = loc.Location(); - gp_Dir2d xdir = loc.XDirection(); - gp_Dir2d ydir = loc.YDirection(); + gp_Ax22d axis = c.Axis(); + double u = this->myCurve->FirstParameter(); + double v = this->myCurve->LastParameter(); writer.Stream() << writer.ind() - << "myCurve->FirstParameter() << "\" " - << "Last=\"" << this->myCurve->LastParameter() << "\" " << "/>" << endl; } @@ -920,31 +986,19 @@ void Geom2dArcOfCircle::Restore(Base::XMLReader &reader) // read the attributes of the father class Geom2dCurve::Restore(reader); - double CenterX,CenterY,XdirX,XdirY,YdirX,YdirY,Radius,First,Last; + double Radius,u,v; + gp_Ax22d axis; // read my Element reader.readElement("Geom2dArcOfCircle"); // get the value of my Attribute - CenterX = reader.getAttributeAsFloat("CenterX"); - CenterY = reader.getAttributeAsFloat("CenterY"); - XdirX = reader.getAttributeAsFloat("XAxisX"); - XdirY = reader.getAttributeAsFloat("XAxisY"); - YdirX = reader.getAttributeAsFloat("YAxisX"); - YdirY = reader.getAttributeAsFloat("YAxisY"); + RestoreAxis(reader, axis, u, v); Radius = reader.getAttributeAsFloat("Radius"); - First = reader.getAttributeAsFloat("First"); - Last = reader.getAttributeAsFloat("Last"); - - // set the read geometry - gp_Pnt2d p1(CenterX,CenterY); - gp_Dir2d xdir(XdirX,XdirY); - gp_Dir2d ydir(YdirX,YdirY); - gp_Ax22d axis(p1, xdir, ydir); try { GCE2d_MakeCircle mc(axis, Radius); if (!mc.IsDone()) throw Base::Exception(gce_ErrorStatusText(mc.Status())); - GCE2d_MakeArcOfCircle ma(mc.Value()->Circ2d(), First, Last); + GCE2d_MakeArcOfCircle ma(mc.Value()->Circ2d(), u, v); if (!ma.IsDone()) throw Base::Exception(gce_ErrorStatusText(ma.Status())); @@ -969,7 +1023,7 @@ PyObject *Geom2dArcOfCircle::getPyObject(void) // ------------------------------------------------- -TYPESYSTEM_SOURCE(Part::Geom2dEllipse, Part::Geom2dCurve) +TYPESYSTEM_SOURCE(Part::Geom2dEllipse, Part::Geom2dConic) Geom2dEllipse::Geom2dEllipse() { @@ -997,27 +1051,6 @@ Geometry2d *Geom2dEllipse::clone(void) const return newEllipse; } -Base::Vector2d Geom2dEllipse::getCenter(void) const -{ - Handle_Geom2d_Ellipse ellipse = Handle_Geom2d_Ellipse::DownCast(handle()); - const gp_Pnt2d& loc = ellipse->Location(); - return Base::Vector2d(loc.X(),loc.Y()); -} - -void Geom2dEllipse::setCenter(const Base::Vector2d& Center) -{ - gp_Pnt2d p1(Center.x,Center.y); - Handle_Geom2d_Ellipse ellipse = Handle_Geom2d_Ellipse::DownCast(handle()); - - try { - ellipse->SetLocation(p1); - } - catch (Standard_Failure) { - Handle_Standard_Failure e = Standard_Failure::Caught(); - throw Base::Exception(e->GetMessageString()); - } -} - double Geom2dEllipse::getMajorRadius(void) const { Handle_Geom2d_Ellipse ellipse = Handle_Geom2d_Ellipse::DownCast(handle()); @@ -1092,26 +1125,6 @@ void Geom2dEllipse::setMajorAxisDir(Base::Vector2d newdir) } } -/*! - * \brief Geom2dEllipse::isReversed tests if an ellipse is reversed - * (i.e. drawn from startpoint to endpoint in CW direction instead - * of CCW.) - * \return Returns True if the arc is CW and false if CCW. - */ -bool Geom2dEllipse::isReversed() const -{ - Handle_Geom2d_Ellipse ellipse = Handle_Geom2d_Ellipse::DownCast(handle()); - gp_Elips2d e = ellipse->Elips2d(); - gp_Ax22d loc = e.Axis(); - gp_Dir2d xdir = loc.XDirection(); - gp_Dir2d ydir = loc.YDirection(); - - Base::Vector3d xd(xdir.X(), xdir.Y(), 0); - Base::Vector3d yd(ydir.X(), ydir.Y(), 0); - Base::Vector3d zd = xd.Cross(yd); - return zd.z < 0; -} - unsigned int Geom2dEllipse::getMemSize (void) const { return sizeof(Geom2d_Ellipse); @@ -1123,19 +1136,13 @@ void Geom2dEllipse::Save(Base::Writer& writer) const Geom2dCurve::Save(writer); gp_Elips2d e = this->myCurve->Elips2d(); - gp_Pnt2d center = e.Location(); - gp_Dir2d xdir = e.Axis().XDirection(); - gp_Dir2d ydir = e.Axis().YDirection(); + gp_Ax22d axis = e.Axis(); writer.Stream() << writer.ind() - << "" << endl; @@ -1146,24 +1153,14 @@ void Geom2dEllipse::Restore(Base::XMLReader& reader) // read the attributes of the father class Geom2dCurve::Restore(reader); - double CenterX,CenterY,XAxisX,XAxisY,YAxisX,YAxisY,MajorRadius,MinorRadius; + double MajorRadius,MinorRadius; + gp_Ax22d axis; // read my Element reader.readElement("Geom2dEllipse"); // get the value of my Attribute - CenterX = reader.getAttributeAsFloat("CenterX"); - CenterY = reader.getAttributeAsFloat("CenterY"); - XAxisX = reader.getAttributeAsFloat("XAxisX"); - XAxisY = reader.getAttributeAsFloat("XAxisY"); - YAxisX = reader.getAttributeAsFloat("YAxisX"); - YAxisY = reader.getAttributeAsFloat("YAxisY"); + RestoreAxis(reader, axis); MajorRadius = reader.getAttributeAsFloat("MajorRadius"); MinorRadius = reader.getAttributeAsFloat("MinorRadius"); - - // set the read geometry - gp_Pnt2d p1(CenterX,CenterY); - gp_Dir2d xdir(XAxisX,XAxisY); - gp_Dir2d ydir(YAxisX,YAxisY); - gp_Ax22d axis(p1, xdir, ydir); try { GCE2d_MakeEllipse mc(axis, MajorRadius, MinorRadius); @@ -1191,7 +1188,7 @@ void Geom2dEllipse::setHandle(const Handle_Geom2d_Ellipse &e) // ------------------------------------------------- -TYPESYSTEM_SOURCE(Part::Geom2dArcOfEllipse, Part::Geom2dCurve) +TYPESYSTEM_SOURCE(Part::Geom2dArcOfEllipse, Part::Geom2dArcOfConic) Geom2dArcOfEllipse::Geom2dArcOfEllipse() { @@ -1228,39 +1225,6 @@ Geometry2d *Geom2dArcOfEllipse::clone(void) const return copy; } -Base::Vector2d Geom2dArcOfEllipse::getStartPoint() const -{ - gp_Pnt2d pnt = this->myCurve->StartPoint(); - return Base::Vector2d(pnt.X(), pnt.Y()); -} - -Base::Vector2d Geom2dArcOfEllipse::getEndPoint() const -{ - gp_Pnt2d pnt = this->myCurve->EndPoint(); - return Base::Vector2d(pnt.X(), pnt.Y()); -} - -Base::Vector2d Geom2dArcOfEllipse::getCenter(void) const -{ - Handle_Geom2d_Ellipse ellipse = Handle_Geom2d_Ellipse::DownCast(myCurve->BasisCurve()); - const gp_Pnt2d& loc = ellipse->Location(); - return Base::Vector2d(loc.X(),loc.Y()); -} - -void Geom2dArcOfEllipse::setCenter(const Base::Vector2d& Center) -{ - gp_Pnt2d p1(Center.x,Center.y); - Handle_Geom2d_Ellipse ellipse = Handle_Geom2d_Ellipse::DownCast(myCurve->BasisCurve()); - - try { - ellipse->SetLocation(p1); - } - catch (Standard_Failure) { - Handle_Standard_Failure e = Standard_Failure::Caught(); - throw Base::Exception(e->GetMessageString()); - } -} - double Geom2dArcOfEllipse::getMajorRadius(void) const { Handle_Geom2d_Ellipse ellipse = Handle_Geom2d_Ellipse::DownCast(myCurve->BasisCurve()); @@ -1339,53 +1303,6 @@ void Geom2dArcOfEllipse::setMajorAxisDir(Base::Vector2d newdir) } } -/*! - * \brief Geom2dArcOfEllipse::isReversedInXY tests if an arc that lies in XY plane is reversed - * (i.e. drawn from startpoint to endpoint in CW direction instead of CCW.) - * \return Returns True if the arc is CW and false if CCW. - */ -bool Geom2dArcOfEllipse::isReversed() const -{ - Handle_Geom2d_Ellipse c = Handle_Geom2d_Ellipse::DownCast(myCurve->BasisCurve()); - assert(!c.IsNull()); - gp_Elips2d e = c->Elips2d(); - gp_Ax22d loc = e.Axis(); - gp_Dir2d xdir = loc.XDirection(); - gp_Dir2d ydir = loc.YDirection(); - - Base::Vector3d xd(xdir.X(), xdir.Y(), 0); - Base::Vector3d yd(ydir.X(), ydir.Y(), 0); - Base::Vector3d zd = xd.Cross(yd); - return zd.z < 0; -} - -/*! - * \brief Geom2dArcOfEllipse::getRange - * \param u [out] start angle of the arc, in radians. - * \param v [out] end angle of the arc, in radians. - */ -void Geom2dArcOfEllipse::getRange(double& u, double& v) const -{ - u = myCurve->FirstParameter(); - v = myCurve->LastParameter(); -} - -/*! - * \brief Geom2dArcOfEllipse::setRange - * \param u [in] start angle of the arc, in radians. - * \param v [in] end angle of the arc, in radians. - */ -void Geom2dArcOfEllipse::setRange(double u, double v) -{ - try { - myCurve->SetTrim(u, v); - } - catch (Standard_Failure) { - Handle_Standard_Failure e = Standard_Failure::Caught(); - throw Base::Exception(e->GetMessageString()); - } -} - unsigned int Geom2dArcOfEllipse::getMemSize (void) const { return sizeof(Geom2d_Ellipse) + 2 *sizeof(double); @@ -1399,23 +1316,17 @@ void Geom2dArcOfEllipse::Save(Base::Writer &writer) const Handle_Geom2d_Ellipse ellipse = Handle_Geom2d_Ellipse::DownCast(this->myCurve->BasisCurve()); gp_Elips2d e = ellipse->Elips2d(); - gp_Pnt2d center = e.Location(); - gp_Dir2d xdir = e.Axis().XDirection(); - gp_Dir2d ydir = e.Axis().YDirection(); + gp_Ax22d axis = e.Axis(); + double u = this->myCurve->FirstParameter(); + double v = this->myCurve->LastParameter(); writer.Stream() << writer.ind() - << "myCurve->FirstParameter() << "\" " - << "Last=\"" << this->myCurve->LastParameter() << "\" " << "/>" << endl; } @@ -1424,33 +1335,21 @@ void Geom2dArcOfEllipse::Restore(Base::XMLReader &reader) // read the attributes of the father class Geom2dCurve::Restore(reader); - double CenterX,CenterY,XAxisX,XAxisY,YAxisX,YAxisY,MajorRadius,MinorRadius,First,Last; + double MajorRadius,MinorRadius,u,v; + gp_Ax22d axis; // read my Element reader.readElement("Geom2dArcOfEllipse"); // get the value of my Attribute - CenterX = reader.getAttributeAsFloat("CenterX"); - CenterY = reader.getAttributeAsFloat("CenterY"); - XAxisX = reader.getAttributeAsFloat("XAxisX"); - XAxisY = reader.getAttributeAsFloat("XAxisY"); - YAxisX = reader.getAttributeAsFloat("YAxisX"); - YAxisY = reader.getAttributeAsFloat("YAxisY"); + RestoreAxis(reader, axis, u, v); MajorRadius = reader.getAttributeAsFloat("MajorRadius"); MinorRadius = reader.getAttributeAsFloat("MinorRadius"); - First = reader.getAttributeAsFloat("First"); - Last = reader.getAttributeAsFloat("Last"); - - // set the read geometry - gp_Pnt2d p1(CenterX,CenterY); - gp_Dir2d xdir(XAxisX,XAxisY); - gp_Dir2d ydir(YAxisX,YAxisY); - gp_Ax22d axis(p1, xdir, ydir); try { GCE2d_MakeEllipse mc(axis, MajorRadius, MinorRadius); if (!mc.IsDone()) throw Base::Exception(gce_ErrorStatusText(mc.Status())); - GCE2d_MakeArcOfEllipse ma(mc.Value()->Elips2d(), First, Last); + GCE2d_MakeArcOfEllipse ma(mc.Value()->Elips2d(), u, v); if (!ma.IsDone()) throw Base::Exception(gce_ErrorStatusText(ma.Status())); @@ -1475,7 +1374,7 @@ PyObject *Geom2dArcOfEllipse::getPyObject(void) // ------------------------------------------------- -TYPESYSTEM_SOURCE(Part::Geom2dHyperbola, Part::Geom2dCurve) +TYPESYSTEM_SOURCE(Part::Geom2dHyperbola, Part::Geom2dConic) Geom2dHyperbola::Geom2dHyperbola() { @@ -1503,27 +1402,6 @@ Geometry2d *Geom2dHyperbola::clone(void) const return newHyp; } -Base::Vector2d Geom2dHyperbola::getCenter(void) const -{ - Handle_Geom2d_Hyperbola h = Handle_Geom2d_Hyperbola::DownCast(handle()); - const gp_Pnt2d& loc = h->Location(); - return Base::Vector2d(loc.X(),loc.Y()); -} - -void Geom2dHyperbola::setCenter(const Base::Vector2d& Center) -{ - gp_Pnt2d p1(Center.x,Center.y); - Handle_Geom2d_Hyperbola h = Handle_Geom2d_Hyperbola::DownCast(handle()); - - try { - h->SetLocation(p1); - } - catch (Standard_Failure) { - Handle_Standard_Failure e = Standard_Failure::Caught(); - throw Base::Exception(e->GetMessageString()); - } -} - double Geom2dHyperbola::getMajorRadius(void) const { Handle_Geom2d_Hyperbola h = Handle_Geom2d_Hyperbola::DownCast(handle()); @@ -1573,19 +1451,13 @@ void Geom2dHyperbola::Save(Base::Writer& writer) const Geom2dCurve::Save(writer); gp_Hypr2d h = this->myCurve->Hypr2d(); - gp_Pnt2d center = h.Location(); - gp_Dir2d xdir = h.Axis().XDirection(); - gp_Dir2d ydir = h.Axis().YDirection(); + gp_Ax22d axis = h.Axis(); writer.Stream() << writer.ind() - << "" << endl; @@ -1596,25 +1468,15 @@ void Geom2dHyperbola::Restore(Base::XMLReader& reader) // read the attributes of the father class Geom2dCurve::Restore(reader); - double CenterX,CenterY,XAxisX,XAxisY,YAxisX,YAxisY,MajorRadius,MinorRadius; + double MajorRadius,MinorRadius; + gp_Ax22d axis; // read my Element reader.readElement("Geom2dHyperbola"); // get the value of my Attribute - CenterX = reader.getAttributeAsFloat("CenterX"); - CenterY = reader.getAttributeAsFloat("CenterY"); - XAxisX = reader.getAttributeAsFloat("XAxisX"); - XAxisY = reader.getAttributeAsFloat("XAxisY"); - YAxisX = reader.getAttributeAsFloat("YAxisX"); - YAxisY = reader.getAttributeAsFloat("YAxisY"); + RestoreAxis(reader, axis); MajorRadius = reader.getAttributeAsFloat("MajorRadius"); MinorRadius = reader.getAttributeAsFloat("MinorRadius"); - // set the read geometry - gp_Pnt2d p1(CenterX,CenterY); - gp_Dir2d xdir(XAxisX,XAxisY); - gp_Dir2d ydir(YAxisX,YAxisY); - gp_Ax22d axis(p1, xdir, ydir); - try { GCE2d_MakeHyperbola mc(axis, MajorRadius, MinorRadius); if (!mc.IsDone()) @@ -1636,7 +1498,7 @@ PyObject *Geom2dHyperbola::getPyObject(void) // ------------------------------------------------- -TYPESYSTEM_SOURCE(Part::Geom2dArcOfHyperbola, Part::Geom2dCurve) +TYPESYSTEM_SOURCE(Part::Geom2dArcOfHyperbola, Part::Geom2dArcOfConic) Geom2dArcOfHyperbola::Geom2dArcOfHyperbola() { @@ -1673,39 +1535,6 @@ Geometry2d *Geom2dArcOfHyperbola::clone(void) const return copy; } -Base::Vector2d Geom2dArcOfHyperbola::getStartPoint() const -{ - gp_Pnt2d pnt = this->myCurve->StartPoint(); - return Base::Vector2d(pnt.X(), pnt.Y()); -} - -Base::Vector2d Geom2dArcOfHyperbola::getEndPoint() const -{ - gp_Pnt2d pnt = this->myCurve->EndPoint(); - return Base::Vector2d(pnt.X(), pnt.Y()); -} - -Base::Vector2d Geom2dArcOfHyperbola::getCenter(void) const -{ - Handle_Geom2d_Hyperbola h = Handle_Geom2d_Hyperbola::DownCast(myCurve->BasisCurve()); - const gp_Pnt2d& loc = h->Location(); - return Base::Vector2d(loc.X(),loc.Y()); -} - -void Geom2dArcOfHyperbola::setCenter(const Base::Vector2d& Center) -{ - gp_Pnt2d p1(Center.x,Center.y); - Handle_Geom2d_Hyperbola h = Handle_Geom2d_Hyperbola::DownCast(myCurve->BasisCurve()); - - try { - h->SetLocation(p1); - } - catch (Standard_Failure) { - Handle_Standard_Failure e = Standard_Failure::Caught(); - throw Base::Exception(e->GetMessageString()); - } -} - double Geom2dArcOfHyperbola::getMajorRadius(void) const { Handle_Geom2d_Hyperbola h = Handle_Geom2d_Hyperbola::DownCast(myCurve->BasisCurve()); @@ -1744,23 +1573,6 @@ void Geom2dArcOfHyperbola::setMinorRadius(double Radius) } } -void Geom2dArcOfHyperbola::getRange(double& u, double& v) const -{ - u = myCurve->FirstParameter(); - v = myCurve->LastParameter(); -} - -void Geom2dArcOfHyperbola::setRange(double u, double v) -{ - try { - myCurve->SetTrim(u, v); - } - catch (Standard_Failure) { - Handle_Standard_Failure e = Standard_Failure::Caught(); - throw Base::Exception(e->GetMessageString()); - } -} - unsigned int Geom2dArcOfHyperbola::getMemSize (void) const { return sizeof(Geom2d_Hyperbola) + 2 *sizeof(double); @@ -1774,23 +1586,17 @@ void Geom2dArcOfHyperbola::Save(Base::Writer &writer) const Handle_Geom2d_Hyperbola hh = Handle_Geom2d_Hyperbola::DownCast(this->myCurve->BasisCurve()); gp_Hypr2d h = hh->Hypr2d(); - gp_Pnt2d center = h.Location(); - gp_Dir2d xdir = h.Axis().XDirection(); - gp_Dir2d ydir = h.Axis().YDirection(); + gp_Ax22d axis = h.Axis(); + double u = this->myCurve->FirstParameter(); + double v = this->myCurve->LastParameter(); writer.Stream() << writer.ind() - << "myCurve->FirstParameter() << "\" " - << "Last=\"" << this->myCurve->LastParameter() << "\" " << "/>" << endl; } @@ -1799,33 +1605,21 @@ void Geom2dArcOfHyperbola::Restore(Base::XMLReader &reader) // read the attributes of the father class Geom2dCurve::Restore(reader); - double CenterX,CenterY,XAxisX,XAxisY,YAxisX,YAxisY,MajorRadius,MinorRadius,First,Last; + double MajorRadius,MinorRadius,u,v; + gp_Ax22d axis; // read my Element reader.readElement("Geom2dHyperbola"); // get the value of my Attribute - CenterX = reader.getAttributeAsFloat("CenterX"); - CenterY = reader.getAttributeAsFloat("CenterY"); - XAxisX = reader.getAttributeAsFloat("XAxisX"); - XAxisY = reader.getAttributeAsFloat("XAxisY"); - YAxisX = reader.getAttributeAsFloat("YAxisX"); - YAxisY = reader.getAttributeAsFloat("YAxisY"); + RestoreAxis(reader, axis, u, v); MajorRadius = reader.getAttributeAsFloat("MajorRadius"); MinorRadius = reader.getAttributeAsFloat("MinorRadius"); - First = reader.getAttributeAsFloat("First"); - Last = reader.getAttributeAsFloat("Last"); - - // set the read geometry - gp_Pnt2d p1(CenterX,CenterY); - gp_Dir2d xdir(XAxisX,XAxisY); - gp_Dir2d ydir(YAxisX,YAxisY); - gp_Ax22d axis(p1, xdir, ydir); try { GCE2d_MakeHyperbola mc(axis, MajorRadius, MinorRadius); if (!mc.IsDone()) throw Base::Exception(gce_ErrorStatusText(mc.Status())); - GCE2d_MakeArcOfHyperbola ma(mc.Value()->Hypr2d(), First, Last); + GCE2d_MakeArcOfHyperbola ma(mc.Value()->Hypr2d(), u, v); if (!ma.IsDone()) throw Base::Exception(gce_ErrorStatusText(ma.Status())); @@ -1850,7 +1644,7 @@ PyObject *Geom2dArcOfHyperbola::getPyObject(void) // ------------------------------------------------- -TYPESYSTEM_SOURCE(Part::Geom2dParabola, Part::Geom2dCurve) +TYPESYSTEM_SOURCE(Part::Geom2dParabola, Part::Geom2dConic) Geom2dParabola::Geom2dParabola() { @@ -1878,27 +1672,6 @@ Geometry2d *Geom2dParabola::clone(void) const return newPar; } -Base::Vector2d Geom2dParabola::getCenter(void) const -{ - Handle_Geom2d_Parabola p = Handle_Geom2d_Parabola::DownCast(handle()); - const gp_Pnt2d& loc = p->Location(); - return Base::Vector2d(loc.X(),loc.Y()); -} - -void Geom2dParabola::setCenter(const Base::Vector2d& Center) -{ - gp_Pnt2d p1(Center.x,Center.y); - Handle_Geom2d_Parabola p = Handle_Geom2d_Parabola::DownCast(handle()); - - try { - p->SetLocation(p1); - } - catch (Standard_Failure) { - Handle_Standard_Failure e = Standard_Failure::Caught(); - throw Base::Exception(e->GetMessageString()); - } -} - double Geom2dParabola::getFocal(void) const { Handle_Geom2d_Parabola p = Handle_Geom2d_Parabola::DownCast(handle()); @@ -1929,20 +1702,14 @@ void Geom2dParabola::Save(Base::Writer& writer) const Geom2dCurve::Save(writer); gp_Parab2d p = this->myCurve->Parab2d(); - gp_Pnt2d center = p.Location(); - gp_Dir2d xdir = p.Axis().XDirection(); - gp_Dir2d ydir = p.Axis().YDirection(); + gp_Ax22d axis = p.Axis(); double focal = p.Focal(); writer.Stream() << writer.ind() - << "" << endl; } @@ -1952,24 +1719,14 @@ void Geom2dParabola::Restore(Base::XMLReader& reader) // read the attributes of the father class Geom2dCurve::Restore(reader); - double CenterX,CenterY,XAxisX,XAxisY,YAxisX,YAxisY,Focal; + double Focal; // read my Element reader.readElement("Geom2dParabola"); + gp_Ax22d axis; // get the value of my Attribute - CenterX = reader.getAttributeAsFloat("CenterX"); - CenterY = reader.getAttributeAsFloat("CenterY"); - XAxisX = reader.getAttributeAsFloat("XAxisX"); - XAxisY = reader.getAttributeAsFloat("XAxisY"); - YAxisX = reader.getAttributeAsFloat("YAxisX"); - YAxisY = reader.getAttributeAsFloat("YAxisY"); + RestoreAxis(reader, axis); Focal = reader.getAttributeAsFloat("Focal"); - // set the read geometry - gp_Pnt2d p1(CenterX,CenterY); - gp_Dir2d xdir(XAxisX,XAxisY); - gp_Dir2d ydir(YAxisX,YAxisY); - gp_Ax22d axis(p1, xdir, ydir); - try { GCE2d_MakeParabola mc(axis, Focal); if (!mc.IsDone()) @@ -1991,7 +1748,7 @@ PyObject *Geom2dParabola::getPyObject(void) // ------------------------------------------------- -TYPESYSTEM_SOURCE(Part::Geom2dArcOfParabola, Part::Geom2dCurve) +TYPESYSTEM_SOURCE(Part::Geom2dArcOfParabola, Part::Geom2dArcOfConic) Geom2dArcOfParabola::Geom2dArcOfParabola() { @@ -2028,39 +1785,6 @@ Geometry2d *Geom2dArcOfParabola::clone(void) const return copy; } -Base::Vector2d Geom2dArcOfParabola::getStartPoint() const -{ - gp_Pnt2d pnt = this->myCurve->StartPoint(); - return Base::Vector2d(pnt.X(), pnt.Y()); -} - -Base::Vector2d Geom2dArcOfParabola::getEndPoint() const -{ - gp_Pnt2d pnt = this->myCurve->EndPoint(); - return Base::Vector2d(pnt.X(), pnt.Y()); -} - -Base::Vector2d Geom2dArcOfParabola::getCenter(void) const -{ - Handle_Geom2d_Parabola p = Handle_Geom2d_Parabola::DownCast(myCurve->BasisCurve()); - const gp_Pnt2d& loc = p->Location(); - return Base::Vector2d(loc.X(),loc.Y()); -} - -void Geom2dArcOfParabola::setCenter(const Base::Vector2d& Center) -{ - gp_Pnt2d p1(Center.x,Center.y); - Handle_Geom2d_Parabola p = Handle_Geom2d_Parabola::DownCast(myCurve->BasisCurve()); - - try { - p->SetLocation(p1); - } - catch (Standard_Failure) { - Handle_Standard_Failure e = Standard_Failure::Caught(); - throw Base::Exception(e->GetMessageString()); - } -} - double Geom2dArcOfParabola::getFocal(void) const { Handle_Geom2d_Parabola p = Handle_Geom2d_Parabola::DownCast(myCurve->BasisCurve()); @@ -2080,23 +1804,6 @@ void Geom2dArcOfParabola::setFocal(double length) } } -void Geom2dArcOfParabola::getRange(double& u, double& v) const -{ - u = myCurve->FirstParameter(); - v = myCurve->LastParameter(); -} - -void Geom2dArcOfParabola::setRange(double u, double v) -{ - try { - myCurve->SetTrim(u, v); - } - catch (Standard_Failure) { - Handle_Standard_Failure e = Standard_Failure::Caught(); - throw Base::Exception(e->GetMessageString()); - } -} - unsigned int Geom2dArcOfParabola::getMemSize (void) const { return sizeof(Geom2d_Parabola) + 2 *sizeof(double); @@ -2109,23 +1816,17 @@ void Geom2dArcOfParabola::Save(Base::Writer &writer) const Handle_Geom2d_Parabola hp = Handle_Geom2d_Parabola::DownCast(this->myCurve->BasisCurve()); gp_Parab2d p = hp->Parab2d(); - gp_Pnt2d center = p.Location(); - gp_Dir2d xdir = p.Axis().XDirection(); - gp_Dir2d ydir = p.Axis().YDirection(); + gp_Ax22d axis = p.Axis(); + double u = this->myCurve->FirstParameter(); + double v = this->myCurve->LastParameter(); double focal = p.Focal(); writer.Stream() << writer.ind() - << "myCurve->FirstParameter() << "\" " - << "Last=\"" << this->myCurve->LastParameter() << "\" " << "/>" << endl; } @@ -2134,35 +1835,23 @@ void Geom2dArcOfParabola::Restore(Base::XMLReader &reader) // read the attributes of the father class Geom2dCurve::Restore(reader); - double CenterX,CenterY,XAxisX,XAxisY,YAxisX,YAxisY,Focal,First,Last; + double Focal,u,v; + gp_Ax22d axis; // read my Element reader.readElement("Geom2dParabola"); // get the value of my Attribute - CenterX = reader.getAttributeAsFloat("CenterX"); - CenterY = reader.getAttributeAsFloat("CenterY"); - XAxisX = reader.getAttributeAsFloat("XAxisX"); - XAxisY = reader.getAttributeAsFloat("XAxisY"); - YAxisX = reader.getAttributeAsFloat("YAxisX"); - YAxisY = reader.getAttributeAsFloat("YAxisY"); + RestoreAxis(reader, axis, u, v); Focal = reader.getAttributeAsFloat("Focal"); - First = reader.getAttributeAsFloat("First"); - Last = reader.getAttributeAsFloat("Last"); - - // set the read geometry - gp_Pnt2d p1(CenterX,CenterY); - gp_Dir2d xdir(XAxisX,XAxisY); - gp_Dir2d ydir(YAxisX,YAxisY); - gp_Ax22d axis(p1, xdir, ydir); try { GCE2d_MakeParabola mc(axis, Focal); if (!mc.IsDone()) throw Base::Exception(gce_ErrorStatusText(mc.Status())); - GCE2d_MakeArcOfParabola ma(mc.Value()->Parab2d(), First, Last); + GCE2d_MakeArcOfParabola ma(mc.Value()->Parab2d(), u, v); if (!ma.IsDone()) throw Base::Exception(gce_ErrorStatusText(ma.Status())); - + Handle_Geom2d_TrimmedCurve tmpcurve = ma.Value(); Handle_Geom2d_Parabola tmpparabola = Handle_Geom2d_Parabola::DownCast(tmpcurve->BasisCurve()); Handle_Geom2d_Parabola parabola = Handle_Geom2d_Parabola::DownCast(this->myCurve->BasisCurve()); diff --git a/src/Mod/Part/App/Geometry2d.h b/src/Mod/Part/App/Geometry2d.h index 1d431af8abb4..b7d5a9736f56 100644 --- a/src/Mod/Part/App/Geometry2d.h +++ b/src/Mod/Part/App/Geometry2d.h @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -189,7 +190,61 @@ class PartExport Geom2dBSplineCurve : public Geom2dCurve Handle_Geom2d_BSplineCurve myCurve; }; -class PartExport Geom2dCircle : public Geom2dCurve +class PartExport Geom2dConic : public Geom2dCurve +{ + TYPESYSTEM_HEADER(); +protected: + Geom2dConic(); + +public: + virtual ~Geom2dConic(); + virtual Geometry2d *clone(void) const = 0; + + Base::Vector2d getCenter(void) const; + void setCenter(const Base::Vector2d& Center); + bool isReversed() const; + + virtual unsigned int getMemSize(void) const = 0; + virtual PyObject *getPyObject(void) = 0; + + const Handle_Geom2d_Geometry& handle() const = 0; + +protected: + void SaveAxis(Base::Writer& writer, const gp_Ax22d&) const; + void RestoreAxis(Base::XMLReader& reader, gp_Ax22d&); +}; + +class PartExport Geom2dArcOfConic : public Geom2dCurve +{ + TYPESYSTEM_HEADER(); +protected: + Geom2dArcOfConic(); + +public: + virtual ~Geom2dArcOfConic(); + virtual Geometry2d *clone(void) const = 0; + + Base::Vector2d getCenter(void) const; + void setCenter(const Base::Vector2d& Center); + bool isReversed() const; + + Base::Vector2d getStartPoint() const; + Base::Vector2d getEndPoint() const; + + void getRange(double& u, double& v) const; + void setRange(double u, double v); + + virtual unsigned int getMemSize(void) const = 0; + virtual PyObject *getPyObject(void) = 0; + + const Handle_Geom2d_Geometry& handle() const = 0; + +protected: + void SaveAxis(Base::Writer& writer, const gp_Ax22d&, double u, double v) const; + void RestoreAxis(Base::XMLReader& reader, gp_Ax22d&, double& u, double& v); +}; + +class PartExport Geom2dCircle : public Geom2dConic { TYPESYSTEM_HEADER(); public: @@ -198,11 +253,8 @@ class PartExport Geom2dCircle : public Geom2dCurve virtual ~Geom2dCircle(); virtual Geometry2d *clone(void) const; - Base::Vector2d getCenter(void) const; double getRadius(void) const; - void setCenter(const Base::Vector2d& Center); void setRadius(double Radius); - bool isReversed() const; // Persistence implementer --------------------- virtual unsigned int getMemSize(void) const; @@ -217,7 +269,7 @@ class PartExport Geom2dCircle : public Geom2dCurve Handle_Geom2d_Circle myCurve; }; -class PartExport Geom2dArcOfCircle : public Geom2dCurve +class PartExport Geom2dArcOfCircle : public Geom2dArcOfConic { TYPESYSTEM_HEADER(); public: @@ -226,16 +278,8 @@ class PartExport Geom2dArcOfCircle : public Geom2dCurve virtual ~Geom2dArcOfCircle(); virtual Geometry2d *clone(void) const; - Base::Vector2d getStartPoint() const; - Base::Vector2d getEndPoint() const; - - Base::Vector2d getCenter(void) const; double getRadius(void) const; - void setCenter(const Base::Vector2d& Center); void setRadius(double Radius); - void getRange(double& u, double& v) const; - void setRange(double u, double v); - bool isReversed() const; // Persistence implementer --------------------- virtual unsigned int getMemSize(void) const; @@ -251,7 +295,7 @@ class PartExport Geom2dArcOfCircle : public Geom2dCurve Handle_Geom2d_TrimmedCurve myCurve; }; -class PartExport Geom2dEllipse : public Geom2dCurve +class PartExport Geom2dEllipse : public Geom2dConic { TYPESYSTEM_HEADER(); public: @@ -260,15 +304,12 @@ class PartExport Geom2dEllipse : public Geom2dCurve virtual ~Geom2dEllipse(); virtual Geometry2d *clone(void) const; - Base::Vector2d getCenter(void) const; - void setCenter(const Base::Vector2d& Center); double getMajorRadius(void) const; void setMajorRadius(double Radius); double getMinorRadius(void) const; void setMinorRadius(double Radius); Base::Vector2d getMajorAxisDir() const; void setMajorAxisDir(Base::Vector2d newdir); - bool isReversed() const; // Persistence implementer --------------------- virtual unsigned int getMemSize(void) const; @@ -284,7 +325,7 @@ class PartExport Geom2dEllipse : public Geom2dCurve Handle_Geom2d_Ellipse myCurve; }; -class PartExport Geom2dArcOfEllipse : public Geom2dCurve +class PartExport Geom2dArcOfEllipse : public Geom2dArcOfConic { TYPESYSTEM_HEADER(); public: @@ -293,21 +334,12 @@ class PartExport Geom2dArcOfEllipse : public Geom2dCurve virtual ~Geom2dArcOfEllipse(); virtual Geometry2d *clone(void) const; - Base::Vector2d getStartPoint() const; - Base::Vector2d getEndPoint() const; - - Base::Vector2d getCenter(void) const; - void setCenter(const Base::Vector2d& Center); double getMajorRadius(void) const; void setMajorRadius(double Radius); double getMinorRadius(void) const; void setMinorRadius(double Radius); Base::Vector2d getMajorAxisDir() const; void setMajorAxisDir(Base::Vector2d newdir); - bool isReversed() const; - - void getRange(double& u, double& v) const; - void setRange(double u, double v); // Persistence implementer --------------------- virtual unsigned int getMemSize(void) const; @@ -323,7 +355,7 @@ class PartExport Geom2dArcOfEllipse : public Geom2dCurve Handle_Geom2d_TrimmedCurve myCurve; }; -class PartExport Geom2dHyperbola : public Geom2dCurve +class PartExport Geom2dHyperbola : public Geom2dConic { TYPESYSTEM_HEADER(); public: @@ -332,8 +364,6 @@ class PartExport Geom2dHyperbola : public Geom2dCurve virtual ~Geom2dHyperbola(); virtual Geometry2d *clone(void) const; - Base::Vector2d getCenter(void) const; - void setCenter(const Base::Vector2d& Center); double getMajorRadius(void) const; void setMajorRadius(double Radius); double getMinorRadius(void) const; @@ -352,7 +382,7 @@ class PartExport Geom2dHyperbola : public Geom2dCurve Handle_Geom2d_Hyperbola myCurve; }; -class PartExport Geom2dArcOfHyperbola : public Geom2dCurve +class PartExport Geom2dArcOfHyperbola : public Geom2dArcOfConic { TYPESYSTEM_HEADER(); public: @@ -361,18 +391,10 @@ class PartExport Geom2dArcOfHyperbola : public Geom2dCurve virtual ~Geom2dArcOfHyperbola(); virtual Geometry2d *clone(void) const; - Base::Vector2d getStartPoint() const; - Base::Vector2d getEndPoint() const; - - Base::Vector2d getCenter(void) const; - void setCenter(const Base::Vector2d& Center); double getMajorRadius(void) const; void setMajorRadius(double Radius); double getMinorRadius(void) const; void setMinorRadius(double Radius); - - void getRange(double& u, double& v) const; - void setRange(double u, double v); // Persistence implementer --------------------- virtual unsigned int getMemSize(void) const; @@ -388,7 +410,7 @@ class PartExport Geom2dArcOfHyperbola : public Geom2dCurve Handle_Geom2d_TrimmedCurve myCurve; }; -class PartExport Geom2dParabola : public Geom2dCurve +class PartExport Geom2dParabola : public Geom2dConic { TYPESYSTEM_HEADER(); public: @@ -397,8 +419,6 @@ class PartExport Geom2dParabola : public Geom2dCurve virtual ~Geom2dParabola(); virtual Geometry2d *clone(void) const; - Base::Vector2d getCenter(void) const; - void setCenter(const Base::Vector2d& Center); double getFocal(void) const; void setFocal(double length); @@ -415,7 +435,7 @@ class PartExport Geom2dParabola : public Geom2dCurve Handle_Geom2d_Parabola myCurve; }; -class PartExport Geom2dArcOfParabola : public Geom2dCurve +class PartExport Geom2dArcOfParabola : public Geom2dArcOfConic { TYPESYSTEM_HEADER(); public: @@ -424,16 +444,8 @@ class PartExport Geom2dArcOfParabola : public Geom2dCurve virtual ~Geom2dArcOfParabola(); virtual Geometry2d *clone(void) const; - Base::Vector2d getStartPoint() const; - Base::Vector2d getEndPoint() const; - - Base::Vector2d getCenter(void) const; - void setCenter(const Base::Vector2d& Center); double getFocal(void) const; void setFocal(double length); - - void getRange(double& u, double& v) const; - void setRange(double u, double v); // Persistence implementer --------------------- virtual unsigned int getMemSize(void) const; From 03ab1a4a4d3cb6c6f5edad84eb162b68b7d7848a Mon Sep 17 00:00:00 2001 From: wmayer Date: Tue, 22 Nov 2016 16:16:48 +0100 Subject: [PATCH 2/2] fix build problems on Linux/OSX --- src/Base/GeometryPyCXX.cpp | 31 +++++++++++++++----------- src/Base/GeometryPyCXX.h | 5 ++--- src/Mod/Part/App/CMakeLists.txt | 18 ++------------- src/Mod/Part/App/Geom2d/CMakeLists.txt | 16 +++++++++++++ 4 files changed, 38 insertions(+), 32 deletions(-) create mode 100644 src/Mod/Part/App/Geom2d/CMakeLists.txt diff --git a/src/Base/GeometryPyCXX.cpp b/src/Base/GeometryPyCXX.cpp index 184d1acec4a2..8a31eae23097 100644 --- a/src/Base/GeometryPyCXX.cpp +++ b/src/Base/GeometryPyCXX.cpp @@ -23,6 +23,7 @@ #include "PreCompiled.h" #ifndef _PreComp_ +# include #endif #include "GeometryPyCXX.h" @@ -92,20 +93,11 @@ namespace Base { Vector2dPy::Vector2dPy(Py::PythonClassInstance *self, Py::Tuple &args, Py::Dict &kwds) : Py::PythonClass::PythonClass(self, args, kwds) { -} - -Vector2dPy::Vector2dPy() - : Py::PythonClass::PythonClass - (reinterpret_cast - (Vector2dPy::type_object()), Py::Tuple(), Py::Dict()) -{ -} + double x=0,y=0; + if (!PyArg_ParseTuple(args.ptr(), "|dd", &x, &y)) { + throw Py::Exception(); + } -Vector2dPy::Vector2dPy(double x, double y) - : Py::PythonClass::PythonClass - (reinterpret_cast - (Vector2dPy::type_object()), Py::Tuple(), Py::Dict()) -{ v.x = x; v.y = y; } @@ -120,10 +112,23 @@ void Vector2dPy::init_type(void) behaviors().doc( "Vector2d class" ); behaviors().supportGetattro(); behaviors().supportSetattro(); + behaviors().supportRepr(); // Call to make the type ready for use behaviors().readyType(); } +Py::Object Vector2dPy::repr() +{ + Py::Float x(v.x); + Py::Float y(v.y); + std::stringstream str; + str << "Vector2 ("; + str << (std::string)x.repr() << ", "<< (std::string)y.repr(); + str << ")"; + + return Py::String(str.str()); +} + Py::Object Vector2dPy::getattro(const Py::String &name_) { std::string name( name_.as_std_string( "utf-8" ) ); diff --git a/src/Base/GeometryPyCXX.h b/src/Base/GeometryPyCXX.h index 58804f0280ff..6704ee9468e4 100644 --- a/src/Base/GeometryPyCXX.h +++ b/src/Base/GeometryPyCXX.h @@ -51,14 +51,13 @@ class BaseExport Vector2dPy : public Py::PythonClass { public: Vector2dPy(Py::PythonClassInstance *self, Py::Tuple &args, Py::Dict &kwds); - Vector2dPy(); - Vector2dPy(double, double); virtual ~Vector2dPy(); static void init_type(void); Py::Object getattro(const Py::String &name_); int setattro(const Py::String &name_, const Py::Object &value); - inline const Vector2d& getValue() const { + virtual Py::Object repr(); + inline const Vector2d& value() const { return v; } inline void setValue(const Vector2d& n) { diff --git a/src/Mod/Part/App/CMakeLists.txt b/src/Mod/Part/App/CMakeLists.txt index 078bd1d989ed..1d04bd7f5114 100644 --- a/src/Mod/Part/App/CMakeLists.txt +++ b/src/Mod/Part/App/CMakeLists.txt @@ -83,22 +83,8 @@ generate_from_xml(TopoShapeSolidPy) generate_from_xml(TopoShapeVertexPy) generate_from_xml(TopoShapeWirePy) generate_from_xml(BRepOffsetAPI_MakePipeShellPy) -generate_from_xml(Geom2d/ArcOfCircle2dPy) -generate_from_xml(Geom2d/ArcOfConic2dPy) -generate_from_xml(Geom2d/ArcOfEllipse2dPy) -generate_from_xml(Geom2d/ArcOfHyperbola2dPy) -generate_from_xml(Geom2d/ArcOfParabola2dPy) -generate_from_xml(Geom2d/BezierCurve2dPy) -generate_from_xml(Geom2d/BSplineCurve2dPy) -generate_from_xml(Geom2d/Circle2dPy) -generate_from_xml(Geom2d/Conic2dPy) -generate_from_xml(Geom2d/Ellipse2dPy) -generate_from_xml(Geom2d/Geometry2dPy) -generate_from_xml(Geom2d/Hyperbola2dPy) -generate_from_xml(Geom2d/Curve2dPy) -generate_from_xml(Geom2d/Line2dSegmentPy) -generate_from_xml(Geom2d/OffsetCurve2dPy) -generate_from_xml(Geom2d/Parabola2dPy) + +add_subdirectory(Geom2d) SET(Features_SRCS FeaturePartBoolean.cpp diff --git a/src/Mod/Part/App/Geom2d/CMakeLists.txt b/src/Mod/Part/App/Geom2d/CMakeLists.txt new file mode 100644 index 000000000000..03c2a1559f37 --- /dev/null +++ b/src/Mod/Part/App/Geom2d/CMakeLists.txt @@ -0,0 +1,16 @@ +generate_from_xml(ArcOfCircle2dPy) +generate_from_xml(ArcOfConic2dPy) +generate_from_xml(ArcOfEllipse2dPy) +generate_from_xml(ArcOfHyperbola2dPy) +generate_from_xml(ArcOfParabola2dPy) +generate_from_xml(BezierCurve2dPy) +generate_from_xml(BSplineCurve2dPy) +generate_from_xml(Circle2dPy) +generate_from_xml(Conic2dPy) +generate_from_xml(Ellipse2dPy) +generate_from_xml(Geometry2dPy) +generate_from_xml(Hyperbola2dPy) +generate_from_xml(Curve2dPy) +generate_from_xml(Line2dSegmentPy) +generate_from_xml(OffsetCurve2dPy) +generate_from_xml(Parabola2dPy)