// $Source: /usr/local/SimSoft/SoftShop/XGraph/Views/OGLView.h,v $
// $Revision: 1.20 $
// $Author: baum $
// $Date: 2001/11/29 15:52:24 $
//
// Login name of the user who locked the revision
// $Locker:  $
// Tag name used to checkout the file
// $Name: Release-20 $
// State assigned to revision
// $State: Exp $
//
//
// $Log: OGLView.h,v $
// Revision 1.20  2001/11/29 15:52:24  baum
// -In Kalender.cpp und Kalender.h Handsteuerung eingebaut
//

#ifndef _OGLVIEW_H
#define _OGLVIEW_H  1

#include "GL/gl.h"

#include "Strings.h"
#include "DynArray.h"
#include "Map.h"

#include "Vec3D.h"
#include "Wrap.h"
#include "Color.h"

#include "View.h"
#include "OGLCam.h"
#include "OGLLight.h"

#ifndef _OGLCALLBACK_H
class OGLViewCallback;
#endif

#ifdef _OGLVIEW_CPP
#  undef _impexp
#  define _impexp __declspec(dllexport)
#elif defined BUILD_VIEWS_DLL
#  undef _impexp
#  define _impexp __declspec(dllexport)
#else
#  undef _impexp
#  define _impexp __declspec(dllimport)
#endif

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

//==================================================================
//		Class-Header
//		for class OGLView
//==================================================================

