From 1f03fb49b38e413e4bca5668ee275c6b5b1e1094 Mon Sep 17 00:00:00 2001 From: smh Date: Tue, 18 Oct 2005 15:32:28 +0000 Subject: [PATCH] Preparation of 3.1.0a2: merge with BR_3_0_0_OCC --- INSTALL | 4 + adm_local/unix/make_commence.in | 6 +- bin/VERSION | 3 +- configure.in.base | 10 +- idl/PYHELLO_Gen.idl | 4 +- resources/PYHELLOCatalog.xml | 2 +- resources/PYHELLO_en.xml | 21 ++- src/PYHELLO/PYHELLO.py | 20 ++- src/PYHELLOGUI/PYHELLOGUI.py | 306 +++++++++++++++++++++++++------- 9 files changed, 293 insertions(+), 83 deletions(-) create mode 100644 INSTALL diff --git a/INSTALL b/INSTALL new file mode 100644 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 diff --git a/adm_local/unix/make_commence.in b/adm_local/unix/make_commence.in index ee4c6fc..623267d 100644 --- a/adm_local/unix/make_commence.in +++ b/adm_local/unix/make_commence.in @@ -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 diff --git a/bin/VERSION b/bin/VERSION index 1b3a8c6..4f4c6b2 100755 --- a/bin/VERSION +++ b/bin/VERSION @@ -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 diff --git a/configure.in.base b/configure.in.base index 151b274..9eaef0a 100644 --- a/configure.in.base +++ b/configure.in.base @@ -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 diff --git a/idl/PYHELLO_Gen.idl b/idl/PYHELLO_Gen.idl index 8757320..603ad16 100644 --- a/idl/PYHELLO_Gen.idl +++ b/idl/PYHELLO_Gen.idl @@ -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 - diff --git a/resources/PYHELLOCatalog.xml b/resources/PYHELLOCatalog.xml index eaae032..f22729e 100644 --- a/resources/PYHELLOCatalog.xml +++ b/resources/PYHELLOCatalog.xml @@ -16,7 +16,7 @@ PYHELLO GUI Data C. Caremoli - 2.2.4 + 3.1.0a EDF - RD 1 PYHELLO.png diff --git a/resources/PYHELLO_en.xml b/resources/PYHELLO_en.xml index 048c191..72070e3 100644 --- a/resources/PYHELLO_en.xml +++ b/resources/PYHELLO_en.xml @@ -2,16 +2,31 @@ + - + + + - + + - + + + + + + + + + + + + diff --git a/src/PYHELLO/PYHELLO.py b/src/PYHELLO/PYHELLO.py index f27c680..527fa80 100644 --- a/src/PYHELLO/PYHELLO.py +++ b/src/PYHELLO/PYHELLO.py @@ -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 - diff --git a/src/PYHELLOGUI/PYHELLOGUI.py b/src/PYHELLOGUI/PYHELLOGUI.py index 5c5c824..79201a6 100644 --- a/src/PYHELLOGUI/PYHELLOGUI.py +++ b/src/PYHELLOGUI/PYHELLOGUI.py @@ -1,76 +1,256 @@ -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, + } -- 2.30.2