Salome HOME
Preparation of 3.1.0a2: merge with BR_3_0_0_OCC ForTest_3_1_0a2
authorsmh <smh@opencascade.com>
Tue, 18 Oct 2005 15:32:28 +0000 (15:32 +0000)
committersmh <smh@opencascade.com>
Tue, 18 Oct 2005 15:32:28 +0000 (15:32 +0000)
INSTALL [new file with mode: 0644]
adm_local/unix/make_commence.in
bin/VERSION
configure.in.base
idl/PYHELLO_Gen.idl
resources/PYHELLOCatalog.xml
resources/PYHELLO_en.xml
src/PYHELLO/PYHELLO.py
src/PYHELLOGUI/PYHELLOGUI.py

diff --git a/INSTALL b/INSTALL
new file mode 100644 (file)
index 0000000..f2f050c
--- /dev/null
+++ b/INSTALL
@@ -0,0 +1,4 @@
+This is the version 3.1.0a2 of PYHELLO (SALOME 2 EXAMPLE MODULE)
+Compatible with :
+       - KERNEL 3.1.0a2
+        - GUI 3.1.0a2
index ee4c6fc551b41a1c6b4148182eed4cd72b3da7bd..623267d618e251d9346bb8fce71c416956700311 100644 (file)
@@ -61,6 +61,9 @@ QT_MT_LIBS = @QT_MT_LIBS@
 MOC = @MOC@
 UIC = @UIC@
 
+# msg2qm
+
+MSG2QM = @MSG2QM@
 
 #QWT
 
@@ -242,8 +245,7 @@ ac_cxx_mutable.m4                 check_mico.m4      libtool.m4             \
 ac_cxx_namespaces.m4              check_omniorb.m4   pyembed.m4                \
 ac_cxx_partial_specialization.m4  check_opengl.m4    python.m4         \
 ac_cxx_typename.m4                check_pthreads.m4  check_cas.m4      \
-ac_cc_warnings.m4                 check_qt.m4        check_med2.m4      \
-check_swig.m4 
+ac_cc_warnings.m4                 check_qt.m4        check_swig.m4 
 
 $(top_srcdir)/aclocal.m4: $(ACLOCAL_SRC:%=@KERNEL_ROOT_DIR@/salome_adm/unix/config_files/%)
        cd $(top_srcdir) ; aclocal --acdir=adm_local/unix/config_files -I @KERNEL_ROOT_DIR@/salome_adm/unix/config_files
index 1b3a8c6be52056612b2ce1671743b3acf00c919a..4f4c6b200ab54362f2fb1223b7943ed45921a42e 100755 (executable)
@@ -1,2 +1 @@
-SALOME 2 EXAMPLE MODULE : PYHELLO : 2.2.4
-This module works with KERNEL 2.2.4
+THIS IS SALOME - PYHELLO VERSION: 3.1.0a1
index 151b274816ce9a9eaf24a51305b1bd54d3b51b21..9eaef0a03b5ce2536dc1897c896cf754b8c87c73 100644 (file)
@@ -115,6 +115,14 @@ AC_SUBST_FILE(CORBA)
 corba=make_$ORB
 CORBA=adm_local/unix/$corba
 
+echo
+echo ---------------------------------------------
+echo testing msg2qm
+echo ---------------------------------------------
+echo
+
+CHECK_MSG2QM
+
 echo
 echo ---------------------------------------------
 echo Testing Kernel
@@ -130,7 +138,7 @@ echo ---------------------------------------------
 echo
 
 echo Configure
-variables="python_ok omniORB_ok Kernel_ok"
+variables="python_ok omniORB_ok msg2qm_ok Kernel_ok"
 
 for var in $variables
 do
index 875732082bc4657e1e2b2eaaff8d601b8d99a873..603ad160b9380a41f9bf371e89e67c591eaf7753 100644 (file)
@@ -2,11 +2,12 @@
 #define __PYHELLO_GEN__
 
 #include "SALOME_Component.idl"
