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