FreeCAD

Форк
0
/
BezierSurfacePyImp.cpp 
715 строк · 23.0 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2008 Werner Mayer <wmayer[at]users.sourceforge.net>     *
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 <Geom_BezierSurface.hxx>
26
# include <TColgp_Array1OfPnt.hxx>
27
# include <TColgp_Array2OfPnt.hxx>
28
# include <TColStd_Array1OfReal.hxx>
29
# include <TColStd_Array2OfReal.hxx>
30
#endif
31

32
#include <Base/GeometryPyCXX.h>
33
#include <Base/VectorPy.h>
34

35
#include "BezierCurvePy.h"
36
#include "BezierSurfacePy.h"
37
#include "BezierSurfacePy.cpp"
38
#include "OCCError.h"
39

40

41
using namespace Part;
42

43
// returns a string which represents the object e.g. when printed in python
44
std::string BezierSurfacePy::representation() const
45
{
46
    return "<BezierSurface object>";
47
}
48

49
PyObject *BezierSurfacePy::PyMake(struct _typeobject *, PyObject *, PyObject *)  // Python wrapper
50
{
51
    // create a new instance of BezierSurfacePy and the Twin object
52
    return new BezierSurfacePy(new GeomBezierSurface);
53
}
54

55
// constructor method
56
int BezierSurfacePy::PyInit(PyObject* /*args*/, PyObject* /*kwd*/)
57
{
58
    return 0;
59
}
60

61
PyObject* BezierSurfacePy::bounds(PyObject *args)
62
{
63
    if (!PyArg_ParseTuple(args, ""))
64
        return nullptr;
65

66
    Handle(Geom_BezierSurface) surf = Handle(Geom_BezierSurface)::DownCast
67
        (getGeometryPtr()->handle());
68
    Py::Tuple bound(4);
69
    Standard_Real u1,u2,v1,v2;
70
    surf->Bounds(u1,u2,v1,v2);
71
    bound.setItem(0,Py::Float(u1));
72
    bound.setItem(1,Py::Float(u2));
73
    bound.setItem(2,Py::Float(v1));
74
    bound.setItem(3,Py::Float(v2));
75
    return Py::new_reference_to(bound);
76
}
77

78
PyObject* BezierSurfacePy::isURational(PyObject *args)
79
{
80
    if (!PyArg_ParseTuple(args, ""))
81
        return nullptr;
82

83
    Handle(Geom_BezierSurface) surf = Handle(Geom_BezierSurface)::DownCast
84
        (getGeometryPtr()->handle());
85
    Standard_Boolean val = surf->IsURational();
86
    return PyBool_FromLong(val ? 1 : 0);
87
}
88

89
PyObject* BezierSurfacePy::isVRational(PyObject *args)
90
{
91
    if (!PyArg_ParseTuple(args, ""))
92
        return nullptr;
93

94
    Handle(Geom_BezierSurface) surf = Handle(Geom_BezierSurface)::DownCast
95
        (getGeometryPtr()->handle());
96
    Standard_Boolean val = surf->IsVRational();
97
    return PyBool_FromLong(val ? 1 : 0);
98
}
99

100
PyObject* BezierSurfacePy::isUPeriodic(PyObject *args)
101
{
102
    if (!PyArg_ParseTuple(args, ""))
103
        return nullptr;
104

105
    Handle(Geom_BezierSurface) surf = Handle(Geom_BezierSurface)::DownCast
106
        (getGeometryPtr()->handle());
107
    Standard_Boolean val = surf->IsUPeriodic();
108
    return PyBool_FromLong(val ? 1 : 0);
109
}
110

111
PyObject* BezierSurfacePy::isVPeriodic(PyObject *args)
112
{
113
    if (!PyArg_ParseTuple(args, ""))
114
        return nullptr;
115

116
    Handle(Geom_BezierSurface) surf = Handle(Geom_BezierSurface)::DownCast
117
        (getGeometryPtr()->handle());
118
    Standard_Boolean val = surf->IsVPeriodic();
119
    return PyBool_FromLong(val ? 1 : 0);
120
}
121

122
PyObject* BezierSurfacePy::isUClosed(PyObject *args)
123
{
124
    if (!PyArg_ParseTuple(args, ""))
125
        return nullptr;
126

127
    Handle(Geom_BezierSurface) surf = Handle(Geom_BezierSurface)::DownCast
128
        (getGeometryPtr()->handle());
129
    Standard_Boolean val = surf->IsUClosed();
130
    return PyBool_FromLong(val ? 1 : 0);
131
}
132

