1 // Copyright (C) 2007-2022 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "GEOMImpl_ICanonicalRecognition.hxx"
25 #include <Basics_OCCTVersion.hxx>
27 #include "GEOM_Function.hxx"
28 #include "GEOM_Object.hxx"
29 #include "GEOM_PythonDump.hxx"
31 #if OCC_VERSION_LARGE > 0x07050303
32 #include <ShapeAnalysis_CanonicalRecognition.hxx>
35 #include <TDataStd_ListIteratorOfListOfExtendedString.hxx>
38 #include <utilities.h>
41 //=============================================================================
45 //=============================================================================
46 GEOMImpl_ICanonicalRecognition::GEOMImpl_ICanonicalRecognition (GEOM_Engine* theEngine)
47 : GEOM_IOperations(theEngine)
49 MESSAGE("GEOMImpl_ICanonicalRecognition::GEOMImpl_ICanonicalRecognition");
52 //=============================================================================
56 //=============================================================================
57 GEOMImpl_ICanonicalRecognition::~GEOMImpl_ICanonicalRecognition()
59 MESSAGE("GEOMImpl_ICanonicalRecognition::~GEOMImpl_ICanonicalRecognition");
62 //=============================================================================
64 * \brief Check if the shape is planar
66 //=============================================================================
67 bool GEOMImpl_ICanonicalRecognition::isPlane(const Handle(GEOM_Object)& theShape, double theTolerance, gp_Pln& thePln)
70 if (theShape.IsNull()) {
71 SetErrorCode("Error: NULL shape");
74 TopoDS_Shape aShape = theShape->GetValue();
75 if (aShape.IsNull()) {
76 SetErrorCode("Error: NULL shape");
80 #if OCC_VERSION_LARGE < 0x07050304
81 SetErrorCode("Shape type detection aborted. Improper OCCT version: please, use OCCT 7.5.3p5 or newer.");
84 ShapeAnalysis_CanonicalRecognition aRecognition(aShape);
86 return aRecognition.GetStatus() == 0 && aRecognition.IsPlane(theTolerance, thePln);
90 //=============================================================================
92 * \brief Check if shape is spherical
94 //=============================================================================
95 bool GEOMImpl_ICanonicalRecognition::isSphere(const Handle(GEOM_Object)& theShape, double theTolerance,
99 if (theShape.IsNull()) {
100 SetErrorCode("Error: NULL shape");
103 TopoDS_Shape aShape = theShape->GetValue();
104 if (aShape.IsNull()) {
105 SetErrorCode("Error: NULL shape");
109 #if OCC_VERSION_LARGE < 0x07050304
110 SetErrorCode("Shape type detection aborted. Improper OCCT version: please, use OCCT 7.5.3p5 or newer.");
113 ShapeAnalysis_CanonicalRecognition aRecognition(aShape);
115 return aRecognition.GetStatus() == 0 && aRecognition.IsSphere(theTolerance, theSphere);
119 //=============================================================================
121 * \brief Check if shape is conical
123 //=============================================================================
124 bool GEOMImpl_ICanonicalRecognition::isCone(const Handle(GEOM_Object)& theShape, double theTolerance,
128 if (theShape.IsNull()) {
129 SetErrorCode("Error: NULL shape");
132 TopoDS_Shape aShape = theShape->GetValue();
133 if (aShape.IsNull()) {
134 SetErrorCode("Error: NULL shape");
138 #if OCC_VERSION_LARGE < 0x07050304
139 SetErrorCode("Shape type detection aborted. Improper OCCT version: please, use OCCT 7.5.3p5 or newer.");
142 ShapeAnalysis_CanonicalRecognition aRecognition(aShape);
144 return aRecognition.GetStatus() == 0 && aRecognition.IsCone(theTolerance, theCone);
148 //=============================================================================
150 * \brief Check if shape is cylinder
152 //=============================================================================
153 bool GEOMImpl_ICanonicalRecognition::isCylinder(const Handle(GEOM_Object)& theShape, double theTolerance,
154 gp_Cylinder& theCylinder)
157 if (theShape.IsNull()) {
158 SetErrorCode("Error: NULL shape");
161 TopoDS_Shape aShape = theShape->GetValue();
162 if (aShape.IsNull()) {
163 SetErrorCode("Error: NULL shape");
167 #if OCC_VERSION_LARGE < 0x07050304
168 SetErrorCode("Shape type detection aborted. Improper OCCT version: please, use OCCT 7.5.3p5 or newer.");
171 ShapeAnalysis_CanonicalRecognition aRecognition(aShape);
173 return aRecognition.GetStatus() == 0 && aRecognition.IsCylinder(theTolerance, theCylinder);
177 //=============================================================================
179 * \brief Check if edge / wire is line
181 //=============================================================================
182 bool GEOMImpl_ICanonicalRecognition::isLine(const Handle(GEOM_Object)& theEdge, double theTolerance,
186 if (theEdge.IsNull()) {
187 SetErrorCode("Error: NULL edge");
190 TopoDS_Shape aShape = theEdge->GetValue();
191 if (aShape.IsNull()) {
192 SetErrorCode("Error: NULL shape");
196 #if OCC_VERSION_LARGE < 0x07050304
197 SetErrorCode("Shape type detection aborted. Improper OCCT version: please, use OCCT 7.5.3p5 or newer.");
200 ShapeAnalysis_CanonicalRecognition aRecognition(aShape);
202 return aRecognition.GetStatus() == 0 && aRecognition.IsLine(theTolerance, theLine);
206 //=============================================================================
208 * \brief Check if edge / wire is circle
210 //=============================================================================
211 bool GEOMImpl_ICanonicalRecognition::isCircle(const Handle(GEOM_Object)& theEdge, double theTolerance,
215 if (theEdge.IsNull()) {
216 SetErrorCode("Error: NULL edge");
219 TopoDS_Shape aShape = theEdge->GetValue();
220 if (aShape.IsNull()) {
221 SetErrorCode("Error: NULL shape");
225 #if OCC_VERSION_LARGE < 0x07050304
226 SetErrorCode("Shape type detection aborted. Improper OCCT version: please, use OCCT 7.5.3p5 or newer.");
229 ShapeAnalysis_CanonicalRecognition aRecognition(aShape);
231 return aRecognition.GetStatus() == 0 && aRecognition.IsCircle(theTolerance, theCircle);
235 //=============================================================================
237 * \brief Check if edge / wire is ellipse
239 //=============================================================================
240 bool GEOMImpl_ICanonicalRecognition::isEllipse(const Handle(GEOM_Object)& theEdge, double theTolerance,
244 if (theEdge.IsNull()) {
245 SetErrorCode("Error: NULL edge");
248 TopoDS_Shape aShape = theEdge->GetValue();
249 if (aShape.IsNull()) {
250 SetErrorCode("Error: NULL shape");
254 #if OCC_VERSION_LARGE < 0x07050304
255 SetErrorCode("Shape type detection aborted. Improper OCCT version: please, use OCCT 7.5.3p5 or newer.");
258 ShapeAnalysis_CanonicalRecognition aRecognition(aShape);
260 return aRecognition.GetStatus() == 0 && aRecognition.IsEllipse(theTolerance, theElips);