TP8 partiel
This commit is contained in:
parent
de42fac315
commit
04f9e68e7b
|
@ -112,3 +112,36 @@ org.eclipse.swt.SWTException: Graphic is disposed
|
|||
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-13 09:49:41.985
|
||||
!MESSAGE InterruptedException
|
||||
!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)
|
||||
|
|
|
@ -10,18 +10,19 @@ 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 petrinet.Arc;
|
||||
import petrinet.Network;
|
||||
import petrinet.PetrinetFactory;
|
||||
import simplepdl.Process;
|
||||
import simplepdl.SimplepdlPackage;
|
||||
import simplepdl.WorkDefinition;
|
||||
import simplepdl.WorkSequence;
|
||||
import simplepdl.WorkSequenceType;
|
||||
import simplepdl.SimplepdlFactory;
|
||||
import simplepdl.SimplepdlPackage;
|
||||
import simplepdl.Request;
|
||||
|
||||
public class simplepdl2petrinet {
|
||||
|
||||
|
@ -41,13 +42,9 @@ public class simplepdl2petrinet {
|
|||
ResourceSet resSet = new ResourceSetImpl();
|
||||
|
||||
// Charger la ressource (notre modèle)
|
||||
URI modelURI = URI.createURI("pdl-sujet.xmi");
|
||||
URI modelURI = URI.createURI("test.xmi");
|
||||
Resource resource = resSet.getResource(modelURI, true);
|
||||
|
||||
// Créer la ressource (modèle convertit)
|
||||
URI convURI = URI.createURI("test.xmi");
|
||||
Resource conv = resSet.createResource(convURI);
|
||||
|
||||
// Récupérer le premier élément du modèle (élément racine)
|
||||
Process process = (Process) resource.getContents().get(0);
|
||||
|
||||
|
@ -58,22 +55,40 @@ public class simplepdl2petrinet {
|
|||
Network network = myFactory.createNetwork();
|
||||
network.setName(process.getName());
|
||||
|
||||
// Conversion des Resource en Places
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
// Conversion des WorkDefinition en Node et Transition
|
||||
for (Object o : process.getProcessElements()) {
|
||||
if (o instanceof WorkDefinition) {
|
||||
WorkDefinition wd = (WorkDefinition) o;
|
||||
String name = wd.getName();
|
||||
System.out.println(" - " + name);
|
||||
|
||||
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(1);
|
||||
running.setTokens(0);
|
||||
Place finished = myFactory.createPlace();
|
||||
finished.setName(name + "_finished");
|
||||
finished.setTokens(1);
|
||||
finished.setTokens(0);
|
||||
|
||||
Arc pause2start = myFactory.createArc();
|
||||
pause2start.setTarget(idle);
|
||||
|
@ -83,10 +98,15 @@ public class simplepdl2petrinet {
|
|||
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);
|
||||
|
@ -103,11 +123,85 @@ public class simplepdl2petrinet {
|
|||
|
||||
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 Requests s'il y en a
|
||||
for (Request req : wd.getRequests()) {
|
||||
System.out.println(req.getTarget());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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 {
|
|
@ -0,0 +1,237 @@
|
|||
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 Resource en Places
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
// 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 Requests s'il y en a
|
||||
for (Request req : wd.getRequests()) {
|
||||
|
||||
int qty = req.getQuantity();
|
||||
Place target = null;
|
||||
|
||||
for (Node node : network.getNodes()) {
|
||||
if (node instanceof Place) {
|
||||
Place place = (Place) node;
|
||||
if (place.getName().equals(req.getTarget().getName())) {
|
||||
target = place;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Arc res2start = myFactory.createArc();
|
||||
res2start.setTarget(target);
|
||||
res2start.setOutgoing(true);
|
||||
res2start.setWeight(qty);
|
||||
Arc finish2res = myFactory.createArc();
|
||||
finish2res.setTarget(target);
|
||||
finish2res.setOutgoing(false);
|
||||
finish2res.setWeight(qty);
|
||||
|
||||
start.getArcs().add(res2start);
|
||||
finish.getArcs().add(finish2res);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,129 +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.Place;
|
||||
import petrinet.Transition;
|
||||
import petrinet.Arc;
|
||||
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());
|
||||
|
||||
// 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 running = myFactory.createPlace();
|
||||
running.setName(name + "_running");
|
||||
running.setTokens(1);
|
||||
Place finished = myFactory.createPlace();
|
||||
finished.setName(name + "_finished");
|
||||
finished.setTokens(1);
|
||||
|
||||
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);
|
||||
Transition start = myFactory.createTransition();
|
||||
start.setName(name + "_start");
|
||||
start.getArcs().add(pause2start)
|
||||
start.getArcs().add(start2running);
|
||||
|
||||
Transition finish = myFactory.createTransition();
|
||||
finish.setName(name + "_finish");
|
||||
}
|
||||
}
|
||||
//
|
||||
// // 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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,242 @@
|
|||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (Node node : network.getNodes()) {
|
||||
if (node instanceof Transition) {
|
||||
Transition t = (Transition) node;
|
||||
if (t.getName().equals() {
|
||||
tran
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// 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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
<?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"/>
|
||||
<requests
|
||||
quantity="5"
|
||||
target="//@processElements.9"/>
|
||||
</processElements>
|
||||
<processElements
|
||||
xsi:type="simplepdl:WorkDefinition"
|
||||
linksToPredecessors="//@processElements.4"
|
||||
linksToSuccessors="//@processElements.5"
|
||||
name="Programmation">
|
||||
<requests
|
||||
quantity="15"
|
||||
target="//@processElements.10"/>
|
||||
<requests
|
||||
quantity="5"
|
||||
target="//@processElements.9"/>
|
||||
</processElements>
|
||||
<processElements
|
||||
xsi:type="simplepdl:WorkDefinition"
|
||||
linksToPredecessors="//@processElements.5 //@processElements.6"
|
||||
name="RedactionTests">
|
||||
<requests
|
||||
quantity="15"
|
||||
target="//@processElements.10"/>
|
||||
<requests
|
||||
quantity="5"
|
||||
target="//@processElements.9"/>
|
||||
</processElements>
|
||||
<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>
|
|
@ -1,104 +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.Place;
|
||||
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());
|
||||
|
||||
// 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");
|
||||
}
|
||||
}
|
||||
//
|
||||
// // 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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,243 @@
|
|||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (Node node : network.getNodes()) {
|
||||
if (node instanceof Transition) {
|
||||
Transition t = (Transition) node;
|
||||
if (t.getName().equals() {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -10,18 +10,19 @@ 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 petrinet.Arc;
|
||||
import petrinet.Network;
|
||||
import petrinet.PetrinetFactory;
|
||||
import simplepdl.Process;
|
||||
import simplepdl.SimplepdlPackage;
|
||||
import simplepdl.WorkDefinition;
|
||||
import simplepdl.WorkSequence;
|
||||
import simplepdl.WorkSequenceType;
|
||||
import simplepdl.SimplepdlFactory;
|
||||
import simplepdl.SimplepdlPackage;
|
||||
import simplepdl.Request;
|
||||
|
||||
public class simplepdl2petrinet {
|
||||
|
||||
|
@ -41,13 +42,9 @@ public class simplepdl2petrinet {
|
|||
ResourceSet resSet = new ResourceSetImpl();
|
||||
|
||||
// Charger la ressource (notre modèle)
|
||||
URI modelURI = URI.createURI("pdl-sujet.xmi");
|
||||
URI modelURI = URI.createURI("test.xmi");
|
||||
Resource resource = resSet.getResource(modelURI, true);
|
||||
|
||||
// Créer la ressource (modèle convertit)
|
||||
URI convURI = URI.createURI("test.xmi");
|
||||
Resource conv = resSet.createResource(convURI);
|
||||
|
||||
// Récupérer le premier élément du modèle (élément racine)
|
||||
Process process = (Process) resource.getContents().get(0);
|
||||
|
||||
|
@ -58,6 +55,22 @@ public class simplepdl2petrinet {
|
|||
Network network = myFactory.createNetwork();
|
||||
network.setName(process.getName());
|
||||
|
||||
// Conversion des Resource en Places
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
// Conversion des WorkDefinition en Node et Transition
|
||||
for (Object o : process.getProcessElements()) {
|
||||
if (o instanceof WorkDefinition) {
|
||||
|
@ -67,12 +80,15 @@ public class simplepdl2petrinet {
|
|||
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(1);
|
||||
running.setTokens(0);
|
||||
Place finished = myFactory.createPlace();
|
||||
finished.setName(name + "_finished");
|
||||
finished.setTokens(1);
|
||||
finished.setTokens(0);
|
||||
|
||||
Arc pause2start = myFactory.createArc();
|
||||
pause2start.setTarget(idle);
|
||||
|
@ -82,10 +98,15 @@ public class simplepdl2petrinet {
|
|||
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);
|
||||
|
@ -102,11 +123,98 @@ public class simplepdl2petrinet {
|
|||
|
||||
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 Requests s'il y en a
|
||||
for (Request req : wd.getRequests()) {
|
||||
|
||||
Place target = null;
|
||||
for (Node node : network.getNodes()) {
|
||||
if (node instanceof Place) {
|
||||
Place place = (Place) node;
|
||||
if (place.getName().equals(req.getTarget().getName())) {
|
||||
target = place;
|
||||
}
|
||||
}
|
||||
}
|
||||
Arc res2start = myFactory.createArc();
|
||||
res2start.setTarget(target);
|
||||
res2start.setOutgoing(false);
|
||||
res2start.setWeight(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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 {
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:petrinet="http://petrinet">
|
||||
<petrinet:Network name="Developpement"/>
|
||||
<petrinet:Place name="Conception_ready" tokens="1"/>
|
||||
<petrinet:Place name="Programmation_ready" tokens="1"/>
|
||||
<petrinet:Place name="RedactionTests_ready" tokens="1"/>
|
||||
<petrinet:Place name="RedactionDocs_ready" tokens="1"/>
|
||||
</xmi:XMI>
|
|
@ -1,145 +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.Place;
|
||||
import petrinet.Transition;
|
||||
import petrinet.Arc;
|
||||
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());
|
||||
|
||||
// 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 running = myFactory.createPlace();
|
||||
running.setName(name + "_running");
|
||||
running.setTokens(1);
|
||||
Place finished = myFactory.createPlace();
|
||||
finished.setName(name + "_finished");
|
||||
finished.setTokens(1);
|
||||
|
||||
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);
|
||||
Transition start = myFactory.createTransition();
|
||||
start.setName(name + "_start");
|
||||
start.getArcs().add(pause2start);
|
||||
start.getArcs().add(start2running);
|
||||
|
||||
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(running);
|
||||
network.getNodes().add(finish);
|
||||
network.getNodes().add(finished);
|
||||
}
|
||||
}
|
||||
//
|
||||
// // 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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:petrinet="http://petrinet">
|
||||
<petrinet:Network name="Developpement"/>
|
||||
<petrinet:Place name="Conception_ready" tokens="1"/>
|
||||
<petrinet:Place name="Programmation_ready" tokens="1"/>
|
||||
<petrinet:Place name="RedactionTests_ready" tokens="1"/>
|
||||
<petrinet:Place name="RedactionDocs_ready" tokens="1"/>
|
||||
</xmi:XMI>
|
|
@ -1,115 +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.Place;
|
||||
import petrinet.Transition;
|
||||
import petrinet.Arc;
|
||||
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("model/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 running = myFactory.createPlace();
|
||||
running.setName(name + "_running");
|
||||
running.setTokens(1);
|
||||
Place finished = myFactory.createPlace();
|
||||
finished.setName(name + "_finished");
|
||||
finished.setTokens(1);
|
||||
|
||||
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);
|
||||
Transition start = myFactory.createTransition();
|
||||
start.setName(name + "_start");
|
||||
start.getArcs().add(pause2start);
|
||||
start.getArcs().add(start2running);
|
||||
|
||||
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(running);
|
||||
network.getNodes().add(finish);
|
||||
network.getNodes().add(finished);
|
||||
}
|
||||
}
|
||||
|
||||
// Sauver la ressource
|
||||
try {
|
||||
resource.save(Collections.EMPTY_MAP);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -10,18 +10,19 @@ 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 petrinet.Arc;
|
||||
import petrinet.Network;
|
||||
import petrinet.PetrinetFactory;
|
||||
import simplepdl.Process;
|
||||
import simplepdl.SimplepdlPackage;
|
||||
import simplepdl.WorkDefinition;
|
||||
import simplepdl.WorkSequence;
|
||||
import simplepdl.WorkSequenceType;
|
||||
import simplepdl.SimplepdlFactory;
|
||||
import simplepdl.SimplepdlPackage;
|
||||
import simplepdl.Request;
|
||||
|
||||
public class simplepdl2petrinet {
|
||||
|
||||
|
@ -41,7 +42,7 @@ public class simplepdl2petrinet {
|
|||
ResourceSet resSet = new ResourceSetImpl();
|
||||
|
||||
// Charger la ressource (notre modèle)
|
||||
URI modelURI = URI.createURI("pdl-sujet.xmi");
|
||||
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)
|
||||
|
@ -54,22 +55,40 @@ public class simplepdl2petrinet {
|
|||
Network network = myFactory.createNetwork();
|
||||
network.setName(process.getName());
|
||||
|
||||
// Conversion des Resource en Places
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
// Conversion des WorkDefinition en Node et Transition
|
||||
for (Object o : process.getProcessElements()) {
|
||||
if (o instanceof WorkDefinition) {
|
||||
WorkDefinition wd = (WorkDefinition) o;
|
||||
String name = wd.getName();
|
||||
System.out.println(" - " + name);
|
||||
|
||||
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(1);
|
||||
running.setTokens(0);
|
||||
Place finished = myFactory.createPlace();
|
||||
finished.setName(name + "_finished");
|
||||
finished.setTokens(1);
|
||||
finished.setTokens(0);
|
||||
|
||||
Arc pause2start = myFactory.createArc();
|
||||
pause2start.setTarget(idle);
|
||||
|
@ -79,10 +98,15 @@ public class simplepdl2petrinet {
|
|||
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);
|
||||
|
@ -99,16 +123,84 @@ public class simplepdl2petrinet {
|
|||
|
||||
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 Requests s'il y en a
|
||||
System.out.println(wd.getRequests());
|
||||
}
|
||||
}
|
||||
|
||||
// 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("test.xmi");
|
||||
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);
|
|
@ -1,123 +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.Place;
|
||||
import petrinet.Transition;
|
||||
import petrinet.Arc;
|
||||
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());
|
||||
|
||||
// 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 running = myFactory.createPlace();
|
||||
running.setName(name + "_running");
|
||||
running.setTokens(1);
|
||||
Place finished = myFactory.createPlace();
|
||||
finished.setName(name + "_finished");
|
||||
finished.setTokens(1);
|
||||
|
||||
Arc pause2start = myFactory.createArc();
|
||||
pause2start.setTarget(idle);
|
||||
pause2start.setOutgoing(false);
|
||||
pause2start.setWeight(1);
|
||||
Transition start = myFactory.createTransition();
|
||||
start.setName(name + "_start");
|
||||
|
||||
Transition finish = myFactory.createTransition();
|
||||
finish.setName(name + "_finish");
|
||||
}
|
||||
}
|
||||
//
|
||||
// // 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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:petrinet="http://petrinet">
|
||||
<petrinet:Network name="Developpement"/>
|
||||
<petrinet:Place name="Conception_ready" tokens="1"/>
|
||||
<petrinet:Place name="Programmation_ready" tokens="1"/>
|
||||
<petrinet:Place name="RedactionTests_ready" tokens="1"/>
|
||||
<petrinet:Place name="RedactionDocs_ready" tokens="1"/>
|
||||
</xmi:XMI>
|
|
@ -10,18 +10,19 @@ 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 petrinet.Arc;
|
||||
import petrinet.Network;
|
||||
import petrinet.PetrinetFactory;
|
||||
import simplepdl.Process;
|
||||
import simplepdl.SimplepdlPackage;
|
||||
import simplepdl.WorkDefinition;
|
||||
import simplepdl.WorkSequence;
|
||||
import simplepdl.WorkSequenceType;
|
||||
import simplepdl.SimplepdlFactory;
|
||||
import simplepdl.SimplepdlPackage;
|
||||
import simplepdl.Request;
|
||||
|
||||
public class simplepdl2petrinet {
|
||||
|
||||
|
@ -38,11 +39,11 @@ public class simplepdl2petrinet {
|
|||
m.put("xmi", new XMIResourceFactoryImpl());
|
||||
|
||||
// Créer un objet resourceSetImpl qui contiendra une ressource EMF (le modèle)
|
||||
ResourceSet resGet = new ResourceSetImpl();
|
||||
ResourceSet resSet = new ResourceSetImpl();
|
||||
|
||||
// Charger la ressource (notre modèle)
|
||||
URI modelURI = URI.createURI("pdl-sujet.xmi");
|
||||
Resource resource = resGet.getResource(modelURI, true);
|
||||
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);
|
||||
|
@ -54,22 +55,40 @@ public class simplepdl2petrinet {
|
|||
Network network = myFactory.createNetwork();
|
||||
network.setName(process.getName());
|
||||
|
||||
// Conversion des Resource en Places
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
// Conversion des WorkDefinition en Node et Transition
|
||||
for (Object o : process.getProcessElements()) {
|
||||
if (o instanceof WorkDefinition) {
|
||||
WorkDefinition wd = (WorkDefinition) o;
|
||||
String name = wd.getName();
|
||||
System.out.println(" - " + name);
|
||||
|
||||
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(1);
|
||||
running.setTokens(0);
|
||||
Place finished = myFactory.createPlace();
|
||||
finished.setName(name + "_finished");
|
||||
finished.setTokens(1);
|
||||
finished.setTokens(0);
|
||||
|
||||
Arc pause2start = myFactory.createArc();
|
||||
pause2start.setTarget(idle);
|
||||
|
@ -79,10 +98,15 @@ public class simplepdl2petrinet {
|
|||
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);
|
||||
|
@ -97,23 +121,107 @@ public class simplepdl2petrinet {
|
|||
finish.getArcs().add(running2finish);
|
||||
finish.getArcs().add(finish2finished);
|
||||
|
||||
System.out.println(" + " + idle.getName());
|
||||
|
||||
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 Requests s'il y en a
|
||||
for (Request req : wd.getRequests()) {
|
||||
|
||||
int qty = req.getQuantity();
|
||||
Place target = null;
|
||||
|
||||
for (Node node : network.getNodes()) {
|
||||
if (node instanceof Place) {
|
||||
Place place = (Place) node;
|
||||
if (place.getName().equals(req.getTarget().getName())) {
|
||||
target = place;
|
||||
}
|
||||
}
|
||||
}
|
||||
Arc res2start = myFactory.createArc();
|
||||
res2start.setTarget(target);
|
||||
res2start.setOutgoing(true);
|
||||
res2start.setWeight(qty);
|
||||
Arc finish2res = myFactory.createArc();
|
||||
finish2res.setTarget(target);
|
||||
finish2res.setOutgoing(false);
|
||||
finish2res.setWeight(qty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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 un objet resourceSetImpl qui contiendra une ressource EMF (le modèle)
|
||||
ResourceSet resSet = new ResourceSetImpl();
|
||||
|
||||
// Créer le nouveau xmi (modèle convertit)
|
||||
URI convURI = URI.createURI("test.xmi");
|
||||
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);
|
|
@ -1,115 +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.Place;
|
||||
import petrinet.Transition;
|
||||
import petrinet.Arc;
|
||||
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());
|
||||
|
||||
// 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 running = myFactory.createPlace();
|
||||
running.setName(name + "_running");
|
||||
running.setTokens(1);
|
||||
Place finished = myFactory.createPlace();
|
||||
finished.setName(name + "_finished");
|
||||
finished.setTokens(1);
|
||||
|
||||
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);
|
||||
Transition start = myFactory.createTransition();
|
||||
start.setName(name + "_start");
|
||||
start.getArcs().add(pause2start);
|
||||
start.getArcs().add(start2running);
|
||||
|
||||
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(running);
|
||||
network.getNodes().add(finish);
|
||||
network.getNodes().add(finished);
|
||||
}
|
||||
}
|
||||
|
||||
// Sauver la ressource
|
||||
try {
|
||||
resource.save(Collections.EMPTY_MAP);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
module SimplePDL2PetriNet;
|
||||
create OUT: petrinet from IN: simplepdl;
|
||||
|
||||
-- Obtenir le processus qui contient ce process element.
|
||||
-- Remarque: Ce helper ne serait pas utile si une r<>f<EFBFBD>rence opposite
|
||||
-- avait <20>t<EFBFBD> plac<61>e entre Process et ProcessElement
|
||||
helper context simplepdl!ProcessElement
|
||||
def: getProcess(): simplepdl!Process =
|
||||
simplepdl!Process.allInstances()
|
||||
->select(p | p.processElements->includes(self))
|
||||
->asSequence()->first();
|
||||
|
||||
-- Traduire un Process en un PetriNet de m<>me nom
|
||||
rule Process2PetriNet {
|
||||
from p: simplepdl!Process
|
||||
to pn: petrinet!Network (name <- p.name)
|
||||
}
|
||||
|
||||
-- Traduire une WorkDefinition en un motif sur le r<>seau de Petri
|
||||
rule WorkDefinition2PetriNet {
|
||||
from wd: simplepdl!WorkDefinition
|
||||
to
|
||||
-- PLACES d'une WorkDefinition
|
||||
p_ready: petrinet!Place(
|
||||
name <- wd.name + '_ready',
|
||||
tokens <- 1,),
|
||||
}
|
|
@ -1,123 +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.Place;
|
||||
import petrinet.Transition;
|
||||
import petrinet.Arc;
|
||||
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 resGet = new ResourceSetImpl();
|
||||
|
||||
// Charger la ressource (notre modèle)
|
||||
URI modelURI = URI.createURI("pdl-sujet.xmi");
|
||||
Resource resource = resGet.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();
|
||||
System.out.println(" - " + name);
|
||||
|
||||
Place idle = myFactory.createPlace();
|
||||
idle.setName(name + "_idle");
|
||||
idle.setTokens(1);
|
||||
Place running = myFactory.createPlace();
|
||||
running.setName(name + "_running");
|
||||
running.setTokens(1);
|
||||
Place finished = myFactory.createPlace();
|
||||
finished.setName(name + "_finished");
|
||||
finished.setTokens(1);
|
||||
|
||||
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);
|
||||
Transition start = myFactory.createTransition();
|
||||
start.setName(name + "_start");
|
||||
start.getArcs().add(pause2start);
|
||||
start.getArcs().add(start2running);
|
||||
|
||||
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(running);
|
||||
network.getNodes().add(finish);
|
||||
network.getNodes().add(finished);
|
||||
}
|
||||
}
|
||||
|
||||
// Créer un objet resourceSetImpl qui contiendra une ressource EMF (le modèle)
|
||||
ResourceSet resSet = new ResourceSetImpl();
|
||||
|
||||
// Créer le nouveau xmi (modèle convertit)
|
||||
URI convURI = URI.createURI("test.xmi");
|
||||
Resource conv = resSet.createResource(convURI);
|
||||
|
||||
// Sauver la ressource
|
||||
try {
|
||||
conv.save(Collections.EMPTY_MAP);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
module SimplePDL2PetriNet;
|
||||
create OUT: petrinet from IN: simplepdl;
|
||||
|
||||
-- Obtenir le processus qui contient ce process element.
|
||||
-- Remarque: Ce helper ne serait pas utile si une r<>f<EFBFBD>rence opposite
|
||||
-- avait <20>t<EFBFBD> plac<61>e entre Process et ProcessElement
|
||||
helper context simplepdl!ProcessElement
|
||||
def: getProcess(): simplepdl!Process =
|
||||
simplepdl!Process.allInstances()
|
||||
->select(p | p.processElements->includes(self))
|
||||
->asSequence()->first();
|
||||
|
||||
-- Traduire un Process en un PetriNet de m<>me nom
|
||||
rule Process2PetriNet {
|
||||
from p: simplepdl!Process
|
||||
to pn: petrinet!Network (name <- p.name)
|
||||
}
|
||||
|
||||
-- Traduire une WorkDefinition en un motif sur le r<>seau de Petri
|
||||
rule WorkDefinition2PetriNet {
|
||||
from wd: simplepdl!WorkDefinition
|
||||
to
|
||||
-- PLACES d'une WorkDefinition
|
||||
p_ready: petrinet!Place(
|
||||
name <- wd.name + '_ready',
|
||||
marking <- 1,
|
||||
net <- wd.getProcess())
|
||||
}
|
|
@ -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>
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:petrinet="http://petrinet">
|
||||
<petrinet:Network name="Developpement"/>
|
||||
<petrinet:Place name="Conception_ready" tokens="1"/>
|
||||
<petrinet:Place name="Programmation_ready" tokens="1"/>
|
||||
<petrinet:Place name="RedactionTests_ready" tokens="1"/>
|
||||
<petrinet:Place name="RedactionDocs_ready" tokens="1"/>
|
||||
</xmi:XMI>
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:petrinet="http://petrinet">
|
||||
<petrinet:Network name="Developpement"/>
|
||||
<petrinet:Place name="Conception_ready" tokens="1"/>
|
||||
<petrinet:Place name="Programmation_ready" tokens="1"/>
|
||||
<petrinet:Place name="RedactionTests_ready" tokens="1"/>
|
||||
<petrinet:Place name="RedactionDocs_ready" tokens="1"/>
|
||||
</xmi:XMI>
|
|
@ -0,0 +1,243 @@
|
|||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (Node node : network.getNodes()) {
|
||||
if (node instanceof Transition) {
|
||||
Transition t = (Transition) node;
|
||||
if (t.getName().equals() {
|
||||
t.getArcs().add(arc1);
|
||||
t.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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
<?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">
|
||||
<requests
|
||||
quantity="2"
|
||||
target="//@processElements.9"/>
|
||||
</processElements>
|
||||
<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>
|
|
@ -1,95 +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());
|
||||
|
||||
// Conversion des WorkDefinition en Node et Transition
|
||||
|
||||
//
|
||||
// // 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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,119 +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.Place;
|
||||
import petrinet.Transition;
|
||||
import petrinet.Arc;
|
||||
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);
|
||||
|
||||
// Créer la ressource (modèle convertit)
|
||||
URI convURI = URI.createURI("test.xmi");
|
||||
Resource conv = resSet.getResource(convURI, 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 running = myFactory.createPlace();
|
||||
running.setName(name + "_running");
|
||||
running.setTokens(1);
|
||||
Place finished = myFactory.createPlace();
|
||||
finished.setName(name + "_finished");
|
||||
finished.setTokens(1);
|
||||
|
||||
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);
|
||||
Transition start = myFactory.createTransition();
|
||||
start.setName(name + "_start");
|
||||
start.getArcs().add(pause2start);
|
||||
start.getArcs().add(start2running);
|
||||
|
||||
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(running);
|
||||
network.getNodes().add(finish);
|
||||
network.getNodes().add(finished);
|
||||
}
|
||||
}
|
||||
|
||||
// Sauver la ressource
|
||||
try {
|
||||
conv.save(Collections.EMPTY_MAP);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:petrinet="http://petrinet">
|
||||
<petrinet:Network name="Developpement"/>
|
||||
<petrinet:Place name="Conception_ready" tokens="1"/>
|
||||
<petrinet:Place name="Programmation_ready" tokens="1"/>
|
||||
<petrinet:Place name="RedactionTests_ready" tokens="1"/>
|
||||
<petrinet:Place name="RedactionDocs_ready" tokens="1"/>
|
||||
</xmi:XMI>
|
|
@ -1,119 +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.Place;
|
||||
import petrinet.Transition;
|
||||
import petrinet.Arc;
|
||||
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);
|
||||
|
||||
// Créer la ressource (modèle convertit)
|
||||
URI convURI = URI.createURI("test.xmi");
|
||||
Resource conv = resSet.getResource(convURI, 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 running = myFactory.createPlace();
|
||||
running.setName(name + "_running");
|
||||
running.setTokens(1);
|
||||
Place finished = myFactory.createPlace();
|
||||
finished.setName(name + "_finished");
|
||||
finished.setTokens(1);
|
||||
|
||||
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);
|
||||
Transition start = myFactory.createTransition();
|
||||
start.setName(name + "_start");
|
||||
start.getArcs().add(pause2start);
|
||||
start.getArcs().add(start2running);
|
||||
|
||||
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(running);
|
||||
network.getNodes().add(finish);
|
||||
network.getNodes().add(finished);
|
||||
}
|
||||
}
|
||||
|
||||
// Sauver la ressource
|
||||
try {
|
||||
resource.save(Collections.EMPTY_MAP);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:petrinet="http://petrinet">
|
||||
<petrinet:Network name="Developpement"/>
|
||||
<petrinet:Place name="Conception_ready" tokens="1"/>
|
||||
<petrinet:Place name="Programmation_ready" tokens="1"/>
|
||||
<petrinet:Place name="RedactionTests_ready" tokens="1"/>
|
||||
<petrinet:Place name="RedactionDocs_ready" tokens="1"/>
|
||||
</xmi:XMI>
|
|
@ -0,0 +1,27 @@
|
|||
module SimplePDL2PetriNet;
|
||||
create OUT: petrinet from IN: simplepdl;
|
||||
|
||||
-- Obtenir le processus qui contient ce process element.
|
||||
-- Remarque: Ce helper ne serait pas utile si une r<>f<EFBFBD>rence opposite
|
||||
-- avait <20>t<EFBFBD> plac<61>e entre Process et ProcessElement
|
||||
helper context simplepdl!ProcessElement
|
||||
def: getProcess(): simplepdl!Process =
|
||||
simplepdl!Process.allInstances()
|
||||
->select(p | p.processElements->includes(self))
|
||||
->asSequence()->first();
|
||||
|
||||
-- Traduire un Process en un PetriNet de m<>me nom
|
||||
rule Process2PetriNet {
|
||||
from p: simplepdl!Process
|
||||
to pn: petrinet!Network (name <- p.name)
|
||||
}
|
||||
|
||||
-- Traduire une WorkDefinition en un motif sur le r<>seau de Petri
|
||||
rule WorkDefinition2PetriNet {
|
||||
from wd: simplepdl!WorkDefinition
|
||||
to
|
||||
-- PLACES d'une WorkDefinition
|
||||
p_ready: petrinet!Place(
|
||||
name <- wd.name + '_ready',
|
||||
tokens <- 1,)
|
||||
}
|
|
@ -1,139 +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.Place;
|
||||
import petrinet.Transition;
|
||||
import petrinet.Arc;
|
||||
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());
|
||||
|
||||
// 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 running = myFactory.createPlace();
|
||||
running.setName(name + "_running");
|
||||
running.setTokens(1);
|
||||
Place finished = myFactory.createPlace();
|
||||
finished.setName(name + "_finished");
|
||||
finished.setTokens(1);
|
||||
|
||||
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);
|
||||
Transition start = myFactory.createTransition();
|
||||
start.setName(name + "_start");
|
||||
start.getArcs().add(pause2start);
|
||||
start.getArcs().add(start2running);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
//
|
||||
// // 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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,119 +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.Place;
|
||||
import petrinet.Transition;
|
||||
import petrinet.Arc;
|
||||
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);
|
||||
|
||||
// Créer la ressource (modèle convertit)
|
||||
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 running = myFactory.createPlace();
|
||||
running.setName(name + "_running");
|
||||
running.setTokens(1);
|
||||
Place finished = myFactory.createPlace();
|
||||
finished.setName(name + "_finished");
|
||||
finished.setTokens(1);
|
||||
|
||||
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);
|
||||
Transition start = myFactory.createTransition();
|
||||
start.setName(name + "_start");
|
||||
start.getArcs().add(pause2start);
|
||||
start.getArcs().add(start2running);
|
||||
|
||||
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(running);
|
||||
network.getNodes().add(finish);
|
||||
network.getNodes().add(finished);
|
||||
}
|
||||
}
|
||||
|
||||
// Sauver la ressource
|
||||
try {
|
||||
resource.save(Collections.EMPTY_MAP);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,115 +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.Place;
|
||||
import petrinet.Transition;
|
||||
import petrinet.Arc;
|
||||
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());
|
||||
|
||||
// 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 running = myFactory.createPlace();
|
||||
running.setName(name + "_running");
|
||||
running.setTokens(1);
|
||||
Place finished = myFactory.createPlace();
|
||||
finished.setName(name + "_finished");
|
||||
finished.setTokens(1);
|
||||
|
||||
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);
|
||||
Transition start = myFactory.createTransition();
|
||||
start.setName(name + "_start");
|
||||
start.getArcs().add(pause2start);
|
||||
start.getArcs().add(start2running);
|
||||
|
||||
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(running);
|
||||
network.getNodes().add(finish);
|
||||
network.getNodes().add(finished);
|
||||
}
|
||||
}
|
||||
|
||||
// Sauver la ressource
|
||||
try {
|
||||
resource.save(Collections.EMPTY_MAP);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,244 @@
|
|||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (Node node : network.getNodes()) {
|
||||
if (node instanceof Transition) {
|
||||
Transition t = (Transition) node;
|
||||
if (t.getName().equals(name + "_start")) {
|
||||
t.getArcs().add(arc1);
|
||||
}
|
||||
else if (t.getName().equals(name + "_finish"))
|
||||
t.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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue