1 package org.opentrafficsim.road.network.factory.xml;
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.gtu.animation.AccelerationGTUColorer;
8 import org.opentrafficsim.core.gtu.animation.GTUColorer;
9 import org.opentrafficsim.core.gtu.animation.IDGTUColorer;
10 import org.opentrafficsim.core.gtu.animation.SpeedGTUColorer;
11 import org.opentrafficsim.core.gtu.animation.SwitchableGTUColorer;
12 import org.xml.sax.SAXException;
13
14
15
16
17
18
19
20
21
22
23 final class GTUColorerTag
24 {
25
26 private GTUColorerTag()
27 {
28
29 }
30
31
32
33
34
35
36
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
61
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
74
75
76 static GTUColorer makeAccelerationGTUColorer(final GlobalTag globalTag)
77 {
78
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
85
86
87 static GTUColorer makeSwitchableGTUColorer(final GlobalTag globalTag)
88 {
89 GTUColorer[] gtuColorers =
90 new GTUColorer[] { new IDGTUColorer(), makeSpeedGTUColorer(globalTag), makeAccelerationGTUColorer(globalTag) };
91
92 return new SwitchableGTUColorer(0, gtuColorers);
93 }
94 }