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.w3c.dom.NodeList;
11  import org.xml.sax.SAXException;
12  
13  /**
14   * <p>
15   * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
16   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
17   * <p>
18   * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
19   * initial version Jul 23, 2015 <br>
20   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
21   */
22  class WidthTag implements Serializable
23  {
24      /** */
25      private static final long serialVersionUID = 20150723L;
26  
27      /** The sOffst. */
28      @SuppressWarnings("checkstyle:visibilitymodifier")
29      Length sOffst = null;
30  
31      /** Parameter a. */
32      @SuppressWarnings("checkstyle:visibilitymodifier")
33      Length a = null;
34  
35      /** Parameter b. */
36      @SuppressWarnings("checkstyle:visibilitymodifier")
37      Length b = null;
38  
39      /** Parameter c. */
40      @SuppressWarnings("checkstyle:visibilitymodifier")
41      Length c = null;
42  
43      /** Parameter d. */
44      @SuppressWarnings("checkstyle:visibilitymodifier")
45      Length d = null;
46  
47      /**
48       * Parse the attributes of the road.type tag. The sub-elements are parsed in separate classes.
49       * @param nodeList NodeList; the list of subnodes of the road node
50       * @param parser OpenDriveNetworkLaneParser; the parser with the lists of information
51       * @param laneTag LaneTag; the LaneTag to which this element belongs
52       * @throws SAXException when parsing of the tag fails
53       * @throws NetworkException when parsing of the tag fails
54       */
55      @SuppressWarnings("checkstyle:needbraces")
56      static void parseWidth(final NodeList nodeList, final OpenDriveNetworkLaneParser parser, final LaneTag laneTag)
57              throws SAXException, NetworkException
58      {
59          int widthCount = 0;
60          for (Node node : XMLParser.getNodes(nodeList, "width"))
61          {
62              widthCount++;
63              WidthTag widthTag = new WidthTag();
64              NamedNodeMap attributes = node.getAttributes();
65  
66              Node sOffst = attributes.getNamedItem("sOffset");
67              if (sOffst != null)
68                  widthTag.sOffst = new Length(Double.parseDouble(sOffst.getNodeValue().trim()), LengthUnit.METER);
69  
70              Node a = attributes.getNamedItem("a");
71              if (a != null)
72                  widthTag.a = new Length(Double.parseDouble(a.getNodeValue().trim()), LengthUnit.METER);
73  
74              Node b = attributes.getNamedItem("b");
75              if (b != null)
76                  widthTag.b = new Length(Double.parseDouble(b.getNodeValue().trim()), LengthUnit.METER);
77  
78              Node c = attributes.getNamedItem("c");
79              if (c != null)
80                  widthTag.c = new Length(Double.parseDouble(c.getNodeValue().trim()), LengthUnit.METER);
81  
82              Node d = attributes.getNamedItem("d");
83              if (d != null)
84                  widthTag.d = new Length(Double.parseDouble(d.getNodeValue().trim()), LengthUnit.METER);
85  
86              laneTag.widthTags.add(widthTag);
87          }
88  
89          // if (widthCount > 1)
90          // System.out.println("ROAD: more than one width tag for road");
91      }
92  
93      /** {@inheritDoc} */
94      @Override
95      public final String toString()
96      {
97          return "WidthTag [sOffst=" + this.sOffst + ", a=" + this.a + ", b=" + this.b + ", c=" + this.c + ", d=" + this.d + "]";
98      }
99  }