133
PyObject* BezierSurfacePy::isVClosed(PyObject *args)
134
{
135
    if (!PyArg_ParseTuple(args, ""))
136
        return nullptr;
137

138
    Handle(Geom_BezierSurface) surf = Handle(Geom_BezierSurface)::DownCast
139
        (getGeometryPtr()->handle());
140
    Standard_Boolean val = surf->IsVPeriodic();
141
    return PyBool_FromLong(val ? 1 : 0);
142
}
143

144
PyObject* BezierSurfacePy::increase(PyObject *args)
145
{
146
    int udegree,vdegree;
147
    if (!PyArg_ParseTuple(args, "ii", &udegree, &vdegree))
148
        return nullptr;
149
    try {
150
        Handle(Geom_BezierSurface) surf = Handle(Geom_BezierSurface)::DownCast
151
            (getGeometryPtr()->handle());
152
        surf->Increase(udegree, vdegree);
153
        Py_Return;
154
    }
155
    catch (Standard_Failure& e) {
156

157
        PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
158
        return nullptr;
159
    }
160
}
161

162
PyObject* BezierSurfacePy::insertPoleColAfter(PyObject *args)
163
{
164
    int vindex;
165
    PyObject* obj;
166
    PyObject* obj2=nullptr;
167
    if (!PyArg_ParseTuple(args, "iO|O",&vindex,&obj,&obj2))
168
        return nullptr;
169
    try {
170
        Py::Sequence list(obj);
171
        TColgp_Array1OfPnt poles(1, list.size());
172
        int index=1;
173
        for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
174
            Py::Vector p(*it);
175
            Base::Vector3d v = p.toVector();
176
            poles(index++) = gp_Pnt(v.x,v.y,v.z);
177
        }
178

179
        Handle(Geom_BezierSurface) surf = Handle(Geom_BezierSurface)::DownCast
180
            (getGeometryPtr()->handle());
181
        if (!obj2) {
182
            surf->InsertPoleColAfter(vindex, poles);
183
        }
184
        else {
185
            Py::Sequence list(obj2);
186
            TColStd_Array1OfReal weights(1, list.size());
187
            int index=1;
188
            for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
189
                weights(index++) = (double)Py::Float(*it);
190
            }
191
            surf->InsertPoleColAfter(vindex, poles, weights);
192
        }
193

194
        Py_Return;
195
    }
196
    catch (Standard_Failure& e) {
197
        PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
198
        return nullptr;
199
    }
200
}
201

202
PyObject* BezierSurfacePy::insertPoleRowAfter(PyObject *args)
203
{
204
    int uindex;
205
    PyObject* obj;
206
    PyObject* obj2=nullptr;
207
    if (!PyArg_ParseTuple(args, "iO|O",&uindex,&obj,&obj2))
208
        return nullptr;
209
    try {
210
        Py::Sequence list(obj);
211
        TColgp_Array1OfPnt poles(1, list.size());
212
        int index=1;
213
        for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
214
            Py::Vector p(*it);
215
            Base::Vector3d v = p.toVector();
216
            poles(index++) = gp_Pnt(v.x,v.y,v.z);
217
        }
218

219
        Handle(Geom_BezierSurface) surf = Handle(Geom_BezierSurface)::DownCast
220
            (getGeometryPtr()->handle());
221
        if (!obj2) {
222
            surf->InsertPoleRowAfter(uindex, poles);
223
        }
224
        else {
225
            Py::Sequence list(obj2);
226
            TColStd_Array1OfReal weights(1, list.size());
227
            int index=1;
228
            for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
229
                weights(index++) = (double)Py::Float(*it);
230
            }
231
            surf->InsertPoleRowAfter(uindex, poles, weights);
232
        }
233

234
        Py_Return;
235
    }
236
    catch (Standard_Failure& e) {
237
        PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
238
        return nullptr;
239
    }
240
}
241

