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

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

r684@mac-90108: laurentgarnier | 2007-07-05 18:31:37 +0200
mise a jour de la visu OpenGl. Ne marche pas encore

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