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-2018 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 RoadMarkTag 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      /** Type */
32      @SuppressWarnings("checkstyle:visibilitymodifier")
33      String type = null;
34  
35      /** Weight */
36      @SuppressWarnings("checkstyle:visibilitymodifier")
37      String weight = null;
38  
39      /** Color */
40      @SuppressWarnings("checkstyle:visibilitymodifier")
41      String color = null;
42  
43      /** Width. */
44      @SuppressWarnings("checkstyle:visibilitymodifier")
45      Length width = null;
46  
47      /** Lane change */
48      @SuppressWarnings("checkstyle:visibilitymodifier")
49      String laneChange = null;
50  
51      /**
52       * Parse the attributes of the road.type tag. The sub-elements are parsed in separate classes.
53       * @param nodeList the list of subnodes of the road node
54       * @param parser the parser with the lists of information
55       * @param laneTag the LaneTag to which this element belongs
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 void parseRoadMark(final NodeList nodeList, final OpenDriveNetworkLaneParser parser, final LaneTag laneTag)
61              throws SAXException, NetworkException
62      {
63          int roadMarkCount = 0;
64          for (Node node : XMLParser.getNodes(nodeList, "roadMark"))
65          {
66  
67              RoadMarkTag roadMarkTag = new RoadMarkTag();
68              NamedNodeMap attributes = node.getAttributes();
69  
70              Node sOffst = attributes.getNamedItem("sOffst");
71              if (sOffst != null)
72                  roadMarkTag.sOffst = new Length(Double.parseDouble(sOffst.getNodeValue().trim()), LengthUnit.METER);
73  
74              Node type = attributes.getNamedItem("type");
75              if (type != null)
76                  roadMarkTag.type = type.getNodeValue().trim();
77  
78              Node weight = attributes.getNamedItem("weight");
79              if (weight != null)
80                  roadMarkTag.weight = weight.getNodeValue().trim();
81  
82              Node color = attributes.getNamedItem("color");
83              if (color != null)
84                  roadMarkTag.color = color.getNodeValue().trim();
85  
86              Node width = attributes.getNamedItem("width");
87              if (width != null)
88                  roadMarkTag.width = new Length(Double.parseDouble(width.getNodeValue().trim()), LengthUnit.METER);
89  
90              Node laneChange = attributes.getNamedItem("laneChange");
91              if (laneChange != null)
92                  roadMarkTag.laneChange = laneChange.getNodeValue().trim();
93  
94              laneTag.roadMarkTags.add(roadMarkCount, roadMarkTag);
95              roadMarkCount++;
96          }
97  
98      }
99  
100     /** {@inheritDoc} */
101     @Override
102     public final String toString()
103     {
104         return "RoadMarkTag [sOffst=" + this.sOffst + ", type=" + this.type + ", weight=" + this.weight + ", color="
105                 + this.color + ", width=" + this.width + ", laneChange=" + this.laneChange + "]";
106     }
107 }