~tapaal-contributor/tapaal/query-export-bug-1767615

« back to all changes in this revision

Viewing changes to src/dk/aau/cs/gui/TabTransformer.java

merged in branch timed-to-untimed-fix-1625989 additing new tool for untiming a net

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package dk.aau.cs.gui;
 
2
 
 
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;
 
10
 
 
11
import java.util.ArrayList;
 
12
 
 
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);
 
20
            }
 
21
            // Make transitions non-urgent
 
22
            for(TimedTransition transition : template.model().transitions()){
 
23
                transition.setUrgent(false);
 
24
            }
 
25
 
 
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());
 
31
                }
 
32
 
 
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);
 
37
                }
 
38
            }
 
39
 
 
40
            // Replace transport arcs with regular arcs
 
41
            for(TimedTransportArcComponent arc : transportArcComponents){
 
42
                // Input arc
 
43
                if(arc.getSource() instanceof Place) {
 
44
                    TimedPlace source = template.model().getPlaceByName(arc.getSource().getName());
 
45
                    TimedTransition destination = template.model().getTransitionByName(arc.getTarget().getName());
 
46
 
 
47
                    TimedInputArc addedArc = new TimedInputArc(source, destination, TimeInterval.ZERO_INF, arc.getWeight());
 
48
                    template.model().add(addedArc);
 
49
 
 
50
                    // GUI
 
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(
 
55
                            0d,
 
56
                            0d,
 
57
                            0d,
 
58
                            0d,
 
59
                            guiSource,
 
60
                            guiTarget,
 
61
                            arc.getWeight().value(),
 
62
                            arc.getSource().getName() + "_to_" + arc.getTarget().getName(),
 
63
                            false
 
64
                    ));
 
65
 
 
66
                    // Build ArcPath
 
67
                    Place oldGuiSource = guiModel.getPlaceByName(arc.getSource().getName());
 
68
                    Transition oldGuiTarget = guiModel.getTransitionByName(arc.getTarget().getName());
 
69
                    ArcPath newArcPath = createArcPath(guiModel, oldGuiSource, oldGuiTarget, newArc);
 
70
 
 
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);
 
79
 
 
80
                }
 
81
                // Output arc
 
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());
 
85
 
 
86
                    TimedOutputArc addedArc = new TimedOutputArc(source, destination, arc.getWeight());
 
87
                    template.model().add(addedArc);
 
88
 
 
89
                    // GUI
 
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(
 
94
                            0d,
 
95
                            0d,
 
96
                            0d,
 
97
                            0d,
 
98
                            guiSource,
 
99
                            guiTarget,
 
100
                            arc.getWeight().value(),
 
101
                            arc.getSource().getName() + "_to_" + arc.getTarget().getName(),
 
102
                            false
 
103
                    );
 
104
 
 
105
                    // Build ArcPath
 
106
                    Place oldGuiTarget = guiModel.getPlaceByName(arc.getTarget().getName());
 
107
                    Transition oldGuiSource = guiModel.getTransitionByName(arc.getSource().getName());
 
108
                    ArcPath newArcPath = createArcPath(guiModel, oldGuiSource, oldGuiTarget, newArc);
 
109
 
 
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);
 
118
 
 
119
                    // Delete the transport arc
 
120
                    arc.delete();
 
121
                }
 
122
            }
 
123
        }
 
124
    }
 
125
 
 
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();
 
130
 
 
131
        // Build ArcPath
 
132
        ArcPath newArcPath = new ArcPath(arc);
 
133
        for(int k = 0; k < arcPathPointsNum; k++) {
 
134
            ArcPathPoint point = arcPath.getArcPathPoint(k);
 
135
            newArcPath.addPoint(
 
136
                    point.getPoint().x,
 
137
                    point.getPoint().y,
 
138
                    point.getPointType()
 
139
            );
 
140
        }
 
141
 
 
142
        return newArcPath;
 
143
    }
 
144
}