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
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
00076 e.printStackTrace();
00077 } catch (InterruptedException e) {
00078
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
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
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
00126 EGLTransformer transformer = new EGLTransformer(eglTransformParameter);
00127 transformer.transform();
00128
00129 return null;
00130 }
00131
00132 }