Merge lp:~tapaal-contributor/tapaal/shared-place-transition-rename-1871091 into lp:tapaal

Proposed by Peter Haahr Taankvist
Status: Merged
Approved by: Jiri Srba
Approved revision: 1047
Merged at revision: 1044
Proposed branch: lp:~tapaal-contributor/tapaal/shared-place-transition-rename-1871091
Merge into: lp:tapaal
Diff against target: 155 lines (+28/-46)
3 files modified
src/dk/aau/cs/gui/undo/MakePlaceNewSharedMultiCommand.java (+11/-21)
src/dk/aau/cs/gui/undo/MakeTransitionNewSharedMultiCommand.java (+11/-23)
src/dk/aau/cs/model/tapn/TimedArcPetriNet.java (+6/-2)
To merge this branch: bzr merge lp:~tapaal-contributor/tapaal/shared-place-transition-rename-1871091
Reviewer Review Type Date Requested Status
Kenneth Yrke Jørgensen code Needs Fixing
Jiri Srba Approve
Review via email: mp+382060@code.launchpad.net

Commit message

Sometimes we accidentally made new shared places, with the same name, in different components, instead of sharing the place across components. This should be fixed now.

To post a comment you must log in.
Revision history for this message
Jiri Srba (srba) wrote :

Tested and works fine also with undo/redo.

review: Approve
Revision history for this message
Kenneth Yrke Jørgensen (yrke) wrote :

Added some comments on the code control flow.

Also I don't like that the waySharedPlaces and SharedTransitions are copyed are different. However, the original code base is really bad, so lets not change this now.

I tested the changed on the testbranch, merges cleanly and seem to fix the problem.

