Debian Codegraph @

DataModel/Route.h

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 /*
2 RailControl - Model Railway Control Software
3
4 Copyright (c) 2017-2025 by Teddy / Dominik Mahrer - www.railcontrol.org
5
6 RailControl is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 3, or (at your option) any
9 later version.
10
11 RailControl is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 See the GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with RailControl; see the file LICENCE. If not see
18 <http://www.gnu.org/licenses/>.
19 */
20
21 #pragma once
22
23 #include <mutex>
24 #include <string>
25 #include <vector>
26
27 #include "DataTypes.h"
28 #include "DataModel/LayoutItem.h"
29 #include "DataModel/LockableItem.h"
30 #include "DataModel/ObjectIdentifier.h"
31 #include "Logger/Logger.h"
32
33 class Manager;
34
35 namespace DataModel
36 {
37 class LocoBase;
38 class Relation;
39
40 class Route : public LayoutItem, public LockableItem
41 {
42 public:
43 static const Delay DefaultDelay = 250;
44
45 enum PushpullType : unsigned char
46 {
47 PushpullTypeNo = 0,
48 PushpullTypeOnly = 1,
49 PushpullTypeBoth = 2
50 };
51
52 enum Speed : unsigned char
53 {
54 SpeedMax = 3,
55 SpeedTravel = 2,
56 SpeedReduced = 1,
57 SpeedCreeping = 0
58 };
59
60 Route() = delete;
61
62 Route(Manager* manager, const RouteID routeID)
63 : LayoutItem(routeID),
64 LockableItem(),
65 manager(manager),
66 executeAtUnlock(false),
67 delay(0),
68 pushpull(PushpullTypeBoth),
69 propulsion(PropulsionUnknown),
70 trainType(TrainTypeAll),
71 minTrainLength(0),
72 maxTrainLength(0),
73 automode(AutomodeNo),
74 fromTrack(),
75 fromOrientation(OrientationRight),
76 toTrack(),
77 toOrientation(OrientationRight),
78 speed(SpeedTravel),
79 feedbackIdReduced(FeedbackNone),
80 reducedDelay(0),
81 feedbackIdCreep(FeedbackNone),
82 creepDelay(0),
83 feedbackIdStop(FeedbackNone),
84 stopDelay(0),
85 feedbackIdOver(FeedbackNone),
86 waitAfterRelease(0),
87 lastUsed(0),
88 counter(0)
89 {
•90 SetRotation(LayoutItem::Rotation0);
91 }
92
93 Route(Manager* manager, const std::string& serialized);
94
95 inline ~Route()
96 {
97 DeleteRelations(relationsAtLock);
98 DeleteRelations(relationsAtUnlock);
99 }
100
101 inline ObjectType GetObjectType() const override
102 {
103 return ObjectTypeRoute;
104 }
105
106 std::string Serialize() const override;
•107 void Deserialize(const std::string& serialized) override;
108
109 inline std::string GetLayoutType() const override
110 {
111 return Languages::GetText(Languages::TextRoute);
112 }
113
114 inline void DeleteRelationsAtLock()
115 {
116 DeleteRelations(relationsAtLock);
117 }
118
119 inline void DeleteRelationsAtUnlock()
120 {
121 DeleteRelations(relationsAtUnlock);
122 }
123
124 inline bool AssignRelationsAtLock(const std::vector<DataModel::Relation*>& newRelations)
125 {
126 return AssignRelations(relationsAtLock, newRelations);
127 }
128
129 inline bool AssignRelationsAtUnlock(const std::vector<DataModel::Relation*>& newRelations)
130 {
131 return AssignRelations(relationsAtUnlock, newRelations);
132 }
133
134 inline const std::vector<DataModel::Relation*>& GetRelationsAtLock() const
135 {
136 return relationsAtLock;
137 }
138
139 inline const std::vector<DataModel::Relation*>& GetRelationsAtUnlock() const
140 {
141 return relationsAtUnlock;
142 }
143
144 bool FromTrackOrientation(Logger::Logger* logger,
145 const TrackID trackID,
146 const Orientation trackOrientation,
147 const DataModel::LocoBase* loco,
148 const bool allowLocoTurn);
149
150 bool Execute(Logger::Logger* logger, const ObjectIdentifier& locoBaseIdentifier);
151
152 inline static bool ExecuteStatic(Logger::Logger* logger, Route* route)
153 {
154 return route->Execute(logger, ObjectIdentifier());
155 }
156
157 bool Reserve(Logger::Logger* logger, const ObjectIdentifier& locoBaseIdentifier) override;
158
159 bool Lock(Logger::Logger* logger, const ObjectIdentifier& locoBaseIdentifier) override;
160
161 bool Release(Logger::Logger* logger, const ObjectIdentifier& locoBaseIdentifier) override
162 {
163 std::lock_guard<std::mutex> Guard(updateMutex);
164 return ReleaseInternal(logger, locoBaseIdentifier);
165 }
166
167 inline Delay GetDelay() const
168 {
169 return delay;
170 }
171
172 inline void SetDelay(Delay delay)
173 {
174 this->delay = delay;
175 }
176
177 inline PushpullType GetPushpull() const
178 {
179 return pushpull;
180 }
181
182 inline void SetPushpull(const PushpullType pushpull)
183 {
184 this->pushpull = pushpull;
185 }
186
187 inline Propulsion GetPropulsion() const
188 {
189 return propulsion;
190 }
191
192 inline void SetPropulsion(const Propulsion propulsion)
193 {
194 this->propulsion = propulsion;
195 }
196
197 inline TrainType GetTrainType() const
198 {
199 return trainType;
200 }
201
202 inline void SetTrainType(const TrainType trainType)
203 {
204 this->trainType = trainType;
205 }
206
207 inline Length GetMinTrainLength() const
208 {
209 return minTrainLength;
210 }
211
212 inline void SetMinTrainLength(const Length length)
213 {
214 this->minTrainLength = length;
215 }
216
217 inline Length GetMaxTrainLength() const
218 {
219 return maxTrainLength;
220 }
221
222 inline void SetMaxTrainLength(const Length length)
223 {
224 this->maxTrainLength = length;
225 }
226
227 inline time_t GetLastUsed() const
228 {
229 return lastUsed;
230 }
231
232 inline void SetAutomode(const Automode automode)
233 {
234 this->automode = automode;
235 }
236
237 inline Automode GetAutomode() const
238 {
239 return automode;
240 }
241
242 inline void SetFromTrack(const TrackID fromTrack)
243 {
244 this->fromTrack = fromTrack;
245 }
246
247 inline TrackID GetFromTrack() const
248 {
249 return fromTrack;
250 }
251
252 inline void SetFromOrientation(const Orientation fromOrientation)
253 {
254 this->fromOrientation = fromOrientation;
255 }
256
257 inline Orientation GetFromOrientation() const
258 {
259 return fromOrientation;
260 }
261
262 inline void SetToTrack(const TrackID toTrack)
263 {
264 this->toTrack = toTrack;
265 }
266
267 inline TrackID GetToTrack() const
268 {
269 return toTrack;
270 }
271
272 inline void SetToOrientation(const Orientation toOrientation)
273 {
274 this->toOrientation = toOrientation;
275 }
276
277 inline Orientation GetToOrientation() const
278 {
279 return toOrientation;
280 }
281
282 inline void SetSpeed(Speed startSpeed)
283 {
284 this->speed = startSpeed;
285 }
286
287 inline Speed GetSpeed() const
288 {
289 return speed;
290 }
291
292 inline void SetFeedbackIdReduced(const FeedbackID feedbackIdReduced)
293 {
294 this->feedbackIdReduced = feedbackIdReduced;
295 }
296
297 inline FeedbackID GetFeedbackIdReduced() const
298 {
299 return feedbackIdReduced;
300 }
301
302 inline void SetReducedDelay(const Delay reducedDelay)
303 {
304 this->reducedDelay = reducedDelay;
305 }
306
307 inline Delay GetReducedDelay() const
308 {
309 return reducedDelay;
310 }
311
312 inline void SetFeedbackIdCreep(const FeedbackID feedbackIdCreep)
313 {
314 this->feedbackIdCreep = feedbackIdCreep;
315 }
316
317 inline FeedbackID GetFeedbackIdCreep() const
318 {
319 return feedbackIdCreep;
320 }
321
322 inline void SetCreepDelay(const Delay creepDelay)
323 {
324 this->creepDelay = creepDelay;
325 }
326
327 inline Delay GetCreepDelay() const
328 {
329 return creepDelay;
330 }
331
332 inline void SetFeedbackIdStop(const FeedbackID feedbackIdStop)
333 {
334 this->feedbackIdStop = feedbackIdStop;
335 }
336
337 inline FeedbackID GetFeedbackIdStop() const
338 {
339 return feedbackIdStop;
340 }
341
342 inline void SetStopDelay(const Delay stopDelay)
343 {
344 this->stopDelay = stopDelay;
345 }
346
347 inline Delay GetStopDelay() const
348 {
349 return stopDelay;
350 }
351
352 inline void SetFeedbackIdOver(const FeedbackID feedbackIdOver)
353 {
354 this->feedbackIdOver = feedbackIdOver;
355 }
356
357 inline FeedbackID GetFeedbackIdOver() const
358 {
359 return feedbackIdOver;
360 }
361
362 inline void SetWaitAfterRelease(const Pause wait)
363 {
364 this->waitAfterRelease = wait;
365 }
366
367 inline Pause GetWaitAfterRelease() const
368 {
369 return waitAfterRelease;
370 }
371
372 inline void SetFollowUpRoute(const RouteID followUpRoute)
373 {
374 this->followUpRoute = followUpRoute;
375 }
376
377 inline RouteID GetFollowUpRoute() const
378 {
379 return followUpRoute;
380 }
381
382 static inline bool CompareShortest(const Route* s1, const Route* s2)
383 {
384 return s1->GetMinTrainLength() < s2->GetMinTrainLength();
385 }
386 static inline bool CompareLastUsed(const Route* s1, const Route* s2)
387 {
388 return s1->GetLastUsed() < s2->GetLastUsed();
389 }
390
391 bool ObjectIsPartOfRoute(const ObjectIdentifier& identifier) const;
392
393 private:
394 bool ReleaseInternal(Logger::Logger* logger, const ObjectIdentifier& locoBaseIdentifier);
395 void ReleaseInternalWithToTrack(Logger::Logger* logger, const ObjectIdentifier& locoBaseIdentifier);
396 static void DeleteRelations(std::vector<DataModel::Relation*>& relations);
397 bool AssignRelations(std::vector<DataModel::Relation*>& relations, const std::vector<DataModel::Relation*>& newRelations);
398
399 Manager* manager;
400 std::mutex updateMutex;
401 bool executeAtUnlock;
402
403 Delay delay;
404 std::vector<DataModel::Relation*> relationsAtLock;
405 std::vector<DataModel::Relation*> relationsAtUnlock;
406 PushpullType pushpull;
407 Propulsion propulsion;
408 TrainType trainType;
409 Length minTrainLength;
410 Length maxTrainLength;
411 Automode automode;
412 TrackID fromTrack;
413 Orientation fromOrientation;
414 TrackID toTrack;
415 Orientation toOrientation;
416
417 Speed speed;
418 FeedbackID feedbackIdReduced;
419 Delay reducedDelay;
420 FeedbackID feedbackIdCreep;
421 Delay creepDelay;
422 FeedbackID feedbackIdStop;
423 Delay stopDelay;
424 FeedbackID feedbackIdOver;
425 Pause waitAfterRelease;
426 RouteID followUpRoute;
427
428 time_t lastUsed;
429 unsigned int counter;
430 };
431 } // namespace DataModel
432