forked from movsim/traffic-simulation-de
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTODO_trafficObjects
More file actions
155 lines (94 loc) · 4.26 KB
/
TODO_trafficObjects
File metadata and controls
155 lines (94 loc) · 4.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
class:
TrafficObjects unifies ObstacleTLDepot.js and SpeedFunnel.js
(2019-10-02)
Nearly finished!!
2 bugs still there
(1) 3 instead of 2 signs drawn OK
(2) traffic light cannot be switched still BUG
(3) obj deactivate if only clicked, not dragged: wrong!
use isDragged: Deactivate objects on road only if isDragged=true;
Don't set isDragged=false in TrafficObjects! that is
the responsibility of canvas_gui!
onmousemove="handleMouseMove(event)"
onmousedown="handleMouseDown(event)"
onmouseup="handleMouseUp(event)"
onclick="handleClick(event)"
(4) du in TrafficObjects.js erroneously also used for traffic
lights/signs OK
===================================================
GENERAL
Main data element:
an array traffObj[]. Each traffObj[i] has elements as in ObstacleTLDepot.js
* id: unique ID
* type: one of "speedLimit", "trafficLight", "obstacle"
there are nObj=nObst+nTL+nSpeedl objects
* isActive: if dropped onto a road (otherwise, it is in the depot or
dragged or zooming back)
* value: speedlimit_ms, "red"/"green", or "n.a." (if obstacle)
* road (reference if active, null otherwise)
Main methods:
(0) constructor defining nObst+nTL+nSpeedl
(1) graphical operations such as drag, zoomBack reuse from
SpeedFunnel, not ObstacleTL
(2a) selectByUser(xPixUser, yPixUser, distCritPix)
-> [success, 'null' or object]
* take directly from ObstacleDepot.pickObject
(2b) selectById(id)
-> [success, 'null' or object]
[(2c) selectByRoadCoords(road,u,v)]
(3a) activateObject(object, road)
* sets object.road reference
* if object.type==='trafficLight' then road.addTrafficLight(object)
* (optionally) calls road.updateTrafficObjects(this) (not necessary
since done timestep oriented in next timestep anyway)
calls appropriate road.activateTrafficLight, road.activateSpeedLimit,
road.putObstacle according to the type and the value (creates special vehicle
objects and/or propagate parameters to the vehicle models).
The road and object are known from the callers:
(i) mouse drop->dropObject method
(ii) programmatic activation during the initialization
(3b) deactivateObject(object)
calls appropriate road.deactivate* routines if object id is active
(then, it knows "his" road)
(4) road.updateTrafficObjects(this)
* Special case: called in main simulation loop
timestep-based (needed for speed limits etc when vehs cross the u
coordinate of an object)
* timestep-based, not event-oriented=> road is
caller, not trafficObjects.
* Up to now completely covered in road.prototype.updateSpeedFunnel
GUI callbacks
(5a) onmousedown callback: pickObject(xPixUser, yPixUser, distCritPix)
-> [success, null or object]
* template from ObstacleTLDepot.js
* uses selectByUser
* if success -> object defined{
* if object.inDepot, just change internal state (isDragged etc)
* if (object.isActive&&(object.type==='trafficLight))
then object.isActive=false; road.removeTrafficLight(object.id)
* if (object.isActive&&(object.type==='trafficLight))
then object.isActive=false; road.removeObstacle(object.id)
(5b) onmouseup callback: dropObject(object, xPixUser, yPixUser,
distCritPix, network)
* determines nearest road from network -> road
* if !nearer to road center than distCritPix -> zoomback
* if nearer than distCritPix:
* set isActive=true;
* calculate u,v from graphics (shift by one obstacle length for
obstacles)
* if object.type==='obstacle' then road.dropDepotObject(...)
-> road.dropObject
* if object.type==='trafficLight' then road.addTrafficLight(object)
-> road.dropObject
* if object.type==='speedLimit' no action needed because of
timestep-based road.updateSpeedFunnel (in contrast to obstacles
and TLs, speed limits do not introduce vehicle-like objects but
change the vehicle model characteristics themselves)
-> road.dropObject
(5c) onclick callback: changeValue(object,newValue)
* sets new value
* sets isActive (indirectly new graphical appearance) if applicable
* If object.isActive&&(object.type==='trafficLight'),
road.changeTrafficLight(object.id, object.value)
* change of speed limit taken care of by road.updateTrafficObject in
next timestep