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