source: trunk/geant4/visualization/OpenGL/src/G4OpenGLQtViewer.cc @ 542

Last change on this file since 542 was 542, checked in by garnier, 17 years ago

r688@mac-90108: laurentgarnier | 2007-07-06 18:41:19 +0200
mise a jour de la visu OpenGl. Ne marche pas encore, en version lente

  • Property svn:mime-type set to text/cpp
File size: 12.9 KB
Line 
1//
2// ********************************************************************
3// * License and Disclaimer                                           *
4// *                                                                  *
5// * The  Geant4 software  is  copyright of the Copyright Holders  of *
6// * the Geant4 Collaboration.  It is provided  under  the terms  and *
7// * conditions of the Geant4 Software License,  included in the file *
8// * LICENSE and available at  http://cern.ch/geant4/license .  These *
9// * include a list of copyright holders.                             *
10// *                                                                  *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work  make  any representation or  warranty, express or implied, *
14// * regarding  this  software system or assume any liability for its *
15// * use.  Please see the license in the file  LICENSE  and URL above *
16// * for the full disclaimer and the limitation of liability.         *
17// *                                                                  *
18// * This  code  implementation is the result of  the  scientific and *
19// * technical work of the GEANT4 collaboration.                      *
20// * By using,  copying,  modifying or  distributing the software (or *
21// * any work based  on the software)  you  agree  to acknowledge its *
22// * use  in  resulting  scientific  publications,  and indicate your *
23// * acceptance of all terms of the Geant4 Software license.          *
24// ********************************************************************
25//
26//
27// $Id: G4OpenGLQtViewer.cc,v 1.17 2006/06/29 21:19:36 gunter Exp $
28// GEANT4 tag $Name: geant4-08-01-patch-01 $
29//
30//
31// G4OpenGLQtViewer : Class to provide Qt specific
32//                     functionality for OpenGL in GEANT4
33//
34// 27/06/2003 : G.Barrand : implementation (at last !).
35
36#ifdef G4VIS_BUILD_OPENGLQT_DRIVER
37
38#include "G4OpenGLQtViewer.hh"
39
40#include "G4ios.hh"
41#include "G4VisExtent.hh"
42#include "G4LogicalVolume.hh"
43#include "G4VSolid.hh"
44#include "G4Point3D.hh"
45#include "G4Normal3D.hh"
46
47#include "G4Qt.hh"
48#include "G4UIManager.hh"
49#include <QtGui/qboxlayout.h>
50#include <QtGui/qdialog.h>
51#include <QtGui/qpushbutton.h>
52
53//////////////////////////////////////////////////////////////////////////////
54/**
55  Implementation of virtual method of G4VViewer
56 */
57void G4OpenGLQtViewer::SetView (
58)
59//////////////////////////////////////////////////////////////////////////////
60//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
61{
62  printf("G4OpenGLQtViewer::SetView ++++++++++++++++++++\n");
63//   if(!fHDC) return;
64//   if(!fHGLRC) return;
65//   ::wglMakeCurrent(fHDC,fHGLRC);
66  fWindow->makeCurrent();
67  G4OpenGLViewer::SetView (); 
68  printf("G4OpenGLQtViewer::SetView --------------------\n");
69}
70
71
72
73//////////////////////////////////////////////////////////////////////////////
74/**
75  Implementation of virtual method of G4VViewer
76 */
77void G4OpenGLQtViewer::ShowView (
78)
79//////////////////////////////////////////////////////////////////////////////
80//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
81{
82  printf("G4OpenGLQtViewer::ShowView  +++++++++++++++++++++\n");
83  //   if(!fHDC) return;
84  glFlush ();
85  printf("G4OpenGLQtViewer::ShowView -----------------------\n");
86
87//   // Empty the Windows message queue :
88//   MSG event;
89//   while ( ::PeekMessage(&event, NULL, 0, 0, PM_REMOVE) ) {
90//     ::TranslateMessage(&event);
91//     ::DispatchMessage (&event);
92//   }
93}
94
95
96// //////////////////////////////////////////////////////////////////////////////
97// void G4OpenGLQtViewer::GetQtConnection (
98// )
99// //////////////////////////////////////////////////////////////////////////////
100// //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
101// {
102// }
103
104//////////////////////////////////////////////////////////////////////////////
105void G4OpenGLQtViewer::CreateGLQtContext (
106)
107//////////////////////////////////////////////////////////////////////////////
108//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
109{
110  printf("G4OpenGLQtViewer::CreateGLQtContext \n");
111}
112
113//////////////////////////////////////////////////////////////////////////////
114void G4OpenGLQtViewer::CreateMainWindow (
115)
116//////////////////////////////////////////////////////////////////////////////
117//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
118{
119
120  if(fWindow) return; //Done.
121  printf("G4OpenGLQtViewer::CreateMainWindow 2\n");
122
123  // launch Qt if not
124  G4Qt* interactorManager = G4Qt::getInstance ();
125  //  G4UImanager* UI = G4UImanager::GetUIpointer();
126
127  fWindow = new QGLWidget() ;
128  fWindow->makeCurrent();
129
130  // create window
131  if (qApp) {
132    GLWindow = new QDialog();//qApp->mainWidget());
133  } else {
134    GLWindow = new QDialog();
135  }
136
137  QHBoxLayout *mainLayout = new QHBoxLayout;
138  mainLayout->addWidget(fWindow);
139  GLWindow->setLayout(mainLayout);
140  GLWindow->setWindowTitle("QGl Viewer");
141  GLWindow->resize(100, 300);
142  GLWindow->show();
143
144
145//   // Bill Gates stuff...
146//   static const char className[] = "G4OpenGLQt";
147//   static bool done = false;
148//   if(done==false) {
149//     WNDCLASS wc;
150//     wc.style = CS_HREDRAW | CS_VREDRAW;
151//     wc.lpfnWndProc = (WNDPROC)WindowProc;
152//     wc.cbClsExtra = 0;
153//     wc.cbWndExtra = 0;
154//     wc.hInstance = ::GetModuleHandle(NULL);
155//     wc.hIcon = LoadIcon  (NULL, IDI_APPLICATION);
156//     wc.hCursor = LoadCursor(NULL,IDC_CROSS);
157//     wc.hbrBackground = NULL;
158//     wc.lpszMenuName = className;
159//     wc.lpszClassName = className;
160//     ::RegisterClass(&wc);
161//     done = true;
162//   } 
163 
164   WinSize_x = 400;
165   WinSize_y = 400;
166   if (WinSize_x < fVP.GetWindowSizeHintX ())
167     WinSize_x = fVP.GetWindowSizeHintX ();
168   if (WinSize_y < fVP.GetWindowSizeHintY ())
169     WinSize_y = fVP.GetWindowSizeHintY ();
170
171//   fWindow = ::CreateWindow(className,fName.c_str(),
172//                         WS_OVERLAPPEDWINDOW,
173//                         //WS_CHILD | WS_VISIBLE,
174//                         0,0,
175//                         WinSize_x,WinSize_y,
176//                         NULL, NULL,
177//                         ::GetModuleHandle(NULL),
178//                         NULL);
179   if(!fWindow) return;
180
181//   ::SetWindowLong(fWindow,GWL_USERDATA,LONG(this));
182
183//   // initialize OpenGL rendering :
184//   fHDC = ::GetDC(fWindow);
185//   if( fHDC && (SetWindowPixelFormat(fHDC)==TRUE) ) {
186//     fHGLRC = ::wglCreateContext(fHDC);
187//   }
188 
189//   if(fHDC && fHGLRC) {
190//     ::wglMakeCurrent(fHDC,fHGLRC);
191//   }
192
193//   ::SetForegroundWindow(fWindow);
194//   ::ShowWindow(fWindow,SW_SHOWDEFAULT);
195//   ::UpdateWindow(fWindow);
196//   ::DrawMenuBar(fWindow);
197}
198
199//////////////////////////////////////////////////////////////////////////////
200void G4OpenGLQtViewer::CreateMainWindow (
201QGLWidget* glWidget
202)
203//////////////////////////////////////////////////////////////////////////////
204//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
205{
206
207  if(fWindow) return; //Done.
208  printf("G4OpenGLQtViewer::CreateMainWindow glWidget\n");
209
210  // launch Qt if not
211  G4Qt* interactorManager = G4Qt::getInstance ();
212  //  G4UImanager* UI = G4UImanager::GetUIpointer();
213
214  fWindow = glWidget ;
215  fWindow->makeCurrent();
216
217  // create window
218  if (qApp) {
219    GLWindow = new QDialog();//qApp->mainWidget());
220  } else {
221    GLWindow = new QDialog();
222  }
223
224  QHBoxLayout *mainLayout = new QHBoxLayout;
225  mainLayout->addWidget(fWindow);
226  GLWindow->setLayout(mainLayout);
227  GLWindow->setWindowTitle("QGl Viewer");
228  GLWindow->resize(300, 300);
229  GLWindow->show();
230
231
232//   // Bill Gates stuff...
233//   static const char className[] = "G4OpenGLQt";
234//   static bool done = false;
235//   if(done==false) {
236//     WNDCLASS wc;
237//     wc.style = CS_HREDRAW | CS_VREDRAW;
238//     wc.lpfnWndProc = (WNDPROC)WindowProc;
239//     wc.cbClsExtra = 0;
240//     wc.cbWndExtra = 0;
241//     wc.hInstance = ::GetModuleHandle(NULL);
242//     wc.hIcon = LoadIcon  (NULL, IDI_APPLICATION);
243//     wc.hCursor = LoadCursor(NULL,IDC_CROSS);
244//     wc.hbrBackground = NULL;
245//     wc.lpszMenuName = className;
246//     wc.lpszClassName = className;
247//     ::RegisterClass(&wc);
248//     done = true;
249//   } 
250 
251   WinSize_x = 400;
252   WinSize_y = 400;
253   if (WinSize_x < fVP.GetWindowSizeHintX ())
254     WinSize_x = fVP.GetWindowSizeHintX ();
255   if (WinSize_y < fVP.GetWindowSizeHintY ())
256     WinSize_y = fVP.GetWindowSizeHintY ();
257
258//   fWindow = ::CreateWindow(className,fName.c_str(),
259//                         WS_OVERLAPPEDWINDOW,
260//                         //WS_CHILD | WS_VISIBLE,
261//                         0,0,
262//                         WinSize_x,WinSize_y,
263//                         NULL, NULL,
264//                         ::GetModuleHandle(NULL),
265//                         NULL);
266   if(!fWindow) return;
267
268//   ::SetWindowLong(fWindow,GWL_USERDATA,LONG(this));
269
270//   // initialize OpenGL rendering :
271//   fHDC = ::GetDC(fWindow);
272//   if( fHDC && (SetWindowPixelFormat(fHDC)==TRUE) ) {
273//     fHGLRC = ::wglCreateContext(fHDC);
274//   }
275 
276//   if(fHDC && fHGLRC) {
277//     ::wglMakeCurrent(fHDC,fHGLRC);
278//   }
279
280//   ::SetForegroundWindow(fWindow);
281//   ::ShowWindow(fWindow,SW_SHOWDEFAULT);
282//   ::UpdateWindow(fWindow);
283//   ::DrawMenuBar(fWindow);
284}
285
286//////////////////////////////////////////////////////////////////////////////
287G4OpenGLQtViewer::G4OpenGLQtViewer (
288 G4OpenGLSceneHandler& scene
289)
290:G4VViewer (scene, -1)
291,G4OpenGLViewer (scene)
292,fWindow(0)
293                                   //,fHDC(0)
294                                   //,fHGLRC(0)
295//////////////////////////////////////////////////////////////////////////////
296//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
297{
298  printf("G4OpenGLQtViewer::G4OpenGLQtViewer \n");
299}
300
301//////////////////////////////////////////////////////////////////////////////
302G4OpenGLQtViewer::~G4OpenGLQtViewer (
303)
304//////////////////////////////////////////////////////////////////////////////
305//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
306{
307  printf("G4OpenGLQtViewer::~G4OpenGLQtViewer \n");
308//   // This is the end (Jim Morisson).
309//   if (fViewId >= 0) {
310//     if(wglGetCurrentContext()!=NULL) wglMakeCurrent(NULL,NULL);
311//     if(fHGLRC)       {
312//       wglDeleteContext(fHGLRC);
313//       fHGLRC = NULL;
314//     }
315   
316//     if(fWindow) {
317//       ::SetWindowLong(fWindow,GWL_USERDATA,LONG(NULL));
318//       if(fHDC) ::ReleaseDC(fWindow,fHDC);
319//       ::DestroyWindow(fWindow);
320//     }
321//   }
322}
323
324// //////////////////////////////////////////////////////////////////////////////
325// LRESULT CALLBACK G4OpenGLQtViewer::WindowProc (
326//  HWND   aWindow
327// ,UINT   aMessage
328// ,WPARAM aWParam
329// ,LPARAM aLParam
330// )
331// //////////////////////////////////////////////////////////////////////////////
332// //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
333// {
334/*
335  switch (aMessage) {
336  case WM_PAINT:{
337    printf("debug : PAINT\n");
338    HDC hDC;
339    PAINTSTRUCT ps;
340    hDC = BeginPaint(aWindow,&ps);
341    if(This) {
342      // FIXME : To have an automatic refresh someone have to redraw here.
343    }
344    EndPaint(aWindow, &ps);
345
346    //FIXME : have to handle WM_RESIZE
347    //pView->WinSize_x = (G4int) width;
348    //pView->WinSize_y = (G4int) height;
349    G4OpenGLQtViewer* This =
350      (G4OpenGLQtViewer*)::GetWindowLong(aWindow,GWL_USERDATA);
351    if(This) {
352      This->SetView();
353      glViewport(0,0,This->WinSize_x,This->WinSize_y);
354      This->ClearView();
355      This->DrawView();
356      // WARNING : the below empty the Windows message queue...
357      This->FinishView();
358    }
359  } return 0;
360  default:
361    return DefWindowProc(aWindow,aMessage,aWParam,aLParam);
362  }
363*/
364//   return DefWindowProc(aWindow,aMessage,aWParam,aLParam);
365// }
366
367// //////////////////////////////////////////////////////////////////////////////
368// bool G4OpenGLQtViewer::SetWindowPixelFormat(
369//  HDC aHdc
370// )
371// //////////////////////////////////////////////////////////////////////////////
372// //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
373// {
374//   // The ungessable...
375
376//   PIXELFORMATDESCRIPTOR pfd;
377//   pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
378//   pfd.nVersion = 1;
379//   pfd.dwFlags =
380//     PFD_DRAW_TO_WINDOW |
381//     PFD_SUPPORT_OPENGL |
382//     PFD_DOUBLEBUFFER |
383//     PFD_STEREO_DONTCARE; 
384//   pfd.iPixelType = PFD_TYPE_RGBA;
385//   pfd.cColorBits = 32;
386//   pfd.cRedBits = 8;
387//   pfd.cRedShift = 16;
388//   pfd.cGreenBits = 8;
389//   pfd.cGreenShift = 8;
390//   pfd.cBlueBits      = 8;
391//   pfd.cBlueShift = 0;
392//   pfd.cAlphaBits = 0;
393//   pfd.cAlphaShift = 0;
394//   pfd.cAccumBits = 64;       
395//   pfd.cAccumRedBits = 16;
396//   pfd.cAccumGreenBits = 16;
397//   pfd.cAccumBlueBits = 16;
398//   pfd.cAccumAlphaBits = 0;
399//   pfd.cDepthBits = 32;
400//   pfd.cStencilBits = 8;
401//   pfd.cAuxBuffers = 0;
402//   pfd.iLayerType = PFD_MAIN_PLANE;
403//   pfd.bReserved      = 0;
404//   pfd.dwLayerMask = 0;
405//   pfd.dwVisibleMask = 0;
406//   pfd.dwDamageMask = 0;
407 
408//   int pixelIndex = ::ChoosePixelFormat(aHdc,&pfd);
409//   if (pixelIndex==0) {
410//     pixelIndex = 1; 
411//     if (::DescribePixelFormat(aHdc,
412//                            pixelIndex,
413//                            sizeof(PIXELFORMATDESCRIPTOR),
414//                            &pfd)==0) {
415//       return false;
416//     }
417//   }
418//   if (::SetPixelFormat(aHdc,pixelIndex,&pfd)==FALSE) return false;
419//  return true;
420//}
421
422
423#endif
Note: See TracBrowser for help on using the repository browser.