Salome HOME
0023299: [CEA] Finalize multi-study removal
authorimn <imn@opencascade.com>
Tue, 18 Oct 2016 13:29:11 +0000 (16:29 +0300)
committerimn <imn@opencascade.com>
Tue, 18 Oct 2016 13:29:11 +0000 (16:29 +0300)
- delete study id parameter

idl/ATOMGEN.idl
src/ATOMGEN/ATOMGEN.py
src/ATOMGENGUI/ATOMGENGUI.py

index dc1c10d513ada4df5c5c5bb72b3b54ad3c1fe468..5a9f331e2c38f3018878fc536cba6163d19f84f9 100644 (file)
@@ -46,11 +46,6 @@ module ATOMGEN_ORB
 
   interface ATOMGEN_Gen : Engines::EngineComponent, SALOMEDS::Driver
   {
-    /*!
-      Set active study
-     */
-    void     setCurrentStudy(in SALOMEDS::Study theStudy);
-
     /*!
       Import atomic data from external XML file
      */
@@ -67,9 +62,9 @@ module ATOMGEN_ORB
     MoleculeList processData(in MoleculeList theData);
 
     /*!
-     Return the data (list of molecules) for given study
+     Return the data (list of molecules)
      */
-     MoleculeList getData(in long studyID);
+     MoleculeList getData();
   };
 };
 
