Salome HOME
PR: add blocFissure plugin
[modules/smesh.git] / src / Tools / blocFissure / gmu / extractionOrientee.py
diff --git a/src/Tools/blocFissure/gmu/extractionOrientee.py b/src/Tools/blocFissure/gmu/extractionOrientee.py
new file mode 100644 (file)
index 0000000..2ea9e52
--- /dev/null
@@ -0,0 +1,51 @@
+# -*- coding: utf-8 -*-
+
+import logging
+from geomsmesh import geompy
+
+from whichSide import whichSide
+
+# -----------------------------------------------------------------------------
+# --- renvoie l'extraction des shapes d'un objet selon leur position par rapport à la face.
+
+def extractionOrientee(face, obj, ref, shapeType, tol, prefix=""):
+  """
+  renvoie l'extraction des shapes d'un objet selon leur position
+  par rapport à la face.
+  shapeType in ["VERTEX", "EDGE", "FACE",...]
+  """
+  logging.info('start')
+  trace = True
+  sideRef = whichSide(face, ref)
+  logging.debug("ref side %s", sideRef)
+  shapesInside = []
+  shapesOutside = []
+  shapesOnside = []
+  shapes = geompy.ExtractShapes(obj, geompy.ShapeType[shapeType], False)
+  i=0
+  j=0
+  k=0
+  prefix = prefix + shapeType
+  for shape in shapes:
+    side = whichSide(face, shape, tol)
+    if side == sideRef:
+      shapesInside.append(shape)
+      if trace:
+        name = prefix + "_Inside%d"%i
+        geompy.addToStudyInFather(obj, shape, name)
+      i+=1
+    elif side == -sideRef:
+      shapesOutside.append(shape)
+      if trace:
+        name = prefix + "_Outside%d"%j
+        geompy.addToStudyInFather(obj, shape, name)
+      j+=1
+    elif side == 0:
+      shapesOnside.append(shape)
+      if trace:
+        name = prefix + "_Onside%d"%k
+        geompy.addToStudyInFather(obj, shape, name)
+      k+=1
+    logging.debug("--- shape was %s", name)
+  return [shapesInside, shapesOutside, shapesOnside]
+