FreeCAD

Форк
0
/
AppMeshPartPy.cpp 
652 строки · 28.8 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2008 Jürgen Riegel <juergen.riegel@web.de>              *
3
 *                                                                         *
4
 *   This file is part of the FreeCAD CAx development system.              *
5
 *                                                                         *
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.      *
10
 *                                                                         *
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.                  *
15
 *                                                                         *
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                                *
20
 *                                                                         *
21
 ***************************************************************************/
22

23
#include "PreCompiled.h"
24
#ifndef _PreComp_
25
#include <BRepBuilderAPI_MakePolygon.hxx>
26
#include <TopoDS.hxx>
27
#endif
28

29
#include <Base/Console.h>
30
#include <Base/Converter.h>
31
#include <Base/GeometryPyCXX.h>
32
#include <Base/Interpreter.h>
33
#include <Base/PyWrapParseTupleAndKeywords.h>
34
#include <Base/Vector3D.h>
35
#include <Base/VectorPy.h>
36
#include <Mod/Mesh/App/Core/Algorithm.h>
37
#include <Mod/Mesh/App/Core/MeshKernel.h>
38
#include <Mod/Mesh/App/MeshPy.h>
39
#include <Mod/Part/App/TopoShapeEdgePy.h>
40
#include <Mod/Part/App/TopoShapePy.h>
41
#include <Mod/Part/App/TopoShapeWirePy.h>
42

43
#include "MeshAlgos.h"
44
#include "Mesher.h"
45

46