+#include "SALOMEDS.idl"
 #include "SALOME_Exception.idl"
 
 module PYHELLO_ORB
 {
-  interface PYHELLO_Gen : Engines::Component
+  interface PYHELLO_Gen : Engines::Component, SALOMEDS::Driver
   {
      string makeBanner(in string name)
          raises (SALOME::SALOME_Exception);
@@ -14,4 +15,3 @@ module PYHELLO_ORB
 };
 
 #endif
-
index eaae032c3ca864652accbc5fde1fee1bfd90e319..f22729e60151ab1e69f781d2ab2d8f8a1d0eac9f 100644 (file)
@@ -16,7 +16,7 @@
                <component-username>PYHELLO GUI</component-username>
                 <component-type>Data</component-type>
                 <component-author>C. Caremoli</component-author>
-                <component-version>2.2.4</component-version>
+                <component-version>3.1.0a</component-version>
                 <component-comment>EDF - RD</component-comment>
                 <component-multistudy>1</component-multistudy>
                 <component-icone>PYHELLO.png</component-icone>
index 048c1911f48e45d825ad04e88d023f8d40d700d2..72070e338aab19a854649fc75713ec7151da9d50 100644 (file)
@@ -2,16 +2,31 @@
 <!DOCTYPE application PUBLIC "" "desktop.dtd">
 <application title="PYHELLO component" date="9/12/2001" author="C Caremoli" appId="PYHELLO" >
 <desktop>
+
 <!-- ### MENUBAR ###  -->
 <menubar>
  <menu-item label-id="PYHELLO" item-id="90" pos-id="3">
-  <popup-item item-id="941" label-id="Lancer IHM" icon-id="" tooltip-id="Lancer IHM PYHELLO" accel-id="" toggle-id="" execute-action=""/>
+  <popup-item item-id="941" label-id="HELLO" icon-id="" tooltip-id="Shows sample dialog box" accel-id="" toggle-id="" execute-action=""/>
+  <separator/>
+  <popup-item item-id="942" label-id="Create object" icon-id="" tooltip-id="Creates and publishes an object" accel-id="" toggle-id="" execute-action=""/>
  </menu-item>
 </menubar>
-<!-- ### TOOLBAR ###  -->
+
+<!-- ### TOOLBARS ###  -->
 <toolbar label-id="PYHELLO">
- <toolbutton-item item-id="941" label-id="Lancer IHM" icon-id="ExecPYHELLO.png" tooltip-id="Lancer IHM PYHELLO" accel-id="" toggle-id="" execute-action=""/>
+ <toolbutton-item item-id="941" label-id="HELLO" icon-id="ExecPYHELLO.png" tooltip-id="Shows sample dialog box" accel-id="" toggle-id="" execute-action=""/>
 </toolbar>
+
+<!-- ### POPUP MENUS ###  -->
+<popupmenu label-id="Popup for ObjectBrowser" context-id="ObjectBrowser" parent-id="" object-id="1000">
+   <popup-item item-id="951" pos-id="" label-id="Delete all" icon-id="" tooltip-id="Removes all children" accel-id="" toggle-id="" execute-action=""/>
+</popupmenu>
+
+<popupmenu label-id="Popup for ObjectBrowser" context-id="ObjectBrowser" parent-id="" object-id="1010">
+   <popup-item item-id="952" pos-id="" label-id="Show me" icon-id="" tooltip-id="Shows an object's name" accel-id="" toggle-id="" execute-action=""/>
+   <popup-item item-id="953" pos-id="" label-id="Delete me" icon-id="" tooltip-id="Removes an object from the study" accel-id="" toggle-id="" execute-action=""/>
+</popupmenu>
+
 </desktop>
 </application>
 
index f27c680b4bb5017e20da85c7ba3f5df9994adb0d..527fa8064f2f7714c47278cfc1ca719d27530b1e 100644 (file)
@@ -1,8 +1,10 @@
 import PYHELLO_ORB__POA
 import SALOME_ComponentPy
+import SALOME_DriverPy
 
 class PYHELLO(PYHELLO_ORB__POA.PYHELLO_Gen,
-              SALOME_ComponentPy.SALOME_ComponentPy_i):
+              SALOME_ComponentPy.SALOME_ComponentPy_i,
+              SALOME_DriverPy.SALOME_DriverPy_i):
     """
         Pour etre un composant SALOME cette classe Python
         doit avoir le nom du composant et heriter de la
@@ -10,16 +12,16 @@ class PYHELLO(PYHELLO_ORB__POA.PYHELLO_Gen,
         par omniidl et de la classe SALOME_ComponentPy_i
         qui porte les services generaux d'un composant SALOME
     """
