From 3a67144291ce5d2bbc775edb3d1809620700e9c2 Mon Sep 17 00:00:00 2001 From: NATHALIE GORE Date: Thu, 14 Nov 2019 16:40:30 +0100 Subject: [PATCH] Parallel planes filters --- .../FiltersPlugin_SameNormalFaces.py | 49 +++++-------------- src/FiltersPlugin/filter-SameNormalFaces.xml | 11 ++--- 2 files changed, 17 insertions(+), 43 deletions(-) diff --git a/src/FiltersPlugin/FiltersPlugin_SameNormalFaces.py b/src/FiltersPlugin/FiltersPlugin_SameNormalFaces.py index 8405213c8..ec151fa59 100644 --- a/src/FiltersPlugin/FiltersPlugin_SameNormalFaces.py +++ b/src/FiltersPlugin/FiltersPlugin_SameNormalFaces.py @@ -50,45 +50,21 @@ class FiltersPlugin_SameNormalFaces(ModelAPI_Filter): def isOk(self, theShape, theResult, theArgs): """ True if theShape is applicable for the filter """ - selectedShapeAttr = modelAPI_AttributeSelection(theArgs.argument("Shape")) + + selectedShapeAttr = modelAPI_AttributeSelection(theArgs.argument("SameNormalFaces")) if selectedShapeAttr is None: return False selectedShape = selectedShapeAttr.value() - isPropagated = modelAPI_AttributeBoolean(theArgs.argument("Propagation")).value() - - # cache selected shape and applicable faces - if selectedShape not in self.myCached: - anOwner = bodyOwner(theResult, True) - if anOwner is None: - anOwner = modelAPI_ResultBody(theResult) - if anOwner is None: - return False - topLevelShape = anOwner.shape() - if not topLevelShape.isSubShape(selectedShape): - return False; - - mapVFAlgo = mapShapesAndAncestors(topLevelShape, GeomAPI_Shape.VERTEX, GeomAPI_Shape.FACE) - mapVF = mapVFAlgo.map() - mapEFAlgo = mapShapesAndAncestors(topLevelShape, GeomAPI_Shape.EDGE, GeomAPI_Shape.FACE) - mapEF = mapEFAlgo.map() - - # faces adjacent to the selected shape - applicableFaces = OriShapeSet() - if selectedShape.shapeType() == GeomAPI_Shape.VERTEX: - if selectedShape in mapVF: applicableFaces = mapVF[selectedShape] - elif selectedShape.shapeType() == GeomAPI_Shape.EDGE: - if selectedShape in mapEF: applicableFaces = mapEF[selectedShape] - elif selectedShape.shapeType() == GeomAPI_Shape.FACE: - applicableFaces.insert(selectedShape) - self.adjacentFaces(selectedShape, mapVF, GeomAPI_Shape.VERTEX, applicableFaces, False) - else: + self.myCached[selectedShape] = [] + selectedFace = GeomAPI_Face(selectedShape) + selectedPlane = selectedFace.getPlane() + + Face = GeomAPI_Face(theShape) + if not Face.isPlanar(): return False - # propagate the connection - if isPropagated: - appFacesCopy = applicableFaces - for ind in range(appFacesCopy.size()): - self.adjacentFaces(appFacesCopy[ind], mapEF, GeomAPI_Shape.EDGE, applicableFaces) - self.myCached[selectedShape] = applicableFaces + Plane = Face.getPlane() + if selectedPlane.intersect(Plane) is None: + self.myCached[selectedShape].append(theShape) return theShape in self.myCached[selectedShape] @@ -98,8 +74,7 @@ class FiltersPlugin_SameNormalFaces(ModelAPI_Filter): def initAttributes(self, theArgs): """ Initializes arguments of a filter """ - theArgs.initAttribute("Shape", ModelAPI_AttributeSelection_typeId()) - theArgs.initAttribute("Propagation", ModelAPI_AttributeBoolean_typeId()) + theArgs.initAttribute("SameNormalFaces", ModelAPI_AttributeSelection_typeId()) def adjacentFaces(self, theFace, theMapSA, theShapeType, theApplicableFaces, theRecursive = True): """ Find all faces neighbour to theFace """ diff --git a/src/FiltersPlugin/filter-SameNormalFaces.xml b/src/FiltersPlugin/filter-SameNormalFaces.xml index 6bdeb22c3..dd7a251a2 100644 --- a/src/FiltersPlugin/filter-SameNormalFaces.xml +++ b/src/FiltersPlugin/filter-SameNormalFaces.xml @@ -1,9 +1,8 @@ - - + + - -- 2.39.2