1 // Copyright (C) 2014-2016 CEA/DEN, EDF R&D
3 // File: GeomAlgoAPI_ShapeAPI.cpp
4 // Created: 17 Mar 2016
5 // Author: Clarisse Genrault (CEA)
7 #include "GeomAlgoAPI_ShapeAPI.h"
9 #include <GeomAlgoAPI_Box.h>
10 #include <GeomAlgoAPI_CompoundBuilder.h>
11 #include <GeomAlgoAPI_Cone.h>
12 #include <GeomAlgoAPI_ConeSegment.h>
13 #include <GeomAlgoAPI_Cylinder.h>
14 #include <GeomAlgoAPI_EdgeBuilder.h>
15 #include <GeomAlgoAPI_Rotation.h>
16 #include <GeomAlgoAPI_Scale.h>
17 #include <GeomAlgoAPI_Sphere.h>
18 #include <GeomAlgoAPI_Symmetry.h>
19 #include <GeomAlgoAPI_Torus.h>
20 #include <GeomAlgoAPI_Translation.h>
22 #include <GeomAPI_Lin.h>
26 namespace GeomAlgoAPI_ShapeAPI
28 //===============================================================================================
29 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeBox(
30 const double theDx, const double theDy,
31 const double theDz) throw (GeomAlgoAPI_Exception)
33 GeomAlgoAPI_Box aBoxAlgo(theDx,theDy,theDz);
35 if (!aBoxAlgo.check()) {
36 throw GeomAlgoAPI_Exception(aBoxAlgo.getError());
41 if(!aBoxAlgo.isDone()) {
42 throw GeomAlgoAPI_Exception(aBoxAlgo.getError());
44 if (!aBoxAlgo.checkValid("Box builder with dimensions")) {
45 throw GeomAlgoAPI_Exception(aBoxAlgo.getError());
47 return aBoxAlgo.shape();
50 //===============================================================================================
51 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeBox(
52 std::shared_ptr<GeomAPI_Pnt> theFirstPoint,
53 std::shared_ptr<GeomAPI_Pnt> theSecondPoint) throw (GeomAlgoAPI_Exception)
55 GeomAlgoAPI_Box aBoxAlgo(theFirstPoint, theSecondPoint);
57 if (!aBoxAlgo.check()) {
58 throw GeomAlgoAPI_Exception(aBoxAlgo.getError());
63 if(!aBoxAlgo.isDone()) {
64 throw GeomAlgoAPI_Exception(aBoxAlgo.getError());
66 if (!aBoxAlgo.checkValid("Box builder with two points")) {
67 throw GeomAlgoAPI_Exception(aBoxAlgo.getError());
69 return aBoxAlgo.shape();
72 //===============================================================================================
73 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeCylinder(
74 std::shared_ptr<GeomAPI_Pnt> theBasePoint, std::shared_ptr<GeomAPI_Edge> theEdge,
75 double theRadius, double theHeight) throw (GeomAlgoAPI_Exception)
77 // Check if the base point is OK
79 throw GeomAlgoAPI_Exception("Cylinder builder :: the base point is not valid.");
81 // Check if the edge is OK
83 throw GeomAlgoAPI_Exception("Cylinder builder :: the axis is not valid.");
86 std::shared_ptr<GeomAPI_Ax2> anAxis;
87 anAxis = std::shared_ptr<GeomAPI_Ax2>(new GeomAPI_Ax2(theBasePoint,
88 theEdge->line()->direction()));
90 GeomAlgoAPI_Cylinder aCylinderAlgo(anAxis, theRadius, theHeight);
92 if (!aCylinderAlgo.check()) {
93 throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
96 aCylinderAlgo.build();
98 if(!aCylinderAlgo.isDone()) {
99 throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
101 if (!aCylinderAlgo.checkValid("Cylinder builder")) {
102 throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
104 return aCylinderAlgo.shape();
107 //===============================================================================================
108 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeCylinder(
109 std::shared_ptr<GeomAPI_Pnt> theBasePoint, std::shared_ptr<GeomAPI_Edge> theEdge,
110 double theRadius, double theHeight, double theAngle) throw (GeomAlgoAPI_Exception)
112 // Check if the base point is OK
114 throw GeomAlgoAPI_Exception("Cylinder builder :: the base point is not valid.");
116 // Check if the edge is OK
118 throw GeomAlgoAPI_Exception("Cylinder builder :: the axis is not valid.");
121 std::shared_ptr<GeomAPI_Ax2> anAxis;
122 anAxis = std::shared_ptr<GeomAPI_Ax2>(new GeomAPI_Ax2(theBasePoint,
123 theEdge->line()->direction()));
125 GeomAlgoAPI_Cylinder aCylinderAlgo(anAxis, theRadius, theHeight, theAngle);
127 if (!aCylinderAlgo.check()) {
128 throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
131 aCylinderAlgo.build();
133 if(!aCylinderAlgo.isDone()) {
134 throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
136 if (!aCylinderAlgo.checkValid("Cylinder portion builder")) {
137 throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
139 return aCylinderAlgo.shape();
142 //===============================================================================================
143 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeCylinder(
144 double theRadius, double theHeight) throw (GeomAlgoAPI_Exception)
146 std::shared_ptr<GeomAPI_Pnt> aBasePoint =
147 std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(0.,0.,0.));
148 std::shared_ptr<GeomAPI_Edge> aEdge = GeomAlgoAPI_EdgeBuilder::line(0., 0., 1.);
149 std::shared_ptr<GeomAPI_Ax2> anAxis;
150 anAxis = std::shared_ptr<GeomAPI_Ax2>(new GeomAPI_Ax2(aBasePoint,
151 aEdge->line()->direction()));
153 GeomAlgoAPI_Cylinder aCylinderAlgo(anAxis, theRadius, theHeight);
155 if (!aCylinderAlgo.check()) {
156 throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
159 aCylinderAlgo.build();
161 if(!aCylinderAlgo.isDone()) {
162 throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
164 if (!aCylinderAlgo.checkValid("Cylinder builder")) {
165 throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
167 return aCylinderAlgo.shape();
170 //===============================================================================================
171 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeCylinder(
172 double theRadius, double theHeight, double theAngle) throw (GeomAlgoAPI_Exception)
174 std::shared_ptr<GeomAPI_Pnt> aBasePoint =
175 std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(0.,0.,0.));
176 std::shared_ptr<GeomAPI_Edge> aEdge = GeomAlgoAPI_EdgeBuilder::line(0., 0., 1.);
177 std::shared_ptr<GeomAPI_Ax2> anAxis;
178 anAxis = std::shared_ptr<GeomAPI_Ax2>(new GeomAPI_Ax2(aBasePoint,
179 aEdge->line()->direction()));
181 GeomAlgoAPI_Cylinder aCylinderAlgo(anAxis, theRadius, theHeight, theAngle);
183 if (!aCylinderAlgo.check()) {
184 throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
187 aCylinderAlgo.build();
189 if(!aCylinderAlgo.isDone()) {
190 throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
192 if (!aCylinderAlgo.checkValid("Cylinder portion builder")) {
193 throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
195 return aCylinderAlgo.shape();
198 //===============================================================================================
199 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeSphere(
200 std::shared_ptr<GeomAPI_Pnt> theCenterPoint, double theRadius) throw (GeomAlgoAPI_Exception)
202 GeomAlgoAPI_Sphere aSphereAlgo(theCenterPoint, theRadius);
204 if (!aSphereAlgo.check()) {
205 throw GeomAlgoAPI_Exception(aSphereAlgo.getError());
210 if(!aSphereAlgo.isDone()) {
211 throw GeomAlgoAPI_Exception(aSphereAlgo.getError());
214 if (!aSphereAlgo.checkValid("Sphere builder")) {
215 throw GeomAlgoAPI_Exception(aSphereAlgo.getError());
217 return aSphereAlgo.shape();
220 //===============================================================================================
221 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeSphere(double theRadius)
222 throw (GeomAlgoAPI_Exception)
224 std::shared_ptr<GeomAPI_Pnt> aCenterPoint =
225 std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(0.,0.,0.));
227 GeomAlgoAPI_Sphere aSphereAlgo(aCenterPoint, theRadius);
229 if (!aSphereAlgo.check()) {
230 throw GeomAlgoAPI_Exception(aSphereAlgo.getError());
235 if(!aSphereAlgo.isDone()) {
236 throw GeomAlgoAPI_Exception(aSphereAlgo.getError());
239 if (!aSphereAlgo.checkValid("Sphere builder")) {
240 throw GeomAlgoAPI_Exception(aSphereAlgo.getError());
242 return aSphereAlgo.shape();
245 //===============================================================================================
246 std::shared_ptr<GeomAPI_Shape> makeTorus(std::shared_ptr<GeomAPI_Pnt> theBasePoint,
247 std::shared_ptr<GeomAPI_Edge> theEdge,
248 double theRadius, double theRingRadius)
249 throw (GeomAlgoAPI_Exception)
251 // Check if the base point is OK
253 throw GeomAlgoAPI_Exception("Torus builder :: the base point is not valid.");
255 // Check if the edge is OK
257 throw GeomAlgoAPI_Exception("Torus builder :: the axis is not valid.");
260 std::shared_ptr<GeomAPI_Ax2> anAxis;
261 anAxis = std::shared_ptr<GeomAPI_Ax2>(new GeomAPI_Ax2(theBasePoint,
262 theEdge->line()->direction()));
264 GeomAlgoAPI_Torus aTorusAlgo(anAxis, theRadius, theRingRadius);
266 if (!aTorusAlgo.check()) {
267 throw GeomAlgoAPI_Exception(aTorusAlgo.getError());
272 if(!aTorusAlgo.isDone()) {
273 throw GeomAlgoAPI_Exception(aTorusAlgo.getError());
276 if (!aTorusAlgo.checkValid("Torus builder")) {
277 throw GeomAlgoAPI_Exception(aTorusAlgo.getError());
279 return aTorusAlgo.shape();
282 //===============================================================================================
283 std::shared_ptr<GeomAPI_Shape> makeTorus(double theRadius, double theRingRadius)
284 throw (GeomAlgoAPI_Exception)
286 std::shared_ptr<GeomAPI_Pnt> aBasePoint =
287 std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(0.,0.,0.));
288 std::shared_ptr<GeomAPI_Edge> aEdge = GeomAlgoAPI_EdgeBuilder::line(0., 0., 1.);
289 std::shared_ptr<GeomAPI_Ax2> anAxis;
290 anAxis = std::shared_ptr<GeomAPI_Ax2>(new GeomAPI_Ax2(aBasePoint,
291 aEdge->line()->direction()));
293 GeomAlgoAPI_Torus aTorusAlgo(anAxis, theRadius, theRingRadius);
295 if (!aTorusAlgo.check()) {
296 throw GeomAlgoAPI_Exception(aTorusAlgo.getError());
301 if(!aTorusAlgo.isDone()) {
302 throw GeomAlgoAPI_Exception(aTorusAlgo.getError());
305 if (!aTorusAlgo.checkValid("Torus builder")) {
306 throw GeomAlgoAPI_Exception(aTorusAlgo.getError());
308 return aTorusAlgo.shape();
311 //===============================================================================================
312 std::shared_ptr<GeomAPI_Shape> makeCone(std::shared_ptr<GeomAPI_Pnt> theBasePoint,
313 std::shared_ptr<GeomAPI_Edge> theEdge,
314 double theBaseRadius, double theTopRadius,
315 double theHeight) throw (GeomAlgoAPI_Exception)
317 // Check if the base point is OK
319 throw GeomAlgoAPI_Exception("Cone builder :: the base point is not valid.");
321 // Check if the edge is OK
323 throw GeomAlgoAPI_Exception("Cone builder :: the axis is not valid.");
326 std::shared_ptr<GeomAPI_Ax2> anAxis;
327 anAxis = std::shared_ptr<GeomAPI_Ax2>(new GeomAPI_Ax2(theBasePoint,
328 theEdge->line()->direction()));
330 GeomAlgoAPI_Cone aConeAlgo(anAxis, theBaseRadius, theTopRadius, theHeight);
332 if (!aConeAlgo.check()) {
333 throw GeomAlgoAPI_Exception(aConeAlgo.getError());
338 if(!aConeAlgo.isDone()) {
339 throw GeomAlgoAPI_Exception(aConeAlgo.getError());
342 if (!aConeAlgo.checkValid("Cone builder")) {
343 throw GeomAlgoAPI_Exception(aConeAlgo.getError());
345 return aConeAlgo.shape();
348 //===============================================================================================
349 std::shared_ptr<GeomAPI_Shape> makeCone(double theBaseRadius, double theTopRadius,
350 double theHeight) throw (GeomAlgoAPI_Exception)
352 std::shared_ptr<GeomAPI_Pnt> aBasePoint =
353 std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(0.,0.,0.));
354 std::shared_ptr<GeomAPI_Edge> aEdge = GeomAlgoAPI_EdgeBuilder::line(0., 0., 1.);
355 std::shared_ptr<GeomAPI_Ax2> anAxis;
356 anAxis = std::shared_ptr<GeomAPI_Ax2>(new GeomAPI_Ax2(aBasePoint,
357 aEdge->line()->direction()));
359 GeomAlgoAPI_Cone aConeAlgo(anAxis, theBaseRadius, theTopRadius, theHeight);
361 if (!aConeAlgo.check()) {
362 throw GeomAlgoAPI_Exception(aConeAlgo.getError());
367 if(!aConeAlgo.isDone()) {
368 throw GeomAlgoAPI_Exception(aConeAlgo.getError());
371 if (!aConeAlgo.checkValid("Cone builder")) {
372 throw GeomAlgoAPI_Exception(aConeAlgo.getError());
374 return aConeAlgo.shape();
377 //===============================================================================================
378 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeTranslation(
379 std::shared_ptr<GeomAPI_Shape> theSourceShape,
380 std::shared_ptr<GeomAPI_Ax1> theAxis,
381 const double theDistance) throw (GeomAlgoAPI_Exception)
383 GeomAlgoAPI_Translation aTranslationAlgo(theSourceShape, theAxis, theDistance);
385 if (!aTranslationAlgo.check()) {
386 throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
389 aTranslationAlgo.build();
391 if(!aTranslationAlgo.isDone()) {
392 throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
395 return aTranslationAlgo.shape();
398 //===============================================================================================
399 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeTranslation(
400 std::shared_ptr<GeomAPI_Shape> theSourceShape,
403 const double theDz) throw (GeomAlgoAPI_Exception)
405 GeomAlgoAPI_Translation aTranslationAlgo(theSourceShape, theDx, theDy, theDz);
407 if (!aTranslationAlgo.check()) {
408 throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
411 aTranslationAlgo.build();
413 if(!aTranslationAlgo.isDone()) {
414 throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
417 return aTranslationAlgo.shape();
420 //===============================================================================================
421 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeTranslation(
422 std::shared_ptr<GeomAPI_Shape> theSourceShape,
423 std::shared_ptr<GeomAPI_Pnt> theStartPoint,
424 std::shared_ptr<GeomAPI_Pnt> theEndPoint) throw (GeomAlgoAPI_Exception)
426 GeomAlgoAPI_Translation aTranslationAlgo(theSourceShape, theStartPoint, theEndPoint);
428 if (!aTranslationAlgo.check()) {
429 throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
432 aTranslationAlgo.build();
434 if(!aTranslationAlgo.isDone()) {
435 throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
438 return aTranslationAlgo.shape();
441 //===============================================================================================
442 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeRotation(
443 std::shared_ptr<GeomAPI_Shape> theSourceShape,
444 std::shared_ptr<GeomAPI_Ax1> theAxis,
445 const double theAngle) throw (GeomAlgoAPI_Exception)
447 GeomAlgoAPI_Rotation aRotationAlgo(theSourceShape, theAxis, theAngle);
449 if (!aRotationAlgo.check()) {
450 throw GeomAlgoAPI_Exception(aRotationAlgo.getError());
453 aRotationAlgo.build();
455 if(!aRotationAlgo.isDone()) {
456 throw GeomAlgoAPI_Exception(aRotationAlgo.getError());
459 return aRotationAlgo.shape();
462 //===============================================================================================
463 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeRotation(
464 std::shared_ptr<GeomAPI_Shape> theSourceShape,
465 std::shared_ptr<GeomAPI_Pnt> theCenterPoint,
466 std::shared_ptr<GeomAPI_Pnt> theStartPoint,
467 std::shared_ptr<GeomAPI_Pnt> theEndPoint) throw (GeomAlgoAPI_Exception)
469 GeomAlgoAPI_Rotation aRotationAlgo(theSourceShape, theCenterPoint, theStartPoint, theEndPoint);
471 if (!aRotationAlgo.check()) {
472 throw GeomAlgoAPI_Exception(aRotationAlgo.getError());
475 aRotationAlgo.build();
477 if(!aRotationAlgo.isDone()) {
478 throw GeomAlgoAPI_Exception(aRotationAlgo.getError());
481 return aRotationAlgo.shape();
484 //===============================================================================================
485 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeSymmetry(
486 std::shared_ptr<GeomAPI_Shape> theSourceShape,
487 std::shared_ptr<GeomAPI_Pnt> thePoint) throw (GeomAlgoAPI_Exception)
489 GeomAlgoAPI_Symmetry aSymmetryAlgo(theSourceShape, thePoint);
491 if (!aSymmetryAlgo.check()) {
492 throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
495 aSymmetryAlgo.build();
497 if(!aSymmetryAlgo.isDone()) {
498 throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
501 return aSymmetryAlgo.shape();
504 //===============================================================================================
505 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeSymmetry(
506 std::shared_ptr<GeomAPI_Shape> theSourceShape,
507 std::shared_ptr<GeomAPI_Ax1> theAxis) throw (GeomAlgoAPI_Exception)
509 GeomAlgoAPI_Symmetry aSymmetryAlgo(theSourceShape, theAxis);
511 if (!aSymmetryAlgo.check()) {
512 throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
515 aSymmetryAlgo.build();
517 if(!aSymmetryAlgo.isDone()) {
518 throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
521 return aSymmetryAlgo.shape();
524 //===============================================================================================
525 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeSymmetry(
526 std::shared_ptr<GeomAPI_Shape> theSourceShape,
527 std::shared_ptr<GeomAPI_Ax2> thePlane) throw (GeomAlgoAPI_Exception)
529 GeomAlgoAPI_Symmetry aSymmetryAlgo(theSourceShape, thePlane);
531 if (!aSymmetryAlgo.check()) {
532 throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
535 aSymmetryAlgo.build();
537 if(!aSymmetryAlgo.isDone()) {
538 throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
541 return aSymmetryAlgo.shape();
544 //===============================================================================================
545 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeScale(
546 std::shared_ptr<GeomAPI_Shape> theSourceShape,
547 std::shared_ptr<GeomAPI_Pnt> theCenterPoint,
548 const double theScaleFactor) throw (GeomAlgoAPI_Exception)
550 GeomAlgoAPI_Scale aScaleAlgo(theSourceShape, theCenterPoint, theScaleFactor);
552 if (!aScaleAlgo.check()) {
553 throw GeomAlgoAPI_Exception(aScaleAlgo.getError());
558 if(!aScaleAlgo.isDone()) {
559 throw GeomAlgoAPI_Exception(aScaleAlgo.getError());
562 return aScaleAlgo.shape();
565 //===============================================================================================
566 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeScale(
567 std::shared_ptr<GeomAPI_Shape> theSourceShape,
568 std::shared_ptr<GeomAPI_Pnt> theCenterPoint,
569 const double theScaleFactorX,
570 const double theScaleFactorY,
571 const double theScaleFactorZ) throw (GeomAlgoAPI_Exception)
573 GeomAlgoAPI_Scale aScaleAlgo(theSourceShape, theCenterPoint,
574 theScaleFactorX, theScaleFactorY, theScaleFactorZ);
576 if (!aScaleAlgo.check()) {
577 throw GeomAlgoAPI_Exception(aScaleAlgo.getError());
582 if(!aScaleAlgo.isDone()) {
583 throw GeomAlgoAPI_Exception(aScaleAlgo.getError());
586 return aScaleAlgo.shape();
589 //===============================================================================================
590 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeMultiTranslation(
591 std::shared_ptr<GeomAPI_Shape> theSourceShape,
592 std::shared_ptr<GeomAPI_Ax1> theAxis,
593 const double theStep,
594 const int theNumber) throw (GeomAlgoAPI_Exception)
597 std::string aError = "Multitranslation builder ";
598 aError+=":: the number of copies for the first direction is null or negative.";
599 throw GeomAlgoAPI_Exception(aError);
603 std::string aError = "Multitranslation builder ";
604 aError+=":: the first axis is not valid";
605 throw GeomAlgoAPI_Exception(aError);
608 ListOfShape aListOfShape;
609 for (int i=0; i<theNumber; i++) {
611 push_back(GeomAlgoAPI_ShapeAPI::makeTranslation(theSourceShape, theAxis, i*theStep));
613 return GeomAlgoAPI_CompoundBuilder::compound(aListOfShape);
616 //===============================================================================================
617 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeMultiTranslation(
618 std::shared_ptr<GeomAPI_Shape> theSourceShape,
619 std::shared_ptr<GeomAPI_Ax1> theFirstAxis,
620 const double theFirstStep,
621 const int theFirstNumber,
622 std::shared_ptr<GeomAPI_Ax1> theSecondAxis,
623 const double theSecondStep,
624 const int theSecondNumber) throw (GeomAlgoAPI_Exception)
626 if (theFirstNumber <=0) {
627 std::string aError = "Multitranslation builder ";
628 aError+=":: the number of copies for the first direction is null or negative.";
629 throw GeomAlgoAPI_Exception(aError);
632 if (theSecondNumber <=0) {
633 std::string aError = "Multitranslation builder ";
634 aError+=":: the number of copies for the second direction is null or negative.";
635 throw GeomAlgoAPI_Exception(aError);
639 std::string aError = "Multitranslation builder ";
640 aError+=":: the first axis is not valid";
641 throw GeomAlgoAPI_Exception(aError);
644 if (!theSecondAxis) {
645 std::string aError = "Multitranslation builder ";
646 aError+=":: the second axis is not valid";
647 throw GeomAlgoAPI_Exception(aError);
650 // Coord theFirstAxis
651 double x1 = theFirstAxis->dir()->x();
652 double y1 = theFirstAxis->dir()->y();
653 double z1 = theFirstAxis->dir()->z();
654 double norm1 = sqrt(x1*x1 + y1*y1 + z1*z1);
656 // Coord theSecondAxis
657 double x2 = theSecondAxis->dir()->x();
658 double y2 = theSecondAxis->dir()->y();
659 double z2 = theSecondAxis->dir()->z();
660 double norm2 = sqrt(x2*x2 + y2*y2 + z2*z2);
662 ListOfShape aListOfShape;
663 for (int j=0; j<theSecondStep; j++) {
664 for (int i=0; i<theFirstNumber; i++) {
665 double dx = i*theFirstStep*x1/norm1+j*theSecondStep*x2/norm2;
666 double dy = i*theFirstStep*y1/norm1+j*theSecondStep*y2/norm2;
667 double dz = i*theFirstStep*z1/norm1+j*theSecondStep*z2/norm2;
668 aListOfShape.push_back(GeomAlgoAPI_ShapeAPI::makeTranslation(theSourceShape, dx, dy, dz));
671 return GeomAlgoAPI_CompoundBuilder::compound(aListOfShape);
674 //===============================================================================================
675 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeConeSegment(
676 const double theRMin1, const double theRMax1,
677 const double theRMin2, const double theRMax2,
679 const double theStartPhi, const double theDeltaPhi) throw (GeomAlgoAPI_Exception)
681 GeomAlgoAPI_ConeSegment aConeSegmentAlgo(theRMin1, theRMax1, theRMin2, theRMax2,
682 theZ, theStartPhi, theDeltaPhi);
684 if (!aConeSegmentAlgo.check()) {
685 throw GeomAlgoAPI_Exception(aConeSegmentAlgo.getError());
688 aConeSegmentAlgo.build();
690 if(!aConeSegmentAlgo.isDone()) {
691 throw GeomAlgoAPI_Exception(aConeSegmentAlgo.getError());
693 if (!aConeSegmentAlgo.checkValid("Cone Segment builder")) {
694 throw GeomAlgoAPI_Exception(aConeSegmentAlgo.getError());
696 return aConeSegmentAlgo.shape();