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