Salome HOME
Merge branch 'master' into cgt/devCEA
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_ShapeAPI.cpp
1 // Copyright (C) 2014-2016 CEA/DEN, EDF R&D
2
3 // File:        GeomAlgoAPI_ShapeAPI.cpp
4 // Created:     17 Mar 2016
5 // Author:      Clarisse Genrault (CEA)
6
7 #include "GeomAlgoAPI_ShapeAPI.h"
8
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>
21
22 #include <GeomAPI_Lin.h>
23
24 #include <math.h>
25
26 namespace GeomAlgoAPI_ShapeAPI
27 {
28   //===============================================================================================
29   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeBox(
30     const double theDx, const double theDy,
31     const double theDz) throw (GeomAlgoAPI_Exception)
32   {
33     GeomAlgoAPI_Box aBoxAlgo(theDx,theDy,theDz);
34
35     if (!aBoxAlgo.check()) {
36       throw GeomAlgoAPI_Exception(aBoxAlgo.getError());
37     }
38
39     aBoxAlgo.build();
40
41     if(!aBoxAlgo.isDone()) {
42       throw GeomAlgoAPI_Exception(aBoxAlgo.getError());
43     }
44     if (!aBoxAlgo.checkValid("Box builder with dimensions")) {
45       throw GeomAlgoAPI_Exception(aBoxAlgo.getError());
46     }
47     return aBoxAlgo.shape();
48   }
49
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)
54   {
55     GeomAlgoAPI_Box aBoxAlgo(theFirstPoint, theSecondPoint);
56
57     if (!aBoxAlgo.check()) {
58       throw GeomAlgoAPI_Exception(aBoxAlgo.getError());
59     }
60
61     aBoxAlgo.build();
62
63     if(!aBoxAlgo.isDone()) {
64       throw GeomAlgoAPI_Exception(aBoxAlgo.getError());
65     }
66     if (!aBoxAlgo.checkValid("Box builder with two points")) {
67       throw GeomAlgoAPI_Exception(aBoxAlgo.getError());
68     }
69     return aBoxAlgo.shape();
70   }
71
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)
76   {
77     // Check if the base point is OK
78     if (!theBasePoint) {
79       throw GeomAlgoAPI_Exception("Cylinder builder :: the base point is not valid.");
80     }
81     // Check if the edge is OK
82     if (!theEdge) {
83       throw GeomAlgoAPI_Exception("Cylinder builder :: the axis is not valid.");
84     }
85
86     std::shared_ptr<GeomAPI_Ax2> anAxis;
87     anAxis = std::shared_ptr<GeomAPI_Ax2>(new GeomAPI_Ax2(theBasePoint,
88                                                           theEdge->line()->direction()));
89
90     GeomAlgoAPI_Cylinder aCylinderAlgo(anAxis, theRadius, theHeight);
91
92     if (!aCylinderAlgo.check()) {
93       throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
94     }
95
96     aCylinderAlgo.build();
97
98     if(!aCylinderAlgo.isDone()) {
99       throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
100     }
101     if (!aCylinderAlgo.checkValid("Cylinder builder")) {
102       throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
103     }
104     return aCylinderAlgo.shape();
105   }
106
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)
111   {
112     // Check if the base point is OK
113     if (!theBasePoint) {
114       throw GeomAlgoAPI_Exception("Cylinder builder :: the base point is not valid.");
115     }
116     // Check if the edge is OK
117     if (!theEdge) {
118       throw GeomAlgoAPI_Exception("Cylinder builder :: the axis is not valid.");
119     }
120
121     std::shared_ptr<GeomAPI_Ax2> anAxis;
122     anAxis = std::shared_ptr<GeomAPI_Ax2>(new GeomAPI_Ax2(theBasePoint,
123                                                           theEdge->line()->direction()));
124
125     GeomAlgoAPI_Cylinder aCylinderAlgo(anAxis, theRadius, theHeight, theAngle);
126
127     if (!aCylinderAlgo.check()) {
128       throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
129     }
130
131     aCylinderAlgo.build();
132
133     if(!aCylinderAlgo.isDone()) {
134       throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
135     }
136     if (!aCylinderAlgo.checkValid("Cylinder portion builder")) {
137       throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
138     }
139     return aCylinderAlgo.shape();
140   }
141
142   //===============================================================================================
143   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeCylinder(
144     double theRadius, double theHeight) throw (GeomAlgoAPI_Exception)
145   {
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()));
152
153     GeomAlgoAPI_Cylinder aCylinderAlgo(anAxis, theRadius, theHeight);
154
155     if (!aCylinderAlgo.check()) {
156       throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
157     }
158
159     aCylinderAlgo.build();
160
161     if(!aCylinderAlgo.isDone()) {
162       throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
163     }
164     if (!aCylinderAlgo.checkValid("Cylinder builder")) {
165       throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
166     }
167     return aCylinderAlgo.shape();
168   }
169
170   //===============================================================================================
171   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeCylinder(
172     double theRadius, double theHeight, double theAngle) throw (GeomAlgoAPI_Exception)
173   {
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()));
180
181     GeomAlgoAPI_Cylinder aCylinderAlgo(anAxis, theRadius, theHeight, theAngle);
182
183     if (!aCylinderAlgo.check()) {
184       throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
185     }
186
187     aCylinderAlgo.build();
188
189     if(!aCylinderAlgo.isDone()) {
190       throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
191     }
192     if (!aCylinderAlgo.checkValid("Cylinder portion builder")) {
193       throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
194     }
195     return aCylinderAlgo.shape();
196   }
197
198   //===============================================================================================
199   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeSphere(
200       std::shared_ptr<GeomAPI_Pnt> theCenterPoint, double theRadius) throw (GeomAlgoAPI_Exception)
201   {
202     GeomAlgoAPI_Sphere aSphereAlgo(theCenterPoint, theRadius);
203
204     if (!aSphereAlgo.check()) {
205       throw GeomAlgoAPI_Exception(aSphereAlgo.getError());
206     }
207
208     aSphereAlgo.build();
209
210     if(!aSphereAlgo.isDone()) {
211       throw GeomAlgoAPI_Exception(aSphereAlgo.getError());
212     }
213
214     if (!aSphereAlgo.checkValid("Sphere builder")) {
215       throw GeomAlgoAPI_Exception(aSphereAlgo.getError());
216     }
217     return aSphereAlgo.shape();
218   }
219
220   //===============================================================================================
221   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeSphere(double theRadius)
222       throw (GeomAlgoAPI_Exception)
223   {
224     std::shared_ptr<GeomAPI_Pnt> aCenterPoint =
225       std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(0.,0.,0.));
226
227     GeomAlgoAPI_Sphere aSphereAlgo(aCenterPoint, theRadius);
228
229     if (!aSphereAlgo.check()) {
230       throw GeomAlgoAPI_Exception(aSphereAlgo.getError());
231     }
232
233     aSphereAlgo.build();
234
235     if(!aSphereAlgo.isDone()) {
236       throw GeomAlgoAPI_Exception(aSphereAlgo.getError());
237     }
238
239     if (!aSphereAlgo.checkValid("Sphere builder")) {
240       throw GeomAlgoAPI_Exception(aSphereAlgo.getError());
241     }
242     return aSphereAlgo.shape();
243   }
244
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)
250   {
251     // Check if the base point is OK
252     if (!theBasePoint) {
253       throw GeomAlgoAPI_Exception("Torus builder :: the base point is not valid.");
254     }
255     // Check if the edge is OK
256     if (!theEdge) {
257       throw GeomAlgoAPI_Exception("Torus builder :: the axis is not valid.");
258     }
259
260     std::shared_ptr<GeomAPI_Ax2> anAxis;
261     anAxis = std::shared_ptr<GeomAPI_Ax2>(new GeomAPI_Ax2(theBasePoint,
262                                                           theEdge->line()->direction()));
263
264     GeomAlgoAPI_Torus aTorusAlgo(anAxis, theRadius, theRingRadius);
265
266     if (!aTorusAlgo.check()) {
267       throw GeomAlgoAPI_Exception(aTorusAlgo.getError());
268     }
269
270     aTorusAlgo.build();
271
272     if(!aTorusAlgo.isDone()) {
273       throw GeomAlgoAPI_Exception(aTorusAlgo.getError());
274     }
275
276     if (!aTorusAlgo.checkValid("Torus builder")) {
277       throw GeomAlgoAPI_Exception(aTorusAlgo.getError());
278     }
279     return aTorusAlgo.shape();
280   }
281
282   //===============================================================================================
283   std::shared_ptr<GeomAPI_Shape> makeTorus(double theRadius, double theRingRadius)
284       throw (GeomAlgoAPI_Exception)
285   {
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()));
292
293     GeomAlgoAPI_Torus aTorusAlgo(anAxis, theRadius, theRingRadius);
294
295     if (!aTorusAlgo.check()) {
296       throw GeomAlgoAPI_Exception(aTorusAlgo.getError());
297     }
298
299     aTorusAlgo.build();
300
301     if(!aTorusAlgo.isDone()) {
302       throw GeomAlgoAPI_Exception(aTorusAlgo.getError());
303     }
304
305     if (!aTorusAlgo.checkValid("Torus builder")) {
306       throw GeomAlgoAPI_Exception(aTorusAlgo.getError());
307     }
308     return aTorusAlgo.shape();
309   }
310
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)
316   {
317     // Check if the base point is OK
318     if (!theBasePoint) {
319       throw GeomAlgoAPI_Exception("Cone builder :: the base point is not valid.");
320     }
321     // Check if the edge is OK
322     if (!theEdge) {
323       throw GeomAlgoAPI_Exception("Cone builder :: the axis is not valid.");
324     }
325
326     std::shared_ptr<GeomAPI_Ax2> anAxis;
327     anAxis = std::shared_ptr<GeomAPI_Ax2>(new GeomAPI_Ax2(theBasePoint,
328                                                           theEdge->line()->direction()));
329
330     GeomAlgoAPI_Cone aConeAlgo(anAxis, theBaseRadius, theTopRadius, theHeight);
331
332     if (!aConeAlgo.check()) {
333       throw GeomAlgoAPI_Exception(aConeAlgo.getError());
334     }
335
336     aConeAlgo.build();
337
338     if(!aConeAlgo.isDone()) {
339       throw GeomAlgoAPI_Exception(aConeAlgo.getError());
340     }
341
342     if (!aConeAlgo.checkValid("Cone builder")) {
343       throw GeomAlgoAPI_Exception(aConeAlgo.getError());
344     }
345     return aConeAlgo.shape();
346   }
347
348   //===============================================================================================
349   std::shared_ptr<GeomAPI_Shape> makeCone(double theBaseRadius, double theTopRadius,
350                                           double theHeight) throw (GeomAlgoAPI_Exception)
351   {
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()));
358
359     GeomAlgoAPI_Cone aConeAlgo(anAxis, theBaseRadius, theTopRadius, theHeight);
360
361     if (!aConeAlgo.check()) {
362       throw GeomAlgoAPI_Exception(aConeAlgo.getError());
363     }
364
365     aConeAlgo.build();
366
367     if(!aConeAlgo.isDone()) {
368       throw GeomAlgoAPI_Exception(aConeAlgo.getError());
369     }
370
371     if (!aConeAlgo.checkValid("Cone builder")) {
372       throw GeomAlgoAPI_Exception(aConeAlgo.getError());
373     }
374     return aConeAlgo.shape();
375   }
376
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)
382   {
383     GeomAlgoAPI_Translation aTranslationAlgo(theSourceShape, theAxis, theDistance);
384
385     if (!aTranslationAlgo.check()) {
386       throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
387     }
388
389     aTranslationAlgo.build();
390
391     if(!aTranslationAlgo.isDone()) {
392       throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
393     }
394
395     return aTranslationAlgo.shape();
396   }
397
398   //===============================================================================================
399   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeTranslation(
400     std::shared_ptr<GeomAPI_Shape> theSourceShape,
401     const double theDx,
402     const double theDy,
403     const double theDz) throw (GeomAlgoAPI_Exception)
404   {
405     GeomAlgoAPI_Translation aTranslationAlgo(theSourceShape, theDx, theDy, theDz);
406
407     if (!aTranslationAlgo.check()) {
408       throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
409     }
410
411     aTranslationAlgo.build();
412
413     if(!aTranslationAlgo.isDone()) {
414       throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
415     }
416
417     return aTranslationAlgo.shape();
418   }
419
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)
425   {
426     GeomAlgoAPI_Translation aTranslationAlgo(theSourceShape, theStartPoint, theEndPoint);
427
428     if (!aTranslationAlgo.check()) {
429       throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
430     }
431
432     aTranslationAlgo.build();
433
434     if(!aTranslationAlgo.isDone()) {
435       throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
436     }
437
438     return aTranslationAlgo.shape();
439   }
440
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)
446   {
447     GeomAlgoAPI_Rotation aRotationAlgo(theSourceShape, theAxis, theAngle);
448
449     if (!aRotationAlgo.check()) {
450       throw GeomAlgoAPI_Exception(aRotationAlgo.getError());
451     }
452
453     aRotationAlgo.build();
454
455     if(!aRotationAlgo.isDone()) {
456       throw GeomAlgoAPI_Exception(aRotationAlgo.getError());
457     }
458
459     return aRotationAlgo.shape();
460   }
461
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)
468   {
469     GeomAlgoAPI_Rotation aRotationAlgo(theSourceShape, theCenterPoint, theStartPoint, theEndPoint);
470
471     if (!aRotationAlgo.check()) {
472       throw GeomAlgoAPI_Exception(aRotationAlgo.getError());
473     }
474
475     aRotationAlgo.build();
476
477     if(!aRotationAlgo.isDone()) {
478       throw GeomAlgoAPI_Exception(aRotationAlgo.getError());
479     }
480
481     return aRotationAlgo.shape();
482   }
483
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)
488   {
489     GeomAlgoAPI_Symmetry aSymmetryAlgo(theSourceShape, thePoint);
490
491     if (!aSymmetryAlgo.check()) {
492       throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
493     }
494
495     aSymmetryAlgo.build();
496
497     if(!aSymmetryAlgo.isDone()) {
498       throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
499     }
500
501     return aSymmetryAlgo.shape();
502   }
503
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)
508   {
509     GeomAlgoAPI_Symmetry aSymmetryAlgo(theSourceShape, theAxis);
510
511     if (!aSymmetryAlgo.check()) {
512       throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
513     }
514
515     aSymmetryAlgo.build();
516
517     if(!aSymmetryAlgo.isDone()) {
518       throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
519     }
520
521     return aSymmetryAlgo.shape();
522   }
523
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)
528   {
529     GeomAlgoAPI_Symmetry aSymmetryAlgo(theSourceShape, thePlane);
530
531     if (!aSymmetryAlgo.check()) {
532       throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
533     }
534
535     aSymmetryAlgo.build();
536
537     if(!aSymmetryAlgo.isDone()) {
538       throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
539     }
540
541     return aSymmetryAlgo.shape();
542   }
543
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)
549   {
550     GeomAlgoAPI_Scale aScaleAlgo(theSourceShape, theCenterPoint, theScaleFactor);
551
552     if (!aScaleAlgo.check()) {
553       throw GeomAlgoAPI_Exception(aScaleAlgo.getError());
554     }
555
556     aScaleAlgo.build();
557
558     if(!aScaleAlgo.isDone()) {
559       throw GeomAlgoAPI_Exception(aScaleAlgo.getError());
560     }
561
562     return aScaleAlgo.shape();
563   }
564
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)
572   {
573     GeomAlgoAPI_Scale aScaleAlgo(theSourceShape, theCenterPoint,
574                                  theScaleFactorX, theScaleFactorY, theScaleFactorZ);
575
576     if (!aScaleAlgo.check()) {
577       throw GeomAlgoAPI_Exception(aScaleAlgo.getError());
578     }
579
580     aScaleAlgo.build();
581
582     if(!aScaleAlgo.isDone()) {
583       throw GeomAlgoAPI_Exception(aScaleAlgo.getError());
584     }
585
586     return aScaleAlgo.shape();
587   }
588
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)
595   {
596     if (theNumber <=0) {
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);
600     }
601
602     if (!theAxis) {
603       std::string aError = "Multitranslation builder ";
604       aError+=":: the first axis is not valid";
605       throw GeomAlgoAPI_Exception(aError);
606     }
607
608     ListOfShape aListOfShape;
609     for (int i=0; i<theNumber; i++) {
610       aListOfShape.
611         push_back(GeomAlgoAPI_ShapeAPI::makeTranslation(theSourceShape, theAxis, i*theStep));
612     }
613     return GeomAlgoAPI_CompoundBuilder::compound(aListOfShape);
614   }
615
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)
625   {
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);
630     }
631
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);
636     }
637
638     if (!theFirstAxis) {
639       std::string aError = "Multitranslation builder ";
640       aError+=":: the first axis is not valid";
641       throw GeomAlgoAPI_Exception(aError);
642     }
643
644     if (!theSecondAxis) {
645       std::string aError = "Multitranslation builder ";
646       aError+=":: the second axis is not valid";
647       throw GeomAlgoAPI_Exception(aError);
648     }
649
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);
655
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);
661
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));
669       }
670     }
671     return GeomAlgoAPI_CompoundBuilder::compound(aListOfShape);
672   }
673
674   //===============================================================================================
675   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeConeSegment(
676     const double theRMin1, const double theRMax1,
677     const double theRMin2, const double theRMax2,
678     const double theZ,
679     const double theStartPhi, const double theDeltaPhi) throw (GeomAlgoAPI_Exception)
680   {
681     GeomAlgoAPI_ConeSegment aConeSegmentAlgo(theRMin1, theRMax1, theRMin2, theRMax2,
682                                              theZ, theStartPhi, theDeltaPhi);
683
684     if (!aConeSegmentAlgo.check()) {
685       throw GeomAlgoAPI_Exception(aConeSegmentAlgo.getError());
686     }
687
688     aConeSegmentAlgo.build();
689
690     if(!aConeSegmentAlgo.isDone()) {
691       throw GeomAlgoAPI_Exception(aConeSegmentAlgo.getError());
692     }
693     if (!aConeSegmentAlgo.checkValid("Cone Segment builder")) {
694       throw GeomAlgoAPI_Exception(aConeSegmentAlgo.getError());
695     }
696     return aConeSegmentAlgo.shape();
697   }
698 }