Salome HOME
e43033afac03ebacaef6581e91eedb8baab43a4f
[modules/geom.git] / src / GEOMImpl / GEOMImpl_ICanonicalRecognition.cxx
1 // Copyright (C) 2007-2023  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include "GEOMImpl_ICanonicalRecognition.hxx"
24
25 #include <Basics_OCCTVersion.hxx>
26
27 #include "GEOM_Function.hxx"
28 #include "GEOM_Object.hxx"
29 #include "GEOM_PythonDump.hxx"
30
31 #if OCC_VERSION_LARGE > 0x07050303
32 #include <ShapeAnalysis_CanonicalRecognition.hxx>
33 #endif
34
35 #include <TDataStd_ListIteratorOfListOfExtendedString.hxx>
36 #include <gp_Pln.hxx>
37
38 #include <utilities.h>
39
40
41 //=============================================================================
42 /*!
43  *   constructor:
44  */
45 //=============================================================================
46 GEOMImpl_ICanonicalRecognition::GEOMImpl_ICanonicalRecognition (GEOM_Engine* theEngine)
47 : GEOM_IOperations(theEngine)
48 {
49   MESSAGE("GEOMImpl_ICanonicalRecognition::GEOMImpl_ICanonicalRecognition");
50 }
51
52 //=============================================================================
53 /*!
54  *  destructor
55  */
56 //=============================================================================
57 GEOMImpl_ICanonicalRecognition::~GEOMImpl_ICanonicalRecognition()
58 {
59   MESSAGE("GEOMImpl_ICanonicalRecognition::~GEOMImpl_ICanonicalRecognition");
60 }
61
62 //=============================================================================
63 /*!
64  * \brief Check if the shape is planar
65  */
66  //=============================================================================
67 bool GEOMImpl_ICanonicalRecognition::isPlane(const Handle(GEOM_Object)& theShape, double theTolerance, gp_Pln& thePln)
68 {
69   SetErrorCode(KO);
70   if (theShape.IsNull()) {
71     SetErrorCode("Error: NULL shape");
72     return false;
73   }
74   TopoDS_Shape aShape = theShape->GetValue();
75   if (aShape.IsNull()) {
76     SetErrorCode("Error: NULL shape");
77     return false;
78   }
79
80 #if OCC_VERSION_LARGE < 0x07050304
81   SetErrorCode("Shape type detection aborted. Improper OCCT version: please, use OCCT 7.5.3p5 or newer.");
82   return false;
83 #else
84   ShapeAnalysis_CanonicalRecognition aRecognition(aShape);
85   SetErrorCode(OK);
86   return aRecognition.GetStatus() == 0 && aRecognition.IsPlane(theTolerance, thePln);
87 #endif
88 }
89
90 //=============================================================================
91 /*!
92  * \brief Check if shape is spherical
93  */
94  //=============================================================================
95 bool GEOMImpl_ICanonicalRecognition::isSphere(const Handle(GEOM_Object)& theShape, double theTolerance,
96   gp_Sphere& theSphere)
97 {
98   SetErrorCode(KO);
99   if (theShape.IsNull()) {
100     SetErrorCode("Error: NULL shape");
101     return false;
102   }
103   TopoDS_Shape aShape = theShape->GetValue();
104   if (aShape.IsNull()) {
105     SetErrorCode("Error: NULL shape");
106     return false;
107   }
108
109 #if OCC_VERSION_LARGE < 0x07050304
110   SetErrorCode("Shape type detection aborted. Improper OCCT version: please, use OCCT 7.5.3p5 or newer.");
111   return false;
112 #else
113   ShapeAnalysis_CanonicalRecognition aRecognition(aShape);
114   SetErrorCode(OK);
115   return aRecognition.GetStatus() == 0 && aRecognition.IsSphere(theTolerance, theSphere);
116 #endif
117 }
118
119 //=============================================================================
120 /*!
121  * \brief Check if shape is conical
122  */
123  //=============================================================================
124 bool GEOMImpl_ICanonicalRecognition::isCone(const Handle(GEOM_Object)& theShape, double theTolerance,
125   gp_Cone& theCone)
126 {
127   SetErrorCode(KO);
128   if (theShape.IsNull()) {
129     SetErrorCode("Error: NULL shape");
130     return false;
131   }
132   TopoDS_Shape aShape = theShape->GetValue();
133   if (aShape.IsNull()) {
134     SetErrorCode("Error: NULL shape");
135     return false;
136   }
137
138 #if OCC_VERSION_LARGE < 0x07050304
139   SetErrorCode("Shape type detection aborted. Improper OCCT version: please, use OCCT 7.5.3p5 or newer.");
140   return false;
141 #else
142   ShapeAnalysis_CanonicalRecognition aRecognition(aShape);
143   SetErrorCode(OK);
144   return aRecognition.GetStatus() == 0 && aRecognition.IsCone(theTolerance, theCone);
145 #endif
146 }
147
148 //=============================================================================
149 /*!
150  * \brief Check if shape is cylinder
151  */
152  //=============================================================================
153 bool GEOMImpl_ICanonicalRecognition::isCylinder(const Handle(GEOM_Object)& theShape, double theTolerance,
154   gp_Cylinder& theCylinder)
155 {
156   SetErrorCode(KO);
157   if (theShape.IsNull()) {
158     SetErrorCode("Error: NULL shape");
159     return false;
160   }
161   TopoDS_Shape aShape = theShape->GetValue();
162   if (aShape.IsNull()) {
163     SetErrorCode("Error: NULL shape");
164     return false;
165   }
166
167 #if OCC_VERSION_LARGE < 0x07050304
168   SetErrorCode("Shape type detection aborted. Improper OCCT version: please, use OCCT 7.5.3p5 or newer.");
169   return false;
170 #else
171   ShapeAnalysis_CanonicalRecognition aRecognition(aShape);
172   SetErrorCode(OK);
173   return aRecognition.GetStatus() == 0 && aRecognition.IsCylinder(theTolerance, theCylinder);
174 #endif
175 }
176
177 //=============================================================================
178 /*!
179  * \brief Check if edge / wire is line
180  */
181  //=============================================================================
182 bool GEOMImpl_ICanonicalRecognition::isLine(const Handle(GEOM_Object)& theEdge, double theTolerance,
183   gp_Lin& theLine)
184 {
185   SetErrorCode(KO);
186   if (theEdge.IsNull()) {
187     SetErrorCode("Error: NULL edge");
188     return false;
189   }
190   TopoDS_Shape aShape = theEdge->GetValue();
191   if (aShape.IsNull()) {
192     SetErrorCode("Error: NULL shape");
193     return false;
194   }
195
196 #if OCC_VERSION_LARGE < 0x07050304
197   SetErrorCode("Shape type detection aborted. Improper OCCT version: please, use OCCT 7.5.3p5 or newer.");
198   return false;
199 #else
200   ShapeAnalysis_CanonicalRecognition aRecognition(aShape);
201   SetErrorCode(OK);
202   return aRecognition.GetStatus() == 0 && aRecognition.IsLine(theTolerance, theLine);
203 #endif
204 }
205
206 //=============================================================================
207 /*!
208  * \brief Check if edge / wire is circle
209  */
210  //=============================================================================
211 bool GEOMImpl_ICanonicalRecognition::isCircle(const Handle(GEOM_Object)& theEdge, double theTolerance,
212   gp_Circ& theCircle)
213 {
214   SetErrorCode(KO);
215   if (theEdge.IsNull()) {
216     SetErrorCode("Error: NULL edge");
217     return false;
218   }
219   TopoDS_Shape aShape = theEdge->GetValue();
220   if (aShape.IsNull()) {
221     SetErrorCode("Error: NULL shape");
222     return false;
223   }
224
225 #if OCC_VERSION_LARGE < 0x07050304
226   SetErrorCode("Shape type detection aborted. Improper OCCT version: please, use OCCT 7.5.3p5 or newer.");
227   return false;
228 #else
229   ShapeAnalysis_CanonicalRecognition aRecognition(aShape);
230   SetErrorCode(OK);
231   return aRecognition.GetStatus() == 0 && aRecognition.IsCircle(theTolerance, theCircle);
232 #endif
233 }
234
235 //=============================================================================
236 /*!
237  * \brief Check if edge / wire is ellipse
238  */
239  //=============================================================================
240 bool GEOMImpl_ICanonicalRecognition::isEllipse(const Handle(GEOM_Object)& theEdge, double theTolerance,
241   gp_Elips& theElips)
242 {
243   SetErrorCode(KO);
244   if (theEdge.IsNull()) {
245     SetErrorCode("Error: NULL edge");
246     return false;
247   }
248   TopoDS_Shape aShape = theEdge->GetValue();
249   if (aShape.IsNull()) {
250     SetErrorCode("Error: NULL shape");
251     return false;
252   }
253
254 #if OCC_VERSION_LARGE < 0x07050304
255   SetErrorCode("Shape type detection aborted. Improper OCCT version: please, use OCCT 7.5.3p5 or newer.");
256   return false;
257 #else
258   ShapeAnalysis_CanonicalRecognition aRecognition(aShape);
259   SetErrorCode(OK);
260   return aRecognition.GetStatus() == 0 && aRecognition.IsEllipse(theTolerance, theElips);
261 #endif
262 }