242
PyObject* BezierSurfacePy::insertPoleColBefore(PyObject *args)
243
{
244
    int vindex;
245
    PyObject* obj;
246
    PyObject* obj2=nullptr;
247
    if (!PyArg_ParseTuple(args, "iO|O",&vindex,&obj,&obj2))
248
        return nullptr;
249
    try {
250
        Py::Sequence list(obj);
251
        TColgp_Array1OfPnt poles(1, list.size());
252
        int index=1;
253
        for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
254
            Py::Vector p(*it);
255
            Base::Vector3d v = p.toVector();
256
            poles(index++) = gp_Pnt(v.x,v.y,v.z);
257
        }
258

259
        Handle(Geom_BezierSurface) surf = Handle(Geom_BezierSurface)::DownCast
260
            (getGeometryPtr()->handle());
261
        if (!obj2) {
262
            surf->InsertPoleColBefore(vindex, poles);
263
        }
264
        else {
265
            Py::Sequence list(obj2);
266
            TColStd_Array1OfReal weights(1, list.size());
267
            int index=1;
268
            for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
269
                weights(index++) = (double)Py::Float(*it);
270
            }
271
            surf->InsertPoleColBefore(vindex, poles, weights);
272
        }
273

274
        Py_Return;
275
    }
276
    catch (Standard_Failure& e) {
277
        PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
278
        return nullptr;
279
    }
280
}
281

282
PyObject* BezierSurfacePy::insertPoleRowBefore(PyObject *args)
283
{
284
    int uindex;
285
    PyObject* obj;
286
    PyObject* obj2=nullptr;
287
    if (!PyArg_ParseTuple(args, "iO|O",&uindex,&obj,&obj2))
288
        return nullptr;
289
    try {
290
        Py::Sequence list(obj);
291
        TColgp_Array1OfPnt poles(1, list.size());
292
        int index=1;
293
        for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
294
            Py::Vector p(*it);
295
            Base::Vector3d v = p.toVector();
296
            poles(index++) = gp_Pnt(v.x,v.y,v.z);
297
        }
298

299
        Handle(Geom_BezierSurface) surf = Handle(Geom_BezierSurface)::DownCast
300
            (getGeometryPtr()->handle());
301
        if (!obj2) {
302
            surf->InsertPoleRowBefore(uindex, poles);
303
        }
304
        else {
305
            Py::Sequence list(obj2);
306
            TColStd_Array1OfReal weights(1, list.size());
307
            int index=1;
308
            for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
309
                weights(index++) = (double)Py::Float(*it);
310
            }
311
            surf->InsertPoleRowBefore(uindex, poles, weights);
312
        }
313

314
        Py_Return;
315
    }
316
    catch (Standard_Failure& e) {
317
        PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
318
        return nullptr;
319
    }
320
}
321

322
PyObject* BezierSurfacePy::removePoleCol(PyObject *args)
323
{
324
    int vindex;
325
    if (!PyArg_ParseTuple(args, "i",&vindex))
326
        return nullptr;
327
    try {
328
        Handle(Geom_BezierSurface) surf = Handle(Geom_BezierSurface)::DownCast
329
            (getGeometryPtr()->handle());
330
        surf->RemovePoleCol(vindex);
331
        Py_Return;
332
    }
333
    catch (Standard_Failure& e) {
334
        PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
335
        return nullptr;
336
    }
337
}
338

339
PyObject* BezierSurfacePy::removePoleRow(PyObject *args)
340
{
341
    int uindex;
342
    if (!PyArg_ParseTuple(args, "i",&uindex))
343
        return nullptr;
344
    try {
345
        Handle(Geom_BezierSurface) surf = Handle(Geom_BezierSurface)::DownCast
346
            (getGeometryPtr()->handle());
347
        surf->RemovePoleRow(uindex);
348
        Py_Return;
349
    }
350
    catch (Standard_Failure& e) {
351
        PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
352
        return nullptr;
353
    }
354
}
355

356
PyObject* BezierSurfacePy::segment(PyObject *args)
357
{
358
    Standard_Real u1,u2,v1,v2;
359
    if (!PyArg_ParseTuple(args, "dddd",&u1,&u2,&v1,&v2))
360
        return nullptr;
361
    try {
362
        Handle(Geom_BezierSurface) surf = Handle(Geom_BezierSurface)::DownCast
363
            (getGeometryPtr()->handle());
364
        surf->Segment(u1,u2,v1,v2);
365
        Py_Return;
366
    }
367
    catch (Standard_Failure& e) {
368
        PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
369
        return nullptr;
370
    }
371
}
372

