diff --git a/plugins/de.fraunhofer.ipa.roscode.generator/src/de/fraunhofer/ipa/roscode/generator/Ros2CodeGenerator.xtend b/plugins/de.fraunhofer.ipa.roscode.generator/src/de/fraunhofer/ipa/roscode/generator/Ros2CodeGenerator.xtend index 23db18105..1e7f98458 100644 --- a/plugins/de.fraunhofer.ipa.roscode.generator/src/de/fraunhofer/ipa/roscode/generator/Ros2CodeGenerator.xtend +++ b/plugins/de.fraunhofer.ipa.roscode.generator/src/de/fraunhofer/ipa/roscode/generator/Ros2CodeGenerator.xtend @@ -8,8 +8,9 @@ import org.eclipse.xtext.generator.IOutputConfigurationProvider import org.eclipse.xtext.generator.OutputConfiguration import java.util.Set import ros.* - - +import java.util.List +import java.util.ArrayList +import java.util.HashSet /** * Generates code from your model files on save. @@ -17,22 +18,94 @@ import ros.* * See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#code-generation */ class Ros2CodeGenerator extends AbstractGenerator { - String resourcepath String import_msgs int char_i + Node node + List PkgsList + Set set + override void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) { resourcepath = resource.URI.toString(); if (! resourcepath.contains("/ros-input")) { - for (node : resource.allContents.toIterable.filter(Node)){ - fsa.generateFile(node.getName()+".cpp",node.compile) + for (pkg : resource.allContents.toIterable.filter(Package)){ + fsa.generateFile(pkg.getName().toLowerCase+"/package.xml",pkg.compile_package_xml) + fsa.generateFile(pkg.getName().toLowerCase+"/CMakeLists.txt",pkg.compile_CMakeLists) + for (art : pkg.artifact){ + node = art.node + fsa.generateFile(pkg.getName().toLowerCase+"/src/"+node.name+".cpp",node.compile_node) + + } + } } } - } -def compile(Node node) ''' + +def compile_package_xml(Package pkg)''' + + + + «pkg.name» + 0.0.0 + This package contains the implementation of the node «pkg.artifact.get(0).node.name» + Jane Doe + Jane Doe + Apache 2.0 + + ament_cmake + + boost + rclcpp + «FOR depend_pkg:pkg.getPkgDependencies» + «depend_pkg» + «ENDFOR» + + ament_lint_auto + ament_lint_common + + + ament_cmake + + +''' + +def compile_CMakeLists(Package pkg)''' +cmake_minimum_required(VERSION 3.5) +project(«pkg.name») + +# Default to C++14 +if(NOT CMAKE_CXX_STANDARD) + set(CMAKE_CXX_STANDARD 14) +endif() + +if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") + add_compile_options(-Wall -Wextra -Wpedantic) +endif() + +find_package(ament_cmake REQUIRED) +find_package(Boost REQUIRED) +find_package(rclcpp REQUIRED) + «FOR depend_pkg:pkg.getPkgDependencies» +find_package(«depend_pkg» REQUIRED) + «ENDFOR» + +«FOR art:pkg.artifact» +add_executable(«art.name» src/«art.node.name».cpp) +ament_target_dependencies(«art.name» «FOR depend_pkg:pkg.getPkgDependencies»«depend_pkg» «ENDFOR») + +install(TARGETS + «art.name» + DESTINATION lib/${PROJECT_NAME}) +«ENDFOR» + +ament_package() +''' + +def compile_node(Node node) ''' #include #include #include @@ -149,6 +222,20 @@ int main(int argc, char * argv[]) } ''' + def List getPkgDependencies(Package pkg){ + set=new HashSet() + PkgsList = new ArrayList() + for (art:pkg.artifact){ + node=art.node + for (pub:node.publisher){set.add(pub.message.package.name)} + for (sub:node.subscriber){set.add(sub.message.package.name)} + for (srvserver:node.serviceserver){set.add(srvserver.service.package.name)} + for (srvclient:node.serviceclient){set.add(srvclient.service.package.name)} + } + PkgsList.addAll(set) + return PkgsList + } + def String check_message_include(String message_name){ import_msgs = message_name.toFirstLower; for (char_i =0; char_i < import_msgs.length; char_i++ ){