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

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

r681@mac-90108: laurentgarnier | 2007-07-05 17:58:13 +0200
mise a jour de la visu OpenGl. Ne marche pas encore

  • Property svn:mime-type set to text/cpp
File size: 13.7 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//   G4OpenGLViewer::SetView (); 
67}
68
69//////////////////////////////////////////////////////////////////////////////
70/**
71  Implementation of virtual method of G4VViewer
72 */
73void G4OpenGLQtViewer::ClearView (
74)
75//////////////////////////////////////////////////////////////////////////////
76//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
77{
78  printf("G4OpenGLQtViewer::ClearView \n");
79}
80
81
82//////////////////////////////////////////////////////////////////////////////
83/**
84  Implementation of virtual method of G4VViewer
85 */
86void G4OpenGLQtViewer::DrawView (
87)
88//////////////////////////////////////////////////////////////////////////////
89//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
90{
91  printf("G4OpenGLQtViewer::DrawView \n");
92}
93
94//////////////////////////////////////////////////////////////////////////////
95/**
96  Implementation of virtual method of G4VViewer
97 */
98void G4OpenGLQtViewer::ShowView (
99)
100//////////////////////////////////////////////////////////////////////////////
101//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
102{
103  printf("G4OpenGLQtViewer::ShowView \n");
104//   if(!fHDC) return;
105//   glFlush ();
106//   // Empty the Windows message queue :
107//   MSG event;
108//   while ( ::PeekMessage(&event, NULL, 0, 0, PM_REMOVE) ) {
109//     ::TranslateMessage(&event);
110//     ::DispatchMessage (&event);
111//   }
112}
113
114
115// //////////////////////////////////////////////////////////////////////////////
116// void G4OpenGLQtViewer::GetQtConnection (
117// )
118// //////////////////////////////////////////////////////////////////////////////
119// //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
120// {
121// }
122
123//////////////////////////////////////////////////////////////////////////////
124void G4OpenGLQtViewer::CreateGLQtContext (
125)
126//////////////////////////////////////////////////////////////////////////////
127//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
128{
129  printf("G4OpenGLQtViewer::CreateGLQtContext \n");
130}
131
132//////////////////////////////////////////////////////////////////////////////
133void G4OpenGLQtViewer::CreateMainWindow (
134)
135//////////////////////////////////////////////////////////////////////////////
136//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
137{
138
139  if(fWindow) return; //Done.
140  printf("G4OpenGLQtViewer::CreateMainWindow 2\n");
141
142  // launch Qt if not
143  G4Qt* interactorManager = G4Qt::getInstance ();
144  //  G4UImanager* UI = G4UImanager::GetUIpointer();
145  printf("G4OpenGLQtViewer::CreateMainWindow 3\n");
146
147  QPushButton hello("Hello world!");
148  hello.resize(100, 30);
149  hello.show();
150
151  fWindow = new QGLWidget() ;
152  fWindow->makeCurrent();
153
154  // create window
155  QDialog* GLWindow ;
156  if (qApp) {
157    GLWindow = new QDialog();//qApp->mainWidget());
158  } else {
159    GLWindow = new QDialog();
160  }
161
162  QHBoxLayout *mainLayout = new QHBoxLayout;
163  mainLayout->addWidget(fWindow);
164  GLWindow->setLayout(mainLayout);
165  GLWindow->setWindowTitle("QGl Viewer");
166  GLWindow->resize(100, 30);
167  GLWindow->show();
168
169
170//   // Bill Gates stuff...
171//   static const char className[] = "G4OpenGLQt";
172//   static bool done = false;
173//   if(done==false) {
174//     WNDCLASS wc;
175//     wc.style = CS_HREDRAW | CS_VREDRAW;
176//     wc.lpfnWndProc = (WNDPROC)WindowProc;
177//     wc.cbClsExtra = 0;
178//     wc.cbWndExtra = 0;
179//     wc.hInstance = ::GetModuleHandle(NULL);
180//     wc.hIcon = LoadIcon  (NULL, IDI_APPLICATION);
181//     wc.hCursor = LoadCursor(NULL,IDC_CROSS);
182//     wc.hbrBackground = NULL;
183//     wc.lpszMenuName = className;
184//     wc.lpszClassName = className;
185//     ::RegisterClass(&wc);
186//     done = true;
187//   } 
188 
189   WinSize_x = 400;
190   WinSize_y = 400;
191   if (WinSize_x < fVP.GetWindowSizeHintX ())
192     WinSize_x = fVP.GetWindowSizeHintX ();
193   if (WinSize_y < fVP.GetWindowSizeHintY ())
194     WinSize_y = fVP.GetWindowSizeHintY ();
195
196//   fWindow = ::CreateWindow(className,fName.c_str(),
197//                         WS_OVERLAPPEDWINDOW,
198//                         //WS_CHILD | WS_VISIBLE,
199//                         0,0,
200//                         WinSize_x,WinSize_y,
201//                         NULL, NULL,
202//                         ::GetModuleHandle(NULL),
203//                         NULL);
204//   if(!fWindow) return;
205
206//   ::SetWindowLong(fWindow,GWL_USERDATA,LONG(this));
207
208//   // initialize OpenGL rendering :
209//   fHDC = ::GetDC(fWindow);
210//   if( fHDC && (SetWindowPixelFormat(fHDC)==TRUE) ) {
211//     fHGLRC = ::wglCreateContext(fHDC);
212//   }
213 
214//   if(fHDC && fHGLRC) {
215//     ::wglMakeCurrent(fHDC,fHGLRC);
216//   }
217
218//   ::SetForegroundWindow(fWindow);
219//   ::ShowWindow(fWindow,SW_SHOWDEFAULT);
220//   ::UpdateWindow(fWindow);
221//   ::DrawMenuBar(fWindow);
222}
223
224//////////////////////////////////////////////////////////////////////////////
225void G4OpenGLQtViewer::CreateMainWindow (
226QGLWidget* glWidget
227)
228//////////////////////////////////////////////////////////////////////////////
229//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
230{
231
232  if(fWindow) return; //Done.
233  printf("G4OpenGLQtViewer::CreateMainWindow glWidget\n");
234
235  // launch Qt if not
236  G4Qt* interactorManager = G4Qt::getInstance ();
237  //  G4UImanager* UI = G4UImanager::GetUIpointer();
238  printf("G4OpenGLQtViewer::CreateMainWindow 3\n");
239
240  fWindow = glWidget ;
241  fWindow->makeCurrent();
242
243  // create window
244  QDialog* GLWindow ;
245  if (qApp) {
246    GLWindow = new QDialog();//qApp->mainWidget());
247  } else {
248    GLWindow = new QDialog();
249  }
250
251  QHBoxLayout *mainLayout = new QHBoxLayout;
252  mainLayout->addWidget(fWindow);
253  GLWindow->setLayout(mainLayout);
254  GLWindow->setWindowTitle("QGl Viewer");
255  GLWindow->resize(300, 300);
256  GLWindow->show();
257
258
259//   // Bill Gates stuff...
260//   static const char className[] = "G4OpenGLQt";
261//   static bool done = false;
262//   if(done==false) {
263//     WNDCLASS wc;
264//     wc.style = CS_HREDRAW | CS_VREDRAW;
265//     wc.lpfnWndProc = (WNDPROC)WindowProc;
266//     wc.cbClsExtra = 0;
267//     wc.cbWndExtra = 0;
268//     wc.hInstance = ::GetModuleHandle(NULL);
269//     wc.hIcon = LoadIcon  (NULL, IDI_APPLICATION);
270//     wc.hCursor = LoadCursor(NULL,IDC_CROSS);
271//     wc.hbrBackground = NULL;
272//     wc.lpszMenuName = className;
273//     wc.lpszClassName = className;
274//     ::RegisterClass(&wc);
275//     done = true;
276//   } 
277 
278   WinSize_x = 400;
279   WinSize_y = 400;
280   if (WinSize_x < fVP.GetWindowSizeHintX ())
281     WinSize_x = fVP.GetWindowSizeHintX ();
282   if (WinSize_y < fVP.GetWindowSizeHintY ())
283     WinSize_y = fVP.GetWindowSizeHintY ();
284
285//   fWindow = ::CreateWindow(className,fName.c_str(),
286//                         WS_OVERLAPPEDWINDOW,
287//                         //WS_CHILD | WS_VISIBLE,
288//                         0,0,
289//                         WinSize_x,WinSize_y,
290//                         NULL, NULL,
291//                         ::GetModuleHandle(NULL),
292//                         NULL);
293//   if(!fWindow) return;
294
295//   ::SetWindowLong(fWindow,GWL_USERDATA,LONG(this));
296
297//   // initialize OpenGL rendering :
298//   fHDC = ::GetDC(fWindow);
299//   if( fHDC && (SetWindowPixelFormat(fHDC)==TRUE) ) {
300//     fHGLRC = ::wglCreateContext(fHDC);
301//   }
302 
303//   if(fHDC && fHGLRC) {
304//     ::wglMakeCurrent(fHDC,fHGLRC);
305//   }
306
307//   ::SetForegroundWindow(fWindow);
308//   ::ShowWindow(fWindow,SW_SHOWDEFAULT);
309//   ::UpdateWindow(fWindow);
310//   ::DrawMenuBar(fWindow);
311}
312
313//////////////////////////////////////////////////////////////////////////////
314G4OpenGLQtViewer::G4OpenGLQtViewer (
315 G4OpenGLSceneHandler& scene
316)
317:G4VViewer (scene, -1)
318,G4OpenGLViewer (scene)
319,fWindow(0)
320                                   //,fHDC(0)
321                                   //,fHGLRC(0)
322//////////////////////////////////////////////////////////////////////////////
323//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
324{
325  printf("G4OpenGLQtViewer::G4OpenGLQtViewer \n");
326}
327
328//////////////////////////////////////////////////////////////////////////////
329G4OpenGLQtViewer::~G4OpenGLQtViewer (
330)
331//////////////////////////////////////////////////////////////////////////////
332//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
333{
334  printf("G4OpenGLQtViewer::~G4OpenGLQtViewer \n");
335//   // This is the end (Jim Morisson).
336//   if (fViewId >= 0) {
337//     if(wglGetCurrentContext()!=NULL) wglMakeCurrent(NULL,NULL);
338//     if(fHGLRC)       {
339//       wglDeleteContext(fHGLRC);
340//       fHGLRC = NULL;
341//     }
342   
343//     if(fWindow) {
344//       ::SetWindowLong(fWindow,GWL_USERDATA,LONG(NULL));
345//       if(fHDC) ::ReleaseDC(fWindow,fHDC);
346//       ::DestroyWindow(fWindow);
347//     }
348//   }
349}
350
351// //////////////////////////////////////////////////////////////////////////////
352// LRESULT CALLBACK G4OpenGLQtViewer::WindowProc (
353//  HWND   aWindow
354// ,UINT   aMessage
355// ,WPARAM aWParam
356// ,LPARAM aLParam
357// )
358// //////////////////////////////////////////////////////////////////////////////
359// //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
360// {
361/*
362  switch (aMessage) {
363  case WM_PAINT:{
364    printf("debug : PAINT\n");
365    HDC hDC;
366    PAINTSTRUCT ps;
367    hDC = BeginPaint(aWindow,&ps);
368    if(This) {
369      // FIXME : To have an automatic refresh someone have to redraw here.
370    }
371    EndPaint(aWindow, &ps);
372
373    //FIXME : have to handle WM_RESIZE
374    //pView->WinSize_x = (G4int) width;
375    //pView->WinSize_y = (G4int) height;
376    G4OpenGLQtViewer* This =
377      (G4OpenGLQtViewer*)::GetWindowLong(aWindow,GWL_USERDATA);
378    if(This) {
379      This->SetView();
380      glViewport(0,0,This->WinSize_x,This->WinSize_y);
381      This->ClearView();
382      This->DrawView();
383      // WARNING : the below empty the Windows message queue...
384      This->FinishView();
385    }
386  } return 0;
387  default:
388    return DefWindowProc(aWindow,aMessage,aWParam,aLParam);
389  }
390*/
391//   return DefWindowProc(aWindow,aMessage,aWParam,aLParam);
392// }
393
394// //////////////////////////////////////////////////////////////////////////////
395// bool G4OpenGLQtViewer::SetWindowPixelFormat(
396//  HDC aHdc
397// )
398// //////////////////////////////////////////////////////////////////////////////
399// //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
400// {
401//   // The ungessable...
402
403//   PIXELFORMATDESCRIPTOR pfd;
404//   pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
405//   pfd.nVersion = 1;
406//   pfd.dwFlags =
407//     PFD_DRAW_TO_WINDOW |
408//     PFD_SUPPORT_OPENGL |
409//     PFD_DOUBLEBUFFER |
410//     PFD_STEREO_DONTCARE; 
411//   pfd.iPixelType = PFD_TYPE_RGBA;
412//   pfd.cColorBits = 32;
413//   pfd.cRedBits = 8;
414//   pfd.cRedShift = 16;
415//   pfd.cGreenBits = 8;
416//   pfd.cGreenShift = 8;
417//   pfd.cBlueBits      = 8;
418//   pfd.cBlueShift = 0;
419//   pfd.cAlphaBits = 0;
420//   pfd.cAlphaShift = 0;
421//   pfd.cAccumBits = 64;       
422//   pfd.cAccumRedBits = 16;
423//   pfd.cAccumGreenBits = 16;
424//   pfd.cAccumBlueBits = 16;
425//   pfd.cAccumAlphaBits = 0;
426//   pfd.cDepthBits = 32;
427//   pfd.cStencilBits = 8;
428//   pfd.cAuxBuffers = 0;
429//   pfd.iLayerType = PFD_MAIN_PLANE;
430//   pfd.bReserved      = 0;
431//   pfd.dwLayerMask = 0;
432//   pfd.dwVisibleMask = 0;
433//   pfd.dwDamageMask = 0;
434 
435//   int pixelIndex = ::ChoosePixelFormat(aHdc,&pfd);
436//   if (pixelIndex==0) {
437//     pixelIndex = 1; 
438//     if (::DescribePixelFormat(aHdc,
439//                            pixelIndex,
440//                            sizeof(PIXELFORMATDESCRIPTOR),
441//                            &pfd)==0) {
442//       return false;
443//     }
444//   }
445//   if (::SetPixelFormat(aHdc,pixelIndex,&pfd)==FALSE) return false;
446//  return true;
447//}
448
449
450#endif
Note: See TracBrowser for help on using the repository browser.