-    def __init__ (self, orb, poa, contID, containerName, instanceName, 
-                  interfaceName):
-        print "PYHELLO.__init__: ",containerName,' ',instanceName
+    def __init__ ( self, orb, poa, contID, containerName, instanceName, 
+                   interfaceName ):
+        print "PYHELLO.__init__: ", containerName, ';', instanceName
         SALOME_ComponentPy.SALOME_ComponentPy_i.__init__(self, orb, poa,
-                    contID, containerName,instanceName, interfaceName, 0 )
+                    contID, containerName, instanceName, interfaceName, 0)
+        SALOME_DriverPy.SALOME_DriverPy_i.__init__(self, interfaceName)
         # On stocke dans l'attribut _naming_service, une reference sur
         # le Naming Service CORBA
-        self._naming_service=SALOME_ComponentPy.SALOME_NamingServicePy_i(self._orb)
+        self._naming_service = SALOME_ComponentPy.SALOME_NamingServicePy_i( self._orb )
 
-    def makeBanner(self,name):
-        banner= "Hello %s" % name
+    def makeBanner( self, name ):
+        banner = "Hello %s!" % name
         return banner
-
index 5c5c8245caee4bb1ffd9b9d827a119a822a7f7c3..79201a6dd795e525ce3a85b330fbe845a576182e 100644 (file)
-import qt
 from qt import *
 import traceback
 
-# Global variable to store Salome Workspace
-WORKSPACE=None
+from omniORB import CORBA
+from SALOME_NamingServicePy import *
+from LifeCycleCORBA import *
+import SALOMEDS
+import SALOMEDS_Attributes_idl
 
+################################################
+# module name
+__MODULE_NAME__ = "PYHELLO"
+__MODULE_ID__   = 1000
+__OBJECT_ID__   = 1010
+################################################
+
+# Get SALOME PyQt interface
 import SalomePyQt
-# Communication with Salome : desktop, signal and slots
 sgPyQt=SalomePyQt.SalomePyQt()
-desktop=sgPyQt.getDesktop()
 
-# LifeCycle and component PYHELLO
-import salome
-lifecycle = salome.lcc
-import PYHELLO_ORB
-pyhello=lifecycle.FindOrLoadComponent("FactoryServerPy", "PYHELLO")
+# Get SALOME Swig interface
+import libSALOME_Swig
+sg = libSALOME_Swig.SALOMEGUI_Swig()
 
-def setWorkSpace(pyws):
-    global WORKSPACE
-    print "setWorkSpace: ",pyws
-    WORKSPACE=pyws
+################################################
 
-def OnGUIEvent(commandID) :
-    print "PYHELLOGUI::OnGUIEvent::commandID,WORKSPACE= ",commandID,WORKSPACE
-    if dict_command.has_key(commandID):
-       try:
-          r=dict_command[commandID](WORKSPACE)
-          print r
-       except:
-          traceback.print_exc()
-    else:
-       print "Pas de commande associĆ©e a : ",commandID
+# init ORB
+orb = CORBA.ORB_init( [''], CORBA.ORB_ID )
+
+# create naming service instance
+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
 
