View Javadoc
1   package org.opentrafficsim.editor.extensions.map;
2   
3   import org.djutils.draw.bounds.Bounds2d;
4   import org.djutils.draw.line.Polygon2d;
5   import org.djutils.draw.point.Point2d;
6   import org.opentrafficsim.base.geometry.OtsLocatable;
7   import org.opentrafficsim.base.geometry.OtsShape;
8   import org.opentrafficsim.draw.road.PriorityAnimation.PriorityData;
9   
10  /**
11   * Priority data for in the editor.
12   * <p>
13   * Copyright (c) 2024-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
14   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
15   * </p>
16   * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
17   */
18  public class MapPriorityData implements PriorityData
19  {
20  
21      /** Link data. */
22      private final MapLinkData linkData;
23  
24      /** Location. */
25      private final Point2d location;
26  
27      /** Bounds. */
28      private final Bounds2d bounds = new Bounds2d(2.0, 2.0);
29  
30      /** Contour. */
31      private final Polygon2d contour;
32  
33      /** Shape (cached). */
34      private OtsShape shape;
35  
36      /**
37       * Constructor.
38       * @param linkData link data.
39       */
40      public MapPriorityData(final MapLinkData linkData)
41      {
42          this.location = linkData.getCenterLine().getLocationFractionExtended(0.5);
43          this.linkData = linkData;
44          this.contour = OtsLocatable.boundsAsContour(this);
45      }
46  
47      @Override
48      public Point2d getLocation()
49      {
50          return this.location;
51      }
52  
53      @Override
54      public Polygon2d getContour()
55      {
56          return this.contour;
57      }
58  
59      @Override
60      public OtsShape getShape()
61      {
62          if (this.shape == null)
63          {
64              this.shape = PriorityData.super.getShape();
65          }
66          return this.shape;
67      }
68  
69      @Override
70      public Bounds2d getBounds()
71      {
72          return this.bounds;
73      }
74  
75      @Override
76      public boolean isAllStop()
77      {
78          return "ALL_STOP".equals(this.linkData.getNode().getAttributeValue("Priority"));
79      }
80  
81      @Override
82      public boolean isBusStop()
83      {
84          return "BUS_STOP".equals(this.linkData.getNode().getAttributeValue("Priority"));
85      }
86  
87      @Override
88      public boolean isNone()
89      {
90          return "NONE".equals(this.linkData.getNode().getAttributeValue("Priority"));
91      }
92  
93      @Override
94      public boolean isPriority()
95      {
96          return "PRIORITY".equals(this.linkData.getNode().getAttributeValue("Priority"));
97      }
98  
99      @Override
100     public boolean isStop()
101     {
102         return "STOP".equals(this.linkData.getNode().getAttributeValue("Priority"));
103     }
104 
105     @Override
106     public boolean isYield()
107     {
108         return "YIELD".equals(this.linkData.getNode().getAttributeValue("Priority"));
109     }
110 
111     @Override
112     public String toString()
113     {
114         return "Priority " + this.linkData.getId();
115     }
116 
117 }