Trax3 3.1.0
trax track library
Loading...
Searching...
No Matches
Switch.h
1// trax track library
2// AD 2014
3//
4// "Doesn't anybody ever know ..."
5//
6// Our Lady Peace
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 "Connector.h"
30
31namespace trax{
32
33 class Location;
34
37 struct NarrowSwitch : virtual Connector{
38
40 static dclspc std::unique_ptr<NarrowSwitch> Make( unsigned char numBranches ) noexcept;
41
42 enum SlotNames : char{
43 slot_none = -1,
44 slot_0 = 0,
50 slot_N = 125,
51 maxSlots
52 };
53
54
56 enum class Status : char{
57 none = -1,
59 branch = 1,
60 branch1 = 1,
61 branch2 = 2,
62 branch3 = 3,
63 branch4 = 4,
64 bramch5 = 5,
65 branchN = 124,
66 maxBranches = 124,
68 change,
70 };
71
72
75 virtual Status Set( Status to, bool pulse = true ) = 0;
76
77 using Connector::Set;
78
79
81 virtual Status Get() const = 0;
82
83
89 virtual void NarrowTrack( std::shared_ptr<TrackBuilder> pNarrowTrack, Track::EndType trackEnd ) = 0;
90
91
93 virtual std::pair<std::shared_ptr<TrackBuilder>,Track::EndType> NarrowTrack() const = 0;
94
95
97 virtual void ClearNarrowTrack() = 0;
98
99
105 virtual void StraightTrack( std::shared_ptr<TrackBuilder> pStaightTrack, Track::EndType trackEnd ) = 0;
106
107
109 virtual std::pair<std::shared_ptr<TrackBuilder>,Track::EndType> StraightTrack() const = 0;
110
111
113 virtual void ClearStraightTrack() = 0;
114
115
122 virtual void DivergedTrack( int divTrackID, std::shared_ptr<TrackBuilder> pDivergedTrack, Track::EndType trackEnd ) = 0;
123
124
126 virtual std::pair<std::shared_ptr<TrackBuilder>,Track::EndType> DivergedTrack( int divTrackID ) const = 0;
127
128
130 virtual void ClearDivergedTrack( int divTrackID ) = 0;
131
132
134 virtual int CntDivergedTracks() const = 0;
135
136
140 virtual Location Bifurcation() const = 0;
141
142
144 virtual Jack& JackOnGo() noexcept = 0;
145
146
148 virtual MultiPlug& PlugToGo() noexcept = 0;
149
150
152 virtual Jack& JackOn( Status status ) = 0;
153
154
156 virtual MultiPlug& PlugTo( Status status ) = 0;
157
158
160 virtual Jack& JackOnDivergedTrack( int divTrackID ) = 0;
161
162
164 virtual MultiPlug& PlugToDivergedTrack( int divTrackID ) = 0;
165 };
166
167
169 dclspc std::string ToString( NarrowSwitch::Status status );
170
171
174 dclspc NarrowSwitch::Status ToNarrowSwitchStatus( const std::string& status );
175
176
178 dclspc NarrowSwitch::Status NarrowSwitchStatusFrom( const std::string& socketName );
179
180
185 struct Switch : virtual NarrowSwitch
186 {
188 static dclspc std::unique_ptr<Switch> Make() noexcept;
189
190
191 static constexpr char slot_count = 3;
192 static constexpr char status_count = 2;
193 static constexpr char branch_count = 1;
194
196
202 virtual void DivergedTrack( std::shared_ptr<TrackBuilder> pDivergedTrack, Track::EndType trackEnd ) = 0;
203
204
206 virtual std::pair<std::shared_ptr<TrackBuilder>,Track::EndType> DivergedTrack() const = 0;
207
208
210
212 virtual void ClearDivergedTrack() = 0;
213
214
216 virtual void SwapTracks() = 0;
217
218
233 virtual bool IsNormal( bool bStopAtFirstTrack = true, Length maxDistance = infinite__length ) const = 0;
234
235
238 virtual bool Normalize() = 0;
239
240
259 virtual bool IsY( bool bStopAtFirstTrack = true, Length maxDistance = infinite__length, AnglePerLength margin = epsilon__angle / 80_m ) const = 0;
260
261
269 virtual bool IsHorizontal( bool bStopAtFirstTrack = true, Length maxDistance = infinite__length ) const = 0;
270
271
279 virtual bool IsVertical( bool bStopAtFirstTrack = true, Length maxDistance = infinite__length ) const = 0;
280
281
296 virtual bool BranchLeftOrRight( bool bStopAtFirstTrack = true, Length maxDistance = infinite__length ) const = 0;
297
298
313 virtual bool BranchUpOrDown( bool bStopAtFirstTrack = true, Length maxDistance = infinite__length ) const = 0;
314
315
317 virtual Jack& JackOnBranch() noexcept = 0;
318
319
321 virtual MultiPlug& PlugToBranch() noexcept = 0;
322 };
323
324
326 struct ThreeWaySwitch : virtual NarrowSwitch{
327
329 static dclspc std::unique_ptr<ThreeWaySwitch> Make() noexcept;
330
331
332 static constexpr char slot_count = 4;
333 static constexpr char status_count = 3;
334 static constexpr char branch_count = 2;
335
336
342 virtual void DivergedTrack1( std::shared_ptr<TrackBuilder> pDivergedTrack1, Track::EndType trackEnd ) = 0;
343
344
346 virtual std::pair<std::shared_ptr<TrackBuilder>,Track::EndType> DivergedTrack1() const = 0;
347
348
350 virtual void ClearDivergedTrack1() = 0;
351
352
358 virtual void DivergedTrack2( std::shared_ptr<TrackBuilder> pDivergedTrack2, Track::EndType trackEnd ) = 0;
359
360
362 virtual std::pair<std::shared_ptr<TrackBuilder>,Track::EndType> DivergedTrack2() const = 0;
363
364
366 virtual void ClearDivergedTrack2() = 0;
367
368
370 virtual void SwapStraightWithDiverged() = 0;
371
373 virtual void SwapStraightWithDiverged2() = 0;
374
376 virtual void SwapDivergedWithDiverged2() = 0;
377
378
384 virtual bool IsNormal() const = 0;
385
386
389 virtual bool Normalize() = 0;
390
391
393 virtual Status StatusToLeft() const = 0;
394
395
397 virtual Status StatusToMiddle() const = 0;
398
399
401 virtual Status StatusToRight() const = 0;
402
403
405 virtual Jack& JackOnBranch1() noexcept = 0;
406
407
409 virtual MultiPlug& PlugToBranch1() noexcept = 0;
410
411
413 virtual Jack& JackOnBranch2() noexcept = 0;
414
415
417 virtual MultiPlug& PlugToBranch2() noexcept = 0;
418 };
419
420
439 struct SingleSlipSwitch : virtual Connector{
440
442 static dclspc std::unique_ptr<SingleSlipSwitch> Make() noexcept;
443
445 slot_none = -1,
446 slot_0 = 0,
452 slot_count
453 };
454
460 enum class Status{
461 none = -1,
463 go1 = go,
464 go2,
466 count,
468 change
469 };
470
473 virtual Status Set( Status to, bool pulse = true ) = 0;
474
475 using Connector::Set;
476
477
479 virtual Status Get() const = 0;
480
481
483 virtual void SetCenter( const spat::Frame<Length,One>& center ) = 0;
484
485
487 virtual Jack& JackOn( Status status ) = 0;
488
489
491 virtual MultiPlug& PlugTo( Status status ) = 0;
492 };
493
494
496 dclspc std::string ToString( SingleSlipSwitch::Status status );
497
498
501 dclspc SingleSlipSwitch::Status ToSingleSlipSwitchStatus( const std::string& status );
502
503
505 dclspc SingleSlipSwitch::Status SingleSlipSwitchStatusFrom( const std::string& socketName );
506
507
527 struct DoubleSlipSwitch : virtual Connector{
528
530 static dclspc std::unique_ptr<DoubleSlipSwitch> Make() noexcept;
531
532
549
550
556 enum class Status{
557 none = -1,
558 go,
559 go1 = go,
560 go2,
561 branch,
562 branch1 = branch,
563 branch2,
564 count,
565 toggle,
566 change
567 };
568
571 virtual Status Set( Status to, bool pulse = true ) = 0;
572
573 using Connector::Set;
574
575
577 virtual Status Get() const = 0;
578
579
581 virtual void SetCenter( const spat::Frame<Length,One>& center ) = 0;
582
583
585 virtual Jack& JackOn( Status status ) = 0;
586
587
589 virtual MultiPlug& PlugTo( Status status ) = 0;
590 };
591
592
594 dclspc std::string ToString( DoubleSlipSwitch::Status status );
595
596
599 dclspc DoubleSlipSwitch::Status ToDoubleSlipSwitchStatus( const std::string& status );
600
601
603 dclspc DoubleSlipSwitch::Status DoubleSlipSwitchStatusFrom( const std::string& socketName );
604
605
606 struct SwitchAligned{
607
608 virtual void Attach( std::shared_ptr<Connector> pSwitch ) = 0;
609
610 virtual bool PreserveUpDirection() const = 0;
611
612 virtual void PreserveUpDirection( bool bPreserveUpDirection ) = 0;
613
614 virtual IDType GetSwitchRef() const = 0;
615
616 virtual std::shared_ptr<Connector> GetSwitch() const = 0;
617
618
619 virtual ~SwitchAligned() = default;
620 SwitchAligned( const SwitchAligned& ) = delete;
621 SwitchAligned( SwitchAligned&& ) = delete;
622 SwitchAligned& operator=( const SwitchAligned& ) = delete;
623 SwitchAligned& operator=( SwitchAligned&& ) = delete;
624 protected:
625 SwitchAligned() = default;
626 };
627
628}
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, 0 > > Length
Length.
Definition DimensionedValues.h:324
constexpr Real _m(Length l) noexcept
Dimensionated Values conversion functions.
Definition DimensionedValues.h:1210
constexpr Length infinite__length
Dimensionated infinite values.
Definition DimensionedValues.h:359
Value< Dimension<-1, 0, 0 > > AnglePerLength
Angle per length.
Definition DimensionedValues.h:321
STL namespace.
Namespace of all the trax track libraries classes and methods.
Definition Collection.h:17
dclspc DoubleSlipSwitch::Status ToDoubleSlipSwitchStatus(const std::string &status)
Makes a status value from a status string.
dclspc NarrowSwitch::Status NarrowSwitchStatusFrom(const std::string &socketName)
dclspc NarrowSwitch::Status ToNarrowSwitchStatus(const std::string &status)
Makes a status value from a status string.
dclspc SingleSlipSwitch::Status SingleSlipSwitchStatusFrom(const std::string &socketName)
dclspc DoubleSlipSwitch::Status DoubleSlipSwitchStatusFrom(const std::string &socketName)
dclspc SingleSlipSwitch::Status ToSingleSlipSwitchStatus(const std::string &status)
Makes a status value from a status string.
A Frame ("TNBFrame") describes a location in 3d space and an orientation using a right handed coordin...
Definition Frame.h:52
A Connector rearranges the connections between several track ends.
Definition Connector.h:226
virtual void Set(const Track &trackA, Track::EndType trackendA, const Track &trackB, Track::EndType trackendB, bool pulse=true)=0
Sets the Connector to the setting that connects the two track ends.
A double slip switch is made from eight tracks that form a crossing with the possibility to divert th...
Definition Switch.h:527
virtual MultiPlug & PlugTo(Status status)=0
Gets a Plug that switches to the specified Status.
virtual Status Set(Status to, bool pulse=true)=0
Turns the switch to the specified setting.
Status
Status values of a switch.
Definition Switch.h:556
static dclspc std::unique_ptr< DoubleSlipSwitch > Make() noexcept
Makes a standard DoubleSlipSwitch object.
virtual void SetCenter(const spat::Frame< Length, One > &center)=0
Sets the center of the switch.
virtual Status Get() const =0
Gets the setting of the switch.
SlotNames
Definition Switch.h:533
@ slot_10
diverging track end connected with third narrowing
Definition Switch.h:545
@ slot_8
diverging track end connected with first narrowing
Definition Switch.h:543
@ slot_7
crossing track end connected with fourth narrowing
Definition Switch.h:542
@ slot_0
first narrowing track end
Definition Switch.h:535
@ slot_11
diverging track end connected with second narrowing
Definition Switch.h:546
@ slot_6
crossing track end connected with third narrowing
Definition Switch.h:541
@ slot_1
second narrowing track end on the same side of first
Definition Switch.h:536
@ slot_3
fourth narrowing track end on same side to third
Definition Switch.h:538
@ slot_2
third narrowing track end on opposite side to the first
Definition Switch.h:537
@ slot_5
crossing track end connected with second narrowing
Definition Switch.h:540
@ slot_9
diverging track end connected with fourth narrowing
Definition Switch.h:544
@ slot_4
crossing track end connected with first narrowing
Definition Switch.h:539
virtual Jack & JackOn(Status status)=0
Gets a Jack that pulses its Plug if the specified Status is set.
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 MultiPlug provides a variable number of actual Plugs to one input slot.
Definition Plug.h:307
Common interface for switch types that maintain an incomming (narrow) track, an outgoing straight tra...
Definition Switch.h:37
virtual Location Bifurcation() const =0
Gets a track Location object right at the bifurcation point of the switch with a foreward direction a...
virtual void NarrowTrack(std::shared_ptr< TrackBuilder > pNarrowTrack, Track::EndType trackEnd)=0
Occupies the slot for the narrow track.
virtual Status Get() const =0
Gets the setting of the switch.
virtual std::pair< std::shared_ptr< TrackBuilder >, Track::EndType > StraightTrack() const =0
virtual void DivergedTrack(int divTrackID, std::shared_ptr< TrackBuilder > pDivergedTrack, Track::EndType trackEnd)=0
Occupies the slot for the diverging track.
static dclspc std::unique_ptr< NarrowSwitch > Make(unsigned char numBranches) noexcept
Makes a standard NarrowSwitch object.
virtual MultiPlug & PlugToGo() noexcept=0
Gets a Plug that sets the switch to go.
virtual void ClearStraightTrack()=0
Clears the slot for the straight track.
virtual std::pair< std::shared_ptr< TrackBuilder >, Track::EndType > NarrowTrack() const =0
virtual MultiPlug & PlugToDivergedTrack(int divTrackID)=0
Gets a Plug that sets the switch to the outgoing track.
virtual void StraightTrack(std::shared_ptr< TrackBuilder > pStaightTrack, Track::EndType trackEnd)=0
Occupies the slot for the straight track.
virtual Jack & JackOnDivergedTrack(int divTrackID)=0
Gets a Jack that pulses its Plug if the switch is set to the branching track.
virtual Status Set(Status to, bool pulse=true)=0
Turns the switch to the specified setting.
virtual void ClearNarrowTrack()=0
Clears the slot for the narrow track.
SlotNames
Definition Switch.h:42
@ slot_2
first diverging track
Definition Switch.h:46
@ slot_N
Nth diverging track.
Definition Switch.h:50
@ slot_1
straight track
Definition Switch.h:45
@ slot_5
fourth diverging track
Definition Switch.h:49
@ slot_3
second diverging track
Definition Switch.h:47
@ slot_0
narrow track
Definition Switch.h:44
@ slot_4
third diverging track
Definition Switch.h:48
Status
Status.
Definition Switch.h:56
@ go
go over straight track
Definition Switch.h:58
@ branch2
go over second diverging track
Definition Switch.h:61
@ toggle
toggle the switch
Definition Switch.h:67
@ branch1
go over first diverging track
Definition Switch.h:60
@ branch
go over first diverging track
Definition Switch.h:59
@ empty
set to first empty from go over branch1 to CntDivergedTracks()
Definition Switch.h:69
virtual int CntDivergedTracks() const =0
virtual MultiPlug & PlugTo(Status status)=0
Gets a Plug that switches to the specified Status.
virtual std::pair< std::shared_ptr< TrackBuilder >, Track::EndType > DivergedTrack(int divTrackID) const =0
virtual Jack & JackOnGo() noexcept=0
Gets a Jack that pulses its Plug if the switch is set to go.
virtual Jack & JackOn(Status status)=0
Gets a Jack that pulses its Plug if the specified Status is set.
virtual void ClearDivergedTrack(int divTrackID)=0
Clears the slot for the straight track.
A single slip switch is made from five tracks that form a crossing with the possibility to divert the...
Definition Switch.h:439
virtual void SetCenter(const spat::Frame< Length, One > &center)=0
Sets the center of the switch.
virtual MultiPlug & PlugTo(Status status)=0
Gets a Plug that switches to the specified Status.
Status
Status values of a switch.
Definition Switch.h:460
virtual Status Get() const =0
Gets the setting of the switch.
SlotNames
Definition Switch.h:444
@ slot_4
diverging track end connecting to slot_0
Definition Switch.h:450
@ slot_5
diverging track end connecting to slot_1
Definition Switch.h:451
@ slot_3
second straight track end
Definition Switch.h:449
@ slot_1
second narrow track end
Definition Switch.h:447
@ slot_0
first narrow track end
Definition Switch.h:446
@ slot_2
first straight track end
Definition Switch.h:448
static dclspc std::unique_ptr< SingleSlipSwitch > Make() noexcept
Makes a standard SingleSlipSwitch object.
virtual Status Set(Status to, bool pulse=true)=0
Turns the switch to the specified setting.
virtual Jack & JackOn(Status status)=0
Gets a Jack that pulses its Plug if the specified Status is set.
A Switch rearranges the connections between three track ends.
Definition Switch.h:186
virtual bool IsNormal(bool bStopAtFirstTrack=true, Length maxDistance=infinite__length) const =0
Returns true, if the straight track has fewer deviation from the narrow's track direction than the di...
virtual bool IsY(bool bStopAtFirstTrack=true, Length maxDistance=infinite__length, AnglePerLength margin=epsilon__angle/80_m) const =0
Is this an Y - switch?
virtual bool IsHorizontal(bool bStopAtFirstTrack=true, Length maxDistance=infinite__length) const =0
virtual void DivergedTrack(std::shared_ptr< TrackBuilder > pDivergedTrack, Track::EndType trackEnd)=0
Occupies the slot for the diverged track.
virtual bool BranchLeftOrRight(bool bStopAtFirstTrack=true, Length maxDistance=infinite__length) const =0
Tests wether the branching track develops to the left or right side of the straight track.
virtual MultiPlug & PlugToBranch() noexcept=0
Gets a Plug that sets the switch to branch.
virtual bool Normalize()=0
Swaps the outgoing tracks if this switch is not normal.
virtual bool BranchUpOrDown(bool bStopAtFirstTrack=true, Length maxDistance=infinite__length) const =0
Tests wether the branching track develops to the up or down side of the straight track.
virtual void ClearDivergedTrack()=0
Clears the slot for the diverged track.
virtual void SwapTracks()=0
Swaps the straight and the diverged track.
virtual Jack & JackOnBranch() noexcept=0
Gets a Jack that pulses its Plug if the switch is set to branch.
static dclspc std::unique_ptr< Switch > Make() noexcept
Makes a standard Switch object.
virtual bool IsVertical(bool bStopAtFirstTrack=true, Length maxDistance=infinite__length) const =0
A switch that is connecting one narrow end to three outgoing track ends.
Definition Switch.h:326
virtual MultiPlug & PlugToBranch2() noexcept=0
Gets a Plug that sets the switch to branch.
virtual Status StatusToRight() const =0
virtual Jack & JackOnBranch2() noexcept=0
Gets a Jack that pulses its Plug if the switch is set to branch.
virtual void SwapStraightWithDiverged2()=0
Swaps the straight and the diverged2 track.
virtual void DivergedTrack2(std::shared_ptr< TrackBuilder > pDivergedTrack2, Track::EndType trackEnd)=0
Occupies the slot for the diverged track.
virtual void DivergedTrack1(std::shared_ptr< TrackBuilder > pDivergedTrack1, Track::EndType trackEnd)=0
Occupies the slot for the diverged track.
virtual bool IsNormal() const =0
Returns true, if the straight track lies in the middle of the two diverging tracks and the first dive...
virtual void SwapStraightWithDiverged()=0
Swaps the straight and the diverged track.
virtual bool Normalize()=0
Rearranges the outgoing tracks if this switch is not normal.
virtual Status StatusToMiddle() const =0
virtual Jack & JackOnBranch1() noexcept=0
Gets a Jack that pulses its Plug if the switch is set to branch.
virtual void ClearDivergedTrack2()=0
Clears the slot for the diverged2 track.
virtual Status StatusToLeft() const =0
virtual void ClearDivergedTrack1()=0
Clears the slot for the diverged1 track.
virtual MultiPlug & PlugToBranch1() noexcept=0
Gets a Plug that sets the switch to branch.
static dclspc std::unique_ptr< ThreeWaySwitch > Make() noexcept
Makes a standard ThreeWaySwitch object.
virtual void SwapDivergedWithDiverged2()=0
Swaps the diverged and the diverged2 track.
Interface for making and shaping tracks.
Definition Track.h:831
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