//---------------------------------------------------------------------------
/*
Remote Train Control Program for Windows

© Copyright 2015 by Mark DiVecchio

    This file is part of Remote Train Control.

    Remote Train Control is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Remote Train Control is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Remote Train Control.  If not, see <http://www.gnu.org/licenses/>.

*/
//---------------------------------------------------------------------------
#ifndef Op_ControlH
#define Op_ControlH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include "_GClass.hpp"
#include "AbCBitBt.hpp"
#include "AbSwitch.hpp"
#include "AbVSlide.hpp"
#include "AbHSlide.hpp"
#include <ExtCtrls.hpp>
#include "HideButton.h"
#include <Graphics.hpp>
#include "AbDial.hpp"
#include "AbNumEdit.hpp"
#include "AbLED.hpp"
#include "AbGearDial.hpp"
#include <Menus.hpp>
#include <Buttons.hpp>
#include "AbVBar.hpp"
#include "ColorButton.hpp"

//
// Defines for each of the functions that can be assigned to
// the three AUX1/AUX2/AUX3 switches
//
// 1 Marker
#define SWITCH_MARKER 1
// 2 Aux 1
#define SWITCH_AUX1 2
// 3 Aux 2
#define SWITCH_AUX2 3
// 4 Aux 3
#define SWITCH_AUX3 4
// 5 Firebox Glow
#define SWITCH_FIREBOX 5
// 6 Running Lights
#define SWITCH_RUNNING 6
// 7 Interior
#define SWITCH_INTERIOR 7
// 8 Number Boards
#define SWITCH_NB 8
// 9 Headlight
#define SWITCH_HEADLIGHT 9
// 10 Track Inspection Light
#define SWITCH_INSPECTION 10
// 11 Mars
#define SWITCH_MARS 11
// 12 Number Boards on Ditch & Mars
#define SWITCH_NB_DITCH_MARS 12
// 13 Running Lights on Ditch & Mars
#define SWITCH_RUNNING_DITCH_MARS 13

// Forward Declaration
class TTrackSignal;

//---------------------------------------------------------------------------
class TOp : public TForm
{
__published:	// IDE-managed Components
    TLabel *Operation_Controls_Label;
    TAbColBitBtn *ESTOP;
	THideButton *HideButton;
	TButton *OpShutdown;
	TTimer *BoostBrakeTimer;
	TButton *FeatureResetButton;
	TPopupMenu *OpPopup;
    TMenuItem *FeatureResetMenu;
	TPopupMenu *BellMenu;
	TMenuItem *N10Seconds;
	TMenuItem *N20Seconds;
	TMenuItem *N30Seconds;
	TPopupMenu *WhistleHornPopup;
	TMenuItem *EightShort;
	TMenuItem *TwoLong;
	TMenuItem *GradeXing;
	TMenuItem *OneLong;
	TMenuItem *TwoShort;
	TMenuItem *ThreeShort;
	TMenuItem *OneLongTwoShort;
	TMenuItem *Speed10;
	TMenuItem *Speed20;
	TMenuItem *Speed05;
	TMenuItem *Stopin10Seconds;
	TMenuItem *Decelerateto0Smph;
	TMenuItem *Speed25;
	TMenuItem *Speed30;
    TMenuItem *ShowEngineCommands1;
	TMenuItem *TrainWreck;
	TPanel *OpPanel;
	TLabel *DitchLabel;
	TComboBox *DitchComboBox;
	TAbVBar *RevLevelBar;
	TAbColBitBtn *LaborRevUpButton;
	TAbColBitBtn *DriftRevDnButton;
	TAbColBitBtn *BoostButton;
	TAbVSlider *SpeedSlider;
	TComboBox *EngineTypeComboBox;
	TAbLED *EngineTypeLED;
	TAbColBitBtn *CPLRFButton;
	TAbColBitBtn *CPLRRButton;
	TRadioGroup *SmokeGroup;
	TLabel *Label1;
	TAbRockerSwitch *BellSwitch;
	TAbRockerSwitch *HDLTSwitch;
	TAbRockerSwitch *SmokeSwitch;
	TAbRockerSwitch *SoundsSwitch;
	TAbRockerSwitch *MarkerLightSwitch;
	TAbRockerSwitch *BeaconLightSwitch;
	TLabel *Label5;
	TAbRockerSwitch *ab3ab2Switch;
	TAbRockerSwitch *ab5ab4Switch;
	TAbRockerSwitch *ab7ab6Switch;
	TLabel *Label2;
	TLabel *Label10;
	TLabel *Label7;
	TAbRockerSwitch *ChuffRateSwitch;
	TAbRockerSwitch *ProtoChuffSwitch;
	TAbRockerSwitch *BrakesSwitch;
	TAbRockerSwitch *CabChatSwitch;
	TAbRockerSwitch *ClickClackSwitch;
	TAbRockerSwitch *CouplerSlackSwitch;
	TAbRockerSwitch *SpareSwitch1;
	TAbRockerSwitch *SpareSwitch2;
	TLabel *Label9;
	TAbColBitBtn *BrakeButton;
	TAbToggleSwitch *DIRToggle;
	TLabel *Label6;
	TLabel *Label11;
	TLabel *Label20;
	TAbColBitBtn *PFAButton;
	TLabel *Label8;
	TAbNumSpin *MaxSpeedSpin;
	TLabel *Label12;
	TAbLED *MotionSoundRequest;
	TColorButton *StopButtonOp;
	TPanel *AccDecPanel;
	TLabel *AccLabel;
	TLabel *DecLabel;
	TLabel *Label3;
	TLabel *Label4;
	TAbNumSpin *DecSpin;
	TAbNumSpin *AccSpin;
	TPanel *PantographPanel;
	TLabel *PantTopLabel;
	TAbRockerSwitch *AutoPantSwitch;
	TAbRockerSwitch *FrontPantSwitch;
	TAbRockerSwitch *RearPantSwitch;
	TLabel *PantBottomLabel;
	TImage *Copyright;
	TButton *SoundControlsButton;
	TAbLED *SimulatedRule17LED;
	TAbLED *BellOnWithHornLED;
	TAbLED *AutoBellLED;
	TMenuItem *Stopin20Seconds;
	TMenuItem *Stopin30Seconds;
	TAbLED *AutoLaboredSmokeLED;
	TMenuItem *EngInfo;
	TMenuItem *TrkSignal;
	TPopupMenu *LightsMenu;
	TMenuItem *AllLightsOff1;
	TMenuItem *AllLightsOn1;
	TAbVSlider *WhistleSlider;
	TPanel *SmokePanel;
	TLabel *Label13;
	TAbRockerSwitch *ProtoWhistleSwitch;
	TAbRockerSwitch *SmokeWhistleSwitch;
	TAbRockerSwitch *SwingingBellSwitch;
	TLabel *Label14;
	TPanel *HornWhistlePanel;
	TAbColBitBtn *SFSButton;
	TAbColBitBtn *SRSButton;
	TAbColBitBtn *SXSButton;
	TAbColBitBtn *WhistleButton;
	TAbColBitBtn *AlternateHornButton;
	TAbColBitBtn *HornButton;
	TAbColBitBtn *Horn2Button;
	TAbColBitBtn *Horn3Button;
	TMenuItem *DelayTest1;
	TMenuItem *EngStat;
	TMenuItem *SetEnginePS2;
	TMenuItem *SetEnginePS3;
	TAbLED *AutoWhistleLED;
    void __fastcall BellSwitchStatusChanged(TObject *Sender);
    void __fastcall HDLTSwitchStatusChanged(TObject *Sender);
    void __fastcall HideButtonClick(TObject *Sender);
	void __fastcall SmokeSwitchStatusChanged(TObject *Sender);
	void __fastcall ClickClackSwitchStatusChanged(TObject *Sender);
	void __fastcall SmokeGroupClick(TObject *Sender);
	void __fastcall AccSpinChange(TObject *Sender);
	void __fastcall DecSpinChange(TObject *Sender);
	void __fastcall CabChatSwitchStatusChanged(TObject *Sender);
	void __fastcall ProtoChuffSwitchStatusChanged(TObject *Sender);
	void __fastcall ChuffRateSwitchStatusChanged(TObject *Sender);
	void __fastcall BrakesSwitchStatusChanged(TObject *Sender);
	void __fastcall PFAButtonClick(TObject *Sender);
	void __fastcall OpShutdownClick(TObject *Sender);
	void __fastcall ESTOPClick(TObject *Sender);
	void __fastcall BoostButtonStatusChanged(TObject *Sender);
	void __fastcall BoostBrakeTimerTimer(TObject *Sender);
	void __fastcall BrakeButtonStatusChanged(TObject *Sender);
	void __fastcall SoundsSwitchStatusChanged(TObject *Sender);
	void __fastcall BeaconLightSwitchStatusChanged(TObject *Sender);
	void __fastcall FeatureResetButtonClick(TObject *Sender);
	void __fastcall WhistleButton1MouseDown(TObject *Sender,
          TMouseButton Button, TShiftState Shift, int X, int Y);
	void __fastcall Whistle1ButtonMouseUp(TObject *Sender, TMouseButton Button,
          TShiftState Shift, int X, int Y);
	void __fastcall LaborRevUpButtonMouseDown(TObject *Sender,
          TMouseButton Button, TShiftState Shift, int X, int Y);
	void __fastcall LaborRevUpButtonMouseUp(TObject *Sender,
          TMouseButton Button, TShiftState Shift, int X, int Y);
	void __fastcall DriftRevDnButtonMouseDown(TObject *Sender,
          TMouseButton Button, TShiftState Shift, int X, int Y);
	void __fastcall DriftRevDnButtonMouseUp(TObject *Sender,
          TMouseButton Button, TShiftState Shift, int X, int Y);
	void __fastcall MaxSpeedSpinChange(TObject *Sender);
	void __fastcall SFSButtonMouseDown(TObject *Sender, TMouseButton Button,
          TShiftState Shift, int X, int Y);
	void __fastcall SRSButtonMouseDown(TObject *Sender, TMouseButton Button,
          TShiftState Shift, int X, int Y);
	void __fastcall SXSButtonMouseDown(TObject *Sender, TMouseButton Button,
          TShiftState Shift, int X, int Y);
	void __fastcall CPLRFButtonMouseDown(TObject *Sender, TMouseButton Button,
          TShiftState Shift, int X, int Y);
	void __fastcall CPLRRButtonMouseDown(TObject *Sender, TMouseButton Button,
          TShiftState Shift, int X, int Y);
	void __fastcall AccSpinValueChanged(TObject *Sender);
	void __fastcall DecSpinValueChanged(TObject *Sender);
	void __fastcall EngineTypeComboBoxClick(TObject *Sender);
	void __fastcall EngineTypeLEDClick(TObject *Sender);
	void __fastcall DitchComboBoxClick(TObject *Sender);
	void __fastcall AutoPantSwitchStatusChanged(TObject *Sender);
	void __fastcall FrontPantSwitchStatusChanged(TObject *Sender);
	void __fastcall RearPantSwitchStatusChanged(TObject *Sender);
	void __fastcall SpeedSliderValueChange(TObject *Sender);
	void __fastcall FormKeyDown(TObject *Sender, WORD &Key,
          TShiftState Shift);
	void __fastcall DIRToggleStatusChanged(TObject *Sender);
	void __fastcall BellSecondsClick(TObject *Sender);
	void __fastcall StopButtonOpMouseDown(TObject *Sender,
          TMouseButton Button, TShiftState Shift, int X, int Y);
	void __fastcall EightShortClick(TObject *Sender);
	void __fastcall TwoLongClick(TObject *Sender);
	void __fastcall GradeXingClick(TObject *Sender);
	void __fastcall OneLongClick(TObject *Sender);
	void __fastcall TwoShortClick(TObject *Sender);
	void __fastcall ThreeShortClick(TObject *Sender);
	void __fastcall OneLongTwoShortClick(TObject *Sender);
	void __fastcall Speed05Click(TObject *Sender);
	void __fastcall Speed10Click(TObject *Sender);
	void __fastcall Speed20Click(TObject *Sender);
	void __fastcall Stopin10SecondsClick(TObject *Sender);
	void __fastcall Decelerateto0SmphClick(TObject *Sender);
	void __fastcall Speed25Click(TObject *Sender);
	void __fastcall Speed30Click(TObject *Sender);
	void __fastcall ShowEngineCommands1Click(TObject *Sender);
	void __fastcall TrainWreckClick(TObject *Sender);
	void __fastcall ab3ab2SwitchStatusChanged(TObject *Sender);
	void __fastcall ab5ab4SwitchStatusChanged(TObject *Sender);
	void __fastcall ab7ab6SwitchStatusChanged(TObject *Sender);
	void __fastcall MarkerLightSwitchStatusChanged(TObject *Sender);
	void __fastcall SoundControlsButtonClick(TObject *Sender);
	void __fastcall Stopin20SecondsClick(TObject *Sender);
	void __fastcall Stopin30SecondsClick(TObject *Sender);
	void __fastcall AutoLaboredSmokeLEDStatusChanged(TObject *Sender);
	void __fastcall AlternateHornButtonMouseDown(TObject *Sender,
          TMouseButton Button, TShiftState Shift, int X, int Y);
	void __fastcall CopyrightClick(TObject *Sender);
	void __fastcall HDLTSwitchDblClick(TObject *Sender);
	void __fastcall BeaconLightSwitchDblClick(TObject *Sender);
	void __fastcall EngInfoClick(TObject *Sender);
	void __fastcall TrkSignalClick(TObject *Sender);
	void __fastcall AllLightsOff1Click(TObject *Sender);
	void __fastcall AllLightsOn1Click(TObject *Sender);
	void __fastcall WhistleSliderValueChange(TObject *Sender);
	void __fastcall ProtoWhistleSwitchStatusChanged(TObject *Sender);
	void __fastcall SmokeWhistleSwitchStatusChanged(TObject *Sender);
	void __fastcall SwingingBellSwitchStatusChanged(TObject *Sender);
	void __fastcall FormDeactivate(TObject *Sender);
	void __fastcall FormActivate(TObject *Sender);
	void __fastcall Operation_Controls_LabelClick(TObject *Sender);
	void __fastcall MaxSpeedSpinValueChanged(TObject *Sender);
	void __fastcall DelayTest1Click(TObject *Sender);
	void __fastcall EngStatClick(TObject *Sender);
	void __fastcall SetEnginePS2Click(TObject *Sender);
	void __fastcall SetEnginePS3Click(TObject *Sender);
	void __fastcall OpPopupPopup(TObject *Sender);
	void __fastcall FormKeyUp(TObject *Sender, WORD &Key, TShiftState Shift);
	void __fastcall SimulatedRule17LEDStatusChanged(TObject *Sender);
	void __fastcall BellOnWithHornLEDStatusChanged(TObject *Sender);
	void __fastcall AutoBellLEDStatusChanged(TObject *Sender);
	void __fastcall SFSButtonMouseUp(TObject *Sender, TMouseButton Button,
          TShiftState Shift, int X, int Y);
	void __fastcall CPLRFButtonMouseUp(TObject *Sender, TMouseButton Button,
          TShiftState Shift, int X, int Y);
	void __fastcall CPLRRButtonMouseUp(TObject *Sender, TMouseButton Button,
          TShiftState Shift, int X, int Y);
	void __fastcall SXSButtonMouseUp(TObject *Sender, TMouseButton Button,
          TShiftState Shift, int X, int Y);
	void __fastcall SRSButtonMouseUp(TObject *Sender, TMouseButton Button,
          TShiftState Shift, int X, int Y);
	void __fastcall AutoWhistleLEDStatusChanged(TObject *Sender);
    void __fastcall AutoBellLEDClick(TObject *Sender);
    void __fastcall AutoWhistleLEDClick(TObject *Sender);
    void __fastcall BellOnWithHornLEDClick(TObject *Sender);
    void __fastcall PFAButtonStatusChanged(TObject *Sender);
    void __fastcall StopButtonOpClick(TObject *Sender);

protected:
    void __fastcall CMStopPFA(TMessage &Message);
    void __fastcall CMLaborRevUp(TMessage &Message);
    void __fastcall CMDriftRevDn(TMessage &Message);
    void __fastcall CMWhistle(TMessage &Message);
    void __fastcall CMCPLRF(TMessage &Message);
    void __fastcall CMCPLRR(TMessage &Message);

