This commit is contained in:
Laurent Fainsin 2021-10-12 18:49:13 +02:00
parent ce79718fa6
commit de42fac315
1478 changed files with 377356 additions and 3749 deletions

View file

@ -1,113 +1,114 @@
!ENTRY org.eclipse.emf.cdo.explorer 4 0 2021-10-10 00:17:27.091
!MESSAGE InterruptedException
!ENTRY org.eclipse.ui 4 0 2021-10-12 17:30:30.073
!MESSAGE Unhandled event loop exception
!STACK 0
java.lang.InterruptedException
at java.base/java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireSharedInterruptibly(AbstractQueuedSynchronizer.java:1343)
at java.base/java.util.concurrent.Semaphore.acquire(Semaphore.java:318)
at org.eclipse.net4j.util.lifecycle.Lifecycle.lock(Lifecycle.java:312)
at org.eclipse.net4j.util.lifecycle.Lifecycle.internalDeactivate(Lifecycle.java:118)
at org.eclipse.net4j.util.lifecycle.ShareableLifecycle.internalDeactivate(ShareableLifecycle.java:52)
at org.eclipse.net4j.util.lifecycle.Lifecycle.deactivate(Lifecycle.java:170)
at org.eclipse.net4j.util.lifecycle.LifecycleUtil.deactivate(LifecycleUtil.java:235)
at org.eclipse.net4j.util.lifecycle.LifecycleUtil.deactivate(LifecycleUtil.java:225)
at org.eclipse.emf.cdo.internal.explorer.bundle.OM.disposeManagers(OM.java:83)
at org.eclipse.emf.cdo.internal.explorer.bundle.OM$Activator.doStop(OM.java:136)
at org.eclipse.net4j.util.om.OSGiActivator.stop(OSGiActivator.java:92)
at org.eclipse.osgi.internal.framework.BundleContextImpl$3.run(BundleContextImpl.java:871)
at org.eclipse.osgi.internal.framework.BundleContextImpl$3.run(BundleContextImpl.java:1)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at org.eclipse.osgi.internal.framework.BundleContextImpl.stop(BundleContextImpl.java:863)
at org.eclipse.osgi.internal.framework.EquinoxBundle.stopWorker0(EquinoxBundle.java:1025)
at org.eclipse.osgi.internal.framework.EquinoxBundle$EquinoxModule.stopWorker(EquinoxBundle.java:370)
at org.eclipse.osgi.container.Module.doStop(Module.java:660)
at org.eclipse.osgi.container.Module.stop(Module.java:521)
at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.decStartLevel(ModuleContainer.java:1886)
at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.doContainerStartLevel(ModuleContainer.java:1761)
at org.eclipse.osgi.container.SystemModule.stopWorker(SystemModule.java:275)
at org.eclipse.osgi.internal.framework.EquinoxBundle$SystemBundle$EquinoxSystemModule.stopWorker(EquinoxBundle.java:202)
at org.eclipse.osgi.container.Module.doStop(Module.java:660)
at org.eclipse.osgi.container.Module.stop(Module.java:521)
at org.eclipse.osgi.container.SystemModule.stop(SystemModule.java:207)
at org.eclipse.osgi.internal.framework.EquinoxBundle$SystemBundle$EquinoxSystemModule$1.run(EquinoxBundle.java:220)
at java.base/java.lang.Thread.run(Thread.java:829)
!SESSION 2021-10-10 00:17:29.406 -----------------------------------------------
eclipse.buildId=4.17.0.I20200902-1800
java.version=11.0.11
java.vendor=Ubuntu
BootLoader constants: OS=linux, ARCH=x86_64, WS=gtk, NL=fr_FR
Framework arguments: -product org.eclipse.epp.package.modeling.product
Command-line arguments: -os linux -ws gtk -arch x86_64 -product org.eclipse.epp.package.modeling.product
org.eclipse.swt.SWTException: Graphic is disposed
at org.eclipse.swt.SWT.error(SWT.java:4869)
at org.eclipse.swt.SWT.error(SWT.java:4784)
at org.eclipse.swt.SWT.error(SWT.java:4755)
at org.eclipse.swt.graphics.Image.getBounds(Image.java:1012)
at org.eclipse.swt.widgets.Tree.rendererRender(Tree.java:3280)
at org.eclipse.swt.widgets.Tree.rendererRenderProc(Tree.java:3109)
at org.eclipse.swt.widgets.Display.rendererRenderProc(Display.java:1636)
at org.eclipse.swt.internal.gtk.GTK.gtk_main_do_event(Native Method)
at org.eclipse.swt.widgets.Display.eventProc(Display.java:1517)
at org.eclipse.swt.internal.gtk.OS.g_main_context_iteration(Native Method)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:4505)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$5.run(PartRenderingEngine.java:1157)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:338)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1046)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:155)
at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:644)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:338)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:551)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:153)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:150)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:203)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:401)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:255)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:657)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:594)
at org.eclipse.equinox.launcher.Main.run(Main.java:1465)
at org.eclipse.equinox.launcher.Main.main(Main.java:1438)
!ENTRY org.eclipse.emf.cdo.explorer 4 0 2021-10-10 00:27:51.311
!MESSAGE InterruptedException
!ENTRY org.eclipse.ui 4 0 2021-10-12 17:30:36.280
!MESSAGE Unhandled event loop exception
!STACK 0
java.lang.InterruptedException
at java.base/java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireSharedInterruptibly(AbstractQueuedSynchronizer.java:1343)
at java.base/java.util.concurrent.Semaphore.acquire(Semaphore.java:318)
at org.eclipse.net4j.util.lifecycle.Lifecycle.lock(Lifecycle.java:312)
at org.eclipse.net4j.util.lifecycle.Lifecycle.internalDeactivate(Lifecycle.java:118)
at org.eclipse.net4j.util.lifecycle.ShareableLifecycle.internalDeactivate(ShareableLifecycle.java:52)
at org.eclipse.net4j.util.lifecycle.Lifecycle.deactivate(Lifecycle.java:170)
at org.eclipse.net4j.util.lifecycle.LifecycleUtil.deactivate(LifecycleUtil.java:235)
at org.eclipse.net4j.util.lifecycle.LifecycleUtil.deactivate(LifecycleUtil.java:225)
at org.eclipse.emf.cdo.internal.explorer.bundle.OM.disposeManagers(OM.java:83)
at org.eclipse.emf.cdo.internal.explorer.bundle.OM$Activator.doStop(OM.java:136)
at org.eclipse.net4j.util.om.OSGiActivator.stop(OSGiActivator.java:92)
at org.eclipse.osgi.internal.framework.BundleContextImpl$3.run(BundleContextImpl.java:871)
at org.eclipse.osgi.internal.framework.BundleContextImpl$3.run(BundleContextImpl.java:1)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at org.eclipse.osgi.internal.framework.BundleContextImpl.stop(BundleContextImpl.java:863)
at org.eclipse.osgi.internal.framework.EquinoxBundle.stopWorker0(EquinoxBundle.java:1025)
at org.eclipse.osgi.internal.framework.EquinoxBundle$EquinoxModule.stopWorker(EquinoxBundle.java:370)
at org.eclipse.osgi.container.Module.doStop(Module.java:660)
at org.eclipse.osgi.container.Module.stop(Module.java:521)
at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.decStartLevel(ModuleContainer.java:1886)
at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.doContainerStartLevel(ModuleContainer.java:1761)
at org.eclipse.osgi.container.SystemModule.stopWorker(SystemModule.java:275)
at org.eclipse.osgi.internal.framework.EquinoxBundle$SystemBundle$EquinoxSystemModule.stopWorker(EquinoxBundle.java:202)
at org.eclipse.osgi.container.Module.doStop(Module.java:660)
at org.eclipse.osgi.container.Module.stop(Module.java:521)
at org.eclipse.osgi.container.SystemModule.stop(SystemModule.java:207)
at org.eclipse.osgi.internal.framework.EquinoxBundle$SystemBundle$EquinoxSystemModule$1.run(EquinoxBundle.java:220)
at java.base/java.lang.Thread.run(Thread.java:829)
!SESSION 2021-10-10 12:58:50.569 -----------------------------------------------
eclipse.buildId=4.17.0.I20200902-1800
java.version=11.0.11
java.vendor=Ubuntu
BootLoader constants: OS=linux, ARCH=x86_64, WS=gtk, NL=fr_FR
Framework arguments: -product org.eclipse.epp.package.modeling.product
Command-line arguments: -os linux -ws gtk -arch x86_64 -product org.eclipse.epp.package.modeling.product
org.eclipse.swt.SWTException: Graphic is disposed
at org.eclipse.swt.SWT.error(SWT.java:4869)
at org.eclipse.swt.SWT.error(SWT.java:4784)
at org.eclipse.swt.SWT.error(SWT.java:4755)
at org.eclipse.swt.graphics.Image.getBounds(Image.java:1012)
at org.eclipse.swt.widgets.Tree.rendererRender(Tree.java:3280)
at org.eclipse.swt.widgets.Tree.rendererRenderProc(Tree.java:3109)
at org.eclipse.swt.widgets.Display.rendererRenderProc(Display.java:1636)
at org.eclipse.swt.internal.gtk.GTK.gtk_main_do_event(Native Method)
at org.eclipse.swt.widgets.Display.eventProc(Display.java:1517)
at org.eclipse.swt.internal.gtk.OS.g_main_context_iteration(Native Method)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:4505)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$5.run(PartRenderingEngine.java:1157)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:338)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1046)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:155)
at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:644)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:338)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:551)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:153)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:150)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:203)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:401)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:255)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:657)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:594)
at org.eclipse.equinox.launcher.Main.run(Main.java:1465)
at org.eclipse.equinox.launcher.Main.main(Main.java:1438)
!ENTRY org.eclipse.emf.cdo.explorer 4 0 2021-10-10 14:40:22.852
!MESSAGE InterruptedException
!ENTRY org.eclipse.ui 4 0 2021-10-12 17:31:16.305
!MESSAGE Unhandled event loop exception
!STACK 0
java.lang.InterruptedException
at java.base/java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireSharedInterruptibly(AbstractQueuedSynchronizer.java:1343)
at java.base/java.util.concurrent.Semaphore.acquire(Semaphore.java:318)
at org.eclipse.net4j.util.lifecycle.Lifecycle.lock(Lifecycle.java:312)
at org.eclipse.net4j.util.lifecycle.Lifecycle.internalDeactivate(Lifecycle.java:118)
at org.eclipse.net4j.util.lifecycle.ShareableLifecycle.internalDeactivate(ShareableLifecycle.java:52)
at org.eclipse.net4j.util.lifecycle.Lifecycle.deactivate(Lifecycle.java:170)
at org.eclipse.net4j.util.lifecycle.LifecycleUtil.deactivate(LifecycleUtil.java:235)
at org.eclipse.net4j.util.lifecycle.LifecycleUtil.deactivate(LifecycleUtil.java:225)
at org.eclipse.emf.cdo.internal.explorer.bundle.OM.disposeManagers(OM.java:83)
at org.eclipse.emf.cdo.internal.explorer.bundle.OM$Activator.doStop(OM.java:136)
at org.eclipse.net4j.util.om.OSGiActivator.stop(OSGiActivator.java:92)
at org.eclipse.osgi.internal.framework.BundleContextImpl$3.run(BundleContextImpl.java:871)
at org.eclipse.osgi.internal.framework.BundleContextImpl$3.run(BundleContextImpl.java:1)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at org.eclipse.osgi.internal.framework.BundleContextImpl.stop(BundleContextImpl.java:863)
at org.eclipse.osgi.internal.framework.EquinoxBundle.stopWorker0(EquinoxBundle.java:1025)
at org.eclipse.osgi.internal.framework.EquinoxBundle$EquinoxModule.stopWorker(EquinoxBundle.java:370)
at org.eclipse.osgi.container.Module.doStop(Module.java:660)
at org.eclipse.osgi.container.Module.stop(Module.java:521)
at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.decStartLevel(ModuleContainer.java:1886)
at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.doContainerStartLevel(ModuleContainer.java:1761)
at org.eclipse.osgi.container.SystemModule.stopWorker(SystemModule.java:275)
at org.eclipse.osgi.internal.framework.EquinoxBundle$SystemBundle$EquinoxSystemModule.stopWorker(EquinoxBundle.java:202)
at org.eclipse.osgi.container.Module.doStop(Module.java:660)
at org.eclipse.osgi.container.Module.stop(Module.java:521)
at org.eclipse.osgi.container.SystemModule.stop(SystemModule.java:207)
at org.eclipse.osgi.internal.framework.EquinoxBundle$SystemBundle$EquinoxSystemModule$1.run(EquinoxBundle.java:220)
at java.base/java.lang.Thread.run(Thread.java:829)
org.eclipse.swt.SWTException: Graphic is disposed
at org.eclipse.swt.SWT.error(SWT.java:4869)
at org.eclipse.swt.SWT.error(SWT.java:4784)
at org.eclipse.swt.SWT.error(SWT.java:4755)
at org.eclipse.swt.graphics.Image.getBounds(Image.java:1012)
at org.eclipse.swt.widgets.Tree.rendererRender(Tree.java:3280)
at org.eclipse.swt.widgets.Tree.rendererRenderProc(Tree.java:3109)
at org.eclipse.swt.widgets.Display.rendererRenderProc(Display.java:1636)
at org.eclipse.swt.internal.gtk.GTK.gtk_main_do_event(Native Method)
at org.eclipse.swt.widgets.Display.eventProc(Display.java:1517)
at org.eclipse.swt.internal.gtk.OS.g_main_context_iteration(Native Method)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:4505)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$5.run(PartRenderingEngine.java:1157)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:338)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1046)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:155)
at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:644)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:338)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:551)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:153)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:150)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:203)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:401)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:255)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:657)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:594)
at org.eclipse.equinox.launcher.Main.run(Main.java:1465)
at org.eclipse.equinox.launcher.Main.main(Main.java:1438)

View file

@ -0,0 +1,6 @@
source.. = src/,\
src-gen/,\
xtend-gen/
bin.includes = META-INF/,\
.,\
plugin.xml

View file

