Salome HOME
Merge branch 'V9_2_2_BR'
[tools/yacsgen.git] / module_generator / hxxcompo.py
index b594ddd3fe342e003a4db976e9c8d8fe989f88c6..975d948228a9938ca34abf5e4f6e32355e8a6e8d 100644 (file)
@@ -1,9 +1,9 @@
-# Copyright (C) 2009-2013  EDF R&D
+# Copyright (C) 2009-2019  EDF R&D
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
 # License as published by the Free Software Foundation; either
-# version 2.1 of the License.
+# version 2.1 of the License, or (at your option) any later version.
 #
 # This library is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 debug=1
 import os
-import string
 import fnmatch
 from tempfile import mkstemp
-from gener import Component, Invalid
-from hxx_tmpl import cxxService, hxxCompo, cxxCompo, compoMakefile
+from module_generator.gener import Component, Invalid
+from module_generator.hxx_tmpl import cxxService, hxxCompo, cxxCompo, cmake_src_compo_hxx
 from module_generator import Service
-from yacstypes import corba_rtn_type,moduleTypes
-from hxx_awk import parse01,parse1,parse2,parse3
-from hxx_awk import cpp2idl_mapping
+from module_generator.yacstypes import corba_rtn_type,moduleTypes
+from module_generator.hxx_awk import parse01,parse1,parse2,parse3
+from module_generator.hxx_awk import cpp2idl_mapping
 # these tables contain the part of code which depends upon c++ types
-from hxx_awk import cpp_impl_a,cpp_impl_b,cpp_impl_c  
-from hxx_awk import cpp2yacs_mapping
+from module_generator.hxx_awk import cpp_impl_a,cpp_impl_b,cpp_impl_c  
+from module_generator.hxx_awk import cpp2yacs_mapping
 from tempfile import mkdtemp
-from hxx_tmpl_gui import hxxgui_cxx, hxxgui_h, hxxgui_icon_ts
-from hxx_tmpl_gui import hxxgui_message_en, hxxgui_message_fr
-from hxx_tmpl_gui import hxxgui_config, hxxgui_xml_fr, hxxgui_xml_en
+from module_generator.hxx_tmpl_gui import hxxgui_cxx, hxxgui_h, hxxgui_icon_ts
+from module_generator.hxx_tmpl_gui import hxxgui_message_en, hxxgui_message_fr
+from module_generator.hxx_tmpl_gui import hxxgui_config, hxxgui_xml_fr, hxxgui_xml_en
+from module_generator.gener import Library
+from module_generator.gui_tmpl import cppsalomeapp
 
 # ------------------------------------------------------------------------------
 
@@ -54,7 +55,7 @@ class HXX2SALOMEComponent(Component):
 
     hxxfileful = search_file(hxxfile,cpp_path)
     cpplibful = search_file(cpplib,cpp_path)
-    format_error = 'Error in HXX2SALOMEComponent : file %s ot found in %s'
+    format_error = 'Error in HXX2SALOMEComponent : file %s not found in %s'
     assert len(hxxfileful) > 0, format_error %  (hxxfile, cpp_path)
     assert len(cpplibful) > 0, format_error % (cpplib, cpp_path)
     hxxfile = hxxfileful[0]
@@ -66,7 +67,7 @@ class HXX2SALOMEComponent(Component):
     f=os.popen(cmd1)
     class_name=f.readlines()[0]
     name=class_name
-    print "classname=",class_name
+    print("classname=",class_name)
     f.close()
 
     # create temporary awk files for the parsing
@@ -127,7 +128,7 @@ class HXX2SALOMEComponent(Component):
     result_parsing=open("parse_type_result","r")
     for line in result_parsing.readlines():
         line=line[0:-1] # get rid of trailing \n
-        words = string.split(line,';')
+        words = line.split(';')
 
         if len(words) >=3 and words[0] == "Function": # detect a new service
             function_name=words[2]
@@ -163,10 +164,10 @@ class HXX2SALOMEComponent(Component):
     #  - store it in service_definition[serv]["impl"]
     for serv in list_of_services:
         if debug:
-            print "service : ",serv
-            print "  inports  -> ",service_definition[serv]["inports"]
-            print "  outports -> ",service_definition[serv]["outports"]
-            print "  return   -> ",service_definition[serv]["ret"]
+            print("service : ",serv)
+            print("  inports  -> ",service_definition[serv]["inports"])
+            print("  outports -> ",service_definition[serv]["outports"])
+            print("  return   -> ",service_definition[serv]["ret"])
 
 
         # Part 1 : Argument pre-processing
@@ -197,7 +198,7 @@ class HXX2SALOMEComponent(Component):
               post=""
               pre=""
 
-              if string.find(cpp_impl_a[argtype],"auto_ptr" ) != -1 :
+              if cpp_impl_a[argtype].find("auto_ptr" ) != -1 :
                   # for auto_ptr argument, retrieve the raw pointer behind
                   post=".get()" 
               if  argtype == "const MEDMEM::MESH&"  or  \
