1
1
package pipe.gui.widgets;
3
3
import dk.aau.cs.gui.Context;
4
import dk.aau.cs.model.tapn.*;
4
5
import dk.aau.cs.model.tapn.Colored.*;
5
6
import dk.aau.cs.model.tapn.Colored.Color;
6
7
import dk.aau.cs.model.tapn.Colored.ExpressionSupport.ExprValues;
7
import dk.aau.cs.model.tapn.TimedInputArc;
8
import dk.aau.cs.model.tapn.TimedOutputArc;
9
import dk.aau.cs.model.tapn.TimedPlace;
10
import dk.aau.cs.model.tapn.TimedTransition;
12
9
import javax.swing.*;
13
import javax.swing.border.TitledBorder;
15
11
import java.awt.event.ActionEvent;
16
12
import java.awt.event.ActionListener;
23
19
List<ColoredInputArc> inputArcs = new ArrayList();
24
20
List<ColoredOutputArc> outputArcs = new ArrayList();
25
21
List<ColoredTransition> transitions = new ArrayList();
22
List<ColoredTransportArc> transportArcs = new ArrayList<ColoredTransportArc>();
26
23
List<TimedPlace> places = new ArrayList();
27
24
List<String> errorMsgs = new ArrayList<String>();
43
40
private void runTypeCheckingAnalysis() {
42
for (ColoredTransportArc transportArc : transportArcs) {
43
if (transportArc.getInputExpression() != null) {
44
getColorTypeMismatchErrors(transportArc.getInputExpression().getValues(new ExprValues()), "Transport arc from place " + transportArc.source().name() + " to transition " + transportArc.transition().name() );
47
if (transportArc.source() instanceof LocalColoredPlace)
48
ct = ((LocalColoredPlace) transportArc.source()).getColorType();
50
ct = ((SharedColoredPlace)transportArc.source()).getColorType();
52
getConnectedPlaceErrors(ct, transportArc.getInputExpression().getValues(new ExprValues()), "Transport arc from place " + transportArc.source().name() + " to transition " + transportArc.transition().name());
54
if (transportArc.getOutputExpression() != null) {
55
getColorTypeMismatchErrors(transportArc.getOutputExpression().getValues(new ExprValues()), "Transport arc from transition " + transportArc.transition().name() + " to place " + transportArc.destination().name());
58
if (transportArc.source() instanceof LocalColoredPlace)
59
ct = ((LocalColoredPlace) transportArc.source()).getColorType();
61
ct = ((SharedColoredPlace)transportArc.source()).getColorType();
63
getConnectedPlaceErrors(ct, transportArc.getOutputExpression().getValues(new ExprValues()), "Transport arc from place " + transportArc.source().name() + " to place " + transportArc.destination().name());
45
67
for (ColoredInputArc inputArc : inputArcs) {
46
68
if (inputArc.getArcExpression() != null) {
47
69
getColorTypeMismatchErrors(inputArc.getArcExpression().getValues(new ExprValues()), "Input arc from place " + inputArc.source().name() + " to transition " + inputArc.destination().name() );
48
getConnectedPlaceErrorsInput(inputArc, inputArc.getArcExpression().getValues(new ExprValues()), "Input arc from place " + inputArc.source().name() + " to transition " + inputArc.destination().name());
72
if (inputArc.source() instanceof LocalColoredPlace)
73
ct = ((LocalColoredPlace) inputArc.source()).getColorType();
75
ct = ((SharedColoredPlace)inputArc.source()).getColorType();
77
getConnectedPlaceErrors(ct, inputArc.getArcExpression().getValues(new ExprValues()), "Input arc from place " + inputArc.source().name() + " to transition " + inputArc.destination().name());
51
80
for (ColoredOutputArc outputArc : outputArcs) {
52
81
if (outputArc.getExpression() != null) {
53
82
getColorTypeMismatchErrors(outputArc.getExpression().getValues(new ExprValues()), "Output arc from transition " + outputArc.source().name() + " to place " + outputArc.destination().name());
54
getConnectedPlaceErrosOutput(outputArc, outputArc.getExpression().getValues(new ExprValues()), "outputArc from transition " + outputArc.source().name() + " to place " + outputArc.destination().name());
85
if (outputArc.destination() instanceof LocalColoredPlace)
86
ct = ((LocalColoredPlace) outputArc.destination()).getColorType();
88
ct = ((SharedColoredPlace)outputArc.destination()).getColorType();
90
getConnectedPlaceErrors(ct, outputArc.getExpression().getValues(new ExprValues()), "outputArc from transition " + outputArc.source().name() + " to place " + outputArc.destination().name());
66
private void getConnectedPlaceErrosOutput(ColoredOutputArc outputArc, ExprValues exprValues, String identifier) {
68
if (outputArc.destination() instanceof LocalColoredPlace)
69
colorType = ((LocalColoredPlace)outputArc.destination()).getColorType();
71
colorType = ((SharedColoredPlace)outputArc.destination()).getColorType();
104
private void getConnectedPlaceErrors(ColorType colorType, ExprValues exprValues, String identifier) {
73
105
for (Variable variable : exprValues.getVariables()) {
74
106
if (variable.getColorType().getName().equals(colorType.getName())) {
75
107
errorMsgs.add("<html>" + identifier + ": The Variable <b>" + variable.getName() + "</b> does not have the same color type as the connecting place.");
97
private void getConnectedPlaceErrorsInput(ColoredInputArc inputArc, ExprValues exprValues, String identifier) {
99
if (inputArc.source() instanceof LocalColoredPlace)
100
colorType = ((LocalColoredPlace)inputArc.source()).getColorType();
102
colorType = ((SharedColoredPlace)inputArc.source()).getColorType();
104
for (Variable variable : exprValues.getVariables()) {
105
if (variable.getColorType().getName().equals(colorType.getName())) {
106
errorMsgs.add("<html>" + identifier + ": The Variable <b>" + variable.getName() + "</b> does not have the same color type as the connecting place.");
109
for (Color color : exprValues.getColors()) {
110
boolean colorExists = false;
111
for (Color color1 : colorType) {
112
if (color.equals(color1)) {
116
if (colorExists != true) {
117
errorMsgs.add("<html>" + identifier + ": color types do not match");
121
for (ColorType type : exprValues.getColorTypes()) {
122
if (!type.getName().equals(colorType.getName())) {
123
errorMsgs.add("<html>" + identifier + ": The color type <b>" + colorType.getName() + "</b> does not have the same color type as the connecting place.");
128
130
private void getColorTypeMismatchErrors(ExprValues exprValues, String identifier) {
129
131
for (Color color : exprValues.getColors()) {