3
import dk.aau.cs.model.tapn.*;
4
import pipe.dataLayer.DataLayer;
5
import pipe.dataLayer.Template;
6
import pipe.gui.graphicElements.*;
7
import pipe.gui.graphicElements.tapn.TimedInputArcComponent;
8
import pipe.gui.graphicElements.tapn.TimedOutputArcComponent;
9
import pipe.gui.graphicElements.tapn.TimedTransportArcComponent;
11
import java.util.ArrayList;
13
public class TabTransformer {
14
static public void removeTimingInformation(TabContent tab){
15
for(Template template : tab.allTemplates()){
16
ArrayList<TimedTransportArcComponent> transportArcComponents = new ArrayList<TimedTransportArcComponent>();
17
// Make place token age invariant infinite
18
for(TimedPlace place : template.model().places()){
19
place.setInvariant(TimeInvariant.LESS_THAN_INFINITY);
21
// Make transitions non-urgent
22
for(TimedTransition transition : template.model().transitions()){
23
transition.setUrgent(false);
26
for(Arc arc : template.guiModel().getArcs()){
27
// Make output arc guards infinite
28
if(arc instanceof TimedOutputArcComponent) {
29
TimedOutputArcComponent arcComp = (TimedOutputArcComponent) arc;
30
arcComp.setGuardAndWeight(TimeInterval.ZERO_INF, arcComp.getWeight());
33
// Add and process transport arcs in separate list to avoid delete errors
34
if(arc instanceof TimedTransportArcComponent){
35
TimedTransportArcComponent arcComp = (TimedTransportArcComponent) arc;
36
transportArcComponents.add(arcComp);
40
// Replace transport arcs with regular arcs
41
for(TimedTransportArcComponent arc : transportArcComponents){
43
if(arc.getSource() instanceof Place) {
44
TimedPlace source = template.model().getPlaceByName(arc.getSource().getName());
45
TimedTransition destination = template.model().getTransitionByName(arc.getTarget().getName());
47
TimedInputArc addedArc = new TimedInputArc(source, destination, TimeInterval.ZERO_INF, arc.getWeight());
48
template.model().add(addedArc);
51
DataLayer guiModel = template.guiModel();
52
Place guiSource = guiModel.getPlaceByName(arc.getSource().getName());
53
Transition guiTarget = guiModel.getTransitionByName(arc.getTarget().getName());
54
Arc newArc = new TimedInputArcComponent(new TimedOutputArcComponent(
61
arc.getWeight().value(),
62
arc.getSource().getName() + "_to_" + arc.getTarget().getName(),
67
Place oldGuiSource = guiModel.getPlaceByName(arc.getSource().getName());
68
Transition oldGuiTarget = guiModel.getTransitionByName(arc.getTarget().getName());
69
ArcPath newArcPath = createArcPath(guiModel, oldGuiSource, oldGuiTarget, newArc);
71
// Set arcPath, guiModel and connectors
72
((TimedInputArcComponent) newArc).setUnderlyingArc(addedArc);
73
newArc.setArcPath(newArcPath);
74
newArc.setGuiModel(guiModel);
75
newArc.updateArcPosition();
76
guiModel.addPetriNetObject(newArc);
77
guiSource.addConnectFrom(newArc);
78
guiTarget.addConnectTo(newArc);
82
else if(arc.getSource() instanceof Transition){
83
TimedPlace destination = template.model().getPlaceByName(arc.getTarget().getName());
84
TimedTransition source = template.model().getTransitionByName(arc.getSource().getName());
86
TimedOutputArc addedArc = new TimedOutputArc(source, destination, arc.getWeight());
87
template.model().add(addedArc);
90
DataLayer guiModel = template.guiModel();
91
Place guiTarget = guiModel.getPlaceByName(arc.getTarget().getName());
92
Transition guiSource = guiModel.getTransitionByName(arc.getSource().getName());
93
Arc newArc = new TimedOutputArcComponent(
100
arc.getWeight().value(),
101
arc.getSource().getName() + "_to_" + arc.getTarget().getName(),
106
Place oldGuiTarget = guiModel.getPlaceByName(arc.getTarget().getName());
107
Transition oldGuiSource = guiModel.getTransitionByName(arc.getSource().getName());
108
ArcPath newArcPath = createArcPath(guiModel, oldGuiSource, oldGuiTarget, newArc);
110
// Set arcPath, guiModel and connectors
111
((TimedOutputArcComponent) newArc).setUnderlyingArc(addedArc);
112
newArc.setArcPath(newArcPath);
113
newArc.setGuiModel(guiModel);
114
newArc.updateArcPosition();
115
guiModel.addPetriNetObject(newArc);
116
guiSource.addConnectFrom(newArc);
117
guiTarget.addConnectTo(newArc);
119
// Delete the transport arc
126
private static ArcPath createArcPath(DataLayer currentGuiModel, PlaceTransitionObject source, PlaceTransitionObject target, Arc arc) {
127
Arc guiArc = currentGuiModel.getArcByEndpoints(source, target);
128
ArcPath arcPath = guiArc.getArcPath();
129
int arcPathPointsNum = arcPath.getNumPoints();
132
ArcPath newArcPath = new ArcPath(arc);
133
for(int k = 0; k < arcPathPointsNum; k++) {
134
ArcPathPoint point = arcPath.getArcPathPoint(k);