Trax3 3.1.0
trax track library
Loading...
Searching...
No Matches
TrackSystem.h
1// trax track library
2// AD 2013
3//
4// "the resolution of all the fruitless searches"
5//
6// Peter Gabriel
7//
8// Copyright (c) 2025 Trend Redaktions- und Verlagsgesellschaft mbH
9// Copyright (c) 2019 Marc-Michael Horstmann
10//
11// Permission is hereby granted to any person obtaining a copy of this software
12// and associated source code (the "Software"), to use, view, and study the
13// Software for personal or internal business purposes, subject to the following
14// conditions:
15//
16// 1. Redistribution, modification, sublicensing, or commercial use of the
17// Software is NOT permitted without prior written consent from the copyright
18// holder.
19//
20// 2. The Software is provided "AS IS", without warranty of any kind, express
21// or implied.
22//
23// 3. All copies of the Software must retain this license notice.
24//
25// For further information, please contact: horstmann.marc@trendverlag.de
26
27#pragma once
28
29#include "Collection.h"
30#include "CollectionDecorator.h"
31#include "trax/Identified.h"
32
33#include "trax/Simulated.h"
34#include "trax/Track.h"
35#include "trax/Location.h"
36
37namespace spat{
38 template<typename> struct Sphere;
39}
40
41namespace trax{
42
44 //struct Module;
46
53 struct TrackSystem : Collection<TrackSystem,TrackBuilder>,
55 Identified<TrackSystem>
56 {
58 static dclspc std::shared_ptr<TrackSystem> Make() noexcept;
59
60 static dclspc std::shared_ptr<TrackSystem> Make(
61 std::unique_ptr<TrackCollectionContainer> pTrackCollectionContainer ) noexcept;
62
63 static dclspc std::shared_ptr<TrackSystem> Make(
64 std::unique_ptr<TrackCollectionContainer> pTrackCollectionContainer,
65 std::unique_ptr<ConnectorCollection> pConnectorCollection ) noexcept;
66
67
69 virtual std::shared_ptr<TrackSystem> This() const noexcept = 0;
70
71
72 // TrackCollections:
73
77 virtual IDType CreateCollection( IDType id = 0 ) = 0;
78
79
82 virtual void RemoveCollection( IDType id ) = 0;
83
84
86 virtual void SetCollectionFrame( IDType id, const spat::Frame<Length,One>& frame ) = 0;
87
88
90 virtual const spat::Frame<Length,One>& GetCollectionFrame( IDType id ) const = 0;
91
92
95
96
98 virtual IDType GetActiveCollection() const = 0;
99
100
101 virtual std::shared_ptr<TrackCollectionContainer> SetTrackCollectionContainer( std::shared_ptr<TrackCollectionContainer> pTrackCollectionContainer ) = 0;
102
103
106 virtual std::shared_ptr<TrackCollectionContainer> GetCollectionContainer() const = 0;
107
108
111 virtual std::shared_ptr<ConnectorCollection> SetConnectorCollection( std::shared_ptr<ConnectorCollection> pConnectorCollection ) = 0;
112
113
116
117
124 virtual void Couple( std::pair<std::shared_ptr<TrackBuilder>,Track::EndType> trackEnd1, std::pair<std::shared_ptr<TrackBuilder>,Track::EndType> trackEnd2 ) const = 0;
125
126 virtual void Couple( const Track::Coupling& coupling, bool bUncoupledOnly = false ) const = 0;
128
129
131 virtual std::shared_ptr<Sensor> GetSensor( IDType id, TrackLocation* pTrackLocation ) const = 0;
132
133
135 virtual Length CalculateGapSize( const Track::End& theOne, const Track::End& theOther ) const = 0;
136
137
139 virtual std::vector<Track::End> GetUncoupledIn( const spat::Sphere<Length>& area ) const = 0;
140
141
146 virtual void Connection( Track::Coupling& coupling ) const = 0;
147
148 virtual void Connection( const Track::End& end, Track::End& coupled ) const = 0;
149
154 virtual void Connection( const Track::Coupling& couplings, Track::Coupling& active ) const = 0;
155
156
162 virtual void CoupleAll( Length maxDistance = 1_m, Angle maxKink = pi, bool bSilent = true ) = 0;
163
164
169 virtual void DeCoupleAll() = 0;
170 };
171
172
179 std::vector<std::tuple<std::shared_ptr<TrackBuilder>,Track::EndType,Length>> dclspc FindTrackEnds( const TrackSystem& system, const spat::Sphere<Length>& area, bool sort = false );
180
181
188 std::vector<std::pair<Location,Length>> dclspc FindTrackLocations( const TrackSystem& system, const spat::Sphere<Length>& area, bool sort = false );
189
190 Location dclspc FindTrackLocation( const TrackSystem& system, const spat::Sphere<Length>& area );
191
192
201 std::vector<std::pair<Location,Length>> dclspc FindTrackLocations( const TrackSystem& system, const spat::VectorBundle<Length,One>& ray, Length gauge = 0_m, bool sort = false );
202
203
213 public:
214
217
218
219 TrackSystemDecorator() = delete;
220
223 TrackSystemDecorator( std::shared_ptr<TrackSystem> pTrackSystem )
225 {}
226
227
231 std::shared_ptr<TrackSystem> This() const noexcept override{
232 return m_pComponent->This();
233 }
234
235 IDType CreateCollection( IDType id = 0 ) override{
236 return m_pComponent->CreateCollection(id);
237 }
238
239 void RemoveCollection( IDType id ) override{
240 return m_pComponent->RemoveCollection(id);
241 }
242
243 void SetCollectionFrame( IDType id, const spat::Frame<Length,One>& frame ) override{
244 return m_pComponent->SetCollectionFrame(id,frame);
245 }
246
248 return m_pComponent->GetCollectionFrame(id);
249 }
250
252 return m_pComponent->SetActiveCollection(id);
253 }
254
255 IDType GetActiveCollection() const override{
256 return m_pComponent->GetActiveCollection();
257 }
258
259 std::shared_ptr<TrackCollectionContainer> GetCollectionContainer() const override{
260 return m_pComponent->GetCollectionContainer();
261 }
262
263 std::shared_ptr<TrackCollectionContainer> SetTrackCollectionContainer( std::shared_ptr<TrackCollectionContainer> pTrackCollectionContainer ) override{
264 return m_pComponent->SetTrackCollectionContainer( pTrackCollectionContainer );
265 }
266
267 std::shared_ptr<ConnectorCollection> SetConnectorCollection( std::shared_ptr<ConnectorCollection> pConnectorCollection ) override{
268 return m_pComponent->SetConnectorCollection( pConnectorCollection );
269 }
270
272 return m_pComponent->GetConnectorCollection();
273 }
274
275 void Couple( std::pair<std::shared_ptr<TrackBuilder>,Track::EndType> trackEnd1, std::pair<std::shared_ptr<TrackBuilder>,Track::EndType> trackEnd2 ) const override{
276 return m_pComponent->Couple( trackEnd1, trackEnd2 );
277 }
278
279 void Couple( const Track::Coupling& coupling, bool bUncoupledOnly = false ) const override{
280 return m_pComponent->Couple( coupling, bUncoupledOnly );
281 }
282
283 std::shared_ptr<Sensor> GetSensor( IDType id, TrackLocation* pTrackLocation ) const override{
284 return m_pComponent->GetSensor( id, pTrackLocation );
285 }
286
287 Length CalculateGapSize( const Track::End& theOne, const Track::End& theOther ) const override{
288 return m_pComponent->CalculateGapSize( theOne, theOther );
289 }
290
291 std::vector<Track::End> GetUncoupledIn( const spat::Sphere<Length>& area ) const override{
292 return m_pComponent->GetUncoupledIn( area );
293 }
294
295 void Connection( Track::Coupling& coupling ) const override{
296 return m_pComponent->Connection(coupling);
297 }
298
299 void Connection( const Track::End& end, Track::End& coupled ) const override{
300 return m_pComponent->Connection(end,coupled);
301 }
302
303 void Connection( const Track::Coupling& couplings, Track::Coupling& active ) const override{
304 return m_pComponent->Connection(couplings,active);
305 }
306
307 void DeCoupleAll() override{
308 return m_pComponent->DeCoupleAll();
309 }
310
311 };
312}
Home of the Track and TrackBuilder interfaces.
CollectionDecorator(std::shared_ptr< InterfaceType > pComponent)
Definition CollectionDecorator.h:58
The base for decorator implementations. Needed as BaseDecorator to combine other decorator implemente...
Definition ObjectIDDecorator.h:27
std::shared_ptr< InterfaceType > m_pComponent
Definition ObjectIDDecorator.h:54
A Location specifies a position on a track system by referencing a track and a TrackLocation on it.
Definition Location.h:110
A decorator for identification part of trax objects.
Definition ObjectIDDecorator.h:90
Definition Simulated.h:82
TrackSystem ComponentType
Type of the decoree.
Definition TrackSystem.h:216
const spat::Frame< Length, One > & GetCollectionFrame(IDType id) const override
Gets the frame of reference for a TrackCollection.
Definition TrackSystem.h:247
std::shared_ptr< TrackSystem > This() const noexcept override
Gets a shared pointer to this.
Definition TrackSystem.h:231
void DeCoupleAll() override
Uncouples all the Tracks in the TrackSystem from each other.
Definition TrackSystem.h:307
std::shared_ptr< ConnectorCollection > SetConnectorCollection(std::shared_ptr< ConnectorCollection > pConnectorCollection) override
Attaches a ConnectorCollection to the track system.
Definition TrackSystem.h:267
TrackSystemDecorator(std::shared_ptr< TrackSystem > pTrackSystem)
Constructs the decorator.
Definition TrackSystem.h:223
std::shared_ptr< Sensor > GetSensor(IDType id, TrackLocation *pTrackLocation) const override
Definition TrackSystem.h:283
void SetCollectionFrame(IDType id, const spat::Frame< Length, One > &frame) override
Sets the frame of reference for a TrackCollection.
Definition TrackSystem.h:243
Length CalculateGapSize(const Track::End &theOne, const Track::End &theOther) const override
Definition TrackSystem.h:287
ConnectorCollection * GetConnectorCollection() const override
Definition TrackSystem.h:271
void RemoveCollection(IDType id) override
Removes the TrackCollection with the specified id.
Definition TrackSystem.h:239
void Connection(const Track::Coupling &couplings, Track::Coupling &active) const override
Writes the coupled tracks data of the trackends in couplings to active.
Definition TrackSystem.h:303
std::shared_ptr< TrackCollectionContainer > GetCollectionContainer() const override
Definition TrackSystem.h:259
std::vector< Track::End > GetUncoupledIn(const spat::Sphere< Length > &area) const override
Searches for a free, uncoupled track end in the area.
Definition TrackSystem.h:291
IDType GetActiveCollection() const override
Definition TrackSystem.h:255
void Connection(Track::Coupling &coupling) const override
Completes the coupling.
Definition TrackSystem.h:295
IDType CreateCollection(IDType id=0) override
Creates a TrackCollection with the supplied id.
Definition TrackSystem.h:235
IDType SetActiveCollection(IDType id) override
Sets a TrackCollection to be the active one.
Definition TrackSystem.h:251
Value< Dimension< 0, 0, 0 > > One
Dimensionless value.
Definition DimensionedValues.h:319
Value< Dimension< 1, 0, 0 > > Length
Length.
Definition DimensionedValues.h:324
constexpr Angle pi
Circle number pi.
Definition DimensionedValues.h:1145
constexpr Real _m(Length l) noexcept
Dimensionated Values conversion functions.
Definition DimensionedValues.h:1210
Value< Dimension< 0, 0, 0 > > Angle
Angle in radians.
Definition DimensionedValues.h:320
The namespace provides classes and methods for spatial computations.
Definition Box.h:32
STL namespace.
Namespace of all the trax track libraries classes and methods.
Definition Collection.h:17
std::vector< std::tuple< std::shared_ptr< TrackBuilder >, Track::EndType, Length > > dclspc FindTrackEnds(const TrackCollection &collection, const spat::Sphere< Length > &area, bool sort=false)
Finds all track ends in the area.
std::vector< std::pair< Location, Length > > dclspc FindTrackLocations(const TrackCollection &collection, const spat::Sphere< Length > &area, bool sort=false)
Finds all tracks that run trough an area.
std::pair< std::shared_ptr< TrackBuilder >, Track::EndType > dclspc Couple(const TrackCollection &collection, TrackBuilder &track, Track::EndType endType, Length maxDistance=1_m, Angle maxKink=pi, bool bSilent=true)
Searches open track ends inside an area around a given track end and couples to the closest.
A Frame ("TNBFrame") describes a location in 3d space and an orientation using a right handed coordin...
Definition Frame.h:52
Sphere with center and radius.
Definition Sphere.h:39
Implements a Vector bundle.
Definition VectorBundle.h:42
Collection to hold a set of Connector objects.
Definition ConnectorCollection.h:36
Type used for IDs in the trax library.
Definition IDType.h:43
A Sensor can get attached to a track and be triggerd when a Location runs over it.
Definition Sensor.h:71
A simulated object. Register the object with a scene to get called back for Update,...
Definition Simulated.h:39
Designates two track ends. Typically used for coupling relations.
Definition Track.h:325
Designates an end at a specific track.
Definition Track.h:303
Interface for making and shaping tracks.
Definition Track.h:831
Collection to hold a set of TrackCollection objects.
Definition TrackCollectionContainer.h:36
Interface for a track used to calculate 3D positions.
Definition Track.h:275
EndType
Designates one of the two ends of a track.
Definition Track.h:292
A TrackLocation ist a location on a single track.
Definition TrackLocation.h:43
A track system is the container for tracks.
Definition TrackSystem.h:56
virtual const spat::Frame< Length, One > & GetCollectionFrame(IDType id) const =0
Gets the frame of reference for a TrackCollection.
virtual std::shared_ptr< TrackSystem > This() const noexcept=0
Gets a shared pointer to this.
virtual std::vector< Track::End > GetUncoupledIn(const spat::Sphere< Length > &area) const =0
Searches for a free, uncoupled track end in the area.
virtual IDType SetActiveCollection(IDType id)=0
Sets a TrackCollection to be the active one.
static dclspc std::shared_ptr< TrackSystem > Make() noexcept
Makes a standard TrackSystem object.
virtual void SetCollectionFrame(IDType id, const spat::Frame< Length, One > &frame)=0
Sets the frame of reference for a TrackCollection.
virtual std::shared_ptr< TrackCollectionContainer > GetCollectionContainer() const =0
virtual IDType GetActiveCollection() const =0
virtual Length CalculateGapSize(const Track::End &theOne, const Track::End &theOther) const =0
virtual void RemoveCollection(IDType id)=0
Removes the TrackCollection with the specified id.
virtual std::shared_ptr< ConnectorCollection > SetConnectorCollection(std::shared_ptr< ConnectorCollection > pConnectorCollection)=0
Attaches a ConnectorCollection to the track system.
virtual void DeCoupleAll()=0
Uncouples all the Tracks in the TrackSystem from each other.
virtual void CoupleAll(Length maxDistance=1_m, Angle maxKink=pi, bool bSilent=true)=0
Couples all open ends in the track system, if they are closer than maxDistance.
virtual IDType CreateCollection(IDType id=0)=0
Creates a TrackCollection with the supplied id.
virtual ConnectorCollection * GetConnectorCollection() const =0
virtual std::shared_ptr< Sensor > GetSensor(IDType id, TrackLocation *pTrackLocation) const =0
virtual void Connection(Track::Coupling &coupling) const =0
Completes the coupling.