]> SALOME platform Git repositories - tools/hxx2salome.git/blobdiff - scripts/hxx2salome
Salome HOME
set-up .gitignore file
[tools/hxx2salome.git] / scripts / hxx2salome
index c7a25a3d33e4783732faae51bb6549f29f0487cd..55052993ab145402cecfd649f33efa859c17f6ae 100755 (executable)
@@ -1,4 +1,8 @@
 #!/bin/bash
+# --
+# Copyright (C) CEA, EDF
+# Author : Nicolas Crouzet (CEA)
+# --
 #
 #
 # salome2 environment file (.bash or .sh) - can also be specified with -e option
@@ -32,9 +36,10 @@ usage()
     echo -e "                            (this file is also used for sourcing environment before compilation if it has sh or bash syntax,"
     echo -e "                             if the syntax is csh, it is not sourced and for compiling (-c option) environment must be set up before)"
     echo -e "    -s script_extension   : to use if your environment file name doesn't have extension"
+    echo -e "    -g                    : to create a gui part in your component building tree"
     echo -e "    -c                    : to compile after generation"
     echo -e "                            (use this option only if you don't have dependencies in your header or libraries"
-    echo -e "                             if it is the case, you'll have to adapt your Makefile.in
+    echo -e "                             if it is the case, you'll have to adapt your Makefile.am
     echo -e "    -l                    : to launch salome "
     exit
 }
@@ -159,7 +164,8 @@ generate_module_source()
 # -------------------------  parse hxx file and generate code  ---------------------------------------
 #
     echo -e "\n-> Extract public functions\n"
-    cat ${hxx_file} | awk -f ${gene_dir}/parse01.awk | awk -f ${gene_dir}/parse1.awk > ${CLASS_NAME}_public_functions
+    # we get first rid of the c like comments (parse01), then of the excetion specification (sed filter), finnaly we extract public functions (parse1)
+    cat ${hxx_file} | awk -f ${gene_dir}/parse01.awk | sed 's/virtual //g' | sed 's/MEDMEM_EXPORT//g' | sed 's/throw.*;/;/g' | awk -f ${gene_dir}/parse1.awk > ${CLASS_NAME}_public_functions
     cat ${CLASS_NAME}_public_functions
     if [ ! -s ${CLASS_NAME}_public_functions ]
     then
@@ -174,7 +180,7 @@ generate_module_source()
 # outputs
     echo -e "\n  IDL file:"
     cat parse_result > hxx2salome_journal
-    echo -e "\n----------------- IDL file ------------------\n">>hxx2salome_journal
+    echo -e "\n----------------- IDL file ------------------\n" >> hxx2salome_journal
     cat code_idl >> hxx2salome_journal
     cat code_idl
     echo -e "\n----------------- hxx file ------------------\n" >> hxx2salome_journal
@@ -183,13 +189,35 @@ generate_module_source()
     cat code_cxx >> hxx2salome_journal
     echo
 #
+# select archive for MEDMEM or MEDCoupling
+    grep MEDCoupling code_idl >& /dev/null
+    if [ $? -eq 0 ]
+    then
+       template_component_archive=${gene_dir}/template_coupling_src.tgz
+    else
+       template_component_archive=${gene_dir}/template_src.tgz
+    fi
+#
 #
 # -------------------  duplicates template module and insert generated code  ------------------------------
 #
     echo -e "\n-> Duplicate template module" | tee hxx2salome_journal
-    tar xvfz ${gene_dir}/template_src.tgz >> hxx2salome_journal
-    mv TEMPLATE_SRC ${CLASS_NAME}_SRC
-    ${gene_dir}/renameSalomeModule -i TEMPLATE ${CLASS_NAME} ${CLASS_NAME}_SRC >> hxx2salome_journal
+    tar xvfz ${template_component_archive} >> hxx2salome_journal
+    mv HXX2SALOME_GENERIC_CLASS_NAME_SRC ${CLASS_NAME}_SRC
+    ${gene_dir}/renameSalomeModule -i HXX2SALOME_GENERIC_CLASS_NAME ${CLASS_NAME} ${CLASS_NAME}_SRC 
+    ###>> hxx2salome_journal
+    ${gene_dir}/renameSalomeModule -i hxx2salome_generic_class_name ${class_name} ${CLASS_NAME}_SRC
+    ###>> hxx2salome_journal
+#
+    if [ $make_gui -eq 0 ]
+    then
+       echo -e "\n-> Delete GUI part from the tree" >> hxx2salome_journal
+       'rm' -rf ${CLASS_NAME}_SRC/src/${CLASS_NAME}GUI
+       sed "s/${CLASS_NAME}GUI//" < ${CLASS_NAME}_SRC/src/Makefile.am > /tmp/h2smkf.$$
+       mv /tmp/h2smkf.$$ ${CLASS_NAME}_SRC/src/Makefile.am
+       cat ${CLASS_NAME}_SRC/configure.ac | awk ' $0 !~ "^.*GUI/Makefile"  { print $0}' > /tmp/h2scac.$$
+       mv /tmp/h2scac.$$  ${CLASS_NAME}_SRC/configure.ac
+    fi
 #
     echo -e "\n-> Substitute generated code in idl file"
     echo "// this idl file was generated by hxx2salome" > tmpfile
