View Javadoc
1   package org.opentrafficsim.road.network.factory;
2   
3   import java.awt.geom.Rectangle2D;
4   import java.awt.geom.Rectangle2D.Double;
5   import java.io.IOException;
6   import java.net.URL;
7   import java.util.ArrayList;
8   
9   import javax.naming.NamingException;
10  import javax.swing.JPanel;
11  import javax.swing.SwingUtilities;
12  import javax.xml.parsers.ParserConfigurationException;
13  
14  import nl.tudelft.simulation.dsol.SimRuntimeException;
15  import nl.tudelft.simulation.dsol.simulators.SimulatorInterface;
16  import nl.tudelft.simulation.language.io.URLResource;
17  
18  import org.djunits.unit.TimeUnit;
19  import org.djunits.value.vdouble.scalar.DoubleScalar;
20  import org.opentrafficsim.core.dsol.OTSDEVSSimulatorInterface;
21  import org.opentrafficsim.core.dsol.OTSModelInterface;
22  import org.opentrafficsim.core.dsol.OTSSimTimeDouble;
23  import org.opentrafficsim.core.geometry.OTSGeometryException;
24  import org.opentrafficsim.core.gtu.GTUException;
25  import org.opentrafficsim.core.gtu.animation.GTUColorer;
26  import org.opentrafficsim.core.network.NetworkException;
27  import org.opentrafficsim.road.network.factory.opendrive.OpenDriveNetworkLaneParser;
28  import org.opentrafficsim.simulationengine.AbstractWrappableAnimation;
29  import org.opentrafficsim.simulationengine.properties.AbstractProperty;
30  import org.xml.sax.SAXException;
31  
32  /**
33   * <p>
34   * Copyright (c) 2013-2015 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
35   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
36   * <p>
37   * $LastChangedDate: 2015-08-05 15:55:21 +0200 (Wed, 05 Aug 2015) $, @version $Revision: 1199 $, by $Author: averbraeck $,
38   * initial version Oct 17, 2014 <br>
39   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
40   */
41  public class TestOpenDriveParser extends AbstractWrappableAnimation
42  {
43      /**
44       * Main program.
45       * @param args String[]; the command line arguments (not used)
46       * @throws SimRuntimeException should never happen
47       */
48      public static void main(final String[] args) throws SimRuntimeException
49      {
50          SwingUtilities.invokeLater(new Runnable()
51          {
52              @Override
53              public void run()
54              {
55                  try
56                  {
57                      TestOpenDriveParser xmlModel = new TestOpenDriveParser();
58                      // 1 hour simulation run for testing
59                      xmlModel.buildAnimator(new Time.Abs(0.0, SECOND), new Time.Rel(0.0, SECOND),
60                          new Time.Rel(60.0, MINUTE), new ArrayList<AbstractProperty<?>>(), null, true);
61                  }
62                  catch (SimRuntimeException | NamingException exception)
63                  {
64                      exception.printStackTrace();
65                  }
66              }
67          });
68      }
69  
70      /** {@inheritDoc} */
71      @Override
72      public final String shortName()
73      {
74          return "TestOpenDriveModel";
75      }
76  
77      /** {@inheritDoc} */
78      @Override
79      public final String description()
80      {
81          return "TestOpenDriveModel";
82      }
83  
84      /** {@inheritDoc} */
85      @Override
86      public final void stopTimersThreads()
87      {
88          super.stopTimersThreads();
89      }
90  
91      /** {@inheritDoc} */
92      @Override
93      protected final JPanel makeCharts()
94      {
95          return null;
96      }
97  
98      /** {@inheritDoc} */
99      @Override
100     protected final OTSModelInterface makeModel(final GTUColorer colorer)
101     {
102         return new TestOpenDriveModel();
103     }
104 
105     /** {@inheritDoc} */
106     @Override
107     protected final Double makeAnimationRectangle()
108     {
109         return new Rectangle2D.Double(-1000, -1000, 2000, 2000);
110     }
111 
112     /**
113      * Model to test the XML parser.
114      * <p>
115      * Copyright (c) 2013-2015 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. <br>
116      * All rights reserved. BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim
117      * License</a>.
118      * <p>
119      * $LastChangedDate: 2015-08-05 15:55:21 +0200 (Wed, 05 Aug 2015) $, @version $Revision: 1199 $, by $Author: averbraeck $,
120      * initial version un 27, 2015 <br>
121      * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
122      * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
123      */
124     class TestOpenDriveModel implements OTSModelInterface
125     {
126         /** */
127         private static final long serialVersionUID = 20150811L;
128 
129         /** the simulator. */
130         private OTSDEVSSimulatorInterface simulator;
131 
132         /** {@inheritDoc} */
133         @Override
134         public final void constructModel(
135             final SimulatorInterface<DoubleScalar.Abs<TimeUnit>, DoubleScalar.Rel<TimeUnit>, OTSSimTimeDouble> pSimulator)
136             throws SimRuntimeException
137         {
138             this.simulator = (OTSDEVSSimulatorInterface) pSimulator;
139             URL url = URLResource.getResource("/testod.xodr");
140             OpenDriveNetworkLaneParser nlp = new OpenDriveNetworkLaneParser(this.simulator);
141             try
142             {
143                 nlp.build(url);
144             }
145             catch (NetworkException | ParserConfigurationException | SAXException | IOException | NamingException
146                 | GTUException | OTSGeometryException exception)
147             {
148                 exception.printStackTrace();
149             }
150         }
151 
152         /** {@inheritDoc} */
153         @Override
154         public SimulatorInterface<DoubleScalar.Abs<TimeUnit>, DoubleScalar.Rel<TimeUnit>, OTSSimTimeDouble> getSimulator()
155             
156         {
157             return this.simulator;
158         }
159 
160     }
161 
162 }