]> SALOME platform Git repositories - samples/atomgen.git/commitdiff
Salome HOME
Merge multi-study removal branch. Before_python3_27062017
authorrnv <rnv@opencascade.com>
Fri, 9 Jun 2017 10:24:08 +0000 (13:24 +0300)
committerrnv <rnv@opencascade.com>
Tue, 13 Jun 2017 09:55:14 +0000 (12:55 +0300)
idl/ATOMGEN.idl
resources/ATOMGENCatalog.xml.in
src/ATOMGEN/ATOMGEN.py [changed mode: 0644->0755]
src/ATOMGENGUI/ATOMGENGUI.py [changed mode: 0644->0755]

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 5fbdf14c26c9dd210faff26579aa206ca247b65b..7d0efef1472babd85521e3f07daaef344485bedf 100644 (file)
@@ -39,7 +39,6 @@
                 <component-author>SALOME team</component-author>
                 <component-version>@SALOMEATOMGEN_VERSION@</component-version>
                 <component-comment>Sample Python-based component</component-comment>
-                <component-multistudy>1</component-multistudy>
                 <component-icone>ATOMGEN.png</component-icone>
                 <constraint>'linux' ~ OS</constraint>
        
old mode 100644 (file)
new mode 100755 (executable)
index b5aebe0..58e5a38
@@ -61,9 +61,11 @@ class ATOMGEN( ATOMGEN_ORB__POA.ATOMGEN_Gen,
                                                           instanceName, interfaceName, 0 )
         SALOME_DriverPy.SALOME_DriverPy_i.__init__( self, interfaceName )
         
+        self._orb = orb
         self._naming_service = SALOME_ComponentPy.SALOME_NamingServicePy_i( self._orb )
-        self.study = None
-        self.studyData = {}
+        obj = self._naming_service.Resolve( '/Study' )
+        self.study = obj._narrow( SALOMEDS.Study )
+        self.studyData = []
         self.entry2PyName = {}
         pass
 
@@ -71,17 +73,14 @@ class ATOMGEN( ATOMGEN_ORB__POA.ATOMGEN_Gen,
         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 ):
-            l = []
-            for m in self.studyData[ studyID ]:
-                l.append( m._this() )
-            return l
-        print "ATOMGEN: getData() failed because studyID ", str( studyID ), " was not found"
-        return []
+        l = []
+        for m in self.studyData:
+            l.append( m._this() )
+        return l
 
     def Save( self, component, URL, isMultiFile ):
         """
@@ -98,9 +97,7 @@ class ATOMGEN( ATOMGEN_ORB__POA.ATOMGEN_Gen,
         global __entry2IOR__
         __entry2IOR__.clear()
         import StringIO, pickle
-        study = component.GetStudy()
-        self.setCurrentStudy( study )
-        iter = study.NewChildIterator(component)
+        iter = self.study.NewChildIterator(component)
         data = []
         while iter.More():
             sobject = iter.Value()
@@ -110,7 +107,7 @@ class ATOMGEN( ATOMGEN_ORB__POA.ATOMGEN_Gen,
             from ATOMGEN_Data import Molecule, Atom
             mol = Molecule(attr.Value())
             __entry2IOR__[sobject.GetID()] = ObjectToString(mol._this())
-            iter1 = study.NewChildIterator(sobject)
+            iter1 = self.study.NewChildIterator(sobject)
             while iter1.More():
                 sobject1 = iter1.Value()
                 iter1.Next()
@@ -118,7 +115,7 @@ class ATOMGEN( ATOMGEN_ORB__POA.ATOMGEN_Gen,
                 if not found: continue
                 name = attr.Value()
                 x = y = z = None
-                iter2 = study.NewChildIterator(sobject1)
+                iter2 = self.study.NewChildIterator(sobject1)
                 while iter2.More():
                     sobject2 = iter2.Value()
                     iter2.Next()
@@ -152,16 +149,11 @@ class ATOMGEN( ATOMGEN_ORB__POA.ATOMGEN_Gen,
             return __entry2IOR__[persistentID]
         return ""
 
-    def Close( self, component ):
+    def Close( self ):
         """
         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 study == self.study:
-            self.study = None
-        pass
+        self.studyData = []
 
     def CanPublishInStudy( self, IOR ):
         """
@@ -171,15 +163,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 +214,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 +243,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 +296,13 @@ 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 ]
-            data += new_data
-            self.studyData[ studyID ] = data
-            return entries
-        print "ATOMGEN: could not append new data because studyID ", str( studyID ), " was not found"
+        data = self.studyData
+        data += new_data
+        self.studyData = data
         return entries
 
     def _translateMolecule( self, mol, i, dx, dy, dz ):
@@ -344,7 +319,7 @@ class ATOMGEN( ATOMGEN_ORB__POA.ATOMGEN_Gen,
         return new_mol
 
 
-    def DumpPython(self, theStudy, isPublished, isMultiFile):
+    def DumpPython(self, isPublished, isMultiFile):
         script = []
         prefix = ""
         if isMultiFile :
@@ -355,10 +330,10 @@ class ATOMGEN( ATOMGEN_ORB__POA.ATOMGEN_Gen,
         script.append(__pyEngineName__ + " = salome.lcc.FindOrLoadComponent(\"FactoryServerPy\", \"ATOMGEN\")")
         
         if isMultiFile :
-            script.append("def RebuildData(theStudy):\n")
-            script.append(prefix+__pyEngineName__ + ".setCurrentStudy(theStudy)\n")
+            script.append("def RebuildData():\n")
+            script.append(prefix+__pyEngineName__ + ".study=salome.myStudy\n")
         else:
-            script.append(__pyEngineName__ + ".setCurrentStudy(theStudy)\n")
+            script.append(__pyEngineName__ + ".study=salome.myStudy\n")
         
         attr = self._getTableAttribute()
         if attr is not None:
@@ -374,10 +349,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 +381,14 @@ class ATOMGEN( ATOMGEN_ORB__POA.ATOMGEN_Gen,
         if self.study is None:
             return
         
-        studyID = self.study._get_StudyId()
-        self.entry2PyName[studyID] = {}
+        self.entry2PyName = {}
         iter = self.study.NewChildIterator(self.study.FindComponent(self._ComponentDataType))
         while iter.More():
             sobject = iter.Value()
-            iter.Next()            
+            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 +406,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
old mode 100644 (file)
new mode 100755 (executable)
index ac27bc5..ebfd4ae
@@ -40,7 +40,7 @@ __CMD_RUN_ALGO__   = 4002
 __CMD_RUN_ALGO1__  = 4010
 
 # study data
-__study_data_map__ = {}
+__study_data__ = {}
 
 ################################################
 # 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()
 
     # 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
@@ -267,10 +241,10 @@ def OnGUIEvent( commandId ):
     """
     print "ATOMGENGUI::OnGUIEvent: commandId =", commandId
     if dict_command.has_key( commandId ):
-        try:
-            dict_command[ commandId ]()
-        except Exception, e:
-            processException( e )
+#        try:
+         dict_command[ commandId ]()
+#        except Exception, e:
+#            processException( e )
     else:
        print "ATOMGENGUI::OnGUIEvent: Action is not implemented: ", commandId
     pass
@@ -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: