View Javadoc
1   package org.opentrafficsim.road.network.factory.vissim;
2   
3   import org.djunits.unit.AccelerationUnit;
4   import org.djunits.unit.SpeedUnit;
5   import org.djunits.value.vdouble.scalar.Acceleration;
6   import org.djunits.value.vdouble.scalar.Speed;
7   import org.opentrafficsim.core.animation.gtu.colorer.AccelerationGTUColorer;
8   import org.opentrafficsim.core.animation.gtu.colorer.GTUColorer;
9   import org.opentrafficsim.core.animation.gtu.colorer.IDGTUColorer;
10  import org.opentrafficsim.core.animation.gtu.colorer.SpeedGTUColorer;
11  import org.opentrafficsim.core.animation.gtu.colorer.SwitchableGTUColorer;
12  import org.xml.sax.SAXException;
13  
14  /**
15   * <p>
16   * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
17   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
18   * <p>
19   * $LastChangedDate: 2019-03-16 19:17:15 +0100 (Sat, 16 Mar 2019) $, @version $Revision: 5157 $, by $Author: averbraeck $,
20   * initial version Jul 28, 2015 <br>
21   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
22   */
23  final class GTUColorerTag
24  {
25      /** Utility class. */
26      private GTUColorerTag()
27      {
28          // do not instantiate
29      }
30  
31      /**
32       * Parses the right GTUColorer from ID|SPEED|ACCELERATION|LANECHANGEURGE|SWITCHABLE.
33       * @param name String; name of the GTUColorer
34       * @param globalTag GlobalTag; to define the default parameters of the colorers
35       * @return the corresponding GTUColorer
36       * @throws SAXException in case the name does not correspond to a known GTUColorer
37       */
38      static GTUColorer parseGTUColorer(final String name, final GlobalTag globalTag) throws SAXException
39      {
40          switch (name)
41          {
42              case "ID":
43                  return new IDGTUColorer();
44  
45              case "SPEED":
46                  return makeSpeedGTUColorer(globalTag);
47  
48              case "ACCELERATION":
49                  return makeAccelerationGTUColorer(globalTag);
50  
51              case "SWITCHABLE":
52                  return makeSwitchableGTUColorer(globalTag);
53  
54              default:
55                  throw new SAXException("GTUCOLORER: unknown name " + name + " not one of ID|SPEED|ACCELERATION|SWITCHABLE");
56          }
57      }
58  
59      /**
60       * @param globalTag GlobalTag; to define the default parameters of the colorers
61       * @return the corresponding GTUColorer
62       */
63      static GTUColorer makeSpeedGTUColorer(final GlobalTag globalTag)
64      {
65          if (globalTag.speedGTUColorerMaxSpeed != null)
66          {
67              return new SpeedGTUColorer(globalTag.speedGTUColorerMaxSpeed);
68          }
69          return new SpeedGTUColorer(new Speed(100.0, SpeedUnit.KM_PER_HOUR));
70      }
71  
72      /**
73       * @param globalTag GlobalTag; to define the default parameters of the colorers
74       * @return the corresponding GTUColorer
75       */
76      static GTUColorer makeAccelerationGTUColorer(final GlobalTag globalTag)
77      {
78          // TODO use parameters for AccelerationGTUColorer
79          return new AccelerationGTUColorer(new Acceleration(1.0, AccelerationUnit.METER_PER_SECOND_2),
80                  new Acceleration(1.0, AccelerationUnit.METER_PER_SECOND_2));
81      }
82  
83      /**
84       * @param globalTag GlobalTag; to define the default parameters of the colorers
85       * @return the corresponding GTUColorer
86       */
87      static GTUColorer makeSwitchableGTUColorer(final GlobalTag globalTag)
88      {
89          GTUColorer[] gtuColorers =
90                  new GTUColorer[] {new IDGTUColorer(), makeSpeedGTUColorer(globalTag), makeAccelerationGTUColorer(globalTag)};
91          // TODO default colorer
92          return new SwitchableGTUColorer(0, gtuColorers);
93      }
94  }