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
# ===================
interface ATOMGEN_Gen : Engines::EngineComponent, SALOMEDS::Driver
{
- /*!
- Set active study
- */
- void setCurrentStudy(in SALOMEDS::Study theStudy);
-
/*!
Import atomic data from external XML file
*/
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();
};
};
<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>
"""
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
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 ):
"""
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()
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()
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 ):
"""
"""
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)
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
"""
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:
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 ):
return new_mol
- def DumpPython(self, theStudy, isPublished, isMultiFile):
+ def DumpPython(self, isPublished, isMultiFile):
script = []
prefix = ""
if isMultiFile :
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:
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):
"""
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):
"""
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
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
__CMD_RUN_ALGO1__ = 4010
# study data
-__study_data_map__ = {}
+__study_data__ = {}
################################################
# Init GUI wrappers
# create life cycle CORBA instance
lcc = LifeCycleCORBA( orb )
-# get study manager
-obj = naming_service.Resolve( '/myStudyManager' )
-studyManager = obj._narrow( SALOMEDS.StudyManager )
-
################################################
# Internal methods
"""
Prints exception info
"""
- print "Exception has been caught:", e
+ print("Exception has been caught:", e)
pass
def warning( message, title = None ):
# --- 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
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():
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
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 )
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
"""
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
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
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:
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
################################################
Constructor
"""
QDialog.__init__(self, sgPyQt.getDesktop())
- self.setupUi(self)
+ self.setupUi(self)
self.onCheckAll()
self.selected = []
self.selectionChanged()
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:
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(),
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(),
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
################################################