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
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()
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()
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:
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)
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 self.entry2PyName.values():
newstring = self._fixPythonName( newstring + "_1")
return newstring
__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
# --- 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
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
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
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
"""
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
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: