Salome HOME
Merge remote-tracking branch 'remotes/origin/master' into BR_coding_rules
[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 #include <GeomAlgoAPI_Box.h>
9 #include <GeomAlgoAPI_Translation.h>
10
11 #include <GeomAPI_Pnt.h>
12 #include <GeomAPI_Edge.h>
13 #include <GeomAlgoAPI_EdgeBuilder.h>
14
15 #include <iostream>
16
17 namespace GeomAlgoAPI_ShapeAPI
18 {
19   //=======================================================================================
20   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeBox(
21     const double theDx, const double theDy,
22     const double theDz) throw (GeomAlgoAPI_Exception)
23   {
24     GeomAlgoAPI_Box aBoxAlgo(theDx,theDy,theDz);
25
26     if (!aBoxAlgo.check()) {
27       throw GeomAlgoAPI_Exception(aBoxAlgo.getError());
28     }
29
30     aBoxAlgo.build();
31
32     if(!aBoxAlgo.isDone()) {
33       throw GeomAlgoAPI_Exception(aBoxAlgo.getError());
34     }
35     if (!aBoxAlgo.checkValid("Box builder with dimensions")) {
36       throw GeomAlgoAPI_Exception(aBoxAlgo.getError());
37     }
38     return aBoxAlgo.shape();
39   }
40
41   //======================================================================================
42   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeBox(
43     std::shared_ptr<GeomAPI_Pnt> theFirstPoint,
44     std::shared_ptr<GeomAPI_Pnt> theSecondPoint) throw (GeomAlgoAPI_Exception)
45   {
46     GeomAlgoAPI_Box aBoxAlgo(theFirstPoint, theSecondPoint);
47
48     if (!aBoxAlgo.check()) {
49       throw GeomAlgoAPI_Exception(aBoxAlgo.getError());
50     }
51
52     aBoxAlgo.build();
53
54     if(!aBoxAlgo.isDone()) {
55       throw GeomAlgoAPI_Exception(aBoxAlgo.getError());
56     }
57     if (!aBoxAlgo.checkValid("Box builder with two points")) {
58       throw GeomAlgoAPI_Exception(aBoxAlgo.getError());
59     }
60     return aBoxAlgo.shape();
61   }
62
63   //=========================================================================================================
64   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeTranslation(
65     std::shared_ptr<GeomAPI_Shape> theSourceShape,
66     std::shared_ptr<GeomAPI_Ax1>   theAxis,
67     const double theDistance) throw (GeomAlgoAPI_Exception)
68   {
69     GeomAlgoAPI_Translation aTranslationAlgo(theSourceShape, theAxis, theDistance);
70
71     if (!aTranslationAlgo.check()) {
72       throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
73     }
74
75     aTranslationAlgo.build();
76
77     if(!aTranslationAlgo.isDone()) {
78       throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
79     }
80     if (!aTranslationAlgo.checkValid("Translation builder with axis and distance")) {
81       throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
82     }
83     return aTranslationAlgo.shape();
84   }
85
86   //=========================================================================================================
87   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeTranslation(
88     std::shared_ptr<GeomAPI_Shape> theSourceShape,
89     const double theDx,
90     const double theDy,
91     const double theDz) throw (GeomAlgoAPI_Exception)
92   {
93     GeomAlgoAPI_Translation aTranslationAlgo(theSourceShape, theDx, theDy, theDz);
94
95     if (!aTranslationAlgo.check()) {
96       throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
97     }
98
99     aTranslationAlgo.build();
100
101     if(!aTranslationAlgo.isDone()) {
102       throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
103     }
104     if (!aTranslationAlgo.checkValid("Translation builder with dimensions")) {
105       throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
106     }
107     return aTranslationAlgo.shape();
108   }
109
110   //=========================================================================================================
111   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeTranslation(
112     std::shared_ptr<GeomAPI_Shape> theSourceShape,
113     std::shared_ptr<GeomAPI_Pnt>   theStartPoint,
114     std::shared_ptr<GeomAPI_Pnt>   theEndPoint) throw (GeomAlgoAPI_Exception)
115   {
116     GeomAlgoAPI_Translation aTranslationAlgo(theSourceShape, theStartPoint, theEndPoint);
117
118     if (!aTranslationAlgo.check()) {
119       throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
120     }
121
122     aTranslationAlgo.build();
123
124     if(!aTranslationAlgo.isDone()) {
125       throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
126     }
127     if (!aTranslationAlgo.checkValid("Translation builder with two points")) {
128       throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
129     }
130     return aTranslationAlgo.shape();
131   }
132 }