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_CompoundBuilder.h>
12 #include <GeomAlgoAPI_ConeSegment.h>
13 #include <GeomAlgoAPI_EdgeBuilder.h>
14 #include <GeomAlgoAPI_Scale.h>
15 #include <GeomAlgoAPI_Symmetry.h>
16 #include <GeomAlgoAPI_Translation.h>
18 #include <GeomAPI_Lin.h>
22 namespace GeomAlgoAPI_ShapeAPI
24 //===============================================================================================
25 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeBox(
26 const double theDx, const double theDy,
27 const double theDz) throw (GeomAlgoAPI_Exception)
29 GeomAlgoAPI_Box aBoxAlgo(theDx,theDy,theDz);
31 if (!aBoxAlgo.check()) {
32 throw GeomAlgoAPI_Exception(aBoxAlgo.getError());
37 if(!aBoxAlgo.isDone()) {
38 throw GeomAlgoAPI_Exception(aBoxAlgo.getError());
40 if (!aBoxAlgo.checkValid("Box builder with dimensions")) {
41 throw GeomAlgoAPI_Exception(aBoxAlgo.getError());
43 return aBoxAlgo.shape();
46 //===============================================================================================
47 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeBox(
48 std::shared_ptr<GeomAPI_Pnt> theFirstPoint,
49 std::shared_ptr<GeomAPI_Pnt> theSecondPoint) throw (GeomAlgoAPI_Exception)
51 GeomAlgoAPI_Box aBoxAlgo(theFirstPoint, theSecondPoint);
53 if (!aBoxAlgo.check()) {
54 throw GeomAlgoAPI_Exception(aBoxAlgo.getError());
59 if(!aBoxAlgo.isDone()) {
60 throw GeomAlgoAPI_Exception(aBoxAlgo.getError());
62 if (!aBoxAlgo.checkValid("Box builder with two points")) {
63 throw GeomAlgoAPI_Exception(aBoxAlgo.getError());
65 return aBoxAlgo.shape();
68 //===============================================================================================
69 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeCylinder(
70 std::shared_ptr<GeomAPI_Pnt> theBasePoint, std::shared_ptr<GeomAPI_Edge> theEdge,
71 double theRadius, double theHeight) throw (GeomAlgoAPI_Exception)
73 std::shared_ptr<GeomAPI_Ax2> anAxis;
74 anAxis = std::shared_ptr<GeomAPI_Ax2>(new GeomAPI_Ax2(theBasePoint,
75 theEdge->line()->direction()));
77 GeomAlgoAPI_Cylinder aCylinderAlgo(anAxis, theRadius, theHeight);
79 if (!aCylinderAlgo.check()) {
80 throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
83 aCylinderAlgo.build();
85 if(!aCylinderAlgo.isDone()) {
86 throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
88 if (!aCylinderAlgo.checkValid("Cylinder builder")) {
89 throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
91 return aCylinderAlgo.shape();
94 //===============================================================================================
95 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeCylinder(
96 std::shared_ptr<GeomAPI_Pnt> theBasePoint, std::shared_ptr<GeomAPI_Edge> theEdge,
97 double theRadius, double theHeight, double theAngle) throw (GeomAlgoAPI_Exception)
99 std::shared_ptr<GeomAPI_Ax2> anAxis;
100 anAxis = std::shared_ptr<GeomAPI_Ax2>(new GeomAPI_Ax2(theBasePoint,
101 theEdge->line()->direction()));
103 GeomAlgoAPI_Cylinder aCylinderAlgo(anAxis, theRadius, theHeight, theAngle);
105 if (!aCylinderAlgo.check()) {
106 throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
109 aCylinderAlgo.build();
111 if(!aCylinderAlgo.isDone()) {
112 throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
114 if (!aCylinderAlgo.checkValid("Cylinder portion builder")) {
115 throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
117 return aCylinderAlgo.shape();
120 //===============================================================================================
121 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeCylinder(
122 double theRadius, double theHeight) throw (GeomAlgoAPI_Exception)
124 std::shared_ptr<GeomAPI_Pnt> aBasePoint =
125 std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(0.,0.,0.));
126 std::shared_ptr<GeomAPI_Edge> aEdge = GeomAlgoAPI_EdgeBuilder::line(0., 0., 1.);
127 std::shared_ptr<GeomAPI_Ax2> anAxis;
128 anAxis = std::shared_ptr<GeomAPI_Ax2>(new GeomAPI_Ax2(aBasePoint,
129 aEdge->line()->direction()));
131 GeomAlgoAPI_Cylinder aCylinderAlgo(anAxis, theRadius, theHeight);
133 if (!aCylinderAlgo.check()) {
134 throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
137 aCylinderAlgo.build();
139 if(!aCylinderAlgo.isDone()) {
140 throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
142 if (!aCylinderAlgo.checkValid("Cylinder builder")) {
143 throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
145 return aCylinderAlgo.shape();
148 //===============================================================================================
149 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeCylinder(
150 double theRadius, double theHeight, double theAngle) throw (GeomAlgoAPI_Exception)
152 std::shared_ptr<GeomAPI_Pnt> aBasePoint =
153 std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(0.,0.,0.));
154 std::shared_ptr<GeomAPI_Edge> aEdge = GeomAlgoAPI_EdgeBuilder::line(0., 0., 1.);
155 std::shared_ptr<GeomAPI_Ax2> anAxis;
156 anAxis = std::shared_ptr<GeomAPI_Ax2>(new GeomAPI_Ax2(aBasePoint,
157 aEdge->line()->direction()));
159 GeomAlgoAPI_Cylinder aCylinderAlgo(anAxis, theRadius, theHeight, theAngle);
161 if (!aCylinderAlgo.check()) {
162 throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
165 aCylinderAlgo.build();
167 if(!aCylinderAlgo.isDone()) {
168 throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
170 if (!aCylinderAlgo.checkValid("Cylinder portion builder")) {
171 throw GeomAlgoAPI_Exception(aCylinderAlgo.getError());
173 return aCylinderAlgo.shape();
176 //===============================================================================================
177 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeTranslation(
178 std::shared_ptr<GeomAPI_Shape> theSourceShape,
179 std::shared_ptr<GeomAPI_Ax1> theAxis,
180 const double theDistance) throw (GeomAlgoAPI_Exception)
182 GeomAlgoAPI_Translation aTranslationAlgo(theSourceShape, theAxis, theDistance);
184 if (!aTranslationAlgo.check()) {
185 throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
188 aTranslationAlgo.build();
190 if(!aTranslationAlgo.isDone()) {
191 throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
193 if (!aTranslationAlgo.checkValid("Translation builder with axis and distance")) {
194 throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
196 return aTranslationAlgo.shape();
199 //===============================================================================================
200 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeTranslation(
201 std::shared_ptr<GeomAPI_Shape> theSourceShape,
204 const double theDz) throw (GeomAlgoAPI_Exception)
206 GeomAlgoAPI_Translation aTranslationAlgo(theSourceShape, theDx, theDy, theDz);
208 if (!aTranslationAlgo.check()) {
209 throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
212 aTranslationAlgo.build();
214 if(!aTranslationAlgo.isDone()) {
215 throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
217 if (!aTranslationAlgo.checkValid("Translation builder with dimensions")) {
218 throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
220 return aTranslationAlgo.shape();
223 //===============================================================================================
224 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeTranslation(
225 std::shared_ptr<GeomAPI_Shape> theSourceShape,
226 std::shared_ptr<GeomAPI_Pnt> theStartPoint,
227 std::shared_ptr<GeomAPI_Pnt> theEndPoint) throw (GeomAlgoAPI_Exception)
229 GeomAlgoAPI_Translation aTranslationAlgo(theSourceShape, theStartPoint, theEndPoint);
231 if (!aTranslationAlgo.check()) {
232 throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
235 aTranslationAlgo.build();
237 if(!aTranslationAlgo.isDone()) {
238 throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
240 if (!aTranslationAlgo.checkValid("Translation builder with two points")) {
241 throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
243 return aTranslationAlgo.shape();
246 //===============================================================================================
247 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeSymmetry(
248 std::shared_ptr<GeomAPI_Shape> theSourceShape,
249 std::shared_ptr<GeomAPI_Pnt> thePoint) throw (GeomAlgoAPI_Exception)
251 GeomAlgoAPI_Symmetry aSymmetryAlgo(theSourceShape, thePoint);
253 if (!aSymmetryAlgo.check()) {
254 throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
257 aSymmetryAlgo.build();
259 if(!aSymmetryAlgo.isDone()) {
260 throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
262 if (!aSymmetryAlgo.checkValid("Symmetry builder by a point")) {
263 throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
265 return aSymmetryAlgo.shape();
268 //===============================================================================================
269 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeSymmetry(
270 std::shared_ptr<GeomAPI_Shape> theSourceShape,
271 std::shared_ptr<GeomAPI_Ax1> theAxis) throw (GeomAlgoAPI_Exception)
273 GeomAlgoAPI_Symmetry aSymmetryAlgo(theSourceShape, theAxis);
275 if (!aSymmetryAlgo.check()) {
276 throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
279 aSymmetryAlgo.build();
281 if(!aSymmetryAlgo.isDone()) {
282 throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
284 if (!aSymmetryAlgo.checkValid("Symmetry builder by an axis")) {
285 throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
287 return aSymmetryAlgo.shape();
290 //===============================================================================================
291 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeSymmetry(
292 std::shared_ptr<GeomAPI_Shape> theSourceShape,
293 std::shared_ptr<GeomAPI_Ax2> thePlane) throw (GeomAlgoAPI_Exception)
295 GeomAlgoAPI_Symmetry aSymmetryAlgo(theSourceShape, thePlane);
297 if (!aSymmetryAlgo.check()) {
298 throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
301 aSymmetryAlgo.build();
303 if(!aSymmetryAlgo.isDone()) {
304 throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
306 if (!aSymmetryAlgo.checkValid("Symmetry builder by a plane")) {
307 throw GeomAlgoAPI_Exception(aSymmetryAlgo.getError());
309 return aSymmetryAlgo.shape();
312 //===============================================================================================
313 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeScale(
314 std::shared_ptr<GeomAPI_Shape> theSourceShape,
315 std::shared_ptr<GeomAPI_Pnt> theCenterPoint,
316 const double theScaleFactor) throw (GeomAlgoAPI_Exception)
318 GeomAlgoAPI_Scale aScaleAlgo(theSourceShape, theCenterPoint, theScaleFactor);
320 if (!aScaleAlgo.check()) {
321 throw GeomAlgoAPI_Exception(aScaleAlgo.getError());
326 if(!aScaleAlgo.isDone()) {
327 throw GeomAlgoAPI_Exception(aScaleAlgo.getError());
329 if (!aScaleAlgo.checkValid("Scale builder by a scale factor")) {
330 throw GeomAlgoAPI_Exception(aScaleAlgo.getError());
332 return aScaleAlgo.shape();
335 //===============================================================================================
336 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeScale(
337 std::shared_ptr<GeomAPI_Shape> theSourceShape,
338 std::shared_ptr<GeomAPI_Pnt> theCenterPoint,
339 const double theScaleFactorX,
340 const double theScaleFactorY,
341 const double theScaleFactorZ) throw (GeomAlgoAPI_Exception)
343 GeomAlgoAPI_Scale aScaleAlgo(theSourceShape, theCenterPoint,
344 theScaleFactorX, theScaleFactorY, theScaleFactorZ);
346 if (!aScaleAlgo.check()) {
347 throw GeomAlgoAPI_Exception(aScaleAlgo.getError());
352 if(!aScaleAlgo.isDone()) {
353 throw GeomAlgoAPI_Exception(aScaleAlgo.getError());
355 if (!aScaleAlgo.checkValid("Scale builder by dimensions")) {
356 throw GeomAlgoAPI_Exception(aScaleAlgo.getError());
358 return aScaleAlgo.shape();
361 //===============================================================================================
362 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeMultiTranslation(
363 std::shared_ptr<GeomAPI_Shape> theSourceShape,
364 std::shared_ptr<GeomAPI_Ax1> theAxis,
365 const double theStep,
366 const int theNumber) throw (GeomAlgoAPI_Exception)
368 ListOfShape aListOfShape;
369 for (int i=0; i<theNumber; i++) {
371 push_back(GeomAlgoAPI_ShapeAPI::makeTranslation(theSourceShape, theAxis, i*theStep));
373 return GeomAlgoAPI_CompoundBuilder::compound(aListOfShape);
376 //===============================================================================================
377 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeMultiTranslation(
378 std::shared_ptr<GeomAPI_Shape> theSourceShape,
379 std::shared_ptr<GeomAPI_Ax1> theFirstAxis,
380 const double theFirstStep,
381 const int theFirstNumber,
382 std::shared_ptr<GeomAPI_Ax1> theSecondAxis,
383 const double theSecondStep,
384 const int theSecondNumber) throw (GeomAlgoAPI_Exception)
386 // Coord theFirstAxis
387 double x1 = theFirstAxis->dir()->x();
388 double y1 = theFirstAxis->dir()->y();
389 double z1 = theFirstAxis->dir()->z();
390 double norm1 = sqrt(x1*x1 + y1*y1 + z1*z1);
392 // Coord theSecondAxis
393 double x2 = theSecondAxis->dir()->x();
394 double y2 = theSecondAxis->dir()->y();
395 double z2 = theSecondAxis->dir()->z();
396 double norm2 = sqrt(x2*x2 + y2*y2 + z2*z2);
398 ListOfShape aListOfShape;
399 for (int j=0; j<theSecondStep; j++) {
400 for (int i=0; i<theFirstNumber; i++) {
401 double dx = i*theFirstStep*x1/norm1+j*theSecondStep*x2/norm2;
402 double dy = i*theFirstStep*y1/norm1+j*theSecondStep*y2/norm2;
403 double dz = i*theFirstStep*z1/norm1+j*theSecondStep*z2/norm2;
404 aListOfShape.push_back(GeomAlgoAPI_ShapeAPI::makeTranslation(theSourceShape, dx, dy, dz));
407 return GeomAlgoAPI_CompoundBuilder::compound(aListOfShape);
410 //===============================================================================================
411 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeConeSegment(
412 const double theRMin1, const double theRMax1,
413 const double theRMin2, const double theRMax2,
415 const double theStartPhi, const double theDeltaPhi) throw (GeomAlgoAPI_Exception)
417 GeomAlgoAPI_ConeSegment aConeSegmentAlgo(theRMin1, theRMax1, theRMin2, theRMax2,
418 theZ, theStartPhi, theDeltaPhi);
420 if (!aConeSegmentAlgo.check()) {
421 throw GeomAlgoAPI_Exception(aConeSegmentAlgo.getError());
424 aConeSegmentAlgo.build();
426 if(!aConeSegmentAlgo.isDone()) {
427 throw GeomAlgoAPI_Exception(aConeSegmentAlgo.getError());
429 if (!aConeSegmentAlgo.checkValid("Cone Segment builder")) {
430 throw GeomAlgoAPI_Exception(aConeSegmentAlgo.getError());
432 return aConeSegmentAlgo.shape();