@@ -227,7 +228,7 @@ class HXX2SALOMEComponent(Component):
         # Part 3.b : In Argument Post-processing
         for (argname,argtype) in service_definition[serv]["inports"]:
             # not all in types require a treatment
-            if cpp_impl_c.has_key(argtype)
+            if argtype in cpp_impl_c
                 format=cpp_impl_c[argtype]
                 # id : treatment of %(module) is postponed in makecxx
                 s_argument_postprocessing += \
@@ -249,7 +250,7 @@ class HXX2SALOMEComponent(Component):
                                            s_argument_postprocessing + \
                                            s_rtn_processing
         if debug:
-            print "implementation :\n",service_definition[serv]["impl"]
+            print("implementation :\n",service_definition[serv]["impl"])
 
     #
     # Create a list of Service objects (called services), 
@@ -278,7 +279,7 @@ class HXX2SALOMEComponent(Component):
         # find out if component uses medmem types and/or medcoupling types
         for (argname,argtype) in inports + outports + [("return",Return)]:
             if moduleTypes[argtype]=="MED":
-                if argtype.count("Coupling")>0:
+                if argtype.count("CorbaInterface")>0:
                     self.use_medcoupling=True
                 else:
                     self.use_medmem=True
@@ -286,13 +287,13 @@ class HXX2SALOMEComponent(Component):
 
         code=service_definition[serv]["impl"]
         if debug:
-            print "service : ",serv
-            print "  inports  -> ",service_definition[serv]["inports"]
-            print "  converted inports  -> ",inports
-            print "  outports -> ",service_definition[serv]["outports"]
-            print "  converted outports  -> ",outports
-            print "  Return  -> ",service_definition[serv]["ret"]
-            print "  converted Return  -> ",Return
+            print("service : ",serv)
+            print("  inports  -> ",service_definition[serv]["inports"])
+            print("  converted inports  -> ",inports)
+            print("  outports -> ",service_definition[serv]["outports"])
+            print("  converted outports  -> ",outports)
+            print("  Return  -> ",service_definition[serv]["ret"])
+            print("  converted Return  -> ",Return)
 
         services.append(Service(serv, 
            inport=inports, 
@@ -302,8 +303,8 @@ class HXX2SALOMEComponent(Component):
            body=code,
            ) )
 
-    Includes="-I${"+name+"CPP_ROOT_DIR}/include"
-    Libs="-L${"+name+"CPP_ROOT_DIR}/lib -l"+name+"CXX"
+    Includes = os.path.join(cpp_path, "include")
+    Libs = [ Library( name=name+"CXX", path=os.path.join(cpp_path, "lib"))]
     Compodefs=""
     Inheritedclass=""
     self.inheritedconstructor=""
@@ -326,17 +327,37 @@ class HXX2SALOMEComponent(Component):
 #include CORBA_CLIENT_HEADER(MEDCouplingCorbaServant)
 #include "MEDCouplingFieldDoubleServant.hxx"
 #include "MEDCouplingUMeshServant.hxx"
+#include "DataArrayDoubleServant.hxx"
 #include "MEDCouplingFieldDouble.hxx"
 #include "MEDCouplingUMesh.hxx"
 #include "MEDCouplingUMeshClient.hxx"
 #include "MEDCouplingFieldDouble.hxx"
 #include "MEDCouplingFieldDoubleClient.hxx"
+#include "MEDCouplingMemArray.hxx"
+#include "DataArrayDoubleClient.hxx"
 """
 
     Component.__init__(self, name, services, impl="CPP", libs=Libs,
-                             rlibs="", includes=Includes, kind="lib",
-                             sources=None,inheritedclass=Inheritedclass,
-                             compodefs=Compodefs)
+                             rlibs=os.path.dirname(cpplib), includes=Includes,
+                             kind="lib", sources=None,
+                             inheritedclass=Inheritedclass,compodefs=Compodefs)
+
+# -----------------------------------------------------------------------------      
+  def libraryName(self):
+    """ Name of the target library
+    """
+    return self.name + "Engine"
+    
+# ------------------------------------------------------------------------------
+  def targetProperties(self):
+    """ define the rpath property of the target using self.rlibs
+    return
+      string containing the commands to add to cmake
+    """
+    text=""
+    if self.rlibs.strip() :
+      text="SET_TARGET_PROPERTIES( %sEngine PROPERTIES INSTALL_RPATH %s)\n" % (self.name, self.rlibs)
+    return text
 
 # ------------------------------------------------------------------------------
   def makeCompo(self, gen):
@@ -346,24 +367,36 @@ class HXX2SALOMEComponent(Component):
     """
     cxxfile = "%s_i.cxx" % self.name
     hxxfile = "%s_i.hxx" % self.name
