Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues when using manual edit with color types - fix 2081345 #179

Merged
merged 13 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.gradle
.idea
.vscode
.r
.bzr-repo
build
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dk/aau/cs/model/CPN/ColorType.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public boolean contains(Color color){
}
return false;
}

public Color getColorByName(String name){
for (Color c : colors) {
if(c.getColorName().equals(name)){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,7 @@ private void isColorTypeUsedInVariable(ColorType colorType, List<String> message
}
}

public boolean canColorBeRemoved(Color color, ArrayList<String> messages) {
public boolean canColorBeRemoved(Color color, List<String> messages) {
isColorTypeUsedInProduct(color.getColorType(), messages);
for (TimedArcPetriNet tapn : allTemplates()) {
for (TimedPlace p : tapn.places()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public JComboBox[] getColorTypeComboBoxesArray() {
private void initPanel() {
colorcomboBoxPanel = new JPanel();
colorcomboBoxPanel.setLayout(new GridBagLayout());

//This panel contains all comboboxes, there can be more than one with ProductTypes
comboBoxPanel = new JPanel(new GridBagLayout());
//In case it is a really large product type we have a scrollPane
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,18 @@ package dk.aau.cs.model.CPN.ConstantsParser;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;

import dk.aau.cs.model.CPN.Color;
import dk.aau.cs.model.CPN.ColorType;
import dk.aau.cs.model.tapn.Constant;
import dk.aau.cs.model.tapn.TimedArcPetriNet;
import dk.aau.cs.model.CPN.Variable;
import dk.aau.cs.model.tapn.TimedArcPetriNetNetwork;
import dk.aau.cs.model.tapn.TimedPlace;
import dk.aau.cs.model.CPN.Expressions.ArcExpression;
import dk.aau.cs.model.tapn.TimedToken;
import dk.aau.cs.model.CPN.ColorMultiset;

import java.util.HashMap;
import java.util.Map;
import java.util.LinkedHashMap;
Expand Down Expand Up @@ -80,29 +88,86 @@ public class ConstantsParser {
for (Variable v : network.variables()) {
List<String> messagesList = new ArrayList<String>();
constantsMap.put(v.getName(), v);
boolean canBeEdited = !(variables.containsKey(v.getName()) && !variables.get(v.getName()).getColorType().equals(v.getColorType()));
boolean canBeEdited = true;
if (variables.containsKey(v.getName())) {
ColorType ct = variables.get(v.getName()).getColorType();
canBeEdited = ct.equals(v.getColorType()) || ct.isIntegerRange();
}

canBeRemovedBitMap.put(v.getName(), network.canVariableBeRemoved(v, messagesList) && canBeEdited);
messages.put(v.getName(), messagesList);
}

// Generate error messages
for (String key : canBeRemovedBitMap.keySet()) {
boolean skip = false;
if (constants.containsKey(key) ||
variables.containsKey(key) && canBeRemovedBitMap.get(key) ||
key.equals("dot") ||
colorTypes.containsKey(key) &&
colorTypes.get(key).equals(constantsMap.get(key))) {
key.equals("dot")) {
continue;
} else if (variables.containsKey(key) && !canBeRemovedBitMap.get(key)) {
boolean skip = false;
for (Variable v : network.variables()) {
if (v.getName().equals(key)) {
skip = v.getColorType().equals(variables.get(key).getColorType());
}
}
}

if (skip) continue;
if (skip) continue;
} else if (colorTypes.containsKey(key)) {
if (colorTypes.get(key).equals(constantsMap.get(key))) continue;

ColorType newCt = colorTypes.get(key);
ColorType ct = (ColorType)constantsMap.get(key);

if (!(ct instanceof ProductType)) {
List<Color> removedColors = new ArrayList<Color>();

for (Color color : ct.getColorList()) {
if (!newCt.contains(color)) {
removedColors.add(color);
}
}

int removeableColors = 0;
for (Color c : removedColors) {
List<String> newMessagesList = new ArrayList<String>();
boolean colorCanBeRemoved = network.canColorBeRemoved(c, newMessagesList);
if (colorCanBeRemoved) {
++removeableColors;
} else {
List<String> messagesList = messages.get(key);
messagesList.addAll(newMessagesList);
messages.put(key, messagesList);
}
}

// Update place color types
for (TimedArcPetriNet tapn : network.allTemplates()) {
for (TimedPlace p : tapn.places()) {
if (p.getColorType().equals(ct)) {
p.setColorType(newCt);
}

ArcExpression expression = p.getExprWithNewColorType(newCt);
if (expression != p.getTokensAsExpression()) {
ColorMultiset cm = expression.eval(network.getContext());
if (cm != null) {
List<TimedToken> tokensToAdd = new ArrayList<TimedToken>(p.tokens());
for (TimedToken token : cm.getTokens(p)) {
tapn.marking().remove(token);
}

p.updateTokens(tokensToAdd, expression);
}
}
}
}

if (removeableColors == removedColors.size()) {
continue;
}
}
}

Object obj = constantsMap.get(key);
if (!canBeRemovedBitMap.get(key)) {
Expand Down Expand Up @@ -276,7 +341,19 @@ void colorTypes() :
}

ct = pct;
} else if (!isProductList.value) {
} else if (isIntList.value) {
ct = new ColorType(id.image);
int lowerBound = Integer.parseInt(values.get(0));
int upperBound = Integer.parseInt(values.get(1));

if (lowerBound > upperBound) {
throw new ParseException("Lower bound must be lowr than or equal to upper bound");
}

for (int i = lowerBound; i <= upperBound; ++i) {
ct.addColor(Integer.toString(i));
}
} else {
ct = new ColorType(id.image);
Set<String> uniqueVals = new HashSet<String>();
for (String color : values) {
Expand Down
Loading