r2135: *** empty log message ***
[ctsim.git] / src / graph3dview.cpp
index 526ab6480ffd3032f3cf6c510b64deff7389ed59..a3343ab8a9523b5a6ce57d372c6b3be7399bb5ef 100644 (file)
@@ -9,7 +9,7 @@
 **  This is part of the CTSim program
 **  Copyright (c) 1983-2001 Kevin Rosenberg
 **
-**  $Id: graph3dview.cpp,v 1.20 2001/03/18 18:08:26 kevin Exp $
+**  $Id: graph3dview.cpp,v 1.28 2002/06/03 16:57:22 kevin Exp $
 **
 **  This program is free software; you can redistribute it and/or modify
 **  it under the terms of the GNU General Public License (version 2) as
@@ -65,7 +65,7 @@
 #include <sstream_subst>
 #endif
 
-void 
+inline void 
 Graph3dFileView::intensityToColor (double dIntensity, GLfloat* vecColor)
 {
   if (dIntensity < 0 || dIntensity > 1) {
@@ -140,28 +140,21 @@ EVT_MENU(IFMENU_FILE_PROPERTIES, Graph3dFileView::OnProperties)
 EVT_MENU(GRAPH3D_VIEW_LIGHTING, Graph3dFileView::OnLighting)
 EVT_MENU(GRAPH3D_VIEW_COLOR, Graph3dFileView::OnColor)
 EVT_MENU(GRAPH3D_VIEW_SMOOTH, Graph3dFileView::OnSmooth)
-EVT_MENU(GRAPH3D_VIEW_SURFACE, Graph3dFileView::OnSurface)
+EVT_MENU(GRAPH3D_VIEW_WIREFRAME, Graph3dFileView::OnWireframe)
 EVT_MENU(GRAPH3D_VIEW_SCALE_MINMAX, Graph3dFileView::OnScaleSet)
 EVT_MENU(GRAPH3D_VIEW_SCALE_AUTO, Graph3dFileView::OnScaleAuto)
 EVT_MENU(GRAPH3D_VIEW_SCALE_FULL, Graph3dFileView::OnScaleFull)
 END_EVENT_TABLE()
 
 Graph3dFileView::Graph3dFileView ()
-  : m_pFileMenu(NULL), m_pViewMenu(NULL), m_pCanvas(NULL), m_pFrame(NULL)
-{
-  m_bDoubleBuffer = true;
-  m_bSmooth = true;
-  m_bLighting = false;
-  m_bSurface = false;
-  m_bLighting = false;
-  m_bColor = true;
-  m_dXRotate = -180;
-  m_dYRotate = -210;
-  m_dZRotate = -195;
-  m_bColorScaleMinSet = false;
-  m_bColorScaleMaxSet = false;
-  m_bCalculatedSurfaceBackground = false;
-}
+  : m_pFileMenu(NULL), m_pViewMenu(NULL), m_pStatusBar(NULL), m_pCanvas(NULL), 
+    m_dXRotate(-180), m_dYRotate(-210), m_dZRotate(195), 
+    m_bDoubleBuffer(true), m_bSmooth(true), m_bWireframe(false), 
+    m_bLighting(true), m_bColor(true), m_bUseVertexArrays(false),
+    m_bColorScaleMinSet(false), m_bColorScaleMaxSet(false),
+    m_pFrame(NULL)
+{}
+
 
 Graph3dFileView::~Graph3dFileView()
 {
@@ -173,20 +166,17 @@ bool
 Graph3dFileView::OnCreate (wxDocument *doc, long WXUNUSED(flags) )
 {
   m_pFrame = CreateChildFrame(doc, this);
-  
-  int width, height;
-  m_pFrame->GetClientSize (&width, &height);
-  m_pFrame->SetTitle("Graph3dFileView");
   m_pCanvas = CreateCanvas (m_pFrame);
-  
-  m_pFrame->Show (true);
+
+  m_pFrame->SetClientSize (m_pCanvas->GetBestSize());
+  SetFrame (m_pFrame);
+  m_pCanvas->SetClientSize (m_pCanvas->GetBestSize());
+  m_pFrame->SetTitle("Graph3dFileView");
+
   m_pCanvas->SetCurrent();
   
   InitGL();
   
-  int x, y;  // X requires a forced resize
-  m_pFrame->GetSize(&x, &y);
-  m_pFrame->SetSize(-1, -1, x, y);
   m_pFrame->SetFocus();
   m_pFrame->Show(true);
   Activate(true);
@@ -194,7 +184,7 @@ Graph3dFileView::OnCreate (wxDocument *doc, long WXUNUSED(flags) )
   m_pViewMenu->Check (GRAPH3D_VIEW_COLOR, m_bColor);
   m_pViewMenu->Check (GRAPH3D_VIEW_LIGHTING, m_bLighting);
   m_pViewMenu->Check (GRAPH3D_VIEW_SMOOTH, m_bSmooth);
-  m_pViewMenu->Check (GRAPH3D_VIEW_SURFACE, m_bSurface);
+  m_pViewMenu->Check (GRAPH3D_VIEW_WIREFRAME, m_bWireframe);
   return true;
 } 
 
@@ -202,10 +192,8 @@ Graph3dFileCanvas*
 Graph3dFileView::CreateCanvas (wxFrame* parent)
 {
   Graph3dFileCanvas* pCanvas;
-  int width, height;
-  parent->GetClientSize (&width, &height);
   
-  pCanvas = new Graph3dFileCanvas (this, parent, wxPoint(0, 0), wxSize(200, 200), 0);
+  pCanvas = new Graph3dFileCanvas (this, parent, wxPoint(-1,-1), wxSize(-1,-1), 0);
   
   pCanvas->SetBackgroundColour(*wxWHITE);
   pCanvas->Clear();
@@ -241,15 +229,7 @@ Graph3dFileView::DrawSurface()
   glTranslated (-static_cast<double>(nx - 1) / 2, 0.0, -static_cast<double>(ny - 1) / 2);
 
   InitMaterials();   
-  if (m_bSurface) {
-    glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
-    if (! m_bColor) {
-      glColor3f (1.0f, 1.0f, 1.0f);
-      glCallList (DISPLAYLIST_NO_COLOR);
-    } else
-      glCallList (DISPLAYLIST_COLOR);
-  }
-  else {
+  if (m_bWireframe) {
     if (! m_bColor)
       glColor3f (1.0f, 1.0f, 1.0f);
     glPolygonOffset (1.0f, 1.0f);
@@ -261,6 +241,13 @@ Graph3dFileView::DrawSurface()
     glPolygonOffset (0.0f, 0.0f);
     glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
     glCallList (DISPLAYLIST_NO_COLOR);
+  } else {
+    glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
+    if (! m_bColor) {
+      glColor3f (1.0f, 1.0f, 1.0f);
+      glCallList (DISPLAYLIST_NO_COLOR);
+    } else
+      glCallList (DISPLAYLIST_COLOR);
   }
   
 }
@@ -289,7 +276,8 @@ Graph3dFileView::CreateDisplayList()
   dYOffset = 0;
 
   double dXPos = -dXOffset;
-  for (unsigned ix = 0; ix < nx - 1; ix++, dXPos++) {
+  unsigned int ix;
+  for (ix = 0; ix < nx - 1; ix++, dXPos++) {
     double dYPos = -dYOffset;
     glBegin(GL_QUAD_STRIP);
     double p1[3], p2[3], p3[3], n1[3]; 
@@ -366,19 +354,13 @@ Graph3dFileView::CreateDisplayList()
 }
 
 
-void
-Graph3dFileView::calculateSurfaceBackground ()
-{
-  if (m_bCalculatedSurfaceBackground)
-    return;
-}
-
 void
 Graph3dFileView::OnProperties (wxCommandEvent& event)
 {
   std::ostringstream os;
   *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<\n";
-  wxMessageDialog dialogMsg (getFrameForChild(), os.str().c_str(), "Imagefile Properties", wxOK | wxICON_INFORMATION);
+  wxMessageDialog dialogMsg (getFrameForChild(), os.str().c_str(), 
+                            "Imagefile Properties", wxOK | wxICON_INFORMATION);
   dialogMsg.ShowModal();
 }
 
@@ -387,15 +369,14 @@ Graph3dFileView::OnLighting (wxCommandEvent& event)
 {
   m_bLighting = ! m_bLighting;
   m_pViewMenu->Check (GRAPH3D_VIEW_LIGHTING, m_bLighting);
-  
   m_pCanvas->Refresh();
 }
 
 void
-Graph3dFileView::OnSurface (wxCommandEvent& event)
+Graph3dFileView::OnWireframe (wxCommandEvent& event)
 {
-  m_bSurface = ! m_bSurface;
-  m_pViewMenu->Check (GRAPH3D_VIEW_SURFACE, m_bSurface);
+  m_bWireframe = ! m_bWireframe;
+  m_pViewMenu->Check (GRAPH3D_VIEW_WIREFRAME, m_bWireframe);
   m_pCanvas->Refresh();
 }
 
@@ -420,19 +401,18 @@ Graph3dFileView::OnSmooth (wxCommandEvent& event)
 void 
 Graph3dFileView::OnDraw (wxDC* dc)
 {
-  if (! m_pCanvas)
-    return;
-  m_pCanvas->SetCurrent();
+  if (m_pCanvas) {
+    m_pCanvas->SetCurrent();
+    Draw();
+    m_pCanvas->SwapBuffers();
+  }
 
-#ifndef __WXMOTIF__
-  //  if (! m_pCanvas->GetContext()) return;
-#endif
-  
-  Draw();
-  std::ostringstream os;
-  os << "Xangle=" << m_dXRotate << ", Yangle=" << m_dYRotate << ", Zangle=" << m_dZRotate;
-  m_pStatusBar->SetStatusText (os.str().c_str());
-  m_pCanvas->SwapBuffers();
+  if (m_pStatusBar) {
+    std::ostringstream os;
+    os << "Xangle=" << m_dXRotate << ", Yangle=" << m_dYRotate 
+       << ", Zangle=" << m_dZRotate;
+    m_pStatusBar->SetStatusText (os.str().c_str());
+  }
 }
 
 
@@ -746,15 +726,19 @@ wxDocChildFrame*
 Graph3dFileView::CreateChildFrame (wxDocument *doc, wxView *view)
 {
 #if CTSIM_MDI
-  wxDocMDIChildFrame* subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Graph3dFile Frame", wxPoint(-1, -1), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
+  wxDocMDIChildFrame* subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Graph3dFile Frame", wxPoint(-1,-1), wxSize(-1,-1), wxDEFAULT_FRAME_STYLE);
 #else
-  wxDocChildFrame* subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "Graph3dFile Frame", wxPoint(-1, -1), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
+  wxDocChildFrame* subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "Graph3dFile Frame", wxPoint(-1,-1), wxSize(-1,-1), wxDEFAULT_FRAME_STYLE);
 #endif
   theApp->setIconForFrame (subframe);
   
+// status bar text not showing tested with enlightenment. disabling for now...
+#if 0 
   m_pStatusBar = new wxStatusBar (subframe, -1);
   subframe->SetStatusBar (m_pStatusBar);
-  
+  m_pStatusBar->Show(true);
+#endif
+
   m_pFileMenu = new wxMenu;
   
   m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
@@ -777,7 +761,7 @@ Graph3dFileView::CreateChildFrame (wxDocument *doc, wxView *view)
   GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
   
   m_pViewMenu = new wxMenu;
-  m_pViewMenu->Append(GRAPH3D_VIEW_SURFACE, "Su&rface\tCtrl-R", "", true);
+  m_pViewMenu->Append(GRAPH3D_VIEW_WIREFRAME, "Wi&reframe\tCtrl-R", "", true);
   m_pViewMenu->Append(GRAPH3D_VIEW_SMOOTH, "S&mooth\tCtrl-M", "", true);
   m_pViewMenu->Append(GRAPH3D_VIEW_COLOR, "Co&lor\tCtrl-L", "", true);
   m_pViewMenu->Append(GRAPH3D_VIEW_LIGHTING, "Li&ghting\tCtrl-G", "", true);
@@ -802,7 +786,7 @@ Graph3dFileView::CreateChildFrame (wxDocument *doc, wxView *view)
   subframe->Centre(wxBOTH);
 
   wxAcceleratorEntry accelEntries[7];
-  accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('R'), GRAPH3D_VIEW_SURFACE);
+  accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('R'), GRAPH3D_VIEW_WIREFRAME);
   accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('L'), GRAPH3D_VIEW_COLOR);
   accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('G'), GRAPH3D_VIEW_LIGHTING);
   accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('M'), GRAPH3D_VIEW_SMOOTH);
@@ -856,6 +840,13 @@ Graph3dFileCanvas::OnDraw (wxDC& dc)
     m_pView->OnDraw(& dc);
 }
 
+
+wxSize
+Graph3dFileCanvas::GetBestSize() const
+{
+  return wxSize (400,400);
+}
+
 void 
 Graph3dFileCanvas::OnSize (wxSizeEvent& event)
 {
@@ -901,8 +892,8 @@ Graph3dFileCanvas::OnChar(wxKeyEvent& event)
     m_pView->m_dYRotate -= 15.0;
     Refresh (false);
     break;
-  case 'r': case 'R':
-    m_pView->OnSurface (dummyEvent);
+  case 'w': case 'W':
+    m_pView->OnWireframe (dummyEvent);
     break;
   case 's': case 'S':
     m_pView->OnSmooth (dummyEvent);