add Python wrappers for Geom2d classes

This commit is contained in:
wmayer 2016-11-22 14:09:19 +01:00
parent 14594dde32
commit 9bdad96a69
38 changed files with 7766 additions and 693 deletions

View File

@ -94,6 +94,22 @@ Vector2dPy::Vector2dPy(Py::PythonClassInstance *self, Py::Tuple &args, Py::Dict
{
}
Vector2dPy::Vector2dPy()
: Py::PythonClass<Vector2dPy>::PythonClass
(reinterpret_cast<Py::PythonClassInstance *>
(Vector2dPy::type_object()), Py::Tuple(), Py::Dict())
{
}
Vector2dPy::Vector2dPy(double x, double y)
: Py::PythonClass<Vector2dPy>::PythonClass
(reinterpret_cast<Py::PythonClassInstance *>
(Vector2dPy::type_object()), Py::Tuple(), Py::Dict())
{
v.x = x;
v.y = y;
}
Vector2dPy::~Vector2dPy()
{
}

View File

@ -51,6 +51,8 @@ class BaseExport Vector2dPy : public Py::PythonClass<Vector2dPy>
{
public:
Vector2dPy(Py::PythonClassInstance *self, Py::Tuple &args, Py::Dict &kwds);
Vector2dPy();
Vector2dPy(double, double);
virtual ~Vector2dPy();
static void init_type(void);

View File

@ -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"
@ -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();

View File

@ -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

View File

@ -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>

View File

@ -0,0 +1,231 @@
/***************************************************************************
* Copyright (c) 2011 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* 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_Circ.hxx>
# include <Geom_Circle.hxx>
# include <GC_MakeArcOfCircle.hxx>
# include <GC_MakeCircle.hxx>
# include <Geom_TrimmedCurve.hxx>
#endif
#include <Mod/Part/App/Geometry.h>
#include <Mod/Part/App/Geom2d/ArcOfCircle2dPy.h>
#include <Mod/Part/App/Geom2d/ArcOfCircle2dPy.cpp>
//#include "CirclePy.h"
//#include "OCCError.h"
#include <Base/GeometryPyCXX.h>
#include <Base/VectorPy.h>
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<CirclePy*>(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<Base::VectorPy*>(pV1)->value();
Base::Vector3d v2 = static_cast<Base::VectorPy*>(pV2)->value();
Base::Vector3d v3 = static_cast<Base::VectorPy*>(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<Base::VectorPy*>(p)->value();
getGeomArcOfCirclePtr()->setCenter(loc);
}
else if (PyObject_TypeCheck(p, &PyTuple_Type)) {
Base::Vector3d loc = Base::getVectorFromTuple<double>(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<Base::VectorPy*>(p)->value();
}
else if (PyTuple_Check(p)) {
val = Base::getVectorFromTuple<double>(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;
}

View File

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd">
<PythonExport
Father="Curve2dPy"
Name="ArcOfConic2dPy"
Twin="Geom2dArcOfConic"
TwinPointer="Geom2dArcOfConic"
Include="Mod/Part/App/Geometry2d.h"
Namespace="Part"
FatherInclude="Mod/Part/App/Geom2d/Curve2dPy.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="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>

View File

@ -0,0 +1,217 @@
/***************************************************************************
* Copyright (c) 2011 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* 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_Circ.hxx>
# include <Geom_Circle.hxx>
# include <GC_MakeArcOfCircle.hxx>
# include <GC_MakeCircle.hxx>
# include <Geom_TrimmedCurve.hxx>
#endif
#include <Mod/Part/App/Geometry2d.h>
#include <Mod/Part/App/Geom2d/ArcOfConic2dPy.h>
#include <Mod/Part/App/Geom2d/ArcOfConic2dPy.cpp>
#include <Mod/Part/App/OCCError.h>
#include <Base/GeometryPyCXX.h>
#include <Base/VectorPy.h>
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<CirclePy*>(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<Base::VectorPy*>(pV1)->value();
Base::Vector3d v2 = static_cast<Base::VectorPy*>(pV2)->value();
Base::Vector3d v3 = static_cast<Base::VectorPy*>(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<Base::VectorPy*>(p)->value();
getGeomArcOfCirclePtr()->setCenter(loc);
}
else if (PyObject_TypeCheck(p, &PyTuple_Type)) {
Base::Vector3d loc = Base::getVectorFromTuple<double>(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<Base::VectorPy*>(p)->value();
}
else if (PyTuple_Check(p)) {
val = Base::getVectorFromTuple<double>(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;
}

View File

@ -0,0 +1,56 @@
<?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="ArcOfEllipse2dPy"
Twin="Geom2dArcOfEllipse"
TwinPointer="Geom2dArcOfEllipse"
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 an ellipse</UserDocu>
</Documentation>
<!--
<Attribute Name="MajorRadius" ReadOnly="false">
<Documentation>
<UserDocu>The major radius of the ellipse.</UserDocu>
</Documentation>
<Parameter Name="MajorRadius" Type="Float"/>
</Attribute>
<Attribute Name="MinorRadius" ReadOnly="false">
<Documentation>
<UserDocu>The minor radius of the ellipse.</UserDocu>
</Documentation>
<Parameter Name="MinorRadius" Type="Float"/>
</Attribute>
<Attribute Name="AngleXU" ReadOnly="false">
<Documentation>
<UserDocu>The angle between the X axis and the major axis of the ellipse.</UserDocu>
</Documentation>
<Parameter Name="AngleXU" Type="Float"/>
</Attribute>
<Attribute Name="Center" ReadOnly="false">
<Documentation>
<UserDocu>Center of the ellipse.</UserDocu>
</Documentation>
<Parameter Name="Center" Type="Object"/>
</Attribute>
<Attribute Name="Axis" ReadOnly="false">
<Documentation>
<UserDocu>The axis direction of the ellipse</UserDocu>
</Documentation>
<Parameter Name="Axis" Type="Object"/>
</Attribute>
<Attribute Name="Ellipse" ReadOnly="true">
<Documentation>
<UserDocu>The internal ellipse representation</UserDocu>
</Documentation>
<Parameter Name="Ellipse" Type="Object"/>
</Attribute>
-->
</PythonExport>
</GenerateModel>

View File

@ -0,0 +1,241 @@
/***************************************************************************
* Copyright (c) 2014 Abdullah Tahiri <abdullah.tahiri.yo@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_Elips.hxx>
# include <Geom_Ellipse.hxx>
# include <GC_MakeArcOfEllipse.hxx>
# include <GC_MakeEllipse.hxx>
# include <Geom_TrimmedCurve.hxx>
#endif
#include <Mod/Part/App/Geometry2d.h>
#include <Mod/Part/App/Geom2d/ArcOfEllipse2dPy.h>
#include <Mod/Part/App/Geom2d/ArcOfEllipse2dPy.cpp>
#include <Mod/Part/App/EllipsePy.h>
#include <Mod/Part/App/OCCError.h>
#include <Base/GeometryPyCXX.h>
#include <Base/VectorPy.h>
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<EllipsePy*>(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<Base::VectorPy*>(p)->value();
getGeomArcOfEllipsePtr()->setCenter(loc);
}
else if (PyObject_TypeCheck(p, &PyTuple_Type)) {
Base::Vector3d loc = Base::getVectorFromTuple<double>(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<Base::VectorPy*>(p)->value();
}
else if (PyTuple_Check(p)) {
val = Base::getVectorFromTuple<double>(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;
}

View File

@ -0,0 +1,56 @@
<?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="ArcOfHyperbola2dPy"
Twin="Geom2dArcOfHyperbola"
TwinPointer="Geom2dArcOfHyperbola"
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@users.sourceforge.net" />
<UserDocu>Describes a portion of an hyperbola</UserDocu>
</Documentation>
<!--
<Attribute Name="MajorRadius" ReadOnly="false">
<Documentation>
<UserDocu>The major radius of the hyperbola.</UserDocu>
</Documentation>
<Parameter Name="MajorRadius" Type="Float"/>
</Attribute>
<Attribute Name="MinorRadius" ReadOnly="false">
<Documentation>
<UserDocu>The minor radius of the hyperbola.</UserDocu>
</Documentation>
<Parameter Name="MinorRadius" Type="Float"/>
</Attribute>
<Attribute Name="AngleXU" ReadOnly="false">
<Documentation>
<UserDocu>The angle between the X axis and the major axis of the hyperbola.</UserDocu>
</Documentation>
<Parameter Name="AngleXU" Type="Float"/>
</Attribute>
<Attribute Name="Center" ReadOnly="false">
<Documentation>
<UserDocu>Center of the hyperbola.</UserDocu>
</Documentation>
<Parameter Name="Center" Type="Object"/>
</Attribute>
<Attribute Name="Axis" ReadOnly="false">
<Documentation>
<UserDocu>The axis direction of the hyperbola</UserDocu>
</Documentation>
<Parameter Name="Axis" Type="Object"/>
</Attribute>
<Attribute Name="Hyperbola" ReadOnly="true">
<Documentation>
<UserDocu>The internal hyperbola representation</UserDocu>
</Documentation>
<Parameter Name="Hyperbola" Type="Object"/>
</Attribute>
-->
</PythonExport>
</GenerateModel>

View File

@ -0,0 +1,241 @@
/***************************************************************************
* Copyright (c) 2014 Abdullah Tahiri <abdullah.tahiri.yo@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_Hypr.hxx>
# include <Geom_Hyperbola.hxx>
# include <GC_MakeArcOfHyperbola.hxx>
# include <GC_MakeHyperbola.hxx>
# include <Geom_TrimmedCurve.hxx>
#endif
#include <Mod/Part/App/Geometry2d.h>
#include <Mod/Part/App/Geom2d/ArcOfHyperbola2dPy.h>
#include <Mod/Part/App/Geom2d/ArcOfHyperbola2dPy.cpp>
#include <Mod/Part/App/HyperbolaPy.h>
#include <Mod/Part/App/OCCError.h>
#include <Base/GeometryPyCXX.h>
#include <Base/VectorPy.h>
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<HyperbolaPy*>(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<Base::VectorPy*>(p)->value();
getGeomArcOfHyperbolaPtr()->setCenter(loc);
}
else if (PyObject_TypeCheck(p, &PyTuple_Type)) {
Base::Vector3d loc = Base::getVectorFromTuple<double>(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<Base::VectorPy*>(p)->value();
}
else if (PyTuple_Check(p)) {
val = Base::getVectorFromTuple<double>(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;
}

View File

@ -0,0 +1,50 @@
<?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="ArcOfParabola2dPy"
Twin="Geom2dArcOfParabola"
TwinPointer="Geom2dArcOfParabola"
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@users.sourceforge.net" />
<UserDocu>Describes a portion of an parabola</UserDocu>
</Documentation>
<!--
<Attribute Name="Focal" ReadOnly="false">
<Documentation>
<UserDocu>The focal length of the parabola.</UserDocu>
</Documentation>
<Parameter Name="Focal" Type="Float"/>
</Attribute>
<Attribute Name="AngleXU" ReadOnly="false">
<Documentation>
<UserDocu>The angle between the X axis and the major axis of the parabola.</UserDocu>
</Documentation>
<Parameter Name="AngleXU" Type="Float"/>
</Attribute>
<Attribute Name="Center" ReadOnly="false">
<Documentation>
<UserDocu>Center of the parabola.</UserDocu>
</Documentation>
<Parameter Name="Center" Type="Object"/>
</Attribute>
<Attribute Name="Axis" ReadOnly="false">
<Documentation>
<UserDocu>The axis direction of the parabola</UserDocu>
</Documentation>
<Parameter Name="Axis" Type="Object"/>
</Attribute>
<Attribute Name="Parabola" ReadOnly="true">
<Documentation>
<UserDocu>The internal parabola representation</UserDocu>
</Documentation>
<Parameter Name="Parabola" Type="Object"/>
</Attribute>
-->
</PythonExport>
</GenerateModel>

View File

@ -0,0 +1,229 @@
/***************************************************************************
* Copyright (c) 2014 Abdullah Tahiri <abdullah.tahiri.yo@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_Parab.hxx>
# include <Geom_Parabola.hxx>
# include <GC_MakeArcOfParabola.hxx>
# include <gce_MakeParab.hxx>
# include <Geom_TrimmedCurve.hxx>
#endif
#include <Mod/Part/App/Geometry2d.h>
#include <Mod/Part/App/Geom2d/ArcOfParabola2dPy.h>
#include <Mod/Part/App/Geom2d/ArcOfParabola2dPy.cpp>
#include <Mod/Part/App/ParabolaPy.h>
#include <Mod/Part/App/OCCError.h>
#include <Base/GeometryPyCXX.h>
#include <Base/VectorPy.h>
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<ParabolaPy*>(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<Base::VectorPy*>(p)->value();
getGeomArcOfParabolaPtr()->setCenter(loc);
}
else if (PyObject_TypeCheck(p, &PyTuple_Type)) {
Base::Vector3d loc = Base::getVectorFromTuple<double>(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<Base::VectorPy*>(p)->value();
}
else if (PyTuple_Check(p)) {
val = Base::getVectorFromTuple<double>(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;
}

View File

@ -0,0 +1,445 @@
<?xml version="1.0" encoding="UTF-8"?>
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd">
<PythonExport
Father="Curve2dPy"
Name="BSplineCurve2dPy"
Twin="Geom2dBSplineCurve"
TwinPointer="Geom2dBSplineCurve"
Include="Mod/Part/App/Geometry2d.h"
Namespace="Part"
FatherInclude="Mod/Part/App/Geom2d/Curve2dPy.h"
FatherNamespace="Part"
Constructor="true">
<Documentation>
<Author Licence="LGPL" Name="Werner Mayer" EMail="wmayer@users.sourceforge.net" />
<UserDocu>Describes a B-Spline curve in 3D space</UserDocu>
</Documentation>
<!--
<Attribute Name="Degree" ReadOnly="true">
<Documentation>
<UserDocu>Returns the polynomial degree of this B-Spline curve.</UserDocu>
</Documentation>
<Parameter Name="Degree" Type="Int"/>
</Attribute>
<Attribute Name="MaxDegree" ReadOnly="true">
<Documentation>
<UserDocu>Returns the value of the maximum polynomial degree of any
B-Spline curve curve. This value is 25.</UserDocu>
</Documentation>
<Parameter Name="MaxDegree" Type="Int"/>
</Attribute>
<Attribute Name="NbPoles" ReadOnly="true">
<Documentation>
<UserDocu>Returns the number of poles of this B-Spline curve.
</UserDocu>
</Documentation>
<Parameter Name="NbPoles" Type="Int"/>
</Attribute>
<Attribute Name="NbKnots" ReadOnly="true">
<Documentation>
<UserDocu>
Returns the number of knots of this B-Spline curve.
</UserDocu>
</Documentation>
<Parameter Name="NbPoles" Type="Int"/>
</Attribute>
<Attribute Name="StartPoint" ReadOnly="true">
<Documentation>
<UserDocu>Returns the start point of this B-Spline curve.</UserDocu>
</Documentation>
<Parameter Name="StartPoint" Type="Object"/>
</Attribute>
<Attribute Name="EndPoint" ReadOnly="true">
<Documentation>
<UserDocu>Returns the end point of this B-Spline curve.</UserDocu>
</Documentation>
<Parameter Name="EndPoint" Type="Object"/>
</Attribute>
<Attribute Name="FirstUKnotIndex" ReadOnly="true">
<Documentation>
<UserDocu>Returns the index in the knot array of the knot
corresponding to the first or last parameter
of this B-Spline curve.</UserDocu>
</Documentation>
<Parameter Name="FirstUKnotIndex" Type="Object"/>
</Attribute>
<Attribute Name="LastUKnotIndex" ReadOnly="true">
<Documentation>
<UserDocu>Returns the index in the knot array of the knot
corresponding to the first or last parameter
of this B-Spline curve.</UserDocu>
</Documentation>
<Parameter Name="LastUKnotIndex" Type="Object"/>
</Attribute>
<Attribute Name="KnotSequence" ReadOnly="true">
<Documentation>
<UserDocu>Returns the knots sequence of this B-Spline curve.</UserDocu>
</Documentation>
<Parameter Name="KnotSequence" Type="List"/>
</Attribute>
<Methode Name="isRational">
<Documentation>
<UserDocu>
Returns true if this B-Spline curve is rational.
A B-Spline curve is rational if, at the time of construction,
the weight table has been initialized.
</UserDocu>
</Documentation>
</Methode>
<Methode Name="isPeriodic">
<Documentation>
<UserDocu>Returns true if this BSpline curve is periodic.</UserDocu>
</Documentation>
</Methode>
<Methode Name="isClosed">
<Documentation>
<UserDocu>
Returns true if the distance between the start point and end point of
this B-Spline curve is less than or equal to gp::Resolution().
</UserDocu>
</Documentation>
</Methode>
<Methode Name="increaseDegree">
<Documentation>
<UserDocu>increase(Int=Degree)
Increases the degree of this B-Spline curve to Degree.
As a result, the poles, weights and multiplicities tables
are modified; the knots table is not changed. Nothing is
done if Degree is less than or equal to the current degree.</UserDocu>
</Documentation>
</Methode>
<Methode Name="increaseMultiplicity">
<Documentation>
<UserDocu>
increaseMultiplicity(int index, int mult)
increaseMultiplicity(int start, int end, int mult)
Increases multiplicity of knots up to mult.
index: the index of a knot to modify (1-based)
start, end: index range of knots to modify.
If mult is lower or equal to the current multiplicity nothing is done. If mult is higher than the degree the degree is used.
</UserDocu>
</Documentation>
</Methode>
<Methode Name="incrementMultiplicity">
<Documentation>
<UserDocu>
incrementMultiplicity(int start, int end, int mult)
Raises multiplicity of knots by mult.
start, end: index range of knots to modify.
</UserDocu>
</Documentation>
</Methode>
<Methode Name="insertKnot">
<Documentation>
<UserDocu>
insertKnot(u, mult = 1, tol = 0.0)
Inserts a knot value in the sequence of knots. If u is an existing knot the
multiplicity is increased by mult. </UserDocu>
</Documentation>
</Methode>
<Methode Name="insertKnots">
<Documentation>
<UserDocu>
insertKnots(list_of_floats, list_of_ints, tol = 0.0, bool_add = True)
Inserts a set of knots values in the sequence of knots.
For each u = list_of_floats[i], mult = list_of_ints[i]
If u is an existing knot the multiplicity is increased by mult if bool_add is
True, otherwise increased to mult.
If u is not on the parameter range nothing is done.
If the multiplicity is negative or null nothing is done. The new multiplicity
is limited to the degree.
The tolerance criterion for knots equality is the max of Epsilon(U) and ParametricTolerance.
</UserDocu>
</Documentation>
</Methode>
<Methode Name="removeKnot">
<Documentation>
<UserDocu>
removeKnot(Index, M, tol)
Reduces the multiplicity of the knot of index Index to M.
If M is equal to 0, the knot is removed.
With a modification of this type, the array of poles is also modified.
Two different algorithms are systematically used to compute the new
poles of the curve. If, for each pole, the distance between the pole
calculated using the first algorithm and the same pole calculated using
the second algorithm, is less than Tolerance, this ensures that the curve
is not modified by more than Tolerance. Under these conditions, true is
returned; otherwise, false is returned.
A low tolerance is used to prevent modification of the curve.
A high tolerance is used to 'smooth' the curve.
</UserDocu>
</Documentation>
</Methode>
<Methode Name="segment">
<Documentation>
<UserDocu>
segment(u1,u2)
Modifies this B-Spline curve by segmenting it.</UserDocu>
</Documentation>
</Methode>
<Methode Name="setKnot">
<Documentation>
<UserDocu>Set a knot of the B-Spline curve.</UserDocu>
</Documentation>
</Methode>
<Methode Name="getKnot">
<Documentation>
<UserDocu>Get a knot of the B-Spline curve.</UserDocu>
</Documentation>
</Methode>
<Methode Name="setKnots">
<Documentation>
<UserDocu>Set knots of the B-Spline curve.</UserDocu>
</Documentation>
</Methode>
<Methode Name="getKnots">
<Documentation>
<UserDocu>Get all knots of the B-Spline curve.</UserDocu>
</Documentation>
</Methode>
<Methode Name="setPole">
<Documentation>
<UserDocu>Modifies this B-Spline curve by assigning P
to the pole of index Index in the poles table.</UserDocu>
</Documentation>
</Methode>
<Methode Name="getPole">
<Documentation>
<UserDocu>Get a pole of the B-Spline curve.</UserDocu>
</Documentation>
</Methode>
<Methode Name="getPoles">
<Documentation>
<UserDocu>Get all poles of the B-Spline curve.</UserDocu>
</Documentation>
</Methode>
<Methode Name="setWeight">
<Documentation>
<UserDocu>Set a weight of the B-Spline curve.</UserDocu>
</Documentation>
</Methode>
<Methode Name="getWeight">
<Documentation>
<UserDocu>Get a weight of the B-Spline curve.</UserDocu>
</Documentation>
</Methode>
<Methode Name="getWeights">
<Documentation>
<UserDocu>Get all weights of the B-Spline curve.</UserDocu>
</Documentation>
</Methode>
<Methode Name="getPolesAndWeights">
<Documentation>
<UserDocu>Returns the table of poles and weights in homogenous ccordinates.</UserDocu>
</Documentation>
</Methode>
<Methode Name="getResolution" Const="true">
<Documentation>
<UserDocu>Computes for this B-Spline curve the parametric tolerance (UTolerance)
for a given 3D tolerance (Tolerance3D).
If f(t) is the equation of this B-Spline curve, the parametric tolerance
ensures that:
|t1-t0| &lt; UTolerance =""==&gt; |f(t1)-f(t0)| &lt; Tolerance3D</UserDocu>
</Documentation>
</Methode>
<Methode Name="movePoint">
<Documentation>
<UserDocu>
movePoint(U, P, Index1, Index2)
Moves the point of parameter U of this B-Spline curve to P.
Index1 and Index2 are the indexes in the table of poles of this B-Spline curve
of the first and last poles designated to be moved.
Returns: (FirstModifiedPole, LastModifiedPole). They are the indexes of the
first and last poles which are effectively modified.</UserDocu>
</Documentation>
</Methode>
<Methode Name="setNotPeriodic">
<Documentation>
<UserDocu>Changes this B-Spline curve into a non-periodic curve.
If this curve is already non-periodic, it is not modified.</UserDocu>
</Documentation>
</Methode>
<Methode Name="setPeriodic">
<Documentation>
<UserDocu>Changes this B-Spline curve into a periodic curve.</UserDocu>
</Documentation>
</Methode>
<Methode Name="setOrigin">
<Documentation>
<UserDocu>Assigns the knot of index Index in the knots table
as the origin of this periodic B-Spline curve. As a consequence,
the knots and poles tables are modified.</UserDocu>
</Documentation>
</Methode>
<Methode Name="getMultiplicity">
<Documentation>
<UserDocu>Returns the multiplicity of the knot of index
from the knots table of this B-Spline curve.</UserDocu>
</Documentation>
</Methode>
<Methode Name="getMultiplicities">
<Documentation>
<UserDocu>
Returns the multiplicities table M of the knots of this B-Spline curve.
</UserDocu>
</Documentation>
</Methode>
<Methode Name="approximate" Keyword="true">
<Documentation>
<UserDocu>
Replaces this B-Spline curve by approximating a set of points.
The function accepts keywords as arguments.
approximate2(Points = list_of_points)
Optional arguments :
DegMin = integer (3) : Minimum degree of the curve.
DegMax = integer (8) : Maximum degree of the curve.
Tolerance = float (1e-3) : approximating tolerance.
Continuity = string ('C2') : Desired continuity of the curve.
Possible values : 'C0','G1','C1','G2','C2','C3','CN'
LengthWeight = float, CurvatureWeight = float, TorsionWeight = float
If one of these arguments is not null, the functions approximates the
points using variational smoothing algorithm, which tries to minimize
additional criterium:
LengthWeight*CurveLength + CurvatureWeight*Curvature + TorsionWeight*Torsion
Continuity must be C0, C1 or C2, else defaults to C2.
Parameters = list of floats : knot sequence of the approximated points.
This argument is only used if the weights above are all null.
ParamType = string ('Uniform','Centripetal' or 'ChordLength')
Parameterization type. Only used if weights and Parameters above aren't specified.
Note : Continuity of the spline defaults to C2. However, it may not be applied if
it conflicts with other parameters ( especially DegMax ).
</UserDocu>
</Documentation>
</Methode>
<Methode Name="getCardinalSplineTangents" Keyword="true">
<Documentation>
<UserDocu>Compute the tangents for a Cardinal spline</UserDocu>
</Documentation>
</Methode>
<Methode Name="interpolate" Keyword="true">
<Documentation>
<UserDocu>
Replaces this B-Spline curve by interpolating a set of points.
The function accepts keywords as arguments.
interpolate(Points = list_of_points)
Optional arguments :
PeriodicFlag = bool (False) : Sets the curve closed or opened.
Tolerance = float (1e-6) : interpolating tolerance
Parameters : knot sequence of the interpolated points.
If not supplied, the function defaults to chord-length parameterization.
If PeriodicFlag == True, one extra parameter must be appended.
EndPoint Tangent constraints :
InitialTangent = vector, FinalTangent = vector
specify tangent vectors for starting and ending points
of the BSpline. Either none, or both must be specified.
Full Tangent constraints :
Tangents = list_of_vectors, TangentFlags = list_of_bools
Both lists must have the same length as Points list.
Tangents specifies the tangent vector of each point in Points list.
TangentFlags (bool) activates or deactivates the corresponding tangent.
These arguments will be ignored if EndPoint Tangents (above) are also defined.
Note : Continuity of the spline defaults to C2. However, if periodic, or tangents
are supplied, the continuity will drop to C1.
</UserDocu>
</Documentation>
</Methode>
<Methode Name="buildFromPoles">
<Documentation>
<UserDocu>
Builds a B-Spline by a list of poles.
</UserDocu>
</Documentation>
</Methode>
<Methode Name="buildFromPolesMultsKnots" Keyword="true">
<Documentation>
<UserDocu>
Builds a B-Spline by a lists of Poles, Mults, Knots.
arguments: poles (sequence of Base.Vector), [mults , knots, periodic, degree, weights (sequence of float), CheckRational]
Examples:
from FreeCAD import Base
import Part
V=Base.Vector
poles=[V(-10,-10),V(10,-10),V(10,10),V(-10,10)]
# non-periodic spline
n=Part.BSplineCurve()
n.buildFromPolesMultsKnots(poles,(3,1,3),(0,0.5,1),False,2)
Part.show(n.toShape())
# periodic spline
p=Part.BSplineCurve()
p.buildFromPolesMultsKnots(poles,(1,1,1,1,1),(0,0.25,0.5,0.75,1),True,2)
Part.show(p.toShape())
# periodic and rational spline
r=Part.BSplineCurve()
r.buildFromPolesMultsKnots(poles,(1,1,1,1,1),(0,0.25,0.5,0.75,1),True,2,(1,0.8,0.7,0.2))
Part.show(r.toShape())
</UserDocu>
</Documentation>
</Methode>
<Methode Name="toBezier">
<Documentation>
<UserDocu>
Build a list of Bezier splines.
</UserDocu>
</Documentation>
</Methode>
<Methode Name="toBiArcs">
<Documentation>
<UserDocu>
Build a list of arcs and lines to approximate the b-spline.
toBiArcs(tolerance) -> list.
</UserDocu>
</Documentation>
</Methode>
<Methode Name="join">
<Documentation>
<UserDocu>
Build a new spline by joining this and a second spline.
</UserDocu>
</Documentation>
</Methode>
<Methode Name="makeC1Continuous">
<Documentation>
<UserDocu>
makeC1Continuous(tol = 1e-6, ang_tol = 1e-7)
Reduces as far as possible the multiplicities of the knots of this BSpline
(keeping the geometry). It returns a new BSpline, which could still be C0.
tol is a geometrical tolerance.
The tol_ang is angular tolerance, in radians. It sets tolerable angle mismatch
of the tangents on the left and on the right to decide if the curve is G1 or
not at a given point.
</UserDocu>
</Documentation>
</Methode>
-->
</PythonExport>
</GenerateModel>

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,146 @@
<?xml version="1.0" encoding="UTF-8"?>
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd">
<PythonExport
Father="Curve2dPy"
Name="BezierCurve2dPy"
Twin="Geom2dBezierCurve"
TwinPointer="Geom2dBezierCurve"
Include="Mod/Part/App/Geometry2d.h"
Namespace="Part"
FatherInclude="Mod/Part/App/Geom2d/Curve2dPy.h"
FatherNamespace="Part"
Constructor="true">
<Documentation>
<Author Licence="LGPL" Name="Werner Mayer" EMail="wmayer@users.sourceforge.net" />
<UserDocu>
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
</UserDocu>
</Documentation>
<!--
<Attribute Name="Degree" ReadOnly="true">
<Documentation>
<UserDocu>Returns the polynomial degree of this Bezier curve,
which is equal to the number of poles minus 1.</UserDocu>
</Documentation>
<Parameter Name="Degree" Type="Int"/>
</Attribute>
<Attribute Name="MaxDegree" ReadOnly="true">
<Documentation>
<UserDocu>Returns the value of the maximum polynomial degree of any
Bezier curve curve. This value is 25.</UserDocu>
</Documentation>
<Parameter Name="MaxDegree" Type="Int"/>
</Attribute>
<Attribute Name="NbPoles" ReadOnly="true">
<Documentation>
<UserDocu>Returns the number of poles of this Bezier curve.
</UserDocu>
</Documentation>
<Parameter Name="NbPoles" Type="Int"/>
</Attribute>
<Attribute Name="StartPoint" ReadOnly="true">
<Documentation>
<UserDocu>Returns the start point of this Bezier curve.</UserDocu>
</Documentation>
<Parameter Name="StartPoint" Type="Object"/>
</Attribute>
<Attribute Name="EndPoint" ReadOnly="true">
<Documentation>
<UserDocu>Returns the end point of this Bezier curve.</UserDocu>
</Documentation>
<Parameter Name="EndPoint" Type="Object"/>
</Attribute>
<Methode Name="isRational">
<Documentation>
<UserDocu>Returns false if the weights of all the poles of this Bezier curve are equal.</UserDocu>
</Documentation>
</Methode>
<Methode Name="isPeriodic">
<Documentation>
<UserDocu>Returns false.</UserDocu>
</Documentation>
</Methode>
<Methode Name="isClosed">
<Documentation>
<UserDocu>Returns true if the distance between the start point and end point of
this Bezier curve is less than or equal to gp::Resolution().
</UserDocu>
</Documentation>
</Methode>
<Methode Name="increase">
<Documentation>
<UserDocu>increase(Int=Degree)
Increases the degree of this Bezier curve to Degree.
As a result, the poles and weights tables are modified.</UserDocu>
</Documentation>
</Methode>
<Methode Name="insertPoleAfter">
<Documentation>
<UserDocu>Inserts after the pole of index.</UserDocu>
</Documentation>
</Methode>
<Methode Name="insertPoleBefore">
<Documentation>
<UserDocu>Inserts before the pole of index.</UserDocu>
</Documentation>
</Methode>
<Methode Name="removePole">
<Documentation>
<UserDocu>Removes the pole of index Index from the table of poles of this Bezier curve.
If this Bezier curve is rational, it can become non-rational.</UserDocu>
</Documentation>
</Methode>
<Methode Name="segment">
<Documentation>
<UserDocu>Modifies this Bezier curve by segmenting it.</UserDocu>
</Documentation>
</Methode>
<Methode Name="setPole">
<Documentation>
<UserDocu>Set a pole of the Bezier curve.</UserDocu>
</Documentation>
</Methode>
<Methode Name="getPole">
<Documentation>
<UserDocu>Get a pole of the Bezier curve.</UserDocu>
</Documentation>
</Methode>
<Methode Name="getPoles">
<Documentation>
<UserDocu>Get all poles of the Bezier curve.</UserDocu>
</Documentation>
</Methode>
<Methode Name="setPoles">
<Documentation>
<UserDocu>Set the poles of the Bezier curve.</UserDocu>
</Documentation>
</Methode>
<Methode Name="setWeight">
<Documentation>
<UserDocu>Set a weight of the Bezier curve.</UserDocu>
</Documentation>
</Methode>
<Methode Name="getWeight">
<Documentation>
<UserDocu>Get a weight of the Bezier curve.</UserDocu>
</Documentation>
</Methode>
<Methode Name="getWeights">
<Documentation>
<UserDocu>Get all weights of the Bezier curve.</UserDocu>
</Documentation>
</Methode>
<Methode Name="getResolution" Const="true">
<Documentation>
<UserDocu>Computes for this Bezier curve the parametric tolerance (UTolerance)
for a given 3D tolerance (Tolerance3D).
If f(t) is the equation of this Bezier curve, the parametric tolerance
ensures that:
|t1-t0| &lt; UTolerance =""==&gt; |f(t1)-f(t0)| &lt; Tolerance3D</UserDocu>
</Documentation>
</Methode>
-->
</PythonExport>
</GenerateModel>

View File

@ -0,0 +1,404 @@
/***************************************************************************
* Copyright (c) 2008 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* 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 <Geom_BezierCurve.hxx>
# include <gp_Pnt.hxx>
# include <TColStd_Array1OfReal.hxx>
# include <TColgp_Array1OfPnt.hxx>
#endif
#include <Base/VectorPy.h>
#include <Base/GeometryPyCXX.h>
#include <Mod/Part/App/OCCError.h>
#include <Mod/Part/App/Geometry2d.h>
#include <Mod/Part/App/Geom2d/BezierCurve2dPy.h>
#include <Mod/Part/App/Geom2d/BezierCurve2dPy.cpp>
using namespace Part;
// returns a string which represents the object e.g. when printed in python
std::string BezierCurve2dPy::representation(void) const
{
return "<BezierCurve object>";
}
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", &degree))
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<Base::VectorPy*>(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<Base::VectorPy*>(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<Base::VectorPy*>(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;
}

View File

@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd">
<PythonExport
Father="Conic2dPy"
Name="Circle2dPy"
Twin="Geom2dCircle"
TwinPointer="Geom2dCircle"
Include="Mod/Part/App/Geometry2d.h"
Namespace="Part"
FatherInclude="Mod/Part/App/Geom2d/Conic2dPy.h"
FatherNamespace="Part"
Constructor="true">
<Documentation>
<Author Licence="LGPL" Name="Werner Mayer" EMail="wmayer@users.sourceforge.net" />
<UserDocu>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
</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="XAxis" ReadOnly="false">
<Documentation>
<UserDocu>The X axis direction of the circle</UserDocu>
</Documentation>
<Parameter Name="XAxis" Type="Object"/>
</Attribute>
<Attribute Name="YAxis" ReadOnly="false">
<Documentation>
<UserDocu>The Y axis direction of the circle</UserDocu>
</Documentation>
<Parameter Name="YAxis" Type="Object"/>
</Attribute>
-->
</PythonExport>
</GenerateModel>

View File

@ -0,0 +1,328 @@
/***************************************************************************
* Copyright (c) 2008 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* 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_Circ.hxx>
# include <Geom_Circle.hxx>
# include <GC_MakeCircle.hxx>
#endif
#include <Mod/Part/App/OCCError.h>
#include <Mod/Part/App/Geom2d/Circle2dPy.h>
#include <Mod/Part/App/Geom2d/Circle2dPy.cpp>
#include <Base/GeometryPyCXX.h>
#include <Base/VectorPy.h>
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<Circle2dPy*>(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<Base::VectorPy*>(pV1)->value();
Base::Vector3d v2 = static_cast<Base::VectorPy*>(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<Circle2dPy*>(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<Base::VectorPy*>(pV1)->value();
Base::Vector3d v2 = static_cast<Base::VectorPy*>(pV2)->value();
Base::Vector3d v3 = static_cast<Base::VectorPy*>(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<Base::VectorPy*>(p)->value();
getGeomCirclePtr()->setCenter(loc);
}
else if (PyObject_TypeCheck(p, &PyTuple_Type)) {
Base::Vector3d loc = Base::getVectorFromTuple<double>(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<Base::VectorPy*>(p)->value();
}
else if (PyTuple_Check(p)) {
val = Base::getVectorFromTuple<double>(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<Base::VectorPy*>(p)->value();
}
else if (PyTuple_Check(p)) {
val = Base::getVectorFromTuple<double>(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<Base::VectorPy*>(p)->value();
}
else if (PyTuple_Check(p)) {
val = Base::getVectorFromTuple<double>(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;
}

View File

@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8"?>
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd">
<PythonExport
Father="Curve2dPy"
Name="Conic2dPy"
Twin="Geom2dConic"
TwinPointer="Geom2dConic"
Include="Mod/Part/App/Geometry2d.h"
Namespace="Part"
FatherInclude="Mod/Part/App/Geom2d/Curve2dPy.h"
FatherNamespace="Part"
Constructor="true">
<Documentation>
<Author Licence="LGPL" Name="Werner Mayer" EMail="wmayer@users.sourceforge.net" />
<UserDocu>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
</UserDocu>
</Documentation>
<!--
<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="XAxis" ReadOnly="false">
<Documentation>
<UserDocu>The X axis direction of the circle</UserDocu>
</Documentation>
<Parameter Name="XAxis" Type="Object"/>
</Attribute>
<Attribute Name="YAxis" ReadOnly="false">
<Documentation>
<UserDocu>The Y axis direction of the circle</UserDocu>
</Documentation>
<Parameter Name="YAxis" Type="Object"/>
</Attribute>
-->
</PythonExport>
</GenerateModel>

View File

@ -0,0 +1,315 @@
/***************************************************************************
* Copyright (c) 2008 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* 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_Circ.hxx>
# include <Geom_Circle.hxx>
# include <GC_MakeCircle.hxx>
#endif
#include <Mod/Part/App/OCCError.h>
#include <Mod/Part/App/Geom2d/Conic2dPy.h>
#include <Mod/Part/App/Geom2d/Conic2dPy.cpp>
#include <Base/GeometryPyCXX.h>
#include <Base/VectorPy.h>
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<Conic2dPy*>(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<Base::VectorPy*>(pV1)->value();
Base::Vector3d v2 = static_cast<Base::VectorPy*>(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<Conic2dPy*>(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<Base::VectorPy*>(pV1)->value();
Base::Vector3d v2 = static_cast<Base::VectorPy*>(pV2)->value();
Base::Vector3d v3 = static_cast<Base::VectorPy*>(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<Base::VectorPy*>(p)->value();
getGeomCirclePtr()->setCenter(loc);
}
else if (PyObject_TypeCheck(p, &PyTuple_Type)) {
Base::Vector3d loc = Base::getVectorFromTuple<double>(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<Base::VectorPy*>(p)->value();
}
else if (PyTuple_Check(p)) {
val = Base::getVectorFromTuple<double>(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<Base::VectorPy*>(p)->value();
}
else if (PyTuple_Check(p)) {
val = Base::getVectorFromTuple<double>(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<Base::VectorPy*>(p)->value();
}
else if (PyTuple_Check(p)) {
val = Base::getVectorFromTuple<double>(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;
}

View File

@ -0,0 +1,160 @@
<?xml version="1.0" encoding="UTF-8"?>
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd">
<PythonExport
Father="Geometry2dPy"
Name="Curve2dPy"
Twin="Geom2dCurve"
TwinPointer="Geom2dCurve"
Include="Mod/Part/App/Geometry2d.h"
Namespace="Part"
FatherInclude="Mod/Part/App/Geom2d/Geometry2dPy.h"
FatherNamespace="Part"
Constructor="true">
<Documentation>
<Author Licence="LGPL" Name="Werner Mayer" EMail="wmayer@users.sourceforge.net" />
<UserDocu>
The abstract class GeometryCurve is the root class of all curve objects.
</UserDocu>
</Documentation>
<!--
<Methode Name="toShape" Const="true">
<Documentation>
<UserDocu>Return the shape for the geometry.</UserDocu>
</Documentation>
</Methode>
<Methode Name="discretize" Const="true" Keyword="true">
<Documentation>
<UserDocu>Discretizes the curve and returns a list of points.
The function accepts keywords as argument:
discretize(Number=n) => gives a list of 'n' equidistant points
discretize(QuasiNumber=n) => gives a list of 'n' quasi equidistant points (is faster than the method above)
discretize(Distance=d) => gives a list of equidistant points with distance 'd'
discretize(Deflection=d) => gives a list of points with a maximum deflection 'd' to the curve
discretize(QuasiDeflection=d) => gives a list of points with a maximum deflection 'd' to the curve (faster)
discretize(Angular=a,Curvature=c,[Minimum=m]) => gives a list of points with an angular deflection of 'a'
and a curvature deflection of 'c'. Optionally a minimum number of points
can be set which by default is set to 2.
Optionally you can set the keywords 'First' and 'Last' to define a sub-range of the parameter range
of the curve.
If no keyword is given then it depends on whether the argument is an int or float.
If it's an int then the behaviour is as if using the keyword 'Number', if it's float
then the behaviour is as if using the keyword 'Distance'.
Example:
import Part
c=Part.Circle()
c.Radius=5
p=c.discretize(Number=50,First=3.14)
s=Part.Compound([Part.Vertex(i) for i in p])
Part.show(s)
p=c.discretize(Angular=0.09,Curvature=0.01,Last=3.14,Minimum=100)
s=Part.Compound([Part.Vertex(i) for i in p])
Part.show(s)
</UserDocu>
</Documentation>
</Methode>
<Methode Name="length">
<Documentation>
<UserDocu>Computes the length of a curve
length([uMin,uMax,Tol]) -> Float</UserDocu>
</Documentation>
</Methode>
<Methode Name="parameterAtDistance">
<Documentation>
<UserDocu>Returns the parameter on the curve of a point at the given distance from a starting parameter.
parameterAtDistance([abscissa, startingParameter]) -> Float the</UserDocu>
</Documentation>
</Methode>
<Methode Name="value">
<Documentation>
<UserDocu>Computes the point of parameter u on this curve</UserDocu>
</Documentation>
</Methode>
<Methode Name="tangent">
<Documentation>
<UserDocu>Computes the tangent of parameter u on this curve</UserDocu>
</Documentation>
</Methode>
<Methode Name="parameter">
<Documentation>
<UserDocu>Returns the parameter on the curve
of the nearest orthogonal projection of the point.</UserDocu>
</Documentation>
</Methode>
<Methode Name="normal" Const="true">
<Documentation>
<UserDocu>Vector = normal(pos) - Get the normal vector at the given parameter [First|Last] if defined</UserDocu>
</Documentation>
</Methode>
<Methode Name="curvature" Const="true">
<Documentation>
<UserDocu>Float = curvature(pos) - Get the curvature at the given parameter [First|Last] if defined</UserDocu>
</Documentation>
</Methode>
<Methode Name="centerOfCurvature" Const="true">
<Documentation>
<UserDocu>Vector = centerOfCurvature(float pos) - Get the center of curvature at the given parameter [First|Last] if defined</UserDocu>
</Documentation>
</Methode>
<Methode Name="intersect" Const="true">
<Documentation>
<UserDocu>
Returns all intersection points and curve segments between the curve and the curve/surface.
</UserDocu>
</Documentation>
</Methode>
<Methode Name="intersectCC" Const="true">
<Documentation>
<UserDocu>
Returns all intersection points between this curve and the given curve.
</UserDocu>
</Documentation>
</Methode>
<Methode Name="toBSpline">
<Documentation>
<UserDocu>
Converts a curve of any type (only part from First to Last)
toBSpline([Float=First, Float=Last]) -> B-Spline curve
</UserDocu>
</Documentation>
</Methode>
<Methode Name="approximateBSpline">
<Documentation>
<UserDocu>
Approximates a curve of any type to a B-Spline curve
approximateBSpline(Tolerance, MaxSegments, MaxDegree, [Order='C2']) -> B-Spline curve
</UserDocu>
</Documentation>
</Methode>
<Attribute Name="Continuity" ReadOnly="true">
<Documentation>
<UserDocu>
Returns the global continuity of the curve.
</UserDocu>
</Documentation>
<Parameter Name="Continuity" Type="String"/>
</Attribute>
<Attribute Name="FirstParameter" ReadOnly="true">
<Documentation>
<UserDocu>
Returns the value of the first parameter.
</UserDocu>
</Documentation>
<Parameter Name="FirstParameter" Type="Float"/>
</Attribute>
<Attribute Name="LastParameter" ReadOnly="true">
<Documentation>
<UserDocu>
Returns the value of the last parameter.
</UserDocu>
</Documentation>
<Parameter Name="LastParameter" Type="Float"/>
</Attribute>
-->
</PythonExport>
</GenerateModel>

View File

@ -0,0 +1,691 @@
/***************************************************************************
* Copyright (c) 2016 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* 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 <sstream>
# include <gp_Dir2d.hxx>
# include <gp_Vec2d.hxx>
# include <GCPnts_UniformAbscissa.hxx>
# include <GCPnts_UniformDeflection.hxx>
# include <GCPnts_TangentialDeflection.hxx>
# include <GCPnts_QuasiUniformAbscissa.hxx>
# include <GCPnts_QuasiUniformDeflection.hxx>
# include <GCPnts_AbscissaPoint.hxx>
# include <Geom2dAPI_InterCurveCurve.hxx>
# include <GeomAPI.hxx>
# include <Geom_Geometry.hxx>
# include <Geom_Curve.hxx>
# include <Geom_Plane.hxx>
# include <Geom_Surface.hxx>
# include <Geom2dAdaptor_Curve.hxx>
# include <GeomFill.hxx>
# include <GeomLProp_CLProps.hxx>
# include <Geom_RectangularTrimmedSurface.hxx>
# include <Geom_BSplineSurface.hxx>
# include <Precision.hxx>
# include <GeomAPI_ProjectPointOnCurve.hxx>
# include <GeomConvert_ApproxCurve.hxx>
# include <Standard_Failure.hxx>
# include <Standard_NullValue.hxx>
# include <ShapeConstruct_Curve.hxx>
# include <GeomAPI_IntCS.hxx>
# include <Geom2dAPI_ExtremaCurveCurve.hxx>
#endif
#include <Base/GeometryPyCXX.h>
#include <Base/VectorPy.h>
#include <Mod/Part/App/Geometry.h>
#include <Mod/Part/App/Geom2d/Curve2dPy.h>
#include <Mod/Part/App/Geom2d/Curve2dPy.cpp>
#include <Mod/Part/App/BSplineSurfacePy.h>
#include <Mod/Part/App/PlanePy.h>
#include <Mod/Part/App/PointPy.h>
#include <Mod/Part/App/BSplineCurvePy.h>
#include <Mod/Part/App/OCCError.h>
#include <Mod/Part/App/TopoShape.h>
#include <Mod/Part/App/TopoShapePy.h>
#include <Mod/Part/App/TopoShapeEdgePy.h>
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 "<Curve2d object>";
}
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<Geometry2dPy*>(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

View File

@ -0,0 +1,99 @@
<?xml version="1.0" encoding="utf-8"?>
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd">
<PythonExport
Father="Conic2dPy"
Name="Ellipse2dPy"
Twin="Geom2dEllipse"
TwinPointer="Geom2dEllipse"
Include="Mod/Part/App/Geometry2d.h"
Namespace="Part"
FatherInclude="Mod/Part/App/Geom2d/Conic2dPy.h"
FatherNamespace="Part"
Constructor="true">
<Documentation>
<Author Licence="LGPL" Name="Werner Mayer" EMail="wmayer@users.sourceforge.net" />
<UserDocu>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)
</UserDocu>
</Documentation>
<!--
<Attribute Name="MajorRadius" ReadOnly="false">
<Documentation>
<UserDocu>The major radius of the ellipse.</UserDocu>
</Documentation>
<Parameter Name="MajorRadius" Type="Float"/>
</Attribute>
<Attribute Name="MinorRadius" ReadOnly="false">
<Documentation>
<UserDocu>The minor radius of the ellipse.</UserDocu>
</Documentation>
<Parameter Name="MinorRadius" Type="Float"/>
</Attribute>
<Attribute Name="AngleXU" ReadOnly="false">
<Documentation>
<UserDocu>The angle between the X axis and the major axis of the ellipse.</UserDocu>
</Documentation>
<Parameter Name="AngleXU" Type="Float"/>
</Attribute>
<Attribute Name="Eccentricity" ReadOnly="true">
<Documentation>
<UserDocu>The eccentricity of the ellipse.</UserDocu>
</Documentation>
<Parameter Name="Eccentricity" Type="Float"/>
</Attribute>
<Attribute Name="Focal" ReadOnly="true">
<Documentation>
<UserDocu>The focal distance of the ellipse.</UserDocu>
</Documentation>
<Parameter Name="Focal" Type="Float"/>
</Attribute>
<Attribute Name="Focus1" ReadOnly="true">
<Documentation>
<UserDocu>The first focus is on the positive side of the major axis of the ellipse;
the second focus is on the negative side.</UserDocu>
</Documentation>
<Parameter Name="Focus1" Type="Object"/>
</Attribute>
<Attribute Name="Focus2" ReadOnly="true">
<Documentation>
<Documentation>
<UserDocu>The first focus is on the positive side of the major axis of the ellipse;
the second focus is on the negative side.
</UserDocu>
</Documentation>
</Documentation>
<Parameter Name="Focus2" Type="Object"/>
</Attribute>
<Attribute Name="Center" ReadOnly="false">
<Documentation>
<UserDocu>Center of the ellipse.</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>
-->
</PythonExport>
</GenerateModel>

View File

@ -0,0 +1,290 @@
/***************************************************************************
* Copyright (c) 2008 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* 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_Elips.hxx>
# include <Geom_Ellipse.hxx>
# include <GC_MakeEllipse.hxx>
#endif
#include <Base/GeometryPyCXX.h>
#include <Base/VectorPy.h>
#include <Mod/Part/App/OCCError.h>
#include <Mod/Part/App/Geometry2d.h>
#include <Mod/Part/App/Geom2d/Ellipse2dPy.h>
#include <Mod/Part/App/Geom2d/Ellipse2dPy.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 Ellipse2dPy::representation(void) const
{
return "<Ellipse2d object>";
}
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<Ellipse2dPy*>(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<Base::VectorPy*>(pV1)->value();
Base::Vector3d v2 = static_cast<Base::VectorPy*>(pV2)->value();
Base::Vector3d v3 = static_cast<Base::VectorPy*>(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<Base::VectorPy*>(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<Base::VectorPy*>(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<Base::VectorPy*>(p)->value();
}
else if (PyTuple_Check(p)) {
val = Base::getVectorFromTuple<double>(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;
}

View File

@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?>
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd">
<PythonExport
Father="PyObjectBase"
Name="Geometry2dPy"
Twin="Geometry2d"
TwinPointer="Geometry2d"
Include="Mod/Part/App/Geometry2d.h"
Namespace="Part"
FatherInclude="Base/PyObjectBase.h"
FatherNamespace="Base"
Constructor="true"
Delete="true">
<Documentation>
<Author Licence="LGPL" Name="Werner Mayer" EMail="wmayer@users.sourceforge.net" />
<UserDocu>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).</UserDocu>
</Documentation>
<!--
<Methode Name="mirror">
<Documentation>
<UserDocu>Performs the symmetrical transformation of this geometric object</UserDocu>
</Documentation>
</Methode>
<Methode Name="rotate">
<Documentation>
<UserDocu>Rotates this geometric object at angle Ang (in radians) about axis</UserDocu>
</Documentation>
</Methode>
<Methode Name="scale">
<Documentation>
<UserDocu>Applies a scaling transformation on this geometric object with a center and scaling factor</UserDocu>
</Documentation>
</Methode>
<Methode Name="transform">
<Documentation>
<UserDocu>Applies a transformation to this geometric object</UserDocu>
</Documentation>
</Methode>
<Methode Name="translate">
<Documentation>
<UserDocu>Translates this geometric object</UserDocu>
</Documentation>
</Methode>
<Methode Name="copy" Const="true">
<Documentation>
<UserDocu>Create a copy of this geometry</UserDocu>
</Documentation>
</Methode>
-->
</PythonExport>
</GenerateModel>

View File

@ -0,0 +1,201 @@
/***************************************************************************
* Copyright (c) 2016 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* 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_Dir2d.hxx>
# include <gp_Pnt2d.hxx>
# include <gp_Vec2d.hxx>
# include <gp_Trsf.hxx>
# include <Geom2d_Geometry.hxx>
# include <Geom2d_Curve.hxx>
# include <Precision.hxx>
# include <Standard_Failure.hxx>
#endif
#include <Base/GeometryPyCXX.h>
#include <Base/Matrix.h>
#include <Base/MatrixPy.h>
#include <Base/Tools2D.h>
#include <Base/Rotation.h>
#include <Base/Placement.h>
#include <Base/PlacementPy.h>
#include <Mod/Part/App/OCCError.h>
#include <Mod/Part/App/Geometry2d.h>
#include <Mod/Part/App/Geom2d/Geometry2dPy.h>
#include <Mod/Part/App/Geom2d/Geometry2dPy.cpp>
#include <Mod/Part/App/TopoShape.h>
#include <Mod/Part/App/TopoShapePy.h>
using namespace Part;
// returns a string which represents the object e.g. when printed in python
std::string Geometry2dPy::representation(void) const
{
return "<Geometry2d object>";
}
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<Base::Vector2dPy*>(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<Base::Vector2dPy*>(o)->getValue();
Base::Vector2d dir = static_cast<Base::Vector2dPy*>(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<Base::PlacementPy*>(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<Base::Vector2dPy*>(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<Base::MatrixPy*>(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<Base::Vector2dPy*>(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<Part::Geometry2dPy*>(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<Part::Geometry2d*>(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;
}

View File

@ -0,0 +1,99 @@
<?xml version="1.0" encoding="utf-8"?>
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd">
<PythonExport
Father="Conic2dPy"
Name="Hyperbola2dPy"
Twin="Geom2dHyperbola"
TwinPointer="Geom2dHyperbola"
Include="Mod/Part/App/Geometry2d.h"
Namespace="Part"
FatherInclude="Mod/Part/App/Geom2d/Conic2dPy.h"
FatherNamespace="Part"
Constructor="true">
<Documentation>
<Author Licence="LGPL" Name="Werner Mayer" EMail="wmayer@users.sourceforge.net" />
<UserDocu>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)
</UserDocu>
</Documentation>
<!--
<Attribute Name="MajorRadius" ReadOnly="false">
<Documentation>
<UserDocu>The major radius of the hyperbola.</UserDocu>
</Documentation>
<Parameter Name="MajorRadius" Type="Float"/>
</Attribute>
<Attribute Name="MinorRadius" ReadOnly="false">
<Documentation>
<UserDocu>The minor radius of the hyperbola.</UserDocu>
</Documentation>
<Parameter Name="MinorRadius" Type="Float"/>
</Attribute>
<Attribute Name="AngleXU" ReadOnly="false">
<Documentation>
<UserDocu>The angle between the X axis and the major axis of the hyperbola.</UserDocu>
</Documentation>
<Parameter Name="AngleXU" Type="Float"/>
</Attribute>
<Attribute Name="Eccentricity" ReadOnly="true">
<Documentation>
<UserDocu>The eccentricity of the hyperbola.</UserDocu>
</Documentation>
<Parameter Name="Eccentricity" Type="Float"/>
</Attribute>
<Attribute Name="Focal" ReadOnly="true">
<Documentation>
<UserDocu>The focal distance of the hyperbola.</UserDocu>
</Documentation>
<Parameter Name="Focal" Type="Float"/>
</Attribute>
<Attribute Name="Focus1" ReadOnly="true">
<Documentation>
<UserDocu>The first focus is on the positive side of the major axis of the hyperbola;
the second focus is on the negative side.</UserDocu>
</Documentation>
<Parameter Name="Focus1" Type="Object"/>
</Attribute>
<Attribute Name="Focus2" ReadOnly="true">
<Documentation>
<Documentation>
<UserDocu>The first focus is on the positive side of the major axis of the hyperbola;
the second focus is on the negative side.
</UserDocu>
</Documentation>
</Documentation>
<Parameter Name="Focus2" Type="Object"/>
</Attribute>
<Attribute Name="Center" ReadOnly="false">
<Documentation>
<UserDocu>Center of the hyperbola.</UserDocu>
</Documentation>
<Parameter Name="Center" Type="Object"/>
</Attribute>
<Attribute Name="Axis" ReadOnly="false">
<Documentation>
<UserDocu>The axis direction of the hyperbola</UserDocu>
</Documentation>
<Parameter Name="Axis" Type="Object"/>
</Attribute>
-->
</PythonExport>
</GenerateModel>

View File

@ -0,0 +1,290 @@
/***************************************************************************
* Copyright (c) 2008 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* 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_Hypr.hxx>
# include <Geom_Hyperbola.hxx>
# include <GC_MakeHyperbola.hxx>
#endif
#include <Base/GeometryPyCXX.h>
#include <Base/VectorPy.h>
#include <Mod/Part/App/OCCError.h>
#include <Mod/Part/App/Geometry2d.h>
#include <Mod/Part/App/Geom2d/Hyperbola2dPy.h>
#include <Mod/Part/App/Geom2d/Hyperbola2dPy.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 Hyperbola2dPy::representation(void) const
{
return "<Hyperbola2d object>";
}
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<Hyperbola2dPy*>(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<Base::VectorPy*>(pV1)->value();
Base::Vector3d v2 = static_cast<Base::VectorPy*>(pV2)->value();
Base::Vector3d v3 = static_cast<Base::VectorPy*>(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<Base::VectorPy*>(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<Base::VectorPy*>(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<Base::VectorPy*>(p)->value();
}
else if (PyTuple_Check(p)) {
val = Base::getVectorFromTuple<double>(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;
}

View File

@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd">
<PythonExport
Father="Curve2dPy"
Name="Line2dSegmentPy"
Twin="Geom2dLineSegment"
TwinPointer="Geom2dLineSegment"
Include="Mod/Part/App/Geometry2d.h"
Namespace="Part"
FatherInclude="Mod/Part/App/Geom2d/Curve2dPy.h"
FatherNamespace="Part"
Constructor="true">
<Documentation>
<Author Licence="LGPL" Name="Werner Mayer" EMail="wmayer@users.sourceforge.net" />
<UserDocu>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</UserDocu>
</Documentation>
<!--
<Methode Name="setParameterRange">
<Documentation>
<UserDocu>Set the parameter range of the underlying line geometry</UserDocu>
</Documentation>
</Methode>
<Attribute Name="StartPoint" ReadOnly="false">
<Documentation>
<UserDocu>Returns the start point of this line.</UserDocu>
</Documentation>
<Parameter Name="StartPoint" Type="Object"/>
</Attribute>
<Attribute Name="EndPoint" ReadOnly="false">
<Documentation>
<UserDocu>Returns the end point point of this line.</UserDocu>
</Documentation>
<Parameter Name="EndPoint" Type="Object"/>
</Attribute>
<Attribute Name="Infinite" ReadOnly="false">
<Documentation>
<UserDocu>Defines the line as infinite. The StartPoint and EndPoint will be ignored as boundaries.</UserDocu>
</Documentation>
<Parameter Name="Infinite" Type="Boolean"/>
</Attribute>
-->
</PythonExport>
</GenerateModel>

View File

@ -0,0 +1,332 @@
/***************************************************************************
* Copyright (c) 2016 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* 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 <gp_Lin.hxx>
# include <Geom_Line.hxx>
# include <Geom_TrimmedCurve.hxx>
# include <GC_MakeLine.hxx>
# include <GC_MakeSegment.hxx>
# include <Precision.hxx>
#endif
#include <Base/VectorPy.h>
#include <Base/GeometryPyCXX.h>
#include <Mod/Part/App/OCCError.h>
#include <Mod/Part/App/Geometry.h>
#include <Mod/Part/App/Geom2d/Line2dSegmentPy.h>
#include <Mod/Part/App/Geom2d/Line2dSegmentPy.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 Line2dSegmentPy::representation(void) const
{
std::stringstream str;
//if(Infinite)
// str << "<Line infinite>";
//else {
Base::Vector2d start = getGeom2dLineSegmentPtr()->getStartPoint();
Base::Vector2d end = getGeom2dLineSegmentPtr()->getEndPoint();
str << "<Line2d ("
<< start.x << "," <<start.y << ") ("
<< end.x << "," <<end.y << ") >";
//}
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<Line2dSegmentPy*>(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<Line2dSegmentPy*>(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<Base::VectorPy*>(pV1)->value();
Base::Vector3d v2 = static_cast<Base::VectorPy*>(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<Base::VectorPy*>(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<Base::VectorPy*>(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;
}

View File

@ -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="Curve2dPy"
Name="OffsetCurve2dPy"
Twin="Geom2dOffsetCurve"
TwinPointer="Geom2dOffsetCurve"
Include="Mod/Part/App/Geometry2d.h"
Namespace="Part"
FatherInclude="Mod/Part/App/Geom2d/Curve2dPy.h"
FatherNamespace="Part"
Constructor="true">
<Documentation>
<Author Licence="LGPL" Name="Werner Mayer" EMail="wmayer@users.sourceforge.net" />
<UserDocu></UserDocu>
</Documentation>
<!--
<Attribute Name="OffsetValue">
<Documentation>
<UserDocu>
Sets or gets the offset value to offset the underlying curve.
</UserDocu>
</Documentation>
<Parameter Name="OffsetValue" Type="Float"/>
</Attribute>
<Attribute Name="OffsetDirection">
<Documentation>
<UserDocu>
Sets or gets the offset direction to offset the underlying curve.
</UserDocu>
</Documentation>
<Parameter Name="OffsetDirection" Type="Object"/>
</Attribute>
<Attribute Name="BasisCurve">
<Documentation>
<UserDocu>
Sets or gets the basic curve.
</UserDocu>
</Documentation>
<Parameter Name="BasisCurve" Type="Object"/>
</Attribute>
-->
</PythonExport>
</GenerateModel>

View File

@ -0,0 +1,165 @@
/***************************************************************************
* Copyright (c) 2008 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* 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 <Geom_OffsetCurve.hxx>
#endif
#include <Mod/Part/App/OCCError.h>
#include <Mod/Part/App/Geometry2d.h>
#include <Mod/Part/App/Geom2d/OffsetCurve2dPy.h>
#include <Mod/Part/App/Geom2d/OffsetCurve2dPy.cpp>
#include <Base/GeometryPyCXX.h>
#include <Base/VectorPy.h>
#include <Base/Vector3D.h>
using namespace Part;
// returns a string which represents the object e.g. when printed in python
std::string OffsetCurve2dPy::representation(void) const
{
return "<OffsetCurve2d object>";
}
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<GeometryPy*>(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<Base::VectorPy*>(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<Base::VectorPy*>(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<double>(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<GeometryPy*>(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;
}

View File

@ -0,0 +1,69 @@
<?xml version="1.0" encoding="UTF-8"?>
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd">
<PythonExport
Father="Conic2dPy"
Name="Parabola2dPy"
Twin="Geom2dParabola"
TwinPointer="Geom2dParabola"
Include="Mod/Part/App/Geometry2d.h"
Namespace="Part"
FatherInclude="Mod/Part/App/Geom2d/Conic2dPy.h"
FatherNamespace="Part"
Constructor="true">
<Documentation>
<Author Licence="LGPL" Name="Werner Mayer" EMail="wmayer@users.sourceforge.net" />
<UserDocu>Describes a parabola in 3D space</UserDocu>
</Documentation>
<!--
<Methode Name="compute">
<Documentation>
<UserDocu>
compute(p1,p2,p3)
The three points must lie on a plane parallel to xy plane and must not be collinear
</UserDocu>
</Documentation>
</Methode>
<Attribute Name="Eccentricity" ReadOnly="true">
<Documentation>
<UserDocu>Returns 1. (which is the eccentricity of any parabola).</UserDocu>
</Documentation>
<Parameter Name="Eccentricity" Type="Float"/>
</Attribute>
<Attribute Name="Focal" ReadOnly="false">
<Documentation>
<UserDocu>The focal distance is the distance between
the apex and the focus of the parabola.</UserDocu>
</Documentation>
<Parameter Name="Focal" Type="Float"/>
</Attribute>
<Attribute Name="Focus" ReadOnly="true">
<Documentation>
<UserDocu>The focus is on the positive side of the
'X Axis' of the local coordinate system of the parabola.</UserDocu>
</Documentation>
<Parameter Name="Focus" Type="Object"/>
</Attribute>
<Attribute Name="Parameter" ReadOnly="true">
<Documentation>
<UserDocu>Compute the parameter of this parabola
which is the distance between its focus
and its directrix. This distance is twice the focal length.
</UserDocu>
</Documentation>
<Parameter Name="Parameter" Type="Float"/>
</Attribute>
<Attribute Name="Location" ReadOnly="false">
<Documentation>
<UserDocu>Location of the parabola</UserDocu>
</Documentation>
<Parameter Name="Location" Type="Object"/>
</Attribute>
<Attribute Name="Axis" ReadOnly="false">
<Documentation>
<UserDocu>The axis direction of the parabola</UserDocu>
</Documentation>
<Parameter Name="Axis" Type="Object"/>
</Attribute>
-->
</PythonExport>
</GenerateModel>

View File

@ -0,0 +1,228 @@
/***************************************************************************
* Copyright (c) 2008 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* 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 <Geom_Parabola.hxx>
#endif
#include <Base/VectorPy.h>
#include <Base/GeometryPyCXX.h>
#include <Mod/Part/App/OCCError.h>
#include <Mod/Part/App/Geometry2d.h>
#include <Mod/Part/App/Geom2d/Parabola2dPy.h>
#include <Mod/Part/App/Geom2d/Parabola2dPy.cpp>
using namespace Part;
// returns a string which represents the object e.g. when printed in python
std::string Parabola2dPy::representation(void) const
{
return "<Parabola2d object>";
}
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<Base::VectorPy*>(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<Base::VectorPy*>(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;
}

File diff suppressed because it is too large Load Diff

View File

@ -36,6 +36,7 @@
#include <Geom2d_TrimmedCurve.hxx>
#include <Geom_Surface.hxx>
#include <TopoDS_Shape.hxx>
#include <gp_Ax22d.hxx>
#include <list>
#include <vector>
#include <Base/Persistence.h>
@ -189,7 +190,61 @@ private:
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 @@ public:
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 @@ private:
Handle_Geom2d_Circle myCurve;
};
class PartExport Geom2dArcOfCircle : public Geom2dCurve
class PartExport Geom2dArcOfCircle : public Geom2dArcOfConic
{
TYPESYSTEM_HEADER();
public:
@ -226,16 +278,8 @@ public:
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 @@ private:
Handle_Geom2d_TrimmedCurve myCurve;
};
class PartExport Geom2dEllipse : public Geom2dCurve
class PartExport Geom2dEllipse : public Geom2dConic
{
TYPESYSTEM_HEADER();
public:
@ -260,15 +304,12 @@ public:
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 @@ private:
Handle_Geom2d_Ellipse myCurve;
};
class PartExport Geom2dArcOfEllipse : public Geom2dCurve
class PartExport Geom2dArcOfEllipse : public Geom2dArcOfConic
{
TYPESYSTEM_HEADER();
public:
@ -293,21 +334,12 @@ public:
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 @@ private:
Handle_Geom2d_TrimmedCurve myCurve;
};
class PartExport Geom2dHyperbola : public Geom2dCurve
class PartExport Geom2dHyperbola : public Geom2dConic
{
TYPESYSTEM_HEADER();
public:
@ -332,8 +364,6 @@ public:
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 @@ private:
Handle_Geom2d_Hyperbola myCurve;
};
class PartExport Geom2dArcOfHyperbola : public Geom2dCurve
class PartExport Geom2dArcOfHyperbola : public Geom2dArcOfConic
{
TYPESYSTEM_HEADER();
public:
@ -361,18 +391,10 @@ public:
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 @@ private:
Handle_Geom2d_TrimmedCurve myCurve;
};
class PartExport Geom2dParabola : public Geom2dCurve
class PartExport Geom2dParabola : public Geom2dConic
{
TYPESYSTEM_HEADER();
public:
@ -397,8 +419,6 @@ public:
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 @@ private:
Handle_Geom2d_Parabola myCurve;
};
class PartExport Geom2dArcOfParabola : public Geom2dCurve
class PartExport Geom2dArcOfParabola : public Geom2dArcOfConic
{
TYPESYSTEM_HEADER();
public:
@ -424,16 +444,8 @@ public:
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;