Salome HOME
Make the SHAPERSTUDY python dump works on SHAPER objects stable, even after modificat...
authormpv <mpv@opencascade.com>
Wed, 12 Feb 2020 13:09:23 +0000 (16:09 +0300)
committermpv <mpv@opencascade.com>
Wed, 12 Feb 2020 13:09:23 +0000 (16:09 +0300)
idl/SHAPERSTUDY_Gen.idl
src/PY/SHAPERSTUDY.py

index fd9e2cc13dec0c0a5a41612279fb9757cb5cf387..9d5d5a34365f7ff464573e16caaa2771c6f3121a 100644 (file)
@@ -101,6 +101,11 @@ interface Gen : GEOM::GEOM_Gen
    *  \brief Searches existing or creates a new SHAPERSTUDY_Object to interact with SHAPER
    */
   SHAPER_Object FindOrCreateShape(in string theInternalEntry);
+
+  /*!
+  *  \brief Stores the variable names of the SHAPER dump to python
+  */
+  void StoreVariableName(in string theEntry, in string theVarName);
 };
 
 interface IShapesOperations : GEOM::GEOM_IShapesOperations
index 3380a40e34b05de80195d8d0a6032192fd20659a..e070b0005346f69e8f68cc25ea6d35d6fdf78aab 100644 (file)
@@ -143,6 +143,13 @@ class SHAPERSTUDY(SHAPERSTUDY_ORB__POA.Gen,
 
         return aResultSO
 
+    def StoreVariableName(self, theEntry, theVarName):
+        """
+        Stores the variable names of the SHAPER dump to python
+        """
+        __entry2DumpName__["s" + theEntry] = theVarName
+
+
     def AddSubShape( theMainShape, theIndices ):
         """
         Add a sub-shape defined by indices in theIndices
@@ -361,13 +368,29 @@ class SHAPERSTUDY(SHAPERSTUDY_ORB__POA.Gen,
         __entry2DumpName__[theID] = aName
         return aName
 
+    def GetShaperEntry(self, theShapeObj):
+        """
+        Returns string in the python dump that generates the SHAPER entry:
+        it may be just entry string, or call for the SHAPER dump variable.
+        """
+        global __entry2DumpName__
+        anEntry = "s" + theShapeObj.GetEntry()
+        if anEntry in __entry2DumpName__:
+          return "model.featureStringId(" + __entry2DumpName__[anEntry] + ")"
+        return "\"" + theShapeObj.GetEntry() + "\""
 
     def DumpPython( self, isPublished, isMultiFile ):
         """
         Dump module data to the Python script.
         """
         global __entry2DumpName__
-        __entry2DumpName__.clear()
+        # remove all non-SHAPER entries
+        aCopyMap = {}
+        for anEntry in __entry2DumpName__:
+          if anEntry.startswith("s"):
+            aCopyMap[anEntry] = __entry2DumpName__[anEntry]
+        __entry2DumpName__ = aCopyMap
+
         anArchiveNum = 1
         # collect all shape-objects in the SHAPERSTUDY tree
         aShapeObjects = []
@@ -404,7 +427,7 @@ class SHAPERSTUDY(SHAPERSTUDY_ORB__POA.Gen,
             aShapeStr = aShapeVar + ", "
             for aGName in aGroupVarNames:
               aShapeStr += aGName + ", "
-            aShapeStr += "= SHAPERSTUDY.shape(\"" + aShapeObj.GetEntry() +"\")"
+            aShapeStr += "= SHAPERSTUDY.shape(" + self.GetShaperEntry(aShapeObj) +")"
             script.append(aShapeStr)
             # dump also dead-shapes with groups and fields in the XAO format
             aRes, aHistSO = aShapeObj.GetSO().FindSubObject(2) # the History folder