1
/***************************************************************************
2
* Copyright (c) 2015 Werner Mayer <wmayer[at]users.sourceforge.net> *
4
* This file is part of the FreeCAD CAx development system. *
6
* This library is free software; you can redistribute it and/or *
7
* modify it under the terms of the GNU Library General Public *
8
* License as published by the Free Software Foundation; either *
9
* version 2 of the License, or (at your option) any later version. *
11
* This library is distributed in the hope that it will be useful, *
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
* GNU Library General Public License for more details. *
16
* You should have received a copy of the GNU Library General Public *
17
* License along with this library; see the file COPYING.LIB. If not, *
18
* write to the Free Software Foundation, Inc., 59 Temple Place, *
19
* Suite 330, Boston, MA 02111-1307, USA *
21
***************************************************************************/
23
#include "PreCompiled.h"
25
# include <GeomPlate_BuildPlateSurface.hxx>
26
# include <GeomPlate_MakeApprox.hxx>
27
# include <GeomPlate_PointConstraint.hxx>
28
# include <GeomPlate_Surface.hxx>
31
#include <Base/GeometryPyCXX.h>
32
#include <Base/PyWrapParseTupleAndKeywords.h>
33
#include <Base/VectorPy.h>
34
#include <Base/Vector3D.h>
36
#include "PlateSurfacePy.h"
37
#include "PlateSurfacePy.cpp"
38
#include "BSplineSurfacePy.h"
44
// returns a string which represents the object e.g. when printed in python
45
std::string PlateSurfacePy::representation() const
47
return "<PlateSurface object>";
50
PyObject *PlateSurfacePy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper
52
// create a new instance of PlateSurfacePy and the Twin object
53
return new PlateSurfacePy(new GeomPlateSurface);
57
int PlateSurfacePy::PyInit(PyObject* args, PyObject* kwds)
59
static const std::array<const char *, 12> kwds_Parameter{"Surface", "Points", "Curves", "Degree",
60
"NbPtsOnCur", "NbIter", "Tol2d", "Tol3d", "TolAng",
61
"TolCurv", "Anisotropie", nullptr};
63
PyObject* surface = nullptr;
64
PyObject* points = nullptr;
65
PyObject* curves = nullptr;
69
double Tol2d = 0.00001;
70
double Tol3d = 0.0001;
73
PyObject* Anisotropie = Py_False; // NOLINT
75
if (!Base::Wrapped_ParseTupleAndKeywords(args, kwds, "|O!OOiiiddddO!", kwds_Parameter,
76
&(GeometryPy::Type), &surface, &points, &curves,
77
&Degree, &NbPtsOnCur, &NbIter, &Tol2d, &Tol3d, &TolAng, &TolCurv,
78
&PyBool_Type, &Anisotropie)) {
82
if (!surface && !points && !curves) {
83
PyErr_SetString(PyExc_ValueError, "set points or curves as constraints");
87
Handle(Geom_Surface) surf;
89
GeometryPy* pcGeo = static_cast<GeometryPy*>(surface);
90
surf = Handle(Geom_Surface)::DownCast
91
(pcGeo->getGeometryPtr()->handle());
93
PyErr_SetString(PyExc_TypeError, "geometry is not a surface");
99
GeomPlate_BuildPlateSurface buildPlate(Degree, NbPtsOnCur, NbIter, Tol2d, Tol3d, TolAng, TolCurv,
100
Base::asBoolean(Anisotropie));
101
if (!surf.IsNull()) {
102
buildPlate.LoadInitSurface(surf);
104
if (!points && !curves) {
105
Standard_Real U1,U2,V1,V2;
106
surf->Bounds(U1,U2,V1,V2);
107
buildPlate.Add(new GeomPlate_PointConstraint(surf->Value(U1,V1),0));
108
buildPlate.Add(new GeomPlate_PointConstraint(surf->Value(U1,V2),0));
109
buildPlate.Add(new GeomPlate_PointConstraint(surf->Value(U2,V1),0));
110
buildPlate.Add(new GeomPlate_PointConstraint(surf->Value(U2,V2),0));
115
Py::Sequence list(points);
116
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
117
Base::Vector3d vec = Py::Vector(*it).toVector();
118
Handle(GeomPlate_PointConstraint) PCont = new GeomPlate_PointConstraint(gp_Pnt(vec.x,vec.y,vec.z),0);
119
buildPlate.Add(PCont);
124
Py::Sequence list(curves);
125
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
130
buildPlate.Perform();
131
getGeomPlateSurfacePtr()->setHandle(buildPlate.Surface());
134
catch (Standard_Failure& e) {
136
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
141
PyObject* PlateSurfacePy::makeApprox(PyObject *args, PyObject* kwds)
143
static const std::array<const char *, 8> kwds_Parameter{"Tol3d", "MaxSegments", "MaxDegree", "MaxDistance",
144
"CritOrder", "Continuity", "EnlargeCoeff", nullptr};
149
double dmax = 0.0001;
151
const char* cont = "C1";
152
double enlargeCoeff = 1.1;
154
if (!Base::Wrapped_ParseTupleAndKeywords(args, kwds, "|diidisd", kwds_Parameter,
155
&tol3d, &maxSeg, &maxDegree, &dmax, &critOrder, &cont, &enlargeCoeff)) {
159
GeomAbs_Shape continuity;
160
std::string uc = cont;
162
continuity = GeomAbs_C0;
164
continuity = GeomAbs_C1;
166
continuity = GeomAbs_C2;
168
continuity = GeomAbs_C3;
170
continuity = GeomAbs_CN;
172
continuity = GeomAbs_G1;
174
continuity = GeomAbs_C1;
177
GeomPlate_MakeApprox approx(Handle(GeomPlate_Surface)::DownCast(getGeomPlateSurfacePtr()->handle()),
178
tol3d, maxSeg, maxDegree, dmax, critOrder, continuity, enlargeCoeff);
179
Handle(Geom_BSplineSurface) hSurf = approx.Surface();
181
if (!hSurf.IsNull()) {
182
return new Part::BSplineSurfacePy(new Part::GeomBSplineSurface(hSurf));
185
PyErr_SetString(PyExc_RuntimeError, "Approximation of B-spline surface failed");
190
PyObject *PlateSurfacePy::getCustomAttributes(const char* /*attr*/) const
195
int PlateSurfacePy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)