[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" |
---|
[581] | 47 | #include "G4OpenGLQtExportDialog.hh" |
---|
[530] | 48 | |
---|
[539] | 49 | #include "G4Qt.hh" |
---|
[569] | 50 | #include "G4UIsession.hh" |
---|
| 51 | #include "G4UImanager.hh" |
---|
[539] | 52 | #include <QtGui/qboxlayout.h> |
---|
| 53 | #include <QtGui/qdialog.h> |
---|
[564] | 54 | #include <QtGui/qmenu.h> |
---|
[580] | 55 | #include <QImageWriter> |
---|
| 56 | #include <QMessageBox> |
---|
[565] | 57 | #include <QFileDialog.h> |
---|
[530] | 58 | |
---|
| 59 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 60 | /** |
---|
[564] | 61 | Implementation of virtual method of G4VViewer |
---|
| 62 | */ |
---|
[530] | 63 | void G4OpenGLQtViewer::SetView ( |
---|
| 64 | ) |
---|
| 65 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 66 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
| 67 | { |
---|
[542] | 68 | printf("G4OpenGLQtViewer::SetView ++++++++++++++++++++\n"); |
---|
[564] | 69 | // if(!fHDC) return; |
---|
| 70 | // if(!fHGLRC) return; |
---|
| 71 | // ::wglMakeCurrent(fHDC,fHGLRC); |
---|
| 72 | // fWindow->makeCurrent(); |
---|
[579] | 73 | G4OpenGLViewer::SetView (); |
---|
[542] | 74 | printf("G4OpenGLQtViewer::SetView --------------------\n"); |
---|
[530] | 75 | } |
---|
| 76 | |
---|
| 77 | |
---|
| 78 | |
---|
| 79 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 80 | /** |
---|
[564] | 81 | Implementation of virtual method of G4VViewer |
---|
| 82 | */ |
---|
[530] | 83 | void G4OpenGLQtViewer::ShowView ( |
---|
| 84 | ) |
---|
| 85 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 86 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
| 87 | { |
---|
[542] | 88 | printf("G4OpenGLQtViewer::ShowView +++++++++++++++++++++\n"); |
---|
[564] | 89 | glFlush (); |
---|
[579] | 90 | if (!GLWindow) { |
---|
| 91 | G4cerr << "Visualization window not defined, please choose one before" << G4endl; |
---|
| 92 | } else { |
---|
| 93 | GLWindow->activateWindow(); |
---|
| 94 | printf("G4OpenGLQtViewer::ShowView -----------------------\n"); |
---|
| 95 | } |
---|
[564] | 96 | // // Empty the Windows message queue : |
---|
| 97 | // MSG event; |
---|
| 98 | // while ( ::PeekMessage(&event, NULL, 0, 0, PM_REMOVE) ) { |
---|
| 99 | // ::TranslateMessage(&event); |
---|
| 100 | // ::DispatchMessage (&event); |
---|
| 101 | // } |
---|
[530] | 102 | } |
---|
| 103 | |
---|
| 104 | |
---|
| 105 | |
---|
| 106 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 107 | void G4OpenGLQtViewer::CreateGLQtContext ( |
---|
| 108 | ) |
---|
| 109 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 110 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
| 111 | { |
---|
| 112 | printf("G4OpenGLQtViewer::CreateGLQtContext \n"); |
---|
| 113 | } |
---|
| 114 | |
---|
[564] | 115 | |
---|
[530] | 116 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 117 | void G4OpenGLQtViewer::CreateMainWindow ( |
---|
[564] | 118 | QGLWidget* glWidget |
---|
| 119 | ) |
---|
[530] | 120 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 121 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
| 122 | { |
---|
| 123 | |
---|
[538] | 124 | if(fWindow) return; //Done. |
---|
[564] | 125 | printf("G4OpenGLQtViewer::CreateMainWindow glWidget\n"); |
---|
[538] | 126 | |
---|
[539] | 127 | // launch Qt if not |
---|
| 128 | G4Qt* interactorManager = G4Qt::getInstance (); |
---|
| 129 | // G4UImanager* UI = G4UImanager::GetUIpointer(); |
---|
| 130 | |
---|
[564] | 131 | fWindow = glWidget ; |
---|
[543] | 132 | // fWindow->makeCurrent(); |
---|
[538] | 133 | |
---|
[539] | 134 | // create window |
---|
[569] | 135 | if (((QApplication*)interactorManager->GetMainInteractor())) { |
---|
| 136 | // look for the main window |
---|
| 137 | bool found = false; |
---|
| 138 | foreach (QWidget *widget, QApplication::allWidgets()) { |
---|
| 139 | if ((found== false) && (widget->inherits("QMainWindow"))) { |
---|
[579] | 140 | printf("G4OpenGLQtViewer::CreateMainWindow case Qapp exist\n"); |
---|
| 141 | GLWindow = new QDialog(widget,Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint); |
---|
[569] | 142 | found = true; |
---|
| 143 | } |
---|
| 144 | } |
---|
| 145 | if (found==false) { |
---|
[579] | 146 | printf("G4OpenGLQtViewer::CreateMainWindow case Qapp exist, but not found\n"); |
---|
[569] | 147 | GLWindow = new QDialog(); |
---|
| 148 | } |
---|
[539] | 149 | } else { |
---|
[579] | 150 | printf("G4OpenGLQtViewer::CreateMainWindow case Qapp exist\n"); |
---|
[539] | 151 | GLWindow = new QDialog(); |
---|
| 152 | } |
---|
| 153 | |
---|
| 154 | QHBoxLayout *mainLayout = new QHBoxLayout; |
---|
[564] | 155 | |
---|
[539] | 156 | mainLayout->addWidget(fWindow); |
---|
| 157 | GLWindow->setLayout(mainLayout); |
---|
| 158 | GLWindow->setWindowTitle("QGl Viewer"); |
---|
[564] | 159 | GLWindow->resize(300, 300); |
---|
[570] | 160 | GLWindow->move(900,300); |
---|
[539] | 161 | GLWindow->show(); |
---|
[530] | 162 | |
---|
[579] | 163 | // delete the pointer if close this |
---|
| 164 | // GLWindow->setAttribute(Qt::WA_DeleteOnClose); |
---|
| 165 | |
---|
| 166 | QObject ::connect(GLWindow, |
---|
| 167 | SIGNAL(rejected()), |
---|
| 168 | this, |
---|
| 169 | SLOT(dialogClosed())); |
---|
| 170 | |
---|
[564] | 171 | WinSize_x = 400; |
---|
| 172 | WinSize_y = 400; |
---|
| 173 | if (WinSize_x < fVP.GetWindowSizeHintX ()) |
---|
| 174 | WinSize_x = fVP.GetWindowSizeHintX (); |
---|
| 175 | if (WinSize_y < fVP.GetWindowSizeHintY ()) |
---|
| 176 | WinSize_y = fVP.GetWindowSizeHintY (); |
---|
[530] | 177 | |
---|
[564] | 178 | if(!fWindow) return; |
---|
| 179 | printf("G4OpenGLQtViewer::CreateMainWindow glWidget END\n"); |
---|
[530] | 180 | |
---|
[564] | 181 | if (!fContextMenu) |
---|
| 182 | createPopupMenu(); |
---|
[530] | 183 | |
---|
[564] | 184 | } |
---|
[530] | 185 | |
---|
[579] | 186 | /** Close the dialog and set the pointer to NULL |
---|
| 187 | */ |
---|
| 188 | void G4OpenGLQtViewer::dialogClosed() { |
---|
| 189 | GLWindow = NULL; |
---|
| 190 | } |
---|
| 191 | |
---|
| 192 | |
---|
[564] | 193 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 194 | G4OpenGLQtViewer::G4OpenGLQtViewer ( |
---|
| 195 | G4OpenGLSceneHandler& scene |
---|
| 196 | ) |
---|
| 197 | :G4VViewer (scene, -1) |
---|
| 198 | ,G4OpenGLViewer (scene) |
---|
| 199 | ,fWindow(0) |
---|
| 200 | ,fContextMenu(0) |
---|
| 201 | ,fMouseAction(true) |
---|
| 202 | { |
---|
| 203 | printf("G4OpenGLQtViewer::G4OpenGLQtViewer \n"); |
---|
[530] | 204 | } |
---|
| 205 | |
---|
| 206 | ////////////////////////////////////////////////////////////////////////////// |
---|
[564] | 207 | G4OpenGLQtViewer::~G4OpenGLQtViewer ( |
---|
[539] | 208 | ) |
---|
| 209 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 210 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
| 211 | { |
---|
[564] | 212 | printf("G4OpenGLQtViewer::~G4OpenGLQtViewer \n"); |
---|
[579] | 213 | delete fContextMenu; |
---|
[564] | 214 | } |
---|
[539] | 215 | |
---|
| 216 | |
---|
[564] | 217 | /** |
---|
| 218 | Create a popup menu for the widget. This menu is activated by right-mouse click |
---|
| 219 | */ |
---|
| 220 | void G4OpenGLQtViewer::createPopupMenu() { |
---|
[539] | 221 | |
---|
[564] | 222 | fContextMenu = new QMenu("All"); |
---|
[539] | 223 | |
---|
[564] | 224 | QMenu *mMouseAction = fContextMenu->addMenu("&Mouse action"); |
---|
| 225 | QAction *rotate = mMouseAction->addAction("&Rotate scene"); |
---|
| 226 | QAction *move = mMouseAction->addAction("&Move scene"); |
---|
| 227 | // INIT mMouse |
---|
| 228 | createRadioAction(rotate,move,SLOT(toggleMouseAction(bool)),1); |
---|
| 229 | |
---|
| 230 | //Style Menu |
---|
| 231 | QMenu *mStyle = fContextMenu->addMenu("&Style"); |
---|
| 232 | |
---|
| 233 | QMenu *mRepresentation = mStyle->addMenu("&Representation"); |
---|
| 234 | QAction *polyhedron = mRepresentation->addAction("Polyhedron"); |
---|
| 235 | QAction *nurbs = mRepresentation->addAction("NURBS"); |
---|
| 236 | // INIT mStyle |
---|
| 237 | G4ViewParameters::RepStyle style; |
---|
| 238 | style = fVP.GetRepStyle(); |
---|
| 239 | if (style == G4ViewParameters::polyhedron) { |
---|
| 240 | createRadioAction(polyhedron,nurbs,SLOT(toggleRepresentation(bool)),1); |
---|
| 241 | } else if (style == G4ViewParameters::nurbs) { |
---|
| 242 | createRadioAction(polyhedron,nurbs,SLOT(toggleRepresentation(bool)),2); |
---|
[539] | 243 | } else { |
---|
[564] | 244 | mRepresentation->clear(); |
---|
[539] | 245 | } |
---|
| 246 | |
---|
| 247 | |
---|
[564] | 248 | QMenu *mDrawing = mStyle->addMenu("&Drawing"); |
---|
| 249 | fDrawingWireframe = mDrawing->addAction("Wireframe"); |
---|
| 250 | fDrawingWireframe->setCheckable(true); |
---|
| 251 | fDrawingWireframe->setChecked(true); |
---|
| 252 | fDrawingLineRemoval = mDrawing->addAction("Hidden line removal"); |
---|
| 253 | fDrawingLineRemoval->setCheckable(true); |
---|
| 254 | fDrawingSurfaceRemoval = mDrawing->addAction("Hidden Surface removal"); |
---|
| 255 | fDrawingSurfaceRemoval->setCheckable(true); |
---|
| 256 | fDrawingLineSurfaceRemoval = mDrawing->addAction("Hidden line and surface removal"); |
---|
| 257 | fDrawingLineSurfaceRemoval->setCheckable(true); |
---|
| 258 | // INIT Drawing |
---|
| 259 | G4ViewParameters::DrawingStyle d_style; |
---|
| 260 | d_style = fVP.GetDrawingStyle(); |
---|
| 261 | |
---|
| 262 | fDrawingWireframe->setCheckable(true); |
---|
| 263 | fDrawingLineRemoval->setCheckable(true); |
---|
| 264 | fDrawingSurfaceRemoval->setCheckable(true); |
---|
| 265 | fDrawingLineSurfaceRemoval->setCheckable(true); |
---|
[539] | 266 | |
---|
[564] | 267 | if (d_style == G4ViewParameters::wireframe) { |
---|
| 268 | fDrawingWireframe->setChecked(true); |
---|
| 269 | } else if (d_style == G4ViewParameters::hlr) { |
---|
| 270 | fDrawingLineRemoval->setChecked(true); |
---|
| 271 | } else if (d_style == G4ViewParameters::hsr) { |
---|
| 272 | fDrawingSurfaceRemoval->setChecked(true); |
---|
| 273 | } else if (d_style == G4ViewParameters::hlhsr) { |
---|
| 274 | fDrawingLineSurfaceRemoval->setChecked(true); |
---|
| 275 | } else { |
---|
| 276 | mDrawing->clear(); |
---|
| 277 | } |
---|
| 278 | |
---|
[565] | 279 | QObject ::connect(fDrawingWireframe, |
---|
| 280 | SIGNAL(triggered(bool)), |
---|
| 281 | this, |
---|
| 282 | SLOT(actionDrawingWireframe())); |
---|
| 283 | QObject ::connect(fDrawingLineRemoval, |
---|
| 284 | SIGNAL(triggered(bool)), |
---|
| 285 | this, |
---|
| 286 | SLOT(actionDrawingLineRemoval())); |
---|
| 287 | QObject ::connect(fDrawingSurfaceRemoval, |
---|
| 288 | SIGNAL(triggered(bool)), |
---|
| 289 | this, |
---|
| 290 | SLOT(actionDrawingSurfaceRemoval())); |
---|
| 291 | QObject ::connect(fDrawingLineSurfaceRemoval, |
---|
| 292 | SIGNAL(triggered(bool)), |
---|
| 293 | this, |
---|
| 294 | SLOT(actionDrawingLineSurfaceRemoval())); |
---|
[564] | 295 | |
---|
| 296 | |
---|
| 297 | QMenu *mBackground = mStyle->addMenu("&Background color"); |
---|
| 298 | QAction *white = mBackground->addAction("White"); |
---|
| 299 | QAction *black = mBackground->addAction("Black"); |
---|
| 300 | if (background.GetRed() == 1. && |
---|
| 301 | background.GetGreen() == 1. && |
---|
| 302 | background.GetBlue() == 1.) { |
---|
| 303 | createRadioAction(white,black,SLOT(toggleBackground(bool)),1); |
---|
| 304 | } else { |
---|
| 305 | createRadioAction(white,black,SLOT(toggleBackground(bool)),2); |
---|
| 306 | } |
---|
| 307 | |
---|
| 308 | |
---|
| 309 | // Action Menu |
---|
| 310 | QMenu *mActions = fContextMenu->addMenu("&Actions"); |
---|
[565] | 311 | QAction *controlPanels = mActions->addAction("Control panels"); |
---|
| 312 | QAction *exitG4 = mActions->addAction("Exit to G4Vis >"); |
---|
[568] | 313 | QAction *createEPS = mActions->addAction("Save as ..."); |
---|
[565] | 314 | QObject ::connect(controlPanels, |
---|
[566] | 315 | SIGNAL(triggered()), |
---|
[565] | 316 | this, |
---|
| 317 | SLOT(actionControlPanels())); |
---|
| 318 | QObject ::connect(exitG4, |
---|
[566] | 319 | SIGNAL(triggered()), |
---|
[565] | 320 | this, |
---|
| 321 | SLOT(actionExitG4())); |
---|
| 322 | QObject ::connect(createEPS, |
---|
[566] | 323 | SIGNAL(triggered()), |
---|
[565] | 324 | this, |
---|
| 325 | SLOT(actionCreateEPS())); |
---|
[564] | 326 | |
---|
| 327 | |
---|
| 328 | // Special Menu |
---|
| 329 | QMenu *mSpecial = fContextMenu->addMenu("S&pecial"); |
---|
| 330 | QMenu *transparency = mSpecial->addMenu("Transparency"); |
---|
| 331 | QAction *transparencyOn = transparency->addAction("On"); |
---|
| 332 | QAction *transparencyOff = transparency->addAction("Off"); |
---|
| 333 | if (transparency_enabled == false) { |
---|
| 334 | createRadioAction(transparencyOn,transparencyOff,SLOT(toggleTransparency(bool)),2); |
---|
| 335 | } else if (transparency_enabled == true) { |
---|
| 336 | createRadioAction(transparencyOn,transparencyOff,SLOT(toggleTransparency(bool)),1); |
---|
| 337 | } else { |
---|
| 338 | mSpecial->clear(); |
---|
| 339 | } |
---|
| 340 | |
---|
| 341 | |
---|
| 342 | QMenu *mAntialiasing = mSpecial->addMenu("Antialiasing"); |
---|
| 343 | QAction *antialiasingOn = mAntialiasing->addAction("On"); |
---|
| 344 | QAction *antialiasingOff = mAntialiasing->addAction("Off"); |
---|
| 345 | if (antialiasing_enabled == false) { |
---|
| 346 | createRadioAction(antialiasingOn,antialiasingOff,SLOT(toggleAntialiasing(bool)),2); |
---|
| 347 | } else if (antialiasing_enabled == true) { |
---|
| 348 | createRadioAction(antialiasingOn,antialiasingOff,SLOT(toggleAntialiasing(bool)),1); |
---|
| 349 | } else { |
---|
| 350 | mAntialiasing->clear(); |
---|
| 351 | } |
---|
| 352 | |
---|
| 353 | QMenu *mHaloing = mSpecial->addMenu("Haloing"); |
---|
| 354 | QAction *haloingOn = mHaloing->addAction("On"); |
---|
| 355 | QAction *haloingOff = mHaloing->addAction("Off"); |
---|
| 356 | if (haloing_enabled == false) { |
---|
| 357 | createRadioAction(haloingOn,haloingOff,SLOT(toggleHaloing(bool)),2); |
---|
| 358 | } else if (haloing_enabled == true) { |
---|
| 359 | createRadioAction(haloingOn,haloingOff,SLOT(toggleHaloing(bool)),1); |
---|
| 360 | } else { |
---|
| 361 | mHaloing->clear(); |
---|
| 362 | } |
---|
| 363 | |
---|
| 364 | QMenu *mAux = mSpecial->addMenu("Auxiliary edges"); |
---|
| 365 | QAction *auxOn = mAux->addAction("On"); |
---|
| 366 | QAction *auxOff = mAux->addAction("Off"); |
---|
| 367 | if (!fVP.IsAuxEdgeVisible()) { |
---|
| 368 | createRadioAction(auxOn,auxOff,SLOT(toggleAux(bool)),1); |
---|
| 369 | } else { |
---|
| 370 | createRadioAction(auxOn,auxOff,SLOT(toggleAux(bool)),2); |
---|
| 371 | } |
---|
| 372 | |
---|
| 373 | |
---|
| 374 | QMenu *mFullScreen = mSpecial->addMenu("Full screen"); |
---|
| 375 | QAction *fullOn = mFullScreen->addAction("On"); |
---|
| 376 | QAction *fullOff = mFullScreen->addAction("Off"); |
---|
| 377 | createRadioAction(fullOn,fullOff,SLOT(toggleFullScreen(bool)),2); |
---|
| 378 | |
---|
| 379 | } |
---|
| 380 | |
---|
| 381 | void G4OpenGLQtViewer::manageContextMenuEvent(QContextMenuEvent *e) |
---|
| 382 | { |
---|
[579] | 383 | if (!GLWindow) { |
---|
| 384 | G4cerr << "Visualization window not defined, please choose one before" << G4endl; |
---|
| 385 | } else { |
---|
[539] | 386 | |
---|
[579] | 387 | if (!fContextMenu) |
---|
| 388 | createPopupMenu(); |
---|
| 389 | |
---|
| 390 | // launch menu |
---|
| 391 | if ( fContextMenu ) { |
---|
| 392 | fContextMenu->exec( e->globalPos() ); |
---|
| 393 | // delete fContextMenu; |
---|
| 394 | } |
---|
[564] | 395 | } |
---|
| 396 | e->accept(); |
---|
| 397 | } |
---|
[539] | 398 | |
---|
| 399 | |
---|
[564] | 400 | /** |
---|
| 401 | Create a radio button menu. The two menu will be connected. When click on one, |
---|
| 402 | eatch state will be invert and callback method will be called. |
---|
| 403 | @param action1 first action to connect |
---|
| 404 | @param action2 second action to connect |
---|
| 405 | @param method callback method |
---|
| 406 | @param nCheck: 1 : first action will be set true. 2 : second action will be set true |
---|
| 407 | */ |
---|
| 408 | void G4OpenGLQtViewer::createRadioAction(QAction *action1,QAction *action2, const std::string& method,unsigned int nCheck) { |
---|
| 409 | |
---|
| 410 | action1->setCheckable(true); |
---|
| 411 | action2->setCheckable(true); |
---|
| 412 | |
---|
| 413 | if (nCheck ==1) |
---|
| 414 | action1->setChecked (true); |
---|
| 415 | else |
---|
| 416 | action2->setChecked (true); |
---|
| 417 | |
---|
| 418 | QObject ::connect(action1, SIGNAL(triggered(bool)),action2, SLOT(toggle())); |
---|
| 419 | QObject ::connect(action2, SIGNAL(triggered(bool)),action1, SLOT(toggle())); |
---|
| 420 | |
---|
| 421 | QObject ::connect(action1, SIGNAL(toggled(bool)),this, method.c_str()); |
---|
| 422 | |
---|
| 423 | } |
---|
| 424 | |
---|
| 425 | /** |
---|
| 426 | Slot activate when drawing->wireframe menu is set |
---|
| 427 | */ |
---|
| 428 | void G4OpenGLQtViewer::actionDrawingWireframe() { |
---|
| 429 | emit toggleDrawingAction(1); |
---|
| 430 | } |
---|
| 431 | |
---|
| 432 | /** |
---|
| 433 | Slot activate when drawing->line removal menu is set |
---|
| 434 | */ |
---|
| 435 | void G4OpenGLQtViewer::actionDrawingLineRemoval() { |
---|
| 436 | emit toggleDrawingAction(2); |
---|
| 437 | } |
---|
| 438 | |
---|
| 439 | /** |
---|
| 440 | Slot activate when drawing->surface removal menu is set |
---|
| 441 | */ |
---|
| 442 | void G4OpenGLQtViewer::actionDrawingSurfaceRemoval() { |
---|
| 443 | emit toggleDrawingAction(3); |
---|
| 444 | } |
---|
| 445 | |
---|
| 446 | /** |
---|
| 447 | Slot activate when drawing->wireframe menu is set |
---|
| 448 | */ |
---|
| 449 | void G4OpenGLQtViewer::actionDrawingLineSurfaceRemoval() { |
---|
| 450 | emit toggleDrawingAction(4); |
---|
| 451 | } |
---|
| 452 | |
---|
| 453 | |
---|
| 454 | /** |
---|
[565] | 455 | Slot activated when drawing menu is toggle |
---|
| 456 | Warning : When G4OpenGLStoredQtViewer::DrawView() method call, |
---|
| 457 | KernelVisitDecision () will be call and will set the fNeedKernelVisit |
---|
| 458 | to 1. See G4XXXStoredViewer::CompareForKernelVisit for explanations. |
---|
| 459 | It will cause a redraw of the view |
---|
| 460 | @param aAction : 1 wireframe, 2 line removal, 3 surface removal, 4 line & surface removal |
---|
| 461 | @see G4OpenGLStoredQtViewer::DrawView |
---|
| 462 | @see G4XXXStoredViewer::CompareForKernelVisit |
---|
[564] | 463 | */ |
---|
| 464 | void G4OpenGLQtViewer::toggleDrawingAction(int aAction) { |
---|
| 465 | |
---|
| 466 | G4ViewParameters::DrawingStyle d_style; |
---|
[539] | 467 | |
---|
| 468 | |
---|
[564] | 469 | if (aAction ==1) { |
---|
| 470 | fDrawingWireframe->setChecked (true); |
---|
| 471 | fDrawingLineRemoval->setChecked (false); |
---|
| 472 | fDrawingSurfaceRemoval->setChecked (false); |
---|
| 473 | fDrawingLineSurfaceRemoval->setChecked (false); |
---|
| 474 | |
---|
| 475 | d_style = G4ViewParameters::wireframe; |
---|
| 476 | |
---|
| 477 | } else if (aAction ==2) { |
---|
| 478 | fDrawingWireframe->setChecked (false); |
---|
| 479 | fDrawingLineRemoval->setChecked (true); |
---|
| 480 | fDrawingSurfaceRemoval->setChecked (false); |
---|
| 481 | fDrawingLineSurfaceRemoval->setChecked (false); |
---|
| 482 | |
---|
| 483 | d_style = G4ViewParameters::hlr; |
---|
| 484 | |
---|
| 485 | } else if (aAction ==3) { |
---|
| 486 | fDrawingWireframe->setChecked (false); |
---|
| 487 | fDrawingLineRemoval->setChecked (false); |
---|
| 488 | fDrawingSurfaceRemoval->setChecked (true); |
---|
| 489 | fDrawingLineSurfaceRemoval->setChecked (false); |
---|
| 490 | |
---|
| 491 | d_style = G4ViewParameters::hsr; |
---|
| 492 | |
---|
| 493 | } else if (aAction ==4) { |
---|
| 494 | fDrawingWireframe->setChecked (false); |
---|
| 495 | fDrawingLineRemoval->setChecked (false); |
---|
| 496 | fDrawingSurfaceRemoval->setChecked (false); |
---|
| 497 | fDrawingLineSurfaceRemoval->setChecked (true); |
---|
| 498 | |
---|
| 499 | d_style = G4ViewParameters::hlhsr; |
---|
| 500 | } |
---|
| 501 | fVP.SetDrawingStyle(d_style); |
---|
| 502 | |
---|
| 503 | updateQWidget(); |
---|
| 504 | printf("G4OpenGLQtViewer::toggleDrawingAction\n"); |
---|
[539] | 505 | } |
---|
| 506 | |
---|
[564] | 507 | |
---|
| 508 | /** |
---|
| 509 | SLOT Activate by a click on the representation menu |
---|
[565] | 510 | Warning : When G4OpenGLStoredQtViewer::DrawView() method call, |
---|
| 511 | KernelVisitDecision () will be call and will set the fNeedKernelVisit |
---|
| 512 | to 1. See G4XXXStoredViewer::CompareForKernelVisit for explanations. |
---|
| 513 | It will cause a redraw of the view |
---|
[564] | 514 | @param check : 1 polyhedron, 0 nurbs |
---|
[565] | 515 | @see G4OpenGLStoredQtViewer::DrawView |
---|
| 516 | @see G4XXXStoredViewer::CompareForKernelVisit |
---|
[564] | 517 | */ |
---|
| 518 | void G4OpenGLQtViewer::toggleRepresentation(bool check) { |
---|
| 519 | |
---|
| 520 | G4ViewParameters::RepStyle style; |
---|
| 521 | if (check == 1) { |
---|
| 522 | style = G4ViewParameters::polyhedron; |
---|
| 523 | } else { |
---|
| 524 | style = G4ViewParameters::nurbs; |
---|
| 525 | } |
---|
| 526 | fVP.SetRepStyle (style); |
---|
| 527 | |
---|
| 528 | printf("G4OpenGLQtViewer::toggleRepresentation 3%d\n",check); |
---|
| 529 | updateQWidget(); |
---|
| 530 | printf("G4OpenGLQtViewer::toggleRepresentation 4%d\n",check); |
---|
[530] | 531 | } |
---|
| 532 | |
---|
[564] | 533 | /** |
---|
| 534 | SLOT Activate by a click on the background menu |
---|
| 535 | @param check : 1 white, 0 black |
---|
| 536 | */ |
---|
| 537 | void G4OpenGLQtViewer::toggleBackground(bool check) { |
---|
| 538 | |
---|
| 539 | // //I need to revisit the kernel if the background colour changes and |
---|
| 540 | // //hidden line removal is enabled, because hlr drawing utilises the |
---|
| 541 | // //background colour in its drawing... |
---|
| 542 | // // (Note added by JA 13/9/2005) Background now handled in view |
---|
| 543 | // // parameters. A kernel visit is triggered on change of background. |
---|
| 544 | if (check == 1) { |
---|
| 545 | ((G4ViewParameters&)this->GetViewParameters()). |
---|
| 546 | SetBackgroundColour(G4Colour(1.,1.,1.)); // White |
---|
| 547 | } else { |
---|
| 548 | ((G4ViewParameters&)this->GetViewParameters()). |
---|
| 549 | SetBackgroundColour(G4Colour(0.,0.,0.)); // Black |
---|
| 550 | } |
---|
| 551 | updateQWidget(); |
---|
[530] | 552 | } |
---|
| 553 | |
---|
[564] | 554 | /** |
---|
| 555 | SLOT Activate by a click on the transparency menu |
---|
| 556 | @param check : 1 , 0 |
---|
| 557 | */ |
---|
| 558 | void G4OpenGLQtViewer::toggleTransparency(bool check) { |
---|
| 559 | |
---|
| 560 | if (check) { |
---|
| 561 | transparency_enabled = false; |
---|
| 562 | } else { |
---|
| 563 | transparency_enabled = true; |
---|
| 564 | } |
---|
| 565 | SetNeedKernelVisit (true); |
---|
| 566 | updateQWidget(); |
---|
| 567 | } |
---|
[530] | 568 | |
---|
[564] | 569 | /** |
---|
| 570 | SLOT Activate by a click on the antialiasing menu |
---|
| 571 | @param check : 1 , 0 |
---|
| 572 | */ |
---|
| 573 | void G4OpenGLQtViewer::toggleAntialiasing(bool check) { |
---|
| 574 | |
---|
| 575 | if (!check) { |
---|
| 576 | antialiasing_enabled = false; |
---|
| 577 | glDisable (GL_LINE_SMOOTH); |
---|
| 578 | glDisable (GL_POLYGON_SMOOTH); |
---|
| 579 | } else { |
---|
| 580 | antialiasing_enabled = true; |
---|
| 581 | glEnable (GL_LINE_SMOOTH); |
---|
| 582 | glHint (GL_LINE_SMOOTH_HINT, GL_NICEST); |
---|
| 583 | glEnable (GL_POLYGON_SMOOTH); |
---|
| 584 | glHint (GL_POLYGON_SMOOTH_HINT, GL_NICEST); |
---|
[530] | 585 | } |
---|
[564] | 586 | |
---|
| 587 | updateQWidget(); |
---|
| 588 | printf("G4OpenGLQtViewer::toggleRepresentation %d\n",check); |
---|
| 589 | } |
---|
| 590 | |
---|
| 591 | /** |
---|
| 592 | SLOT Activate by a click on the haloing menu |
---|
| 593 | @param check : 1 , 0 |
---|
[530] | 594 | */ |
---|
[564] | 595 | //FIXME : I SEE NOTHING... |
---|
| 596 | void G4OpenGLQtViewer::toggleHaloing(bool check) { |
---|
| 597 | if (check) { |
---|
| 598 | haloing_enabled = false; |
---|
| 599 | } else { |
---|
| 600 | haloing_enabled = true; |
---|
| 601 | } |
---|
[530] | 602 | |
---|
[564] | 603 | updateQWidget(); |
---|
[530] | 604 | |
---|
[564] | 605 | printf("G4OpenGLQtViewer::toggleRepresentation %d\n",check); |
---|
| 606 | } |
---|
| 607 | |
---|
| 608 | /** |
---|
| 609 | SLOT Activate by a click on the auxiliaire edges menu |
---|
| 610 | @param check : 1 , 0 |
---|
| 611 | */ |
---|
| 612 | void G4OpenGLQtViewer::toggleAux(bool check) { |
---|
| 613 | if (check) { |
---|
| 614 | fVP.SetAuxEdgeVisible(false); |
---|
| 615 | } else { |
---|
| 616 | fVP.SetAuxEdgeVisible(true); |
---|
| 617 | } |
---|
| 618 | SetNeedKernelVisit (true); |
---|
| 619 | updateQWidget(); |
---|
| 620 | |
---|
| 621 | printf("G4OpenGLQtViewer::toggleRepresentation %d\n",check); |
---|
| 622 | } |
---|
| 623 | |
---|
| 624 | /** |
---|
| 625 | SLOT Activate by a click on the full screen menu |
---|
| 626 | @param check : 1 , 0 |
---|
| 627 | */ |
---|
| 628 | void G4OpenGLQtViewer::toggleFullScreen(bool check) { |
---|
| 629 | GLWindow->setWindowState(GLWindow->windowState() ^ Qt::WindowFullScreen); |
---|
| 630 | |
---|
| 631 | printf("G4OpenGLQtViewer::toggleRepresentation %d\n",check); |
---|
| 632 | } |
---|
| 633 | |
---|
| 634 | /** |
---|
| 635 | SLOT Activate by a click on the mouse action menu |
---|
| 636 | @param check : 1 , 0 |
---|
| 637 | */ |
---|
| 638 | void G4OpenGLQtViewer::toggleMouseAction(bool check) { |
---|
| 639 | if (check) { // rotate scene |
---|
| 640 | fMouseAction = true; |
---|
| 641 | } else { // move scene |
---|
| 642 | fMouseAction = false; |
---|
| 643 | } |
---|
| 644 | |
---|
| 645 | printf("G4OpenGLQtViewer::toggleRepresentation %d\n",check); |
---|
| 646 | } |
---|
| 647 | |
---|
| 648 | |
---|
[565] | 649 | void G4OpenGLQtViewer::actionControlPanels() { |
---|
| 650 | printf("G4OpenGLQtViewer::actionControlPanels \n"); |
---|
| 651 | } |
---|
| 652 | |
---|
| 653 | void G4OpenGLQtViewer::actionExitG4() { |
---|
| 654 | printf("G4OpenGLQtViewer::actionExitG4() \n"); |
---|
| 655 | } |
---|
| 656 | |
---|
| 657 | void G4OpenGLQtViewer::actionCreateEPS() { |
---|
[580] | 658 | QString filters; |
---|
| 659 | QList<QByteArray> formats = QImageWriter::supportedImageFormats (); |
---|
| 660 | for (int i = 0; i < formats.size(); ++i) { |
---|
[582] | 661 | filters +=formats.at(i); |
---|
[580] | 662 | if ((i+1) <formats.size()) { |
---|
| 663 | filters += ";;"; |
---|
| 664 | } |
---|
| 665 | } |
---|
[582] | 666 | QString* selectedFilter = new QString(); |
---|
[580] | 667 | QString nomFich = QFileDialog::getSaveFileName ( GLWindow, |
---|
| 668 | tr("Save as ..."), |
---|
| 669 | ".", |
---|
[582] | 670 | filters, |
---|
| 671 | selectedFilter ); |
---|
[580] | 672 | // bmp jpg jpeg png ppm xbm xpm |
---|
[582] | 673 | if (nomFich == "") { |
---|
| 674 | return; |
---|
| 675 | } |
---|
| 676 | nomFich += "."+selectedFilter->toLower(); |
---|
| 677 | printf("G4OpenGLQtViewer::name %s\n",nomFich.toStdString().c_str()); |
---|
[580] | 678 | if(nomFich.endsWith(".eps")) { |
---|
| 679 | G4cerr << "This version of G4UI Could not generate EPS." << G4endl; |
---|
| 680 | } else if(nomFich.endsWith(".jpg") || nomFich.endsWith(".jpeg")) { |
---|
[583] | 681 | G4OpenGLQtExportDialog* exportDialog= new G4OpenGLQtExportDialog(GLWindow,nomFich,fWindow->height(),fWindow->width()); |
---|
[582] | 682 | int res = exportDialog->exec(); |
---|
| 683 | printf("G4OpenGLQtViewer::actionCreateEPS() --%d-- quality:\n",res); |
---|
[580] | 684 | fWindow->grabFrameBuffer().save(nomFich); |
---|
[568] | 685 | } else { |
---|
| 686 | fWindow->grabFrameBuffer().save(nomFich); |
---|
[580] | 687 | // grabFrameBuffer() :: Returns an image of the frame buffer. If withAlpha is true the alpha channel is included. |
---|
[568] | 688 | } |
---|
[580] | 689 | |
---|
[565] | 690 | printf("G4OpenGLQtViewer::actionCreateEPS() \n"); |
---|
| 691 | } |
---|
| 692 | |
---|
[580] | 693 | /* |
---|
| 694 | // http://www.google.com/codesearch?hl=en&q=+jpg+Qt+quality+QDialog+show:FZkUoth8oiw:TONpW2mR-_c:tyTfrKMO-xI&sa=N&cd=2&ct=rc&cs_p=http://soft.proindependent.com/src/qtiplot-0.8.9.zip&cs_f=qtiplot-0.8.9/qtiplot/src/application.cpp#a0 |
---|
| 695 | void ApplicationWindow::exportLayer() |
---|
| 696 | { |
---|
| 697 | QWidget *w=ws->activeWindow(); |
---|
| 698 | if (!w || !w->isA("MultiLayer")) |
---|
| 699 | return; |
---|
| 700 | |
---|
| 701 | Graph* g = ((MultiLayer*)w)->activeGraph(); |
---|
| 702 | if (!g) |
---|
| 703 | return; |
---|
| 704 | |
---|
| 705 | ImageExportDialog *ied = new ImageExportDialog(this, 0); |
---|
| 706 | ied->setDir(workingDir); |
---|
| 707 | if ( ied->exec() == QDialog::Accepted ) |
---|
| 708 | { |
---|
| 709 | workingDir = ied->dirPath(); |
---|
| 710 | QString fname = ied->selectedFile(); |
---|
| 711 | QString selectedFilter = ied->selectedFilter(); |
---|
| 712 | |
---|
| 713 | QFileInfo fi(fname); |
---|
| 714 | QString baseName = fi.fileName(); |
---|
| 715 | |
---|
| 716 | if (baseName.contains(".")==0) |
---|
| 717 | fname.append(selectedFilter.remove("*")); |
---|
| 718 | |
---|
| 719 | if ( QFile::exists(fname) && |
---|
| 720 | QMessageBox::question(0, tr("QtiPlot - Overwrite File?"), |
---|
| 721 | tr("A file called: <p><b>%1</b><p>already exists. " |
---|
| 722 | "Do you want to overwrite it?") |
---|
| 723 | .arg(fname), |
---|
| 724 | tr("&Yes"), tr("&No"), |
---|
| 725 | QString::null, 0, 1 ) ) |
---|
| 726 | return ; |
---|
| 727 | else |
---|
| 728 | { |
---|
| 729 | QFile f(fname); |
---|
| 730 | if ( !f.open( IO_WriteOnly ) ) |
---|
| 731 | { |
---|
| 732 | QMessageBox::critical(0, tr("QtiPlot - Export Error"), |
---|
| 733 | tr("Could not write to file: <br><h4> %1 </h4><p>Please verify that you have the right to write to this location!").arg(fname)); |
---|
| 734 | return; |
---|
| 735 | } |
---|
| 736 | |
---|
| 737 | if (selectedFilter.contains(".eps")) |
---|
| 738 | { |
---|
| 739 | if (ied->showExportOptions()) |
---|
| 740 | { |
---|
| 741 | epsExportDialog *ed= new epsExportDialog (fname, this, "exportDialog", TRUE, WStyle_Tool|WDestructiveClose); |
---|
| 742 | connect (ed, SIGNAL(exportToEPS(const QString&, int, QPrinter::Orientation, QPrinter::PageSize, QPrinter::ColorMode)), |
---|
| 743 | g, SLOT(exportToEPS(const QString&, int, QPrinter::Orientation, QPrinter::PageSize, QPrinter::ColorMode))); |
---|
| 744 | |
---|
| 745 | ed->showNormal(); |
---|
| 746 | ed->setActiveWindow(); |
---|
| 747 | } |
---|
| 748 | else |
---|
| 749 | g->exportToEPS(fname); |
---|
| 750 | |
---|
| 751 | if (((MultiLayer*)w)->hasOverlapingLayers()) |
---|
| 752 | ((MultiLayer*)w)->updateTransparency(); |
---|
| 753 | return; |
---|
| 754 | } |
---|
| 755 | else if (selectedFilter.contains(".svg")) |
---|
| 756 | { |
---|
| 757 | g->exportToSVG(fname); |
---|
| 758 | return; |
---|
| 759 | } |
---|
| 760 | // else if (selectedFilter.contains(".wmf")) |
---|
| 761 | // { |
---|
| 762 | // g->exportToWmf(fname); |
---|
| 763 | // return; |
---|
| 764 | } |
---|
[582] | 765 | QStringList list=QImage::outputFormatList (); |
---|
[580] | 766 | for (int i=0; i<(int)list.count(); i++) |
---|
| 767 | { |
---|
| 768 | if (selectedFilter.contains("."+(list[i]).lower())) |
---|
| 769 | { |
---|
[582] | 770 | if (ied->showExportOptions()) |
---|
| 771 | { |
---|
| 772 | imageExportDialog* ed= new imageExportDialog(false, this,"exportDialog",TRUE,WStyle_Tool|WDestructiveClose); |
---|
[580] | 773 | connect (ed, SIGNAL(options(const QString&, const QString&, int, bool)), |
---|
| 774 | g, SLOT(exportImage(const QString&, const QString&, int, bool))); |
---|
| 775 | |
---|
| 776 | ed->setExportPath(fname, list[i]); |
---|
| 777 | ed->enableTransparency(); |
---|
| 778 | ed->showNormal(); |
---|
| 779 | ed->setActiveWindow(); |
---|
| 780 | } |
---|
| 781 | else |
---|
| 782 | g->exportImage(fname, list[i], 100, true); |
---|
| 783 | |
---|
| 784 | if (((MultiLayer*)w)->hasOverlapingLayers()) |
---|
| 785 | ((MultiLayer*)w)->updateTransparency(); |
---|
| 786 | return; |
---|
| 787 | } |
---|
| 788 | } |
---|
| 789 | } |
---|
| 790 | } |
---|
| 791 | } |
---|
[565] | 792 | |
---|
[580] | 793 | void Graph::exportToSVG(const QString& fname) |
---|
| 794 | { |
---|
| 795 | // enable workaround for Qt3 misalignments |
---|
| 796 | QwtPainter::setSVGMode(true); |
---|
| 797 | QPicture picture; |
---|
| 798 | QPainter p(&picture); |
---|
| 799 | d_plot->print(&p, d_plot->rect()); |
---|
| 800 | p.end(); |
---|
[565] | 801 | |
---|
[580] | 802 | picture.save(fname, "svg"); |
---|
| 803 | } |
---|
| 804 | */ |
---|
| 805 | |
---|
| 806 | |
---|
| 807 | |
---|
| 808 | |
---|
[564] | 809 | /** |
---|
| 810 | Save the current mouse press point |
---|
| 811 | @param p mouse click point |
---|
| 812 | */ |
---|
| 813 | void G4OpenGLQtViewer::G4MousePressEvent(QPoint p) |
---|
| 814 | { |
---|
| 815 | lastPos = p; |
---|
| 816 | } |
---|
| 817 | |
---|
| 818 | /** |
---|
| 819 | @param pos_x mouse x position |
---|
| 820 | @param pos_y mouse y position |
---|
| 821 | @param mButtons mouse button active |
---|
| 822 | */ |
---|
| 823 | void G4OpenGLQtViewer::G4MouseMoveEvent(int pos_x, int pos_y,Qt::MouseButtons mButtons) |
---|
| 824 | { |
---|
| 825 | int dx = pos_x - lastPos.x(); |
---|
| 826 | int dy = pos_y - lastPos.y(); |
---|
[530] | 827 | |
---|
[564] | 828 | if (fMouseAction) { // rotate |
---|
| 829 | if (mButtons & Qt::LeftButton) { |
---|
| 830 | //phi spin stuff here |
---|
| 831 | |
---|
| 832 | G4Vector3D vp = fVP.GetViewpointDirection ().unit (); |
---|
| 833 | G4Vector3D up = fVP.GetUpVector ().unit (); |
---|
| 834 | |
---|
| 835 | G4Vector3D yprime = (up.cross(vp)).unit(); |
---|
| 836 | G4Vector3D zprime = (vp.cross(yprime)).unit(); |
---|
| 837 | |
---|
| 838 | G4double delta_alpha; |
---|
| 839 | G4double delta_theta; |
---|
| 840 | |
---|
| 841 | if (fVP.GetLightsMoveWithCamera()) { |
---|
| 842 | delta_alpha = dy; |
---|
| 843 | delta_theta = -dx; |
---|
| 844 | } else { |
---|
| 845 | delta_alpha = -dy; |
---|
| 846 | delta_theta = dx; |
---|
| 847 | } |
---|
[530] | 848 | |
---|
[564] | 849 | delta_alpha *= deg; |
---|
| 850 | delta_theta *= deg; |
---|
[530] | 851 | |
---|
[564] | 852 | G4Vector3D new_vp = std::cos(delta_alpha) * vp + std::sin(delta_alpha) * zprime; |
---|
| 853 | |
---|
| 854 | G4Vector3D new_up; |
---|
| 855 | if (fVP.GetLightsMoveWithCamera()) { |
---|
| 856 | new_up = (new_vp.cross(yprime)).unit(); |
---|
| 857 | fVP.SetUpVector(new_up); |
---|
| 858 | } else { |
---|
| 859 | new_up = up; |
---|
| 860 | } |
---|
| 861 | //////////////// |
---|
| 862 | // Rotates by fixed azimuthal angle delta_theta. |
---|
| 863 | |
---|
| 864 | G4double cosalpha = new_up.dot (new_vp.unit()); |
---|
| 865 | G4double sinalpha = std::sqrt (1. - std::pow (cosalpha, 2)); |
---|
| 866 | yprime = (new_up.cross (new_vp.unit())).unit (); |
---|
| 867 | G4Vector3D xprime = yprime.cross (new_up); |
---|
| 868 | // Projection of vp on plane perpendicular to up... |
---|
| 869 | G4Vector3D a1 = sinalpha * xprime; |
---|
| 870 | // Required new projection... |
---|
| 871 | G4Vector3D a2 = |
---|
| 872 | sinalpha * (std::cos (delta_theta) * xprime + std::sin (delta_theta) * yprime); |
---|
| 873 | // Required Increment vector... |
---|
| 874 | G4Vector3D delta = a2 - a1; |
---|
| 875 | // So new viewpoint is... |
---|
| 876 | G4Vector3D viewPoint = new_vp.unit() + delta; |
---|
| 877 | |
---|
| 878 | fVP.SetViewAndLights (viewPoint); |
---|
| 879 | updateQWidget(); |
---|
| 880 | |
---|
| 881 | } else if (mButtons & Qt::RightButton) { |
---|
| 882 | // NEVER DONE BECAUSE OF MOUSE MENU |
---|
| 883 | // printf("G4OpenGLQtViewer::mouseMoveEvent Right \n"); |
---|
| 884 | // setXRotation(xRot + dy/2); |
---|
| 885 | // setZRotation(zRot + dx/2); |
---|
| 886 | // updateQWidget(); |
---|
| 887 | } |
---|
| 888 | } else { // move |
---|
| 889 | |
---|
| 890 | float dx = pos_x - lastPos.x(); |
---|
| 891 | float dy = pos_y - lastPos.y(); |
---|
| 892 | |
---|
| 893 | G4Point3D stp |
---|
| 894 | = GetSceneHandler()->GetScene()->GetStandardTargetPoint(); |
---|
| 895 | |
---|
| 896 | G4Point3D tp = stp + fVP.GetCurrentTargetPoint (); |
---|
| 897 | |
---|
| 898 | const G4Vector3D& upVector = fVP.GetUpVector (); |
---|
| 899 | const G4Vector3D& vpVector = fVP.GetViewpointDirection (); |
---|
| 900 | |
---|
| 901 | G4Vector3D unitRight = (upVector.cross (vpVector)).unit(); |
---|
| 902 | G4Vector3D unitUp = (vpVector.cross (unitRight)).unit(); |
---|
| 903 | |
---|
| 904 | tp += -dx * unitRight + dy * unitUp; |
---|
| 905 | fVP.SetCurrentTargetPoint (tp - stp); |
---|
| 906 | |
---|
| 907 | updateQWidget(); |
---|
| 908 | } |
---|
| 909 | lastPos = QPoint(pos_x, pos_y); |
---|
| 910 | } |
---|
| 911 | |
---|
[568] | 912 | |
---|
[530] | 913 | #endif |
---|