Trax3 3.1.0
trax track library
Loading...
Searching...
No Matches
TrainComponent.h
1// trax track library
2// AD 2024
3//
4// "the resolution of all the fruitless searches"
5//
6// Peter Gabriel
7//
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
30#include "RailRunner.h"
31#include "trax/Orientation.h"
32
33namespace trax{
34
35 struct Bogie;
36 struct Train;
37
40 {
42 virtual std::shared_ptr<TrainComponent> ThisTrainComponent() const noexcept = 0;
43
44
46 virtual Train* GetTrain() const noexcept = 0;
47
48
50 virtual Orientation GetOrientation() const noexcept = 0;
51
52
55 virtual std::pair<Train*,Orientation> GetTopmostTrain() const noexcept = 0;
56
57
59 virtual bool IsFinal() const noexcept = 0;
60
61
64 virtual bool IsParent( const Train& train ) const noexcept = 0;
65
66
67 enum class DistanceType{
68 actual,
69 min,
70 max,
71 half,
72 };
73
74 using RailRunner::Rail;
75
81 virtual void Rail( const Location& location, bool bMoveTo, DistanceType distance ) = 0;
82
83
85
86 virtual void ResetToGlobalAnchor( const spat::Frame<Length,One>& anchorPose, DistanceType distance ) = 0;
87
88
89
90 // Coupled:
91
93 struct Coupling{
94 std::shared_ptr<TrainComponent> pTrainComponentA;
96 std::shared_ptr<TrainComponent> pTrainComponentB;
98 };
99
100
117 virtual bool Couple( EndType end, TrainComponent& with, EndType withEnd, bool btriggerPulses = true ) noexcept = 0;
118
119
128 virtual std::pair<std::shared_ptr<TrainComponent>,EndType> GetCoupledTrainComponent( EndType end ) const noexcept = 0;
129
130
140 virtual Length GetCouplingLength( EndType end, DistanceType distance = DistanceType::max ) const noexcept = 0;
141
142
151
157 virtual std::pair<Bogie&,EndType> GetTipAt( EndType end ) = 0;
158
164 virtual std::pair<const Bogie&,EndType> GetTipAt( EndType end ) const = 0;
166
167
168 // Geometry:
169
176 virtual Length GetOverhang( EndType end, DistanceType distance = DistanceType::actual ) const noexcept = 0;
177
178
182 virtual Length GetLength( DistanceType distance = DistanceType::actual ) const noexcept = 0;
183
184
185 // Dynamics:
186
188 virtual Mass GetTotalMass() const noexcept = 0;
189
190
191 // Jacks 'N Plugs:
192
195 virtual Jack& JackOnRail() noexcept = 0;
196
197
200 virtual Jack& JackOnDerail() noexcept = 0;
201
202
203 protected:
204 friend class Train_Imp;
205 // TrainComponent_Imp:
206 virtual void SetTrain( Train* pTrain ) noexcept = 0;
207
208 virtual void SetOrientation( Orientation orientation ) noexcept = 0;
209 };
210
211
213 dclspc bool Couple( const TrainComponent::Coupling& coupling ) noexcept;
214
215
217 dclspc Train* CommonParent( const TrainComponent& a, const TrainComponent& b ) noexcept;
218
219
220}
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
Value< Dimension< 0, 1, 0 > > Mass
Mass.
Definition DimensionedValues.h:327
STL namespace.
Namespace of all the trax track libraries classes and methods.
Definition Collection.h:17
dclspc Train * CommonParent(const TrainComponent &a, const TrainComponent &b) noexcept
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
A Bogie is a RailRunner that can be attached to another Bogie by a swivel and can be coupled to anoth...
Definition Bogie.h:67
A jack a plug can get connected with.
Definition Jack.h:83
Provides two values for orientation.
Definition Orientation.h:37
Interface for train and rolling stock that can be railed on a track and might provide brakes and powe...
Definition RailRunner.h:345
virtual void ResetToGlobalAnchor(const spat::Frame< Length, One > &anchorPose)=0
Sets the position of the RailRunner so that its global anchor alignes to the given global pose.
EndType
Types of the RailRunner's end's.
Definition RailRunner.h:351
virtual void Rail(const Location &location, bool bMoveTo=true)=0
Attaches this RailRunner onto the specified track location.
Structure describing a coupling between two TrainComponents.
Definition TrainComponent.h:93
EndType endB
The end of B.
Definition TrainComponent.h:97
EndType endA
The end of A.
Definition TrainComponent.h:95
std::shared_ptr< TrainComponent > pTrainComponentA
The TrainComponent A.
Definition TrainComponent.h:94
std::shared_ptr< TrainComponent > pTrainComponentB
The TrainComponent B.
Definition TrainComponent.h:96
A TrainComponent is a part of a Train.
Definition TrainComponent.h:40
virtual std::pair< std::shared_ptr< TrainComponent >, EndType > GetCoupledTrainComponent(EndType end) const noexcept=0
Get the coupled TrainComponent.
virtual Mass GetTotalMass() const noexcept=0
virtual void Rail(const Location &location, bool bMoveTo, DistanceType distance)=0
Rails this TrainComponent at the given location.
virtual Length GetOverhang(EndType end, DistanceType distance=DistanceType::actual) const noexcept=0
Gets the distances from the track location (i.e. global anchor) to the north or south tip of the Rail...
virtual Length GetLength(DistanceType distance=DistanceType::actual) const noexcept=0
Gets the total length of this RailRunner.
virtual Orientation GetOrientation() const noexcept=0
virtual Train * GetTrain() const noexcept=0
virtual bool IsParent(const Train &train) const noexcept=0
virtual bool IsFinal() const noexcept=0
virtual Jack & JackOnRail() noexcept=0
Gets a Jack that pulses its Plug if the RailRunner gets railed on a track.
virtual Jack & JackOnDerail() noexcept=0
Gets a Jack that pulses its Plug if the RailRunner derails.
virtual std::shared_ptr< TrainComponent > ThisTrainComponent() const noexcept=0
Gets a shared pointer to this.
virtual std::pair< Bogie &, EndType > GetTipAt(EndType end)=0
virtual Length GetCouplingLength(EndType end, DistanceType distance=DistanceType::max) const noexcept=0
Gets the length of the coupling from TrainComponent edge to TrainComponent edge.
virtual bool Couple(EndType end, TrainComponent &with, EndType withEnd, bool btriggerPulses=true) noexcept=0
Couples this TrainComponent with another at the respective ends.
virtual std::pair< Train *, Orientation > GetTopmostTrain() const noexcept=0
A Train is a collection of TrainComponents that are coupled in a row.
Definition Train.h:43