Petri Net Graphics

The Petri net classes as they are don’t contain any visualization information like object positioning, object dimension, or border style. To keep logic and visualization separated, the graphical information is available in graphical container classes. Figure 7 visualizes the inheritance hierarchy of the graphical Petri net classes with the corresponding Petri net classes. Note that AbstractGraphicalCPN and AbstractCPNGraphics are direct sub- classes of AbstractGraphicalPN and AbstractPNGraphics instead of inheriting from the P/T-Net classes. The reason for this is the difference in the marking and the flow relation constraints, which are represented as strings in the CPN and the IF-Net.

Inheritance hierarchy of the graphical Petri net classes with the aggregated Petri net classes.

Figure 7: Inheritance hierarchy of the graphical Petri net classes with the aggregated Petri net classes.

The graphical attributes in the graphical classes are motivated by the styling possibil- ities given by the PNML standard (see http://www.pnml.org/version-2009/version-2009.php). Basically we differentiate between graphical information of nodes (places and transitions), arcs (flow relations), and annotations (labels). The corresponding attributes are listed in the classes NodeGraphics, ArcGraphics, and AnnotationGraphics.

The graphic objects are assigned to elements of the Petri net using an associative array with the name of the node, arc or annotation as key. In the following example we set the text alignment for all arc annotations to right. At first we create the graphic objects and assign colors to the color names. The token clearances and the subject clearances also need a positioning:

IFNetGraphics ifNetG = new IFNetGraphics();
GraphicalIFNet gIFNet = new GraphicalIFNet(ifnet, ifNetG);

Map<String, Color> colors = new HashMap<String, Color>();
colors.put("black", Color.BLACK);
colors.put("red", Color.RED);
colors.put("green", Color.GREEN);
ifNetG.setColors(colors);

ifNetG.setClearancesPosition(new Position(20, 30));
ifNetG.setTokenLabelsPosition(new Position(40, 30));

Now the text alignment can be set:

Font annotationFont = new Font();
annotationFont.setAlign(Align.RIGHT);
AnnotationGraphics arcAnnotation = new AnnotationGraphics();
arcAnnotation.setFont(annotationFont);

ifNetG.getArcAnnotationGraphics().put(f1.getName(), arcAnnotation);
ifNetG.getArcAnnotationGraphics().put(f2.getName(), arcAnnotation);
ifNetG.getArcAnnotationGraphics().put(f3.getName(), arcAnnotation);
ifNetG.getArcAnnotationGraphics().put(f4.getName(), arcAnnotation);
ifNetG.getArcAnnotationGraphics().put(f5.getName(), arcAnnotation);
ifNetG.getArcAnnotationGraphics().put(f6.getName(), arcAnnotation);

The object ifNetG now contains the associations between Petri net components and graphical information. The object’s toString()-method returns the following string:

                    placeGraphics# 0
               transitionGraphics# 0
                      arcGraphics# 0
                    tokenGraphics# 0

            arcAnnotationGraphics# 6:
                                     arcTP_tOutpOut: [Font( align:right )]

                                     arcTP_tInp1: [Font( align:right )]
                                     arcTP_tdp2: [Font( align:right )]
                                     arcPT_p1td: [Font( align:right )]
                                     arcPT_pIntIn: [Font( align:right )]
                                     arcPT_p2tOut: [Font( align:right )]

     placeLabelAnnotationGraphics# 0
transitionLabelAnnotationGraphics# 0

                      tokenColors# 3:
                                     red: java.awt.Color[r=255,g=0,b=0]

                                     green: java.awt.Color[r=0,g=255,b=0]
                                     black: java.awt.Color[r=0,g=0,b=0]

           accessFunctionGraphics# 0
                  subjectGraphics# 0

               clearancesPosition#:  Position( 20.0 / 30.0 )
              tokenLabelsPosition#:  Position( 40.0 / 30.0 )