mirror of
http://172.16.200.102/dalzilio/Fiacre_Simulator.git
synced 2025-11-22 17:17:57 +01:00
Initial commit.
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
|
||||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="src" path="xtend-gen"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
1
eclipse/plugins/com.irtsaintexupery.fiacre.simulator.msc.generator/.gitignore
vendored
Normal file
1
eclipse/plugins/com.irtsaintexupery.fiacre.simulator.msc.generator/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/bin/
|
||||
@@ -0,0 +1,34 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>com.irtsaintexupery.fiacre.simulator.msc.generator</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.pde.ManifestBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.pde.SchemaBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.pde.PluginNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@@ -0,0 +1,7 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.source=1.8
|
||||
@@ -0,0 +1,19 @@
|
||||
Manifest-Version: 1.0
|
||||
Bundle-ManifestVersion: 2
|
||||
Bundle-Name: Generator
|
||||
Bundle-SymbolicName: com.irtsaintexupery.fiacre.simulator.msc.generator;singleton:=true
|
||||
Bundle-Version: 1.0.0.qualifier
|
||||
Bundle-Activator: com.irtsaintexupery.fiacre.simulator.msc.generator.Activator
|
||||
Bundle-Vendor: IRTSAINTEXUPERY
|
||||
Require-Bundle: org.eclipse.ui,
|
||||
org.eclipse.core.runtime,
|
||||
org.eclipse.core.resources,
|
||||
org.eclipse.emf.ecore,
|
||||
com.irtsaintexupey.fiacre.simulator.msc,
|
||||
com.google.guava,
|
||||
org.eclipse.xtext.xbase.lib,
|
||||
org.eclipse.xtend.lib,
|
||||
org.eclipse.xtend.lib.macro
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
|
||||
Bundle-ActivationPolicy: lazy
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
source.. = src/
|
||||
output.. = bin/
|
||||
bin.includes = plugin.xml,\
|
||||
META-INF/,\
|
||||
.
|
||||
@@ -0,0 +1,36 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?eclipse version="3.4"?>
|
||||
<plugin>
|
||||
|
||||
<extension
|
||||
point="org.eclipse.ui.popupMenus">
|
||||
<objectContribution
|
||||
objectClass="org.eclipse.core.resources.IFile"
|
||||
id="com.irtsaintexupery.fiacre.simulator.msc.generator.contribution1">
|
||||
<menu
|
||||
label="Fiacre MSC generator"
|
||||
path="additions"
|
||||
id="com.irtsaintexupery.fiacre.simulator.msc.generator.menu1">
|
||||
<separator
|
||||
name="group1">
|
||||
</separator>
|
||||
</menu>
|
||||
<action
|
||||
label="Generate MSC"
|
||||
class="com.irtsaintexupery.fiacre.simulator.msc.generator.popup.actions.GenerateMSC"
|
||||
menubarPath="com.irtsaintexupery.fiacre.simulator.msc.generator.menu1/group1"
|
||||
enablesFor="1"
|
||||
id="com.irtsaintexupery.fiacre.simulator.msc.generator.newAction">
|
||||
</action>
|
||||
</objectContribution>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.ui.preferencePages">
|
||||
<page
|
||||
class="com.irtsaintexupery.fiacre.simulator.msc.generator.WorkbenchPreferencePage"
|
||||
id="com.irtsaintexupery.fiacre.simulator.msc.generator.page1"
|
||||
name="Fiacre MSC generator">
|
||||
</page>
|
||||
</extension>
|
||||
|
||||
</plugin>
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.irtsaintexupery.fiacre.simulator.msc.generator;
|
||||
|
||||
import org.eclipse.jface.resource.ImageDescriptor;
|
||||
import org.eclipse.ui.plugin.AbstractUIPlugin;
|
||||
import org.osgi.framework.BundleContext;
|
||||
|
||||
/**
|
||||
* The activator class controls the plug-in life cycle
|
||||
*/
|
||||
public class Activator extends AbstractUIPlugin {
|
||||
|
||||
// The plug-in ID
|
||||
public static final String PLUGIN_ID = "com.irtsaintexupery.fiacre.simulator.msc.generator"; //$NON-NLS-1$
|
||||
|
||||
// The shared instance
|
||||
private static Activator plugin;
|
||||
|
||||
public static String MSCGEN_PATH = "";
|
||||
/**
|
||||
* The constructor
|
||||
*/
|
||||
public Activator() {
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
|
||||
*/
|
||||
public void start(BundleContext context) throws Exception {
|
||||
super.start(context);
|
||||
plugin = this;
|
||||
MSCGEN_PATH = getPreferenceStore().getString("mscgen");
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
|
||||
*/
|
||||
public void stop(BundleContext context) throws Exception {
|
||||
plugin = null;
|
||||
super.stop(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the shared instance
|
||||
*
|
||||
* @return the shared instance
|
||||
*/
|
||||
public static Activator getDefault() {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an image descriptor for the image file at the given
|
||||
* plug-in relative path
|
||||
*
|
||||
* @param path the path
|
||||
* @return the image descriptor
|
||||
*/
|
||||
public static ImageDescriptor getImageDescriptor(String path) {
|
||||
return imageDescriptorFromPlugin(PLUGIN_ID, path);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.irtsaintexupery.fiacre.simulator.msc.generator;
|
||||
|
||||
import org.eclipse.jface.preference.DirectoryFieldEditor;
|
||||
import org.eclipse.jface.preference.FieldEditorPreferencePage;
|
||||
import org.eclipse.jface.preference.FileFieldEditor;
|
||||
import org.eclipse.ui.IWorkbench;
|
||||
import org.eclipse.ui.IWorkbenchPreferencePage;
|
||||
|
||||
|
||||
public class WorkbenchPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage{
|
||||
|
||||
@Override
|
||||
protected void createFieldEditors() {
|
||||
// TODO Auto-generated method stub
|
||||
addField(new FileFieldEditor("mscgen", "MSC generator", getFieldEditorParent()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(IWorkbench workbench) {
|
||||
// TODO Auto-generated method stub
|
||||
setPreferenceStore(Activator.getDefault().getPreferenceStore());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
package com.irtsaintexupery.fiacre.simulator.msc.generator.popup.actions;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.emf.common.util.URI;
|
||||
import org.eclipse.emf.ecore.resource.Resource;
|
||||
import org.eclipse.emf.ecore.resource.ResourceSet;
|
||||
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
|
||||
import org.eclipse.jface.action.IAction;
|
||||
import org.eclipse.jface.dialogs.MessageDialog;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
import org.eclipse.ui.IObjectActionDelegate;
|
||||
import org.eclipse.ui.IWorkbenchPart;
|
||||
|
||||
import com.irtsaintexupery.fiacre.simulator.msc.generator.Activator;
|
||||
import com.irtsaintexupery.fiacre.simulator.msc.msc.MSC;
|
||||
|
||||
|
||||
public class GenerateMSC implements IObjectActionDelegate {
|
||||
|
||||
private Shell shell;
|
||||
private ISelection selection;
|
||||
/**
|
||||
* Constructor for Action1.
|
||||
*/
|
||||
public GenerateMSC() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
|
||||
*/
|
||||
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
|
||||
shell = targetPart.getSite().getShell();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see IActionDelegate#run(IAction)
|
||||
*/
|
||||
public void run(IAction action) {
|
||||
// Créer un objet resourceSetImpl qui contiendra une ressource EMF (notre modèle)
|
||||
ResourceSet resSet = new ResourceSetImpl();
|
||||
|
||||
// Charger la ressource (notre modèle)
|
||||
URI modelURI = URI.createURI(getFile().getLocationURI().toString());
|
||||
Resource resource = resSet.getResource(modelURI, true);
|
||||
|
||||
// Récupérer le premier élément du modèle (élément racine)
|
||||
MSC msc = (MSC) resource.getContents().get(0);
|
||||
//System.out.println("process"+ msc);
|
||||
MSCGenerator mscgen= new MSCGenerator(msc);
|
||||
|
||||
try{
|
||||
PrintWriter writer = new PrintWriter(getFile().getLocation().toString()+".msc", "UTF-8");
|
||||
writer.println(mscgen.generate());
|
||||
writer.close();
|
||||
} catch (IOException e) {
|
||||
// do something
|
||||
}
|
||||
GeneratePng(getFile());
|
||||
try {
|
||||
getFile().getParent().refreshLocal(1, null);
|
||||
} catch (CoreException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
// added getFile() method
|
||||
private IFile getFile() {
|
||||
return (IFile) ((IStructuredSelection) selection).getFirstElement();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see IActionDelegate#selectionChanged(IAction, ISelection)
|
||||
*/
|
||||
public void selectionChanged(IAction action, ISelection selection) {
|
||||
// Don't forget this line.
|
||||
// It is the most important line.
|
||||
this.selection = selection;
|
||||
}
|
||||
protected static void GeneratePng(IFile file) {
|
||||
try {
|
||||
ProcessBuilder pb_make = new ProcessBuilder(Activator.MSCGEN_PATH,"-T", "png", "-o", file.getLocation().toString()+".png",
|
||||
file.getLocation().toString()+".msc");
|
||||
|
||||
|
||||
pb_make.directory(new File(file.getParent().getLocation().toString()));
|
||||
Process p = pb_make.start();
|
||||
p.waitFor();
|
||||
//System.out.println("Generate MSC chronogram");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
} catch (InterruptedException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
package com.irtsaintexupery.fiacre.simulator.msc.generator.popup.actions
|
||||
|
||||
import com.irtsaintexupery.fiacre.simulator.msc.msc.MSC
|
||||
import com.irtsaintexupery.fiacre.simulator.msc.msc.EnterStateStep
|
||||
import com.irtsaintexupery.fiacre.simulator.msc.msc.SynchronisationStep
|
||||
import com.irtsaintexupery.fiacre.simulator.msc.msc.SendStep
|
||||
import com.irtsaintexupery.fiacre.simulator.msc.msc.MicroStep
|
||||
|
||||
class MSCGenerator {
|
||||
var MSC msc
|
||||
|
||||
new(MSC _msc) {
|
||||
msc = _msc
|
||||
}
|
||||
|
||||
def String generate() {
|
||||
var String generated
|
||||
generated = "msc{" + "\n\n\t"
|
||||
generated += "# The entities " + "\n" + "\t"
|
||||
|
||||
for (site : msc.sites) {
|
||||
if(msc.sites.last != site) {
|
||||
generated += site.name + ", "
|
||||
} else {
|
||||
generated += site.name + ";\n\t"
|
||||
}
|
||||
}
|
||||
generated += "# The relations " + "\n" + "\t"
|
||||
generated += "|||;\n"
|
||||
|
||||
for (step : msc.steps) {
|
||||
for (micro : step.microSteps) {
|
||||
if(step.microSteps.last != micro) {
|
||||
generated += generate(micro) + ", "
|
||||
} else {
|
||||
generated += generate(micro) + ";\n\t"
|
||||
}
|
||||
}
|
||||
generated += "|||;\n"
|
||||
}
|
||||
generated += "\n}"
|
||||
generated
|
||||
}
|
||||
def generate(MicroStep micro) {
|
||||
if(micro instanceof EnterStateStep)
|
||||
generate(micro as EnterStateStep)
|
||||
else if(micro instanceof SynchronisationStep)
|
||||
generate(micro as SynchronisationStep)
|
||||
else
|
||||
generate(micro as SendStep)
|
||||
}
|
||||
|
||||
def String generate(EnterStateStep esst) {
|
||||
esst.site.name+" box "+ esst.site.name +"[label=\"" +esst.stateName+"\"]"
|
||||
}
|
||||
|
||||
def String generate(SynchronisationStep sst) {
|
||||
if(sst.sites.size ==1){
|
||||
sst.sites.get(0).name+" abox "+ sst.sites.get(0).name +"[label=\"sync\"]"
|
||||
}
|
||||
else{
|
||||
sst.sites.get(0).name +" :: "+sst.sites.get(1).name
|
||||
}
|
||||
}
|
||||
|
||||
def String generate(SendStep sst) {
|
||||
sst.senderSites.get(0).name+ " => "+ sst.receiverSites.get(0).name
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
/.MSCGenerator.java._trace
|
||||
/.MSCGenerator.xtendbin
|
||||
/MSCGenerator.java
|
||||
Reference in New Issue
Block a user