]> SALOME platform Git repositories - modules/shaper_study.git/blobdiff - src/PY/SHAPERSTUDY_IOperations.py
Salome HOME
Make SHAPEr STUDY fields exported in SMESH into MED file
[modules/shaper_study.git] / src / PY / SHAPERSTUDY_IOperations.py
index 9925c6177df142d6d51728cff4fc39b7a425ed3d..aad76b9265ec077293b6e21122bb4f2c46709a7e 100644 (file)
 #
 
 import SHAPERSTUDY_ORB__POA
+import SHAPERSTUDY_ORB
 import SHAPERSTUDY_Object
 import GEOM
 from SHAPERSTUDY_utils import getStudy
 
 import StudyData_Swig
 
-class SHAPERSTUDY_IShapesOperations(SHAPERSTUDY_ORB__POA.IShapesOperations):
+class SHAPERSTUDY_IShapesOperations(SHAPERSTUDY_ORB__POA.IShapesOperations,
+                                    SHAPERSTUDY_Object.SHAPERSTUDY_GenericObject):
     """
     Construct an instance of SHAPERSTUDY IShapesOperations.
     """
@@ -48,7 +50,10 @@ class SHAPERSTUDY_IShapesOperations(SHAPERSTUDY_ORB__POA.IShapesOperations):
         """
         aList = self.myop.GetAllSubShapesIDs(theShape.getShape(), theShapeType, isSorted)
         self.done = not aList.empty()
-        return aList
+        aResult = []
+        for i in aList:
+          aResult.append(i)
+        return aResult
 
     def GetSharedShapes( self, theShape1, theShape2, theShapeType ):
         """
@@ -61,7 +66,10 @@ class SHAPERSTUDY_IShapesOperations(SHAPERSTUDY_ORB__POA.IShapesOperations):
         """
         aList = self.myop.GetSharedShapes(theShape1.getShape(), theShape2.getShape(), theShapeType)
         self.done = not aList.empty()
-        return aList
+        aResult = []
+        for i in aList:
+          aResult.append(i)
+        return aResult
 
     def GetSubShapeIndex( self, theMainShape, theSubShape ):
         """
@@ -83,7 +91,7 @@ class SHAPERSTUDY_IShapesOperations(SHAPERSTUDY_ORB__POA.IShapesOperations):
         # create a shape-object that contain the internal shape only
         aShapeObj = SHAPERSTUDY_Object.SHAPERSTUDY_Object()
         aShapeObj.SetShapeByPointer(aShape)
-        return aShapeObj
+        return aShapeObj._this()
 
     def GetInPlace( self, theShapeWhere, theShapeWhat ):
         """
@@ -127,7 +135,6 @@ class SHAPERSTUDY_IGroupOperations(SHAPERSTUDY_ORB__POA.IGroupOperations):
 
         aGroup = SHAPERSTUDY_Object.SHAPERSTUDY_Group()
         aGroupPtr = aGroup._this()
-        aGroupPtr.SetType(37) # the group type
         aGroup.SetSelectionType(theShapeType) # create a new field specific for the group python object
         self.done = True
         return aGroupPtr
@@ -174,8 +181,6 @@ class SHAPERSTUDY_IGroupOperations(SHAPERSTUDY_ORB__POA.IGroupOperations):
         aFatherSO = aSO.GetFather()
         return aFatherSO.GetObject()
 
-        return None # not found
-
     def GetType( self, theGroup ):
         """
         Returns a type (int) of sub-objects stored in the group
@@ -197,11 +202,48 @@ class SHAPERSTUDY_IFieldOperations(SHAPERSTUDY_ORB__POA.IFieldOperations):
     def __init__ ( self, *args):
         pass
 
+    def CreateFieldByType( self, theMainShape, theShapeType):
+        """
+        Creates a new group which will store sub-shapes of theMainShape
+        """
+        if theShapeType != 8 and theShapeType != 7 and theShapeType != 6 and theShapeType != 4 and theShapeType != 2: 
+          print("Error: You could create field of only next type: vertex, edge, face or solid, whole part")
+          return None
+
+        aField = SHAPERSTUDY_Object.SHAPERSTUDY_Field()
+        aFieldPtr = aField._this()
+        aField.SetSelectionType(theShapeType) # create a new field specific for the group python object
+        return aFieldPtr
+
+    def FindField(self, theOwner, theEntry):
+        """
+        Searches existing field of theOwner shape by the entry. Returns NULL if can not find.
+        """
+        aStudy = getStudy()
+        anIter = aStudy.NewChildIterator(theOwner.GetSO())
+        while anIter.More():
+          if len(anIter.Value().GetIOR()):
+            aFieldObj = anIter.Value().GetObject()
+            if aFieldObj:
+              if aFieldObj.GetEntry() == theEntry:
+                return aFieldObj
+          anIter.Next()
+        return None # not found
+
+
     def GetFields( self, shape ):
         """
         Returns all fields on a shape
         """
-        return [ SHAPERSTUDY_Field() ]
+        aResList = []
+        aStudy = getStudy()
+        anIter = aStudy.NewChildIterator(shape.GetSO())
+        while anIter.More():
+          aFieldObj = anIter.Value().GetObject()
+          if aFieldObj and isinstance(aFieldObj, SHAPERSTUDY_ORB._objref_SHAPER_Field):
+            aResList.append(aFieldObj)
+          anIter.Next()
+        return aResList
 
     pass