373
PyObject* BezierSurfacePy::setPole(PyObject *args)
374
{
375
    int uindex,vindex;
376
    PyObject* obj;
377
    double weight=0.0;
378
    if (!PyArg_ParseTuple(args, "iiO!|d",&uindex,&vindex,&(Base::VectorPy::Type),&obj,&weight))
379
        return nullptr;
380
    try {
381
        Base::Vector3d pole = static_cast<Base::VectorPy*>(obj)->value();
382
        Handle(Geom_BezierSurface) surf = Handle(Geom_BezierSurface)::DownCast
383
            (getGeometryPtr()->handle());
384
        if (weight <= gp::Resolution())
385
            surf->SetPole(uindex,vindex,gp_Pnt(pole.x,pole.y,pole.z));
386
        else
387
            surf->SetPole(uindex,vindex,gp_Pnt(pole.x,pole.y,pole.z),weight);
388
        Py_Return;
389
    }
390
    catch (Standard_Failure& e) {
391
        PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
392
        return nullptr;
393
    }
394
}
395

396
PyObject* BezierSurfacePy::setPoleCol(PyObject *args)
397
{
398
    int vindex;
399
    PyObject* obj;
400
    PyObject* obj2=nullptr;
401
    if (!PyArg_ParseTuple(args, "iO|O",&vindex,&obj,&obj2))
402
        return nullptr;
403
    try {
404
        Py::Sequence list(obj);
405
        TColgp_Array1OfPnt poles(1, list.size());
406
        int index=1;
407
        for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
408
            Py::Vector p(*it);
409
            Base::Vector3d v = p.toVector();
410
            poles(index++) = gp_Pnt(v.x,v.y,v.z);
411
        }
412

413
        Handle(Geom_BezierSurface) surf = Handle(Geom_BezierSurface)::DownCast
414
            (getGeometryPtr()->handle());
415
        if (!obj2) {
416
            surf->SetPoleCol(vindex, poles);
417
        }
418
        else {
419
            Py::Sequence list(obj2);
420
            TColStd_Array1OfReal weights(1, list.size());
421
            int index=1;
422
            for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
423
                weights(index++) = (double)Py::Float(*it);
424
            }
425
            surf->SetPoleCol(vindex, poles, weights);
426
        }
427

428
        Py_Return;
429
    }
430
    catch (Standard_Failure& e) {
431
        PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
432
        return nullptr;
433
    }
434
}
435

436
PyObject* BezierSurfacePy::setPoleRow(PyObject *args)
437
{
438
    int uindex;
439
    PyObject* obj;
440
    PyObject* obj2=nullptr;
441
    if (!PyArg_ParseTuple(args, "iO|O",&uindex,&obj,&obj2))
442
        return nullptr;
443
    try {
444
        Py::Sequence list(obj);
445
        TColgp_Array1OfPnt poles(1, list.size());
446
        int index=1;
447
        for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
448
            Py::Vector p(*it);
449
            Base::Vector3d v = p.toVector();
450
            poles(index++) = gp_Pnt(v.x,v.y,v.z);
451
        }
452

453
        Handle(Geom_BezierSurface) surf = Handle(Geom_BezierSurface)::DownCast
454
            (getGeometryPtr()->handle());
455
        if (!obj2) {
456
            surf->SetPoleRow(uindex, poles);
457
        }
458
        else {
459
            Py::Sequence list(obj2);
460
            TColStd_Array1OfReal weights(1, list.size());
461
            int index=1;
462
            for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
463
                weights(index++) = (double)Py::Float(*it);
464
            }
465
            surf->SetPoleRow(uindex, poles, weights);
466
        }
467

468
        Py_Return;
469
    }
470
    catch (Standard_Failure& e) {
471
        PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
472
        return nullptr;
473
    }
474
}
475

476
PyObject* BezierSurfacePy::getPole(PyObject *args)
477
{
478
    int uindex,vindex;
479
    if (!PyArg_ParseTuple(args, "ii",&uindex,&vindex))
480
        return nullptr;
481
    try {
482
        Handle(Geom_BezierSurface) surf = Handle(Geom_BezierSurface)::DownCast
483
            (getGeometryPtr()->handle());
484
        Standard_OutOfRange_Raise_if
485
            (uindex < 1 || uindex > surf->NbUPoles() ||
486
             vindex < 1 || vindex > surf->NbVPoles(), "Pole index out of range");
487
        gp_Pnt p = surf->Pole(uindex,vindex);
488
        return new Base::VectorPy(Base::Vector3d(p.X(),p.Y(),p.Z()));
489
    }
490
    catch (Standard_Failure& e) {
491
        PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
492
        return nullptr;
493
    }
494
}
495

