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