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.opentrafficsim.core.dsol.OTSDEVSSimulatorInterface;
11  import org.opentrafficsim.core.dsol.OTSModelInterface;
12  import org.opentrafficsim.core.dsol.OTSSimTimeDouble;
13  import org.opentrafficsim.core.network.factory.Link;
14  import org.opentrafficsim.core.network.factory.Node;
15  import org.opentrafficsim.core.unit.TimeUnit;
16  import org.opentrafficsim.core.value.vdouble.scalar.DoubleScalar;
17  
18  /**
19   * <p>
20   * Copyright (c) 2013-2014 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/node/13">OpenTrafficSim License</a>.
22   * <p>
23   * @version Sep 9, 2014 <br>
24   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
25   * @author <a href="http://www.citg.tudelft.nl">Guus Tamminga</a>
26   */
27  public class ShapeModel implements OTSModelInterface
28  {
29      /** */
30      private static final long serialVersionUID = 20140815L;
31  
32      /** the simulator. */
33      private OTSDEVSSimulatorInterface simulator;
34  
35      /** nodes from shape file. */
36      private Map<String, Node> nodes;
37  
38      /** links from shape file. */
39      private Map<String, Link> shpLinks;
40  
41      /** {@inheritDoc} */
42      @Override
43      public final void constructModel(
44          final SimulatorInterface<DoubleScalar.Abs<TimeUnit>, DoubleScalar.Rel<TimeUnit>, OTSSimTimeDouble> theSimulator)
45          throws SimRuntimeException, RemoteException
46      {
47          this.simulator = (OTSDEVSSimulatorInterface) theSimulator;
48          try
49          {
50              // Read the shape files with the function:
51              this.nodes = ShapeFileReader.ReadNodes("/gis/TESTcordonnodes.shp", "NODENR", true, true);
52              this.shpLinks = new HashMap<>();
53              ShapeFileReader.readLinks("/gis/TESTcordonlinks_aangevuld.shp", this.shpLinks, this.nodes, this.simulator);
54  
55              this.simulator.scheduleEventAbs(new DoubleScalar.Abs<TimeUnit>(0.0, TimeUnit.SECOND), this, this,
56                  "ntmFlowTimestep", null);
57          }
58          catch (Throwable exception)
59          {
60              exception.printStackTrace();
61          }
62      }
63  
64      /** {@inheritDoc} */
65      @Override
66      public final SimulatorInterface<DoubleScalar.Abs<TimeUnit>, DoubleScalar.Rel<TimeUnit>, OTSSimTimeDouble> getSimulator()
67          throws RemoteException
68      {
69          return this.simulator;
70      }
71  
72  }