Salome HOME
Merge multi-study removal branch. Before_python3_27062017
authorrnv <rnv@opencascade.com>
Thu, 8 Jun 2017 16:52:35 +0000 (19:52 +0300)
committerrnv <rnv@opencascade.com>
Tue, 13 Jun 2017 10:00:25 +0000 (13:00 +0300)
1  2 
src/PYHELLO/PYHELLO.py
src/PYHELLO/PYHELLO_utils.py
src/PYHELLOGUI/PYHELLOGUI.py

diff --combined src/PYHELLO/PYHELLO.py
index 36aba6d48638167782129d02e702ed2b40745dfa,64d83cd55c1d064ae84a776b015dbbdcbcf915cf..c5540f94e591c8f639146edbc22c048f2ea9403c
mode 100644,100644..100755
@@@ -45,7 -45,7 +45,7 @@@ class PYHELLO(PYHELLO_ORB__POA.PYHELLO_
      def __init__ ( self, orb, poa, contID, containerName, instanceName,
                     interfaceName ):
          SALOME_ComponentPy.SALOME_ComponentPy_i.__init__(self, orb, poa,
 -                    contID, containerName, instanceName, interfaceName, 0)
 +                    contID, containerName, instanceName, interfaceName, False)
          SALOME_DriverPy.SALOME_DriverPy_i.__init__(self, interfaceName)
          #
          self._naming_service = SALOME_ComponentPy.SALOME_NamingServicePy_i( self._orb )
      """
      Create object.
      """
-     def createObject( self, study, name ):
+     def createObject( self, name ):
 -        builder = salome.myStudy.NewBuilder()
++        study = getStudy()
 +        builder = study.NewBuilder()
-         father  = findOrCreateComponent( study )
-         object  = builder.NewObject( father )
-         attr    = builder.FindOrCreateAttribute( object, "AttributeName" )
+         father  = findOrCreateComponent()
 -        object  = builder.NewObject( father )
 -        attr    = builder.FindOrCreateAttribute( object, "AttributeName" )
++        obj  = builder.NewObject( father )
++        attr    = builder.FindOrCreateAttribute( obj, "AttributeName" )
          attr.SetValue( name )
--        attr    = builder.FindOrCreateAttribute( object, "AttributeLocalID" )
++        attr    = builder.FindOrCreateAttribute( obj, "AttributeLocalID" )
          attr.SetValue( objectID() )
          pass
  
      """
      Dump module data to the Python script.
      """
-     def DumpPython( self, study, isPublished, isMultiFile ):
+     def DumpPython( self, isPublished, isMultiFile ):
          abuffer = []
          names = []
 -        father = salome.myStudy.FindComponent( moduleName() )
++        study = getStudy()
 +        father = study.FindComponent( moduleName() )
          if father:
 -            iter = salome.myStudy.NewChildIterator( father )
 +            iter = study.NewChildIterator( father )
              while iter.More():
                  name = iter.Value().GetName()
                  if name: names.append( name )
                  pass
              pass
          if names:
-             abuffer += [ "from salome import lcc" ]
+             abuffer += [ "import salome" ]
              abuffer += [ "import PYHELLO_ORB" ]
              abuffer += [ "" ]
-             abuffer += [ "pyhello = lcc.FindOrLoadComponent( 'FactoryServerPy', '%s' )" % moduleName() ]
+             abuffer += [ "pyhello = salome.lcc.FindOrLoadComponent( 'FactoryServerPy', '%s' )" % moduleName() ]
              abuffer += [ "" ]
-             abuffer += [ "pyhello.createObject( theStudy, '%s' )" % name for name in names ]
+             abuffer += [ "pyhello.createObject( '%s' )" % name for name in names ]
              abuffer += [ "" ]
              pass
          if isMultiFile:
              abuffer       = [ "  " + s for s in abuffer ]
-             abuffer[0:0]  = [ "def RebuildData( theStudy ):" ]
+             abuffer[0:0]  = [ "def RebuildData():" ]
              abuffer      += [ "  pass" ]
          abuffer += [ "\0" ]
          return ("\n".join( abuffer ), 1)
index cb54ac1b82e8143bb2c339dc23490f3b64347fbc,224e0fbeb96666f7441b561b183d1ea32da6cadc..d53d1d8ade3ecacd3309ba0ff7ea0ac2fbf98d03
mode 100644,100644..100755
@@@ -32,13 -32,12 +32,14 @@@ __all__ = 
      "getORB",
      "getNS",
      "getLCC",
-     "getStudyManager",
      "getEngine",
++    "getStudy",
      "getEngineIOR",
      "findOrCreateComponent",
      "getObjectID",
      ]
  
++
  from omniORB import CORBA
  from SALOME_NamingServicePy import SALOME_NamingServicePy_i
  from LifeCycleCORBA import LifeCycleCORBA
@@@ -128,18 -127,6 +129,18 @@@ def getLCC()
          pass
      return __lcc__
  
