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

Change of range in product - fix 2037066 #115

Merged
merged 12 commits into from
Nov 11, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public abstract class GuardExpression extends Expression {

public ColorType getColorType() { return colorType; }

public void setColorType(ColorType colorType) { this.colorType = colorType; }

@Override
public abstract GuardExpression replace(Expression object1, Expression object2, boolean replaceAllInstances);

Expand Down
10 changes: 10 additions & 0 deletions src/main/java/dk/aau/cs/model/tapn/TimedArcPetriNetNetwork.java
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,16 @@ public Integer getVariableIndex(String name) {
return null;
}

public boolean doesSimilarRangeExist(ColorType newColorType) {
srba marked this conversation as resolved.
Show resolved Hide resolved
for (ColorType ct : colorTypes) {
if (ct.getColors().toString().equals(newColorType.getColors().toString()) && !ct.equals(newColorType)) {
srba marked this conversation as resolved.
Show resolved Hide resolved
return true;
}
}

return false;
}

public boolean isNameUsedForColorType(String name) {
for (ColorType element : colorTypes) {
if (element.getName().equals(name)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,7 @@ private void onOK() {
"Error", JOptionPane.ERROR_MESSAGE);
return;
}

try {
if (rangeOfIntegersPanelEnabled && (Integer.parseInt(lowerBoundTextField.getText()) > Integer.parseInt(upperBoundTextField.getText()))) {
JOptionPane.showMessageDialog(
Expand Down Expand Up @@ -1078,6 +1079,14 @@ private void onOK() {
newColorType.addColor(String.valueOf(i));
}

if (network.doesSimilarRangeExist(newColorType)) {
JOptionPane.showMessageDialog(
TAPAALGUI.getApp(),
"Color type with similar range already exists!",
srba marked this conversation as resolved.
Show resolved Hide resolved
"Error", JOptionPane.ERROR_MESSAGE);
return;
}

if (oldColorType != null) {
if (oldColorType.equals(newColorType)) {
exit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,19 @@ public void undo() {
}
}
for (TimedInputArc arc : tapn.inputArcs()) {
if (arc.getArcExpression() != null && arc.source().getColorType() == oldColorType)
if (arc.getArcExpression() != null) {
arc.setExpression(arc.getArcExpression().getExprWithNewColorType(oldColorType));
}
}
for (TimedOutputArc arc : tapn.outputArcs()) {
if (arc.getExpression() != null && arc.destination().getColorType() == oldColorType)
if (arc.getExpression() != null) {
arc.setExpression(arc.getExpression().getExprWithNewColorType(oldColorType));
}
}
for (TimedTransition transition : tapn.transitions()) {
if (transition.getGuard() != null) {
transition.getGuard().setColorType(oldColorType);
}
}
}

Expand Down Expand Up @@ -75,19 +82,27 @@ public void redo() {
}
}
for (TimedInputArc arc : tapn.inputArcs()) {
if (arc.getArcExpression() != null && arc.source().getColorType() == newColorType)
if (arc.getArcExpression() != null) {
arc.setExpression(arc.getArcExpression().getExprWithNewColorType(newColorType));
}
}
for (TimedOutputArc arc : tapn.outputArcs()) {
if (arc.getExpression() != null && arc.destination().getColorType() == newColorType)
if (arc.getExpression() != null) {
arc.setExpression(arc.getExpression().getExprWithNewColorType(newColorType));
}
}
for (TimedTransition transition : tapn.transitions()) {
if (transition.getGuard() != null) {
transition.getGuard().setColorType(newColorType);
}
}
}

eval(newColorType);

for (Variable var : network.variables()) {
if (var.getColorType().equals(oldColorType)) {
System.out.println();
srba marked this conversation as resolved.
Show resolved Hide resolved
var.setColorType(newColorType);
}
}
Expand Down