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 FourStop 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 FourStop xmlModel = new FourStop();
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(-1000, -1000, 2000, 2000);
116 }
117
118
119 @Override
120 public String toString()
121 {
122 return "FourStop []";
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 URL url = URLResource.getResource("/4-stop.xml");
155 XmlNetworkLaneParser nlp = new XmlNetworkLaneParser(this.simulator);
156 try
157 {
158 nlp.build(url);
159 }
160 catch (NetworkException | ParserConfigurationException | SAXException | IOException | NamingException
161 | GTUException | OTSGeometryException exception)
162 {
163 exception.printStackTrace();
164 }
165 }
166
167
168 @Override
169 public SimulatorInterface<DoubleScalar.Abs<TimeUnit>, DoubleScalar.Rel<TimeUnit>, OTSSimTimeDouble>
170 getSimulator()
171
172 {
173 return this.simulator;
174 }
175
176
177 @Override
178 public final String toString()
179 {
180 return "TestXMLModel [simulator=" + this.simulator + "]";
181 }
182
183 }
184
185 }