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 // Maximum speed in scale km/h (0.0f means "use throttle % cap") 081 private float maxSpeedScaleKmh = 0.0f; 082 private float minReliableOperatingSpeed = 0.0f; 083 private String rampRate = Bundle.getMessage("RAMP_NONE"); 084 private TrainDetection trainDetection = TrainDetection.TRAINDETECTION_WHOLETRAIN; 085 private boolean runInReverse = false; 086 private boolean soundDecoder = false; 087 private float maxTrainLength = 100.0f; 088 private float maxTrainLengthMeters = 30.0f; 089 private TrainLengthUnits trainLengthUnits = TrainLengthUnits.TRAINLENGTH_SCALEFEET; // units used to enter value 090 private boolean useSpeedProfile = false; 091 private boolean stopBySpeedProfile = false; 092 private float stopBySpeedProfileAdjust = 1.0f; 093 private int fNumberLight = 0; 094 private int fNumberBell = 1; 095 private int fNumberHorn = 2; 096 097 private float waitTime = 3.0f; //seconds: required only by dispatcher system to pause train at beginning of transit (station) 098 099 private String blockName = ""; //required only by Dispatcher System to inhibit running of transit if this block is occupied 100 101 private Float stopByDistanceMm = 0.0f; 102 private StopReference stopByDistanceRef = StopReference.HEAD; // default choice 103 104 // Physics: additional train weight, stored as metric tonnes (t) 105 private float additionalTrainWeightMetricTonnes = 0.0f; 106 107 private boolean useStopSensor = true; 108 109 public enum StopReference { HEAD, TAIL } 110 111 // 112 // Access methods for manual and automatic instance variables 113 // 114 public void setVersion(int ver) { 115 version = ver; 116 } 117 public int getVersion() { 118 return version; 119 } 120 121 public void setTransitName(String s) { 122 transitName = s; 123 } 124 125 public String getTransitName() { 126 return transitName; 127 } 128 129 public void setTransitId(String s) { 130 transitId = s; 131 } 132 133 public String getTransitId() { 134 return transitId; 135 } 136 137 public void setDynamicTransit(boolean b) { 138 dynamicTransit = b; 139 } 140 141 public boolean getDynamicTransit() { 142 return dynamicTransit; 143 } 144 145 public void setDynamicTransitCloseLoopIfPossible(boolean b) { 146 dynamicTransitCloseLoopIfPossible = b; 147 } 148 149 public boolean getDynamicTransitCloseLoopIfPossible() { 150 return dynamicTransitCloseLoopIfPossible; 151 } 152 public void setTrainName(String s) { 153 trainName = s; 154 } 155 156 public String getTrainName() { 157 return trainName; 158 } 159 160 public void setRosterId(String s) { 161 rosterID = s; 162 } 163 164 public String getRosterId() { 165 return rosterID; 166 } 167 168 public boolean getUseStopSensor() { 169 return useStopSensor; 170 } 171 172 public void setUseStopSensor(boolean value) { 173 this.useStopSensor = value; 174 } 175 176 public void setTrainUserName(String s) { 177 trainUserName = s; 178 } 179 180 public String getTrainUserName() { 181 return trainUserName; 182 } 183 184 public void setDccAddress(String s) { 185 dccAddress = s; 186 } 187 188 public String getDccAddress() { 189 return dccAddress; 190 } 191 192 public void setTrainInTransit(boolean b) { 193 trainInTransit = b; 194 } 195 196 public boolean getTrainInTransit() { 197 return trainInTransit; 198 } 199 200 public void setStartBlockName(String s) { 201 startBlockName = s; 202 } 203 204 public String getStartBlockName() { 205 return startBlockName; 206 } 207 208 public void setViaBlockName(String s) { 209 viaBlockName = s; 210 } 211 212 public String getViaBlockName() { 213 return viaBlockName; 214 } 215 216 public void setStartBlockId(String s) { 217 startBlockId = s; 218 } 219 220 public String getStartBlockId() { 221 return startBlockId; 222 } 223 224 public void setStartBlockSeq(int i) { 225 startBlockSeq = i; 226 } 227 228 public int getStartBlockSeq() { 229 return startBlockSeq; 230 } 231 232 public void setDestinationBlockName(String s) { 233 destinationBlockName = s; 234 } 235 236 public String getDestinationBlockName() { 237 return destinationBlockName; 238 } 239 240 public void setDestinationBlockId(String s) { 241 destinationBlockId = s; 242 } 243 244 public void setStopByDistanceMm(float value) { 245 stopByDistanceMm = value; 246 } 247 248 public void setStopByDistanceRef(StopReference value) { 249 stopByDistanceRef = value; 250 } 251 252 public float getStopByDistanceMm() { 253 return stopByDistanceMm; 254 } 255 256 public StopReference getStopByDistanceRef() { 257 return stopByDistanceRef; 258 } 259 260 public String getDestinationBlockId() { 261 return destinationBlockId; 262 } 263 264 public void setDestinationBlockSeq(int i) { 265 destinationBlockSeq = i; 266 } 267 268 public int getDestinationBlockSeq() { 269 return destinationBlockSeq; 270 } 271 272 public void setTrainsFrom(TrainsFrom value) { 273 trainFromRoster = false; 274 trainFromTrains = false; 275 trainFromUser = false; 276 trainFromSetLater = false; 277 switch (value) { 278 case TRAINSFROMROSTER: 279 trainFromRoster = true; 280 break; 281 case TRAINSFROMOPS: 282 trainFromTrains = true; 283 break; 284 case TRAINSFROMUSER: 285 trainFromUser = true; 286 break; 287 case TRAINSFROMSETLATER: 288 default: 289 trainFromSetLater = true; 290 } 291 } 292 293 public TrainsFrom getTrainsFrom() { 294 if (trainFromRoster) { 295 return TrainsFrom.TRAINSFROMROSTER; 296 } else if (trainFromTrains) { 297 return TrainsFrom.TRAINSFROMOPS; 298 } else if (trainFromUser) { 299 return TrainsFrom.TRAINSFROMUSER; 300 } 301 return TrainsFrom.TRAINSFROMSETLATER; 302 } 303 304 public void setTrainFromRoster(boolean b) { 305 trainFromRoster = b; 306 } 307 308 public boolean getTrainFromRoster() { 309 return trainFromRoster; 310 } 311 312 public void setTrainFromTrains(boolean b) { 313 trainFromTrains = b; 314 } 315 316 public boolean getTrainFromTrains() { 317 return trainFromTrains; 318 } 319 320 public void setTrainFromUser(boolean b) { 321 trainFromUser = b; 322 } 323 324 public boolean getTrainFromUser() { 325 return trainFromUser; 326 } 327 328 public void setTrainFromSetLater(boolean b) { 329 trainFromSetLater = b; 330 } 331 332 public boolean getTrainFromSetLater() { 333 return trainFromSetLater; 334 } 335 336 public void setTerminateWhenDone(boolean b) { 337 terminateWhenDone = b; 338 } 339 340 public boolean getTerminateWhenDone() { 341 return terminateWhenDone; 342 } 343 344 public void setNextTrain(String s) { 345 nextTrain = s; 346 } 347 348 public String getNextTrain() { 349 return nextTrain; 350 } 351 352 353 public void setPriority(int pri) { 354 priority = pri; 355 } 356 357 public int getPriority() { 358 return priority; 359 } 360 361 public void setAutoRun(boolean b) { 362 autoRun = b; 363 } 364 365 public boolean getAutoRun() { 366 return autoRun; 367 } 368 369 public void setResetWhenDone(boolean b) { 370 resetWhenDone = b; 371 } 372 373 public boolean getResetWhenDone() { 374 return resetWhenDone; 375 } 376 377 public void setAllocateAllTheWay(boolean b) { 378 allocateAllTheWay = b; 379 } 380 381 public boolean getAllocateAllTheWay() { 382 return allocateAllTheWay; 383 } 384 385 public void setAllocationMethod(int i) { 386 allocationMethod = i; 387 } 388 389 public int getAllocationMethod() { 390 return allocationMethod; 391 } 392 393 public void setUseSpeedProfile(boolean b) { 394 useSpeedProfile = b; 395 } 396 397 public boolean getUseSpeedProfile() { 398 return useSpeedProfile; 399 } 400 401 public void setStopBySpeedProfile(boolean b) { 402 stopBySpeedProfile = b; 403 } 404 405 public boolean getStopBySpeedProfile() { 406 return stopBySpeedProfile; 407 } 408 409 public void setStopBySpeedProfileAdjust(float f) { 410 stopBySpeedProfileAdjust = f; 411 } 412 413 public float getStopBySpeedProfileAdjust() { 414 return stopBySpeedProfileAdjust; 415 } 416 417 public void setReverseAtEnd(boolean b) { 418 reverseAtEnd = b; 419 } 420 421 public boolean getReverseAtEnd() { 422 return reverseAtEnd; 423 } 424 425 public void setDelayedStart(int ds) { 426 delayedStart = ds; 427 } 428 429 /** 430 * delayed start code for this train 431 * 432 * @return one of ActiveTrain.NODELAY,TIMEDDELAY,SENSORDELAY 433 */ 434 public int getDelayedStart() { 435 return delayedStart; 436 } 437 438 public void setDepartureTimeHr(int hr) { 439 departureTimeHr = hr; 440 } 441 442 public int getDepartureTimeHr() { 443 return departureTimeHr; 444 } 445 446 public void setDepartureTimeMin(int min) { 447 departureTimeMin = min; 448 } 449 450 public int getDepartureTimeMin() { 451 return departureTimeMin; 452 } 453 454 public void setDelaySensorName(String sen) { 455 delaySensorName = sen; 456 } 457 458 public String getDelaySensorName() { 459 return delaySensorName; 460 } 461 462 public void setReverseDelayedRestart(int ds) { 463 reverseDelayedRestart = ds; 464 } 465 466 /** 467 * return restart code for this train, only used for continuous running 468 * 469 * @return one of ActiveTrain.NODELAY,TIMEDDELAY,SENSORDELAY 470 */ 471 public int getReverseDelayedRestart() { 472 return reverseDelayedRestart; 473 } 474 475 public void setReverseRestartSensorName(String value) { 476 reverseRestartSensorName = value; 477 } 478 479 public String getReverseRestartSensorName() { 480 return reverseRestartSensorName; 481 } 482 483 public void setReverseResetRestartSensor(boolean value) { 484 reverseResetRestartSensor = value; 485 } 486 487 public boolean getReverseResetRestartSensor() { 488 return reverseResetRestartSensor; 489 } 490 491 public Sensor getReverseRestartSensor() { 492 if (reverseRestartSensorName == null) { 493 return null; 494 } 495 return jmri.InstanceManager.sensorManagerInstance().getSensor(reverseRestartSensorName); 496 } 497 498 public void setReverseRestartDelayMin(int value) { 499 reverseRestartDelayMin = value; 500 } 501 502 public int getReverseRestartDelayMin() { 503 return reverseRestartDelayMin; 504 } 505 506 /** 507 * retrieve the startup delay sensor using the delay sensor name 508 * 509 * @return delay sensor, or null if delay sensor name not set 510 */ 511 public Sensor getDelaySensor() { 512 if (delaySensorName == null) { 513 return null; 514 } 515 return InstanceManager.getDefault(SensorManager.class).getSensor(delaySensorName); 516 } 517 518 public boolean getResetStartSensor() { 519 return resetStartSensor; 520 } 521 522 public void setResetStartSensor(boolean b) { 523 resetStartSensor = b; 524 } 525 526 public void setTrainType(String s) { 527 trainType = s; 528 } 529 530 public String getTrainType() { 531 return trainType; 532 } 533 534 public void setDelayedRestart(int ds) { 535 delayedRestart = ds; 536 } 537 538 /** 539 * return restart code for this train, only used for continuous running 540 * 541 * @return one of ActiveTrain.NODELAY,TIMEDDELAY,SENSORDELAY 542 */ 543 public int getDelayedRestart() { 544 return delayedRestart; 545 } 546 547 public void setRestartSensorName(String sen) { 548 restartSensorName = sen; 549 } 550 551 public String getRestartSensorName() { 552 return restartSensorName; 553 } 554 555 /** 556 * retrieve the restart sensor using the restart sensor name 557 * 558 * @return restart sensor, or null if the restart sensor name not set 559 */ 560 public Sensor getRestartSensor() { 561 if (restartSensorName == null) { 562 return null; 563 } 564 return jmri.InstanceManager.sensorManagerInstance().getSensor(restartSensorName); 565 } 566 567 public boolean getResetRestartSensor() { 568 return resetRestartSensor; 569 } 570 571 public void setResetRestartSensor(boolean b) { 572 resetRestartSensor = b; 573 } 574 575 /** 576 * number of minutes to delay between restarting for continuous runs 577 * 578 * @param s number of minutes to delay 579 */ 580 public void setRestartDelayMin(int s) { 581 restartDelayMin = s; 582 } 583 584 public int getRestartDelayMin() { 585 return restartDelayMin; 586 } 587 588 public boolean getLoadAtStartup() { 589 return loadAtStartup; 590 } 591 592 public void setLoadAtStartup(boolean loadAtStartup) { 593 this.loadAtStartup = loadAtStartup; 594 } 595 596 // 597 // Access methods for automatic operation instance variables 598 // 599 public void setSpeedFactor(float f) { 600 speedFactor = f; 601 } 602 603 public Float getSpeedFactor() { 604 return speedFactor; 605 } 606 607 public void setMaxSpeed(float f) { 608 maxSpeed = f; 609 } 610 611 public Float getMaxSpeed() { 612 return maxSpeed; 613 } 614 615 /** 616 * Sets the maximum speed in scale km/h. Use 0.0f to disable and fall back to throttle percent. 617 * @param kmh scale kilometers per hour 618 */ 619 public void setMaxSpeedScaleKmh(float kmh) { maxSpeedScaleKmh = kmh; } 620 621 /** 622 * Gets the maximum speed in scale km/h. 0.0f means "disabled". 623 * @return scale km/h 624 */ 625 public float getMaxSpeedScaleKmh() { return maxSpeedScaleKmh; } 626 627 public void setMinReliableOperatingSpeed(float f) { 628 minReliableOperatingSpeed = f; 629 } 630 631 public float getMinReliableOperatingSpeed() { 632 return minReliableOperatingSpeed; 633 } 634 635 public void setRampRate(String s) { 636 rampRate = s; 637 } 638 639 public String getRampRate() { 640 return rampRate; 641 } 642 643 /** 644 * Set the detection get 645 * @param b {@link ActiveTrain.TrainDetection} 646 */ 647 public void setTrainDetection(TrainDetection b) { 648 trainDetection = b; 649 } 650 651 /** 652 * Get the detection type 653 * @return {@link ActiveTrain.TrainDetection} 654 */ 655 public TrainDetection getTrainDetection() { 656 return trainDetection; 657 } 658 659 /** 660 * @deprecated use {@link #setTrainDetection} 661 * @param b true or false 662 */ 663 @Deprecated (since="5.7.6",forRemoval=true) 664 public void setResistanceWheels(boolean b) { 665 if (b) { 666 trainDetection = TrainDetection.TRAINDETECTION_WHOLETRAIN; 667 } else { 668 trainDetection = TrainDetection.TRAINDETECTION_HEADONLY; 669 } 670 } 671 672 /** 673 * @deprecated use {@link #getTrainDetection} 674 * @return true or false 675 */ 676 @Deprecated (since="5.7.6",forRemoval=true) 677 public boolean getResistanceWheels() { 678 if (trainDetection == TrainDetection.TRAINDETECTION_WHOLETRAIN) { 679 return true; 680 } 681 return false; 682 } 683 684 public void setRunInReverse(boolean b) { 685 runInReverse = b; 686 } 687 688 public boolean getRunInReverse() { 689 return runInReverse; 690 } 691 692 public void setSoundDecoder(boolean b) { 693 soundDecoder = b; 694 } 695 696 public boolean getSoundDecoder() { 697 return soundDecoder; 698 } 699 700 /** 701 * Sets F number for the Light 702 * @param value F Number. 703 */ 704 public void setFNumberLight(int value) { 705 fNumberLight = value; 706 } 707 708 /** 709 * returns the F number for the Light 710 * @return F Number 711 */ 712 public int getFNumberLight() { 713 return fNumberLight; 714 } 715 716 /** 717 * Sets F number for the Bell 718 * @param value F Number. 719 */ 720 public void setFNumberBell(int value) { 721 fNumberBell = value; 722 } 723 724 /** 725 * returns the F number for the Bell 726 * @return F Number 727 */ 728 public int getFNumberBell() { 729 return fNumberBell; 730 } 731 732 /** 733 * Sets F number for the Horn 734 * @param value F Number. 735 */ 736 public void setFNumberHorn(int value) { 737 fNumberHorn = value; 738 } 739 740 /** 741 * returns the F number for the Horn 742 * @return F Number 743 */ 744 public int getFNumberHorn() { 745 return fNumberHorn; 746 } 747 748 /** 749 * @deprecated use {@link #setMaxTrainLengthScaleMeters} 750 * or {@link #setMaxTrainLengthScaleMeters} 751 * @param f train length 752 */ 753 @Deprecated (since="5.9.7",forRemoval=true) 754 public void setMaxTrainLength(float f) { 755 maxTrainLength = f; 756 } 757 758 /** 759 * @deprecated use {@link #getMaxTrainLengthScaleMeters} 760 * or {@link #getMaxTrainLengthScaleFeet} 761 * @return train length of in units of the writing application 762 */ 763 @Deprecated (since="5.9.7",forRemoval=true) 764 public float getMaxTrainLength() { 765 return maxTrainLength; 766 } 767 768 /** 769 * Sets the max train length expected during run 770 * @param f scale Meters. 771 */ 772 public void setMaxTrainLengthScaleMeters(float f) { 773 maxTrainLengthMeters = f; 774 } 775 776 /** 777 * Gets the Max train length expected during run 778 * @return scale meters 779 */ 780 public float getMaxTrainLengthScaleMeters() { 781 return maxTrainLengthMeters; 782 } 783 784 /** 785 * Sets the max train length expected 786 * @param f scale Meters. 787 */ 788 public void setMaxTrainLengthScaleFeet(float f) { 789 maxTrainLengthMeters = f / 3.28084f; 790 } 791 792 /** 793 * Gets the Max train length expected during route 794 * @return scale meters 795 */ 796 public float getMaxTrainLengthScaleFeet() { 797 return maxTrainLengthMeters * 3.28084f; 798 } 799 800 /** 801 * Sets the gui units used to enter or display (The units are always held in scale meters) 802 * @param value {@link ActiveTrain.TrainLengthUnits} 803 */ 804 public void setTrainLengthUnits(TrainLengthUnits value) { 805 trainLengthUnits = value; 806 } 807 808 /** 809 * Get the GUI units entered (The data is held in scale Meters) 810 * @return {@link ActiveTrain.TrainLengthUnits} 811 */ 812 public TrainLengthUnits getTrainLengthUnits() { 813 return trainLengthUnits; 814 } 815 816 public void setWaitTime(float f) { waitTime = f; } 817 818 public float getWaitTime() { 819 return waitTime; 820 } 821 822 public void setBlockName(String s) { blockName = s; } 823 824 public String getBlockName() { return blockName; } 825 826 // --- Physics additional weight (metric tonnes) --- 827 public void setAdditionalTrainWeightMetricTonnes(float value) { additionalTrainWeightMetricTonnes = value; } 828 public float getAdditionalTrainWeightMetricTonnes() { return additionalTrainWeightMetricTonnes; } 829 830 // --- Physics rolling resistance coefficient (dimensionless), defaults ~0.002 831 private float rollingResistanceCoeff = 0.002f; 832 public void setRollingResistanceCoeff(float value) { rollingResistanceCoeff = Math.max(0.0f, value); } 833 public float getRollingResistanceCoeff() { return rollingResistanceCoeff; } 834 835 836 // --- Physics: driver's applied power/regulator during acceleration (0.0..1.0); default 1.0 (=100%) 837 private float driverPowerPercent = 1.0f; 838 /** Sets the driver's applied power/regulator during acceleration (0.0..1.0). */ 839 public void setDriverPowerPercent(float value) { 840 // Clamp 0..1 841 driverPowerPercent = (value < 0.0f) ? 0.0f : ((value > 1.0f) ? 1.0f : value); 842 } 843 /** Gets the driver's applied power/regulator during acceleration (0.0..1.0). */ 844 public float getDriverPowerPercent() { return driverPowerPercent; } 845} 846 847