]> SALOME platform Git repositories - samples/atomgen.git/commitdiff
Salome HOME
Merge V9_dev branch into master SHAPER_V9_1_0RC1
authorrnv <rnv@opencascade.com>
Wed, 6 Jun 2018 13:02:34 +0000 (16:02 +0300)
committerrnv <rnv@opencascade.com>
Thu, 14 Jun 2018 08:33:56 +0000 (11:33 +0300)
CMakeLists.txt
idl/ATOMGEN.idl
resources/ATOMGENCatalog.xml.in
src/ATOMGEN/ATOMGEN.py [changed mode: 0644->0755]
src/ATOMGEN/ATOMGEN_XmlParser.py
src/ATOMGENGUI/ATOMGENGUI.py [changed mode: 0644->0755]

index bb10010326ce0f7a056cae5a56b2a2c585667387..1b949e6d3f02e516001a7954eb56a71f45cb3475 100755 (executable)
@@ -33,7 +33,7 @@ SET(${PROJECT_NAME_UC}_MINOR_VERSION 5)
 SET(${PROJECT_NAME_UC}_PATCH_VERSION 0)
 SET(${PROJECT_NAME_UC}_VERSION
   ${${PROJECT_NAME_UC}_MAJOR_VERSION}.${${PROJECT_NAME_UC}_MINOR_VERSION}.${${PROJECT_NAME_UC}_PATCH_VERSION})
-SET(${PROJECT_NAME_UC}_VERSION_DEV 1)
+SET(${PROJECT_NAME_UC}_VERSION_DEV 0)
 
 # Common CMake macros
 # ===================
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..04e5d51
@@ -58,12 +58,14 @@ class ATOMGEN( ATOMGEN_ORB__POA.ATOMGEN_Gen,
         """
         SALOME_ComponentPy.SALOME_ComponentPy_i.__init__( self, orb, poa,
                                                           contID, containerName,
-                                                          instanceName, interfaceName, 0 )
+                                                          instanceName, interfaceName, False )
         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,19 +97,17 @@ 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()
-            iter.Next()
+        while iterator.More():
+            sobject = iterator.Value()
+            iterator.Next()
             found, attr = sobject.FindAttribute("AttributeName")
             if not found: continue
             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()
@@ -148,20 +145,15 @@ class ATOMGEN( ATOMGEN_ORB__POA.ATOMGEN_Gen,
     def LocalPersistentIDToIOR(self, sobject, persistentID, isMultiFile, isASCII):
         "Converts persistent ID of the object to its IOR."
         global __entry2IOR__
-        if __entry2IOR__.has_key(persistentID):
+        if persistentID in __entry2IOR__:
             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:
@@ -367,19 +342,18 @@ class ATOMGEN( ATOMGEN_ORB__POA.ATOMGEN_Gen,
                 script.append(s)
         
         if isMultiFile :
-           script.append(prefix+"pass")
-       else:
-           script.append("\n")
-       script.append("\0")
+            script.append(prefix + "pass")
+        else:
+            script.append("\n")
+        script.append("\0")
         
         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 list(self.entry2PyName.keys()) :
+            all = all.replace(k,self.entry2PyName[k])
         
-        return (all,1)
+        return (all.encode(),1)
     
     def _getTableAttribute(self):
         """
@@ -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 list(self.entry2PyName.values()):
            newstring = self._fixPythonName( newstring + "_1")
         return newstring
index 4e468a27b9d65b9418596a7f0cb71297ac50302f..50daf3272df10b551d3e30f431037a96b938e2ec 100644 (file)
@@ -74,7 +74,6 @@ def writeXmlFile( filename, data ):
             atomnode.setAttribute( __z_attr__, str( atom.z ) )
             molnode.appendChild( atomnode )
         docnode.appendChild( molnode )
-    file = open( filename, "w" )
-    file.write( doc.toprettyxml() )
-    file.close()
+    with open(filename, "w") as f:
+        f.write(doc.toprettyxml())
     pass
old mode 100644 (file)
new mode 100755 (executable)
index ac27bc5..d759d3b
@@ -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
 
@@ -82,7 +78,7 @@ def processException( e ):
     """
     Prints exception info
     """
-    print "Exception has been caught:", e
+    print("Exception has been caught:", e)
     pass
 
 def warning( message, title = None ):
@@ -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
@@ -126,17 +122,13 @@ def initialize():
     Creates menus, toolbars and performs other internal
     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 ] = {}
+    print("ATOMGENGUI::initialize")
+    global __study_data__
     # get selection object
     selection = sgPyQt.getSelection()
     selection.ClearIObjects()
-    __study_data_map__[ studyId ][ "selection" ] = selection
-    print "ATOMGENGUI::initialize done"
+    __study_data__[ "selection" ] = selection
+    print("ATOMGENGUI::initialize done")
     pass
 
 def windows():
