/
FeaturePrimitive.cpp
683 lines (569 loc) · 25 KB
/
FeaturePrimitive.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
/***************************************************************************
* Copyright (c) 2015 Stefan Tröger <stefantroeger@gmx.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_
#endif
#include "FeaturePrimitive.h"
#include "DatumPoint.h"
#include "DatumCS.h"
#include <Mod/Part/App/modelRefine.h>
#include <Mod/Part/App/PartFeaturePy.h>
#include <Base/Exception.h>
#include <Base/Tools.h>
#include <App/Document.h>
#include <App/Application.h>
#include <App/FeaturePythonPyImp.h>
#include <BRepPrimAPI_MakeBox.hxx>
#include <BRepBuilderAPI_GTransform.hxx>
#include <BRepAlgoAPI_Fuse.hxx>
#include <BRepAlgoAPI_Cut.hxx>
#include <BRepBuilderAPI_Transform.hxx>
#include <BRepPrimAPI_MakeCylinder.hxx>
#include <BRepPrimAPI_MakeSphere.hxx>
#include <BRepPrimAPI_MakeCone.hxx>
#include <BRepPrimAPI_MakeTorus.hxx>
#include <BRepPrimAPI_MakePrism.hxx>
#include <BRepBuilderAPI_MakePolygon.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>
#include <BRepBuilderAPI_MakeSolid.hxx>
#include <QObject>
#include <math.h>
using namespace PartDesign;
namespace PartDesign {
const App::PropertyQuantityConstraint::Constraints torusRangeV = {-180.0,180.0,1.0};
const App::PropertyQuantityConstraint::Constraints angleRangeU = {0.0,360.0,1.0};
const App::PropertyQuantityConstraint::Constraints angleRangeV = {-90.0,90.0,1.0};
const App::PropertyQuantityConstraint::Constraints quantityRange = {0.0,FLT_MAX,0.1};
PROPERTY_SOURCE_WITH_EXTENSIONS(PartDesign::FeaturePrimitive, PartDesign::FeatureAddSub)
FeaturePrimitive::FeaturePrimitive()
: primitiveType(Box)
{
Part::AttachExtension::initExtension(this);
}
TopoDS_Shape FeaturePrimitive::refineShapeIfActive(const TopoDS_Shape& oldShape) const
{
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/PartDesign");
if (hGrp->GetBool("RefineModel", false)) {
Part::BRepBuilderAPI_RefineModel mkRefine(oldShape);
TopoDS_Shape resShape = mkRefine.Shape();
return resShape;
}
return oldShape;
}
App::DocumentObjectExecReturn* FeaturePrimitive::execute(const TopoDS_Shape& primitiveShape)
{
try {
//transform the primitive in the correct coordinance
FeatureAddSub::execute();
//if we have no base we just add the standard primitive shape
TopoDS_Shape base;
try{
//if we have a base shape we need to make sure that it does not get our transformation to
BRepBuilderAPI_Transform trsf(getBaseShape(), getLocation().Transformation().Inverted(), true);
base = trsf.Shape();
}
catch(const Base::Exception&) {
//as we use this for preview we can add it even if useless for subtractive
AddSubShape.setValue(primitiveShape);
if(getAddSubType() == FeatureAddSub::Additive)
Shape.setValue(getSolid(primitiveShape));
else
return new App::DocumentObjectExecReturn("Cannot subtract primitive feature without base feature");
return App::DocumentObject::StdReturn;
}
if(getAddSubType() == FeatureAddSub::Additive) {
BRepAlgoAPI_Fuse mkFuse(base, primitiveShape);
if (!mkFuse.IsDone())
return new App::DocumentObjectExecReturn("Adding the primitive failed");
// we have to get the solids (fuse sometimes creates compounds)
TopoDS_Shape boolOp = this->getSolid(mkFuse.Shape());
// lets check if the result is a solid
if (boolOp.IsNull())
return new App::DocumentObjectExecReturn("Resulting shape is not a solid");
boolOp = refineShapeIfActive(boolOp);
Shape.setValue(getSolid(boolOp));
AddSubShape.setValue(primitiveShape);
}
else if(getAddSubType() == FeatureAddSub::Subtractive) {
BRepAlgoAPI_Cut mkCut(base, primitiveShape);
if (!mkCut.IsDone())
return new App::DocumentObjectExecReturn("Subtracting the primitive failed");
// we have to get the solids (fuse sometimes creates compounds)
TopoDS_Shape boolOp = this->getSolid(mkCut.Shape());
// lets check if the result is a solid
if (boolOp.IsNull())
return new App::DocumentObjectExecReturn("Resulting shape is not a solid");
boolOp = refineShapeIfActive(boolOp);
Shape.setValue(getSolid(boolOp));
AddSubShape.setValue(primitiveShape);
}
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
return new App::DocumentObjectExecReturn(e->GetMessageString());
}
return App::DocumentObject::StdReturn;
}
void FeaturePrimitive::onChanged(const App::Property* prop)
{
FeatureAddSub::onChanged(prop);
}
PYTHON_TYPE_DEF(PrimitivePy, Part::PartFeaturePy)
PYTHON_TYPE_IMP(PrimitivePy, Part::PartFeaturePy)
PyObject* FeaturePrimitive::getPyObject()
{
if (PythonObject.is(Py::_None())){
// ref counter is set to 1
PythonObject = Py::Object(new PrimitivePy(this),true);
}
return Py::new_reference_to(PythonObject);
}
PROPERTY_SOURCE(PartDesign::Box, PartDesign::FeaturePrimitive)
Box::Box()
{
ADD_PROPERTY_TYPE(Length,(10.0f),"Box",App::Prop_None,"The length of the box");
ADD_PROPERTY_TYPE(Width ,(10.0f),"Box",App::Prop_None,"The width of the box");
ADD_PROPERTY_TYPE(Height,(10.0f),"Box",App::Prop_None,"The height of the box");
Length.setConstraints(&quantityRange);
Width.setConstraints(&quantityRange);
Height.setConstraints(&quantityRange);
primitiveType = FeaturePrimitive::Box;
}
App::DocumentObjectExecReturn* Box::execute(void)
{
double L = Length.getValue();
double W = Width.getValue();
double H = Height.getValue();
if (L < Precision::Confusion())
return new App::DocumentObjectExecReturn("Length of box too small");
if (W < Precision::Confusion())
return new App::DocumentObjectExecReturn("Width of box too small");
if (H < Precision::Confusion())
return new App::DocumentObjectExecReturn("Height of box too small");
try {
// Build a box using the dimension attributes
BRepPrimAPI_MakeBox mkBox(L, W, H);
return FeaturePrimitive::execute(mkBox.Shape());
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
return new App::DocumentObjectExecReturn(e->GetMessageString());
}
}
short int Box::mustExecute() const
{
if ( Length.isTouched() ||
Height.isTouched() ||
Width.isTouched() )
return 1;
return FeaturePrimitive::mustExecute();
}
PROPERTY_SOURCE(PartDesign::AdditiveBox, PartDesign::Box)
PROPERTY_SOURCE(PartDesign::SubtractiveBox, PartDesign::Box)
PROPERTY_SOURCE(PartDesign::Cylinder, PartDesign::FeaturePrimitive)
Cylinder::Cylinder()
{
ADD_PROPERTY_TYPE(Radius,(10.0f),"Cylinder",App::Prop_None,"The radius of the cylinder");
ADD_PROPERTY_TYPE(Angle,(360.0f),"Cylinder",App::Prop_None,"The closing angle of the cylinder ");
ADD_PROPERTY_TYPE(Height,(10.0f),"Cylinder",App::Prop_None,"The height of the cylinder");
Angle.setConstraints(&angleRangeU);
Radius.setConstraints(&quantityRange);
Height.setConstraints(&quantityRange);
primitiveType = FeaturePrimitive::Cylinder;
}
App::DocumentObjectExecReturn* Cylinder::execute(void)
{
// Build a cylinder
if (Radius.getValue() < Precision::Confusion())
return new App::DocumentObjectExecReturn("Radius of cylinder too small");
if (Height.getValue() < Precision::Confusion())
return new App::DocumentObjectExecReturn("Height of cylinder too small");
try {
BRepPrimAPI_MakeCylinder mkCylr(Radius.getValue(),
Height.getValue(),
Angle.getValue()/180.0f*M_PI);
return FeaturePrimitive::execute(mkCylr.Shape());
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
return new App::DocumentObjectExecReturn(e->GetMessageString());
}
return App::DocumentObject::StdReturn;
}
short int Cylinder::mustExecute() const
{
if ( Radius.isTouched() ||
Height.isTouched() ||
Angle.isTouched() )
return 1;
return FeaturePrimitive::mustExecute();
}
PROPERTY_SOURCE(PartDesign::AdditiveCylinder, PartDesign::Cylinder)
PROPERTY_SOURCE(PartDesign::SubtractiveCylinder, PartDesign::Cylinder)
PROPERTY_SOURCE(PartDesign::Sphere, PartDesign::FeaturePrimitive)
Sphere::Sphere()
{
ADD_PROPERTY_TYPE(Radius,(5.0),"Sphere",App::Prop_None,"The radius of the sphere");
Radius.setConstraints(&quantityRange);
ADD_PROPERTY_TYPE(Angle1,(-90.0f),"Sphere",App::Prop_None,"The angle of the sphere");
Angle1.setConstraints(&angleRangeV);
ADD_PROPERTY_TYPE(Angle2,(90.0f),"Sphere",App::Prop_None,"The angle of the sphere");
Angle2.setConstraints(&angleRangeV);
ADD_PROPERTY_TYPE(Angle3,(360.0f),"Sphere",App::Prop_None,"The angle of the sphere");
Angle3.setConstraints(&angleRangeU);
primitiveType = FeaturePrimitive::Sphere;
}
App::DocumentObjectExecReturn* Sphere::execute(void)
{
// Build a sphere
if (Radius.getValue() < Precision::Confusion())
return new App::DocumentObjectExecReturn("Radius of sphere too small");
try {
BRepPrimAPI_MakeSphere mkSphere(Radius.getValue(),
Angle1.getValue()/180.0f*M_PI,
Angle2.getValue()/180.0f*M_PI,
Angle3.getValue()/180.0f*M_PI);
return FeaturePrimitive::execute(mkSphere.Shape());
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
return new App::DocumentObjectExecReturn(e->GetMessageString());
}
return App::DocumentObject::StdReturn;
}
short int Sphere::mustExecute() const
{
if ( Radius.isTouched() ||
Angle1.isTouched() ||
Angle2.isTouched() ||
Angle3.isTouched())
return 1;
return FeaturePrimitive::mustExecute();
}
PROPERTY_SOURCE(PartDesign::AdditiveSphere, PartDesign::Sphere)
PROPERTY_SOURCE(PartDesign::SubtractiveSphere, PartDesign::Sphere)
PROPERTY_SOURCE(PartDesign::Cone, PartDesign::FeaturePrimitive)
Cone::Cone()
{
ADD_PROPERTY_TYPE(Radius1,(2.0),"Cone",App::Prop_None,"The radius of the cone");
ADD_PROPERTY_TYPE(Radius2,(4.0),"Cone",App::Prop_None,"The radius of the cone");
ADD_PROPERTY_TYPE(Height,(10.0),"Cone",App::Prop_None,"The height of the cone");
ADD_PROPERTY_TYPE(Angle,(360.0),"Cone",App::Prop_None,"The angle of the cone");
Angle.setConstraints(&angleRangeU);
Radius1.setConstraints(&quantityRange);
Radius2.setConstraints(&quantityRange);
Height.setConstraints(&quantityRange);
primitiveType = FeaturePrimitive::Cone;
}
App::DocumentObjectExecReturn* Cone::execute(void)
{
if (Radius1.getValue() < 0)
return new App::DocumentObjectExecReturn("Radius of cone too small");
if (Radius2.getValue() < 0)
return new App::DocumentObjectExecReturn("Radius of cone too small");
if (Height.getValue() < Precision::Confusion())
return new App::DocumentObjectExecReturn("Height of cone too small");
try {
// Build a cone
BRepPrimAPI_MakeCone mkCone(Radius1.getValue(),
Radius2.getValue(),
Height.getValue(),
Angle.getValue()/180.0f*M_PI);
return FeaturePrimitive::execute(mkCone.Shape());
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
return new App::DocumentObjectExecReturn(e->GetMessageString());
}
return App::DocumentObject::StdReturn;
}
short int Cone::mustExecute() const
{
if (Radius1.isTouched())
return 1;
if (Radius2.isTouched())
return 1;
if (Height.isTouched())
return 1;
if (Angle.isTouched())
return 1;
return FeaturePrimitive::mustExecute();
}
PROPERTY_SOURCE(PartDesign::AdditiveCone, PartDesign::Cone)
PROPERTY_SOURCE(PartDesign::SubtractiveCone, PartDesign::Cone)
PROPERTY_SOURCE(PartDesign::Ellipsoid, PartDesign::FeaturePrimitive)
Ellipsoid::Ellipsoid()
{
ADD_PROPERTY_TYPE(Radius1,(2.0),"Ellipsoid",App::Prop_None,"The radius of the ellipsoid");
Radius1.setConstraints(&quantityRange);
ADD_PROPERTY_TYPE(Radius2,(4.0),"Ellipsoid",App::Prop_None,"The radius of the ellipsoid");
Radius2.setConstraints(&quantityRange);
ADD_PROPERTY_TYPE(Radius3,(0.0),"Ellipsoid",App::Prop_None,"The radius of the ellipsoid");
Radius3.setConstraints(&quantityRange);
ADD_PROPERTY_TYPE(Angle1,(-90.0f),"Ellipsoid",App::Prop_None,"The angle of the ellipsoid");
Angle1.setConstraints(&angleRangeV);
ADD_PROPERTY_TYPE(Angle2,(90.0f),"Ellipsoid",App::Prop_None,"The angle of the ellipsoid");
Angle2.setConstraints(&angleRangeV);
ADD_PROPERTY_TYPE(Angle3,(360.0f),"Ellipsoid",App::Prop_None,"The angle of the ellipsoid");
Angle3.setConstraints(&angleRangeU);
primitiveType = FeaturePrimitive::Ellipsoid;
}
App::DocumentObjectExecReturn* Ellipsoid::execute(void)
{
// Build a sphere
if (Radius1.getValue() < Precision::Confusion())
return new App::DocumentObjectExecReturn("Radius of ellipsoid too small");
if (Radius2.getValue() < Precision::Confusion())
return new App::DocumentObjectExecReturn("Radius of ellipsoid too small");
try {
gp_Pnt pnt(0.0,0.0,0.0);
gp_Dir dir(0.0,0.0,1.0);
gp_Ax2 ax2(pnt,dir);
BRepPrimAPI_MakeSphere mkSphere(ax2,
Radius2.getValue(),
Angle1.getValue()/180.0f*M_PI,
Angle2.getValue()/180.0f*M_PI,
Angle3.getValue()/180.0f*M_PI);
Standard_Real scaleX = 1.0;
Standard_Real scaleZ = Radius1.getValue()/Radius2.getValue();
// issue #1798: A third radius has been introduced. To be backward
// compatible if Radius3 is 0.0 (default) it's handled to be the same
// as Radius2
Standard_Real scaleY = 1.0;
if (Radius3.getValue() >= Precision::Confusion())
scaleY = Radius3.getValue()/Radius2.getValue();
gp_GTrsf mat;
mat.SetValue(1,1,scaleX);
mat.SetValue(2,1,0.0);
mat.SetValue(3,1,0.0);
mat.SetValue(1,2,0.0);
mat.SetValue(2,2,scaleY);
mat.SetValue(3,2,0.0);
mat.SetValue(1,3,0.0);
mat.SetValue(2,3,0.0);
mat.SetValue(3,3,scaleZ);
BRepBuilderAPI_GTransform mkTrsf(mkSphere.Shape(), mat);
return FeaturePrimitive::execute(mkTrsf.Shape());
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
return new App::DocumentObjectExecReturn(e->GetMessageString());
}
return App::DocumentObject::StdReturn;
}
short int Ellipsoid::mustExecute() const
{
if (Radius1.isTouched())
return 1;
if (Radius2.isTouched())
return 1;
if (Radius3.isTouched())
return 1;
if (Angle1.isTouched())
return 1;
if (Angle2.isTouched())
return 1;
if (Angle3.isTouched())
return 1;
return FeaturePrimitive::mustExecute();
}
PROPERTY_SOURCE(PartDesign::AdditiveEllipsoid, PartDesign::Ellipsoid)
PROPERTY_SOURCE(PartDesign::SubtractiveEllipsoid, PartDesign::Ellipsoid)
PROPERTY_SOURCE(PartDesign::Torus, PartDesign::FeaturePrimitive)
Torus::Torus()
{
ADD_PROPERTY_TYPE(Radius1,(10.0),"Torus",App::Prop_None,"The radius of the torus");
Radius1.setConstraints(&quantityRange);
ADD_PROPERTY_TYPE(Radius2,(2.0),"Torus",App::Prop_None,"The radius of the torus");
Radius2.setConstraints(&quantityRange);
ADD_PROPERTY_TYPE(Angle1,(-180.0),"Torus",App::Prop_None,"The angle of the torus");
Angle1.setConstraints(&torusRangeV);
ADD_PROPERTY_TYPE(Angle2,(180.0),"Torus",App::Prop_None,"The angle of the torus");
Angle2.setConstraints(&torusRangeV);
ADD_PROPERTY_TYPE(Angle3,(360.0),"Torus",App::Prop_None,"The angle of the torus");
Angle3.setConstraints(&angleRangeU);
primitiveType = FeaturePrimitive::Torus;
}
App::DocumentObjectExecReturn* Torus::execute(void)
{
if (Radius1.getValue() < Precision::Confusion())
return new App::DocumentObjectExecReturn("Radius of torus too small");
if (Radius2.getValue() < Precision::Confusion())
return new App::DocumentObjectExecReturn("Radius of torus too small");
try {
BRepPrimAPI_MakeTorus mkTorus(Radius1.getValue(),
Radius2.getValue(),
Angle1.getValue()/180.0f*M_PI,
Angle2.getValue()/180.0f*M_PI,
Angle3.getValue()/180.0f*M_PI);
return FeaturePrimitive::execute(mkTorus.Solid());
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
return new App::DocumentObjectExecReturn(e->GetMessageString());
}
return App::DocumentObject::StdReturn;
}
short int Torus::mustExecute() const
{
if (Radius1.isTouched())
return 1;
if (Radius2.isTouched())
return 1;
if (Angle1.isTouched())
return 1;
if (Angle2.isTouched())
return 1;
if (Angle3.isTouched())
return 1;
return FeaturePrimitive::mustExecute();
}
PROPERTY_SOURCE(PartDesign::AdditiveTorus, PartDesign::Torus)
PROPERTY_SOURCE(PartDesign::SubtractiveTorus, PartDesign::Torus)
PROPERTY_SOURCE(PartDesign::Prism, PartDesign::FeaturePrimitive)
Prism::Prism()
{
ADD_PROPERTY_TYPE(Polygon,(6.0),"Prism",App::Prop_None,"Number of sides in the polygon, of the prism");
ADD_PROPERTY_TYPE(Circumradius,(2.0),"Prism",App::Prop_None,"Circumradius (centre to vertex) of the polygon, of the prism");
ADD_PROPERTY_TYPE(Height,(10.0f),"Prism",App::Prop_None,"The height of the prism");
primitiveType = FeaturePrimitive::Prism;
}
App::DocumentObjectExecReturn* Prism::execute(void)
{
// Build a prism
if (Polygon.getValue() < 3)
return new App::DocumentObjectExecReturn("Polygon of prism is invalid, must have 3 or more sides");
if (Circumradius.getValue() < Precision::Confusion())
return new App::DocumentObjectExecReturn("Circumradius of the polygon, of the prism, is too small");
if (Height.getValue() < Precision::Confusion())
return new App::DocumentObjectExecReturn("Height of prism is too small");
try {
long nodes = Polygon.getValue();
Base::Matrix4D mat;
mat.rotZ(Base::toRadians(360.0/nodes));
// create polygon
BRepBuilderAPI_MakePolygon mkPoly;
Base::Vector3d v(Circumradius.getValue(),0,0);
for (long i=0; i<nodes; i++) {
mkPoly.Add(gp_Pnt(v.x,v.y,v.z));
v = mat * v;
}
mkPoly.Add(gp_Pnt(v.x,v.y,v.z));
BRepBuilderAPI_MakeFace mkFace(mkPoly.Wire());
BRepPrimAPI_MakePrism mkPrism(mkFace.Face(), gp_Vec(0,0,Height.getValue()));
return FeaturePrimitive::execute(mkPrism.Shape());
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
return new App::DocumentObjectExecReturn(e->GetMessageString());
}
return App::DocumentObject::StdReturn;
}
short int Prism::mustExecute() const
{
if (Polygon.isTouched())
return 1;
if (Circumradius.isTouched())
return 1;
if (Height.isTouched())
return 1;
return FeaturePrimitive::mustExecute();
}
PROPERTY_SOURCE(PartDesign::AdditivePrism, PartDesign::Prism)
PROPERTY_SOURCE(PartDesign::SubtractivePrism, PartDesign::Prism)
PROPERTY_SOURCE(PartDesign::Wedge, PartDesign::FeaturePrimitive)
Wedge::Wedge()
{
ADD_PROPERTY_TYPE(Xmin,(0.0f),"Wedge",App::Prop_None,"Xmin of the wedge");
ADD_PROPERTY_TYPE(Ymin,(0.0f),"Wedge",App::Prop_None,"Ymin of the wedge");
ADD_PROPERTY_TYPE(Zmin,(0.0f),"Wedge",App::Prop_None,"Zmin of the wedge");
ADD_PROPERTY_TYPE(X2min,(2.0f),"Wedge",App::Prop_None,"X2min of the wedge");
ADD_PROPERTY_TYPE(Z2min,(2.0f),"Wedge",App::Prop_None,"Z2min of the wedge");
ADD_PROPERTY_TYPE(Xmax,(10.0f),"Wedge",App::Prop_None,"Xmax of the wedge");
ADD_PROPERTY_TYPE(Ymax,(10.0f),"Wedge",App::Prop_None,"Ymax of the wedge");
ADD_PROPERTY_TYPE(Zmax,(10.0f),"Wedge",App::Prop_None,"Zmax of the wedge");
ADD_PROPERTY_TYPE(X2max,(8.0f),"Wedge",App::Prop_None,"X2max of the wedge");
ADD_PROPERTY_TYPE(Z2max,(8.0f),"Wedge",App::Prop_None,"Z2max of the wedge");
primitiveType = FeaturePrimitive::Wedge;
}
App::DocumentObjectExecReturn* Wedge::execute(void)
{
double xmin = Xmin.getValue();
double ymin = Ymin.getValue();
double zmin = Zmin.getValue();
double z2min = Z2min.getValue();
double x2min = X2min.getValue();
double xmax = Xmax.getValue();
double ymax = Ymax.getValue();
double zmax = Zmax.getValue();
double z2max = Z2max.getValue();
double x2max = X2max.getValue();
double dx = xmax-xmin;
double dy = ymax-ymin;
double dz = zmax-zmin;
double dz2 = z2max-z2min;
double dx2 = x2max-x2min;
if (dx < Precision::Confusion())
return new App::DocumentObjectExecReturn("delta x of wedge too small");
if (dy < Precision::Confusion())
return new App::DocumentObjectExecReturn("delta y of wedge too small");
if (dz < Precision::Confusion())
return new App::DocumentObjectExecReturn("delta z of wedge too small");
if (dz2 < 0)
return new App::DocumentObjectExecReturn("delta z2 of wedge is negative");
if (dx2 < 0)
return new App::DocumentObjectExecReturn("delta x2 of wedge is negative");
try {
gp_Pnt pnt(0.0,0.0,0.0);
gp_Dir dir(0.0,0.0,1.0);
BRepPrim_Wedge mkWedge(gp_Ax2(pnt,dir),
xmin, ymin, zmin, z2min, x2min,
xmax, ymax, zmax, z2max, x2max);
BRepBuilderAPI_MakeSolid mkSolid;
mkSolid.Add(mkWedge.Shell());
return FeaturePrimitive::execute(mkSolid.Solid());
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
return new App::DocumentObjectExecReturn(e->GetMessageString());
}
return App::DocumentObject::StdReturn;
}
short int Wedge::mustExecute() const
{
if (Xmin.isTouched() ||
Ymin.isTouched() ||
Zmin.isTouched() ||
X2min.isTouched() ||
Z2min.isTouched() ||
Xmax.isTouched() ||
Ymax.isTouched() ||
Zmax.isTouched() ||
X2max.isTouched() ||
Z2max.isTouched())
return 1;
return FeaturePrimitive::mustExecute();
}
PROPERTY_SOURCE(PartDesign::AdditiveWedge, PartDesign::Wedge)
PROPERTY_SOURCE(PartDesign::SubtractiveWedge, PartDesign::Wedge)
}