Salome HOME
Fix error when reading file on a non-utf-8 locale
[modules/shaper.git] / src / FiltersPlugin / FiltersPlugin_VerticalFace.cpp
index 49fd944c6e7098826aa69d809b79ed56dabceec6..105ada64e6d6d2f7a094b000bb50e3fc2220cdde 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2021  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
 #include <GeomAPI_Shell.h>
 #include <GeomAPI_Cylinder.h>
 
+#include <cmath>
+
 bool FiltersPlugin_VerticalFace::isSupported(GeomAPI_Shape::ShapeType theType) const
 {
   return theType == GeomAPI_Shape::FACE;
 }
 
-bool FiltersPlugin_VerticalFace::isOk(
-  const GeomShapePtr& theShape, const ModelAPI_FiltersArgs& theArgs) const
+bool FiltersPlugin_VerticalFace::isOk(const GeomShapePtr& theShape, const ResultPtr&,
+                                      const ModelAPI_FiltersArgs& /*theArgs*/) const
 {
-  if (!theShape->isFace() || !theShape->isPlanar())
-    return false;
+  static const double THE_TOLERANCE = 1.e-7;
+
+  bool isVertical = false;
+  if (!theShape->isFace())
+    return isVertical;
 
   GeomFacePtr aFace(new GeomAPI_Face(theShape));
 
   GeomPlanePtr aPlane = aFace->getPlane();
-  GeomDirPtr aDir = aPlane->direction();
-  return fabs(aDir->z()) <= 1.e-7;
+  if (aPlane) {
+    GeomDirPtr aDir = aPlane->direction();
+    isVertical = fabs(aDir->z()) <= THE_TOLERANCE;
+  }
+  else {
+    GeomCylinderPtr aCylinder = aFace->getCylinder();
+    if (aCylinder) {
+      GeomDirPtr aDir = aCylinder->axis();
+      isVertical = fabs(fabs(aDir->z()) - 1.0) <= THE_TOLERANCE;
+    }
+  }
+  return isVertical;
 }