+# --- get PYHELLO engine ---
+def _getEngine():
+    import PYHELLO_ORB
+    engine = lcc.FindOrLoadComponent( "FactoryServerPy", __MODULE_NAME__ )
+    return engine
+
+# --- get active study ---
+def _getStudy():
+    studyId = sgPyQt.getStudyId()
+    study = studyManager.GetStudyByID( studyId )
+    return study
+    
+# --- returns 1 if object has children ---
+def _hasChildren( sobj ):
+    if sobj:
+        study = _getStudy()
+        iter  = study.NewChildIterator( sobj )
+        while iter.More():
+            name = iter.Value().GetName()
+            if name:
+                return 1
+            iter.Next()
+    return 0
+
+# --- finds or creates component object ---
+def _findOrCreateComponent():
+    study = _getStudy()
+    father = study.FindComponent( __MODULE_NAME__ )
+    if father is None:
+        builder = study.NewBuilder()
+        father = builder.NewComponent( __MODULE_NAME__ )
+        attr = builder.FindOrCreateAttribute( father, "AttributeName" )
+        attr.SetValue( __MODULE_NAME__ )
+        attr = builder.FindOrCreateAttribute( father, "AttributeLocalID" )
+        attr.SetValue( __MODULE_ID__ )
+        try:
+            ### The following line is commented because it causes crashes ! ###
+            ### builder.DefineComponentInstance( father, _getEngine() )
+            pass
+        except:
+            pass
+    return father
+    
+################################################
+# Callback functions
+
+# set workspace (obsolete method, not used)
+def setWorkSpace( pyws ):
+    print "PYHELLOGUI::setWorkSpace : ", pyws
+    pass
+
+# called when module is activated
 def setSettings():
-    print "setSettings"
-
-def activeStudyChanged(ID):
-    print "activeStudyChanged: ",ID
-
-def definePopup(theContext, theObject, theParent):
-    print "PYHELLOGUI --- definePopup: ",theContext,theObject,theParent
-
-def customPopup(popup, theContext, theObject, theParent):
-    print "PYHELLOGUI --- customPopup: ",theContext,theObject,theParent
-
-class MyDialog(qt.QDialog):
-      def __init__(self,parent=None, name=None, modal=0, flags=0):
-          qt.QDialog.__init__(self,parent, name, modal, flags)
-          self.vb = qt.QVBoxLayout(self, 8)
-          self.vb.setAutoAdd(1)
-          self.hb0 = qt.QHBox(self)
-          label=QLabel("Prenom",self.hb0)
-          self.entry=QLineEdit( self.hb0)
-
-          self.hb = qt.QHBox(self)
-          c = qt.QPushButton("OK", self.hb)
-          self.connect(c, qt.SIGNAL('clicked()'), self, SLOT('accept()'))
-          d = qt.QPushButton("CANCEL", self.hb)
-          self.connect(d, qt.SIGNAL('clicked()'), self, SLOT('reject()'))
-
-def ExecPYHELLO(ws):
-    # Modal dialog, parent desktop
-    w=MyDialog(desktop,"Name",1)
-    # Wait answer
-    r=w.exec_loop()
-    if r == QDialog.Accepted:
-       name=str(w.entry.text())
-       banner=pyhello.makeBanner(name)
-       QMessageBox.about(desktop,'Salome Example',banner)
+    print "PYHELLOGUI::setSettings"
+    pass
+
+# called when active study is changed
+def activeStudyChanged( studyID ):
+    print "PYHELLOGUI::activeStudyChanged: study ID =", studyID
+    pass
+
+# define popup menu
+def definePopup( context, object, parent ):
+    object = ""
+    parent = ""
+
+    study = _getStudy()
+    if sg.SelectedCount() == 1:
+        entry = sg.getSelected( 0 )
+        if entry != '':
+            sobj = study.FindObjectID( entry )
+            if sobj is not None:
+                test, anAttr = sobj.FindAttribute( "AttributeLocalID" )
+                if test :
+                    id = anAttr._narrow( SALOMEDS.AttributeLocalID ).Value()
+                    if ( id >= 0 ):
+                        object = str( id )
+    print "PYHELLOGUI::definePopup :", context, object, parent
+    return context, object, parent
+
+# customize popup menu
+def customPopup( popup, context, object, parent ):
+    print "PYHELLOGUI::customPopup :", context, object, parent
+    id = int( object )
+    if id == __MODULE_ID__:
+        study = _getStudy()
+        if sg.SelectedCount() == 1:
+            entry = sg.getSelected( 0 )
+            if entry != '':
+                sobj = study.FindObjectID( entry )
+                if sobj and not _hasChildren( sobj ):
+                    popup.removeItem( 951 ) # remove 'Delete All' command
+    pass
+
+# process GUI action
+def OnGUIEvent(commandID) :
+    print "PYHELLOGUI::OnGUIEvent : commandID =",commandID
+    if dict_command.has_key( commandID ):
+        try:
+            dict_command[commandID]()
+        except:
+            traceback.print_exc()
     else:
