diff --git a/src/Mod/Part/App/AppPart.cpp b/src/Mod/Part/App/AppPart.cpp index 4e521342c..c52c467cf 100644 --- a/src/Mod/Part/App/AppPart.cpp +++ b/src/Mod/Part/App/AppPart.cpp @@ -55,6 +55,7 @@ #include "TopoShapeCompSolidPy.h" #include "TopoShapeShellPy.h" #include "LinePy.h" +#include "PointPy.h" #include "CirclePy.h" #include "EllipsePy.h" #include "ArcPy.h" @@ -106,6 +107,7 @@ void PartExport initPart() Base::Interpreter().addType(&Part::TopoShapeShellPy ::Type,partModule,"Shell"); Base::Interpreter().addType(&Part::LinePy ::Type,partModule,"Line"); + Base::Interpreter().addType(&Part::PointPy ::Type,partModule,"Point"); Base::Interpreter().addType(&Part::CirclePy ::Type,partModule,"Circle"); Base::Interpreter().addType(&Part::EllipsePy ::Type,partModule,"Ellipse"); Base::Interpreter().addType(&Part::HyperbolaPy ::Type,partModule,"Hyperbola"); diff --git a/src/Mod/Part/App/CMakeLists.txt b/src/Mod/Part/App/CMakeLists.txt index 20a33407b..079a52a3e 100644 --- a/src/Mod/Part/App/CMakeLists.txt +++ b/src/Mod/Part/App/CMakeLists.txt @@ -34,6 +34,7 @@ generate_from_xml(GeometryPy) generate_from_xml(GeometryCurvePy) generate_from_xml(GeometrySurfacePy) generate_from_xml(LinePy) +generate_from_xml(PointPy) generate_from_xml(BezierCurvePy) generate_from_xml(BSplineCurvePy) generate_from_xml(PlanePy) @@ -154,6 +155,8 @@ SET(Python_SRCS GeometrySurfacePyImp.cpp LinePy.xml LinePyImp.cpp + PointPy.xml + PointPyImp.cpp BezierCurvePy.xml BezierCurvePyImp.cpp BSplineCurvePy.xml diff --git a/src/Mod/Part/App/Makefile.am b/src/Mod/Part/App/Makefile.am index 778427814..ddb4b3946 100644 --- a/src/Mod/Part/App/Makefile.am +++ b/src/Mod/Part/App/Makefile.am @@ -14,6 +14,7 @@ BUILT_SOURCES=\ GeometryCurvePy.cpp \ GeometrySurfacePy.cpp \ LinePy.cpp \ + PointPy.cpp \ BezierCurvePy.cpp \ BSplineCurvePy.cpp \ PlanePy.cpp \ @@ -53,6 +54,7 @@ libPart_la_BUILT=\ GeometryCurvePy.h \ GeometrySurfacePy.h \ LinePy.h \ + PointPy.h \ BezierCurvePy.h \ BSplineCurvePy.h \ PlanePy.h \ @@ -94,6 +96,7 @@ libPart_la_SOURCES=\ GeometryCurvePyImp.cpp \ GeometrySurfacePyImp.cpp \ LinePyImp.cpp \ + PointPyImp.cpp \ BezierCurvePyImp.cpp \ BSplineCurvePyImp.cpp \ PlanePyImp.cpp \ @@ -273,6 +276,7 @@ EXTRA_DIST = \ GeometryCurvePy.xml \ GeometrySurfacePy.xml \ LinePy.xml \ + PointPy.xml \ BezierCurvePy.xml \ BSplineCurvePy.xml \ PlanePy.xml \ diff --git a/src/Mod/Part/App/PointPy.xml b/src/Mod/Part/App/PointPy.xml new file mode 100644 index 000000000..9ad55f961 --- /dev/null +++ b/src/Mod/Part/App/PointPy.xml @@ -0,0 +1,45 @@ + + + + + + Describes a point +To create a point there are several ways: +Part.Point() + Creates a default point + +Part.Point(Point) + Creates a copy of the given point + +Part.Point(Vector) + Creates a line for the given coordinates + + + + X component of this point. + + + + + + Y component of this point. + + + + + + Z component of this point. + + + + + diff --git a/src/Mod/Part/App/PointPyImp.cpp b/src/Mod/Part/App/PointPyImp.cpp new file mode 100644 index 000000000..91417844a --- /dev/null +++ b/src/Mod/Part/App/PointPyImp.cpp @@ -0,0 +1,174 @@ +/*************************************************************************** + * Copyright (c) 2012 Konstantinos Poulios * + * * + * 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 "Geometry.h" +#include "PointPy.h" +#include "PointPy.cpp" + +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 PointPy::representation(void) const +{ + std::stringstream str; + Base::Vector3d coords = getGeomPointPtr()->getPoint(); + str << ""; + return str.str(); +} + +PyObject *PointPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper +{ + // create a new instance of PointPy and the Twin object + return new PointPy(new GeomPoint); +} + +// constructor method +int PointPy::PyInit(PyObject* args, PyObject* /*kwd*/) +{ + + if (PyArg_ParseTuple(args, "")) { + // default point + return 0; + } + + PyErr_Clear(); + PyObject *pPoint; + if (PyArg_ParseTuple(args, "O!", &(PointPy::Type), &pPoint)) { + // Copy point + PointPy* pcPoint = static_cast(pPoint); + // get Geom_CartesianPoint of that point + Handle_Geom_CartesianPoint that_point = Handle_Geom_CartesianPoint::DownCast + (pcPoint->getGeomPointPtr()->handle()); + // get Geom_CartesianPoint of this point + Handle_Geom_CartesianPoint this_point = Handle_Geom_CartesianPoint::DownCast + (this->getGeomPointPtr()->handle()); + + // Assign the coordinates + this_point->SetPnt(that_point->Pnt()); + return 0; + } + + PyErr_Clear(); + PyObject *pV; + if (PyArg_ParseTuple(args, "O!", &(Base::VectorPy::Type), &pV)) { + Base::Vector3d v = static_cast(pV)->value(); + Handle_Geom_CartesianPoint this_point = Handle_Geom_CartesianPoint::DownCast + (this->getGeomPointPtr()->handle()); + this_point->SetCoord(v.x,v.y,v.z); + return 0; + } + + PyErr_SetString(PyExc_TypeError, "Point constructor accepts:\n" + "-- empty parameter list\n" + "-- Point\n" + "-- Coordinates vector"); + return -1; +} + +Py::Float PointPy::getX(void) const +{ + Handle_Geom_CartesianPoint this_point = Handle_Geom_CartesianPoint::DownCast + (this->getGeomPointPtr()->handle()); + return Py::Float(this_point->X()); +} + +void PointPy::setX(Py::Float X) +{ + Handle_Geom_CartesianPoint this_point = Handle_Geom_CartesianPoint::DownCast + (this->getGeomPointPtr()->handle()); + + try { + this_point->SetX(double(X)); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + throw Py::Exception(e->GetMessageString()); + } +} + +Py::Float PointPy::getY(void) const +{ + Handle_Geom_CartesianPoint this_point = Handle_Geom_CartesianPoint::DownCast + (this->getGeomPointPtr()->handle()); + return Py::Float(this_point->Y()); +} + +void PointPy::setY(Py::Float Y) +{ + Handle_Geom_CartesianPoint this_point = Handle_Geom_CartesianPoint::DownCast + (this->getGeomPointPtr()->handle()); + + try { + this_point->SetY(double(Y)); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + throw Py::Exception(e->GetMessageString()); + } +} + +Py::Float PointPy::getZ(void) const +{ + Handle_Geom_CartesianPoint this_point = Handle_Geom_CartesianPoint::DownCast + (this->getGeomPointPtr()->handle()); + return Py::Float(this_point->Z()); +} + +void PointPy::setZ(Py::Float Z) +{ + Handle_Geom_CartesianPoint this_point = Handle_Geom_CartesianPoint::DownCast + (this->getGeomPointPtr()->handle()); + + try { + this_point->SetZ(double(Z)); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + throw Py::Exception(e->GetMessageString()); + } +} + + +PyObject *PointPy::getCustomAttributes(const char* /*attr*/) const +{ + return 0; +} + +int PointPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) +{ + return 0; +}