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