~cpn-gui/tapaal/bug-fixing3

« back to all changes in this revision

Viewing changes to src/dk/aau/cs/io/TapnXmlLoader.java

  • Committer: Mark Glavind
  • Date: 2019-04-02 09:42:28 UTC
  • mfrom: (1021.1.10 loadPNML)
  • Revision ID: mglavi14@student.aau.dk-20190402094228-qb0n0o36m7i51by2
merge from load PNML, feature completed

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
package dk.aau.cs.io;
2
2
 
 
3
import java.awt.*;
3
4
import java.io.File;
4
5
import java.io.IOException;
5
6
import java.io.InputStream;
6
 
import java.util.ArrayList;
7
 
import java.util.Collection;
8
 
import java.util.HashMap;
 
7
import java.util.*;
9
8
import java.util.List;
10
9
 
11
10
import javax.swing.JOptionPane;
13
12
import javax.xml.parsers.DocumentBuilderFactory;
14
13
import javax.xml.parsers.ParserConfigurationException;
15
14
 
 
15
import dk.aau.cs.debug.Logger;
 
16
import dk.aau.cs.model.tapn.Colored.*;
 
17
import dk.aau.cs.model.tapn.Colored.Color;
 
18
import dk.aau.cs.model.tapn.Colored.Expressions.ArcExpression;
 
19
import dk.aau.cs.model.tapn.Colored.Expressions.ExpressionContext;
 
20
import dk.aau.cs.model.tapn.Colored.Expressions.GuardExpression;
16
21
import org.w3c.dom.Document;
17
22
import org.w3c.dom.Element;
18
23
import org.w3c.dom.Node;
35
40
import pipe.gui.graphicElements.Place;
36
41
import pipe.gui.graphicElements.PlaceTransitionObject;
37
42
import pipe.gui.graphicElements.Transition;
 
43
import pipe.gui.graphicElements.cpn.*;
38
44
import pipe.gui.graphicElements.tapn.TimedInhibitorArcComponent;
39
45
import pipe.gui.graphicElements.tapn.TimedInputArcComponent;
40
46
import pipe.gui.graphicElements.tapn.TimedOutputArcComponent;
73
79
import dk.aau.cs.model.tapn.Weight;
74
80
import dk.aau.cs.util.FormatException;
75
81
import dk.aau.cs.util.Require;
 
82
import sun.rmi.runtime.Log;
76
83
 
77
84
public class TapnXmlLoader {
78
85
        private static final String PLACENAME_ERROR_MESSAGE = "The keywords \"true\" and \"false\" are reserved and can not be used as place names.\nPlaces with these names will be renamed to \"_true\" and \"_false\" respectively.\n\n Note that any queries using these places may not be parsed correctly.";
79
 
        private HashMap<TimedTransitionComponent, TimedTransportArcComponent> presetArcs = new HashMap<TimedTransitionComponent, TimedTransportArcComponent>();;
 
86
        private HashMap<TimedTransitionComponent, TimedTransportArcComponent> presetArcs = new HashMap<TimedTransitionComponent, TimedTransportArcComponent>();
80
87
        private HashMap<TimedTransitionComponent, TimedTransportArcComponent> postsetArcs = new HashMap<TimedTransitionComponent, TimedTransportArcComponent>();
81
88
        private HashMap<TimedTransportArcComponent, TimeInterval> transportArcsTimeIntervals = new HashMap<TimedTransportArcComponent, TimeInterval>();
 
89
        private HashMap<ColoredTransportArcComponent, List<ColoredTimeInterval>> coloredTransportArcsTimeIntervals = new HashMap<ColoredTransportArcComponent, List<ColoredTimeInterval>>();
 
90
        private LoadTACPN loadTACPN = new LoadTACPN();
82
91
 
83
92
        private DrawingSurfaceImpl drawingSurface;
84
93
        private NameGenerator nameGenerator = new NameGenerator();
137
146
                idResolver.clear();
138
147
                
139
148
                ConstantStore constants = new ConstantStore(parseConstants(doc));
140
 
 
141
 
