View Javadoc
1   package org.opentrafficsim.road.network.factory.xml.old;
2   
3   import java.io.Serializable;
4   
5   import org.djunits.value.vdouble.scalar.Direction;
6   import org.djunits.value.vdouble.scalar.Length;
7   import org.opentrafficsim.core.geometry.OTSPoint3D;
8   import org.opentrafficsim.core.network.NetworkException;
9   import org.opentrafficsim.core.network.factory.xml.units.AngleUnits;
10  import org.opentrafficsim.core.network.factory.xml.units.LengthUnits;
11  import org.w3c.dom.NamedNodeMap;
12  import org.w3c.dom.Node;
13  import org.xml.sax.SAXException;
14  
15  /**
16   * <p>
17   * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
18   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
19   * <p>
20   * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
21   * initial version Jul 24, 2015 <br>
22   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
23   */
24  class ArcTag implements Serializable
25  {
26      /** */
27      private static final long serialVersionUID = 20150724L;
28  
29      /** Angle. */
30      @SuppressWarnings("checkstyle:visibilitymodifier")
31      Direction angle = null;
32  
33      /** Radius. */
34      @SuppressWarnings("checkstyle:visibilitymodifier")
35      Length radius = null;
36  
37      /** Direction. */
38      @SuppressWarnings("checkstyle:visibilitymodifier")
39      ArcDirection direction = null;
40  
41      /** The center coordinate of the arc. Will be filled after parsing. */
42      @SuppressWarnings("checkstyle:visibilitymodifier")
43      OTSPoint3D center;
44  
45      /** The startAngle in radians compared to the center coordinate. Will be filled after parsing. */
46      @SuppressWarnings("checkstyle:visibilitymodifier")
47      double startAngle;
48  
49      /** Direction of the arc; LEFT or RIGHT. */
50      enum ArcDirection
51      {
52          /** Left = counter-clockwise. */
53          LEFT,
54          /** Right = clockwise. */
55          RIGHT;
56      }
57  
58      /**
59       * Parse the LINK.ARC tag.
60       * @param arcNode Node; the XML-node to parse
61       * @param parser XmlNetworkLaneParserOld; the parser with the lists of information
62       * @param linkTag LinkTag; the parent link tag
63       * @throws SAXException when parsing of the tag fails
64       * @throws NetworkException when parsing of the tag fails
65       */
66      @SuppressWarnings("checkstyle:needbraces")
67      static void parseArc(final Node arcNode, final XmlNetworkLaneParserOld parser, final LinkTag linkTag)
68              throws SAXException, NetworkException
69      {
70          NamedNodeMap arcAttributes = arcNode.getAttributes();
71          linkTag.arcTag = new ArcTag();
72  
73          Node radius = arcAttributes.getNamedItem("RADIUS");
74          if (radius == null)
75              throw new SAXException("ARC: missing attribute RADIUS");
76          linkTag.arcTag.radius = LengthUnits.parseLength(radius.getNodeValue());
77  
78          Node angle = arcAttributes.getNamedItem("ANGLE");
79          if (angle == null)
80              throw new SAXException("ARC: missing attribute ANGLE");
81          linkTag.arcTag.angle = AngleUnits.parseDirection(angle.getNodeValue());
82  
83          Node dirNode = arcAttributes.getNamedItem("DIRECTION");
84          if (dirNode == null)
85              throw new SAXException("ARC: missing attribute DIRECTION");
86          String dir = dirNode.getNodeValue().trim();
87          linkTag.arcTag.direction = (dir.equals("L") || dir.equals("LEFT") || dir.equals("COUNTERCLOCKWISE")) ? ArcDirection.LEFT
88                  : ArcDirection.RIGHT;
89  
90      }
91  
92      /** {@inheritDoc} */
93      @Override
94      public final String toString()
95      {
96          return "ArcTag [angle=" + this.angle + ", radius=" + this.radius + ", direction=" + this.direction + ", center="
97                  + this.center + ", startAngle=" + this.startAngle + "]";
98      }
99  }