From c88d134c68fa4eaf33432fe8b6820b113bb25e3f Mon Sep 17 00:00:00 2001 From: jfa Date: Thu, 8 Sep 2022 17:45:33 +0300 Subject: [PATCH] Provide compatibility with older OCCT versions --- .../GeomAlgoAPI_CanonicalRecognition.cpp | 67 +++++++++++++++++-- .../GeomAlgoAPI_CanonicalRecognition.h | 5 ++ src/PythonAPI/Test/TestCR.py | 47 ++++++++----- src/PythonAPI/geom/CanonicalRecognition.py | 8 +++ 4 files changed, 103 insertions(+), 24 deletions(-) diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_CanonicalRecognition.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_CanonicalRecognition.cpp index 7e6e087e7..dc935586d 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_CanonicalRecognition.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_CanonicalRecognition.cpp @@ -19,7 +19,24 @@ #include "GeomAlgoAPI_CanonicalRecognition.h" +#include +// code from KERNEL_SRC/src/Basics/Basics_OCCTVersion.hxx +#ifdef OCC_VERSION_SERVICEPACK +# define OCC_VERSION_LARGE (OCC_VERSION_MAJOR << 24 | OCC_VERSION_MINOR << 16 | OCC_VERSION_MAINTENANCE << 8 | OCC_VERSION_SERVICEPACK) +#else +# ifdef OCC_VERSION_DEVELOPMENT +# define OCC_VERSION_LARGE ((OCC_VERSION_MAJOR << 24 | OCC_VERSION_MINOR << 16 | OCC_VERSION_MAINTENANCE << 8)-1) +# else +# define OCC_VERSION_LARGE (OCC_VERSION_MAJOR << 24 | OCC_VERSION_MINOR << 16 | OCC_VERSION_MAINTENANCE << 8) +# endif +#endif + +#if OCC_VERSION_LARGE > 0x07050303 #include +#endif + +#include + #include #include #include @@ -50,8 +67,10 @@ bool GeomAlgoAPI_CanonicalRecognition::isPlane(const GeomShapePtr& theShape, dou gp_Dir(theNormal[0], theNormal[1], theNormal[2])); } - ShapeAnalysis_CanonicalRecognition aRecognition(aShape); bool aResult = false; + +#if OCC_VERSION_LARGE > 0x07050303 + ShapeAnalysis_CanonicalRecognition aRecognition(aShape); try { if (aRecognition.GetStatus() == 0) aResult = aRecognition.IsPlane(theTolerance, aPln); @@ -59,6 +78,7 @@ bool GeomAlgoAPI_CanonicalRecognition::isPlane(const GeomShapePtr& theShape, dou catch (...) { return false; } +#endif gp_Pnt aOrig = aPln.Location(); if (theOrigin.size() != 3) @@ -97,8 +117,11 @@ bool GeomAlgoAPI_CanonicalRecognition::isSphere(const GeomShapePtr& theShape, do } else aSphere.SetRadius(1.0); - ShapeAnalysis_CanonicalRecognition aRecognition(aShape); + bool aResult = false; + +#if OCC_VERSION_LARGE > 0x07050303 + ShapeAnalysis_CanonicalRecognition aRecognition(aShape); try { if (aRecognition.GetStatus() == 0) aResult = aRecognition.IsSphere(theTolerance, aSphere); @@ -106,6 +129,7 @@ bool GeomAlgoAPI_CanonicalRecognition::isSphere(const GeomShapePtr& theShape, do catch (...) { return false; } +#endif gp_Pnt aLoc = aSphere.Location(); if (theOrigin.size() != 3) @@ -141,8 +165,11 @@ bool GeomAlgoAPI_CanonicalRecognition::isCone(const GeomShapePtr& theShape, doub } else aCone.SetRadius(1.0); - ShapeAnalysis_CanonicalRecognition aRecognition(aShape); + bool aResult = false; + +#if OCC_VERSION_LARGE > 0x07050303 + ShapeAnalysis_CanonicalRecognition aRecognition(aShape); try { if (aRecognition.GetStatus() == 0) aResult = aRecognition.IsCone(theTolerance, aCone); @@ -150,6 +177,7 @@ bool GeomAlgoAPI_CanonicalRecognition::isCone(const GeomShapePtr& theShape, doub catch (...) { return false; } +#endif gp_Dir aDir = aCone.Axis().Direction(); if (theAxis.size() != 3) @@ -194,8 +222,11 @@ bool GeomAlgoAPI_CanonicalRecognition::isCylinder(const GeomShapePtr& theShape, } else aCylinder.SetRadius(1.0); - ShapeAnalysis_CanonicalRecognition aRecognition(aShape); + bool aResult = false; + +#if OCC_VERSION_LARGE > 0x07050303 + ShapeAnalysis_CanonicalRecognition aRecognition(aShape); try { if (aRecognition.GetStatus() == 0) aResult = aRecognition.IsCylinder(theTolerance, aCylinder); @@ -203,6 +234,7 @@ bool GeomAlgoAPI_CanonicalRecognition::isCylinder(const GeomShapePtr& theShape, catch (...) { return false; } +#endif gp_Dir aDir = aCylinder.Axis().Direction(); if (theAxis.size() != 3) @@ -241,8 +273,11 @@ bool GeomAlgoAPI_CanonicalRecognition::isLine(const GeomShapePtr& theEdge, doubl aLine.SetLocation(gp_Pnt(theOrigin[0], theOrigin[1], theOrigin[2])); aLine.SetDirection(gp_Dir(theDir[0], theDir[1], theDir[2])); } - ShapeAnalysis_CanonicalRecognition aRecognition(aShape); + bool aResult = false; + +#if OCC_VERSION_LARGE > 0x07050303 + ShapeAnalysis_CanonicalRecognition aRecognition(aShape); try { if (aRecognition.GetStatus() == 0) aResult = aRecognition.IsLine(theTolerance, aLine); @@ -250,6 +285,7 @@ bool GeomAlgoAPI_CanonicalRecognition::isLine(const GeomShapePtr& theEdge, doubl catch (...) { return false; } +#endif gp_Pnt aLoc = aLine.Location(); if (theOrigin.size() != 3) @@ -292,8 +328,11 @@ bool GeomAlgoAPI_CanonicalRecognition::isCircle(const GeomShapePtr& theEdge, dou } else aCircle.SetRadius(1.0); - ShapeAnalysis_CanonicalRecognition aRecognition(aShape); + bool aResult = false; + +#if OCC_VERSION_LARGE > 0x07050303 + ShapeAnalysis_CanonicalRecognition aRecognition(aShape); try { if (aRecognition.GetStatus() == 0) aResult = aRecognition.IsCircle(theTolerance, aCircle); @@ -301,6 +340,7 @@ bool GeomAlgoAPI_CanonicalRecognition::isCircle(const GeomShapePtr& theEdge, dou catch (...) { return false; } +#endif gp_Pnt aLoc = aCircle.Location(); if (theOrigin.size() != 3) @@ -350,8 +390,11 @@ bool GeomAlgoAPI_CanonicalRecognition::isEllipse(const GeomShapePtr& theEdge, do } else aElips.SetMajorRadius(1.0); - ShapeAnalysis_CanonicalRecognition aRecognition(aShape); + bool aResult = false; + +#if OCC_VERSION_LARGE > 0x07050303 + ShapeAnalysis_CanonicalRecognition aRecognition(aShape); try { if (aRecognition.GetStatus() == 0) aResult = aRecognition.IsEllipse(theTolerance, aElips); @@ -359,6 +402,7 @@ bool GeomAlgoAPI_CanonicalRecognition::isEllipse(const GeomShapePtr& theEdge, do catch (...) { return false; } +#endif gp_Pnt aLoc = aElips.Position().Location(); if (theOrigin.size() != 3) @@ -386,3 +430,12 @@ bool GeomAlgoAPI_CanonicalRecognition::isEllipse(const GeomShapePtr& theEdge, do return aResult; } + +bool GeomAlgoAPI_CanonicalRecognition::isImplemented() +{ +#if OCC_VERSION_LARGE > 0x07050303 + return true; +#else + return false; +#endif +} diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_CanonicalRecognition.h b/src/GeomAlgoAPI/GeomAlgoAPI_CanonicalRecognition.h index e1c860f64..6efddfac9 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_CanonicalRecognition.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_CanonicalRecognition.h @@ -75,6 +75,11 @@ public: std::vector& theOrigin, double& theMajorRadius, double& theMinorRadius); + /*! + * \brief Check if the algorithm is implemented (Shaper is built with appropriate OCCT version) + */ + GEOMALGOAPI_EXPORT static bool isImplemented(); + }; #endif diff --git a/src/PythonAPI/Test/TestCR.py b/src/PythonAPI/Test/TestCR.py index a029c4c7a..634275b10 100644 --- a/src/PythonAPI/Test/TestCR.py +++ b/src/PythonAPI/Test/TestCR.py @@ -1,16 +1,28 @@ -#!/usr/bin/env python - -### -### This file is generated automatically by SALOME v9.9.0 with dump python functionality -### - - -### -### SHAPER component -### +# Copyright (C) 2014-2022 CEA/DEN, EDF R&D +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# from salome.shaper import model, geom +def isCRImplemented(): + CR = geom.CanonicalRecognition() + return CR.isImplemented() + def GetShapeType(theShape): CR = geom.CanonicalRecognition() if CR.isLine(theShape, 0.1)[0]: @@ -96,10 +108,11 @@ aConeShape = ConeShell_1.defaultResult().shape() aEllipseShape = EllipseWire_1.defaultResult().shape() ### Check shapes types -assert (GetShapeType(aPlaneShape) == "Plane") -assert (GetShapeType(aCircleShape)[1] == "Circle") -assert (GetShapeType(aLineShape) == "Line") -assert (GetShapeType(aCylinderShape) == "Cylinder") -assert (GetShapeType(aSphereShape) == "Sphere") -assert (GetShapeType(aConeShape) == "Cone") -assert (GetShapeType(aEllipseShape)[1] == "Ellipse") +if isCRImplemented(): + assert (GetShapeType(aPlaneShape) == "Plane") + assert (GetShapeType(aCircleShape)[1] == "Circle") + assert (GetShapeType(aLineShape) == "Line") + assert (GetShapeType(aCylinderShape) == "Cylinder") + assert (GetShapeType(aSphereShape) == "Sphere") + assert (GetShapeType(aConeShape) == "Cone") + assert (GetShapeType(aEllipseShape)[1] == "Ellipse") diff --git a/src/PythonAPI/geom/CanonicalRecognition.py b/src/PythonAPI/geom/CanonicalRecognition.py index f7510762b..44b025582 100644 --- a/src/PythonAPI/geom/CanonicalRecognition.py +++ b/src/PythonAPI/geom/CanonicalRecognition.py @@ -75,3 +75,11 @@ class CanonicalRecognition: > CR.isEllipse(edge, tolerance, normal, dirX, origin, majorRadius, minorRadius) """ return GeomAlgoAPI_CanonicalRecognition.isEllipse(edge, tolerance, normal, dirX, origin, majorRadius, minorRadius) + + def isImplemented(self): + """ + Check if the CanonicalRecognition is implemented (built with appropriate OCCT version) + Usage: + > CR.isImplemented() + """ + return GeomAlgoAPI_CanonicalRecognition.isImplemented() -- 2.39.2