1 package org.opentrafficsim.road.test;
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.djunits.value.vdouble.scalar.Duration;
21 import org.djunits.value.vdouble.scalar.Time;
22 import org.opentrafficsim.core.dsol.OTSDEVSSimulatorInterface;
23 import org.opentrafficsim.core.dsol.OTSModelInterface;
24 import org.opentrafficsim.core.dsol.OTSSimTimeDouble;
25 import org.opentrafficsim.core.geometry.OTSGeometryException;
26 import org.opentrafficsim.core.gtu.GTUException;
27 import org.opentrafficsim.core.gtu.animation.GTUColorer;
28 import org.opentrafficsim.core.network.NetworkException;
29 import org.opentrafficsim.road.network.factory.xml.XmlNetworkLaneParser;
30 import org.opentrafficsim.simulationengine.AbstractWrappableAnimation;
31 import org.opentrafficsim.simulationengine.OTSSimulationException;
32 import org.opentrafficsim.simulationengine.properties.AbstractProperty;
33 import org.opentrafficsim.simulationengine.properties.PropertyException;
34 import org.xml.sax.SAXException;
35
36
37
38
39
40
41
42
43
44
45
46
47 public class LMRSTests extends AbstractWrappableAnimation
48 {
49
50
51
52
53
54 public static void main(final String[] args) throws SimRuntimeException
55 {
56 SwingUtilities.invokeLater(new Runnable()
57 {
58 @Override
59 public void run()
60 {
61 try
62 {
63 LMRSTests xmlModel = new LMRSTests();
64
65 xmlModel.buildAnimator(new Time(0.0, TimeUnit.SECOND), new Duration(0.0, TimeUnit.SECOND),
66 new Duration(60.0, TimeUnit.MINUTE), new ArrayList<AbstractProperty<?>>(), null, true);
67 }
68 catch (SimRuntimeException | NamingException | OTSSimulationException | PropertyException exception)
69 {
70 exception.printStackTrace();
71 }
72 }
73 });
74 }
75
76
77 @Override
78 public final String shortName()
79 {
80 return "TestXMLModel";
81 }
82
83
84 @Override
85 public final String description()
86 {
87 return "TestXMLModel";
88 }
89
90
91 @Override
92 public final void stopTimersThreads()
93 {
94 super.stopTimersThreads();
95 }
96
97
98 @Override
99 protected final JPanel makeCharts()
100 {
101 return null;
102 }
103
104
105 @Override
106 protected final OTSModelInterface makeModel(final GTUColorer colorer)
107 {
108 return new TestXMLModel();
109 }
110
111
112 @Override
113 protected final Double makeAnimationRectangle()
114 {
115 return new Rectangle2D.Double(-100, -100, 3200, 200);
116 }
117
118
119 @Override
120 public String toString()
121 {
122 return "LMRSTests []";
123 }
124
125
126
127
128
129
130
131
132
133
134
135
136
137 class TestXMLModel implements OTSModelInterface
138 {
139
140 private static final long serialVersionUID = 20141121L;
141
142
143 private OTSDEVSSimulatorInterface simulator;
144
145
146 @Override
147 public final
148 void
149 constructModel(
150 final SimulatorInterface<DoubleScalar.Abs<TimeUnit>, DoubleScalar.Rel<TimeUnit>, OTSSimTimeDouble> pSimulator)
151 throws SimRuntimeException
152 {
153 this.simulator = (OTSDEVSSimulatorInterface) pSimulator;
154
155
156 URL url = URLResource.getResource("/LMRSOnRampTest.xml");
157
158
159 XmlNetworkLaneParser nlp = new XmlNetworkLaneParser(this.simulator);
160 try
161 {
162 nlp.build(url);
163 }
164 catch (NetworkException | ParserConfigurationException | SAXException | IOException | NamingException
165 | GTUException | OTSGeometryException exception)
166 {
167 exception.printStackTrace();
168 }
169 }
170
171
172 @Override
173 public SimulatorInterface<DoubleScalar.Abs<TimeUnit>, DoubleScalar.Rel<TimeUnit>, OTSSimTimeDouble>
174 getSimulator()
175
176 {
177 return this.simulator;
178 }
179
180
181 @Override
182 public final String toString()
183 {
184 return "TestXMLModel [simulator=" + this.simulator + "]";
185 }
186
187 }
188
189 }