Salome HOME
Remove trailing whitespaces
[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_ConeSegment.h>
11 #include <GeomAlgoAPI_EdgeBuilder.h>
12 #include <GeomAlgoAPI_Symmetry.h>
13 #include <GeomAlgoAPI_Translation.h>
14
15 namespace GeomAlgoAPI_ShapeAPI
16 {
17   //=======================================================================================
18   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeBox(
19     const double theDx, const double theDy,
20     const double theDz) throw (GeomAlgoAPI_Exception)
21   {
22     GeomAlgoAPI_Box aBoxAlgo(theDx,theDy,theDz);
23
24     if (!aBoxAlgo.check()) {
25       throw GeomAlgoAPI_Exception(aBoxAlgo.getError());
26     }
27
28     aBoxAlgo.build();
29
30     if(!aBoxAlgo.isDone()) {
31       throw GeomAlgoAPI_Exception(aBoxAlgo.getError());
32     }
33     if (!aBoxAlgo.checkValid("Box builder with dimensions")) {
34       throw GeomAlgoAPI_Exception(aBoxAlgo.getError());
35     }
36     return aBoxAlgo.shape();
37   }
38
39   //======================================================================================
40   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeBox(
41     std::shared_ptr<GeomAPI_Pnt> theFirstPoint,
42     std::shared_ptr<GeomAPI_Pnt> theSecondPoint) throw (GeomAlgoAPI_Exception)
43   {
44     GeomAlgoAPI_Box aBoxAlgo(theFirstPoint, theSecondPoint);
45
46     if (!aBoxAlgo.check()) {
47       throw GeomAlgoAPI_Exception(aBoxAlgo.getError());
48     }
49
50     aBoxAlgo.build();
51
52     if(!aBoxAlgo.isDone()) {
53       throw GeomAlgoAPI_Exception(aBoxAlgo.getError());
54     }
55     if (!aBoxAlgo.checkValid("Box builder with two points")) {
56       throw GeomAlgoAPI_Exception(aBoxAlgo.getError());
57     }
58     return aBoxAlgo.shape();
59   }
60
61   //=========================================================================================================
62   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeTranslation(
63     std::shared_ptr<GeomAPI_Shape> theSourceShape,
64     std::shared_ptr<GeomAPI_Ax1>   theAxis,
65     const double theDistance) throw (GeomAlgoAPI_Exception)
66   {
67     GeomAlgoAPI_Translation aTranslationAlgo(theSourceShape, theAxis, theDistance);
68
69     if (!aTranslationAlgo.check()) {
70       throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
71     }
72
73     aTranslationAlgo.build();
74
75     if(!aTranslationAlgo.isDone()) {
76       throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
77     }
78     if (!aTranslationAlgo.checkValid("Translation builder with axis and distance")) {
79       throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
80     }
81     return aTranslationAlgo.shape();
82   }
83
84   //=========================================================================================================
85   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeTranslation(
86     std::shared_ptr<GeomAPI_Shape> theSourceShape,
87     const double theDx,
88     const double theDy,
89     const double theDz) throw (GeomAlgoAPI_Exception)
90   {
91     GeomAlgoAPI_Translation aTranslationAlgo(theSourceShape, theDx, theDy, theDz);
92
93     if (!aTranslationAlgo.check()) {
94       throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
95     }
96
97     aTranslationAlgo.build();
98
99     if(!aTranslationAlgo.isDone()) {
100       throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
101     }
102     if (!aTranslationAlgo.checkValid("Translation builder with dimensions")) {
103       throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
104     }
105     return aTranslationAlgo.shape();
106   }
107
108   //=========================================================================================================
109   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeTranslation(
110     std::shared_ptr<GeomAPI_Shape> theSourceShape,
111     std::shared_ptr<GeomAPI_Pnt>   theStartPoint,
112     std::shared_ptr<GeomAPI_Pnt>   theEndPoint) throw (GeomAlgoAPI_Exception)
113   {
114     GeomAlgoAPI_Translation aTranslationAlgo(theSourceShape, theStartPoint, theEndPoint);
115
116     if (!aTranslationAlgo.check()) {
117       throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
118     }
119
120     aTranslationAlgo.build();
121
122     if(!aTranslationAlgo.isDone()) {
123       throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
124     }
125     if (!aTranslationAlgo.checkValid("Translation builder with two points")) {
126       throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
127     }
128     return aTranslationAlgo.shape();
129   }
130
131   //=========================================================================================================
132   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeSymmetry(
133     std::shared_ptr<GeomAPI_Shape> theSourceShape,
134     std::shared_ptr<GeomAPI_Pnt>   thePoint) throw (GeomAlgoAPI_Exception)
135   {
136     GeomAlgoAPI_Symmetry aSymmetryAlgo(theSourceShape, thePoint);
137
138     if (!aSymmetryAlgo.check()) {
139       throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
140     }
141
142     aSymmetryAlgo.build();
143
144     if(!aSymmetryAlgo.isDone()) {
145       throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
146     }
147     if (!aSymmetryAlgo.checkValid("Symmetry builder by a point")) {
148       throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
149     }
150     return aSymmetryAlgo.shape();
151   }
152
153   //=========================================================================================================
154   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeSymmetry(
155     std::shared_ptr<GeomAPI_Shape> theSourceShape,
156     std::shared_ptr<GeomAPI_Ax1>   theAxis) throw (GeomAlgoAPI_Exception)
157   {
158     GeomAlgoAPI_Symmetry aSymmetryAlgo(theSourceShape, theAxis);
159
160     if (!aSymmetryAlgo.check()) {
161       throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
162     }
163
164     aSymmetryAlgo.build();
165
166     if(!aSymmetryAlgo.isDone()) {
167       throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
168     }
169     if (!aSymmetryAlgo.checkValid("Symmetry builder by an axis")) {
170       throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
171     }
172     return aSymmetryAlgo.shape();
173   }
174
175   //=========================================================================================================
176   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeSymmetry(
177     std::shared_ptr<GeomAPI_Shape> theSourceShape,
178     std::shared_ptr<GeomAPI_Ax2>   thePlane) throw (GeomAlgoAPI_Exception)
179   {
180     GeomAlgoAPI_Symmetry aSymmetryAlgo(theSourceShape, thePlane);
181
182     if (!aSymmetryAlgo.check()) {
183       throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
184     }
185
186     aSymmetryAlgo.build();
187
188     if(!aSymmetryAlgo.isDone()) {
189       throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
190     }
191     if (!aSymmetryAlgo.checkValid("Symmetry builder by a plane")) {
192       throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
193     }
194     return aSymmetryAlgo.shape();
195   }
196
197   //=========================================================================================================
198   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeConeSegment(
199     const double theRMin1, const double theRMax1,
200     const double theRMin2, const double theRMax2,
201     const double theZ,
202     const double theStartPhi, const double theDeltaPhi) throw (GeomAlgoAPI_Exception)
203   {
204     GeomAlgoAPI_ConeSegment aConeSegmentAlgo(theRMin1, theRMax1, theRMin2, theRMax2,
205                                              theZ, theStartPhi, theDeltaPhi);
206
207     if (!aConeSegmentAlgo.check()) {
208       throw GeomAlgoAPI_Exception(aConeSegmentAlgo.getError());
209     }
210
211     aConeSegmentAlgo.build();
212
213     if(!aConeSegmentAlgo.isDone()) {
214       throw GeomAlgoAPI_Exception(aConeSegmentAlgo.getError());
215     }
216     if (!aConeSegmentAlgo.checkValid("Cone Segment builder")) {
217       throw GeomAlgoAPI_Exception(aConeSegmentAlgo.getError());
218     }
219     return aConeSegmentAlgo.shape();
220   }
221 }