47
// clang-format off
48
namespace MeshPart {
49
class Module : public Py::ExtensionModule<Module>
50
{
51
public:
52
    Module() : Py::ExtensionModule<Module>("MeshPart")
53
    {
54
        add_varargs_method("loftOnCurve",&Module::loftOnCurve,
55
            "Creates a mesh loft based on a curve and an up vector\n"
56
            "\n"
57
            "loftOnCurve(curve, poly, upVector, MaxSize)\n"
58
            "\n"
59
            "Args:\n"
60
            "    curve (topology):\n"
61
            "    poly (list of (x, y z) or (x, y) tuples of floats):\n"
62
            "    upVector ((x, y, z) tuple):\n"
63
            "    MaxSize (float):\n"
64
        );
65
        add_varargs_method("findSectionParameters",&Module::findSectionParameters,
66
            "Find the parameters of the edge where when projecting the corresponding point\n"
67
            "will lie on an edge of the mesh\n"
68
            "\n"
69
            "findSectionParameters(Edge, Mesh, Vector) -> list\n"
70
        );
71
        add_keyword_method("projectShapeOnMesh",&Module::projectShapeOnMesh,
72
            "Projects a shape onto a mesh with a given maximum distance\n"
73
            "projectShapeOnMesh(Shape, Mesh, float) -> polygon\n"
74
            "or projects the shape in a given direction\n"
75
            "\n"
76
            "Multiple signatures are available:\n"
77
            "\n"
78
            "projectShapeOnMesh(Shape, Mesh, float) -> list of polygons\n"
79
            "projectShapeOnMesh(Shape, Mesh, Vector) -> list of polygons\n"
80
            "projectShapeOnMesh(list of polygons, Mesh, Vector) -> list of polygons\n"
81
        );
82
        add_varargs_method("projectPointsOnMesh",&Module::projectPointsOnMesh,
83
            "Projects points onto a mesh with a given direction\n"
84
            "and tolerance."
85
            "projectPointsOnMesh(list of points, Mesh, Vector, [float]) -> list of points\n"
86
        );
87
        add_varargs_method("wireFromSegment",&Module::wireFromSegment,
88
            "Create wire(s) from boundary of a mesh segment\n"
89
        );
90
        add_varargs_method("wireFromMesh",&Module::wireFromMesh,
91
            "Create wire(s) from boundary of a mesh\n"
92
        );
93
        add_keyword_method("meshFromShape",&Module::meshFromShape,
94
            "Create surface mesh from shape\n"
95
            "\n"
96
            "Multiple signatures are available:\n"
97
            "\n"
98
            "    meshFromShape(Shape)\n"
99
            "    meshFromShape(Shape, LinearDeflection,\n"
100
            "                         AngularDeflection=0.5,\n"
101
            "                         Relative=False,"
102
            "                         Segments=False,\n"
103
            "                         GroupColors=[])\n"
104
            "    meshFromShape(Shape, MaxLength)\n"
105
            "    meshFromShape(Shape, MaxArea)\n"
106
            "    meshFromShape(Shape, LocalLength)\n"
107
            "    meshFromShape(Shape, Deflection)\n"
108
            "    meshFromShape(Shape, MinLength, MaxLength)\n"
109
            "\n"
110
            "Additionally, when FreeCAD is built with netgen, the following\n"
111
            "signatures are also available (they are "
112
#ifndef HAVE_NETGEN
113
            "NOT "
114
#endif
115
            "currently):\n"
116
            "\n"
117
            "    meshFromShape(Shape, Fineness, SecondOrder=0,\n"
118
            "                         Optimize=1, AllowQuad=0, MaxLength=0, MinLength=0)\n"
119
            "    meshFromShape(Shape, GrowthRate=0, SegPerEdge=0,\n"
120
            "                  SegPerRadius=0, SecondOrder=0, Optimize=1,\n"
121
            "                  AllowQuad=0)\n"
122
            "\n"
123
            "Args:\n"
124
            "    Shape (required, topology) - TopoShape to create mesh of.\n"
125
            "    LinearDeflection (required, float)\n"
126
            "    AngularDeflection (optional, float)\n"
127
            "    Segments (optional, boolean)\n"
128
            "    GroupColors (optional, list of (Red, Green, Blue) tuples)\n"
129
            "    MaxLength (required, float)\n"
130
            "    MaxArea (required, float)\n"
131
            "    LocalLength (required, float)\n"
132
            "    Deflection (required, float)\n"
133
            "    MinLength (required, float)\n"
134
            "    Fineness (required, integer)\n"
135
            "    SecondOrder (optional, integer boolean)\n"
136
            "    Optimize (optional, integer boolean)\n"
137
            "    AllowQuad (optional, integer boolean)\n"
138
            "    GrowthRate (optional, float)\n"
139
            "    SegPerEdge (optional, float)\n"
140
            "    SegPerRadius (optional, float)\n"
141
        );
142
        initialize("This module is the MeshPart module."); // register with Python
143
    }
144

145
private:
146
    Py::Object invoke_method_varargs(void *method_def, const Py::Tuple &args) override
147
    {
148
        try {
149
            return Py::ExtensionModule<Module>::invoke_method_varargs(method_def, args);
150
        }
151
        catch (const Standard_Failure &e) {
152
            std::string str;
153
            Standard_CString msg = e.GetMessageString();
154
            str += typeid(e).name();
155
            str += " ";
156
            if (msg) {str += msg;}
157
            else     {str += "No OCCT Exception Message";}
158
            Base::Console().Error("%s\n", str.c_str());
159
            throw Py::Exception(Base::PyExc_FC_GeneralError, str);
160
        }
161
        catch (const Base::Exception &e) {
162
            std::string str;
163
            str += "FreeCAD exception thrown (";
164
            str += e.what();
165
            str += ")";
166
            e.ReportException();
167
            throw Py::RuntimeError(str);
168
        }
169
        catch (const std::exception &e) {
170
            std::string str;
171
            str += "C++ exception thrown (";
172
            str += e.what();
173
            str += ")";
174
            Base::Console().Error("%s\n", str.c_str());
175
            throw Py::RuntimeError(str);
176
        }
177
    }
178

179
    Py::Object loftOnCurve(const Py::Tuple& args)
180
    {
181
        Part::TopoShapePy   *pcObject;
182
        PyObject *pcTopoObj,*pcListObj;
183
        float x=0.0f,y=0.0f,z=1.0f,size = 0.1f;
184

185
        if (!PyArg_ParseTuple(args.ptr(), "O!O(fff)f", &(Part::TopoShapePy::Type), &pcTopoObj,&pcListObj,&x,&y,&z,&size))
186
//      if (!PyArg_ParseTuple(args, "O!O!", &(App::TopoShapePy::Type), &pcTopoObj,&PyList_Type,&pcListObj,x,y,z,size))
187
            throw Py::Exception();
188

189
        pcObject = static_cast<Part::TopoShapePy*>(pcTopoObj);
190
        MeshCore::MeshKernel M;
191

192
        std::vector<Base::Vector3f> poly;
193
        auto exText( "List of Tuples of three or two floats needed as second parameter!" );
194

195
        if (!PyList_Check(pcListObj))
196
            throw Py::TypeError(exText);
197

198
        int nSize = PyList_Size(pcListObj);
199
        for (int i=0; i<nSize;++i) {
200
            PyObject* item = PyList_GetItem(pcListObj, i);
201
            if (!PyTuple_Check(item))
202
                throw Py::TypeError(exText);
203

204
            int nTSize = PyTuple_Size(item);
205
            if (nTSize != 2 && nTSize != 3)
206
                throw Py::ValueError(exText);
207

208
            Base::Vector3f vec(0,0,0);
209

210
            for(int l = 0; l < nTSize;l++) {
211
                PyObject* item2 = PyTuple_GetItem(item, l);
212
                if (!PyFloat_Check(item2))
213
                    throw Py::TypeError(exText);
214
                vec[l] = (float)PyFloat_AS_DOUBLE(item2);
215
            }
216
            poly.push_back(vec);
217
        }
218

219
        TopoDS_Shape aShape = pcObject->getTopoShapePtr()->getShape();
220
        // use the MeshAlgos
221
        MeshPart::MeshAlgos::LoftOnCurve(M,aShape,poly,Base::Vector3f(x,y,z),size);
222
        return Py::asObject(new Mesh::MeshPy(new Mesh::MeshObject(M)));
223
    }
224
    Py::Object findSectionParameters(const Py::Tuple& args)
225
    {
226
        PyObject *e, *m, *v;
227
        if (!PyArg_ParseTuple(args.ptr(), "O!O!O!", &(Part::TopoShapeEdgePy::Type), &e,
228
                                                    &(Mesh::MeshPy::Type), &m,
229
                                                    &(Base::VectorPy::Type),&v))
230
            throw Py::Exception();
231

232
        TopoDS_Shape shape = static_cast<Part::TopoShapePy*>(e)->getTopoShapePtr()->getShape();
233
        const Mesh::MeshObject* mesh = static_cast<Mesh::MeshPy*>(m)->getMeshObjectPtr();
234
        MeshCore::MeshKernel kernel(mesh->getKernel());
235
        kernel.Transform(mesh->getTransform());
236
        Base::Vector3d* vec = static_cast<Base::VectorPy*>(v)->getVectorPtr();
237
        Base::Vector3f dir = Base::convertTo<Base::Vector3f>(*vec);
238

239
        MeshProjection proj(kernel);
240
        std::set<double> parameters;
241
        proj.findSectionParameters(TopoDS::Edge(shape), dir, parameters);
242

243
        Py::List list;
244
        for (auto it : parameters) {
245
            Py::Float val(it);
246
            list.append(val);
247
        }
248

249
        return list;
250
    }
251
    Py::Object projectShapeOnMesh(const Py::Tuple& args, const Py::Dict& kwds)
252
    {
253
        static const std::array<const char *, 4> kwds_maxdist{"Shape", "Mesh", "MaxDistance", nullptr};
254
        PyObject *s, *m;
255
        double maxDist;
256
        if (Base::Wrapped_ParseTupleAndKeywords(args.ptr(), kwds.ptr(),
257
                                                "O!O!d", kwds_maxdist,
258
                                                &Part::TopoShapePy::Type, &s,
259
                                                &Mesh::MeshPy::Type, &m,
260
                                                &maxDist)) {
261
            TopoDS_Shape shape = static_cast<Part::TopoShapePy*>(s)->getTopoShapePtr()->getShape();
262
            const Mesh::MeshObject* mesh = static_cast<Mesh::MeshPy*>(m)->getMeshObjectPtr();
263
            MeshCore::MeshKernel kernel(mesh->getKernel());
264
            kernel.Transform(mesh->getTransform());
265

266
            MeshProjection proj(kernel);
267
            std::vector<MeshProjection::PolyLine> polylines;
268
            proj.projectToMesh(shape, maxDist, polylines);
269

270
            Py::List list;
271
            for (const auto& it : polylines) {
272
                Py::List poly;
273
                for (auto jt : it.points) {
274
                    Py::Vector v(jt);
275
                    poly.append(v);
276
                }
277
                list.append(poly);
278
            }
279

280
            return list;
281
        }
282

283
        static const std::array<const char *, 4> kwds_dir {"Shape", "Mesh", "Direction", nullptr};
284
        PyErr_Clear();
285
        PyObject *v;
286
        if (Base::Wrapped_ParseTupleAndKeywords(args.ptr(), kwds.ptr(),
287
                                                "O!O!O!", kwds_dir,
288
                                                &Part::TopoShapePy::Type, &s,
289
                                                &Mesh::MeshPy::Type, &m,
290
                                                &Base::VectorPy::Type, &v)) {
291
            TopoDS_Shape shape = static_cast<Part::TopoShapePy*>(s)->getTopoShapePtr()->getShape();
292
            const Mesh::MeshObject* mesh = static_cast<Mesh::MeshPy*>(m)->getMeshObjectPtr();
293
            Base::Vector3d* vec = static_cast<Base::VectorPy*>(v)->getVectorPtr();
294
            Base::Vector3f dir = Base::convertTo<Base::Vector3f>(*vec);
295

296
            MeshCore::MeshKernel kernel(mesh->getKernel());
297
            kernel.Transform(mesh->getTransform());
298

299
            MeshProjection proj(kernel);
300
            std::vector<MeshProjection::PolyLine> polylines;
301
            proj.projectParallelToMesh(shape, dir, polylines);
302
            Py::List list;
303
            for (const auto& it : polylines) {
304
                Py::List poly;
305
                for (auto jt : it.points) {
306
                    Py::Vector v(jt);
307
                    poly.append(v);
308
                }
309
                list.append(poly);
310
            }
311

312
            return list;
313
        }
314

315
        static const std::array<const char *, 4> kwds_poly {"Polygons", "Mesh", "Direction", nullptr};
316
        PyErr_Clear();
317
        PyObject *seq;
318
        if (Base::Wrapped_ParseTupleAndKeywords(args.ptr(), kwds.ptr(),
319
                                                "OO!O!", kwds_poly,
320
                                                &seq,
321
                                                &Mesh::MeshPy::Type, &m,
322
                                                &Base::VectorPy::Type, &v)) {
323
            std::vector<MeshProjection::PolyLine> polylinesIn;
324
            Py::Sequence edges(seq);
325
            polylinesIn.reserve(edges.size());
326

327
            // collect list of sampled input edges
328
            for (Py::Sequence::iterator it = edges.begin(); it != edges.end(); ++it) {
329
                Py::Sequence edge(*it);
330
                MeshProjection::PolyLine poly;
331
                poly.points.reserve(edge.size());
332

333
                for (Py::Sequence::iterator jt = edge.begin(); jt != edge.end(); ++jt) {
334
                    Py::Vector pnt(*jt);
335
                    poly.points.push_back(Base::convertTo<Base::Vector3f>(pnt.toVector()));
336
                }
337

338
                polylinesIn.push_back(poly);
339
            }
340

341
            const Mesh::MeshObject* mesh = static_cast<Mesh::MeshPy*>(m)->getMeshObjectPtr();
342
            Base::Vector3d* vec = static_cast<Base::VectorPy*>(v)->getVectorPtr();
343
            Base::Vector3f dir = Base::convertTo<Base::Vector3f>(*vec);
344

345
            MeshCore::MeshKernel kernel(mesh->getKernel());
346
            kernel.Transform(mesh->getTransform());
347

348
            MeshProjection proj(kernel);
349
            std::vector<MeshProjection::PolyLine> polylines;
350
            proj.projectParallelToMesh(polylinesIn, dir, polylines);
351

352
            Py::List list;
353
            for (const auto& it : polylines) {
354
                Py::List poly;
355
                for (auto jt : it.points) {
356
                    Py::Vector v(jt);
357
                    poly.append(v);
358
                }
359
                list.append(poly);
360
            }
361

362
            return list;
363
        }
364

365
        throw Py::TypeError("Expected arguments are:\n"
366
                            "Shape, Mesh, float or\n"
367
                            "Shape, Mesh, Vector or\n"
368
                            "Polygons, Mesh, Vector\n");
369
    }
370
    Py::Object projectPointsOnMesh(const Py::Tuple& args)
371
    {
372
        PyObject *seq, *m, *v;
373
        double precision = -1;
374
        if (PyArg_ParseTuple(args.ptr(), "OO!O!|d",
375
                                        &seq,
376
                                        &Mesh::MeshPy::Type, &m,
377
                                        &Base::VectorPy::Type, &v,
378
                                        &precision)) {
379
            std::vector<Base::Vector3f> pointsIn;
380
            Py::Sequence points(seq);
381
            pointsIn.reserve(points.size());
382

383
            // collect list of input points
384
            for (Py::Sequence::iterator it = points.begin(); it != points.end(); ++it) {
385
                Py::Vector pnt(*it);
386
                pointsIn.push_back(Base::convertTo<Base::Vector3f>(pnt.toVector()));
387
            }
388

389
            const Mesh::MeshObject* mesh = static_cast<Mesh::MeshPy*>(m)->getMeshObjectPtr();
390
            Base::Vector3d* vec = static_cast<Base::VectorPy*>(v)->getVectorPtr();
391
            Base::Vector3f dir = Base::convertTo<Base::Vector3f>(*vec);
392

393
            MeshCore::MeshKernel kernel(mesh->getKernel());
394
            kernel.Transform(mesh->getTransform());
395

396
            MeshProjection proj(kernel);
397
            std::vector<Base::Vector3f> pointsOut;
398
            proj.projectOnMesh(pointsIn, dir, static_cast<float>(precision), pointsOut);
399

400
            Py::List list;
401
            for (auto it : pointsOut) {
402
                Py::Vector v(it);
403
                list.append(v);
404
            }
405

406
            return list;
407
        }
408

409
        throw Py::Exception();
410
    }
411
    Py::Object wireFromSegment(const Py::Tuple& args)
412
    {
413
        PyObject *o, *m;
414
        if (!PyArg_ParseTuple(args.ptr(), "O!O!", &(Mesh::MeshPy::Type), &m,&PyList_Type,&o))
415
            throw Py::Exception();
416

417
        Py::List list(o);
418
        Mesh::MeshObject* mesh = static_cast<Mesh::MeshPy*>(m)->getMeshObjectPtr();
419
        std::vector<MeshCore::FacetIndex> segm;
420
        segm.reserve(list.size());
421
        for (Py_ssize_t i=0; i<list.size(); i++) {
422
            segm.push_back((long)Py::Long(list[i]));
423
        }
424

425
        std::list<std::vector<Base::Vector3f> > bounds;
426
        MeshCore::MeshAlgorithm algo(mesh->getKernel());
427
        algo.GetFacetBorders(segm, bounds);
428

429
        Py::List wires;
430
        std::list<std::vector<Base::Vector3f> >::iterator bt;
431

432
        for (bt = bounds.begin(); bt != bounds.end(); ++bt) {
433
            BRepBuilderAPI_MakePolygon mkPoly;
434
            for (std::vector<Base::Vector3f>::reverse_iterator it = bt->rbegin(); it != bt->rend(); ++it) {
435
                mkPoly.Add(gp_Pnt(it->x,it->y,it->z));
436
            }
437
            if (mkPoly.IsDone()) {
438
                PyObject* wire = new Part::TopoShapeWirePy(new Part::TopoShape(mkPoly.Wire()));
439
                wires.append(Py::Object(wire, true));
440
            }
441
        }
442

443
        return wires;
444
    }
445
    Py::Object wireFromMesh(const Py::Tuple& args)
446
    {
447
        PyObject *m;
448
        if (!PyArg_ParseTuple(args.ptr(), "O!", &(Mesh::MeshPy::Type), &m))
449
            throw Py::Exception();
450

451
        Mesh::MeshObject* mesh = static_cast<Mesh::MeshPy*>(m)->getMeshObjectPtr();
452

453
        std::list<std::vector<Base::Vector3f> > bounds;
454
        MeshCore::MeshAlgorithm algo(mesh->getKernel());
455
        algo.GetMeshBorders(bounds);
456

457
        Py::List wires;
458
        std::list<std::vector<Base::Vector3f> >::iterator bt;
459

460
        for (bt = bounds.begin(); bt != bounds.end(); ++bt) {
461
            BRepBuilderAPI_MakePolygon mkPoly;
462
            for (std::vector<Base::Vector3f>::reverse_iterator it = bt->rbegin(); it != bt->rend(); ++it) {
463
                mkPoly.Add(gp_Pnt(it->x,it->y,it->z));
464
            }
465
            if (mkPoly.IsDone()) {
466
                PyObject* wire = new Part::TopoShapeWirePy(new Part::TopoShape(mkPoly.Wire()));
467
                wires.append(Py::Object(wire, true));
468
            }
469
        }
470

471
        return wires;
472
    }
473
    Py::Object meshFromShape(const Py::Tuple& args, const Py::Dict& kwds)
474
    {
475
        PyObject *shape;
476

477
        auto runMesher = [](const MeshPart::Mesher& mesher) {
478
            Mesh::MeshObject* mesh;
479
            {
480
                Base::PyGILStateRelease releaser{};
481
                mesh = mesher.createMesh();
482
            }
483
            return Py::asObject(new Mesh::MeshPy(mesh));
484
        };
485

486
        static const std::array<const char *, 7> kwds_lindeflection{"Shape", "LinearDeflection", "AngularDeflection",
487
                                                                    "Relative", "Segments", "GroupColors", nullptr};
488
        PyErr_Clear();
489
        double lindeflection=0;
490
        double angdeflection=0.5;
491
        PyObject* relative = Py_False;
492
        PyObject* segment = Py_False;
493
        PyObject* groupColors = nullptr;
494
        if (Base::Wrapped_ParseTupleAndKeywords(args.ptr(), kwds.ptr(), "O!d|dO!O!O", kwds_lindeflection,
495
                                                &(Part::TopoShapePy::Type), &shape, &lindeflection,
496
                                                &angdeflection, &(PyBool_Type), &relative,
497
                                                &(PyBool_Type), &segment, &groupColors)) {
498
            MeshPart::Mesher mesher(static_cast<Part::TopoShapePy*>(shape)->getTopoShapePtr()->getShape());
499
            mesher.setMethod(MeshPart::Mesher::Standard);
500
            mesher.setDeflection(lindeflection);
501
            mesher.setAngularDeflection(angdeflection);
502
            mesher.setRegular(true);
503
            mesher.setRelative(Base::asBoolean(relative));
504
            mesher.setSegments(Base::asBoolean(segment));
505
            if (groupColors) {
506
                Py::Sequence list(groupColors);
507
                std::vector<uint32_t> colors;
508
                colors.reserve(list.size());
509
                for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
510
                    Py::Tuple t(*it);
511
                    Py::Float r(t[0]);
512
                    Py::Float g(t[1]);
513
                    Py::Float b(t[2]);
514
                    App::Color c(static_cast<float>(r),
515
                                 static_cast<float>(g),
516
                                 static_cast<float>(b));
517
                    colors.push_back(c.getPackedValue());
518
                }
519
                mesher.setColors(colors);
520
            }
521
            return runMesher(mesher);
522
        }
523

524
        static const std::array<const char *, 3> kwds_maxLength{"Shape", "MaxLength", nullptr};
525
        PyErr_Clear();
526
        double maxLength=0;
527
        if (Base::Wrapped_ParseTupleAndKeywords(args.ptr(), kwds.ptr(), "O!d", kwds_maxLength,
528
                                                &(Part::TopoShapePy::Type), &shape, &maxLength)) {
529
            MeshPart::Mesher mesher(static_cast<Part::TopoShapePy*>(shape)->getTopoShapePtr()->getShape());
530
            mesher.setMethod(MeshPart::Mesher::Mefisto);
531
            mesher.setMaxLength(maxLength);
532
            mesher.setRegular(true);
533
            return runMesher(mesher);
534
        }
535

536
        static const std::array<const char *, 3> kwds_maxArea{"Shape", "MaxArea", nullptr};
537
        PyErr_Clear();
538
        double maxArea=0;
539
        if (Base::Wrapped_ParseTupleAndKeywords(args.ptr(), kwds.ptr(), "O!d", kwds_maxArea,
540
                                                &(Part::TopoShapePy::Type), &shape, &maxArea)) {
541
            MeshPart::Mesher mesher(static_cast<Part::TopoShapePy*>(shape)->getTopoShapePtr()->getShape());
542
            mesher.setMethod(MeshPart::Mesher::Mefisto);
543
            mesher.setMaxArea(maxArea);
544
            mesher.setRegular(true);
545
            return runMesher(mesher);
546
        }
547

548
        static const std::array<const char *, 3> kwds_localLen{"Shape", "LocalLength", nullptr};
549
        PyErr_Clear();
550
        double localLen=0;
551
        if (Base::Wrapped_ParseTupleAndKeywords(args.ptr(), kwds.ptr(), "O!d", kwds_localLen,
552
                                                &(Part::TopoShapePy::Type), &shape, &localLen)) {
553
            MeshPart::Mesher mesher(static_cast<Part::TopoShapePy*>(shape)->getTopoShapePtr()->getShape());
554
            mesher.setMethod(MeshPart::Mesher::Mefisto);
555
            mesher.setLocalLength(localLen);
556
            mesher.setRegular(true);
557
            return runMesher(mesher);
558
        }
559

560
        static const std::array<const char *, 3> kwds_deflection{"Shape", "Deflection", nullptr};
561
        PyErr_Clear();
562
        double deflection=0;
563
        if (Base::Wrapped_ParseTupleAndKeywords(args.ptr(), kwds.ptr(), "O!d", kwds_deflection,
564
                                                &(Part::TopoShapePy::Type), &shape, &deflection)) {
565
            MeshPart::Mesher mesher(static_cast<Part::TopoShapePy*>(shape)->getTopoShapePtr()->getShape());
566
            mesher.setMethod(MeshPart::Mesher::Mefisto);
567
            mesher.setDeflection(deflection);
568
            mesher.setRegular(true);
569
            return runMesher(mesher);
570
        }
571

572
        static const std::array<const char *, 4> kwds_minmaxLen{"Shape", "MinLength", "MaxLength", nullptr};
573
        PyErr_Clear();
574
        double minLen=0, maxLen=0;
575
        if (Base::Wrapped_ParseTupleAndKeywords(args.ptr(), kwds.ptr(), "O!dd", kwds_minmaxLen,
576
                                                &(Part::TopoShapePy::Type), &shape, &minLen, &maxLen)) {
577
            MeshPart::Mesher mesher(static_cast<Part::TopoShapePy*>(shape)->getTopoShapePtr()->getShape());
578
            mesher.setMethod(MeshPart::Mesher::Mefisto);
579
            mesher.setMinMaxLengths(minLen, maxLen);
580
            mesher.setRegular(true);
581
            return runMesher(mesher);
582
        }
583

584
        static const std::array<const char *, 8> kwds_fineness{"Shape", "Fineness", "SecondOrder", "Optimize",
585
                                                               "AllowQuad", "MinLength", "MaxLength", nullptr};
586
        PyErr_Clear();
587
        int fineness=0, secondOrder=0, optimize=1, allowquad=0;
588
        if (Base::Wrapped_ParseTupleAndKeywords(args.ptr(), kwds.ptr(), "O!i|iiidd", kwds_fineness,
589
                                                &(Part::TopoShapePy::Type), &shape, &fineness,
590
                                                &secondOrder, &optimize, &allowquad, &minLen, &maxLen)) {
591
#if defined (HAVE_NETGEN)
592
            MeshPart::Mesher mesher(static_cast<Part::TopoShapePy*>(shape)->getTopoShapePtr()->getShape());
593
            mesher.setMethod(MeshPart::Mesher::Netgen);
594
            mesher.setFineness(fineness);
595
            mesher.setSecondOrder(secondOrder != 0);
596
            mesher.setOptimize(optimize != 0);
597
            mesher.setQuadAllowed(allowquad != 0);
598
            mesher.setMinMaxLengths(minLen, maxLen);
599
            return runMesher(mesher);
600
#else
601
            throw Py::RuntimeError("SMESH was built without NETGEN support");
602
#endif
603
        }
604

605
        static const std::array<const char *, 10> kwds_user{"Shape", "GrowthRate", "SegPerEdge", "SegPerRadius",
606
                                                            "SecondOrder", "Optimize", "AllowQuad", "MinLength",
607
                                                            "MaxLength", nullptr};
608
        PyErr_Clear();
609
        double growthRate=0, nbSegPerEdge=0, nbSegPerRadius=0;
610
        if (Base::Wrapped_ParseTupleAndKeywords(args.ptr(), kwds.ptr(), "O!|dddiiidd", kwds_user,
611
                                                &(Part::TopoShapePy::Type), &shape,
612
                                                &growthRate, &nbSegPerEdge, &nbSegPerRadius,
613
                                                &secondOrder, &optimize, &allowquad, &minLen, &maxLen)) {
614
#if defined (HAVE_NETGEN)
615
            MeshPart::Mesher mesher(static_cast<Part::TopoShapePy*>(shape)->getTopoShapePtr()->getShape());
616
            mesher.setMethod(MeshPart::Mesher::Netgen);
617
            mesher.setGrowthRate(growthRate);
618
            mesher.setNbSegPerEdge(nbSegPerEdge);
619
            mesher.setNbSegPerRadius(nbSegPerRadius);
620
            mesher.setSecondOrder(secondOrder != 0);
621
            mesher.setOptimize(optimize != 0);
622
            mesher.setQuadAllowed(allowquad != 0);
623
            mesher.setMinMaxLengths(minLen, maxLen);
624
            return runMesher(mesher);
625
#else
626
            throw Py::RuntimeError("SMESH was built without NETGEN support");
627
#endif
628
        }
629

630
        PyErr_Clear();
631
        if (PyArg_ParseTuple(args.ptr(), "O!", &(Part::TopoShapePy::Type), &shape)) {
632
            MeshPart::Mesher mesher(static_cast<Part::TopoShapePy*>(shape)->getTopoShapePtr()->getShape());
633
#if defined (HAVE_NETGEN)
634
            mesher.setMethod(MeshPart::Mesher::Netgen);
635
#else
636
            mesher.setMethod(MeshPart::Mesher::Mefisto);
637
            mesher.setRegular(true);
638
#endif
639
            return runMesher(mesher);
640
        }
641

642
        throw Py::TypeError("Wrong arguments");
643
    }
644
};
645

646
PyObject* initModule()
647
{
648
    return Base::Interpreter().addModule(new Module);
649
}
650

651
} // namespace MeshPart
652
// clang-format on
653

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.