001package jmri.jmrit.dispatcher;
002
003import jmri.InstanceManager;
004import jmri.Sensor;
005import jmri.SensorManager;
006import jmri.jmrit.dispatcher.ActiveTrain.TrainDetection;
007import jmri.jmrit.dispatcher.ActiveTrain.TrainLengthUnits;
008import jmri.jmrit.dispatcher.DispatcherFrame.TrainsFrom;
009
010/**
011 * TrainInfo is a temporary object specifying New Train information just read
012 * from disk, or to be written to disk
013 * <p>
014 * Used in conjunction with TrainInfoFile.java to save and retrieve New Train
015 * information
016 * <p>
017 * When adding a new item of New Train information, modifications need to be
018 * made to TrainInfoFile.java and dispatcher-traininfo.DTD as well as this
019 * module.
020 *
021 * @author Dave Duchamp Copyright (C) 2009
022 */
023public class TrainInfo {
024
025    public TrainInfo() {
026    }
027
028    // instance variables for both manual and automatic operation
029    private int version = 1;
030    private String transitName = "";
031    private String transitId = "";
032    private String trainName = "";
033    private String rosterID = "";
034    private String trainUserName = "";
035    private String dccAddress = "3";
036    private boolean trainInTransit = false;
037    private String startBlockName = "";
038    private String startBlockId = "";
039    private int startBlockSeq = -1;
040    private String destinationBlockName = "";
041    private String destinationBlockId = "";
042    private int destinationBlockSeq = -1;
043    private boolean trainFromRoster = true;
044    private boolean trainFromTrains = false;
045    private boolean trainFromUser = false;
046    private boolean trainFromSetLater = false;
047    private int priority = 5;
048    private boolean autoRun = false;
049    private boolean resetWhenDone = false;
050    private boolean allocateAllTheWay = false;
051    private int allocationMethod = 3;
052    private boolean reverseAtEnd = false;
053    private int delayedStart = ActiveTrain.NODELAY;
054    private int delayedRestart = ActiveTrain.NODELAY;
055    private int departureTimeHr = 8;
056    private int departureTimeMin = 00;
057    private String delaySensorName = null;
058    private boolean resetStartSensor = true;
059
060    private String restartSensorName = null;
061    private boolean resetRestartSensor = true;
062    private int restartDelayMin = 0;
063
064    private int reverseDelayedRestart = ActiveTrain.NODELAY;
065    private String reverseRestartSensorName = null;
066    private boolean reverseResetRestartSensor = true;
067    private int reverseRestartDelayMin = 0;
068
069    private String trainType = "";
070    private boolean terminateWhenDone = false;
071    private String nextTrain = "None";
072    private boolean loadAtStartup = false;
073
074    // instance variables for automatic operation
075    private float speedFactor = 1.0f;
076    private float maxSpeed = 1.0f;
077    private float minReliableOperatingSpeed = 0.0f;
078    private String rampRate = Bundle.getMessage("RAMP_NONE");
079    private TrainDetection trainDetection = TrainDetection.TRAINDETECTION_HEADONLY;
080    private boolean runInReverse = false;
081    private boolean soundDecoder = false;
082    private float maxTrainLength = 100.0f;
083    private float maxTrainLengthMeters = 30.0f;
084    private TrainLengthUnits trainLengthUnits = TrainLengthUnits.TRAINLENGTH_SCALEFEET; // units used to enter value
085    private boolean useSpeedProfile = false;
086    private boolean stopBySpeedProfile = false;
087    private float stopBySpeedProfileAdjust = 1.0f;
088
089    private float waitTime = 1.0f; //required only by dispatcher system to pause train at beginning of transit (station)
090
091    private String blockName = ""; //required only by Dispatcher System to inhibit running of transit if this block is occupied
092
093
094    //
095    // Access methods for manual and automatic instance variables
096    //
097    public void setVersion(int ver) {
098        version = ver;
099    }
100    public int getVersion() {
101        return version;
102    }
103
104    public void setTransitName(String s) {
105        transitName = s;
106    }
107
108    public String getTransitName() {
109        return transitName;
110    }
111
112    public void setTransitId(String s) {
113        transitId = s;
114    }
115
116    public String getTransitId() {
117        return transitId;
118    }
119
120    public void setTrainName(String s) {
121        trainName = s;
122    }
123
124    public String getTrainName() {
125        return trainName;
126    }
127
128    public void setRosterId(String s) {
129        rosterID = s;
130    }
131
132    public String getRosterId() {
133        return rosterID;
134    }
135
136    public void setTrainUserName(String s) {
137        trainUserName = s;
138    }
139
140    public String getTrainUserName() {
141        return trainUserName;
142    }
143
144    public void setDccAddress(String s) {
145        dccAddress = s;
146    }
147
148    public String getDccAddress() {
149        return dccAddress;
150    }
151
152    public void setTrainInTransit(boolean b) {
153        trainInTransit = b;
154    }
155
156    public boolean getTrainInTransit() {
157        return trainInTransit;
158    }
159
160    public void setStartBlockName(String s) {
161        startBlockName = s;
162    }
163
164    public String getStartBlockName() {
165        return startBlockName;
166    }
167
168    public void setStartBlockId(String s) {
169        startBlockId = s;
170    }
171
172    public String getStartBlockId() {
173        return startBlockId;
174    }
175
176    public void setStartBlockSeq(int i) {
177        startBlockSeq = i;
178    }
179
180    public int getStartBlockSeq() {
181        return startBlockSeq;
182    }
183
184    public void setDestinationBlockName(String s) {
185        destinationBlockName = s;
186    }
187
188    public String getDestinationBlockName() {
189        return destinationBlockName;
190    }
191
192    public void setDestinationBlockId(String s) {
193        destinationBlockId = s;
194    }
195
196    public String getDestinationBlockId() {
197        return destinationBlockId;
198    }
199
200    public void setDestinationBlockSeq(int i) {
201        destinationBlockSeq = i;
202    }
203
204    public int getDestinationBlockSeq() {
205        return destinationBlockSeq;
206    }
207
208    public void setTrainsFrom(TrainsFrom value) {
209        trainFromRoster = false;
210        trainFromTrains = false;
211        trainFromUser = false;
212        trainFromSetLater = false;
213        switch (value) {
214            case TRAINSFROMROSTER:
215                trainFromRoster = true;
216                break;
217            case TRAINSFROMOPS:
218                trainFromTrains = true;
219                break;
220            case TRAINSFROMUSER:
221                trainFromUser = true;
222                break;
223            case TRAINSFROMSETLATER:
224            default:
225                trainFromSetLater = true;
226        }
227    }
228
229    public TrainsFrom getTrainsFrom() {
230        if (trainFromRoster) {
231            return TrainsFrom.TRAINSFROMROSTER;
232        } else if (trainFromTrains) {
233            return TrainsFrom.TRAINSFROMOPS;
234        } else if (trainFromUser) {
235            return TrainsFrom.TRAINSFROMUSER;
236        }
237        return TrainsFrom.TRAINSFROMSETLATER;
238    }
239
240    public void setTrainFromRoster(boolean b) {
241        trainFromRoster = b;
242    }
243
244    public boolean getTrainFromRoster() {
245        return trainFromRoster;
246    }
247
248    public void setTrainFromTrains(boolean b) {
249        trainFromTrains = b;
250    }
251
252    public boolean getTrainFromTrains() {
253        return trainFromTrains;
254    }
255
256    public void setTrainFromUser(boolean b) {
257        trainFromUser = b;
258    }
259
260    public boolean getTrainFromUser() {
261        return trainFromUser;
262    }
263
264    public void setTrainFromSetLater(boolean b) {
265        trainFromSetLater = b;
266    }
267
268    public boolean getTrainFromSetLater() {
269        return trainFromSetLater;
270    }
271
272    public void setTerminateWhenDone(boolean b) {
273        terminateWhenDone = b;
274    }
275
276    public boolean getTerminateWhenDone() {
277        return terminateWhenDone;
278    }
279
280    public void setNextTrain(String s) {
281        nextTrain = s;
282    }
283
284    public String getNextTrain() {
285        return nextTrain;
286    }
287
288
289    public void setPriority(int pri) {
290        priority = pri;
291    }
292
293    public int getPriority() {
294        return priority;
295    }
296
297    public void setAutoRun(boolean b) {
298        autoRun = b;
299    }
300
301    public boolean getAutoRun() {
302        return autoRun;
303    }
304
305    public void setResetWhenDone(boolean b) {
306        resetWhenDone = b;
307    }
308
309    public boolean getResetWhenDone() {
310        return resetWhenDone;
311    }
312
313    public void setAllocateAllTheWay(boolean b) {
314        allocateAllTheWay = b;
315    }
316
317    public boolean getAllocateAllTheWay() {
318        return allocateAllTheWay;
319    }
320
321    public void setAllocationMethod(int i) {
322        allocationMethod = i;
323    }
324
325    public int getAllocationMethod() {
326        return allocationMethod;
327    }
328
329    public void setUseSpeedProfile(boolean b) {
330        useSpeedProfile = b;
331    }
332
333    public boolean getUseSpeedProfile() {
334        return useSpeedProfile;
335    }
336
337    public void setStopBySpeedProfile(boolean b) {
338        stopBySpeedProfile = b;
339    }
340
341    public boolean getStopBySpeedProfile() {
342        return stopBySpeedProfile;
343    }
344
345    public void setStopBySpeedProfileAdjust(float f) {
346        stopBySpeedProfileAdjust = f;
347    }
348
349    public float getStopBySpeedProfileAdjust() {
350        return stopBySpeedProfileAdjust;
351    }
352
353    public void setReverseAtEnd(boolean b) {
354        reverseAtEnd = b;
355    }
356
357    public boolean getReverseAtEnd() {
358        return reverseAtEnd;
359    }
360
361    public void setDelayedStart(int ds) {
362        delayedStart = ds;
363    }
364
365    /**
366     * delayed start code for this train
367     *
368     * @return one of ActiveTrain.NODELAY,TIMEDDELAY,SENSORDELAY
369     */
370    public int getDelayedStart() {
371        return delayedStart;
372    }
373
374    public void setDepartureTimeHr(int hr) {
375        departureTimeHr = hr;
376    }
377
378    public int getDepartureTimeHr() {
379        return departureTimeHr;
380    }
381
382    public void setDepartureTimeMin(int min) {
383        departureTimeMin = min;
384    }
385
386    public int getDepartureTimeMin() {
387        return departureTimeMin;
388    }
389
390    public void setDelaySensorName(String sen) {
391        delaySensorName = sen;
392    }
393
394    public String getDelaySensorName() {
395        return delaySensorName;
396    }
397
398    public void setReverseDelayedRestart(int ds) {
399        reverseDelayedRestart = ds;
400    }
401
402    /**
403     * return restart code for this train, only used for continuous running
404     *
405     * @return one of ActiveTrain.NODELAY,TIMEDDELAY,SENSORDELAY
406     */
407    public int getReverseDelayedRestart() {
408        return reverseDelayedRestart;
409    }
410
411    public void setReverseRestartSensorName(String value) {
412        reverseRestartSensorName = value;
413    }
414
415    public String getReverseRestartSensorName() {
416        return reverseRestartSensorName;
417    }
418
419    public void setReverseResetRestartSensor(boolean value) {
420        reverseResetRestartSensor = value;
421    }
422
423    public boolean getReverseResetRestartSensor() {
424        return reverseResetRestartSensor;
425    }
426
427    public Sensor getReverseRestartSensor() {
428        if (reverseRestartSensorName == null) {
429            return null;
430        }
431        return jmri.InstanceManager.sensorManagerInstance().getSensor(reverseRestartSensorName);
432    }
433
434    public void setReverseRestartDelayMin(int value) {
435        reverseRestartDelayMin = value;
436    }
437
438    public int getReverseRestartDelayMin() {
439        return reverseRestartDelayMin;
440    }
441
442    /**
443     * retrieve the startup delay sensor using the delay sensor name
444     *
445     * @return delay sensor, or null if delay sensor name not set
446     */
447    public Sensor getDelaySensor() {
448        if (delaySensorName == null) {
449            return null;
450        }
451        return InstanceManager.getDefault(SensorManager.class).getSensor(delaySensorName);
452    }
453
454    public boolean getResetStartSensor() {
455        return resetStartSensor;
456    }
457
458    public void setResetStartSensor(boolean b) {
459        resetStartSensor = b;
460    }
461
462    public void setTrainType(String s) {
463        trainType = s;
464    }
465
466    public String getTrainType() {
467        return trainType;
468    }
469
470    public void setDelayedRestart(int ds) {
471        delayedRestart = ds;
472    }
473
474    /**
475     * return restart code for this train, only used for continuous running
476     *
477     * @return one of ActiveTrain.NODELAY,TIMEDDELAY,SENSORDELAY
478     */
479    public int getDelayedRestart() {
480        return delayedRestart;
481    }
482
483    public void setRestartSensorName(String sen) {
484        restartSensorName = sen;
485    }
486
487    public String getRestartSensorName() {
488        return restartSensorName;
489    }
490
491    /**
492     * retrieve the restart sensor using the restart sensor name
493     *
494     * @return restart sensor, or null if the restart sensor name not set
495     */
496    public Sensor getRestartSensor() {
497        if (restartSensorName == null) {
498            return null;
499        }
500        return jmri.InstanceManager.sensorManagerInstance().getSensor(restartSensorName);
501    }
502
503    public boolean getResetRestartSensor() {
504        return resetRestartSensor;
505    }
506
507    public void setResetRestartSensor(boolean b) {
508        resetRestartSensor = b;
509    }
510
511    /**
512     * number of minutes to delay between restarting for continuous runs
513     *
514     * @param s number of minutes to delay
515     */
516    public void setRestartDelayMin(int s) {
517        restartDelayMin = s;
518    }
519
520    public int getRestartDelayMin() {
521        return restartDelayMin;
522    }
523
524    public boolean getLoadAtStartup() {
525        return loadAtStartup;
526    }
527
528    public void setLoadAtStartup(boolean loadAtStartup) {
529        this.loadAtStartup = loadAtStartup;
530    }
531
532    //
533    // Access methods for automatic operation instance variables
534    //
535    public void setSpeedFactor(float f) {
536        speedFactor = f;
537    }
538
539    public Float getSpeedFactor() {
540        return speedFactor;
541    }
542
543    public void setMaxSpeed(float f) {
544        maxSpeed = f;
545    }
546
547    public Float getMaxSpeed() {
548        return maxSpeed;
549    }
550
551    public void setMinReliableOperatingSpeed(float f) {
552        minReliableOperatingSpeed = f;
553    }
554
555    public float getMinReliableOperatingSpeed() {
556        return minReliableOperatingSpeed;
557    }
558
559    public void setRampRate(String s) {
560        rampRate = s;
561    }
562
563    public String getRampRate() {
564        return rampRate;
565    }
566
567    /**
568     * Set the detection get
569     * @param b {@link ActiveTrain.TrainDetection}
570     */
571    public void setTrainDetection(TrainDetection b) {
572        trainDetection = b;
573    }
574
575    /**
576     * Get the detection type
577     * @return  {@link ActiveTrain.TrainDetection}
578     */
579    public TrainDetection getTrainDetection() {
580        return trainDetection;
581    }
582
583    /**
584     * @deprecated use {@link #setTrainDetection}
585     * @param b true or false
586     */
587    @Deprecated (since="5.7.6",forRemoval=true)
588    public void setResistanceWheels(boolean b) {
589        if (b) {
590            trainDetection = TrainDetection.TRAINDETECTION_WHOLETRAIN;
591        } else {
592            trainDetection = TrainDetection.TRAINDETECTION_HEADONLY;
593        }
594    }
595
596    /**
597     * @deprecated use {@link #getTrainDetection}
598     * @return true or false
599     */
600    @Deprecated (since="5.7.6",forRemoval=true)
601    public boolean getResistanceWheels() {
602        if (trainDetection == TrainDetection.TRAINDETECTION_WHOLETRAIN) {
603            return true;
604        }
605        return false;
606    }
607
608    public void setRunInReverse(boolean b) {
609        runInReverse = b;
610    }
611
612    public boolean getRunInReverse() {
613        return runInReverse;
614    }
615
616    public void setSoundDecoder(boolean b) {
617        soundDecoder = b;
618    }
619
620    public boolean getSoundDecoder() {
621        return soundDecoder;
622    }
623
624    /**
625     * @deprecated use {@link #setMaxTrainLengthScaleMeters}
626     *               or {@link #setMaxTrainLengthScaleMeters}
627     * @param f train length
628     */
629    @Deprecated (since="5.9.7",forRemoval=true)
630    public void setMaxTrainLength(float f) {
631        maxTrainLength = f;
632    }
633
634    /**
635     * @deprecated use {@link #getMaxTrainLengthScaleMeters}
636     *              or {@link #getMaxTrainLengthScaleFeet}
637     * @return train length of in units of the writing application
638     */
639    @Deprecated (since="5.9.7",forRemoval=true)
640    public float getMaxTrainLength() {
641        return maxTrainLength;
642    }
643
644    /**
645     * Sets the max train length expected during run
646     * @param f scale Meters.
647     */
648    public void setMaxTrainLengthScaleMeters(float f) {
649        maxTrainLengthMeters = f;
650    }
651
652    /**
653     * Gets the Max train length expected during run
654     * @return scale meters
655     */
656    public float getMaxTrainLengthScaleMeters() {
657        return maxTrainLengthMeters;
658    }
659
660    /**
661     * Sets the max train length expected
662     * @param f scale Meters.
663     */
664    public void setMaxTrainLengthScaleFeet(float f) {
665        maxTrainLengthMeters = f / 3.28084f;
666    }
667
668    /**
669     * Gets the Max train length expected during route
670     * @return scale meters
671     */
672    public float getMaxTrainLengthScaleFeet() {
673        return maxTrainLengthMeters * 3.28084f;
674    }
675
676   /**
677     * Sets the gui units used to enter or display (The units are always held in scale meters)
678     * @param value {@link ActiveTrain.TrainLengthUnits}
679     */
680    public void setTrainLengthUnits(TrainLengthUnits value) {
681        trainLengthUnits = value;
682    }
683
684    /**
685     * Get the GUI units entered (The data is held in scale Meters)
686     * @return  {@link ActiveTrain.TrainLengthUnits}
687     */
688    public TrainLengthUnits getTrainLengthUnits() {
689        return trainLengthUnits;
690    }
691
692    public void setWaitTime(float f) { waitTime = f; }
693
694    public float getWaitTime() {
695        return waitTime;
696    }
697
698    public void setBlockName(String s) { blockName = s; }
699
700    public String getBlockName() { return blockName; }
701
702}