Salome HOME
Deleting the option of "Scale" feature from dimensions in X, in Y and in Z.
[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_Cylinder.h>
11 #include <GeomAlgoAPI_ConeSegment.h>
12 #include <GeomAlgoAPI_EdgeBuilder.h>
13 #include <GeomAlgoAPI_Scale.h>
14 #include <GeomAlgoAPI_Symmetry.h>
15 #include <GeomAlgoAPI_Translation.h>
16
17 #include <GeomAPI_Lin.h>
18
19 namespace GeomAlgoAPI_ShapeAPI
20 {
21   //===============================================================================================
22   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeBox(
23     const double theDx, const double theDy,
24     const double theDz) throw (GeomAlgoAPI_Exception)
25   {
26     GeomAlgoAPI_Box aBoxAlgo(theDx,theDy,theDz);
27
28     if (!aBoxAlgo.check()) {
29       throw GeomAlgoAPI_Exception(aBoxAlgo.getError());
30     }
31
32     aBoxAlgo.build();
33
34     if(!aBoxAlgo.isDone()) {
35       throw GeomAlgoAPI_Exception(aBoxAlgo.getError());
36     }
37     if (!aBoxAlgo.checkValid("Box builder with dimensions")) {
38       throw GeomAlgoAPI_Exception(aBoxAlgo.getError());
39     }
40     return aBoxAlgo.shape();
41   }
42
43   //===============================================================================================
44   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeBox(
45     std::shared_ptr<GeomAPI_Pnt> theFirstPoint,
46     std::shared_ptr<GeomAPI_Pnt> theSecondPoint) throw (GeomAlgoAPI_Exception)
47   {
48     GeomAlgoAPI_Box aBoxAlgo(theFirstPoint, theSecondPoint);
49
50     if (!aBoxAlgo.check()) {
51       throw GeomAlgoAPI_Exception(aBoxAlgo.getError());
52     }
53
54     aBoxAlgo.build();
55
56     if(!aBoxAlgo.isDone()) {
57       throw GeomAlgoAPI_Exception(aBoxAlgo.getError());
58     }
59     if (!aBoxAlgo.checkValid("Box builder with two points")) {
60       throw GeomAlgoAPI_Exception(aBoxAlgo.getError());
61     }
62     return aBoxAlgo.shape();
63   }
64
65   //===============================================================================================
66   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeCylinder(
67     std::shared_ptr<GeomAPI_Pnt> theBasePoint, std::shared_ptr<GeomAPI_Edge> theEdge,
68     double theRadius, double theHeight) throw (GeomAlgoAPI_Exception)
69   {
70     std::shared_ptr<GeomAPI_Ax2> anAxis;
71     anAxis = std::shared_ptr<GeomAPI_Ax2>(new GeomAPI_Ax2(theBasePoint,
72                                                           theEdge->line()->direction()));
73
74     GeomAlgoAPI_Cylinder aCylinderAlgo(anAxis, theRadius, theHeight);
75
76     if (!aCylinderAlgo.check()) {
77       throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
78     }
79
80     aCylinderAlgo.build();
81
82     if(!aCylinderAlgo.isDone()) {
83       throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
84     }
85     if (!aCylinderAlgo.checkValid("Cylinder builder")) {
86       throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
87     }
88     return aCylinderAlgo.shape();
89   }
90
91   //===============================================================================================
92   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeCylinder(
93     std::shared_ptr<GeomAPI_Pnt> theBasePoint, std::shared_ptr<GeomAPI_Edge> theEdge,
94     double theRadius, double theHeight, double theAngle) throw (GeomAlgoAPI_Exception)
95   {
96     std::shared_ptr<GeomAPI_Ax2> anAxis;
97     anAxis = std::shared_ptr<GeomAPI_Ax2>(new GeomAPI_Ax2(theBasePoint,
98                                                           theEdge->line()->direction()));
99
100     GeomAlgoAPI_Cylinder aCylinderAlgo(anAxis, theRadius, theHeight, theAngle);
101
102     if (!aCylinderAlgo.check()) {
103       throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
104     }
105
106     aCylinderAlgo.build();
107
108     if(!aCylinderAlgo.isDone()) {
109       throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
110     }
111     if (!aCylinderAlgo.checkValid("Cylinder portion builder")) {
112       throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
113     }
114     return aCylinderAlgo.shape();
115   }
116
117   //===============================================================================================
118   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeCylinder(
119     double theRadius, double theHeight) throw (GeomAlgoAPI_Exception)
120   {
121     std::shared_ptr<GeomAPI_Pnt> aBasePoint =
122       std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(0.,0.,0.));
123     std::shared_ptr<GeomAPI_Edge> aEdge = GeomAlgoAPI_EdgeBuilder::line(0., 0., 1.);
124     std::shared_ptr<GeomAPI_Ax2> anAxis;
125     anAxis = std::shared_ptr<GeomAPI_Ax2>(new GeomAPI_Ax2(aBasePoint,
126                                                           aEdge->line()->direction()));
127
128     GeomAlgoAPI_Cylinder aCylinderAlgo(anAxis, theRadius, theHeight);
129
130     if (!aCylinderAlgo.check()) {
131       throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
132     }
133
134     aCylinderAlgo.build();
135
136     if(!aCylinderAlgo.isDone()) {
137       throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
138     }
139     if (!aCylinderAlgo.checkValid("Cylinder builder")) {
140       throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
141     }
142     return aCylinderAlgo.shape();
143   }
144
145   //===============================================================================================
146   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeCylinder(
147     double theRadius, double theHeight, double theAngle) throw (GeomAlgoAPI_Exception)
148   {
149     std::shared_ptr<GeomAPI_Pnt> aBasePoint =
150       std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(0.,0.,0.));
151     std::shared_ptr<GeomAPI_Edge> aEdge = GeomAlgoAPI_EdgeBuilder::line(0., 0., 1.);
152     std::shared_ptr<GeomAPI_Ax2> anAxis;
153     anAxis = std::shared_ptr<GeomAPI_Ax2>(new GeomAPI_Ax2(aBasePoint,
154                                                           aEdge->line()->direction()));
155
156     GeomAlgoAPI_Cylinder aCylinderAlgo(anAxis, theRadius, theHeight, theAngle);
157
158     if (!aCylinderAlgo.check()) {
159       throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
160     }
161
162     aCylinderAlgo.build();
163
164     if(!aCylinderAlgo.isDone()) {
165       throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
166     }
167     if (!aCylinderAlgo.checkValid("Cylinder portion builder")) {
168       throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
169     }
170     return aCylinderAlgo.shape();
171   }
172
173   //===============================================================================================
174   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeTranslation(
175     std::shared_ptr<GeomAPI_Shape> theSourceShape,
176     std::shared_ptr<GeomAPI_Ax1>   theAxis,
177     const double theDistance) throw (GeomAlgoAPI_Exception)
178   {
179     GeomAlgoAPI_Translation aTranslationAlgo(theSourceShape, theAxis, theDistance);
180
181     if (!aTranslationAlgo.check()) {
182       throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
183     }
184
185     aTranslationAlgo.build();
186
187     if(!aTranslationAlgo.isDone()) {
188       throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
189     }
190     if (!aTranslationAlgo.checkValid("Translation builder with axis and distance")) {
191       throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
192     }
193     return aTranslationAlgo.shape();
194   }
195
196   //===============================================================================================
197   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeTranslation(
198     std::shared_ptr<GeomAPI_Shape> theSourceShape,
199     const double theDx,
200     const double theDy,
201     const double theDz) throw (GeomAlgoAPI_Exception)
202   {
203     GeomAlgoAPI_Translation aTranslationAlgo(theSourceShape, theDx, theDy, theDz);
204
205     if (!aTranslationAlgo.check()) {
206       throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
207     }
208
209     aTranslationAlgo.build();
210
211     if(!aTranslationAlgo.isDone()) {
212       throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
213     }
214     if (!aTranslationAlgo.checkValid("Translation builder with dimensions")) {
215       throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
216     }
217     return aTranslationAlgo.shape();
218   }
219
220   //===============================================================================================
221   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeTranslation(
222     std::shared_ptr<GeomAPI_Shape> theSourceShape,
223     std::shared_ptr<GeomAPI_Pnt>   theStartPoint,
224     std::shared_ptr<GeomAPI_Pnt>   theEndPoint) throw (GeomAlgoAPI_Exception)
225   {
226     GeomAlgoAPI_Translation aTranslationAlgo(theSourceShape, theStartPoint, theEndPoint);
227
228     if (!aTranslationAlgo.check()) {
229       throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
230     }
231
232     aTranslationAlgo.build();
233
234     if(!aTranslationAlgo.isDone()) {
235       throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
236     }
237     if (!aTranslationAlgo.checkValid("Translation builder with two points")) {
238       throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
239     }
240     return aTranslationAlgo.shape();
241   }
242
243   //===============================================================================================
244   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeSymmetry(
245     std::shared_ptr<GeomAPI_Shape> theSourceShape,
246     std::shared_ptr<GeomAPI_Pnt>   thePoint) throw (GeomAlgoAPI_Exception)
247   {
248     GeomAlgoAPI_Symmetry aSymmetryAlgo(theSourceShape, thePoint);
249
250     if (!aSymmetryAlgo.check()) {
251       throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
252     }
253
254     aSymmetryAlgo.build();
255
256     if(!aSymmetryAlgo.isDone()) {
257       throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
258     }
259     if (!aSymmetryAlgo.checkValid("Symmetry builder by a point")) {
260       throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
261     }
262     return aSymmetryAlgo.shape();
263   }
264
265   //===============================================================================================
266   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeSymmetry(
267     std::shared_ptr<GeomAPI_Shape> theSourceShape,
268     std::shared_ptr<GeomAPI_Ax1>   theAxis) throw (GeomAlgoAPI_Exception)
269   {
270     GeomAlgoAPI_Symmetry aSymmetryAlgo(theSourceShape, theAxis);
271
272     if (!aSymmetryAlgo.check()) {
273       throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
274     }
275
276     aSymmetryAlgo.build();
277
278     if(!aSymmetryAlgo.isDone()) {
279       throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
280     }
281     if (!aSymmetryAlgo.checkValid("Symmetry builder by an axis")) {
282       throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
283     }
284     return aSymmetryAlgo.shape();
285   }
286
287   //===============================================================================================
288   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeSymmetry(
289     std::shared_ptr<GeomAPI_Shape> theSourceShape,
290     std::shared_ptr<GeomAPI_Ax2>   thePlane) throw (GeomAlgoAPI_Exception)
291   {
292     GeomAlgoAPI_Symmetry aSymmetryAlgo(theSourceShape, thePlane);
293
294     if (!aSymmetryAlgo.check()) {
295       throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
296     }
297
298     aSymmetryAlgo.build();
299
300     if(!aSymmetryAlgo.isDone()) {
301       throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
302     }
303     if (!aSymmetryAlgo.checkValid("Symmetry builder by a plane")) {
304       throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
305     }
306     return aSymmetryAlgo.shape();
307   }
308
309   //===============================================================================================
310   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeScale(
311     std::shared_ptr<GeomAPI_Shape> theSourceShape,
312     std::shared_ptr<GeomAPI_Pnt>   theCenterPoint,
313     const double                   theScaleFactor) throw (GeomAlgoAPI_Exception)
314   {
315     GeomAlgoAPI_Scale aScaleAlgo(theSourceShape, theCenterPoint, theScaleFactor);
316
317     if (!aScaleAlgo.check()) {
318       throw GeomAlgoAPI_Exception(aScaleAlgo.getError());
319     }
320
321     aScaleAlgo.build();
322
323     if(!aScaleAlgo.isDone()) {
324       throw GeomAlgoAPI_Exception(aScaleAlgo.getError());
325     }
326     if (!aScaleAlgo.checkValid("Scale builder by a scale factor")) {
327       throw GeomAlgoAPI_Exception(aScaleAlgo.getError());
328     }
329     return aScaleAlgo.shape();
330   }
331
332   //===============================================================================================
333   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeConeSegment(
334     const double theRMin1, const double theRMax1,
335     const double theRMin2, const double theRMax2,
336     const double theZ,
337     const double theStartPhi, const double theDeltaPhi) throw (GeomAlgoAPI_Exception)
338   {
339     GeomAlgoAPI_ConeSegment aConeSegmentAlgo(theRMin1, theRMax1, theRMin2, theRMax2,
340                                              theZ, theStartPhi, theDeltaPhi);
341
342     if (!aConeSegmentAlgo.check()) {
343       throw GeomAlgoAPI_Exception(aConeSegmentAlgo.getError());
344     }
345
346     aConeSegmentAlgo.build();
347
348     if(!aConeSegmentAlgo.isDone()) {
349       throw GeomAlgoAPI_Exception(aConeSegmentAlgo.getError());
350     }
351     if (!aConeSegmentAlgo.checkValid("Cone Segment builder")) {
352       throw GeomAlgoAPI_Exception(aConeSegmentAlgo.getError());
353     }
354     return aConeSegmentAlgo.shape();
355   }
356 }