// $Source: /usr/local/SimSoft/Sfx3D/src/gsl/gui.h,v $
// $Revision: 1.2 $
// $Author: baum $
// $Date: 2001/11/29 15:18:09 $
//
// Login name of the user who locked the revision
// $Locker:  $
// Tag name used to checkout the file
// $Name:  $
// State assigned to revision
// $State: Exp $
//
//
// $Log: gui.h,v $
// Revision 1.2  2001/11/29 15:18:09  baum
// -Realzeitsteuerung eingebaut
// -Handsteuerung eingebaut
//

#ifndef _GUI_H
#define _GUI_H	1


#include "tcl.h"

#include "Array.h"
#include "DynArray.h"
#include "Strings.h"

#include "Token.h"
#include "modell.h"

#include "Vec3D.h"

#include "XGraph/Wrap.h"
#include "XGraph/Color.h"
#include "XGraph/OGLCB.h"
#include "XGraph/ToglView.h"

#include "baustein.h"

#ifndef _PATTERN_H
  class Pattern;
#endif

#ifdef _GUI_CPP
#  undef _impexp
#  define _impexp __declspec(dllexport)
#elif defined BUILD_GRAF_DLL
#  undef _impexp
#  define _impexp
#else
#  undef _impexp
#  define _impexp __declspec(dllimport)
#endif

#if defined __GNUC__ || defined __hpux
#  undef _impexp
#  define _impexp
#endif

extern _impexp Tcl_Interp *SFXInterp;

extern class SFXViewHandler *MyViewHandler;

//==================================================================
//		Class-Header
//		for class SFXViewHandler
//==================================================================

class _impexp SFXViewHandler {
  public:
    SFXViewHandler  (Tcl_Interp* interp, const SFXModel& model);
    ~SFXViewHandler ();

    void createView (int xPos, int yPos);

    static void poseViews    (SFXViewHandler* forWhom);
    static void disposeViews (SFXViewHandler* forWhom, bool minimize = true, bool wasRunning = true);

    bool isPosed () const;

    const SimTime& TimeUpdate     () const;
    const SimTime& LastTimeUpdate () const;
    void  markTimeUpdate ();


    // redrawing the Views
    void flushViews ();

  protected:

  private:
    SFXModel*   ObjModel;
    Tcl_Interp* ObjInterp;

    class SFXDialogHandler* ObjDlgHandler;

    bool        ObjPosed;
    bool        ObjStopAfterPosed;
    unsigned    ObjCountOfDisposedViews;
    unsigned    ObjWinHeight;
    unsigned    ObjWinWidth;
    RGBAColor   ObjBgColor;
    WrapBox     ObjGridWrap;
    double      ObjGridSize;
    bool        ObjWithGrid;
    bool        ObjWireframe;
    bool        ObjLighting;
    bool        ObjAntialiasing;
    bool        ObjFogging;
    double      ObjFogDensity;
    Vec3D       ObjLightPos;
    Vec3D       ObjLightDir;
    ViewPoint   ObjViewPoint;
    SimTime     ObjTimeUpdate;
    SimTime     ObjLastTimeUpdate;

    DynArray<ToglView> ObjViews;

    void removeView       (ToglView* view);
    void setViewToDefault (ToglView* view);
    void setViewToViewpoint (ToglView* view,Ustring point);

    void setCamToDefault  (ToglView* view);
    void setCamToWalk     (ToglView* view);
    void setCamToZoom     (ToglView* view);
    void setCamToLight    (ToglView* view);
    void setCamToPermObj  (ToglView* view, GeoObject* go);
    void setCamToTempObj  (ToglView* view, GeoObject* go);
    void setObjectToFocus (ToglView* view, GeoObject* go);

    void saveSettings     (ToglView* view);

    static unsigned ClassId;
    static void     hangUpObject  (GeoObject* gObj);
    static int      ViewDialog    (ClientData clientData, Tcl_Interp *interp,
                                   int argc, const char *argv[]);
    static int      ContextDialog (ClientData cD, Tcl_Interp *interp,
                                   int argc, const char *argv[]);

    // declared, but not defined
    SFXViewHandler ();
    SFXViewHandler (const SFXViewHandler&);
    const SFXViewHandler operator = (const SFXViewHandler&);

};

//==================================================================
//		Class-Header
//		for class SFXVDialogHandler
//==================================================================

class SFXBaseDialog;

class SFXDialogHandler {
  public:
    SFXDialogHandler  (const SFXModel& model);
    ~SFXDialogHandler ();

    SFXBaseDialog* findDialog (const Ustring& widgetName) const;

    void addDialog    (const SFXBaseDialog&);
    void removeDialog (const SFXBaseDialog&);

