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