    void __fastcall CMSFS(TMessage &Message);
    void __fastcall CMSAH(TMessage &Message);
    void __fastcall CMSRS(TMessage &Message);
    void __fastcall CMSXS(TMessage &Message);

    void __fastcall WMTouch(TMessage &Message);

    BEGIN_MESSAGE_MAP
    	MESSAGE_HANDLER(CM_STOPPFA, TMessage, CMStopPFA)
        MESSAGE_HANDLER(CM_LABORREVUP, TMessage, CMLaborRevUp)
        MESSAGE_HANDLER(CM_DRIFTREVDN, TMessage, CMDriftRevDn)
        MESSAGE_HANDLER(CM_WHISTLE, TMessage, CMWhistle)
        MESSAGE_HANDLER(CM_CPLRF, TMessage, CMCPLRF)
        MESSAGE_HANDLER(CM_CPLRR, TMessage, CMCPLRR)

        MESSAGE_HANDLER(CM_SFS, TMessage, CMSFS)
        MESSAGE_HANDLER(CM_SAH, TMessage, CMSAH)
        MESSAGE_HANDLER(CM_SRS, TMessage, CMSRS)
        MESSAGE_HANDLER(CM_SXS, TMessage, CMSXS)
    END_MESSAGE_MAP(TForm)

private:	// User declarations
    int RemoteNo, ConsistNo, TIUNo;
    int HeadEngineNo;
	String ConsistName, HeadEngineName;
    char * LashUpEngineListOp;
    int PFAButtonCount;

