1
/***************************************************************************
2
* Copyright (c) 2020 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 <Standard_Failure.hxx>
28
#include "GeomPlate/BuildPlateSurfacePy.h"
29
#include "GeomPlate/BuildPlateSurfacePy.cpp"
30
#include "GeomPlate/CurveConstraintPy.h"
31
#include "GeomPlate/PointConstraintPy.h"
32
#include "Geometry2d.h"
33
#include "GeometrySurfacePy.h"
35
#include <Base/PyWrapParseTupleAndKeywords.h>
41
* \brief BuildPlateSurfacePy::PyMake
49
l1=Part.LineSegment(v1, v2)
50
l2=Part.LineSegment(v2, v3)
51
l3=Part.LineSegment(v3, v4)
52
l4=Part.LineSegment(v4, v1)
54
c1=Part.GeomPlate.CurveConstraint(l1)
55
c2=Part.GeomPlate.CurveConstraint(l2)
56
c3=Part.GeomPlate.CurveConstraint(l3)
57
c4=Part.GeomPlate.CurveConstraint(l4)
58
c5=Part.GeomPlate.PointConstraint(v5)
60
bp=Part.GeomPlate.BuildPlateSurface()
69
Part.show(bs.toShape())
70
Part.show(l1.toShape())
71
Part.show(l2.toShape())
72
Part.show(l3.toShape())
73
Part.show(l4.toShape())
78
PyObject *BuildPlateSurfacePy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper
80
// create a new instance of BuildPlateSurfacePy
81
return new BuildPlateSurfacePy(nullptr);
85
int BuildPlateSurfacePy::PyInit(PyObject* args, PyObject* kwds)
87
PyObject *surf = nullptr;
91
double tol2d = 0.00001;
92
double tol3d = 0.0001;
95
PyObject* anisotropy = Py_False;
97
static const std::array<const char *, 10> keywords{"Surface", "Degree", "NbPtsOnCur", "NbIter", "Tol2d", "Tol3d",
98
"TolAng", "TolCurv", "Anisotropy", nullptr};
99
if (!Base::Wrapped_ParseTupleAndKeywords(args, kwds, "|O!iiiddddO!", keywords,
100
&(GeometrySurfacePy::Type), &surf, °ree,
101
&nbPtsOnCur, &nbIter, &tol2d, &tol3d,
102
&tolAng, &tolCurv, &PyBool_Type, &anisotropy)) {
107
std::unique_ptr<GeomPlate_BuildPlateSurface> ptr(new GeomPlate_BuildPlateSurface
108
(degree, nbPtsOnCur, nbIter, tol2d, tol3d, tolAng, tolCurv,
109
Base::asBoolean(anisotropy)));
112
GeomSurface* surface = static_cast<GeometrySurfacePy*>(surf)->getGeomSurfacePtr();
113
Handle(Geom_Surface) handle = Handle(Geom_Surface)::DownCast(surface->handle());
114
if (handle.IsNull()) {
115
PyErr_SetString(PyExc_ReferenceError, "No valid surface handle");
118
ptr->LoadInitSurface(handle);
121
setTwinPointer(ptr.release());
125
catch (const Standard_Failure& e) {
126
PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
131
// returns a string which represents the object e.g. when printed in python
132
std::string BuildPlateSurfacePy::representation() const
134
return {"<GeomPlate_BuildPlateSurface object>"};
137
PyObject* BuildPlateSurfacePy::init(PyObject *args)
139
if (!PyArg_ParseTuple(args, ""))
143
getGeomPlate_BuildPlateSurfacePtr()->Init();
146
catch (const Standard_Failure& e) {
147
PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
152
PyObject* BuildPlateSurfacePy::loadInitSurface(PyObject *args)
155
if (!PyArg_ParseTuple(args, "O!", &(GeometrySurfacePy::Type), &surf))
158
GeomSurface* surface = static_cast<GeometrySurfacePy*>(surf)->getGeomSurfacePtr();
159
Handle(Geom_Surface) handle = Handle(Geom_Surface)::DownCast(surface->handle());
160
if (handle.IsNull()) {
161
PyErr_SetString(PyExc_ReferenceError, "No valid surface handle");
166
getGeomPlate_BuildPlateSurfacePtr()->LoadInitSurface(handle);
169
catch (const Standard_Failure& e) {
170
PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
175
PyObject* BuildPlateSurfacePy::add(PyObject *args)
178
if (!PyArg_ParseTuple(args, "O", &cont))
182
if (PyObject_TypeCheck(cont, &PointConstraintPy::Type)) {
183
GeomPlate_PointConstraint* pc = static_cast<PointConstraintPy*>(cont)->getGeomPlate_PointConstraintPtr();
184
getGeomPlate_BuildPlateSurfacePtr()->Add(new GeomPlate_PointConstraint(*pc));
187
else if (PyObject_TypeCheck(cont, &CurveConstraintPy::Type)) {
188
GeomPlate_CurveConstraint* cc = static_cast<CurveConstraintPy*>(cont)->getGeomPlate_CurveConstraintPtr();
189
getGeomPlate_BuildPlateSurfacePtr()->Add(new GeomPlate_CurveConstraint(*cc));
193
PyErr_SetString(PyExc_TypeError, "PointConstraint or CurveConstraint expected");
197
catch (const Standard_Failure& e) {
198
PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
203
PyObject* BuildPlateSurfacePy::setNbBounds(PyObject *args)
206
if (!PyArg_ParseTuple(args, "i", &count))
210
getGeomPlate_BuildPlateSurfacePtr()->SetNbBounds(count);
213
catch (const Standard_Failure& e) {
214
PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
219
PyObject* BuildPlateSurfacePy::perform(PyObject *args)
221
if (!PyArg_ParseTuple(args, ""))
225
getGeomPlate_BuildPlateSurfacePtr()->Perform();
228
catch (const Standard_Failure& e) {
229
PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
234
PyObject* BuildPlateSurfacePy::isDone(PyObject *args)
236
if (!PyArg_ParseTuple(args, ""))
240
Standard_Boolean ok = getGeomPlate_BuildPlateSurfacePtr()->IsDone();
241
return Py_BuildValue("O", (ok ? Py_True : Py_False));
243
catch (const Standard_Failure& e) {
244
PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
249
PyObject* BuildPlateSurfacePy::surface(PyObject *args)
251
if (!PyArg_ParseTuple(args, ""))
255
Handle(Geom_Surface) hSurf = getGeomPlate_BuildPlateSurfacePtr()->Surface();
259
std::unique_ptr<GeomSurface> geo(makeFromSurface(hSurf));
260
return geo->getPyObject();
262
catch (const Standard_Failure& e) {
263
PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
268
PyObject* BuildPlateSurfacePy::surfInit(PyObject *args)
270
if (!PyArg_ParseTuple(args, ""))
274
Handle(Geom_Surface) hSurf = getGeomPlate_BuildPlateSurfacePtr()->SurfInit();
278
std::unique_ptr<GeomSurface> geo(makeFromSurface(hSurf));
279
return geo->getPyObject();
281
catch (const Standard_Failure& e) {
282
PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
287
PyObject* BuildPlateSurfacePy::curveConstraint(PyObject *args)
290
if (!PyArg_ParseTuple(args, "i", &index))
294
Handle(GeomPlate_CurveConstraint) hCC = getGeomPlate_BuildPlateSurfacePtr()->CurveConstraint(index);
298
std::unique_ptr<GeomPlate_CurveConstraint> ptr(new GeomPlate_CurveConstraint(*hCC));
299
return new CurveConstraintPy(ptr.release());
301
catch (const Standard_Failure& e) {
302
PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
307
PyObject* BuildPlateSurfacePy::pointConstraint(PyObject *args)
310
if (!PyArg_ParseTuple(args, "i", &index))
314
Handle(GeomPlate_PointConstraint) hPC = getGeomPlate_BuildPlateSurfacePtr()->PointConstraint(index);
318
std::unique_ptr<GeomPlate_PointConstraint> ptr(new GeomPlate_PointConstraint(*hPC));
319
return new PointConstraintPy(ptr.release());
321
catch (const Standard_Failure& e) {
322
PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
327
PyObject* BuildPlateSurfacePy::disc2dContour(PyObject *args)
330
if (!PyArg_ParseTuple(args, "i", &index))
334
TColgp_SequenceOfXY seq2d;
335
getGeomPlate_BuildPlateSurfacePtr()->Disc2dContour(index, seq2d);
338
for (int i = seq2d.Lower(); i <= seq2d.Upper(); ++i) {
339
const gp_XY& pnt = seq2d.Value(i);
341
coord.setItem(0, Py::Float(pnt.X()));
342
coord.setItem(1, Py::Float(pnt.Y()));
346
return Py::new_reference_to(list);
348
catch (const Standard_Failure& e) {
349
PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
354
PyObject* BuildPlateSurfacePy::disc3dContour(PyObject *args)
357
if (!PyArg_ParseTuple(args, "ii", &index, &order))
361
TColgp_SequenceOfXYZ seq3d;
362
getGeomPlate_BuildPlateSurfacePtr()->Disc3dContour(index, order, seq3d);
365
for (int i = seq3d.Lower(); i <= seq3d.Upper(); ++i) {
366
const gp_XYZ& pnt = seq3d.Value(i);
368
coord.setItem(0, Py::Float(pnt.X()));
369
coord.setItem(1, Py::Float(pnt.Y()));
370
coord.setItem(2, Py::Float(pnt.Z()));
374
return Py::new_reference_to(list);
376
catch (const Standard_Failure& e) {
377
PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
382
PyObject* BuildPlateSurfacePy::sense(PyObject *args)
384
if (!PyArg_ParseTuple(args, ""))
388
Handle(TColStd_HArray1OfInteger) hOrder = getGeomPlate_BuildPlateSurfacePtr()->Sense();
390
if (!hOrder.IsNull()) {
391
for (auto i = hOrder->Lower(); i <= hOrder->Upper(); ++i) {
392
list.append(Py::Long(hOrder->Value(i)));
395
return Py::new_reference_to(list);
397
catch (const Standard_Failure& e) {
398
PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
403
PyObject* BuildPlateSurfacePy::curves2d(PyObject *args)
405
if (!PyArg_ParseTuple(args, ""))
409
Handle(TColGeom2d_HArray1OfCurve) hCurves = getGeomPlate_BuildPlateSurfacePtr()->Curves2d();
411
if (!hCurves.IsNull()) {
412
for (auto i = hCurves->Lower(); i <= hCurves->Upper(); ++i) {
413
Handle(Geom2d_Curve) hCurve = hCurves->Value(i);
414
std::unique_ptr<Geom2dCurve> ptr(makeFromCurve2d(hCurve));
416
list.append(Py::asObject(ptr->getPyObject()));
419
return Py::new_reference_to(list);
421
catch (const Standard_Failure& e) {
422
PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
427
PyObject* BuildPlateSurfacePy::order(PyObject *args)
429
if (!PyArg_ParseTuple(args, ""))
433
Handle(TColStd_HArray1OfInteger) hOrder = getGeomPlate_BuildPlateSurfacePtr()->Order();
435
if (!hOrder.IsNull()) {
436
for (auto i = hOrder->Lower(); i <= hOrder->Upper(); ++i) {
437
list.append(Py::Long(hOrder->Value(i)));
440
return Py::new_reference_to(list);
442
catch (const Standard_Failure& e) {
443
PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
448
PyObject* BuildPlateSurfacePy::G0Error(PyObject *args)
451
if (!PyArg_ParseTuple(args, "|i", &index))
455
Standard_Real v = index < 1 ? getGeomPlate_BuildPlateSurfacePtr()->G0Error()
456
: getGeomPlate_BuildPlateSurfacePtr()->G0Error(index);
457
return PyFloat_FromDouble(v);
459
catch (const Standard_Failure& e) {
460
PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
465
PyObject* BuildPlateSurfacePy::G1Error(PyObject *args)
468
if (!PyArg_ParseTuple(args, "|i", &index))
472
Standard_Real v = index < 1 ? getGeomPlate_BuildPlateSurfacePtr()->G1Error()
473
: getGeomPlate_BuildPlateSurfacePtr()->G1Error(index);
474
return PyFloat_FromDouble(v);
476
catch (const Standard_Failure& e) {
477
PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
482
PyObject* BuildPlateSurfacePy::G2Error(PyObject *args)
485
if (!PyArg_ParseTuple(args, "|i", &index))
489
Standard_Real v = index < 1 ? getGeomPlate_BuildPlateSurfacePtr()->G2Error()
490
: getGeomPlate_BuildPlateSurfacePtr()->G2Error(index);
491
return PyFloat_FromDouble(v);
493
catch (const Standard_Failure& e) {
494
PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
499
PyObject *BuildPlateSurfacePy::getCustomAttributes(const char* /*attr*/) const
504
int BuildPlateSurfacePy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)