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.xml.XmlNetworkLaneParser;
28 import org.opentrafficsim.simulationengine.AbstractWrappableAnimation;
29 import org.opentrafficsim.simulationengine.properties.AbstractProperty;
30 import org.xml.sax.SAXException;
31
32
33
34
35
36
37
38
39
40
41 public class TestXMLParser extends AbstractWrappableAnimation
42 {
43
44
45
46
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 TestXMLParser xmlModel = new TestXMLParser();
58
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
71 @Override
72 public final String shortName()
73 {
74 return "TestXMLModel";
75 }
76
77
78 @Override
79 public final String description()
80 {
81 return "TestXMLModel";
82 }
83
84
85 @Override
86 public final void stopTimersThreads()
87 {
88 super.stopTimersThreads();
89 }
90
91
92 @Override
93 protected final JPanel makeCharts()
94 {
95 return null;
96 }
97
98
99 @Override
100 protected final OTSModelInterface makeModel(final GTUColorer colorer)
101 {
102 return new TestXMLModel();
103 }
104
105
106 @Override
107 protected final Double makeAnimationRectangle()
108 {
109 return new Rectangle2D.Double(-1000, -1000, 2000, 2000);
110 }
111
112
113
114
115
116
117
118
119
120
121
122
123
124 class TestXMLModel implements OTSModelInterface
125 {
126
127 private static final long serialVersionUID = 20141121L;
128
129
130 private OTSDEVSSimulatorInterface simulator;
131
132
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
140
141 URL url = URLResource.getResource("/circular-road-new-gtu-example.xml");
142
143 XmlNetworkLaneParser nlp = new XmlNetworkLaneParser(this.simulator);
144 try
145 {
146 nlp.build(url);
147 }
148 catch (NetworkException | ParserConfigurationException | SAXException | IOException | NamingException
149 | GTUException | OTSGeometryException exception)
150 {
151 exception.printStackTrace();
152 }
153 }
154
155
156 @Override
157 public SimulatorInterface<DoubleScalar.Abs<TimeUnit>, DoubleScalar.Rel<TimeUnit>, OTSSimTimeDouble> getSimulator()
158
159 {
160 return this.simulator;
161 }
162
163 }
164
165 }