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 SpiralTag 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 curvStart = null;
29  
30      /** Degree of the curve at the end(s-coordinate?). */
31      @SuppressWarnings("checkstyle:visibilitymodifier")
32      Length curvEnd = null;
33  
34      /**
35       * Parse the attributes of the road.type tag. The sub-elements are parsed in separate classes.
36       * @param nodeList NodeList; the list of subnodes of the road node
37       * @param parser OpenDriveNetworkLaneParser; the parser with the lists of information
38       * @param geometryTag GeometryTag; the GeometryTag to which this element belongs
39       * @throws SAXException when parsing of the tag fails
40       */
41      @SuppressWarnings("checkstyle:needbraces")
42      static void parseSpiral(final NodeList nodeList, final OpenDriveNetworkLaneParser parser, final GeometryTag geometryTag)
43              throws SAXException
44      {
45          int typeCount = 0;
46          for (Node node : XMLParser.getNodes(nodeList, "spiral"))
47          {
48              typeCount++;
49  
50              SpiralTag spiralTag = new SpiralTag();
51              NamedNodeMap attributes = node.getAttributes();
52  
53              Node curvStart = attributes.getNamedItem("curvStart");
54              if (curvStart != null)
55                  spiralTag.curvStart = new Length(Double.parseDouble(curvStart.getNodeValue().trim()), LengthUnit.SI);
56  
57              Node curvEnd = attributes.getNamedItem("curvEnd");
58              if (curvEnd != null)
59                  spiralTag.curvEnd = new Length(Double.parseDouble(curvEnd.getNodeValue().trim()), LengthUnit.SI);
60  
61              geometryTag.spiralTag = spiralTag;
62          }
63  
64          if (typeCount > 1)
65              throw new SAXException("ROAD: more than one spiral tag!");
66      }
67  
68      /** {@inheritDoc} */
69      @Override
70      public final String toString()
71      {
72          return "SpiralTag [curvStart=" + this.curvStart + ", curvEnd=" + this.curvEnd + "]";
73      }
74  }