View Javadoc
1   package org.opentrafficsim.road.network.factory.opendrive;
2   
3   import java.io.Serializable;
4   
5   import org.djunits.unit.LengthUnit;
6   import org.djunits.value.vdouble.scalar.Length;
7   import org.w3c.dom.NamedNodeMap;
8   import org.w3c.dom.Node;
9   import org.w3c.dom.NodeList;
10  import org.xml.sax.SAXException;
11  
12  /**
13   * <p>
14   * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
15   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
16   * <p>
17   * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
18   * initial version Jul 23, 2015 <br>
19   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
20   */
21  class ArcTag implements Serializable
22  {
23      /** */
24      private static final long serialVersionUID = 20150723L;
25  
26      /** Degree of the curve at the start(s-coordinate?). */
27      @SuppressWarnings("checkstyle:visibilitymodifier")
28      Length curvature = null;
29  
30      /**
31       * Parse the attributes of the road.type tag. The sub-elements are parsed in separate classes.
32       * @param nodeList NodeList; the list of subnodes of the road node
33       * @param parser OpenDriveNetworkLaneParser; the parser with the lists of information
34       * @param geometryTag GeometryTag; the GeometryTag to which this element belongs
35       * @throws SAXException when parsing of the tag fails
36       */
37      @SuppressWarnings("checkstyle:needbraces")
38      static void parseArc(final NodeList nodeList, final OpenDriveNetworkLaneParser parser, final GeometryTag geometryTag)
39              throws SAXException
40      {
41          int typeCount = 0;
42          for (Node node : XMLParser.getNodes(nodeList, "arc"))
43          {
44              typeCount++;
45              ArcTag arcTag = new ArcTag();
46              NamedNodeMap attributes = node.getAttributes();
47  
48              Node curvature = attributes.getNamedItem("curvature");
49              if (curvature != null)
50                  arcTag.curvature = new Length(Double.parseDouble(curvature.getNodeValue().trim()), LengthUnit.SI);
51  
52              geometryTag.arcTag = arcTag;
53          }
54  
55          if (typeCount > 1)
56              throw new SAXException("ROAD: more than one arc tag!");
57      }
58  
59      /** {@inheritDoc} */
60      @Override
61      public final String toString()
62      {
63          return "ArcTag [curvature=" + this.curvature + "]";
64      }
65  }