                TimedArcPetriNetNetwork network = new TimedArcPetriNetNetwork(constants);
 
149
                TimedArcPetriNetNetwork network;
 
150
                if (doc.getElementsByTagName("net").item(0).getAttributes().getNamedItem("type").getNodeValue().equals("TACPN"))
 
151
                        network = new ColoredArcPetriNetNetwork(constants);
 
152
                else
 
153
                        network = new TimedArcPetriNetNetwork(constants);
142
154
 
143
155
                parseSharedPlaces(doc, network, constants);
144
156
                parseSharedTransitions(doc, network);
248
260
                String name = getTAPNName(tapnNode);
249
261
 
250
262
                boolean active = getActiveStatus(tapnNode);
251
 
                
252
 
                TimedArcPetriNet tapn = new TimedArcPetriNet(name);
 
263
                TimedArcPetriNet tapn;
 
264
                if (network.isColored())
 
265
                        tapn = new ColoredArcPetriNet(name);
 
266
                else
 
267
                        tapn = new TimedArcPetriNet(name);
 
268
 
253
269
                tapn.setActive(active);
254
270
                network.add(tapn);
255
271
                nameGenerator.add(tapn);
261
277
            guiModel = new DataLayer(NetType.TAPN);
262
278
        }
263
279
                Template template = new Template(tapn, guiModel, new Zoomer());
264
 
 
265
280
                NodeList nodeList = tapnNode.getChildNodes();
266
281
                for (int i = 0; i < nodeList.getLength(); i++) {
267
282
                        Node node = nodeList.item(i);
 
283
                        if (node instanceof Element) {
 
284
                                if (node.getNodeName().equals("declaration")) {
 
285
                                        loadTACPN.parseDeclarations(node, tapn, template);
 
286
                                }
 
287
                        }
 
288
                }
 
289
                for (int i = 0; i < nodeList.getLength(); i++) {
 
290
                        Node node = nodeList.item(i);
268
291
                        if(node instanceof Element){
269
292
                                parseElement((Element)node, template, network, constants);
270
293
                        }
302
325
                        template.guiModel().addPetriNetObject(transition);
303
326
                        addListeners(transition, template);
304
327
                } else if ("arc".equals(element.getNodeName())) {
305
 
                        parseAndAddArc(element, template, constants);
 
328
                        parseAndAddArc(element, template, constants, network);
306
329
                }
307
330
        }
308
331
 
398
421
                if (nameInput.length() == 0 && idInput.length() > 0) {
399
422
                        nameInput = idInput;
400
423
                }
 
424
                GuardExpression guardExpr = null;
 
425
                if (network.isColored()) {
 
426
                        Node conditionNode = PNMLoader.getFirstDirectChild(transition, "condition");
 
427
                        if (conditionNode != null) {
 
428
                                try {
 
429
                                        guardExpr = loadTACPN.parseGuardExpression(PNMLoader.getFirstDirectChild(conditionNode, "structure"));
 
430
                                } catch (FormatException e) {
 
431
                                        e.printStackTrace();
 
432
                                }
 
433
                        }
 
434
                }
 
435
                TimedTransition t;
 
436
                if (network.isColored())
 
437
                        t = new ColoredTransition(nameInput, guardExpr);
 
438
                else
 
439
                        t = new TimedTransition(nameInput);
401
440
 
402
 
                
403
 
                TimedTransition t = new TimedTransition(nameInput);
404
441
                t.setUrgent(isUrgent);
405
442
                if(network.isNameUsedForShared(nameInput)){
406
443
                        t.setName(nameGenerator.getNewTransitionName(tapn)); // introduce temporary name to avoid exceptions
410
447
                        tapn.add(t);
411
448
                }
412
449
                nameGenerator.updateIndicesForAllModels(nameInput);
413
 
                TimedTransitionComponent transitionComponent = new TimedTransitionComponent(
414
 
                                positionXInput, positionYInput, idInput, nameInput,
415
 
                                nameOffsetXInput, nameOffsetYInput, true,
416
 
                                infiniteServer, angle, priority);
 
450
                TimedTransitionComponent transitionComponent;
 
451
                if (network.isColored())
 
452
                        transitionComponent = new ColoredTransitionComponent(positionXInput, positionYInput, idInput, nameInput,
 
453
                                        nameOffsetXInput, nameOffsetYInput,
 
454
                                        true, infiniteServer, angle, priority);
 
