View Javadoc
1   package org.opentrafficsim.road.network.factory.opendrive;
2   
3   import java.io.Serializable;
4   
5   import org.djunits.unit.AngleUnit;
6   import org.djunits.unit.LengthUnit;
7   import org.djunits.value.vdouble.scalar.Angle;
8   import org.djunits.value.vdouble.scalar.Length;
9   import org.opentrafficsim.core.network.NetworkException;
10  import org.w3c.dom.NamedNodeMap;
11  import org.w3c.dom.Node;
12  import org.xml.sax.SAXException;
13  
14  /**
15   * <p>
16   * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
17   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
18   * <p>
19   * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
20   * initial version Jul 23, 2015 <br>
21   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
22   */
23  class ObjectTag implements Serializable
24  {
25      /** */
26      private static final long serialVersionUID = 20150723L;
27  
28      /** Parameter s. */
29      @SuppressWarnings("checkstyle:visibilitymodifier")
30      Length s = null;
31  
32      /** Parameter t. */
33      @SuppressWarnings("checkstyle:visibilitymodifier")
34      Length t = null;
35  
36      /** Id. */
37      @SuppressWarnings("checkstyle:visibilitymodifier")
38      String id = null;
39  
40      /** Name. */
41      @SuppressWarnings("checkstyle:visibilitymodifier")
42      String name = null;
43  
44      /** Orientation. */
45      @SuppressWarnings("checkstyle:visibilitymodifier")
46      String orientation = null;
47  
48      /** The zOffset. */
49      @SuppressWarnings("checkstyle:visibilitymodifier")
50      Length zOffset = null;
51  
52      /** Type. */
53      @SuppressWarnings("checkstyle:visibilitymodifier")
54      String type = null;
55  
56      /** Valid length. */
57      @SuppressWarnings("checkstyle:visibilitymodifier")
58      Length validLength = null;
59  
60      /** Length. */
61      @SuppressWarnings("checkstyle:visibilitymodifier")
62      Length length = null;
63  
64      /** Width. */
65      @SuppressWarnings("checkstyle:visibilitymodifier")
66      Length width = null;
67  
68      /** Height. */
69      @SuppressWarnings("checkstyle:visibilitymodifier")
70      Length height = null;
71  
72      /** The hdg. */
73      @SuppressWarnings("checkstyle:visibilitymodifier")
74      Angle hdg = null;
75  
76      /** Pitch. */
77      @SuppressWarnings("checkstyle:visibilitymodifier")
78      Angle pitch = null;
79  
80      /** Roll. */
81      @SuppressWarnings("checkstyle:visibilitymodifier")
82      Angle roll = null;
83  
84      /**
85       * Parse the attributes of the road.type tag. The sub-elements are parsed in separate classes.
86       * @param node Node; the node with signal information
87       * @param parser OpenDriveNetworkLaneParser; the parser with the lists of information
88       * @return the constructed SignalTag
89       * @throws SAXException when parsing of the tag fails
90       * @throws NetworkException when parsing of the tag fails
91       */
92      @SuppressWarnings("checkstyle:needbraces")
93      static ObjectTag parseObject(final Node node, final OpenDriveNetworkLaneParser parser) throws SAXException, NetworkException
94      {
95          ObjectTag objectTag = new ObjectTag();
96          NamedNodeMap attributes = node.getAttributes();
97  
98          Node s = attributes.getNamedItem("s");
99          if (s != null)
100             objectTag.s = new Length(Double.parseDouble(s.getNodeValue().trim()), LengthUnit.METER);
101 
102         Node t = attributes.getNamedItem("t");
103         if (t != null)
104             objectTag.t = new Length(Double.parseDouble(t.getNodeValue().trim()), LengthUnit.METER);
105 
106         Node id = attributes.getNamedItem("id");
107         if (id != null)
108             objectTag.id = id.getNodeValue().trim();
109 
110         Node name = attributes.getNamedItem("name");
111         if (name != null)
112             objectTag.name = name.getNodeValue().trim();
113 
114         Node orientation = attributes.getNamedItem("orientation");
115         if (orientation != null)
116             objectTag.orientation = orientation.getNodeValue().trim();
117 
118         Node zOffset = attributes.getNamedItem("zOffset");
119         if (zOffset != null)
120             objectTag.zOffset = new Length(Double.parseDouble(zOffset.getNodeValue().trim()), LengthUnit.METER);
121 
122         Node type = attributes.getNamedItem("type");
123         if (type != null)
124             objectTag.type = type.getNodeValue().trim();
125 
126         Node validLength = attributes.getNamedItem("validLength");
127         if (validLength != null)
128             objectTag.validLength = new Length(Double.parseDouble(validLength.getNodeValue().trim()), LengthUnit.METER);
129 
130         Node length = attributes.getNamedItem("length");
131         if (length != null)
132             objectTag.length = new Length(Double.parseDouble(length.getNodeValue().trim()), LengthUnit.METER);
133 
134         Node width = attributes.getNamedItem("width");
135         if (width != null)
136             objectTag.width = new Length(Double.parseDouble(width.getNodeValue().trim()), LengthUnit.METER);
137 
138         Node height = attributes.getNamedItem("height");
139         if (height != null)
140             objectTag.height = new Length(Double.parseDouble(height.getNodeValue().trim()), LengthUnit.METER);
141 
142         Node hdg = attributes.getNamedItem("hdg");
143         if (hdg != null)
144             objectTag.hdg = new Angle(Double.parseDouble(hdg.getNodeValue().trim()), AngleUnit.RADIAN);
145 
146         Node pitch = attributes.getNamedItem("pitch");
147         if (pitch != null)
148             objectTag.pitch = new Angle(Double.parseDouble(pitch.getNodeValue().trim()), AngleUnit.RADIAN);
149 
150         Node roll = attributes.getNamedItem("roll");
151         if (roll != null)
152             objectTag.roll = new Angle(Double.parseDouble(roll.getNodeValue().trim()), AngleUnit.RADIAN);
153 
154         return objectTag;
155 
156     }
157 
158     /** {@inheritDoc} */
159     @Override
160     public final String toString()
161     {
162         return "ObjectTag [s=" + this.s + ", t=" + this.t + ", id=" + this.id + ", name=" + this.name + ", orientation="
163                 + this.orientation + ", zOffset=" + this.zOffset + ", type=" + this.type + ", validLength=" + this.validLength
164                 + ", length=" + this.length + ", width=" + this.width + ", height=" + this.height + ", hdg=" + this.hdg
165                 + ", pitch=" + this.pitch + ", roll=" + this.roll + "]";
166     }
167 }