Salome HOME
Add the GDML primitive "Cone Segment".
[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_Translation.h>
13
14 #include <GeomAPI_Pnt.h>
15 #include <GeomAPI_Edge.h>
16
17 //#include <iostream>
18
19 namespace GeomAlgoAPI_ShapeAPI
20 {
21   //=======================================================================================
22   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeBox(
23     const double theDx, const double theDy,
24     const double theDz) throw (GeomAlgoAPI_Exception)
25   {
26     GeomAlgoAPI_Box aBoxAlgo(theDx,theDy,theDz);
27
28     if (!aBoxAlgo.check()) {
29       throw GeomAlgoAPI_Exception(aBoxAlgo.getError());
30     }
31
32     aBoxAlgo.build();
33
34     if(!aBoxAlgo.isDone()) {
35       throw GeomAlgoAPI_Exception(aBoxAlgo.getError());
36     }
37     if (!aBoxAlgo.checkValid("Box builder with dimensions")) {
38       throw GeomAlgoAPI_Exception(aBoxAlgo.getError());
39     }
40     return aBoxAlgo.shape();
41   }
42
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)
47   {
48     GeomAlgoAPI_Box aBoxAlgo(theFirstPoint, theSecondPoint);
49
50     if (!aBoxAlgo.check()) {
51       throw GeomAlgoAPI_Exception(aBoxAlgo.getError());
52     }
53
54     aBoxAlgo.build();
55
56     if(!aBoxAlgo.isDone()) {
57       throw GeomAlgoAPI_Exception(aBoxAlgo.getError());
58     }
59     if (!aBoxAlgo.checkValid("Box builder with two points")) {
60       throw GeomAlgoAPI_Exception(aBoxAlgo.getError());
61     }
62     return aBoxAlgo.shape();
63   }
64
65   //=========================================================================================================
66   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeTranslation(
67     std::shared_ptr<GeomAPI_Shape> theSourceShape,
68     std::shared_ptr<GeomAPI_Ax1>   theAxis,
69     const double theDistance) throw (GeomAlgoAPI_Exception)
70   {
71     GeomAlgoAPI_Translation aTranslationAlgo(theSourceShape, theAxis, theDistance);
72
73     if (!aTranslationAlgo.check()) {
74       throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
75     }
76
77     aTranslationAlgo.build();
78
79     if(!aTranslationAlgo.isDone()) {
80       throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
81     }
82     if (!aTranslationAlgo.checkValid("Translation builder with axis and distance")) {
83       throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
84     }
85     return aTranslationAlgo.shape();
86   }
87
88   //=========================================================================================================
89   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeTranslation(
90     std::shared_ptr<GeomAPI_Shape> theSourceShape,
91     const double theDx,
92     const double theDy,
93     const double theDz) throw (GeomAlgoAPI_Exception)
94   {
95     GeomAlgoAPI_Translation aTranslationAlgo(theSourceShape, theDx, theDy, theDz);
96
97     if (!aTranslationAlgo.check()) {
98       throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
99     }
100
101     aTranslationAlgo.build();
102
103     if(!aTranslationAlgo.isDone()) {
104       throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
105     }
106     if (!aTranslationAlgo.checkValid("Translation builder with dimensions")) {
107       throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
108     }
109     return aTranslationAlgo.shape();
110   }
111
112   //=========================================================================================================
113   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeTranslation(
114     std::shared_ptr<GeomAPI_Shape> theSourceShape,
115     std::shared_ptr<GeomAPI_Pnt>   theStartPoint,
116     std::shared_ptr<GeomAPI_Pnt>   theEndPoint) throw (GeomAlgoAPI_Exception)
117   {
118     GeomAlgoAPI_Translation aTranslationAlgo(theSourceShape, theStartPoint, theEndPoint);
119
120     if (!aTranslationAlgo.check()) {
121       throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
122     }
123
124     aTranslationAlgo.build();
125
126     if(!aTranslationAlgo.isDone()) {
127       throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
128     }
129     if (!aTranslationAlgo.checkValid("Translation builder with two points")) {
130       throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
131     }
132     return aTranslationAlgo.shape();
133   }
134
135   //=========================================================================================================
136   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeConeSegment(
137     const double theRMin1, const double theRMax1,
138     const double theRMin2, const double theRMax2,
139     const double theZ,
140     const double theStartPhi, const double theDeltaPhi) throw (GeomAlgoAPI_Exception)
141   {
142     GeomAlgoAPI_ConeSegment aConeSegmentAlgo(theRMin1, theRMax1, theRMin2, theRMax2,
143                                              theZ, theStartPhi, theDeltaPhi);
144
145     if (!aConeSegmentAlgo.check()) {
146       throw GeomAlgoAPI_Exception(aConeSegmentAlgo.getError());
147     }
148
149     aConeSegmentAlgo.build();
150
151     if(!aConeSegmentAlgo.isDone()) {
152       throw GeomAlgoAPI_Exception(aConeSegmentAlgo.getError());
153     }
154     if (!aConeSegmentAlgo.checkValid("Cone Segment builder")) {
155       throw GeomAlgoAPI_Exception(aConeSegmentAlgo.getError());
156     }
157     return aConeSegmentAlgo.shape();
158   }
159 }