    unsigned Timing    () const;
    unsigned setTiming (unsigned time); // in millisecs!!!!

  protected:

  private:
    // declared, but not defined!
    SFXDialogHandler ();
    SFXDialogHandler (const SFXDialogHandler&);
    const SFXDialogHandler& operator = (const SFXDialogHandler&);

    DynArray<SFXBaseDialog> ObjDialoge;

    unsigned       ObjTiming;
    SFXModel*      ObjModel;
    Tcl_TimerToken ObjTimerToken;

    static void updateTiming (ClientData cd);
};

//==================================================================
//		Class-Header
//		for the Dialog classes
//==================================================================

class SFXBaseDialog {
  public:
    const Ustring& WidgetName () const;

    virtual void update  () const {};
    virtual void setVals () const {};
    virtual void dispose ();

  protected:
    SFXBaseDialog (SFXDialogHandler*);
    virtual ~SFXBaseDialog ();

    Ustring           ObjWidgetName;
    SFXDialogHandler* ObjDlgHandler;
    Array<Ustring>    ObjVarNames;

  private:
    // declared, but not defined!
    SFXBaseDialog ();
    SFXBaseDialog (const SFXBaseDialog&);
    const SFXBaseDialog& operator = (const SFXBaseDialog&);
};

//==================================================================

class SFXPermDialog : public SFXBaseDialog {
  public:
    virtual void update  () const {};
    virtual void setVals () const {};

  protected:
    SFXPermDialog (typBaustein* perm, SFXDialogHandler* dlgHandler);
    virtual ~SFXPermDialog () {};

    typBaustein* ObjPermanent;

  private:
    // declared, but not defined!
    SFXPermDialog ();
    SFXPermDialog (const SFXPermDialog&);
    const SFXPermDialog& operator = (const SFXPermDialog&);
};

//==================================================================

class SFXPermStateDlg : public SFXPermDialog {
  public:
    static SFXBaseDialog* create (typBaustein* perm, SFXDialogHandler* dlgHandler);

    virtual void update  () const;

  protected:
    SFXPermStateDlg  (typBaustein* perm, SFXDialogHandler* dlgHandler);
    ~SFXPermStateDlg () {};

  private:
    // declared, but not defined!
    SFXPermStateDlg ();
    SFXPermStateDlg (const SFXPermStateDlg&);
    const SFXPermStateDlg& operator = (const SFXPermStateDlg&);

    static Ustring ClassTerms;
};

//==================================================================

class SFXPermControlDlg : public SFXPermDialog {
  public:
    static SFXBaseDialog* create (typBaustein* perm, SFXDialogHandler* dlgHandler);

    virtual void update  () const;
    virtual void setVals () const;

  protected:
    SFXPermControlDlg  (typBaustein* perm, SFXDialogHandler* dlgHandler);
    ~SFXPermControlDlg () {};

  private:
    typAvis* ObjAvis;
  
    // declared, but not defined!
    SFXPermControlDlg ();
    SFXPermControlDlg (const SFXPermControlDlg&);
    const SFXPermControlDlg& operator = (const SFXPermControlDlg&);

    static Ustring ClassTermsWithAvis;
    static Ustring ClassTermsWithoutAvis;
};

//==================================================================

class SFXPermUserDataDlg : public SFXPermDialog {
  public:
    static SFXBaseDialog* create (typBaustein* perm, SFXDialogHandler* dlgHandler);

    virtual void update  () const;

  protected:
    SFXPermUserDataDlg  (typBaustein* perm, SFXDialogHandler* dlgHandler);
    ~SFXPermUserDataDlg () {};

  private:
    // declared, but not defined!
    SFXPermUserDataDlg ();
    SFXPermUserDataDlg (const SFXPermUserDataDlg&);
    const SFXPermUserDataDlg& operator = (const SFXPermUserDataDlg&);
};

//==================================================================

class SFXTempDialog : public SFXBaseDialog {
  public:
    static SFXBaseDialog* create (typTransportEinheit* temp, SFXDialogHandler* dlgHandler);
    virtual void update  () const;

  protected:
    SFXTempDialog (typTransportEinheit* temp, SFXDialogHandler* dlgHandler);
    virtual ~SFXTempDialog () {};

  private:
    // declared, but not defined!
    SFXTempDialog ();
    SFXTempDialog (const SFXTempDialog&);
    const SFXTempDialog& operator = (const SFXTempDialog&);

    typTransportEinheit* ObjTemporary;

    static Ustring ClassTerms;
};

//==================================================================

class SFXTempUserDataDialog : public SFXBaseDialog {
  public:
    static SFXBaseDialog* create (typTransportEinheit* temp, SFXDialogHandler* dlgHandler);
    virtual void update  () const;

