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.opentrafficsim.core.network.NetworkException;
8   import org.w3c.dom.NamedNodeMap;
9   import org.w3c.dom.Node;
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 SuperElevationTag implements Serializable
22  {
23  
24      /** */
25      private static final long serialVersionUID = 20150723L;
26  
27      /** Sequence of the geometry. */
28      @SuppressWarnings("checkstyle:visibilitymodifier")
29      int id = 0;
30  
31      /** Start position (s-coordinate). */
32      @SuppressWarnings("checkstyle:visibilitymodifier")
33      Length s = null;
34  
35      /** The a position (s-coordinate). */
36      @SuppressWarnings("checkstyle:visibilitymodifier")
37      Length a = null;
38  
39      /** The b position (s-coordinate). */
40      @SuppressWarnings("checkstyle:visibilitymodifier")
41      Length b = null;
42  
43      /** The c position (s-coordinate). */
44      @SuppressWarnings("checkstyle:visibilitymodifier")
45      Length c = null;
46  
47      /** The d position (s-coordinate) */
48      @SuppressWarnings("checkstyle:visibilitymodifier")
49      Length d = null;
50  
51      /**
52       * Parse the attributes of the road tag. The sub-elements are parsed in separate classes.
53       * @param node Node; the top-level road node
54       * @param parser OpenDriveNetworkLaneParser; the parser with the lists of information
55       * @return the generated RoadTag for further reference
56       * @throws SAXException when parsing of the tag fails
57       * @throws NetworkException when parsing of the tag fails
58       */
59      @SuppressWarnings("checkstyle:needbraces")
60      static SuperElevationTag parseSuperElevation(final Node node, final OpenDriveNetworkLaneParser parser)
61              throws SAXException, NetworkException
62      {
63          NamedNodeMap attributes = node.getAttributes();
64          SuperElevationTag elevationTag = new SuperElevationTag();
65  
66          Node s = attributes.getNamedItem("s");
67          if (s == null)
68              throw new SAXException("Geometry: missing attribute s");
69          elevationTag.s = new Length(Double.parseDouble(s.getNodeValue().trim()), LengthUnit.METER);
70  
71          Node a = attributes.getNamedItem("a");
72          if (a == null)
73              throw new SAXException("Geometry: missing attribute a");
74          elevationTag.a = new Length(Double.parseDouble(a.getNodeValue().trim()), LengthUnit.METER);
75  
76          Node b = attributes.getNamedItem("b");
77          if (b == null)
78              throw new SAXException("Geometry: missing attribute b");
79          elevationTag.b = new Length(Double.parseDouble(b.getNodeValue().trim()), LengthUnit.METER);
80  
81          Node c = attributes.getNamedItem("c");
82          if (c == null)
83              throw new SAXException("Geometry: missing attribute c");
84          elevationTag.c = new Length(Double.parseDouble(c.getNodeValue().trim()), LengthUnit.METER);
85  
86          Node d = attributes.getNamedItem("d");
87          if (d == null)
88              throw new SAXException("Geometry: missing attribute d");
89          elevationTag.d = new Length(Double.parseDouble(d.getNodeValue().trim()), LengthUnit.METER);
90  
91          return elevationTag;
92      }
93  
94      /** {@inheritDoc} */
95      @Override
96      public final String toString()
97      {
98          return "SuperElevationTag [id=" + this.id + ", s=" + this.s + ", a=" + this.a + ", b=" + this.b + ", c=" + this.c
99                  + ", d=" + this.d + "]";
100     }
101 }