Trax3 3.1.0
trax track library
Loading...
Searching...
No Matches
trax::Train Struct Referenceabstract

A Train is a collection of TrainComponents that are coupled in a row. More...

#include <C:/Trend/Development/Trax3/Code/trax/rigid/trains/Train.h>

Inheritance diagram for trax::Train:

Public Member Functions

virtual std::shared_ptr< TrainThisTrain () const noexcept=0
 Gets a shared pointer to this.
virtual int GetNumberOfComponents () const noexcept=0
virtual std::shared_ptr< TrainComponentGetComponent (int index) const =0
 Gets the TrainComponent at zero based index.
virtual int GetIndexOf (const TrainComponent &component) const noexcept=0
virtual void Take (EndType atEnd, Train &fromTrain, EndType withEnd)=0
 Takes all components from another Train.
virtual std::pair< std::shared_ptr< Train >, std::shared_ptr< Train > > SplitAfter (int idxAt)=0
 Splits this Train into two Trains at the specified index.
virtual std::shared_ptr< TrainSeparate ()=0
 Removes everything south of a broken internal coupling from this Train, and returns a new Train with the components that were removed.
virtual void Reduce (bool bRecursive=true) noexcept=0
 Removes TrainComponents from this Train and includes them directly to the parent train. This Train will become empty and !IsValid().
virtual void Clear () noexcept=0
 Removes all components from this train.
virtual bool Couple (EndType thisEnd, Train &with, EndType withEnd) noexcept=0
 Couples this Train with another at the respective ends.
virtual bool IsUnCoupledInternally () const noexcept=0
virtual struct JackJackOnUnCoupleInternal () noexcept=0
 Gets a Jack that pulses its Plug if a coupling inside the train (including all sub-Trains) is uncoupled for whatever reason.
virtual bool Couple (EndType end, TrainComponent &with, EndType withEnd, bool btriggerPulses=true) noexcept=0
 Couples this TrainComponent with another at the respective ends.
Create

Creates a train from components

virtual bool Create (TrainComponent &trainComponent, Orientation orientation=Orientation::Value::para)=0
virtual bool Create (const std::vector< std::pair< std::shared_ptr< TrainComponent >, Orientation > > &trainComponents, Orientation orientation=Orientation::Value::para, bool bMoveTo=true, DistanceType distance=DistanceType::actual)=0
Align

Positions the component at the respective Train end, but does not couple it or include it in the train.

If this Train is railed, the component will be railed at the respective end; if the Train is not railed, the component will be moved to the respective end.

Exceptions
std::exceptionif there is an error in railing the component.
std::logic_errorif there are invalid components.
virtual void Align (EndType atEnd, TrainComponent &component, EndType withEnd) const =0
virtual void Align (EndType atEnd, TrainComponent &component, Orientation orientation) const =0
Append

Appends a TrainComponent to this Train.

The component gets coupled (if bCouple) and becomes a part of this Train, but it will not get moved or railed. Use Align() to position or rail it properly first.

Parameters
atEndEnd of this Train to append to.
pComponentThe TrainComponent to append. Does nothing if nullptr.
bCoupleif true, the omponent gets coupled properly, if false the coupling state remains unchanged.
withEndEnd of the TrainComponent to append.
orientationOrientation of the TrainComponent to append it in.
Exceptions
std::invalid_argumentif the TrainComponent is already part of a Train.
std::runtime_errorif the TrainComponent is of unknown type.
virtual void Append (EndType atEnd, std::shared_ptr< TrainComponent > pComponent, EndType withEnd, bool bCouple=true)=0
virtual void Append (EndType atEnd, std::shared_ptr< TrainComponent > pComponent, Orientation orientation, bool bCouple=true)=0
Public Member Functions inherited from trax::TrainComponent
virtual std::shared_ptr< TrainComponentThisTrainComponent () const noexcept=0
 Gets a shared pointer to this.
virtual TrainGetTrain () const noexcept=0
virtual Orientation GetOrientation () const noexcept=0
virtual std::pair< Train *, OrientationGetTopmostTrain () const noexcept=0
virtual bool IsFinal () const noexcept=0
virtual bool IsParent (const Train &train) const noexcept=0
virtual void Rail (const Location &location, bool bMoveTo, DistanceType distance)=0
 Rails this TrainComponent at the given location.
