From 681340563acdc5e6da28b1f236e4490b209c3a12 Mon Sep 17 00:00:00 2001 From: jfa Date: Mon, 11 Apr 2005 07:11:46 +0000 Subject: [PATCH] PAL8379: add in geompy.py a function for filtering edges by length. --- src/GEOM_SWIG/batchmode_geompy.py | 28 +++++++++++++++ src/GEOM_SWIG/geompy.py | 59 +++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+) diff --git a/src/GEOM_SWIG/batchmode_geompy.py b/src/GEOM_SWIG/batchmode_geompy.py index 452023fcf..e9b8eeeb3 100644 --- a/src/GEOM_SWIG/batchmode_geompy.py +++ b/src/GEOM_SWIG/batchmode_geompy.py @@ -1061,6 +1061,34 @@ def GetMainShape(theGroup): print "GetMainShape : ", GroupOp.GetErrorCode() return anObj +def GetEdgesByLength (theShape, min_length, max_length, include_min = 1, include_max = 1): + """ + Create group of edges of theShape, whose length is in range [min_length, max_length]. + If include_min/max == 0, edges with length == min/max_length will not be included in result. + """ + + edges = SubShapeAll(theShape, ShapeType["EDGE"]) + edges_in_range = [] + for edge in edges: + Props = BasicProperties(edge) + if min_length <= Props[0] and Props[0] <= max_length: + if (not include_min) and (min_length == Props[0]): + skip = 1 + else: + if (not include_max) and (Props[0] == max_length): + skip = 1 + else: + edges_in_range.append(edge) + + if len(edges_in_range) <= 0: + print "No edges found by given criteria" + return 0 + + group_edges = CreateGroup(theShape, ShapeType["EDGE"]) + UnionList(group_edges, edges_in_range) + + return group_edges + # Add Path to the system path # def addPath(Path): diff --git a/src/GEOM_SWIG/geompy.py b/src/GEOM_SWIG/geompy.py index 60c341f82..a561d6e84 100644 --- a/src/GEOM_SWIG/geompy.py +++ b/src/GEOM_SWIG/geompy.py @@ -2392,6 +2392,65 @@ def GetMainShape(theGroup): print "GetMainShape : ", GroupOp.GetErrorCode() return anObj +def GetEdgesByLength (theShape, min_length, max_length, include_min = 1, include_max = 1): + """ + Create group of edges of theShape, whose length is in range [min_length, max_length]. + If include_min/max == 0, edges with length == min/max_length will not be included in result. + """ + + edges = SubShapeAll(theShape, ShapeType["EDGE"]) + edges_in_range = [] + for edge in edges: + Props = BasicProperties(edge) + if min_length <= Props[0] and Props[0] <= max_length: + if (not include_min) and (min_length == Props[0]): + skip = 1 + else: + if (not include_max) and (Props[0] == max_length): + skip = 1 + else: + edges_in_range.append(edge) + + if len(edges_in_range) <= 0: + print "No edges found by given criteria" + return 0 + + group_edges = CreateGroup(theShape, ShapeType["EDGE"]) + UnionList(group_edges, edges_in_range) + + return group_edges + +def SelectEdges (min_length, max_length, include_min = 1, include_max = 1): + """ + Create group of edges of selected shape, whose length is in range [min_length, max_length]. + If include_min/max == 0, edges with length == min/max_length will not be included in result. + """ + + nb_selected = sg.SelectedCount() + if nb_selected < 1: + print "Select a shape before calling this function, please." + return 0 + if nb_selected > 1: + print "Only one shape must be selected" + return 0 + + id_shape = sg.getSelected(0) + shape = IDToObject( id_shape ) + + group_edges = GetEdgesByLength(shape, min_length, max_length, include_min, include_max) + + left_str = " < " + right_str = " < " + if include_min: left_str = " <= " + if include_max: right_str = " <= " + + addToStudyInFather(shape, group_edges, "Group of edges with " + `min_length` + + left_str + "length" + right_str + `max_length`) + + sg.updateObjBrowser(1) + + return group_edges + def addPath(Path): """ * Add Path to load python scripts from