455
                else
 
456
                        transitionComponent = new TimedTransitionComponent(
 
457
                                        positionXInput, positionYInput, idInput, nameInput,
 
458
                                        nameOffsetXInput, nameOffsetYInput, true,
 
459
                                        infiniteServer, angle, priority);
 
460
 
417
461
                transitionComponent.setUnderlyingTransition(t);
418
 
                
 
462
 
 
463
 
419
464
                if (!displayName){
420
465
                        transitionComponent.setAttributesVisible(false);
421
466
                }
422
467
                return transitionComponent;
423
468
        }
424
469
 
 
470
        private Pair<String, Vector<Color>> parseColorInvariant(Element colorinvariant, TimedArcPetriNetNetwork network)  {
 
471
                String inscription, colorTypeName;
 
472
                Vector<Color> colors = new Vector<Color>();
 
473
                Element colorTypeELe = (Element) colorinvariant.getElementsByTagName("colortype").item(0);
 
474
                inscription = colorinvariant.getElementsByTagName("inscription").item(0).getAttributes().getNamedItem("inscription").getNodeValue();
 
475
                colorTypeName = colorTypeELe.getAttributes().getNamedItem("name").getNodeValue();
 
476
                if (network.isNameUsedForColorType(colorTypeName)) {
 
477
                        NodeList colorNodeList = colorTypeELe.getElementsByTagName("color");
 
478
                        String colorName;
 
479
                        ColorType ct = network.getColorTypeByName(colorTypeName);
 
480
                        for (int i = 0; i < colorNodeList.getLength(); i++) {
 
481
                                colorName = colorNodeList.item(i).getAttributes().getNamedItem("value").getNodeValue();
 
482
                                colors.add(new Color(ct, 0, colorName));
 
483
                        }
 
484
                } else {
 
485
                        try {
 
486
                                throw new FormatException("The color type used for an invariant does not exist");
 
487
                        } catch (FormatException e) {
 
488
                                e.printStackTrace();
 
489
                        }
 
490
                }
 
491
 
 
492
                Pair<String, Vector<Color>> pair = new Pair<String, Vector<Color>>(inscription, colors);
 
493
                return pair;
 
494
        }
 
495
 
425
496
        private TimedPlaceComponent parsePlace(Element place, TimedArcPetriNetNetwork network, TimedArcPetriNet tapn, ConstantStore constants) {
426
497
                double positionXInput = Double.parseDouble(place.getAttribute("positionX"));
427
498
                double positionYInput = Double.parseDouble(place.getAttribute("positionY"));
453
524
                                firstPlaceRenameWarning = false;
454
525
                        }
455
526
                }
456
 
                
 
527
                List<ColoredTimeInvariant> ctiList = new ArrayList<ColoredTimeInvariant>();
 
528
                ColorType ct = ColorType.COLORTYPE_DOT;
 
529
                Point position = new Point(0,0);
 
530
                ArcExpression colorMarking = null;
 
531
                if (network.isColored()) {
 
532
                        NodeList nodes = place.getElementsByTagName("colorinvariant");
 
533
                        if (nodes != null) {
 
534
                                for (int i = 0; i < nodes.getLength(); i++) {
 
535
                                        Pair<String, Vector<Color>> pair = parseColorInvariant((Element) nodes.item(i), network);
 
536
                                        ColoredTimeInvariant cti = ColoredTimeInvariant.parse(pair.getFirst(), constants, pair.getSecond());
 
537
                                        ctiList.add(cti);
 
538
                                }
 
539
                        }
 
540
                        ctiList.add(ColoredTimeInvariant.parse(place.getAttribute("inscription"), constants, new Vector<Color>(){{add(Color.STAR_COLOR);}}));
 
541
                        Node hlInitialMarkingNode = place.getElementsByTagName("hlinitialMarking").item(0);
 
542
                        Node typeNode = place.getElementsByTagName("type").item(0);
 
543
                        if (typeNode != null) {
 
544
                                try {
 
545
                                        ct = loadTACPN.parseUserSort(typeNode);
 
546
                                } catch (FormatException e) {
 
547
                                        e.printStackTrace();
 
548
                                }
 
549
                        }
 
550
 
 
551
                        if (hlInitialMarkingNode != null && hlInitialMarkingNode instanceof Element) {
 
552
                                Element graphics =(Element) ((Element)hlInitialMarkingNode).getElementsByTagName("graphics").item(0);
 
553
                                position = loadTACPN.parseGraphics(graphics, PNMLoader.GraphicsType.Offset);
 
554
                                try {
 
555
                                        colorMarking = loadTACPN.parseArcExpression(((Element)hlInitialMarkingNode).getElementsByTagName("structure").item(0));
 
556
                                } catch (FormatException e) {
 
557
                                        e.printStackTrace();
 
558
                                }
 
559
                        }
 
560
                }
 