virtual void ResetToGlobalAnchor (const spat::Frame< Length, One > &anchorPose, DistanceType distance)=0
virtual std::pair< std::shared_ptr< TrainComponent >, EndTypeGetCoupledTrainComponent (EndType end) const noexcept=0
 Get the coupled TrainComponent.
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 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 RailRunner.
virtual Length GetLength (DistanceType distance=DistanceType::actual) const noexcept=0
 Gets the total length of this RailRunner.
virtual Mass GetTotalMass () const noexcept=0
virtual JackJackOnRail () noexcept=0
 Gets a Jack that pulses its Plug if the RailRunner gets railed on a track.
virtual JackJackOnDerail () noexcept=0
 Gets a Jack that pulses its Plug if the RailRunner derails.
virtual void Rail (const Location &location, bool bMoveTo=true)=0
 Attaches this RailRunner onto the specified track location.
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.
virtual std::pair< Bogie &, EndTypeGetTipAt (EndType end)=0
virtual std::pair< const Bogie &, EndTypeGetTipAt (EndType end) const =0
Public Member Functions inherited from trax::RailRunner
virtual const char * TypeName () const noexcept=0
virtual std::shared_ptr< RailRunnerThis () const noexcept=0
 Gets a shared pointer to this.
virtual bool IsValid () const noexcept=0
virtual Location GetLocation () const noexcept=0
 Gets the track location were the RailRunner is railed.
virtual void DeRail () noexcept=0
 Take the RailRunner from the track.
virtual bool IsRailed () const noexcept=0
 Is the RailRunner on a track?
virtual spat::Frame< Length, OneGetGlobalAnchor () const =0
 Gets the global anchor of the RailRunner.
virtual void SetVelocity (Velocity velocity)=0
 Sets the velocity of this RailRunner along the track.
virtual Velocity GetVelocity () const =0
virtual void TargetVelocity (Velocity velocity)=0
 Sets the target velocity to aim for by using the supplied Thrust() and Brake() settings.
virtual Velocity TargetVelocity () const noexcept=0
virtual EndType TargetDirection () const noexcept=0
 Gets the principle direction of movement according to the sign of the target velocity.
virtual Power MaximumPowerOutput () const noexcept=0
virtual Power CurrentPowerOutput () const noexcept=0
virtual Velocity MaximumVelocity () const noexcept=0
virtual void Thrust (One byfactor)=0
 Sets the fraction of the maximum thrust to apply in order to reach the target velocity specified by TargetVelocity().
virtual One Thrust () const noexcept=0
 Gets the fraction of the maximum thrust applied.
virtual void ThrustAbsolute (Force thrust)=0
 Sets the thrust as absolute force values. If the value exceeds MaxThrust() it get clipped.
virtual Force ThrustAbsolute () const noexcept=0
virtual void Brake (One byfactor)=0
 Sets the fraction of the maximum braking to apply in order
to reach a zero velocity.
virtual One Brake () const noexcept=0
 Gets the fraction of the maximum braking applied.
virtual void BrakeAbsolute (Force brake)=0
 Sets the brake as absolute force value. If the value exceeds MaxBrake() it gets clipped.
virtual Force BrakeAbsolute () const noexcept=0
virtual Force MaxBrake () const noexcept=0
 Gets the maximal available braking. This value is determined by the properties of the Wheelsets attached to WheelFrames wich in turn are attached to a bogie.
virtual void ActivateCoupling (EndType end)=0
 Activates the coupling at the respective end of the RailRunner.
virtual void DeactivateCoupling (EndType end)=0
 Deactivates the coupling at the respective end of the RailRunner.
virtual bool IsActivated (EndType end) const noexcept=0
virtual bool Uncouple (EndType end=EndType::all, bool btriggerPulses=true) noexcept=0
 Uncouples the RailRunner at the specified end.
virtual bool IsCoupled (EndType end=EndType::any) const noexcept=0
 Is the coupling coupled?
virtual Length GetCouplingHeight (EndType end) const noexcept=0
 Gets the height of the coupling over the track.
virtual JackJackOnCouple (EndType end)=0
 Gets a Jack that pulses its Plug if one (or any) of the RailRunner's outmost couplings get coupled.
virtual JackJackOnUnCouple (EndType end)=0
 Gets a Jack that pulses its Plug if one (or any) of the RailRunner's outmost couplings get uncoupled or breaks.
