Turnout

Struct Turnout 

Source
pub struct Turnout { /* private fields */ }
Expand description

Turnout track struct

Implementations§

Source§

impl Turnout

Source

pub fn new( layer: u32, options: u32, postion: u32, scale: Scale, flags: u32, origx: f64, origy: f64, elev: u32, angle: f64, tablist: String, adjopt: Option<(f64, f64)>, pieropt: Option<(f64, String)>, body: TurnoutBody, ) -> Self

Initialize a new turnout

§Parameters:
  • layer the layer the turnout is on
  • options its options
  • postion the position of the points
  • scale the model scale
  • flags its flags
  • origx org X
  • origy org Y
  • elev elevation
  • angle its angle
  • tablist tab separated list of strings
  • adjopt optional adjustments
  • pieropt optiona pier
  • body its body (track ends. etc.)

Returns a fresh new Turnout struct

Source

pub fn Layer(&self) -> u32

Source

pub fn Options(&self) -> u32

Source

pub fn Postion(&self) -> u32

Source

pub fn Scale(&self) -> Scale

Source

pub fn Flags(&self) -> u32

Source

pub fn OrigX(&self) -> f64

Source

pub fn OrigY(&self) -> f64

Source

pub fn Elev(&self) -> u32

Source

pub fn Angle(&self) -> f64

Source

pub fn Tablist(&self) -> String

Examples found in repository?
examples/PrintAllControlScripts/main.rs (line 153)
80fn main() {
81    let args: Vec<String> = env::args().collect();
82    let program = args[0].clone();
83
84    let mut opts = Options::new();
85    opts.optflag("b", "blocks", "print Blocks");
86    opts.optflag("m", "switchmotors", "print Switchmotors");
87    opts.optflag("s", "signals", "print Signals ");
88    opts.optflag("c", "controls", "print Controls");
89    opts.optflag("x", "sensors", "print Sensors");
90    opts.optflag("a", "all", "print all (this is the default)");
91    opts.optflag("h", "help", "print this help menu");
92    let matches = match opts.parse(&args[1..]) {
93        Ok(m) => { m },
94        Err(f) => { panic!("{}", f.to_string());  },
95    };
96    if matches.opt_present("h") {
97        print_usage(&program, opts);
98        return ();
99    };
100    let mut blocks: bool = false;
101    let mut switchmotors: bool = false;
102    let mut signals: bool = false;
103    let mut controls: bool = false;
104    let mut sensors: bool = false;
105    let mut all: bool = true;
106    if matches.opt_present("b") {
107        blocks = true;
108        all = false;
109    }
110    if matches.opt_present("m") {
111        switchmotors = true;
112        all = false;
113    }
114    if matches.opt_present("s") {
115        signals = true; 
116        all = false;
117    }
118    if matches.opt_present("c") {
119        controls = true; 
120        all = false;
121    }
122    if matches.opt_present("x") {
123        sensors = true;
124        all = false;
125    }
126    if matches.opt_present("a") {
127        all = true;
128    }
129    let layoutfile = if !matches.free.is_empty() {
130        matches.free[0].clone()
131    } else {
132        print_usage(&program, opts);
133        panic!("Missing layout file!");
134    };
135    let layout = match Layout::new(layoutfile) {
136        Ok(l) => { l },
137        Err(message) => { panic!("{}",message.to_string()); },
138    };
139    println!("{}",layout);
140    if blocks || all {
141        for (index, block) in layout.BlockIter() {
142            println!("Block # {}:",*index);
143            println!("\tName: {}",block.Name());
144            println!("\tScript: {}",block.Script());
145            println!("\tTrack list: {}",block.Tracklist());
146        }
147    }
148    if switchmotors || all {
149        for (index, switchmotor) in layout.SwitchMotorIter() {
150            println!("SwitchMotor # {}:",*index);
151            println!("\tName: {}",switchmotor.Name());
152            let turnout = layout.Turnout(switchmotor.Turnout()).expect("Should not happen");
153            let tablist = turnout.Tablist();
154            let tabelts: Vec<&str> = tablist.split('\t').collect();
155            println!("\tTurnout #{} ({})",switchmotor.Turnout(),tabelts[1]);
156            println!("\tNormal: {}",switchmotor.Normal());
157            println!("\tReverse: {}",switchmotor.Reverse());
158            println!("\tPoint Sense: {}",switchmotor.Pointsense());
159        }
160    }
161    if signals || all {
162        for (index, signal) in layout.SignalIter() {
163            println!("Signal # {}:",*index);
164            println!("\tName: {}",signal.Name());
165            println!("\tHeads: {}",signal.Numheads());
166            let aspects = signal.Aspectlist();
167            if aspects.len() > 0 {
168                println!("\tAspects:");
169                for ia in 0..aspects.len() {
170                    let aspect = &aspects[ia];
171                    println!("\t\t{}: {}",aspect.Name(), aspect.Script());
172                }
173            }
174        }
175    }
176    if sensors || all {
177        for (index, sensor) in layout.SensorIter() {
178            println!("Sensor # {}",*index);
179            println!("\tName: {}",sensor.Name());
180            println!("\tScript: {}",sensor.Script());
181        }
182    }
183    if controls  || all {
184        for (index, control) in layout.ControlIter() {
185            println!("Control # {}",*index);
186            println!("\tName: {}",control.Name());
187            println!("\tOn Script: {}",control.OnScript());
188            println!("\tOff Script: {}",control.OffScript());
189        }
190    }
191}
Source

pub fn AdjOpt(&self) -> Option<(f64, f64)>

Source

pub fn PierOpt(&self) -> Option<(f64, String)>

Source

pub fn Body(&self) -> TurnoutBody

Trait Implementations§

Source§

impl Clone for Turnout

Source§

fn clone(&self) -> Turnout

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Turnout

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Turnout

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Turnout

Source§

fn eq(&self, other: &Turnout) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Turnout

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.