  protected:
    SFXTempUserDataDialog (typTransportEinheit* temp, SFXDialogHandler* dlgHandler);
    virtual ~SFXTempUserDataDialog () {};

  private:
    // declared, but not defined!
    SFXTempUserDataDialog ();
    SFXTempUserDataDialog (const SFXTempUserDataDialog&);
    const SFXTempUserDataDialog& operator = (const SFXTempUserDataDialog&);

    typTransportEinheit* ObjTemporary;
};

//==================================================================

class SFXRouteDialog : public SFXBaseDialog {
  public:
    static SFXBaseDialog* create (typTransportRoute* route, SFXDialogHandler* dlgHandler);
    virtual void update  () const;

  protected:
    SFXRouteDialog (typTransportRoute* route, SFXDialogHandler* dlgHandler);
    virtual ~SFXRouteDialog () {};

  private:
    // declared, but not defined!
    SFXRouteDialog ();
    SFXRouteDialog (const SFXRouteDialog&);
    const SFXRouteDialog& operator = (const SFXRouteDialog&);

    typTransportRoute* ObjRoute;

    static Ustring ClassTerms;
};

//==================================================================

class SFXWorkScheduleDialog : public SFXBaseDialog {
  public:
    static SFXBaseDialog* create (typArbeitsplan* ws, SFXDialogHandler* dlgHandler);
    virtual void update  () const;

  protected:
    SFXWorkScheduleDialog (typArbeitsplan* ws, SFXDialogHandler* dlgHandler);
    virtual ~SFXWorkScheduleDialog () {};

  private:
    // declared, but not defined!
    SFXWorkScheduleDialog ();
    SFXWorkScheduleDialog (const SFXWorkScheduleDialog&);
    const SFXWorkScheduleDialog& operator = (const SFXWorkScheduleDialog&);

    typArbeitsplan* ObjWorkSchedule;

    static Ustring ClassTerms;
};

//==================================================================
//  some definitions
//  for class SFXCallback
//==================================================================
class SFXCallback;

typedef void (ButtonHandling)  (SFXCallback * who, OGLView* view,
                                int button, int state, int x, int y);

typedef void (MotionHandling)  (SFXCallback * who, OGLView* view,
                                int state, int x, int y);

typedef void (PassiveHandling) (SFXCallback * who, OGLView* view,
                                int x, int y);

//==================================================================
//		Class-Header
//		for class SFXCallback
//==================================================================

class _impexp SFXCallback : public OGLViewCallback {
  public:
    // constructor
    SFXCallback ();

    // destructor
    virtual ~SFXCallback ();

    void setToStandard   ();
    void setToCamSetting ();
    void setToWalking    ();
    void setToZooming    ();
    void setToLight      ();

  private:
    // data-members
    int ObjStartX;
    int ObjStartY;
    int ObjDelta;
    unsigned ObjCursor;
    class SFXCBTimerData* ObjTimerData;
    Tk_TimerToken         ObjWalkTimer;
    GeoObject        ObjZoomRect;
    ButtonHandling  *ObjButtonHandling;
    MotionHandling  *ObjMotionHandling;
    PassiveHandling *ObjPassiveHandling;

    virtual void MouseButtonCB  (OGLView* view, int button, int state, int x, int y);
    virtual void MouseMotionCB  (OGLView* view, int state, int x, int y);
    virtual void MousePassiveCB (OGLView* view, int x, int y);

    static void StdButton     (SFXCallback *who, OGLView *view, int button, int state, int x, int y);
    static void CamSetButton  (SFXCallback *who, OGLView *view, int button, int state, int x, int y);
    static void ZoomButton    (SFXCallback *who, OGLView *view, int button, int state, int x, int y);

    static void StdMotion     (SFXCallback *who, OGLView *view, int state, int x, int y);
    static void WalkMotion    (SFXCallback *who, OGLView *view, int state, int x, int y);
    static void CamSetMotion  (SFXCallback *who, OGLView *view, int state, int x, int y);
    static void ZoomMotion    (SFXCallback *who, OGLView *view, int state, int x, int y);
    static void LightMotion   (SFXCallback *who, OGLView *view, int state, int x, int y);

    static void Passive       (SFXCallback *who, OGLView *view, int x, int y);

    static void walkTiming    (ClientData cd);

    static char* StatusText   (const GeoObject& obj);

    static Pattern *ClassRedRect;
    static unsigned ClassRefCounter;
    static void setup   ();
    static void cleanup ();

    static double ClassMinViewAngle;
    static double ClassMaxViewAngle;

    // copy constructor declared, but not defined
    SFXCallback (const SFXCallback&);

    // assignment operator declared, but not defined
    SFXCallback& operator = (const SFXCallback&);
};

#endif // !_GUI_H
