1 package org.opentrafficsim.road.network.factory.xml.old;
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
16
17
18
19
20
21
22
23 final class GTUColorerTag
24 {
25
26 private GTUColorerTag()
27 {
28
29 }
30
31
32
33 static GTUColorer defaultColorer = null;
34
35
36
37
38
39
40
41
42 static GTUColorer parseGTUColorer(final String name, final GlobalTag globalTag) throws SAXException
43 {
44 switch (name)
45 {
46 case "ID":
47 return new IDGTUColorer();
48
49 case "SPEED":
50 return makeSpeedGTUColorer(globalTag);
51
52 case "ACCELERATION":
53 return makeAccelerationGTUColorer(globalTag);
54
55 case "SWITCHABLE":
56 return makeSwitchableGTUColorer(globalTag);
57
58 default:
59 throw new SAXException("GTUCOLORER: unknown name " + name + " not one of ID|SPEED|ACCELERATION|SWITCHABLE");
60 }
61 }
62
63
64
65
66
67 static GTUColorer makeSpeedGTUColorer(final GlobalTag globalTag)
68 {
69 if (defaultColorer != null)
70 return defaultColorer;
71 if (globalTag.speedGTUColorerMaxSpeed != null)
72 {
73 return new SpeedGTUColorer(globalTag.speedGTUColorerMaxSpeed);
74 }
75 return new SpeedGTUColorer(new Speed(100.0, SpeedUnit.KM_PER_HOUR));
76 }
77
78
79
80
81
82 static GTUColorer makeAccelerationGTUColorer(final GlobalTag globalTag)
83 {
84 if (defaultColorer != null)
85 return defaultColorer;
86
87 return new AccelerationGTUColorer(new Acceleration(1.0, AccelerationUnit.METER_PER_SECOND_2),
88 new Acceleration(1.0, AccelerationUnit.METER_PER_SECOND_2));
89 }
90
91
92
93
94
95 static GTUColorer makeSwitchableGTUColorer(final GlobalTag globalTag)
96 {
97 if (defaultColorer != null)
98 return defaultColorer;
99 GTUColorer[] gtuColorers =
100 new GTUColorer[] {new IDGTUColorer(), makeSpeedGTUColorer(globalTag), makeAccelerationGTUColorer(globalTag)};
101
102 return new SwitchableGTUColorer(0, gtuColorers);
103 }
104 }