Add python interface for Part::GeomPoint
This commit is contained in:
parent
938fadc746
commit
2e6255305c
|
@ -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");
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 \
|
||||
|
|
45
src/Mod/Part/App/PointPy.xml
Normal file
45
src/Mod/Part/App/PointPy.xml
Normal file
|
@ -0,0 +1,45 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd">
|
||||
<PythonExport
|
||||
Father="GeometryPy"
|
||||
Name="PointPy"
|
||||
Twin="GeomPoint"
|
||||
TwinPointer="GeomPoint"
|
||||
Include="Mod/Part/App/Geometry.h"
|
||||
Namespace="Part"
|
||||
FatherInclude="Mod/Part/App/GeometryPy.h"
|
||||
FatherNamespace="Part"
|
||||
Constructor="true">
|
||||
<Documentation>
|
||||
<Author Licence="LGPL" Name="Werner Mayer" EMail="wmayer@users.sourceforge.net" />
|
||||
<UserDocu>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</UserDocu>
|
||||
</Documentation>
|
||||
<Attribute Name="X" ReadOnly="false">
|
||||
<Documentation>
|
||||
<UserDocu>X component of this point.</UserDocu>
|
||||
</Documentation>
|
||||
<Parameter Name="X" Type="Float"/>
|
||||
</Attribute>
|
||||
<Attribute Name="Y" ReadOnly="false">
|
||||
<Documentation>
|
||||
<UserDocu>Y component of this point.</UserDocu>
|
||||
</Documentation>
|
||||
<Parameter Name="Y" Type="Float"/>
|
||||
</Attribute>
|
||||
<Attribute Name="Z" ReadOnly="false">
|
||||
<Documentation>
|
||||
<UserDocu>Z component of this point.</UserDocu>
|
||||
</Documentation>
|
||||
<Parameter Name="Z" Type="Float"/>
|
||||
</Attribute>
|
||||
</PythonExport>
|
||||
</GenerateModel>
|
174
src/Mod/Part/App/PointPyImp.cpp
Normal file
174
src/Mod/Part/App/PointPyImp.cpp
Normal file
|
@ -0,0 +1,174 @@
|
|||
/***************************************************************************
|
||||
* Copyright (c) 2012 Konstantinos Poulios <logari81[at]gmail.com> *
|
||||
* *
|
||||
* 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 <gp.hxx>
|
||||
# include <Geom_CartesianPoint.hxx>
|
||||
# include <GC_MakeLine.hxx>
|
||||
# include <GC_MakeSegment.hxx>
|
||||
# include <Precision.hxx>
|
||||
#endif
|
||||
|
||||
#include <Base/VectorPy.h>
|
||||
#include <Base/GeometryPyCXX.h>
|
||||
|
||||
#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 << "<Point (" << coords.x << "," << coords.y << "," << coords.z << ") >";
|
||||
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<PointPy*>(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<Base::VectorPy*>(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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user