@@ -217,12 +245,12 @@ generate_module_source()
     get_python_test_file
     get_info_makefile
     
-    echo -e "\n-> Substitute flags in Makefile.in"
-    sed "s?HXX2SALOME_INCLUDE?${makefile_include}?g
-         s?HXX2SALOME_PYTHON_FILE?${python_test_file}?g
-         s?HXX2SALOME_LIB?${makefile_lib}?g
-        " ${CLASS_NAME}_SRC/src/${CLASS_NAME}/Makefile.in > tmpfile
-    mv tmpfile ${CLASS_NAME}_SRC/src/${CLASS_NAME}/Makefile.in
+    echo -e "\n-> Substitute flags in Makefile.am"
+    sed -i "s?HXX2SALOME_INCLUDE?${makefile_include}?g
+            s?HXX2SALOME_PYTHON_FILE?${python_test_file}?g
+            s?HXX2SALOME_LIB?${makefile_lib}?g
+           " ${CLASS_NAME}_SRC/src/${CLASS_NAME}/Makefile.am
+          
 #
 # generate component catalog
     echo -e "\n-> Generate component catalog" | tee hxx2salome_journal
@@ -234,10 +262,19 @@ generate_module_source()
     fi
     cd ${CLASS_NAME}_SRC/resources
     VER=`cat ${KERNEL_ROOT_DIR}/bin/salome/VERSION | awk ' { print $NF }'` # extract number of version 
-    ${idlparser} -Wbcatalog=tmp.xml,icon=${CLASS_NAME}.png,version=${VER} -I${KERNEL_ROOT_DIR}/idl/salome -I${MED_ROOT_DIR}/idl/salome ../idl/${CLASS_NAME}_Gen.idl >& /dev/null | tee  hxx2salome_journal
-    cat tmp.xml | sed 's/_Gen//g' > ${CLASS_NAME}Catalog.xml
-    rm tmp.xml
-#
+    export PYTHONPATH=${PYTHONPATH}:${KERNEL_ROOT_DIR}/bin/salome  # to be sure IDLparser is in PYTHONPATH
+    #${idlparser} -Wbcatalog=${CLASS_NAME}Catalog.xml,icon=${CLASS_NAME}.png,version=${VER} -I${KERNEL_ROOT_DIR}/idl/salome -I${MED_ROOT_DIR}/idl/salome ../idl/${CLASS_NAME}_Gen.idl >& /dev/null | tee  hxx2salome_journal
+    ${idlparser} -Wbcatalog=${CLASS_NAME}Catalog.xml,icon=${CLASS_NAME}.png,version=${VER} -I${KERNEL_ROOT_DIR}/idl/salome -I${MED_ROOT_DIR}/idl/salome ../idl/${CLASS_NAME}_Gen.idl 
+    if [ -f ${CLASS_NAME}Catalog.xml ]
+    then
+        sed -i "s?_Gen??g
+               s?SALOME/vectorOfDouble?dblevec?g
+                s?SALOME/vectorOfLong?intvec?g
+               s?${CLASS_NAME}_ORB/StrSeq?stringvec?g"  ${CLASS_NAME}Catalog.xml
+    else
+       echo Error with runIDLparser - the catalog was not generated
+       exit
+    fi
 }
 
 compile()
