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 | #include "G4Scene.hh" |
---|
47 | |
---|
48 | #include "G4Qt.hh" |
---|
49 | #include "G4UIManager.hh" |
---|
50 | #include <QtGui/qboxlayout.h> |
---|
51 | #include <QtGui/qdialog.h> |
---|
52 | #include <QtGui/qmenu.h> |
---|
53 | |
---|
54 | ////////////////////////////////////////////////////////////////////////////// |
---|
55 | /** |
---|
56 | Implementation of virtual method of G4VViewer |
---|
57 | */ |
---|
58 | void G4OpenGLQtViewer::SetView ( |
---|
59 | ) |
---|
60 | ////////////////////////////////////////////////////////////////////////////// |
---|
61 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
62 | { |
---|
63 | printf("G4OpenGLQtViewer::SetView ++++++++++++++++++++\n"); |
---|
64 | // if(!fHDC) return; |
---|
65 | // if(!fHGLRC) return; |
---|
66 | // ::wglMakeCurrent(fHDC,fHGLRC); |
---|
67 | // fWindow->makeCurrent(); |
---|
68 | G4OpenGLViewer::SetView (); |
---|
69 | printf("G4OpenGLQtViewer::SetView --------------------\n"); |
---|
70 | } |
---|
71 | |
---|
72 | |
---|
73 | |
---|
74 | ////////////////////////////////////////////////////////////////////////////// |
---|
75 | /** |
---|
76 | Implementation of virtual method of G4VViewer |
---|
77 | */ |
---|
78 | void G4OpenGLQtViewer::ShowView ( |
---|
79 | ) |
---|
80 | ////////////////////////////////////////////////////////////////////////////// |
---|
81 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
82 | { |
---|
83 | printf("G4OpenGLQtViewer::ShowView +++++++++++++++++++++\n"); |
---|
84 | // if(!fHDC) return; |
---|
85 | // fWindow->resize(100, 300); |
---|
86 | glFlush (); |
---|
87 | printf("G4OpenGLQtViewer::ShowView -----------------------\n"); |
---|
88 | |
---|
89 | // // Empty the Windows message queue : |
---|
90 | // MSG event; |
---|
91 | // while ( ::PeekMessage(&event, NULL, 0, 0, PM_REMOVE) ) { |
---|
92 | // ::TranslateMessage(&event); |
---|
93 | // ::DispatchMessage (&event); |
---|
94 | // } |
---|
95 | } |
---|
96 | |
---|
97 | |
---|
98 | |
---|
99 | ////////////////////////////////////////////////////////////////////////////// |
---|
100 | void G4OpenGLQtViewer::CreateGLQtContext ( |
---|
101 | ) |
---|
102 | ////////////////////////////////////////////////////////////////////////////// |
---|
103 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
104 | { |
---|
105 | printf("G4OpenGLQtViewer::CreateGLQtContext \n"); |
---|
106 | } |
---|
107 | |
---|
108 | |
---|
109 | ////////////////////////////////////////////////////////////////////////////// |
---|
110 | void G4OpenGLQtViewer::CreateMainWindow ( |
---|
111 | QGLWidget* glWidget |
---|
112 | ) |
---|
113 | ////////////////////////////////////////////////////////////////////////////// |
---|
114 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
115 | { |
---|
116 | |
---|
117 | if(fWindow) return; //Done. |
---|
118 | printf("G4OpenGLQtViewer::CreateMainWindow glWidget\n"); |
---|
119 | |
---|
120 | // launch Qt if not |
---|
121 | G4Qt* interactorManager = G4Qt::getInstance (); |
---|
122 | // G4UImanager* UI = G4UImanager::GetUIpointer(); |
---|
123 | |
---|
124 | fWindow = glWidget ; |
---|
125 | // fWindow->makeCurrent(); |
---|
126 | |
---|
127 | // create window |
---|
128 | if (qApp) { |
---|
129 | GLWindow = new QDialog();//qApp->mainWidget()); |
---|
130 | } else { |
---|
131 | GLWindow = new QDialog(); |
---|
132 | } |
---|
133 | |
---|
134 | QHBoxLayout *mainLayout = new QHBoxLayout; |
---|
135 | |
---|
136 | mainLayout->addWidget(fWindow); |
---|
137 | GLWindow->setLayout(mainLayout); |
---|
138 | GLWindow->setWindowTitle("QGl Viewer"); |
---|
139 | GLWindow->resize(300, 300); |
---|
140 | GLWindow->show(); |
---|
141 | |
---|
142 | WinSize_x = 400; |
---|
143 | WinSize_y = 400; |
---|
144 | if (WinSize_x < fVP.GetWindowSizeHintX ()) |
---|
145 | WinSize_x = fVP.GetWindowSizeHintX (); |
---|
146 | if (WinSize_y < fVP.GetWindowSizeHintY ()) |
---|
147 | WinSize_y = fVP.GetWindowSizeHintY (); |
---|
148 | |
---|
149 | if(!fWindow) return; |
---|
150 | printf("G4OpenGLQtViewer::CreateMainWindow glWidget END\n"); |
---|
151 | |
---|
152 | } |
---|
153 | |
---|
154 | ////////////////////////////////////////////////////////////////////////////// |
---|
155 | G4OpenGLQtViewer::G4OpenGLQtViewer ( |
---|
156 | G4OpenGLSceneHandler& scene |
---|
157 | ) |
---|
158 | :G4VViewer (scene, -1) |
---|
159 | ,G4OpenGLViewer (scene) |
---|
160 | ,fWindow(0) |
---|
161 | ,fContextMenu(0) |
---|
162 | ,fMouseAction(true) |
---|
163 | //,fHDC(0) |
---|
164 | //,fHGLRC(0) |
---|
165 | ////////////////////////////////////////////////////////////////////////////// |
---|
166 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
167 | { |
---|
168 | printf("G4OpenGLQtViewer::G4OpenGLQtViewer \n"); |
---|
169 | } |
---|
170 | |
---|
171 | ////////////////////////////////////////////////////////////////////////////// |
---|
172 | G4OpenGLQtViewer::~G4OpenGLQtViewer ( |
---|
173 | ) |
---|
174 | ////////////////////////////////////////////////////////////////////////////// |
---|
175 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
176 | { |
---|
177 | printf("G4OpenGLQtViewer::~G4OpenGLQtViewer \n"); |
---|
178 | delete fContextMenu; |
---|
179 | |
---|
180 | // // This is the end (Jim Morisson). |
---|
181 | // if (fViewId >= 0) { |
---|
182 | // if(wglGetCurrentContext()!=NULL) wglMakeCurrent(NULL,NULL); |
---|
183 | // if(fHGLRC) { |
---|
184 | // wglDeleteContext(fHGLRC); |
---|
185 | // fHGLRC = NULL; |
---|
186 | // } |
---|
187 | |
---|
188 | // if(fWindow) { |
---|
189 | // ::SetWindowLong(fWindow,GWL_USERDATA,LONG(NULL)); |
---|
190 | // if(fHDC) ::ReleaseDC(fWindow,fHDC); |
---|
191 | // ::DestroyWindow(fWindow); |
---|
192 | // } |
---|
193 | // } |
---|
194 | } |
---|
195 | |
---|
196 | |
---|
197 | void G4OpenGLQtViewer::createPopupMenu() { |
---|
198 | |
---|
199 | fContextMenu = new QMenu("All"); |
---|
200 | |
---|
201 | QMenu *mMouseAction = fContextMenu->addMenu("&Mouse action"); |
---|
202 | QAction *rotate = mMouseAction->addAction("&Rotate scene"); |
---|
203 | QAction *move = mMouseAction->addAction("&Move scene"); |
---|
204 | // INIT mMouse |
---|
205 | createRadioAction(rotate,move,SLOT(toggleMouseAction(bool)),1); |
---|
206 | |
---|
207 | //Style Menu |
---|
208 | QMenu *mStyle = fContextMenu->addMenu("&Style"); |
---|
209 | |
---|
210 | QMenu *mRepresentation = mStyle->addMenu("&Representation"); |
---|
211 | QAction *polyhedron = mRepresentation->addAction("Polyhedron"); |
---|
212 | QAction *nurbs = mRepresentation->addAction("NURBS"); |
---|
213 | // INIT mStyle |
---|
214 | G4ViewParameters::RepStyle style; |
---|
215 | style = fVP.GetRepStyle(); |
---|
216 | if (style == G4ViewParameters::polyhedron) { |
---|
217 | createRadioAction(polyhedron,nurbs,SLOT(toggleRepresentation(bool)),1); |
---|
218 | } else if (style == G4ViewParameters::nurbs) { |
---|
219 | createRadioAction(polyhedron,nurbs,SLOT(toggleRepresentation(bool)),2); |
---|
220 | } else { |
---|
221 | mRepresentation->clear(); |
---|
222 | } |
---|
223 | |
---|
224 | |
---|
225 | QMenu *mDrawing = mStyle->addMenu("&Drawing"); |
---|
226 | fDrawingWireframe = mDrawing->addAction("Wireframe"); |
---|
227 | fDrawingWireframe->setCheckable(true); |
---|
228 | fDrawingWireframe->setChecked(true); |
---|
229 | fDrawingLineRemoval = mDrawing->addAction("Hidden line removal"); |
---|
230 | fDrawingLineRemoval->setCheckable(true); |
---|
231 | fDrawingSurfaceRemoval = mDrawing->addAction("Hidden Surface removal"); |
---|
232 | fDrawingSurfaceRemoval->setCheckable(true); |
---|
233 | fDrawingLineSurfaceRemoval = mDrawing->addAction("Hidden line and surface removal"); |
---|
234 | fDrawingLineSurfaceRemoval->setCheckable(true); |
---|
235 | // INIT Drawing |
---|
236 | G4ViewParameters::DrawingStyle d_style; |
---|
237 | d_style = fVP.GetDrawingStyle(); |
---|
238 | |
---|
239 | fDrawingWireframe->setCheckable(true); |
---|
240 | fDrawingLineRemoval->setCheckable(true); |
---|
241 | fDrawingSurfaceRemoval->setCheckable(true); |
---|
242 | fDrawingLineSurfaceRemoval->setCheckable(true); |
---|
243 | |
---|
244 | if (d_style == G4ViewParameters::wireframe) { |
---|
245 | fDrawingWireframe->setChecked(true); |
---|
246 | } else if (d_style == G4ViewParameters::hlr) { |
---|
247 | fDrawingLineRemoval->setChecked(true); |
---|
248 | } else if (d_style == G4ViewParameters::hsr) { |
---|
249 | fDrawingSurfaceRemoval->setChecked(true); |
---|
250 | } else if (d_style == G4ViewParameters::hlhsr) { |
---|
251 | fDrawingLineSurfaceRemoval->setChecked(true); |
---|
252 | } else { |
---|
253 | mDrawing->clear(); |
---|
254 | } |
---|
255 | |
---|
256 | QObject ::connect(fDrawingWireframe, SIGNAL(triggered(bool)),this, SLOT(actionDrawingWireframe())); |
---|
257 | QObject ::connect(fDrawingLineRemoval, SIGNAL(triggered(bool)),this, SLOT(actionDrawingLineRemoval())); |
---|
258 | QObject ::connect(fDrawingSurfaceRemoval, SIGNAL(triggered(bool)),this, SLOT(actionDrawingSurfaceRemoval())); |
---|
259 | QObject ::connect(fDrawingLineSurfaceRemoval, SIGNAL(triggered(bool)),this, SLOT(actionDrawingLineSurfaceRemoval())); |
---|
260 | |
---|
261 | |
---|
262 | QMenu *mBackground = mStyle->addMenu("&Background color"); |
---|
263 | QAction *white = mBackground->addAction("White"); |
---|
264 | QAction *black = mBackground->addAction("Black"); |
---|
265 | if (background.GetRed() == 1. && |
---|
266 | background.GetGreen() == 1. && |
---|
267 | background.GetBlue() == 1.) { |
---|
268 | createRadioAction(white,black,SLOT(toggleBackground(bool)),1); |
---|
269 | } else { |
---|
270 | createRadioAction(white,black,SLOT(toggleBackground(bool)),2); |
---|
271 | } |
---|
272 | |
---|
273 | |
---|
274 | // Action Menu |
---|
275 | QMenu *mActions = fContextMenu->addMenu("&Actions"); |
---|
276 | QAction *rotation = mActions->addAction("Rotation control panel"); |
---|
277 | QAction *panning = mActions->addAction("Panning control panel"); |
---|
278 | QAction *setControl = mActions->addAction("Set control panel limits"); |
---|
279 | |
---|
280 | // Miscellany Menu |
---|
281 | QMenu * mMisc = fContextMenu->addMenu("&Miscellany"); |
---|
282 | QAction *miscellany = mMisc->addAction("Miscellany control panel"); |
---|
283 | QAction *exitG4 = mMisc->addAction("Exit to G4Vis >"); |
---|
284 | QAction *createEPS = mMisc->addAction("Create .eps file"); |
---|
285 | |
---|
286 | // Special Menu |
---|
287 | QMenu *mSpecial = fContextMenu->addMenu("S&pecial"); |
---|
288 | QMenu *transparency = mSpecial->addMenu("Transparency"); |
---|
289 | QAction *transparencyOn = transparency->addAction("On"); |
---|
290 | QAction *transparencyOff = transparency->addAction("Off"); |
---|
291 | if (transparency_enabled == false) { |
---|
292 | createRadioAction(transparencyOn,transparencyOff,SLOT(toggleTransparency(bool)),2); |
---|
293 | } else if (transparency_enabled == true) { |
---|
294 | createRadioAction(transparencyOn,transparencyOff,SLOT(toggleTransparency(bool)),1); |
---|
295 | } else { |
---|
296 | mSpecial->clear(); |
---|
297 | } |
---|
298 | |
---|
299 | |
---|
300 | QMenu *mAntialiasing = mSpecial->addMenu("Antialiasing"); |
---|
301 | QAction *antialiasingOn = mAntialiasing->addAction("On"); |
---|
302 | QAction *antialiasingOff = mAntialiasing->addAction("Off"); |
---|
303 | if (antialiasing_enabled == false) { |
---|
304 | createRadioAction(antialiasingOn,antialiasingOff,SLOT(toggleAntialiasing(bool)),2); |
---|
305 | } else if (antialiasing_enabled == true) { |
---|
306 | createRadioAction(antialiasingOn,antialiasingOff,SLOT(toggleAntialiasing(bool)),1); |
---|
307 | } else { |
---|
308 | mAntialiasing->clear(); |
---|
309 | } |
---|
310 | |
---|
311 | QMenu *mHaloing = mSpecial->addMenu("Haloing"); |
---|
312 | QAction *haloingOn = mHaloing->addAction("On"); |
---|
313 | QAction *haloingOff = mHaloing->addAction("Off"); |
---|
314 | if (haloing_enabled == false) { |
---|
315 | createRadioAction(haloingOn,haloingOff,SLOT(toggleHaloing(bool)),2); |
---|
316 | } else if (haloing_enabled == true) { |
---|
317 | createRadioAction(haloingOn,haloingOff,SLOT(toggleHaloing(bool)),1); |
---|
318 | } else { |
---|
319 | mHaloing->clear(); |
---|
320 | } |
---|
321 | |
---|
322 | QMenu *mAux = mSpecial->addMenu("Auxiliary edges"); |
---|
323 | QAction *auxOn = mAux->addAction("On"); |
---|
324 | QAction *auxOff = mAux->addAction("Off"); |
---|
325 | if (!fVP.IsAuxEdgeVisible()) { |
---|
326 | createRadioAction(auxOn,auxOff,SLOT(toggleAux(bool)),1); |
---|
327 | } else { |
---|
328 | createRadioAction(auxOn,auxOff,SLOT(toggleAux(bool)),2); |
---|
329 | } |
---|
330 | |
---|
331 | |
---|
332 | QMenu *mFullScreen = mSpecial->addMenu("Full screen"); |
---|
333 | QAction *fullOn = mFullScreen->addAction("On"); |
---|
334 | QAction *fullOff = mFullScreen->addAction("Off"); |
---|
335 | createRadioAction(fullOn,fullOff,SLOT(toggleFullScreen(bool)),2); |
---|
336 | |
---|
337 | } |
---|
338 | |
---|
339 | void G4OpenGLQtViewer::manageContextMenuEvent(QContextMenuEvent *e) |
---|
340 | { |
---|
341 | if (!GLWindow) return; |
---|
342 | |
---|
343 | if (!fContextMenu) |
---|
344 | createPopupMenu(); |
---|
345 | |
---|
346 | // launch menu |
---|
347 | if ( fContextMenu ) { |
---|
348 | fContextMenu->exec( e->globalPos() ); |
---|
349 | // delete fContextMenu; |
---|
350 | } |
---|
351 | e->accept(); |
---|
352 | } |
---|
353 | |
---|
354 | |
---|
355 | /** |
---|
356 | Create a radio button menu. The two menu will be connected. When click on one, |
---|
357 | eatch state will be invert and callback method will be called. |
---|
358 | @param action1 first action to connect |
---|
359 | @param action2 second action to connect |
---|
360 | @method callback method |
---|
361 | @nCheck 1: first action xill be set true. 2 : second action will be set true |
---|
362 | */ |
---|
363 | void G4OpenGLQtViewer::createRadioAction(QAction *action1,QAction *action2, const std::string& method,unsigned int nCheck) { |
---|
364 | |
---|
365 | action1->setCheckable(true); |
---|
366 | action2->setCheckable(true); |
---|
367 | |
---|
368 | if (nCheck ==1) |
---|
369 | action1->setChecked (true); |
---|
370 | else |
---|
371 | action2->setChecked (true); |
---|
372 | |
---|
373 | QObject ::connect(action1, SIGNAL(triggered(bool)),action2, SLOT(toggle())); |
---|
374 | QObject ::connect(action2, SIGNAL(triggered(bool)),action1, SLOT(toggle())); |
---|
375 | |
---|
376 | QObject ::connect(action1, SIGNAL(toggled(bool)),this, method.c_str()); |
---|
377 | |
---|
378 | } |
---|
379 | |
---|
380 | void G4OpenGLQtViewer::actionDrawingWireframe() { |
---|
381 | emit toggleDrawingAction(1); |
---|
382 | } |
---|
383 | void G4OpenGLQtViewer::actionDrawingLineRemoval() { |
---|
384 | emit toggleDrawingAction(2); |
---|
385 | } |
---|
386 | void G4OpenGLQtViewer::actionDrawingSurfaceRemoval() { |
---|
387 | emit toggleDrawingAction(3); |
---|
388 | } |
---|
389 | void G4OpenGLQtViewer::actionDrawingLineSurfaceRemoval() { |
---|
390 | emit toggleDrawingAction(4); |
---|
391 | } |
---|
392 | |
---|
393 | |
---|
394 | |
---|
395 | void G4OpenGLQtViewer::toggleDrawingAction(int aAction) { |
---|
396 | |
---|
397 | G4ViewParameters::DrawingStyle d_style; |
---|
398 | |
---|
399 | |
---|
400 | if (aAction ==1) { |
---|
401 | fDrawingWireframe->setChecked (true); |
---|
402 | fDrawingLineRemoval->setChecked (false); |
---|
403 | fDrawingSurfaceRemoval->setChecked (false); |
---|
404 | fDrawingLineSurfaceRemoval->setChecked (false); |
---|
405 | |
---|
406 | d_style = G4ViewParameters::wireframe; |
---|
407 | |
---|
408 | } else if (aAction ==2) { |
---|
409 | fDrawingWireframe->setChecked (false); |
---|
410 | fDrawingLineRemoval->setChecked (true); |
---|
411 | fDrawingSurfaceRemoval->setChecked (false); |
---|
412 | fDrawingLineSurfaceRemoval->setChecked (false); |
---|
413 | |
---|
414 | d_style = G4ViewParameters::hlr; |
---|
415 | |
---|
416 | } else if (aAction ==3) { |
---|
417 | fDrawingWireframe->setChecked (false); |
---|
418 | fDrawingLineRemoval->setChecked (false); |
---|
419 | fDrawingSurfaceRemoval->setChecked (true); |
---|
420 | fDrawingLineSurfaceRemoval->setChecked (false); |
---|
421 | |
---|
422 | d_style = G4ViewParameters::hsr; |
---|
423 | |
---|
424 | } else if (aAction ==4) { |
---|
425 | fDrawingWireframe->setChecked (false); |
---|
426 | fDrawingLineRemoval->setChecked (false); |
---|
427 | fDrawingSurfaceRemoval->setChecked (false); |
---|
428 | fDrawingLineSurfaceRemoval->setChecked (true); |
---|
429 | |
---|
430 | d_style = G4ViewParameters::hlhsr; |
---|
431 | } |
---|
432 | fVP.SetDrawingStyle(d_style); |
---|
433 | |
---|
434 | updateQWidget(); |
---|
435 | printf("G4OpenGLQtViewer::toggleDrawingAction\n"); |
---|
436 | } |
---|
437 | |
---|
438 | |
---|
439 | /** |
---|
440 | SLOT Activate by a click on the representation menu |
---|
441 | |
---|
442 | */ |
---|
443 | void G4OpenGLQtViewer::toggleRepresentation(bool check) { |
---|
444 | |
---|
445 | G4ViewParameters::RepStyle style; |
---|
446 | if (check == 1) { |
---|
447 | style = G4ViewParameters::polyhedron; |
---|
448 | } else { |
---|
449 | style = G4ViewParameters::nurbs; |
---|
450 | } |
---|
451 | fVP.SetRepStyle (style); |
---|
452 | |
---|
453 | printf("G4OpenGLQtViewer::toggleRepresentation 3%d\n",check); |
---|
454 | updateQWidget(); |
---|
455 | printf("G4OpenGLQtViewer::toggleRepresentation 4%d\n",check); |
---|
456 | |
---|
457 | } |
---|
458 | void G4OpenGLQtViewer::toggleBackground(bool check) { |
---|
459 | |
---|
460 | // //I need to revisit the kernel if the background colour changes and |
---|
461 | // //hidden line removal is enabled, because hlr drawing utilises the |
---|
462 | // //background colour in its drawing... |
---|
463 | // // (Note added by JA 13/9/2005) Background now handled in view |
---|
464 | // // parameters. A kernel visit is triggered on change of background. |
---|
465 | if (check == 1) { |
---|
466 | ((G4ViewParameters&)this->GetViewParameters()). |
---|
467 | SetBackgroundColour(G4Colour(1.,1.,1.)); // White |
---|
468 | } else { |
---|
469 | ((G4ViewParameters&)this->GetViewParameters()). |
---|
470 | SetBackgroundColour(G4Colour(0.,0.,0.)); // Black |
---|
471 | } |
---|
472 | updateQWidget(); |
---|
473 | } |
---|
474 | |
---|
475 | void G4OpenGLQtViewer::toggleTransparency(bool check) { |
---|
476 | |
---|
477 | if (check) { |
---|
478 | transparency_enabled = false; |
---|
479 | } else { |
---|
480 | transparency_enabled = true; |
---|
481 | } |
---|
482 | SetNeedKernelVisit (true); |
---|
483 | updateQWidget(); |
---|
484 | } |
---|
485 | |
---|
486 | void G4OpenGLQtViewer::toggleAntialiasing(bool check) { |
---|
487 | |
---|
488 | if (!check) { |
---|
489 | antialiasing_enabled = false; |
---|
490 | glDisable (GL_LINE_SMOOTH); |
---|
491 | glDisable (GL_POLYGON_SMOOTH); |
---|
492 | } else { |
---|
493 | antialiasing_enabled = true; |
---|
494 | glEnable (GL_LINE_SMOOTH); |
---|
495 | glHint (GL_LINE_SMOOTH_HINT, GL_NICEST); |
---|
496 | glEnable (GL_POLYGON_SMOOTH); |
---|
497 | glHint (GL_POLYGON_SMOOTH_HINT, GL_NICEST); |
---|
498 | } |
---|
499 | |
---|
500 | updateQWidget(); |
---|
501 | // pView->SetView (); |
---|
502 | // pView->ClearView (); |
---|
503 | // pView->DrawView (); |
---|
504 | |
---|
505 | printf("G4OpenGLQtViewer::toggleRepresentation %d\n",check); |
---|
506 | } |
---|
507 | |
---|
508 | //FIXME : I SEE NOTHING... |
---|
509 | void G4OpenGLQtViewer::toggleHaloing(bool check) { |
---|
510 | if (check) { |
---|
511 | haloing_enabled = false; |
---|
512 | } else { |
---|
513 | haloing_enabled = true; |
---|
514 | } |
---|
515 | |
---|
516 | updateQWidget(); |
---|
517 | |
---|
518 | printf("G4OpenGLQtViewer::toggleRepresentation %d\n",check); |
---|
519 | } |
---|
520 | void G4OpenGLQtViewer::toggleAux(bool check) { |
---|
521 | if (check) { |
---|
522 | fVP.SetAuxEdgeVisible(false); |
---|
523 | } else { |
---|
524 | fVP.SetAuxEdgeVisible(true); |
---|
525 | } |
---|
526 | SetNeedKernelVisit (true); |
---|
527 | updateQWidget(); |
---|
528 | |
---|
529 | printf("G4OpenGLQtViewer::toggleRepresentation %d\n",check); |
---|
530 | } |
---|
531 | void G4OpenGLQtViewer::toggleFullScreen(bool check) { |
---|
532 | GLWindow->setWindowState(GLWindow->windowState() ^ Qt::WindowFullScreen); |
---|
533 | |
---|
534 | printf("G4OpenGLQtViewer::toggleRepresentation %d\n",check); |
---|
535 | } |
---|
536 | |
---|
537 | void G4OpenGLQtViewer::toggleMouseAction(bool check) { |
---|
538 | if (check) { // rotate scene |
---|
539 | fMouseAction = true; |
---|
540 | } else { // move scene |
---|
541 | fMouseAction = false; |
---|
542 | } |
---|
543 | |
---|
544 | printf("G4OpenGLQtViewer::toggleRepresentation %d\n",check); |
---|
545 | } |
---|
546 | |
---|
547 | |
---|
548 | void G4OpenGLQtViewer::G4MousePressEvent(QPoint p) |
---|
549 | { |
---|
550 | lastPos = p; |
---|
551 | } |
---|
552 | |
---|
553 | void G4OpenGLQtViewer::G4MouseMoveEvent(int pos_x, int pos_y,Qt::MouseButtons mButtons) |
---|
554 | { |
---|
555 | int dx = pos_x - lastPos.x(); |
---|
556 | int dy = pos_y - lastPos.y(); |
---|
557 | |
---|
558 | if (fMouseAction) { // rotate |
---|
559 | if (mButtons & Qt::LeftButton) { |
---|
560 | //phi spin stuff here |
---|
561 | |
---|
562 | G4Vector3D vp = fVP.GetViewpointDirection ().unit (); |
---|
563 | G4Vector3D up = fVP.GetUpVector ().unit (); |
---|
564 | |
---|
565 | G4Vector3D yprime = (up.cross(vp)).unit(); |
---|
566 | G4Vector3D zprime = (vp.cross(yprime)).unit(); |
---|
567 | |
---|
568 | G4double delta_alpha; |
---|
569 | G4double delta_theta; |
---|
570 | |
---|
571 | if (fVP.GetLightsMoveWithCamera()) { |
---|
572 | delta_alpha = dy; |
---|
573 | delta_theta = -dx; |
---|
574 | } else { |
---|
575 | delta_alpha = -dy; |
---|
576 | delta_theta = dx; |
---|
577 | } |
---|
578 | |
---|
579 | delta_alpha *= deg; |
---|
580 | delta_theta *= deg; |
---|
581 | |
---|
582 | G4Vector3D new_vp = std::cos(delta_alpha) * vp + std::sin(delta_alpha) * zprime; |
---|
583 | |
---|
584 | G4Vector3D new_up; |
---|
585 | if (fVP.GetLightsMoveWithCamera()) { |
---|
586 | new_up = (new_vp.cross(yprime)).unit(); |
---|
587 | fVP.SetUpVector(new_up); |
---|
588 | } else { |
---|
589 | new_up = up; |
---|
590 | } |
---|
591 | //////////////// |
---|
592 | // Rotates by fixed azimuthal angle delta_theta. |
---|
593 | |
---|
594 | G4double cosalpha = new_up.dot (new_vp.unit()); |
---|
595 | G4double sinalpha = std::sqrt (1. - std::pow (cosalpha, 2)); |
---|
596 | yprime = (new_up.cross (new_vp.unit())).unit (); |
---|
597 | G4Vector3D xprime = yprime.cross (new_up); |
---|
598 | // Projection of vp on plane perpendicular to up... |
---|
599 | G4Vector3D a1 = sinalpha * xprime; |
---|
600 | // Required new projection... |
---|
601 | G4Vector3D a2 = |
---|
602 | sinalpha * (std::cos (delta_theta) * xprime + std::sin (delta_theta) * yprime); |
---|
603 | // Required Increment vector... |
---|
604 | G4Vector3D delta = a2 - a1; |
---|
605 | // So new viewpoint is... |
---|
606 | G4Vector3D viewPoint = new_vp.unit() + delta; |
---|
607 | |
---|
608 | fVP.SetViewAndLights (viewPoint); |
---|
609 | updateQWidget(); |
---|
610 | |
---|
611 | } else if (mButtons & Qt::RightButton) { |
---|
612 | // NEVER DONE BECAUSE OF MOUSE MENU |
---|
613 | // printf("G4OpenGLQtViewer::mouseMoveEvent Right \n"); |
---|
614 | // setXRotation(xRot + dy/2); |
---|
615 | // setZRotation(zRot + dx/2); |
---|
616 | // updateQWidget(); |
---|
617 | } |
---|
618 | } else { // move |
---|
619 | |
---|
620 | float dx = pos_x - lastPos.x(); |
---|
621 | float dy = pos_y - lastPos.y(); |
---|
622 | |
---|
623 | G4Point3D stp |
---|
624 | = GetSceneHandler()->GetScene()->GetStandardTargetPoint(); |
---|
625 | |
---|
626 | G4Point3D tp = stp + fVP.GetCurrentTargetPoint (); |
---|
627 | |
---|
628 | const G4Vector3D& upVector = fVP.GetUpVector (); |
---|
629 | const G4Vector3D& vpVector = fVP.GetViewpointDirection (); |
---|
630 | |
---|
631 | G4Vector3D unitRight = (upVector.cross (vpVector)).unit(); |
---|
632 | G4Vector3D unitUp = (vpVector.cross (unitRight)).unit(); |
---|
633 | |
---|
634 | tp += -dx * unitRight + dy * unitUp; |
---|
635 | fVP.SetCurrentTargetPoint (tp - stp); |
---|
636 | |
---|
637 | updateQWidget(); |
---|
638 | } |
---|
639 | lastPos = QPoint(pos_x, pos_y); |
---|
640 | } |
---|
641 | |
---|
642 | |
---|
643 | float G4OpenGLQtViewer::getXRot() |
---|
644 | { |
---|
645 | return xRot; |
---|
646 | } |
---|
647 | |
---|
648 | float G4OpenGLQtViewer::getYRot() |
---|
649 | { |
---|
650 | return yRot; |
---|
651 | } |
---|
652 | |
---|
653 | float G4OpenGLQtViewer::getZRot() |
---|
654 | { |
---|
655 | return zRot; |
---|
656 | } |
---|
657 | |
---|
658 | #endif |
---|