1 // Copyright (C) 2014-2016 CEA/DEN, EDF R&D
3 // File: GeomAlgoAPI_ShapeAPI.cpp
4 // Created: 17 Mar 2016
5 // Author: Clarisse Genrault (CEA)
7 #include "GeomAlgoAPI_ShapeAPI.h"
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>
17 #include <GeomAPI_Lin.h>
19 namespace GeomAlgoAPI_ShapeAPI
21 //===============================================================================================
22 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeBox(
23 const double theDx, const double theDy,
24 const double theDz) throw (GeomAlgoAPI_Exception)
26 GeomAlgoAPI_Box aBoxAlgo(theDx,theDy,theDz);
28 if (!aBoxAlgo.check()) {
29 throw GeomAlgoAPI_Exception(aBoxAlgo.getError());
34 if(!aBoxAlgo.isDone()) {
35 throw GeomAlgoAPI_Exception(aBoxAlgo.getError());
37 if (!aBoxAlgo.checkValid("Box builder with dimensions")) {
38 throw GeomAlgoAPI_Exception(aBoxAlgo.getError());
40 return aBoxAlgo.shape();
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)
48 GeomAlgoAPI_Box aBoxAlgo(theFirstPoint, theSecondPoint);
50 if (!aBoxAlgo.check()) {
51 throw GeomAlgoAPI_Exception(aBoxAlgo.getError());
56 if(!aBoxAlgo.isDone()) {
57 throw GeomAlgoAPI_Exception(aBoxAlgo.getError());
59 if (!aBoxAlgo.checkValid("Box builder with two points")) {
60 throw GeomAlgoAPI_Exception(aBoxAlgo.getError());
62 return aBoxAlgo.shape();
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)
70 std::shared_ptr<GeomAPI_Ax2> anAxis;
71 anAxis = std::shared_ptr<GeomAPI_Ax2>(new GeomAPI_Ax2(theBasePoint,
72 theEdge->line()->direction()));
74 GeomAlgoAPI_Cylinder aCylinderAlgo(anAxis, theRadius, theHeight);
76 if (!aCylinderAlgo.check()) {
77 throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
80 aCylinderAlgo.build();
82 if(!aCylinderAlgo.isDone()) {
83 throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
85 if (!aCylinderAlgo.checkValid("Cylinder builder")) {
86 throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
88 return aCylinderAlgo.shape();
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)
96 std::shared_ptr<GeomAPI_Ax2> anAxis;
97 anAxis = std::shared_ptr<GeomAPI_Ax2>(new GeomAPI_Ax2(theBasePoint,
98 theEdge->line()->direction()));
100 GeomAlgoAPI_Cylinder aCylinderAlgo(anAxis, theRadius, theHeight, theAngle);
102 if (!aCylinderAlgo.check()) {
103 throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
106 aCylinderAlgo.build();
108 if(!aCylinderAlgo.isDone()) {
109 throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
111 if (!aCylinderAlgo.checkValid("Cylinder portion builder")) {
112 throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
114 return aCylinderAlgo.shape();
117 //===============================================================================================
118 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeCylinder(
119 double theRadius, double theHeight) throw (GeomAlgoAPI_Exception)
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()));
128 GeomAlgoAPI_Cylinder aCylinderAlgo(anAxis, theRadius, theHeight);
130 if (!aCylinderAlgo.check()) {
131 throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
134 aCylinderAlgo.build();
136 if(!aCylinderAlgo.isDone()) {
137 throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
139 if (!aCylinderAlgo.checkValid("Cylinder builder")) {
140 throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
142 return aCylinderAlgo.shape();
145 //===============================================================================================
146 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeCylinder(
147 double theRadius, double theHeight, double theAngle) throw (GeomAlgoAPI_Exception)
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()));
156 GeomAlgoAPI_Cylinder aCylinderAlgo(anAxis, theRadius, theHeight, theAngle);
158 if (!aCylinderAlgo.check()) {
159 throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
162 aCylinderAlgo.build();
164 if(!aCylinderAlgo.isDone()) {
165 throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
167 if (!aCylinderAlgo.checkValid("Cylinder portion builder")) {
168 throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
170 return aCylinderAlgo.shape();
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)
179 GeomAlgoAPI_Translation aTranslationAlgo(theSourceShape, theAxis, theDistance);
181 if (!aTranslationAlgo.check()) {
182 throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
185 aTranslationAlgo.build();
187 if(!aTranslationAlgo.isDone()) {
188 throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
190 if (!aTranslationAlgo.checkValid("Translation builder with axis and distance")) {
191 throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
193 return aTranslationAlgo.shape();
196 //===============================================================================================
197 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeTranslation(
198 std::shared_ptr<GeomAPI_Shape> theSourceShape,
201 const double theDz) throw (GeomAlgoAPI_Exception)
203 GeomAlgoAPI_Translation aTranslationAlgo(theSourceShape, theDx, theDy, theDz);
205 if (!aTranslationAlgo.check()) {
206 throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
209 aTranslationAlgo.build();
211 if(!aTranslationAlgo.isDone()) {
212 throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
214 if (!aTranslationAlgo.checkValid("Translation builder with dimensions")) {
215 throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
217 return aTranslationAlgo.shape();
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)
226 GeomAlgoAPI_Translation aTranslationAlgo(theSourceShape, theStartPoint, theEndPoint);
228 if (!aTranslationAlgo.check()) {
229 throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
232 aTranslationAlgo.build();
234 if(!aTranslationAlgo.isDone()) {
235 throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
237 if (!aTranslationAlgo.checkValid("Translation builder with two points")) {
238 throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
240 return aTranslationAlgo.shape();
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)
248 GeomAlgoAPI_Symmetry aSymmetryAlgo(theSourceShape, thePoint);
250 if (!aSymmetryAlgo.check()) {
251 throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
254 aSymmetryAlgo.build();
256 if(!aSymmetryAlgo.isDone()) {
257 throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
259 if (!aSymmetryAlgo.checkValid("Symmetry builder by a point")) {
260 throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
262 return aSymmetryAlgo.shape();
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)
270 GeomAlgoAPI_Symmetry aSymmetryAlgo(theSourceShape, theAxis);
272 if (!aSymmetryAlgo.check()) {
273 throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
276 aSymmetryAlgo.build();
278 if(!aSymmetryAlgo.isDone()) {
279 throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
281 if (!aSymmetryAlgo.checkValid("Symmetry builder by an axis")) {
282 throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
284 return aSymmetryAlgo.shape();
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)
292 GeomAlgoAPI_Symmetry aSymmetryAlgo(theSourceShape, thePlane);
294 if (!aSymmetryAlgo.check()) {
295 throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
298 aSymmetryAlgo.build();
300 if(!aSymmetryAlgo.isDone()) {
301 throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
303 if (!aSymmetryAlgo.checkValid("Symmetry builder by a plane")) {
304 throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
306 return aSymmetryAlgo.shape();
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)
315 GeomAlgoAPI_Scale aScaleAlgo(theSourceShape, theCenterPoint, theScaleFactor);
317 if (!aScaleAlgo.check()) {
318 throw GeomAlgoAPI_Exception(aScaleAlgo.getError());
323 if(!aScaleAlgo.isDone()) {
324 throw GeomAlgoAPI_Exception(aScaleAlgo.getError());
326 if (!aScaleAlgo.checkValid("Scale builder by a scale factor")) {
327 throw GeomAlgoAPI_Exception(aScaleAlgo.getError());
329 return aScaleAlgo.shape();
332 //===============================================================================================
333 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeConeSegment(
334 const double theRMin1, const double theRMax1,
335 const double theRMin2, const double theRMax2,
337 const double theStartPhi, const double theDeltaPhi) throw (GeomAlgoAPI_Exception)
339 GeomAlgoAPI_ConeSegment aConeSegmentAlgo(theRMin1, theRMax1, theRMin2, theRMax2,
340 theZ, theStartPhi, theDeltaPhi);
342 if (!aConeSegmentAlgo.check()) {
343 throw GeomAlgoAPI_Exception(aConeSegmentAlgo.getError());
346 aConeSegmentAlgo.build();
348 if(!aConeSegmentAlgo.isDone()) {
349 throw GeomAlgoAPI_Exception(aConeSegmentAlgo.getError());
351 if (!aConeSegmentAlgo.checkValid("Cone Segment builder")) {
352 throw GeomAlgoAPI_Exception(aConeSegmentAlgo.getError());
354 return aConeSegmentAlgo.shape();