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