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

Last change on this file since 541 was 541, checked in by garnier, 18 years ago

r686@mac-90108: laurentgarnier | 2007-07-06 15:07:30 +0200
mise a jour de la visu OpenGl. Ne marche pas encore

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