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