496
PyObject* BezierSurfacePy::getPoles(PyObject *args)
497
{
498
    if (!PyArg_ParseTuple(args, ""))
499
        return nullptr;
500
    try {
501
        Handle(Geom_BezierSurface) surf = Handle(Geom_BezierSurface)::DownCast
502
            (getGeometryPtr()->handle());
503
        TColgp_Array2OfPnt p(1,surf->NbUPoles(),1,surf->NbVPoles());
504
        surf->Poles(p);
505
        Py::List poles;
506
        for (Standard_Integer i=p.LowerRow(); i<=p.UpperRow(); i++) {
507
            Py::List row;
508
            for (Standard_Integer j=p.LowerCol(); j<=p.UpperCol(); j++) {
509
                const gp_Pnt& pole = p(i,j);
510
                row.append(Py::asObject(new Base::VectorPy(
511
                    Base::Vector3d(pole.X(),pole.Y(),pole.Z()))));
512
            }
513
            poles.append(row);
514
        }
515
        return Py::new_reference_to(poles);
516
    }
517
    catch (Standard_Failure& e) {
518
        PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
519
        return nullptr;
520
    }
521
}
522

523
PyObject* BezierSurfacePy::setWeight(PyObject *args)
524
{
525
    int uindex,vindex;
526
    double weight;
527
    if (!PyArg_ParseTuple(args, "iid",&uindex,&vindex,&weight))
528
        return nullptr;
529
    try {
530
        Handle(Geom_BezierSurface) surf = Handle(Geom_BezierSurface)::DownCast
531
            (getGeometryPtr()->handle());
532
        surf->SetWeight(uindex,vindex,weight);
533
        Py_Return;
534
    }
535
    catch (Standard_Failure& e) {
536
        PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
537
        return nullptr;
538
    }
539
}
540

541
PyObject* BezierSurfacePy::setWeightCol(PyObject *args)
542
{
543
    int vindex;
544
    PyObject* obj;
545
    if (!PyArg_ParseTuple(args, "iO",&vindex,&obj))
546
        return nullptr;
547
    try {
548
        Py::Sequence list(obj);
549
        TColStd_Array1OfReal weights(1, list.size());
550
        int index=1;
551
        for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
552
            weights(index++) = (double)Py::Float(*it);
553
        }
554

555
        Handle(Geom_BezierSurface) surf = Handle(Geom_BezierSurface)::DownCast
556
            (getGeometryPtr()->handle());
557
        surf->SetWeightCol(vindex, weights);
558
        Py_Return;
559
    }
560
    catch (Standard_Failure& e) {
561
        PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
562
        return nullptr;
563
    }
564
}
565

566
PyObject* BezierSurfacePy::setWeightRow(PyObject *args)
567
{
568
    int uindex;
569
    PyObject* obj;
570
    if (!PyArg_ParseTuple(args, "iO",&uindex,&obj))
571
        return nullptr;
572
    try {
573
        Py::Sequence list(obj);
574
        TColStd_Array1OfReal weights(1, list.size());
575
        int index=1;
576
        for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
577
            weights(index++) = (double)Py::Float(*it);
578
        }
579

580
        Handle(Geom_BezierSurface) surf = Handle(Geom_BezierSurface)::DownCast
581
            (getGeometryPtr()->handle());
582
        surf->SetWeightRow(uindex, weights);
583
        Py_Return;
584
    }
585
    catch (Standard_Failure& e) {
586
        PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
587
        return nullptr;
588
    }
589
}
590

591
PyObject* BezierSurfacePy::getWeight(PyObject *args)
592
{
593
    int uindex,vindex;
594
    if (!PyArg_ParseTuple(args, "ii",&uindex,&vindex))
595
        return nullptr;
596
    try {
597
        Handle(Geom_BezierSurface) surf = Handle(Geom_BezierSurface)::DownCast
598
            (getGeometryPtr()->handle());
599
        Standard_OutOfRange_Raise_if
600
            (uindex < 1 || uindex > surf->NbUPoles() ||
601
             vindex < 1 || vindex > surf->NbVPoles(), "Weight index out of range");
602
        double w = surf->Weight(uindex,vindex);
603
        return Py_BuildValue("d", w);
604
    }
605
    catch (Standard_Failure& e) {
606
        PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
607
        return nullptr;
608
    }
609
}
610

