From c4cf14b971c784b9269ab37c0ea75e9c6b5bfcd7 Mon Sep 17 00:00:00 2001 From: vsv Date: Fri, 7 Jun 2019 12:52:42 +0300 Subject: [PATCH] Implement OnPlane filter --- src/FiltersPlugin/FiltersPlugin_OnPlane.cpp | 66 ++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/src/FiltersPlugin/FiltersPlugin_OnPlane.cpp b/src/FiltersPlugin/FiltersPlugin_OnPlane.cpp index f2771a8cf..3bb1019a2 100644 --- a/src/FiltersPlugin/FiltersPlugin_OnPlane.cpp +++ b/src/FiltersPlugin/FiltersPlugin_OnPlane.cpp @@ -20,6 +20,17 @@ #include "FiltersPlugin_OnPlane.h" #include +#include +#include +#include +#include +#include +#include +#include +#include + + +#define LIN_TOLERANCE 1.e-7 bool FiltersPlugin_OnPlane::isSupported(GeomAPI_Shape::ShapeType theType) const { @@ -34,6 +45,13 @@ bool FiltersPlugin_OnPlane::isSupported(GeomAPI_Shape::ShapeType theType) const return false; } +GeomPlanePtr getPlane(AttributeSelectionPtr theAttr) +{ + GeomShapePtr aGeom = theAttr->value(); + GeomFacePtr aFace(new GeomAPI_Face(aGeom)); + return aFace->getPlane(); +} + bool FiltersPlugin_OnPlane::isOk(const GeomShapePtr& theShape, const ModelAPI_FiltersArgs& theArgs) const { @@ -42,7 +60,53 @@ bool FiltersPlugin_OnPlane::isOk(const GeomShapePtr& theShape, std::dynamic_pointer_cast(aAttr); if (!aList.get()) return false; - // ToDo + if (theShape->isVertex()) { + GeomVertexPtr aVertex(new GeomAPI_Vertex(theShape)); + GeomPointPtr aPnt = aVertex->point(); + for (int i = 0; i < aList->size(); i++) { + GeomPlanePtr aPlane = getPlane(aList->value(i)); + if (aPlane->distance(aPnt) < LIN_TOLERANCE) + return true; + } + } + else if (theShape->isEdge()) { + GeomEdgePtr aEdge(new GeomAPI_Edge(theShape)); + if (aEdge->isLine()) { + GeomPointPtr aPnt1 = aEdge->firstPoint(); + GeomPointPtr aPnt2 = aEdge->lastPoint(); + for (int i = 0; i < aList->size(); i++) { + GeomPlanePtr aPlane = getPlane(aList->value(i)); + if ((aPlane->distance(aPnt1) < LIN_TOLERANCE) && (aPlane->distance(aPnt2) < LIN_TOLERANCE)) + return true; + } + } + else if (aEdge->isCircle()) { + GeomCurvePtr aCurve(new GeomAPI_Curve(aEdge)); + GeomCirclePtr aCircle(new GeomAPI_Circ(aCurve)); + GeomDirPtr aDir = aCircle->normal(); + GeomPointPtr aPnt = aCircle->center(); + for (int i = 0; i < aList->size(); i++) { + GeomPlanePtr aPlane = getPlane(aList->value(i)); + if ((aPlane->direction()->isParallel(aDir)) && (aPlane->distance(aPnt) < LIN_TOLERANCE)) + return true; + } + } + } + else if (theShape->isFace()) { + GeomFacePtr aFace(new GeomAPI_Face(theShape)); + if (aFace->isPlanar()) { + GeomPlanePtr aPln = aFace->getPlane(); + for (int i = 0; i < aList->size(); i++) { + AttributeSelectionPtr aAttr = aList->value(i); + GeomShapePtr aGeom = aAttr->value(); + if (!aGeom->isSame(theShape)) { + GeomPlanePtr aPlane = getPlane(aAttr); + if (aPlane->isCoincident(aPln)) + return true; + } + } + } + } return false; } -- 2.39.2