Salome HOME
Merge branch 'master' into cgt/devCEA
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_ShapeAPI.cpp
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #include "GeomAlgoAPI_ShapeAPI.h"
22
23 #include <GeomAlgoAPI_Box.h>
24 #include <GeomAlgoAPI_CompoundBuilder.h>
25 #include <GeomAlgoAPI_Cone.h>
26 #include <GeomAlgoAPI_ConeSegment.h>
27 #include <GeomAlgoAPI_Cylinder.h>
28 #include <GeomAlgoAPI_EdgeBuilder.h>
29 #include <GeomAlgoAPI_Rotation.h>
30 #include <GeomAlgoAPI_Scale.h>
31 #include <GeomAlgoAPI_Sphere.h>
32 #include <GeomAlgoAPI_Symmetry.h>
33 #include <GeomAlgoAPI_Torus.h>
34 #include <GeomAlgoAPI_Translation.h>
35
36 #include <GeomAPI_Lin.h>
37
38 #include <math.h>
39
40 namespace GeomAlgoAPI_ShapeAPI
41 {
42   //===============================================================================================
43   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeBox(
44     const double theDx, const double theDy,
45     const double theDz) throw (GeomAlgoAPI_Exception)
46   {
47     GeomAlgoAPI_Box aBoxAlgo(theDx,theDy,theDz);
48
49     if (!aBoxAlgo.check()) {
50       throw GeomAlgoAPI_Exception(aBoxAlgo.getError());
51     }
52
53     aBoxAlgo.build();
54
55     if(!aBoxAlgo.isDone()) {
56       throw GeomAlgoAPI_Exception(aBoxAlgo.getError());
57     }
58     if (!aBoxAlgo.checkValid("Box builder with dimensions")) {
59       throw GeomAlgoAPI_Exception(aBoxAlgo.getError());
60     }
61     return aBoxAlgo.shape();
62   }
63
64   //===============================================================================================
65   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeBox(
66     std::shared_ptr<GeomAPI_Pnt> theFirstPoint,
67     std::shared_ptr<GeomAPI_Pnt> theSecondPoint) throw (GeomAlgoAPI_Exception)
68   {
69     GeomAlgoAPI_Box aBoxAlgo(theFirstPoint, theSecondPoint);
70
71     if (!aBoxAlgo.check()) {
72       throw GeomAlgoAPI_Exception(aBoxAlgo.getError());
73     }
74
75     aBoxAlgo.build();
76
77     if(!aBoxAlgo.isDone()) {
78       throw GeomAlgoAPI_Exception(aBoxAlgo.getError());
79     }
80     if (!aBoxAlgo.checkValid("Box builder with two points")) {
81       throw GeomAlgoAPI_Exception(aBoxAlgo.getError());
82     }
83     return aBoxAlgo.shape();
84   }
85
86   //===============================================================================================
87   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeCylinder(
88     std::shared_ptr<GeomAPI_Pnt> theBasePoint, std::shared_ptr<GeomAPI_Edge> theEdge,
89     double theRadius, double theHeight) throw (GeomAlgoAPI_Exception)
90   {
91     // Check if the base point is OK
92     if (!theBasePoint) {
93       throw GeomAlgoAPI_Exception("Cylinder builder :: the base point is not valid.");
94     }
95     // Check if the edge is OK
96     if (!theEdge) {
97       throw GeomAlgoAPI_Exception("Cylinder builder :: the axis is not valid.");
98     }
99
100     std::shared_ptr<GeomAPI_Ax2> anAxis;
101     anAxis = std::shared_ptr<GeomAPI_Ax2>(new GeomAPI_Ax2(theBasePoint,
102                                                           theEdge->line()->direction()));
103
104     GeomAlgoAPI_Cylinder aCylinderAlgo(anAxis, theRadius, theHeight);
105
106     if (!aCylinderAlgo.check()) {
107       throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
108     }
109
110     aCylinderAlgo.build();
111
112     if(!aCylinderAlgo.isDone()) {
113       throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
114     }
115     if (!aCylinderAlgo.checkValid("Cylinder builder")) {
116       throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
117     }
118     return aCylinderAlgo.shape();
119   }
120
121   //===============================================================================================
122   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeCylinder(
123     std::shared_ptr<GeomAPI_Pnt> theBasePoint, std::shared_ptr<GeomAPI_Edge> theEdge,
124     double theRadius, double theHeight, double theAngle) throw (GeomAlgoAPI_Exception)
125   {
126     // Check if the base point is OK
127     if (!theBasePoint) {
128       throw GeomAlgoAPI_Exception("Cylinder builder :: the base point is not valid.");
129     }
130     // Check if the edge is OK
131     if (!theEdge) {
132       throw GeomAlgoAPI_Exception("Cylinder builder :: the axis is not valid.");
133     }
134
135     std::shared_ptr<GeomAPI_Ax2> anAxis;
136     anAxis = std::shared_ptr<GeomAPI_Ax2>(new GeomAPI_Ax2(theBasePoint,
137                                                           theEdge->line()->direction()));
138
139     GeomAlgoAPI_Cylinder aCylinderAlgo(anAxis, theRadius, theHeight, theAngle);
140
141     if (!aCylinderAlgo.check()) {
142       throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
143     }
144
145     aCylinderAlgo.build();
146
147     if(!aCylinderAlgo.isDone()) {
148       throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
149     }
150     if (!aCylinderAlgo.checkValid("Cylinder portion builder")) {
151       throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
152     }
153     return aCylinderAlgo.shape();
154   }
155
156   //===============================================================================================
157   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeCylinder(
158     double theRadius, double theHeight) throw (GeomAlgoAPI_Exception)
159   {
160     std::shared_ptr<GeomAPI_Pnt> aBasePoint =
161       std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(0.,0.,0.));
162     std::shared_ptr<GeomAPI_Edge> aEdge = GeomAlgoAPI_EdgeBuilder::line(0., 0., 1.);
163     std::shared_ptr<GeomAPI_Ax2> anAxis;
164     anAxis = std::shared_ptr<GeomAPI_Ax2>(new GeomAPI_Ax2(aBasePoint,
165                                                           aEdge->line()->direction()));
166
167     GeomAlgoAPI_Cylinder aCylinderAlgo(anAxis, theRadius, theHeight);
168
169     if (!aCylinderAlgo.check()) {
170       throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
171     }
172
173     aCylinderAlgo.build();
174
175     if(!aCylinderAlgo.isDone()) {
176       throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
177     }
178     if (!aCylinderAlgo.checkValid("Cylinder builder")) {
179       throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
180     }
181     return aCylinderAlgo.shape();
182   }
183
184   //===============================================================================================
185   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeCylinder(
186     double theRadius, double theHeight, double theAngle) throw (GeomAlgoAPI_Exception)
187   {
188     std::shared_ptr<GeomAPI_Pnt> aBasePoint =
189       std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(0.,0.,0.));
190     std::shared_ptr<GeomAPI_Edge> aEdge = GeomAlgoAPI_EdgeBuilder::line(0., 0., 1.);
191     std::shared_ptr<GeomAPI_Ax2> anAxis;
192     anAxis = std::shared_ptr<GeomAPI_Ax2>(new GeomAPI_Ax2(aBasePoint,
193                                                           aEdge->line()->direction()));
194
195     GeomAlgoAPI_Cylinder aCylinderAlgo(anAxis, theRadius, theHeight, theAngle);
196
197     if (!aCylinderAlgo.check()) {
198       throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
199     }
200
201     aCylinderAlgo.build();
202
203     if(!aCylinderAlgo.isDone()) {
204       throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
205     }
206     if (!aCylinderAlgo.checkValid("Cylinder portion builder")) {
207       throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
208     }
209     return aCylinderAlgo.shape();
210   }
211
212   //===============================================================================================
213   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeSphere(
214       std::shared_ptr<GeomAPI_Pnt> theCenterPoint, double theRadius) throw (GeomAlgoAPI_Exception)
215   {
216     GeomAlgoAPI_Sphere aSphereAlgo(theCenterPoint, theRadius);
217
218     if (!aSphereAlgo.check()) {
219       throw GeomAlgoAPI_Exception(aSphereAlgo.getError());
220     }
221
222     aSphereAlgo.build();
223
224     if(!aSphereAlgo.isDone()) {
225       throw GeomAlgoAPI_Exception(aSphereAlgo.getError());
226     }
227
228     if (!aSphereAlgo.checkValid("Sphere builder")) {
229       throw GeomAlgoAPI_Exception(aSphereAlgo.getError());
230     }
231     return aSphereAlgo.shape();
232   }
233
234   //===============================================================================================
235   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeSphere(double theRadius)
236       throw (GeomAlgoAPI_Exception)
237   {
238     std::shared_ptr<GeomAPI_Pnt> aCenterPoint =
239       std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(0.,0.,0.));
240
241     GeomAlgoAPI_Sphere aSphereAlgo(aCenterPoint, theRadius);
242
243     if (!aSphereAlgo.check()) {
244       throw GeomAlgoAPI_Exception(aSphereAlgo.getError());
245     }
246
247     aSphereAlgo.build();
248
249     if(!aSphereAlgo.isDone()) {
250       throw GeomAlgoAPI_Exception(aSphereAlgo.getError());
251     }
252
253     if (!aSphereAlgo.checkValid("Sphere builder")) {
254       throw GeomAlgoAPI_Exception(aSphereAlgo.getError());
255     }
256     return aSphereAlgo.shape();
257   }
258
259   //===============================================================================================
260   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeTorus(
261       std::shared_ptr<GeomAPI_Pnt> theBasePoint,
262       std::shared_ptr<GeomAPI_Edge> theEdge,double theRadius, double theRingRadius)
263       throw (GeomAlgoAPI_Exception)
264   {
265     // Check if the base point is OK
266     if (!theBasePoint) {
267       throw GeomAlgoAPI_Exception("Torus builder :: the base point is not valid.");
268     }
269     // Check if the edge is OK
270     if (!theEdge) {
271       throw GeomAlgoAPI_Exception("Torus builder :: the axis is not valid.");
272     }
273
274     std::shared_ptr<GeomAPI_Ax2> anAxis;
275     anAxis = std::shared_ptr<GeomAPI_Ax2>(new GeomAPI_Ax2(theBasePoint,
276                                                           theEdge->line()->direction()));
277
278     GeomAlgoAPI_Torus aTorusAlgo(anAxis, theRadius, theRingRadius);
279
280     if (!aTorusAlgo.check()) {
281       throw GeomAlgoAPI_Exception(aTorusAlgo.getError());
282     }
283
284     aTorusAlgo.build();
285
286     if(!aTorusAlgo.isDone()) {
287       throw GeomAlgoAPI_Exception(aTorusAlgo.getError());
288     }
289
290     if (!aTorusAlgo.checkValid("Torus builder")) {
291       throw GeomAlgoAPI_Exception(aTorusAlgo.getError());
292     }
293     return aTorusAlgo.shape();
294   }
295
296   //===============================================================================================
297   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeTorus(double theRadius,
298       double theRingRadius) throw (GeomAlgoAPI_Exception)
299   {
300     std::shared_ptr<GeomAPI_Pnt> aBasePoint =
301       std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(0.,0.,0.));
302     std::shared_ptr<GeomAPI_Edge> aEdge = GeomAlgoAPI_EdgeBuilder::line(0., 0., 1.);
303     std::shared_ptr<GeomAPI_Ax2> anAxis;
304     anAxis = std::shared_ptr<GeomAPI_Ax2>(new GeomAPI_Ax2(aBasePoint,
305                                                           aEdge->line()->direction()));
306
307     GeomAlgoAPI_Torus aTorusAlgo(anAxis, theRadius, theRingRadius);
308
309     if (!aTorusAlgo.check()) {
310       throw GeomAlgoAPI_Exception(aTorusAlgo.getError());
311     }
312
313     aTorusAlgo.build();
314
315     if(!aTorusAlgo.isDone()) {
316       throw GeomAlgoAPI_Exception(aTorusAlgo.getError());
317     }
318
319     if (!aTorusAlgo.checkValid("Torus builder")) {
320       throw GeomAlgoAPI_Exception(aTorusAlgo.getError());
321     }
322     return aTorusAlgo.shape();
323   }
324
325   //===============================================================================================
326   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeCone(
327       std::shared_ptr<GeomAPI_Pnt> theBasePoint,
328       std::shared_ptr<GeomAPI_Edge> theEdge,
329       double theBaseRadius, double theTopRadius,
330       double theHeight) throw (GeomAlgoAPI_Exception)
331   {
332     // Check if the base point is OK
333     if (!theBasePoint) {
334       throw GeomAlgoAPI_Exception("Cone builder :: the base point is not valid.");
335     }
336     // Check if the edge is OK
337     if (!theEdge) {
338       throw GeomAlgoAPI_Exception("Cone builder :: the axis is not valid.");
339     }
340
341     std::shared_ptr<GeomAPI_Ax2> anAxis;
342     anAxis = std::shared_ptr<GeomAPI_Ax2>(new GeomAPI_Ax2(theBasePoint,
343                                                           theEdge->line()->direction()));
344
345     GeomAlgoAPI_Cone aConeAlgo(anAxis, theBaseRadius, theTopRadius, theHeight);
346
347     if (!aConeAlgo.check()) {
348       throw GeomAlgoAPI_Exception(aConeAlgo.getError());
349     }
350
351     aConeAlgo.build();
352
353     if(!aConeAlgo.isDone()) {
354       throw GeomAlgoAPI_Exception(aConeAlgo.getError());
355     }
356
357     if (!aConeAlgo.checkValid("Cone builder")) {
358       throw GeomAlgoAPI_Exception(aConeAlgo.getError());
359     }
360     return aConeAlgo.shape();
361   }
362
363   //===============================================================================================
364   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeCone(
365       double theBaseRadius, double theTopRadius,
366       double theHeight) throw (GeomAlgoAPI_Exception)
367   {
368     std::shared_ptr<GeomAPI_Pnt> aBasePoint =
369       std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(0.,0.,0.));
370     std::shared_ptr<GeomAPI_Edge> aEdge = GeomAlgoAPI_EdgeBuilder::line(0., 0., 1.);
371     std::shared_ptr<GeomAPI_Ax2> anAxis;
372     anAxis = std::shared_ptr<GeomAPI_Ax2>(new GeomAPI_Ax2(aBasePoint,
373                                                           aEdge->line()->direction()));
374
375     GeomAlgoAPI_Cone aConeAlgo(anAxis, theBaseRadius, theTopRadius, theHeight);
376
377     if (!aConeAlgo.check()) {
378       throw GeomAlgoAPI_Exception(aConeAlgo.getError());
379     }
380
381     aConeAlgo.build();
382
383     if(!aConeAlgo.isDone()) {
384       throw GeomAlgoAPI_Exception(aConeAlgo.getError());
385     }
386
387     if (!aConeAlgo.checkValid("Cone builder")) {
388       throw GeomAlgoAPI_Exception(aConeAlgo.getError());
389     }
390     return aConeAlgo.shape();
391   }
392
393   //===============================================================================================
394   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeTranslation(
395     std::shared_ptr<GeomAPI_Shape> theSourceShape,
396     std::shared_ptr<GeomAPI_Ax1>   theAxis,
397     const double theDistance) throw (GeomAlgoAPI_Exception)
398   {
399     GeomAlgoAPI_Translation aTranslationAlgo(theSourceShape, theAxis, theDistance);
400
401     if (!aTranslationAlgo.check()) {
402       throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
403     }
404
405     aTranslationAlgo.build();
406
407     if(!aTranslationAlgo.isDone()) {
408       throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
409     }
410
411     return aTranslationAlgo.shape();
412   }
413
414   //===============================================================================================
415   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeTranslation(
416     std::shared_ptr<GeomAPI_Shape> theSourceShape,
417     const double theDx,
418     const double theDy,
419     const double theDz) throw (GeomAlgoAPI_Exception)
420   {
421     GeomAlgoAPI_Translation aTranslationAlgo(theSourceShape, theDx, theDy, theDz);
422
423     if (!aTranslationAlgo.check()) {
424       throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
425     }
426
427     aTranslationAlgo.build();
428
429     if(!aTranslationAlgo.isDone()) {
430       throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
431     }
432
433     return aTranslationAlgo.shape();
434   }
435
436   //===============================================================================================
437   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeTranslation(
438     std::shared_ptr<GeomAPI_Shape> theSourceShape,
439     std::shared_ptr<GeomAPI_Pnt>   theStartPoint,
440     std::shared_ptr<GeomAPI_Pnt>   theEndPoint) throw (GeomAlgoAPI_Exception)
441   {
442     GeomAlgoAPI_Translation aTranslationAlgo(theSourceShape, theStartPoint, theEndPoint);
443
444     if (!aTranslationAlgo.check()) {
445       throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
446     }
447
448     aTranslationAlgo.build();
449
450     if(!aTranslationAlgo.isDone()) {
451       throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
452     }
453
454     return aTranslationAlgo.shape();
455   }
456
457   //===============================================================================================
458   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeRotation(
459     std::shared_ptr<GeomAPI_Shape> theSourceShape,
460     std::shared_ptr<GeomAPI_Ax1> theAxis,
461     const double theAngle) throw (GeomAlgoAPI_Exception)
462   {
463     GeomAlgoAPI_Rotation aRotationAlgo(theSourceShape, theAxis, theAngle);
464
465     if (!aRotationAlgo.check()) {
466       throw GeomAlgoAPI_Exception(aRotationAlgo.getError());
467     }
468
469     aRotationAlgo.build();
470
471     if(!aRotationAlgo.isDone()) {
472       throw GeomAlgoAPI_Exception(aRotationAlgo.getError());
473     }
474
475     return aRotationAlgo.shape();
476   }
477
478   //===============================================================================================
479   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeRotation(
480     std::shared_ptr<GeomAPI_Shape> theSourceShape,
481     std::shared_ptr<GeomAPI_Pnt> theCenterPoint,
482     std::shared_ptr<GeomAPI_Pnt> theStartPoint,
483     std::shared_ptr<GeomAPI_Pnt> theEndPoint) throw (GeomAlgoAPI_Exception)
484   {
485     GeomAlgoAPI_Rotation aRotationAlgo(theSourceShape, theCenterPoint, theStartPoint, theEndPoint);
486
487     if (!aRotationAlgo.check()) {
488       throw GeomAlgoAPI_Exception(aRotationAlgo.getError());
489     }
490
491     aRotationAlgo.build();
492
493     if(!aRotationAlgo.isDone()) {
494       throw GeomAlgoAPI_Exception(aRotationAlgo.getError());
495     }
496
497     return aRotationAlgo.shape();
498   }
499
500   //===============================================================================================
501   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeSymmetry(
502     std::shared_ptr<GeomAPI_Shape> theSourceShape,
503     std::shared_ptr<GeomAPI_Pnt>   thePoint) throw (GeomAlgoAPI_Exception)
504   {
505     GeomAlgoAPI_Symmetry aSymmetryAlgo(theSourceShape, thePoint);
506
507     if (!aSymmetryAlgo.check()) {
508       throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
509     }
510
511     aSymmetryAlgo.build();
512
513     if(!aSymmetryAlgo.isDone()) {
514       throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
515     }
516
517     return aSymmetryAlgo.shape();
518   }
519
520   //===============================================================================================
521   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeSymmetry(
522     std::shared_ptr<GeomAPI_Shape> theSourceShape,
523     std::shared_ptr<GeomAPI_Ax1>   theAxis) throw (GeomAlgoAPI_Exception)
524   {
525     GeomAlgoAPI_Symmetry aSymmetryAlgo(theSourceShape, theAxis);
526
527     if (!aSymmetryAlgo.check()) {
528       throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
529     }
530
531     aSymmetryAlgo.build();
532
533     if(!aSymmetryAlgo.isDone()) {
534       throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
535     }
536
537     return aSymmetryAlgo.shape();
538   }
539
540   //===============================================================================================
541   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeSymmetry(
542     std::shared_ptr<GeomAPI_Shape> theSourceShape,
543     std::shared_ptr<GeomAPI_Ax2>   thePlane) throw (GeomAlgoAPI_Exception)
544   {
545     GeomAlgoAPI_Symmetry aSymmetryAlgo(theSourceShape, thePlane);
546
547     if (!aSymmetryAlgo.check()) {
548       throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
549     }
550
551     aSymmetryAlgo.build();
552
553     if(!aSymmetryAlgo.isDone()) {
554       throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
555     }
556
557     return aSymmetryAlgo.shape();
558   }
559
560   //===============================================================================================
561   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeScale(
562     std::shared_ptr<GeomAPI_Shape> theSourceShape,
563     std::shared_ptr<GeomAPI_Pnt>   theCenterPoint,
564     const double                   theScaleFactor) throw (GeomAlgoAPI_Exception)
565   {
566     GeomAlgoAPI_Scale aScaleAlgo(theSourceShape, theCenterPoint, theScaleFactor);
567
568     if (!aScaleAlgo.check()) {
569       throw GeomAlgoAPI_Exception(aScaleAlgo.getError());
570     }
571
572     aScaleAlgo.build();
573
574     if(!aScaleAlgo.isDone()) {
575       throw GeomAlgoAPI_Exception(aScaleAlgo.getError());
576     }
577
578     return aScaleAlgo.shape();
579   }
580
581   //===============================================================================================
582   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeScale(
583     std::shared_ptr<GeomAPI_Shape> theSourceShape,
584     std::shared_ptr<GeomAPI_Pnt>   theCenterPoint,
585     const double                   theScaleFactorX,
586     const double                   theScaleFactorY,
587     const double                   theScaleFactorZ) throw (GeomAlgoAPI_Exception)
588   {
589     GeomAlgoAPI_Scale aScaleAlgo(theSourceShape, theCenterPoint,
590                                  theScaleFactorX, theScaleFactorY, theScaleFactorZ);
591
592     if (!aScaleAlgo.check()) {
593       throw GeomAlgoAPI_Exception(aScaleAlgo.getError());
594     }
595
596     aScaleAlgo.build();
597
598     if(!aScaleAlgo.isDone()) {
599       throw GeomAlgoAPI_Exception(aScaleAlgo.getError());
600     }
601
602     return aScaleAlgo.shape();
603   }
604
605   //===============================================================================================
606   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeMultiTranslation(
607     std::shared_ptr<GeomAPI_Shape> theSourceShape,
608     std::shared_ptr<GeomAPI_Ax1> theAxis,
609     const double theStep,
610     const int theNumber) throw (GeomAlgoAPI_Exception)
611   {
612     if (!theAxis) {
613       std::string aError = "Multitranslation builder ";
614       aError+=":: the first axis is not valid";
615       throw GeomAlgoAPI_Exception(aError);
616     }
617
618     if (theNumber <=0) {
619       std::string aError = "Multitranslation builder ";
620       aError+=":: the number of copies for the first direction is null or negative.";
621       throw GeomAlgoAPI_Exception(aError);
622     }
623
624     ListOfShape aListOfShape;
625     for (int i=0; i<theNumber; i++) {
626       aListOfShape.
627         push_back(GeomAlgoAPI_ShapeAPI::makeTranslation(theSourceShape, theAxis, i*theStep));
628     }
629     return GeomAlgoAPI_CompoundBuilder::compound(aListOfShape);
630   }
631
632   //===============================================================================================
633   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeMultiTranslation(
634     std::shared_ptr<GeomAPI_Shape> theSourceShape,
635     std::shared_ptr<GeomAPI_Ax1> theFirstAxis,
636     const double theFirstStep,
637     const int theFirstNumber,
638     std::shared_ptr<GeomAPI_Ax1> theSecondAxis,
639     const double theSecondStep,
640     const int theSecondNumber) throw (GeomAlgoAPI_Exception)
641   {
642     if (!theFirstAxis) {
643       std::string aError = "Multitranslation builder ";
644       aError+=":: the first axis is not valid";
645       throw GeomAlgoAPI_Exception(aError);
646     }
647
648     if (!theSecondAxis) {
649       std::string aError = "Multitranslation builder ";
650       aError+=":: the second axis is not valid";
651       throw GeomAlgoAPI_Exception(aError);
652     }
653
654     if (theFirstNumber <=0) {
655       std::string aError = "Multitranslation builder ";
656       aError+=":: the number of copies for the first direction is null or negative.";
657       throw GeomAlgoAPI_Exception(aError);
658     }
659
660     if (theSecondNumber <=0) {
661       std::string aError = "Multitranslation builder ";
662       aError+=":: the number of copies for the second direction is null or negative.";
663       throw GeomAlgoAPI_Exception(aError);
664     }
665
666     // Coord theFirstAxis
667     double x1 = theFirstAxis->dir()->x();
668     double y1 = theFirstAxis->dir()->y();
669     double z1 = theFirstAxis->dir()->z();
670     double norm1 = sqrt(x1*x1 + y1*y1 + z1*z1);
671
672     // Coord theSecondAxis
673     double x2 = theSecondAxis->dir()->x();
674     double y2 = theSecondAxis->dir()->y();
675     double z2 = theSecondAxis->dir()->z();
676     double norm2 = sqrt(x2*x2 + y2*y2 + z2*z2);
677
678     ListOfShape aListOfShape;
679     for (int j=0; j<theSecondStep; j++) {
680       for (int i=0; i<theFirstNumber; i++) {
681         double dx = i*theFirstStep*x1/norm1+j*theSecondStep*x2/norm2;
682         double dy = i*theFirstStep*y1/norm1+j*theSecondStep*y2/norm2;
683         double dz = i*theFirstStep*z1/norm1+j*theSecondStep*z2/norm2;
684         aListOfShape.push_back(GeomAlgoAPI_ShapeAPI::makeTranslation(theSourceShape, dx, dy, dz));
685       }
686     }
687     return GeomAlgoAPI_CompoundBuilder::compound(aListOfShape);
688   }
689
690   //===============================================================================================
691   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeMultiRotation(
692     std::shared_ptr<GeomAPI_Shape> theSourceShape,
693     std::shared_ptr<GeomAPI_Ax1> theAxis,
694     const int theNumber)
695   {
696     if (!theAxis) {
697       std::string aError = "Multirotation builder ";
698       aError+=":: the axis is not valid";
699       throw GeomAlgoAPI_Exception(aError);
700     }
701
702     if (theNumber <=0) {
703       std::string aError = "Multirotation builder ";
704       aError+=":: the number of copies is null or negative.";
705       throw GeomAlgoAPI_Exception(aError);
706     }
707
708     double anAngle = 360./theNumber;
709
710     ListOfShape aListOfShape;
711     for (int i=0; i<theNumber; i++) {
712       aListOfShape.
713         push_back(GeomAlgoAPI_ShapeAPI::makeRotation(theSourceShape, theAxis, i*anAngle));
714     }
715     return GeomAlgoAPI_CompoundBuilder::compound(aListOfShape);
716   }
717
718   //===============================================================================================
719   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeMultiRotation(
720     std::shared_ptr<GeomAPI_Shape> theSourceShape,
721     std::shared_ptr<GeomAPI_Ax1> theAxis,
722     const double theStep,
723     const int theNumber)
724   {
725     if (!theAxis) {
726       std::string aError = "Multirotation builder ";
727       aError+=":: the axis is not valid";
728       throw GeomAlgoAPI_Exception(aError);
729     }
730
731     if (theNumber <=0) {
732       std::string aError = "Multirotation builder ";
733       aError+=":: the number of copies is null or negative.";
734       throw GeomAlgoAPI_Exception(aError);
735     }
736
737     ListOfShape aListOfShape;
738     for (int i=0; i<theNumber; i++) {
739       aListOfShape.
740         push_back(GeomAlgoAPI_ShapeAPI::makeRotation(theSourceShape, theAxis, i*theStep));
741     }
742     return GeomAlgoAPI_CompoundBuilder::compound(aListOfShape);
743   }
744
745   //===============================================================================================
746   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeConeSegment(
747     const double theRMin1, const double theRMax1,
748     const double theRMin2, const double theRMax2,
749     const double theZ,
750     const double theStartPhi, const double theDeltaPhi) throw (GeomAlgoAPI_Exception)
751   {
752     GeomAlgoAPI_ConeSegment aConeSegmentAlgo(theRMin1, theRMax1, theRMin2, theRMax2,
753                                              theZ, theStartPhi, theDeltaPhi);
754
755     if (!aConeSegmentAlgo.check()) {
756       throw GeomAlgoAPI_Exception(aConeSegmentAlgo.getError());
757     }
758
759     aConeSegmentAlgo.build();
760
761     if(!aConeSegmentAlgo.isDone()) {
762       throw GeomAlgoAPI_Exception(aConeSegmentAlgo.getError());
763     }
764     if (!aConeSegmentAlgo.checkValid("Cone Segment builder")) {
765       throw GeomAlgoAPI_Exception(aConeSegmentAlgo.getError());
766     }
767     return aConeSegmentAlgo.shape();
768   }
769 }