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

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

r708@mac-90108: laurentgarnier | 2007-07-11 12:47:09 +0200
pas mal, sauf que le gun ne fait aucun effet

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