//##ModelId=4030D76F004E
class _impexp OGLView : public View
  {
  public:
    // getting Index of free DisplayList
	//##ModelId=4030D76F005E
    static unsigned getFreeIndex ();

    // init all Lights and Attributes
	//##ModelId=4030D76F0060
    static void setup   ();
	//##ModelId=4030D76F0062
    static void cleanup ();
	//##ModelId=4030D76F006E
    static bool isInitialized ();

	//##ModelId=4030D76F0070
    unsigned Width  () const;
	//##ModelId=4030D76F0072
    unsigned Height () const;
	//##ModelId=4030D76F007E
    const RGBAColor& BgColor    () const;
	//##ModelId=4030D76F0080
    virtual void     setBgColor (const RGBAColor& col);

    // creates the Window with Space
	//##ModelId=4030D76F008C
    virtual void pose (Space *);

    // for Space to cut connection
	//##ModelId=4030D76F008F
    virtual void dispose ();

    // redrawing the View
	//##ModelId=4030D76F0091
    virtual void flush ();

    // get a Camera-handle
	//##ModelId=4030D76F009D
    OGLCamera *Camera ();

    // manipulate the projection of camera
	//##ModelId=4030D76F009E
    virtual void setToPerspectiveProj ();
	//##ModelId=4030D76F00A0
    virtual void setToOrthogonalProj  ();

    // manipulate and get informations about ViewPoints
	//##ModelId=4030D76F00AB
    virtual const ViewPoint& addViewPoint    (const Ustring& name, const ViewPoint& vp);
	//##ModelId=4030D76F00AF
    virtual bool             removeViewPoint (const Ustring& name);
	//##ModelId=4030D76F00B2
    virtual bool             setToViewPoint  (const Ustring& name);

	//##ModelId=4030D76F00BD
    const Map<Ustring, ViewPoint> ViewPoints () const;

    // manipulate CB-Handling
	//##ModelId=4030D76F00BF
    OGLViewCallback* Callback () const;
	//##ModelId=4030D76F00C1
    void setCallback (OGLViewCallback* myCB);

    // find clicked Object
    // and save to 'HitObject'
	//##ModelId=4030D76F00CC
    static void doSelect (OGLView *view, DynArray<GeoObject>& selectedObjects,
                          GLint x, GLint y, GLint width, GLint height);

    // wich Object is selected of an subset of GeoObjects
    // (for example DynArray of 'SelectedObjects' from class Selection)
	//##ModelId=4030D76F00DD
    GeoObject *doSelectOfSubset (const DynArray<GeoObject>& subsetOfObjects,
                                 GLint x, GLint y, GLint width, GLint height);

    // Update View every 'timing' in millisecs
	//##ModelId=4030D76F00EC
    virtual void makeMovie (unsigned);
	//##ModelId=4030D76F00EF
    virtual void stopMovie ();

    // setting the window title
	//##ModelId=4030D76F00FB
    virtual void setTitle (char *);

    // some Settings, but be carefull because all
    // activated Settings will be slow down the App
	//##ModelId=4030D76F00FE
    OGLLight*    Light     ();
	//##ModelId=4030D76F00FF
    virtual void showLight ();
	//##ModelId=4030D76F0109
    virtual void hideLight ();

	//##ModelId=4030D76F010B
    bool isLightOn () const;
	//##ModelId=4030D76F010D
    virtual void lightOn  ();
	//##ModelId=4030D76F010F
    virtual void lightOut ();

	//##ModelId=4030D76F011A
    bool isSmoothOn () const;
	//##ModelId=4030D76F011C
    virtual void smoothOn  ();
	//##ModelId=4030D76F011E
    virtual void smoothOut ();

	//##ModelId=4030D76F0128
    bool isWireOn () const;
	//##ModelId=4030D76F012A
    virtual void wireOn  ();
	//##ModelId=4030D76F012C
    virtual void wireOut ();

	//##ModelId=4030D76F012E
    bool isShadowOn () const;
	//##ModelId=4030D76F0138
    virtual void shadowOn  ();
	//##ModelId=4030D76F013A
    virtual void shadowOut ();

	//##ModelId=4030D76F013C
    void   setFogColor   (const RGBAColor& fogCol);
	//##ModelId=4030D76F0148
    void   setFogDensity (double density);
	//##ModelId=4030D76F014A
    double FogDensity    () const;

	//##ModelId=4030D76F014C
    bool isFogOn () const;
	//##ModelId=4030D76F014E
    virtual void fogOn       ();
	//##ModelId=4030D76F0158
    virtual void fogOut      ();

    // show Axis
	//##ModelId=4030D76F015A
    virtual void showAxis ();
	//##ModelId=4030D76F015C
    virtual void hideAxis ();

    // setup Grid (automatic or manual)
	//##ModelId=4030D76F0168
    void setGrid ();
	//##ModelId=4030D76F0169
    void setGrid (GLfloat gridSize, const Vec3D& min, const Vec3D& max);
	//##ModelId=4030D76F0178
    void setGridColor (const RGBAColor& col);

    // some informations about the grid
	//##ModelId=4030D76F017A
    float GridSize   ();
	//##ModelId=4030D76F017B
    const WrapBox& Grid  ();

    // show or hide Grid
	//##ModelId=4030D76F0186
    bool hasToShowGrid () const;
	//##ModelId=4030D76F0188
    virtual void showGrid    ();
	//##ModelId=4030D76F018A
    virtual void hideGrid    ();

    // setup Base
	//##ModelId=4030D76F018C
    void setBase (const Vec3D& min, const Vec3D& max, unsigned baseSubDiv = 20);
	//##ModelId=4030D76F0199
    void setBaseColor (const RGBAColor& col);

    // some informations about the Base
	//##ModelId=4030D76F019B
    unsigned BaseSubdivision ();
	//##ModelId=4030D76F01A5
    const WrapBox& Base ();

    // show or hide Base
	//##ModelId=4030D76F01A6
    bool hasToShowBase () const;
	//##ModelId=4030D76F01A8
    virtual void showBase    ();
	//##ModelId=4030D76F01AA
    virtual void hideBase    ();

  protected:
    //constructor (all Koords are in ScreenPixels)
	//##ModelId=4030D76F01B6
    OGLView (unsigned xPos, unsigned yPos, unsigned xSize, unsigned ySize,
             const RGBAColor& bgColor);

    //destructor
	//##ModelId=4030D76F01C5
    virtual ~OGLView ();

    //data members
	//##ModelId=4030D76F01C8
    unsigned  ObjWidth;
	//##ModelId=4030D76F01D5
    unsigned  ObjHeight;
	//##ModelId=4030D76F01DA
    unsigned  ObjPosX;
	//##ModelId=4030D76F01E5
    unsigned  ObjPosY;
	//##ModelId=4030D76F01F5
    RGBAColor ObjBgColor;

	//##ModelId=4030D76F01F9
    bool     ObjLightOn;
	//##ModelId=4030D76F0203
    bool     ObjShowLight;
	//##ModelId=4030D76F0205
    OGLLight ObjLight;
	//##ModelId=4030D76F0214
    static GLuint ClassLightOnIndex;
	//##ModelId=4030D76F0223
    static GLuint ClassLightOutIndex;

	//##ModelId=4030D76F0227
    bool      ObjFog;
	//##ModelId=4030D76F0233
    RGBAColor ObjFogColor;
	//##ModelId=4030D76F0243
    RGBAColor ObjSaveColor;
	//##ModelId=4030D76F0248
    GLfloat   ObjFogDensity;
	//##ModelId=4030D76F0252
    static GLuint ClassFogOnIndex;
	//##ModelId=4030D76F0262
    static GLuint ClassFogOutIndex;

	//##ModelId=4030D76F0266
    bool   ObjSmooth;
	//##ModelId=4030D76F0272
    static GLuint ClassSmoothOnIndex;
	//##ModelId=4030D76F0281
    static GLuint ClassSmoothOutIndex;

	//##ModelId=4030D76F0290
    bool   ObjWire;
	//##ModelId=4030D76F02A0
    static GLuint ClassWireOnIndex;
	//##ModelId=4030D76F02A5
    static GLuint ClassWireOutIndex;

	//##ModelId=4030D76F02B1
    bool   ObjShadow;
	//##ModelId=4030D76F02C0
    static GLuint ClassShadowOnIndex;
	//##ModelId=4030D76F02CF
    static GLuint ClassShadowOutIndex;

	//##ModelId=4030D76F02DF
    unsigned  ObjTiming;

	//##ModelId=4030D76F02E4
    OGLCamera ObjMyCamera;
	//##ModelId=4030D76F02FF
    Map<Ustring, ViewPoint> ObjViewPoints;

	//##ModelId=4030D76F030E
    static GLuint ClassSelectBuf[];
	//##ModelId=4030D76F031C
    static double ClassSelectionDepth;

    // some stuff for CB-Handling
	//##ModelId=4030D76F032D
    OGLViewCallback *ObjMyCB;

    //DisplayListIndex of Grid or Axis

    // bulding Grid, Axis or Base (for shadows)
	//##ModelId=4030D76F0331
    bool      ObjWithAxis;
	//##ModelId=4030D76F033D
    GLuint    ObjAxisIndex;

	//##ModelId=4030D76F034B
    bool      ObjWithGrid;
	//##ModelId=4030D76F035C
    GLuint    ObjGridIndex;
	//##ModelId=4030D76F036C
    GLfloat   ObjGridSize;
	//##ModelId=4030D76F037B
    WrapBox   ObjGrid;
	//##ModelId=4030D76F038B
    RGBAColor ObjGridColor;

	//##ModelId=4030D76F0399
    bool      ObjWithBase;
	//##ModelId=4030D76F03AA
    GLuint    ObjBaseIndex;
	//##ModelId=4030D76F03B9
    unsigned  ObjBaseSubdivision;
	//##ModelId=4030D76F03BE
    WrapBox   ObjBase;
	//##ModelId=4030D76F03C9
    RGBAColor ObjBaseColor;

	//##ModelId=4030D76F03D8
    void buildGrid ();
	//##ModelId=4030D76F03D9
    void buildAxis ();
	//##ModelId=4030D7700000
    void buildBase ();

    // resizeing, rendering
	//##ModelId=4030D7700001
    void resize       (const double& width, const double& height);
	//##ModelId=4030D770001F
    void render       ();

  private:
    // copy constructor declared, but not defined
	//##ModelId=4030D7700020
    OGLView (const OGLView&);

    // assignment operator declared, but not defined
	//##ModelId=4030D770002E
    OGLView& operator = (const OGLView&);

    // init the OpenGL state for max perfomance
	//##ModelId=4030D770003E
    static void setupOpenGL ();

    // detail-rendering and getSelection
	//##ModelId=4030D7700040
    void renderScene  ();
	//##ModelId=4030D7700041
    void renderExtras ();
	//##ModelId=4030D770004E
    void renderObject (GeoObject& gobj);
	//##ModelId=4030D770005D
    void selectObject (GeoObject& gobj, DynArray<GeoObject>& selectedObjects);

	//##ModelId=4030D770006E
    GeoObject *subsetSelect (const GeoObject& gobj);

}; // class OGLView

#endif // !_OGLVIEW_H

