r640: no message
[ctsim.git] / src / graph3dview.h
1 /*****************************************************************************
2 ** FILE IDENTIFICATION
3 **
4 **   Name:          graph3dview.h
5 **   Purpose:       Header file for 3d graph view
6 **   Programmer:    Kevin Rosenberg
7 **   Date Started:  Jan 2001
8 **
9 **  This is part of the CTSim program
10 **  Copyright (c) 1983-2001 Kevin Rosenberg
11 **
12 **  $Id: graph3dview.h,v 1.7 2001/03/18 18:08:26 kevin Exp $
13 **
14 **  This program is free software; you can redistribute it and/or modify
15 **  it under the terms of the GNU General Public License (version 2) as
16 **  published by the Free Software Foundation.
17 **
18 **  This program is distributed in the hope that it will be useful,
19 **  but WITHOUT ANY WARRANTY; without even the implied warranty of
20 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 **  GNU General Public License for more details.
22 **
23 **  You should have received a copy of the GNU General Public License
24 **  along with this program; if not, write to the Free Software
25 **  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26 ******************************************************************************/
27
28 #if !wxUSE_GLCANVAS
29 #error Please set wxUSE_GLCANVAS to 1 in setup.h.
30 #endif
31
32 #include "wx/timer.h"
33 #include "wx/glcanvas.h"
34
35 #include <GL/gl.h>
36 #include <GL/glu.h>
37
38
39 class Graph3dFileCanvas;
40 class Graph3dFileView : public wxView 
41 {
42   friend Graph3dFileCanvas;
43
44 private:
45   DECLARE_DYNAMIC_CLASS(Graph3dFileView)   
46   DECLARE_EVENT_TABLE()
47    
48   wxMenu* m_pFileMenu;
49   wxMenu *m_pViewMenu;
50   wxStatusBar* m_pStatusBar;
51
52   GLfloat m_dXRotate;
53   GLfloat m_dYRotate;
54   GLfloat m_dZRotate;
55   bool m_bUseVertexArrays;
56   bool m_bDoubleBuffer;
57   bool m_bSmooth;
58   bool m_bLighting;
59   bool m_bSurface;
60   bool m_bColor;
61   enum {
62     DISPLAYLIST_COLOR = 1,
63     DISPLAYLIST_NO_COLOR = 2,
64   };
65
66   double m_dGraphMin;
67   double m_dGraphMax;
68   double m_dColorScaleMin;
69   double m_dColorScaleMax;
70   bool m_bColorScaleMinSet;
71   bool m_bColorScaleMaxSet;
72   bool m_bCalculatedSurfaceBackground;
73
74   void Draw();
75   void DrawSurface();
76   void CreateDisplayList();
77   void InitMaterials();
78   void InitGL();
79
80   Graph3dFileCanvas* m_pCanvas;
81   Graph3dFileCanvas *CreateCanvas (wxFrame* parent);
82
83 #if CTSIM_MDI
84   wxDocMDIChildFrame* m_pFrame;
85   wxDocMDIChildFrame* CreateChildFrame(wxDocument *doc, wxView *view);
86 #else
87   wxDocChildFrame* m_pFrame;
88   wxDocChildFrame* CreateChildFrame(wxDocument *doc, wxView *view);
89 #endif
90
91   wxWindow* getFrameForChild() 
92 #if CTSIM_MDI
93   { return theApp->getMainFrame(); }
94 #else
95   { return m_pFrame; }
96 #endif
97
98   void intensityToColor (double dIntensity, GLfloat* vecColor);
99
100 public:
101   Graph3dFileView();
102   virtual ~Graph3dFileView();
103   void canvasClosed()
104   { m_pCanvas = NULL; m_pFrame = NULL; }
105
106   bool OnCreate(wxDocument *doc, long flags);
107   void OnDraw(wxDC* dc);
108   void OnUpdate(wxView *sender, wxObject *hint = NULL);
109   bool OnClose (bool deleteWindow = true);
110   void OnProperties (wxCommandEvent& event);
111   void OnLighting (wxCommandEvent& event);
112   void OnSurface (wxCommandEvent& event);
113   void OnColor (wxCommandEvent& event);
114   void OnSmooth (wxCommandEvent& event);
115   void OnScaleSet (wxCommandEvent& event);
116   void OnScaleAuto (wxCommandEvent& event);
117   void OnScaleFull (wxCommandEvent& event);
118   void calculateSurfaceBackground();
119
120 #if CTSIM_MDI
121   wxDocMDIChildFrame* getFrame() { return m_pFrame; }
122 #else
123   wxDocChildFrame* getFrame() { return m_pFrame; }
124 #endif
125   Graph3dFileCanvas* getCanvas() { return m_pCanvas; }
126   Graph3dFileDocument* GetDocument() 
127   { return dynamic_cast<Graph3dFileDocument*>(wxView::GetDocument()); }
128 };
129
130
131 class Graph3dFileCanvas: public wxGLCanvas
132 {
133 private:
134   DECLARE_EVENT_TABLE()
135
136   void Reshape (int width, int height);
137   Graph3dFileView* m_pView;
138
139 public:
140    Graph3dFileCanvas (Graph3dFileView* view, wxWindow *parent, const wxPoint& pos = wxDefaultPosition,
141       const wxSize& size = wxDefaultSize, long style = 0);
142    virtual ~Graph3dFileCanvas();
143
144    virtual void OnDraw(wxDC& dc);
145    void OnSize(wxSizeEvent& event);
146    void OnEraseBackground(wxEraseEvent& event);
147    void OnChar(wxKeyEvent& event);
148    void OnMouseEvent(wxMouseEvent& event);
149    void setView (Graph3dFileView* pView)  { m_pView = pView; }
150 };