    String RegFileRootKey;

    bool bBoosting, bBraking, bLaboredSmoke;
    int SavedSmokeLevel;
    int LastSetSpeed;

    TEngineCommands * EC;
	float LastSentSpeedValue;
    __fastcall TOp(TComponent* Owner);
    
    // values used by Volume and Mute
    int LastSentMasterVolumeValue, SavedMasterVolumeValue;
    
    // places to save event handler addresses
    void __fastcall (__closure *BellOnValueChanged)(TObject *Sender);
    void __fastcall (__closure *DirOnValueChanged)(TObject *Sender);
    void __fastcall (__closure *SmokeOnValueChanged)(TObject *Sender);
    void __fastcall (__closure *SpeedOnValueChanged)(TObject *Sender);
    void __fastcall (__closure *AccSpinOnValueChanged)(TObject *Sender);
    void __fastcall (__closure *DecSpinOnValueChanged)(TObject *Sender);

 	int iRevLevel;		// Diesel Rev Level 1-8
    bool LocalTransparencyOverride;

    void __fastcall (__closure *EventOnValueChange)(TObject *Sender);
    void __fastcall (__closure *EventOnStatusChanged)(TObject *Sender);
    void __fastcall (__closure *EventValueChange)(TObject *Sender);

public:		// User declarations

