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> GeomAlgoAPI_ShapeAPI::makeTorus(
247 std::shared_ptr<GeomAPI_Pnt> theBasePoint,
248 std::shared_ptr<GeomAPI_Edge> theEdge,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> GeomAlgoAPI_ShapeAPI::makeTorus(double theRadius,
284 double theRingRadius) 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> GeomAlgoAPI_ShapeAPI::makeCone(
313 std::shared_ptr<GeomAPI_Pnt> theBasePoint,
314 std::shared_ptr<GeomAPI_Edge> theEdge,
315 double theBaseRadius, double theTopRadius,
316 double theHeight) throw (GeomAlgoAPI_Exception)
318 // Check if the base point is OK
320 throw GeomAlgoAPI_Exception("Cone builder :: the base point is not valid.");
322 // Check if the edge is OK
324 throw GeomAlgoAPI_Exception("Cone builder :: the axis is not valid.");
327 std::shared_ptr<GeomAPI_Ax2> anAxis;
328 anAxis = std::shared_ptr<GeomAPI_Ax2>(new GeomAPI_Ax2(theBasePoint,
329 theEdge->line()->direction()));
331 GeomAlgoAPI_Cone aConeAlgo(anAxis, theBaseRadius, theTopRadius, theHeight);
333 if (!aConeAlgo.check()) {
334 throw GeomAlgoAPI_Exception(aConeAlgo.getError());
339 if(!aConeAlgo.isDone()) {
340 throw GeomAlgoAPI_Exception(aConeAlgo.getError());
343 if (!aConeAlgo.checkValid("Cone builder")) {
344 throw GeomAlgoAPI_Exception(aConeAlgo.getError());
346 return aConeAlgo.shape();
349 //===============================================================================================
350 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeCone(
351 double theBaseRadius, double theTopRadius,
352 double theHeight) throw (GeomAlgoAPI_Exception)
354 std::shared_ptr<GeomAPI_Pnt> aBasePoint =
355 std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(0.,0.,0.));
356 std::shared_ptr<GeomAPI_Edge> aEdge = GeomAlgoAPI_EdgeBuilder::line(0., 0., 1.);
357 std::shared_ptr<GeomAPI_Ax2> anAxis;
358 anAxis = std::shared_ptr<GeomAPI_Ax2>(new GeomAPI_Ax2(aBasePoint,
359 aEdge->line()->direction()));
361 GeomAlgoAPI_Cone aConeAlgo(anAxis, theBaseRadius, theTopRadius, theHeight);
363 if (!aConeAlgo.check()) {
364 throw GeomAlgoAPI_Exception(aConeAlgo.getError());
369 if(!aConeAlgo.isDone()) {
370 throw GeomAlgoAPI_Exception(aConeAlgo.getError());
373 if (!aConeAlgo.checkValid("Cone builder")) {
374 throw GeomAlgoAPI_Exception(aConeAlgo.getError());
376 return aConeAlgo.shape();
379 //===============================================================================================
380 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeTranslation(
381 std::shared_ptr<GeomAPI_Shape> theSourceShape,
382 std::shared_ptr<GeomAPI_Ax1> theAxis,
383 const double theDistance) throw (GeomAlgoAPI_Exception)
385 GeomAlgoAPI_Translation aTranslationAlgo(theSourceShape, theAxis, theDistance);
387 if (!aTranslationAlgo.check()) {
388 throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
391 aTranslationAlgo.build();
393 if(!aTranslationAlgo.isDone()) {
394 throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
397 return aTranslationAlgo.shape();
400 //===============================================================================================
401 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeTranslation(
402 std::shared_ptr<GeomAPI_Shape> theSourceShape,
405 const double theDz) throw (GeomAlgoAPI_Exception)
407 GeomAlgoAPI_Translation aTranslationAlgo(theSourceShape, theDx, theDy, theDz);
409 if (!aTranslationAlgo.check()) {
410 throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
413 aTranslationAlgo.build();
415 if(!aTranslationAlgo.isDone()) {
416 throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
419 return aTranslationAlgo.shape();
422 //===============================================================================================
423 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeTranslation(
424 std::shared_ptr<GeomAPI_Shape> theSourceShape,
425 std::shared_ptr<GeomAPI_Pnt> theStartPoint,
426 std::shared_ptr<GeomAPI_Pnt> theEndPoint) throw (GeomAlgoAPI_Exception)
428 GeomAlgoAPI_Translation aTranslationAlgo(theSourceShape, theStartPoint, theEndPoint);
430 if (!aTranslationAlgo.check()) {
431 throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
434 aTranslationAlgo.build();
436 if(!aTranslationAlgo.isDone()) {
437 throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
440 return aTranslationAlgo.shape();
443 //===============================================================================================
444 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeRotation(
445 std::shared_ptr<GeomAPI_Shape> theSourceShape,
446 std::shared_ptr<GeomAPI_Ax1> theAxis,
447 const double theAngle) throw (GeomAlgoAPI_Exception)
449 GeomAlgoAPI_Rotation aRotationAlgo(theSourceShape, theAxis, theAngle);
451 if (!aRotationAlgo.check()) {
452 throw GeomAlgoAPI_Exception(aRotationAlgo.getError());
455 aRotationAlgo.build();
457 if(!aRotationAlgo.isDone()) {
458 throw GeomAlgoAPI_Exception(aRotationAlgo.getError());
461 return aRotationAlgo.shape();
464 //===============================================================================================
465 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeRotation(
466 std::shared_ptr<GeomAPI_Shape> theSourceShape,
467 std::shared_ptr<GeomAPI_Pnt> theCenterPoint,
468 std::shared_ptr<GeomAPI_Pnt> theStartPoint,
469 std::shared_ptr<GeomAPI_Pnt> theEndPoint) throw (GeomAlgoAPI_Exception)
471 GeomAlgoAPI_Rotation aRotationAlgo(theSourceShape, theCenterPoint, theStartPoint, theEndPoint);
473 if (!aRotationAlgo.check()) {
474 throw GeomAlgoAPI_Exception(aRotationAlgo.getError());
477 aRotationAlgo.build();
479 if(!aRotationAlgo.isDone()) {
480 throw GeomAlgoAPI_Exception(aRotationAlgo.getError());
483 return aRotationAlgo.shape();
486 //===============================================================================================
487 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeSymmetry(
488 std::shared_ptr<GeomAPI_Shape> theSourceShape,
489 std::shared_ptr<GeomAPI_Pnt> thePoint) throw (GeomAlgoAPI_Exception)
491 GeomAlgoAPI_Symmetry aSymmetryAlgo(theSourceShape, thePoint);
493 if (!aSymmetryAlgo.check()) {
494 throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
497 aSymmetryAlgo.build();
499 if(!aSymmetryAlgo.isDone()) {
500 throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
503 return aSymmetryAlgo.shape();
506 //===============================================================================================
507 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeSymmetry(
508 std::shared_ptr<GeomAPI_Shape> theSourceShape,
509 std::shared_ptr<GeomAPI_Ax1> theAxis) throw (GeomAlgoAPI_Exception)
511 GeomAlgoAPI_Symmetry aSymmetryAlgo(theSourceShape, theAxis);
513 if (!aSymmetryAlgo.check()) {
514 throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
517 aSymmetryAlgo.build();
519 if(!aSymmetryAlgo.isDone()) {
520 throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
523 return aSymmetryAlgo.shape();
526 //===============================================================================================
527 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeSymmetry(
528 std::shared_ptr<GeomAPI_Shape> theSourceShape,
529 std::shared_ptr<GeomAPI_Ax2> thePlane) throw (GeomAlgoAPI_Exception)
531 GeomAlgoAPI_Symmetry aSymmetryAlgo(theSourceShape, thePlane);
533 if (!aSymmetryAlgo.check()) {
534 throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
537 aSymmetryAlgo.build();
539 if(!aSymmetryAlgo.isDone()) {
540 throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
543 return aSymmetryAlgo.shape();
546 //===============================================================================================
547 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeScale(
548 std::shared_ptr<GeomAPI_Shape> theSourceShape,
549 std::shared_ptr<GeomAPI_Pnt> theCenterPoint,
550 const double theScaleFactor) throw (GeomAlgoAPI_Exception)
552 GeomAlgoAPI_Scale aScaleAlgo(theSourceShape, theCenterPoint, theScaleFactor);
554 if (!aScaleAlgo.check()) {
555 throw GeomAlgoAPI_Exception(aScaleAlgo.getError());
560 if(!aScaleAlgo.isDone()) {
561 throw GeomAlgoAPI_Exception(aScaleAlgo.getError());
564 return aScaleAlgo.shape();
567 //===============================================================================================
568 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeScale(
569 std::shared_ptr<GeomAPI_Shape> theSourceShape,
570 std::shared_ptr<GeomAPI_Pnt> theCenterPoint,
571 const double theScaleFactorX,
572 const double theScaleFactorY,
573 const double theScaleFactorZ) throw (GeomAlgoAPI_Exception)
575 GeomAlgoAPI_Scale aScaleAlgo(theSourceShape, theCenterPoint,
576 theScaleFactorX, theScaleFactorY, theScaleFactorZ);
578 if (!aScaleAlgo.check()) {
579 throw GeomAlgoAPI_Exception(aScaleAlgo.getError());
584 if(!aScaleAlgo.isDone()) {
585 throw GeomAlgoAPI_Exception(aScaleAlgo.getError());
588 return aScaleAlgo.shape();
591 //===============================================================================================
592 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeMultiTranslation(
593 std::shared_ptr<GeomAPI_Shape> theSourceShape,
594 std::shared_ptr<GeomAPI_Ax1> theAxis,
595 const double theStep,
596 const int theNumber) throw (GeomAlgoAPI_Exception)
599 std::string aError = "Multitranslation builder ";
600 aError+=":: the first axis is not valid";
601 throw GeomAlgoAPI_Exception(aError);
605 std::string aError = "Multitranslation builder ";
606 aError+=":: the number of copies for the first direction is null or negative.";
607 throw GeomAlgoAPI_Exception(aError);
610 ListOfShape aListOfShape;
611 for (int i=0; i<theNumber; i++) {
613 push_back(GeomAlgoAPI_ShapeAPI::makeTranslation(theSourceShape, theAxis, i*theStep));
615 return GeomAlgoAPI_CompoundBuilder::compound(aListOfShape);
618 //===============================================================================================
619 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeMultiTranslation(
620 std::shared_ptr<GeomAPI_Shape> theSourceShape,
621 std::shared_ptr<GeomAPI_Ax1> theFirstAxis,
622 const double theFirstStep,
623 const int theFirstNumber,
624 std::shared_ptr<GeomAPI_Ax1> theSecondAxis,
625 const double theSecondStep,
626 const int theSecondNumber) throw (GeomAlgoAPI_Exception)
629 std::string aError = "Multitranslation builder ";
630 aError+=":: the first axis is not valid";
631 throw GeomAlgoAPI_Exception(aError);
634 if (!theSecondAxis) {
635 std::string aError = "Multitranslation builder ";
636 aError+=":: the second axis is not valid";
637 throw GeomAlgoAPI_Exception(aError);
640 if (theFirstNumber <=0) {
641 std::string aError = "Multitranslation builder ";
642 aError+=":: the number of copies for the first direction is null or negative.";
643 throw GeomAlgoAPI_Exception(aError);
646 if (theSecondNumber <=0) {
647 std::string aError = "Multitranslation builder ";
648 aError+=":: the number of copies for the second direction is null or negative.";
649 throw GeomAlgoAPI_Exception(aError);
652 // Coord theFirstAxis
653 double x1 = theFirstAxis->dir()->x();
654 double y1 = theFirstAxis->dir()->y();
655 double z1 = theFirstAxis->dir()->z();
656 double norm1 = sqrt(x1*x1 + y1*y1 + z1*z1);
658 // Coord theSecondAxis
659 double x2 = theSecondAxis->dir()->x();
660 double y2 = theSecondAxis->dir()->y();
661 double z2 = theSecondAxis->dir()->z();
662 double norm2 = sqrt(x2*x2 + y2*y2 + z2*z2);
664 ListOfShape aListOfShape;
665 for (int j=0; j<theSecondStep; j++) {
666 for (int i=0; i<theFirstNumber; i++) {
667 double dx = i*theFirstStep*x1/norm1+j*theSecondStep*x2/norm2;
668 double dy = i*theFirstStep*y1/norm1+j*theSecondStep*y2/norm2;
669 double dz = i*theFirstStep*z1/norm1+j*theSecondStep*z2/norm2;
670 aListOfShape.push_back(GeomAlgoAPI_ShapeAPI::makeTranslation(theSourceShape, dx, dy, dz));
673 return GeomAlgoAPI_CompoundBuilder::compound(aListOfShape);
676 //===============================================================================================
677 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeConeSegment(
678 const double theRMin1, const double theRMax1,
679 const double theRMin2, const double theRMax2,
681 const double theStartPhi, const double theDeltaPhi) throw (GeomAlgoAPI_Exception)
683 GeomAlgoAPI_ConeSegment aConeSegmentAlgo(theRMin1, theRMax1, theRMin2, theRMax2,
684 theZ, theStartPhi, theDeltaPhi);
686 if (!aConeSegmentAlgo.check()) {
687 throw GeomAlgoAPI_Exception(aConeSegmentAlgo.getError());
690 aConeSegmentAlgo.build();
692 if(!aConeSegmentAlgo.isDone()) {
693 throw GeomAlgoAPI_Exception(aConeSegmentAlgo.getError());
695 if (!aConeSegmentAlgo.checkValid("Cone Segment builder")) {
696 throw GeomAlgoAPI_Exception(aConeSegmentAlgo.getError());
698 return aConeSegmentAlgo.shape();