virtual JackJackOnCouplingActivated (EndType end)=0
 Gets a Jack that pulses its Plug if one (or any) of the RailRunner's outmost couplings get activated.
virtual JackJackOnCouplingDeactivated (EndType end)=0
 Gets a Jack that pulses its Plug if one (or any) of the RailRunner's outmost couplings get deactivated.
virtual void UserData (RailRunnerUserData *pData) noexcept=0
 Sets a pointer to user provided data.
virtual RailRunnerUserData * UserData () const noexcept=0
virtual Force MaxThrust () const noexcept=0
virtual Force MaxThrust (Velocity velocity) const noexcept=0
Public Member Functions inherited from trax::Identified< RailRunner >
virtual const std::string & Reference (const std::string &name) const=0
 Gets a reference that was set for this object by name.
virtual const std::vector< char const * > & ReferenceNames (const std::string &namePart) const=0
 Searches for all reference names that countain namePart as substring in the name.
virtual IDType ID () const noexcept=0
 Identified (const Identified &)=delete
Identified & operator= (const Identified &)=delete

Static Public Member Functions

static dclspc std::shared_ptr< TrainMake () noexcept
 Makes a Train object.

Additional Inherited Members

Public Types inherited from trax::TrainComponent
enum class  DistanceType { actual , min , max , half }
Public Types inherited from trax::RailRunner
enum class  EndType : char {
  none = 0 , north , south , any ,
  all
}
 Types of the RailRunner's end's. More...
Protected Member Functions inherited from trax::TrainComponent
virtual void SetTrain (Train *pTrain) noexcept=0
virtual void SetOrientation (Orientation orientation) noexcept=0

Detailed Description

A Train is a collection of TrainComponents that are coupled in a row.

A Train can be railed and moved on a track. It can be coupled with other Trains and can be split into two Trains. A Train can be reduced to a collection of RollingStock. If a Train splits by a breaking coupling the Train object dereferences all its components and becomes invalid.

Member Function Documentation

◆ Align() [1/2]

virtual void trax::Train::Align ( EndType atEnd,
TrainComponent & component,
EndType withEnd ) const
pure virtual
Parameters
atEndEnd of this Train to append to.
componentThe TrainComponent to align.
withEndEnd of the TrainComponent to align with.

◆ Align() [2/2]

virtual void trax::Train::Align ( EndType atEnd,
TrainComponent & component,
Orientation orientation ) const
pure virtual
Parameters
atEndEnd of this Train to append to.
componentThe TrainComponent to align.
orientationThe orientation of the TrainComponent to align it in.

◆ Clear()

virtual void trax::Train::Clear ( )
pure virtualnoexcept

Removes all components from this train.

Decouples all components and removes them from this train. It leaves subtrains intact.

◆ Couple() [1/2]

virtual bool trax::TrainComponent::Couple ( EndType end,
TrainComponent & with,
EndType withEnd,
bool btriggerPulses = true )
virtualnoexcept

Couples this TrainComponent with another at the respective ends.

It doesn't matter, wether the two couplings are near each other or not. The coupling will try to maintain the actual distance of the two TrainComponent's ends. The coupling attempt will fail if the two TrainComponent are already coupled (with different partners or the same parters at different ends) or if one of the couplings is deactivated. An coupling attempt will also fail, when two couplings wear different coupling type indices.

See also
Bogie::CouplingProps.
Parameters
endEnd of this TrainComponent.
withOther TrainComponent.
withEndOther TrainComponent's end to couple with.
btriggerPulsesIf true the respective JackOnCouple jacks are pulsing.
Returns
true if a new coupling was established or the two TrainComponent were already properly coupled.

Implements trax::TrainComponent.

◆ Couple() [2/2]

virtual bool trax::Train::Couple ( EndType thisEnd,
Train & with,
EndType withEnd )
pure virtualnoexcept

Couples this Train with another at the respective ends.

It doesn't matter, wether the two couplings are near each other or not. The coupling will try to maintain the actual distance of the two Train's ends. The coupling attempt will fail if the two Trains are already coupled (with different partners or the same parters at different ends) or if one of the couplings is deactivated. An coupling attempt will also fail, when two couplings wear different coupling type indices.