review: Needs Fixing (code)
Revision history for this message
Kenneth Yrke Jørgensen (yrke) :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/dk/aau/cs/gui/undo/MakePlaceNewSharedMultiCommand.java'
2--- src/dk/aau/cs/gui/undo/MakePlaceNewSharedMultiCommand.java 2019-02-03 11:41:57 +0000
3+++ src/dk/aau/cs/gui/undo/MakePlaceNewSharedMultiCommand.java 2020-04-10 11:26:34 +0000
4@@ -35,17 +35,6 @@
5 public class MakePlaceNewSharedMultiCommand extends Command {
6
7 private final String newSharedName;
8- private final List<TimedArcPetriNet> tapns;
9- private Hashtable<TAPNQuery, TAPNQuery> newQueryToOldQueryMapping;
10- //private final List<TimedToken> oldTokens;
11- private final TabContent currentTab;
12- private SharedPlacesAndTransitionsPanel sharedPanel;
13- private ArrayList<SharedPlace> sharedPlaces;
14- private HashMap<TimedArcPetriNet, DataLayer> guiModels;
15- private String originalName;
16- private ArrayList<TimedPlace> timedPlaces = new ArrayList<TimedPlace>();
17- private NameGenerator nameGenerator;
18- private pipe.gui.undo.UndoManager undoManager;
19 private Context context;
20 private Place place;
21 private Command command;
22@@ -60,25 +49,26 @@
23
24 this.place = place;
25 this.context = context;
26- this.tapns = context.network().allTemplates();
27 this.newSharedName = newSharedName;
28- this.sharedPlaces = new ArrayList<SharedPlace>();
29- this.currentTab = context.tabContent();
30- this.sharedPanel = currentTab.getSharedPlacesAndTransitionsPanel();
31- guiModels = context.tabContent().getGuiModels();
32- this.originalName = originalName;
33- undoManager = currentTab.drawingSurface().getUndoManager();
34- //oldTokens = place.tokens();
35- newQueryToOldQueryMapping = new Hashtable<TAPNQuery, TAPNQuery>();
36 }
37
38 @Override
39 public void redo() {
40+ SharedPlace sharedPlace = null;
41+ int i = 0;
42 for(Template template : context.tabContent().allTemplates()) {
43 TimedPlaceComponent component = (TimedPlaceComponent)template.guiModel().getPlaceByName(place.getName());
44- if(component != null) {
45+ //We make a new shared place with the first place
46+ if(component != null && i < 1) {
47 command = new MakePlaceNewSharedCommand(template.model(), newSharedName, component.underlyingPlace(), component, context.tabContent(), true);
48 command.redo();
49+ sharedPlace = (SharedPlace)component.underlyingPlace();
50+ commands.add(command);
51+ i++;
52+ //For the rest we make them shared with the recently made place
53+ } else if (component != null && i >= 1){
54+ command = new MakePlaceSharedCommand(context.activeModel(), sharedPlace, component.underlyingPlace(), component, context.tabContent());
55+ command.redo();
56 commands.add(command);
57 }
58 }
59
60=== modified file 'src/dk/aau/cs/gui/undo/MakeTransitionNewSharedMultiCommand.java'
61--- src/dk/aau/cs/gui/undo/MakeTransitionNewSharedMultiCommand.java 2019-02-03 11:41:57 +0000
62+++ src/dk/aau/cs/gui/undo/MakeTransitionNewSharedMultiCommand.java 2020-04-10 11:26:34 +0000
63@@ -11,17 +11,13 @@
64 import pipe.dataLayer.Template;
65 import pipe.gui.CreateGui;
66 import pipe.gui.GuiFrame;
67-import pipe.gui.graphicElements.Place;
68 import pipe.gui.graphicElements.Transition;
69-import pipe.gui.graphicElements.tapn.TimedPlaceComponent;
70 import pipe.gui.graphicElements.tapn.TimedTransitionComponent;
71 import dk.aau.cs.TCTL.visitors.BooleanResult;
72-import dk.aau.cs.TCTL.visitors.MakePlaceSharedVisitor;
73 import dk.aau.cs.gui.Context;
74 import dk.aau.cs.gui.NameGenerator;
75 import dk.aau.cs.gui.SharedPlacesAndTransitionsPanel;
76 import dk.aau.cs.gui.TabContent;
77-import dk.aau.cs.model.tapn.LocalTimedPlace;
78 import dk.aau.cs.model.tapn.SharedPlace;
79 import dk.aau.cs.model.tapn.SharedTransition;
80 import dk.aau.cs.model.tapn.TimedArcPetriNet;
81@@ -35,17 +31,6 @@
82
83 public class MakeTransitionNewSharedMultiCommand extends Command {
84 private final String newSharedName;
85- private final List<TimedArcPetriNet> tapns;
86- private Hashtable<TAPNQuery, TAPNQuery> newQueryToOldQueryMapping;
87- //private final List<TimedToken> oldTokens;
88- private final TabContent currentTab;
89- private SharedPlacesAndTransitionsPanel sharedPanel;
90- private ArrayList<SharedPlace> sharedPlaces;
91- private HashMap<TimedArcPetriNet, DataLayer> guiModels;
92- private String originalName;
93- private ArrayList<TimedPlace> timedPlaces = new ArrayList<TimedPlace>();
94- private NameGenerator nameGenerator;
95- private pipe.gui.undo.UndoManager undoManager;
96 private Context context;
97 private Transition transition;
98 private Command command;
99@@ -60,23 +45,26 @@
100
101 this.transition = transition;
102 this.context = context;
103- this.tapns = context.network().allTemplates();
104 this.newSharedName = newSharedName;
105- this.currentTab = context.tabContent();
106- this.sharedPanel = currentTab.getSharedPlacesAndTransitionsPanel();
107- guiModels = context.tabContent().getGuiModels();
108- undoManager = currentTab.drawingSurface().getUndoManager();
109- //oldTokens = place.tokens();
110- newQueryToOldQueryMapping = new Hashtable<TAPNQuery, TAPNQuery>();
111 }
112
113 @Override
114 public void redo() {
115+ SharedTransition sharedTransition = null;
116+ int i = 0;
117 for(Template template : context.tabContent().allTemplates()) {
118 TimedTransitionComponent component = (TimedTransitionComponent)template.guiModel().getTransitionByName(transition.getName());
119- if(component != null) {
120+ //We make a new shared transition with the first transition
121+ if(component != null && i < 1) {
122 command = new MakeTransitionNewSharedCommand(template.model(), newSharedName, component.underlyingTransition(), context.tabContent(), true);
123 command.redo();
124+ sharedTransition = component.underlyingTransition().sharedTransition();
125+ commands.add(command);
126+ i++;
127+ //For the rest we make them shared with the recently made transition
128+ } else if (component != null && i >= 1){
129+ command = new MakeTransitionSharedCommand(context.activeModel(), sharedTransition, component.underlyingTransition(), context.tabContent());
130+ command.redo();
131 commands.add(command);
132 }
133 }
134
135=== modified file 'src/dk/aau/cs/model/tapn/TimedArcPetriNet.java'
136--- src/dk/aau/cs/model/tapn/TimedArcPetriNet.java 2019-03-14 19:41:23 +0000
137+++ src/dk/aau/cs/model/tapn/TimedArcPetriNet.java 2020-04-10 11:26:34 +0000
138@@ -287,11 +287,15 @@
139 for(TimedPlace p : places) {
140 TimedPlace copy = p.copy();
141 tapn.add(copy);
142- if(!p.isShared()){
143- for(int i = 0; i < p.numberOfTokens(); i++) {
144+ if(!p.isShared()) {
145+ for (int i = 0; i < p.numberOfTokens(); i++) {
146 tapn.addToken(new TimedToken(copy));
147 }
148 }
149+ if(p.isShared()){
150+ tapn.remove(copy);
151+ tapn.add(p);
152+ }
153 }
154
155 for(TimedTransition t : transitions){

Subscribers

People subscribed via source and target branches