View Javadoc
1   package org.opentrafficsim.demo.geometry.shape;
2   
3   import java.rmi.RemoteException;
4   import java.util.HashMap;
5   import java.util.Map;
6   
7   import nl.tudelft.simulation.dsol.SimRuntimeException;
8   import nl.tudelft.simulation.dsol.simulators.SimulatorInterface;
9   
10  import org.djunits.unit.TimeUnit;
11  import org.djunits.value.vdouble.scalar.DoubleScalar;
12  import org.opentrafficsim.core.dsol.OTSDEVSSimulatorInterface;
13  import org.opentrafficsim.core.dsol.OTSModelInterface;
14  import org.opentrafficsim.core.dsol.OTSSimTimeDouble;
15  import org.opentrafficsim.core.network.Link;
16  import org.opentrafficsim.core.network.OTSNode;
17  
18  /**
19   * <p>
20   * Copyright (c) 2013-2015 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
21   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
22   * <p>
23   * $LastChangedDate: 2016-04-05 21:30:47 +0200 (Tue, 05 Apr 2016) $, @version $Revision: 1889 $, by $Author: pknoppers $,
24   * initial version Sep 9, 2014 <br>
25   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
26   * @author <a href="http://www.citg.tudelft.nl">Guus Tamminga</a>
27   */
28  public class ShapeModel implements OTSModelInterface
29  {
30      /** */
31      private static final long serialVersionUID = 20140815L;
32  
33      /** The simulator. */
34      private OTSDEVSSimulatorInterface simulator;
35  
36      /** Nodes from shape file. */
37      private Map<String, OTSNode> nodes;
38  
39      /** Links from shape file. */
40      private Map<String, Link> shpLinks;
41  
42      /** {@inheritDoc} */
43      @Override
44      public final
45          void
46          constructModel(
47              final SimulatorInterface<DoubleScalar.Abs<TimeUnit>, DoubleScalar.Rel<TimeUnit>, OTSSimTimeDouble> theSimulator)
48              throws SimRuntimeException, RemoteException
49      {
50          this.simulator = (OTSDEVSSimulatorInterface) theSimulator;
51          try
52          {
53              // Read the shape files with the function:
54              this.nodes = ShapeFileReader.readNodes("/gis/TESTcordonnodes.shp", "NODENR", true, true);
55              this.shpLinks = new HashMap<>();
56              ShapeFileReader.readLinks("/gis/TESTcordonlinks_aangevuld.shp", this.shpLinks, this.nodes, this.simulator);
57  
58              this.simulator.scheduleEventAbs(new DoubleScalar.Abs<TimeUnit>(0.0, TimeUnit.SECOND), this, this,
59                  "ntmFlowTimestep", null);
60          }
61          catch (Throwable exception)
62          {
63              exception.printStackTrace();
64          }
65      }
66  
67      /** {@inheritDoc} */
68      @Override
69      public final SimulatorInterface<DoubleScalar.Abs<TimeUnit>, DoubleScalar.Rel<TimeUnit>, OTSSimTimeDouble>
70          getSimulator() throws RemoteException
71      {
72          return this.simulator;
73      }
74  
75  }