@@ -146,7 +138,7 @@ def windows():
     Should return a map of the SALOME dockable windows id's
     needed to be opened when module is activated.
     """
-    print "ATOMGENGUI::windows"
+    print("ATOMGENGUI::windows")
     winMap = {}
     winMap[ SalomePyQt.WT_ObjectBrowser ] = Qt.LeftDockWidgetArea
     winMap[ SalomePyQt.WT_PyConsole ]     = Qt.BottomDockWidgetArea
@@ -159,33 +151,32 @@ def views():
     Should return a list of the SALOME view window types
     needed to be opened when module is activated.
     """
-    print "ATOMGENGUI::views"
+    print("ATOMGENGUI::views")
     return None
 
 def activate():
     """
     This method is called when GUI module is being activated.
     """
-    print "ATOMGENGUI::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
@@ -208,11 +199,10 @@ def deactivate():
     """
     This method is called when GUI module is being deactivated.
     """
-    print "ATOMGENGUI::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
@@ -245,7 +219,7 @@ def createPopupMenu( popup, context ):
     Should analyze the selection and fill in the popup menu
     with the corresponding actions
     """
-    print "ATOMGENGUI::createPopupMenu: popup =", popup, "; context =", context
+    print("ATOMGENGUI::createPopupMenu: popup =", popup, "; context =", context)
     selected = selectedItems()
     isOk = False
     for entry in selected:
@@ -265,14 +239,14 @@ def OnGUIEvent( commandId ):
     This method is called when user activates some GUI action
     <commandId> is an ID of the GUI action.
     """
-    print "ATOMGENGUI::OnGUIEvent: commandId =", commandId
-    if dict_command.has_key( commandId ):
+    print("ATOMGENGUI::OnGUIEvent: commandId =", commandId)
+    if commandId in dict_command:
         try:
             dict_command[ commandId ]()
-        except Exception, e:
+        except Exception as e:
             processException( e )
     else:
-       print "ATOMGENGUI::OnGUIEvent: Action is not implemented: ", commandId
+       print("ATOMGENGUI::OnGUIEvent: Action is not implemented: ", commandId)
     pass
 
 ################################################
@@ -289,7 +263,7 @@ class RunDlg(QDialog, Ui_RunDlg):
         Constructor
         """
         QDialog.__init__(self, sgPyQt.getDesktop())
-       self.setupUi(self)
+        self.setupUi(self)
         self.onCheckAll()
         self.selected = []
         self.selectionChanged()
@@ -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:
@@ -379,14 +353,14 @@ def selectionChanged():
     Global selection changed slot
     """
     selected = selectedItems()
-    print "--> Selected objects: %d"%len(selected)
+    print("--> Selected objects: %d"%len(selected))
     pass
 
 def onImportXml():
     """
     Import XML file action slot
     """
-    print "--> onImportXml() is started"
+    print("--> onImportXml() is started")
     filters = []
     filters.append( tr( "XML_FILES" ) )
     fileName = sgPyQt.getFileName( sgPyQt.getDesktop(),
@@ -394,21 +368,21 @@ def onImportXml():
                                    filters,
                                    tr( "IMPORT_XML" ),
                                    True )
-    fileName = unicode(fileName)
+    fileName = str(fileName)
 
     if len(fileName) > 0 :
         if not _getEngine().importXmlFile( str( fileName ) ):
             warning( "IMPORT_ERROR" )
         else:
             sgPyQt.updateObjBrowser()
-    print "--> onImportXml() is finished"
+    print("--> onImportXml() is finished")
     pass
 
 def onExportXml():
     """
     Export XML file action slot
     """
-    print "--> onExportXml() is started"
+    print("--> onExportXml() is started")
     filters = []
     filters.append( tr( "XML_FILES" ) )
     fileName = sgPyQt.getFileName( sgPyQt.getDesktop(),
@@ -416,23 +390,23 @@ def onExportXml():
                                    filters,
                                    tr( "EXPORT_XML" ),
                                    False )
-    fileName = unicode(fileName)
+#     fileName = str(fileName)
 
     if len(fileName) > 0 :
-        if not _getEngine().exportXmlFile( str( fileName ) ):
+        if not _getEngine().exportXmlFile(fileName):
             warning( "EXPORT_ERROR" )
-    print "--> onExportXml() is finished"
+    print("--> onExportXml() is finished")
     pass
 
 def onRunAlgo():
-    print "--> onRunAlgo() is started !!!"
+    print("--> onRunAlgo() is started !!!")
     global myRunDlg
     if not myRunDlg:
         myRunDlg = RunDlg()
     myRunDlg.show()
     myRunDlg.activateWindow()
     myRunDlg.setFocus()
-    print "--> onRunAlgol() is finished"
+    print("--> onRunAlgol() is finished")
     pass
 
 ################################################