-       print "CANCEL"
+       print "The command is not implemented: ",commandID
+
+################################################
+# GUI actions implementation
+
+# ----------------------- #
+# Sample dialog box
+# ----------------------- #
+class MyDialog( QDialog ):
+    # constructor
+    def __init__( self, parent = None, modal = 0):
+        QDialog.__init__( self, parent, "MyDialog", modal )
+        self.setCaption( "HELLO!" )
+        vb = QVBoxLayout( self, 8 )
+        vb.setAutoAdd( 1 )
+        hb0 = QHBox( self )
+        label = QLabel( "Prenom: ", hb0 )
+        self.entry = QLineEdit( hb0 )
+        self.entry.setMinimumWidth( 200 )
+        
+        hb1 = QHBox( self )
+        bOk = QPushButton( "&OK", hb1 )
+        self.connect( bOk, SIGNAL( 'clicked()' ), self, SLOT( 'accept()' ) )
+        dummy = QWidget( hb1 )
+        bCancel = QPushButton( "&Cancel", hb1 )
+        self.connect( bCancel, SIGNAL( 'clicked()' ), self, SLOT( 'close()' ) )
+        hb1.setStretchFactor( dummy, 10 )
+        pass
+    
+    # OK button slot
+    def accept( self ):
+        name = str( self.entry.text() )
+        if name != "":
+            banner = _getEngine().makeBanner( name )
+            QMessageBox.information( self, 'Info', banner )
+            self.close()
+        else:
+            QMessageBox.warning( self, 'Error!', 'Please, enter the name!' )
+        pass
+
+# ----------------------- #
+def ShowHELLO():
+    # create dialog box
+    d = MyDialog( sgPyQt.getDesktop(), 1 )
+    # show dialog box
+    d.exec_loop()
+
+__id__ = 0
+
+# ----------------------- #
+def CreateObject():
+    global __id__
+    study   = _getStudy()
+    builder = study.NewBuilder()
+    father  = _findOrCreateComponent()
+    object  = builder.NewObject( father )
+    attr    = builder.FindOrCreateAttribute( object, "AttributeName" )
+    __id__  = __id__ + 1
+    attr.SetValue( "Object " +  str( __id__ ) )
+    attr    = builder.FindOrCreateAttribute( object, "AttributeLocalID" )
+    attr.SetValue( __OBJECT_ID__ )
+    sgPyQt.updateObjBrowser()
+    pass
+
+# ----------------------- #
+def DeleteAll():
+    study = _getStudy()
+    father = study.FindComponent( __MODULE_NAME__ )
+    if father:
+        iter = study.NewChildIterator( father )
+        builder = study.NewBuilder()
+        while iter.More():
+            sobj = iter.Value()
+            iter.Next()
+            builder.RemoveObjectWithChildren( sobj )
+        sgPyQt.updateObjBrowser()
+    pass
+
+# ----------------------- #
+def ShowMe():
+    study = _getStudy()
+    entry = sg.getSelected( 0 )
+    if entry != '':
+        sobj = study.FindObjectID( entry )
+        if ( sobj ):
+            test, attr = sobj.FindAttribute( "AttributeName" )
+            if test:
+                QMessageBox.information( sgPyQt.getDesktop(), 'Info', "My name is '%s'" % attr.Value() )
+                
+    pass
+
+# ----------------------- #
+def Delete():
+    study = _getStudy()
+    entry = sg.getSelected( 0 )
+    if entry != '':
+        sobj = study.FindObjectID( entry )
+        if ( sobj ):
+            builder = study.NewBuilder()
+            builder.RemoveObject( sobj )
+            sgPyQt.updateObjBrowser()
+    pass
 
-dict_command={
-               941:ExecPYHELLO,
-             }
+# ----------------------- #
+dict_command = {
+    941 : ShowHELLO,
+    942 : CreateObject,
+    951 : DeleteAll,
+    952 : ShowMe,
+    953 : Delete,
+    }