| 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/Object.h" |
| 29 |
|
| 30 |
class Manager; |
| 31 |
|
| 32 |
namespace DataModel |
| 33 |
{ |
| 34 |
class Relation; |
| 35 |
class Signal; |
| 36 |
class Track; |
| 37 |
|
| 38 |
class Cluster : public Object |
| 39 |
{ |
| 40 |
public: |
| 41 |
Cluster(__attribute__((unused)) Manager* manager, const ClusterID clusterID) |
| 42 |
: Object(clusterID), |
| 43 |
orientation(OrientationRight) |
| 44 |
{ |
| 45 |
} |
| 46 |
|
| 47 |
Cluster(const std::string& serialized) |
| 48 |
: Object(ClusterNone), |
| 49 |
orientation(OrientationRight) |
| 50 |
{ |
| 51 |
Deserialize(serialized); |
| 52 |
} |
| 53 |
|
| 54 |
virtual ~Cluster() |
| 55 |
{ |
| 56 |
DeleteTracks(); |
| 57 |
} |
| 58 |
|
| 59 |
inline ObjectType GetObjectType() const override |
| 60 |
{ |
| 61 |
return ObjectTypeCluster; |
| 62 |
} |
| 63 |
|
| 64 |
std::string Serialize() const override; |
| 65 |
bool Deserialize(const std::string& serialized) override; |
| 66 |
|
| 67 |
inline bool CanSetLocoBaseOrientation(const Orientation orientation, |
| 68 |
const ObjectIdentifier& locoBaseIdentifier) |
| 69 |
{ |
| 70 |
std::lock_guard<std::mutex> Guard(orientationMutex); |
| 71 |
return CanSetLocoBaseOrientationUnlocked(orientation, locoBaseIdentifier); |
| 72 |
} |
| 73 |
|
| 74 |
bool SetLocoBaseOrientation(const Orientation orientation, |
| 75 |
const ObjectIdentifier& locoBaseIdentifier); |
| 76 |
|
| 77 |
inline Orientation GetLocoOrientation() const |
| 78 |
{ |
| 79 |
return orientation; |
| 80 |
} |
| 81 |
|
| 82 |
inline const std::vector<DataModel::Relation*>& GetTracks() const |
| 83 |
{ |
| 84 |
return tracks; |
| 85 |
} |
| 86 |
|
| 87 |
void DeleteTracks(); |
| 88 |
void DeleteTrack(DataModel::Track* trackToDelete); |
| 89 |
void AssignTracks(const std::vector<DataModel::Relation*>& newTracks); |
| 90 |
|
| 91 |
private: |
| 92 |
bool CanSetLocoBaseOrientationUnlocked(const Orientation orientation, |
| 93 |
const ObjectIdentifier& locoBaseIdentifier); |
| 94 |
|
| 95 |
Orientation orientation; |
| 96 |
mutable std::mutex orientationMutex; |
| 97 |
std::vector<DataModel::Relation*> tracks; |
| 98 |
}; |
| 99 |
} // namespace DataModel |