561
 
 
562
 
457
563
                idResolver.add(tapn.name(), idInput, nameInput);
458
564
 
459
565
                TimedPlace p;
461
567
                        p = network.getSharedPlaceByName(nameInput);
462
568
                        tapn.add(p);
463
569
                }else{
464
 
                        p = new LocalTimedPlace(nameInput, TimeInvariant.parse(invariant, constants));
465
 
                        tapn.add(p);
466
 
                        for (int i = 0; i < initialMarkingInput; i++) {
467
 
                                network.marking().add(new TimedToken(p));
 
570
                        if (network.isColored()) {
 
571
                                p = new LocalColoredPlace(nameInput, ct);
 
572
                                tapn.add(p);
 
573
                                ((LocalColoredPlace)p).setCtiList(ctiList);
 
574
 
 
575
                                if (colorMarking != null) {
 
576
                                        ExpressionContext context = new ExpressionContext(new HashMap<String, Color>(), loadTACPN.getColortypes());
 
577
                                        ColorMultiset cm = colorMarking.eval(context);
 
578
                                        for (ColoredToken ctElement : cm.getTokens(p)) {
 
579
                                                network.marking().add(ctElement);
 
580
                                                //p.addToken(ctElement);
 
581
                                        }
 
582
                                }
 
583
                        } else {
 
584
                                p = new LocalTimedPlace(nameInput, TimeInvariant.parse(invariant, constants));
 
585
                                tapn.add(p);
 
586
                                for (int i = 0; i < initialMarkingInput; i++) {
 
587
                                        network.marking().add(new TimedToken(p));
 
588
                                }
468
589
                        }
469
590
                }
 
591
                TimedPlaceComponent placeComponent;
470
592
                nameGenerator.updateIndicesForAllModels(nameInput);
471
 
                TimedPlaceComponent placeComponent = new TimedPlaceComponent(positionXInput, positionYInput, idInput, nameInput, nameOffsetXInput, nameOffsetYInput, initialMarkingInput, markingOffsetXInput, markingOffsetYInput, 0);
 
593
                if (network.isColored())
 
594
                        placeComponent = new ColoredPlaceComponent(positionXInput, positionYInput, idInput, nameInput, nameOffsetXInput, nameOffsetYInput, position.x, position.y);
 
595
                else
 
596
                        placeComponent = new TimedPlaceComponent(positionXInput, positionYInput, idInput, nameInput, nameOffsetXInput, nameOffsetYInput, initialMarkingInput, markingOffsetXInput, markingOffsetYInput, 0);
 
597
 
472
598
                placeComponent.setUnderlyingPlace(p);
473
599
                
474
600
                if (!displayName){
478
604
                return placeComponent;
479
605
        }
480
606
 
481
 
        private void parseAndAddArc(Element arc, Template template, ConstantStore constants) throws FormatException {
 
607
        private void parseAndAddArc(Element arc, Template template, ConstantStore constants, TimedArcPetriNetNetwork network) throws FormatException {
482
608
                String idInput = arc.getAttribute("id");
483
609
                String sourceInput = arc.getAttribute("source");
484
610
                String targetInput = arc.getAttribute("target");
516
642
                        weight = Weight.parseWeight(arc.getAttribute("weight"), constants);
517
643
                }
518
644
 
 
645
                ArcExpression arcExpr = null;
 
646
                List<ColoredTimeInterval> ctiList = new ArrayList<ColoredTimeInterval>();
 
647
                if (network.isColored()) {
 
648
                        Node hlInscription = PNMLoader.getFirstDirectChild(arc, "hlinscription");
 
649
                        if (hlInscription != null)
 
650
                                hlInscription = PNMLoader.getFirstDirectChild(hlInscription, "structure");
 
651
                        if (hlInscription != null)
 
652
                                arcExpr = loadTACPN.parseArcExpression(hlInscription);
 
653
 
 
654
                        NodeList intervalNodes = arc.getElementsByTagName("colorinterval");
 
655
                        if (intervalNodes != null) {
 
656
                                for (int i = 0; i < intervalNodes.getLength(); i++) {
 
657
                                        if (intervalNodes.item(i) instanceof  Element) {
 
658
                                                Element interval = (Element) intervalNodes.item(i);
 
659
                                                Pair<String, Vector<Color>> pair =  parseColorInvariant(interval, network);
 
660
                                                ColoredTimeInterval coloredinterval = ColoredTimeInterval.parse(pair.getFirst(), constants, pair.getSecond());
 
661
                                                ctiList.add(coloredinterval);
 
662
                                        }
 
663
                                }
 
664
                        }
 
665
                }
 
666
 
519
667
                Arc tempArc;
520
668
 
521
669
                if (type.equals("tapnInhibitor")) {
522
 
 
523
670
                        tempArc = parseAndAddTimedInhibitorArc(idInput, taggedArc,
524
671
                                        inscriptionTempStorage, sourceIn, targetIn, _startx,
525
672
                                        _starty, _endx, _endy,template, constants, weight);
528
675
                        if (type.equals("timed")) {
529
676
                                tempArc = parseAndAddTimedInputArc(idInput, taggedArc,
530
677
                                                inscriptionTempStorage, sourceIn, targetIn, _startx,
531
 
                                                _starty, _endx, _endy, template, constants, weight);
 
678
                                                _starty, _endx, _endy, template, constants, weight, network.isColored(), ctiList, arcExpr);
532
679
 
533
 
                        } else if (type.equals("transport")) {
 
680
                        } else if (type.equals("transport")) { // crashes here
534
681
                                tempArc = parseAndAddTransportArc(idInput, taggedArc,
535
682
                                                inscriptionTempStorage, sourceIn, targetIn, _startx,
536
 
                                                _starty, _endx, _endy, template, constants, weight);
 
683
                                                _starty, _endx, _endy, template, constants, weight, arcExpr, network.isColored(), ctiList);
537
684
 
538
685
                        } else {
539
686
                                tempArc = parseAndAddTimedOutputArc(idInput, taggedArc,
540
687
                                                inscriptionTempStorage, sourceIn, targetIn, _startx,
541
 
                                                _starty, _endx, _endy, template, weight);
 
688
                                                _starty, _endx, _endy, template, weight, arcExpr, network.isColored());
542
689
                        }
