001// Warnings objectInputStream here about changes to this structure and how it will affect old/new programs:
002//https://howtodoinjava.com/java/serialization/a-mini-guide-for-implementing-serializable-interface-objectInputStream-java/
003
004package jmri.jmrit.ctc.ctcserialdata;
005
006import java.util.ArrayList;
007import java.util.HashMap;
008import javax.swing.ButtonGroup;
009import jmri.jmrit.ctc.*;
010
011/**
012 *
013 * @author Gregory J. Bedlek Copyright (C) 2018, 2019
014 */
015public class CodeButtonHandlerData {
016    public static final int SWITCH_NOT_SLAVED = -1;
017
018    public enum LOCK_IMPLEMENTATION {
019// The values in paren's are the RadioGroup values set by "CommonSubs.numberButtonGroup",
020// gotten by calling "CommonSubs.getButtonSelectedInt".
021        GREGS(0), OTHER(1);
022        private final int _mRadioGroupValue;
023        private final static HashMap<Integer, LOCK_IMPLEMENTATION> map = new HashMap<>();
024        private LOCK_IMPLEMENTATION (int radioGroupValue) { _mRadioGroupValue = radioGroupValue; }
025        static { for (LOCK_IMPLEMENTATION value : LOCK_IMPLEMENTATION.values()) { map.put(value._mRadioGroupValue, value); }}
026        public int getInt() { return _mRadioGroupValue; }
027        public static LOCK_IMPLEMENTATION getLockImplementation(int radioGroupValue) { return map.get(radioGroupValue); }
028        public static LOCK_IMPLEMENTATION getLockImplementation(ButtonGroup buttonGroup) { return map.get(ProjectsCommonSubs.getButtonSelectedInt(buttonGroup)); }
029    }
030
031    public enum TURNOUT_TYPE {
032// The values in paren's are the RadioGroup values set by "CommonSubs.numberButtonGroup",
033// gotten by calling "CommonSubs.getButtonSelectedInt".
034        TURNOUT(0), CROSSOVER(1), DOUBLE_CROSSOVER(2);
035        private final int _mRadioGroupValue;
036        private final static HashMap<Integer, TURNOUT_TYPE> map = new HashMap<>();
037        private TURNOUT_TYPE (int radioGroupValue) { _mRadioGroupValue = radioGroupValue; }
038        static { for (TURNOUT_TYPE value : TURNOUT_TYPE.values()) { map.put(value._mRadioGroupValue, value); }}
039        public int getInt() { return _mRadioGroupValue; }
040        public static TURNOUT_TYPE getTurnoutType(int radioGroupValue) { return map.get(radioGroupValue); }
041        public static TURNOUT_TYPE getTurnoutType(ButtonGroup buttonGroup) { return map.get(ProjectsCommonSubs.getButtonSelectedInt(buttonGroup)); }
042    }
043
044    public enum TRAFFIC_DIRECTION {
045        LEFT,
046        BOTH,
047        RIGHT;
048    }
049
050    public CodeButtonHandlerData(int uniqueID, int switchNumber, int signalEtcNumber, int guiColumnNumber) {
051        _mUniqueID = uniqueID;
052        _mSwitchNumber = switchNumber;
053        _mSignalEtcNumber = signalEtcNumber;
054        _mOSSectionSwitchSlavedToUniqueID = SWITCH_NOT_SLAVED;
055        _mGUIColumnNumber = guiColumnNumber;
056        _mSWDI_GUITurnoutType = CodeButtonHandlerData.TURNOUT_TYPE.TURNOUT;
057        _mTUL_LockImplementation = LOCK_IMPLEMENTATION.GREGS;
058    }
059
060//  This number NEVER changes, and is how this object is uniquely identified:
061    public int _mUniqueID = -1;         // FORCE serialization to write out the FIRST unique number 0 into the XML file (to make me happy!)
062    public int _mSwitchNumber;         // Switch Indicators and lever #
063    public int _mSignalEtcNumber;      // Signal Indicators, lever, locktoggle, callon and code button number
064
065    public String myString() { return Bundle.getMessage("CBHD_SwitchNumber") + " " + _mSwitchNumber + ", " + Bundle.getMessage("CBHD_SignalNumberEtc") + " " + _mSignalEtcNumber + Bundle.getMessage("CBHD_ColumnNumber") + " " + _mGUIColumnNumber + (_mGUIGeneratedAtLeastOnceAlready ? "*" : "") + ", [" + _mUniqueID + "]"; }  // NOI18N
066    public String myShortStringNoComma() { return _mSwitchNumber + "/" + _mSignalEtcNumber; }
067
068/*
069Because of "getAllInternalSensorStringFields", ANY JMRI sensor object that we
070create should have "InternalSensor" (case sensitive,
071example: _mCodeButtonInternalSensor) as ANY PART of their variable name and
072declared as type String.  This will insure that the GUI program will write these
073sensors out to a separate file for JMRI to load to automatically create
074these senosrs.  Other sensors that pre-exist within JMRI should NOT have
075that as part of their variable name (ex: _mOSSectionOccupiedExternalSensor).
076
077Also, see CheckJMRIObject's "public static final String EXTERNAL_xxx" definitions
078at the top for "automatic" JMRI object verification.
079*/
080
081    public NBHSensor            _mCodeButtonInternalSensor;
082    public NBHSensor            _mOSSectionOccupiedExternalSensor;              // Required
083    public NBHSensor            _mOSSectionOccupiedExternalSensor2;             // Optional
084    public int                  _mOSSectionSwitchSlavedToUniqueID;
085    public int                  _mGUIColumnNumber;
086    public boolean              _mGUIGeneratedAtLeastOnceAlready;
087    public int                  _mCodeButtonDelayTime;
088//  Signal Direction Indicators:
089    public boolean              _mSIDI_Enabled;
090    public NBHSensor            _mSIDI_LeftInternalSensor;
091    public NBHSensor            _mSIDI_NormalInternalSensor;
092    public NBHSensor            _mSIDI_RightInternalSensor;
093    public int                  _mSIDI_CodingTimeInMilliseconds;
094    public int                  _mSIDI_TimeLockingTimeInMilliseconds;
095    public TRAFFIC_DIRECTION    _mSIDI_TrafficDirection;
096    public ArrayList<NBHSignal> _mSIDI_LeftRightTrafficSignals = new ArrayList<>();
097    public ArrayList<NBHSignal> _mSIDI_RightLeftTrafficSignals = new ArrayList<>();
098//  Signal Direction Lever:
099    public boolean              _mSIDL_Enabled;
100    public NBHSensor            _mSIDL_LeftInternalSensor;
101    public NBHSensor            _mSIDL_NormalInternalSensor;
102    public NBHSensor            _mSIDL_RightInternalSensor;
103//  Switch Direction Indicators:
104    public boolean              _mSWDI_Enabled;
105    public NBHSensor            _mSWDI_NormalInternalSensor;
106    public NBHSensor            _mSWDI_ReversedInternalSensor;
107    public NBHTurnout           _mSWDI_ExternalTurnout;
108    public int                  _mSWDI_CodingTimeInMilliseconds;
109    public boolean              _mSWDI_FeedbackDifferent;
110    public TURNOUT_TYPE         _mSWDI_GUITurnoutType;
111    public boolean              _mSWDI_GUITurnoutLeftHand;
112    public boolean              _mSWDI_GUICrossoverLeftHand;
113//  Switch Direction Lever:
114    public boolean              _mSWDL_Enabled;
115    public NBHSensor            _mSWDL_InternalSensor;
116//  Call On:
117    public boolean              _mCO_Enabled;
118    public NBHSensor            _mCO_CallOnToggleInternalSensor;
119    public ArrayList<CallOnData> _mCO_GroupingsList = new ArrayList<>();
120//  Traffic Locking:
121    public boolean              _mTRL_Enabled;
122    public ArrayList<TrafficLockingData> _mTRL_LeftTrafficLockingRules = new ArrayList<>();
123    public ArrayList<TrafficLockingData> _mTRL_RightTrafficLockingRules = new ArrayList<>();
124//  Turnout Locking:
125    public boolean              _mTUL_Enabled;
126    public NBHSensor            _mTUL_DispatcherInternalSensorLockToggle;
127    public NBHTurnout           _mTUL_ExternalTurnout;
128    public boolean              _mTUL_ExternalTurnoutFeedbackDifferent;
129    public NBHSensor            _mTUL_DispatcherInternalSensorUnlockedIndicator;
130    public boolean              _mTUL_NoDispatcherControlOfSwitch;
131    public boolean              _mTUL_ndcos_WhenLockedSwitchStateIsClosed;
132    public boolean              _mTUL_GUI_IconsEnabled;
133    public LOCK_IMPLEMENTATION  _mTUL_LockImplementation;
134    public NBHTurnout           _mTUL_AdditionalExternalTurnout1;
135    public boolean              _mTUL_AdditionalExternalTurnout1FeedbackDifferent;
136    public NBHTurnout           _mTUL_AdditionalExternalTurnout2;
137    public boolean              _mTUL_AdditionalExternalTurnout2FeedbackDifferent;
138    public NBHTurnout           _mTUL_AdditionalExternalTurnout3;
139    public boolean              _mTUL_AdditionalExternalTurnout3FeedbackDifferent;
140//  Indication Locking (Signals):
141    public boolean              _mIL_Enabled;
142    public ArrayList<NBHSignal>      _mIL_Signals = new ArrayList<>();
143
144}