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