#ifndef MGCOSY_H
#define MGCOSY_H

#ifndef ROOT_TGFrame
#include <TGFrame.h>
#endif

#ifndef MARS_MObservatory
#include "MObservatory.h"
#endif

#ifndef COSY_MStarList
#include "MStarList.h"
#endif

class TIterator;

class TGTab;
class TGLabel;
class TGTextView;
class TGPopupMenu;
class TGLayoutHints;
class TGCompositeFrame;
class TGHorizontal3DLine;

class ZdAz;
class RaDec;
class MsgQueue;
class MCeCoCom;

class MGList;
class MGImage;
class MGAccuracy;
class MGAccuracyTime;
class MGVelocity;
class MGCoordinates;
class MGSkyPosition;

class MGCosy : public TGMainFrame
{
private:
    const MObservatory::LocationName_t fObservatory;

    //
    // Create a main frame with a number of different buttons.
    //
    MGList        *fList;

    TGLabel       *fLabel1;
    TGLabel       *fLabel2;
    // TGLabel       *fLabel3;

    // TGLabel       *fOffsetZd;
    // TGLabel       *fOffsetAz;

    TGLabel       *fRaEst;
    TGLabel       *fDecEst;

    TGLabel       *fRaSoll;
    TGLabel       *fDecSoll;

    TGLabel       *fZdSoll;
    TGLabel       *fAzSoll;

    TGLabel       *fMsgZd;
    TGLabel       *fMsgAz;

    TGLabel       *fUtc;
    TGLabel       *fMjd;

    TGLabel       *fWeather;

    MStarList     fPreDefList;
    MStarList     fStarList;

    MGCoordinates *fCZdAz;
    MGCoordinates *fCRaDec;
    MGCoordinates *fCCalib;

    MGSkyPosition  *fSkyPosition;
    MGAccuracy     *fAccuracy;
    MGVelocity     *fVelocity;
    MGVelocity     *fOffset;

    MGImage *fImage;

    MsgQueue      *fQueue;

    TGTab         *fTab;

    TGLabel *fArmed;
    TGLabel *fError;
    TGLabel *fMoving;
    TGLabel *fTracking;
    TGLabel *fStopping;
    TGLabel *fStopped;
    //TGLabel *fAvailDkc1;
    //TGLabel *fAvailDkc2;
    TGLabel *fAvailTcp;

    TGLabel *fDkcReady1;
    TGLabel *fDkcReady2;
    TGLabel *fDkcEmergency;
    TGLabel *fDkcPcMode;
    TGLabel *fDkcRF1;
    TGLabel *fDkcRF2;
    TGLabel *fDkcBrake;
    TGLabel *fDkcPower;

    TGTextView *fLog;

    FontStruct_t fFont;

    void CreateMenu();
    void CreateLabel(TGCompositeFrame *f);
    void CreateTabs(const char *prepos);
    void CreatePredefinedPos(TGCompositeFrame *tf1, const char *prepos);
    void CreateStarList(TGCompositeFrame *tf1);

    void StartPos();
    void StartTrack(bool track);
    void StartTrackPos(Long_t mp1=0);
    void StartDemo();
    //void StartCalib();
    void StartTPoint();

    void EnableLabel(TGLabel *label, Bool_t stat);
    void SetLabelColor(TGLabel *label, Bool_t col);
    //void UpdateOffset(ZdAz &off);
    void UpdateZdAz(ZdAz &off);
    void UpdateRaDec(ZdAz &pos, double mjd, RaDec &radec);
    double UpdateTime();

public:
    MGCosy(MObservatory::LocationName_t key, const char *prepos, MsgQueue *q);
    ~MGCosy();

    void CloseWindow();

    TGLabel *GetLabel1() const { return fLabel1; }
    TGLabel *GetLabel2() const { return fLabel2; }
    //TGLabel *GetLabel3() const { return fLabel3; }

    TGTextView *GetLog() const { return fLog; }
    MGImage    *GetImage()     { return fImage; }

    void Update(ZdAz pos, ZdAz acc, /*ZdAz vel, ZdAz off,*/ RaDec radec, ZdAz soll, UInt_t stat, UInt_t pdo3, UInt_t stat2, Bool_t armed, const TString &statzd, const TString &stataz);
    void UpdateWeather(const MCeCoCom &com);

    Bool_t ProcessMessage(Long_t msg, Long_t mp1, Long_t mp2);

    ClassDef(MGCosy, 0)
};

#endif