index b5aebe02c6dae1de31a085e3ca9fa96ec65b4bd7..b56c040e4bcd67abc71343c760d3d0f88242ad76 100644 (file)
@@ -63,24 +63,24 @@ class ATOMGEN( ATOMGEN_ORB__POA.ATOMGEN_Gen,
         
         self._naming_service = SALOME_ComponentPy.SALOME_NamingServicePy_i( self._orb )
         self.study = None
-        self.studyData = {}
-        self.entry2PyName = {}
+        self.studyData = None
+        self.entry2PyName = None
         pass
 
     def getVersion( self ):
         import salome_version
         return salome_version.getVersion("ATOMGEN", True)
     
-    def getData( self, studyID ):
+    def getData( self ):
         """
         Gets study data
         """
-        if self.studyData.has_key( studyID ):
+        if self.studyData:
             l = []
-            for m in self.studyData[ studyID ]:
+            for m in self.studyData:
                 l.append( m._this() )
             return l
-        print "ATOMGEN: getData() failed because studyID ", str( studyID ), " was not found"
+        print "ATOMGEN: getData() failed because study was not found"
         return []
 
     def Save( self, component, URL, isMultiFile ):
@@ -99,7 +99,7 @@ class ATOMGEN( ATOMGEN_ORB__POA.ATOMGEN_Gen,
         __entry2IOR__.clear()
         import StringIO, pickle
         study = component.GetStudy()
-        self.setCurrentStudy( study )
+        self.study = study
         iter = study.NewChildIterator(component)
         data = []
         while iter.More():
@@ -157,8 +157,8 @@ class ATOMGEN( ATOMGEN_ORB__POA.ATOMGEN_Gen,
         Called when study is closed
         """
         study = component.GetStudy()
-        if study and self.studyData.has_key( study._get_StudyId() ):
-            del self.studyData[ study._get_StudyId() ]
+        if self.studyData:
+            self.studyData = None
         if study == self.study:
             self.study = None
         pass
@@ -171,15 +171,15 @@ class ATOMGEN( ATOMGEN_ORB__POA.ATOMGEN_Gen,
         """
         return True
 
-    def PublishInStudy( self, study, sobject, object, name ):
+    def PublishInStudy( self, sobject, object, name ):
         """
         Publishes the object in the study.
         """
-        if study and object and object._narrow(ATOMGEN_ORB.Molecule):
-            builder = study.NewBuilder()
+        if self.study and object and object._narrow(ATOMGEN_ORB.Molecule):
+            builder = self.study.NewBuilder()
             builder.NewCommand()
             # get or create component object
-            father = study.FindComponent(self._ComponentDataType)
+            father = self.study.FindComponent(self._ComponentDataType)
             if father is None:
                 builder
                 father = builder.NewComponent(self._ComponentDataType)
@@ -222,18 +222,6 @@ class ATOMGEN( ATOMGEN_ORB__POA.ATOMGEN_Gen,
             return sobject
         return None
 
-    def setCurrentStudy( self, study ):
-        """
-        Sets the active study
-        """
-        self.study = study
-        if self.study and not self.getData( self.study._get_StudyId() ):
-            studyID = self.study._get_StudyId()
-            self.studyData[ studyID ] = []
-            self.entry2PyName[ studyID ] = {}
-            print "ATOMGEN: init new arrays for studyID ", str( studyID ) 
-        pass
-
     def importXmlFile( self, fileName ):
         """
         Imports atomic data from external XML file
@@ -263,8 +251,7 @@ class ATOMGEN( ATOMGEN_ORB__POA.ATOMGEN_Gen,
         """
         if self.study:
             from ATOMGEN_XmlParser import writeXmlFile
-            studyID = self.study._get_StudyId()
-            writeXmlFile( fileName, self.studyData[ studyID ] )
+            writeXmlFile( fileName, self.studyData )
             cmd = __pyEngineName__+ ".exportXmlFile('" + fileName + "')"
             attr = self._getTableAttribute()
             if attr is not None:
@@ -317,17 +304,16 @@ class ATOMGEN( ATOMGEN_ORB__POA.ATOMGEN_Gen,
                 mol.atoms[ i ]._this()
             mol_servant = mol._this()
             if publish :
-                so = self.PublishInStudy(self.study, None, mol_servant, mol_servant.getName())
+                so = self.PublishInStudy(None, mol_servant, mol_servant.getName())
                 if so is not None:
                     entries.append(so.GetID())
         # store data
-        studyID = self.study._get_StudyId()
-        if self.studyData.has_key( studyID ):
-            data = self.studyData[ studyID ]
+        if self.studyData:
+            data = self.studyData
             data += new_data
-            self.studyData[ studyID ] = data
+            self.studyData = data
             return entries
-        print "ATOMGEN: could not append new data because studyID ", str( studyID ), " was not found"
+        print "ATOMGEN: could not append new data"
         return entries
 
     def _translateMolecule( self, mol, i, dx, dy, dz ):
@@ -356,9 +342,9 @@ class ATOMGEN( ATOMGEN_ORB__POA.ATOMGEN_Gen,
         
         if isMultiFile :
             script.append("def RebuildData(theStudy):\n")
-            script.append(prefix+__pyEngineName__ + ".setCurrentStudy(theStudy)\n")
+            script.append(prefix+__pyEngineName__ + ".study=theStudy\n")
         else:
-            script.append(__pyEngineName__ + ".setCurrentStudy(theStudy)\n")
+            script.append(__pyEngineName__ + ".study=theStudy\n")
         
         attr = self._getTableAttribute()
         if attr is not None:
@@ -374,10 +360,9 @@ class ATOMGEN( ATOMGEN_ORB__POA.ATOMGEN_Gen,
         
         all = "\n".join(script)
         self._getPyNames()        
-        studyID = self.study._get_StudyId()
         
-        for k in self.entry2PyName[studyID].keys() :
-            all = all.replace(k,self.entry2PyName[studyID][k])
+        for k in self.entry2PyName.keys() :
+            all = all.replace(k,self.entry2PyName[k])
         
         return (all,1)
     
@@ -407,15 +392,14 @@ class ATOMGEN( ATOMGEN_ORB__POA.ATOMGEN_Gen,
         if self.study is None:
             return
         
-        studyID = self.study._get_StudyId()
-        self.entry2PyName[studyID] = {}
+        self.entry2PyName = None
         iter = self.study.NewChildIterator(self.study.FindComponent(self._ComponentDataType))
         while iter.More():
             sobject = iter.Value()
             iter.Next()            
             found, attr = sobject.FindAttribute("AttributeName")
             if not found: continue
-            self.entry2PyName[studyID][sobject.GetID()] = self._fixPythonName(attr.Value())            
+            self.entry2PyName[sobject.GetID()] = self._fixPythonName(attr.Value())            
             
     def _fixPythonName(self, in_str):
         """
@@ -433,10 +417,8 @@ class ATOMGEN( ATOMGEN_ORB__POA.ATOMGEN_Gen,
             newstring = "mol_1"
 
         if newstring[0] in string.digits:
-            newstring = "a"+newstring
-            
-        studyID = self.study._get_StudyId()
+            newstring = "a"+newstring     
         
-        if newstring in self.entry2PyName[studyID].values():
+        if newstring in self.entry2PyName.values():
            newstring = self._fixPythonName( newstring + "_1")
         return newstring
index ac27bc5d446e4506c00d7c27088f682f8f887938..365005abe8d2d599be631c8c3e7acebeb2bda8c7 100644 (file)
@@ -40,7 +40,7 @@ __CMD_RUN_ALGO__   = 4002
 __CMD_RUN_ALGO1__  = 4010
 
 # study data
-__study_data_map__ = {}
+__study_data__ = None
 
 ################################################
 # Init GUI wrappers
@@ -65,10 +65,6 @@ naming_service = SALOME_NamingServicePy_i( orb )
 # create life cycle CORBA instance
 lcc = LifeCycleCORBA( orb )
 
-# get study manager
-obj = naming_service.Resolve( '/myStudyManager' )
-studyManager = obj._narrow( SALOMEDS.StudyManager )
-
 ################################################
 # Internal methods
 
@@ -107,10 +103,10 @@ def _getEngine():
 # --- get active study ---
 def _getStudy():
     """
-    Gets actuve study
+    Gets study
     """
-    studyId = sgPyQt.getStudyId()
-    study = studyManager.GetStudyByID( studyId )
+    obj = naming_service.Resolve( '/Study' )
+    study = obj._narrow( SALOMEDS.Study )
     return study
 
 myStudy = None
@@ -127,15 +123,11 @@ def initialize():
     initialization
     """
     print "ATOMGENGUI::initialize"
-    global __study_data_map__
-    # get study id
-    studyId = sgPyQt.getStudyId()
-    if not __study_data_map__.has_key( studyId ):
-        __study_data_map__[ studyId ] = {}
+    global __study_data__
     # get selection object
     selection = sgPyQt.getSelection()
     selection.ClearIObjects()
-    __study_data_map__[ studyId ][ "selection" ] = selection
+    __study_data__[ "selection" ] = selection
     print "ATOMGENGUI::initialize done"
     pass
 
@@ -169,23 +161,22 @@ def activate():
     print "ATOMGENGUI::activate"
     # set current study
     global myStudy
-    global __study_data_map__
+    global __study_data__
     myStudy = _getStudy()
-    _getEngine().setCurrentStudy( myStudy )
-    studyId = myStudy._get_StudyId()
+    _getEngine().study = myStudy
 
     # create actions
-    __study_data_map__[ studyId ][ "actions" ] = {}
+    __study_data__[ "actions" ] = {}
     a = sgPyQt.createAction( __CMD_IMPORT_XML__,
                              tr( "MEN_IMPORT_XML" ),
                              tr( "TOP_IMPORT_XML" ),
                              tr( "STB_IMPORT_XML" ) )
-    __study_data_map__[ studyId ][ "actions" ][ __CMD_IMPORT_XML__ ] = a
+    __study_data__[ "actions" ][ __CMD_IMPORT_XML__ ] = a
     a = sgPyQt.createAction( __CMD_EXPORT_XML__,
                              tr( "MEN_EXPORT_XML" ),
                              tr( "TOP_EXPORT_XML" ),
                              tr( "STB_EXPORT_XML" ) )
-    __study_data_map__[ studyId ][ "actions" ][ __CMD_EXPORT_XML__ ] = a
+    __study_data__[ "actions" ][ __CMD_EXPORT_XML__ ] = a
 
     # create menus
     fileMnu = sgPyQt.createMenu( QApplication.translate( "ATOMGENGUI", "MEN_FILE" ), -1, -1 )
@@ -195,7 +186,7 @@ def activate():
     sgPyQt.createMenu( sgPyQt.createSeparator(), fileMnu, -1, 20 )
 
     # connect selection
-    selection = __study_data_map__[ studyId ][ "selection" ]
+    selection = __study_data__[ "selection" ]
     selection.ClearIObjects()
     selection.currentSelectionChanged.connect( selectionChanged )
     global myRunDlg
@@ -211,8 +202,7 @@ def deactivate():
     print "ATOMGENGUI::deactivate"
     # connect selection
     global myStudy
-    studyId = myStudy._get_StudyId()
-    selection = __study_data_map__[ studyId ][ "selection" ]
+    selection = __study_data__[ "selection" ]
     selection.ClearIObjects()
     selection.currentSelectionChanged.disconnect( selectionChanged )
     global myRunDlg
@@ -222,22 +212,6 @@ def deactivate():
     myStudy = None
     pass
 
-def activeStudyChanged( studyId ):
-    """
-    This method is called when active study is chaghed
-    (user switches between studies desktops).
-    <studyId> is an id of study being activated.
-    """
-    print "ATOMGENGUI::activeStudyChanged: study Id =", studyId
-    global myStudy
-    if myStudy and myStudy._get_StudyId() == studyId:
-        return
-    global myRunDlg
-    if myRunDlg:
-        myRunDlg.close()
-        myRunDlg = None
-    pass
-
 def createPopupMenu( popup, context ):
     """
     This method is called when popup menu is requested
@@ -302,7 +276,7 @@ class RunDlg(QDialog, Ui_RunDlg):
         self.acLab.setEnabled( not self.allCheck.isChecked() )
         self.acName.setEnabled( not self.allCheck.isChecked() )
 
-        selection = __study_data_map__[ myStudy._get_StudyId() ][ "selection" ]
+        selection = __study_data__[ "selection" ]
         if not self.allCheck.isChecked():
             selection.currentSelectionChanged.connect(self.selectionChanged)
         else: