[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 | // |
---|
[704] | 27 | // $Id: G4OpenGLQtViewer.cc,v 1.10 2008/01/30 10:54:13 lgarnier Exp $ |
---|
[593] | 28 | // GEANT4 tag $Name: $ |
---|
[530] | 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 | |
---|
[707] | 38 | #define GEANT4_QT_DEBUG |
---|
[610] | 39 | |
---|
[530] | 40 | #include "G4OpenGLQtViewer.hh" |
---|
| 41 | |
---|
| 42 | #include "G4ios.hh" |
---|
| 43 | #include "G4VisExtent.hh" |
---|
| 44 | #include "G4LogicalVolume.hh" |
---|
| 45 | #include "G4VSolid.hh" |
---|
| 46 | #include "G4Point3D.hh" |
---|
| 47 | #include "G4Normal3D.hh" |
---|
[564] | 48 | #include "G4Scene.hh" |
---|
[581] | 49 | #include "G4OpenGLQtExportDialog.hh" |
---|
[703] | 50 | #include "G4UnitsTable.hh" |
---|
[539] | 51 | #include "G4Qt.hh" |
---|
[569] | 52 | #include "G4UImanager.hh" |
---|
[702] | 53 | #include "G4UIcommandTree.hh" |
---|
[595] | 54 | #include <qapplication.h> |
---|
[599] | 55 | #include <qlayout.h> |
---|
[595] | 56 | #include <qdialog.h> |
---|
[599] | 57 | |
---|
| 58 | #if QT_VERSION >= 0x040000 |
---|
[595] | 59 | #include <qmenu.h> |
---|
| 60 | #include <qimagewriter.h> |
---|
[599] | 61 | #else |
---|
| 62 | #include <qaction.h> |
---|
| 63 | #include <qwidgetlist.h> |
---|
| 64 | #include <qpopupmenu.h> |
---|
| 65 | #include <qimage.h> |
---|
| 66 | #endif |
---|
| 67 | |
---|
[595] | 68 | #include <qmessagebox.h> |
---|
| 69 | #include <qfiledialog.h> |
---|
| 70 | #include <qprinter.h> |
---|
| 71 | #include <qpainter.h> |
---|
| 72 | #include <qgl.h> // include <qglwidget.h> |
---|
| 73 | #include <qdialog.h> |
---|
| 74 | #include <qevent.h> //include <qcontextmenuevent.h> |
---|
[530] | 75 | |
---|
[593] | 76 | |
---|
[530] | 77 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 78 | /** |
---|
[564] | 79 | Implementation of virtual method of G4VViewer |
---|
| 80 | */ |
---|
[530] | 81 | void G4OpenGLQtViewer::SetView ( |
---|
| 82 | ) |
---|
| 83 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 84 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
| 85 | { |
---|
[608] | 86 | #ifdef GEANT4_QT_DEBUG |
---|
[542] | 87 | printf("G4OpenGLQtViewer::SetView ++++++++++++++++++++\n"); |
---|
[608] | 88 | #endif |
---|
[564] | 89 | // if(!fHDC) return; |
---|
| 90 | // if(!fHGLRC) return; |
---|
| 91 | // ::wglMakeCurrent(fHDC,fHGLRC); |
---|
| 92 | // fWindow->makeCurrent(); |
---|
[579] | 93 | G4OpenGLViewer::SetView (); |
---|
[608] | 94 | #ifdef GEANT4_QT_DEBUG |
---|
[542] | 95 | printf("G4OpenGLQtViewer::SetView --------------------\n"); |
---|
[608] | 96 | #endif |
---|
[530] | 97 | } |
---|
| 98 | |
---|
[673] | 99 | /** |
---|
| 100 | * Set the viewport of the scene |
---|
| 101 | */ |
---|
| 102 | void G4OpenGLQtViewer::setupViewport(int aWidth, int aHeight) |
---|
| 103 | { |
---|
[709] | 104 | int side = aWidth; |
---|
| 105 | if (aHeight < aWidth) side = aHeight; |
---|
[673] | 106 | glViewport((aWidth - side) / 2, (aHeight - side) / 2, side, side); |
---|
| 107 | |
---|
| 108 | glMatrixMode(GL_PROJECTION); |
---|
| 109 | glLoadIdentity(); |
---|
| 110 | glOrtho(-0.5, +0.5, +0.5, -0.5, 4.0, 15.0); |
---|
| 111 | glMatrixMode(GL_MODELVIEW); |
---|
| 112 | } |
---|
[530] | 113 | |
---|
| 114 | |
---|
| 115 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 116 | /** |
---|
[564] | 117 | Implementation of virtual method of G4VViewer |
---|
| 118 | */ |
---|
[530] | 119 | void G4OpenGLQtViewer::ShowView ( |
---|
| 120 | ) |
---|
| 121 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 122 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
| 123 | { |
---|
[608] | 124 | #ifdef GEANT4_QT_DEBUG |
---|
[542] | 125 | printf("G4OpenGLQtViewer::ShowView +++++++++++++++++++++\n"); |
---|
[608] | 126 | #endif |
---|
[579] | 127 | if (!GLWindow) { |
---|
[638] | 128 | G4cerr << "Visualization window not defined, please choose one before\n" << G4endl; |
---|
[579] | 129 | } else { |
---|
[599] | 130 | #if QT_VERSION < 0x040000 |
---|
| 131 | GLWindow->setActiveWindow(); |
---|
| 132 | #else |
---|
[579] | 133 | GLWindow->activateWindow(); |
---|
[599] | 134 | #endif |
---|
[608] | 135 | #ifdef GEANT4_QT_DEBUG |
---|
[579] | 136 | printf("G4OpenGLQtViewer::ShowView -----------------------\n"); |
---|
[608] | 137 | #endif |
---|
[579] | 138 | } |
---|
[678] | 139 | glFlush (); |
---|
[564] | 140 | // // Empty the Windows message queue : |
---|
| 141 | // MSG event; |
---|
| 142 | // while ( ::PeekMessage(&event, NULL, 0, 0, PM_REMOVE) ) { |
---|
| 143 | // ::TranslateMessage(&event); |
---|
| 144 | // ::DispatchMessage (&event); |
---|
| 145 | // } |
---|
[530] | 146 | } |
---|
| 147 | |
---|
| 148 | |
---|
| 149 | |
---|
| 150 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 151 | void G4OpenGLQtViewer::CreateGLQtContext ( |
---|
| 152 | ) |
---|
| 153 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 154 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
| 155 | { |
---|
[608] | 156 | #ifdef GEANT4_QT_DEBUG |
---|
[530] | 157 | printf("G4OpenGLQtViewer::CreateGLQtContext \n"); |
---|
[608] | 158 | #endif |
---|
[530] | 159 | } |
---|
| 160 | |
---|
[564] | 161 | |
---|
[530] | 162 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 163 | void G4OpenGLQtViewer::CreateMainWindow ( |
---|
[585] | 164 | QGLWidget* glWidget |
---|
| 165 | ) |
---|
[530] | 166 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 167 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
| 168 | { |
---|
| 169 | |
---|
[538] | 170 | if(fWindow) return; //Done. |
---|
[608] | 171 | #ifdef GEANT4_QT_DEBUG |
---|
[564] | 172 | printf("G4OpenGLQtViewer::CreateMainWindow glWidget\n"); |
---|
[608] | 173 | #endif |
---|
[538] | 174 | |
---|
[539] | 175 | // launch Qt if not |
---|
| 176 | G4Qt* interactorManager = G4Qt::getInstance (); |
---|
| 177 | // G4UImanager* UI = G4UImanager::GetUIpointer(); |
---|
| 178 | |
---|
[564] | 179 | fWindow = glWidget ; |
---|
[543] | 180 | // fWindow->makeCurrent(); |
---|
[538] | 181 | |
---|
[539] | 182 | // create window |
---|
[569] | 183 | if (((QApplication*)interactorManager->GetMainInteractor())) { |
---|
| 184 | // look for the main window |
---|
| 185 | bool found = false; |
---|
[599] | 186 | #if QT_VERSION < 0x040000 |
---|
[631] | 187 | // theses lines does nothing exept this one "GLWindow = new QDialog(0..." |
---|
[626] | 188 | // but if I comment them, it doesn't work... |
---|
| 189 | QWidgetList *list = QApplication::allWidgets(); |
---|
| 190 | QWidgetListIt it( *list ); // iterate over the widgets |
---|
| 191 | QWidget * widget; |
---|
| 192 | while ( (widget=it.current()) != 0 ) { // for each widget... |
---|
| 193 | ++it; |
---|
| 194 | if ((found== false) && (widget->inherits("QMainWindow"))) { |
---|
| 195 | GLWindow = new QDialog(0,0,FALSE,Qt::WStyle_Title | Qt::WStyle_SysMenu | Qt::WStyle_MinMax ); |
---|
| 196 | found = true; |
---|
| 197 | } |
---|
| 198 | } |
---|
| 199 | delete list; // delete the list, not the widgets |
---|
[599] | 200 | #else |
---|
[626] | 201 | foreach (QWidget *widget, QApplication::allWidgets()) { |
---|
| 202 | if ((found== false) && (widget->inherits("QMainWindow"))) { |
---|
[650] | 203 | GLWindow = new QDialog(0,Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint); |
---|
[626] | 204 | found = true; |
---|
| 205 | } |
---|
| 206 | } |
---|
[608] | 207 | #endif |
---|
[612] | 208 | |
---|
| 209 | #if QT_VERSION < 0x040000 |
---|
[610] | 210 | glWidget->reparent(GLWindow,0,QPoint(0,0)); |
---|
[612] | 211 | #else |
---|
| 212 | glWidget->setParent(GLWindow); |
---|
| 213 | #endif |
---|
[599] | 214 | |
---|
[569] | 215 | if (found==false) { |
---|
[608] | 216 | #ifdef GEANT4_QT_DEBUG |
---|
[579] | 217 | printf("G4OpenGLQtViewer::CreateMainWindow case Qapp exist, but not found\n"); |
---|
[608] | 218 | #endif |
---|
[569] | 219 | GLWindow = new QDialog(); |
---|
| 220 | } |
---|
[539] | 221 | } else { |
---|
[608] | 222 | #ifdef GEANT4_QT_DEBUG |
---|
[579] | 223 | printf("G4OpenGLQtViewer::CreateMainWindow case Qapp exist\n"); |
---|
[608] | 224 | #endif |
---|
[539] | 225 | GLWindow = new QDialog(); |
---|
| 226 | } |
---|
| 227 | |
---|
[599] | 228 | QHBoxLayout *mainLayout = new QHBoxLayout(GLWindow); |
---|
[564] | 229 | |
---|
[539] | 230 | mainLayout->addWidget(fWindow); |
---|
[599] | 231 | |
---|
| 232 | #if QT_VERSION < 0x040000 |
---|
| 233 | GLWindow->setCaption( tr( "QGl Viewer" )); |
---|
| 234 | #else |
---|
[539] | 235 | GLWindow->setLayout(mainLayout); |
---|
[599] | 236 | GLWindow->setWindowTitle(tr("QGl Viewer")); |
---|
| 237 | #endif |
---|
[564] | 238 | GLWindow->resize(300, 300); |
---|
[570] | 239 | GLWindow->move(900,300); |
---|
[539] | 240 | GLWindow->show(); |
---|
[530] | 241 | |
---|
[579] | 242 | // delete the pointer if close this |
---|
| 243 | // GLWindow->setAttribute(Qt::WA_DeleteOnClose); |
---|
| 244 | |
---|
[610] | 245 | #if QT_VERSION >= 0x040000 |
---|
[711] | 246 | // QObject ::connect(GLWindow, |
---|
| 247 | // SIGNAL(rejected()), |
---|
| 248 | // this, |
---|
| 249 | // SLOT(dialogClosed())); |
---|
[610] | 250 | #endif |
---|
[579] | 251 | |
---|
[564] | 252 | WinSize_x = 400; |
---|
| 253 | WinSize_y = 400; |
---|
| 254 | if (WinSize_x < fVP.GetWindowSizeHintX ()) |
---|
| 255 | WinSize_x = fVP.GetWindowSizeHintX (); |
---|
| 256 | if (WinSize_y < fVP.GetWindowSizeHintY ()) |
---|
| 257 | WinSize_y = fVP.GetWindowSizeHintY (); |
---|
[530] | 258 | |
---|
[564] | 259 | if(!fWindow) return; |
---|
[608] | 260 | #ifdef GEANT4_QT_DEBUG |
---|
[564] | 261 | printf("G4OpenGLQtViewer::CreateMainWindow glWidget END\n"); |
---|
[608] | 262 | #endif |
---|
[530] | 263 | |
---|
[564] | 264 | if (!fContextMenu) |
---|
| 265 | createPopupMenu(); |
---|
[530] | 266 | |
---|
[564] | 267 | } |
---|
[530] | 268 | |
---|
[610] | 269 | #if QT_VERSION >= 0x040000 |
---|
[579] | 270 | /** Close the dialog and set the pointer to NULL |
---|
| 271 | */ |
---|
[711] | 272 | // void G4OpenGLQtViewer::dialogClosed() { |
---|
| 273 | // #ifdef GEANT4_QT_DEBUG |
---|
| 274 | // printf("G4OpenGLQtViewer::dialogClosed END\n"); |
---|
| 275 | // #endif |
---|
| 276 | // // GLWindow = NULL; |
---|
| 277 | // } |
---|
[610] | 278 | #endif |
---|
[579] | 279 | |
---|
[564] | 280 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 281 | G4OpenGLQtViewer::G4OpenGLQtViewer ( |
---|
| 282 | G4OpenGLSceneHandler& scene |
---|
| 283 | ) |
---|
| 284 | :G4VViewer (scene, -1) |
---|
| 285 | ,G4OpenGLViewer (scene) |
---|
| 286 | ,fWindow(0) |
---|
| 287 | ,fContextMenu(0) |
---|
[696] | 288 | ,fMouseAction(STYLE1) |
---|
[713] | 289 | ,fDeltaRotation(1) |
---|
[712] | 290 | ,fDeltaSceneTranslation(0.01) |
---|
| 291 | ,fDeltaDepth(0.01) |
---|
| 292 | ,fDeltaZoom(0.1) |
---|
[702] | 293 | ,holdKeyEvent(false) |
---|
[564] | 294 | { |
---|
[608] | 295 | #ifdef GEANT4_QT_DEBUG |
---|
[564] | 296 | printf("G4OpenGLQtViewer::G4OpenGLQtViewer \n"); |
---|
[608] | 297 | #endif |
---|
[530] | 298 | } |
---|
| 299 | |
---|
| 300 | ////////////////////////////////////////////////////////////////////////////// |
---|
[564] | 301 | G4OpenGLQtViewer::~G4OpenGLQtViewer ( |
---|
[539] | 302 | ) |
---|
| 303 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 304 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
| 305 | { |
---|
[608] | 306 | #ifdef GEANT4_QT_DEBUG |
---|
[564] | 307 | printf("G4OpenGLQtViewer::~G4OpenGLQtViewer \n"); |
---|
[608] | 308 | #endif |
---|
[564] | 309 | } |
---|
[539] | 310 | |
---|
| 311 | |
---|
[564] | 312 | /** |
---|
| 313 | Create a popup menu for the widget. This menu is activated by right-mouse click |
---|
| 314 | */ |
---|
| 315 | void G4OpenGLQtViewer::createPopupMenu() { |
---|
[539] | 316 | |
---|
[599] | 317 | #if QT_VERSION < 0x040000 |
---|
| 318 | fContextMenu = new QPopupMenu( GLWindow,"All" ); |
---|
| 319 | #else |
---|
[564] | 320 | fContextMenu = new QMenu("All"); |
---|
[599] | 321 | #endif |
---|
[539] | 322 | |
---|
[599] | 323 | #if QT_VERSION < 0x040000 |
---|
| 324 | QPopupMenu *mMouseAction = new QPopupMenu( fContextMenu ); |
---|
[678] | 325 | fContextMenu->insertItem("&Mouse actions"); |
---|
[617] | 326 | #else |
---|
[678] | 327 | QMenu *mMouseAction = fContextMenu->addMenu("&Mouse actions"); |
---|
[617] | 328 | #endif |
---|
[599] | 329 | |
---|
[678] | 330 | #if QT_VERSION < 0x040000 |
---|
| 331 | // === Mouse menu === |
---|
[599] | 332 | |
---|
[713] | 333 | mMouseAction->setCheckable(true); |
---|
| 334 | |
---|
[678] | 335 | fMouseRotate = new QPopupMenu(mMouseAction); |
---|
| 336 | mMouseAction->insertItem("&Rotate",fMouseRotate); |
---|
| 337 | fMouseRotate->setCheckable(true); |
---|
| 338 | |
---|
[713] | 339 | fMouseMove = new QPopupMenu(mMouseAction); |
---|
| 340 | mMouseAction->insertItem("&Move",fMouseMove); |
---|
| 341 | fMouseMove->setCheckable(true); |
---|
| 342 | |
---|
[681] | 343 | fMousePick = new QPopupMenu(mMouseAction); |
---|
| 344 | mMouseAction->insertItem("&Pick",fMousePick); |
---|
| 345 | fMousePick->setCheckable(true); |
---|
| 346 | |
---|
[707] | 347 | fMouseShortcuts = new QPopupMenu(mMouseAction); |
---|
| 348 | mMouseAction->insertItem("&Show Shortcuts",fMouseShortcuts); |
---|
| 349 | fMouseShortcuts->setCheckable(true); |
---|
| 350 | |
---|
[599] | 351 | #else |
---|
| 352 | // === Mouse menu === |
---|
| 353 | |
---|
[678] | 354 | fMouseRotate = mMouseAction->addAction("Rotate"); |
---|
| 355 | fMouseRotate->setCheckable(true); |
---|
| 356 | |
---|
[713] | 357 | fMouseMove = mMouseAction->addAction("Move"); |
---|
| 358 | fMouseMove->setCheckable(true); |
---|
| 359 | |
---|
[681] | 360 | fMousePick = mMouseAction->addAction("Pick"); |
---|
| 361 | fMousePick->setCheckable(true); |
---|
[707] | 362 | |
---|
| 363 | fMouseShortcuts = mMouseAction->addAction("Show Shortcuts"); |
---|
| 364 | fMouseShortcuts->setCheckable(true); |
---|
[599] | 365 | #endif |
---|
| 366 | |
---|
[564] | 367 | // INIT mMouse |
---|
[678] | 368 | #if QT_VERSION < 0x040000 |
---|
[709] | 369 | fMouseRotate->setItemChecked(0,true); |
---|
[564] | 370 | |
---|
[678] | 371 | QObject ::connect(fMouseRotate, |
---|
| 372 | SIGNAL(activated(int)), |
---|
| 373 | this, |
---|
| 374 | SLOT(actionMouseRotate())); |
---|
| 375 | |
---|
[713] | 376 | QObject ::connect(fMouseMove, |
---|
| 377 | SIGNAL(activated(int)), |
---|
| 378 | this, |
---|
| 379 | SLOT(actionMouseMove())); |
---|
| 380 | |
---|
[707] | 381 | QObject ::connect(fMousePick, |
---|
[678] | 382 | SIGNAL(activated(int)), |
---|
| 383 | this, |
---|
[707] | 384 | SLOT(actionMousePick())); |
---|
[678] | 385 | |
---|
[707] | 386 | QObject ::connect(fMouseShortcuts, |
---|
[678] | 387 | SIGNAL(activated(int)), |
---|
| 388 | this, |
---|
[707] | 389 | SLOT(actionMouseShortcuts())); |
---|
[678] | 390 | |
---|
| 391 | #else |
---|
| 392 | fMouseRotate->setChecked(true); |
---|
| 393 | |
---|
| 394 | QObject ::connect(fMouseRotate, |
---|
| 395 | SIGNAL(triggered(bool)), |
---|
| 396 | this, |
---|
| 397 | SLOT(actionMouseRotate())); |
---|
| 398 | |
---|
[713] | 399 | QObject ::connect(fMouseMove, |
---|
| 400 | SIGNAL(triggered(bool)), |
---|
| 401 | this, |
---|
| 402 | SLOT(actionMouseMove())); |
---|
| 403 | |
---|
[707] | 404 | QObject ::connect(fMousePick, |
---|
[678] | 405 | SIGNAL(triggered(bool)), |
---|
| 406 | this, |
---|
[707] | 407 | SLOT(actionMousePick())); |
---|
[678] | 408 | |
---|
[707] | 409 | QObject ::connect(fMouseShortcuts, |
---|
[678] | 410 | SIGNAL(triggered(bool)), |
---|
| 411 | this, |
---|
[707] | 412 | SLOT(actionMouseShortcuts())); |
---|
[678] | 413 | #endif |
---|
| 414 | |
---|
[599] | 415 | #if QT_VERSION < 0x040000 |
---|
| 416 | // === Style Menu === |
---|
| 417 | QPopupMenu *mStyle = new QPopupMenu(fContextMenu); |
---|
| 418 | |
---|
| 419 | QPopupMenu *mRepresentation = new QPopupMenu(fContextMenu); |
---|
| 420 | |
---|
[703] | 421 | QPopupMenu *mProjection = new QPopupMenu(fContextMenu); |
---|
[702] | 422 | |
---|
[617] | 423 | #if QT_VERSION < 0x030200 |
---|
[715] | 424 | QAction *polyhedron = new QAction("&Polyhedron","&Polyhedron",CTRL+Key_P,mRepresentation,0,true); |
---|
| 425 | QAction *nurbs = new QAction("&NURBS","&NURBS",CTRL+Key_N,mRepresentation,0,true); |
---|
[702] | 426 | |
---|
[715] | 427 | QAction *ortho = new QAction("&Orthographic","&Orthographic",CTRL+Key_O,mProjection,0,true); |
---|
| 428 | QAction *perspective = new QAction("&Perspective","&Perspective",CTRL+Key_P,mProjection,0,true); |
---|
[617] | 429 | #else |
---|
[599] | 430 | QAction *polyhedron = new QAction("&Polyhedron",CTRL+Key_P,mRepresentation); |
---|
| 431 | QAction *nurbs = new QAction("&NURBS",CTRL+Key_N,mRepresentation); |
---|
[702] | 432 | |
---|
| 433 | QAction *ortho = new QAction("&Orthographic",CTRL+Key_O,mProjection); |
---|
| 434 | QAction *perspective = new QAction("&Perspective",CTRL+Key_P,mProjection); |
---|
[715] | 435 | polyhedron->setToggleAction(true); |
---|
| 436 | nurbs->setToggleAction(true); |
---|
| 437 | ortho->setToggleAction(true); |
---|
| 438 | perspective->setToggleAction(true); |
---|
[617] | 439 | #endif |
---|
[599] | 440 | polyhedron->addTo(mRepresentation); |
---|
| 441 | nurbs->addTo(mRepresentation); |
---|
| 442 | |
---|
[702] | 443 | ortho->addTo(mProjection); |
---|
| 444 | perspective->addTo(mProjection); |
---|
| 445 | |
---|
[599] | 446 | mStyle->insertItem("&Representation",mRepresentation); |
---|
[702] | 447 | mStyle->insertItem("&Projection",mProjection); |
---|
[599] | 448 | fContextMenu->insertItem("&Style",mStyle); |
---|
| 449 | |
---|
[702] | 450 | |
---|
[599] | 451 | #else |
---|
| 452 | // === Style Menu === |
---|
[564] | 453 | QMenu *mStyle = fContextMenu->addMenu("&Style"); |
---|
| 454 | |
---|
| 455 | QMenu *mRepresentation = mStyle->addMenu("&Representation"); |
---|
[703] | 456 | QMenu *mProjection = mStyle->addMenu("&Projection"); |
---|
[632] | 457 | QAction *polyhedron = mRepresentation->addAction("Polyhedron"); |
---|
[564] | 458 | QAction *nurbs = mRepresentation->addAction("NURBS"); |
---|
[702] | 459 | |
---|
[703] | 460 | QAction *ortho = mProjection->addAction("Orthographic"); |
---|
| 461 | QAction *perspective = mProjection->addAction("Persepective"); |
---|
[599] | 462 | #endif |
---|
[702] | 463 | |
---|
| 464 | // INIT mRepresentation |
---|
[564] | 465 | G4ViewParameters::RepStyle style; |
---|
| 466 | style = fVP.GetRepStyle(); |
---|
| 467 | if (style == G4ViewParameters::polyhedron) { |
---|
| 468 | createRadioAction(polyhedron,nurbs,SLOT(toggleRepresentation(bool)),1); |
---|
| 469 | } else if (style == G4ViewParameters::nurbs) { |
---|
| 470 | createRadioAction(polyhedron,nurbs,SLOT(toggleRepresentation(bool)),2); |
---|
[539] | 471 | } else { |
---|
[564] | 472 | mRepresentation->clear(); |
---|
[539] | 473 | } |
---|
| 474 | |
---|
[702] | 475 | // INIT mProjection |
---|
| 476 | if (fVP.GetFieldHalfAngle() == 0) { |
---|
| 477 | createRadioAction(ortho, perspective,SLOT(toggleProjection(bool)),1); |
---|
| 478 | } else { |
---|
| 479 | createRadioAction(ortho, perspective,SLOT(toggleProjection(bool)),2); |
---|
| 480 | } |
---|
[539] | 481 | |
---|
[599] | 482 | #if QT_VERSION < 0x040000 |
---|
| 483 | // === Drawing Menu === |
---|
| 484 | QPopupMenu *mDrawing = new QPopupMenu(fContextMenu); |
---|
| 485 | fContextMenu->insertItem("&Drawing",mDrawing); |
---|
| 486 | |
---|
| 487 | fDrawingWireframe = new QPopupMenu(mDrawing); |
---|
| 488 | mDrawing->insertItem("&Wireframe",fDrawingWireframe); |
---|
| 489 | |
---|
| 490 | mDrawing->setCheckable(true); |
---|
| 491 | fDrawingWireframe->setCheckable(true); |
---|
| 492 | |
---|
| 493 | fDrawingLineRemoval = new QPopupMenu(mDrawing); |
---|
| 494 | mDrawing->insertItem("&Hidden line removal",fDrawingLineRemoval); |
---|
| 495 | fDrawingLineRemoval->setCheckable(true); |
---|
| 496 | |
---|
| 497 | fDrawingSurfaceRemoval = new QPopupMenu(mDrawing); |
---|
| 498 | mDrawing->insertItem("&Hidden surface removal",fDrawingSurfaceRemoval); |
---|
| 499 | fDrawingSurfaceRemoval->setCheckable(true); |
---|
| 500 | |
---|
| 501 | fDrawingLineSurfaceRemoval = new QPopupMenu(mDrawing); |
---|
| 502 | mDrawing->insertItem("&Hidden line and surface removal",fDrawingLineSurfaceRemoval); |
---|
| 503 | fDrawingLineSurfaceRemoval->setCheckable(true); |
---|
| 504 | |
---|
| 505 | #else |
---|
| 506 | // === Drawing Menu === |
---|
[564] | 507 | QMenu *mDrawing = mStyle->addMenu("&Drawing"); |
---|
[599] | 508 | |
---|
[564] | 509 | fDrawingWireframe = mDrawing->addAction("Wireframe"); |
---|
| 510 | fDrawingWireframe->setCheckable(true); |
---|
[599] | 511 | |
---|
[564] | 512 | fDrawingLineRemoval = mDrawing->addAction("Hidden line removal"); |
---|
| 513 | fDrawingLineRemoval->setCheckable(true); |
---|
[599] | 514 | |
---|
[564] | 515 | fDrawingSurfaceRemoval = mDrawing->addAction("Hidden Surface removal"); |
---|
| 516 | fDrawingSurfaceRemoval->setCheckable(true); |
---|
[599] | 517 | |
---|
[564] | 518 | fDrawingLineSurfaceRemoval = mDrawing->addAction("Hidden line and surface removal"); |
---|
| 519 | fDrawingLineSurfaceRemoval->setCheckable(true); |
---|
[599] | 520 | #endif |
---|
[564] | 521 | // INIT Drawing |
---|
| 522 | G4ViewParameters::DrawingStyle d_style; |
---|
| 523 | d_style = fVP.GetDrawingStyle(); |
---|
| 524 | |
---|
[599] | 525 | #if QT_VERSION < 0x040000 |
---|
[564] | 526 | if (d_style == G4ViewParameters::wireframe) { |
---|
[599] | 527 | fDrawingWireframe->setItemChecked(0,true); |
---|
| 528 | } else if (d_style == G4ViewParameters::hlr) { |
---|
| 529 | fDrawingLineRemoval->setItemChecked(0,true); |
---|
| 530 | } else if (d_style == G4ViewParameters::hsr) { |
---|
| 531 | fDrawingSurfaceRemoval->setItemChecked(0,true); |
---|
| 532 | } else if (d_style == G4ViewParameters::hlhsr) { |
---|
| 533 | fDrawingLineSurfaceRemoval->setItemChecked(0,true); |
---|
| 534 | } else { |
---|
| 535 | mDrawing->clear(); |
---|
| 536 | } |
---|
[610] | 537 | #ifdef GEANT4_QT_DEBUG |
---|
| 538 | printf("G4OpenGLQtViewer:: fDrawingWireframe 1\n"); |
---|
| 539 | #endif |
---|
| 540 | QObject ::connect(fDrawingWireframe, |
---|
| 541 | SIGNAL(activated(int)), |
---|
| 542 | this, |
---|
| 543 | SLOT(actionDrawingWireframe())); |
---|
| 544 | #ifdef GEANT4_QT_DEBUG |
---|
| 545 | printf("G4OpenGLQtViewer:: fDrawingWireframe 2\n"); |
---|
| 546 | #endif |
---|
| 547 | QObject ::connect(fDrawingLineRemoval, |
---|
| 548 | SIGNAL(activated(int)), |
---|
| 549 | this, |
---|
| 550 | SLOT(actionDrawingLineRemoval())); |
---|
| 551 | QObject ::connect(fDrawingSurfaceRemoval, |
---|
| 552 | SIGNAL(activated(int)), |
---|
| 553 | this, |
---|
| 554 | SLOT(actionDrawingSurfaceRemoval())); |
---|
| 555 | QObject ::connect(fDrawingLineSurfaceRemoval, |
---|
| 556 | SIGNAL(activated(int)), |
---|
| 557 | this, |
---|
| 558 | SLOT(actionDrawingLineSurfaceRemoval())); |
---|
[599] | 559 | #else |
---|
| 560 | if (d_style == G4ViewParameters::wireframe) { |
---|
[564] | 561 | fDrawingWireframe->setChecked(true); |
---|
| 562 | } else if (d_style == G4ViewParameters::hlr) { |
---|
| 563 | fDrawingLineRemoval->setChecked(true); |
---|
| 564 | } else if (d_style == G4ViewParameters::hsr) { |
---|
| 565 | fDrawingSurfaceRemoval->setChecked(true); |
---|
| 566 | } else if (d_style == G4ViewParameters::hlhsr) { |
---|
| 567 | fDrawingLineSurfaceRemoval->setChecked(true); |
---|
| 568 | } else { |
---|
| 569 | mDrawing->clear(); |
---|
| 570 | } |
---|
[565] | 571 | QObject ::connect(fDrawingWireframe, |
---|
| 572 | SIGNAL(triggered(bool)), |
---|
| 573 | this, |
---|
| 574 | SLOT(actionDrawingWireframe())); |
---|
| 575 | QObject ::connect(fDrawingLineRemoval, |
---|
| 576 | SIGNAL(triggered(bool)), |
---|
| 577 | this, |
---|
| 578 | SLOT(actionDrawingLineRemoval())); |
---|
| 579 | QObject ::connect(fDrawingSurfaceRemoval, |
---|
| 580 | SIGNAL(triggered(bool)), |
---|
| 581 | this, |
---|
| 582 | SLOT(actionDrawingSurfaceRemoval())); |
---|
| 583 | QObject ::connect(fDrawingLineSurfaceRemoval, |
---|
| 584 | SIGNAL(triggered(bool)), |
---|
| 585 | this, |
---|
| 586 | SLOT(actionDrawingLineSurfaceRemoval())); |
---|
[610] | 587 | #endif |
---|
[564] | 588 | |
---|
| 589 | |
---|
[610] | 590 | |
---|
[599] | 591 | #if QT_VERSION < 0x040000 |
---|
| 592 | QPopupMenu *mBackground = new QPopupMenu(mStyle); |
---|
| 593 | mStyle->insertItem("&Background color",mBackground); |
---|
| 594 | |
---|
[617] | 595 | #if QT_VERSION < 0x030200 |
---|
[715] | 596 | QAction *white = new QAction("&White","&White",CTRL+Key_W,mBackground,0,true); |
---|
| 597 | QAction *black = new QAction("&Black","&Black",CTRL+Key_B,mBackground,0,true); |
---|
[617] | 598 | #else |
---|
[599] | 599 | QAction *white = new QAction("&White",CTRL+Key_W,mBackground); |
---|
| 600 | QAction *black = new QAction("&Black",CTRL+Key_B,mBackground); |
---|
[715] | 601 | white->setToggleAction(true); |
---|
| 602 | black->setToggleAction(true); |
---|
[617] | 603 | #endif |
---|
[599] | 604 | white->addTo(mBackground); |
---|
| 605 | black->addTo(mBackground); |
---|
| 606 | |
---|
| 607 | #else |
---|
[564] | 608 | QMenu *mBackground = mStyle->addMenu("&Background color"); |
---|
| 609 | QAction *white = mBackground->addAction("White"); |
---|
| 610 | QAction *black = mBackground->addAction("Black"); |
---|
[599] | 611 | |
---|
| 612 | #endif |
---|
[564] | 613 | if (background.GetRed() == 1. && |
---|
| 614 | background.GetGreen() == 1. && |
---|
| 615 | background.GetBlue() == 1.) { |
---|
| 616 | createRadioAction(white,black,SLOT(toggleBackground(bool)),1); |
---|
| 617 | } else { |
---|
| 618 | createRadioAction(white,black,SLOT(toggleBackground(bool)),2); |
---|
| 619 | } |
---|
| 620 | |
---|
| 621 | |
---|
[599] | 622 | #if QT_VERSION < 0x040000 |
---|
| 623 | // === Action Menu === |
---|
| 624 | QPopupMenu *mActions = new QPopupMenu(fContextMenu); |
---|
| 625 | fContextMenu->insertItem("&Actions",mActions); |
---|
| 626 | |
---|
[617] | 627 | #if QT_VERSION < 0x030200 |
---|
[715] | 628 | QAction *createEPS = new QAction("&Save as ...","&Save as ...",CTRL+Key_S,mActions,0,true); |
---|
[617] | 629 | #else |
---|
[599] | 630 | QAction *createEPS = new QAction("&Save as ...",CTRL+Key_S,mActions); |
---|
[715] | 631 | createEPS->setToggleAction(true); |
---|
[617] | 632 | #endif |
---|
[599] | 633 | createEPS->addTo(mActions); |
---|
[610] | 634 | QObject ::connect(createEPS, |
---|
| 635 | SIGNAL(activated()), |
---|
| 636 | this, |
---|
| 637 | SLOT(actionCreateEPS())); |
---|
[599] | 638 | |
---|
| 639 | #else |
---|
| 640 | // === Action Menu === |
---|
[564] | 641 | QMenu *mActions = fContextMenu->addMenu("&Actions"); |
---|
[568] | 642 | QAction *createEPS = mActions->addAction("Save as ..."); |
---|
[565] | 643 | QObject ::connect(createEPS, |
---|
[566] | 644 | SIGNAL(triggered()), |
---|
[565] | 645 | this, |
---|
| 646 | SLOT(actionCreateEPS())); |
---|
[610] | 647 | #endif |
---|
[564] | 648 | |
---|
| 649 | |
---|
[610] | 650 | |
---|
[599] | 651 | #if QT_VERSION < 0x040000 |
---|
| 652 | // === Special Menu === |
---|
| 653 | QPopupMenu *mSpecial = new QPopupMenu(fContextMenu); |
---|
| 654 | fContextMenu->insertItem("S&pecial",mSpecial); |
---|
| 655 | |
---|
| 656 | QPopupMenu *mTransparency = new QPopupMenu(mSpecial); |
---|
| 657 | mSpecial->insertItem("Transparency",mTransparency); |
---|
| 658 | |
---|
[617] | 659 | #if QT_VERSION < 0x030200 |
---|
[715] | 660 | QAction *transparencyOn = new QAction("&On","&On",CTRL+Key_O,mTransparency,0,true); |
---|
| 661 | QAction *transparencyOff = new QAction("&Off","&Off",CTRL+Key_F,mTransparency,0,true); |
---|
[617] | 662 | #else |
---|
[599] | 663 | QAction *transparencyOn = new QAction("&On",CTRL+Key_O,mTransparency); |
---|
| 664 | QAction *transparencyOff = new QAction("&Off",CTRL+Key_F,mTransparency); |
---|
[715] | 665 | transparencyOn->setToggleAction(true); |
---|
| 666 | transparencyOff->setToggleAction(true); |
---|
[617] | 667 | #endif |
---|
[599] | 668 | transparencyOn->addTo(mTransparency); |
---|
| 669 | transparencyOff->addTo(mTransparency); |
---|
| 670 | |
---|
| 671 | #else |
---|
| 672 | // === Special Menu === |
---|
[564] | 673 | QMenu *mSpecial = fContextMenu->addMenu("S&pecial"); |
---|
[599] | 674 | QMenu *mTransparency = mSpecial->addMenu("Transparency"); |
---|
| 675 | QAction *transparencyOn = mTransparency->addAction("On"); |
---|
| 676 | QAction *transparencyOff = mTransparency->addAction("Off"); |
---|
| 677 | #endif |
---|
| 678 | |
---|
[564] | 679 | if (transparency_enabled == false) { |
---|
| 680 | createRadioAction(transparencyOn,transparencyOff,SLOT(toggleTransparency(bool)),2); |
---|
| 681 | } else if (transparency_enabled == true) { |
---|
| 682 | createRadioAction(transparencyOn,transparencyOff,SLOT(toggleTransparency(bool)),1); |
---|
| 683 | } else { |
---|
| 684 | mSpecial->clear(); |
---|
| 685 | } |
---|
| 686 | |
---|
| 687 | |
---|
[599] | 688 | #if QT_VERSION < 0x040000 |
---|
| 689 | QPopupMenu *mAntialiasing = new QPopupMenu(mSpecial); |
---|
| 690 | mSpecial->insertItem("Antialiasing",mAntialiasing); |
---|
| 691 | |
---|
[617] | 692 | #if QT_VERSION < 0x030200 |
---|
[715] | 693 | QAction *antialiasingOn = new QAction("&On","&On",CTRL+Key_O,mAntialiasing,0,true); |
---|
| 694 | QAction *antialiasingOff = new QAction("&Off","&Off",CTRL+Key_F,mAntialiasing,0,true); |
---|
[617] | 695 | #else |
---|
[599] | 696 | QAction *antialiasingOn = new QAction("&On",CTRL+Key_O,mAntialiasing); |
---|
| 697 | QAction *antialiasingOff = new QAction("&Off",CTRL+Key_F,mAntialiasing); |
---|
[715] | 698 | antialiasingOn->setToggleAction(true); |
---|
| 699 | antialiasingOff->setToggleAction(true); |
---|
[617] | 700 | #endif |
---|
[599] | 701 | antialiasingOn->addTo(mAntialiasing); |
---|
| 702 | antialiasingOff->addTo(mAntialiasing); |
---|
| 703 | |
---|
| 704 | #else |
---|
[564] | 705 | QMenu *mAntialiasing = mSpecial->addMenu("Antialiasing"); |
---|
| 706 | QAction *antialiasingOn = mAntialiasing->addAction("On"); |
---|
| 707 | QAction *antialiasingOff = mAntialiasing->addAction("Off"); |
---|
[599] | 708 | #endif |
---|
| 709 | |
---|
[564] | 710 | if (antialiasing_enabled == false) { |
---|
| 711 | createRadioAction(antialiasingOn,antialiasingOff,SLOT(toggleAntialiasing(bool)),2); |
---|
| 712 | } else if (antialiasing_enabled == true) { |
---|
| 713 | createRadioAction(antialiasingOn,antialiasingOff,SLOT(toggleAntialiasing(bool)),1); |
---|
| 714 | } else { |
---|
| 715 | mAntialiasing->clear(); |
---|
| 716 | } |
---|
| 717 | |
---|
[599] | 718 | #if QT_VERSION < 0x040000 |
---|
| 719 | QPopupMenu *mHaloing = new QPopupMenu(mSpecial); |
---|
| 720 | mSpecial->insertItem("Haloing",mHaloing); |
---|
| 721 | |
---|
[617] | 722 | #if QT_VERSION < 0x030200 |
---|
[715] | 723 | QAction *haloingOn = new QAction("&On","&On",CTRL+Key_O,mHaloing,0,true); |
---|
| 724 | QAction *haloingOff = new QAction("&Off","&Off",CTRL+Key_F,mHaloing,0,true); |
---|
[617] | 725 | #else |
---|
[599] | 726 | QAction *haloingOn = new QAction("&On",CTRL+Key_O,mHaloing); |
---|
| 727 | QAction *haloingOff = new QAction("&Off",CTRL+Key_F,mHaloing); |
---|
[715] | 728 | haloingOn->setToggleAction(true); |
---|
| 729 | haloingOff->setToggleAction(true); |
---|
[617] | 730 | #endif |
---|
[599] | 731 | haloingOn->addTo(mHaloing); |
---|
| 732 | haloingOff->addTo(mHaloing); |
---|
| 733 | #else |
---|
[564] | 734 | QMenu *mHaloing = mSpecial->addMenu("Haloing"); |
---|
| 735 | QAction *haloingOn = mHaloing->addAction("On"); |
---|
| 736 | QAction *haloingOff = mHaloing->addAction("Off"); |
---|
[599] | 737 | #endif |
---|
[564] | 738 | if (haloing_enabled == false) { |
---|
| 739 | createRadioAction(haloingOn,haloingOff,SLOT(toggleHaloing(bool)),2); |
---|
| 740 | } else if (haloing_enabled == true) { |
---|
| 741 | createRadioAction(haloingOn,haloingOff,SLOT(toggleHaloing(bool)),1); |
---|
| 742 | } else { |
---|
| 743 | mHaloing->clear(); |
---|
| 744 | } |
---|
| 745 | |
---|
[599] | 746 | #if QT_VERSION < 0x040000 |
---|
| 747 | QPopupMenu *mAux = new QPopupMenu(mSpecial); |
---|
| 748 | mSpecial->insertItem("Auxiliairy edges",mAux); |
---|
| 749 | |
---|
[617] | 750 | #if QT_VERSION < 0x030200 |
---|
[715] | 751 | QAction *auxOn = new QAction("&On","&On",CTRL+Key_O,mAux,0,true); |
---|
| 752 | QAction *auxOff = new QAction("&Off","&Off",CTRL+Key_F,mAux,0,true); |
---|
[617] | 753 | #else |
---|
[599] | 754 | QAction *auxOn = new QAction("&On",CTRL+Key_O,mAux); |
---|
| 755 | QAction *auxOff = new QAction("&Off",CTRL+Key_F,mAux); |
---|
[715] | 756 | auxOn->setToggleAction(true); |
---|
| 757 | auxOff->setToggleAction(true); |
---|
[617] | 758 | #endif |
---|
[599] | 759 | auxOn->addTo(mAux); |
---|
| 760 | auxOff->addTo(mAux); |
---|
| 761 | |
---|
| 762 | #else |
---|
[564] | 763 | QMenu *mAux = mSpecial->addMenu("Auxiliary edges"); |
---|
| 764 | QAction *auxOn = mAux->addAction("On"); |
---|
| 765 | QAction *auxOff = mAux->addAction("Off"); |
---|
[599] | 766 | #endif |
---|
[564] | 767 | if (!fVP.IsAuxEdgeVisible()) { |
---|
| 768 | createRadioAction(auxOn,auxOff,SLOT(toggleAux(bool)),1); |
---|
| 769 | } else { |
---|
| 770 | createRadioAction(auxOn,auxOff,SLOT(toggleAux(bool)),2); |
---|
| 771 | } |
---|
| 772 | |
---|
| 773 | |
---|
[715] | 774 | |
---|
[599] | 775 | #if QT_VERSION < 0x040000 |
---|
| 776 | QPopupMenu *mFullScreen = new QPopupMenu(mSpecial); |
---|
| 777 | mSpecial->insertItem("Full screen",mFullScreen); |
---|
| 778 | |
---|
[715] | 779 | #if QT_VERSION < 0x030200 |
---|
| 780 | QAction *fullOn = new QAction("&On","&On",CTRL+Key_O,mFullScreen,0,true); |
---|
| 781 | QAction *fullOff = new QAction("&Off","&Off",CTRL+Key_F,mFullScreen,0,true); |
---|
| 782 | #else |
---|
[599] | 783 | QAction *fullOn = new QAction("&On",CTRL+Key_O,mFullScreen); |
---|
| 784 | QAction *fullOff = new QAction("&Off",CTRL+Key_F,mFullScreen); |
---|
[715] | 785 | fullOn->setToggleAction(true); |
---|
| 786 | fullOff->setToggleAction(true); |
---|
| 787 | #endif |
---|
[599] | 788 | fullOn->addTo(mFullScreen); |
---|
| 789 | fullOff->addTo(mFullScreen); |
---|
| 790 | #else |
---|
[715] | 791 | QMenu *mFullScreen = mSpecial->addMenu("&Full screen"); |
---|
[564] | 792 | QAction *fullOn = mFullScreen->addAction("On"); |
---|
| 793 | QAction *fullOff = mFullScreen->addAction("Off"); |
---|
[599] | 794 | #endif |
---|
[704] | 795 | createRadioAction(fullOn,fullOff,SLOT(toggleFullScreen()),2); |
---|
[564] | 796 | |
---|
| 797 | } |
---|
| 798 | |
---|
| 799 | void G4OpenGLQtViewer::manageContextMenuEvent(QContextMenuEvent *e) |
---|
| 800 | { |
---|
[579] | 801 | if (!GLWindow) { |
---|
[638] | 802 | G4cerr << "Visualization window not defined, please choose one before\n" << G4endl; |
---|
[579] | 803 | } else { |
---|
[539] | 804 | |
---|
[579] | 805 | if (!fContextMenu) |
---|
| 806 | createPopupMenu(); |
---|
| 807 | |
---|
| 808 | // launch menu |
---|
| 809 | if ( fContextMenu ) { |
---|
| 810 | fContextMenu->exec( e->globalPos() ); |
---|
| 811 | // delete fContextMenu; |
---|
| 812 | } |
---|
[564] | 813 | } |
---|
| 814 | e->accept(); |
---|
| 815 | } |
---|
[539] | 816 | |
---|
| 817 | |
---|
[564] | 818 | /** |
---|
| 819 | Create a radio button menu. The two menu will be connected. When click on one, |
---|
| 820 | eatch state will be invert and callback method will be called. |
---|
| 821 | @param action1 first action to connect |
---|
| 822 | @param action2 second action to connect |
---|
| 823 | @param method callback method |
---|
| 824 | @param nCheck: 1 : first action will be set true. 2 : second action will be set true |
---|
| 825 | */ |
---|
[599] | 826 | #if QT_VERSION < 0x040000 |
---|
[564] | 827 | void G4OpenGLQtViewer::createRadioAction(QAction *action1,QAction *action2, const std::string& method,unsigned int nCheck) { |
---|
| 828 | |
---|
[599] | 829 | if (action1->parent()->inherits("QPopupMenu")){ |
---|
| 830 | ((QPopupMenu*)action1->parent())->setCheckable(true); |
---|
[715] | 831 | ((QPopupMenu*)action2->parent())->setCheckable(true); |
---|
[599] | 832 | } |
---|
[715] | 833 | action1->setOn(false); |
---|
| 834 | action2->setOn(false); |
---|
[599] | 835 | |
---|
| 836 | if (nCheck ==1) |
---|
[715] | 837 | action1->setOn(true); |
---|
[599] | 838 | else |
---|
[715] | 839 | action2->setOn(true); |
---|
[599] | 840 | |
---|
[610] | 841 | QObject ::connect(action1, SIGNAL(activated()),action2, SLOT(toggle())); |
---|
| 842 | QObject ::connect(action2, SIGNAL(activated()),action1, SLOT(toggle())); |
---|
[599] | 843 | |
---|
| 844 | QObject ::connect(action1, SIGNAL(toggled(bool)),this, method.c_str()); |
---|
| 845 | } |
---|
| 846 | |
---|
| 847 | #else |
---|
| 848 | void G4OpenGLQtViewer::createRadioAction(QAction *action1,QAction *action2, const std::string& method,unsigned int nCheck) { |
---|
| 849 | |
---|
[564] | 850 | action1->setCheckable(true); |
---|
| 851 | action2->setCheckable(true); |
---|
| 852 | |
---|
| 853 | if (nCheck ==1) |
---|
| 854 | action1->setChecked (true); |
---|
| 855 | else |
---|
| 856 | action2->setChecked (true); |
---|
| 857 | |
---|
| 858 | QObject ::connect(action1, SIGNAL(triggered(bool)),action2, SLOT(toggle())); |
---|
| 859 | QObject ::connect(action2, SIGNAL(triggered(bool)),action1, SLOT(toggle())); |
---|
| 860 | |
---|
| 861 | QObject ::connect(action1, SIGNAL(toggled(bool)),this, method.c_str()); |
---|
| 862 | |
---|
| 863 | } |
---|
[599] | 864 | #endif |
---|
[564] | 865 | |
---|
| 866 | /** |
---|
[678] | 867 | Slot activate when mouseAction->rotate menu is set |
---|
| 868 | */ |
---|
| 869 | void G4OpenGLQtViewer::actionMouseRotate() { |
---|
[696] | 870 | emit toggleMouseAction(STYLE1); |
---|
[678] | 871 | } |
---|
| 872 | |
---|
| 873 | |
---|
| 874 | /** |
---|
[713] | 875 | Slot activate when mouseAction->rotate menu is set |
---|
| 876 | */ |
---|
| 877 | void G4OpenGLQtViewer::actionMouseMove() { |
---|
| 878 | emit toggleMouseAction(STYLE2); |
---|
| 879 | } |
---|
| 880 | |
---|
| 881 | |
---|
| 882 | /** |
---|
[707] | 883 | Slot activate when mouseAction->zoom menu is set |
---|
[678] | 884 | */ |
---|
[707] | 885 | void G4OpenGLQtViewer::actionMousePick() { |
---|
[678] | 886 | #ifdef GEANT4_QT_DEBUG |
---|
[707] | 887 | printf("G4OpenGLQtViewer::actionMousePick \n"); |
---|
[678] | 888 | #endif |
---|
[696] | 889 | emit toggleMouseAction(STYLE3); |
---|
[678] | 890 | } |
---|
| 891 | |
---|
| 892 | /** |
---|
[681] | 893 | Slot activate when mouseAction->zoom menu is set |
---|
| 894 | */ |
---|
[707] | 895 | void G4OpenGLQtViewer::actionMouseShortcuts() { |
---|
[681] | 896 | #ifdef GEANT4_QT_DEBUG |
---|
[707] | 897 | printf("G4OpenGLQtViewer::actionMouseShortcuts \n"); |
---|
[681] | 898 | #endif |
---|
[713] | 899 | emit toggleMouseAction(STYLE4); |
---|
[681] | 900 | } |
---|
| 901 | |
---|
| 902 | /** |
---|
[564] | 903 | Slot activate when drawing->wireframe menu is set |
---|
| 904 | */ |
---|
| 905 | void G4OpenGLQtViewer::actionDrawingWireframe() { |
---|
| 906 | emit toggleDrawingAction(1); |
---|
| 907 | } |
---|
| 908 | |
---|
| 909 | /** |
---|
| 910 | Slot activate when drawing->line removal menu is set |
---|
| 911 | */ |
---|
| 912 | void G4OpenGLQtViewer::actionDrawingLineRemoval() { |
---|
| 913 | emit toggleDrawingAction(2); |
---|
| 914 | } |
---|
| 915 | |
---|
| 916 | /** |
---|
| 917 | Slot activate when drawing->surface removal menu is set |
---|
| 918 | */ |
---|
| 919 | void G4OpenGLQtViewer::actionDrawingSurfaceRemoval() { |
---|
| 920 | emit toggleDrawingAction(3); |
---|
| 921 | } |
---|
| 922 | |
---|
| 923 | /** |
---|
| 924 | Slot activate when drawing->wireframe menu is set |
---|
| 925 | */ |
---|
| 926 | void G4OpenGLQtViewer::actionDrawingLineSurfaceRemoval() { |
---|
| 927 | emit toggleDrawingAction(4); |
---|
| 928 | } |
---|
| 929 | |
---|
| 930 | |
---|
| 931 | /** |
---|
[678] | 932 | Slot activated when mouse action is toggle |
---|
[696] | 933 | @param aAction : STYLE1, STYLE2, STYLE3 |
---|
[678] | 934 | */ |
---|
| 935 | void G4OpenGLQtViewer::toggleMouseAction(mouseActions aAction) { |
---|
| 936 | |
---|
[713] | 937 | if ((aAction == STYLE1) || //initialize all |
---|
| 938 | (aAction == STYLE2) || |
---|
| 939 | (aAction == STYLE3) || |
---|
| 940 | (aAction == STYLE4)) { |
---|
| 941 | #if QT_VERSION < 0x040000 |
---|
| 942 | fMouseRotate->setItemChecked (0,false); |
---|
| 943 | fMouseMove->setItemChecked (0,false); |
---|
| 944 | fMousePick->setItemChecked (0,false); |
---|
| 945 | fMouseShortcuts->setItemChecked (0,false); |
---|
| 946 | #else |
---|
| 947 | fMouseRotate->setChecked (false); |
---|
| 948 | fMouseMove->setChecked (false); |
---|
| 949 | fMousePick->setChecked (false); |
---|
| 950 | fMouseShortcuts->setChecked (false); |
---|
| 951 | #endif |
---|
| 952 | fVP.SetPicking(false); |
---|
| 953 | fMouseAction = aAction; |
---|
| 954 | } |
---|
| 955 | // rotate |
---|
[707] | 956 | if (aAction == STYLE1) { // rotate |
---|
| 957 | G4cout << "Click and move mouse to rotate volume \n" << G4endl; |
---|
| 958 | G4cout << "Press left/right arrows to move volume left/right\n" << G4endl; |
---|
| 959 | G4cout << "Press up/down arrows to move volume up/down\n" << G4endl; |
---|
| 960 | G4cout << "Press CONTROL+up/down arrows to move volume toward/forward\n" << G4endl; |
---|
| 961 | G4cout << "Press SHIFT+left/right arrows to rotate volume left/right\n" << G4endl; |
---|
| 962 | G4cout << "Press SHIFT+up/down arrows to rotate volume up/down\n" << G4endl; |
---|
[696] | 963 | G4cout << "Press +/- to zoom into volume\n" << G4endl; |
---|
[678] | 964 | #if QT_VERSION < 0x040000 |
---|
| 965 | fMouseRotate->setItemChecked (0,true); |
---|
| 966 | #else |
---|
| 967 | fMouseRotate->setChecked (true); |
---|
| 968 | #endif |
---|
[713] | 969 | } else if (aAction == STYLE2) { //move |
---|
| 970 | G4cout << "Move camera point of view with mouse\n" << G4endl; |
---|
| 971 | #if QT_VERSION < 0x040000 |
---|
| 972 | fMouseMove->setItemChecked (0,true); |
---|
| 973 | #else |
---|
| 974 | fMouseMove->setChecked (true); |
---|
| 975 | #endif |
---|
| 976 | } else if (aAction == STYLE3) { //pick |
---|
[707] | 977 | G4cout << "Click and pick \n" << G4endl; |
---|
[678] | 978 | #if QT_VERSION < 0x040000 |
---|
[707] | 979 | fMousePick->setItemChecked (0,true); |
---|
[678] | 980 | #else |
---|
[707] | 981 | fMousePick->setChecked (true); |
---|
[678] | 982 | #endif |
---|
[707] | 983 | fVP.SetPicking(true); |
---|
[713] | 984 | } else if (aAction == STYLE4) { // display shortcuts |
---|
[678] | 985 | #if QT_VERSION < 0x040000 |
---|
[707] | 986 | fMouseShortcuts->setItemChecked (0,true); |
---|
[678] | 987 | #else |
---|
[707] | 988 | fMouseShortcuts->setChecked (true); |
---|
[678] | 989 | #endif |
---|
[707] | 990 | |
---|
| 991 | G4cout << "Click and move mouse to rotate volume \n" << G4endl; |
---|
| 992 | G4cout << "Press left/right arrows to move volume left/right\n" << G4endl; |
---|
| 993 | G4cout << "Press up/down arrows to move volume up/down\n" << G4endl; |
---|
| 994 | G4cout << "Press CONTROL+up/down arrows to move volume toward/forward\n" << G4endl; |
---|
| 995 | G4cout << "Press SHIFT+left/right arrows to rotate volume left/right\n" << G4endl; |
---|
| 996 | G4cout << "Press SHIFT+up/down arrows to rotate volume up/down\n" << G4endl; |
---|
| 997 | G4cout << "Press +/- to zoom into volume\n" << G4endl; |
---|
[678] | 998 | } |
---|
| 999 | |
---|
| 1000 | } |
---|
| 1001 | /** |
---|
[565] | 1002 | Slot activated when drawing menu is toggle |
---|
| 1003 | Warning : When G4OpenGLStoredQtViewer::DrawView() method call, |
---|
| 1004 | KernelVisitDecision () will be call and will set the fNeedKernelVisit |
---|
| 1005 | to 1. See G4XXXStoredViewer::CompareForKernelVisit for explanations. |
---|
| 1006 | It will cause a redraw of the view |
---|
| 1007 | @param aAction : 1 wireframe, 2 line removal, 3 surface removal, 4 line & surface removal |
---|
| 1008 | @see G4OpenGLStoredQtViewer::DrawView |
---|
| 1009 | @see G4XXXStoredViewer::CompareForKernelVisit |
---|
[564] | 1010 | */ |
---|
| 1011 | void G4OpenGLQtViewer::toggleDrawingAction(int aAction) { |
---|
| 1012 | |
---|
| 1013 | G4ViewParameters::DrawingStyle d_style; |
---|
[539] | 1014 | |
---|
| 1015 | |
---|
[564] | 1016 | if (aAction ==1) { |
---|
[600] | 1017 | #if QT_VERSION < 0x040000 |
---|
| 1018 | fDrawingWireframe->setItemChecked (0,true); |
---|
| 1019 | fDrawingLineRemoval->setItemChecked (0,false); |
---|
| 1020 | fDrawingSurfaceRemoval->setItemChecked (0,false); |
---|
| 1021 | fDrawingLineSurfaceRemoval->setItemChecked (0,false); |
---|
| 1022 | #else |
---|
[564] | 1023 | fDrawingWireframe->setChecked (true); |
---|
| 1024 | fDrawingLineRemoval->setChecked (false); |
---|
| 1025 | fDrawingSurfaceRemoval->setChecked (false); |
---|
| 1026 | fDrawingLineSurfaceRemoval->setChecked (false); |
---|
[600] | 1027 | #endif |
---|
[564] | 1028 | |
---|
| 1029 | d_style = G4ViewParameters::wireframe; |
---|
| 1030 | |
---|
| 1031 | } else if (aAction ==2) { |
---|
[600] | 1032 | #if QT_VERSION < 0x040000 |
---|
| 1033 | fDrawingWireframe->setItemChecked (0,false); |
---|
| 1034 | fDrawingLineRemoval->setItemChecked (0,true); |
---|
| 1035 | fDrawingSurfaceRemoval->setItemChecked (0,false); |
---|
| 1036 | fDrawingLineSurfaceRemoval->setItemChecked (0,false); |
---|
| 1037 | #else |
---|
[564] | 1038 | fDrawingWireframe->setChecked (false); |
---|
| 1039 | fDrawingLineRemoval->setChecked (true); |
---|
| 1040 | fDrawingSurfaceRemoval->setChecked (false); |
---|
| 1041 | fDrawingLineSurfaceRemoval->setChecked (false); |
---|
[600] | 1042 | #endif |
---|
[564] | 1043 | |
---|
| 1044 | d_style = G4ViewParameters::hlr; |
---|
| 1045 | |
---|
| 1046 | } else if (aAction ==3) { |
---|
[600] | 1047 | #if QT_VERSION < 0x040000 |
---|
| 1048 | fDrawingWireframe->setItemChecked (0,false); |
---|
| 1049 | fDrawingLineRemoval->setItemChecked (0,false); |
---|
| 1050 | fDrawingSurfaceRemoval->setItemChecked (0,true); |
---|
| 1051 | fDrawingLineSurfaceRemoval->setItemChecked (0,false); |
---|
| 1052 | #else |
---|
[564] | 1053 | fDrawingWireframe->setChecked (false); |
---|
| 1054 | fDrawingLineRemoval->setChecked (false); |
---|
| 1055 | fDrawingSurfaceRemoval->setChecked (true); |
---|
| 1056 | fDrawingLineSurfaceRemoval->setChecked (false); |
---|
[600] | 1057 | #endif |
---|
[564] | 1058 | |
---|
| 1059 | d_style = G4ViewParameters::hsr; |
---|
| 1060 | |
---|
| 1061 | } else if (aAction ==4) { |
---|
[600] | 1062 | #if QT_VERSION < 0x040000 |
---|
| 1063 | fDrawingWireframe->setItemChecked (0,false); |
---|
| 1064 | fDrawingLineRemoval->setItemChecked (0,false); |
---|
| 1065 | fDrawingSurfaceRemoval->setItemChecked (0,false); |
---|
| 1066 | fDrawingLineSurfaceRemoval->setItemChecked (0,true); |
---|
| 1067 | #else |
---|
[564] | 1068 | fDrawingWireframe->setChecked (false); |
---|
| 1069 | fDrawingLineRemoval->setChecked (false); |
---|
| 1070 | fDrawingSurfaceRemoval->setChecked (false); |
---|
| 1071 | fDrawingLineSurfaceRemoval->setChecked (true); |
---|
[600] | 1072 | #endif |
---|
[564] | 1073 | d_style = G4ViewParameters::hlhsr; |
---|
| 1074 | } |
---|
| 1075 | fVP.SetDrawingStyle(d_style); |
---|
| 1076 | |
---|
| 1077 | updateQWidget(); |
---|
[608] | 1078 | #ifdef GEANT4_QT_DEBUG |
---|
[564] | 1079 | printf("G4OpenGLQtViewer::toggleDrawingAction\n"); |
---|
[608] | 1080 | #endif |
---|
[539] | 1081 | } |
---|
| 1082 | |
---|
[564] | 1083 | |
---|
| 1084 | /** |
---|
| 1085 | SLOT Activate by a click on the representation menu |
---|
[565] | 1086 | Warning : When G4OpenGLStoredQtViewer::DrawView() method call, |
---|
| 1087 | KernelVisitDecision () will be call and will set the fNeedKernelVisit |
---|
| 1088 | to 1. See G4XXXStoredViewer::CompareForKernelVisit for explanations. |
---|
| 1089 | It will cause a redraw of the view |
---|
[564] | 1090 | @param check : 1 polyhedron, 0 nurbs |
---|
[565] | 1091 | @see G4OpenGLStoredQtViewer::DrawView |
---|
| 1092 | @see G4XXXStoredViewer::CompareForKernelVisit |
---|
[564] | 1093 | */ |
---|
| 1094 | void G4OpenGLQtViewer::toggleRepresentation(bool check) { |
---|
| 1095 | |
---|
| 1096 | G4ViewParameters::RepStyle style; |
---|
| 1097 | if (check == 1) { |
---|
| 1098 | style = G4ViewParameters::polyhedron; |
---|
| 1099 | } else { |
---|
| 1100 | style = G4ViewParameters::nurbs; |
---|
| 1101 | } |
---|
| 1102 | fVP.SetRepStyle (style); |
---|
| 1103 | |
---|
| 1104 | updateQWidget(); |
---|
[530] | 1105 | } |
---|
| 1106 | |
---|
[564] | 1107 | /** |
---|
[702] | 1108 | SLOT Activate by a click on the projection menu |
---|
| 1109 | Warning : When G4OpenGLStoredQtViewer::DrawView() method call, |
---|
| 1110 | KernelVisitDecision () will be call and will set the fNeedKernelVisit |
---|
| 1111 | to 1. See G4XXXStoredViewer::CompareForKernelVisit for explanations. |
---|
| 1112 | It will cause a redraw of the view |
---|
| 1113 | @param check : 1 orthographic, 2 perspective |
---|
| 1114 | @see G4OpenGLStoredQtViewer::DrawView |
---|
| 1115 | @see G4XXXStoredViewer::CompareForKernelVisit |
---|
| 1116 | */ |
---|
| 1117 | void G4OpenGLQtViewer::toggleProjection(bool check) { |
---|
| 1118 | |
---|
| 1119 | if (check == 1) { |
---|
| 1120 | fVP.SetFieldHalfAngle (0); |
---|
| 1121 | } else { |
---|
[703] | 1122 | |
---|
[702] | 1123 | // look for the default parameter hidden in G4UIcommand parameters |
---|
| 1124 | G4UImanager* UI = G4UImanager::GetUIpointer(); |
---|
| 1125 | if(UI==NULL) |
---|
| 1126 | return; |
---|
| 1127 | G4UIcommandTree * treeTop = UI->GetTree(); |
---|
| 1128 | |
---|
| 1129 | // find command |
---|
| 1130 | G4UIcommand* command = treeTop->FindPath("/vis/viewer/set/projection"); |
---|
| 1131 | if (!command) |
---|
| 1132 | return; |
---|
| 1133 | |
---|
| 1134 | // find param |
---|
[703] | 1135 | G4UIparameter * angleParam = NULL; |
---|
[702] | 1136 | for(G4int i=0; i<command->GetParameterEntries(); i++) |
---|
| 1137 | { |
---|
| 1138 | if( command->GetParameter(i)->GetParameterName() == "field-half-angle" ) { |
---|
[703] | 1139 | angleParam = command->GetParameter(i); |
---|
[702] | 1140 | } |
---|
| 1141 | } |
---|
[703] | 1142 | if (!angleParam) |
---|
[702] | 1143 | return; |
---|
[703] | 1144 | |
---|
| 1145 | // find unit |
---|
| 1146 | G4UIparameter * unitParam = NULL; |
---|
| 1147 | for(G4int i=0; i<command->GetParameterEntries(); i++) |
---|
| 1148 | { |
---|
| 1149 | if( command->GetParameter(i)->GetParameterName() == "unit" ) { |
---|
| 1150 | unitParam = command->GetParameter(i); |
---|
| 1151 | } |
---|
| 1152 | } |
---|
| 1153 | if (!unitParam) |
---|
| 1154 | return; |
---|
| 1155 | |
---|
| 1156 | G4double defaultValue = command->ConvertToDouble(angleParam->GetDefaultValue()) |
---|
| 1157 | * G4UnitDefinition::GetValueOf(unitParam->GetDefaultValue()); |
---|
| 1158 | if (defaultValue > 89.5 || defaultValue <= 0.0) { |
---|
| 1159 | G4cerr << "Field half angle should be 0 < angle <= 89.5 degrees. Check your default Field half angle parameter\n"; |
---|
| 1160 | } else { |
---|
| 1161 | G4cout << "Perspective view has been set to default value. Field half angle="<<angleParam->GetDefaultValue() <<" \n" << G4endl; |
---|
| 1162 | fVP.SetFieldHalfAngle (defaultValue); |
---|
| 1163 | SetView (); |
---|
| 1164 | } |
---|
| 1165 | } |
---|
[702] | 1166 | updateQWidget(); |
---|
| 1167 | } |
---|
| 1168 | |
---|
| 1169 | |
---|
| 1170 | /** |
---|
[564] | 1171 | SLOT Activate by a click on the background menu |
---|
| 1172 | @param check : 1 white, 0 black |
---|
| 1173 | */ |
---|
| 1174 | void G4OpenGLQtViewer::toggleBackground(bool check) { |
---|
| 1175 | |
---|
| 1176 | // //I need to revisit the kernel if the background colour changes and |
---|
| 1177 | // //hidden line removal is enabled, because hlr drawing utilises the |
---|
| 1178 | // //background colour in its drawing... |
---|
| 1179 | // // (Note added by JA 13/9/2005) Background now handled in view |
---|
| 1180 | // // parameters. A kernel visit is triggered on change of background. |
---|
| 1181 | if (check == 1) { |
---|
| 1182 | ((G4ViewParameters&)this->GetViewParameters()). |
---|
| 1183 | SetBackgroundColour(G4Colour(1.,1.,1.)); // White |
---|
| 1184 | } else { |
---|
| 1185 | ((G4ViewParameters&)this->GetViewParameters()). |
---|
| 1186 | SetBackgroundColour(G4Colour(0.,0.,0.)); // Black |
---|
| 1187 | } |
---|
| 1188 | updateQWidget(); |
---|
[530] | 1189 | } |
---|
| 1190 | |
---|
[564] | 1191 | /** |
---|
| 1192 | SLOT Activate by a click on the transparency menu |
---|
| 1193 | @param check : 1 , 0 |
---|
| 1194 | */ |
---|
| 1195 | void G4OpenGLQtViewer::toggleTransparency(bool check) { |
---|
| 1196 | |
---|
| 1197 | if (check) { |
---|
| 1198 | transparency_enabled = false; |
---|
| 1199 | } else { |
---|
| 1200 | transparency_enabled = true; |
---|
| 1201 | } |
---|
| 1202 | SetNeedKernelVisit (true); |
---|
| 1203 | updateQWidget(); |
---|
| 1204 | } |
---|
[530] | 1205 | |
---|
[564] | 1206 | /** |
---|
| 1207 | SLOT Activate by a click on the antialiasing menu |
---|
| 1208 | @param check : 1 , 0 |
---|
| 1209 | */ |
---|
| 1210 | void G4OpenGLQtViewer::toggleAntialiasing(bool check) { |
---|
| 1211 | |
---|
| 1212 | if (!check) { |
---|
| 1213 | antialiasing_enabled = false; |
---|
| 1214 | glDisable (GL_LINE_SMOOTH); |
---|
| 1215 | glDisable (GL_POLYGON_SMOOTH); |
---|
| 1216 | } else { |
---|
| 1217 | antialiasing_enabled = true; |
---|
| 1218 | glEnable (GL_LINE_SMOOTH); |
---|
| 1219 | glHint (GL_LINE_SMOOTH_HINT, GL_NICEST); |
---|
| 1220 | glEnable (GL_POLYGON_SMOOTH); |
---|
| 1221 | glHint (GL_POLYGON_SMOOTH_HINT, GL_NICEST); |
---|
[530] | 1222 | } |
---|
[564] | 1223 | |
---|
| 1224 | updateQWidget(); |
---|
| 1225 | } |
---|
| 1226 | |
---|
| 1227 | /** |
---|
| 1228 | SLOT Activate by a click on the haloing menu |
---|
| 1229 | @param check : 1 , 0 |
---|
[530] | 1230 | */ |
---|
[564] | 1231 | //FIXME : I SEE NOTHING... |
---|
| 1232 | void G4OpenGLQtViewer::toggleHaloing(bool check) { |
---|
| 1233 | if (check) { |
---|
| 1234 | haloing_enabled = false; |
---|
| 1235 | } else { |
---|
| 1236 | haloing_enabled = true; |
---|
| 1237 | } |
---|
[530] | 1238 | |
---|
[564] | 1239 | updateQWidget(); |
---|
[530] | 1240 | |
---|
[564] | 1241 | } |
---|
| 1242 | |
---|
| 1243 | /** |
---|
| 1244 | SLOT Activate by a click on the auxiliaire edges menu |
---|
| 1245 | @param check : 1 , 0 |
---|
| 1246 | */ |
---|
| 1247 | void G4OpenGLQtViewer::toggleAux(bool check) { |
---|
| 1248 | if (check) { |
---|
| 1249 | fVP.SetAuxEdgeVisible(false); |
---|
| 1250 | } else { |
---|
| 1251 | fVP.SetAuxEdgeVisible(true); |
---|
| 1252 | } |
---|
| 1253 | SetNeedKernelVisit (true); |
---|
| 1254 | updateQWidget(); |
---|
| 1255 | |
---|
| 1256 | } |
---|
| 1257 | |
---|
| 1258 | /** |
---|
| 1259 | SLOT Activate by a click on the full screen menu |
---|
| 1260 | */ |
---|
[704] | 1261 | void G4OpenGLQtViewer::toggleFullScreen() { |
---|
[617] | 1262 | #if QT_VERSION >= 0x030200 |
---|
[564] | 1263 | GLWindow->setWindowState(GLWindow->windowState() ^ Qt::WindowFullScreen); |
---|
[617] | 1264 | #else |
---|
[638] | 1265 | G4cerr << "This version of G4UI Could not generate the selected format\n" << G4endl; |
---|
[617] | 1266 | #endif |
---|
[564] | 1267 | } |
---|
| 1268 | |
---|
[565] | 1269 | void G4OpenGLQtViewer::actionCreateEPS() { |
---|
[580] | 1270 | QString filters; |
---|
[600] | 1271 | #if QT_VERSION < 0x040000 |
---|
| 1272 | QStrList listFormat=QImageIO::outputFormats(); |
---|
| 1273 | char *tmp=listFormat.first(); |
---|
| 1274 | while (tmp!=0) { |
---|
| 1275 | filters += QString(tmp) + ";;"; |
---|
| 1276 | tmp=listFormat.next(); |
---|
| 1277 | } |
---|
| 1278 | #else |
---|
[580] | 1279 | QList<QByteArray> formats = QImageWriter::supportedImageFormats (); |
---|
| 1280 | for (int i = 0; i < formats.size(); ++i) { |
---|
[600] | 1281 | filters +=formats.at(i) + ";;"; |
---|
[580] | 1282 | } |
---|
[600] | 1283 | #endif |
---|
[588] | 1284 | filters += "eps;;"; |
---|
| 1285 | filters += "ps;;"; |
---|
| 1286 | filters += "pdf"; |
---|
[639] | 1287 | QString* selectedFormat = new QString(); |
---|
[600] | 1288 | #if QT_VERSION < 0x040000 |
---|
| 1289 | QString nomFich = QFileDialog::getSaveFileName ( ".", |
---|
| 1290 | filters, |
---|
| 1291 | GLWindow, |
---|
| 1292 | "Save file dialog", |
---|
| 1293 | tr("Save as ..."), |
---|
[639] | 1294 | selectedFormat ); |
---|
[600] | 1295 | #else |
---|
[580] | 1296 | QString nomFich = QFileDialog::getSaveFileName ( GLWindow, |
---|
| 1297 | tr("Save as ..."), |
---|
| 1298 | ".", |
---|
[582] | 1299 | filters, |
---|
[639] | 1300 | selectedFormat ); |
---|
[600] | 1301 | #endif |
---|
[580] | 1302 | // bmp jpg jpeg png ppm xbm xpm |
---|
[582] | 1303 | if (nomFich == "") { |
---|
| 1304 | return; |
---|
| 1305 | } |
---|
[600] | 1306 | #if QT_VERSION < 0x040000 |
---|
[639] | 1307 | nomFich += "."+QString(selectedFormat->ascii()); |
---|
| 1308 | QString format = selectedFormat->lower(); |
---|
[600] | 1309 | #else |
---|
[639] | 1310 | nomFich += "."+QString(selectedFormat->toStdString().c_str()); |
---|
| 1311 | QString format = selectedFormat->toLower(); |
---|
[600] | 1312 | #endif |
---|
[656] | 1313 | G4OpenGLQtExportDialog* exportDialog= new G4OpenGLQtExportDialog(GLWindow,format,fWindow->height(),fWindow->width()); |
---|
[585] | 1314 | if( exportDialog->exec()) { |
---|
[593] | 1315 | |
---|
| 1316 | QImage image; |
---|
[655] | 1317 | bool res = false; |
---|
[635] | 1318 | if ((exportDialog->getWidth() !=fWindow->width()) || |
---|
| 1319 | (exportDialog->getHeight() !=fWindow->height())) { |
---|
[655] | 1320 | if (format != QString("eps")) { |
---|
[638] | 1321 | G4cerr << "Export->Change Size : This function is not implemented, to export in another size, please resize your frame to what you need\n" << G4endl; |
---|
[585] | 1322 | |
---|
[635] | 1323 | // rescaleImage(exportDialog->getWidth(),exportDialog->getHeight());// re-scale image |
---|
| 1324 | // QGLWidget* glResized = fWindow; |
---|
| 1325 | |
---|
| 1326 | // FIXME : |
---|
| 1327 | // L.Garnier : I've try to implement change size function, but the problem is |
---|
| 1328 | // the renderPixmap function call the QGLWidget to resize and it doesn't draw |
---|
| 1329 | // the content of this widget... It only draw the background. |
---|
| 1330 | |
---|
| 1331 | // fWindow->renderPixmap (exportDialog->getWidth()*2,exportDialog->getHeight()*2,true ); |
---|
| 1332 | |
---|
| 1333 | // QPixmap pixmap = fWindow->renderPixmap (); |
---|
| 1334 | |
---|
| 1335 | // image = pixmap->toImage(); |
---|
[593] | 1336 | // glResized->resize(exportDialog->getWidth()*2,exportDialog->getHeight()*2); |
---|
| 1337 | // image = glResized->grabFrameBuffer(); |
---|
[655] | 1338 | } |
---|
[635] | 1339 | } else { |
---|
| 1340 | image = fWindow->grabFrameBuffer(); |
---|
| 1341 | } |
---|
[639] | 1342 | if (format == QString("eps")) { |
---|
[652] | 1343 | if (exportDialog->getVectorEPS()) { |
---|
[655] | 1344 | res = generateVectorEPS(nomFich,exportDialog->getWidth(),exportDialog->getHeight(),image); |
---|
[652] | 1345 | } else { |
---|
[655] | 1346 | res = generateEPS(nomFich,exportDialog->getNbColor(),image); |
---|
[652] | 1347 | } |
---|
[639] | 1348 | } else if ((format == "ps") || (format == "pdf")) { |
---|
[655] | 1349 | res = generatePS_PDF(nomFich,exportDialog->getNbColor(),image); |
---|
| 1350 | } else if ((format == "tif") || |
---|
| 1351 | (format == "tiff") || |
---|
| 1352 | (format == "jpg") || |
---|
| 1353 | (format == "jpeg") || |
---|
| 1354 | (format == "png") || |
---|
| 1355 | (format == "pbm") || |
---|
| 1356 | (format == "pgm") || |
---|
| 1357 | (format == "ppm") || |
---|
| 1358 | (format == "bmp") || |
---|
| 1359 | (format == "xbm") || |
---|
| 1360 | (format == "xpm")) { |
---|
[639] | 1361 | #if QT_VERSION < 0x040000 |
---|
[655] | 1362 | res = image.save(nomFich,selectedFormat->ascii(),exportDialog->getSliderValue()); |
---|
[639] | 1363 | #else |
---|
[655] | 1364 | res = image.save(nomFich,0,exportDialog->getSliderValue()); |
---|
[639] | 1365 | #endif |
---|
[585] | 1366 | } else { |
---|
[638] | 1367 | G4cerr << "This version of G4UI Could not generate the selected format\n" << G4endl; |
---|
[585] | 1368 | } |
---|
[655] | 1369 | if (res == false) { |
---|
| 1370 | #if QT_VERSION < 0x040000 |
---|
| 1371 | G4cerr << "Error while saving file... "<<nomFich.ascii()<<"\n" << G4endl; |
---|
| 1372 | #else |
---|
| 1373 | G4cerr << "Error while saving file... "<<nomFich.toStdString().c_str()<<"\n" << G4endl; |
---|
| 1374 | #endif |
---|
| 1375 | } else { |
---|
| 1376 | #if QT_VERSION < 0x040000 |
---|
[656] | 1377 | G4cout << "File "<<nomFich.ascii()<<" has been saved \n" << G4endl; |
---|
[655] | 1378 | #else |
---|
[656] | 1379 | G4cout << "File "<<nomFich.toStdString().c_str()<<" has been saved \n" << G4endl; |
---|
[655] | 1380 | #endif |
---|
| 1381 | } |
---|
[585] | 1382 | |
---|
| 1383 | } else { // cancel selected |
---|
| 1384 | return; |
---|
[568] | 1385 | } |
---|
[580] | 1386 | |
---|
[608] | 1387 | #ifdef GEANT4_QT_DEBUG |
---|
[565] | 1388 | printf("G4OpenGLQtViewer::actionCreateEPS() \n"); |
---|
[608] | 1389 | #endif |
---|
[565] | 1390 | } |
---|
| 1391 | |
---|
[580] | 1392 | /* |
---|
| 1393 | // 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 |
---|
[565] | 1394 | |
---|
[580] | 1395 | void Graph::exportToSVG(const QString& fname) |
---|
| 1396 | { |
---|
| 1397 | // enable workaround for Qt3 misalignments |
---|
| 1398 | QwtPainter::setSVGMode(true); |
---|
| 1399 | QPicture picture; |
---|
| 1400 | QPainter p(&picture); |
---|
| 1401 | d_plot->print(&p, d_plot->rect()); |
---|
| 1402 | p.end(); |
---|
[565] | 1403 | |
---|
[580] | 1404 | picture.save(fname, "svg"); |
---|
| 1405 | } |
---|
| 1406 | */ |
---|
| 1407 | |
---|
| 1408 | |
---|
| 1409 | |
---|
| 1410 | |
---|
[564] | 1411 | /** |
---|
| 1412 | Save the current mouse press point |
---|
| 1413 | @param p mouse click point |
---|
| 1414 | */ |
---|
| 1415 | void G4OpenGLQtViewer::G4MousePressEvent(QPoint p) |
---|
| 1416 | { |
---|
[696] | 1417 | fLastPos = p; |
---|
[707] | 1418 | if (fMouseAction == STYLE2){ // pick |
---|
[681] | 1419 | Pick(p.x(),p.y()); |
---|
| 1420 | } |
---|
[564] | 1421 | } |
---|
| 1422 | |
---|
[696] | 1423 | |
---|
[564] | 1424 | /** |
---|
| 1425 | @param pos_x mouse x position |
---|
| 1426 | @param pos_y mouse y position |
---|
| 1427 | @param mButtons mouse button active |
---|
| 1428 | */ |
---|
[599] | 1429 | |
---|
| 1430 | #if QT_VERSION < 0x040000 |
---|
[696] | 1431 | void G4OpenGLQtViewer::G4MouseEvent(int pos_x, int pos_y,Qt::ButtonState mButtons) |
---|
[599] | 1432 | #else |
---|
[696] | 1433 | void G4OpenGLQtViewer::G4MouseEvent(int pos_x, int pos_y,Qt::MouseButtons mButtons) |
---|
[599] | 1434 | #endif |
---|
[564] | 1435 | { |
---|
[713] | 1436 | |
---|
[703] | 1437 | int dx = fLastPos.x() - pos_x; |
---|
| 1438 | int dy = fLastPos.y() - pos_y; |
---|
[713] | 1439 | |
---|
| 1440 | |
---|
[696] | 1441 | if (fMouseAction == STYLE1) { // rotate |
---|
[564] | 1442 | if (mButtons & Qt::LeftButton) { |
---|
[696] | 1443 | G4MouseRotateEvent(dx,dy); |
---|
[564] | 1444 | } |
---|
[713] | 1445 | } else if (fMouseAction == STYLE2) { // move |
---|
| 1446 | if (mButtons & Qt::LeftButton) { |
---|
| 1447 | G4double coef = ((G4double)getSceneNearWidth())/((G4double)WinSize_x); |
---|
| 1448 | if (WinSize_y <WinSize_x) { |
---|
| 1449 | coef = ((G4double)getSceneNearWidth())/((G4double)WinSize_y); |
---|
| 1450 | } |
---|
| 1451 | fVP.IncrementPan(dx*coef,-dy*coef); |
---|
| 1452 | updateQWidget(); |
---|
| 1453 | } |
---|
[564] | 1454 | } |
---|
[696] | 1455 | fLastPos = QPoint(pos_x, pos_y); |
---|
[564] | 1456 | } |
---|
| 1457 | |
---|
[696] | 1458 | /** |
---|
[711] | 1459 | Move the scene of dx, dy, dz values. |
---|
[696] | 1460 | @param dx delta mouse x position |
---|
| 1461 | @param dy delta mouse y position |
---|
| 1462 | */ |
---|
| 1463 | |
---|
[713] | 1464 | void G4OpenGLQtViewer::G4MouseMoveEvent(G4double dx,G4double dy, G4double dz) |
---|
[696] | 1465 | { |
---|
[712] | 1466 | GLdouble coefTrans = getSceneNearWidth()*fDeltaSceneTranslation; |
---|
| 1467 | GLdouble coefDepth = getSceneDepth()*fDeltaDepth; |
---|
[707] | 1468 | |
---|
[713] | 1469 | fVP.IncrementPan(-dx*coefTrans,dy*coefTrans,dz*coefDepth); |
---|
[712] | 1470 | |
---|
[713] | 1471 | updateQWidget(); |
---|
[696] | 1472 | } |
---|
| 1473 | |
---|
| 1474 | |
---|
| 1475 | /** |
---|
| 1476 | @param dx delta mouse x position |
---|
| 1477 | @param dy delta mouse y position |
---|
| 1478 | */ |
---|
| 1479 | |
---|
[713] | 1480 | void G4OpenGLQtViewer::G4MouseRotateEvent(G4double dx, G4double dy) |
---|
[696] | 1481 | { |
---|
[713] | 1482 | dx = dx * fDeltaRotation; |
---|
| 1483 | dy = dy * fDeltaRotation; |
---|
| 1484 | |
---|
[696] | 1485 | //phi spin stuff here |
---|
| 1486 | |
---|
| 1487 | G4Vector3D vp = fVP.GetViewpointDirection ().unit (); |
---|
| 1488 | G4Vector3D up = fVP.GetUpVector ().unit (); |
---|
| 1489 | |
---|
| 1490 | G4Vector3D yprime = (up.cross(vp)).unit(); |
---|
| 1491 | G4Vector3D zprime = (vp.cross(yprime)).unit(); |
---|
| 1492 | |
---|
| 1493 | G4double delta_alpha; |
---|
| 1494 | G4double delta_theta; |
---|
| 1495 | |
---|
| 1496 | if (fVP.GetLightsMoveWithCamera()) { |
---|
| 1497 | delta_alpha = dy; |
---|
| 1498 | delta_theta = -dx; |
---|
| 1499 | } else { |
---|
| 1500 | delta_alpha = -dy; |
---|
| 1501 | delta_theta = dx; |
---|
| 1502 | } |
---|
| 1503 | |
---|
| 1504 | delta_alpha *= deg; |
---|
| 1505 | delta_theta *= deg; |
---|
| 1506 | |
---|
| 1507 | G4Vector3D new_vp = std::cos(delta_alpha) * vp + std::sin(delta_alpha) * zprime; |
---|
| 1508 | |
---|
| 1509 | G4Vector3D new_up; |
---|
| 1510 | if (fVP.GetLightsMoveWithCamera()) { |
---|
| 1511 | new_up = (new_vp.cross(yprime)).unit(); |
---|
| 1512 | fVP.SetUpVector(new_up); |
---|
| 1513 | } else { |
---|
| 1514 | new_up = up; |
---|
| 1515 | } |
---|
| 1516 | //////////////// |
---|
| 1517 | // Rotates by fixed azimuthal angle delta_theta. |
---|
| 1518 | |
---|
| 1519 | G4double cosalpha = new_up.dot (new_vp.unit()); |
---|
| 1520 | G4double sinalpha = std::sqrt (1. - std::pow (cosalpha, 2)); |
---|
| 1521 | yprime = (new_up.cross (new_vp.unit())).unit (); |
---|
| 1522 | G4Vector3D xprime = yprime.cross (new_up); |
---|
| 1523 | // Projection of vp on plane perpendicular to up... |
---|
| 1524 | G4Vector3D a1 = sinalpha * xprime; |
---|
| 1525 | // Required new projection... |
---|
| 1526 | G4Vector3D a2 = |
---|
| 1527 | sinalpha * (std::cos (delta_theta) * xprime + std::sin (delta_theta) * yprime); |
---|
| 1528 | // Required Increment vector... |
---|
| 1529 | G4Vector3D delta = a2 - a1; |
---|
| 1530 | // So new viewpoint is... |
---|
| 1531 | G4Vector3D viewPoint = new_vp.unit() + delta; |
---|
| 1532 | |
---|
| 1533 | fVP.SetViewAndLights (viewPoint); |
---|
| 1534 | updateQWidget(); |
---|
| 1535 | |
---|
| 1536 | } |
---|
| 1537 | |
---|
[660] | 1538 | /** This is the benning of a rescale function. It does nothing for the moment |
---|
| 1539 | @param aWidth : new width |
---|
| 1540 | @param aHeight : new height |
---|
| 1541 | */ |
---|
[585] | 1542 | void G4OpenGLQtViewer::rescaleImage( |
---|
| 1543 | int aWidth |
---|
| 1544 | ,int aHeight |
---|
| 1545 | ){ |
---|
[608] | 1546 | #ifdef GEANT4_QT_DEBUG |
---|
[586] | 1547 | printf("should rescale \n"); |
---|
[608] | 1548 | #endif |
---|
[660] | 1549 | GLfloat* feedback_buffer; |
---|
| 1550 | GLint returned; |
---|
| 1551 | FILE* file; |
---|
| 1552 | |
---|
[673] | 1553 | // feedback_buffer = new GLfloat[size]; |
---|
| 1554 | // glFeedbackBuffer (size, GL_3D_COLOR, feedback_buffer); |
---|
| 1555 | // glRenderMode (GL_FEEDBACK); |
---|
[660] | 1556 | |
---|
[673] | 1557 | // glViewport (0, 0, aWidth, aHeight); |
---|
| 1558 | // DrawView(); |
---|
| 1559 | // returned = glRenderMode (GL_RENDER); |
---|
[660] | 1560 | |
---|
[585] | 1561 | } |
---|
[586] | 1562 | |
---|
| 1563 | /** |
---|
[652] | 1564 | Generate Vectorial Encapsulated Postscript form image |
---|
[586] | 1565 | @param aFilename : name of file |
---|
| 1566 | @param aInColor : numbers of colors : 1->BW 2->RGB 3->RGB+Alpha |
---|
| 1567 | @param aImage : Image to print |
---|
| 1568 | */ |
---|
[652] | 1569 | bool G4OpenGLQtViewer::generateVectorEPS ( |
---|
| 1570 | QString aFilename |
---|
| 1571 | ,int aWidth |
---|
| 1572 | ,int aHeight |
---|
| 1573 | ,QImage aImage |
---|
| 1574 | ) |
---|
| 1575 | { |
---|
| 1576 | // Print vectored PostScript |
---|
| 1577 | |
---|
| 1578 | G4int size = 5000000; |
---|
| 1579 | |
---|
| 1580 | GLfloat* feedback_buffer; |
---|
| 1581 | GLint returned; |
---|
| 1582 | FILE* file; |
---|
| 1583 | |
---|
| 1584 | feedback_buffer = new GLfloat[size]; |
---|
| 1585 | glFeedbackBuffer (size, GL_3D_COLOR, feedback_buffer); |
---|
| 1586 | glRenderMode (GL_FEEDBACK); |
---|
| 1587 | |
---|
[709] | 1588 | int side = aWidth; |
---|
| 1589 | if (aHeight < aWidth) side = aHeight; |
---|
[675] | 1590 | glViewport((aWidth - side) / 2, (aHeight - side) / 2, side, side); |
---|
[652] | 1591 | DrawView(); |
---|
| 1592 | |
---|
| 1593 | returned = glRenderMode (GL_RENDER); |
---|
| 1594 | |
---|
| 1595 | |
---|
| 1596 | #if QT_VERSION < 0x040000 |
---|
| 1597 | file = fopen (aFilename.ascii(), "w"); |
---|
| 1598 | #else |
---|
| 1599 | file = fopen (aFilename.toStdString().c_str(), "w"); |
---|
| 1600 | #endif |
---|
| 1601 | if (file) { |
---|
| 1602 | spewWireframeEPS (file, returned, feedback_buffer, "rendereps"); |
---|
| 1603 | } else { |
---|
[658] | 1604 | #if QT_VERSION < 0x040000 |
---|
[673] | 1605 | G4cerr << "Could not open "<< aFilename.ascii()<<"\n" << G4endl; |
---|
[658] | 1606 | #else |
---|
[673] | 1607 | G4cerr << "Could not open "<< aFilename.toStdString().c_str()<<"\n" << G4endl; |
---|
[658] | 1608 | #endif |
---|
[652] | 1609 | } |
---|
| 1610 | |
---|
| 1611 | delete[] feedback_buffer; |
---|
| 1612 | |
---|
| 1613 | return true; |
---|
| 1614 | } |
---|
| 1615 | |
---|
| 1616 | /** |
---|
| 1617 | Generate Encapsulated Postscript form image |
---|
| 1618 | @param aFilename : name of file |
---|
| 1619 | @param aInColor : numbers of colors : 1->BW 2->RGB 3->RGB+Alpha |
---|
| 1620 | @param aImage : Image to print |
---|
| 1621 | */ |
---|
[588] | 1622 | bool G4OpenGLQtViewer::generateEPS ( |
---|
[586] | 1623 | QString aFilename |
---|
| 1624 | ,int aInColor |
---|
| 1625 | ,QImage aImage |
---|
| 1626 | ) |
---|
| 1627 | { |
---|
[587] | 1628 | // FIXME |
---|
[608] | 1629 | #ifdef GEANT4_QT_DEBUG |
---|
[586] | 1630 | printf("saving EPS\n"); |
---|
[608] | 1631 | #endif |
---|
[586] | 1632 | |
---|
| 1633 | FILE* fp; |
---|
[587] | 1634 | |
---|
[649] | 1635 | if (aImage.bits () == NULL) |
---|
[588] | 1636 | return false; |
---|
[586] | 1637 | |
---|
[600] | 1638 | #if QT_VERSION < 0x040000 |
---|
| 1639 | fp = fopen (aFilename.ascii(), "w"); |
---|
| 1640 | #else |
---|
[602] | 1641 | fp = fopen (aFilename.toStdString().c_str(), "w"); |
---|
[600] | 1642 | #endif |
---|
[586] | 1643 | if (fp == NULL) { |
---|
[588] | 1644 | return false; |
---|
[586] | 1645 | } |
---|
| 1646 | |
---|
| 1647 | fprintf (fp, "%%!PS-Adobe-2.0 EPSF-1.2\n"); |
---|
[600] | 1648 | #if QT_VERSION < 0x040000 |
---|
| 1649 | fprintf (fp, "%%%%Title: %s\n", aFilename.ascii()); |
---|
| 1650 | #else |
---|
[602] | 1651 | fprintf (fp, "%%%%Title: %s\n", aFilename.toStdString().c_str()); |
---|
[600] | 1652 | #endif |
---|
[586] | 1653 | fprintf (fp, "%%%%Creator: OpenGL pixmap render output\n"); |
---|
[587] | 1654 | fprintf (fp, "%%%%BoundingBox: 0 0 %d %d\n", aImage.width(), aImage.height()); |
---|
[586] | 1655 | fprintf (fp, "%%%%EndComments\n"); |
---|
| 1656 | fprintf (fp, "gsave\n"); |
---|
| 1657 | fprintf (fp, "/bwproc {\n"); |
---|
| 1658 | fprintf (fp, " rgbproc\n"); |
---|
| 1659 | fprintf (fp, " dup length 3 idiv string 0 3 0 \n"); |
---|
| 1660 | fprintf (fp, " 5 -1 roll {\n"); |
---|
| 1661 | fprintf (fp, " add 2 1 roll 1 sub dup 0 eq\n"); |
---|
| 1662 | fprintf (fp, " { pop 3 idiv 3 -1 roll dup 4 -1 roll dup\n"); |
---|
| 1663 | fprintf (fp, " 3 1 roll 5 -1 roll } put 1 add 3 0 \n"); |
---|
| 1664 | fprintf (fp, " { 2 1 roll } ifelse\n"); |
---|
| 1665 | fprintf (fp, " }forall\n"); |
---|
| 1666 | fprintf (fp, " pop pop pop\n"); |
---|
| 1667 | fprintf (fp, "} def\n"); |
---|
| 1668 | fprintf (fp, "systemdict /colorimage known not {\n"); |
---|
| 1669 | fprintf (fp, " /colorimage {\n"); |
---|
| 1670 | fprintf (fp, " pop\n"); |
---|
| 1671 | fprintf (fp, " pop\n"); |
---|
| 1672 | fprintf (fp, " /rgbproc exch def\n"); |
---|
| 1673 | fprintf (fp, " { bwproc } image\n"); |
---|
| 1674 | fprintf (fp, " } def\n"); |
---|
| 1675 | fprintf (fp, "} if\n"); |
---|
[587] | 1676 | fprintf (fp, "/picstr %d string def\n", aImage.width() * aInColor); |
---|
| 1677 | fprintf (fp, "%d %d scale\n", aImage.width(), aImage.height()); |
---|
| 1678 | fprintf (fp, "%d %d %d\n", aImage.width(), aImage.height(), 8); |
---|
| 1679 | fprintf (fp, "[%d 0 0 %d 0 0]\n", aImage.width(), aImage.height()); |
---|
[586] | 1680 | fprintf (fp, "{currentfile picstr readhexstring pop}\n"); |
---|
| 1681 | fprintf (fp, "false %d\n", aInColor); |
---|
| 1682 | fprintf (fp, "colorimage\n"); |
---|
| 1683 | |
---|
| 1684 | |
---|
[588] | 1685 | int width = aImage.width(); |
---|
| 1686 | int height = aImage.height(); |
---|
| 1687 | int depth = aImage.depth(); |
---|
| 1688 | int size = width*height; |
---|
| 1689 | |
---|
| 1690 | if (depth == 1) |
---|
| 1691 | size = (width+7)/8*height; |
---|
| 1692 | else if (aInColor == 1) |
---|
| 1693 | size = size*3; |
---|
| 1694 | |
---|
| 1695 | int i = 0; |
---|
[649] | 1696 | // if ( aInColor ==1 ) { |
---|
| 1697 | // FIXME : L. Garnier. For the moment 10 dec 2007, I could not find a way |
---|
| 1698 | // to save correctly grayscale Image. I mean that color or grayscale image |
---|
| 1699 | // have the same file save size ! |
---|
| 1700 | |
---|
| 1701 | /* } else*/ if (depth == 8) { |
---|
[588] | 1702 | for(int y=height-1; y >=0 ; y--) { |
---|
| 1703 | const uchar * s = aImage.scanLine(y); |
---|
| 1704 | for(int x=0; x <width; x++) { |
---|
| 1705 | QRgb rgb = aImage.color(s[x]); |
---|
| 1706 | if (aInColor == 1) { |
---|
| 1707 | fprintf (fp, " %02hx ",(unsigned char)qGray(rgb)); |
---|
| 1708 | i++; |
---|
| 1709 | } else { |
---|
| 1710 | fprintf (fp, " %02hx %02hx %02hx", |
---|
| 1711 | (unsigned char) qRed(rgb), |
---|
| 1712 | (unsigned char) qGreen(rgb), |
---|
| 1713 | (unsigned char) qBlue(rgb)); |
---|
| 1714 | i += 3; |
---|
| 1715 | } |
---|
| 1716 | } |
---|
[586] | 1717 | fprintf (fp, "\n"); |
---|
[588] | 1718 | } |
---|
| 1719 | } else { |
---|
[601] | 1720 | #if QT_VERSION < 0x040000 |
---|
[649] | 1721 | bool alpha = aImage.hasAlphaBuffer(); |
---|
[601] | 1722 | #else |
---|
[588] | 1723 | bool alpha = aImage.hasAlphaChannel(); |
---|
| 1724 | for(int y=height-1; y >=0 ; y--) { |
---|
| 1725 | QRgb * s = (QRgb*)(aImage.scanLine(y)); |
---|
| 1726 | for(int x=0; x <width; x++) { |
---|
| 1727 | QRgb rgb = (*s++); |
---|
| 1728 | if (alpha && qAlpha(rgb) < 0x40) // 25% alpha, convert to white - |
---|
| 1729 | rgb = qRgb(0xff, 0xff, 0xff); |
---|
| 1730 | if (aInColor == 1) { |
---|
| 1731 | fprintf (fp, " %02hx ",(unsigned char)qGray(rgb)); |
---|
| 1732 | i++; |
---|
| 1733 | } else { |
---|
| 1734 | fprintf (fp, " %02hx %02hx %02hx", |
---|
| 1735 | (unsigned char) qRed(rgb), |
---|
| 1736 | (unsigned char) qGreen(rgb), |
---|
| 1737 | (unsigned char) qBlue(rgb)); |
---|
| 1738 | i += 3; |
---|
| 1739 | } |
---|
[587] | 1740 | } |
---|
| 1741 | fprintf (fp, "\n"); |
---|
[588] | 1742 | } |
---|
[601] | 1743 | #endif |
---|
| 1744 | |
---|
[586] | 1745 | } |
---|
[588] | 1746 | |
---|
[586] | 1747 | fprintf (fp, "grestore\n"); |
---|
| 1748 | fprintf (fp, "showpage\n"); |
---|
| 1749 | fclose (fp); |
---|
[588] | 1750 | |
---|
| 1751 | return true; |
---|
[586] | 1752 | } |
---|
[588] | 1753 | /** |
---|
| 1754 | Generate Postscript or PDF form image |
---|
| 1755 | @param aFilename : name of file |
---|
| 1756 | @param aInColor : numbers of colors : 1->BW 2->RGB |
---|
| 1757 | @param aImage : Image to print |
---|
| 1758 | */ |
---|
| 1759 | bool G4OpenGLQtViewer::generatePS_PDF ( |
---|
| 1760 | QString aFilename |
---|
| 1761 | ,int aInColor |
---|
| 1762 | ,QImage aImage |
---|
| 1763 | ) |
---|
| 1764 | { |
---|
[638] | 1765 | |
---|
[600] | 1766 | #if QT_VERSION < 0x040000 |
---|
| 1767 | #ifdef Q_WS_MAC || Q_WS_X11 |
---|
[588] | 1768 | QPrinter printer; |
---|
| 1769 | // printer.setPageSize(pageSize); |
---|
| 1770 | if (aInColor == 1) { |
---|
| 1771 | printer.setColorMode(QPrinter::GrayScale); |
---|
| 1772 | } else { |
---|
| 1773 | printer.setColorMode(QPrinter::Color); |
---|
| 1774 | } |
---|
| 1775 | |
---|
[600] | 1776 | /* FIXME : I don't know which format it will save... |
---|
| 1777 | if (aFilename.endsWith(".ps")) { |
---|
| 1778 | printer.setOutputFormat(QPrinter::PostScriptFormat); |
---|
| 1779 | } else { |
---|
| 1780 | printer.setOutputFormat(QPrinter::PdfFormat); |
---|
| 1781 | } |
---|
| 1782 | */ |
---|
| 1783 | printer.setOutputFileName(aFilename); |
---|
| 1784 | // printer.setFullPage ( true); |
---|
| 1785 | QPainter paint(&printer); |
---|
| 1786 | paint.drawImage (0,0,aImage ); |
---|
| 1787 | paint.end(); |
---|
| 1788 | #else |
---|
[638] | 1789 | G4cerr << "This fonction is only supported on Mac OsX or X11 with Qt3. Full platform supported with Qt4\n" << G4endl; |
---|
[600] | 1790 | #endif |
---|
| 1791 | #else |
---|
| 1792 | QPrinter printer; |
---|
| 1793 | // printer.setPageSize(pageSize); |
---|
[637] | 1794 | |
---|
| 1795 | // FIXME : L. Garnier 4/12/07 |
---|
| 1796 | // This is not working, it does nothing. Image is staying in color mode |
---|
| 1797 | // So I have desactivate the B/W button in GUI |
---|
| 1798 | if ((!aImage.isGrayscale ()) &&(aInColor ==1 )) { |
---|
| 1799 | #if QT_VERSION < 0x040000 |
---|
| 1800 | aImage = aImage.convertDepth(1,Qt::MonoOnly); |
---|
| 1801 | #else |
---|
| 1802 | aImage = aImage.convertToFormat ( aImage.format(), Qt::MonoOnly); |
---|
| 1803 | #endif |
---|
[600] | 1804 | } |
---|
| 1805 | |
---|
[637] | 1806 | |
---|
[588] | 1807 | if (aFilename.endsWith(".ps")) { |
---|
[606] | 1808 | #if QT_VERSION > 0x040200 |
---|
[588] | 1809 | printer.setOutputFormat(QPrinter::PostScriptFormat); |
---|
[606] | 1810 | #endif |
---|
[588] | 1811 | } else { |
---|
[606] | 1812 | #if QT_VERSION > 0x040100 |
---|
[588] | 1813 | printer.setOutputFormat(QPrinter::PdfFormat); |
---|
[606] | 1814 | #endif |
---|
[588] | 1815 | } |
---|
[606] | 1816 | #if QT_VERSION > 0x040100 |
---|
[588] | 1817 | printer.setOutputFileName(aFilename); |
---|
[606] | 1818 | #endif |
---|
[588] | 1819 | // printer.setFullPage ( true); |
---|
| 1820 | QPainter paint(&printer); |
---|
[637] | 1821 | paint.drawImage (0,0,aImage); |
---|
[588] | 1822 | paint.end(); |
---|
[600] | 1823 | #endif |
---|
[588] | 1824 | return true; |
---|
| 1825 | } |
---|
| 1826 | |
---|
| 1827 | |
---|
[696] | 1828 | void G4OpenGLQtViewer::G4keyPressEvent (QKeyEvent * event) |
---|
| 1829 | { |
---|
[702] | 1830 | if (holdKeyEvent) |
---|
| 1831 | return; |
---|
| 1832 | |
---|
| 1833 | holdKeyEvent = true; |
---|
| 1834 | |
---|
[709] | 1835 | #if QT_VERSION < 0x040000 |
---|
| 1836 | if ((event->key() == Qt::Key_Down) && (event->state() & Qt::AltButton )) { // go backward |
---|
| 1837 | #else |
---|
[707] | 1838 | if ((event->key() == Qt::Key_Down) && (event->modifiers() & Qt::AltModifier )) { // go backward |
---|
[709] | 1839 | #endif |
---|
[712] | 1840 | |
---|
[707] | 1841 | G4MouseMoveEvent(0,0,1); |
---|
| 1842 | } |
---|
[709] | 1843 | #if QT_VERSION < 0x040000 |
---|
| 1844 | else if ((event->key() == Qt::Key_Up) && (event->state() & Qt::AltButton)) { // go forward |
---|
| 1845 | #else |
---|
[707] | 1846 | else if ((event->key() == Qt::Key_Up) && (event->modifiers() & Qt::AltModifier)) { // go forward |
---|
[709] | 1847 | #endif |
---|
[707] | 1848 | G4MouseMoveEvent(0,0,-1); |
---|
| 1849 | } |
---|
[709] | 1850 | #if QT_VERSION < 0x040000 |
---|
| 1851 | if ((event->key() == Qt::Key_Down) && (event->state() & Qt::ShiftButton)) { // rotate phi |
---|
| 1852 | #else |
---|
[707] | 1853 | if ((event->key() == Qt::Key_Down) && (event->modifiers() & Qt::ShiftModifier)) { // rotate phi |
---|
[709] | 1854 | #endif |
---|
[707] | 1855 | G4MouseRotateEvent(0,-1); |
---|
| 1856 | } |
---|
[709] | 1857 | #if QT_VERSION < 0x040000 |
---|
| 1858 | else if ((event->key() == Qt::Key_Up) && (event->state() & Qt::ShiftButton)) { // rotate phi |
---|
| 1859 | #else |
---|
[707] | 1860 | else if ((event->key() == Qt::Key_Up) && (event->modifiers() & Qt::ShiftModifier)) { // rotate phi |
---|
[709] | 1861 | #endif |
---|
[707] | 1862 | G4MouseRotateEvent(0,1); |
---|
| 1863 | } |
---|
[709] | 1864 | #if QT_VERSION < 0x040000 |
---|
| 1865 | if ((event->key() == Qt::Key_Left) && (event->state() & Qt::ShiftButton)) { // rotate theta |
---|
| 1866 | #else |
---|
[707] | 1867 | if ((event->key() == Qt::Key_Left) && (event->modifiers() & Qt::ShiftModifier)) { // rotate theta |
---|
[709] | 1868 | #endif |
---|
[707] | 1869 | G4MouseRotateEvent(1,0); |
---|
| 1870 | } |
---|
[709] | 1871 | #if QT_VERSION < 0x040000 |
---|
[716] | 1872 | else if ((event->key() == Qt::Key_Right) && (event->state() & Qt::ShiftButton)) { // rotate theta |
---|
[709] | 1873 | #else |
---|
| 1874 | else if ((event->key() == Qt::Key_Right) && (event->modifiers() & Qt::ShiftModifier)) { // rotate theta |
---|
| 1875 | #endif |
---|
[707] | 1876 | G4MouseRotateEvent(-1,0); |
---|
| 1877 | } |
---|
[704] | 1878 | if (event->key() == Qt::Key_Escape) { // escaped from full screen |
---|
| 1879 | toggleFullScreen(); |
---|
[707] | 1880 | } |
---|
| 1881 | if (event->key() == Qt::Key_Plus) { // zoom in |
---|
[712] | 1882 | fVP.SetZoomFactor(fVP.GetZoomFactor()*(1+fDeltaZoom)); |
---|
[707] | 1883 | updateQWidget(); |
---|
| 1884 | } |
---|
| 1885 | else if (event->key() == Qt::Key_Minus) { // zoom out |
---|
[712] | 1886 | fVP.SetZoomFactor(fVP.GetZoomFactor()*(1-fDeltaZoom)); |
---|
[707] | 1887 | updateQWidget(); |
---|
| 1888 | } |
---|
| 1889 | // with no modifiers |
---|
[716] | 1890 | #if QT_VERSION < 0x040000 |
---|
| 1891 | if (event->state() == Qt::NoButton) { |
---|
| 1892 | #else |
---|
| 1893 | if (event->modifiers() == Qt::NoModifier) { |
---|
| 1894 | #endif |
---|
[707] | 1895 | if (event->key() == Qt::Key_Down) { // go down |
---|
[702] | 1896 | G4MouseMoveEvent(0,1,0); |
---|
[696] | 1897 | } |
---|
[707] | 1898 | else if (event->key() == Qt::Key_Up) { // go up |
---|
[702] | 1899 | G4MouseMoveEvent(0,-1,0); |
---|
[696] | 1900 | } |
---|
[707] | 1901 | if (event->key() == Qt::Key_Left) { // go left |
---|
[696] | 1902 | G4MouseMoveEvent(-1,0,0); |
---|
| 1903 | } |
---|
[707] | 1904 | else if (event->key() == Qt::Key_Right) { // go right |
---|
[696] | 1905 | G4MouseMoveEvent(1,0,0); |
---|
| 1906 | } |
---|
[707] | 1907 | } |
---|
[702] | 1908 | holdKeyEvent = false; |
---|
[696] | 1909 | } |
---|
| 1910 | |
---|
[588] | 1911 | /* |
---|
[696] | 1912 | |
---|
[588] | 1913 | void MultiLayer::exportToSVG(const QString& fname) |
---|
| 1914 | { |
---|
| 1915 | QPicture picture; |
---|
| 1916 | QPainter p(&picture); |
---|
| 1917 | for (int i=0;i<(int)graphsList->count();i++) |
---|
| 1918 | { |
---|
| 1919 | Graph *gr=(Graph *)graphsList->at(i); |
---|
| 1920 | Plot *myPlot= (Plot *)gr->plotWidget(); |
---|
| 1921 | |
---|
| 1922 | QPoint pos=gr->pos(); |
---|
| 1923 | |
---|
| 1924 | int width=int(myPlot->frameGeometry().width()); |
---|
| 1925 | int height=int(myPlot->frameGeometry().height()); |
---|
| 1926 | |
---|
| 1927 | myPlot->print(&p, QRect(pos,QSize(width,height))); |
---|
| 1928 | } |
---|
| 1929 | |
---|
| 1930 | p.end(); |
---|
| 1931 | picture.save(fname, "svg"); |
---|
| 1932 | } |
---|
| 1933 | */ |
---|
[707] | 1934 | #endif |
---|