    __fastcall TOp(TComponent* Owner, int, int, int, String, char *);
    __fastcall ~TOp(void);
	HWND ParentHandle;	// accessed by Train_Control.cpp
    void __fastcall SetStandardAccDecValues(int EngineNo, int TIUNo);
   	void __fastcall SetSpeedSliderValue(float);
    void __fastcall Set_Speed(int Value);					// used by DelayedCommand()
    void __fastcall SendOneCommand(unsigned char * Cmd);	// used by DelayedCommand()

	// Controls to mate up with Quick Controls Windows
    TAbToggleSwitch * ptrQuick_Dir;
    TAbRockerSwitch * ptrQuick_Bell, * ptrQuick_Smoke;
    TAbNumEdit * ptrQuick_Speed;
    TMaskEdit * ptrQuick_EngNumber;
    TColor * ptrQuick_RunState;		// pointer to an array indexed by Engine Number
    TAbHSlider * ptrQuick_Sound;

    // expanded to Whistle and Coupler Buttons
	TAbColBitBtn * ptrQuick_Whistle;
	TAbColBitBtn * ptrQuick_Horn;
	TAbColBitBtn * ptrQuick_SFS;
	TAbColBitBtn * ptrQuick_SRS;
	TAbColBitBtn * ptrQuick_SXS;
	TAbColBitBtn * ptrQuick_CPLRF;
	TAbColBitBtn * ptrQuick_CPLRR;

   	// Pointers to mate up with Sound Controls Window
    TAbRockerSwitch * ptrVol_EngineSoundOnSwitch;
    TAbVSlider * ptrVol_MasterVolume;
  	// Pointer to mate up with Quick Controls Window
    //TAbHSlider * ptrQuick_MasterVolume;

    TTrackSignal * MyTrackSignal;
};
//---------------------------------------------------------------------------
extern PACKAGE TOp *Op;
//---------------------------------------------------------------------------
#endif
