Trax3 3.1.0
trax track library
Loading...
Searching...
No Matches
Signal.h
1// trax track library
2// AD 2014
3//
4// "Voelker hoert die Signale,"
5// auf zum letzten Gefecht!"
6//
7// Emil Luckhardt
8//
9// Copyright (c) 2025 Trend Redaktions- und Verlagsgesellschaft mbH
10// Copyright (c) 2019 Marc-Michael Horstmann
11//
12// Permission is hereby granted to any person obtaining a copy of this software
13// and associated source code (the "Software"), to use, view, and study the
14// Software for personal or internal business purposes, subject to the following
15// conditions:
16//
17// 1. Redistribution, modification, sublicensing, or commercial use of the
18// Software is NOT permitted without prior written consent from the copyright
19// holder.
20//
21// 2. The Software is provided "AS IS", without warranty of any kind, express
22// or implied.
23//
24// 3. All copies of the Software must retain this license notice.
25//
26// For further information, please contact: horstmann.marc@trendverlag.de
27
28#pragma once
29
43
44#include "Identified.h"
45#include "Track.h"
46#include "Location.h"
47
48namespace trax{
49
50 struct Jack;
51 struct MultiPlug;
52 struct SocketRegistry;
53
54
60 struct Signal : Identified<Signal>
61 {
63 virtual const char* TypeName() const noexcept = 0;
64
65
67 enum class Status{
68 none = -1,
69 stop = 0,
70 clear = 1,
71 slow,
72 velocity0 = stop,
73 velocity1 = clear,
74 velocity2 = slow,
75 velocity3,
76 velocity4,
77 velocity5,
78 velocity6,
79 velocity7,
80 velocity8,
81 velocity9,
82 velocity10,
83 velocity11,
84 velocity12,
85 velocityMax = velocity12,
86 caution,
87 doors_open,
88 doors_close,
89 uncouple,
90 lights_on,
91 jump,
92 count,
93 toggle,
94 change
95 };
96
97
102 virtual Status Set( Status status, bool pulse = true ) = 0;
103
104
107 virtual void Toggle( bool pulse = true ) = 0;
108
109
111 virtual Status Get() const = 0;
112
113
115 virtual int CountStatus() const = 0;
116
117
119 virtual void Attach( TrackBuilder* pTrackBuilder ) noexcept = 0;
120
121
124 virtual TrackBuilder* TrackAttached() const = 0;
125
126
129 virtual void GetTrackRange( TrackRange& trackRange ) const = 0;
130
131
136 virtual Location GetLocation() const = 0;
137
138
140 virtual MultiPlug& PlugToToggle() = 0;
141
142
144 virtual Jack& JackOnChange() = 0;
145
146
148 virtual Jack& JackOn( Status status ) = 0;
149
150
152 virtual Jack& JackOnChangeTo( Status status ) = 0;
153
154
156 virtual MultiPlug& PlugTo( Status status ) = 0;
157
158
161 virtual void RegisterSockets( SocketRegistry& modul ) = 0;
162
163
165 virtual void UnregisterSockets( SocketRegistry& modul ) = 0;
166 };
167
168 dclspc constexpr bool IsVelocityStatus( Signal::Status status );
169
170
176 struct VelocityControl : virtual Signal
177 {
179 static dclspc std::unique_ptr<VelocityControl> Make() noexcept;
180
181
194 virtual bool AffectTravelVelocity( Status status, bool bTravel ) = 0;
195
196
200 virtual bool AffectTravelVelocity( Status status ) const = 0;
201
202
212 virtual void SetVelocity( Status status, Velocity velocityMin, Velocity velocityMax ) = 0;
213
214
224 virtual void SetVelocity( Status status, Velocity velocity ) = 0;
225
226
234 virtual void VelocityMin( Status status, Velocity velocityMin ) = 0;
235
236
244 virtual void VelocityMax( Status status, Velocity velocityMax) = 0;
245
246
252 virtual Velocity VelocityMin( Status status ) const = 0;
253
254
260 virtual Velocity VelocityMax( Status status ) const = 0;
261
262
264 virtual bool IsValidState( Status status ) const = 0;
265
266
270 virtual void Remove( Status status ) = 0;
271
272
274 virtual void Clear() = 0;
275
276
279 virtual void StopDistance( Length distance ) = 0;
280
281
283 virtual Length StopDistance() const = 0;
284
285
291 virtual Jack& JackOnVelocity( Status status ) = 0;
292
293
299 virtual MultiPlug& PlugToVelocity( Status status ) = 0;
300 };
301
302 struct Depot;
303
315 struct JumpSite : virtual Signal{
316
318 static dclspc std::unique_ptr<JumpSite> Make() noexcept;
319
321 virtual void Target( const Location& target ) = 0;
322
323
325 virtual void Target( std::shared_ptr<Depot> pDepot ) = 0;
326
327
330 virtual bool IsTargetLocation() const = 0;
331
332
334 virtual const Location& TargetLocation() const = 0;
335
336
339 virtual std::shared_ptr<Depot> TargetDepot() const = 0;
340
341
343 virtual Jack& JackOnJump() = 0;
344
345
347 virtual Jack& JackOnChangeToJump() = 0;
348
349
351 virtual MultiPlug& PlugToJump() = 0;
352
353
355 virtual Jack& JackOnClear() = 0;
356
357
359 virtual Jack& JackOnChangeToClear() = 0;
360
361
363 virtual MultiPlug& PlugToClear() = 0;
364 };
365
366
369 struct TrackEndTransition : virtual Signal{
370
372 static dclspc std::unique_ptr<TrackEndTransition> Make( Track* pToTrack, Track::EndType toEnd ) noexcept;
373
376 virtual Track* From( Track::EndType& end ) const = 0;
377
378
380 virtual Track* From() const = 0;
381
382
385 virtual Track* To( Track::EndType& end ) const = 0;
386
387
389 virtual Track* To() const = 0;
390 };
391
392
394 dclspc std::string ToString( Signal::Status status );
395
396
399 dclspc Signal::Status ToSignalStatus( const std::string& status );
400
401
402 dclspc Signal::Status SignalStatusFrom( const std::string& socketName );
403
404
405
407 struct SignalTarget{
408
416 virtual bool Notify( const Signal& signal, Length distance ) = 0;
417
418
422 virtual void Active( bool bActive ) noexcept = 0;
423
424
426 virtual bool Active() const noexcept = 0;
427
428
429 virtual ~SignalTarget() = default;
430 SignalTarget( const SignalTarget& ) = delete;
431 SignalTarget( SignalTarget&& ) = delete;
432 SignalTarget& operator=( const SignalTarget& ) = delete;
433 SignalTarget& operator=( SignalTarget&& ) = delete;
434 protected:
435 SignalTarget() = default;
436 };
437
440 struct SignalAligned{
441
442 virtual void Attach( std::shared_ptr<Signal> pSignal, Length parameterOffset = 0_m ) = 0;
443
444 virtual IDType GetSignalRef() const = 0;
445
446 virtual Length ParameterOffset() const = 0;
447
448 virtual void ParameterOffset( Length parameterOffset ) = 0;
449
450 virtual bool PreserveUpDirection() const = 0;
451
452 virtual void PreserveUpDirection( bool bPreserveUpDirection ) = 0;
453
454 virtual ~SignalAligned() = default;
455 SignalAligned( const SignalAligned& ) = delete;
456 SignalAligned( SignalAligned&& ) = delete;
457 SignalAligned& operator=( const SignalAligned& ) = delete;
458 SignalAligned& operator=( SignalAligned&& ) = delete;
459 protected:
460 SignalAligned() = default;
461 };
462
463}
Home of the Track and TrackBuilder interfaces.
A Location specifies a position on a track system by referencing a track and a TrackLocation on it.
Definition Location.h:110
Value< Dimension< 1, 0, -1 > > Velocity
Velocity.
Definition DimensionedValues.h:331
Value< Dimension< 1, 0, 0 > > Length
Length.
Definition DimensionedValues.h:324
constexpr Real _m(Length l) noexcept
Dimensionated Values conversion functions.
Definition DimensionedValues.h:1210
STL namespace.
Namespace of all the trax track libraries classes and methods.
Definition Collection.h:17
dclspc Signal::Status ToSignalStatus(const std::string &status)
Makes a status value from a status string.
Type used for IDs in the trax library.
Definition IDType.h:43
A jack a plug can get connected with.
Definition Jack.h:83
A Signal that triggers a Train to jump to a jump site.
Definition Signal.h:315
virtual std::shared_ptr< Depot > TargetDepot() const =0
virtual const Location & TargetLocation() const =0
virtual void Target(const Location &target)=0
Sets the target to a location.
virtual Jack & JackOnChangeToJump()=0
Gets a Jack that pulses its Plug if the signal is set to jump and was not set so before.
virtual Jack & JackOnClear()=0
Gets a Jack that pulses its Plug if the signal is set to clear.
static dclspc std::unique_ptr< JumpSite > Make() noexcept
Makes a JumpSite object.
virtual bool IsTargetLocation() const =0
virtual Jack & JackOnJump()=0
Gets a Jack that pulses its Plug if the signal is set to jump.
virtual MultiPlug & PlugToJump()=0
Gets a Plug that sets the signal to jump.
virtual Jack & JackOnChangeToClear()=0
Gets a Jack that pulses its Plug if the signal is set to clear and was not set so before.
virtual MultiPlug & PlugToClear()=0
Gets a Plug that sets the signal to clear.
A MultiPlug provides a variable number of actual Plugs to one input slot.
Definition Plug.h:307
A Signal is positioned along a track and is submitted to a Train if it runs over it.
Definition Signal.h:61
virtual const char * TypeName() const noexcept=0
virtual MultiPlug & PlugTo(Status status)=0
Gets a Plug that switches to the specified Status.
virtual void Toggle(bool pulse=true)=0
Sets the signal state to the next setting.
virtual void UnregisterSockets(SocketRegistry &modul)=0
Removes all references to Plugs and Jacks from the module.
virtual Jack & JackOnChange()=0
virtual void RegisterSockets(SocketRegistry &modul)=0
Registers all the Plugs with the module and supplies the Jacks with plug ids for connecting.
virtual void Attach(TrackBuilder *pTrackBuilder) noexcept=0
Attaches the Signal to a TrackBuilder.
Status
Various Signal status settings.
Definition Signal.h:67
virtual Status Get() const =0
Get the Signal's setting.
virtual Jack & JackOnChangeTo(Status status)=0
Gets a Jack that pulses its Plug if the specified Status is set and was not set before.
virtual MultiPlug & PlugToToggle()=0
virtual Status Set(Status status, bool pulse=true)=0
Set the Signal's setting.
virtual Jack & JackOn(Status status)=0
Gets a Jack that pulses its Plug if the specified Status is set.
virtual int CountStatus() const =0
Gets the number of signal status the signal provides.
virtual void GetTrackRange(TrackRange &trackRange) const =0
Gets the range on the track on wich the signal is effective.
virtual Location GetLocation() const =0
Creates a Location for the signals reference point on the tracks.
virtual TrackBuilder * TrackAttached() const =0
virtual bool Active() const noexcept=0
virtual void Active(bool bActive) noexcept=0
Switches the target on or off to receive notifications from signals.
virtual bool Notify(const Signal &signal, Length distance)=0
Method called to notify about a signalling state.
Interface for a registry that reconnects Plugs and Jacks according to their IDs.
Definition SocketRegistry.h:40
Interface for making and shaping tracks.
Definition Track.h:831
A Signal that can be placed at track couplings to signal that a Train runs over the coupling between ...
Definition Signal.h:369
virtual Track * From() const =0
static dclspc std::unique_ptr< TrackEndTransition > Make(Track *pToTrack, Track::EndType toEnd) noexcept
Makes a standard TrackEndTransition object.
virtual Track * To() const =0
virtual Track * To(Track::EndType &end) const =0
virtual Track * From(Track::EndType &end) const =0
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
An interval on a track, referenced by an id.
Definition TrackLocation.h:132
Interface for signals that control the velocity of trains.
Definition Signal.h:177
virtual void VelocityMin(Status status, Velocity velocityMin)=0
Sets the minimum velocity.
virtual MultiPlug & PlugToVelocity(Status status)=0
virtual void StopDistance(Length distance)=0
Sets a distance from the far edge to stop at.
virtual bool IsValidState(Status status) const =0
static dclspc std::unique_ptr< VelocityControl > Make() noexcept
Makes a VelocityControl object.
virtual bool AffectTravelVelocity(Status status, bool bTravel)=0
Set if the signal should affect the velocity permanently.
virtual void Clear()=0
Removes all signal states.
virtual void VelocityMax(Status status, Velocity velocityMax)=0
Sets the maximum velocity.
virtual Jack & JackOnVelocity(Status status)=0
virtual void Remove(Status status)=0
Removes thje signal state with index idx.
virtual void SetVelocity(Status status, Velocity velocityMin, Velocity velocityMax)=0
Set the target velocities.