1 package org.opentrafficsim.demo.conflict;
2
3 import java.awt.Dimension;
4 import java.net.URL;
5 import java.rmi.RemoteException;
6
7 import javax.naming.NamingException;
8
9 import org.djunits.value.vdouble.scalar.Duration;
10 import org.djunits.value.vdouble.scalar.Time;
11 import org.djutils.io.URLResource;
12 import org.opentrafficsim.animation.gtu.colorer.DefaultSwitchableGtuColorer;
13 import org.opentrafficsim.core.dsol.AbstractOtsModel;
14 import org.opentrafficsim.core.dsol.OtsAnimator;
15 import org.opentrafficsim.core.dsol.OtsSimulatorInterface;
16 import org.opentrafficsim.demo.conflict.TurboRoundaboutDemo.TurboRoundaboutModel;
17 import org.opentrafficsim.draw.OtsDrawingException;
18 import org.opentrafficsim.road.network.RoadNetwork;
19 import org.opentrafficsim.road.network.factory.xml.parser.XmlParser;
20 import org.opentrafficsim.swing.gui.OtsAnimationPanel;
21 import org.opentrafficsim.swing.gui.OtsSimulationApplication;
22
23 import nl.tudelft.simulation.dsol.SimRuntimeException;
24 import nl.tudelft.simulation.language.DsolException;
25
26
27
28
29
30
31
32
33
34
35 public class TurboRoundaboutDemo extends OtsSimulationApplication<TurboRoundaboutModel>
36 {
37
38 private static final long serialVersionUID = 20161211L;
39
40
41
42
43
44
45
46
47 public TurboRoundaboutDemo(final String title, final OtsAnimationPanel panel, final TurboRoundaboutModel model)
48 throws OtsDrawingException
49 {
50 super(model, panel);
51 }
52
53
54
55
56
57 public static void main(final String[] args)
58 {
59 demo(true);
60 }
61
62
63
64
65
66 public static void demo(final boolean exitOnClose)
67 {
68 try
69 {
70 OtsAnimator simulator = new OtsAnimator("TurboRoundaboutDemo");
71 final TurboRoundaboutModel junctionModel = new TurboRoundaboutModel(simulator);
72 simulator.initialize(Time.ZERO, Duration.ZERO, Duration.instantiateSI(3600.0), junctionModel);
73 OtsAnimationPanel animationPanel =
74 new OtsAnimationPanel(junctionModel.getNetwork().getExtent(), new Dimension(800, 600), simulator,
75 junctionModel, new DefaultSwitchableGtuColorer(), junctionModel.getNetwork());
76 TurboRoundaboutDemo app = new TurboRoundaboutDemo("Turbo-Roundabout demo", animationPanel, junctionModel);
77 app.setExitOnClose(exitOnClose);
78 animationPanel.enableSimulationControlButtons();
79 }
80 catch (SimRuntimeException | NamingException | RemoteException | OtsDrawingException | DsolException exception)
81 {
82 exception.printStackTrace();
83 }
84 }
85
86
87
88
89 public static class TurboRoundaboutModel extends AbstractOtsModel
90 {
91
92 private static final long serialVersionUID = 20161211L;
93
94
95 private RoadNetwork network;
96
97
98
99
100 public TurboRoundaboutModel(final OtsSimulatorInterface simulator)
101 {
102 super(simulator);
103 }
104
105
106 @Override
107 public void constructModel() throws SimRuntimeException
108 {
109 try
110 {
111 URL xmlURL = URLResource.getResource("/resources/conflict/TurboRoundabout.xml");
112 this.network = new RoadNetwork("TurboRoundabout", getSimulator());
113 new XmlParser(this.network).setUrl(xmlURL).build();
114 }
115 catch (Exception exception)
116 {
117 exception.printStackTrace();
118 }
119 }
120
121
122 @Override
123 public RoadNetwork getNetwork()
124 {
125 return this.network;
126 }
127
128 }
129 }