RosOrocosCppTransform.java
Go to the documentation of this file.
00001 
00004 package org.best_of_robotics.transform.ros.to.cplusplus.handler;
00005 
00006 import java.io.BufferedReader;
00007 import java.io.IOException;
00008 import java.io.InputStreamReader;
00009 
00010 import org.best_of_robotics.transform.service.ITransformService;
00011 import org.best_of_robotics.transform.service.access.TransformAccessActivator;
00012 import org.best_of_robotics.transform.service.parameter.IEglTransformParameter;
00013 import org.best_of_robotics.transform.service.parameter.IEtlTransformParameter;
00014 import org.best_of_robotics.transform.service.parameter.TransformParameterFactory;
00015 import org.best_of_robotics.transform.ros.to.cplusplus.Activator;
00016 import org.best_of_robotics.transform.ros.to.cplusplus.EGLTransformer;
00017 import org.best_of_robotics.transform.ros.to.cplusplus.EtlTransformer;
00018 import org.eclipse.core.commands.AbstractHandler;
00019 import org.eclipse.core.commands.ExecutionEvent;
00020 import org.eclipse.core.commands.ExecutionException;
00021 import org.eclipse.core.resources.IFile;
00022 import org.eclipse.jface.dialogs.MessageDialog;
00023 import org.eclipse.ui.IEditorInput;
00024 import org.eclipse.ui.IEditorPart;
00025 import org.eclipse.ui.IFileEditorInput;
00026 import org.eclipse.ui.PlatformUI;
00027 
00032 public class RosOrocosCppTransform extends AbstractHandler {
00033         
00034         public RosOrocosCppTransform() {                
00035         }
00036 
00037         @Override
00038         public Object execute(ExecutionEvent event) throws ExecutionException {
00039                 IFile sourcefile = null;
00040                 IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
00041                 if (editor != null) {
00042             IEditorInput input = editor.getEditorInput();
00043             if (input instanceof IFileEditorInput) {
00044                 sourcefile = ((IFileEditorInput)input).getFile();
00045                 System.out.println("File from editor: " + sourcefile.getLocation().toOSString());
00046                 if(sourcefile.getFileExtension().compareTo("ros_package") != 0 && sourcefile.getFileExtension().compareTo("ros_package_diagram")!=0)
00047                 {
00048                         sourcefile = null;
00049                         MessageDialog
00050                                         .openError(
00051                                                         PlatformUI.getWorkbench()
00052                                                                         .getActiveWorkbenchWindow().getShell(),
00053                                                         "Error on Editor Selection 2",
00054                                                         "Please select the editor from which you want to generate code and execute command again.");
00055                 }
00056                 
00057             }
00058         }
00059                 
00060                 
00061                 if(sourcefile == null)
00062                         return null;
00063                 
00064                 //configure new transform parameter
00065                 String cmd = "rospack find bride_templates";
00066                 String template_dir = "";
00067                 Runtime run = Runtime.getRuntime();
00068                 Process pr;
00069                 try {
00070                         pr = run.exec(cmd);
00071                         pr.waitFor();
00072                         BufferedReader buf = new BufferedReader(new InputStreamReader(pr.getInputStream()));
00073                         template_dir = buf.readLine();
00074                 } catch (IOException e) {
00075                         // TODO Auto-generated catch block
00076                         e.printStackTrace();
00077                 } catch (InterruptedException e) {
00078                         // TODO Auto-generated catch block
00079                         e.printStackTrace();
00080                 }
00081                 if(template_dir.length() == 0)
00082                 {
00083                         System.out.println("Couldn't find template package");
00084                         return null;
00085                 }
00086                 
00087                 System.out.println("Taking transformation: " + template_dir + "/cpp/rtt_ros_package/package.egl");
00088                 
00089                 //First Transfer ROS Model to OROCOS Model
00090                 //configure new transform parameter
00091                 /*IEtlTransformParameter etlTransformParameter = TransformParameterFactory.createEtlTransformParameter();
00092                 etlTransformParameter.setTransformName("ROS To OROCOS");
00093                 etlTransformParameter.setEtlTransformPath("file://" + template_dir + "/cpp/rtt_ros_package/ros_to_orocos.etl");
00094                 etlTransformParameter.setPluginID(Activator.PLUGIN_ID);
00095                 etlTransformParameter.setSourceMetaModelURI("http://ros/1.0");
00096                 etlTransformParameter.setSourceModelFilePath(sourcefile.getLocation().removeFileExtension().toOSString() + ".ros_package");
00097                 etlTransformParameter.setSourceName("Source");
00098                 etlTransformParameter.setSourceReadOnLoad(true);
00099                 etlTransformParameter.setSourceStoreOnDisposal(false);
00100                 etlTransformParameter.setTargetMetaModelURI("org.best_of_robotics.model.rtt");
00101                 
00102                 String targetModelFilePath = sourcefile.getLocation().removeFileExtension().toOSString() + "gen.rtt";
00103                 
00104                 etlTransformParameter.setTargetModelFilePath(targetModelFilePath);
00105                 etlTransformParameter.setTargetName("Target");
00106                 etlTransformParameter.setTargetReadOnLoad(false);
00107                 etlTransformParameter.setTargetStoreOnDisposal(true);
00108                 
00109                 //do transform
00110                 EtlTransformer transformer = new EtlTransformer(etlTransformParameter);
00111                 transformer.transform();*/
00112                 
00113                 IEglTransformParameter eglTransformParameter = TransformParameterFactory.createEglTransformParameter();
00114                 eglTransformParameter.setTransformName("ROS Pacakge to cpp implementation");
00115                 eglTransformParameter.setEglTransform("file://" + template_dir + "/cpp/rtt_ros_package/package.egl");
00116                 eglTransformParameter.setPluginID(Activator.PLUGIN_ID);
00117                 eglTransformParameter.setSourceMetaModelURI("http://ros/1.0");
00118                 eglTransformParameter.setSourceModelFilePath(sourcefile.getLocation().removeFileExtension().toOSString() + ".ros_package");
00119                 eglTransformParameter.setSourceName("Source");
00120                 eglTransformParameter.setSourceReadOnLoad(true);
00121                 eglTransformParameter.setSourceStoreOnDisposal(false);
00122                 
00123                 eglTransformParameter.setOutputRoot("file:" + sourcefile.getProject().getLocation().toOSString());
00124                 
00125                 //do transform
00126                 EGLTransformer transformer = new EGLTransformer(eglTransformParameter);
00127                 transformer.transform();
00128                 
00129                 return null;
00130         }
00131 
00132 }


bride_plugin_source
Author(s): Alexander Bubeck
autogenerated on Sun Oct 5 2014 22:38:34