+ add Python binding to Plate surface
This commit is contained in:
parent
fe522bc66b
commit
13e2b24ddf
|
@ -80,6 +80,7 @@
|
|||
#include "ConePy.h"
|
||||
#include "CylinderPy.h"
|
||||
#include "OffsetSurfacePy.h"
|
||||
#include "PlateSurfacePy.h"
|
||||
#include "PlanePy.h"
|
||||
#include "RectangularTrimmedSurfacePy.h"
|
||||
#include "SpherePy.h"
|
||||
|
@ -201,6 +202,7 @@ void PartExport initPart()
|
|||
Base::Interpreter().addType(&Part::BezierSurfacePy ::Type,partModule,"BezierSurface");
|
||||
Base::Interpreter().addType(&Part::BSplineSurfacePy ::Type,partModule,"BSplineSurface");
|
||||
Base::Interpreter().addType(&Part::OffsetSurfacePy ::Type,partModule,"OffsetSurface");
|
||||
Base::Interpreter().addType(&Part::PlateSurfacePy ::Type,partModule,"PlateSurface");
|
||||
Base::Interpreter().addType(&Part::SurfaceOfExtrusionPy ::Type,partModule,"SurfaceOfExtrusion");
|
||||
Base::Interpreter().addType(&Part::SurfaceOfRevolutionPy::Type,partModule,"SurfaceOfRevolution");
|
||||
Base::Interpreter().addType(&Part::RectangularTrimmedSurfacePy
|
||||
|
@ -298,6 +300,7 @@ void PartExport initPart()
|
|||
Part::GeomToroid ::init();
|
||||
Part::GeomPlane ::init();
|
||||
Part::GeomOffsetSurface ::init();
|
||||
Part::GeomPlateSurface ::init();
|
||||
Part::GeomTrimmedSurface ::init();
|
||||
Part::GeomSurfaceOfRevolution ::init();
|
||||
Part::GeomSurfaceOfExtrusion ::init();
|
||||
|
|
|
@ -62,13 +62,12 @@ generate_from_xml(ToroidPy)
|
|||
generate_from_xml(BezierSurfacePy)
|
||||
generate_from_xml(BSplineSurfacePy)
|
||||
generate_from_xml(OffsetSurfacePy)
|
||||
generate_from_xml(PlateSurfacePy)
|
||||
generate_from_xml(RectangularTrimmedSurfacePy)
|
||||
generate_from_xml(SurfaceOfExtrusionPy)
|
||||
generate_from_xml(SurfaceOfRevolutionPy)
|
||||
generate_from_xml(PartFeaturePy)
|
||||
generate_from_xml(Part2DObjectPy)
|
||||
generate_from_xml(OffsetSurfacePy)
|
||||
generate_from_xml(OffsetSurfacePy)
|
||||
generate_from_xml(TopoShapePy)
|
||||
generate_from_xml(TopoShapeCompoundPy)
|
||||
generate_from_xml(TopoShapeCompSolidPy)
|
||||
|
@ -197,6 +196,8 @@ SET(Python_SRCS
|
|||
BSplineSurfacePyImp.cpp
|
||||
OffsetSurfacePy.xml
|
||||
OffsetSurfacePyImp.cpp
|
||||
PlateSurfacePy.xml
|
||||
PlateSurfacePyImp.cpp
|
||||
RectangularTrimmedSurfacePy.xml
|
||||
RectangularTrimmedSurfacePyImp.cpp
|
||||
SurfaceOfExtrusionPy.xml
|
||||
|
|
|
@ -46,6 +46,7 @@
|
|||
# include <Geom_SphericalSurface.hxx>
|
||||
# include <Geom_ToroidalSurface.hxx>
|
||||
# include <Geom_OffsetSurface.hxx>
|
||||
# include <GeomPlate_Surface.hxx>
|
||||
# include <Geom_RectangularTrimmedSurface.hxx>
|
||||
# include <Geom_SurfaceOfRevolution.hxx>
|
||||
# include <Geom_SurfaceOfLinearExtrusion.hxx>
|
||||
|
@ -184,13 +185,13 @@ unsigned int Geometry::getMemSize (void) const
|
|||
return 1;
|
||||
}
|
||||
|
||||
void Geometry::Save (Base::Writer &writer) const
|
||||
void Geometry::Save(Base::Writer &writer) const
|
||||
{
|
||||
const char c = Construction?'1':'0';
|
||||
writer.Stream() << writer.ind() << "<Construction value=\"" << c << "\"/>" << endl;
|
||||
}
|
||||
|
||||
void Geometry::Restore (Base::XMLReader &reader)
|
||||
void Geometry::Restore(Base::XMLReader &reader)
|
||||
{
|
||||
// read my Element
|
||||
reader.readElement("Construction");
|
||||
|
@ -249,7 +250,7 @@ void GeomPoint::setPoint(const Base::Vector3d& p)
|
|||
}
|
||||
|
||||
// Persistence implementer
|
||||
unsigned int GeomPoint::getMemSize (void) const
|
||||
unsigned int GeomPoint::getMemSize (void) const
|
||||
{
|
||||
return sizeof(Geom_CartesianPoint);
|
||||
}
|
||||
|
@ -3214,6 +3215,7 @@ PyObject *GeomPlane::getPyObject(void)
|
|||
{
|
||||
return new PlanePy((GeomPlane*)this->clone());
|
||||
}
|
||||
|
||||
// -------------------------------------------------
|
||||
|
||||
TYPESYSTEM_SOURCE(Part::GeomOffsetSurface,Part::GeomSurface);
|
||||
|
@ -3265,6 +3267,73 @@ PyObject *GeomOffsetSurface::getPyObject(void)
|
|||
|
||||
// -------------------------------------------------
|
||||
|
||||
TYPESYSTEM_SOURCE(Part::GeomPlateSurface,Part::GeomSurface);
|
||||
|
||||
GeomPlateSurface::GeomPlateSurface()
|
||||
{
|
||||
}
|
||||
|
||||
GeomPlateSurface::GeomPlateSurface(const Handle_Geom_Surface& s, const Plate_Plate& plate)
|
||||
{
|
||||
this->mySurface = new GeomPlate_Surface(s, plate);
|
||||
}
|
||||
|
||||
GeomPlateSurface::GeomPlateSurface(const GeomPlate_BuildPlateSurface& buildPlate)
|
||||
{
|
||||
Handle_GeomPlate_Surface s = buildPlate.Surface();
|
||||
this->mySurface = Handle_GeomPlate_Surface::DownCast(s->Copy());
|
||||
}
|
||||
|
||||
GeomPlateSurface::GeomPlateSurface(const Handle_GeomPlate_Surface& s)
|
||||
{
|
||||
this->mySurface = Handle_GeomPlate_Surface::DownCast(s->Copy());
|
||||
}
|
||||
|
||||
GeomPlateSurface::~GeomPlateSurface()
|
||||
{
|
||||
}
|
||||
|
||||
void GeomPlateSurface::setHandle(const Handle_GeomPlate_Surface& s)
|
||||
{
|
||||
mySurface = Handle_GeomPlate_Surface::DownCast(s->Copy());
|
||||
}
|
||||
|
||||
const Handle_Geom_Geometry& GeomPlateSurface::handle() const
|
||||
{
|
||||
return mySurface;
|
||||
}
|
||||
|
||||
Geometry *GeomPlateSurface::clone(void) const
|
||||
{
|
||||
GeomPlateSurface *newSurf = new GeomPlateSurface(mySurface);
|
||||
newSurf->Construction = this->Construction;
|
||||
return newSurf;
|
||||
}
|
||||
|
||||
// Persistence implementer
|
||||
unsigned int GeomPlateSurface::getMemSize (void) const
|
||||
{
|
||||
throw Base::NotImplementedError("GeomPlateSurface::getMemSize");
|
||||
}
|
||||
|
||||
void GeomPlateSurface::Save(Base::Writer &/*writer*/) const
|
||||
{
|
||||
throw Base::NotImplementedError("GeomPlateSurface::Save");
|
||||
}
|
||||
|
||||
void GeomPlateSurface::Restore(Base::XMLReader &/*reader*/)
|
||||
{
|
||||
throw Base::NotImplementedError("GeomPlateSurface::Restore");
|
||||
}
|
||||
|
||||
PyObject *GeomPlateSurface::getPyObject(void)
|
||||
{
|
||||
throw Base::NotImplementedError("GeomPlateSurface::getPyObject");
|
||||
// return new PlateSurfacePy(static_cast<GeomPlateSurface*>(this->clone()));
|
||||
}
|
||||
|
||||
// -------------------------------------------------
|
||||
|
||||
TYPESYSTEM_SOURCE(Part::GeomTrimmedSurface,Part::GeomSurface);
|
||||
|
||||
GeomTrimmedSurface::GeomTrimmedSurface()
|
||||
|
|
|
@ -43,9 +43,12 @@
|
|||
#include <Handle_Geom_ToroidalSurface.hxx>
|
||||
#include <Handle_Geom_Plane.hxx>
|
||||
#include <Handle_Geom_OffsetSurface.hxx>
|
||||
#include <Handle_GeomPlate_Surface.hxx>
|
||||
#include <Handle_Geom_RectangularTrimmedSurface.hxx>
|
||||
#include <Handle_Geom_SurfaceOfRevolution.hxx>
|
||||
#include <Handle_Geom_SurfaceOfLinearExtrusion.hxx>
|
||||
#include <GeomPlate_BuildPlateSurface.hxx>
|
||||
#include <Plate_Plate.hxx>
|
||||
#include <TopoDS_Shape.hxx>
|
||||
#include <gp_Ax1.hxx>
|
||||
#include <gp_Dir.hxx>
|
||||
|
@ -746,6 +749,31 @@ private:
|
|||
Handle_Geom_OffsetSurface mySurface;
|
||||
};
|
||||
|
||||
class PartExport GeomPlateSurface : public GeomSurface
|
||||
{
|
||||
TYPESYSTEM_HEADER();
|
||||
public:
|
||||
GeomPlateSurface();
|
||||
GeomPlateSurface(const Handle_Geom_Surface&, const Plate_Plate&);
|
||||
GeomPlateSurface(const GeomPlate_BuildPlateSurface&);
|
||||
GeomPlateSurface(const Handle_GeomPlate_Surface&);
|
||||
virtual ~GeomPlateSurface();
|
||||
virtual Geometry *clone(void) const;
|
||||
|
||||
// Persistence implementer ---------------------
|
||||
virtual unsigned int getMemSize(void) const;
|
||||
virtual void Save(Base::Writer &/*writer*/) const;
|
||||
virtual void Restore(Base::XMLReader &/*reader*/);
|
||||
// Base implementer ----------------------------
|
||||
virtual PyObject *getPyObject(void);
|
||||
|
||||
void setHandle(const Handle_GeomPlate_Surface& s);
|
||||
const Handle_Geom_Geometry& handle() const;
|
||||
|
||||
private:
|
||||
Handle_GeomPlate_Surface mySurface;
|
||||
};
|
||||
|
||||
class PartExport GeomTrimmedSurface : public GeomSurface
|
||||
{
|
||||
TYPESYSTEM_HEADER();
|
||||
|
|
33
src/Mod/Part/App/PlateSurfacePy.xml
Normal file
33
src/Mod/Part/App/PlateSurfacePy.xml
Normal file
|
@ -0,0 +1,33 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd">
|
||||
<PythonExport
|
||||
Father="GeometrySurfacePy"
|
||||
Name="PlateSurfacePy"
|
||||
Twin="GeomPlateSurface"
|
||||
TwinPointer="GeomPlateSurface"
|
||||
Include="Mod/Part/App/Geometry.h"
|
||||
Namespace="Part"
|
||||
FatherInclude="Mod/Part/App/GeometrySurfacePy.h"
|
||||
FatherNamespace="Part"
|
||||
Constructor="true">
|
||||
<Documentation>
|
||||
<Author Licence="LGPL" Name="Werner Mayer" EMail="wmayer@users.sourceforge.net" />
|
||||
<UserDocu></UserDocu>
|
||||
</Documentation>
|
||||
<Methode Name="uIso">
|
||||
<Documentation>
|
||||
<UserDocu>Builds the U isoparametric line of this surface</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Methode Name="vIso">
|
||||
<Documentation>
|
||||
<UserDocu>Builds the V isoparametric line of this surface</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Methode Name="makeApprox" Keyword="true">
|
||||
<Documentation>
|
||||
<UserDocu>Approximate the plate surface to a B-Spline surface</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
</PythonExport>
|
||||
</GenerateModel>
|
208
src/Mod/Part/App/PlateSurfacePyImp.cpp
Normal file
208
src/Mod/Part/App/PlateSurfacePyImp.cpp
Normal file
|
@ -0,0 +1,208 @@
|
|||
/***************************************************************************
|
||||
* Copyright (c) 2015 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 <GeomPlate_MakeApprox.hxx>
|
||||
# include <GeomPlate_Surface.hxx>
|
||||
# include <GeomPlate_BuildPlateSurface.hxx>
|
||||
# include <GeomPlate_PointConstraint.hxx>
|
||||
# include <GeomPlate_CurveConstraint.hxx>
|
||||
#endif
|
||||
|
||||
#include <Base/GeometryPyCXX.h>
|
||||
#include <Base/VectorPy.h>
|
||||
#include <Base/Vector3D.h>
|
||||
|
||||
#include "OCCError.h"
|
||||
#include "Geometry.h"
|
||||
#include "PlateSurfacePy.h"
|
||||
#include "PlateSurfacePy.cpp"
|
||||
#include "BSplineSurfacePy.h"
|
||||
|
||||
using namespace Part;
|
||||
|
||||
// returns a string which represents the object e.g. when printed in python
|
||||
std::string PlateSurfacePy::representation(void) const
|
||||
{
|
||||
return "<PlateSurface object>";
|
||||
}
|
||||
|
||||
PyObject *PlateSurfacePy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper
|
||||
{
|
||||
// create a new instance of PlateSurfacePy and the Twin object
|
||||
return new PlateSurfacePy(new GeomPlateSurface);
|
||||
}
|
||||
|
||||
// constructor method
|
||||
int PlateSurfacePy::PyInit(PyObject* args, PyObject* kwds)
|
||||
{
|
||||
static char* kwds_Parameter[] = {"Surface","Points","Curves","Degree",
|
||||
"NbPtsOnCur","NbIter","Tol2d","Tol3d","TolAng","TolCurv","Anisotropie",NULL};
|
||||
|
||||
PyObject* surface = 0;
|
||||
PyObject* points = 0;
|
||||
PyObject* curves = 0;
|
||||
int Degree = 3;
|
||||
int NbPtsOnCur = 10;
|
||||
int NbIter = 3;
|
||||
double Tol2d = 0.00001;
|
||||
double Tol3d = 0.0001;
|
||||
double TolAng = 0.01;
|
||||
double TolCurv = 0.1;
|
||||
PyObject* Anisotropie = Py_False;
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O!OOiiiddddO!", kwds_Parameter,
|
||||
&(GeometryPy::Type), &surface, &points, &curves,
|
||||
&Degree, &NbPtsOnCur, &NbIter, &Tol2d, &Tol3d, &TolAng, &TolCurv,
|
||||
&PyBool_Type,&Anisotropie))
|
||||
return -1;
|
||||
|
||||
if (!surface && !points && !curves) {
|
||||
PyErr_SetString(PyExc_ValueError, "set points or curves as constraints");
|
||||
return -1;
|
||||
}
|
||||
|
||||
Handle_Geom_Surface surf;
|
||||
if (surface) {
|
||||
GeometryPy* pcGeo = static_cast<GeometryPy*>(surface);
|
||||
surf = Handle_Geom_Surface::DownCast
|
||||
(pcGeo->getGeometryPtr()->handle());
|
||||
if (surf.IsNull()) {
|
||||
PyErr_SetString(PyExc_TypeError, "geometry is not a surface");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
GeomPlate_BuildPlateSurface buildPlate(Degree, NbPtsOnCur, NbIter, Tol2d, Tol3d, TolAng, TolCurv,
|
||||
PyObject_IsTrue(Anisotropie) ? Standard_True : Standard_False);
|
||||
if (!surf.IsNull()) {
|
||||
buildPlate.LoadInitSurface(surf);
|
||||
|
||||
if (!points && !curves) {
|
||||
Standard_Real U1,U2,V1,V2;
|
||||
surf->Bounds(U1,U2,V1,V2);
|
||||
buildPlate.Add(new GeomPlate_PointConstraint(surf->Value(U1,V1),0));
|
||||
buildPlate.Add(new GeomPlate_PointConstraint(surf->Value(U1,V2),0));
|
||||
buildPlate.Add(new GeomPlate_PointConstraint(surf->Value(U2,V1),0));
|
||||
buildPlate.Add(new GeomPlate_PointConstraint(surf->Value(U2,V2),0));
|
||||
}
|
||||
}
|
||||
|
||||
if (points) {
|
||||
Py::Sequence list(points);
|
||||
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
|
||||
Base::Vector3d vec = Py::Vector(*it).toVector();
|
||||
Handle(GeomPlate_PointConstraint) PCont = new GeomPlate_PointConstraint(gp_Pnt(vec.x,vec.y,vec.z),0);
|
||||
buildPlate.Add(PCont);
|
||||
}
|
||||
}
|
||||
|
||||
if (curves) {
|
||||
Py::Sequence list(curves);
|
||||
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
|
||||
//TODO
|
||||
}
|
||||
}
|
||||
|
||||
buildPlate.Perform();
|
||||
getGeomPlateSurfacePtr()->setHandle(buildPlate.Surface());
|
||||
return 0;
|
||||
}
|
||||
catch (Standard_Failure) {
|
||||
Handle_Standard_Failure e = Standard_Failure::Caught();
|
||||
PyErr_SetString(PartExceptionOCCError, e->GetMessageString());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
PyObject* PlateSurfacePy::makeApprox(PyObject *args, PyObject* kwds)
|
||||
{
|
||||
static char* kwds_Parameter[] = {"Tol3d","MaxSegments","MaxDegree","MaxDistance",
|
||||
"CritOrder","Continuity","EnlargeCoeff",NULL};
|
||||
|
||||
double tol3d=0.01;
|
||||
int maxSeg=9;
|
||||
int maxDegree=3;
|
||||
double dmax = 0.0001;
|
||||
int critOrder=0;
|
||||
char* cont = "C1";
|
||||
double enlargeCoeff = 1.1;
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|diidisd", kwds_Parameter,
|
||||
&tol3d, &maxSeg, &maxDegree, &dmax, &critOrder, &cont, &enlargeCoeff))
|
||||
return 0;
|
||||
|
||||
GeomAbs_Shape continuity;
|
||||
std::string uc = cont;
|
||||
if (uc == "C0")
|
||||
continuity = GeomAbs_C0;
|
||||
else if (uc == "C1")
|
||||
continuity = GeomAbs_C1;
|
||||
else if (uc == "C2")
|
||||
continuity = GeomAbs_C2;
|
||||
else if (uc == "C3")
|
||||
continuity = GeomAbs_C3;
|
||||
else if (uc == "CN")
|
||||
continuity = GeomAbs_CN;
|
||||
else if (uc == "G1")
|
||||
continuity = GeomAbs_G1;
|
||||
else
|
||||
continuity = GeomAbs_C1;
|
||||
|
||||
PY_TRY {
|
||||
GeomPlate_MakeApprox approx(Handle_GeomPlate_Surface::DownCast(getGeomPlateSurfacePtr()->handle()),
|
||||
tol3d, maxSeg, maxDegree, dmax, critOrder, continuity, enlargeCoeff);
|
||||
Handle_Geom_BSplineSurface hSurf = approx.Surface();
|
||||
|
||||
if (!hSurf.IsNull()) {
|
||||
return new Part::BSplineSurfacePy(new Part::GeomBSplineSurface(hSurf));
|
||||
}
|
||||
|
||||
PyErr_SetString(PyExc_RuntimeError, "Approximation of B-Spline surface failed");
|
||||
return 0;
|
||||
} PY_CATCH_OCC;
|
||||
}
|
||||
|
||||
PyObject* PlateSurfacePy::uIso(PyObject *args)
|
||||
{
|
||||
PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
|
||||
return 0;
|
||||
}
|
||||
|
||||
PyObject* PlateSurfacePy::vIso(PyObject *args)
|
||||
{
|
||||
PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
|
||||
return 0;
|
||||
}
|
||||
|
||||
PyObject *PlateSurfacePy::getCustomAttributes(const char* /*attr*/) const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int PlateSurfacePy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
|
||||
{
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user