- # Get study manager
- ###
- __study_manager__ = None
- def getStudyManager():
-     global __study_manager__
-     if __study_manager__ is None:
-         obj = getNS().Resolve( '/myStudyManager' )
-         __study_manager__ = obj._narrow( SALOMEDS.StudyManager )
 +##
-     return __study_manager__
++# Get study
++###
++__study__ = None
++def getStudy():
++    global __study__
++    if __study__ is None:
++      obj = getNS().Resolve( '/Study' )
++        __study__ = obj._narrow( SALOMEDS.Study )
 +        pass
++    return __study__
 +
  ###
  # Get PYHELLO engine
  ###
@@@ -164,10 -151,10 +165,11 @@@ def getEngineIOR()
  ###
  # Find or create PYHELLO component object in a study
  ###
- def findOrCreateComponent( study ):
-     father = study.FindComponent( moduleName() )
+ def findOrCreateComponent():
 -    father = salome.myStudy.FindComponent( moduleName() )
++    study = getStudy()
++    father =study.FindComponent( moduleName() )
      if father is None:
 -        builder = salome.myStudy.NewBuilder()
 +        builder = study.NewBuilder()
          father = builder.NewComponent( moduleName() )
          attr = builder.FindOrCreateAttribute( father, "AttributeName" )
          attr.SetValue( moduleName() )
  ###
  # Get object's ID
  ###
- def getObjectID( study, entry ):
+ def getObjectID( entry ):
      ID = unknownID()
-     if study and entry:
++    study = getStudy()
+     if entry:
 -        sobj = salome.myStudy.FindObjectID( entry )
 +        sobj = study.FindObjectID( entry )
          if sobj is not None:
              test, anAttr = sobj.FindAttribute( "AttributeLocalID" )
              if test: ID = anAttr._narrow( SALOMEDS.AttributeLocalID ).Value()
index 887d43d4ebdd37a26a99801e424105a1e1d7a3a3,708aa7493a8e81eb4a6b81d85b1b226dc639000d..d352ddf85b90e0506f8f264e0bc04d51637608ea
@@@ -31,6 -31,6 +31,8 @@@ from qtsalome import 
  
  from PYHELLO_utils import *
  
++import salome
++
  ################################################
  # GUI context class
  # Used to store actions, menus, toolbars, etc...
@@@ -107,10 -107,6 +109,6 @@@ class GUIcontext
  # Global variables
  ################################################
  
- # study-to-context map
- __study2context__   = {}
- # current context
- __current_context__ = None
  # object counter
  __objectid__ = 0
  