See also
Bogie::CouplingProps.
Parameters
thisEndEnd of this Train.
withOther Train.
withEndOther Train's end to couple with.
Returns
true if a new coupling was established or the two Trains were already properly coupled.

◆ Create() [1/2]

virtual bool trax::Train::Create ( const std::vector< std::pair< std::shared_ptr< TrainComponent >, Orientation > > & trainComponents,
Orientation orientation = Orientation::Value::para,
bool bMoveTo = true,
DistanceType distance = DistanceType::actual )
pure virtual

This method takes a list of uncoupled TrainComponents and builds a Train from them. It will do the coupling of the elements properly.

Parameters
trainComponentsA list of TrainComponents to make a Train from.
orientationThe orientation of the given components in the Train. location, prior to coupling.
bMoveToIf true, the TrainComponents will be moved to a proper position.
distanceThe distance to use between the TrainComponents in moving.
Returns
True if the train was successfully created.

◆ Create() [2/2]

virtual bool trax::Train::Create ( TrainComponent & trainComponent,
Orientation orientation = Orientation::Value::para )
pure virtual

This method will find all already coupled components and build a Train from them.

Parameters
trainComponentThe TrainComponent to make a Train from.
orientationThe orientation of the given components in the Train. location, prior to coupling.
Returns
True if the train was successfully created.

◆ GetComponent()

virtual std::shared_ptr< TrainComponent > trax::Train::GetComponent ( int index) const
pure virtual

Gets the TrainComponent at zero based index.

Parameters
indexzero based Index of the TrainComponent.

◆ GetIndexOf()

virtual int trax::Train::GetIndexOf ( const TrainComponent & component) const
pure virtualnoexcept
Returns
the valid zero based index of the component if it is part of this Train or -1.
Parameters
componentThe TrainComponent to search for.

◆ GetNumberOfComponents()

virtual int trax::Train::GetNumberOfComponents ( ) const
pure virtualnoexcept
Returns
The number of train components.

◆ IsUnCoupledInternally()

virtual bool trax::Train::IsUnCoupledInternally ( ) const
pure virtualnoexcept
Returns
false if all the internal couplings of this Train (inluding that of sub-Trains) are coupled propery. True if one such coupling is broken or uncoupled.

◆ Reduce()

virtual void trax::Train::Reduce ( bool bRecursive = true)
pure virtualnoexcept

Removes TrainComponents from this Train and includes them directly to the parent train. This Train will become empty and !IsValid().

Does nothing if this Train has no parent Train. The coupling and railing states as well as the poses of the components remain unchanged.

Parameters
bRecursiveif true, the method will be applied recursively to all sub-components, leaving the Train reduced to its RollingStock components only.

◆ Separate()

virtual std::shared_ptr< Train > trax::Train::Separate ( )
pure virtual

Removes everything south of a broken internal coupling from this Train, and returns a new Train with the components that were removed.

No coupling or railing as well as no change of poses is done. The new train as well as this train might be left with a single component; use Reduce() or Clear() to remove redundant Trains.

Returns
a new Train with the components that were removed or nullptr if there was no broken coupling.

◆ SplitAfter()

virtual std::pair< std::shared_ptr< Train >, std::shared_ptr< Train > > trax::Train::SplitAfter ( int idxAt)
pure virtual

Splits this Train into two Trains at the specified index.

Two new trains are created from the components, leaving the idxAt component at the first and idxAt+1 at the second fragment. This train becomes the parent train of the two new trains. Note that the TrainComponents idxAt and idxAt+1 do not get uncoupled from each other; use Clear() to remove all components from this train and decouple them.

Parameters
idxAtThe zero based index to split at. 0 is the first component.
Returns
A pair of shared pointers to the two new trains. Will be nullptrs if idxAt is out of range.

◆ Take()

virtual void trax::Train::Take ( EndType atEnd,
Train & fromTrain,
EndType withEnd )
pure virtual

Takes all components from another Train.

Takes all components from another Train and Append()s them to this Train. As with Append() the components are not railed or moved, but get coupled if not already so. This methods does not change the poses of the components.

Parameters
atEndEnd of this Train to append to.
fromTrainThe Train to take components from.
withEndEnd of the fromTrain to take components from.

The documentation for this struct was generated from the following file:
  • C:/Trend/Development/Trax3/Code/trax/rigid/trains/Train.h