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.core.dsol.AbstractOtsModel;
13 import org.opentrafficsim.core.dsol.OtsAnimator;
14 import org.opentrafficsim.core.dsol.OtsSimulatorInterface;
15 import org.opentrafficsim.core.gtu.Gtu;
16 import org.opentrafficsim.demo.conflict.TJunctionDemo.TJunctionModel;
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 TJunctionDemo extends OtsSimulationApplication<TJunctionModel>
36 {
37
38 private static final long serialVersionUID = 20161211L;
39
40
41
42
43
44
45
46
47 public TJunctionDemo(final String title, final OtsAnimationPanel panel, final TJunctionModel 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 Gtu.ALIGNED = false;
69 try
70 {
71 OtsAnimator simulator = new OtsAnimator("TJunctionDemo");
72 final TJunctionModel junctionModel = new TJunctionModel(simulator);
73 simulator.initialize(Time.ZERO, Duration.ZERO, Duration.instantiateSI(3600.0), junctionModel);
74 OtsAnimationPanel animationPanel = new OtsAnimationPanel(junctionModel.getNetwork().getExtent(),
75 new Dimension(800, 600), simulator, junctionModel, DEFAULT_COLORER, junctionModel.getNetwork());
76 TJunctionDemo app = new TJunctionDemo("T-Junction 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 TJunctionModel extends AbstractOtsModel
90 {
91
92 private static final long serialVersionUID = 20161211L;
93
94
95 private RoadNetwork network;
96
97
98
99
100 public TJunctionModel(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/TJunction.xml");
112 this.network = new RoadNetwork("TJunction", getSimulator());
113 new XmlParser(this.network).setUrl(xmlURL).setScenario("1").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 }