| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 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 Track; |
| 36 |
|
| 37 |
class Cluster : public Object |
| 38 |
{ |
| 39 |
public: |
| •40 |
inline Cluster(Manager* manager, |
| 41 |
const ClusterID clusterID) |
| 42 |
: Object(clusterID), |
| •43 |
manager(manager), |
| 44 |
orientation(OrientationRight) |
| 45 |
{ |
| •46 |
} |
| 47 |
|
| •48 |
inline Cluster(Manager* manager, |
| 49 |
const std::string& serialized) |
| 50 |
: Object(ClusterNone), |
| •51 |
manager(manager), |
| 52 |
orientation(OrientationRight) |
| 53 |
{ |
| 54 |
Deserialize(serialized); |
| 55 |
} |
| 56 |
|
| 57 |
virtual ~Cluster() |
| 58 |
{ |
| 59 |
DeleteTracks(); |
| 60 |
} |
| 61 |
|
| 62 |
inline ObjectType GetObjectType() const override |
| 63 |
{ |
| 64 |
return ObjectTypeCluster; |
| 65 |
} |
| 66 |
|
| 67 |
std::string Serialize() const override; |
| •68 |
void Deserialize(const std::string& serialized) override; |
| 69 |
|
| 70 |
inline bool CanSetLocoBaseOrientation(const Orientation orientation, |
| 71 |
const ObjectIdentifier& locoBaseIdentifier) |
| 72 |
{ |
| 73 |
std::lock_guard<std::mutex> Guard(orientationMutex); |
| 74 |
return CanSetLocoBaseOrientationUnlocked(orientation, locoBaseIdentifier); |
| 75 |
} |
| 76 |
|
| 77 |
bool SetLocoBaseOrientation(const Orientation orientation, |
| 78 |
const ObjectIdentifier& locoBaseIdentifier); |
| 79 |
|
| 80 |
inline Orientation GetLocoOrientation() const |
| 81 |
{ |
| 82 |
return orientation; |
| 83 |
} |
| 84 |
|
| 85 |
inline const std::vector<DataModel::Relation*>& GetTracks() const |
| 86 |
{ |
| 87 |
return tracks; |
| 88 |
} |
| 89 |
|
| 90 |
void DeleteTracks(); |
| 91 |
void DeleteTrack(DataModel::Track* trackToDelete); |
| 92 |
void AssignTracks(const std::vector<DataModel::Relation*>& newTracks); |
| 93 |
|
| 94 |
private: |
| 95 |
bool CanSetLocoBaseOrientationUnlocked(const Orientation orientation, |
| 96 |
const ObjectIdentifier& locoBaseIdentifier); |
| 97 |
|
| •98 |
Manager* manager; |
| 99 |
Orientation orientation; |
| 100 |
mutable std::mutex orientationMutex; |
| 101 |
std::vector<DataModel::Relation*> tracks; |
| 102 |
}; |
| 103 |
} |