@ -0,0 +1,205 @@
package simplepdl.manip;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
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.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import petrinet.PetrinetPackage;
import petrinet.Place;
import petrinet.Transition;
import petrinet.Arc;
import petrinet.Network;
import petrinet.Node;
import petrinet.PetrinetFactory;
import simplepdl.Process;
import simplepdl.WorkDefinition;
import simplepdl.WorkSequence;
import simplepdl.WorkSequenceType;
import simplepdl.SimplepdlPackage;
public class simplepdl2petrinet {
public static void main(String[] args) {
// Charger les package SimplePDL et Petrinet afin de les enregistrer dans le registre d'Eclipse.
SimplepdlPackage packageInstance = SimplepdlPackage.eINSTANCE;
PetrinetPackage packageInstance2 = PetrinetPackage.eINSTANCE;
// Enregistrer l'extension ".xmi" comme devant être ouverte à
// l'aide d'un objet "XMIResourceFactoryImpl"
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("xmi", new XMIResourceFactoryImpl());
// Créer un objet resourceSetImpl qui contiendra une ressource EMF (le modèle)
ResourceSet resSet = new ResourceSetImpl();
// Charger la ressource (notre modèle)
URI modelURI = URI.createURI("test.xmi");
Resource resource = resSet.getResource(modelURI, true);
// Récupérer le premier élément du modèle (élément racine)
Process process = (Process) resource.getContents().get(0);
// La fabrique pour fabriquer les éléments de PetriNET
PetrinetFactory myFactory = PetrinetFactory.eINSTANCE;
// Créer un élément Network
Network network = myFactory.createNetwork();
network.setName(process.getName());
// Conversion des WorkDefinition en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof WorkDefinition) {
WorkDefinition wd = (WorkDefinition) o;
String name = wd.getName();
Place idle = myFactory.createPlace();
idle.setName(name + "_idle");
idle.setTokens(1);
Place started = myFactory.createPlace();
started.setName(name + "_started");
started.setTokens(0);
Place running = myFactory.createPlace();
running.setName(name + "_running");
running.setTokens(0);
Place finished = myFactory.createPlace();
finished.setName(name + "_finished");
finished.setTokens(0);
Arc pause2start = myFactory.createArc();
pause2start.setTarget(idle);
pause2start.setOutgoing(false);
pause2start.setWeight(1);
Arc start2running = myFactory.createArc();
start2running.setTarget(running);
start2running.setOutgoing(true);
start2running.setWeight(1);
Arc start2started = myFactory.createArc();
start2started.setTarget(started);
start2started.setOutgoing(true);
start2started.setWeight(1);
Transition start = myFactory.createTransition();
start.setName(name + "_start");
start.getArcs().add(pause2start);
start.getArcs().add(start2running);
start.getArcs().add(start2started);
Arc running2finish = myFactory.createArc();
running2finish.setTarget(running);
running2finish.setOutgoing(false);
running2finish.setWeight(1);
Arc finish2finished = myFactory.createArc();
finish2finished.setTarget(finished);
finish2finished.setOutgoing(true);
finish2finished.setWeight(1);
Transition finish = myFactory.createTransition();
finish.setName(name + "_finish");
finish.getArcs().add(running2finish);
finish.getArcs().add(finish2finished);
network.getNodes().add(idle);
network.getNodes().add(start);
network.getNodes().add(started);
network.getNodes().add(running);
network.getNodes().add(finish);
network.getNodes().add(finished);
}
}
// Conversion des WorkSequence en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof WorkSequence) {
WorkSequence ws = (WorkSequence) o;
WorkSequenceType type = ws.getLinkType();
WorkDefinition predecessor = ws.getPredecessor();
WorkDefinition successor = ws.getSuccessor();
// creation des suffixs permettant la recherche des noeuds
String predecessor_suffix = new String();
String successor_suffix = new String();
switch (type) {
case START_TO_START:
predecessor_suffix = "_started";
successor_suffix = "_start";
break;
case START_TO_FINISH:
predecessor_suffix = "_started";
successor_suffix = "_finished";
break;
case FINISH_TO_START:
predecessor_suffix = "_finished";
successor_suffix = "_start";
break;
case FINISH_TO_FINISH:
predecessor_suffix = "_finished";
successor_suffix = "_finish";
break;
default:
System.out.print("the fuck ?");
break;
}
// creation du read-arc
Arc arc1 = myFactory.createArc();
arc1.setOutgoing(false);
arc1.setWeight(1);
Arc arc2 = myFactory.createArc();
arc2.setOutgoing(true);
arc2.setWeight(1);
for (Node node : network.getNodes()) {
if (node instanceof Place) {
Place place = (Place) node;
if (place.getName().equals(predecessor.getName() + predecessor_suffix)) {
arc1.setTarget(place);
arc2.setTarget(place);
}
}
if (node instanceof Transition) {
Transition transition = (Transition) node;
if (transition.getName().equals(successor.getName() + successor_suffix)) {
transition.getArcs().add(arc1);
transition.getArcs().add(arc2);
}
}
}
}
}
// Conversion des WorkSequence en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof Resource) {
Resource r = (Resource) o;
EObject qty = r.getEObject("quantity");
System.out.println(qty);
}
}
// Créer le nouveau xmi (modèle convertit)
URI convURI = URI.createURI("models/Developpement_petrinet.xmi");
Resource conv = resSet.createResource(convURI);
// Ajouter le Network dans le nouveau modèle
conv.getContents().add(network);
// Sauver la ressource
try {
conv.save(Collections.EMPTY_MAP);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,6 @@
source.. = src/,\
src-gen/,\
xtend-gen/
bin.includes = META-INF/,\
.,\
plugin.xml

View file

@ -0,0 +1,45 @@
// automatically generated by Xtext
grammar fr.n7.simplepdl.txt.PDL with org.eclipse.xtext.common.Terminals
import "http://simplepdl"
import "http://www.eclipse.org/emf/2002/Ecore" as ecore
Process :
'process' name=ID '{'
processElements+=ProcessElement*
'}' ;
ProcessElement :
WorkDefinition | WorkSequence | Guidance | Resource
;
WorkDefinition :
'wd' name=ID
requests+=Request*
;
WorkSequence :
'ws' linkType=WorkSequenceType
'from' predecessor=[WorkDefinition]
'to' successor=[WorkDefinition]
;
Guidance :
'note' text=STRING
;
Resource :
'res' name=ID quantity=INT
;
Request :
'req' target=[Resource] quantity=INT
;
enum WorkSequenceType :
startToStart = 's2s'
| finishToStart = 'f2s'
| startToFinish = 's2f'
| finishToFinish = 'f2f'
;

View file

@ -0,0 +1,16 @@
source.. = src/,\
src-gen/,\
xtend-gen/
bin.includes = META-INF/,\
.,\
plugin.xml
additional.bundles = org.eclipse.xtext.xbase,\
org.eclipse.xtext.common.types,\
org.eclipse.xtext.xtext.generator,\
org.eclipse.emf.codegen.ecore,\
org.eclipse.emf.mwe.utils,\
org.eclipse.emf.mwe2.launch,\
org.eclipse.emf.mwe2.lib,\
org.objectweb.asm,\
org.apache.commons.logging,\
org.apache.log4j

View file

@ -0,0 +1,51 @@
// automatically generated by Xtext
grammar fr.n7.simplepdl.txt.PDL with org.eclipse.xtext.common.Terminals
import "http://simplepdl"
import "http://www.eclipse.org/emf/2002/Ecore" as ecore
Process returns Process :
{Process}
'process' name=ID '{'
processElements+=ProcessElement*
'}' ;
ProcessElement returns ProcessElement:
WorkDefinition | WorkSequence | Guidance | Resource
;
WorkDefinition returns WorkDefinition :
{WorkDefinition}
'wd' name=ID
requests+=Request*
;
WorkSequence returns WorkSequence :
{WorkSequence}
'ws' linkType=WorkSequenceType
'from' predecessor=[WorkDefinition]
'to' successor=[WorkDefinition]
;
Guidance returns Guidance :
{Guidance}
'note' text=STRING
;
Resource returns Resource :
{Resource}
'res' name=ID quantity=INT
;
Request returns Request :
{Request}
'req' target=[Resource] quantity=INT
;
enum WorkSequenceType :
startToStart = 's2s'
| finishToStart = 'f2s'
| startToFinish = 's2f'
| finishToFinish = 'f2f'
;

View file

@ -1,88 +0,0 @@
package simplepdl.manip;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
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.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import petrinet.PetrinetPackage;
import petrinet.PetrinetFactory;
import simplepdl.Process;
import simplepdl.WorkDefinition;
import simplepdl.WorkSequence;
import simplepdl.WorkSequenceType;
import simplepdl.SimplepdlFactory;
import simplepdl.SimplepdlPackage;
public class simplepdl2petrinet {
public static void main(String[] args) {
// Charger le package SimplePDL afin de l'enregistrer dans le registre d'Eclipse.
SimplepdlPackage packageInstance = SimplepdlPackage.eINSTANCE;
PetrinetPackage packageInstance2 = PetrinetPackage.eINSTANCE;
// Enregistrer l'extension ".xmi" comme devant être ouverte à
// l'aide d'un objet "XMIResourceFactoryImpl"
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("xmi", new XMIResourceFactoryImpl());
// Créer un objet resourceSetImpl qui contiendra une ressource EMF (le modèle)
ResourceSet resSet = new ResourceSetImpl();
// Définir la ressource (le modèle)
URI modelURI = URI.createURI("models/SimplePDLCreator_Created_Process.xmi");
Resource resource = resSet.createResource(modelURI);
// La fabrique pour fabriquer les éléments de SimplePDL
SimplepdlFactory myFactory = SimplepdlFactory.eINSTANCE;
// Créer un élément Process
Process process = myFactory.createProcess();
process.setName("Mon premier processus");
// Ajouter le Process dans le modèle
resource.getContents().add(process);
// Ajouter deux WorkDefinitions
WorkDefinition wd1 = myFactory.createWorkDefinition();
wd1.setName("Ma première WorkDefinition, quelle émotion");
WorkDefinition wd2 = myFactory.createWorkDefinition();
wd2.setName("Ma deuxième WorkDefinition, toujours autant d'émotion");
process.getProcessElements().add(wd1);
process.getProcessElements().add(wd2);
// Ajouter une WorkSequence entre les deux WorkDefinitions
WorkSequence seq = myFactory.createWorkSequence();
seq.setPredecessor(wd1);
seq.setSuccessor(wd2);
seq.setLinkType(WorkSequenceType.FINISH_TO_FINISH);
process.getProcessElements().add(seq);
// Ajouter une deuxième WorkSequence entre les deux WorkDefinitions
WorkSequence seq2 = myFactory.createWorkSequence();
seq2.setPredecessor(wd1);
seq2.setSuccessor(wd2);
seq2.setLinkType(WorkSequenceType.START_TO_START);
process.getProcessElements().add(seq2);
// Sauver la ressource
try {
resource.save(Collections.EMPTY_MAP);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,26 @@
grammar fr.n7.PDL1 with org.eclipse.xtext.common.Terminals
generate pDL1 "http://www.n7.fr/PDL1"
Process :
'process' name=ID
ProcessElement :
WorkDefinition | WorkSequence | Guidance;
WorkDefinition :
'wd' name=ID;
WorkSequence :
'ws' linkType=WorkSequenceType
'from' predecessor=[WorkDefinition]
'to' successor=[WorkDefinition] ;
Guidance :
'note' texte=STRING ;
enum WorkSequenceType :
start2start = 's2s'
| finish2start = 'f2s'
| start2finish = 's2f'
| finish2finish = 'f2f'
;

View file

@ -1,87 +0,0 @@
package simplepdl.manip;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
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.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import petrinet.PetrinetPackage;
import simplepdl.Process;
import simplepdl.WorkDefinition;
import simplepdl.WorkSequence;
import simplepdl.WorkSequenceType;
import simplepdl.SimplepdlFactory;
import simplepdl.SimplepdlPackage;
public class simplepdl2petrinet {
public static void main(String[] args) {
// Charger le package SimplePDL afin de l'enregistrer dans le registre d'Eclipse.
SimplepdlPackage packageInstance = SimplepdlPackage.eINSTANCE;
PetrinetPackage packageInstance2 = PetrinetPackage.eINSTANCE;
// Enregistrer l'extension ".xmi" comme devant être ouverte à
// l'aide d'un objet "XMIResourceFactoryImpl"
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("xmi", new XMIResourceFactoryImpl());
// Créer un objet resourceSetImpl qui contiendra une ressource EMF (le modèle)
ResourceSet resSet = new ResourceSetImpl();
// Définir la ressource (le modèle)
URI modelURI = URI.createURI("models/SimplePDLCreator_Created_Process.xmi");
Resource resource = resSet.createResource(modelURI);
// La fabrique pour fabriquer les éléments de SimplePDL
SimplepdlFactory myFactory = SimplepdlFactory.eINSTANCE;
// Créer un élément Process
Process process = myFactory.createProcess();
process.setName("Mon premier processus");
// Ajouter le Process dans le modèle
resource.getContents().add(process);
// Ajouter deux WorkDefinitions
WorkDefinition wd1 = myFactory.createWorkDefinition();
wd1.setName("Ma première WorkDefinition, quelle émotion");
WorkDefinition wd2 = myFactory.createWorkDefinition();
wd2.setName("Ma deuxième WorkDefinition, toujours autant d'émotion");
process.getProcessElements().add(wd1);
process.getProcessElements().add(wd2);
// Ajouter une WorkSequence entre les deux WorkDefinitions
WorkSequence seq = myFactory.createWorkSequence();
seq.setPredecessor(wd1);
seq.setSuccessor(wd2);
seq.setLinkType(WorkSequenceType.FINISH_TO_FINISH);
process.getProcessElements().add(seq);
// Ajouter une deuxième WorkSequence entre les deux WorkDefinitions
WorkSequence seq2 = myFactory.createWorkSequence();
seq2.setPredecessor(wd1);
seq2.setSuccessor(wd2);
seq2.setLinkType(WorkSequenceType.START_TO_START);
process.getProcessElements().add(seq2);
// Sauver la ressource
try {
resource.save(Collections.EMPTY_MAP);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,29 @@
grammar fr.n7.PDL3 with org.eclipse.xtext.common.Terminals
generate pDL3 "http://www.n7.fr/PDL3"
Process :
'process' ':' name=ID
processElements+=ProcessElement* ;
ProcessElement :
WorkDefinitionList | WorkSequenceList ;
WorkDefinitionList :
'workdefinitions' ':' WorkDefinition+=WorkDefinition* ;
WorkDefinition :
name=ID ";" ;
WorkSequenceList :
'worksequences' ':' WorkSequence+=WorkSequence* ;
WorkSequence :
predecessor=[WorkDefinition] linkType=WorkSequenceType successor=[WorkDefinition] ";" ;
enum WorkSequenceType :
start2start = 's2s'
| finish2start = 'f2s'
| start2finish = 's2f'
| finish2finish = 'f2f'
;

View file

@ -0,0 +1,205 @@
package simplepdl.manip;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
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.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import petrinet.PetrinetPackage;
import petrinet.Place;
import petrinet.Transition;
import petrinet.Arc;
import petrinet.Network;
import petrinet.Node;
import petrinet.PetrinetFactory;
import simplepdl.Process;
import simplepdl.WorkDefinition;
import simplepdl.WorkSequence;
import simplepdl.WorkSequenceType;
import simplepdl.SimplepdlPackage;
public class simplepdl2petrinet {
public static void main(String[] args) {
// Charger les package SimplePDL et Petrinet afin de les enregistrer dans le registre d'Eclipse.
SimplepdlPackage packageInstance = SimplepdlPackage.eINSTANCE;
PetrinetPackage packageInstance2 = PetrinetPackage.eINSTANCE;
// Enregistrer l'extension ".xmi" comme devant être ouverte à
// l'aide d'un objet "XMIResourceFactoryImpl"
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("xmi", new XMIResourceFactoryImpl());
// Créer un objet resourceSetImpl qui contiendra une ressource EMF (le modèle)
ResourceSet resSet = new ResourceSetImpl();
// Charger la ressource (notre modèle)
URI modelURI = URI.createURI("test.xmi");
Resource resource = resSet.getResource(modelURI, true);
// Récupérer le premier élément du modèle (élément racine)
Process process = (Process) resource.getContents().get(0);
// La fabrique pour fabriquer les éléments de PetriNET
PetrinetFactory myFactory = PetrinetFactory.eINSTANCE;
// Créer un élément Network
Network network = myFactory.createNetwork();
network.setName(process.getName());
// Conversion des WorkDefinition en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof WorkDefinition) {
WorkDefinition wd = (WorkDefinition) o;
String name = wd.getName();
Place idle = myFactory.createPlace();
idle.setName(name + "_idle");
idle.setTokens(1);
Place started = myFactory.createPlace();
started.setName(name + "_started");
started.setTokens(0);
Place running = myFactory.createPlace();
running.setName(name + "_running");
running.setTokens(0);
Place finished = myFactory.createPlace();
finished.setName(name + "_finished");
finished.setTokens(0);
Arc pause2start = myFactory.createArc();
pause2start.setTarget(idle);
pause2start.setOutgoing(false);
pause2start.setWeight(1);
Arc start2running = myFactory.createArc();
start2running.setTarget(running);
start2running.setOutgoing(true);
start2running.setWeight(1);
Arc start2started = myFactory.createArc();
start2started.setTarget(started);
start2started.setOutgoing(true);
start2started.setWeight(1);
Transition start = myFactory.createTransition();
start.setName(name + "_start");
start.getArcs().add(pause2start);
start.getArcs().add(start2running);
start.getArcs().add(start2started);
Arc running2finish = myFactory.createArc();
running2finish.setTarget(running);
running2finish.setOutgoing(false);
running2finish.setWeight(1);
Arc finish2finished = myFactory.createArc();
finish2finished.setTarget(finished);
finish2finished.setOutgoing(true);
finish2finished.setWeight(1);
Transition finish = myFactory.createTransition();
finish.setName(name + "_finish");
finish.getArcs().add(running2finish);
finish.getArcs().add(finish2finished);
network.getNodes().add(idle);
network.getNodes().add(start);
network.getNodes().add(started);
network.getNodes().add(running);
network.getNodes().add(finish);
network.getNodes().add(finished);
}
}
// Conversion des WorkSequence en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof WorkSequence) {
WorkSequence ws = (WorkSequence) o;
WorkSequenceType type = ws.getLinkType();
WorkDefinition predecessor = ws.getPredecessor();
WorkDefinition successor = ws.getSuccessor();
// creation des suffixs permettant la recherche des noeuds
String predecessor_suffix = new String();
String successor_suffix = new String();
switch (type) {
case START_TO_START:
predecessor_suffix = "_started";
successor_suffix = "_start";
break;
case START_TO_FINISH:
predecessor_suffix = "_started";
successor_suffix = "_finished";
break;
case FINISH_TO_START:
predecessor_suffix = "_finished";
successor_suffix = "_start";
break;
case FINISH_TO_FINISH:
predecessor_suffix = "_finished";
successor_suffix = "_finish";
break;
default:
System.out.print("the fuck ?");
break;
}
// creation du read-arc
Arc arc1 = myFactory.createArc();
arc1.setOutgoing(false);
arc1.setWeight(1);
Arc arc2 = myFactory.createArc();
arc2.setOutgoing(true);
arc2.setWeight(1);
for (Node node : network.getNodes()) {
if (node instanceof Place) {
Place place = (Place) node;
if (place.getName().equals(predecessor.getName() + predecessor_suffix)) {
arc1.setTarget(place);
arc2.setTarget(place);
}
}
if (node instanceof Transition) {
Transition transition = (Transition) node;
if (transition.getName().equals(successor.getName() + successor_suffix)) {
transition.getArcs().add(arc1);
transition.getArcs().add(arc2);
}
}
}
}
}
// Conversion des WorkSequence en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof Resource) {
Resource r = (Resource) o;
EObject qty = r.getEObject("quantity");
System.out.println(qty);
System.out.println("mdr"));
}
}
// Créer le nouveau xmi (modèle convertit)
URI convURI = URI.createURI("models/Developpement_petrinet.xmi");
Resource conv = resSet.createResource(convURI);
// Ajouter le Network dans le nouveau modèle
conv.getContents().add(network);
// Sauver la ressource
try {
conv.save(Collections.EMPTY_MAP);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View file

@ -1,88 +0,0 @@
package simplepdl.manip;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
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.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import petrinet.PetrinetPackage;
import petrinet.PetrinetFactory;
import simplepdl.Process;
import simplepdl.WorkDefinition;
import simplepdl.WorkSequence;
import simplepdl.WorkSequenceType;
import simplepdl.SimplepdlFactory;
import simplepdl.SimplepdlPackage;
public class simplepdl2petrinet {
public static void main(String[] args) {
// Charger les package SimplePDL et Petrinet afin de les enregistrer dans le registre d'Eclipse.
SimplepdlPackage packageInstance = SimplepdlPackage.eINSTANCE;
PetrinetPackage packageInstance2 = PetrinetPackage.eINSTANCE;
// Enregistrer l'extension ".xmi" comme devant être ouverte à
// l'aide d'un objet "XMIResourceFactoryImpl"
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("xmi", new XMIResourceFactoryImpl());
// Créer un objet resourceSetImpl qui contiendra une ressource EMF (le modèle)
ResourceSet resSet = new ResourceSetImpl();
// Définir la ressource (le modèle)
URI modelURI = URI.createURI("models/SimplePDL2PetriNET.xmi");
Resource resource = resSet.createResource(modelURI);
// La fabrique pour fabriquer les éléments de SimplePDL
SimplepdlFactory myFactory = SimplepdlFactory.eINSTANCE;
// Créer un élément Process
Process process = myFactory.createProcess();
process.setName("Mon premier processus");
// Ajouter le Process dans le modèle
resource.getContents().add(process);
// Ajouter deux WorkDefinitions
WorkDefinition wd1 = myFactory.createWorkDefinition();
wd1.setName("Ma première WorkDefinition, quelle émotion");
WorkDefinition wd2 = myFactory.createWorkDefinition();
wd2.setName("Ma deuxième WorkDefinition, toujours autant d'émotion");
process.getProcessElements().add(wd1);
process.getProcessElements().add(wd2);
// Ajouter une WorkSequence entre les deux WorkDefinitions
WorkSequence seq = myFactory.createWorkSequence();
seq.setPredecessor(wd1);
seq.setSuccessor(wd2);
seq.setLinkType(WorkSequenceType.FINISH_TO_FINISH);
process.getProcessElements().add(seq);
// Ajouter une deuxième WorkSequence entre les deux WorkDefinitions
WorkSequence seq2 = myFactory.createWorkSequence();
seq2.setPredecessor(wd1);
seq2.setSuccessor(wd2);
seq2.setLinkType(WorkSequenceType.START_TO_START);
process.getProcessElements().add(seq2);
// Sauver la ressource
try {
resource.save(Collections.EMPTY_MAP);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,30 @@
grammar fr.n7.PDL1 with org.eclipse.xtext.common.Terminals
generate pDL1 "http://www.n7.fr/PDL1"
Process :
'process' ':' name=ID
processElements+=ProcessElement* ;
ProcessElement :
WorkDefinitionList | WorkSequenceList ;
WorkDefinitionList :
'workdefinitions' ':' WorkDefinition+=WorkDefinition* ;
WorkDefinition :
name=ID ";" ;
WorkSequenceList :
'worksequences' ':' WorkSequence+=WorkSequence* ;
WorkSequence :
predecessor=[WorkDefinition] linkType=WorkSequenceType successor=[WorkDefinition] ;
enum WorkSequenceType :
start2start = 's2s'
| finish2start = 'f2s'
| start2finish = 's2f'
| finish2finish = 'f2f'
;

View file

@ -0,0 +1,218 @@
package simplepdl.manip;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
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.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import petrinet.Arc;
import petrinet.Network;
import petrinet.Node;
import petrinet.PetrinetFactory;
import petrinet.PetrinetPackage;
import petrinet.Place;
import petrinet.Transition;
import simplepdl.Process;
import simplepdl.SimplepdlPackage;
import simplepdl.WorkDefinition;
import simplepdl.WorkSequence;
import simplepdl.WorkSequenceType;
public class simplepdl2petrinet {
public static void main(String[] args) {
// Charger les package SimplePDL et Petrinet afin de les enregistrer dans le registre d'Eclipse.
SimplepdlPackage packageInstance = SimplepdlPackage.eINSTANCE;
PetrinetPackage packageInstance2 = PetrinetPackage.eINSTANCE;
// Enregistrer l'extension ".xmi" comme devant être ouverte à
// l'aide d'un objet "XMIResourceFactoryImpl"
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("xmi", new XMIResourceFactoryImpl());
// Créer un objet resourceSetImpl qui contiendra une ressource EMF (le modèle)
ResourceSet resSet = new ResourceSetImpl();
// Charger la ressource (notre modèle)
URI modelURI = URI.createURI("test.xmi");
Resource resource = resSet.getResource(modelURI, true);
// Récupérer le premier élément du modèle (élément racine)
Process process = (Process) resource.getContents().get(0);
// La fabrique pour fabriquer les éléments de PetriNET
PetrinetFactory myFactory = PetrinetFactory.eINSTANCE;
// Créer un élément Network
Network network = myFactory.createNetwork();
network.setName(process.getName());
// Conversion des WorkDefinition en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof WorkDefinition) {
WorkDefinition wd = (WorkDefinition) o;
String name = wd.getName();
Place idle = myFactory.createPlace();
idle.setName(name + "_idle");
idle.setTokens(1);
Place started = myFactory.createPlace();
started.setName(name + "_started");
started.setTokens(0);
Place running = myFactory.createPlace();
running.setName(name + "_running");
running.setTokens(0);
Place finished = myFactory.createPlace();
finished.setName(name + "_finished");
finished.setTokens(0);
Arc pause2start = myFactory.createArc();
pause2start.setTarget(idle);
pause2start.setOutgoing(false);
pause2start.setWeight(1);
Arc start2running = myFactory.createArc();
start2running.setTarget(running);
start2running.setOutgoing(true);
start2running.setWeight(1);
Arc start2started = myFactory.createArc();
start2started.setTarget(started);
start2started.setOutgoing(true);
start2started.setWeight(1);
Transition start = myFactory.createTransition();
start.setName(name + "_start");
start.getArcs().add(pause2start);
start.getArcs().add(start2running);
start.getArcs().add(start2started);
Arc running2finish = myFactory.createArc();
running2finish.setTarget(running);
running2finish.setOutgoing(false);
running2finish.setWeight(1);
Arc finish2finished = myFactory.createArc();
finish2finished.setTarget(finished);
finish2finished.setOutgoing(true);
finish2finished.setWeight(1);
Transition finish = myFactory.createTransition();
finish.setName(name + "_finish");
finish.getArcs().add(running2finish);
finish.getArcs().add(finish2finished);
network.getNodes().add(idle);
network.getNodes().add(start);
network.getNodes().add(started);
network.getNodes().add(running);
network.getNodes().add(finish);
network.getNodes().add(finished);
}
}
// Conversion des WorkSequence en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof WorkSequence) {
WorkSequence ws = (WorkSequence) o;
WorkSequenceType type = ws.getLinkType();
WorkDefinition predecessor = ws.getPredecessor();
WorkDefinition successor = ws.getSuccessor();
// creation des suffixs permettant la recherche des noeuds
String predecessor_suffix = new String();
String successor_suffix = new String();
switch (type) {
case START_TO_START:
predecessor_suffix = "_started";
successor_suffix = "_start";
break;
case START_TO_FINISH:
predecessor_suffix = "_started";
successor_suffix = "_finished";
break;
case FINISH_TO_START:
predecessor_suffix = "_finished";
successor_suffix = "_start";
break;
case FINISH_TO_FINISH:
predecessor_suffix = "_finished";
successor_suffix = "_finish";
break;
default:
System.out.print("the fuck ?");
break;
}
// creation du read-arc
Arc arc1 = myFactory.createArc();
arc1.setOutgoing(false);
arc1.setWeight(1);
Arc arc2 = myFactory.createArc();
arc2.setOutgoing(true);
arc2.setWeight(1);
for (Node node : network.getNodes()) {
if (node instanceof Place) {
Place place = (Place) node;
if (place.getName().equals(predecessor.getName() + predecessor_suffix)) {
arc1.setTarget(place);
arc2.setTarget(place);
}
}
if (node instanceof Transition) {
Transition transition = (Transition) node;
if (transition.getName().equals(successor.getName() + successor_suffix)) {
transition.getArcs().add(arc1);
transition.getArcs().add(arc2);
}
}
}
}
}
// Conversion des Resource et Request en Node et Arcs
for (Object o : process.getProcessElements()) {
if (o instanceof simplepdl.Resource) {
simplepdl.Resource r = (simplepdl.Resource) o;
String name = r.getName();
int qty = r.getQuantity();
Place res = myFactory.createPlace();
res.setName(name);
res.setTokens(qty);
}
if (o instanceof simplepdl.Request) {
simplepdl.Request r = (simplepdl.Request) o;
WorkDefinition target = r.getTarget();
int qty = r.getQuantity();
Place res = myFactory.createPlace();
res.setName(name);
res.setTokens(qty);
}
}
// Créer le nouveau xmi (modèle convertit)
URI convURI = URI.createURI("models/Developpement_petrinet.xmi");
Resource conv = resSet.createResource(convURI);
// Ajouter le Network dans le nouveau modèle
conv.getContents().add(network);
// Sauver la ressource
try {
conv.save(Collections.EMPTY_MAP);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,180 @@
/**
*/
package simplepdl.provider;
import java.util.Collection;
import java.util.List;
import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.util.ResourceLocator;
import org.eclipse.emf.edit.provider.ComposeableAdapterFactory;
import org.eclipse.emf.edit.provider.IEditingDomainItemProvider;
import org.eclipse.emf.edit.provider.IItemLabelProvider;
import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
import org.eclipse.emf.edit.provider.IItemPropertySource;
import org.eclipse.emf.edit.provider.IStructuredItemContentProvider;
import org.eclipse.emf.edit.provider.ITreeItemContentProvider;
import org.eclipse.emf.edit.provider.ItemPropertyDescriptor;
import org.eclipse.emf.edit.provider.ItemProviderAdapter;
import org.eclipse.emf.edit.provider.ViewerNotification;
import simplepdl.Request;
import simplepdl.SimplepdlPackage;
/**
* This is the item provider adapter for a {@link simplepdl.Request} object.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public class RequestItemProvider
extends ItemProviderAdapter
implements
IEditingDomainItemProvider,
IStructuredItemContentProvider,
ITreeItemContentProvider,
IItemLabelProvider,
IItemPropertySource {
/**
* This constructs an instance from a factory and a notifier.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public RequestItemProvider(AdapterFactory adapterFactory) {
super(adapterFactory);
}
/**
* This returns the property descriptors for the adapted class.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public List<IItemPropertyDescriptor> getPropertyDescriptors(Object object) {
if (itemPropertyDescriptors == null) {
super.getPropertyDescriptors(object);
addQuantityPropertyDescriptor(object);
addTargetPropertyDescriptor(object);
}
return itemPropertyDescriptors;
}
/**
* This adds a property descriptor for the Quantity feature.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
protected void addQuantityPropertyDescriptor(Object object) {
itemPropertyDescriptors.add
(createItemPropertyDescriptor
(((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(),
getResourceLocator(),
getString("_UI_Request_quantity_feature"),
getString("_UI_PropertyDescriptor_description", "_UI_Request_quantity_feature", "_UI_Request_type"),
SimplepdlPackage.Literals.REQUEST__QUANTITY,
true,
false,
false,
ItemPropertyDescriptor.INTEGRAL_VALUE_IMAGE,
null,
null));
}
/**
* This adds a property descriptor for the Target feature.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
protected void addTargetPropertyDescriptor(Object object) {
itemPropertyDescriptors.add
(createItemPropertyDescriptor
(((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(),
getResourceLocator(),
getString("_UI_Request_target_feature"),
getString("_UI_PropertyDescriptor_description", "_UI_Request_target_feature", "_UI_Request_type"),
SimplepdlPackage.Literals.REQUEST__TARGET,
true,
false,
true,
null,
null,
null));
}
/**
* This returns Request.gif.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public Object getImage(Object object) {
return overlayImage(object, getResourceLocator().getImage("full/obj16/Request"));
}
/**
* This returns the label text for the adapted class.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public String getText(Object object) {
Request request = (Request)object;
String targetname = request.getTarget() != null ? request.getTarget().getName() : "";
return getString("_UI_Request_type") + " --" + request.getQuantity() + "--> " + targetname;
}
/**
* This handles model notifications by calling {@link #updateChildren} to update any cached
* children and by creating a viewer notification, which it passes to {@link #fireNotifyChanged}.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public void notifyChanged(Notification notification) {
updateChildren(notification);
switch (notification.getFeatureID(Request.class)) {
case SimplepdlPackage.REQUEST__QUANTITY:
fireNotifyChanged(new ViewerNotification(notification, notification.getNotifier(), false, true));
return;
}
super.notifyChanged(notification);
}
/**
* This adds {@link org.eclipse.emf.edit.command.CommandParameter}s describing the children
* that can be created under this object.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
protected void collectNewChildDescriptors(Collection<Object> newChildDescriptors, Object object) {
super.collectNewChildDescriptors(newChildDescriptors, object);
}
/**
* Return the resource locator for this item provider's resources.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public ResourceLocator getResourceLocator() {
return SimplepdlEditPlugin.INSTANCE;
}
}

View file

@ -0,0 +1,191 @@
package simplepdl.manip;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
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.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import petrinet.PetrinetPackage;
import petrinet.Place;
import petrinet.Transition;
import petrinet.Arc;
import petrinet.Network;
import petrinet.Node;
import petrinet.PetrinetFactory;
import simplepdl.Process;
import simplepdl.WorkDefinition;
import simplepdl.WorkSequence;
import simplepdl.WorkSequenceType;
import simplepdl.SimplepdlPackage;
public class simplepdl2petrinet {
public static void main(String[] args) {
// Charger les package SimplePDL et Petrinet afin de les enregistrer dans le registre d'Eclipse.
SimplepdlPackage packageInstance = SimplepdlPackage.eINSTANCE;
PetrinetPackage packageInstance2 = PetrinetPackage.eINSTANCE;
// Enregistrer l'extension ".xmi" comme devant être ouverte à
// l'aide d'un objet "XMIResourceFactoryImpl"
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("xmi", new XMIResourceFactoryImpl());
// Créer un objet resourceSetImpl qui contiendra une ressource EMF (le modèle)
ResourceSet resSet = new ResourceSetImpl();
// Charger la ressource (notre modèle)
URI modelURI = URI.createURI("pdl-sujet.xmi");
Resource resource = resSet.getResource(modelURI, true);
// Récupérer le premier élément du modèle (élément racine)
Process process = (Process) resource.getContents().get(0);
// La fabrique pour fabriquer les éléments de PetriNET
PetrinetFactory myFactory = PetrinetFactory.eINSTANCE;
// Créer un élément Network
Network network = myFactory.createNetwork();
network.setName(process.getName());
// Conversion des WorkDefinition en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof WorkDefinition) {
WorkDefinition wd = (WorkDefinition) o;
String name = wd.getName();
Place idle = myFactory.createPlace();
idle.setName(name + "_idle");
idle.setTokens(1);
Place started = myFactory.createPlace();
started.setName(name + "_started");
started.setTokens(0);
Place running = myFactory.createPlace();
running.setName(name + "_running");
running.setTokens(0);
Place finished = myFactory.createPlace();
finished.setName(name + "_finished");
finished.setTokens(0);
Arc pause2start = myFactory.createArc();
pause2start.setTarget(idle);
pause2start.setOutgoing(false);
pause2start.setWeight(1);
Arc start2running = myFactory.createArc();
start2running.setTarget(running);
start2running.setOutgoing(true);
start2running.setWeight(1);
Arc start2started = myFactory.createArc();
start2started.setTarget(started);
start2started.setOutgoing(true);
start2started.setWeight(1);
Transition start = myFactory.createTransition();
start.setName(name + "_start");
start.getArcs().add(pause2start);
start.getArcs().add(start2running);
start.getArcs().add(start2started);
Arc running2finish = myFactory.createArc();
running2finish.setTarget(running);
running2finish.setOutgoing(false);
running2finish.setWeight(1);
Arc finish2finished = myFactory.createArc();
finish2finished.setTarget(finished);
finish2finished.setOutgoing(true);
finish2finished.setWeight(1);
Transition finish = myFactory.createTransition();
finish.setName(name + "_finish");
finish.getArcs().add(running2finish);
finish.getArcs().add(finish2finished);
network.getNodes().add(idle);
network.getNodes().add(start);
network.getNodes().add(started);
network.getNodes().add(running);
network.getNodes().add(finish);
network.getNodes().add(finished);
}
}
// Conversion des WorkSequence en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof WorkSequence) {
WorkSequence ws = (WorkSequence) o;
WorkSequenceType type = ws.getLinkType();
WorkDefinition predecessor = ws.getPredecessor();
WorkDefinition successor = ws.getSuccessor();
// creation des suffixs permettant la recherche des noeuds
String predecessor_suffix = new String();
String successor_suffix = new String();
switch (type) {
case START_TO_START:
predecessor_suffix = "_started";
successor_suffix = "_start";
break;
case START_TO_FINISH:
predecessor_suffix = "_started";
successor_suffix = "_finished";
break;
case FINISH_TO_START:
predecessor_suffix = "_finished";
successor_suffix = "_start";
break;
case FINISH_TO_FINISH:
predecessor_suffix = "_finished";
successor_suffix = "_finish";
break;
default:
System.out.print("the fuck ?");
break;
}
// creation du read-arc
Arc arc1 = myFactory.createArc();
arc1.setOutgoing(false);
arc1.setWeight(1);
Arc arc2 = myFactory.createArc();
arc2.setOutgoing(true);
arc2.setWeight(1);
for (Node node : network.getNodes()) {
if (node instanceof Place) {
Place place = (Place) node;
if (place.getName().equals(predecessor.getName() + predecessor_suffix)) {
arc1.setTarget(place);
arc2.setTarget(place);
}
}
if (node instanceof Transition) {
Transition transition = (Transition) node;
if (transition.getName().equals(successor.getName() + successor_suffix)) {
transition.getArcs().add(arc1);
transition.getArcs().add(arc2);
}
}
}
}
}
// Créer le nouveau xmi (modèle convertit)
URI convURI = URI.createURI("models/Developpement_petrinet.xmi");
Resource conv = resSet.createResource(convURI);
// Ajouter le Network dans le nouveau modèle
conv.getContents().add(network);
// Sauver la ressource
try {
conv.save(Collections.EMPTY_MAP);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,217 @@
package simplepdl.manip;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
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.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import petrinet.Arc;
import petrinet.Network;
import petrinet.Node;
import petrinet.PetrinetFactory;
import petrinet.PetrinetPackage;
import petrinet.Place;
import petrinet.Transition;
import simplepdl.Process;
import simplepdl.SimplepdlPackage;
import simplepdl.WorkDefinition;
import simplepdl.WorkSequence;
import simplepdl.WorkSequenceType;
import simplepdl.Request;
public class simplepdl2petrinet {
public static void main(String[] args) {
// Charger les package SimplePDL et Petrinet afin de les enregistrer dans le registre d'Eclipse.
SimplepdlPackage packageInstance = SimplepdlPackage.eINSTANCE;
PetrinetPackage packageInstance2 = PetrinetPackage.eINSTANCE;
// Enregistrer l'extension ".xmi" comme devant être ouverte à
// l'aide d'un objet "XMIResourceFactoryImpl"
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("xmi", new XMIResourceFactoryImpl());
// Créer un objet resourceSetImpl qui contiendra une ressource EMF (le modèle)
ResourceSet resSet = new ResourceSetImpl();
// Charger la ressource (notre modèle)
URI modelURI = URI.createURI("test.xmi");
Resource resource = resSet.getResource(modelURI, true);
// Récupérer le premier élément du modèle (élément racine)
Process process = (Process) resource.getContents().get(0);
// La fabrique pour fabriquer les éléments de PetriNET
PetrinetFactory myFactory = PetrinetFactory.eINSTANCE;
// Créer un élément Network
Network network = myFactory.createNetwork();
network.setName(process.getName());
// Conversion des WorkDefinition en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof WorkDefinition) {
WorkDefinition wd = (WorkDefinition) o;
String name = wd.getName();
Place idle = myFactory.createPlace();
idle.setName(name + "_idle");
idle.setTokens(1);
Place started = myFactory.createPlace();
started.setName(name + "_started");
started.setTokens(0);
Place running = myFactory.createPlace();
running.setName(name + "_running");
running.setTokens(0);
Place finished = myFactory.createPlace();
finished.setName(name + "_finished");
finished.setTokens(0);
Arc pause2start = myFactory.createArc();
pause2start.setTarget(idle);
pause2start.setOutgoing(false);
pause2start.setWeight(1);
Arc start2running = myFactory.createArc();
start2running.setTarget(running);
start2running.setOutgoing(true);
start2running.setWeight(1);
Arc start2started = myFactory.createArc();
start2started.setTarget(started);
start2started.setOutgoing(true);
start2started.setWeight(1);
Transition start = myFactory.createTransition();
start.setName(name + "_start");
start.getArcs().add(pause2start);
start.getArcs().add(start2running);
start.getArcs().add(start2started);
Arc running2finish = myFactory.createArc();
running2finish.setTarget(running);
running2finish.setOutgoing(false);
running2finish.setWeight(1);
Arc finish2finished = myFactory.createArc();
finish2finished.setTarget(finished);
finish2finished.setOutgoing(true);
finish2finished.setWeight(1);
Transition finish = myFactory.createTransition();
finish.setName(name + "_finish");
finish.getArcs().add(running2finish);
finish.getArcs().add(finish2finished);
network.getNodes().add(idle);
network.getNodes().add(start);
network.getNodes().add(started);
network.getNodes().add(running);
network.getNodes().add(finish);
network.getNodes().add(finished);
}
}
// Conversion des WorkSequence en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof WorkSequence) {
WorkSequence ws = (WorkSequence) o;
WorkSequenceType type = ws.getLinkType();
WorkDefinition predecessor = ws.getPredecessor();
WorkDefinition successor = ws.getSuccessor();
// creation des suffixs permettant la recherche des noeuds
String predecessor_suffix = new String();
String successor_suffix = new String();
switch (type) {
case START_TO_START:
predecessor_suffix = "_started";
successor_suffix = "_start";
break;
case START_TO_FINISH:
predecessor_suffix = "_started";
successor_suffix = "_finished";
break;
case FINISH_TO_START:
predecessor_suffix = "_finished";
successor_suffix = "_start";
break;
case FINISH_TO_FINISH:
predecessor_suffix = "_finished";
successor_suffix = "_finish";
break;
default:
System.out.print("the fuck ?");
break;
}
// creation du read-arc
Arc arc1 = myFactory.createArc();
arc1.setOutgoing(false);
arc1.setWeight(1);
Arc arc2 = myFactory.createArc();
arc2.setOutgoing(true);
arc2.setWeight(1);
for (Node node : network.getNodes()) {
if (node instanceof Place) {
Place place = (Place) node;
if (place.getName().equals(predecessor.getName() + predecessor_suffix)) {
arc1.setTarget(place);
arc2.setTarget(place);
}
}
if (node instanceof Transition) {
Transition transition = (Transition) node;
if (transition.getName().equals(successor.getName() + successor_suffix)) {
transition.getArcs().add(arc1);
transition.getArcs().add(arc2);
}
}
}
}
}
// Conversion des Resource et Request en Node et Arcs
for (Object o : process.getProcessElements()) {
if (o instanceof simplepdl.Resource) {
simplepdl.Resource r = (simplepdl.Resource) o;
String name = r.getName();
int qty = r.getQuantity();
Place res = myFactory.createPlace();
res.setName(name);
res.setTokens(qty);
}
if (o instanceof simplepdl.Request) {
Request r = (Request) o;
simplepdl.Resource target = r.getTarget();
int qty = r.getQuantity();
}
}
// Créer le nouveau xmi (modèle convertit)
URI convURI = URI.createURI("models/Developpement_petrinet.xmi");
Resource conv = resSet.createResource(convURI);
// Ajouter le Network dans le nouveau modèle
conv.getContents().add(network);
// Sauver la ressource
try {
conv.save(Collections.EMPTY_MAP);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,9 @@
grammar fr.n7.PDL2 with org.eclipse.xtext.common.Terminals
generate pDL2 "http://www.n7.fr/PDL2"
Model:
greetings+=Greeting*;
Greeting:
'Hello' name=ID '!';

View file

@ -0,0 +1,201 @@
package simplepdl.manip;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
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.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import petrinet.PetrinetPackage;
import petrinet.Place;
import petrinet.Transition;
import petrinet.Arc;
import petrinet.Network;
import petrinet.Node;
import petrinet.PetrinetFactory;
import simplepdl.Process;
import simplepdl.WorkDefinition;
import simplepdl.WorkSequence;
import simplepdl.WorkSequenceType;
import simplepdl.SimplepdlPackage;
public class simplepdl2petrinet {
public static void main(String[] args) {
// Charger les package SimplePDL et Petrinet afin de les enregistrer dans le registre d'Eclipse.
SimplepdlPackage packageInstance = SimplepdlPackage.eINSTANCE;
PetrinetPackage packageInstance2 = PetrinetPackage.eINSTANCE;
// Enregistrer l'extension ".xmi" comme devant être ouverte à
// l'aide d'un objet "XMIResourceFactoryImpl"
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("xmi", new XMIResourceFactoryImpl());
// Créer un objet resourceSetImpl qui contiendra une ressource EMF (le modèle)
ResourceSet resSet = new ResourceSetImpl();
// Charger la ressource (notre modèle)
URI modelURI = URI.createURI("test.xmi");
Resource resource = resSet.getResource(modelURI, true);
// Récupérer le premier élément du modèle (élément racine)
Process process = (Process) resource.getContents().get(0);
// La fabrique pour fabriquer les éléments de PetriNET
PetrinetFactory myFactory = PetrinetFactory.eINSTANCE;
// Créer un élément Network
Network network = myFactory.createNetwork();
network.setName(process.getName());
// Conversion des WorkDefinition en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof WorkDefinition) {
WorkDefinition wd = (WorkDefinition) o;
String name = wd.getName();
Place idle = myFactory.createPlace();
idle.setName(name + "_idle");
idle.setTokens(1);
Place started = myFactory.createPlace();
started.setName(name + "_started");
started.setTokens(0);
Place running = myFactory.createPlace();
running.setName(name + "_running");
running.setTokens(0);
Place finished = myFactory.createPlace();
finished.setName(name + "_finished");
finished.setTokens(0);
Arc pause2start = myFactory.createArc();
pause2start.setTarget(idle);
pause2start.setOutgoing(false);
pause2start.setWeight(1);
Arc start2running = myFactory.createArc();
start2running.setTarget(running);
start2running.setOutgoing(true);
start2running.setWeight(1);
Arc start2started = myFactory.createArc();
start2started.setTarget(started);
start2started.setOutgoing(true);
start2started.setWeight(1);
Transition start = myFactory.createTransition();
start.setName(name + "_start");
start.getArcs().add(pause2start);
start.getArcs().add(start2running);
start.getArcs().add(start2started);
Arc running2finish = myFactory.createArc();
running2finish.setTarget(running);
running2finish.setOutgoing(false);
running2finish.setWeight(1);
Arc finish2finished = myFactory.createArc();
finish2finished.setTarget(finished);
finish2finished.setOutgoing(true);
finish2finished.setWeight(1);
Transition finish = myFactory.createTransition();
finish.setName(name + "_finish");
finish.getArcs().add(running2finish);
finish.getArcs().add(finish2finished);
network.getNodes().add(idle);
network.getNodes().add(start);
network.getNodes().add(started);
network.getNodes().add(running);
network.getNodes().add(finish);
network.getNodes().add(finished);
}
}
// Conversion des WorkSequence en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof WorkSequence) {
WorkSequence ws = (WorkSequence) o;
WorkSequenceType type = ws.getLinkType();
WorkDefinition predecessor = ws.getPredecessor();
WorkDefinition successor = ws.getSuccessor();
// creation des suffixs permettant la recherche des noeuds
String predecessor_suffix = new String();
String successor_suffix = new String();
switch (type) {
case START_TO_START:
predecessor_suffix = "_started";
successor_suffix = "_start";
break;
case START_TO_FINISH:
predecessor_suffix = "_started";
successor_suffix = "_finished";
break;
case FINISH_TO_START:
predecessor_suffix = "_finished";
successor_suffix = "_start";
break;
case FINISH_TO_FINISH:
predecessor_suffix = "_finished";
successor_suffix = "_finish";
break;
default:
System.out.print("the fuck ?");
break;
}
// creation du read-arc
Arc arc1 = myFactory.createArc();
arc1.setOutgoing(false);
arc1.setWeight(1);
Arc arc2 = myFactory.createArc();
arc2.setOutgoing(true);
arc2.setWeight(1);
for (Node node : network.getNodes()) {
if (node instanceof Place) {
Place place = (Place) node;
if (place.getName().equals(predecessor.getName() + predecessor_suffix)) {
arc1.setTarget(place);
arc2.setTarget(place);
}
}
if (node instanceof Transition) {
Transition transition = (Transition) node;
if (transition.getName().equals(successor.getName() + successor_suffix)) {
transition.getArcs().add(arc1);
transition.getArcs().add(arc2);
}
}
}
}
}
// Conversion des WorkSequence en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof Resource) {
}
}
// Créer le nouveau xmi (modèle convertit)
URI convURI = URI.createURI("models/Developpement_petrinet.xmi");
Resource conv = resSet.createResource(convURI);
// Ajouter le Network dans le nouveau modèle
conv.getContents().add(network);
// Sauver la ressource
try {
conv.save(Collections.EMPTY_MAP);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,6 @@
source.. = src/,\
src-gen/,\
xtend-gen/
bin.includes = META-INF/,\
.,\
plugin.xml

View file

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<viewpoint:DAnalysis xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:viewpoint="http://www.eclipse.org/sirius/1.1.0" uid="_rlbscCtrEeyPENyXrdwYKQ" version="14.3.1.202003261200">
<semanticResources>PDL1.ecore</semanticResources>
<semanticResources>PDL1.genmodel</semanticResources>
</viewpoint:DAnalysis>

View file

@ -0,0 +1,203 @@
package simplepdl.manip;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
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.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import petrinet.Arc;
import petrinet.Network;
import petrinet.Node;
import petrinet.PetrinetFactory;
import petrinet.PetrinetPackage;
import petrinet.Place;
import petrinet.Transition;
import simplepdl.Process;
import simplepdl.SimplepdlPackage;
import simplepdl.WorkDefinition;
import simplepdl.WorkSequence;
import simplepdl.WorkSequenceType;
public class simplepdl2petrinet {
public static void main(String[] args) {
// Charger les package SimplePDL et Petrinet afin de les enregistrer dans le registre d'Eclipse.
SimplepdlPackage packageInstance = SimplepdlPackage.eINSTANCE;
PetrinetPackage packageInstance2 = PetrinetPackage.eINSTANCE;
// Enregistrer l'extension ".xmi" comme devant être ouverte à
// l'aide d'un objet "XMIResourceFactoryImpl"
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("xmi", new XMIResourceFactoryImpl());
// Créer un objet resourceSetImpl qui contiendra une ressource EMF (le modèle)
ResourceSet resSet = new ResourceSetImpl();
// Charger la ressource (notre modèle)
URI modelURI = URI.createURI("test.xmi");
Resource resource = resSet.getResource(modelURI, true);
// Récupérer le premier élément du modèle (élément racine)
Process process = (Process) resource.getContents().get(0);
// La fabrique pour fabriquer les éléments de PetriNET
PetrinetFactory myFactory = PetrinetFactory.eINSTANCE;
// Créer un élément Network
Network network = myFactory.createNetwork();
network.setName(process.getName());
// Conversion des WorkDefinition en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof WorkDefinition) {
WorkDefinition wd = (WorkDefinition) o;
String name = wd.getName();
Place idle = myFactory.createPlace();
idle.setName(name + "_idle");
idle.setTokens(1);
Place started = myFactory.createPlace();
started.setName(name + "_started");
started.setTokens(0);
Place running = myFactory.createPlace();
running.setName(name + "_running");
running.setTokens(0);
Place finished = myFactory.createPlace();
finished.setName(name + "_finished");
finished.setTokens(0);
Arc pause2start = myFactory.createArc();
pause2start.setTarget(idle);
pause2start.setOutgoing(false);
pause2start.setWeight(1);
Arc start2running = myFactory.createArc();
start2running.setTarget(running);
start2running.setOutgoing(true);
start2running.setWeight(1);
Arc start2started = myFactory.createArc();
start2started.setTarget(started);
start2started.setOutgoing(true);
start2started.setWeight(1);
Transition start = myFactory.createTransition();
start.setName(name + "_start");
start.getArcs().add(pause2start);
start.getArcs().add(start2running);
start.getArcs().add(start2started);
Arc running2finish = myFactory.createArc();
running2finish.setTarget(running);
running2finish.setOutgoing(false);
running2finish.setWeight(1);
Arc finish2finished = myFactory.createArc();
finish2finished.setTarget(finished);
finish2finished.setOutgoing(true);
finish2finished.setWeight(1);
Transition finish = myFactory.createTransition();
finish.setName(name + "_finish");
finish.getArcs().add(running2finish);
finish.getArcs().add(finish2finished);
network.getNodes().add(idle);
network.getNodes().add(start);
network.getNodes().add(started);
network.getNodes().add(running);
network.getNodes().add(finish);
network.getNodes().add(finished);
}
}
// Conversion des WorkSequence en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof WorkSequence) {
WorkSequence ws = (WorkSequence) o;
WorkSequenceType type = ws.getLinkType();
WorkDefinition predecessor = ws.getPredecessor();
WorkDefinition successor = ws.getSuccessor();
// creation des suffixs permettant la recherche des noeuds
String predecessor_suffix = new String();
String successor_suffix = new String();
switch (type) {
case START_TO_START:
predecessor_suffix = "_started";
successor_suffix = "_start";
break;
case START_TO_FINISH:
predecessor_suffix = "_started";
successor_suffix = "_finished";
break;
case FINISH_TO_START:
predecessor_suffix = "_finished";
successor_suffix = "_start";
break;
case FINISH_TO_FINISH:
predecessor_suffix = "_finished";
successor_suffix = "_finish";
break;
default:
System.out.print("the fuck ?");
break;
}
// creation du read-arc
Arc arc1 = myFactory.createArc();
arc1.setOutgoing(false);
arc1.setWeight(1);
Arc arc2 = myFactory.createArc();
arc2.setOutgoing(true);
arc2.setWeight(1);
for (Node node : network.getNodes()) {
if (node instanceof Place) {
Place place = (Place) node;
if (place.getName().equals(predecessor.getName() + predecessor_suffix)) {
arc1.setTarget(place);
arc2.setTarget(place);
}
}
if (node instanceof Transition) {
Transition transition = (Transition) node;
if (transition.getName().equals(successor.getName() + successor_suffix)) {
transition.getArcs().add(arc1);
transition.getArcs().add(arc2);
}
}
}
}
}
// Conversion des WorkSequence en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof Resource) {
simplepdl.Resource r = (simplepdl.Resource) o;
int qty = r.getQuantity();
System.out.println(qty);
}
}
// Créer le nouveau xmi (modèle convertit)
URI convURI = URI.createURI("models/Developpement_petrinet.xmi");
Resource conv = resSet.createResource(convURI);
// Ajouter le Network dans le nouveau modèle
conv.getContents().add(network);
// Sauver la ressource
try {
conv.save(Collections.EMPTY_MAP);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,6 @@
source.. = src/,\
src-gen/,\
xtend-gen/
bin.includes = META-INF/,\
.,\
plugin.xml

View file

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<simplepdl:Process xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:simplepdl="http://simplepdl" name="Developpement">
<processElements xsi:type="simplepdl:WorkDefinition" linksToSuccessors="//@processElements.4 //@processElements.6 //@processElements.7 //@processElements.8" name="Conception"/>
<processElements xsi:type="simplepdl:WorkDefinition" linksToPredecessors="//@processElements.4" linksToSuccessors="//@processElements.5" name="Programmation"/>
<processElements xsi:type="simplepdl:WorkDefinition" linksToPredecessors="//@processElements.5 //@processElements.6" name="RedactionTests"/>
<processElements xsi:type="simplepdl:WorkDefinition" linksToPredecessors="//@processElements.7 //@processElements.8" name="RedactionDocs"/>
<processElements xsi:type="simplepdl:WorkSequence" linkType="finishToStart" predecessor="//@processElements.0" successor="//@processElements.1"/>
<processElements xsi:type="simplepdl:WorkSequence" linkType="finishToFinish" predecessor="//@processElements.1" successor="//@processElements.2"/>
<processElements xsi:type="simplepdl:WorkSequence" predecessor="//@processElements.0" successor="//@processElements.2"/>
<processElements xsi:type="simplepdl:WorkSequence" predecessor="//@processElements.0" successor="//@processElements.3"/>
<processElements xsi:type="simplepdl:WorkSequence" linkType="finishToFinish" predecessor="//@processElements.0" successor="//@processElements.3"/>
</simplepdl:Process>

View file

@ -0,0 +1,29 @@
grammar fr.n7.PDL1 with org.eclipse.xtext.common.Terminals
generate pDL1 "http://www.n7.fr/PDL1"
Process :
'process' ':' name=ID
processElements+=ProcessElement* ;
ProcessElement :
WorkDefinitionList | WorkSequenceList ;
WorkDefinitionList :
'workdefinitions' ':' WorkDefinition+=WorkDefinition* ;
WorkDefinition :
name=ID ";" ;
WorkSequenceList :
'worksequences' ':' WorkSequence+=WorkSequence* ;
WorkSequence :
predecessor=[WorkDefinition] linkType=WorkSequenceType successor=[WorkDefinition] ;
enum WorkSequenceType :
start2start = 's2s'
| finish2start = 'f2s'
| start2finish = 's2f'
| finish2finish = 'f2f'
;

View file

@ -0,0 +1,30 @@
grammar fr.n7.PDL1 with org.eclipse.xtext.common.Terminals
generate pDL1 "http://www.n7.fr/PDL1"
Process :
'process' ':' name=ID
processElements+=ProcessElement* ;
ProcessElement :
WorkDefinitionList | WorkSequenceList ;
WorkDefinitionList :
'workdefinitions' ':' WorkDefinition+=WorkDefinition* ;
WorkDefinition :
name=ID ";" ;
WorkSequenceList :
'worksequences' ':' WorkSequence+=WorkSequence* ;
WorkSequence :
predecessor=[WorkDefinition] linkType=WorkSequenceType successor=[WorkDefinition];
enum WorkSequenceType :
start2start = 's2s'
| finish2start = 'f2s'
| start2finish = 's2f'
| finish2finish = 'f2f'
;

View file

@ -0,0 +1,31 @@
grammar fr.n7.PDL1 with org.eclipse.xtext.common.Terminals
generate pDL1 "http://www.n7.fr/PDL1"
Process :
'process' ':' name=ID
processElements+=ProcessElement* ;
ProcessElement :
WorkDefinitionList | WorkSequence | Guidance;
WorkDefinitionList :
'workdefinitions' ':' WorkDefinition+ ;
WorkDefinition :
name=ID ";" ;
WorkSequence :
'ws' linkType=WorkSequenceType
'from' predecessor=[WorkDefinition]
'to' successor=[WorkDefinition] ;
Guidance :
'note' texte=STRING ;
enum WorkSequenceType :
start2start = 's2s'
| finish2start = 'f2s'
| start2finish = 's2f'
| finish2finish = 'f2f'
;

View file

@ -0,0 +1,191 @@
package simplepdl.manip;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
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.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import petrinet.PetrinetPackage;
import petrinet.Place;
import petrinet.Transition;
import petrinet.Arc;
import petrinet.Network;
import petrinet.Node;
import petrinet.PetrinetFactory;
import simplepdl.Process;
import simplepdl.WorkDefinition;
import simplepdl.WorkSequence;
import simplepdl.WorkSequenceType;
import simplepdl.SimplepdlPackage;
public class simplepdl2petrinet {
public static void main(String[] args) {
// Charger les package SimplePDL et Petrinet afin de les enregistrer dans le registre d'Eclipse.
SimplepdlPackage packageInstance = SimplepdlPackage.eINSTANCE;
PetrinetPackage packageInstance2 = PetrinetPackage.eINSTANCE;
// Enregistrer l'extension ".xmi" comme devant être ouverte à
// l'aide d'un objet "XMIResourceFactoryImpl"
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("xmi", new XMIResourceFactoryImpl());
// Créer un objet resourceSetImpl qui contiendra une ressource EMF (le modèle)
ResourceSet resSet = new ResourceSetImpl();
// Charger la ressource (notre modèle)
URI modelURI = URI.createURI("test.xmi");
Resource resource = resSet.getResource(modelURI, true);
// Récupérer le premier élément du modèle (élément racine)
Process process = (Process) resource.getContents().get(0);
// La fabrique pour fabriquer les éléments de PetriNET
PetrinetFactory myFactory = PetrinetFactory.eINSTANCE;
// Créer un élément Network
Network network = myFactory.createNetwork();
network.setName(process.getName());
// Conversion des WorkDefinition en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof WorkDefinition) {
WorkDefinition wd = (WorkDefinition) o;
String name = wd.getName();
Place idle = myFactory.createPlace();
idle.setName(name + "_idle");
idle.setTokens(1);
Place started = myFactory.createPlace();
started.setName(name + "_started");
started.setTokens(0);
Place running = myFactory.createPlace();
running.setName(name + "_running");
running.setTokens(0);
Place finished = myFactory.createPlace();
finished.setName(name + "_finished");
finished.setTokens(0);
Arc pause2start = myFactory.createArc();
pause2start.setTarget(idle);
pause2start.setOutgoing(false);
pause2start.setWeight(1);
Arc start2running = myFactory.createArc();
start2running.setTarget(running);
start2running.setOutgoing(true);
start2running.setWeight(1);
Arc start2started = myFactory.createArc();
start2started.setTarget(started);
start2started.setOutgoing(true);
start2started.setWeight(1);
Transition start = myFactory.createTransition();
start.setName(name + "_start");
start.getArcs().add(pause2start);
start.getArcs().add(start2running);
start.getArcs().add(start2started);
Arc running2finish = myFactory.createArc();
running2finish.setTarget(running);
running2finish.setOutgoing(false);
running2finish.setWeight(1);
Arc finish2finished = myFactory.createArc();
finish2finished.setTarget(finished);
finish2finished.setOutgoing(true);
finish2finished.setWeight(1);
Transition finish = myFactory.createTransition();
finish.setName(name + "_finish");
finish.getArcs().add(running2finish);
finish.getArcs().add(finish2finished);
network.getNodes().add(idle);
network.getNodes().add(start);
network.getNodes().add(started);
network.getNodes().add(running);
network.getNodes().add(finish);
network.getNodes().add(finished);
}
}
// Conversion des WorkSequence en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof WorkSequence) {
WorkSequence ws = (WorkSequence) o;
WorkSequenceType type = ws.getLinkType();
WorkDefinition predecessor = ws.getPredecessor();
WorkDefinition successor = ws.getSuccessor();
// creation des suffixs permettant la recherche des noeuds
String predecessor_suffix = new String();
String successor_suffix = new String();
switch (type) {
case START_TO_START:
predecessor_suffix = "_started";
successor_suffix = "_start";
break;
case START_TO_FINISH:
predecessor_suffix = "_started";
successor_suffix = "_finished";
break;
case FINISH_TO_START:
predecessor_suffix = "_finished";
successor_suffix = "_start";
break;
case FINISH_TO_FINISH:
predecessor_suffix = "_finished";
successor_suffix = "_finish";
break;
default:
System.out.print("the fuck ?");
break;
}
// creation du read-arc
Arc arc1 = myFactory.createArc();
arc1.setOutgoing(false);
arc1.setWeight(1);
Arc arc2 = myFactory.createArc();
arc2.setOutgoing(true);
arc2.setWeight(1);
for (Node node : network.getNodes()) {
if (node instanceof Place) {
Place place = (Place) node;
if (place.getName().equals(predecessor.getName() + predecessor_suffix)) {
arc1.setTarget(place);
arc2.setTarget(place);
}
}
if (node instanceof Transition) {
Transition transition = (Transition) node;
if (transition.getName().equals(successor.getName() + successor_suffix)) {
transition.getArcs().add(arc1);
transition.getArcs().add(arc2);
}
}
}
}
}
// Créer le nouveau xmi (modèle convertit)
URI convURI = URI.createURI("models/Developpement_petrinet.xmi");
Resource conv = resSet.createResource(convURI);
// Ajouter le Network dans le nouveau modèle
conv.getContents().add(network);
// Sauver la ressource
try {
conv.save(Collections.EMPTY_MAP);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,6 @@
source.. = src/,\
src-gen/,\
xtend-gen/
bin.includes = META-INF/,\
.,\
plugin.xml

View file

@ -0,0 +1,203 @@
package simplepdl.manip;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
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.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import petrinet.Arc;
import petrinet.Network;
import petrinet.Node;
import petrinet.PetrinetFactory;
import petrinet.PetrinetPackage;
import petrinet.Place;
import petrinet.Transition;
import simplepdl.Process;
import simplepdl.SimplepdlPackage;
import simplepdl.WorkDefinition;
import simplepdl.WorkSequence;
import simplepdl.WorkSequenceType;
public class simplepdl2petrinet {
public static void main(String[] args) {
// Charger les package SimplePDL et Petrinet afin de les enregistrer dans le registre d'Eclipse.
SimplepdlPackage packageInstance = SimplepdlPackage.eINSTANCE;
PetrinetPackage packageInstance2 = PetrinetPackage.eINSTANCE;
// Enregistrer l'extension ".xmi" comme devant être ouverte à
// l'aide d'un objet "XMIResourceFactoryImpl"
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("xmi", new XMIResourceFactoryImpl());
// Créer un objet resourceSetImpl qui contiendra une ressource EMF (le modèle)
ResourceSet resSet = new ResourceSetImpl();
// Charger la ressource (notre modèle)
URI modelURI = URI.createURI("test.xmi");
Resource resource = resSet.getResource(modelURI, true);
// Récupérer le premier élément du modèle (élément racine)
Process process = (Process) resource.getContents().get(0);
// La fabrique pour fabriquer les éléments de PetriNET
PetrinetFactory myFactory = PetrinetFactory.eINSTANCE;
// Créer un élément Network
Network network = myFactory.createNetwork();
network.setName(process.getName());
// Conversion des WorkDefinition en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof WorkDefinition) {
WorkDefinition wd = (WorkDefinition) o;
String name = wd.getName();
Place idle = myFactory.createPlace();
idle.setName(name + "_idle");
idle.setTokens(1);
Place started = myFactory.createPlace();
started.setName(name + "_started");
started.setTokens(0);
Place running = myFactory.createPlace();
running.setName(name + "_running");
running.setTokens(0);
Place finished = myFactory.createPlace();
finished.setName(name + "_finished");
finished.setTokens(0);
Arc pause2start = myFactory.createArc();
pause2start.setTarget(idle);
pause2start.setOutgoing(false);
pause2start.setWeight(1);
Arc start2running = myFactory.createArc();
start2running.setTarget(running);
start2running.setOutgoing(true);
start2running.setWeight(1);
Arc start2started = myFactory.createArc();
start2started.setTarget(started);
start2started.setOutgoing(true);
start2started.setWeight(1);
Transition start = myFactory.createTransition();
start.setName(name + "_start");
start.getArcs().add(pause2start);
start.getArcs().add(start2running);
start.getArcs().add(start2started);
Arc running2finish = myFactory.createArc();
running2finish.setTarget(running);
running2finish.setOutgoing(false);
running2finish.setWeight(1);
Arc finish2finished = myFactory.createArc();
finish2finished.setTarget(finished);
finish2finished.setOutgoing(true);
finish2finished.setWeight(1);
Transition finish = myFactory.createTransition();
finish.setName(name + "_finish");
finish.getArcs().add(running2finish);
finish.getArcs().add(finish2finished);
network.getNodes().add(idle);
network.getNodes().add(start);
network.getNodes().add(started);
network.getNodes().add(running);
network.getNodes().add(finish);
network.getNodes().add(finished);
}
}
// Conversion des WorkSequence en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof WorkSequence) {
WorkSequence ws = (WorkSequence) o;
WorkSequenceType type = ws.getLinkType();
WorkDefinition predecessor = ws.getPredecessor();
WorkDefinition successor = ws.getSuccessor();
// creation des suffixs permettant la recherche des noeuds
String predecessor_suffix = new String();
String successor_suffix = new String();
switch (type) {
case START_TO_START:
predecessor_suffix = "_started";
successor_suffix = "_start";
break;
case START_TO_FINISH:
predecessor_suffix = "_started";
successor_suffix = "_finished";
break;
case FINISH_TO_START:
predecessor_suffix = "_finished";
successor_suffix = "_start";
break;
case FINISH_TO_FINISH:
predecessor_suffix = "_finished";
successor_suffix = "_finish";
break;
default:
System.out.print("the fuck ?");
break;
}
// creation du read-arc
Arc arc1 = myFactory.createArc();
arc1.setOutgoing(false);
arc1.setWeight(1);
Arc arc2 = myFactory.createArc();
arc2.setOutgoing(true);
arc2.setWeight(1);
for (Node node : network.getNodes()) {
if (node instanceof Place) {
Place place = (Place) node;
if (place.getName().equals(predecessor.getName() + predecessor_suffix)) {
arc1.setTarget(place);
arc2.setTarget(place);
}
}
if (node instanceof Transition) {
Transition transition = (Transition) node;
if (transition.getName().equals(successor.getName() + successor_suffix)) {
transition.getArcs().add(arc1);
transition.getArcs().add(arc2);
}
}
}
}
}
// Conversion des WorkSequence en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof simplepdl.Resource) {
simplepdl.Resource r = (simplepdl.Resource) o;
int qty = r.getQuantity();
System.out.println(qty);
}
}
// Créer le nouveau xmi (modèle convertit)
URI convURI = URI.createURI("models/Developpement_petrinet.xmi");
Resource conv = resSet.createResource(convURI);
// Ajouter le Network dans le nouveau modèle
conv.getContents().add(network);
// Sauver la ressource
try {
conv.save(Collections.EMPTY_MAP);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,205 @@
package simplepdl.manip;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
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.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import petrinet.Arc;
import petrinet.Network;
import petrinet.Node;
import petrinet.PetrinetFactory;
import petrinet.PetrinetPackage;
import petrinet.Place;
import petrinet.Transition;
import simplepdl.Process;
import simplepdl.SimplepdlPackage;
import simplepdl.WorkDefinition;
import simplepdl.WorkSequence;
import simplepdl.WorkSequenceType;
public class simplepdl2petrinet {
public static void main(String[] args) {
// Charger les package SimplePDL et Petrinet afin de les enregistrer dans le registre d'Eclipse.
SimplepdlPackage packageInstance = SimplepdlPackage.eINSTANCE;
PetrinetPackage packageInstance2 = PetrinetPackage.eINSTANCE;
// Enregistrer l'extension ".xmi" comme devant être ouverte à
// l'aide d'un objet "XMIResourceFactoryImpl"
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("xmi", new XMIResourceFactoryImpl());
// Créer un objet resourceSetImpl qui contiendra une ressource EMF (le modèle)
ResourceSet resSet = new ResourceSetImpl();
// Charger la ressource (notre modèle)
URI modelURI = URI.createURI("test.xmi");
Resource resource = resSet.getResource(modelURI, true);
// Récupérer le premier élément du modèle (élément racine)
Process process = (Process) resource.getContents().get(0);
// La fabrique pour fabriquer les éléments de PetriNET
PetrinetFactory myFactory = PetrinetFactory.eINSTANCE;
// Créer un élément Network
Network network = myFactory.createNetwork();
network.setName(process.getName());
// Conversion des WorkDefinition en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof WorkDefinition) {
WorkDefinition wd = (WorkDefinition) o;
String name = wd.getName();
Place idle = myFactory.createPlace();
idle.setName(name + "_idle");
idle.setTokens(1);
Place started = myFactory.createPlace();
started.setName(name + "_started");
started.setTokens(0);
Place running = myFactory.createPlace();
running.setName(name + "_running");
running.setTokens(0);
Place finished = myFactory.createPlace();
finished.setName(name + "_finished");
finished.setTokens(0);
Arc pause2start = myFactory.createArc();
pause2start.setTarget(idle);
pause2start.setOutgoing(false);
pause2start.setWeight(1);
Arc start2running = myFactory.createArc();
start2running.setTarget(running);
start2running.setOutgoing(true);
start2running.setWeight(1);
Arc start2started = myFactory.createArc();
start2started.setTarget(started);
start2started.setOutgoing(true);
start2started.setWeight(1);
Transition start = myFactory.createTransition();
start.setName(name + "_start");
start.getArcs().add(pause2start);
start.getArcs().add(start2running);
start.getArcs().add(start2started);
Arc running2finish = myFactory.createArc();
running2finish.setTarget(running);
running2finish.setOutgoing(false);
running2finish.setWeight(1);
Arc finish2finished = myFactory.createArc();
finish2finished.setTarget(finished);
finish2finished.setOutgoing(true);
finish2finished.setWeight(1);
Transition finish = myFactory.createTransition();
finish.setName(name + "_finish");
finish.getArcs().add(running2finish);
finish.getArcs().add(finish2finished);
network.getNodes().add(idle);
network.getNodes().add(start);
network.getNodes().add(started);
network.getNodes().add(running);
network.getNodes().add(finish);
network.getNodes().add(finished);
}
}
// Conversion des WorkSequence en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof WorkSequence) {
WorkSequence ws = (WorkSequence) o;
WorkSequenceType type = ws.getLinkType();
WorkDefinition predecessor = ws.getPredecessor();
WorkDefinition successor = ws.getSuccessor();
// creation des suffixs permettant la recherche des noeuds
String predecessor_suffix = new String();
String successor_suffix = new String();
switch (type) {
case START_TO_START:
predecessor_suffix = "_started";
successor_suffix = "_start";
break;
case START_TO_FINISH:
predecessor_suffix = "_started";
successor_suffix = "_finished";
break;
case FINISH_TO_START:
predecessor_suffix = "_finished";
successor_suffix = "_start";
break;
case FINISH_TO_FINISH:
predecessor_suffix = "_finished";
successor_suffix = "_finish";
break;
default:
System.out.print("the fuck ?");
break;
}
// creation du read-arc
Arc arc1 = myFactory.createArc();
arc1.setOutgoing(false);
arc1.setWeight(1);
Arc arc2 = myFactory.createArc();
arc2.setOutgoing(true);
arc2.setWeight(1);
for (Node node : network.getNodes()) {
if (node instanceof Place) {
Place place = (Place) node;
if (place.getName().equals(predecessor.getName() + predecessor_suffix)) {
arc1.setTarget(place);
arc2.setTarget(place);
}
}
if (node instanceof Transition) {
Transition transition = (Transition) node;
if (transition.getName().equals(successor.getName() + successor_suffix)) {
transition.getArcs().add(arc1);
transition.getArcs().add(arc2);
}
}
}
}
}
System.out.println("test");
// Conversion des WorkSequence en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof Resource) {
simplepdl.Resource r = (simplepdl.Resource) o;
int qty = r.getQuantity();
System.out.println(qty);
}
}
// Créer le nouveau xmi (modèle convertit)
URI convURI = URI.createURI("models/Developpement_petrinet.xmi");
Resource conv = resSet.createResource(convURI);
// Ajouter le Network dans le nouveau modèle
conv.getContents().add(network);
// Sauver la ressource
try {
conv.save(Collections.EMPTY_MAP);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,6 @@
source.. = src/,\
src-gen/,\
xtend-gen/
bin.includes = META-INF/,\
.,\
plugin.xml

View file

@ -1,86 +0,0 @@
package simplepdl.manip;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
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.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import simplepdl.Process;
import simplepdl.WorkDefinition;
import simplepdl.WorkSequence;
import simplepdl.WorkSequenceType;
import simplepdl.SimplepdlFactory;
import simplepdl.SimplepdlPackage;
public class simplepdl2petrinet {
public static void main(String[] args) {
// Charger le package SimplePDL afin de l'enregistrer dans le registre d'Eclipse.
SimplepdlPackage packageInstance = SimplepdlPackage.eINSTANCE;
PetrinetPackage packageInstance2 = PetrinetPackage.eINSTANCE;
// Enregistrer l'extension ".xmi" comme devant être ouverte à
// l'aide d'un objet "XMIResourceFactoryImpl"
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("xmi", new XMIResourceFactoryImpl());
// Créer un objet resourceSetImpl qui contiendra une ressource EMF (le modèle)
ResourceSet resSet = new ResourceSetImpl();
// Définir la ressource (le modèle)
URI modelURI = URI.createURI("models/SimplePDLCreator_Created_Process.xmi");
Resource resource = resSet.createResource(modelURI);
// La fabrique pour fabriquer les éléments de SimplePDL
SimplepdlFactory myFactory = SimplepdlFactory.eINSTANCE;
// Créer un élément Process
Process process = myFactory.createProcess();
process.setName("Mon premier processus");
// Ajouter le Process dans le modèle
resource.getContents().add(process);
// Ajouter deux WorkDefinitions
WorkDefinition wd1 = myFactory.createWorkDefinition();
wd1.setName("Ma première WorkDefinition, quelle émotion");
WorkDefinition wd2 = myFactory.createWorkDefinition();
wd2.setName("Ma deuxième WorkDefinition, toujours autant d'émotion");
process.getProcessElements().add(wd1);
process.getProcessElements().add(wd2);
// Ajouter une WorkSequence entre les deux WorkDefinitions
WorkSequence seq = myFactory.createWorkSequence();
seq.setPredecessor(wd1);
seq.setSuccessor(wd2);
seq.setLinkType(WorkSequenceType.FINISH_TO_FINISH);
process.getProcessElements().add(seq);
// Ajouter une deuxième WorkSequence entre les deux WorkDefinitions
WorkSequence seq2 = myFactory.createWorkSequence();
seq2.setPredecessor(wd1);
seq2.setSuccessor(wd2);
seq2.setLinkType(WorkSequenceType.START_TO_START);
process.getProcessElements().add(seq2);
// Sauver la ressource
try {
resource.save(Collections.EMPTY_MAP);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View file

@ -1,88 +0,0 @@
package simplepdl.manip;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
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.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import petrinet.PetrinetPackage;
import petrinet.PetrinetFactory;
import simplepdl.Process;
import simplepdl.WorkDefinition;
import simplepdl.WorkSequence;
import simplepdl.WorkSequenceType;
import simplepdl.SimplepdlFactory;
import simplepdl.SimplepdlPackage;
public class simplepdl2petrinet {
public static void main(String[] args) {
// Charger les package SimplePDL et Petrinet afin de les enregistrer dans le registre d'Eclipse.
SimplepdlPackage packageInstance = SimplepdlPackage.eINSTANCE;
PetrinetPackage packageInstance2 = PetrinetPackage.eINSTANCE;
// Enregistrer l'extension ".xmi" comme devant être ouverte à
// l'aide d'un objet "XMIResourceFactoryImpl"
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("xmi", new XMIResourceFactoryImpl());
// Créer un objet resourceSetImpl qui contiendra une ressource EMF (le modèle)
ResourceSet resSet = new ResourceSetImpl();
// Définir la ressource (le modèle)
URI modelURI = URI.createURI("models/SimplePDL2PetriNET.xmi");
Resource resource = resSet.createResource(modelURI);
// La fabrique pour fabriquer les éléments de SimplePDL
SimplepdlFactory myFactory = SimplepdlFactory.eINSTANCE;
// Créer un élément Process
Process process = myFactory.createProcess();
process.setName("Mon premier processus");
// Ajouter le Process dans le modèle
resource.getContents().add(process);
// Ajouter deux WorkDefinitions
WorkDefinition wd1 = myFactory.createWorkDefinition();
wd1.setName("Ma première WorkDefinition, quelle émotion");
WorkDefinition wd2 = myFactory.createWorkDefinition();
wd2.setName("Ma deuxième WorkDefinition, toujours autant d'émotion");
process.getProcessElements().add(wd1);
process.getProcessElements().add(wd2);
// Ajouter une WorkSequence entre les deux WorkDefinitions
WorkSequence seq = myFactory.createWorkSequence();
seq.setPredecessor(wd1);
seq.setSuccessor(wd2);
seq.setLinkType(WorkSequenceType.FINISH_TO_FINISH);
process.getProcessElements().add(seq);
// Ajouter une deuxième WorkSequence entre les deux WorkDefinitions
WorkSequence seq2 = myFactory.createWorkSequence();
seq2.setPredecessor(wd1);
seq2.setSuccessor(wd2);
seq2.setLinkType(WorkSequenceType.START_TO_START);
process.getProcessElements().add(seq2);
// Sauver la ressource
try {
resource.save(Collections.EMPTY_MAP);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,6 @@
source.. = src/,\
src-gen/,\
xtend-gen/
bin.includes = META-INF/,\
.,\
plugin.xml

View file

@ -0,0 +1,9 @@
grammar fr.n7.PDL3 with org.eclipse.xtext.common.Terminals
generate pDL3 "http://www.n7.fr/PDL3"
Model:
greetings+=Greeting*;
Greeting:
'Hello' name=ID '!';

View file

@ -0,0 +1,205 @@
package simplepdl.manip;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
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.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import petrinet.PetrinetPackage;
import petrinet.Place;
import petrinet.Transition;
import petrinet.Arc;
import petrinet.Network;
import petrinet.Node;
import petrinet.PetrinetFactory;
import simplepdl.Process;
import simplepdl.WorkDefinition;
import simplepdl.WorkSequence;
import simplepdl.WorkSequenceType;
import simplepdl.SimplepdlPackage;
public class simplepdl2petrinet {
public static void main(String[] args) {
// Charger les package SimplePDL et Petrinet afin de les enregistrer dans le registre d'Eclipse.
SimplepdlPackage packageInstance = SimplepdlPackage.eINSTANCE;
PetrinetPackage packageInstance2 = PetrinetPackage.eINSTANCE;
// Enregistrer l'extension ".xmi" comme devant être ouverte à
// l'aide d'un objet "XMIResourceFactoryImpl"
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("xmi", new XMIResourceFactoryImpl());
// Créer un objet resourceSetImpl qui contiendra une ressource EMF (le modèle)
ResourceSet resSet = new ResourceSetImpl();
// Charger la ressource (notre modèle)
URI modelURI = URI.createURI("test.xmi");
Resource resource = resSet.getResource(modelURI, true);
// Récupérer le premier élément du modèle (élément racine)
Process process = (Process) resource.getContents().get(0);
// La fabrique pour fabriquer les éléments de PetriNET
PetrinetFactory myFactory = PetrinetFactory.eINSTANCE;
// Créer un élément Network
Network network = myFactory.createNetwork();
network.setName(process.getName());
// Conversion des WorkDefinition en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof WorkDefinition) {
WorkDefinition wd = (WorkDefinition) o;
String name = wd.getName();
Place idle = myFactory.createPlace();
idle.setName(name + "_idle");
idle.setTokens(1);
Place started = myFactory.createPlace();
started.setName(name + "_started");
started.setTokens(0);
Place running = myFactory.createPlace();
running.setName(name + "_running");
running.setTokens(0);
Place finished = myFactory.createPlace();
finished.setName(name + "_finished");
finished.setTokens(0);
Arc pause2start = myFactory.createArc();
pause2start.setTarget(idle);
pause2start.setOutgoing(false);
pause2start.setWeight(1);
Arc start2running = myFactory.createArc();
start2running.setTarget(running);
start2running.setOutgoing(true);
start2running.setWeight(1);
Arc start2started = myFactory.createArc();
start2started.setTarget(started);
start2started.setOutgoing(true);
start2started.setWeight(1);
Transition start = myFactory.createTransition();
start.setName(name + "_start");
start.getArcs().add(pause2start);
start.getArcs().add(start2running);
start.getArcs().add(start2started);
Arc running2finish = myFactory.createArc();
running2finish.setTarget(running);
running2finish.setOutgoing(false);
running2finish.setWeight(1);
Arc finish2finished = myFactory.createArc();
finish2finished.setTarget(finished);
finish2finished.setOutgoing(true);
finish2finished.setWeight(1);
Transition finish = myFactory.createTransition();
finish.setName(name + "_finish");
finish.getArcs().add(running2finish);
finish.getArcs().add(finish2finished);
network.getNodes().add(idle);
network.getNodes().add(start);
network.getNodes().add(started);
network.getNodes().add(running);
network.getNodes().add(finish);
network.getNodes().add(finished);
}
}
// Conversion des WorkSequence en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof WorkSequence) {
WorkSequence ws = (WorkSequence) o;
WorkSequenceType type = ws.getLinkType();
WorkDefinition predecessor = ws.getPredecessor();
WorkDefinition successor = ws.getSuccessor();
// creation des suffixs permettant la recherche des noeuds
String predecessor_suffix = new String();
String successor_suffix = new String();
switch (type) {
case START_TO_START:
predecessor_suffix = "_started";
successor_suffix = "_start";
break;
case START_TO_FINISH:
predecessor_suffix = "_started";
successor_suffix = "_finished";
break;
case FINISH_TO_START:
predecessor_suffix = "_finished";
successor_suffix = "_start";
break;
case FINISH_TO_FINISH:
predecessor_suffix = "_finished";
successor_suffix = "_finish";
break;
default:
System.out.print("the fuck ?");
break;
}
// creation du read-arc
Arc arc1 = myFactory.createArc();
arc1.setOutgoing(false);
arc1.setWeight(1);
Arc arc2 = myFactory.createArc();
arc2.setOutgoing(true);
arc2.setWeight(1);
for (Node node : network.getNodes()) {
if (node instanceof Place) {
Place place = (Place) node;
if (place.getName().equals(predecessor.getName() + predecessor_suffix)) {
arc1.setTarget(place);
arc2.setTarget(place);
}
}
if (node instanceof Transition) {
Transition transition = (Transition) node;
if (transition.getName().equals(successor.getName() + successor_suffix)) {
transition.getArcs().add(arc1);
transition.getArcs().add(arc2);
}
}
}
}
}
// Conversion des WorkSequence en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof Resource) {
Resource r = (Resource) o;
EObject qty = r.getEObject("quantity");
System.out.println(qty);
System.out.println("mdr");
}
}
// Créer le nouveau xmi (modèle convertit)
URI convURI = URI.createURI("models/Developpement_petrinet.xmi");
Resource conv = resSet.createResource(convURI);
// Ajouter le Network dans le nouveau modèle
conv.getContents().add(network);
// Sauver la ressource
try {
conv.save(Collections.EMPTY_MAP);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,9 @@
grammar fr.n7.PDL1 with org.eclipse.xtext.common.Terminals
generate pDL1 "http://www.n7.fr/PDL1"
Model:
greetings+=Greeting*;
Greeting:
'Hello' name=ID '!';

View file

@ -0,0 +1,29 @@
grammar fr.n7.PDL2 with org.eclipse.xtext.common.Terminals
generate pDL2 "http://www.n7.fr/PDL2"
Process :
'process' ':' name=ID
processElements+=ProcessElement* ;
ProcessElement :
WorkDefinitionList | WorkSequenceList ;
WorkDefinitionList :
'workdefinitions' ':' WorkDefinition+=WorkDefinition* ;
WorkDefinition :
name=ID ";" ;
WorkSequenceList :
'worksequences' ':' WorkSequence+=WorkSequence* ;
WorkSequence :
predecessor=[WorkDefinition] linkType=WorkSequenceType successor=[WorkDefinition] ";" ;
enum WorkSequenceType :
start2start = 's2s'
| finish2start = 'f2s'
| start2finish = 's2f'
| finish2finish = 'f2f'
;

View file

@ -0,0 +1,43 @@
// automatically generated by Xtext
grammar fr.n7.simplepdl.txt.PDL with org.eclipse.xtext.common.Terminals
import "http://simplepdl"
import "http://www.eclipse.org/emf/2002/Ecore" as ecore
Process :
'process' name=ID '{'
processElements+=ProcessElement*
'}' ;
ProcessElement :
WorkDefinition | WorkSequence | Guidance | Resource ;
WorkDefinition :
'wd' name=ID
requests+=Request*
;
WorkSequence :
'ws' linkType=WorkSequenceType
'from' predecessor=[WorkDefinition]
'to' successor=[WorkDefinition] ;
Guidance :
'note' text=STRING ;
Resource :
'res' name=ID quantity=INT
;
Request :
'req' target=[Resource] quantity=INT
;
enum WorkSequenceType :
startToStart = 's2s'
| finishToStart = 'f2s'
| startToFinish = 's2f'
| finishToFinish = 'f2f'
;

View file

@ -0,0 +1,16 @@
source.. = src/,\
src-gen/,\
xtend-gen/
bin.includes = META-INF/,\
.,\
plugin.xml
additional.bundles = org.eclipse.xtext.xbase,\
org.eclipse.xtext.common.types,\
org.eclipse.xtext.xtext.generator,\
org.eclipse.emf.codegen.ecore,\
org.eclipse.emf.mwe.utils,\
org.eclipse.emf.mwe2.launch,\
org.eclipse.emf.mwe2.lib,\
org.objectweb.asm,\
org.apache.commons.logging,\
org.apache.log4j

View file

@ -0,0 +1,207 @@
package simplepdl.manip;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
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.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import petrinet.PetrinetPackage;
import petrinet.Place;
import petrinet.Transition;
import petrinet.Arc;
import petrinet.Network;
import petrinet.Node;
import petrinet.PetrinetFactory;
import simplepdl.Process;
import simplepdl.WorkDefinition;
import simplepdl.WorkSequence;
import simplepdl.WorkSequenceType;
import simplepdl.SimplepdlPackage;
import simplepdl.Resource;
public class simplepdl2petrinet {
public static void main(String[] args) {
// Charger les package SimplePDL et Petrinet afin de les enregistrer dans le registre d'Eclipse.
SimplepdlPackage packageInstance = SimplepdlPackage.eINSTANCE;
PetrinetPackage packageInstance2 = PetrinetPackage.eINSTANCE;
// Enregistrer l'extension ".xmi" comme devant être ouverte à
// l'aide d'un objet "XMIResourceFactoryImpl"
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("xmi", new XMIResourceFactoryImpl());
// Créer un objet resourceSetImpl qui contiendra une ressource EMF (le modèle)
ResourceSet resSet = new ResourceSetImpl();
// Charger la ressource (notre modèle)
URI modelURI = URI.createURI("test.xmi");
Resource resource = resSet.getResource(modelURI, true);
// Récupérer le premier élément du modèle (élément racine)
Process process = (Process) resource.getContents().get(0);
// La fabrique pour fabriquer les éléments de PetriNET
PetrinetFactory myFactory = PetrinetFactory.eINSTANCE;
// Créer un élément Network
Network network = myFactory.createNetwork();
network.setName(process.getName());
// Conversion des WorkDefinition en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof WorkDefinition) {
WorkDefinition wd = (WorkDefinition) o;
String name = wd.getName();
Place idle = myFactory.createPlace();
idle.setName(name + "_idle");
idle.setTokens(1);
Place started = myFactory.createPlace();
started.setName(name + "_started");
started.setTokens(0);
Place running = myFactory.createPlace();
running.setName(name + "_running");
running.setTokens(0);
Place finished = myFactory.createPlace();
finished.setName(name + "_finished");
finished.setTokens(0);
Arc pause2start = myFactory.createArc();
pause2start.setTarget(idle);
pause2start.setOutgoing(false);
pause2start.setWeight(1);
Arc start2running = myFactory.createArc();
start2running.setTarget(running);
start2running.setOutgoing(true);
start2running.setWeight(1);
Arc start2started = myFactory.createArc();
start2started.setTarget(started);
start2started.setOutgoing(true);
start2started.setWeight(1);
Transition start = myFactory.createTransition();
start.setName(name + "_start");
start.getArcs().add(pause2start);
start.getArcs().add(start2running);
start.getArcs().add(start2started);
Arc running2finish = myFactory.createArc();
running2finish.setTarget(running);
running2finish.setOutgoing(false);
running2finish.setWeight(1);
Arc finish2finished = myFactory.createArc();
finish2finished.setTarget(finished);
finish2finished.setOutgoing(true);
finish2finished.setWeight(1);
Transition finish = myFactory.createTransition();
finish.setName(name + "_finish");
finish.getArcs().add(running2finish);
finish.getArcs().add(finish2finished);
network.getNodes().add(idle);
network.getNodes().add(start);
network.getNodes().add(started);
network.getNodes().add(running);
network.getNodes().add(finish);
network.getNodes().add(finished);
}
}
// Conversion des WorkSequence en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof WorkSequence) {
WorkSequence ws = (WorkSequence) o;
WorkSequenceType type = ws.getLinkType();
WorkDefinition predecessor = ws.getPredecessor();
WorkDefinition successor = ws.getSuccessor();
// creation des suffixs permettant la recherche des noeuds
String predecessor_suffix = new String();
String successor_suffix = new String();
switch (type) {
case START_TO_START:
predecessor_suffix = "_started";
successor_suffix = "_start";
break;
case START_TO_FINISH:
predecessor_suffix = "_started";
successor_suffix = "_finished";
break;
case FINISH_TO_START:
predecessor_suffix = "_finished";
successor_suffix = "_start";
break;
case FINISH_TO_FINISH:
predecessor_suffix = "_finished";
successor_suffix = "_finish";
break;
default:
System.out.print("the fuck ?");
break;
}
// creation du read-arc
Arc arc1 = myFactory.createArc();
arc1.setOutgoing(false);
arc1.setWeight(1);
Arc arc2 = myFactory.createArc();
arc2.setOutgoing(true);
arc2.setWeight(1);
for (Node node : network.getNodes()) {
if (node instanceof Place) {
Place place = (Place) node;
if (place.getName().equals(predecessor.getName() + predecessor_suffix)) {
arc1.setTarget(place);
arc2.setTarget(place);
}
}
if (node instanceof Transition) {
Transition transition = (Transition) node;
if (transition.getName().equals(successor.getName() + successor_suffix)) {
transition.getArcs().add(arc1);
transition.getArcs().add(arc2);
}
}
}
}
}
System.out.println("mdr2");
// Conversion des WorkSequence en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof Resource) {
Resource r = (Resource) o;
EObject qty = r.getEObject("quantity");
System.out.println(qty);
System.out.println("mdr");
}
}
// Créer le nouveau xmi (modèle convertit)
URI convURI = URI.createURI("models/Developpement_petrinet.xmi");
Resource conv = resSet.createResource(convURI);
// Ajouter le Network dans le nouveau modèle
conv.getContents().add(network);
// Sauver la ressource
try {
conv.save(Collections.EMPTY_MAP);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,16 @@
source.. = src/,\
src-gen/,\
xtend-gen/
bin.includes = META-INF/,\
.,\
plugin.xml
additional.bundles = org.eclipse.xtext.xbase,\
org.eclipse.xtext.common.types,\
org.eclipse.xtext.xtext.generator,\
org.eclipse.emf.codegen.ecore,\
org.eclipse.emf.mwe.utils,\
org.eclipse.emf.mwe2.launch,\
org.eclipse.emf.mwe2.lib,\
org.objectweb.asm,\
org.apache.commons.logging,\
org.apache.log4j

View file

@ -0,0 +1,6 @@
source.. = src/,\
src-gen/,\
xtend-gen/
bin.includes = META-INF/,\
.,\
plugin.xml

View file

@ -1,88 +0,0 @@
package simplepdl.manip;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
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.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import petrinet.PetrinetPackage;
import petrinet.PetrinetFactory;
import simplepdl.Process;
import simplepdl.WorkDefinition;
import simplepdl.WorkSequence;
import simplepdl.WorkSequenceType;
import simplepdl.SimplepdlFactory;
import simplepdl.SimplepdlPackage;
public class simplepdl2petrinet {
public static void main(String[] args) {
// Charger les package SimplePDL et Petrinet afin de les enregistrer dans le registre d'Eclipse.
SimplepdlPackage packageInstance = SimplepdlPackage.eINSTANCE;
PetrinetPackage packageInstance2 = PetrinetPackage.eINSTANCE;
// Enregistrer l'extension ".xmi" comme devant être ouverte à
// l'aide d'un objet "XMIResourceFactoryImpl"
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("xmi", new XMIResourceFactoryImpl());
// Créer un objet resourceSetImpl qui contiendra une ressource EMF (le modèle)
ResourceSet resSet = new ResourceSetImpl();
// Définir la ressource (le modèle)
URI modelURI = URI.createURI("models/SimplePDLCreator_Created_Process.xmi");
Resource resource = resSet.createResource(modelURI);
// La fabrique pour fabriquer les éléments de SimplePDL
SimplepdlFactory myFactory = SimplepdlFactory.eINSTANCE;
// Créer un élément Process
Process process = myFactory.createProcess();
process.setName("Mon premier processus");
// Ajouter le Process dans le modèle
resource.getContents().add(process);
// Ajouter deux WorkDefinitions
WorkDefinition wd1 = myFactory.createWorkDefinition();
wd1.setName("Ma première WorkDefinition, quelle émotion");
WorkDefinition wd2 = myFactory.createWorkDefinition();
wd2.setName("Ma deuxième WorkDefinition, toujours autant d'émotion");
process.getProcessElements().add(wd1);
process.getProcessElements().add(wd2);
// Ajouter une WorkSequence entre les deux WorkDefinitions
WorkSequence seq = myFactory.createWorkSequence();
seq.setPredecessor(wd1);
seq.setSuccessor(wd2);
seq.setLinkType(WorkSequenceType.FINISH_TO_FINISH);
process.getProcessElements().add(seq);
// Ajouter une deuxième WorkSequence entre les deux WorkDefinitions
WorkSequence seq2 = myFactory.createWorkSequence();
seq2.setPredecessor(wd1);
seq2.setSuccessor(wd2);
seq2.setLinkType(WorkSequenceType.START_TO_START);
process.getProcessElements().add(seq2);
// Sauver la ressource
try {
resource.save(Collections.EMPTY_MAP);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,204 @@
package simplepdl.manip;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
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.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import petrinet.PetrinetPackage;
import petrinet.Place;
import petrinet.Transition;
import petrinet.Arc;
import petrinet.Network;
import petrinet.Node;
import petrinet.PetrinetFactory;
import simplepdl.Process;
import simplepdl.WorkDefinition;
import simplepdl.WorkSequence;
import simplepdl.WorkSequenceType;
import simplepdl.SimplepdlPackage;
import simplepdl.Resource;
public class simplepdl2petrinet {
public static void main(String[] args) {
// Charger les package SimplePDL et Petrinet afin de les enregistrer dans le registre d'Eclipse.
SimplepdlPackage packageInstance = SimplepdlPackage.eINSTANCE;
PetrinetPackage packageInstance2 = PetrinetPackage.eINSTANCE;
// Enregistrer l'extension ".xmi" comme devant être ouverte à
// l'aide d'un objet "XMIResourceFactoryImpl"
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("xmi", new XMIResourceFactoryImpl());
// Créer un objet resourceSetImpl qui contiendra une ressource EMF (le modèle)
ResourceSet resSet = new ResourceSetImpl();
// Charger la ressource (notre modèle)
URI modelURI = URI.createURI("test.xmi");
Resource resource = resSet.getResource(modelURI, true);
// Récupérer le premier élément du modèle (élément racine)
Process process = (Process) resource.getContents().get(0);
// La fabrique pour fabriquer les éléments de PetriNET
PetrinetFactory myFactory = PetrinetFactory.eINSTANCE;
// Créer un élément Network
Network network = myFactory.createNetwork();
network.setName(process.getName());
// Conversion des WorkDefinition en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof WorkDefinition) {
WorkDefinition wd = (WorkDefinition) o;
String name = wd.getName();
Place idle = myFactory.createPlace();
idle.setName(name + "_idle");
idle.setTokens(1);
Place started = myFactory.createPlace();
started.setName(name + "_started");
started.setTokens(0);
Place running = myFactory.createPlace();
running.setName(name + "_running");
running.setTokens(0);
Place finished = myFactory.createPlace();
finished.setName(name + "_finished");
finished.setTokens(0);
Arc pause2start = myFactory.createArc();
pause2start.setTarget(idle);
pause2start.setOutgoing(false);
pause2start.setWeight(1);
Arc start2running = myFactory.createArc();
start2running.setTarget(running);
start2running.setOutgoing(true);
start2running.setWeight(1);
Arc start2started = myFactory.createArc();
start2started.setTarget(started);
start2started.setOutgoing(true);
start2started.setWeight(1);
Transition start = myFactory.createTransition();
start.setName(name + "_start");
start.getArcs().add(pause2start);
start.getArcs().add(start2running);
start.getArcs().add(start2started);
Arc running2finish = myFactory.createArc();
running2finish.setTarget(running);
running2finish.setOutgoing(false);
running2finish.setWeight(1);
Arc finish2finished = myFactory.createArc();
finish2finished.setTarget(finished);
finish2finished.setOutgoing(true);
finish2finished.setWeight(1);
Transition finish = myFactory.createTransition();
finish.setName(name + "_finish");
finish.getArcs().add(running2finish);
finish.getArcs().add(finish2finished);
network.getNodes().add(idle);
network.getNodes().add(start);
network.getNodes().add(started);
network.getNodes().add(running);
network.getNodes().add(finish);
network.getNodes().add(finished);
}
}
// Conversion des WorkSequence en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof WorkSequence) {
WorkSequence ws = (WorkSequence) o;
WorkSequenceType type = ws.getLinkType();
WorkDefinition predecessor = ws.getPredecessor();
WorkDefinition successor = ws.getSuccessor();
// creation des suffixs permettant la recherche des noeuds
String predecessor_suffix = new String();
String successor_suffix = new String();
switch (type) {
case START_TO_START:
predecessor_suffix = "_started";
successor_suffix = "_start";
break;
case START_TO_FINISH:
predecessor_suffix = "_started";
successor_suffix = "_finished";
break;
case FINISH_TO_START:
predecessor_suffix = "_finished";
successor_suffix = "_start";
break;
case FINISH_TO_FINISH:
predecessor_suffix = "_finished";
successor_suffix = "_finish";
break;
default:
System.out.print("the fuck ?");
break;
}
// creation du read-arc
Arc arc1 = myFactory.createArc();
arc1.setOutgoing(false);
arc1.setWeight(1);
Arc arc2 = myFactory.createArc();
arc2.setOutgoing(true);
arc2.setWeight(1);
for (Node node : network.getNodes()) {
if (node instanceof Place) {
Place place = (Place) node;
if (place.getName().equals(predecessor.getName() + predecessor_suffix)) {
arc1.setTarget(place);
arc2.setTarget(place);
}
}
if (node instanceof Transition) {
Transition transition = (Transition) node;
if (transition.getName().equals(successor.getName() + successor_suffix)) {
transition.getArcs().add(arc1);
transition.getArcs().add(arc2);
}
}
}
}
}
// Conversion des WorkSequence en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof Resource) {
simplepdl.Resource r = (simplepdl.Resource) o;
int qty = r.getQuantity();
System.out.println(qty);
}
}
// Créer le nouveau xmi (modèle convertit)
URI convURI = URI.createURI("models/Developpement_petrinet.xmi");
Resource conv = resSet.createResource(convURI);
// Ajouter le Network dans le nouveau modèle
conv.getContents().add(network);
// Sauver la ressource
try {
conv.save(Collections.EMPTY_MAP);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,6 @@
source.. = src/,\
src-gen/,\
xtend-gen/
bin.includes = META-INF/,\
.,\
plugin.xml

View file

@ -0,0 +1,6 @@
source.. = src/,\
src-gen/,\
xtend-gen/
bin.includes = META-INF/,\
.,\
plugin.xml

View file

@ -0,0 +1,180 @@
/**
*/
package simplepdl.provider;
import java.util.Collection;
import java.util.List;
import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.util.ResourceLocator;
import org.eclipse.emf.edit.provider.ComposeableAdapterFactory;
import org.eclipse.emf.edit.provider.IEditingDomainItemProvider;
import org.eclipse.emf.edit.provider.IItemLabelProvider;
import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
import org.eclipse.emf.edit.provider.IItemPropertySource;
import org.eclipse.emf.edit.provider.IStructuredItemContentProvider;
import org.eclipse.emf.edit.provider.ITreeItemContentProvider;
import org.eclipse.emf.edit.provider.ItemPropertyDescriptor;
import org.eclipse.emf.edit.provider.ItemProviderAdapter;
import org.eclipse.emf.edit.provider.ViewerNotification;
import simplepdl.Request;
import simplepdl.SimplepdlPackage;
/**
* This is the item provider adapter for a {@link simplepdl.Request} object.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public class RequestItemProvider
extends ItemProviderAdapter
implements
IEditingDomainItemProvider,
IStructuredItemContentProvider,
ITreeItemContentProvider,
IItemLabelProvider,
IItemPropertySource {
/**
* This constructs an instance from a factory and a notifier.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public RequestItemProvider(AdapterFactory adapterFactory) {
super(adapterFactory);
}
/**
* This returns the property descriptors for the adapted class.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public List<IItemPropertyDescriptor> getPropertyDescriptors(Object object) {
if (itemPropertyDescriptors == null) {
super.getPropertyDescriptors(object);
addQuantityPropertyDescriptor(object);
addTargetPropertyDescriptor(object);
}
return itemPropertyDescriptors;
}
/**
* This adds a property descriptor for the Quantity feature.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
protected void addQuantityPropertyDescriptor(Object object) {
itemPropertyDescriptors.add
(createItemPropertyDescriptor
(((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(),
getResourceLocator(),
getString("_UI_Request_quantity_feature"),
getString("_UI_PropertyDescriptor_description", "_UI_Request_quantity_feature", "_UI_Request_type"),
SimplepdlPackage.Literals.REQUEST__QUANTITY,
true,
false,
false,
ItemPropertyDescriptor.INTEGRAL_VALUE_IMAGE,
null,
null));
}
/**
* This adds a property descriptor for the Target feature.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
protected void addTargetPropertyDescriptor(Object object) {
itemPropertyDescriptors.add
(createItemPropertyDescriptor
(((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(),
getResourceLocator(),
getString("_UI_Request_target_feature"),
getString("_UI_PropertyDescriptor_description", "_UI_Request_target_feature", "_UI_Request_type"),
SimplepdlPackage.Literals.REQUEST__TARGET,
true,
false,
true,
null,
null,
null));
}
/**
* This returns Request.gif.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public Object getImage(Object object) {
return overlayImage(object, getResourceLocator().getImage("full/obj16/Request"));
}
/**
* This returns the label text for the adapted class.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public String getText(Object object) {
Request request = (Request)object;
String targetname = request.getTarget() != null ? "" : request.getTarget().getName();
return getString("_UI_Request_type") + " --" + request.getQuantity() + "--> " + targetname;
}
/**
* This handles model notifications by calling {@link #updateChildren} to update any cached
* children and by creating a viewer notification, which it passes to {@link #fireNotifyChanged}.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public void notifyChanged(Notification notification) {
updateChildren(notification);
switch (notification.getFeatureID(Request.class)) {
case SimplepdlPackage.REQUEST__QUANTITY:
fireNotifyChanged(new ViewerNotification(notification, notification.getNotifier(), false, true));
return;
}
super.notifyChanged(notification);
}
/**
* This adds {@link org.eclipse.emf.edit.command.CommandParameter}s describing the children
* that can be created under this object.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
protected void collectNewChildDescriptors(Collection<Object> newChildDescriptors, Object object) {
super.collectNewChildDescriptors(newChildDescriptors, object);
}
/**
* Return the resource locator for this item provider's resources.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public ResourceLocator getResourceLocator() {
return SimplepdlEditPlugin.INSTANCE;
}
}

View file

@ -1,92 +0,0 @@
package simplepdl.manip;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
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.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import petrinet.PetrinetPackage;
import petrinet.PetrinetFactory;
import simplepdl.Process;
import simplepdl.WorkDefinition;
import simplepdl.WorkSequence;
import simplepdl.WorkSequenceType;
import simplepdl.SimplepdlFactory;
import simplepdl.SimplepdlPackage;
public class simplepdl2petrinet {
public static void main(String[] args) {
// Charger les package SimplePDL et Petrinet afin de les enregistrer dans le registre d'Eclipse.
SimplepdlPackage packageInstance = SimplepdlPackage.eINSTANCE;
PetrinetPackage packageInstance2 = PetrinetPackage.eINSTANCE;
// Enregistrer l'extension ".xmi" comme devant être ouverte à
// l'aide d'un objet "XMIResourceFactoryImpl"
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("xmi", new XMIResourceFactoryImpl());
// Créer un objet resourceSetImpl qui contiendra une ressource EMF (le modèle)
ResourceSet resSet = new ResourceSetImpl();
// Charger la ressource (notre modèle)
URI modelURI = URI.createURI("pdl-sujet.xmi");
Resource resource = resSet.getResource(modelURI, true);
// La fabrique pour fabriquer les éléments de SimplePDL
SimplepdlFactory myFactory = SimplepdlFactory.eINSTANCE;
// Créer un élément Process
Process process = myFactory.createProcess();
process.setName("Mon premier processus");
// Ajouter le Process dans le modèle
resource.getContents().add(process);
// Ajouter deux WorkDefinitions
WorkDefinition wd1 = myFactory.createWorkDefinition();
wd1.setName("Ma première WorkDefinition, quelle émotion");
WorkDefinition wd2 = myFactory.createWorkDefinition();
wd2.setName("Ma deuxième WorkDefinition, toujours autant d'émotion");
process.getProcessElements().add(wd1);
process.getProcessElements().add(wd2);
// Ajouter une WorkSequence entre les deux WorkDefinitions
WorkSequence seq = myFactory.createWorkSequence();
seq.setPredecessor(wd1);
seq.setSuccessor(wd2);
seq.setLinkType(WorkSequenceType.FINISH_TO_FINISH);
process.getProcessElements().add(seq);
// Ajouter une deuxième WorkSequence entre les deux WorkDefinitions
WorkSequence seq2 = myFactory.createWorkSequence();
seq2.setPredecessor(wd1);
seq2.setSuccessor(wd2);
seq2.setLinkType(WorkSequenceType.START_TO_START);
process.getProcessElements().add(seq2);
// Sauver la ressource
try {
resource.save(Collections.EMPTY_MAP);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,225 @@
package simplepdl.manip;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
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.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import petrinet.Arc;
import petrinet.Network;
import petrinet.Node;
import petrinet.PetrinetFactory;
import petrinet.PetrinetPackage;
import petrinet.Place;
import petrinet.Transition;
import simplepdl.Process;
import simplepdl.SimplepdlPackage;
import simplepdl.WorkDefinition;
import simplepdl.WorkSequence;
import simplepdl.WorkSequenceType;
import simplepdl.Request;
public class simplepdl2petrinet {
public static void main(String[] args) {
// Charger les package SimplePDL et Petrinet afin de les enregistrer dans le registre d'Eclipse.
SimplepdlPackage packageInstance = SimplepdlPackage.eINSTANCE;
PetrinetPackage packageInstance2 = PetrinetPackage.eINSTANCE;
// Enregistrer l'extension ".xmi" comme devant être ouverte à
// l'aide d'un objet "XMIResourceFactoryImpl"
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("xmi", new XMIResourceFactoryImpl());
// Créer un objet resourceSetImpl qui contiendra une ressource EMF (le modèle)
ResourceSet resSet = new ResourceSetImpl();
// Charger la ressource (notre modèle)
URI modelURI = URI.createURI("test.xmi");
Resource resource = resSet.getResource(modelURI, true);
// Récupérer le premier élément du modèle (élément racine)
Process process = (Process) resource.getContents().get(0);
// La fabrique pour fabriquer les éléments de PetriNET
PetrinetFactory myFactory = PetrinetFactory.eINSTANCE;
// Créer un élément Network
Network network = myFactory.createNetwork();
network.setName(process.getName());
// Conversion des WorkDefinition en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof WorkDefinition) {
WorkDefinition wd = (WorkDefinition) o;
String name = wd.getName();
Place idle = myFactory.createPlace();
idle.setName(name + "_idle");
idle.setTokens(1);
Place started = myFactory.createPlace();
started.setName(name + "_started");
started.setTokens(0);
Place running = myFactory.createPlace();
running.setName(name + "_running");
running.setTokens(0);
Place finished = myFactory.createPlace();
finished.setName(name + "_finished");
finished.setTokens(0);
Arc pause2start = myFactory.createArc();
pause2start.setTarget(idle);
pause2start.setOutgoing(false);
pause2start.setWeight(1);
Arc start2running = myFactory.createArc();
start2running.setTarget(running);
start2running.setOutgoing(true);
start2running.setWeight(1);
Arc start2started = myFactory.createArc();
start2started.setTarget(started);
start2started.setOutgoing(true);
start2started.setWeight(1);
Transition start = myFactory.createTransition();
start.setName(name + "_start");
start.getArcs().add(pause2start);
start.getArcs().add(start2running);
start.getArcs().add(start2started);
Arc running2finish = myFactory.createArc();
running2finish.setTarget(running);
running2finish.setOutgoing(false);
running2finish.setWeight(1);
Arc finish2finished = myFactory.createArc();
finish2finished.setTarget(finished);
finish2finished.setOutgoing(true);
finish2finished.setWeight(1);
Transition finish = myFactory.createTransition();
finish.setName(name + "_finish");
finish.getArcs().add(running2finish);
finish.getArcs().add(finish2finished);
network.getNodes().add(idle);
network.getNodes().add(start);
network.getNodes().add(started);
network.getNodes().add(running);
network.getNodes().add(finish);
network.getNodes().add(finished);
}
}
// Conversion des WorkSequence en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof WorkSequence) {
WorkSequence ws = (WorkSequence) o;
WorkSequenceType type = ws.getLinkType();
WorkDefinition predecessor = ws.getPredecessor();
WorkDefinition successor = ws.getSuccessor();
// creation des suffixs permettant la recherche des noeuds
String predecessor_suffix = new String();
String successor_suffix = new String();
switch (type) {
case START_TO_START:
predecessor_suffix = "_started";
successor_suffix = "_start";
break;
case START_TO_FINISH:
predecessor_suffix = "_started";
successor_suffix = "_finished";
break;
case FINISH_TO_START:
predecessor_suffix = "_finished";
successor_suffix = "_start";
break;
case FINISH_TO_FINISH:
predecessor_suffix = "_finished";
successor_suffix = "_finish";
break;
default:
System.out.print("the fuck ?");
break;
}
// creation du read-arc
Arc arc1 = myFactory.createArc();
arc1.setOutgoing(false);
arc1.setWeight(1);
Arc arc2 = myFactory.createArc();
arc2.setOutgoing(true);
arc2.setWeight(1);
for (Node node : network.getNodes()) {
if (node instanceof Place) {
Place place = (Place) node;
if (place.getName().equals(predecessor.getName() + predecessor_suffix)) {
arc1.setTarget(place);
arc2.setTarget(place);
}
}
if (node instanceof Transition) {
Transition transition = (Transition) node;
if (transition.getName().equals(successor.getName() + successor_suffix)) {
transition.getArcs().add(arc1);
transition.getArcs().add(arc2);
}
}
}
}
}
// Conversion des Resource et Request en Node et Arcs
for (Object o : process.getProcessElements()) {
if (o instanceof simplepdl.Resource) {
simplepdl.Resource r = (simplepdl.Resource) o;
String name = r.getName();
int qty = r.getQuantity();
Place res = myFactory.createPlace();
res.setName(name);
res.setTokens(qty);
}
if (o instanceof simplepdl.Request) {
Request r = (Request) o;
simplepdl.Resource target = r.getTarget();
int qty = r.getQuantity();
Arc arc1 = myFactory.createArc();
arc1.setOutgoing(true);
arc1.setWeight(qty);
arc1.setTarget(target);
Arc arc2 = myFactory.createArc();
arc2.setOutgoing(false);
arc2.setWeight(qty);
}
}
// Créer le nouveau xmi (modèle convertit)
URI convURI = URI.createURI("models/Developpement_petrinet.xmi");
Resource conv = resSet.createResource(convURI);
// Ajouter le Network dans le nouveau modèle
conv.getContents().add(network);
// Sauver la ressource
try {
conv.save(Collections.EMPTY_MAP);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,16 @@
source.. = src/,\
src-gen/,\
xtend-gen/
bin.includes = META-INF/,\
.,\
plugin.xml
additional.bundles = org.eclipse.xtext.xbase,\
org.eclipse.xtext.common.types,\
org.eclipse.xtext.xtext.generator,\
org.eclipse.emf.codegen.ecore,\
org.eclipse.emf.mwe.utils,\
org.eclipse.emf.mwe2.launch,\
org.eclipse.emf.mwe2.lib,\
org.objectweb.asm,\
org.apache.commons.logging,\
org.apache.log4j

View file

@ -1,85 +0,0 @@
package simplepdl.manip;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
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.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import simplepdl.Process;
import simplepdl.WorkDefinition;
import simplepdl.WorkSequence;
import simplepdl.WorkSequenceType;
import simplepdl.SimplepdlFactory;
import simplepdl.SimplepdlPackage;
public class simplepdl2petrinet {
public static void main(String[] args) {
// Charger le package SimplePDL afin de l'enregistrer dans le registre d'Eclipse.
SimplepdlPackage packageInstance = SimplepdlPackage.eINSTANCE;
// Enregistrer l'extension ".xmi" comme devant être ouverte à
// l'aide d'un objet "XMIResourceFactoryImpl"
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("xmi", new XMIResourceFactoryImpl());
// Créer un objet resourceSetImpl qui contiendra une ressource EMF (le modèle)
ResourceSet resSet = new ResourceSetImpl();
// Définir la ressource (le modèle)
URI modelURI = URI.createURI("models/SimplePDLCreator_Created_Process.xmi");
Resource resource = resSet.createResource(modelURI);
// La fabrique pour fabriquer les éléments de SimplePDL
SimplepdlFactory myFactory = SimplepdlFactory.eINSTANCE;
// Créer un élément Process
Process process = myFactory.createProcess();
process.setName("Mon premier processus");
// Ajouter le Process dans le modèle
resource.getContents().add(process);
// Ajouter deux WorkDefinitions
WorkDefinition wd1 = myFactory.createWorkDefinition();
wd1.setName("Ma première WorkDefinition, quelle émotion");
WorkDefinition wd2 = myFactory.createWorkDefinition();
wd2.setName("Ma deuxième WorkDefinition, toujours autant d'émotion");
process.getProcessElements().add(wd1);
process.getProcessElements().add(wd2);
// Ajouter une WorkSequence entre les deux WorkDefinitions
WorkSequence seq = myFactory.createWorkSequence();
seq.setPredecessor(wd1);
seq.setSuccessor(wd2);
seq.setLinkType(WorkSequenceType.FINISH_TO_FINISH);
process.getProcessElements().add(seq);
// Ajouter une deuxième WorkSequence entre les deux WorkDefinitions
WorkSequence seq2 = myFactory.createWorkSequence();
seq2.setPredecessor(wd1);
seq2.setSuccessor(wd2);
seq2.setLinkType(WorkSequenceType.START_TO_START);
process.getProcessElements().add(seq2);
// Sauver la ressource
try {
resource.save(Collections.EMPTY_MAP);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,207 @@
package simplepdl.manip;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
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.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import petrinet.PetrinetPackage;
import petrinet.Place;
import petrinet.Transition;
import petrinet.Arc;
import petrinet.Network;
import petrinet.Node;
import petrinet.PetrinetFactory;
import simplepdl.Process;
import simplepdl.WorkDefinition;
import simplepdl.WorkSequence;
import simplepdl.WorkSequenceType;
import simplepdl.SimplepdlPackage;
public class simplepdl2petrinet {
public static void main(String[] args) {
// Charger les package SimplePDL et Petrinet afin de les enregistrer dans le registre d'Eclipse.
SimplepdlPackage packageInstance = SimplepdlPackage.eINSTANCE;
PetrinetPackage packageInstance2 = PetrinetPackage.eINSTANCE;
// Enregistrer l'extension ".xmi" comme devant être ouverte à
// l'aide d'un objet "XMIResourceFactoryImpl"
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("xmi", new XMIResourceFactoryImpl());
// Créer un objet resourceSetImpl qui contiendra une ressource EMF (le modèle)
ResourceSet resSet = new ResourceSetImpl();
// Charger la ressource (notre modèle)
URI modelURI = URI.createURI("test.xmi");
Resource resource = resSet.getResource(modelURI, true);
// Récupérer le premier élément du modèle (élément racine)
Process process = (Process) resource.getContents().get(0);
// La fabrique pour fabriquer les éléments de PetriNET
PetrinetFactory myFactory = PetrinetFactory.eINSTANCE;
// Créer un élément Network
Network network = myFactory.createNetwork();
network.setName(process.getName());
// Conversion des WorkDefinition en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof WorkDefinition) {
WorkDefinition wd = (WorkDefinition) o;
String name = wd.getName();
Place idle = myFactory.createPlace();
idle.setName(name + "_idle");
idle.setTokens(1);
Place started = myFactory.createPlace();
started.setName(name + "_started");
started.setTokens(0);
Place running = myFactory.createPlace();
running.setName(name + "_running");
running.setTokens(0);
Place finished = myFactory.createPlace();
finished.setName(name + "_finished");
finished.setTokens(0);
Arc pause2start = myFactory.createArc();
pause2start.setTarget(idle);
pause2start.setOutgoing(false);
pause2start.setWeight(1);
Arc start2running = myFactory.createArc();
start2running.setTarget(running);
start2running.setOutgoing(true);
start2running.setWeight(1);
Arc start2started = myFactory.createArc();
start2started.setTarget(started);
start2started.setOutgoing(true);
start2started.setWeight(1);
Transition start = myFactory.createTransition();
start.setName(name + "_start");
start.getArcs().add(pause2start);
start.getArcs().add(start2running);
start.getArcs().add(start2started);
Arc running2finish = myFactory.createArc();
running2finish.setTarget(running);
running2finish.setOutgoing(false);
running2finish.setWeight(1);
Arc finish2finished = myFactory.createArc();
finish2finished.setTarget(finished);
finish2finished.setOutgoing(true);
finish2finished.setWeight(1);
Transition finish = myFactory.createTransition();
finish.setName(name + "_finish");
finish.getArcs().add(running2finish);
finish.getArcs().add(finish2finished);
network.getNodes().add(idle);
network.getNodes().add(start);
network.getNodes().add(started);
network.getNodes().add(running);
network.getNodes().add(finish);
network.getNodes().add(finished);
}
}
// Conversion des WorkSequence en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof WorkSequence) {
WorkSequence ws = (WorkSequence) o;
WorkSequenceType type = ws.getLinkType();
WorkDefinition predecessor = ws.getPredecessor();
WorkDefinition successor = ws.getSuccessor();
// creation des suffixs permettant la recherche des noeuds
String predecessor_suffix = new String();
String successor_suffix = new String();
switch (type) {
case START_TO_START:
predecessor_suffix = "_started";
successor_suffix = "_start";
break;
case START_TO_FINISH:
predecessor_suffix = "_started";
successor_suffix = "_finished";
break;
case FINISH_TO_START:
predecessor_suffix = "_finished";
successor_suffix = "_start";
break;
case FINISH_TO_FINISH:
predecessor_suffix = "_finished";
successor_suffix = "_finish";
break;
default:
System.out.print("the fuck ?");
break;
}
// creation du read-arc
Arc arc1 = myFactory.createArc();
arc1.setOutgoing(false);
arc1.setWeight(1);
Arc arc2 = myFactory.createArc();
arc2.setOutgoing(true);
arc2.setWeight(1);
for (Node node : network.getNodes()) {
if (node instanceof Place) {
Place place = (Place) node;
if (place.getName().equals(predecessor.getName() + predecessor_suffix)) {
arc1.setTarget(place);
arc2.setTarget(place);
}
}
if (node instanceof Transition) {
Transition transition = (Transition) node;
if (transition.getName().equals(successor.getName() + successor_suffix)) {
transition.getArcs().add(arc1);
transition.getArcs().add(arc2);
}
}
}
}
}
System.out.println("mdr2");
// Conversion des WorkSequence en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof Resource) {
Resource r = (Resource) o;
EObject qty = r.getEObject("quantity");
System.out.println(qty);
System.out.println("mdr");
}
}
// Créer le nouveau xmi (modèle convertit)
URI convURI = URI.createURI("models/Developpement_petrinet.xmi");
Resource conv = resSet.createResource(convURI);
// Ajouter le Network dans le nouveau modèle
conv.getContents().add(network);
// Sauver la ressource
try {
conv.save(Collections.EMPTY_MAP);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,205 @@
package simplepdl.manip;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
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.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import petrinet.PetrinetPackage;
import petrinet.Place;
import petrinet.Transition;
import petrinet.Arc;
import petrinet.Network;
import petrinet.Node;
import petrinet.PetrinetFactory;
import simplepdl.Process;
import simplepdl.WorkDefinition;
import simplepdl.WorkSequence;
import simplepdl.WorkSequenceType;
import simplepdl.SimplepdlPackage;
public class simplepdl2petrinet {
public static void main(String[] args) {
// Charger les package SimplePDL et Petrinet afin de les enregistrer dans le registre d'Eclipse.
SimplepdlPackage packageInstance = SimplepdlPackage.eINSTANCE;
PetrinetPackage packageInstance2 = PetrinetPackage.eINSTANCE;
// Enregistrer l'extension ".xmi" comme devant être ouverte à
// l'aide d'un objet "XMIResourceFactoryImpl"
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("xmi", new XMIResourceFactoryImpl());
// Créer un objet resourceSetImpl qui contiendra une ressource EMF (le modèle)
ResourceSet resSet = new ResourceSetImpl();
// Charger la ressource (notre modèle)
URI modelURI = URI.createURI("test.xmi");
Resource resource = resSet.getResource(modelURI, true);
// Récupérer le premier élément du modèle (élément racine)
Process process = (Process) resource.getContents().get(0);
// La fabrique pour fabriquer les éléments de PetriNET
PetrinetFactory myFactory = PetrinetFactory.eINSTANCE;
// Créer un élément Network
Network network = myFactory.createNetwork();
network.setName(process.getName());
// Conversion des WorkDefinition en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof WorkDefinition) {
WorkDefinition wd = (WorkDefinition) o;
String name = wd.getName();
Place idle = myFactory.createPlace();
idle.setName(name + "_idle");
idle.setTokens(1);
Place started = myFactory.createPlace();
started.setName(name + "_started");
started.setTokens(0);
Place running = myFactory.createPlace();
running.setName(name + "_running");
running.setTokens(0);
Place finished = myFactory.createPlace();
finished.setName(name + "_finished");
finished.setTokens(0);
Arc pause2start = myFactory.createArc();
pause2start.setTarget(idle);
pause2start.setOutgoing(false);
pause2start.setWeight(1);
Arc start2running = myFactory.createArc();
start2running.setTarget(running);
start2running.setOutgoing(true);
start2running.setWeight(1);
Arc start2started = myFactory.createArc();
start2started.setTarget(started);
start2started.setOutgoing(true);
start2started.setWeight(1);
Transition start = myFactory.createTransition();
start.setName(name + "_start");
start.getArcs().add(pause2start);
start.getArcs().add(start2running);
start.getArcs().add(start2started);
Arc running2finish = myFactory.createArc();
running2finish.setTarget(running);
running2finish.setOutgoing(false);
running2finish.setWeight(1);
Arc finish2finished = myFactory.createArc();
finish2finished.setTarget(finished);
finish2finished.setOutgoing(true);
finish2finished.setWeight(1);
Transition finish = myFactory.createTransition();
finish.setName(name + "_finish");
finish.getArcs().add(running2finish);
finish.getArcs().add(finish2finished);
network.getNodes().add(idle);
network.getNodes().add(start);
network.getNodes().add(started);
network.getNodes().add(running);
network.getNodes().add(finish);
network.getNodes().add(finished);
}
}
// Conversion des WorkSequence en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof WorkSequence) {
WorkSequence ws = (WorkSequence) o;
WorkSequenceType type = ws.getLinkType();
WorkDefinition predecessor = ws.getPredecessor();
WorkDefinition successor = ws.getSuccessor();
// creation des suffixs permettant la recherche des noeuds
String predecessor_suffix = new String();
String successor_suffix = new String();
switch (type) {
case START_TO_START:
predecessor_suffix = "_started";
successor_suffix = "_start";
break;
case START_TO_FINISH:
predecessor_suffix = "_started";
successor_suffix = "_finished";
break;
case FINISH_TO_START:
predecessor_suffix = "_finished";
successor_suffix = "_start";
break;
case FINISH_TO_FINISH:
predecessor_suffix = "_finished";
successor_suffix = "_finish";
break;
default:
System.out.print("the fuck ?");
break;
}
// creation du read-arc
Arc arc1 = myFactory.createArc();
arc1.setOutgoing(false);
arc1.setWeight(1);
Arc arc2 = myFactory.createArc();
arc2.setOutgoing(true);
arc2.setWeight(1);
for (Node node : network.getNodes()) {
if (node instanceof Place) {
Place place = (Place) node;
if (place.getName().equals(predecessor.getName() + predecessor_suffix)) {
arc1.setTarget(place);
arc2.setTarget(place);
}
}
if (node instanceof Transition) {
Transition transition = (Transition) node;
if (transition.getName().equals(successor.getName() + successor_suffix)) {
transition.getArcs().add(arc1);
transition.getArcs().add(arc2);
}
}
}
}
}
// Conversion des WorkSequence en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof Resource) {
Resource r = (Resource) o;
EObject qty = r.getEObject("quantity");
print(qty);
}
}
// Créer le nouveau xmi (modèle convertit)
URI convURI = URI.createURI("models/Developpement_petrinet.xmi");
Resource conv = resSet.createResource(convURI);
// Ajouter le Network dans le nouveau modèle
conv.getContents().add(network);
// Sauver la ressource
try {
conv.save(Collections.EMPTY_MAP);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<viewpoint:DAnalysis xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:viewpoint="http://www.eclipse.org/sirius/1.1.0" uid="_rlbscCtrEeyPENyXrdwYKQ" version="14.3.1.202003261200"/>

View file

@ -0,0 +1,6 @@
source.. = src/,\
src-gen/,\
xtend-gen/
bin.includes = META-INF/,\
.,\
plugin.xml

View file

@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8"?>
<simplepdl:Process
xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:simplepdl="http://simplepdl"
name="Developpement">
<processElements
xsi:type="simplepdl:WorkDefinition"
linksToSuccessors="//@processElements.4 //@processElements.6 //@processElements.7 //@processElements.8"
name="Conception">
<requests
quantity="15"
target="//@processElements.10"/>
</processElements>
<processElements
xsi:type="simplepdl:WorkDefinition"
linksToPredecessors="//@processElements.4"
linksToSuccessors="//@processElements.5"
name="Programmation"/>
<processElements
xsi:type="simplepdl:WorkDefinition"
linksToPredecessors="//@processElements.5 //@processElements.6"
name="RedactionTests"/>
<processElements
xsi:type="simplepdl:WorkDefinition"
linksToPredecessors="//@processElements.7 //@processElements.8"
name="RedactionDocs"/>
<processElements
xsi:type="simplepdl:WorkSequence"
linkType="finishToStart"
predecessor="//@processElements.0"
successor="//@processElements.1"/>
<processElements
xsi:type="simplepdl:WorkSequence"
linkType="finishToFinish"
predecessor="//@processElements.1"
successor="//@processElements.2"/>
<processElements
xsi:type="simplepdl:WorkSequence"
predecessor="//@processElements.0"
successor="//@processElements.2"/>
<processElements
xsi:type="simplepdl:WorkSequence"
predecessor="//@processElements.0"
successor="//@processElements.3"/>
<processElements
xsi:type="simplepdl:WorkSequence"
linkType="finishToFinish"
predecessor="//@processElements.0"
successor="//@processElements.3"/>
<processElements
xsi:type="simplepdl:Resource"
quantity="10"
name="Crayon"/>
<processElements
xsi:type="simplepdl:Resource"
quantity="20"
name="Papier"/>
</simplepdl:Process>

View file

@ -1,88 +0,0 @@
package simplepdl.manip;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
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.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import petrinet.PetrinetPackage;
import petrinet.PetrinetFactory;
import simplepdl.Process;
import simplepdl.WorkDefinition;
import simplepdl.WorkSequence;
import simplepdl.WorkSequenceType;
import simplepdl.SimplepdlFactory;
import simplepdl.SimplepdlPackage;
public class simplepdl2petrinet {
public static void main(String[] args) {
// Charger les package SimplePDL et Petrinet afin de les enregistrer dans le registre d'Eclipse.
SimplepdlPackage packageInstance = SimplepdlPackage.eINSTANCE;
PetrinetPackage packageInstance2 = PetrinetPackage.eINSTANCE;
// Enregistrer l'extension ".xmi" comme devant être ouverte à
// l'aide d'un objet "XMIResourceFactoryImpl"
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("xmi", new XMIResourceFactoryImpl());
// Créer un objet resourceSetImpl qui contiendra une ressource EMF (le modèle)
ResourceSet resSet = new ResourceSetImpl();
// Définir la ressource (le modèle)
URI modelURI = URI.createURI("models/SimplePDLCreator_Created_Process.xmi");
Resource resource = resSet.createResource(modelURI);
// La fabrique pour fabriquer les éléments de SimplePDL
SimplepdlFactory myFactory = SimplepdlFactory.eINSTANCE;
// Créer un élément Process
Process process = myFactory.createProcess();
process.setName("Mon premier processus");
// Ajouter le Process dans le modèle
resource.getContents().add(process);
// Ajouter deux WorkDefinitions
WorkDefinition wd1 = myFactory.createWorkDefinition();
wd1.setName("Ma première WorkDefinition, quelle émotion");
WorkDefinition wd2 = myFactory.createWorkDefinition();
wd2.setName("Ma deuxième WorkDefinition, toujours autant d'émotion");
process.getProcessElements().add(wd1);
process.getProcessElements().add(wd2);
// Ajouter une WorkSequence entre les deux WorkDefinitions
WorkSequence seq = myFactory.createWorkSequence();
seq.setPredecessor(wd1);
seq.setSuccessor(wd2);
seq.setLinkType(WorkSequenceType.FINISH_TO_FINISH);
process.getProcessElements().add(seq);
// Ajouter une deuxième WorkSequence entre les deux WorkDefinitions
WorkSequence seq2 = myFactory.createWorkSequence();
seq2.setPredecessor(wd1);
seq2.setSuccessor(wd2);
seq2.setLinkType(WorkSequenceType.START_TO_START);
process.getProcessElements().add(seq2);
// Sauver la ressource
try {
resource.save(Collections.EMPTY_MAP);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,6 @@
source.. = src/,\
src-gen/,\
xtend-gen/
bin.includes = META-INF/,\
.,\
plugin.xml

View file

@ -0,0 +1,45 @@
// automatically generated by Xtext
grammar fr.n7.simplepdl.txt.PDL with org.eclipse.xtext.common.Terminals
import "http://simplepdl"
import "http://www.eclipse.org/emf/2002/Ecore" as ecore
Process :
'process' name=ID '{'
processElements+=ProcessElement*
'}' ;
ProcessElement :
WorkDefinition | WorkSequence | Guidance | Resource
;
WorkDefinition :
'wd' name=ID
requests+=Request*
;
WorkSequence :
'ws' linkType=WorkSequenceType
'from' predecessor=[WorkDefinition]
'to' successor=[WorkDefinition]
;
Guidance :
'note' text=STRING
;
Resource :
'res' name=ID quantity=INT
;
Request :
'req' target=[Resource] quantity=INT
;
enum WorkSequenceType :
startToStart = 's2s'
| finishToStart = 'f2s'
| startToFinish = 's2f'
| finishToFinish = 'f2f'
;

View file

@ -0,0 +1,26 @@
grammar fr.n7.PDL1 with org.eclipse.xtext.common.Terminals
generate pDL1 "http://www.n7.fr/PDL1"
Process :
'process' name=ID ;
ProcessElement :
WorkDefinition | WorkSequence | Guidance;
WorkDefinition :
'wd' name=ID;
WorkSequence :
'ws' linkType=WorkSequenceType
'from' predecessor=[WorkDefinition]
'to' successor=[WorkDefinition] ;
Guidance :
'note' texte=STRING ;
enum WorkSequenceType :
start2start = 's2s'
| finish2start = 'f2s'
| start2finish = 's2f'
| finish2finish = 'f2f'
;

View file

@ -0,0 +1,29 @@
grammar fr.n7.PDL1 with org.eclipse.xtext.common.Terminals
generate pDL1 "http://www.n7.fr/PDL1"
Process :
'process' ':' name=ID
processElements+=ProcessElement* ;
ProcessElement :
WorkDefinitionList | WorkSequenceList ;
WorkDefinitionList :
'workdefinitions' ':' WorkDefinition+=WorkDefinition* ;
WorkDefinition :
name=ID ";" ;
WorkSequenceList :
'worksequences' ':' WorkSequence+=WorkSequence* ;
WorkSequence :
predecessor=[WorkDefinition] linkType=WorkSequenceType successor=[WorkDefinition] ";" ;
enum WorkSequenceType :
start2start = 's2s'
| finish2start = 'f2s'
| start2finish = 's2f'
| finish2finish = 'f2f'
;

View file

@ -0,0 +1,219 @@
package simplepdl.manip;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
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.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import petrinet.Arc;
import petrinet.Network;
import petrinet.Node;
import petrinet.PetrinetFactory;
import petrinet.PetrinetPackage;
import petrinet.Place;
import petrinet.Transition;
import simplepdl.Process;
import simplepdl.SimplepdlPackage;
import simplepdl.WorkDefinition;
import simplepdl.WorkSequence;
import simplepdl.WorkSequenceType;
import simplepdl.Request;
public class simplepdl2petrinet {
public static void main(String[] args) {
// Charger les package SimplePDL et Petrinet afin de les enregistrer dans le registre d'Eclipse.
SimplepdlPackage packageInstance = SimplepdlPackage.eINSTANCE;
PetrinetPackage packageInstance2 = PetrinetPackage.eINSTANCE;
// Enregistrer l'extension ".xmi" comme devant être ouverte à
// l'aide d'un objet "XMIResourceFactoryImpl"
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("xmi", new XMIResourceFactoryImpl());
// Créer un objet resourceSetImpl qui contiendra une ressource EMF (le modèle)
ResourceSet resSet = new ResourceSetImpl();
// Charger la ressource (notre modèle)
URI modelURI = URI.createURI("test.xmi");
Resource resource = resSet.getResource(modelURI, true);
// Récupérer le premier élément du modèle (élément racine)
Process process = (Process) resource.getContents().get(0);
// La fabrique pour fabriquer les éléments de PetriNET
PetrinetFactory myFactory = PetrinetFactory.eINSTANCE;
// Créer un élément Network
Network network = myFactory.createNetwork();
network.setName(process.getName());
// Conversion des WorkDefinition en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof WorkDefinition) {
WorkDefinition wd = (WorkDefinition) o;
String name = wd.getName();
Place idle = myFactory.createPlace();
idle.setName(name + "_idle");
idle.setTokens(1);
Place started = myFactory.createPlace();
started.setName(name + "_started");
started.setTokens(0);
Place running = myFactory.createPlace();
running.setName(name + "_running");
running.setTokens(0);
Place finished = myFactory.createPlace();
finished.setName(name + "_finished");
finished.setTokens(0);
Arc pause2start = myFactory.createArc();
pause2start.setTarget(idle);
pause2start.setOutgoing(false);
pause2start.setWeight(1);
Arc start2running = myFactory.createArc();
start2running.setTarget(running);
start2running.setOutgoing(true);
start2running.setWeight(1);
Arc start2started = myFactory.createArc();
start2started.setTarget(started);
start2started.setOutgoing(true);
start2started.setWeight(1);
Transition start = myFactory.createTransition();
start.setName(name + "_start");
start.getArcs().add(pause2start);
start.getArcs().add(start2running);
start.getArcs().add(start2started);
Arc running2finish = myFactory.createArc();
running2finish.setTarget(running);
running2finish.setOutgoing(false);
running2finish.setWeight(1);
Arc finish2finished = myFactory.createArc();
finish2finished.setTarget(finished);
finish2finished.setOutgoing(true);
finish2finished.setWeight(1);
Transition finish = myFactory.createTransition();
finish.setName(name + "_finish");
finish.getArcs().add(running2finish);
finish.getArcs().add(finish2finished);
network.getNodes().add(idle);
network.getNodes().add(start);
network.getNodes().add(started);
network.getNodes().add(running);
network.getNodes().add(finish);
network.getNodes().add(finished);
}
}
// Conversion des WorkSequence en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof WorkSequence) {
WorkSequence ws = (WorkSequence) o;
WorkSequenceType type = ws.getLinkType();
WorkDefinition predecessor = ws.getPredecessor();
WorkDefinition successor = ws.getSuccessor();
// creation des suffixs permettant la recherche des noeuds
String predecessor_suffix = new String();
String successor_suffix = new String();
switch (type) {
case START_TO_START:
predecessor_suffix = "_started";
successor_suffix = "_start";
break;
case START_TO_FINISH:
predecessor_suffix = "_started";
successor_suffix = "_finished";
break;
case FINISH_TO_START:
predecessor_suffix = "_finished";
successor_suffix = "_start";
break;
case FINISH_TO_FINISH:
predecessor_suffix = "_finished";
successor_suffix = "_finish";
break;
default:
System.out.print("the fuck ?");
break;
}
// creation du read-arc
Arc arc1 = myFactory.createArc();
arc1.setOutgoing(false);
arc1.setWeight(1);
Arc arc2 = myFactory.createArc();
arc2.setOutgoing(true);
arc2.setWeight(1);
for (Node node : network.getNodes()) {
if (node instanceof Place) {
Place place = (Place) node;
if (place.getName().equals(predecessor.getName() + predecessor_suffix)) {
arc1.setTarget(place);
arc2.setTarget(place);
}
}
if (node instanceof Transition) {
Transition transition = (Transition) node;
if (transition.getName().equals(successor.getName() + successor_suffix)) {
transition.getArcs().add(arc1);
transition.getArcs().add(arc2);
}
}
}
}
}
// Conversion des Resource et Request en Node et Arcs
for (Object o : process.getProcessElements()) {
if (o instanceof simplepdl.Resource) {
simplepdl.Resource r = (simplepdl.Resource) o;
String name = r.getName();
int qty = r.getQuantity();
Place res = myFactory.createPlace();
res.setName(name);
res.setTokens(qty);
}
if (o instanceof simplepdl.Request) {
Request r = (Request) o;
simplepdl.Resource target = r.getTarget();
int qty = r.getQuantity();
Place res = myFactory.createPlace();
res.setName(name);
res.setTokens(qty);
}
}
// Créer le nouveau xmi (modèle convertit)
URI convURI = URI.createURI("models/Developpement_petrinet.xmi");
Resource conv = resSet.createResource(convURI);
// Ajouter le Network dans le nouveau modèle
conv.getContents().add(network);
// Sauver la ressource
try {
conv.save(Collections.EMPTY_MAP);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,201 @@
package simplepdl.manip;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
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.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import petrinet.Arc;
import petrinet.Network;
import petrinet.Node;
import petrinet.PetrinetFactory;
import petrinet.PetrinetPackage;
import petrinet.Place;
import petrinet.Transition;
import simplepdl.Process;
import simplepdl.SimplepdlPackage;
import simplepdl.WorkDefinition;
import simplepdl.WorkSequence;
import simplepdl.WorkSequenceType;
public class simplepdl2petrinet {
public static void main(String[] args) {
// Charger les package SimplePDL et Petrinet afin de les enregistrer dans le registre d'Eclipse.
SimplepdlPackage packageInstance = SimplepdlPackage.eINSTANCE;
PetrinetPackage packageInstance2 = PetrinetPackage.eINSTANCE;
// Enregistrer l'extension ".xmi" comme devant être ouverte à
// l'aide d'un objet "XMIResourceFactoryImpl"
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("xmi", new XMIResourceFactoryImpl());
// Créer un objet resourceSetImpl qui contiendra une ressource EMF (le modèle)
ResourceSet resSet = new ResourceSetImpl();
// Charger la ressource (notre modèle)
URI modelURI = URI.createURI("test.xmi");
Resource resource = resSet.getResource(modelURI, true);
// Récupérer le premier élément du modèle (élément racine)
Process process = (Process) resource.getContents().get(0);
// La fabrique pour fabriquer les éléments de PetriNET
PetrinetFactory myFactory = PetrinetFactory.eINSTANCE;
// Créer un élément Network
Network network = myFactory.createNetwork();
network.setName(process.getName());
// Conversion des WorkDefinition en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof WorkDefinition) {
WorkDefinition wd = (WorkDefinition) o;
String name = wd.getName();
Place idle = myFactory.createPlace();
idle.setName(name + "_idle");
idle.setTokens(1);
Place started = myFactory.createPlace();
started.setName(name + "_started");
started.setTokens(0);
Place running = myFactory.createPlace();
running.setName(name + "_running");
running.setTokens(0);
Place finished = myFactory.createPlace();
finished.setName(name + "_finished");
finished.setTokens(0);
Arc pause2start = myFactory.createArc();
pause2start.setTarget(idle);
pause2start.setOutgoing(false);
pause2start.setWeight(1);
Arc start2running = myFactory.createArc();
start2running.setTarget(running);
start2running.setOutgoing(true);
start2running.setWeight(1);
Arc start2started = myFactory.createArc();
start2started.setTarget(started);
start2started.setOutgoing(true);
start2started.setWeight(1);
Transition start = myFactory.createTransition();
start.setName(name + "_start");
start.getArcs().add(pause2start);
start.getArcs().add(start2running);
start.getArcs().add(start2started);
Arc running2finish = myFactory.createArc();
running2finish.setTarget(running);
running2finish.setOutgoing(false);
running2finish.setWeight(1);
Arc finish2finished = myFactory.createArc();
finish2finished.setTarget(finished);
finish2finished.setOutgoing(true);
finish2finished.setWeight(1);
Transition finish = myFactory.createTransition();
finish.setName(name + "_finish");
finish.getArcs().add(running2finish);
finish.getArcs().add(finish2finished);
network.getNodes().add(idle);
network.getNodes().add(start);
network.getNodes().add(started);
network.getNodes().add(running);
network.getNodes().add(finish);
network.getNodes().add(finished);
}
}
// Conversion des WorkSequence en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof WorkSequence) {
WorkSequence ws = (WorkSequence) o;
WorkSequenceType type = ws.getLinkType();
WorkDefinition predecessor = ws.getPredecessor();
WorkDefinition successor = ws.getSuccessor();
// creation des suffixs permettant la recherche des noeuds
String predecessor_suffix = new String();
String successor_suffix = new String();
switch (type) {
case START_TO_START:
predecessor_suffix = "_started";
successor_suffix = "_start";
break;
case START_TO_FINISH:
predecessor_suffix = "_started";
successor_suffix = "_finished";
break;
case FINISH_TO_START:
predecessor_suffix = "_finished";
successor_suffix = "_start";
break;
case FINISH_TO_FINISH:
predecessor_suffix = "_finished";
successor_suffix = "_finish";
break;
default:
System.out.print("the fuck ?");
break;
}
// creation du read-arc
Arc arc1 = myFactory.createArc();
arc1.setOutgoing(false);
arc1.setWeight(1);
Arc arc2 = myFactory.createArc();
arc2.setOutgoing(true);
arc2.setWeight(1);
for (Node node : network.getNodes()) {
if (node instanceof Place) {
Place place = (Place) node;
if (place.getName().equals(predecessor.getName() + predecessor_suffix)) {
arc1.setTarget(place);
arc2.setTarget(place);
}
}
if (node instanceof Transition) {
Transition transition = (Transition) node;
if (transition.getName().equals(successor.getName() + successor_suffix)) {
transition.getArcs().add(arc1);
transition.getArcs().add(arc2);
}
}
}
}
}
// Conversion des WorkSequence en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof simplepdl.Resource) {
simplepdl.Resource r = (simplepdl.Resource) o;
int qty = r.getQuantity();
}
}
// Créer le nouveau xmi (modèle convertit)
URI convURI = URI.createURI("models/Developpement_petrinet.xmi");
Resource conv = resSet.createResource(convURI);
// Ajouter le Network dans le nouveau modèle
conv.getContents().add(network);
// Sauver la ressource
try {
conv.save(Collections.EMPTY_MAP);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View file

@ -1,91 +0,0 @@
package simplepdl.manip;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
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.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import petrinet.PetrinetPackage;
import petrinet.PetrinetFactory;
import simplepdl.Process;
import simplepdl.WorkDefinition;
import simplepdl.WorkSequence;
import simplepdl.WorkSequenceType;
import simplepdl.SimplepdlFactory;
import simplepdl.SimplepdlPackage;
public class simplepdl2petrinet {
public static void main(String[] args) {
// Charger les package SimplePDL et Petrinet afin de les enregistrer dans le registre d'Eclipse.
SimplepdlPackage packageInstance = SimplepdlPackage.eINSTANCE;
PetrinetPackage packageInstance2 = PetrinetPackage.eINSTANCE;
// Enregistrer l'extension ".xmi" comme devant être ouverte à
// l'aide d'un objet "XMIResourceFactoryImpl"
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("xmi", new XMIResourceFactoryImpl());
// Créer un objet resourceSetImpl qui contiendra une ressource EMF (le modèle)
ResourceSet resSet = new ResourceSetImpl();
// Charger la ressource (notre modèle)
URI modelURI = URI.createURI("pdl-sujet.xmi");
Resource resource = resSet.getResource(modelURI, true);
// Récupérer le premier élément du modèle (élément racine)
Process process = (Process) resource.getContents().get(0);
// La fabrique pour fabriquer les éléments de PetriNET
PetrinetFactory myFactory = PetrinetFactory.eINSTANCE;
// Créer un élément Process
Process process = myFactory.createProcess();
process.setName("Mon premier processus");
// Ajouter le Process dans le modèle
resource.getContents().add(process);
// Ajouter deux WorkDefinitions
WorkDefinition wd1 = myFactory.createWorkDefinition();
wd1.setName("Ma première WorkDefinition, quelle émotion");
WorkDefinition wd2 = myFactory.createWorkDefinition();
wd2.setName("Ma deuxième WorkDefinition, toujours autant d'émotion");
process.getProcessElements().add(wd1);
process.getProcessElements().add(wd2);
// Ajouter une WorkSequence entre les deux WorkDefinitions
WorkSequence seq = myFactory.createWorkSequence();
seq.setPredecessor(wd1);
seq.setSuccessor(wd2);
seq.setLinkType(WorkSequenceType.FINISH_TO_FINISH);
process.getProcessElements().add(seq);
// Ajouter une deuxième WorkSequence entre les deux WorkDefinitions
WorkSequence seq2 = myFactory.createWorkSequence();
seq2.setPredecessor(wd1);
seq2.setSuccessor(wd2);
seq2.setLinkType(WorkSequenceType.START_TO_START);
process.getProcessElements().add(seq2);
// Sauver la ressource
try {
resource.save(Collections.EMPTY_MAP);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,68 @@
// automatically generated by Xtext
grammar fr.n7.simplepdl.txt.PDL with org.eclipse.xtext.common.Terminals
import "http://simplepdl"
import "http://www.eclipse.org/emf/2002/Ecore" as ecore
Process returns Process:
{Process}
'Process'
name=EString
'{'
('processElements' '{' processElements+=ProcessElement ( "," processElements+=ProcessElement)* '}' )?
'}';
ProcessElement returns ProcessElement:
WorkDefinition | WorkSequence | Guidance | Resource;
EString returns ecore::EString:
STRING | ID;
WorkDefinition returns WorkDefinition:
{WorkDefinition}
'WorkDefinition'
name=EString
'{'
('linksToPredecessors' '(' linksToPredecessors+=[WorkSequence|EString] ( "," linksToPredecessors+=[WorkSequence|EString])* ')' )?
('linksToSuccessors' '(' linksToSuccessors+=[WorkSequence|EString] ( "," linksToSuccessors+=[WorkSequence|EString])* ')' )?
('requests' '{' requests+=Request ( "," requests+=Request)* '}' )?
'}';
WorkSequence returns WorkSequence:
'WorkSequence'
'{'
'linkType' linkType=WorkSequenceType
'predecessor' predecessor=[WorkDefinition|EString]
'successor' successor=[WorkDefinition|EString]
'}';
Guidance returns Guidance:
'Guidance'
'{'
'text' text=EString
('elements' '(' elements+=[ProcessElement|EString] ( "," elements+=[ProcessElement|EString])* ')' )?
'}';
Resource returns Resource:
'Resource'
name=EString
'{'
'quantity' quantity=EInt
'}';
Request returns Request:
'Request'
'{'
'quantity' quantity=EInt
'target' target=[Resource|EString]
'}';
EInt returns ecore::EInt:
'-'? INT;
enum WorkSequenceType returns WorkSequenceType:
startToStart = 'startToStart' | finishToStart = 'finishToStart' | startToFinish = 'startToFinish' | finishToFinish = 'finishToFinish';

View file

@ -0,0 +1,180 @@
/**
*/
package simplepdl.provider;
import java.util.Collection;
import java.util.List;
import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.util.ResourceLocator;
import org.eclipse.emf.edit.provider.ComposeableAdapterFactory;
import org.eclipse.emf.edit.provider.IEditingDomainItemProvider;
import org.eclipse.emf.edit.provider.IItemLabelProvider;
import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
import org.eclipse.emf.edit.provider.IItemPropertySource;
import org.eclipse.emf.edit.provider.IStructuredItemContentProvider;
import org.eclipse.emf.edit.provider.ITreeItemContentProvider;
import org.eclipse.emf.edit.provider.ItemPropertyDescriptor;
import org.eclipse.emf.edit.provider.ItemProviderAdapter;
import org.eclipse.emf.edit.provider.ViewerNotification;
import simplepdl.Request;
import simplepdl.SimplepdlPackage;
/**
* This is the item provider adapter for a {@link simplepdl.Request} object.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public class RequestItemProvider
extends ItemProviderAdapter
implements
IEditingDomainItemProvider,
IStructuredItemContentProvider,
ITreeItemContentProvider,
IItemLabelProvider,
IItemPropertySource {
/**
* This constructs an instance from a factory and a notifier.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public RequestItemProvider(AdapterFactory adapterFactory) {
super(adapterFactory);
}
/**
* This returns the property descriptors for the adapted class.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public List<IItemPropertyDescriptor> getPropertyDescriptors(Object object) {
if (itemPropertyDescriptors == null) {
super.getPropertyDescriptors(object);
addQuantityPropertyDescriptor(object);
addTargetPropertyDescriptor(object);
}
return itemPropertyDescriptors;
}
/**
* This adds a property descriptor for the Quantity feature.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
protected void addQuantityPropertyDescriptor(Object object) {
itemPropertyDescriptors.add
(createItemPropertyDescriptor
(((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(),
getResourceLocator(),
getString("_UI_Request_quantity_feature"),
getString("_UI_PropertyDescriptor_description", "_UI_Request_quantity_feature", "_UI_Request_type"),
SimplepdlPackage.Literals.REQUEST__QUANTITY,
true,
false,
false,
ItemPropertyDescriptor.INTEGRAL_VALUE_IMAGE,
null,
null));
}
/**
* This adds a property descriptor for the Target feature.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
protected void addTargetPropertyDescriptor(Object object) {
itemPropertyDescriptors.add
(createItemPropertyDescriptor
(((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(),
getResourceLocator(),
getString("_UI_Request_target_feature"),
getString("_UI_PropertyDescriptor_description", "_UI_Request_target_feature", "_UI_Request_type"),
SimplepdlPackage.Literals.REQUEST__TARGET,
true,
false,
true,
null,
null,
null));
}
/**
* This returns Request.gif.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public Object getImage(Object object) {
return overlayImage(object, getResourceLocator().getImage("full/obj16/Request"));
}
/**
* This returns the label text for the adapted class.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public String getText(Object object) {
Request request = (Request)object;
String targetname = request.getTarget() != null ? request.getTarget().getName() : "";
return getString("_UI_Request_type") + " --" + request.getQuantity() + "--> " + targetname;
}
/**
* This handles model notifications by calling {@link #updateChildren} to update any cached
* children and by creating a viewer notification, which it passes to {@link #fireNotifyChanged}.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public void notifyChanged(Notification notification) {
updateChildren(notification);
switch (notification.getFeatureID(Request.class)) {
case SimplepdlPackage.REQUEST__QUANTITY:
fireNotifyChanged(new ViewerNotification(notification, notification.getNotifier(), false, true));
return;
}
super.notifyChanged(notification);
}
/**
* This adds {@link org.eclipse.emf.edit.command.CommandParameter}s describing the children
* that can be created under this object.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
protected void collectNewChildDescriptors(Collection<Object> newChildDescriptors, Object object) {
super.collectNewChildDescriptors(newChildDescriptors, object);
}
/**
* Return the resource locator for this item provider's resources.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public ResourceLocator getResourceLocator() {
return SimplepdlEditPlugin.INSTANCE;
}
}

View file

@ -1,92 +0,0 @@
package simplepdl.manip;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
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.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import petrinet.PetrinetPackage;
import petrinet.Network;
import petrinet.PetrinetFactory;
import simplepdl.Process;
import simplepdl.WorkDefinition;
import simplepdl.WorkSequence;
import simplepdl.WorkSequenceType;
import simplepdl.SimplepdlFactory;
import simplepdl.SimplepdlPackage;
public class simplepdl2petrinet {
public static void main(String[] args) {
// Charger les package SimplePDL et Petrinet afin de les enregistrer dans le registre d'Eclipse.
SimplepdlPackage packageInstance = SimplepdlPackage.eINSTANCE;
PetrinetPackage packageInstance2 = PetrinetPackage.eINSTANCE;
// Enregistrer l'extension ".xmi" comme devant être ouverte à
// l'aide d'un objet "XMIResourceFactoryImpl"
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("xmi", new XMIResourceFactoryImpl());
// Créer un objet resourceSetImpl qui contiendra une ressource EMF (le modèle)
ResourceSet resSet = new ResourceSetImpl();
// Charger la ressource (notre modèle)
URI modelURI = URI.createURI("pdl-sujet.xmi");
Resource resource = resSet.getResource(modelURI, true);
// Récupérer le premier élément du modèle (élément racine)
Process process = (Process) resource.getContents().get(0);
// La fabrique pour fabriquer les éléments de PetriNET
PetrinetFactory myFactory = PetrinetFactory.eINSTANCE;
// Créer un élément Network
Network network = myFactory.createNetwork();
network.setName(process.getName());
//
// // Ajouter le Process dans le modèle
// resource.getContents().add(process);
//
// // Ajouter deux WorkDefinitions
// WorkDefinition wd1 = myFactory.createWorkDefinition();
// wd1.setName("Ma première WorkDefinition, quelle émotion");
//
// WorkDefinition wd2 = myFactory.createWorkDefinition();
// wd2.setName("Ma deuxième WorkDefinition, toujours autant d'émotion");
//
// process.getProcessElements().add(wd1);
// process.getProcessElements().add(wd2);
//
// // Ajouter une WorkSequence entre les deux WorkDefinitions
// WorkSequence seq = myFactory.createWorkSequence();
// seq.setPredecessor(wd1);
// seq.setSuccessor(wd2);
// seq.setLinkType(WorkSequenceType.FINISH_TO_FINISH);
//
// process.getProcessElements().add(seq);
//
// // Ajouter une deuxième WorkSequence entre les deux WorkDefinitions
// WorkSequence seq2 = myFactory.createWorkSequence();
// seq2.setPredecessor(wd1);
// seq2.setSuccessor(wd2);
// seq2.setLinkType(WorkSequenceType.START_TO_START);
//
// process.getProcessElements().add(seq2);
// Sauver la ressource
try {
resource.save(Collections.EMPTY_MAP);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,43 @@
// automatically generated by Xtext
grammar fr.n7.simplepdl.txt.PDL with org.eclipse.xtext.common.Terminals
import "http://simplepdl"
import "http://www.eclipse.org/emf/2002/Ecore" as ecore
Process :
'process' name=ID '{'
processElements+=ProcessElement*
'}' ;
ProcessElement :
WorkDefinition | WorkSequence | Guidance | Resource ;
WorkDefinition :
'wd' name=ID
requests+=Request*
;
WorkSequence :
'ws' linkType=WorkSequenceType
'from' predecessor=[WorkDefinition]
'to' successor=[WorkDefinition] ;
Guidance :
'note' text=STRING ;
Resource :
'res' name=ID quantity=INT
;
Request :
'req' target=[Resource] quantity=INT
;
enum WorkSequenceType :
startToStart = 's2s'
| finishToStart = 'f2s'
| startToFinish = 's2f'
| finishToFinish = 'f2f'
;

View file

@ -1,88 +0,0 @@
package simplepdl.manip;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
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.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import petrinet.PetrinetPackage;
import petrinet.PetrinetFactory;
import simplepdl.Process;
import simplepdl.WorkDefinition;
import simplepdl.WorkSequence;
import simplepdl.WorkSequenceType;
import simplepdl.SimplepdlFactory;
import simplepdl.SimplepdlPackage;
public class simplepdl2petrinet {
public static void main(String[] args) {
// Charger les package SimplePDL et Petrinet afin de les enregistrer dans le registre d'Eclipse.
SimplepdlPackage packageInstance = SimplepdlPackage.eINSTANCE;
PetrinetPackage packageInstance2 = PetrinetPackage.eINSTANCE;
// Enregistrer l'extension ".xmi" comme devant être ouverte à
// l'aide d'un objet "XMIResourceFactoryImpl"
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("xmi", new XMIResourceFactoryImpl());
// Créer un objet resourceSetImpl qui contiendra une ressource EMF (le modèle)
ResourceSet resSet = new ResourceSetImpl();
// Définir la ressource (le modèle)
URI modelURI = URI.createURI("models/SimplePDLCreator_Created_Process.xmi");
Resource resource = resSet.createResource(modelURI);
// La fabrique pour fabriquer les éléments de SimplePDL
SimplepdlFactory myFactory = SimplepdlFactory.eINSTANCE;
// Créer un élément Process
Process process = myFactory.createProcess();
process.setName("Mon premier processus");
// Ajouter le Process dans le modèle
resource.getContents().add(process);
// Ajouter deux WorkDefinitions
WorkDefinition wd1 = myFactory.createWorkDefinition();
wd1.setName("Ma première WorkDefinition, quelle émotion");
WorkDefinition wd2 = myFactory.createWorkDefinition();
wd2.setName("Ma deuxième WorkDefinition, toujours autant d'émotion");
process.getProcessElements().add(wd1);
process.getProcessElements().add(wd2);
// Ajouter une WorkSequence entre les deux WorkDefinitions
WorkSequence seq = myFactory.createWorkSequence();
seq.setPredecessor(wd1);
seq.setSuccessor(wd2);
seq.setLinkType(WorkSequenceType.FINISH_TO_FINISH);
process.getProcessElements().add(seq);
// Ajouter une deuxième WorkSequence entre les deux WorkDefinitions
WorkSequence seq2 = myFactory.createWorkSequence();
seq2.setPredecessor(wd1);
seq2.setSuccessor(wd2);
seq2.setLinkType(WorkSequenceType.START_TO_START);
process.getProcessElements().add(seq2);
// Sauver la ressource
try {
resource.save(Collections.EMPTY_MAP);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,208 @@
package simplepdl.manip;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
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.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import petrinet.PetrinetPackage;
import petrinet.Place;
import petrinet.Transition;
import petrinet.Arc;
import petrinet.Network;
import petrinet.Node;
import petrinet.PetrinetFactory;
import simplepdl.Process;
import simplepdl.WorkDefinition;
import simplepdl.WorkSequence;
import simplepdl.WorkSequenceType;
import simplepdl.SimplepdlPackage;
import simplepdl.Resource;
public class simplepdl2petrinet {
public static void main(String[] args) {
// Charger les package SimplePDL et Petrinet afin de les enregistrer dans le registre d'Eclipse.
SimplepdlPackage packageInstance = SimplepdlPackage.eINSTANCE;
PetrinetPackage packageInstance2 = PetrinetPackage.eINSTANCE;
// Enregistrer l'extension ".xmi" comme devant être ouverte à
// l'aide d'un objet "XMIResourceFactoryImpl"
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("xmi", new XMIResourceFactoryImpl());
// Créer un objet resourceSetImpl qui contiendra une ressource EMF (le modèle)
ResourceSet resSet = new ResourceSetImpl();
// Charger la ressource (notre modèle)
URI modelURI = URI.createURI("test.xmi");
Resource resource = resSet.getResource(modelURI, true);
// Récupérer le premier élément du modèle (élément racine)
Process process = (Process) resource.getContents().get(0);
// La fabrique pour fabriquer les éléments de PetriNET
PetrinetFactory myFactory = PetrinetFactory.eINSTANCE;
// Créer un élément Network
Network network = myFactory.createNetwork();
network.setName(process.getName());
// Conversion des WorkDefinition en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof WorkDefinition) {
WorkDefinition wd = (WorkDefinition) o;
String name = wd.getName();
Place idle = myFactory.createPlace();
idle.setName(name + "_idle");
idle.setTokens(1);
Place started = myFactory.createPlace();
started.setName(name + "_started");
started.setTokens(0);
Place running = myFactory.createPlace();
running.setName(name + "_running");
running.setTokens(0);
Place finished = myFactory.createPlace();
finished.setName(name + "_finished");
finished.setTokens(0);
Arc pause2start = myFactory.createArc();
pause2start.setTarget(idle);
pause2start.setOutgoing(false);
pause2start.setWeight(1);
Arc start2running = myFactory.createArc();
start2running.setTarget(running);
start2running.setOutgoing(true);
start2running.setWeight(1);
Arc start2started = myFactory.createArc();
start2started.setTarget(started);
start2started.setOutgoing(true);
start2started.setWeight(1);
Transition start = myFactory.createTransition();
start.setName(name + "_start");
start.getArcs().add(pause2start);
start.getArcs().add(start2running);
start.getArcs().add(start2started);
Arc running2finish = myFactory.createArc();
running2finish.setTarget(running);
running2finish.setOutgoing(false);
running2finish.setWeight(1);
Arc finish2finished = myFactory.createArc();
finish2finished.setTarget(finished);
finish2finished.setOutgoing(true);
finish2finished.setWeight(1);
Transition finish = myFactory.createTransition();
finish.setName(name + "_finish");
finish.getArcs().add(running2finish);
finish.getArcs().add(finish2finished);
network.getNodes().add(idle);
network.getNodes().add(start);
network.getNodes().add(started);
network.getNodes().add(running);
network.getNodes().add(finish);
network.getNodes().add(finished);
}
}
// Conversion des WorkSequence en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof WorkSequence) {
WorkSequence ws = (WorkSequence) o;
WorkSequenceType type = ws.getLinkType();
WorkDefinition predecessor = ws.getPredecessor();
WorkDefinition successor = ws.getSuccessor();
// creation des suffixs permettant la recherche des noeuds
String predecessor_suffix = new String();
String successor_suffix = new String();
switch (type) {
case START_TO_START:
predecessor_suffix = "_started";
successor_suffix = "_start";
break;
case START_TO_FINISH:
predecessor_suffix = "_started";
successor_suffix = "_finished";
break;
case FINISH_TO_START:
predecessor_suffix = "_finished";
successor_suffix = "_start";
break;
case FINISH_TO_FINISH:
predecessor_suffix = "_finished";
successor_suffix = "_finish";
break;
default:
System.out.print("the fuck ?");
break;
}
// creation du read-arc
Arc arc1 = myFactory.createArc();
arc1.setOutgoing(false);
arc1.setWeight(1);
Arc arc2 = myFactory.createArc();
arc2.setOutgoing(true);
arc2.setWeight(1);
for (Node node : network.getNodes()) {
if (node instanceof Place) {
Place place = (Place) node;
if (place.getName().equals(predecessor.getName() + predecessor_suffix)) {
arc1.setTarget(place);
arc2.setTarget(place);
}
}
if (node instanceof Transition) {
Transition transition = (Transition) node;
if (transition.getName().equals(successor.getName() + successor_suffix)) {
transition.getArcs().add(arc1);
transition.getArcs().add(arc2);
}
}
}
}
}
System.out.println("mdr2");
// Conversion des WorkSequence en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof Resource) {
Resource r = (Resource) o;
EObject qty = r.getEObject("quantity");
System.out.println(qty);
System.out.println("mdr");
}
}
// Créer le nouveau xmi (modèle convertit)
URI convURI = URI.createURI("models/Developpement_petrinet.xmi");
Resource conv = resSet.createResource(convURI);
// Ajouter le Network dans le nouveau modèle
conv.getContents().add(network);
// Sauver la ressource
try {
conv.save(Collections.EMPTY_MAP);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,31 @@
grammar fr.n7.PDL1 with org.eclipse.xtext.common.Terminals
generate pDL1 "http://www.n7.fr/PDL1"
Process :
'process' ':' name=ID
processElements+=ProcessElement* ;
ProcessElement :
WorkDefinitionList | WorkSequence | Guidance;
WorkDefinitionList :
'workdefinitions' ':' WorkDefinition+=WorkDefinition* ;
WorkDefinition :
name=ID ";" ;
WorkSequence :
'ws' linkType=WorkSequenceType
'from' predecessor=[WorkDefinition]
'to' successor=[WorkDefinition] ;
Guidance :
'note' texte=STRING ;
enum WorkSequenceType :
start2start = 's2s'
| finish2start = 'f2s'
| start2finish = 's2f'
| finish2finish = 'f2f'
;

View file

@ -0,0 +1,201 @@
package simplepdl.manip;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
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.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import petrinet.PetrinetPackage;
import petrinet.Place;
import petrinet.Transition;
import petrinet.Arc;
import petrinet.Network;
import petrinet.Node;
import petrinet.PetrinetFactory;
import simplepdl.Process;
import simplepdl.WorkDefinition;
import simplepdl.WorkSequence;
import simplepdl.WorkSequenceType;
import simplepdl.SimplepdlPackage;
public class simplepdl2petrinet {
public static void main(String[] args) {
// Charger les package SimplePDL et Petrinet afin de les enregistrer dans le registre d'Eclipse.
SimplepdlPackage packageInstance = SimplepdlPackage.eINSTANCE;
PetrinetPackage packageInstance2 = PetrinetPackage.eINSTANCE;
// Enregistrer l'extension ".xmi" comme devant être ouverte à
// l'aide d'un objet "XMIResourceFactoryImpl"
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("xmi", new XMIResourceFactoryImpl());
// Créer un objet resourceSetImpl qui contiendra une ressource EMF (le modèle)
ResourceSet resSet = new ResourceSetImpl();
// Charger la ressource (notre modèle)
URI modelURI = URI.createURI("test.xmi");
Resource resource = resSet.getResource(modelURI, true);
// Récupérer le premier élément du modèle (élément racine)
Process process = (Process) resource.getContents().get(0);
// La fabrique pour fabriquer les éléments de PetriNET
PetrinetFactory myFactory = PetrinetFactory.eINSTANCE;
// Créer un élément Network
Network network = myFactory.createNetwork();
network.setName(process.getName());
// Conversion des WorkDefinition en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof WorkDefinition) {
WorkDefinition wd = (WorkDefinition) o;
String name = wd.getName();
Place idle = myFactory.createPlace();
idle.setName(name + "_idle");
idle.setTokens(1);
Place started = myFactory.createPlace();
started.setName(name + "_started");
started.setTokens(0);
Place running = myFactory.createPlace();
running.setName(name + "_running");
running.setTokens(0);
Place finished = myFactory.createPlace();
finished.setName(name + "_finished");
finished.setTokens(0);
Arc pause2start = myFactory.createArc();
pause2start.setTarget(idle);
pause2start.setOutgoing(false);
pause2start.setWeight(1);
Arc start2running = myFactory.createArc();
start2running.setTarget(running);
start2running.setOutgoing(true);
start2running.setWeight(1);
Arc start2started = myFactory.createArc();
start2started.setTarget(started);
start2started.setOutgoing(true);
start2started.setWeight(1);
Transition start = myFactory.createTransition();
start.setName(name + "_start");
start.getArcs().add(pause2start);
start.getArcs().add(start2running);
start.getArcs().add(start2started);
Arc running2finish = myFactory.createArc();
running2finish.setTarget(running);
running2finish.setOutgoing(false);
running2finish.setWeight(1);
Arc finish2finished = myFactory.createArc();
finish2finished.setTarget(finished);
finish2finished.setOutgoing(true);
finish2finished.setWeight(1);
Transition finish = myFactory.createTransition();
finish.setName(name + "_finish");
finish.getArcs().add(running2finish);
finish.getArcs().add(finish2finished);
network.getNodes().add(idle);
network.getNodes().add(start);
network.getNodes().add(started);
network.getNodes().add(running);
network.getNodes().add(finish);
network.getNodes().add(finished);
}
}
// Conversion des WorkSequence en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof WorkSequence) {
WorkSequence ws = (WorkSequence) o;
WorkSequenceType type = ws.getLinkType();
WorkDefinition predecessor = ws.getPredecessor();
WorkDefinition successor = ws.getSuccessor();
// creation des suffixs permettant la recherche des noeuds
String predecessor_suffix = new String();
String successor_suffix = new String();
switch (type) {
case START_TO_START:
predecessor_suffix = "_started";
successor_suffix = "_start";
break;
case START_TO_FINISH:
predecessor_suffix = "_started";
successor_suffix = "_finished";
break;
case FINISH_TO_START:
predecessor_suffix = "_finished";
successor_suffix = "_start";
break;
case FINISH_TO_FINISH:
predecessor_suffix = "_finished";
successor_suffix = "_finish";
break;
default:
System.out.print("the fuck ?");
break;
}
// creation du read-arc
Arc arc1 = myFactory.createArc();
arc1.setOutgoing(false);
arc1.setWeight(1);
Arc arc2 = myFactory.createArc();
arc2.setOutgoing(true);
arc2.setWeight(1);
for (Node node : network.getNodes()) {
if (node instanceof Place) {
Place place = (Place) node;
if (place.getName().equals(predecessor.getName() + predecessor_suffix)) {
arc1.setTarget(place);
arc2.setTarget(place);
}
}
if (node instanceof Transition) {
Transition transition = (Transition) node;
if (transition.getName().equals(successor.getName() + successor_suffix)) {
transition.getArcs().add(arc1);
transition.getArcs().add(arc2);
}
}
}
}
}
// Conversion des WorkSequence en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof Ressource) {
}
}
// Créer le nouveau xmi (modèle convertit)
URI convURI = URI.createURI("models/Developpement_petrinet.xmi");
Resource conv = resSet.createResource(convURI);
// Ajouter le Network dans le nouveau modèle
conv.getContents().add(network);
// Sauver la ressource
try {
conv.save(Collections.EMPTY_MAP);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,71 @@
<?xml version="1.0" encoding="UTF-8"?>
<simplepdl:Process
xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:simplepdl="http://simplepdl"
name="Developpement">
<processElements
xsi:type="simplepdl:WorkDefinition"
linksToSuccessors="//@processElements.4 //@processElements.6 //@processElements.7 //@processElements.8"
name="Conception">
<requests
quantity="15"
target="//@processElements.10"/>
</processElements>
<processElements
xsi:type="simplepdl:WorkDefinition"
linksToPredecessors="//@processElements.4"
linksToSuccessors="//@processElements.5"
name="Programmation">
<requests
quantity="15"
target="//@processElements.10"/>
</processElements>
<processElements
xsi:type="simplepdl:WorkDefinition"
linksToPredecessors="//@processElements.5 //@processElements.6"
name="RedactionTests"/>
<processElements
xsi:type="simplepdl:WorkDefinition"
linksToPredecessors="//@processElements.7 //@processElements.8"
name="RedactionDocs">
<requests
quantity="5"
target="//@processElements.10"/>
<requests
quantity="5"
target="//@processElements.9"/>
</processElements>
<processElements
xsi:type="simplepdl:WorkSequence"
linkType="finishToStart"
predecessor="//@processElements.0"
successor="//@processElements.1"/>
<processElements
xsi:type="simplepdl:WorkSequence"
linkType="finishToFinish"
predecessor="//@processElements.1"
successor="//@processElements.2"/>
<processElements
xsi:type="simplepdl:WorkSequence"
predecessor="//@processElements.0"
successor="//@processElements.2"/>
<processElements
xsi:type="simplepdl:WorkSequence"
predecessor="//@processElements.0"
successor="//@processElements.3"/>
<processElements
xsi:type="simplepdl:WorkSequence"
linkType="finishToFinish"
predecessor="//@processElements.0"
successor="//@processElements.3"/>
<processElements
xsi:type="simplepdl:Resource"
quantity="10"
name="Crayon"/>
<processElements
xsi:type="simplepdl:Resource"
quantity="20"
name="Papier"/>
</simplepdl:Process>

View file

@ -0,0 +1,29 @@
grammar fr.n7.PDL1 with org.eclipse.xtext.common.Terminals
generate pDL1 "http://www.n7.fr/PDL1"
Process :
'process' ':' name=ID
processElements+=ProcessElement* ;
ProcessElement :
WorkDefinitionList | WorkSequenceList ;
WorkDefinitionList :
'workdefinitions' ':' WorkDefinition+=WorkDefinition* ;
WorkDefinition :
name=ID ";" ;
WorkSequenceList :
'worksequences' ':' WorkSequence+=WorkSequence* ;
WorkSequence :
predecessor=[WorkDefinition] linkType=WorkSequenceType successor=[WorkDefinition] ";" ;
enum WorkSequenceType :
start2start = 's2s'
| finish2start = 'f2s'
| start2finish = 's2f'
| finish2finish = 'f2f'
;

View file

@ -0,0 +1,6 @@
source.. = src/,\
src-gen/,\
xtend-gen/
bin.includes = META-INF/,\
.,\
plugin.xml

View file

@ -0,0 +1,202 @@
package simplepdl.manip;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
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.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import petrinet.PetrinetPackage;
import petrinet.Place;
import petrinet.Transition;
import petrinet.Arc;
import petrinet.Network;
import petrinet.Node;
import petrinet.PetrinetFactory;
import simplepdl.Process;
import simplepdl.WorkDefinition;
import simplepdl.WorkSequence;
import simplepdl.WorkSequenceType;
import simplepdl.SimplepdlPackage;
public class simplepdl2petrinet {
public static void main(String[] args) {
// Charger les package SimplePDL et Petrinet afin de les enregistrer dans le registre d'Eclipse.
SimplepdlPackage packageInstance = SimplepdlPackage.eINSTANCE;
PetrinetPackage packageInstance2 = PetrinetPackage.eINSTANCE;
// Enregistrer l'extension ".xmi" comme devant être ouverte à
// l'aide d'un objet "XMIResourceFactoryImpl"
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("xmi", new XMIResourceFactoryImpl());
// Créer un objet resourceSetImpl qui contiendra une ressource EMF (le modèle)
ResourceSet resSet = new ResourceSetImpl();
// Charger la ressource (notre modèle)
URI modelURI = URI.createURI("test.xmi");
Resource resource = resSet.getResource(modelURI, true);
// Récupérer le premier élément du modèle (élément racine)
Process process = (Process) resource.getContents().get(0);
// La fabrique pour fabriquer les éléments de PetriNET
PetrinetFactory myFactory = PetrinetFactory.eINSTANCE;
// Créer un élément Network
Network network = myFactory.createNetwork();
network.setName(process.getName());
// Conversion des WorkDefinition en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof WorkDefinition) {
WorkDefinition wd = (WorkDefinition) o;
String name = wd.getName();
Place idle = myFactory.createPlace();
idle.setName(name + "_idle");
idle.setTokens(1);
Place started = myFactory.createPlace();
started.setName(name + "_started");
started.setTokens(0);
Place running = myFactory.createPlace();
running.setName(name + "_running");
running.setTokens(0);
Place finished = myFactory.createPlace();
finished.setName(name + "_finished");
finished.setTokens(0);
Arc pause2start = myFactory.createArc();
pause2start.setTarget(idle);
pause2start.setOutgoing(false);
pause2start.setWeight(1);
Arc start2running = myFactory.createArc();
start2running.setTarget(running);
start2running.setOutgoing(true);
start2running.setWeight(1);
Arc start2started = myFactory.createArc();
start2started.setTarget(started);
start2started.setOutgoing(true);
start2started.setWeight(1);
Transition start = myFactory.createTransition();
start.setName(name + "_start");
start.getArcs().add(pause2start);
start.getArcs().add(start2running);
start.getArcs().add(start2started);
Arc running2finish = myFactory.createArc();
running2finish.setTarget(running);
running2finish.setOutgoing(false);
running2finish.setWeight(1);
Arc finish2finished = myFactory.createArc();
finish2finished.setTarget(finished);
finish2finished.setOutgoing(true);
finish2finished.setWeight(1);
Transition finish = myFactory.createTransition();
finish.setName(name + "_finish");
finish.getArcs().add(running2finish);
finish.getArcs().add(finish2finished);
network.getNodes().add(idle);
network.getNodes().add(start);
network.getNodes().add(started);
network.getNodes().add(running);
network.getNodes().add(finish);
network.getNodes().add(finished);
}
}
// Conversion des WorkSequence en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof WorkSequence) {
WorkSequence ws = (WorkSequence) o;
WorkSequenceType type = ws.getLinkType();
WorkDefinition predecessor = ws.getPredecessor();
WorkDefinition successor = ws.getSuccessor();
// creation des suffixs permettant la recherche des noeuds
String predecessor_suffix = new String();
String successor_suffix = new String();
switch (type) {
case START_TO_START:
predecessor_suffix = "_started";
successor_suffix = "_start";
break;
case START_TO_FINISH:
predecessor_suffix = "_started";
successor_suffix = "_finished";
break;
case FINISH_TO_START:
predecessor_suffix = "_finished";
successor_suffix = "_start";
break;
case FINISH_TO_FINISH:
predecessor_suffix = "_finished";
successor_suffix = "_finish";
break;
default:
System.out.print("the fuck ?");
break;
}
// creation du read-arc
Arc arc1 = myFactory.createArc();
arc1.setOutgoing(false);
arc1.setWeight(1);
Arc arc2 = myFactory.createArc();
arc2.setOutgoing(true);
arc2.setWeight(1);
for (Node node : network.getNodes()) {
if (node instanceof Place) {
Place place = (Place) node;
if (place.getName().equals(predecessor.getName() + predecessor_suffix)) {
arc1.setTarget(place);
arc2.setTarget(place);
}
}
if (node instanceof Transition) {
Transition transition = (Transition) node;
if (transition.getName().equals(successor.getName() + successor_suffix)) {
transition.getArcs().add(arc1);
transition.getArcs().add(arc2);
}
}
}
}
}
// Conversion des WorkSequence en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof Resource) {
Resource r = (Resource) o;
int qty = r.getQuantity();
}
}
// Créer le nouveau xmi (modèle convertit)
URI convURI = URI.createURI("models/Developpement_petrinet.xmi");
Resource conv = resSet.createResource(convURI);
// Ajouter le Network dans le nouveau modèle
conv.getContents().add(network);
// Sauver la ressource
try {
conv.save(Collections.EMPTY_MAP);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,41 @@
// automatically generated by Xtext
grammar fr.n7.simplepdl.txt.PDL with org.eclipse.xtext.common.Terminals
import "http://simplepdl"
import "http://www.eclipse.org/emf/2002/Ecore" as ecore
Process :
'process' name=ID '{'
processElements+=ProcessElement*
'}' ;
ProcessElement :
WorkDefinition | WorkSequence | Guidance | Resource | Request ;
WorkDefinition :
'wd' name=ID;
WorkSequence :
'ws' linkType=WorkSequenceType
'from' predecessor=[WorkDefinition]
'to' successor=[WorkDefinition] ;
Guidance :
'note' text=STRING ;
Resource :
'res' name=ID quantity=INT
;
Request :
'req' target=[Resource] quantity=INT
;
enum WorkSequenceType :
startToStart = 's2s'
| finishToStart = 'f2s'
| startToFinish = 's2f'
| finishToFinish = 'f2f'
;

View file

@ -0,0 +1,6 @@
source.. = src/,\
src-gen/,\
xtend-gen/
bin.includes = META-INF/,\
.,\
plugin.xml

View file

@ -0,0 +1,233 @@
package simplepdl.manip;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
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.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import petrinet.Arc;
import petrinet.Network;
import petrinet.Node;
import petrinet.PetrinetFactory;
import petrinet.PetrinetPackage;
import petrinet.Place;
import petrinet.Transition;
import simplepdl.Process;
import simplepdl.SimplepdlPackage;
import simplepdl.WorkDefinition;
import simplepdl.WorkSequence;
import simplepdl.WorkSequenceType;
import simplepdl.Request;
public class simplepdl2petrinet {
public static void main(String[] args) {
// Charger les package SimplePDL et Petrinet afin de les enregistrer dans le registre d'Eclipse.
SimplepdlPackage packageInstance = SimplepdlPackage.eINSTANCE;
PetrinetPackage packageInstance2 = PetrinetPackage.eINSTANCE;
// Enregistrer l'extension ".xmi" comme devant être ouverte à
// l'aide d'un objet "XMIResourceFactoryImpl"
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("xmi", new XMIResourceFactoryImpl());
// Créer un objet resourceSetImpl qui contiendra une ressource EMF (le modèle)
ResourceSet resSet = new ResourceSetImpl();
// Charger la ressource (notre modèle)
URI modelURI = URI.createURI("test.xmi");
Resource resource = resSet.getResource(modelURI, true);
// Récupérer le premier élément du modèle (élément racine)
Process process = (Process) resource.getContents().get(0);
// La fabrique pour fabriquer les éléments de PetriNET
PetrinetFactory myFactory = PetrinetFactory.eINSTANCE;
// Créer un élément Network
Network network = myFactory.createNetwork();
network.setName(process.getName());
// Conversion des WorkDefinition en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof WorkDefinition) {
WorkDefinition wd = (WorkDefinition) o;
String name = wd.getName();
Place idle = myFactory.createPlace();
idle.setName(name + "_idle");
idle.setTokens(1);
Place started = myFactory.createPlace();
started.setName(name + "_started");
started.setTokens(0);
Place running = myFactory.createPlace();
running.setName(name + "_running");
running.setTokens(0);
Place finished = myFactory.createPlace();
finished.setName(name + "_finished");
finished.setTokens(0);
Arc pause2start = myFactory.createArc();
pause2start.setTarget(idle);
pause2start.setOutgoing(false);
pause2start.setWeight(1);
Arc start2running = myFactory.createArc();
start2running.setTarget(running);
start2running.setOutgoing(true);
start2running.setWeight(1);
Arc start2started = myFactory.createArc();
start2started.setTarget(started);
start2started.setOutgoing(true);
start2started.setWeight(1);
Transition start = myFactory.createTransition();
start.setName(name + "_start");
start.getArcs().add(pause2start);
start.getArcs().add(start2running);
start.getArcs().add(start2started);
Arc running2finish = myFactory.createArc();
running2finish.setTarget(running);
running2finish.setOutgoing(false);
running2finish.setWeight(1);
Arc finish2finished = myFactory.createArc();
finish2finished.setTarget(finished);
finish2finished.setOutgoing(true);
finish2finished.setWeight(1);
Transition finish = myFactory.createTransition();
finish.setName(name + "_finish");
finish.getArcs().add(running2finish);
finish.getArcs().add(finish2finished);
network.getNodes().add(idle);
network.getNodes().add(start);
network.getNodes().add(started);
network.getNodes().add(running);
network.getNodes().add(finish);
network.getNodes().add(finished);
}
}
// Conversion des WorkSequence en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof WorkSequence) {
WorkSequence ws = (WorkSequence) o;
WorkSequenceType type = ws.getLinkType();
WorkDefinition predecessor = ws.getPredecessor();
WorkDefinition successor = ws.getSuccessor();
// creation des suffixs permettant la recherche des noeuds
String predecessor_suffix = new String();
String successor_suffix = new String();
switch (type) {
case START_TO_START:
predecessor_suffix = "_started";
successor_suffix = "_start";
break;
case START_TO_FINISH:
predecessor_suffix = "_started";
successor_suffix = "_finished";
break;
case FINISH_TO_START:
predecessor_suffix = "_finished";
successor_suffix = "_start";
break;
case FINISH_TO_FINISH:
predecessor_suffix = "_finished";
successor_suffix = "_finish";
break;
default:
System.out.print("the fuck ?");
break;
}
// creation du read-arc
Arc arc1 = myFactory.createArc();
arc1.setOutgoing(false);
arc1.setWeight(1);
Arc arc2 = myFactory.createArc();
arc2.setOutgoing(true);
arc2.setWeight(1);
for (Node node : network.getNodes()) {
if (node instanceof Place) {
Place place = (Place) node;
if (place.getName().equals(predecessor.getName() + predecessor_suffix)) {
arc1.setTarget(place);
arc2.setTarget(place);
}
}
if (node instanceof Transition) {
Transition transition = (Transition) node;
if (transition.getName().equals(successor.getName() + successor_suffix)) {
transition.getArcs().add(arc1);
transition.getArcs().add(arc2);
}
}
}
}
}
// Conversion des Resource et Request en Node et Arcs
for (Object o : process.getProcessElements()) {
if (o instanceof simplepdl.Resource) {
simplepdl.Resource r = (simplepdl.Resource) o;
String name = r.getName();
int qty = r.getQuantity();
Place res = myFactory.createPlace();
res.setName(name);
res.setTokens(qty);
network.getNodes().add(res);
}
if (o instanceof simplepdl.Request) {
Request r = (Request) o;
simplepdl.Resource target = r.getTarget();
int qty = r.getQuantity();
Arc arc1 = myFactory.createArc();
arc1.setOutgoing(true);
arc1.setWeight(qty);
Arc arc2 = myFactory.createArc();
arc2.setOutgoing(false);
arc2.setWeight(qty);
for (Node node : network.getNodes()) {
if (node instanceof Place) {
Place place = (Place) node;
if (place.getName().equals(target.getName()) {
arc1.setTarget(place);
arc2.setTarget(place);
}
}
}
}
}
// Créer le nouveau xmi (modèle convertit)
URI convURI = URI.createURI("models/Developpement_petrinet.xmi");
Resource conv = resSet.createResource(convURI);
// Ajouter le Network dans le nouveau modèle
conv.getContents().add(network);
// Sauver la ressource
try {
conv.save(Collections.EMPTY_MAP);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,226 @@
package simplepdl.manip;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
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.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import petrinet.Arc;
import petrinet.Network;
import petrinet.Node;
import petrinet.PetrinetFactory;
import petrinet.PetrinetPackage;
import petrinet.Place;
import petrinet.Transition;
import simplepdl.Process;
import simplepdl.SimplepdlPackage;
import simplepdl.WorkDefinition;
import simplepdl.WorkSequence;
import simplepdl.WorkSequenceType;
import simplepdl.Request;
public class simplepdl2petrinet {
public static void main(String[] args) {
// Charger les package SimplePDL et Petrinet afin de les enregistrer dans le registre d'Eclipse.
SimplepdlPackage packageInstance = SimplepdlPackage.eINSTANCE;
PetrinetPackage packageInstance2 = PetrinetPackage.eINSTANCE;
// Enregistrer l'extension ".xmi" comme devant être ouverte à
// l'aide d'un objet "XMIResourceFactoryImpl"
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("xmi", new XMIResourceFactoryImpl());
// Créer un objet resourceSetImpl qui contiendra une ressource EMF (le modèle)
ResourceSet resSet = new ResourceSetImpl();
// Charger la ressource (notre modèle)
URI modelURI = URI.createURI("test.xmi");
Resource resource = resSet.getResource(modelURI, true);
// Récupérer le premier élément du modèle (élément racine)
Process process = (Process) resource.getContents().get(0);
// La fabrique pour fabriquer les éléments de PetriNET
PetrinetFactory myFactory = PetrinetFactory.eINSTANCE;
// Créer un élément Network
Network network = myFactory.createNetwork();
network.setName(process.getName());
// Conversion des WorkDefinition en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof WorkDefinition) {
WorkDefinition wd = (WorkDefinition) o;
String name = wd.getName();
Place idle = myFactory.createPlace();
idle.setName(name + "_idle");
idle.setTokens(1);
Place started = myFactory.createPlace();
started.setName(name + "_started");
started.setTokens(0);
Place running = myFactory.createPlace();
running.setName(name + "_running");
running.setTokens(0);
Place finished = myFactory.createPlace();
finished.setName(name + "_finished");
finished.setTokens(0);
Arc pause2start = myFactory.createArc();
pause2start.setTarget(idle);
pause2start.setOutgoing(false);
pause2start.setWeight(1);
Arc start2running = myFactory.createArc();
start2running.setTarget(running);
start2running.setOutgoing(true);
start2running.setWeight(1);
Arc start2started = myFactory.createArc();
start2started.setTarget(started);
start2started.setOutgoing(true);
start2started.setWeight(1);
Transition start = myFactory.createTransition();
start.setName(name + "_start");
start.getArcs().add(pause2start);
start.getArcs().add(start2running);
start.getArcs().add(start2started);
Arc running2finish = myFactory.createArc();
running2finish.setTarget(running);
running2finish.setOutgoing(false);
running2finish.setWeight(1);
Arc finish2finished = myFactory.createArc();
finish2finished.setTarget(finished);
finish2finished.setOutgoing(true);
finish2finished.setWeight(1);
Transition finish = myFactory.createTransition();
finish.setName(name + "_finish");
finish.getArcs().add(running2finish);
finish.getArcs().add(finish2finished);
network.getNodes().add(idle);
network.getNodes().add(start);
network.getNodes().add(started);
network.getNodes().add(running);
network.getNodes().add(finish);
network.getNodes().add(finished);
}
}
// Conversion des WorkSequence en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof WorkSequence) {
WorkSequence ws = (WorkSequence) o;
WorkSequenceType type = ws.getLinkType();
WorkDefinition predecessor = ws.getPredecessor();
WorkDefinition successor = ws.getSuccessor();
// creation des suffixs permettant la recherche des noeuds
String predecessor_suffix = new String();
String successor_suffix = new String();
switch (type) {
case START_TO_START:
predecessor_suffix = "_started";
successor_suffix = "_start";
break;
case START_TO_FINISH:
predecessor_suffix = "_started";
successor_suffix = "_finished";
break;
case FINISH_TO_START:
predecessor_suffix = "_finished";
successor_suffix = "_start";
break;
case FINISH_TO_FINISH:
predecessor_suffix = "_finished";
successor_suffix = "_finish";
break;
default:
System.out.print("the fuck ?");
break;
}
// creation du read-arc
Arc arc1 = myFactory.createArc();
arc1.setOutgoing(false);
arc1.setWeight(1);
Arc arc2 = myFactory.createArc();
arc2.setOutgoing(true);
arc2.setWeight(1);
for (Node node : network.getNodes()) {
if (node instanceof Place) {
Place place = (Place) node;
if (place.getName().equals(predecessor.getName() + predecessor_suffix)) {
arc1.setTarget(place);
arc2.setTarget(place);
}
}
if (node instanceof Transition) {
Transition transition = (Transition) node;
if (transition.getName().equals(successor.getName() + successor_suffix)) {
transition.getArcs().add(arc1);
transition.getArcs().add(arc2);
}
}
}
}
}
// Conversion des Resource et Request en Node et Arcs
for (Object o : process.getProcessElements()) {
if (o instanceof simplepdl.Resource) {
simplepdl.Resource r = (simplepdl.Resource) o;
String name = r.getName();
int qty = r.getQuantity();
Place res = myFactory.createPlace();
res.setName(name);
res.setTokens(qty);
network.getNodes().add(res);
}
if (o instanceof simplepdl.Request) {
Request r = (Request) o;
simplepdl.Resource target = r.getTarget();
int qty = r.getQuantity();
Arc arc1 = myFactory.createArc();
arc1.setOutgoing(true);
arc1.setWeight(qty);
arc1.setTarget(target);
Arc arc2 = myFactory.createArc();
arc2.setOutgoing(false);
arc2.setWeight(qty);
}
}
// Créer le nouveau xmi (modèle convertit)
URI convURI = URI.createURI("models/Developpement_petrinet.xmi");
Resource conv = resSet.createResource(convURI);
// Ajouter le Network dans le nouveau modèle
conv.getContents().add(network);
// Sauver la ressource
try {
conv.save(Collections.EMPTY_MAP);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,6 @@
source.. = src/,\
src-gen/,\
xtend-gen/
bin.includes = META-INF/,\
.,\
plugin.xml

View file

@ -0,0 +1,6 @@
source.. = src/,\
src-gen/,\
xtend-gen/
bin.includes = META-INF/,\
.,\
plugin.xml

View file

@ -0,0 +1,218 @@
package simplepdl.manip;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
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.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import petrinet.Arc;
import petrinet.Network;
import petrinet.Node;
import petrinet.PetrinetFactory;
import petrinet.PetrinetPackage;
import petrinet.Place;
import petrinet.Transition;
import simplepdl.Process;
import simplepdl.SimplepdlPackage;
import simplepdl.WorkDefinition;
import simplepdl.WorkSequence;
import simplepdl.WorkSequenceType;
public class simplepdl2petrinet {
public static void main(String[] args) {
// Charger les package SimplePDL et Petrinet afin de les enregistrer dans le registre d'Eclipse.
SimplepdlPackage packageInstance = SimplepdlPackage.eINSTANCE;
PetrinetPackage packageInstance2 = PetrinetPackage.eINSTANCE;
// Enregistrer l'extension ".xmi" comme devant être ouverte à
// l'aide d'un objet "XMIResourceFactoryImpl"
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("xmi", new XMIResourceFactoryImpl());
// Créer un objet resourceSetImpl qui contiendra une ressource EMF (le modèle)
ResourceSet resSet = new ResourceSetImpl();
// Charger la ressource (notre modèle)
URI modelURI = URI.createURI("test.xmi");
Resource resource = resSet.getResource(modelURI, true);
// Récupérer le premier élément du modèle (élément racine)
Process process = (Process) resource.getContents().get(0);
// La fabrique pour fabriquer les éléments de PetriNET
PetrinetFactory myFactory = PetrinetFactory.eINSTANCE;
// Créer un élément Network
Network network = myFactory.createNetwork();
network.setName(process.getName());
// Conversion des WorkDefinition en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof WorkDefinition) {
WorkDefinition wd = (WorkDefinition) o;
String name = wd.getName();
Place idle = myFactory.createPlace();
idle.setName(name + "_idle");
idle.setTokens(1);
Place started = myFactory.createPlace();
started.setName(name + "_started");
started.setTokens(0);
Place running = myFactory.createPlace();
running.setName(name + "_running");
running.setTokens(0);
Place finished = myFactory.createPlace();
finished.setName(name + "_finished");
finished.setTokens(0);
Arc pause2start = myFactory.createArc();
pause2start.setTarget(idle);
pause2start.setOutgoing(false);
pause2start.setWeight(1);
Arc start2running = myFactory.createArc();
start2running.setTarget(running);
start2running.setOutgoing(true);
start2running.setWeight(1);
Arc start2started = myFactory.createArc();
start2started.setTarget(started);
start2started.setOutgoing(true);
start2started.setWeight(1);
Transition start = myFactory.createTransition();
start.setName(name + "_start");
start.getArcs().add(pause2start);
start.getArcs().add(start2running);
start.getArcs().add(start2started);
Arc running2finish = myFactory.createArc();
running2finish.setTarget(running);
running2finish.setOutgoing(false);
running2finish.setWeight(1);
Arc finish2finished = myFactory.createArc();
finish2finished.setTarget(finished);
finish2finished.setOutgoing(true);
finish2finished.setWeight(1);
Transition finish = myFactory.createTransition();
finish.setName(name + "_finish");
finish.getArcs().add(running2finish);
finish.getArcs().add(finish2finished);
network.getNodes().add(idle);
network.getNodes().add(start);
network.getNodes().add(started);
network.getNodes().add(running);
network.getNodes().add(finish);
network.getNodes().add(finished);
}
}
// Conversion des WorkSequence en Node et Transition
for (Object o : process.getProcessElements()) {
if (o instanceof WorkSequence) {
WorkSequence ws = (WorkSequence) o;
WorkSequenceType type = ws.getLinkType();
WorkDefinition predecessor = ws.getPredecessor();
WorkDefinition successor = ws.getSuccessor();
// creation des suffixs permettant la recherche des noeuds
String predecessor_suffix = new String();
String successor_suffix = new String();
switch (type) {
case START_TO_START:
predecessor_suffix = "_started";
successor_suffix = "_start";
break;
case START_TO_FINISH:
predecessor_suffix = "_started";
successor_suffix = "_finished";
break;
case FINISH_TO_START:
predecessor_suffix = "_finished";
successor_suffix = "_start";
break;
case FINISH_TO_FINISH:
predecessor_suffix = "_finished";
successor_suffix = "_finish";
break;
default:
System.out.print("the fuck ?");
break;
}
// creation du read-arc
Arc arc1 = myFactory.createArc();
arc1.setOutgoing(false);
arc1.setWeight(1);
Arc arc2 = myFactory.createArc();
arc2.setOutgoing(true);
arc2.setWeight(1);
for (Node node : network.getNodes()) {
if (node instanceof Place) {
Place place = (Place) node;
if (place.getName().equals(predecessor.getName() + predecessor_suffix)) {
arc1.setTarget(place);
arc2.setTarget(place);
}
}
if (node instanceof Transition) {
Transition transition = (Transition) node;
if (transition.getName().equals(successor.getName() + successor_suffix)) {
transition.getArcs().add(arc1);
transition.getArcs().add(arc2);
}
}
}
}
}
// Conversion des Resource et Request en Node et Arcs
for (Object o : process.getProcessElements()) {
if (o instanceof simplepdl.Resource) {
simplepdl.Resource r = (simplepdl.Resource) o;
String name = r.getName();
int qty = r.getQuantity();
Place res = myFactory.createPlace();
res.setName(name);
res.setTokens(qty);
}
if (o instanceof simplepdl.Request) {
simplepdl.Request r = (simplepdl.Request) o;
simplepdl.Resource target = r.getTarget();
int qty = r.getQuantity();
Place res = myFactory.createPlace();
res.setName(name);
res.setTokens(qty);
}
}
// Créer le nouveau xmi (modèle convertit)
URI convURI = URI.createURI("models/Developpement_petrinet.xmi");
Resource conv = resSet.createResource(convURI);
// Ajouter le Network dans le nouveau modèle
conv.getContents().add(network);
// Sauver la ressource
try {
conv.save(Collections.EMPTY_MAP);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,31 @@
grammar fr.n7.PDL1 with org.eclipse.xtext.common.Terminals
generate pDL1 "http://www.n7.fr/PDL1"
Process :
'process' ':' name=ID
processElements+=ProcessElement* ;
ProcessElement :
WorkDefinitionList | WorkSequence | Guidance;
WorkDefinitionList :
'workdefinitions' ':' WorkDefinitionList+=WorkDefinition* ;
WorkDefinition :
name=ID ";" ;
WorkSequence :
'ws' linkType=WorkSequenceType
'from' predecessor=[WorkDefinition]
'to' successor=[WorkDefinition] ;
Guidance :
'note' texte=STRING ;
enum WorkSequenceType :
start2start = 's2s'
| finish2start = 'f2s'
| start2finish = 's2f'
| finish2finish = 'f2f'
;

Some files were not shown because too many files have changed in this diff Show more