611
PyObject* BezierSurfacePy::getWeights(PyObject *args)
612
{
613
    if (!PyArg_ParseTuple(args, ""))
614
        return nullptr;
615
    try {
616
        Handle(Geom_BezierSurface) surf = Handle(Geom_BezierSurface)::DownCast
617
            (getGeometryPtr()->handle());
618
        TColStd_Array2OfReal w(1,surf->NbUPoles(),1,surf->NbVPoles());
619
        surf->Weights(w);
620
        Py::List weights;
621
        for (Standard_Integer i=w.LowerRow(); i<=w.UpperRow(); i++) {
622
            Py::List row;
623
            for (Standard_Integer j=w.LowerCol(); j<=w.UpperCol(); j++) {
624
                row.append(Py::Float(w(i,j)));
625
            }
626
            weights.append(row);
627
        }
628
        return Py::new_reference_to(weights);
629
    }
630
    catch (Standard_Failure& e) {
631
        PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
632
        return nullptr;
633
    }
634
}
635

636
PyObject* BezierSurfacePy::getResolution(PyObject *args)
637
{
638
    double tol;
639
    if (!PyArg_ParseTuple(args, "d", &tol))
640
        return nullptr;
641
    try {
642
        Handle(Geom_BezierSurface) surf = Handle(Geom_BezierSurface)::DownCast
643
            (getGeometryPtr()->handle());
644
        double utol, vtol;
645
        surf->Resolution(tol,utol,vtol);
646
        return Py_BuildValue("(dd)",utol,vtol);
647
    }
648
    catch (Standard_Failure& e) {
649
        PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
650
        return nullptr;
651
    }
652
}
653

654
PyObject* BezierSurfacePy::exchangeUV(PyObject *args)
655
{
656
    if (!PyArg_ParseTuple(args, ""))
657
        return nullptr;
658

659
    try {
660
        Handle(Geom_BezierSurface) surf = Handle(Geom_BezierSurface)::DownCast
661
            (getGeometryPtr()->handle());
662
        //FIXME: Crashes
663
        surf->ExchangeUV();
664
        Py_Return;
665
    }
666
    catch (Standard_Failure& e) {
667
        PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
668
        return nullptr;
669
    }
670
}
671

672
Py::Long BezierSurfacePy::getUDegree() const
673
{
674
    Handle(Geom_BezierSurface) surf = Handle(Geom_BezierSurface)::DownCast
675
        (getGeometryPtr()->handle());
676
    return Py::Long(surf->UDegree());
677
}
678

679
Py::Long BezierSurfacePy::getVDegree() const
680
{
681
    Handle(Geom_BezierSurface) surf = Handle(Geom_BezierSurface)::DownCast
682
        (getGeometryPtr()->handle());
683
    return Py::Long(surf->VDegree());
684
}
685

686
Py::Long BezierSurfacePy::getMaxDegree() const
687
{
688
    Handle(Geom_BezierSurface) surf = Handle(Geom_BezierSurface)::DownCast
689
        (getGeometryPtr()->handle());
690
    return Py::Long(surf->MaxDegree());
691
}
692

693
Py::Long BezierSurfacePy::getNbUPoles() const
694
{
695
    Handle(Geom_BezierSurface) surf = Handle(Geom_BezierSurface)::DownCast
696
        (getGeometryPtr()->handle());
697
    return Py::Long(surf->NbUPoles());
698
}
699

700
Py::Long BezierSurfacePy::getNbVPoles() const
701
{
702
    Handle(Geom_BezierSurface) surf = Handle(Geom_BezierSurface)::DownCast
703
        (getGeometryPtr()->handle());
704
    return Py::Long(surf->NbVPoles());
705
}
706

707
PyObject *BezierSurfacePy::getCustomAttributes(const char* /*attr*/) const
708
{
709
    return nullptr;
710
}
711

712
int BezierSurfacePy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
713
{
714
    return 0;
715
}
716

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

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

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

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