@@@ -130,27 -126,12 +128,12 @@@ sg = libSALOME_Swig.SALOMEGUI_Swig(
  # Internal methods
  ################################################
  
- ###
- # get active study ID
- ###
- def _getStudyId():
-     return sgPyQt.getStudyId()
- ###
- # get active study
- ###
- def _getStudy():
-     studyId = _getStudyId()
-     study = getStudyManager().GetStudyByID( studyId )
-     return study
  ###
  # returns True if object has children
  ###
  def _hasChildren( sobj ):
      if sobj:
-         study = _getStudy()
-         iter  = study.NewChildIterator( sobj )
+         iter  = salome.myStudy.NewChildIterator( sobj )
          while iter.More():
              name = iter.Value().GetName()
              if name:
          pass
      return False
  
- ###
- # get current GUI context
- ###
- def _getContext():
-     global __current_context__
-     return __current_context__
- ###
- # set and return current GUI context
- # study ID is passed as parameter
- ###
- def _setContext( studyID ):
-     global __study2context__, __current_context__
-     if not __study2context__.has_key(studyID):
-         __study2context__[studyID] = GUIcontext()
-         pass
-     __current_context__ = __study2context__[studyID]
-     return __current_context__
  ###
  # increment object counter in the map
  ###
@@@ -194,7 -156,7 +158,7 @@@ def _getSelection()
      selcount = sg.SelectedCount()
      seltypes = {}
      for i in range( selcount ):
-         _incObjToMap( seltypes, getObjectID( _getStudy(), sg.getSelected( i ) ) )
+         _incObjToMap( seltypes, getObjectID( sg.getSelected( i ) ) )
          pass
      return selcount, seltypes
  
  # called when module is initialized
  # perform initialization actions
  def initialize():
-     if verbose() : print "PYHELLOGUI.initialize() : study : %d" % _getStudyId()
+     if verbose() : print "PYHELLOGUI.initialize()"
      # set default preferences values
      if not sgPyQt.hasSetting( "PYHELLO", "def_obj_name"):
          sgPyQt.addSetting( "PYHELLO", "def_obj_name", GUIcontext.DEFAULT_NAME )
  # called when module is initialized
  # return map of popup windows to be used by the module
  def windows():
-     if verbose() : print "PYHELLOGUI.windows() : study : %d" % _getStudyId()
+     if verbose() : print "PYHELLOGUI.windows()"
      wm = {}
      wm[SalomePyQt.WT_ObjectBrowser] = Qt.LeftDockWidgetArea
      wm[SalomePyQt.WT_PyConsole]     = Qt.BottomDockWidgetArea
  # called when module is initialized
  # return list of 2d/3d views to be used ny the module
  def views():
-     if verbose() : print "PYHELLOGUI.views() : study : %d" % _getStudyId()
+     if verbose() : print "PYHELLOGUI.views()"
      return []
  
  # called when module is initialized
  # export module's preferences
  def createPreferences():
-     if verbose() : print "PYHELLOGUI.createPreferences() : study : %d" % _getStudyId()
+     if verbose() : print "PYHELLOGUI.createPreferences()"
      gid = sgPyQt.addPreference( "General" )
      gid = sgPyQt.addPreference( "Object creation", gid )
      pid = sgPyQt.addPreference( "Default name",  gid, SalomePyQt.PT_String,   "PYHELLO", "def_obj_name" )
  # called when module is activated
  # returns True if activating is successfull and False otherwise
  def activate():
-     if verbose() : print "PYHELLOGUI.activate() : study : %d" % _getStudyId()
-     ctx = _setContext( _getStudyId() )
+     if verbose() : print "PYHELLOGUI.activate()"
+     GUIcontext()
      return True
  
  # called when module is deactivated
  def deactivate():
-     if verbose() : print "PYHELLOGUI.deactivate() : study : %d" % _getStudyId()
-     pass
- # called when active study is changed
- # active study ID is passed as parameter
- def activeStudyChanged( studyID ):
-     if verbose() : print "PYHELLOGUI.activeStudyChanged(): study : %d" % studyID
-     ctx = _setContext( _getStudyId() )
+     if verbose() : print "PYHELLOGUI.deactivate()"
      pass
  
  # called when popup menu is invoked
  # popup menu and menu context are passed as parameters
  def createPopupMenu( popup, context ):
      if verbose() : print "PYHELLOGUI.createPopupMenu(): context = %s" % context
-     ctx = _setContext( _getStudyId() )
-     study = _getStudy()
      selcount, selected = _getSelection()
      if verbose() : print selcount, selected
      if selcount == 1:
@@@ -473,25 -426,24 +428,24 @@@ def CreateObject()
          name = "%s %d" % ( default_name, __objectid__ )
          pass
      if not name: return
-     getEngine().createObject( _getStudy(), name )
-     sg.updateObjBrowser( True )
+     getEngine().createObject( name )
+     sg.updateObjBrowser()
      pass
  
  ###
  # Delete all objects
  ###
  def DeleteAll():
-     study = _getStudy()
-     father = study.FindComponent( moduleName() )
+     father = salome.myStudy.FindComponent( moduleName() )
      if father:
-         iter = study.NewChildIterator( father )
-         builder = study.NewBuilder()
+         iter = salome.myStudy.NewChildIterator( father )
+         builder = salome.myStudy.NewBuilder()
          while iter.More():
              sobj = iter.Value()
              iter.Next()
              builder.RemoveObjectWithChildren( sobj )
              pass
-         sg.updateObjBrowser( True )
+         sg.updateObjBrowser()
          pass
      pass
  
  # Show object's name
  ###
  def ShowMe():
-     study = _getStudy()
      entry = sg.getSelected( 0 )
      if entry != '':
-         sobj = study.FindObjectID( entry )
+         sobj = salome.myStudy.FindObjectID( entry )
          if ( sobj ):
              test, attr = sobj.FindAttribute( "AttributeName" )
              if test:
  # Delete selected object(s)
  ###
  def Delete():
-     study = _getStudy()
-     builder = study.NewBuilder()
+     builder = salome.myStudy.NewBuilder()
      if sg.SelectedCount() <= 0: return
      for i in range( sg.SelectedCount() ):
          entry = sg.getSelected( i )
          if entry != '':
-             sobj = study.FindObjectID( entry )
+             sobj = salome.myStudy.FindObjectID( entry )
              if ( sobj ):
                  builder.RemoveObject( sobj )
                  pass
              pass
          pass
-     sg.updateObjBrowser( True )
+     sg.updateObjBrowser()
      pass
  
  ###
  # Rename selected object
  ###
  def Rename():
-     study = _getStudy()
-     builder = study.NewBuilder()
+     builder = salome.myStudy.NewBuilder()
      entry = sg.getSelected( 0 )
      if entry != '':
-         sobj = study.FindObjectID( entry )
+         sobj = salome.myStudy.FindObjectID( entry )
          if ( sobj ):
              name, ok = QInputDialog.getText( sgPyQt.getDesktop(),
                                               "Object name",
              if not ok or not name: return
              attr = builder.FindOrCreateAttribute( sobj, "AttributeName" )
              attr.SetValue( name )
-             sg.updateObjBrowser( True )
+             sg.updateObjBrowser()
              pass
          pass
      pass