r472: Initial import of Graph3d Doc/View
[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.1 2001/01/30 07:32:13 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 typedef GLfloat glTripleFloat[3];
40
41 class Graph3dFileCanvas;
42 class Graph3dFileView : public wxView 
43 {
44   friend Graph3dFileCanvas;
45
46 private:
47   DECLARE_DYNAMIC_CLASS(Graph3dFileView)   
48   DECLARE_EVENT_TABLE()
49    
50   wxMenu* m_pFileMenu;
51   GLfloat m_dXRotate;
52   GLfloat m_dYRotate;
53   std::vector<glTripleFloat> m_vecVerts;
54   std::vector<glTripleFloat> m_vecNorms;
55   GLint m_nVerts;
56   GLboolean m_bUseVertexArrays;
57   GLboolean m_bDoubleBuffer;
58   GLboolean m_bSmooth;
59   GLboolean m_bLighting;
60
61   void Draw();
62   void DrawSurface();
63   void InitMaterials();
64   void InitGL();
65
66   Graph3dFileCanvas* m_pCanvas;
67   Graph3dFileCanvas *CreateCanvas (wxFrame* parent);
68
69 #if CTSIM_MDI
70   wxDocMDIChildFrame* m_pFrame;
71   wxDocMDIChildFrame* CreateChildFrame(wxDocument *doc, wxView *view);
72 #else
73   wxDocChildFrame* m_pFrame;
74   wxDocChildFrame* CreateChildFrame(wxDocument *doc, wxView *view);
75 #endif
76
77   wxWindow* getFrameForChild() 
78 #if CTSIM_MDI
79   { return theApp->getMainFrame(); }
80 #else
81   { return m_pFrame; }
82 #endif
83
84 public:
85   Graph3dFileView();
86   virtual ~Graph3dFileView();
87   void canvasClosed()
88   { m_pCanvas = NULL; m_pFrame = NULL; }
89
90   bool OnCreate(wxDocument *doc, long flags);
91   void OnDraw(wxDC* dc);
92   void OnUpdate(wxView *sender, wxObject *hint = NULL);
93   bool OnClose (bool deleteWindow = true);
94   void OnProperties (wxCommandEvent& event);
95
96 #if CTSIM_MDI
97   wxDocMDIChildFrame* getFrame() { return m_pFrame; }
98 #else
99   wxDocChildFrame* getFrame() { return m_pFrame; }
100 #endif
101
102   Graph3dFileDocument* GetDocument() 
103   { return dynamic_cast<Graph3dFileDocument*>(wxView::GetDocument()); }
104 };
105
106
107 class Graph3dFileCanvas: public wxGLCanvas
108 {
109 private:
110   DECLARE_EVENT_TABLE()
111
112   void Reshape (int width, int height);
113   Graph3dFileView* m_pView;
114
115 public:
116    Graph3dFileCanvas (Graph3dFileView* view, wxWindow *parent, const wxPoint& pos = wxDefaultPosition,
117       const wxSize& size = wxDefaultSize, long style = 0, int* gl_attrib = NULL);
118    virtual ~Graph3dFileCanvas();
119
120    virtual void OnDraw(wxDC& dc);
121    void OnSize(wxSizeEvent& event);
122    void OnEraseBackground(wxEraseEvent& event);
123    void OnChar(wxKeyEvent& event);
124    void OnMouseEvent(wxMouseEvent& event);
125    void setView (Graph3dFileView* pView)  { m_pView = pView; }
126 };