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

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

r689@mac-90108: laurentgarnier | 2007-07-09 18:33:54 +0200
visu OpenGL en cours de debug NE MARCHE PAS

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