View Javadoc
1   package org.opentrafficsim.editor.extensions.map;
2   
3   import org.djutils.draw.bounds.Bounds2d;
4   import org.djutils.draw.point.Point2d;
5   import org.opentrafficsim.draw.DrawLevel;
6   import org.opentrafficsim.draw.road.GtuGeneratorPositionAnimation.GtuGeneratorPositionData;
7   import org.opentrafficsim.editor.OtsEditor;
8   import org.opentrafficsim.editor.XsdTreeNode;
9   
10  /**
11   * Generator data for the editor Map.
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 MapGeneratorData extends MapLaneBasedObjectData implements GtuGeneratorPositionData
19  {
20  
21      /** Type, 'Generator' or 'List generator'. */
22      private final String type;
23  
24      /** Bounds. */
25      private Bounds2d bounds = new Bounds2d(0.0, 4.75, -1.0, 1.0);
26  
27      /**
28       * Constructor.
29       * @param map map.
30       * @param node node.
31       * @param editor editor.
32       */
33      public MapGeneratorData(final EditorMap map, final XsdTreeNode node, final OtsEditor editor)
34      {
35          super(map, node, editor);
36          this.type = node.getNodeName().equals("Generator") ? "Generator " : "List generator ";
37      }
38  
39      @Override
40      public Bounds2d getRelativeBounds()
41      {
42          return this.bounds;
43      }
44  
45      @Override
46      public int getQueueCount()
47      {
48          return 0;
49      }
50  
51      @Override
52      public double getZ()
53      {
54          return DrawLevel.OBJECT.getZ();
55      }
56  
57      @Override
58      public String toString()
59      {
60          return this.type + getLinkLanePositionId();
61      }
62  
63      /**
64       * Signed distance function. The point must be relative. As this is a line object, only positive values are returned.
65       * @param point point for which distance is returned
66       * @return distance from point to these bounds
67       */
68      @Override
69      public double signedDistance(final Point2d point)
70      {
71          return getLine().closestPointOnPolyLine(point).distance(point);
72      }
73  
74  }