RosPythonTransform.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.TransformParameterFactory;
00014 import org.best_of_robotics.transform.ros.to.cplusplus.Activator;
00015 import org.best_of_robotics.transform.ros.to.cplusplus.EGLTransformer;
00016 import org.eclipse.core.commands.AbstractHandler;
00017 import org.eclipse.core.commands.ExecutionEvent;
00018 import org.eclipse.core.commands.ExecutionException;
00019 import org.eclipse.core.resources.IFile;
00020 import org.eclipse.jface.dialogs.MessageDialog;
00021 import org.eclipse.ui.IEditorInput;
00022 import org.eclipse.ui.IEditorPart;
00023 import org.eclipse.ui.IFileEditorInput;
00024 import org.eclipse.ui.PlatformUI;
00025 
00030 public class RosPythonTransform extends AbstractHandler {
00031         
00032         public RosPythonTransform() {           
00033         }
00034 
00035         @Override
00036         public Object execute(ExecutionEvent event) throws ExecutionException {
00037                 IFile sourcefile = null;
00038                 IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
00039                 if (editor != null) {
00040             IEditorInput input = editor.getEditorInput();
00041             if (input instanceof IFileEditorInput) {
00042                 sourcefile = ((IFileEditorInput)input).getFile();
00043                 System.out.println("File from editor: " + sourcefile.getLocation().toOSString());
00044                 if(sourcefile.getFileExtension().compareTo("ros_package") != 0 && sourcefile.getFileExtension().compareTo("ros_package_diagram")!=0)
00045                 {
00046                         sourcefile = null;
00047                         MessageDialog
00048                                         .openError(
00049                                                         PlatformUI.getWorkbench()
00050                                                                         .getActiveWorkbenchWindow().getShell(),
00051                                                         "Error on Editor Selection 2",
00052                                                         "Please select the editor from which you want to generate code and execute command again.");
00053                 }
00054                 
00055             }
00056         }
00057                 
00058                 
00059                 if(sourcefile == null)
00060                         return null;
00061                 
00062                 //configure new transform parameter
00063                 String cmd = "rospack find bride_templates";
00064                 String template_dir = "";
00065                 Runtime run = Runtime.getRuntime();
00066                 Process pr;
00067                 try {
00068                         pr = run.exec(cmd);
00069                         pr.waitFor();
00070                         BufferedReader buf = new BufferedReader(new InputStreamReader(pr.getInputStream()));
00071                         template_dir = buf.readLine();
00072                 } catch (IOException e) {
00073                         // TODO Auto-generated catch block
00074                         e.printStackTrace();
00075                 } catch (InterruptedException e) {
00076                         // TODO Auto-generated catch block
00077                         e.printStackTrace();
00078                 }
00079                 if(template_dir.length() == 0)
00080                 {
00081                         System.out.println("Couldn't find template package");
00082                         return null;
00083                 }
00084                 
00085                 System.out.println("Taking transformation: " + template_dir + "/python/package/package.egl");
00086                 
00087                 IEglTransformParameter eglTransformParameter = TransformParameterFactory.createEglTransformParameter();
00088                 eglTransformParameter.setTransformName("ROS Package to python implementation");
00089                 eglTransformParameter.setEglTransform("file://" + template_dir + "/python/package/package.egl");
00090                 eglTransformParameter.setPluginID(Activator.PLUGIN_ID);
00091                 eglTransformParameter.setSourceMetaModelURI("http://ros/1.0");
00092                 eglTransformParameter.setSourceModelFilePath(sourcefile.getLocation().removeFileExtension().toOSString() + ".ros_package");
00093                 eglTransformParameter.setSourceName("Source");
00094                 eglTransformParameter.setSourceReadOnLoad(true);
00095                 eglTransformParameter.setSourceStoreOnDisposal(false);
00096                 
00097                 eglTransformParameter.setOutputRoot("file:" + sourcefile.getProject().getLocation().toOSString());
00098                 
00099                 //get transform service
00100                 
00101                 
00102                 //do transform
00103                 EGLTransformer transformer = new EGLTransformer(eglTransformParameter);
00104                 transformer.transform();
00105                 
00106                 return null;
00107         }
00108 
00109 }


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