Skip to content

Commit

Permalink
Merge pull request #346 from wwmayer/geom2dpy
Browse files Browse the repository at this point in the history
add Python wrappers for Geom2d classes
  • Loading branch information
wwmayer committed Nov 22, 2016
2 parents 14594dd + 03ab1a4 commit 3e06d0a
Show file tree
Hide file tree
Showing 39 changed files with 7,773 additions and 694 deletions.
21 changes: 21 additions & 0 deletions src/Base/GeometryPyCXX.cpp
Expand Up @@ -23,6 +23,7 @@

#include "PreCompiled.h"
#ifndef _PreComp_
# include <sstream>
#endif

#include "GeometryPyCXX.h"
Expand Down Expand Up @@ -92,6 +93,13 @@ namespace Base {
Vector2dPy::Vector2dPy(Py::PythonClassInstance *self, Py::Tuple &args, Py::Dict &kwds)
: Py::PythonClass<Vector2dPy>::PythonClass(self, args, kwds)
{
double x=0,y=0;
if (!PyArg_ParseTuple(args.ptr(), "|dd", &x, &y)) {
throw Py::Exception();
}

v.x = x;
v.y = y;
}

Vector2dPy::~Vector2dPy()
Expand All @@ -104,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" ) );
Expand Down
3 changes: 2 additions & 1 deletion src/Base/GeometryPyCXX.h
Expand Up @@ -56,7 +56,8 @@ class BaseExport Vector2dPy : public Py::PythonClass<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) {
Expand Down
117 changes: 78 additions & 39 deletions src/Mod/Part/App/AppPart.cpp
Expand Up @@ -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 <Mod/Part/App/Geom2d/ArcOfCircle2dPy.h>
#include <Mod/Part/App/Geom2d/ArcOfConic2dPy.h>
#include <Mod/Part/App/Geom2d/ArcOfEllipse2dPy.h>
#include <Mod/Part/App/Geom2d/ArcOfHyperbola2dPy.h>
#include <Mod/Part/App/Geom2d/ArcOfParabola2dPy.h>
#include <Mod/Part/App/Geom2d/BezierCurve2dPy.h>
#include <Mod/Part/App/Geom2d/BSplineCurve2dPy.h>
#include <Mod/Part/App/Geom2d/Circle2dPy.h>
#include <Mod/Part/App/Geom2d/Conic2dPy.h>
#include <Mod/Part/App/Geom2d/Ellipse2dPy.h>
#include <Mod/Part/App/Geom2d/Geometry2dPy.h>
#include <Mod/Part/App/Geom2d/Hyperbola2dPy.h>
#include <Mod/Part/App/Geom2d/Curve2dPy.h>
#include <Mod/Part/App/Geom2d/Line2dSegmentPy.h>
#include <Mod/Part/App/Geom2d/OffsetCurve2dPy.h>
#include <Mod/Part/App/Geom2d/Parabola2dPy.h>
#include "PropertyGeometryList.h"
#include "DatumFeature.h"
#include "Attacher.h"
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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();
Expand Down
41 changes: 41 additions & 0 deletions src/Mod/Part/App/CMakeLists.txt
Expand Up @@ -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}
Expand Down Expand Up @@ -83,6 +84,8 @@ generate_from_xml(TopoShapeVertexPy)
generate_from_xml(TopoShapeWirePy)
generate_from_xml(BRepOffsetAPI_MakePipeShellPy)

add_subdirectory(Geom2d)

SET(Features_SRCS
FeaturePartBoolean.cpp
FeaturePartBoolean.h
Expand Down Expand Up @@ -249,10 +252,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
Expand Down
44 changes: 44 additions & 0 deletions src/Mod/Part/App/Geom2d/ArcOfCircle2dPy.xml
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd">
<PythonExport
Father="ArcOfConic2dPy"
Name="ArcOfCircle2dPy"
Twin="Geom2dArcOfCircle"
TwinPointer="Geom2dArcOfCircle"
Include="Mod/Part/App/Geometry2d.h"
Namespace="Part"
FatherInclude="Mod/Part/App/Geom2d/ArcOfConic2dPy.h"
FatherNamespace="Part"
Constructor="true">
<Documentation>
<Author Licence="LGPL" Name="Werner Mayer" EMail="wmayer[at]users.sourceforge.net" />
<UserDocu>Describes a portion of a circle</UserDocu>
</Documentation>
<!--
<Attribute Name="Radius" ReadOnly="false">
<Documentation>
<UserDocu>The radius of the circle.</UserDocu>
</Documentation>
<Parameter Name="Radius" Type="Float"/>
</Attribute>
<Attribute Name="Center" ReadOnly="false">
<Documentation>
<UserDocu>Center of the circle.</UserDocu>
</Documentation>
<Parameter Name="Center" Type="Object"/>
</Attribute>
<Attribute Name="Axis" ReadOnly="false">
<Documentation>
<UserDocu>The axis direction of the circle</UserDocu>
</Documentation>
<Parameter Name="Axis" Type="Object"/>
</Attribute>
<Attribute Name="Circle" ReadOnly="true">
<Documentation>
<UserDocu>The internal circle representation</UserDocu>
</Documentation>
<Parameter Name="Circle" Type="Object"/>
</Attribute>
-->
</PythonExport>
</GenerateModel>

0 comments on commit 3e06d0a

Please sign in to comment.