-    return {"Makefile.am":gen.makeMakefile(self.getMakefileItems(gen)),
+    (cmake_text, cmake_vars) = self.additionalLibraries()
+    
+    cmakelist_content = cmake_src_compo_hxx.substitute(
+                        module = gen.module.name,
+                        component = self.name,
+                        componentlib = self.libraryName(),
+                        includes = self.includes,
+                        libs = cmake_vars,
+                        find_libs = cmake_text,
+                        target_properties = self.targetProperties()
+                        )
+    
+    return {"CMakeLists.txt":cmakelist_content,
             cxxfile:self.makecxx(gen),
             hxxfile:self.makehxx(gen)
            }
 
 # ------------------------------------------------------------------------------
-  def getMakefileItems(self,gen):
-      makefileItems={"header":"""
-include $(top_srcdir)/adm_local/make_common_starter.am
-
-"""}
-      makefileItems["lib_LTLIBRARIES"]=["lib"+self.name+"Engine.la"]
-      makefileItems["salomeinclude_HEADERS"]=["%s_i.hxx" % self.name]
-      makefileItems["body"]=compoMakefile.substitute(module=gen.module.name,
-                                                     component=self.name,
-                                                     libs=self.libs,
-                                                     includes=self.includes)
-      return makefileItems
+#  def getMakefileItems(self,gen):
+#      makefileItems={"header":"""
+#include $(top_srcdir)/adm_local/make_common_starter.am
+#
+#"""}
+#      makefileItems["lib_LTLIBRARIES"]=["lib"+self.name+"Engine.la"]
+#      makefileItems["salomeinclude_HEADERS"]=["%s_i.hxx" % self.name]
+#      makefileItems["body"]=compoMakefile.substitute(module=gen.module.name,
+#                                                     component=self.name,
+#                                                     libs=self.libs,
+#                                                     includes=self.includes)
+#      return makefileItems
 
 # ------------------------------------------------------------------------------
   def makehxx(self, gen):
@@ -396,7 +429,7 @@ include $(top_srcdir)/adm_local/make_common_starter.am
     defs = []
     for serv in self.services:
       defs.append(serv.defs)
-      print "CNC bug : ",serv.body
+      print("CNC bug : ",serv.body)
       service = cxxService.substitute(
                            component=self.name, 
                            service=serv.name,
@@ -424,6 +457,17 @@ include $(top_srcdir)/adm_local/make_common_starter.am
       gui_config=hxxgui_config.substitute(component_name=self.name)
       gui_xml_fr=hxxgui_xml_fr.substitute(component_name=self.name)
       gui_xml_en=hxxgui_xml_en.substitute(component_name=self.name)
+      gui_salomeapp_gen=cppsalomeapp.substitute(module=self.name,
+                                                lmodule=self.name.lower(),
+                                                version="V0")
+      # for a salome component generated by hxx2salome from a c++ component, 
+      # the documentation points at the c++ component documentation
+      salome_doc_path=os.path.join("%"+self.name+"_ROOT_DIR%","share",
+                                   "doc","salome","gui",self.name.lower(),
+                                   "index.html")
+      cpp_doc_path=os.path.join("%"+self.name+"CPP_ROOT_DIR%","share",
+                                "doc",self.name,"index.html")
+      gui_salomeapp=gui_salomeapp_gen.replace(salome_doc_path,cpp_doc_path)
       temp_dir=mkdtemp()
       gui_cxx_file_name=os.path.join(temp_dir,self.name+"GUI.cxx")
       gui_h_file_name=os.path.join(temp_dir,self.name+"GUI.h")
@@ -433,6 +477,7 @@ include $(top_srcdir)/adm_local/make_common_starter.am
       gui_config_file_name=os.path.join(temp_dir,"config")
       gui_xml_fr_file_name=os.path.join(temp_dir,self.name+"_en.xml")
       gui_xml_en_file_name=os.path.join(temp_dir,self.name+"_fr.xml")
+      gui_salomeapp_file_name=os.path.join(temp_dir,"SalomeApp.xml")
 
       list_of_gui_names=[]
 
@@ -476,5 +521,19 @@ include $(top_srcdir)/adm_local/make_common_starter.am
       gui_xml_en_file.close()
       list_of_gui_names.append(gui_xml_en_file_name)
 
-
+      gui_salomeapp_file=open(gui_salomeapp_file_name,"w")
+      gui_salomeapp_file.write(gui_salomeapp)
+      gui_salomeapp_file.close()
+      list_of_gui_names.append(gui_salomeapp_file_name)
       return list_of_gui_names
+
+  def getIdlInterfaces(self):
+    services = self.getIdlServices()
+    from .hxx_tmpl import interfaceidlhxx
+    Inherited=""
+    if self.use_medmem==True:
+        Inherited="Engines::EngineComponent,SALOME::MultiCommClass,SALOME_MED::MED_Gen_Driver"
+    else:
+        Inherited="Engines::EngineComponent"
+    return interfaceidlhxx.substitute(component=self.name,inherited=Inherited, services="\n".join(services))
+