]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Apply patch of Renaud Nedelec for exportation of groups to GEOM
authormpv <mpv@opencascade.com>
Thu, 22 Jan 2015 09:07:11 +0000 (12:07 +0300)
committermpv <mpv@opencascade.com>
Thu, 22 Jan 2015 09:07:11 +0000 (12:07 +0300)
src/ConnectorPlugin/ConnectorPlugin_ExportFeature.py
src/Model/Model_AttributeSelection.cpp
src/Model/Model_AttributeSelection.h
src/ModelAPI/ModelAPI_AttributeSelection.h

index 8b3163426638cdb97464bfe6bb8115deb36036ee..ea030b363731b7b9e352f72eede91f01d0f45496 100644 (file)
@@ -31,17 +31,25 @@ class ExportFeature(ModelAPI.ModelAPI_Feature):
         return False
 
     def initAttributes(self):
-        # This feature has no attributes, but should perfore some actions on initialization
+        # This feature has no attributes, but should perform some actions on initialization
         aSession = ModelAPI.ModelAPI_Session.get()
-        aPart = aSession.activeDocument()
+        self.Part = aSession.activeDocument()
+        self.geomObjects = []
+        self.geompy = geomBuilder.New(salome.myStudy)
+       
+        # Export bodies and groups
+        self.exportBodies()
+        self.exportGroups()
+        
+    def exportBodies(self):
         # Get all bodies
         kResultBodyType = "Bodies"
-        aPartSize = aPart.size(kResultBodyType)
+        aPartSize = self.Part.size(kResultBodyType)
         if aPartSize == 0:
             EventsAPI.Events_Error_send("No results in the active document")
             return
-
-        anObjList = [aPart.object(kResultBodyType, idx) for idx in xrange(aPartSize)]
+          
+        anObjList = [self.Part.object(kResultBodyType, idx) for idx in xrange(aPartSize)]     
         for idx, anObject in enumerate(anObjList):
             aResult = ModelAPI.modelAPI_Result(anObject)
             aBodyResult = ModelAPI.modelAPI_ResultBody(aResult)
@@ -50,10 +58,49 @@ class ExportFeature(ModelAPI.ModelAPI_Feature):
             aShape = aBodyResult.shape()
             aDump = aShape.getShapeStream()
             # Load shape to SALOME Geom
-            geompy = geomBuilder.New(salome.myStudy)
-            aBrep = geompy.RestoreShape(aDump)
-            geompy.addToStudy(aBrep, "NewGeomShape_{0}".format(idx))
+            aBrep = self.geompy.RestoreShape(aDump)
+            self.geompy.addToStudy(aBrep, "NewGeomShape_{0}".format(idx + 1))
+            self.geomObjects.append([aShape, aBrep])
+
+    def exportGroups(self):
+        # iterate all features to find groups
+        aFeaturesNum = self.Part.size("Features")
+        groupIndex = 0
+        for anIndex in range(0, aFeaturesNum):
+            aFeature = self.Part.object("Features", anIndex)
+            aSelectionList = aFeature.data().selectionList("group_list")
+            # if a group has been found
+            if aSelectionList:
+                groupIndex = groupIndex + 1
+                self.createGroupFromList(aSelectionList, "NewGeomGroup_{0}".format(groupIndex))
+                     
+    def createGroupFromList(self, theSelectionList, theGroupName):     
+        # iterate on all selected entities of the group
+        # and get the corresponding ID
+        aSelectionNum = theSelectionList.size()
+        Ids = []
+        for aSelIndex in range(0, aSelectionNum):
+            aSelection = theSelectionList.value(aSelIndex)
+            aSelectionContext = aSelection.context()
+            anID = aSelection.Id()
+            Ids.append(anID)
+            if aSelection.value().isVertex():
+                groupType = "VERTEX"
+            elif aSelection.value().isEdge():
+                groupType = "EDGE" 
+            elif aSelection.value().isFace():
+                groupType = "FACE"
+            else:
+                groupType = "SOLID"
 
+        # iterate on exported objects and check if the current
+        # group refers to this object
+        for obj in self.geomObjects: 
+            if aSelectionContext.shape().isEqual(obj[0]):
+                aGroup = self.geompy.CreateGroup(obj[1], self.geompy.ShapeType[groupType])
+                self.geompy.UnionIDs(aGroup,Ids)
+                self.geompy.addToStudyInFather(obj[1], aGroup, theGroupName)
+          
     def execute(self):
         # Nothing to execute: all logic would be in the initAttributes
         pass
index ab3768d061faec388f9ac3f4c36f65fddf955581..cab45489b05f4e184edba3bb7adee9b546f02a23 100644 (file)
@@ -1006,3 +1006,20 @@ void Model_AttributeSelection::selectSubShape(const std::string& theType, const
   }
 
 }
+
+int Model_AttributeSelection::Id()
+{
+  std::shared_ptr<GeomAPI_Shape> aSelection = value();
+  std::shared_ptr<GeomAPI_Shape> aContext = context()->shape();
+  const TopoDS_Shape& aMainShape = aContext->impl<TopoDS_Shape>();
+  const TopoDS_Shape& aSubShape = aSelection->impl<TopoDS_Shape>();
+  int anID = 0;
+  if (aSelection && !aSelection->isNull() &&
+      aContext   && !aContext->isNull())
+  {
+    TopTools_IndexedMapOfShape aSubShapesMap;
+    TopExp::MapShapes(aMainShape, aSubShapesMap);
+    anID = aSubShapesMap.FindIndex(aSubShape);
+  }
+  return anID;
+}
index 4ca2ef3db2230fcd79ebd748144f3f6bce4ddf9e..8708c136dc932defde1ecfba2c0761475841ee7f 100644 (file)
@@ -41,6 +41,12 @@ public:
 
   /// Returns a textual string of the selection
   MODEL_EXPORT virtual std::string namingName();
+  
+  /// Returns an Id of the selection
+  /// NOTE: This method has been added for temporary export of groups towards old GEOM
+  /// It should then be removed when a direct use of objects from NewGeom
+  /// will be possible from SMESH module of SALOME.
+  MODEL_EXPORT virtual int Id();
 
   /// Selects (i.e. creates Naming data structure) of sub-shape specifed by textual name
   MODEL_EXPORT virtual void selectSubShape(const std::string& theType, const std::string& theSubShapeName);
index 3778ecdd4d30acc48d75b552e9ebb62df3c67378..fc7675f48b196a8ef2f8a5a251f6a521448e58d4 100644 (file)
@@ -46,6 +46,9 @@ class ModelAPI_AttributeSelection : public ModelAPI_Attribute
 
   /// Returns a textual string of the selection
   virtual std::string namingName() = 0;
+  
+  /// Returns an id of the selection
+  virtual int Id() = 0;
 
 
   /// Selects sub-shape by the textual Name