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_Symmetry.h>
14 #include <GeomAlgoAPI_Translation.h>
16 #include <GeomAPI_Lin.h>
18 namespace GeomAlgoAPI_ShapeAPI
20 //===============================================================================================
21 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeBox(
22 const double theDx, const double theDy,
23 const double theDz) throw (GeomAlgoAPI_Exception)
25 GeomAlgoAPI_Box aBoxAlgo(theDx,theDy,theDz);
27 if (!aBoxAlgo.check()) {
28 throw GeomAlgoAPI_Exception(aBoxAlgo.getError());
33 if(!aBoxAlgo.isDone()) {
34 throw GeomAlgoAPI_Exception(aBoxAlgo.getError());
36 if (!aBoxAlgo.checkValid("Box builder with dimensions")) {
37 throw GeomAlgoAPI_Exception(aBoxAlgo.getError());
39 return aBoxAlgo.shape();
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)
47 GeomAlgoAPI_Box aBoxAlgo(theFirstPoint, theSecondPoint);
49 if (!aBoxAlgo.check()) {
50 throw GeomAlgoAPI_Exception(aBoxAlgo.getError());
55 if(!aBoxAlgo.isDone()) {
56 throw GeomAlgoAPI_Exception(aBoxAlgo.getError());
58 if (!aBoxAlgo.checkValid("Box builder with two points")) {
59 throw GeomAlgoAPI_Exception(aBoxAlgo.getError());
61 return aBoxAlgo.shape();
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)
69 std::shared_ptr<GeomAPI_Ax2> anAxis;
70 anAxis = std::shared_ptr<GeomAPI_Ax2>(new GeomAPI_Ax2(theBasePoint,
71 theEdge->line()->direction()));
73 GeomAlgoAPI_Cylinder aCylinderAlgo(anAxis, theRadius, theHeight);
75 if (!aCylinderAlgo.check()) {
76 throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
79 aCylinderAlgo.build();
81 if(!aCylinderAlgo.isDone()) {
82 throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
84 if (!aCylinderAlgo.checkValid("Cylinder builder")) {
85 throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
87 return aCylinderAlgo.shape();
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)
95 std::shared_ptr<GeomAPI_Ax2> anAxis;
96 anAxis = std::shared_ptr<GeomAPI_Ax2>(new GeomAPI_Ax2(theBasePoint,
97 theEdge->line()->direction()));
99 GeomAlgoAPI_Cylinder aCylinderAlgo(anAxis, theRadius, theHeight, theAngle);
101 if (!aCylinderAlgo.check()) {
102 throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
105 aCylinderAlgo.build();
107 if(!aCylinderAlgo.isDone()) {
108 throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
110 if (!aCylinderAlgo.checkValid("Cylinder portion builder")) {
111 throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
113 return aCylinderAlgo.shape();
116 //===============================================================================================
117 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeCylinder(
118 double theRadius, double theHeight) throw (GeomAlgoAPI_Exception)
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()));
127 GeomAlgoAPI_Cylinder aCylinderAlgo(anAxis, theRadius, theHeight);
129 if (!aCylinderAlgo.check()) {
130 throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
133 aCylinderAlgo.build();
135 if(!aCylinderAlgo.isDone()) {
136 throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
138 if (!aCylinderAlgo.checkValid("Cylinder builder")) {
139 throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
141 return aCylinderAlgo.shape();
144 //===============================================================================================
145 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeCylinder(
146 double theRadius, double theHeight, double theAngle) throw (GeomAlgoAPI_Exception)
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()));
155 GeomAlgoAPI_Cylinder aCylinderAlgo(anAxis, theRadius, theHeight, theAngle);
157 if (!aCylinderAlgo.check()) {
158 throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
161 aCylinderAlgo.build();
163 if(!aCylinderAlgo.isDone()) {
164 throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
166 if (!aCylinderAlgo.checkValid("Cylinder portion builder")) {
167 throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
169 return aCylinderAlgo.shape();
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)
178 GeomAlgoAPI_Translation aTranslationAlgo(theSourceShape, theAxis, theDistance);
180 if (!aTranslationAlgo.check()) {
181 throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
184 aTranslationAlgo.build();
186 if(!aTranslationAlgo.isDone()) {
187 throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
189 if (!aTranslationAlgo.checkValid("Translation builder with axis and distance")) {
190 throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
192 return aTranslationAlgo.shape();
195 //===============================================================================================
196 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeTranslation(
197 std::shared_ptr<GeomAPI_Shape> theSourceShape,
200 const double theDz) throw (GeomAlgoAPI_Exception)
202 GeomAlgoAPI_Translation aTranslationAlgo(theSourceShape, theDx, theDy, theDz);
204 if (!aTranslationAlgo.check()) {
205 throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
208 aTranslationAlgo.build();
210 if(!aTranslationAlgo.isDone()) {
211 throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
213 if (!aTranslationAlgo.checkValid("Translation builder with dimensions")) {
214 throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
216 return aTranslationAlgo.shape();
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)
225 GeomAlgoAPI_Translation aTranslationAlgo(theSourceShape, theStartPoint, theEndPoint);
227 if (!aTranslationAlgo.check()) {
228 throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
231 aTranslationAlgo.build();
233 if(!aTranslationAlgo.isDone()) {
234 throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
236 if (!aTranslationAlgo.checkValid("Translation builder with two points")) {
237 throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
239 return aTranslationAlgo.shape();
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)
247 GeomAlgoAPI_Symmetry aSymmetryAlgo(theSourceShape, thePoint);
249 if (!aSymmetryAlgo.check()) {
250 throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
253 aSymmetryAlgo.build();
255 if(!aSymmetryAlgo.isDone()) {
256 throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
258 if (!aSymmetryAlgo.checkValid("Symmetry builder by a point")) {
259 throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
261 return aSymmetryAlgo.shape();
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)
269 GeomAlgoAPI_Symmetry aSymmetryAlgo(theSourceShape, theAxis);
271 if (!aSymmetryAlgo.check()) {
272 throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
275 aSymmetryAlgo.build();
277 if(!aSymmetryAlgo.isDone()) {
278 throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
280 if (!aSymmetryAlgo.checkValid("Symmetry builder by an axis")) {
281 throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
283 return aSymmetryAlgo.shape();
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)
291 GeomAlgoAPI_Symmetry aSymmetryAlgo(theSourceShape, thePlane);
293 if (!aSymmetryAlgo.check()) {
294 throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
297 aSymmetryAlgo.build();
299 if(!aSymmetryAlgo.isDone()) {
300 throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
302 if (!aSymmetryAlgo.checkValid("Symmetry builder by a plane")) {
303 throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
305 return aSymmetryAlgo.shape();
308 //===============================================================================================
309 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeConeSegment(
310 const double theRMin1, const double theRMax1,
311 const double theRMin2, const double theRMax2,
313 const double theStartPhi, const double theDeltaPhi) throw (GeomAlgoAPI_Exception)
315 GeomAlgoAPI_ConeSegment aConeSegmentAlgo(theRMin1, theRMax1, theRMin2, theRMax2,
316 theZ, theStartPhi, theDeltaPhi);
318 if (!aConeSegmentAlgo.check()) {
319 throw GeomAlgoAPI_Exception(aConeSegmentAlgo.getError());
322 aConeSegmentAlgo.build();
324 if(!aConeSegmentAlgo.isDone()) {
325 throw GeomAlgoAPI_Exception(aConeSegmentAlgo.getError());
327 if (!aConeSegmentAlgo.checkValid("Cone Segment builder")) {
328 throw GeomAlgoAPI_Exception(aConeSegmentAlgo.getError());
330 return aConeSegmentAlgo.shape();