From: caremoli Date: Fri, 15 Oct 2010 10:02:17 +0000 (+0000) Subject: CCAR: complete development (issue YACSDEV 21001) that provides X-Git-Tag: V5_1_5rc1~5 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=499f8f22d221fb30f04875f0308d1f0b8d125d19;p=tools%2Fyacsgen.git CCAR: complete development (issue YACSDEV 21001) that provides means to add a documentation, a GUI to a module and to add or redefine methods of a component. With these modifications, it is now possible to generate a complete module such as PYHELLO and HELLO. --- diff --git a/Examples/cppgui1/components.py b/Examples/cppgui1/components.py index 43cd326..0fc17ea 100644 --- a/Examples/cppgui1/components.py +++ b/Examples/cppgui1/components.py @@ -21,7 +21,74 @@ execfile("../context.py") import os -from module_generator import Generator,Module,Service,CPPComponent +from module_generator import * + +idldefs=""" +#include "myinterface.idl" +""" + +compodefs=r""" + + +class A: public virtual POA_Idl_A +{ +public: + void createObject(::SALOMEDS::Study_ptr theStudy, const char* name){}; + + // Driver interface + virtual SALOMEDS::TMPFile* Save(SALOMEDS::SComponent_ptr theComponent, const char* theURL, bool isMultiFile){return 0;}; + virtual SALOMEDS::TMPFile* SaveASCII(SALOMEDS::SComponent_ptr theComponent, const char* theURL, bool isMultiFile){return 0;}; + virtual bool Load(SALOMEDS::SComponent_ptr theComponent, const SALOMEDS::TMPFile& theStream, const char* theURL, bool isMultiFile){return 0;}; + virtual bool LoadASCII(SALOMEDS::SComponent_ptr theComponent, const SALOMEDS::TMPFile& theStream, const char* theURL, bool isMultiFile){return 0;}; + virtual void Close(SALOMEDS::SComponent_ptr IORSComponent){}; + virtual char* ComponentDataType(){return "cppcompos";}; + virtual char* IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject, const char* IORString, CORBA::Boolean isMultiFile, CORBA::Boolean isASCII){return 0;}; + virtual char* LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject, const char* aLocalPersistentID, CORBA::Boolean isMultiFile, + CORBA::Boolean isASCII){return 0;}; + virtual bool CanPublishInStudy(CORBA::Object_ptr theIOR){return 0;}; + virtual SALOMEDS::SObject_ptr PublishInStudy(SALOMEDS::Study_ptr theStudy,SALOMEDS::SObject_ptr theSObject,CORBA::Object_ptr theObject, + const char* theName){return 0;}; + virtual CORBA::Boolean CanCopy(SALOMEDS::SObject_ptr theObject){return 0;}; + virtual SALOMEDS::TMPFile* CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID){return 0;}; + virtual CORBA::Boolean CanPaste(const char* theComponentName, CORBA::Long theObjectID){return 0;}; + virtual SALOMEDS::SObject_ptr PasteInto(const SALOMEDS::TMPFile& theStream, CORBA::Long theObjectID, SALOMEDS::SObject_ptr theObject){return 0;}; +}; + +""" + +compomethods=r""" + + Engines::TMPFile* DumpPython(CORBA::Object_ptr theStudy, + CORBA::Boolean isPublished, + CORBA::Boolean& isValidScript) + { + std::cerr << "je suis dans le dump:" << __LINE__ << std::endl; + SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(theStudy); + if(CORBA::is_nil(aStudy)) + return new Engines::TMPFile(0); + + SALOMEDS::SObject_var aSO = aStudy->FindComponent("cppcompos"); + if(CORBA::is_nil(aSO)) + return new Engines::TMPFile(0); + + std::string Script = "import cppcompos_ORB\n"; + Script += "import salome\n"; + Script += "compo = salome.lcc.FindOrLoadComponent('FactoryServer','cppcompos')\n"; + Script += "def RebuildData(theStudy):\n"; + Script += " compo.SetCurrentStudy(theStudy)\n"; + const char* aScript=Script.c_str(); + + char* aBuffer = new char[strlen(aScript)+1]; + strcpy(aBuffer, aScript); + CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer; + int aBufferSize = strlen(aBuffer)+1; + Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aBufferSize, aBufferSize, anOctetBuf, 1); + isValidScript = true; + return aStreamFile._retn(); + } + + +""" body=""" std::cerr << "a: " << a << std::endl; @@ -29,18 +96,24 @@ std::cerr << "b: " << b << std::endl; c=a+b; std::cerr << "c: " << c << std::endl; """ -c1=CPPComponent("compo1",services=[ +c1=CPPComponent("cppcompos",services=[ Service("s1",inport=[("a","double"),("b","double")], outport=[("c","double")], defs="//def1",body=body, ), ], includes="-I/usr/include", + idls=["*.idl"], + interfacedefs=idldefs, + inheritedinterface="Idl_A", + compodefs=compodefs, + inheritedclass="A", + addedmethods=compomethods, ) modul=Module("cppcompos",components=[c1],prefix="./install", doc=["*.rst",], - gui=["cppcomposGUI.cxx","cppcomposGUI.h","Makefile.am","demo.ui","*.png"], + gui=["cppcomposGUI.cxx","cppcomposGUI.h","demo.ui","*.png"], ) g=Generator(modul,context) diff --git a/Examples/cppgui1/cppcomposGUI.cxx b/Examples/cppgui1/cppcomposGUI.cxx index 0c2bfcb..47df890 100644 --- a/Examples/cppgui1/cppcomposGUI.cxx +++ b/Examples/cppgui1/cppcomposGUI.cxx @@ -2,7 +2,14 @@ #include #include #include +#include #include +#include + +#include +#include CORBA_CLIENT_HEADER(cppcompos) +#include CORBA_CLIENT_HEADER(SALOMEDS) +#include CORBA_CLIENT_HEADER(SALOMEDS_Attributes) // QT Includes #include @@ -23,12 +30,17 @@ cppcomposGUI::cppcomposGUI() : { } +static cppcompos_ORB::cppcompos_var engine; + // Module's initialization void cppcomposGUI::initialize( CAM_Application* app ) { SalomeApp_Module::initialize( app ); + Engines::Component_var comp = dynamic_cast(app)->lcc()->FindOrLoad_Component( "FactoryServer","cppcompos" ); + engine = cppcompos_ORB::cppcompos::_narrow(comp); + QWidget* aParent = application()->desktop(); SUIT_ResourceMgr* aResourceMgr = app->resourceMgr(); @@ -48,6 +60,14 @@ void cppcomposGUI::initialize( CAM_Application* app ) createTool( 902, aToolId ); } +// Get compatible dockable windows. +void cppcomposGUI::windows( QMap& theMap ) const +{ + theMap.clear(); + theMap.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea ); + theMap.insert( SalomeApp_Application::WT_PyConsole, Qt::BottomDockWidgetArea ); +} + // Module's engine IOR QString cppcomposGUI::engineIOR() const { @@ -62,6 +82,25 @@ bool cppcomposGUI::activateModule( SUIT_Study* theStudy ) setMenuShown( true ); setToolShown( true ); + SALOME_NamingService *aNamingService = SalomeApp_Application::namingService(); + CORBA::Object_var aSMObject = aNamingService->Resolve("/myStudyManager"); + SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow(aSMObject); + SALOMEDS::Study_var aDSStudy = aStudyManager->GetStudyByID(theStudy->id()); + + SALOMEDS::SComponent_var aFather = aDSStudy->FindComponent("cppcompos"); + if (aFather->_is_nil()) + { + SALOMEDS::StudyBuilder_var aStudyBuilder = aDSStudy->NewBuilder(); + aFather = aStudyBuilder->NewComponent("cppcompos"); + SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aFather, "AttributeName"); + SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr); + aName->SetValue("cppcompos"); + aName->Destroy(); + aStudyBuilder->DefineComponentInstance(aFather, engine); + } + CORBA::Boolean valid; + engine->DumpPython(aDSStudy,1,valid); + return bOk; } @@ -83,6 +122,9 @@ void cppcomposGUI::OnGetBanner() if ( ok && !myName.isEmpty()) { + ::CORBA::Double c; + engine->s1(1.,2.,c); + std::cerr << c << std::endl; QString banner = "Hello " + myName; SUIT_MessageBox::information( getApp()->desktop(), "info", banner, "OK" ); } diff --git a/Examples/cppgui1/cppcomposGUI.h b/Examples/cppgui1/cppcomposGUI.h index a9f5abc..e722eb6 100644 --- a/Examples/cppgui1/cppcomposGUI.h +++ b/Examples/cppgui1/cppcomposGUI.h @@ -12,6 +12,7 @@ public: cppcomposGUI(); void initialize( CAM_Application* ); QString engineIOR() const; + virtual void windows( QMap& theMap ) const; public slots: bool deactivateModule( SUIT_Study* ); diff --git a/Examples/cppgui1/myinterface.idl b/Examples/cppgui1/myinterface.idl new file mode 100644 index 0000000..16207a9 --- /dev/null +++ b/Examples/cppgui1/myinterface.idl @@ -0,0 +1,8 @@ +#include "SALOMEDS.idl" +#include "SALOME_Exception.idl" + +interface Idl_A : SALOMEDS::Driver +{ + void createObject(in SALOMEDS::Study theStudy, in string name) raises (SALOME::SALOME_Exception); +}; + diff --git a/Examples/pygui1/components.py b/Examples/pygui1/components.py index 89171e8..1ca7ac3 100644 --- a/Examples/pygui1/components.py +++ b/Examples/pygui1/components.py @@ -22,7 +22,7 @@ import os #import context from .. execfile("../context.py") -from module_generator import Generator,Module,Service,PYComponent +from module_generator import * defs=""" """ @@ -31,12 +31,75 @@ body=""" c=a+b d=a-b """ -c1=PYComponent("compo2",services=[ + +idldefs=""" +#include "myinterface.idl" +""" + +compodefs=r""" +import SALOME_DriverPy +import traceback + +class A(SALOME_DriverPy.SALOME_DriverPy_i): + def __init__(self): + SALOME_DriverPy.SALOME_DriverPy_i.__init__(self,"pycompos") + return + + def createObject( self, study, name ): + "Create object. " + try: + print study,name + builder = study.NewBuilder() + father = study.FindComponent( "pycompos" ) + if father is None: + father = builder.NewComponent( "pycompos" ) + attr = builder.FindOrCreateAttribute( father, "AttributeName" ) + attr.SetValue( "pycompos" ) + + object = builder.NewObject( father ) + attr = builder.FindOrCreateAttribute( object, "AttributeName" ) + attr.SetValue( name ) + except: + traceback.print_exc() + + def DumpPython( self, study, isPublished ): + abuffer = [] + abuffer.append( "def RebuildData( theStudy ):" ) + names = [] + father = study.FindComponent( "pycompos" ) + if father: + iter = study.NewChildIterator( father ) + while iter.More(): + name = iter.Value().GetName() + if name: names.append( name ) + iter.Next() + pass + pass + if names: + abuffer += [ " from salome import lcc" ] + abuffer += [ " import pycompos_ORB" ] + abuffer += [ " " ] + abuffer += [ " compo = lcc.FindOrLoadComponent( 'FactoryServerPy', 'pycompos' )" ] + abuffer += [ " " ] + abuffer += [ " compo.createObject( theStudy, '%s' )" % name for name in names ] + pass + abuffer += [ " " ] + + return ("\n".join( abuffer ), 1) + +""" + +c1=PYComponent("pycompos",services=[ Service("s1",inport=[("a","double"),("b","double")], outport=[("c","double"),("d","double")], defs=defs,body=body, ), ], + idls=["*.idl"], + interfacedefs=idldefs, + inheritedinterface="Idl_A", + compodefs=compodefs, + inheritedclass="A", ) modul=Module("pycompos",components=[c1],prefix="./install", diff --git a/Examples/pygui1/myinterface.idl b/Examples/pygui1/myinterface.idl new file mode 100644 index 0000000..16207a9 --- /dev/null +++ b/Examples/pygui1/myinterface.idl @@ -0,0 +1,8 @@ +#include "SALOMEDS.idl" +#include "SALOME_Exception.idl" + +interface Idl_A : SALOMEDS::Driver +{ + void createObject(in SALOMEDS::Study theStudy, in string name) raises (SALOME::SALOME_Exception); +}; + diff --git a/Examples/pygui1/pycomposGUI.py b/Examples/pygui1/pycomposGUI.py index 933665f..f57dd52 100644 --- a/Examples/pygui1/pycomposGUI.py +++ b/Examples/pygui1/pycomposGUI.py @@ -5,10 +5,34 @@ from PyQt4.QtGui import * from PyQt4.QtWebKit import * from PyQt4 import QtCore, QtGui, uic +import salome +import pycompos_ORB + # Get SALOME PyQt interface import SalomePyQt sgPyQt = SalomePyQt.SalomePyQt() +# Get SALOME Swig interface +import libSALOME_Swig +sg = libSALOME_Swig.SALOMEGUI_Swig() + +# object counter +__objectid__ = 0 + +### +# get active study ID +### +def _getStudyId(): + return sgPyQt.getStudyId() + +### +# get active study +### +def _getStudy(): + studyId = _getStudyId() + study = salome.myStudyManager.GetStudyByID( studyId ) + return study + # called when module is initialized # return map of popup windows to be used by the module def windows(): @@ -36,12 +60,38 @@ def activate(): a = sgPyQt.createAction( 942, "Hello2", "Hello2", "Show hello2 dialog box" ,"exec.png") sgPyQt.createMenu( a, mid ) sgPyQt.createTool( a, tid ) + a = sgPyQt.createAction( 943, "Create object", "Create object", "Create object","exec.png" ) + sgPyQt.createMenu( a, mid ) + sgPyQt.createTool( a, tid ) + return True # called when module is deactivated def deactivate(): pass +_engine=None +def getEngine(): + global _engine + if not _engine: + _engine= salome.lcc.FindOrLoadComponent( "FactoryServerPy", "pycompos" ) + return _engine + +### +# Create new object +### +def CreateObject(): + global __objectid__ + default_name = str( sgPyQt.stringSetting( "pycompos", "def_obj_name", "Object" ).trimmed() ) + # generate object name + __objectid__ = __objectid__ + 1 + name = "%s_%d" % ( default_name, __objectid__ ) + if not name: return + getEngine().createObject( _getStudy(), name ) + print getEngine().s1(4,5) + print getEngine().ComponentDataType() + sg.updateObjBrowser( True ) + class DemoImpl(QtGui.QDialog): def __init__(self, *args): super(DemoImpl, self).__init__(*args) @@ -69,5 +119,7 @@ def OnGUIEvent( commandID ): widget = DemoImpl(sgPyQt.getDesktop()) widget.show() + elif commandID==943: + CreateObject() diff --git a/module_generator/aster_tmpl.py b/module_generator/aster_tmpl.py index 3922590..80c255a 100644 --- a/module_generator/aster_tmpl.py +++ b/module_generator/aster_tmpl.py @@ -24,7 +24,7 @@ except: asterCompo=""" import sys,traceback,os -import ${module}__POA +import ${module}_ORB__POA import calcium import dsccalcium import SALOME @@ -48,11 +48,11 @@ except: ${servicesdef} #ENDDEF -class ${component}(${module}__POA.${component},dsccalcium.PyDSCComponent,SUPERV): +class ${component}(${module}_ORB__POA.${component},dsccalcium.PyDSCComponent,SUPERV): ''' To be identified as a SALOME component this Python class must have the same name as the component, inherit omniorb - class ${module}__POA.${component} and DSC class dsccalcium.PyDSCComponent + class ${module}_ORB__POA.${component} and DSC class dsccalcium.PyDSCComponent that implements DSC API. ''' def __init__ ( self, orb, poa, contID, containerName, instanceName, interfaceName ): @@ -78,7 +78,7 @@ asterCompo=Template(asterCompo) asterCEXECompo=""" import sys,traceback,os import string -import ${module}__POA +import ${module}_ORB__POA import calcium import dsccalcium import SALOME @@ -97,11 +97,11 @@ ${servicesdef} class ExecutionError(Exception): '''General exception during execution''' -class ${component}(${module}__POA.${component},dsccalcium.PyDSCComponent,SUPERV): +class ${component}(${module}_ORB__POA.${component},dsccalcium.PyDSCComponent,SUPERV): ''' To be identified as a SALOME component this Python class must have the same name as the component, inherit omniorb - class ${module}__POA.${component} and DSC class dsccalcium.PyDSCComponent + class ${module}_ORB__POA.${component} and DSC class dsccalcium.PyDSCComponent that implements DSC API. ''' def __init__ ( self, orb, poa, contID, containerName, instanceName, interfaceName ): diff --git a/module_generator/cata_tmpl.py b/module_generator/cata_tmpl.py index e0258f5..d3c6f7f 100644 --- a/module_generator/cata_tmpl.py +++ b/module_generator/cata_tmpl.py @@ -34,7 +34,7 @@ idl=""" ${idldefs} -module ${module} +module ${module}_ORB { typedef sequence stringvec; typedef sequence dblevec; @@ -49,7 +49,7 @@ ${interfaces} idl=Template(idl) interface=""" - interface ${component}:Engines::Superv_Component + interface ${component}:${inheritedinterface} Engines::Superv_Component { ${services} }; @@ -94,22 +94,21 @@ xml_service = Template(xml_service) idlMakefile=""" include $$(top_srcdir)/adm_local/make_common_starter.am -BUILT_SOURCES = ${module}SK.cc ${PACO_BUILT_SOURCES} -IDL_FILES=${module}.idl +BUILT_SOURCES = ${module}SK.cc ${PACO_BUILT_SOURCES} ${other_sks} +IDL_FILES=${module}.idl ${other_idls} -lib_LTLIBRARIES = lib${module}.la +lib_LTLIBRARIES = libSalomeIDL${module}.la salomeidl_DATA = $$(IDL_FILES) ${PACO_salomeidl_DATA} -salomepython_DATA = ${module}_idl.py ${PACO_salomepython_DATA} -lib${module}_la_SOURCES = -nodist_lib${module}_la_SOURCES = ${module}SK.cc +libSalomeIDL${module}_la_SOURCES = +nodist_libSalomeIDL${module}_la_SOURCES = ${module}SK.cc ${other_sks} nodist_salomeinclude_HEADERS= ${module}.hh ${PACO_SALOMEINCLUDE_HEADERS} -lib${module}_la_CXXFLAGS = -I. $$(SALOME_INCLUDES) -lib${module}_la_LIBADD = $$(SALOME_IDL_LIBS) +libSalomeIDL${module}_la_CXXFLAGS = -I. $$(SALOME_INCLUDES) +libSalomeIDL${module}_la_LIBADD = $$(SALOME_IDL_LIBS) ########################################################## %SK.cc %.hh : %.idl -\t$$(OMNIORB_IDL) -bcxx $$(IDLCXXFLAGS) $$(OMNIORB_IDLCXXFLAGS) $$(IDL_INCLUDES) $$< +\t$$(OMNIORB_IDL) -bcxx $$(OMNIORB_IDLCXXFLAGS) $$(IDL_INCLUDES) $$< %_idl.py : %.idl -\t$$(OMNIORB_IDL) -bpython $$(IDL_INCLUDES) ${PACO_INCLUDES} $$< +\t$$(OMNIORB_IDL) $$(OMNIORB_IDLPYFLAGS) $$(IDL_INCLUDES) ${PACO_INCLUDES} $$< %PaCO.hxx %PaCO.cxx : %.idl %.xml \t$$(OMNIORB_IDL) -I@KERNEL_ROOT_DIR@/idl/salome -p@PACOPATH@/lib/python -bpaco -Wb$$(top_srcdir)/idl/$$*.xml,$$(srcdir):@PACOPATH@/idl:@KERNEL_ROOT_DIR@/idl/salome $$(top_srcdir)/idl/$$*.idl @@ -117,16 +116,15 @@ CLEANFILES = *.hh *SK.cc *.py *.hxx *.cxx EXTRA_DIST = $$(IDL_FILES) -clean-local: -\trm -rf ${module} ${module}__POA - -install-data-local: -\t$${mkinstalldirs} $$(DESTDIR)$$(salomepythondir) -\tcp -R ${module} ${module}__POA $$(DESTDIR)$$(salomepythondir) +install-data-local: $$(IDL_FILES) +\t$$(INSTALL) -d $$(DESTDIR)$$(salomepythondir) +\tls $$^ | while read file; do \\ +\t$$(OMNIORB_IDL) $$(OMNIORB_IDLPYFLAGS) $$(IDL_INCLUDES) -C$$(DESTDIR)$$(salomepythondir) $$$$file ; \\ +\tdone uninstall-local: -\trm -rf $$(DESTDIR)$$(salomepythondir)/${module} -\trm -rf $$(DESTDIR)$$(salomepythondir)/${module}__POA +\trm -rf $$(DESTDIR)$$(salomepythondir)/* + """ idlMakefile=Template(idlMakefile) diff --git a/module_generator/cpp_tmpl.py b/module_generator/cpp_tmpl.py index 4979bfa..eadcce2 100644 --- a/module_generator/cpp_tmpl.py +++ b/module_generator/cpp_tmpl.py @@ -235,7 +235,7 @@ extern "C" Engines::Container_var container = Engines::Container::_narrow(obj); ${component}_i * myEngine = new ${component}_i(orb, poa, container, instanceName.c_str(), "${component}"); pman->activate(); - obj=myEngine->_this(); + obj=myEngine->POA_${module}_ORB::${component}::_this(); Engines::Component_var component = Engines::Component::_narrow(obj); string component_registerName = containerName + "/" + instanceName; salomens->Register(component,component_registerName.c_str()); @@ -276,9 +276,8 @@ hxxCompo=""" ${compodefs} //ENDDEF -class ${component}_i: ${inheritedclass} - public virtual POA_${module}::${component}, - public virtual Superv_Component_i +class ${component}_i: public virtual POA_${module}_ORB::${component}, + ${inheritedclass} public virtual Superv_Component_i { public: ${component}_i(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa, @@ -402,7 +401,7 @@ lib${component}Engine_la_SOURCES = ${component}.cxx ${sources} nodist_lib${component}Engine_la_SOURCES = lib${component}Engine_la_CXXFLAGS = -I$$(top_builddir)/idl $$(SALOME_INCLUDES) ${includes} lib${component}Engine_la_FFLAGS = $$(SALOME_INCLUDES) -fexceptions ${includes} -lib${component}Engine_la_LIBADD = ${libs} -L$$(top_builddir)/idl -l${module} $${SALOME_LIBS} $$(FLIBS) +lib${component}Engine_la_LIBADD = ${libs} -L$$(top_builddir)/idl -lSalomeIDL${module} $${SALOME_LIBS} $$(FLIBS) lib${component}Engine_la_LDFLAGS = ${rlibs} """ compoMakefile=Template(compoMakefile) @@ -412,7 +411,7 @@ lib${component}Exelib_la_SOURCES = ${component}.cxx nodist_lib${component}Exelib_la_SOURCES = lib${component}Exelib_la_CXXFLAGS = -I$$(top_builddir)/idl $$(SALOME_INCLUDES) ${includes} lib${component}Exelib_la_FFLAGS = $$(SALOME_INCLUDES) -fexceptions ${includes} -lib${component}Exelib_la_LIBADD = ${libs} -L$$(top_builddir)/idl -l${module} $${SALOME_LIBS} $$(FLIBS) +lib${component}Exelib_la_LIBADD = ${libs} -L$$(top_builddir)/idl -lSalomeIDL${module} $${SALOME_LIBS} $$(FLIBS) lib${component}Exelib_la_LDFLAGS = ${rlibs} """ compoEXEMakefile=Template(compoEXEMakefile) diff --git a/module_generator/cppcompo.py b/module_generator/cppcompo.py index f6561f8..aec9c78 100644 --- a/module_generator/cppcompo.py +++ b/module_generator/cppcompo.py @@ -45,20 +45,29 @@ class CPPComponent(Component): to define the component class by deriving it (see *inheritedclass* parameter) :param inheritedclass: can be used to define a base class for the component. The base class can be defined in external source or with the *compodefs* parameter. The value of the *inheritedclass* parameter is the name of the base class. + :param idls: can be used to add extra idl CORBA interfaces to the component. This parameter must gives a list of idl file + names that are added into the generated module (idl directory) and compiled with the generated idl of the module. + :param interfacedefs: can be used to add idl definitions (or includes of idl files) into the generated idl of the module. + :param inheritedinterface: can be used to make the component inherit an extra idl interface that has been included through + the *idls* and *interfacedefs* parameters. See the cppgui1 example for how to use these last parameters. + :param addmethods: is a C++ specific parameter that can be used to redefine a component method (DumpPython for example). This + parameter is a string that must contain the definition and implementation code of the method. See the cppgui1 example + for how to use it. For example, the following call defines a standalone component named "mycompo" with one service s1 (it must have been defined before):: >>> c1 = module_generator.CPPComponent('mycompo', services=[s1,], kind="exe", exe_path="./launch.sh") """ - def __init__(self, name, services=None, libs="", rlibs="", includes="", - kind="lib", exe_path=None, sources=None, inheritedclass="", - compodefs=""): + def __init__(self, name, services=None, libs="", rlibs="", includes="", kind="lib", + exe_path=None, sources=None, inheritedclass="", compodefs="", + idls=None,interfacedefs="",inheritedinterface="",addedmethods=""): self.exe_path = exe_path - Component.__init__(self, name, services, impl="CPP", libs=libs, - rlibs=rlibs, includes=includes, kind=kind, - sources=sources,inheritedclass=inheritedclass, - compodefs=compodefs) + Component.__init__(self, name, services, impl="CPP", libs=libs, rlibs=rlibs, + includes=includes, kind=kind, sources=sources, + inheritedclass=inheritedclass, compodefs=compodefs, idls=idls, + interfacedefs=interfacedefs, inheritedinterface=inheritedinterface, + addedmethods=addedmethods) def validate(self): """ validate component definition parameters""" @@ -125,6 +134,9 @@ AM_CFLAGS=$(SALOME_INCLUDES) -fexceptions service = " void %s(" % serv.name service = service+gen.makeArgs(serv)+");" services.append(service) + + if self.addedmethods: + services.append(self.addedmethods) servicesdef = "\n".join(services) inheritedclass=self.inheritedclass diff --git a/module_generator/gener.py b/module_generator/gener.py index 60bf73b..74153d9 100644 --- a/module_generator/gener.py +++ b/module_generator/gener.py @@ -123,7 +123,8 @@ class Module(object): class Component(object): def __init__(self, name, services=None, impl="PY", libs="", rlibs="", includes="", kind="lib", sources=None, - inheritedclass="",compodefs=""): + inheritedclass="",compodefs="", + idls=None,interfacedefs="",inheritedinterface="",addedmethods=""): self.name = name self.impl = impl self.kind = kind @@ -134,6 +135,10 @@ class Component(object): self.sources = sources or [] self.inheritedclass=inheritedclass self.compodefs=compodefs + self.idls=idls + self.interfacedefs=interfacedefs + self.inheritedinterface=inheritedinterface + self.addedmethods=addedmethods def validate(self): if self.impl not in ValidImpl: @@ -189,8 +194,8 @@ class Service(object): """ - def __init__(self, name, inport=None, outport=None, instream=None, - outstream=None, parallel_instream=None, parallel_outstream=None, body="", defs="", impl_type="sequential"): + def __init__(self, name, inport=None, outport=None, instream=None, outstream=None, + parallel_instream=None, parallel_outstream=None, defs="", body="", impl_type="sequential"): self.name = name self.inport = inport or [] self.outport = outport or [] @@ -229,7 +234,7 @@ class Service(object): if name in lports: raise Invalid("%s is already defined as a stream port" % name) lports.add(name) - + for port in self.parallel_instream: name, typ = self.validateParallelStream(port) if name in lports: @@ -481,12 +486,24 @@ echo " Qt ..................... : $qt_ok" other_require=other_require, ) + #if components have other idls + other_idls="" + other_sks="" + for compo in module.components: + if compo.idls: + for idl in compo.idls: + for fidl in glob.glob(idl): + other_idls=other_idls+os.path.basename(fidl) +" " + other_sks=other_sks+os.path.splitext(os.path.basename(fidl))[0]+"SK.cc " + idlfiles={"Makefile.am": idlMakefile.substitute(module=module.name, PACO_BUILT_SOURCES=PACO_BUILT_SOURCES, PACO_SALOMEINCLUDE_HEADERS=PACO_SALOMEINCLUDE_HEADERS, PACO_INCLUDES=PACO_INCLUDES, PACO_salomepython_DATA=PACO_salomepython_DATA, - PACO_salomeidl_DATA=PACO_salomeidl_DATA), + PACO_salomeidl_DATA=PACO_salomeidl_DATA, + other_idls=other_idls,other_sks=other_sks, + ), idlfile : self.makeidl(), } if paco: @@ -505,6 +522,12 @@ echo " Qt ..................... : $qt_ok" else: shutil.copyfile(src, os.path.join(namedir, "src", os.path.basename(src))) + if compo.idls: + #copy provided idl files in idl directory + for idl in compo.idls: + for fidl in glob.glob(idl): + shutil.copyfile(fidl, os.path.join(namedir, "idl", os.path.basename(fidl))) + for m4file in ("check_Kernel.m4", "check_omniorb.m4", "ac_linker_options.m4", "ac_cxx_option.m4", "python.m4", "enable_pthreads.m4", "check_f77.m4", @@ -512,6 +535,7 @@ echo " Qt ..................... : $qt_ok" "check_mpi.m4", "check_lam.m4", "check_openmpi.m4", "check_mpich.m4"): shutil.copyfile(os.path.join(self.kernel, "salome_adm", "unix", "config_files", m4file), os.path.join(namedir, "adm_local", m4file)) + if self.module.gui: for m4file in ("check_GUI.m4", "check_qt.m4", "check_opengl.m4"): shutil.copyfile(os.path.join(self.gui, "adm_local", "unix", "config_files", m4file), @@ -687,7 +711,9 @@ echo " Qt ..................... : $qt_ok" service = " void %s(" % serv.name service = service+",".join(params)+");" services.append(service) + interfaces.append(parallel_interface.substitute(component=compo.name, services="\n".join(services))) + else: services = [] for serv in compo.services: @@ -709,13 +735,21 @@ echo " Qt ..................... : $qt_ok" service = " void %s(" % serv.name service = service+",".join(params)+") raises (SALOME::SALOME_Exception);" services.append(service) - interfaces.append(interface.substitute(component=compo.name, services="\n".join(services))) + + inheritedinterface="" + if compo.inheritedinterface: + inheritedinterface=compo.inheritedinterface+"," + interfaces.append(interface.substitute(component=compo.name, services="\n".join(services),inheritedinterface=inheritedinterface)) #build idl includes for SALOME modules idldefs="" for mod in self.used_modules: idldefs = idldefs + salome_modules[mod]["idldefs"] + for compo in self.module.components: + if compo.interfacedefs: + idldefs = idldefs + compo.interfacedefs + return idl.substitute(module=self.module.name, interfaces='\n'.join(interfaces),idldefs=idldefs) # For PaCO++ diff --git a/module_generator/gui_tmpl.py b/module_generator/gui_tmpl.py index 74f2964..2cc897b 100644 --- a/module_generator/gui_tmpl.py +++ b/module_generator/gui_tmpl.py @@ -36,7 +36,7 @@ BUILT_SOURCES=${uisources} lib_LTLIBRARIES= lib${module}.la lib${module}_la_SOURCES = ${sources} lib${module}_la_CPPFLAGS = $$(SALOME_INCLUDES) $$(GUI_CXXFLAGS) $$(QT_INCLUDES) -I$$(top_builddir)/idl -lib${module}_la_LIBADD = -L$$(top_builddir)/idl -l${module} +lib${module}_la_LIBADD = -L$$(top_builddir)/idl -lSalomeIDL${module} salomeres_DATA =SalomeApp.xml ${other_sources} diff --git a/module_generator/pycompo.py b/module_generator/pycompo.py index 27f4c0b..3e6953d 100644 --- a/module_generator/pycompo.py +++ b/module_generator/pycompo.py @@ -50,6 +50,11 @@ class PYComponent(Component): to define the component class by deriving it (see *inheritedclass* parameter) :param inheritedclass: can be used to define a base class for the component. The base class can be defined in external source or with the *compodefs* parameter. The value of the *inheritedclass* parameter is the name of the base class. + :param idls: can be used to add extra idl CORBA interfaces. This parameter must gives a list of idl file names that are + added into the generated module (idl directory) and compiled with the generated idl of the module. + :param interfacedefs: can be used to add idl definitions (or includes of idl files) into the generated idl of the module. + :param inheritedinterface: can be used to make the component inherit an extra idl interface that has been included through + the *idls* and *interfacedefs* parameters. See the pygui1 example for how to use these last parameters. For example, the following call defines a Python component named "mycompo" with one service s1 (it must have been defined before):: @@ -57,13 +62,13 @@ class PYComponent(Component): python_path="apath") """ - def __init__(self, name, services=None, python_path=None, kind="lib", - sources=None, inheritedclass="", compodefs=""): + def __init__(self, name, services=None, kind="lib", sources=None, python_path=None, + compodefs="", inheritedclass="", idls=None, interfacedefs="", inheritedinterface=""): """initialise component attributes""" self.python_path = python_path or [] - Component.__init__(self, name, services, impl="PY", kind=kind, - sources=sources, inheritedclass=inheritedclass, - compodefs=compodefs) + Component.__init__(self, name, services, impl="PY", kind=kind, sources=sources, + inheritedclass=inheritedclass, compodefs=compodefs, + idls=idls,interfacedefs=interfacedefs,inheritedinterface=inheritedinterface) def validate(self): """validate component attributes""" diff --git a/module_generator/pyth_tmpl.py b/module_generator/pyth_tmpl.py index 4996d6d..e88595b 100644 --- a/module_generator/pyth_tmpl.py +++ b/module_generator/pyth_tmpl.py @@ -25,7 +25,7 @@ except: pyCompo=""" import sys,traceback,os sys.path=sys.path+[${python_path}] -import ${module}__POA +import ${module}_ORB__POA import calcium import dsccalcium import SALOME @@ -45,11 +45,11 @@ ${compodefs} ${servicesdef} #ENDDEF -class ${component}(${inheritedclass} ${module}__POA.${component},dsccalcium.PyDSCComponent): +class ${component}(${module}_ORB__POA.${component}, ${inheritedclass} dsccalcium.PyDSCComponent): ''' To be identified as a SALOME component this Python class must have the same name as the component, inherit omniorb - class ${module}__POA.${component} and DSC class dsccalcium.PyDSCComponent + class ${module}_ORB__POA.${component} and DSC class dsccalcium.PyDSCComponent that implements DSC API. ''' def __init__ ( self, orb, poa, contID, containerName, instanceName, interfaceName ):