543
 
 
544
690
                }
545
691
                tempArc.setNameOffsetX(nameOffsetXInput);
546
692
                tempArc.setNameOffsetY(nameOffsetYInput);
551
697
        private TimedOutputArcComponent parseAndAddTimedOutputArc(String idInput, boolean taggedArc,
552
698
                        String inscriptionTempStorage, PlaceTransitionObject sourceIn,
553
699
                        PlaceTransitionObject targetIn, double _startx, double _starty,
554
 
                        double _endx, double _endy, Template template, Weight weight) throws FormatException {
555
 
 
556
 
                TimedOutputArcComponent tempArc = new TimedOutputArcComponent(_startx, _starty, _endx, _endy, 
 
700
                        double _endx, double _endy, Template template, Weight weight,
 
701
          ArcExpression expr, boolean isColored) throws FormatException {
 
702
 
 
703
            TimedOutputArcComponent tempArc;
 
704
 
 
705
            if (!isColored)
 
706
                    tempArc = new TimedOutputArcComponent(_startx, _starty, _endx, _endy,
557
707
                                sourceIn, targetIn,     (inscriptionTempStorage!="" ? Integer.valueOf(inscriptionTempStorage) : 1), idInput, taggedArc);
 
708
            else
 
709
                tempArc = new ColoredOutputArcComponent(_startx, _starty, _endx, _endy,
 
710
                    sourceIn, targetIn, weight.value(), expr, idInput, taggedArc);
558
711
 
559
712
                TimedPlace place = template.model().getPlaceByName(targetIn.getName());
560
713
                TimedTransition transition = template.model().getTransitionByName(sourceIn.getName());
561
714
 
562
 
                TimedOutputArc outputArc = new TimedOutputArc(transition, place, weight);
 
715
                TimedOutputArc outputArc;
 
716
                if (!isColored)
 
717
                    outputArc = new TimedOutputArc(transition, place, weight);
 
718
                else
 
719
                    outputArc = new ColoredOutputArc(transition, place, expr);
563
720
                tempArc.setUnderlyingArc(outputArc);
564
721
 
565
722
                if(template.model().hasArcFromTransitionToPlace(outputArc.source(),outputArc.destination())) {
578
735
        private TimedTransportArcComponent parseAndAddTransportArc(String idInput, boolean taggedArc,
579
736
                        String inscriptionTempStorage, PlaceTransitionObject sourceIn,
580
737
                        PlaceTransitionObject targetIn, double _startx, double _starty,
581
 
                        double _endx, double _endy, Template template, ConstantStore constants, Weight weight) {
 
738
                        double _endx, double _endy, Template template, ConstantStore constants, Weight weight, ArcExpression expr, boolean isColored, List<ColoredTimeInterval> ctiList) {
582
739
 
583
740
                
584
741
                String[] inscriptionSplit = {};
589
746
                if (sourceIn instanceof Place) {
590
747
                        isInPreSet = true;
591
748
                }
592
 
                TimedTransportArcComponent tempArc = new TimedTransportArcComponent(new TimedInputArcComponent(
 
749
                TimedTransportArcComponent tempArc;
 
750
                if (!isColored)
 
751
                        tempArc = new TimedTransportArcComponent(new TimedInputArcComponent(
593
752
                                new TimedOutputArcComponent(_startx, _starty, _endx, _endy,     sourceIn, targetIn, 1, idInput, taggedArc),
594
753
                                inscriptionSplit[0]), Integer.parseInt(inscriptionSplit[1]), isInPreSet);
 
754
                else
 
755
                        tempArc = new ColoredTransportArcComponent(new ColoredInputArcComponent(
 
756
                                new ColoredOutputArcComponent(_startx, _starty, _endx, _endy, sourceIn, targetIn, 1, expr, idInput, taggedArc),
 
757
                                inscriptionTempStorage), weight.value(), isInPreSet);
595
758
 
596
759
                sourceIn.addConnectFrom(tempArc);
597
760
                targetIn.addConnectTo(tempArc);
598
761
 
599
762
                if (isInPreSet) {
600
 
                        if (postsetArcs.containsKey((TimedTransitionComponent) targetIn)) {
601
 
                                TimedTransportArcComponent postsetTransportArc = postsetArcs.get((TimedTransitionComponent) targetIn);
 
763
            TimeInterval interval;
 
764
            if (!isColored)
 
765
                interval = TimeInterval.parse(inscriptionSplit[0],      constants);
 
766
            else {
 
767
                interval = ColoredTimeInterval.parse(inscriptionTempStorage, constants, new Vector<Color>(){{add(Color.STAR_COLOR);}});
 
768
                ctiList.add((ColoredTimeInterval) interval);
 
769
            }
 
770
                        if (postsetArcs.containsKey(targetIn)) {
 
771
                                TimedTransportArcComponent postsetTransportArc = postsetArcs.get(targetIn);
602
772
                                TimedPlace sourcePlace = template.model().getPlaceByName(sourceIn.getName());
603
773
                                TimedTransition trans = template.model().getTransitionByName(targetIn.getName());
604
774
                                TimedPlace destPlace = template.model().getPlaceByName(postsetTransportArc.getTarget().getName());
605
 
                                TimeInterval interval = TimeInterval.parse(inscriptionSplit[0], constants);
 
775
 
 
776
 
606
777
 
607
778
                                assert (sourcePlace != null);
608
779
                                assert (trans != null);
609
780
                                assert (destPlace != null);
610
781
 
611
 
                                TransportArc transArc = new TransportArc(sourcePlace, trans, destPlace, interval, weight);
 
782
                                TransportArc transArc;
 
783
                                if (!isColored)
 
784
                                        transArc = new TransportArc(sourcePlace, trans, destPlace, interval, weight);
 
785
                                else
 
786
                                        transArc = new ColoredTransportArc(sourcePlace, trans, destPlace, ctiList);
612
787
 
613
788
                                tempArc.setUnderlyingArc(transArc);
614
789
                                postsetTransportArc.setUnderlyingArc(transArc);
621
796
                                postsetArcs.remove((TimedTransitionComponent) targetIn);
622
797
                        } else {
623
798
                                presetArcs.put((TimedTransitionComponent) targetIn,     tempArc);
624
 
                                transportArcsTimeIntervals.put(tempArc, TimeInterval.parse(inscriptionSplit[0], constants));
 
799
                                if (isColored)
 
800
                                        coloredTransportArcsTimeIntervals.put((ColoredTransportArcComponent) tempArc, ctiList);
 
801
                                else
 
802
                                        transportArcsTimeIntervals.put(tempArc, TimeInterval.parse(inscriptionSplit[0], constants)); //TODO:: exception crash
625
803
                        }
626
804
                } else {
627
 
                        if (presetArcs.containsKey((TimedTransitionComponent) sourceIn)) {
628
 
                                TimedTransportArcComponent presetTransportArc = presetArcs.get((TimedTransitionComponent) sourceIn);
 
805
                        if (presetArcs.containsKey( sourceIn)) {
 
806
                                TimedTransportArcComponent presetTransportArc = presetArcs.get(sourceIn);
629
807
                                TimedPlace sourcePlace = template.model().getPlaceByName(presetTransportArc.getSource().getName());
630
808
                                TimedTransition trans = template.model().getTransitionByName(sourceIn.getName());
631
809
                                TimedPlace destPlace = template.model().getPlaceByName(targetIn.getName());
632
 
                                TimeInterval interval = transportArcsTimeIntervals.get(presetTransportArc);
 
810
                Logger.log(coloredTransportArcsTimeIntervals.get(presetTransportArc));
 
811
                                TimeInterval interval = null;
 
812
                                List<ColoredTimeInterval> timeIntervals = null;
 
813
                                if (!isColored)
 
814
                                    interval = transportArcsTimeIntervals.get(presetTransportArc);
 
815
                                else
 
816
                    timeIntervals = coloredTransportArcsTimeIntervals.get(presetTransportArc);
633
817
 
634
818
                                assert (sourcePlace != null);
635
819
                                assert (trans != null);
636
820
                                assert (destPlace != null);
637
821
 
638
 
                                TransportArc transArc = new TransportArc(sourcePlace, trans, destPlace, interval, weight);
 
822
                                TransportArc transArc;
 
823
                                if (!isColored)
 
824
                                        transArc = new TransportArc(sourcePlace, trans, destPlace, interval, weight);
 
825
                                else
 
826
                                        transArc = new ColoredTransportArc(sourcePlace, trans, destPlace, timeIntervals);
639
827
 
640
828
                                tempArc.setUnderlyingArc(transArc);
641
829
                                presetTransportArc.setUnderlyingArc(transArc);
645
833
                                addListeners(tempArc, template);
646
834
                                template.model().add(transArc);
647
835
 
648
 
                                presetArcs.remove((TimedTransitionComponent) sourceIn);
 
836
                                presetArcs.remove(sourceIn);
649
837
                                transportArcsTimeIntervals.remove(presetTransportArc);
650
838
                        } else {
651
839
                                postsetArcs.put((TimedTransitionComponent) sourceIn, tempArc);
657
845
        private Arc parseAndAddTimedInputArc(String idInput, boolean taggedArc,
658
846
                        String inscriptionTempStorage, PlaceTransitionObject sourceIn,
659
847
                        PlaceTransitionObject targetIn, double _startx, double _starty,
660
 
                        double _endx, double _endy, Template template, ConstantStore constants, Weight weight) throws FormatException {
 
848
                        double _endx, double _endy, Template template, ConstantStore constants, Weight weight, boolean isColored, List<ColoredTimeInterval> ctiList, ArcExpression expr ) throws FormatException {
661
849
                Arc tempArc;
662
 
                tempArc = new TimedInputArcComponent(new TimedOutputArcComponent(
 
850
 
 
851
                if (!isColored)
 
852
                        tempArc = new TimedInputArcComponent(new TimedOutputArcComponent(
663
853
                                _startx, _starty, _endx, _endy, sourceIn, targetIn, 1, idInput,
664
854
                                taggedArc),
665
855
                                (inscriptionTempStorage != null ? inscriptionTempStorage : ""));
 
856
                else
 
857
                        tempArc = new ColoredInputArcComponent(new ColoredOutputArcComponent(_startx, _starty, _endx, _endy, sourceIn,
 
858
                                        targetIn, 1, expr, idInput, taggedArc), inscriptionTempStorage);
666
859
 
667
860
                TimedPlace place = template.model().getPlaceByName(sourceIn.getName());
668
861
                TimedTransition transition = template.model().getTransitionByName(targetIn.getName());
669
 
                TimeInterval interval = TimeInterval.parse(inscriptionTempStorage, constants);
670
 
 
671
 
                TimedInputArc inputArc = new TimedInputArc(place, transition, interval, weight);
 
862
 
 
863
                TimeInterval interval;
 
864
                if (!isColored)
 
865
                    interval = TimeInterval.parse(inscriptionTempStorage, constants);
 
866
                else {
 
867
            interval = ColoredTimeInterval.parse(inscriptionTempStorage, constants, new Vector<Color>(){{add(Color.STAR_COLOR);}});
 
868
            ctiList.add((ColoredTimeInterval) interval);
 
869
        }
 
870
 
 
871
 
 
872
 
 
873
 
 
874
                TimedInputArc inputArc;
 
875
                if (!isColored)
 
876
                        inputArc = new TimedInputArc(place, transition, interval, weight);
 
877
                else
 
878
                        inputArc = new ColoredInputArc(place, transition, ctiList, expr);
 
879
 
672
880
                ((TimedInputArcComponent) tempArc).setUnderlyingArc(inputArc);
673
881
 
674
882
                if(template.model().hasArcFromPlaceToTransition(inputArc.source(), inputArc.destination())) {
695
903
                                (inscriptionTempStorage != null ? inscriptionTempStorage : ""));
696
904
                TimedPlace place = template.model().getPlaceByName(sourceIn.getName());
697
905
                TimedTransition transition = template.model().getTransitionByName(targetIn.getName());
698
 
                TimeInterval interval = TimeInterval.parse(inscriptionTempStorage, constants);
699
 
                
700
 
                if(!interval.equals(TimeInterval.ZERO_INF) && firstInhibitorIntervalWarning) {
701
 
                        JOptionPane.showMessageDialog(CreateGui.getApp(), "The chosen model contained inhibitor arcs with unsupported intervals.\n\nTAPAAL only supports inhibitor arcs with intervals [0,inf).\n\nAny other interval on inhibitor arcs will be replaced with [0,inf).", "Unsupported Interval Detected on Inhibitor Arc", JOptionPane.INFORMATION_MESSAGE);
702
 
                        firstInhibitorIntervalWarning = false;
703
 
                }
704
 
                
705
 
                TimedInhibitorArc inhibArc = new TimedInhibitorArc(place, transition, interval, weight);
 
906
                TimeInterval interval = null;
 
907
                if (!inscriptionTempStorage.equals("")) {
 
908
            interval = TimeInterval.parse(inscriptionTempStorage, constants);
 
909
 
 
910
            if(!interval.equals(TimeInterval.ZERO_INF) && firstInhibitorIntervalWarning) {
 
911
                JOptionPane.showMessageDialog(CreateGui.getApp(), "The chosen model contained inhibitor arcs with unsupported intervals.\n\nTAPAAL only supports inhibitor arcs with intervals [0,inf).\n\nAny other interval on inhibitor arcs will be replaced with [0,inf).", "Unsupported Interval Detected on Inhibitor Arc", JOptionPane.INFORMATION_MESSAGE);
 
912
                firstInhibitorIntervalWarning = false;
 
913
            }
 
914
        }
 
915
 
 
916
        TimedInhibitorArc inhibArc = new TimedInhibitorArc(place, transition, interval, weight);
706
917
 
707
918
                tempArc.setUnderlyingArc(inhibArc);
708
919
                template.guiModel().addPetriNetObject(tempArc);