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