@@ -320,6 +357,8 @@ update_environment()
 copy_component_source()
 {
     mv ${tmp_dir}/${CLASS_NAME}_SRC/* ${NEW_COMPONENT_SRC_DIR}
+    mkdir -p ${NEW_COMPONENT_BUILD_DIR}
+    mkdir -p ${NEW_COMPONENT_ROOT_DIR}
 }
 
 good_bye()
@@ -340,11 +379,12 @@ good_bye()
     echo -e "\trun Salome"
     echo -e "\tadd ${CLASS_NAME} to the Salome modules list"
     echo -e "\t\t(with the --modules option of the runSalome command or"
-    echo -e "\t\tby editing the ~/.salome_2.2.4/salome.launch file)"
+    echo -e "\t\tby editing your own per-user configuration file ~/.SalomeApprc.3.x.x)"
     echo -e "\nIf the header of your component includes other headers that are not in the same directories,"
-    echo -e "or if yout library has dependencies you want to specify,"
-    echo -e "you'll have to modify the following Makefile:in : "
-    echo -e "\t\${${CLASS_NAME}_SRC_DIR}/src/${CLASS_NAME}/Makefile.in"
+    echo -e "or if your library has dependencies you want to specify,"
+    echo -e "you'll have to modify the following files Makefile.am: "
+    echo -e "\t\${${CLASS_NAME}_SRC_DIR}/src/${CLASS_NAME}/Makefile.am"
+    echo -e "\t\${${CLASS_NAME}_SRC_DIR}/src/${CLASS_NAME}GUI/Makefile.am"
 }
 
 launch_salome()
@@ -395,12 +435,21 @@ CPP_ROOT_DIR=
 NEW_COMPONENT_ROOT_DIR=
 NEW_COMPONENT_SRC_DIR=
 NEW_COMPONENT_BUILD_DIR=
+SHELL_EXT=sh
 do_compile=0
 do_launch=0
+make_gui=0
 #
 welcome # print some welcome info
 #
-while getopts "cs:e:h:l" Option
+gene_dir=`dirname $0`
+if [ ! -f ${gene_dir}/parse3.awk -o ! -f ${gene_dir}/template_src.tgz ] # final check
+then
+    echo -e "\nError : scripts parse3.awk or template_src.tgz not present in hxx2salome directory  : $gene_dir"
+    usage
+fi
+#
+while getopts "cs:e:h:lg" Option
 do
    case $Option in
      h) usage
@@ -411,6 +460,7 @@ do
            csh)  SHELL_EXT=csh;;      
            *)    SHELL_EXT=sh;;
        esac;;
+     g) make_gui=1;;
      c) do_compile=1;;
      l) do_launch=1;;
      *) echo "Unimplemented option chosen : $Option."
@@ -450,8 +500,12 @@ fi
 #                                         only if KERNEL_ROOT_DIR and MED_ROOT_DIR are defined
 if [ "${SHELL_EXT}" == "sh" ] && [ ${ENVIRON_FILE} ] && [ -f ${ENVIRON_FILE} ]
 then
+   pwd
    echo -e "\n    Environment file with sh syntax specified => we source ${ENVIRON_FILE}"
-   source ${ENVIRON_FILE}
+   cat ${ENVIRON_FILE} | sed "s/ENV_FOR_LAUNCH=1/ENV_FOR_LAUNCH=0/g" > ${ENVIRON_FILE}.tmp
+   source ${ENVIRON_FILE}.tmp
+   #rm ${ENVIRON_FILE}.tmp
+   #source ${ENVIRON_FILE}
 else
    if [ ${KERNEL_ROOT_DIR} ] && [ -d ${KERNEL_ROOT_DIR} ] && [ ${MED_ROOT_DIR} ] && [ -d ${MED_ROOT_DIR} ]
    then
@@ -465,25 +519,14 @@ else
        fi
    fi
 fi
-
-#
-if [ ${HXX2SALOME_ROOT_DIR} ] && [ -d ${HXX2SALOME_ROOT_DIR} ]
-then
-    gene_dir=${HXX2SALOME_ROOT_DIR}
-else
-    gene_dir=`pwd` # case where hxx2salome was launched from HXX2SALOME directory
-fi
-echo "    hxx2salome directory : $gene_dir"
-if [ ! -f ${gene_dir}/parse1.awk -o ! -f ${gene_dir}/parse2.awk ] # check if script are found
-then
-    echo -e "\nError : Variable HXX2SALOME_ROOT_DIR shoud be set, or hxx2salome should be launched localy from bin directory"
-    usage
-fi
 #
 # get class name
 #
-CLASS_NAME=`awk '$1 == "class" && $0 !~ /;/ {print $2}' ${hxx_file}`
+CLASS_NAME=`awk '$1 == "class" && $0 !~ /;/ {print $2}' ${hxx_file}|awk -F: '{print $1}'`
 echo "    Name of class :" $CLASS_NAME
+class_name=`echo ${CLASS_NAME} | awk '{print tolower($0)}'`
+echo class_name = ${class_name}
+
 if [ ! $CLASS_NAME ]
 then
     echo -e "\nError:\n  Sorry - No class definition was found!\n  Please check your header file\n"