[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 |
---|
| 424 | QAction *polyhedron = new QAction("&Polyhedron","&Polyhedron",CTRL+Key_P,mRepresentation); |
---|
| 425 | QAction *nurbs = new QAction("&NURBS","&NURBS",CTRL+Key_N,mRepresentation); |
---|
[702] | 426 | |
---|
| 427 | QAction *ortho = new QAction("&Orthographic","&Orthographic",CTRL+Key_O,mProjection); |
---|
| 428 | QAction *perspective = new QAction("&Perspective","&Perspective",CTRL+Key_P,mProjection); |
---|
[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); |
---|
[617] | 435 | #endif |
---|
[599] | 436 | polyhedron->addTo(mRepresentation); |
---|
| 437 | nurbs->addTo(mRepresentation); |
---|
| 438 | |
---|
[702] | 439 | ortho->addTo(mProjection); |
---|
| 440 | perspective->addTo(mProjection); |
---|
| 441 | |
---|
[599] | 442 | mStyle->insertItem("&Representation",mRepresentation); |
---|
[702] | 443 | mStyle->insertItem("&Projection",mProjection); |
---|
[599] | 444 | fContextMenu->insertItem("&Style",mStyle); |
---|
| 445 | |
---|
[702] | 446 | |
---|
[599] | 447 | #else |
---|
| 448 | // === Style Menu === |
---|
[564] | 449 | QMenu *mStyle = fContextMenu->addMenu("&Style"); |
---|
| 450 | |
---|
| 451 | QMenu *mRepresentation = mStyle->addMenu("&Representation"); |
---|
[703] | 452 | QMenu *mProjection = mStyle->addMenu("&Projection"); |
---|
[632] | 453 | QAction *polyhedron = mRepresentation->addAction("Polyhedron"); |
---|
[564] | 454 | QAction *nurbs = mRepresentation->addAction("NURBS"); |
---|
[702] | 455 | |
---|
[703] | 456 | QAction *ortho = mProjection->addAction("Orthographic"); |
---|
| 457 | QAction *perspective = mProjection->addAction("Persepective"); |
---|
[599] | 458 | #endif |
---|
[702] | 459 | |
---|
| 460 | // INIT mRepresentation |
---|
[564] | 461 | G4ViewParameters::RepStyle style; |
---|
| 462 | style = fVP.GetRepStyle(); |
---|
| 463 | if (style == G4ViewParameters::polyhedron) { |
---|
| 464 | createRadioAction(polyhedron,nurbs,SLOT(toggleRepresentation(bool)),1); |
---|
| 465 | } else if (style == G4ViewParameters::nurbs) { |
---|
| 466 | createRadioAction(polyhedron,nurbs,SLOT(toggleRepresentation(bool)),2); |
---|
[539] | 467 | } else { |
---|
[564] | 468 | mRepresentation->clear(); |
---|
[539] | 469 | } |
---|
| 470 | |
---|
[702] | 471 | // INIT mProjection |
---|
| 472 | if (fVP.GetFieldHalfAngle() == 0) { |
---|
| 473 | createRadioAction(ortho, perspective,SLOT(toggleProjection(bool)),1); |
---|
| 474 | } else { |
---|
| 475 | createRadioAction(ortho, perspective,SLOT(toggleProjection(bool)),2); |
---|
| 476 | } |
---|
[539] | 477 | |
---|
[599] | 478 | #if QT_VERSION < 0x040000 |
---|
| 479 | // === Drawing Menu === |
---|
| 480 | QPopupMenu *mDrawing = new QPopupMenu(fContextMenu); |
---|
| 481 | fContextMenu->insertItem("&Drawing",mDrawing); |
---|
| 482 | |
---|
| 483 | fDrawingWireframe = new QPopupMenu(mDrawing); |
---|
| 484 | mDrawing->insertItem("&Wireframe",fDrawingWireframe); |
---|
| 485 | |
---|
| 486 | mDrawing->setCheckable(true); |
---|
| 487 | fDrawingWireframe->setCheckable(true); |
---|
| 488 | |
---|
| 489 | fDrawingLineRemoval = new QPopupMenu(mDrawing); |
---|
| 490 | mDrawing->insertItem("&Hidden line removal",fDrawingLineRemoval); |
---|
| 491 | fDrawingLineRemoval->setCheckable(true); |
---|
| 492 | |
---|
| 493 | fDrawingSurfaceRemoval = new QPopupMenu(mDrawing); |
---|
| 494 | mDrawing->insertItem("&Hidden surface removal",fDrawingSurfaceRemoval); |
---|
| 495 | fDrawingSurfaceRemoval->setCheckable(true); |
---|
| 496 | |
---|
| 497 | fDrawingLineSurfaceRemoval = new QPopupMenu(mDrawing); |
---|
| 498 | mDrawing->insertItem("&Hidden line and surface removal",fDrawingLineSurfaceRemoval); |
---|
| 499 | fDrawingLineSurfaceRemoval->setCheckable(true); |
---|
| 500 | |
---|
| 501 | #else |
---|
| 502 | // === Drawing Menu === |
---|
[564] | 503 | QMenu *mDrawing = mStyle->addMenu("&Drawing"); |
---|
[599] | 504 | |
---|
[564] | 505 | fDrawingWireframe = mDrawing->addAction("Wireframe"); |
---|
| 506 | fDrawingWireframe->setCheckable(true); |
---|
[599] | 507 | |
---|
[564] | 508 | fDrawingLineRemoval = mDrawing->addAction("Hidden line removal"); |
---|
| 509 | fDrawingLineRemoval->setCheckable(true); |
---|
[599] | 510 | |
---|
[564] | 511 | fDrawingSurfaceRemoval = mDrawing->addAction("Hidden Surface removal"); |
---|
| 512 | fDrawingSurfaceRemoval->setCheckable(true); |
---|
[599] | 513 | |
---|
[564] | 514 | fDrawingLineSurfaceRemoval = mDrawing->addAction("Hidden line and surface removal"); |
---|
| 515 | fDrawingLineSurfaceRemoval->setCheckable(true); |
---|
[599] | 516 | #endif |
---|
[564] | 517 | // INIT Drawing |
---|
| 518 | G4ViewParameters::DrawingStyle d_style; |
---|
| 519 | d_style = fVP.GetDrawingStyle(); |
---|
| 520 | |
---|
[599] | 521 | #if QT_VERSION < 0x040000 |
---|
[564] | 522 | if (d_style == G4ViewParameters::wireframe) { |
---|
[599] | 523 | fDrawingWireframe->setItemChecked(0,true); |
---|
| 524 | } else if (d_style == G4ViewParameters::hlr) { |
---|
| 525 | fDrawingLineRemoval->setItemChecked(0,true); |
---|
| 526 | } else if (d_style == G4ViewParameters::hsr) { |
---|
| 527 | fDrawingSurfaceRemoval->setItemChecked(0,true); |
---|
| 528 | } else if (d_style == G4ViewParameters::hlhsr) { |
---|
| 529 | fDrawingLineSurfaceRemoval->setItemChecked(0,true); |
---|
| 530 | } else { |
---|
| 531 | mDrawing->clear(); |
---|
| 532 | } |
---|
[610] | 533 | #ifdef GEANT4_QT_DEBUG |
---|
| 534 | printf("G4OpenGLQtViewer:: fDrawingWireframe 1\n"); |
---|
| 535 | #endif |
---|
| 536 | QObject ::connect(fDrawingWireframe, |
---|
| 537 | SIGNAL(activated(int)), |
---|
| 538 | this, |
---|
| 539 | SLOT(actionDrawingWireframe())); |
---|
| 540 | #ifdef GEANT4_QT_DEBUG |
---|
| 541 | printf("G4OpenGLQtViewer:: fDrawingWireframe 2\n"); |
---|
| 542 | #endif |
---|
| 543 | QObject ::connect(fDrawingLineRemoval, |
---|
| 544 | SIGNAL(activated(int)), |
---|
| 545 | this, |
---|
| 546 | SLOT(actionDrawingLineRemoval())); |
---|
| 547 | QObject ::connect(fDrawingSurfaceRemoval, |
---|
| 548 | SIGNAL(activated(int)), |
---|
| 549 | this, |
---|
| 550 | SLOT(actionDrawingSurfaceRemoval())); |
---|
| 551 | QObject ::connect(fDrawingLineSurfaceRemoval, |
---|
| 552 | SIGNAL(activated(int)), |
---|
| 553 | this, |
---|
| 554 | SLOT(actionDrawingLineSurfaceRemoval())); |
---|
[599] | 555 | #else |
---|
| 556 | if (d_style == G4ViewParameters::wireframe) { |
---|
[564] | 557 | fDrawingWireframe->setChecked(true); |
---|
| 558 | } else if (d_style == G4ViewParameters::hlr) { |
---|
| 559 | fDrawingLineRemoval->setChecked(true); |
---|
| 560 | } else if (d_style == G4ViewParameters::hsr) { |
---|
| 561 | fDrawingSurfaceRemoval->setChecked(true); |
---|
| 562 | } else if (d_style == G4ViewParameters::hlhsr) { |
---|
| 563 | fDrawingLineSurfaceRemoval->setChecked(true); |
---|
| 564 | } else { |
---|
| 565 | mDrawing->clear(); |
---|
| 566 | } |
---|
[565] | 567 | QObject ::connect(fDrawingWireframe, |
---|
| 568 | SIGNAL(triggered(bool)), |
---|
| 569 | this, |
---|
| 570 | SLOT(actionDrawingWireframe())); |
---|
| 571 | QObject ::connect(fDrawingLineRemoval, |
---|
| 572 | SIGNAL(triggered(bool)), |
---|
| 573 | this, |
---|
| 574 | SLOT(actionDrawingLineRemoval())); |
---|
| 575 | QObject ::connect(fDrawingSurfaceRemoval, |
---|
| 576 | SIGNAL(triggered(bool)), |
---|
| 577 | this, |
---|
| 578 | SLOT(actionDrawingSurfaceRemoval())); |
---|
| 579 | QObject ::connect(fDrawingLineSurfaceRemoval, |
---|
| 580 | SIGNAL(triggered(bool)), |
---|
| 581 | this, |
---|
| 582 | SLOT(actionDrawingLineSurfaceRemoval())); |
---|
[610] | 583 | #endif |
---|
[564] | 584 | |
---|
| 585 | |
---|
[610] | 586 | |
---|
[599] | 587 | #if QT_VERSION < 0x040000 |
---|
| 588 | QPopupMenu *mBackground = new QPopupMenu(mStyle); |
---|
| 589 | mStyle->insertItem("&Background color",mBackground); |
---|
| 590 | |
---|
[617] | 591 | #if QT_VERSION < 0x030200 |
---|
| 592 | QAction *white = new QAction("&White","&White",CTRL+Key_W,mBackground); |
---|
| 593 | QAction *black = new QAction("&Black","&Black",CTRL+Key_B,mBackground); |
---|
| 594 | #else |
---|
[599] | 595 | QAction *white = new QAction("&White",CTRL+Key_W,mBackground); |
---|
| 596 | QAction *black = new QAction("&Black",CTRL+Key_B,mBackground); |
---|
[617] | 597 | #endif |
---|
[599] | 598 | white->addTo(mBackground); |
---|
| 599 | black->addTo(mBackground); |
---|
| 600 | |
---|
| 601 | #else |
---|
[564] | 602 | QMenu *mBackground = mStyle->addMenu("&Background color"); |
---|
| 603 | QAction *white = mBackground->addAction("White"); |
---|
| 604 | QAction *black = mBackground->addAction("Black"); |
---|
[599] | 605 | |
---|
| 606 | #endif |
---|
[564] | 607 | if (background.GetRed() == 1. && |
---|
| 608 | background.GetGreen() == 1. && |
---|
| 609 | background.GetBlue() == 1.) { |
---|
| 610 | createRadioAction(white,black,SLOT(toggleBackground(bool)),1); |
---|
| 611 | } else { |
---|
| 612 | createRadioAction(white,black,SLOT(toggleBackground(bool)),2); |
---|
| 613 | } |
---|
| 614 | |
---|
| 615 | |
---|
[599] | 616 | #if QT_VERSION < 0x040000 |
---|
| 617 | // === Action Menu === |
---|
| 618 | QPopupMenu *mActions = new QPopupMenu(fContextMenu); |
---|
| 619 | fContextMenu->insertItem("&Actions",mActions); |
---|
| 620 | |
---|
[617] | 621 | #if QT_VERSION < 0x030200 |
---|
| 622 | QAction *createEPS = new QAction("&Save as ...","&Save as ...",CTRL+Key_S,mActions); |
---|
| 623 | #else |
---|
[599] | 624 | QAction *createEPS = new QAction("&Save as ...",CTRL+Key_S,mActions); |
---|
[617] | 625 | #endif |
---|
[599] | 626 | createEPS->addTo(mActions); |
---|
[610] | 627 | QObject ::connect(createEPS, |
---|
| 628 | SIGNAL(activated()), |
---|
| 629 | this, |
---|
| 630 | SLOT(actionCreateEPS())); |
---|
[599] | 631 | |
---|
| 632 | #else |
---|
| 633 | // === Action Menu === |
---|
[564] | 634 | QMenu *mActions = fContextMenu->addMenu("&Actions"); |
---|
[568] | 635 | QAction *createEPS = mActions->addAction("Save as ..."); |
---|
[565] | 636 | QObject ::connect(createEPS, |
---|
[566] | 637 | SIGNAL(triggered()), |
---|
[565] | 638 | this, |
---|
| 639 | SLOT(actionCreateEPS())); |
---|
[610] | 640 | #endif |
---|
[564] | 641 | |
---|
| 642 | |
---|
[610] | 643 | |
---|
[599] | 644 | #if QT_VERSION < 0x040000 |
---|
| 645 | // === Special Menu === |
---|
| 646 | QPopupMenu *mSpecial = new QPopupMenu(fContextMenu); |
---|
| 647 | fContextMenu->insertItem("S&pecial",mSpecial); |
---|
| 648 | |
---|
| 649 | QPopupMenu *mTransparency = new QPopupMenu(mSpecial); |
---|
| 650 | mSpecial->insertItem("Transparency",mTransparency); |
---|
| 651 | |
---|
[617] | 652 | #if QT_VERSION < 0x030200 |
---|
| 653 | QAction *transparencyOn = new QAction("&On","&On",CTRL+Key_O,mTransparency); |
---|
| 654 | QAction *transparencyOff = new QAction("&Off","&Off",CTRL+Key_F,mTransparency); |
---|
| 655 | #else |
---|
[599] | 656 | QAction *transparencyOn = new QAction("&On",CTRL+Key_O,mTransparency); |
---|
| 657 | QAction *transparencyOff = new QAction("&Off",CTRL+Key_F,mTransparency); |
---|
[617] | 658 | #endif |
---|
[599] | 659 | transparencyOn->addTo(mTransparency); |
---|
| 660 | transparencyOff->addTo(mTransparency); |
---|
| 661 | |
---|
| 662 | #else |
---|
| 663 | // === Special Menu === |
---|
[564] | 664 | QMenu *mSpecial = fContextMenu->addMenu("S&pecial"); |
---|
[599] | 665 | QMenu *mTransparency = mSpecial->addMenu("Transparency"); |
---|
| 666 | QAction *transparencyOn = mTransparency->addAction("On"); |
---|
| 667 | QAction *transparencyOff = mTransparency->addAction("Off"); |
---|
| 668 | #endif |
---|
| 669 | |
---|
[564] | 670 | if (transparency_enabled == false) { |
---|
| 671 | createRadioAction(transparencyOn,transparencyOff,SLOT(toggleTransparency(bool)),2); |
---|
| 672 | } else if (transparency_enabled == true) { |
---|
| 673 | createRadioAction(transparencyOn,transparencyOff,SLOT(toggleTransparency(bool)),1); |
---|
| 674 | } else { |
---|
| 675 | mSpecial->clear(); |
---|
| 676 | } |
---|
| 677 | |
---|
| 678 | |
---|
[599] | 679 | #if QT_VERSION < 0x040000 |
---|
| 680 | QPopupMenu *mAntialiasing = new QPopupMenu(mSpecial); |
---|
| 681 | mSpecial->insertItem("Antialiasing",mAntialiasing); |
---|
| 682 | |
---|
[617] | 683 | #if QT_VERSION < 0x030200 |
---|
| 684 | QAction *antialiasingOn = new QAction("&On","&On",CTRL+Key_O,mAntialiasing); |
---|
| 685 | QAction *antialiasingOff = new QAction("&Off","&Off",CTRL+Key_F,mAntialiasing); |
---|
| 686 | #else |
---|
[599] | 687 | QAction *antialiasingOn = new QAction("&On",CTRL+Key_O,mAntialiasing); |
---|
| 688 | QAction *antialiasingOff = new QAction("&Off",CTRL+Key_F,mAntialiasing); |
---|
[617] | 689 | #endif |
---|
[599] | 690 | antialiasingOn->addTo(mAntialiasing); |
---|
| 691 | antialiasingOff->addTo(mAntialiasing); |
---|
| 692 | |
---|
| 693 | #else |
---|
[564] | 694 | QMenu *mAntialiasing = mSpecial->addMenu("Antialiasing"); |
---|
| 695 | QAction *antialiasingOn = mAntialiasing->addAction("On"); |
---|
| 696 | QAction *antialiasingOff = mAntialiasing->addAction("Off"); |
---|
[599] | 697 | #endif |
---|
| 698 | |
---|
[564] | 699 | if (antialiasing_enabled == false) { |
---|
| 700 | createRadioAction(antialiasingOn,antialiasingOff,SLOT(toggleAntialiasing(bool)),2); |
---|
| 701 | } else if (antialiasing_enabled == true) { |
---|
| 702 | createRadioAction(antialiasingOn,antialiasingOff,SLOT(toggleAntialiasing(bool)),1); |
---|
| 703 | } else { |
---|
| 704 | mAntialiasing->clear(); |
---|
| 705 | } |
---|
| 706 | |
---|
[599] | 707 | #if QT_VERSION < 0x040000 |
---|
| 708 | QPopupMenu *mHaloing = new QPopupMenu(mSpecial); |
---|
| 709 | mSpecial->insertItem("Haloing",mHaloing); |
---|
| 710 | |
---|
[617] | 711 | #if QT_VERSION < 0x030200 |
---|
| 712 | QAction *haloingOn = new QAction("&On","&On",CTRL+Key_O,mHaloing); |
---|
| 713 | QAction *haloingOff = new QAction("&Off","&Off",CTRL+Key_F,mHaloing); |
---|
| 714 | #else |
---|
[599] | 715 | QAction *haloingOn = new QAction("&On",CTRL+Key_O,mHaloing); |
---|
| 716 | QAction *haloingOff = new QAction("&Off",CTRL+Key_F,mHaloing); |
---|
[617] | 717 | #endif |
---|
[599] | 718 | haloingOn->addTo(mHaloing); |
---|
| 719 | haloingOff->addTo(mHaloing); |
---|
| 720 | #else |
---|
[564] | 721 | QMenu *mHaloing = mSpecial->addMenu("Haloing"); |
---|
| 722 | QAction *haloingOn = mHaloing->addAction("On"); |
---|
| 723 | QAction *haloingOff = mHaloing->addAction("Off"); |
---|
[599] | 724 | #endif |
---|
[564] | 725 | if (haloing_enabled == false) { |
---|
| 726 | createRadioAction(haloingOn,haloingOff,SLOT(toggleHaloing(bool)),2); |
---|
| 727 | } else if (haloing_enabled == true) { |
---|
| 728 | createRadioAction(haloingOn,haloingOff,SLOT(toggleHaloing(bool)),1); |
---|
| 729 | } else { |
---|
| 730 | mHaloing->clear(); |
---|
| 731 | } |
---|
| 732 | |
---|
[599] | 733 | #if QT_VERSION < 0x040000 |
---|
| 734 | QPopupMenu *mAux = new QPopupMenu(mSpecial); |
---|
| 735 | mSpecial->insertItem("Auxiliairy edges",mAux); |
---|
| 736 | |
---|
[617] | 737 | #if QT_VERSION < 0x030200 |
---|
| 738 | QAction *auxOn = new QAction("&On","&On",CTRL+Key_O,mAux); |
---|
| 739 | QAction *auxOff = new QAction("&Off","&Off",CTRL+Key_F,mAux); |
---|
| 740 | #else |
---|
[599] | 741 | QAction *auxOn = new QAction("&On",CTRL+Key_O,mAux); |
---|
| 742 | QAction *auxOff = new QAction("&Off",CTRL+Key_F,mAux); |
---|
[617] | 743 | #endif |
---|
[599] | 744 | auxOn->addTo(mAux); |
---|
| 745 | auxOff->addTo(mAux); |
---|
| 746 | |
---|
| 747 | #else |
---|
[564] | 748 | QMenu *mAux = mSpecial->addMenu("Auxiliary edges"); |
---|
| 749 | QAction *auxOn = mAux->addAction("On"); |
---|
| 750 | QAction *auxOff = mAux->addAction("Off"); |
---|
[599] | 751 | #endif |
---|
[564] | 752 | if (!fVP.IsAuxEdgeVisible()) { |
---|
| 753 | createRadioAction(auxOn,auxOff,SLOT(toggleAux(bool)),1); |
---|
| 754 | } else { |
---|
| 755 | createRadioAction(auxOn,auxOff,SLOT(toggleAux(bool)),2); |
---|
| 756 | } |
---|
| 757 | |
---|
| 758 | |
---|
[617] | 759 | #if QT_VERSION >= 0x030200 |
---|
[599] | 760 | #if QT_VERSION < 0x040000 |
---|
| 761 | QPopupMenu *mFullScreen = new QPopupMenu(mSpecial); |
---|
| 762 | mSpecial->insertItem("Full screen",mFullScreen); |
---|
| 763 | |
---|
| 764 | QAction *fullOn = new QAction("&On",CTRL+Key_O,mFullScreen); |
---|
| 765 | QAction *fullOff = new QAction("&Off",CTRL+Key_F,mFullScreen); |
---|
| 766 | fullOn->addTo(mFullScreen); |
---|
| 767 | fullOff->addTo(mFullScreen); |
---|
| 768 | #else |
---|
[564] | 769 | QMenu *mFullScreen = mSpecial->addMenu("Full screen"); |
---|
| 770 | QAction *fullOn = mFullScreen->addAction("On"); |
---|
| 771 | QAction *fullOff = mFullScreen->addAction("Off"); |
---|
[599] | 772 | #endif |
---|
[704] | 773 | createRadioAction(fullOn,fullOff,SLOT(toggleFullScreen()),2); |
---|
[617] | 774 | #endif |
---|
[564] | 775 | |
---|
| 776 | } |
---|
| 777 | |
---|
| 778 | void G4OpenGLQtViewer::manageContextMenuEvent(QContextMenuEvent *e) |
---|
| 779 | { |
---|
[579] | 780 | if (!GLWindow) { |
---|
[638] | 781 | G4cerr << "Visualization window not defined, please choose one before\n" << G4endl; |
---|
[579] | 782 | } else { |
---|
[539] | 783 | |
---|
[579] | 784 | if (!fContextMenu) |
---|
| 785 | createPopupMenu(); |
---|
| 786 | |
---|
| 787 | // launch menu |
---|
| 788 | if ( fContextMenu ) { |
---|
| 789 | fContextMenu->exec( e->globalPos() ); |
---|
| 790 | // delete fContextMenu; |
---|
| 791 | } |
---|
[564] | 792 | } |
---|
| 793 | e->accept(); |
---|
| 794 | } |
---|
[539] | 795 | |
---|
| 796 | |
---|
[564] | 797 | /** |
---|
| 798 | Create a radio button menu. The two menu will be connected. When click on one, |
---|
| 799 | eatch state will be invert and callback method will be called. |
---|
| 800 | @param action1 first action to connect |
---|
| 801 | @param action2 second action to connect |
---|
| 802 | @param method callback method |
---|
| 803 | @param nCheck: 1 : first action will be set true. 2 : second action will be set true |
---|
| 804 | */ |
---|
[599] | 805 | #if QT_VERSION < 0x040000 |
---|
[564] | 806 | void G4OpenGLQtViewer::createRadioAction(QAction *action1,QAction *action2, const std::string& method,unsigned int nCheck) { |
---|
| 807 | |
---|
[599] | 808 | if (action1->parent()->inherits("QPopupMenu")){ |
---|
| 809 | ((QPopupMenu*)action1->parent())->setCheckable(true); |
---|
| 810 | } |
---|
| 811 | ((QPopupMenu*)action1->parent())->setItemChecked(0,true); |
---|
| 812 | ((QPopupMenu*)action1->parent())->setItemChecked(1,true); |
---|
| 813 | |
---|
| 814 | if (nCheck ==1) |
---|
| 815 | ((QPopupMenu*)action1->parent())->setItemChecked(0,true); |
---|
| 816 | else |
---|
| 817 | ((QPopupMenu*)action1->parent())->setItemChecked(1,true); |
---|
| 818 | |
---|
[610] | 819 | //FIXME : Should not work on Qt3 |
---|
| 820 | QObject ::connect(action1, SIGNAL(activated()),action2, SLOT(toggle())); |
---|
| 821 | QObject ::connect(action2, SIGNAL(activated()),action1, SLOT(toggle())); |
---|
[599] | 822 | |
---|
| 823 | QObject ::connect(action1, SIGNAL(toggled(bool)),this, method.c_str()); |
---|
| 824 | } |
---|
| 825 | |
---|
| 826 | #else |
---|
| 827 | void G4OpenGLQtViewer::createRadioAction(QAction *action1,QAction *action2, const std::string& method,unsigned int nCheck) { |
---|
| 828 | |
---|
[564] | 829 | action1->setCheckable(true); |
---|
| 830 | action2->setCheckable(true); |
---|
| 831 | |
---|
| 832 | if (nCheck ==1) |
---|
| 833 | action1->setChecked (true); |
---|
| 834 | else |
---|
| 835 | action2->setChecked (true); |
---|
| 836 | |
---|
| 837 | QObject ::connect(action1, SIGNAL(triggered(bool)),action2, SLOT(toggle())); |
---|
| 838 | QObject ::connect(action2, SIGNAL(triggered(bool)),action1, SLOT(toggle())); |
---|
| 839 | |
---|
| 840 | QObject ::connect(action1, SIGNAL(toggled(bool)),this, method.c_str()); |
---|
| 841 | |
---|
| 842 | } |
---|
[599] | 843 | #endif |
---|
[564] | 844 | |
---|
| 845 | /** |
---|
[678] | 846 | Slot activate when mouseAction->rotate menu is set |
---|
| 847 | */ |
---|
| 848 | void G4OpenGLQtViewer::actionMouseRotate() { |
---|
[696] | 849 | emit toggleMouseAction(STYLE1); |
---|
[678] | 850 | } |
---|
| 851 | |
---|
| 852 | |
---|
| 853 | /** |
---|
[713] | 854 | Slot activate when mouseAction->rotate menu is set |
---|
| 855 | */ |
---|
| 856 | void G4OpenGLQtViewer::actionMouseMove() { |
---|
| 857 | emit toggleMouseAction(STYLE2); |
---|
| 858 | } |
---|
| 859 | |
---|
| 860 | |
---|
| 861 | /** |
---|
[707] | 862 | Slot activate when mouseAction->zoom menu is set |
---|
[678] | 863 | */ |
---|
[707] | 864 | void G4OpenGLQtViewer::actionMousePick() { |
---|
[678] | 865 | #ifdef GEANT4_QT_DEBUG |
---|
[707] | 866 | printf("G4OpenGLQtViewer::actionMousePick \n"); |
---|
[678] | 867 | #endif |
---|
[696] | 868 | emit toggleMouseAction(STYLE3); |
---|
[678] | 869 | } |
---|
| 870 | |
---|
| 871 | /** |
---|
[681] | 872 | Slot activate when mouseAction->zoom menu is set |
---|
| 873 | */ |
---|
[707] | 874 | void G4OpenGLQtViewer::actionMouseShortcuts() { |
---|
[681] | 875 | #ifdef GEANT4_QT_DEBUG |
---|
[707] | 876 | printf("G4OpenGLQtViewer::actionMouseShortcuts \n"); |
---|
[681] | 877 | #endif |
---|
[713] | 878 | emit toggleMouseAction(STYLE4); |
---|
[681] | 879 | } |
---|
| 880 | |
---|
| 881 | /** |
---|
[564] | 882 | Slot activate when drawing->wireframe menu is set |
---|
| 883 | */ |
---|
| 884 | void G4OpenGLQtViewer::actionDrawingWireframe() { |
---|
| 885 | emit toggleDrawingAction(1); |
---|
| 886 | } |
---|
| 887 | |
---|
| 888 | /** |
---|
| 889 | Slot activate when drawing->line removal menu is set |
---|
| 890 | */ |
---|
| 891 | void G4OpenGLQtViewer::actionDrawingLineRemoval() { |
---|
| 892 | emit toggleDrawingAction(2); |
---|
| 893 | } |
---|
| 894 | |
---|
| 895 | /** |
---|
| 896 | Slot activate when drawing->surface removal menu is set |
---|
| 897 | */ |
---|
| 898 | void G4OpenGLQtViewer::actionDrawingSurfaceRemoval() { |
---|
| 899 | emit toggleDrawingAction(3); |
---|
| 900 | } |
---|
| 901 | |
---|
| 902 | /** |
---|
| 903 | Slot activate when drawing->wireframe menu is set |
---|
| 904 | */ |
---|
| 905 | void G4OpenGLQtViewer::actionDrawingLineSurfaceRemoval() { |
---|
| 906 | emit toggleDrawingAction(4); |
---|
| 907 | } |
---|
| 908 | |
---|
| 909 | |
---|
| 910 | /** |
---|
[678] | 911 | Slot activated when mouse action is toggle |
---|
[696] | 912 | @param aAction : STYLE1, STYLE2, STYLE3 |
---|
[678] | 913 | */ |
---|
| 914 | void G4OpenGLQtViewer::toggleMouseAction(mouseActions aAction) { |
---|
| 915 | |
---|
[713] | 916 | if ((aAction == STYLE1) || //initialize all |
---|
| 917 | (aAction == STYLE2) || |
---|
| 918 | (aAction == STYLE3) || |
---|
| 919 | (aAction == STYLE4)) { |
---|
| 920 | #if QT_VERSION < 0x040000 |
---|
| 921 | fMouseRotate->setItemChecked (0,false); |
---|
| 922 | fMouseMove->setItemChecked (0,false); |
---|
| 923 | fMousePick->setItemChecked (0,false); |
---|
| 924 | fMouseShortcuts->setItemChecked (0,false); |
---|
| 925 | #else |
---|
| 926 | fMouseRotate->setChecked (false); |
---|
| 927 | fMouseMove->setChecked (false); |
---|
| 928 | fMousePick->setChecked (false); |
---|
| 929 | fMouseShortcuts->setChecked (false); |
---|
| 930 | #endif |
---|
| 931 | fVP.SetPicking(false); |
---|
| 932 | fMouseAction = aAction; |
---|
| 933 | } |
---|
| 934 | // rotate |
---|
[707] | 935 | if (aAction == STYLE1) { // rotate |
---|
| 936 | G4cout << "Click and move mouse to rotate volume \n" << G4endl; |
---|
| 937 | G4cout << "Press left/right arrows to move volume left/right\n" << G4endl; |
---|
| 938 | G4cout << "Press up/down arrows to move volume up/down\n" << G4endl; |
---|
| 939 | G4cout << "Press CONTROL+up/down arrows to move volume toward/forward\n" << G4endl; |
---|
| 940 | G4cout << "Press SHIFT+left/right arrows to rotate volume left/right\n" << G4endl; |
---|
| 941 | G4cout << "Press SHIFT+up/down arrows to rotate volume up/down\n" << G4endl; |
---|
[696] | 942 | G4cout << "Press +/- to zoom into volume\n" << G4endl; |
---|
[678] | 943 | #if QT_VERSION < 0x040000 |
---|
| 944 | fMouseRotate->setItemChecked (0,true); |
---|
| 945 | #else |
---|
| 946 | fMouseRotate->setChecked (true); |
---|
| 947 | #endif |
---|
[713] | 948 | } else if (aAction == STYLE2) { //move |
---|
| 949 | G4cout << "Move camera point of view with mouse\n" << G4endl; |
---|
| 950 | #if QT_VERSION < 0x040000 |
---|
| 951 | fMouseMove->setItemChecked (0,true); |
---|
| 952 | #else |
---|
| 953 | fMouseMove->setChecked (true); |
---|
| 954 | #endif |
---|
| 955 | } else if (aAction == STYLE3) { //pick |
---|
[707] | 956 | G4cout << "Click and pick \n" << G4endl; |
---|
[678] | 957 | #if QT_VERSION < 0x040000 |
---|
[707] | 958 | fMousePick->setItemChecked (0,true); |
---|
[678] | 959 | #else |
---|
[707] | 960 | fMousePick->setChecked (true); |
---|
[678] | 961 | #endif |
---|
[707] | 962 | fVP.SetPicking(true); |
---|
[713] | 963 | } else if (aAction == STYLE4) { // display shortcuts |
---|
[678] | 964 | #if QT_VERSION < 0x040000 |
---|
[707] | 965 | fMouseShortcuts->setItemChecked (0,true); |
---|
[678] | 966 | #else |
---|
[707] | 967 | fMouseShortcuts->setChecked (true); |
---|
[678] | 968 | #endif |
---|
[707] | 969 | |
---|
| 970 | G4cout << "Click and move mouse to rotate volume \n" << G4endl; |
---|
| 971 | G4cout << "Press left/right arrows to move volume left/right\n" << G4endl; |
---|
| 972 | G4cout << "Press up/down arrows to move volume up/down\n" << G4endl; |
---|
| 973 | G4cout << "Press CONTROL+up/down arrows to move volume toward/forward\n" << G4endl; |
---|
| 974 | G4cout << "Press SHIFT+left/right arrows to rotate volume left/right\n" << G4endl; |
---|
| 975 | G4cout << "Press SHIFT+up/down arrows to rotate volume up/down\n" << G4endl; |
---|
| 976 | G4cout << "Press +/- to zoom into volume\n" << G4endl; |
---|
[678] | 977 | } |
---|
| 978 | |
---|
| 979 | } |
---|
| 980 | /** |
---|
[565] | 981 | Slot activated when drawing menu is toggle |
---|
| 982 | Warning : When G4OpenGLStoredQtViewer::DrawView() method call, |
---|
| 983 | KernelVisitDecision () will be call and will set the fNeedKernelVisit |
---|
| 984 | to 1. See G4XXXStoredViewer::CompareForKernelVisit for explanations. |
---|
| 985 | It will cause a redraw of the view |
---|
| 986 | @param aAction : 1 wireframe, 2 line removal, 3 surface removal, 4 line & surface removal |
---|
| 987 | @see G4OpenGLStoredQtViewer::DrawView |
---|
| 988 | @see G4XXXStoredViewer::CompareForKernelVisit |
---|
[564] | 989 | */ |
---|
| 990 | void G4OpenGLQtViewer::toggleDrawingAction(int aAction) { |
---|
| 991 | |
---|
| 992 | G4ViewParameters::DrawingStyle d_style; |
---|
[539] | 993 | |
---|
| 994 | |
---|
[564] | 995 | if (aAction ==1) { |
---|
[600] | 996 | #if QT_VERSION < 0x040000 |
---|
| 997 | fDrawingWireframe->setItemChecked (0,true); |
---|
| 998 | fDrawingLineRemoval->setItemChecked (0,false); |
---|
| 999 | fDrawingSurfaceRemoval->setItemChecked (0,false); |
---|
| 1000 | fDrawingLineSurfaceRemoval->setItemChecked (0,false); |
---|
| 1001 | #else |
---|
[564] | 1002 | fDrawingWireframe->setChecked (true); |
---|
| 1003 | fDrawingLineRemoval->setChecked (false); |
---|
| 1004 | fDrawingSurfaceRemoval->setChecked (false); |
---|
| 1005 | fDrawingLineSurfaceRemoval->setChecked (false); |
---|
[600] | 1006 | #endif |
---|
[564] | 1007 | |
---|
| 1008 | d_style = G4ViewParameters::wireframe; |
---|
| 1009 | |
---|
| 1010 | } else if (aAction ==2) { |
---|
[600] | 1011 | #if QT_VERSION < 0x040000 |
---|
| 1012 | fDrawingWireframe->setItemChecked (0,false); |
---|
| 1013 | fDrawingLineRemoval->setItemChecked (0,true); |
---|
| 1014 | fDrawingSurfaceRemoval->setItemChecked (0,false); |
---|
| 1015 | fDrawingLineSurfaceRemoval->setItemChecked (0,false); |
---|
| 1016 | #else |
---|
[564] | 1017 | fDrawingWireframe->setChecked (false); |
---|
| 1018 | fDrawingLineRemoval->setChecked (true); |
---|
| 1019 | fDrawingSurfaceRemoval->setChecked (false); |
---|
| 1020 | fDrawingLineSurfaceRemoval->setChecked (false); |
---|
[600] | 1021 | #endif |
---|
[564] | 1022 | |
---|
| 1023 | d_style = G4ViewParameters::hlr; |
---|
| 1024 | |
---|
| 1025 | } else if (aAction ==3) { |
---|
[600] | 1026 | #if QT_VERSION < 0x040000 |
---|
| 1027 | fDrawingWireframe->setItemChecked (0,false); |
---|
| 1028 | fDrawingLineRemoval->setItemChecked (0,false); |
---|
| 1029 | fDrawingSurfaceRemoval->setItemChecked (0,true); |
---|
| 1030 | fDrawingLineSurfaceRemoval->setItemChecked (0,false); |
---|
| 1031 | #else |
---|
[564] | 1032 | fDrawingWireframe->setChecked (false); |
---|
| 1033 | fDrawingLineRemoval->setChecked (false); |
---|
| 1034 | fDrawingSurfaceRemoval->setChecked (true); |
---|
| 1035 | fDrawingLineSurfaceRemoval->setChecked (false); |
---|
[600] | 1036 | #endif |
---|
[564] | 1037 | |
---|
| 1038 | d_style = G4ViewParameters::hsr; |
---|
| 1039 | |
---|
| 1040 | } else if (aAction ==4) { |
---|
[600] | 1041 | #if QT_VERSION < 0x040000 |
---|
| 1042 | fDrawingWireframe->setItemChecked (0,false); |
---|
| 1043 | fDrawingLineRemoval->setItemChecked (0,false); |
---|
| 1044 | fDrawingSurfaceRemoval->setItemChecked (0,false); |
---|
| 1045 | fDrawingLineSurfaceRemoval->setItemChecked (0,true); |
---|
| 1046 | #else |
---|
[564] | 1047 | fDrawingWireframe->setChecked (false); |
---|
| 1048 | fDrawingLineRemoval->setChecked (false); |
---|
| 1049 | fDrawingSurfaceRemoval->setChecked (false); |
---|
| 1050 | fDrawingLineSurfaceRemoval->setChecked (true); |
---|
[600] | 1051 | #endif |
---|
[564] | 1052 | d_style = G4ViewParameters::hlhsr; |
---|
| 1053 | } |
---|
| 1054 | fVP.SetDrawingStyle(d_style); |
---|
| 1055 | |
---|
| 1056 | updateQWidget(); |
---|
[608] | 1057 | #ifdef GEANT4_QT_DEBUG |
---|
[564] | 1058 | printf("G4OpenGLQtViewer::toggleDrawingAction\n"); |
---|
[608] | 1059 | #endif |
---|
[539] | 1060 | } |
---|
| 1061 | |
---|
[564] | 1062 | |
---|
| 1063 | /** |
---|
| 1064 | SLOT Activate by a click on the representation menu |
---|
[565] | 1065 | Warning : When G4OpenGLStoredQtViewer::DrawView() method call, |
---|
| 1066 | KernelVisitDecision () will be call and will set the fNeedKernelVisit |
---|
| 1067 | to 1. See G4XXXStoredViewer::CompareForKernelVisit for explanations. |
---|
| 1068 | It will cause a redraw of the view |
---|
[564] | 1069 | @param check : 1 polyhedron, 0 nurbs |
---|
[565] | 1070 | @see G4OpenGLStoredQtViewer::DrawView |
---|
| 1071 | @see G4XXXStoredViewer::CompareForKernelVisit |
---|
[564] | 1072 | */ |
---|
| 1073 | void G4OpenGLQtViewer::toggleRepresentation(bool check) { |
---|
| 1074 | |
---|
| 1075 | G4ViewParameters::RepStyle style; |
---|
| 1076 | if (check == 1) { |
---|
| 1077 | style = G4ViewParameters::polyhedron; |
---|
| 1078 | } else { |
---|
| 1079 | style = G4ViewParameters::nurbs; |
---|
| 1080 | } |
---|
| 1081 | fVP.SetRepStyle (style); |
---|
| 1082 | |
---|
| 1083 | updateQWidget(); |
---|
[530] | 1084 | } |
---|
| 1085 | |
---|
[564] | 1086 | /** |
---|
[702] | 1087 | SLOT Activate by a click on the projection menu |
---|
| 1088 | Warning : When G4OpenGLStoredQtViewer::DrawView() method call, |
---|
| 1089 | KernelVisitDecision () will be call and will set the fNeedKernelVisit |
---|
| 1090 | to 1. See G4XXXStoredViewer::CompareForKernelVisit for explanations. |
---|
| 1091 | It will cause a redraw of the view |
---|
| 1092 | @param check : 1 orthographic, 2 perspective |
---|
| 1093 | @see G4OpenGLStoredQtViewer::DrawView |
---|
| 1094 | @see G4XXXStoredViewer::CompareForKernelVisit |
---|
| 1095 | */ |
---|
| 1096 | void G4OpenGLQtViewer::toggleProjection(bool check) { |
---|
| 1097 | |
---|
| 1098 | if (check == 1) { |
---|
| 1099 | fVP.SetFieldHalfAngle (0); |
---|
| 1100 | } else { |
---|
[703] | 1101 | |
---|
[702] | 1102 | // look for the default parameter hidden in G4UIcommand parameters |
---|
| 1103 | G4UImanager* UI = G4UImanager::GetUIpointer(); |
---|
| 1104 | if(UI==NULL) |
---|
| 1105 | return; |
---|
| 1106 | G4UIcommandTree * treeTop = UI->GetTree(); |
---|
| 1107 | |
---|
| 1108 | // find command |
---|
| 1109 | G4UIcommand* command = treeTop->FindPath("/vis/viewer/set/projection"); |
---|
| 1110 | if (!command) |
---|
| 1111 | return; |
---|
| 1112 | |
---|
| 1113 | // find param |
---|
[703] | 1114 | G4UIparameter * angleParam = NULL; |
---|
[702] | 1115 | for(G4int i=0; i<command->GetParameterEntries(); i++) |
---|
| 1116 | { |
---|
| 1117 | if( command->GetParameter(i)->GetParameterName() == "field-half-angle" ) { |
---|
[703] | 1118 | angleParam = command->GetParameter(i); |
---|
[702] | 1119 | } |
---|
| 1120 | } |
---|
[703] | 1121 | if (!angleParam) |
---|
[702] | 1122 | return; |
---|
[703] | 1123 | |
---|
| 1124 | // find unit |
---|
| 1125 | G4UIparameter * unitParam = NULL; |
---|
| 1126 | for(G4int i=0; i<command->GetParameterEntries(); i++) |
---|
| 1127 | { |
---|
| 1128 | if( command->GetParameter(i)->GetParameterName() == "unit" ) { |
---|
| 1129 | unitParam = command->GetParameter(i); |
---|
| 1130 | } |
---|
| 1131 | } |
---|
| 1132 | if (!unitParam) |
---|
| 1133 | return; |
---|
| 1134 | |
---|
| 1135 | G4double defaultValue = command->ConvertToDouble(angleParam->GetDefaultValue()) |
---|
| 1136 | * G4UnitDefinition::GetValueOf(unitParam->GetDefaultValue()); |
---|
| 1137 | if (defaultValue > 89.5 || defaultValue <= 0.0) { |
---|
| 1138 | G4cerr << "Field half angle should be 0 < angle <= 89.5 degrees. Check your default Field half angle parameter\n"; |
---|
| 1139 | } else { |
---|
| 1140 | G4cout << "Perspective view has been set to default value. Field half angle="<<angleParam->GetDefaultValue() <<" \n" << G4endl; |
---|
| 1141 | fVP.SetFieldHalfAngle (defaultValue); |
---|
| 1142 | SetView (); |
---|
| 1143 | } |
---|
| 1144 | } |
---|
[702] | 1145 | updateQWidget(); |
---|
| 1146 | } |
---|
| 1147 | |
---|
| 1148 | |
---|
| 1149 | /** |
---|
[564] | 1150 | SLOT Activate by a click on the background menu |
---|
| 1151 | @param check : 1 white, 0 black |
---|
| 1152 | */ |
---|
| 1153 | void G4OpenGLQtViewer::toggleBackground(bool check) { |
---|
| 1154 | |
---|
| 1155 | // //I need to revisit the kernel if the background colour changes and |
---|
| 1156 | // //hidden line removal is enabled, because hlr drawing utilises the |
---|
| 1157 | // //background colour in its drawing... |
---|
| 1158 | // // (Note added by JA 13/9/2005) Background now handled in view |
---|
| 1159 | // // parameters. A kernel visit is triggered on change of background. |
---|
| 1160 | if (check == 1) { |
---|
| 1161 | ((G4ViewParameters&)this->GetViewParameters()). |
---|
| 1162 | SetBackgroundColour(G4Colour(1.,1.,1.)); // White |
---|
| 1163 | } else { |
---|
| 1164 | ((G4ViewParameters&)this->GetViewParameters()). |
---|
| 1165 | SetBackgroundColour(G4Colour(0.,0.,0.)); // Black |
---|
| 1166 | } |
---|
| 1167 | updateQWidget(); |
---|
[530] | 1168 | } |
---|
| 1169 | |
---|
[564] | 1170 | /** |
---|
| 1171 | SLOT Activate by a click on the transparency menu |
---|
| 1172 | @param check : 1 , 0 |
---|
| 1173 | */ |
---|
| 1174 | void G4OpenGLQtViewer::toggleTransparency(bool check) { |
---|
| 1175 | |
---|
| 1176 | if (check) { |
---|
| 1177 | transparency_enabled = false; |
---|
| 1178 | } else { |
---|
| 1179 | transparency_enabled = true; |
---|
| 1180 | } |
---|
| 1181 | SetNeedKernelVisit (true); |
---|
| 1182 | updateQWidget(); |
---|
| 1183 | } |
---|
[530] | 1184 | |
---|
[564] | 1185 | /** |
---|
| 1186 | SLOT Activate by a click on the antialiasing menu |
---|
| 1187 | @param check : 1 , 0 |
---|
| 1188 | */ |
---|
| 1189 | void G4OpenGLQtViewer::toggleAntialiasing(bool check) { |
---|
| 1190 | |
---|
| 1191 | if (!check) { |
---|
| 1192 | antialiasing_enabled = false; |
---|
| 1193 | glDisable (GL_LINE_SMOOTH); |
---|
| 1194 | glDisable (GL_POLYGON_SMOOTH); |
---|
| 1195 | } else { |
---|
| 1196 | antialiasing_enabled = true; |
---|
| 1197 | glEnable (GL_LINE_SMOOTH); |
---|
| 1198 | glHint (GL_LINE_SMOOTH_HINT, GL_NICEST); |
---|
| 1199 | glEnable (GL_POLYGON_SMOOTH); |
---|
| 1200 | glHint (GL_POLYGON_SMOOTH_HINT, GL_NICEST); |
---|
[530] | 1201 | } |
---|
[564] | 1202 | |
---|
| 1203 | updateQWidget(); |
---|
| 1204 | } |
---|
| 1205 | |
---|
| 1206 | /** |
---|
| 1207 | SLOT Activate by a click on the haloing menu |
---|
| 1208 | @param check : 1 , 0 |
---|
[530] | 1209 | */ |
---|
[564] | 1210 | //FIXME : I SEE NOTHING... |
---|
| 1211 | void G4OpenGLQtViewer::toggleHaloing(bool check) { |
---|
| 1212 | if (check) { |
---|
| 1213 | haloing_enabled = false; |
---|
| 1214 | } else { |
---|
| 1215 | haloing_enabled = true; |
---|
| 1216 | } |
---|
[530] | 1217 | |
---|
[564] | 1218 | updateQWidget(); |
---|
[530] | 1219 | |
---|
[564] | 1220 | } |
---|
| 1221 | |
---|
| 1222 | /** |
---|
| 1223 | SLOT Activate by a click on the auxiliaire edges menu |
---|
| 1224 | @param check : 1 , 0 |
---|
| 1225 | */ |
---|
| 1226 | void G4OpenGLQtViewer::toggleAux(bool check) { |
---|
| 1227 | if (check) { |
---|
| 1228 | fVP.SetAuxEdgeVisible(false); |
---|
| 1229 | } else { |
---|
| 1230 | fVP.SetAuxEdgeVisible(true); |
---|
| 1231 | } |
---|
| 1232 | SetNeedKernelVisit (true); |
---|
| 1233 | updateQWidget(); |
---|
| 1234 | |
---|
| 1235 | } |
---|
| 1236 | |
---|
| 1237 | /** |
---|
| 1238 | SLOT Activate by a click on the full screen menu |
---|
| 1239 | */ |
---|
[704] | 1240 | void G4OpenGLQtViewer::toggleFullScreen() { |
---|
[617] | 1241 | #if QT_VERSION >= 0x030200 |
---|
[564] | 1242 | GLWindow->setWindowState(GLWindow->windowState() ^ Qt::WindowFullScreen); |
---|
[617] | 1243 | #else |
---|
[638] | 1244 | G4cerr << "This version of G4UI Could not generate the selected format\n" << G4endl; |
---|
[617] | 1245 | #endif |
---|
[564] | 1246 | } |
---|
| 1247 | |
---|
[565] | 1248 | void G4OpenGLQtViewer::actionCreateEPS() { |
---|
[580] | 1249 | QString filters; |
---|
[600] | 1250 | #if QT_VERSION < 0x040000 |
---|
| 1251 | QStrList listFormat=QImageIO::outputFormats(); |
---|
| 1252 | char *tmp=listFormat.first(); |
---|
| 1253 | while (tmp!=0) { |
---|
| 1254 | filters += QString(tmp) + ";;"; |
---|
| 1255 | tmp=listFormat.next(); |
---|
| 1256 | } |
---|
| 1257 | #else |
---|
[580] | 1258 | QList<QByteArray> formats = QImageWriter::supportedImageFormats (); |
---|
| 1259 | for (int i = 0; i < formats.size(); ++i) { |
---|
[600] | 1260 | filters +=formats.at(i) + ";;"; |
---|
[580] | 1261 | } |
---|
[600] | 1262 | #endif |
---|
[588] | 1263 | filters += "eps;;"; |
---|
| 1264 | filters += "ps;;"; |
---|
| 1265 | filters += "pdf"; |
---|
[639] | 1266 | QString* selectedFormat = new QString(); |
---|
[600] | 1267 | #if QT_VERSION < 0x040000 |
---|
| 1268 | QString nomFich = QFileDialog::getSaveFileName ( ".", |
---|
| 1269 | filters, |
---|
| 1270 | GLWindow, |
---|
| 1271 | "Save file dialog", |
---|
| 1272 | tr("Save as ..."), |
---|
[639] | 1273 | selectedFormat ); |
---|
[600] | 1274 | #else |
---|
[580] | 1275 | QString nomFich = QFileDialog::getSaveFileName ( GLWindow, |
---|
| 1276 | tr("Save as ..."), |
---|
| 1277 | ".", |
---|
[582] | 1278 | filters, |
---|
[639] | 1279 | selectedFormat ); |
---|
[600] | 1280 | #endif |
---|
[580] | 1281 | // bmp jpg jpeg png ppm xbm xpm |
---|
[582] | 1282 | if (nomFich == "") { |
---|
| 1283 | return; |
---|
| 1284 | } |
---|
[600] | 1285 | #if QT_VERSION < 0x040000 |
---|
[639] | 1286 | nomFich += "."+QString(selectedFormat->ascii()); |
---|
| 1287 | QString format = selectedFormat->lower(); |
---|
[600] | 1288 | #else |
---|
[639] | 1289 | nomFich += "."+QString(selectedFormat->toStdString().c_str()); |
---|
| 1290 | QString format = selectedFormat->toLower(); |
---|
[600] | 1291 | #endif |
---|
[656] | 1292 | G4OpenGLQtExportDialog* exportDialog= new G4OpenGLQtExportDialog(GLWindow,format,fWindow->height(),fWindow->width()); |
---|
[585] | 1293 | if( exportDialog->exec()) { |
---|
[593] | 1294 | |
---|
| 1295 | QImage image; |
---|
[655] | 1296 | bool res = false; |
---|
[635] | 1297 | if ((exportDialog->getWidth() !=fWindow->width()) || |
---|
| 1298 | (exportDialog->getHeight() !=fWindow->height())) { |
---|
[655] | 1299 | if (format != QString("eps")) { |
---|
[638] | 1300 | 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] | 1301 | |
---|
[635] | 1302 | // rescaleImage(exportDialog->getWidth(),exportDialog->getHeight());// re-scale image |
---|
| 1303 | // QGLWidget* glResized = fWindow; |
---|
| 1304 | |
---|
| 1305 | // FIXME : |
---|
| 1306 | // L.Garnier : I've try to implement change size function, but the problem is |
---|
| 1307 | // the renderPixmap function call the QGLWidget to resize and it doesn't draw |
---|
| 1308 | // the content of this widget... It only draw the background. |
---|
| 1309 | |
---|
| 1310 | // fWindow->renderPixmap (exportDialog->getWidth()*2,exportDialog->getHeight()*2,true ); |
---|
| 1311 | |
---|
| 1312 | // QPixmap pixmap = fWindow->renderPixmap (); |
---|
| 1313 | |
---|
| 1314 | // image = pixmap->toImage(); |
---|
[593] | 1315 | // glResized->resize(exportDialog->getWidth()*2,exportDialog->getHeight()*2); |
---|
| 1316 | // image = glResized->grabFrameBuffer(); |
---|
[655] | 1317 | } |
---|
[635] | 1318 | } else { |
---|
| 1319 | image = fWindow->grabFrameBuffer(); |
---|
| 1320 | } |
---|
[639] | 1321 | if (format == QString("eps")) { |
---|
[652] | 1322 | if (exportDialog->getVectorEPS()) { |
---|
[655] | 1323 | res = generateVectorEPS(nomFich,exportDialog->getWidth(),exportDialog->getHeight(),image); |
---|
[652] | 1324 | } else { |
---|
[655] | 1325 | res = generateEPS(nomFich,exportDialog->getNbColor(),image); |
---|
[652] | 1326 | } |
---|
[639] | 1327 | } else if ((format == "ps") || (format == "pdf")) { |
---|
[655] | 1328 | res = generatePS_PDF(nomFich,exportDialog->getNbColor(),image); |
---|
| 1329 | } else if ((format == "tif") || |
---|
| 1330 | (format == "tiff") || |
---|
| 1331 | (format == "jpg") || |
---|
| 1332 | (format == "jpeg") || |
---|
| 1333 | (format == "png") || |
---|
| 1334 | (format == "pbm") || |
---|
| 1335 | (format == "pgm") || |
---|
| 1336 | (format == "ppm") || |
---|
| 1337 | (format == "bmp") || |
---|
| 1338 | (format == "xbm") || |
---|
| 1339 | (format == "xpm")) { |
---|
[639] | 1340 | #if QT_VERSION < 0x040000 |
---|
[655] | 1341 | res = image.save(nomFich,selectedFormat->ascii(),exportDialog->getSliderValue()); |
---|
[639] | 1342 | #else |
---|
[655] | 1343 | res = image.save(nomFich,0,exportDialog->getSliderValue()); |
---|
[639] | 1344 | #endif |
---|
[585] | 1345 | } else { |
---|
[638] | 1346 | G4cerr << "This version of G4UI Could not generate the selected format\n" << G4endl; |
---|
[585] | 1347 | } |
---|
[655] | 1348 | if (res == false) { |
---|
| 1349 | #if QT_VERSION < 0x040000 |
---|
| 1350 | G4cerr << "Error while saving file... "<<nomFich.ascii()<<"\n" << G4endl; |
---|
| 1351 | #else |
---|
| 1352 | G4cerr << "Error while saving file... "<<nomFich.toStdString().c_str()<<"\n" << G4endl; |
---|
| 1353 | #endif |
---|
| 1354 | } else { |
---|
| 1355 | #if QT_VERSION < 0x040000 |
---|
[656] | 1356 | G4cout << "File "<<nomFich.ascii()<<" has been saved \n" << G4endl; |
---|
[655] | 1357 | #else |
---|
[656] | 1358 | G4cout << "File "<<nomFich.toStdString().c_str()<<" has been saved \n" << G4endl; |
---|
[655] | 1359 | #endif |
---|
| 1360 | } |
---|
[585] | 1361 | |
---|
| 1362 | } else { // cancel selected |
---|
| 1363 | return; |
---|
[568] | 1364 | } |
---|
[580] | 1365 | |
---|
[608] | 1366 | #ifdef GEANT4_QT_DEBUG |
---|
[565] | 1367 | printf("G4OpenGLQtViewer::actionCreateEPS() \n"); |
---|
[608] | 1368 | #endif |
---|
[565] | 1369 | } |
---|
| 1370 | |
---|
[580] | 1371 | /* |
---|
| 1372 | // 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] | 1373 | |
---|
[580] | 1374 | void Graph::exportToSVG(const QString& fname) |
---|
| 1375 | { |
---|
| 1376 | // enable workaround for Qt3 misalignments |
---|
| 1377 | QwtPainter::setSVGMode(true); |
---|
| 1378 | QPicture picture; |
---|
| 1379 | QPainter p(&picture); |
---|
| 1380 | d_plot->print(&p, d_plot->rect()); |
---|
| 1381 | p.end(); |
---|
[565] | 1382 | |
---|
[580] | 1383 | picture.save(fname, "svg"); |
---|
| 1384 | } |
---|
| 1385 | */ |
---|
| 1386 | |
---|
| 1387 | |
---|
| 1388 | |
---|
| 1389 | |
---|
[564] | 1390 | /** |
---|
| 1391 | Save the current mouse press point |
---|
| 1392 | @param p mouse click point |
---|
| 1393 | */ |
---|
| 1394 | void G4OpenGLQtViewer::G4MousePressEvent(QPoint p) |
---|
| 1395 | { |
---|
[696] | 1396 | fLastPos = p; |
---|
[707] | 1397 | if (fMouseAction == STYLE2){ // pick |
---|
[681] | 1398 | Pick(p.x(),p.y()); |
---|
| 1399 | } |
---|
[564] | 1400 | } |
---|
| 1401 | |
---|
[696] | 1402 | |
---|
[564] | 1403 | /** |
---|
| 1404 | @param pos_x mouse x position |
---|
| 1405 | @param pos_y mouse y position |
---|
| 1406 | @param mButtons mouse button active |
---|
| 1407 | */ |
---|
[599] | 1408 | |
---|
| 1409 | #if QT_VERSION < 0x040000 |
---|
[696] | 1410 | void G4OpenGLQtViewer::G4MouseEvent(int pos_x, int pos_y,Qt::ButtonState mButtons) |
---|
[599] | 1411 | #else |
---|
[696] | 1412 | void G4OpenGLQtViewer::G4MouseEvent(int pos_x, int pos_y,Qt::MouseButtons mButtons) |
---|
[599] | 1413 | #endif |
---|
[564] | 1414 | { |
---|
[713] | 1415 | |
---|
[703] | 1416 | int dx = fLastPos.x() - pos_x; |
---|
| 1417 | int dy = fLastPos.y() - pos_y; |
---|
[713] | 1418 | |
---|
| 1419 | |
---|
[696] | 1420 | if (fMouseAction == STYLE1) { // rotate |
---|
[564] | 1421 | if (mButtons & Qt::LeftButton) { |
---|
[696] | 1422 | G4MouseRotateEvent(dx,dy); |
---|
[564] | 1423 | } |
---|
[713] | 1424 | } else if (fMouseAction == STYLE2) { // move |
---|
| 1425 | if (mButtons & Qt::LeftButton) { |
---|
| 1426 | G4double coef = ((G4double)getSceneNearWidth())/((G4double)WinSize_x); |
---|
| 1427 | if (WinSize_y <WinSize_x) { |
---|
| 1428 | coef = ((G4double)getSceneNearWidth())/((G4double)WinSize_y); |
---|
| 1429 | } |
---|
| 1430 | fVP.IncrementPan(dx*coef,-dy*coef); |
---|
| 1431 | updateQWidget(); |
---|
| 1432 | } |
---|
[564] | 1433 | } |
---|
[696] | 1434 | fLastPos = QPoint(pos_x, pos_y); |
---|
[564] | 1435 | } |
---|
| 1436 | |
---|
[696] | 1437 | /** |
---|
[711] | 1438 | Move the scene of dx, dy, dz values. |
---|
[696] | 1439 | @param dx delta mouse x position |
---|
| 1440 | @param dy delta mouse y position |
---|
| 1441 | */ |
---|
| 1442 | |
---|
[713] | 1443 | void G4OpenGLQtViewer::G4MouseMoveEvent(G4double dx,G4double dy, G4double dz) |
---|
[696] | 1444 | { |
---|
[712] | 1445 | GLdouble coefTrans = getSceneNearWidth()*fDeltaSceneTranslation; |
---|
| 1446 | GLdouble coefDepth = getSceneDepth()*fDeltaDepth; |
---|
[707] | 1447 | |
---|
[713] | 1448 | fVP.IncrementPan(-dx*coefTrans,dy*coefTrans,dz*coefDepth); |
---|
[712] | 1449 | |
---|
[713] | 1450 | updateQWidget(); |
---|
[696] | 1451 | } |
---|
| 1452 | |
---|
| 1453 | |
---|
| 1454 | /** |
---|
| 1455 | @param dx delta mouse x position |
---|
| 1456 | @param dy delta mouse y position |
---|
| 1457 | */ |
---|
| 1458 | |
---|
[713] | 1459 | void G4OpenGLQtViewer::G4MouseRotateEvent(G4double dx, G4double dy) |
---|
[696] | 1460 | { |
---|
[713] | 1461 | dx = dx * fDeltaRotation; |
---|
| 1462 | dy = dy * fDeltaRotation; |
---|
| 1463 | |
---|
[696] | 1464 | //phi spin stuff here |
---|
| 1465 | |
---|
| 1466 | G4Vector3D vp = fVP.GetViewpointDirection ().unit (); |
---|
| 1467 | G4Vector3D up = fVP.GetUpVector ().unit (); |
---|
| 1468 | |
---|
| 1469 | G4Vector3D yprime = (up.cross(vp)).unit(); |
---|
| 1470 | G4Vector3D zprime = (vp.cross(yprime)).unit(); |
---|
| 1471 | |
---|
| 1472 | G4double delta_alpha; |
---|
| 1473 | G4double delta_theta; |
---|
| 1474 | |
---|
| 1475 | if (fVP.GetLightsMoveWithCamera()) { |
---|
| 1476 | delta_alpha = dy; |
---|
| 1477 | delta_theta = -dx; |
---|
| 1478 | } else { |
---|
| 1479 | delta_alpha = -dy; |
---|
| 1480 | delta_theta = dx; |
---|
| 1481 | } |
---|
| 1482 | |
---|
| 1483 | delta_alpha *= deg; |
---|
| 1484 | delta_theta *= deg; |
---|
| 1485 | |
---|
| 1486 | G4Vector3D new_vp = std::cos(delta_alpha) * vp + std::sin(delta_alpha) * zprime; |
---|
| 1487 | |
---|
| 1488 | G4Vector3D new_up; |
---|
| 1489 | if (fVP.GetLightsMoveWithCamera()) { |
---|
| 1490 | new_up = (new_vp.cross(yprime)).unit(); |
---|
| 1491 | fVP.SetUpVector(new_up); |
---|
| 1492 | } else { |
---|
| 1493 | new_up = up; |
---|
| 1494 | } |
---|
| 1495 | //////////////// |
---|
| 1496 | // Rotates by fixed azimuthal angle delta_theta. |
---|
| 1497 | |
---|
| 1498 | G4double cosalpha = new_up.dot (new_vp.unit()); |
---|
| 1499 | G4double sinalpha = std::sqrt (1. - std::pow (cosalpha, 2)); |
---|
| 1500 | yprime = (new_up.cross (new_vp.unit())).unit (); |
---|
| 1501 | G4Vector3D xprime = yprime.cross (new_up); |
---|
| 1502 | // Projection of vp on plane perpendicular to up... |
---|
| 1503 | G4Vector3D a1 = sinalpha * xprime; |
---|
| 1504 | // Required new projection... |
---|
| 1505 | G4Vector3D a2 = |
---|
| 1506 | sinalpha * (std::cos (delta_theta) * xprime + std::sin (delta_theta) * yprime); |
---|
| 1507 | // Required Increment vector... |
---|
| 1508 | G4Vector3D delta = a2 - a1; |
---|
| 1509 | // So new viewpoint is... |
---|
| 1510 | G4Vector3D viewPoint = new_vp.unit() + delta; |
---|
| 1511 | |
---|
| 1512 | fVP.SetViewAndLights (viewPoint); |
---|
| 1513 | updateQWidget(); |
---|
| 1514 | |
---|
| 1515 | } |
---|
| 1516 | |
---|
[660] | 1517 | /** This is the benning of a rescale function. It does nothing for the moment |
---|
| 1518 | @param aWidth : new width |
---|
| 1519 | @param aHeight : new height |
---|
| 1520 | */ |
---|
[585] | 1521 | void G4OpenGLQtViewer::rescaleImage( |
---|
| 1522 | int aWidth |
---|
| 1523 | ,int aHeight |
---|
| 1524 | ){ |
---|
[608] | 1525 | #ifdef GEANT4_QT_DEBUG |
---|
[586] | 1526 | printf("should rescale \n"); |
---|
[608] | 1527 | #endif |
---|
[660] | 1528 | GLfloat* feedback_buffer; |
---|
| 1529 | GLint returned; |
---|
| 1530 | FILE* file; |
---|
| 1531 | |
---|
[673] | 1532 | // feedback_buffer = new GLfloat[size]; |
---|
| 1533 | // glFeedbackBuffer (size, GL_3D_COLOR, feedback_buffer); |
---|
| 1534 | // glRenderMode (GL_FEEDBACK); |
---|
[660] | 1535 | |
---|
[673] | 1536 | // glViewport (0, 0, aWidth, aHeight); |
---|
| 1537 | // DrawView(); |
---|
| 1538 | // returned = glRenderMode (GL_RENDER); |
---|
[660] | 1539 | |
---|
[585] | 1540 | } |
---|
[586] | 1541 | |
---|
| 1542 | /** |
---|
[652] | 1543 | Generate Vectorial Encapsulated Postscript form image |
---|
[586] | 1544 | @param aFilename : name of file |
---|
| 1545 | @param aInColor : numbers of colors : 1->BW 2->RGB 3->RGB+Alpha |
---|
| 1546 | @param aImage : Image to print |
---|
| 1547 | */ |
---|
[652] | 1548 | bool G4OpenGLQtViewer::generateVectorEPS ( |
---|
| 1549 | QString aFilename |
---|
| 1550 | ,int aWidth |
---|
| 1551 | ,int aHeight |
---|
| 1552 | ,QImage aImage |
---|
| 1553 | ) |
---|
| 1554 | { |
---|
| 1555 | // Print vectored PostScript |
---|
| 1556 | |
---|
| 1557 | G4int size = 5000000; |
---|
| 1558 | |
---|
| 1559 | GLfloat* feedback_buffer; |
---|
| 1560 | GLint returned; |
---|
| 1561 | FILE* file; |
---|
| 1562 | |
---|
| 1563 | feedback_buffer = new GLfloat[size]; |
---|
| 1564 | glFeedbackBuffer (size, GL_3D_COLOR, feedback_buffer); |
---|
| 1565 | glRenderMode (GL_FEEDBACK); |
---|
| 1566 | |
---|
[709] | 1567 | int side = aWidth; |
---|
| 1568 | if (aHeight < aWidth) side = aHeight; |
---|
[675] | 1569 | glViewport((aWidth - side) / 2, (aHeight - side) / 2, side, side); |
---|
[652] | 1570 | DrawView(); |
---|
| 1571 | |
---|
| 1572 | returned = glRenderMode (GL_RENDER); |
---|
| 1573 | |
---|
| 1574 | |
---|
| 1575 | #if QT_VERSION < 0x040000 |
---|
| 1576 | file = fopen (aFilename.ascii(), "w"); |
---|
| 1577 | #else |
---|
| 1578 | file = fopen (aFilename.toStdString().c_str(), "w"); |
---|
| 1579 | #endif |
---|
| 1580 | if (file) { |
---|
| 1581 | spewWireframeEPS (file, returned, feedback_buffer, "rendereps"); |
---|
| 1582 | } else { |
---|
[658] | 1583 | #if QT_VERSION < 0x040000 |
---|
[673] | 1584 | G4cerr << "Could not open "<< aFilename.ascii()<<"\n" << G4endl; |
---|
[658] | 1585 | #else |
---|
[673] | 1586 | G4cerr << "Could not open "<< aFilename.toStdString().c_str()<<"\n" << G4endl; |
---|
[658] | 1587 | #endif |
---|
[652] | 1588 | } |
---|
| 1589 | |
---|
| 1590 | delete[] feedback_buffer; |
---|
| 1591 | |
---|
| 1592 | return true; |
---|
| 1593 | } |
---|
| 1594 | |
---|
| 1595 | /** |
---|
| 1596 | Generate Encapsulated Postscript form image |
---|
| 1597 | @param aFilename : name of file |
---|
| 1598 | @param aInColor : numbers of colors : 1->BW 2->RGB 3->RGB+Alpha |
---|
| 1599 | @param aImage : Image to print |
---|
| 1600 | */ |
---|
[588] | 1601 | bool G4OpenGLQtViewer::generateEPS ( |
---|
[586] | 1602 | QString aFilename |
---|
| 1603 | ,int aInColor |
---|
| 1604 | ,QImage aImage |
---|
| 1605 | ) |
---|
| 1606 | { |
---|
[587] | 1607 | // FIXME |
---|
[608] | 1608 | #ifdef GEANT4_QT_DEBUG |
---|
[586] | 1609 | printf("saving EPS\n"); |
---|
[608] | 1610 | #endif |
---|
[586] | 1611 | |
---|
| 1612 | FILE* fp; |
---|
[587] | 1613 | |
---|
[649] | 1614 | if (aImage.bits () == NULL) |
---|
[588] | 1615 | return false; |
---|
[586] | 1616 | |
---|
[600] | 1617 | #if QT_VERSION < 0x040000 |
---|
| 1618 | fp = fopen (aFilename.ascii(), "w"); |
---|
| 1619 | #else |
---|
[602] | 1620 | fp = fopen (aFilename.toStdString().c_str(), "w"); |
---|
[600] | 1621 | #endif |
---|
[586] | 1622 | if (fp == NULL) { |
---|
[588] | 1623 | return false; |
---|
[586] | 1624 | } |
---|
| 1625 | |
---|
| 1626 | fprintf (fp, "%%!PS-Adobe-2.0 EPSF-1.2\n"); |
---|
[600] | 1627 | #if QT_VERSION < 0x040000 |
---|
| 1628 | fprintf (fp, "%%%%Title: %s\n", aFilename.ascii()); |
---|
| 1629 | #else |
---|
[602] | 1630 | fprintf (fp, "%%%%Title: %s\n", aFilename.toStdString().c_str()); |
---|
[600] | 1631 | #endif |
---|
[586] | 1632 | fprintf (fp, "%%%%Creator: OpenGL pixmap render output\n"); |
---|
[587] | 1633 | fprintf (fp, "%%%%BoundingBox: 0 0 %d %d\n", aImage.width(), aImage.height()); |
---|
[586] | 1634 | fprintf (fp, "%%%%EndComments\n"); |
---|
| 1635 | fprintf (fp, "gsave\n"); |
---|
| 1636 | fprintf (fp, "/bwproc {\n"); |
---|
| 1637 | fprintf (fp, " rgbproc\n"); |
---|
| 1638 | fprintf (fp, " dup length 3 idiv string 0 3 0 \n"); |
---|
| 1639 | fprintf (fp, " 5 -1 roll {\n"); |
---|
| 1640 | fprintf (fp, " add 2 1 roll 1 sub dup 0 eq\n"); |
---|
| 1641 | fprintf (fp, " { pop 3 idiv 3 -1 roll dup 4 -1 roll dup\n"); |
---|
| 1642 | fprintf (fp, " 3 1 roll 5 -1 roll } put 1 add 3 0 \n"); |
---|
| 1643 | fprintf (fp, " { 2 1 roll } ifelse\n"); |
---|
| 1644 | fprintf (fp, " }forall\n"); |
---|
| 1645 | fprintf (fp, " pop pop pop\n"); |
---|
| 1646 | fprintf (fp, "} def\n"); |
---|
| 1647 | fprintf (fp, "systemdict /colorimage known not {\n"); |
---|
| 1648 | fprintf (fp, " /colorimage {\n"); |
---|
| 1649 | fprintf (fp, " pop\n"); |
---|
| 1650 | fprintf (fp, " pop\n"); |
---|
| 1651 | fprintf (fp, " /rgbproc exch def\n"); |
---|
| 1652 | fprintf (fp, " { bwproc } image\n"); |
---|
| 1653 | fprintf (fp, " } def\n"); |
---|
| 1654 | fprintf (fp, "} if\n"); |
---|
[587] | 1655 | fprintf (fp, "/picstr %d string def\n", aImage.width() * aInColor); |
---|
| 1656 | fprintf (fp, "%d %d scale\n", aImage.width(), aImage.height()); |
---|
| 1657 | fprintf (fp, "%d %d %d\n", aImage.width(), aImage.height(), 8); |
---|
| 1658 | fprintf (fp, "[%d 0 0 %d 0 0]\n", aImage.width(), aImage.height()); |
---|
[586] | 1659 | fprintf (fp, "{currentfile picstr readhexstring pop}\n"); |
---|
| 1660 | fprintf (fp, "false %d\n", aInColor); |
---|
| 1661 | fprintf (fp, "colorimage\n"); |
---|
| 1662 | |
---|
| 1663 | |
---|
[588] | 1664 | int width = aImage.width(); |
---|
| 1665 | int height = aImage.height(); |
---|
| 1666 | int depth = aImage.depth(); |
---|
| 1667 | int size = width*height; |
---|
| 1668 | |
---|
| 1669 | if (depth == 1) |
---|
| 1670 | size = (width+7)/8*height; |
---|
| 1671 | else if (aInColor == 1) |
---|
| 1672 | size = size*3; |
---|
| 1673 | |
---|
| 1674 | int i = 0; |
---|
[649] | 1675 | // if ( aInColor ==1 ) { |
---|
| 1676 | // FIXME : L. Garnier. For the moment 10 dec 2007, I could not find a way |
---|
| 1677 | // to save correctly grayscale Image. I mean that color or grayscale image |
---|
| 1678 | // have the same file save size ! |
---|
| 1679 | |
---|
| 1680 | /* } else*/ if (depth == 8) { |
---|
[588] | 1681 | for(int y=height-1; y >=0 ; y--) { |
---|
| 1682 | const uchar * s = aImage.scanLine(y); |
---|
| 1683 | for(int x=0; x <width; x++) { |
---|
| 1684 | QRgb rgb = aImage.color(s[x]); |
---|
| 1685 | if (aInColor == 1) { |
---|
| 1686 | fprintf (fp, " %02hx ",(unsigned char)qGray(rgb)); |
---|
| 1687 | i++; |
---|
| 1688 | } else { |
---|
| 1689 | fprintf (fp, " %02hx %02hx %02hx", |
---|
| 1690 | (unsigned char) qRed(rgb), |
---|
| 1691 | (unsigned char) qGreen(rgb), |
---|
| 1692 | (unsigned char) qBlue(rgb)); |
---|
| 1693 | i += 3; |
---|
| 1694 | } |
---|
| 1695 | } |
---|
[586] | 1696 | fprintf (fp, "\n"); |
---|
[588] | 1697 | } |
---|
| 1698 | } else { |
---|
[601] | 1699 | #if QT_VERSION < 0x040000 |
---|
[649] | 1700 | bool alpha = aImage.hasAlphaBuffer(); |
---|
[601] | 1701 | #else |
---|
[588] | 1702 | bool alpha = aImage.hasAlphaChannel(); |
---|
| 1703 | for(int y=height-1; y >=0 ; y--) { |
---|
| 1704 | QRgb * s = (QRgb*)(aImage.scanLine(y)); |
---|
| 1705 | for(int x=0; x <width; x++) { |
---|
| 1706 | QRgb rgb = (*s++); |
---|
| 1707 | if (alpha && qAlpha(rgb) < 0x40) // 25% alpha, convert to white - |
---|
| 1708 | rgb = qRgb(0xff, 0xff, 0xff); |
---|
| 1709 | if (aInColor == 1) { |
---|
| 1710 | fprintf (fp, " %02hx ",(unsigned char)qGray(rgb)); |
---|
| 1711 | i++; |
---|
| 1712 | } else { |
---|
| 1713 | fprintf (fp, " %02hx %02hx %02hx", |
---|
| 1714 | (unsigned char) qRed(rgb), |
---|
| 1715 | (unsigned char) qGreen(rgb), |
---|
| 1716 | (unsigned char) qBlue(rgb)); |
---|
| 1717 | i += 3; |
---|
| 1718 | } |
---|
[587] | 1719 | } |
---|
| 1720 | fprintf (fp, "\n"); |
---|
[588] | 1721 | } |
---|
[601] | 1722 | #endif |
---|
| 1723 | |
---|
[586] | 1724 | } |
---|
[588] | 1725 | |
---|
[586] | 1726 | fprintf (fp, "grestore\n"); |
---|
| 1727 | fprintf (fp, "showpage\n"); |
---|
| 1728 | fclose (fp); |
---|
[588] | 1729 | |
---|
| 1730 | return true; |
---|
[586] | 1731 | } |
---|
[588] | 1732 | /** |
---|
| 1733 | Generate Postscript or PDF form image |
---|
| 1734 | @param aFilename : name of file |
---|
| 1735 | @param aInColor : numbers of colors : 1->BW 2->RGB |
---|
| 1736 | @param aImage : Image to print |
---|
| 1737 | */ |
---|
| 1738 | bool G4OpenGLQtViewer::generatePS_PDF ( |
---|
| 1739 | QString aFilename |
---|
| 1740 | ,int aInColor |
---|
| 1741 | ,QImage aImage |
---|
| 1742 | ) |
---|
| 1743 | { |
---|
[638] | 1744 | |
---|
[600] | 1745 | #if QT_VERSION < 0x040000 |
---|
| 1746 | #ifdef Q_WS_MAC || Q_WS_X11 |
---|
[588] | 1747 | QPrinter printer; |
---|
| 1748 | // printer.setPageSize(pageSize); |
---|
| 1749 | if (aInColor == 1) { |
---|
| 1750 | printer.setColorMode(QPrinter::GrayScale); |
---|
| 1751 | } else { |
---|
| 1752 | printer.setColorMode(QPrinter::Color); |
---|
| 1753 | } |
---|
| 1754 | |
---|
[600] | 1755 | /* FIXME : I don't know which format it will save... |
---|
| 1756 | if (aFilename.endsWith(".ps")) { |
---|
| 1757 | printer.setOutputFormat(QPrinter::PostScriptFormat); |
---|
| 1758 | } else { |
---|
| 1759 | printer.setOutputFormat(QPrinter::PdfFormat); |
---|
| 1760 | } |
---|
| 1761 | */ |
---|
| 1762 | printer.setOutputFileName(aFilename); |
---|
| 1763 | // printer.setFullPage ( true); |
---|
| 1764 | QPainter paint(&printer); |
---|
| 1765 | paint.drawImage (0,0,aImage ); |
---|
| 1766 | paint.end(); |
---|
| 1767 | #else |
---|
[638] | 1768 | G4cerr << "This fonction is only supported on Mac OsX or X11 with Qt3. Full platform supported with Qt4\n" << G4endl; |
---|
[600] | 1769 | #endif |
---|
| 1770 | #else |
---|
| 1771 | QPrinter printer; |
---|
| 1772 | // printer.setPageSize(pageSize); |
---|
[637] | 1773 | |
---|
| 1774 | // FIXME : L. Garnier 4/12/07 |
---|
| 1775 | // This is not working, it does nothing. Image is staying in color mode |
---|
| 1776 | // So I have desactivate the B/W button in GUI |
---|
| 1777 | if ((!aImage.isGrayscale ()) &&(aInColor ==1 )) { |
---|
| 1778 | #if QT_VERSION < 0x040000 |
---|
| 1779 | aImage = aImage.convertDepth(1,Qt::MonoOnly); |
---|
| 1780 | #else |
---|
| 1781 | aImage = aImage.convertToFormat ( aImage.format(), Qt::MonoOnly); |
---|
| 1782 | #endif |
---|
[600] | 1783 | } |
---|
| 1784 | |
---|
[637] | 1785 | |
---|
[588] | 1786 | if (aFilename.endsWith(".ps")) { |
---|
[606] | 1787 | #if QT_VERSION > 0x040200 |
---|
[588] | 1788 | printer.setOutputFormat(QPrinter::PostScriptFormat); |
---|
[606] | 1789 | #endif |
---|
[588] | 1790 | } else { |
---|
[606] | 1791 | #if QT_VERSION > 0x040100 |
---|
[588] | 1792 | printer.setOutputFormat(QPrinter::PdfFormat); |
---|
[606] | 1793 | #endif |
---|
[588] | 1794 | } |
---|
[606] | 1795 | #if QT_VERSION > 0x040100 |
---|
[588] | 1796 | printer.setOutputFileName(aFilename); |
---|
[606] | 1797 | #endif |
---|
[588] | 1798 | // printer.setFullPage ( true); |
---|
| 1799 | QPainter paint(&printer); |
---|
[637] | 1800 | paint.drawImage (0,0,aImage); |
---|
[588] | 1801 | paint.end(); |
---|
[600] | 1802 | #endif |
---|
[588] | 1803 | return true; |
---|
| 1804 | } |
---|
| 1805 | |
---|
| 1806 | |
---|
[696] | 1807 | void G4OpenGLQtViewer::G4keyPressEvent (QKeyEvent * event) |
---|
| 1808 | { |
---|
[702] | 1809 | if (holdKeyEvent) |
---|
| 1810 | return; |
---|
| 1811 | |
---|
| 1812 | holdKeyEvent = true; |
---|
| 1813 | |
---|
[709] | 1814 | #if QT_VERSION < 0x040000 |
---|
| 1815 | if ((event->key() == Qt::Key_Down) && (event->state() & Qt::AltButton )) { // go backward |
---|
| 1816 | #else |
---|
[707] | 1817 | if ((event->key() == Qt::Key_Down) && (event->modifiers() & Qt::AltModifier )) { // go backward |
---|
[709] | 1818 | #endif |
---|
[712] | 1819 | |
---|
[707] | 1820 | G4MouseMoveEvent(0,0,1); |
---|
| 1821 | } |
---|
[709] | 1822 | #if QT_VERSION < 0x040000 |
---|
| 1823 | else if ((event->key() == Qt::Key_Up) && (event->state() & Qt::AltButton)) { // go forward |
---|
| 1824 | #else |
---|
[707] | 1825 | else if ((event->key() == Qt::Key_Up) && (event->modifiers() & Qt::AltModifier)) { // go forward |
---|
[709] | 1826 | #endif |
---|
[707] | 1827 | G4MouseMoveEvent(0,0,-1); |
---|
| 1828 | } |
---|
[709] | 1829 | #if QT_VERSION < 0x040000 |
---|
| 1830 | if ((event->key() == Qt::Key_Down) && (event->state() & Qt::ShiftButton)) { // rotate phi |
---|
| 1831 | #else |
---|
[707] | 1832 | if ((event->key() == Qt::Key_Down) && (event->modifiers() & Qt::ShiftModifier)) { // rotate phi |
---|
[709] | 1833 | #endif |
---|
[707] | 1834 | G4MouseRotateEvent(0,-1); |
---|
| 1835 | } |
---|
[709] | 1836 | #if QT_VERSION < 0x040000 |
---|
| 1837 | else if ((event->key() == Qt::Key_Up) && (event->state() & Qt::ShiftButton)) { // rotate phi |
---|
| 1838 | #else |
---|
[707] | 1839 | else if ((event->key() == Qt::Key_Up) && (event->modifiers() & Qt::ShiftModifier)) { // rotate phi |
---|
[709] | 1840 | #endif |
---|
[707] | 1841 | G4MouseRotateEvent(0,1); |
---|
| 1842 | } |
---|
[709] | 1843 | #if QT_VERSION < 0x040000 |
---|
| 1844 | if ((event->key() == Qt::Key_Left) && (event->state() & Qt::ShiftButton)) { // rotate theta |
---|
| 1845 | #else |
---|
[707] | 1846 | if ((event->key() == Qt::Key_Left) && (event->modifiers() & Qt::ShiftModifier)) { // rotate theta |
---|
[709] | 1847 | #endif |
---|
[707] | 1848 | G4MouseRotateEvent(1,0); |
---|
| 1849 | } |
---|
[709] | 1850 | #if QT_VERSION < 0x040000 |
---|
[707] | 1851 | else if ((event->key() == Qt::Key_Right) && (event->modifiers() & Qt::ShiftModifier)) { // rotate theta |
---|
[709] | 1852 | #else |
---|
| 1853 | else if ((event->key() == Qt::Key_Right) && (event->modifiers() & Qt::ShiftModifier)) { // rotate theta |
---|
| 1854 | #endif |
---|
[707] | 1855 | G4MouseRotateEvent(-1,0); |
---|
| 1856 | } |
---|
[704] | 1857 | if (event->key() == Qt::Key_Escape) { // escaped from full screen |
---|
| 1858 | toggleFullScreen(); |
---|
[707] | 1859 | } |
---|
| 1860 | if (event->key() == Qt::Key_Plus) { // zoom in |
---|
[712] | 1861 | fVP.SetZoomFactor(fVP.GetZoomFactor()*(1+fDeltaZoom)); |
---|
[707] | 1862 | updateQWidget(); |
---|
| 1863 | } |
---|
| 1864 | else if (event->key() == Qt::Key_Minus) { // zoom out |
---|
[712] | 1865 | fVP.SetZoomFactor(fVP.GetZoomFactor()*(1-fDeltaZoom)); |
---|
[707] | 1866 | updateQWidget(); |
---|
| 1867 | } |
---|
| 1868 | // with no modifiers |
---|
| 1869 | if (!event->modifiers()) { |
---|
| 1870 | if (event->key() == Qt::Key_Down) { // go down |
---|
[702] | 1871 | G4MouseMoveEvent(0,1,0); |
---|
[696] | 1872 | } |
---|
[707] | 1873 | else if (event->key() == Qt::Key_Up) { // go up |
---|
[702] | 1874 | G4MouseMoveEvent(0,-1,0); |
---|
[696] | 1875 | } |
---|
[707] | 1876 | if (event->key() == Qt::Key_Left) { // go left |
---|
[696] | 1877 | G4MouseMoveEvent(-1,0,0); |
---|
| 1878 | } |
---|
[707] | 1879 | else if (event->key() == Qt::Key_Right) { // go right |
---|
[696] | 1880 | G4MouseMoveEvent(1,0,0); |
---|
| 1881 | } |
---|
[707] | 1882 | } |
---|
[702] | 1883 | holdKeyEvent = false; |
---|
[696] | 1884 | } |
---|
| 1885 | |
---|
[588] | 1886 | /* |
---|
[696] | 1887 | |
---|
[588] | 1888 | void MultiLayer::exportToSVG(const QString& fname) |
---|
| 1889 | { |
---|
| 1890 | QPicture picture; |
---|
| 1891 | QPainter p(&picture); |
---|
| 1892 | for (int i=0;i<(int)graphsList->count();i++) |
---|
| 1893 | { |
---|
| 1894 | Graph *gr=(Graph *)graphsList->at(i); |
---|
| 1895 | Plot *myPlot= (Plot *)gr->plotWidget(); |
---|
| 1896 | |
---|
| 1897 | QPoint pos=gr->pos(); |
---|
| 1898 | |
---|
| 1899 | int width=int(myPlot->frameGeometry().width()); |
---|
| 1900 | int height=int(myPlot->frameGeometry().height()); |
---|
| 1901 | |
---|
| 1902 | myPlot->print(&p, QRect(pos,QSize(width,height))); |
---|
| 1903 | } |
---|
| 1904 | |
---|
| 1905 | p.end(); |
---|
| 1906 | picture.save(fname, "svg"); |
---|
| 1907 | } |
---|
| 1908 | */ |
---|
[707] | 1909 | #endif |
---|