[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 | // |
---|
[632] | 27 | // $Id: G4OpenGLQtViewer.cc,v 1.8 2007/11/30 14:47:30 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 | |
---|
[635] | 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" |
---|
[530] | 50 | |
---|
[539] | 51 | #include "G4Qt.hh" |
---|
[569] | 52 | #include "G4UIsession.hh" |
---|
| 53 | #include "G4UImanager.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 | { |
---|
| 104 | int side = qMin(aWidth, aHeight); |
---|
| 105 | glViewport((aWidth - side) / 2, (aHeight - side) / 2, side, side); |
---|
| 106 | |
---|
| 107 | glMatrixMode(GL_PROJECTION); |
---|
| 108 | glLoadIdentity(); |
---|
| 109 | glOrtho(-0.5, +0.5, +0.5, -0.5, 4.0, 15.0); |
---|
| 110 | glMatrixMode(GL_MODELVIEW); |
---|
| 111 | } |
---|
[530] | 112 | |
---|
| 113 | |
---|
| 114 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 115 | /** |
---|
[564] | 116 | Implementation of virtual method of G4VViewer |
---|
| 117 | */ |
---|
[530] | 118 | void G4OpenGLQtViewer::ShowView ( |
---|
| 119 | ) |
---|
| 120 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 121 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
| 122 | { |
---|
[608] | 123 | #ifdef GEANT4_QT_DEBUG |
---|
[542] | 124 | printf("G4OpenGLQtViewer::ShowView +++++++++++++++++++++\n"); |
---|
[608] | 125 | #endif |
---|
[564] | 126 | glFlush (); |
---|
[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 | } |
---|
[564] | 139 | // // Empty the Windows message queue : |
---|
| 140 | // MSG event; |
---|
| 141 | // while ( ::PeekMessage(&event, NULL, 0, 0, PM_REMOVE) ) { |
---|
| 142 | // ::TranslateMessage(&event); |
---|
| 143 | // ::DispatchMessage (&event); |
---|
| 144 | // } |
---|
[530] | 145 | } |
---|
| 146 | |
---|
| 147 | |
---|
| 148 | |
---|
| 149 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 150 | void G4OpenGLQtViewer::CreateGLQtContext ( |
---|
| 151 | ) |
---|
| 152 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 153 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
| 154 | { |
---|
[608] | 155 | #ifdef GEANT4_QT_DEBUG |
---|
[530] | 156 | printf("G4OpenGLQtViewer::CreateGLQtContext \n"); |
---|
[608] | 157 | #endif |
---|
[530] | 158 | } |
---|
| 159 | |
---|
[564] | 160 | |
---|
[530] | 161 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 162 | void G4OpenGLQtViewer::CreateMainWindow ( |
---|
[585] | 163 | QGLWidget* glWidget |
---|
| 164 | ) |
---|
[530] | 165 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 166 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
| 167 | { |
---|
| 168 | |
---|
[538] | 169 | if(fWindow) return; //Done. |
---|
[608] | 170 | #ifdef GEANT4_QT_DEBUG |
---|
[564] | 171 | printf("G4OpenGLQtViewer::CreateMainWindow glWidget\n"); |
---|
[608] | 172 | #endif |
---|
[538] | 173 | |
---|
[539] | 174 | // launch Qt if not |
---|
| 175 | G4Qt* interactorManager = G4Qt::getInstance (); |
---|
| 176 | // G4UImanager* UI = G4UImanager::GetUIpointer(); |
---|
| 177 | |
---|
[564] | 178 | fWindow = glWidget ; |
---|
[543] | 179 | // fWindow->makeCurrent(); |
---|
[538] | 180 | |
---|
[539] | 181 | // create window |
---|
[569] | 182 | if (((QApplication*)interactorManager->GetMainInteractor())) { |
---|
| 183 | // look for the main window |
---|
| 184 | bool found = false; |
---|
[599] | 185 | #if QT_VERSION < 0x040000 |
---|
[631] | 186 | // theses lines does nothing exept this one "GLWindow = new QDialog(0..." |
---|
[626] | 187 | // but if I comment them, it doesn't work... |
---|
| 188 | QWidgetList *list = QApplication::allWidgets(); |
---|
| 189 | QWidgetListIt it( *list ); // iterate over the widgets |
---|
| 190 | QWidget * widget; |
---|
| 191 | while ( (widget=it.current()) != 0 ) { // for each widget... |
---|
| 192 | ++it; |
---|
| 193 | if ((found== false) && (widget->inherits("QMainWindow"))) { |
---|
| 194 | GLWindow = new QDialog(0,0,FALSE,Qt::WStyle_Title | Qt::WStyle_SysMenu | Qt::WStyle_MinMax ); |
---|
| 195 | found = true; |
---|
| 196 | } |
---|
| 197 | } |
---|
| 198 | delete list; // delete the list, not the widgets |
---|
[599] | 199 | #else |
---|
[626] | 200 | foreach (QWidget *widget, QApplication::allWidgets()) { |
---|
| 201 | if ((found== false) && (widget->inherits("QMainWindow"))) { |
---|
[650] | 202 | GLWindow = new QDialog(0,Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint); |
---|
[626] | 203 | found = true; |
---|
| 204 | } |
---|
| 205 | } |
---|
[608] | 206 | #endif |
---|
[612] | 207 | |
---|
| 208 | #if QT_VERSION < 0x040000 |
---|
[610] | 209 | glWidget->reparent(GLWindow,0,QPoint(0,0)); |
---|
[612] | 210 | #else |
---|
| 211 | glWidget->setParent(GLWindow); |
---|
| 212 | #endif |
---|
[599] | 213 | |
---|
[569] | 214 | if (found==false) { |
---|
[608] | 215 | #ifdef GEANT4_QT_DEBUG |
---|
[579] | 216 | printf("G4OpenGLQtViewer::CreateMainWindow case Qapp exist, but not found\n"); |
---|
[608] | 217 | #endif |
---|
[569] | 218 | GLWindow = new QDialog(); |
---|
| 219 | } |
---|
[539] | 220 | } else { |
---|
[608] | 221 | #ifdef GEANT4_QT_DEBUG |
---|
[579] | 222 | printf("G4OpenGLQtViewer::CreateMainWindow case Qapp exist\n"); |
---|
[608] | 223 | #endif |
---|
[539] | 224 | GLWindow = new QDialog(); |
---|
| 225 | } |
---|
| 226 | |
---|
[599] | 227 | QHBoxLayout *mainLayout = new QHBoxLayout(GLWindow); |
---|
[564] | 228 | |
---|
[539] | 229 | mainLayout->addWidget(fWindow); |
---|
[599] | 230 | |
---|
| 231 | #if QT_VERSION < 0x040000 |
---|
| 232 | GLWindow->setCaption( tr( "QGl Viewer" )); |
---|
| 233 | #else |
---|
[539] | 234 | GLWindow->setLayout(mainLayout); |
---|
[599] | 235 | GLWindow->setWindowTitle(tr("QGl Viewer")); |
---|
| 236 | #endif |
---|
[564] | 237 | GLWindow->resize(300, 300); |
---|
[570] | 238 | GLWindow->move(900,300); |
---|
[539] | 239 | GLWindow->show(); |
---|
[530] | 240 | |
---|
[579] | 241 | // delete the pointer if close this |
---|
| 242 | // GLWindow->setAttribute(Qt::WA_DeleteOnClose); |
---|
| 243 | |
---|
[610] | 244 | #if QT_VERSION >= 0x040000 |
---|
[579] | 245 | QObject ::connect(GLWindow, |
---|
| 246 | SIGNAL(rejected()), |
---|
| 247 | this, |
---|
| 248 | SLOT(dialogClosed())); |
---|
[610] | 249 | #endif |
---|
[579] | 250 | |
---|
[564] | 251 | WinSize_x = 400; |
---|
| 252 | WinSize_y = 400; |
---|
| 253 | if (WinSize_x < fVP.GetWindowSizeHintX ()) |
---|
| 254 | WinSize_x = fVP.GetWindowSizeHintX (); |
---|
| 255 | if (WinSize_y < fVP.GetWindowSizeHintY ()) |
---|
| 256 | WinSize_y = fVP.GetWindowSizeHintY (); |
---|
[530] | 257 | |
---|
[564] | 258 | if(!fWindow) return; |
---|
[608] | 259 | #ifdef GEANT4_QT_DEBUG |
---|
[564] | 260 | printf("G4OpenGLQtViewer::CreateMainWindow glWidget END\n"); |
---|
[608] | 261 | #endif |
---|
[530] | 262 | |
---|
[564] | 263 | if (!fContextMenu) |
---|
| 264 | createPopupMenu(); |
---|
[530] | 265 | |
---|
[564] | 266 | } |
---|
[530] | 267 | |
---|
[610] | 268 | #if QT_VERSION >= 0x040000 |
---|
[579] | 269 | /** Close the dialog and set the pointer to NULL |
---|
| 270 | */ |
---|
| 271 | void G4OpenGLQtViewer::dialogClosed() { |
---|
[610] | 272 | #ifdef GEANT4_QT_DEBUG |
---|
| 273 | printf("G4OpenGLQtViewer::dialogClosed END\n"); |
---|
| 274 | #endif |
---|
| 275 | // GLWindow = NULL; |
---|
[579] | 276 | } |
---|
[610] | 277 | #endif |
---|
[579] | 278 | |
---|
[564] | 279 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 280 | G4OpenGLQtViewer::G4OpenGLQtViewer ( |
---|
| 281 | G4OpenGLSceneHandler& scene |
---|
| 282 | ) |
---|
| 283 | :G4VViewer (scene, -1) |
---|
| 284 | ,G4OpenGLViewer (scene) |
---|
| 285 | ,fWindow(0) |
---|
| 286 | ,fContextMenu(0) |
---|
| 287 | ,fMouseAction(true) |
---|
| 288 | { |
---|
[608] | 289 | #ifdef GEANT4_QT_DEBUG |
---|
[564] | 290 | printf("G4OpenGLQtViewer::G4OpenGLQtViewer \n"); |
---|
[608] | 291 | #endif |
---|
[530] | 292 | } |
---|
| 293 | |
---|
| 294 | ////////////////////////////////////////////////////////////////////////////// |
---|
[564] | 295 | G4OpenGLQtViewer::~G4OpenGLQtViewer ( |
---|
[539] | 296 | ) |
---|
| 297 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 298 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
| 299 | { |
---|
[608] | 300 | #ifdef GEANT4_QT_DEBUG |
---|
[564] | 301 | printf("G4OpenGLQtViewer::~G4OpenGLQtViewer \n"); |
---|
[608] | 302 | #endif |
---|
[564] | 303 | } |
---|
[539] | 304 | |
---|
| 305 | |
---|
[564] | 306 | /** |
---|
| 307 | Create a popup menu for the widget. This menu is activated by right-mouse click |
---|
| 308 | */ |
---|
| 309 | void G4OpenGLQtViewer::createPopupMenu() { |
---|
[539] | 310 | |
---|
[599] | 311 | #if QT_VERSION < 0x040000 |
---|
| 312 | fContextMenu = new QPopupMenu( GLWindow,"All" ); |
---|
| 313 | #else |
---|
[564] | 314 | fContextMenu = new QMenu("All"); |
---|
[599] | 315 | #endif |
---|
| 316 | Q_CHECK_PTR( fContextMenu ); |
---|
[539] | 317 | |
---|
[599] | 318 | #if QT_VERSION < 0x040000 |
---|
| 319 | // === Mouse menu === |
---|
| 320 | QPopupMenu *mMouseAction = new QPopupMenu( fContextMenu ); |
---|
| 321 | Q_CHECK_PTR( mMouseAction ); |
---|
| 322 | |
---|
[617] | 323 | #if QT_VERSION < 0x030200 |
---|
| 324 | QAction *rotate = new QAction("&Rotate scene","&Rotate scene",CTRL+Key_N,mMouseAction); |
---|
| 325 | QAction *move = new QAction("&Move scene","&Move scene",CTRL+Key_M,mMouseAction); |
---|
| 326 | #else |
---|
[599] | 327 | QAction *rotate = new QAction("&Rotate scene",CTRL+Key_N,mMouseAction); |
---|
| 328 | QAction *move = new QAction("&Move scene",CTRL+Key_M,mMouseAction); |
---|
[617] | 329 | #endif |
---|
[599] | 330 | rotate->addTo(mMouseAction); |
---|
| 331 | move->addTo(mMouseAction); |
---|
| 332 | |
---|
| 333 | fContextMenu->insertItem( "&Mouse action", mMouseAction); |
---|
| 334 | |
---|
| 335 | #else |
---|
| 336 | // === Mouse menu === |
---|
[564] | 337 | QMenu *mMouseAction = fContextMenu->addMenu("&Mouse action"); |
---|
[599] | 338 | |
---|
[564] | 339 | QAction *rotate = mMouseAction->addAction("&Rotate scene"); |
---|
| 340 | QAction *move = mMouseAction->addAction("&Move scene"); |
---|
[599] | 341 | #endif |
---|
| 342 | |
---|
[564] | 343 | // INIT mMouse |
---|
| 344 | createRadioAction(rotate,move,SLOT(toggleMouseAction(bool)),1); |
---|
| 345 | |
---|
[599] | 346 | #if QT_VERSION < 0x040000 |
---|
| 347 | // === Style Menu === |
---|
| 348 | QPopupMenu *mStyle = new QPopupMenu(fContextMenu); |
---|
| 349 | |
---|
| 350 | QPopupMenu *mRepresentation = new QPopupMenu(fContextMenu); |
---|
| 351 | |
---|
[617] | 352 | #if QT_VERSION < 0x030200 |
---|
| 353 | QAction *polyhedron = new QAction("&Polyhedron","&Polyhedron",CTRL+Key_P,mRepresentation); |
---|
| 354 | QAction *nurbs = new QAction("&NURBS","&NURBS",CTRL+Key_N,mRepresentation); |
---|
| 355 | #else |
---|
[599] | 356 | QAction *polyhedron = new QAction("&Polyhedron",CTRL+Key_P,mRepresentation); |
---|
| 357 | QAction *nurbs = new QAction("&NURBS",CTRL+Key_N,mRepresentation); |
---|
[617] | 358 | #endif |
---|
[599] | 359 | polyhedron->addTo(mRepresentation); |
---|
| 360 | nurbs->addTo(mRepresentation); |
---|
| 361 | |
---|
| 362 | mStyle->insertItem("&Representation",mRepresentation); |
---|
| 363 | fContextMenu->insertItem("&Style",mStyle); |
---|
| 364 | |
---|
| 365 | #else |
---|
| 366 | // === Style Menu === |
---|
[564] | 367 | QMenu *mStyle = fContextMenu->addMenu("&Style"); |
---|
| 368 | |
---|
| 369 | QMenu *mRepresentation = mStyle->addMenu("&Representation"); |
---|
[632] | 370 | QAction *polyhedron = mRepresentation->addAction("Polyhedron"); |
---|
[564] | 371 | QAction *nurbs = mRepresentation->addAction("NURBS"); |
---|
[599] | 372 | #endif |
---|
[564] | 373 | // INIT mStyle |
---|
| 374 | G4ViewParameters::RepStyle style; |
---|
| 375 | style = fVP.GetRepStyle(); |
---|
| 376 | if (style == G4ViewParameters::polyhedron) { |
---|
| 377 | createRadioAction(polyhedron,nurbs,SLOT(toggleRepresentation(bool)),1); |
---|
| 378 | } else if (style == G4ViewParameters::nurbs) { |
---|
| 379 | createRadioAction(polyhedron,nurbs,SLOT(toggleRepresentation(bool)),2); |
---|
[539] | 380 | } else { |
---|
[564] | 381 | mRepresentation->clear(); |
---|
[539] | 382 | } |
---|
| 383 | |
---|
| 384 | |
---|
[599] | 385 | #if QT_VERSION < 0x040000 |
---|
| 386 | // === Drawing Menu === |
---|
| 387 | QPopupMenu *mDrawing = new QPopupMenu(fContextMenu); |
---|
| 388 | fContextMenu->insertItem("&Drawing",mDrawing); |
---|
| 389 | |
---|
| 390 | fDrawingWireframe = new QPopupMenu(mDrawing); |
---|
| 391 | mDrawing->insertItem("&Wireframe",fDrawingWireframe); |
---|
| 392 | |
---|
| 393 | mDrawing->setCheckable(true); |
---|
| 394 | fDrawingWireframe->setCheckable(true); |
---|
| 395 | |
---|
| 396 | fDrawingLineRemoval = new QPopupMenu(mDrawing); |
---|
| 397 | mDrawing->insertItem("&Hidden line removal",fDrawingLineRemoval); |
---|
| 398 | fDrawingLineRemoval->setCheckable(true); |
---|
| 399 | |
---|
| 400 | fDrawingSurfaceRemoval = new QPopupMenu(mDrawing); |
---|
| 401 | mDrawing->insertItem("&Hidden surface removal",fDrawingSurfaceRemoval); |
---|
| 402 | fDrawingSurfaceRemoval->setCheckable(true); |
---|
| 403 | |
---|
| 404 | fDrawingLineSurfaceRemoval = new QPopupMenu(mDrawing); |
---|
| 405 | mDrawing->insertItem("&Hidden line and surface removal",fDrawingLineSurfaceRemoval); |
---|
| 406 | fDrawingLineSurfaceRemoval->setCheckable(true); |
---|
| 407 | |
---|
| 408 | #else |
---|
| 409 | // === Drawing Menu === |
---|
[564] | 410 | QMenu *mDrawing = mStyle->addMenu("&Drawing"); |
---|
[599] | 411 | |
---|
[564] | 412 | fDrawingWireframe = mDrawing->addAction("Wireframe"); |
---|
| 413 | fDrawingWireframe->setCheckable(true); |
---|
[599] | 414 | |
---|
[564] | 415 | fDrawingLineRemoval = mDrawing->addAction("Hidden line removal"); |
---|
| 416 | fDrawingLineRemoval->setCheckable(true); |
---|
[599] | 417 | |
---|
[564] | 418 | fDrawingSurfaceRemoval = mDrawing->addAction("Hidden Surface removal"); |
---|
| 419 | fDrawingSurfaceRemoval->setCheckable(true); |
---|
[599] | 420 | |
---|
[564] | 421 | fDrawingLineSurfaceRemoval = mDrawing->addAction("Hidden line and surface removal"); |
---|
| 422 | fDrawingLineSurfaceRemoval->setCheckable(true); |
---|
[599] | 423 | #endif |
---|
[564] | 424 | // INIT Drawing |
---|
| 425 | G4ViewParameters::DrawingStyle d_style; |
---|
| 426 | d_style = fVP.GetDrawingStyle(); |
---|
| 427 | |
---|
[599] | 428 | #if QT_VERSION < 0x040000 |
---|
[564] | 429 | if (d_style == G4ViewParameters::wireframe) { |
---|
[599] | 430 | fDrawingWireframe->setItemChecked(0,true); |
---|
| 431 | } else if (d_style == G4ViewParameters::hlr) { |
---|
| 432 | fDrawingLineRemoval->setItemChecked(0,true); |
---|
| 433 | } else if (d_style == G4ViewParameters::hsr) { |
---|
| 434 | fDrawingSurfaceRemoval->setItemChecked(0,true); |
---|
| 435 | } else if (d_style == G4ViewParameters::hlhsr) { |
---|
| 436 | fDrawingLineSurfaceRemoval->setItemChecked(0,true); |
---|
| 437 | } else { |
---|
| 438 | mDrawing->clear(); |
---|
| 439 | } |
---|
[610] | 440 | #ifdef GEANT4_QT_DEBUG |
---|
| 441 | printf("G4OpenGLQtViewer:: fDrawingWireframe 1\n"); |
---|
| 442 | #endif |
---|
| 443 | QObject ::connect(fDrawingWireframe, |
---|
| 444 | SIGNAL(activated(int)), |
---|
| 445 | this, |
---|
| 446 | SLOT(actionDrawingWireframe())); |
---|
| 447 | #ifdef GEANT4_QT_DEBUG |
---|
| 448 | printf("G4OpenGLQtViewer:: fDrawingWireframe 2\n"); |
---|
| 449 | #endif |
---|
| 450 | QObject ::connect(fDrawingLineRemoval, |
---|
| 451 | SIGNAL(activated(int)), |
---|
| 452 | this, |
---|
| 453 | SLOT(actionDrawingLineRemoval())); |
---|
| 454 | QObject ::connect(fDrawingSurfaceRemoval, |
---|
| 455 | SIGNAL(activated(int)), |
---|
| 456 | this, |
---|
| 457 | SLOT(actionDrawingSurfaceRemoval())); |
---|
| 458 | QObject ::connect(fDrawingLineSurfaceRemoval, |
---|
| 459 | SIGNAL(activated(int)), |
---|
| 460 | this, |
---|
| 461 | SLOT(actionDrawingLineSurfaceRemoval())); |
---|
[599] | 462 | #else |
---|
| 463 | if (d_style == G4ViewParameters::wireframe) { |
---|
[564] | 464 | fDrawingWireframe->setChecked(true); |
---|
| 465 | } else if (d_style == G4ViewParameters::hlr) { |
---|
| 466 | fDrawingLineRemoval->setChecked(true); |
---|
| 467 | } else if (d_style == G4ViewParameters::hsr) { |
---|
| 468 | fDrawingSurfaceRemoval->setChecked(true); |
---|
| 469 | } else if (d_style == G4ViewParameters::hlhsr) { |
---|
| 470 | fDrawingLineSurfaceRemoval->setChecked(true); |
---|
| 471 | } else { |
---|
| 472 | mDrawing->clear(); |
---|
| 473 | } |
---|
[565] | 474 | QObject ::connect(fDrawingWireframe, |
---|
| 475 | SIGNAL(triggered(bool)), |
---|
| 476 | this, |
---|
| 477 | SLOT(actionDrawingWireframe())); |
---|
| 478 | QObject ::connect(fDrawingLineRemoval, |
---|
| 479 | SIGNAL(triggered(bool)), |
---|
| 480 | this, |
---|
| 481 | SLOT(actionDrawingLineRemoval())); |
---|
| 482 | QObject ::connect(fDrawingSurfaceRemoval, |
---|
| 483 | SIGNAL(triggered(bool)), |
---|
| 484 | this, |
---|
| 485 | SLOT(actionDrawingSurfaceRemoval())); |
---|
| 486 | QObject ::connect(fDrawingLineSurfaceRemoval, |
---|
| 487 | SIGNAL(triggered(bool)), |
---|
| 488 | this, |
---|
| 489 | SLOT(actionDrawingLineSurfaceRemoval())); |
---|
[610] | 490 | #endif |
---|
[564] | 491 | |
---|
| 492 | |
---|
[610] | 493 | |
---|
[599] | 494 | #if QT_VERSION < 0x040000 |
---|
| 495 | QPopupMenu *mBackground = new QPopupMenu(mStyle); |
---|
| 496 | mStyle->insertItem("&Background color",mBackground); |
---|
| 497 | |
---|
[617] | 498 | #if QT_VERSION < 0x030200 |
---|
| 499 | QAction *white = new QAction("&White","&White",CTRL+Key_W,mBackground); |
---|
| 500 | QAction *black = new QAction("&Black","&Black",CTRL+Key_B,mBackground); |
---|
| 501 | #else |
---|
[599] | 502 | QAction *white = new QAction("&White",CTRL+Key_W,mBackground); |
---|
| 503 | QAction *black = new QAction("&Black",CTRL+Key_B,mBackground); |
---|
[617] | 504 | #endif |
---|
[599] | 505 | white->addTo(mBackground); |
---|
| 506 | black->addTo(mBackground); |
---|
| 507 | |
---|
| 508 | #else |
---|
[564] | 509 | QMenu *mBackground = mStyle->addMenu("&Background color"); |
---|
| 510 | QAction *white = mBackground->addAction("White"); |
---|
| 511 | QAction *black = mBackground->addAction("Black"); |
---|
[599] | 512 | |
---|
| 513 | #endif |
---|
[564] | 514 | if (background.GetRed() == 1. && |
---|
| 515 | background.GetGreen() == 1. && |
---|
| 516 | background.GetBlue() == 1.) { |
---|
| 517 | createRadioAction(white,black,SLOT(toggleBackground(bool)),1); |
---|
| 518 | } else { |
---|
| 519 | createRadioAction(white,black,SLOT(toggleBackground(bool)),2); |
---|
| 520 | } |
---|
| 521 | |
---|
| 522 | |
---|
[599] | 523 | #if QT_VERSION < 0x040000 |
---|
| 524 | // === Action Menu === |
---|
| 525 | QPopupMenu *mActions = new QPopupMenu(fContextMenu); |
---|
| 526 | fContextMenu->insertItem("&Actions",mActions); |
---|
| 527 | |
---|
[617] | 528 | #if QT_VERSION < 0x030200 |
---|
[673] | 529 | // QAction *controlPanels = new QAction("&Control panels","&Control panels",CTRL+Key_C,mActions); |
---|
| 530 | // QAction *exitG4 = new QAction("&Exit to G4Vis >","&Exit to G4Vis >",CTRL+Key_E,mActions); |
---|
[617] | 531 | QAction *createEPS = new QAction("&Save as ...","&Save as ...",CTRL+Key_S,mActions); |
---|
| 532 | #else |
---|
[673] | 533 | // QAction *controlPanels = new QAction("&Control panels",CTRL+Key_C,mActions); |
---|
| 534 | // QAction *exitG4 = new QAction("&Exit to G4Vis >",CTRL+Key_E,mActions); |
---|
[599] | 535 | QAction *createEPS = new QAction("&Save as ...",CTRL+Key_S,mActions); |
---|
[617] | 536 | #endif |
---|
[673] | 537 | // controlPanels->addTo(mActions); |
---|
| 538 | // exitG4->addTo(mActions); |
---|
[599] | 539 | createEPS->addTo(mActions); |
---|
[673] | 540 | // QObject ::connect(controlPanels, |
---|
| 541 | // SIGNAL(activated()), |
---|
| 542 | // this, |
---|
| 543 | // SLOT(actionControlPanels())); |
---|
| 544 | // QObject ::connect(exitG4, |
---|
| 545 | // SIGNAL(activated()), |
---|
| 546 | // this, |
---|
| 547 | // SLOT(actionExitG4())); |
---|
[610] | 548 | QObject ::connect(createEPS, |
---|
| 549 | SIGNAL(activated()), |
---|
| 550 | this, |
---|
| 551 | SLOT(actionCreateEPS())); |
---|
[599] | 552 | |
---|
| 553 | #else |
---|
| 554 | // === Action Menu === |
---|
[564] | 555 | QMenu *mActions = fContextMenu->addMenu("&Actions"); |
---|
[673] | 556 | // QAction *controlPanels = mActions->addAction("Control panels"); |
---|
| 557 | // QAction *exitG4 = mActions->addAction("Exit to G4Vis >"); |
---|
[568] | 558 | QAction *createEPS = mActions->addAction("Save as ..."); |
---|
[673] | 559 | // QObject ::connect(controlPanels, |
---|
| 560 | // SIGNAL(triggered()), |
---|
| 561 | // this, |
---|
| 562 | // SLOT(actionControlPanels())); |
---|
| 563 | // QObject ::connect(exitG4, |
---|
| 564 | // SIGNAL(triggered()), |
---|
| 565 | // this, |
---|
| 566 | // SLOT(actionExitG4())); |
---|
[565] | 567 | QObject ::connect(createEPS, |
---|
[566] | 568 | SIGNAL(triggered()), |
---|
[565] | 569 | this, |
---|
| 570 | SLOT(actionCreateEPS())); |
---|
[610] | 571 | #endif |
---|
[564] | 572 | |
---|
| 573 | |
---|
[610] | 574 | |
---|
[599] | 575 | #if QT_VERSION < 0x040000 |
---|
| 576 | // === Special Menu === |
---|
| 577 | QPopupMenu *mSpecial = new QPopupMenu(fContextMenu); |
---|
| 578 | fContextMenu->insertItem("S&pecial",mSpecial); |
---|
| 579 | |
---|
| 580 | QPopupMenu *mTransparency = new QPopupMenu(mSpecial); |
---|
| 581 | mSpecial->insertItem("Transparency",mTransparency); |
---|
| 582 | |
---|
[617] | 583 | #if QT_VERSION < 0x030200 |
---|
| 584 | QAction *transparencyOn = new QAction("&On","&On",CTRL+Key_O,mTransparency); |
---|
| 585 | QAction *transparencyOff = new QAction("&Off","&Off",CTRL+Key_F,mTransparency); |
---|
| 586 | #else |
---|
[599] | 587 | QAction *transparencyOn = new QAction("&On",CTRL+Key_O,mTransparency); |
---|
| 588 | QAction *transparencyOff = new QAction("&Off",CTRL+Key_F,mTransparency); |
---|
[617] | 589 | #endif |
---|
[599] | 590 | transparencyOn->addTo(mTransparency); |
---|
| 591 | transparencyOff->addTo(mTransparency); |
---|
| 592 | |
---|
| 593 | #else |
---|
| 594 | // === Special Menu === |
---|
[564] | 595 | QMenu *mSpecial = fContextMenu->addMenu("S&pecial"); |
---|
[599] | 596 | QMenu *mTransparency = mSpecial->addMenu("Transparency"); |
---|
| 597 | QAction *transparencyOn = mTransparency->addAction("On"); |
---|
| 598 | QAction *transparencyOff = mTransparency->addAction("Off"); |
---|
| 599 | #endif |
---|
| 600 | |
---|
[564] | 601 | if (transparency_enabled == false) { |
---|
| 602 | createRadioAction(transparencyOn,transparencyOff,SLOT(toggleTransparency(bool)),2); |
---|
| 603 | } else if (transparency_enabled == true) { |
---|
| 604 | createRadioAction(transparencyOn,transparencyOff,SLOT(toggleTransparency(bool)),1); |
---|
| 605 | } else { |
---|
| 606 | mSpecial->clear(); |
---|
| 607 | } |
---|
| 608 | |
---|
| 609 | |
---|
[599] | 610 | #if QT_VERSION < 0x040000 |
---|
| 611 | QPopupMenu *mAntialiasing = new QPopupMenu(mSpecial); |
---|
| 612 | mSpecial->insertItem("Antialiasing",mAntialiasing); |
---|
| 613 | |
---|
[617] | 614 | #if QT_VERSION < 0x030200 |
---|
| 615 | QAction *antialiasingOn = new QAction("&On","&On",CTRL+Key_O,mAntialiasing); |
---|
| 616 | QAction *antialiasingOff = new QAction("&Off","&Off",CTRL+Key_F,mAntialiasing); |
---|
| 617 | #else |
---|
[599] | 618 | QAction *antialiasingOn = new QAction("&On",CTRL+Key_O,mAntialiasing); |
---|
| 619 | QAction *antialiasingOff = new QAction("&Off",CTRL+Key_F,mAntialiasing); |
---|
[617] | 620 | #endif |
---|
[599] | 621 | antialiasingOn->addTo(mAntialiasing); |
---|
| 622 | antialiasingOff->addTo(mAntialiasing); |
---|
| 623 | |
---|
| 624 | #else |
---|
[564] | 625 | QMenu *mAntialiasing = mSpecial->addMenu("Antialiasing"); |
---|
| 626 | QAction *antialiasingOn = mAntialiasing->addAction("On"); |
---|
| 627 | QAction *antialiasingOff = mAntialiasing->addAction("Off"); |
---|
[599] | 628 | #endif |
---|
| 629 | |
---|
[564] | 630 | if (antialiasing_enabled == false) { |
---|
| 631 | createRadioAction(antialiasingOn,antialiasingOff,SLOT(toggleAntialiasing(bool)),2); |
---|
| 632 | } else if (antialiasing_enabled == true) { |
---|
| 633 | createRadioAction(antialiasingOn,antialiasingOff,SLOT(toggleAntialiasing(bool)),1); |
---|
| 634 | } else { |
---|
| 635 | mAntialiasing->clear(); |
---|
| 636 | } |
---|
| 637 | |
---|
[599] | 638 | #if QT_VERSION < 0x040000 |
---|
| 639 | QPopupMenu *mHaloing = new QPopupMenu(mSpecial); |
---|
| 640 | mSpecial->insertItem("Haloing",mHaloing); |
---|
| 641 | |
---|
[617] | 642 | #if QT_VERSION < 0x030200 |
---|
| 643 | QAction *haloingOn = new QAction("&On","&On",CTRL+Key_O,mHaloing); |
---|
| 644 | QAction *haloingOff = new QAction("&Off","&Off",CTRL+Key_F,mHaloing); |
---|
| 645 | #else |
---|
[599] | 646 | QAction *haloingOn = new QAction("&On",CTRL+Key_O,mHaloing); |
---|
| 647 | QAction *haloingOff = new QAction("&Off",CTRL+Key_F,mHaloing); |
---|
[617] | 648 | #endif |
---|
[599] | 649 | haloingOn->addTo(mHaloing); |
---|
| 650 | haloingOff->addTo(mHaloing); |
---|
| 651 | #else |
---|
[564] | 652 | QMenu *mHaloing = mSpecial->addMenu("Haloing"); |
---|
| 653 | QAction *haloingOn = mHaloing->addAction("On"); |
---|
| 654 | QAction *haloingOff = mHaloing->addAction("Off"); |
---|
[599] | 655 | #endif |
---|
[564] | 656 | if (haloing_enabled == false) { |
---|
| 657 | createRadioAction(haloingOn,haloingOff,SLOT(toggleHaloing(bool)),2); |
---|
| 658 | } else if (haloing_enabled == true) { |
---|
| 659 | createRadioAction(haloingOn,haloingOff,SLOT(toggleHaloing(bool)),1); |
---|
| 660 | } else { |
---|
| 661 | mHaloing->clear(); |
---|
| 662 | } |
---|
| 663 | |
---|
[599] | 664 | #if QT_VERSION < 0x040000 |
---|
| 665 | QPopupMenu *mAux = new QPopupMenu(mSpecial); |
---|
| 666 | mSpecial->insertItem("Auxiliairy edges",mAux); |
---|
| 667 | |
---|
[617] | 668 | #if QT_VERSION < 0x030200 |
---|
| 669 | QAction *auxOn = new QAction("&On","&On",CTRL+Key_O,mAux); |
---|
| 670 | QAction *auxOff = new QAction("&Off","&Off",CTRL+Key_F,mAux); |
---|
| 671 | #else |
---|
[599] | 672 | QAction *auxOn = new QAction("&On",CTRL+Key_O,mAux); |
---|
| 673 | QAction *auxOff = new QAction("&Off",CTRL+Key_F,mAux); |
---|
[617] | 674 | #endif |
---|
[599] | 675 | auxOn->addTo(mAux); |
---|
| 676 | auxOff->addTo(mAux); |
---|
| 677 | |
---|
| 678 | #else |
---|
[564] | 679 | QMenu *mAux = mSpecial->addMenu("Auxiliary edges"); |
---|
| 680 | QAction *auxOn = mAux->addAction("On"); |
---|
| 681 | QAction *auxOff = mAux->addAction("Off"); |
---|
[599] | 682 | #endif |
---|
[564] | 683 | if (!fVP.IsAuxEdgeVisible()) { |
---|
| 684 | createRadioAction(auxOn,auxOff,SLOT(toggleAux(bool)),1); |
---|
| 685 | } else { |
---|
| 686 | createRadioAction(auxOn,auxOff,SLOT(toggleAux(bool)),2); |
---|
| 687 | } |
---|
| 688 | |
---|
| 689 | |
---|
[617] | 690 | #if QT_VERSION >= 0x030200 |
---|
[599] | 691 | #if QT_VERSION < 0x040000 |
---|
| 692 | QPopupMenu *mFullScreen = new QPopupMenu(mSpecial); |
---|
| 693 | mSpecial->insertItem("Full screen",mFullScreen); |
---|
| 694 | |
---|
| 695 | QAction *fullOn = new QAction("&On",CTRL+Key_O,mFullScreen); |
---|
| 696 | QAction *fullOff = new QAction("&Off",CTRL+Key_F,mFullScreen); |
---|
| 697 | fullOn->addTo(mFullScreen); |
---|
| 698 | fullOff->addTo(mFullScreen); |
---|
| 699 | #else |
---|
[564] | 700 | QMenu *mFullScreen = mSpecial->addMenu("Full screen"); |
---|
| 701 | QAction *fullOn = mFullScreen->addAction("On"); |
---|
| 702 | QAction *fullOff = mFullScreen->addAction("Off"); |
---|
[599] | 703 | #endif |
---|
[564] | 704 | createRadioAction(fullOn,fullOff,SLOT(toggleFullScreen(bool)),2); |
---|
[617] | 705 | #endif |
---|
[564] | 706 | |
---|
| 707 | } |
---|
| 708 | |
---|
| 709 | void G4OpenGLQtViewer::manageContextMenuEvent(QContextMenuEvent *e) |
---|
| 710 | { |
---|
[579] | 711 | if (!GLWindow) { |
---|
[638] | 712 | G4cerr << "Visualization window not defined, please choose one before\n" << G4endl; |
---|
[579] | 713 | } else { |
---|
[539] | 714 | |
---|
[579] | 715 | if (!fContextMenu) |
---|
| 716 | createPopupMenu(); |
---|
| 717 | |
---|
| 718 | // launch menu |
---|
| 719 | if ( fContextMenu ) { |
---|
| 720 | fContextMenu->exec( e->globalPos() ); |
---|
| 721 | // delete fContextMenu; |
---|
| 722 | } |
---|
[564] | 723 | } |
---|
| 724 | e->accept(); |
---|
| 725 | } |
---|
[539] | 726 | |
---|
| 727 | |
---|
[564] | 728 | /** |
---|
| 729 | Create a radio button menu. The two menu will be connected. When click on one, |
---|
| 730 | eatch state will be invert and callback method will be called. |
---|
| 731 | @param action1 first action to connect |
---|
| 732 | @param action2 second action to connect |
---|
| 733 | @param method callback method |
---|
| 734 | @param nCheck: 1 : first action will be set true. 2 : second action will be set true |
---|
| 735 | */ |
---|
[599] | 736 | #if QT_VERSION < 0x040000 |
---|
[564] | 737 | void G4OpenGLQtViewer::createRadioAction(QAction *action1,QAction *action2, const std::string& method,unsigned int nCheck) { |
---|
| 738 | |
---|
[599] | 739 | if (action1->parent()->inherits("QPopupMenu")){ |
---|
| 740 | ((QPopupMenu*)action1->parent())->setCheckable(true); |
---|
| 741 | } |
---|
| 742 | ((QPopupMenu*)action1->parent())->setItemChecked(0,true); |
---|
| 743 | ((QPopupMenu*)action1->parent())->setItemChecked(1,true); |
---|
| 744 | |
---|
| 745 | if (nCheck ==1) |
---|
| 746 | ((QPopupMenu*)action1->parent())->setItemChecked(0,true); |
---|
| 747 | else |
---|
| 748 | ((QPopupMenu*)action1->parent())->setItemChecked(1,true); |
---|
| 749 | |
---|
[610] | 750 | //FIXME : Should not work on Qt3 |
---|
| 751 | QObject ::connect(action1, SIGNAL(activated()),action2, SLOT(toggle())); |
---|
| 752 | QObject ::connect(action2, SIGNAL(activated()),action1, SLOT(toggle())); |
---|
[599] | 753 | |
---|
| 754 | QObject ::connect(action1, SIGNAL(toggled(bool)),this, method.c_str()); |
---|
| 755 | } |
---|
| 756 | |
---|
| 757 | #else |
---|
| 758 | void G4OpenGLQtViewer::createRadioAction(QAction *action1,QAction *action2, const std::string& method,unsigned int nCheck) { |
---|
| 759 | |
---|
[564] | 760 | action1->setCheckable(true); |
---|
| 761 | action2->setCheckable(true); |
---|
| 762 | |
---|
| 763 | if (nCheck ==1) |
---|
| 764 | action1->setChecked (true); |
---|
| 765 | else |
---|
| 766 | action2->setChecked (true); |
---|
| 767 | |
---|
| 768 | QObject ::connect(action1, SIGNAL(triggered(bool)),action2, SLOT(toggle())); |
---|
| 769 | QObject ::connect(action2, SIGNAL(triggered(bool)),action1, SLOT(toggle())); |
---|
| 770 | |
---|
| 771 | QObject ::connect(action1, SIGNAL(toggled(bool)),this, method.c_str()); |
---|
| 772 | |
---|
| 773 | } |
---|
[599] | 774 | #endif |
---|
[564] | 775 | |
---|
| 776 | /** |
---|
| 777 | Slot activate when drawing->wireframe menu is set |
---|
| 778 | */ |
---|
| 779 | void G4OpenGLQtViewer::actionDrawingWireframe() { |
---|
| 780 | emit toggleDrawingAction(1); |
---|
| 781 | } |
---|
| 782 | |
---|
| 783 | /** |
---|
| 784 | Slot activate when drawing->line removal menu is set |
---|
| 785 | */ |
---|
| 786 | void G4OpenGLQtViewer::actionDrawingLineRemoval() { |
---|
| 787 | emit toggleDrawingAction(2); |
---|
| 788 | } |
---|
| 789 | |
---|
| 790 | /** |
---|
| 791 | Slot activate when drawing->surface removal menu is set |
---|
| 792 | */ |
---|
| 793 | void G4OpenGLQtViewer::actionDrawingSurfaceRemoval() { |
---|
| 794 | emit toggleDrawingAction(3); |
---|
| 795 | } |
---|
| 796 | |
---|
| 797 | /** |
---|
| 798 | Slot activate when drawing->wireframe menu is set |
---|
| 799 | */ |
---|
| 800 | void G4OpenGLQtViewer::actionDrawingLineSurfaceRemoval() { |
---|
| 801 | emit toggleDrawingAction(4); |
---|
| 802 | } |
---|
| 803 | |
---|
| 804 | |
---|
| 805 | /** |
---|
[565] | 806 | Slot activated when drawing menu is toggle |
---|
| 807 | Warning : When G4OpenGLStoredQtViewer::DrawView() method call, |
---|
| 808 | KernelVisitDecision () will be call and will set the fNeedKernelVisit |
---|
| 809 | to 1. See G4XXXStoredViewer::CompareForKernelVisit for explanations. |
---|
| 810 | It will cause a redraw of the view |
---|
| 811 | @param aAction : 1 wireframe, 2 line removal, 3 surface removal, 4 line & surface removal |
---|
| 812 | @see G4OpenGLStoredQtViewer::DrawView |
---|
| 813 | @see G4XXXStoredViewer::CompareForKernelVisit |
---|
[564] | 814 | */ |
---|
| 815 | void G4OpenGLQtViewer::toggleDrawingAction(int aAction) { |
---|
| 816 | |
---|
| 817 | G4ViewParameters::DrawingStyle d_style; |
---|
[539] | 818 | |
---|
| 819 | |
---|
[564] | 820 | if (aAction ==1) { |
---|
[600] | 821 | #if QT_VERSION < 0x040000 |
---|
| 822 | fDrawingWireframe->setItemChecked (0,true); |
---|
| 823 | fDrawingLineRemoval->setItemChecked (0,false); |
---|
| 824 | fDrawingSurfaceRemoval->setItemChecked (0,false); |
---|
| 825 | fDrawingLineSurfaceRemoval->setItemChecked (0,false); |
---|
| 826 | #else |
---|
[564] | 827 | fDrawingWireframe->setChecked (true); |
---|
| 828 | fDrawingLineRemoval->setChecked (false); |
---|
| 829 | fDrawingSurfaceRemoval->setChecked (false); |
---|
| 830 | fDrawingLineSurfaceRemoval->setChecked (false); |
---|
[600] | 831 | #endif |
---|
[564] | 832 | |
---|
| 833 | d_style = G4ViewParameters::wireframe; |
---|
| 834 | |
---|
| 835 | } else if (aAction ==2) { |
---|
[600] | 836 | #if QT_VERSION < 0x040000 |
---|
| 837 | fDrawingWireframe->setItemChecked (0,false); |
---|
| 838 | fDrawingLineRemoval->setItemChecked (0,true); |
---|
| 839 | fDrawingSurfaceRemoval->setItemChecked (0,false); |
---|
| 840 | fDrawingLineSurfaceRemoval->setItemChecked (0,false); |
---|
| 841 | #else |
---|
[564] | 842 | fDrawingWireframe->setChecked (false); |
---|
| 843 | fDrawingLineRemoval->setChecked (true); |
---|
| 844 | fDrawingSurfaceRemoval->setChecked (false); |
---|
| 845 | fDrawingLineSurfaceRemoval->setChecked (false); |
---|
[600] | 846 | #endif |
---|
[564] | 847 | |
---|
| 848 | d_style = G4ViewParameters::hlr; |
---|
| 849 | |
---|
| 850 | } else if (aAction ==3) { |
---|
[600] | 851 | #if QT_VERSION < 0x040000 |
---|
| 852 | fDrawingWireframe->setItemChecked (0,false); |
---|
| 853 | fDrawingLineRemoval->setItemChecked (0,false); |
---|
| 854 | fDrawingSurfaceRemoval->setItemChecked (0,true); |
---|
| 855 | fDrawingLineSurfaceRemoval->setItemChecked (0,false); |
---|
| 856 | #else |
---|
[564] | 857 | fDrawingWireframe->setChecked (false); |
---|
| 858 | fDrawingLineRemoval->setChecked (false); |
---|
| 859 | fDrawingSurfaceRemoval->setChecked (true); |
---|
| 860 | fDrawingLineSurfaceRemoval->setChecked (false); |
---|
[600] | 861 | #endif |
---|
[564] | 862 | |
---|
| 863 | d_style = G4ViewParameters::hsr; |
---|
| 864 | |
---|
| 865 | } else if (aAction ==4) { |
---|
[600] | 866 | #if QT_VERSION < 0x040000 |
---|
| 867 | fDrawingWireframe->setItemChecked (0,false); |
---|
| 868 | fDrawingLineRemoval->setItemChecked (0,false); |
---|
| 869 | fDrawingSurfaceRemoval->setItemChecked (0,false); |
---|
| 870 | fDrawingLineSurfaceRemoval->setItemChecked (0,true); |
---|
| 871 | #else |
---|
[564] | 872 | fDrawingWireframe->setChecked (false); |
---|
| 873 | fDrawingLineRemoval->setChecked (false); |
---|
| 874 | fDrawingSurfaceRemoval->setChecked (false); |
---|
| 875 | fDrawingLineSurfaceRemoval->setChecked (true); |
---|
[600] | 876 | #endif |
---|
[564] | 877 | d_style = G4ViewParameters::hlhsr; |
---|
| 878 | } |
---|
| 879 | fVP.SetDrawingStyle(d_style); |
---|
| 880 | |
---|
| 881 | updateQWidget(); |
---|
[608] | 882 | #ifdef GEANT4_QT_DEBUG |
---|
[564] | 883 | printf("G4OpenGLQtViewer::toggleDrawingAction\n"); |
---|
[608] | 884 | #endif |
---|
[539] | 885 | } |
---|
| 886 | |
---|
[564] | 887 | |
---|
| 888 | /** |
---|
| 889 | SLOT Activate by a click on the representation menu |
---|
[565] | 890 | Warning : When G4OpenGLStoredQtViewer::DrawView() method call, |
---|
| 891 | KernelVisitDecision () will be call and will set the fNeedKernelVisit |
---|
| 892 | to 1. See G4XXXStoredViewer::CompareForKernelVisit for explanations. |
---|
| 893 | It will cause a redraw of the view |
---|
[564] | 894 | @param check : 1 polyhedron, 0 nurbs |
---|
[565] | 895 | @see G4OpenGLStoredQtViewer::DrawView |
---|
| 896 | @see G4XXXStoredViewer::CompareForKernelVisit |
---|
[564] | 897 | */ |
---|
| 898 | void G4OpenGLQtViewer::toggleRepresentation(bool check) { |
---|
| 899 | |
---|
| 900 | G4ViewParameters::RepStyle style; |
---|
| 901 | if (check == 1) { |
---|
| 902 | style = G4ViewParameters::polyhedron; |
---|
| 903 | } else { |
---|
| 904 | style = G4ViewParameters::nurbs; |
---|
| 905 | } |
---|
| 906 | fVP.SetRepStyle (style); |
---|
| 907 | |
---|
[608] | 908 | #ifdef GEANT4_QT_DEBUG |
---|
[564] | 909 | printf("G4OpenGLQtViewer::toggleRepresentation 3%d\n",check); |
---|
[608] | 910 | #endif |
---|
[564] | 911 | updateQWidget(); |
---|
[608] | 912 | #ifdef GEANT4_QT_DEBUG |
---|
[564] | 913 | printf("G4OpenGLQtViewer::toggleRepresentation 4%d\n",check); |
---|
[608] | 914 | #endif |
---|
[530] | 915 | } |
---|
| 916 | |
---|
[564] | 917 | /** |
---|
| 918 | SLOT Activate by a click on the background menu |
---|
| 919 | @param check : 1 white, 0 black |
---|
| 920 | */ |
---|
| 921 | void G4OpenGLQtViewer::toggleBackground(bool check) { |
---|
| 922 | |
---|
| 923 | // //I need to revisit the kernel if the background colour changes and |
---|
| 924 | // //hidden line removal is enabled, because hlr drawing utilises the |
---|
| 925 | // //background colour in its drawing... |
---|
| 926 | // // (Note added by JA 13/9/2005) Background now handled in view |
---|
| 927 | // // parameters. A kernel visit is triggered on change of background. |
---|
| 928 | if (check == 1) { |
---|
| 929 | ((G4ViewParameters&)this->GetViewParameters()). |
---|
| 930 | SetBackgroundColour(G4Colour(1.,1.,1.)); // White |
---|
| 931 | } else { |
---|
| 932 | ((G4ViewParameters&)this->GetViewParameters()). |
---|
| 933 | SetBackgroundColour(G4Colour(0.,0.,0.)); // Black |
---|
| 934 | } |
---|
| 935 | updateQWidget(); |
---|
[530] | 936 | } |
---|
| 937 | |
---|
[564] | 938 | /** |
---|
| 939 | SLOT Activate by a click on the transparency menu |
---|
| 940 | @param check : 1 , 0 |
---|
| 941 | */ |
---|
| 942 | void G4OpenGLQtViewer::toggleTransparency(bool check) { |
---|
| 943 | |
---|
| 944 | if (check) { |
---|
| 945 | transparency_enabled = false; |
---|
| 946 | } else { |
---|
| 947 | transparency_enabled = true; |
---|
| 948 | } |
---|
| 949 | SetNeedKernelVisit (true); |
---|
| 950 | updateQWidget(); |
---|
| 951 | } |
---|
[530] | 952 | |
---|
[564] | 953 | /** |
---|
| 954 | SLOT Activate by a click on the antialiasing menu |
---|
| 955 | @param check : 1 , 0 |
---|
| 956 | */ |
---|
| 957 | void G4OpenGLQtViewer::toggleAntialiasing(bool check) { |
---|
| 958 | |
---|
| 959 | if (!check) { |
---|
| 960 | antialiasing_enabled = false; |
---|
| 961 | glDisable (GL_LINE_SMOOTH); |
---|
| 962 | glDisable (GL_POLYGON_SMOOTH); |
---|
| 963 | } else { |
---|
| 964 | antialiasing_enabled = true; |
---|
| 965 | glEnable (GL_LINE_SMOOTH); |
---|
| 966 | glHint (GL_LINE_SMOOTH_HINT, GL_NICEST); |
---|
| 967 | glEnable (GL_POLYGON_SMOOTH); |
---|
| 968 | glHint (GL_POLYGON_SMOOTH_HINT, GL_NICEST); |
---|
[530] | 969 | } |
---|
[564] | 970 | |
---|
| 971 | updateQWidget(); |
---|
[608] | 972 | #ifdef GEANT4_QT_DEBUG |
---|
[564] | 973 | printf("G4OpenGLQtViewer::toggleRepresentation %d\n",check); |
---|
[608] | 974 | #endif |
---|
[564] | 975 | } |
---|
| 976 | |
---|
| 977 | /** |
---|
| 978 | SLOT Activate by a click on the haloing menu |
---|
| 979 | @param check : 1 , 0 |
---|
[530] | 980 | */ |
---|
[564] | 981 | //FIXME : I SEE NOTHING... |
---|
| 982 | void G4OpenGLQtViewer::toggleHaloing(bool check) { |
---|
| 983 | if (check) { |
---|
| 984 | haloing_enabled = false; |
---|
| 985 | } else { |
---|
| 986 | haloing_enabled = true; |
---|
| 987 | } |
---|
[530] | 988 | |
---|
[564] | 989 | updateQWidget(); |
---|
[530] | 990 | |
---|
[608] | 991 | #ifdef GEANT4_QT_DEBUG |
---|
[564] | 992 | printf("G4OpenGLQtViewer::toggleRepresentation %d\n",check); |
---|
[608] | 993 | #endif |
---|
[564] | 994 | } |
---|
| 995 | |
---|
| 996 | /** |
---|
| 997 | SLOT Activate by a click on the auxiliaire edges menu |
---|
| 998 | @param check : 1 , 0 |
---|
| 999 | */ |
---|
| 1000 | void G4OpenGLQtViewer::toggleAux(bool check) { |
---|
| 1001 | if (check) { |
---|
| 1002 | fVP.SetAuxEdgeVisible(false); |
---|
| 1003 | } else { |
---|
| 1004 | fVP.SetAuxEdgeVisible(true); |
---|
| 1005 | } |
---|
| 1006 | SetNeedKernelVisit (true); |
---|
| 1007 | updateQWidget(); |
---|
| 1008 | |
---|
[608] | 1009 | #ifdef GEANT4_QT_DEBUG |
---|
[564] | 1010 | printf("G4OpenGLQtViewer::toggleRepresentation %d\n",check); |
---|
[608] | 1011 | #endif |
---|
[564] | 1012 | } |
---|
| 1013 | |
---|
| 1014 | /** |
---|
| 1015 | SLOT Activate by a click on the full screen menu |
---|
| 1016 | @param check : 1 , 0 |
---|
| 1017 | */ |
---|
| 1018 | void G4OpenGLQtViewer::toggleFullScreen(bool check) { |
---|
[617] | 1019 | #if QT_VERSION >= 0x030200 |
---|
[564] | 1020 | GLWindow->setWindowState(GLWindow->windowState() ^ Qt::WindowFullScreen); |
---|
[617] | 1021 | #else |
---|
[638] | 1022 | G4cerr << "This version of G4UI Could not generate the selected format\n" << G4endl; |
---|
[617] | 1023 | #endif |
---|
[608] | 1024 | #ifdef GEANT4_QT_DEBUG |
---|
[564] | 1025 | printf("G4OpenGLQtViewer::toggleRepresentation %d\n",check); |
---|
[608] | 1026 | #endif |
---|
[564] | 1027 | } |
---|
| 1028 | |
---|
| 1029 | /** |
---|
| 1030 | SLOT Activate by a click on the mouse action menu |
---|
| 1031 | @param check : 1 , 0 |
---|
| 1032 | */ |
---|
| 1033 | void G4OpenGLQtViewer::toggleMouseAction(bool check) { |
---|
| 1034 | if (check) { // rotate scene |
---|
| 1035 | fMouseAction = true; |
---|
| 1036 | } else { // move scene |
---|
| 1037 | fMouseAction = false; |
---|
| 1038 | } |
---|
| 1039 | |
---|
[608] | 1040 | #ifdef GEANT4_QT_DEBUG |
---|
[564] | 1041 | printf("G4OpenGLQtViewer::toggleRepresentation %d\n",check); |
---|
[608] | 1042 | #endif |
---|
[564] | 1043 | } |
---|
| 1044 | |
---|
| 1045 | |
---|
[673] | 1046 | // void G4OpenGLQtViewer::actionControlPanels() { |
---|
| 1047 | // #ifdef GEANT4_QT_DEBUG |
---|
| 1048 | // printf("G4OpenGLQtViewer::actionControlPanels \n"); |
---|
| 1049 | // #endif |
---|
| 1050 | // } |
---|
[565] | 1051 | |
---|
[673] | 1052 | // void G4OpenGLQtViewer::actionExitG4() { |
---|
| 1053 | // #ifdef GEANT4_QT_DEBUG |
---|
| 1054 | // printf("G4OpenGLQtViewer::actionExitG4() \n"); |
---|
| 1055 | // #endif |
---|
| 1056 | // } |
---|
[565] | 1057 | |
---|
| 1058 | void G4OpenGLQtViewer::actionCreateEPS() { |
---|
[580] | 1059 | QString filters; |
---|
[600] | 1060 | #if QT_VERSION < 0x040000 |
---|
| 1061 | QStrList listFormat=QImageIO::outputFormats(); |
---|
| 1062 | char *tmp=listFormat.first(); |
---|
| 1063 | while (tmp!=0) { |
---|
| 1064 | filters += QString(tmp) + ";;"; |
---|
| 1065 | tmp=listFormat.next(); |
---|
| 1066 | } |
---|
| 1067 | #else |
---|
[580] | 1068 | QList<QByteArray> formats = QImageWriter::supportedImageFormats (); |
---|
| 1069 | for (int i = 0; i < formats.size(); ++i) { |
---|
[600] | 1070 | filters +=formats.at(i) + ";;"; |
---|
[580] | 1071 | } |
---|
[600] | 1072 | #endif |
---|
[588] | 1073 | filters += "eps;;"; |
---|
| 1074 | filters += "ps;;"; |
---|
| 1075 | filters += "pdf"; |
---|
[639] | 1076 | QString* selectedFormat = new QString(); |
---|
[600] | 1077 | #if QT_VERSION < 0x040000 |
---|
| 1078 | QString nomFich = QFileDialog::getSaveFileName ( ".", |
---|
| 1079 | filters, |
---|
| 1080 | GLWindow, |
---|
| 1081 | "Save file dialog", |
---|
| 1082 | tr("Save as ..."), |
---|
[639] | 1083 | selectedFormat ); |
---|
[600] | 1084 | #else |
---|
[580] | 1085 | QString nomFich = QFileDialog::getSaveFileName ( GLWindow, |
---|
| 1086 | tr("Save as ..."), |
---|
| 1087 | ".", |
---|
[582] | 1088 | filters, |
---|
[639] | 1089 | selectedFormat ); |
---|
[600] | 1090 | #endif |
---|
[580] | 1091 | // bmp jpg jpeg png ppm xbm xpm |
---|
[582] | 1092 | if (nomFich == "") { |
---|
| 1093 | return; |
---|
| 1094 | } |
---|
[600] | 1095 | #if QT_VERSION < 0x040000 |
---|
[639] | 1096 | nomFich += "."+QString(selectedFormat->ascii()); |
---|
| 1097 | QString format = selectedFormat->lower(); |
---|
[600] | 1098 | #else |
---|
[639] | 1099 | nomFich += "."+QString(selectedFormat->toStdString().c_str()); |
---|
| 1100 | QString format = selectedFormat->toLower(); |
---|
[600] | 1101 | #endif |
---|
[656] | 1102 | G4OpenGLQtExportDialog* exportDialog= new G4OpenGLQtExportDialog(GLWindow,format,fWindow->height(),fWindow->width()); |
---|
[585] | 1103 | if( exportDialog->exec()) { |
---|
[593] | 1104 | |
---|
| 1105 | QImage image; |
---|
[655] | 1106 | bool res = false; |
---|
[635] | 1107 | if ((exportDialog->getWidth() !=fWindow->width()) || |
---|
| 1108 | (exportDialog->getHeight() !=fWindow->height())) { |
---|
[655] | 1109 | if (format != QString("eps")) { |
---|
[638] | 1110 | 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] | 1111 | |
---|
[635] | 1112 | // rescaleImage(exportDialog->getWidth(),exportDialog->getHeight());// re-scale image |
---|
| 1113 | // QGLWidget* glResized = fWindow; |
---|
| 1114 | |
---|
| 1115 | // FIXME : |
---|
| 1116 | // L.Garnier : I've try to implement change size function, but the problem is |
---|
| 1117 | // the renderPixmap function call the QGLWidget to resize and it doesn't draw |
---|
| 1118 | // the content of this widget... It only draw the background. |
---|
| 1119 | |
---|
| 1120 | // fWindow->renderPixmap (exportDialog->getWidth()*2,exportDialog->getHeight()*2,true ); |
---|
| 1121 | |
---|
| 1122 | // QPixmap pixmap = fWindow->renderPixmap (); |
---|
| 1123 | |
---|
| 1124 | // image = pixmap->toImage(); |
---|
[593] | 1125 | // glResized->resize(exportDialog->getWidth()*2,exportDialog->getHeight()*2); |
---|
| 1126 | // image = glResized->grabFrameBuffer(); |
---|
[655] | 1127 | } |
---|
[635] | 1128 | } else { |
---|
| 1129 | image = fWindow->grabFrameBuffer(); |
---|
| 1130 | } |
---|
[639] | 1131 | if (format == QString("eps")) { |
---|
[652] | 1132 | if (exportDialog->getVectorEPS()) { |
---|
[655] | 1133 | res = generateVectorEPS(nomFich,exportDialog->getWidth(),exportDialog->getHeight(),image); |
---|
[652] | 1134 | } else { |
---|
[655] | 1135 | res = generateEPS(nomFich,exportDialog->getNbColor(),image); |
---|
[652] | 1136 | } |
---|
[639] | 1137 | } else if ((format == "ps") || (format == "pdf")) { |
---|
[655] | 1138 | res = generatePS_PDF(nomFich,exportDialog->getNbColor(),image); |
---|
| 1139 | } else if ((format == "tif") || |
---|
| 1140 | (format == "tiff") || |
---|
| 1141 | (format == "jpg") || |
---|
| 1142 | (format == "jpeg") || |
---|
| 1143 | (format == "png") || |
---|
| 1144 | (format == "pbm") || |
---|
| 1145 | (format == "pgm") || |
---|
| 1146 | (format == "ppm") || |
---|
| 1147 | (format == "bmp") || |
---|
| 1148 | (format == "xbm") || |
---|
| 1149 | (format == "xpm")) { |
---|
[639] | 1150 | #if QT_VERSION < 0x040000 |
---|
[655] | 1151 | res = image.save(nomFich,selectedFormat->ascii(),exportDialog->getSliderValue()); |
---|
[639] | 1152 | #else |
---|
[655] | 1153 | res = image.save(nomFich,0,exportDialog->getSliderValue()); |
---|
[639] | 1154 | #endif |
---|
[585] | 1155 | } else { |
---|
[638] | 1156 | G4cerr << "This version of G4UI Could not generate the selected format\n" << G4endl; |
---|
[585] | 1157 | } |
---|
[655] | 1158 | if (res == false) { |
---|
| 1159 | #if QT_VERSION < 0x040000 |
---|
| 1160 | G4cerr << "Error while saving file... "<<nomFich.ascii()<<"\n" << G4endl; |
---|
| 1161 | #else |
---|
| 1162 | G4cerr << "Error while saving file... "<<nomFich.toStdString().c_str()<<"\n" << G4endl; |
---|
| 1163 | #endif |
---|
| 1164 | } else { |
---|
| 1165 | #if QT_VERSION < 0x040000 |
---|
[656] | 1166 | G4cout << "File "<<nomFich.ascii()<<" has been saved \n" << G4endl; |
---|
[655] | 1167 | #else |
---|
[656] | 1168 | G4cout << "File "<<nomFich.toStdString().c_str()<<" has been saved \n" << G4endl; |
---|
[655] | 1169 | #endif |
---|
| 1170 | } |
---|
[585] | 1171 | |
---|
| 1172 | } else { // cancel selected |
---|
| 1173 | return; |
---|
[568] | 1174 | } |
---|
[580] | 1175 | |
---|
[608] | 1176 | #ifdef GEANT4_QT_DEBUG |
---|
[565] | 1177 | printf("G4OpenGLQtViewer::actionCreateEPS() \n"); |
---|
[608] | 1178 | #endif |
---|
[565] | 1179 | } |
---|
| 1180 | |
---|
[580] | 1181 | /* |
---|
| 1182 | // 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] | 1183 | |
---|
[580] | 1184 | void Graph::exportToSVG(const QString& fname) |
---|
| 1185 | { |
---|
| 1186 | // enable workaround for Qt3 misalignments |
---|
| 1187 | QwtPainter::setSVGMode(true); |
---|
| 1188 | QPicture picture; |
---|
| 1189 | QPainter p(&picture); |
---|
| 1190 | d_plot->print(&p, d_plot->rect()); |
---|
| 1191 | p.end(); |
---|
[565] | 1192 | |
---|
[580] | 1193 | picture.save(fname, "svg"); |
---|
| 1194 | } |
---|
| 1195 | */ |
---|
| 1196 | |
---|
| 1197 | |
---|
| 1198 | |
---|
| 1199 | |
---|
[564] | 1200 | /** |
---|
| 1201 | Save the current mouse press point |
---|
| 1202 | @param p mouse click point |
---|
| 1203 | */ |
---|
| 1204 | void G4OpenGLQtViewer::G4MousePressEvent(QPoint p) |
---|
| 1205 | { |
---|
| 1206 | lastPos = p; |
---|
| 1207 | } |
---|
| 1208 | |
---|
[673] | 1209 | |
---|
[564] | 1210 | /** |
---|
| 1211 | @param pos_x mouse x position |
---|
| 1212 | @param pos_y mouse y position |
---|
| 1213 | @param mButtons mouse button active |
---|
| 1214 | */ |
---|
[599] | 1215 | |
---|
| 1216 | #if QT_VERSION < 0x040000 |
---|
| 1217 | void G4OpenGLQtViewer::G4MouseMoveEvent(int pos_x, int pos_y,Qt::ButtonState mButtons) |
---|
| 1218 | #else |
---|
[673] | 1219 | void G4OpenGLQtViewer::G4MouseMoveEvent(int pos_x, int pos_y,Qt::MouseButtons mButtons) |
---|
[599] | 1220 | #endif |
---|
[564] | 1221 | { |
---|
| 1222 | int dx = pos_x - lastPos.x(); |
---|
| 1223 | int dy = pos_y - lastPos.y(); |
---|
| 1224 | if (fMouseAction) { // rotate |
---|
| 1225 | if (mButtons & Qt::LeftButton) { |
---|
| 1226 | //phi spin stuff here |
---|
| 1227 | |
---|
| 1228 | G4Vector3D vp = fVP.GetViewpointDirection ().unit (); |
---|
| 1229 | G4Vector3D up = fVP.GetUpVector ().unit (); |
---|
| 1230 | |
---|
| 1231 | G4Vector3D yprime = (up.cross(vp)).unit(); |
---|
| 1232 | G4Vector3D zprime = (vp.cross(yprime)).unit(); |
---|
| 1233 | |
---|
| 1234 | G4double delta_alpha; |
---|
| 1235 | G4double delta_theta; |
---|
| 1236 | |
---|
| 1237 | if (fVP.GetLightsMoveWithCamera()) { |
---|
| 1238 | delta_alpha = dy; |
---|
| 1239 | delta_theta = -dx; |
---|
| 1240 | } else { |
---|
| 1241 | delta_alpha = -dy; |
---|
| 1242 | delta_theta = dx; |
---|
| 1243 | } |
---|
[530] | 1244 | |
---|
[564] | 1245 | delta_alpha *= deg; |
---|
| 1246 | delta_theta *= deg; |
---|
[530] | 1247 | |
---|
[564] | 1248 | G4Vector3D new_vp = std::cos(delta_alpha) * vp + std::sin(delta_alpha) * zprime; |
---|
| 1249 | |
---|
| 1250 | G4Vector3D new_up; |
---|
| 1251 | if (fVP.GetLightsMoveWithCamera()) { |
---|
| 1252 | new_up = (new_vp.cross(yprime)).unit(); |
---|
| 1253 | fVP.SetUpVector(new_up); |
---|
| 1254 | } else { |
---|
| 1255 | new_up = up; |
---|
| 1256 | } |
---|
| 1257 | //////////////// |
---|
| 1258 | // Rotates by fixed azimuthal angle delta_theta. |
---|
| 1259 | |
---|
| 1260 | G4double cosalpha = new_up.dot (new_vp.unit()); |
---|
| 1261 | G4double sinalpha = std::sqrt (1. - std::pow (cosalpha, 2)); |
---|
| 1262 | yprime = (new_up.cross (new_vp.unit())).unit (); |
---|
| 1263 | G4Vector3D xprime = yprime.cross (new_up); |
---|
| 1264 | // Projection of vp on plane perpendicular to up... |
---|
| 1265 | G4Vector3D a1 = sinalpha * xprime; |
---|
| 1266 | // Required new projection... |
---|
| 1267 | G4Vector3D a2 = |
---|
| 1268 | sinalpha * (std::cos (delta_theta) * xprime + std::sin (delta_theta) * yprime); |
---|
| 1269 | // Required Increment vector... |
---|
| 1270 | G4Vector3D delta = a2 - a1; |
---|
| 1271 | // So new viewpoint is... |
---|
| 1272 | G4Vector3D viewPoint = new_vp.unit() + delta; |
---|
| 1273 | |
---|
| 1274 | fVP.SetViewAndLights (viewPoint); |
---|
| 1275 | updateQWidget(); |
---|
| 1276 | |
---|
| 1277 | } else if (mButtons & Qt::RightButton) { |
---|
| 1278 | // NEVER DONE BECAUSE OF MOUSE MENU |
---|
| 1279 | // setXRotation(xRot + dy/2); |
---|
| 1280 | // setZRotation(zRot + dx/2); |
---|
| 1281 | // updateQWidget(); |
---|
| 1282 | } |
---|
| 1283 | } else { // move |
---|
| 1284 | |
---|
| 1285 | float dx = pos_x - lastPos.x(); |
---|
| 1286 | float dy = pos_y - lastPos.y(); |
---|
| 1287 | |
---|
| 1288 | G4Point3D stp |
---|
| 1289 | = GetSceneHandler()->GetScene()->GetStandardTargetPoint(); |
---|
| 1290 | |
---|
| 1291 | G4Point3D tp = stp + fVP.GetCurrentTargetPoint (); |
---|
| 1292 | |
---|
| 1293 | const G4Vector3D& upVector = fVP.GetUpVector (); |
---|
| 1294 | const G4Vector3D& vpVector = fVP.GetViewpointDirection (); |
---|
| 1295 | |
---|
| 1296 | G4Vector3D unitRight = (upVector.cross (vpVector)).unit(); |
---|
| 1297 | G4Vector3D unitUp = (vpVector.cross (unitRight)).unit(); |
---|
| 1298 | |
---|
| 1299 | tp += -dx * unitRight + dy * unitUp; |
---|
| 1300 | fVP.SetCurrentTargetPoint (tp - stp); |
---|
| 1301 | |
---|
| 1302 | updateQWidget(); |
---|
| 1303 | } |
---|
| 1304 | lastPos = QPoint(pos_x, pos_y); |
---|
| 1305 | } |
---|
| 1306 | |
---|
[660] | 1307 | /** This is the benning of a rescale function. It does nothing for the moment |
---|
| 1308 | @param aWidth : new width |
---|
| 1309 | @param aHeight : new height |
---|
| 1310 | */ |
---|
[585] | 1311 | void G4OpenGLQtViewer::rescaleImage( |
---|
| 1312 | int aWidth |
---|
| 1313 | ,int aHeight |
---|
| 1314 | ){ |
---|
[608] | 1315 | #ifdef GEANT4_QT_DEBUG |
---|
[586] | 1316 | printf("should rescale \n"); |
---|
[608] | 1317 | #endif |
---|
[660] | 1318 | GLfloat* feedback_buffer; |
---|
| 1319 | GLint returned; |
---|
| 1320 | FILE* file; |
---|
| 1321 | |
---|
[673] | 1322 | // feedback_buffer = new GLfloat[size]; |
---|
| 1323 | // glFeedbackBuffer (size, GL_3D_COLOR, feedback_buffer); |
---|
| 1324 | // glRenderMode (GL_FEEDBACK); |
---|
[660] | 1325 | |
---|
[673] | 1326 | // glViewport (0, 0, aWidth, aHeight); |
---|
| 1327 | // DrawView(); |
---|
| 1328 | // returned = glRenderMode (GL_RENDER); |
---|
[660] | 1329 | |
---|
[585] | 1330 | } |
---|
[586] | 1331 | |
---|
| 1332 | /** |
---|
[652] | 1333 | Generate Vectorial Encapsulated Postscript form image |
---|
[586] | 1334 | @param aFilename : name of file |
---|
| 1335 | @param aInColor : numbers of colors : 1->BW 2->RGB 3->RGB+Alpha |
---|
| 1336 | @param aImage : Image to print |
---|
| 1337 | */ |
---|
[652] | 1338 | bool G4OpenGLQtViewer::generateVectorEPS ( |
---|
| 1339 | QString aFilename |
---|
| 1340 | ,int aWidth |
---|
| 1341 | ,int aHeight |
---|
| 1342 | ,QImage aImage |
---|
| 1343 | ) |
---|
| 1344 | { |
---|
| 1345 | // Print vectored PostScript |
---|
| 1346 | |
---|
| 1347 | G4int size = 5000000; |
---|
| 1348 | |
---|
| 1349 | GLfloat* feedback_buffer; |
---|
| 1350 | GLint returned; |
---|
| 1351 | FILE* file; |
---|
| 1352 | |
---|
| 1353 | feedback_buffer = new GLfloat[size]; |
---|
| 1354 | glFeedbackBuffer (size, GL_3D_COLOR, feedback_buffer); |
---|
| 1355 | glRenderMode (GL_FEEDBACK); |
---|
| 1356 | |
---|
[675] | 1357 | int side = qMin(aWidth, aHeight); |
---|
| 1358 | glViewport((aWidth - side) / 2, (aHeight - side) / 2, side, side); |
---|
[652] | 1359 | DrawView(); |
---|
| 1360 | |
---|
| 1361 | returned = glRenderMode (GL_RENDER); |
---|
| 1362 | |
---|
| 1363 | |
---|
| 1364 | #if QT_VERSION < 0x040000 |
---|
| 1365 | file = fopen (aFilename.ascii(), "w"); |
---|
| 1366 | #else |
---|
| 1367 | file = fopen (aFilename.toStdString().c_str(), "w"); |
---|
| 1368 | #endif |
---|
| 1369 | if (file) { |
---|
| 1370 | spewWireframeEPS (file, returned, feedback_buffer, "rendereps"); |
---|
| 1371 | } else { |
---|
[658] | 1372 | #if QT_VERSION < 0x040000 |
---|
[673] | 1373 | G4cerr << "Could not open "<< aFilename.ascii()<<"\n" << G4endl; |
---|
[658] | 1374 | #else |
---|
[673] | 1375 | G4cerr << "Could not open "<< aFilename.toStdString().c_str()<<"\n" << G4endl; |
---|
[658] | 1376 | #endif |
---|
[652] | 1377 | } |
---|
| 1378 | |
---|
| 1379 | delete[] feedback_buffer; |
---|
| 1380 | |
---|
| 1381 | return true; |
---|
| 1382 | } |
---|
| 1383 | |
---|
| 1384 | /** |
---|
| 1385 | Generate Encapsulated Postscript form image |
---|
| 1386 | @param aFilename : name of file |
---|
| 1387 | @param aInColor : numbers of colors : 1->BW 2->RGB 3->RGB+Alpha |
---|
| 1388 | @param aImage : Image to print |
---|
| 1389 | */ |
---|
[588] | 1390 | bool G4OpenGLQtViewer::generateEPS ( |
---|
[586] | 1391 | QString aFilename |
---|
| 1392 | ,int aInColor |
---|
| 1393 | ,QImage aImage |
---|
| 1394 | ) |
---|
| 1395 | { |
---|
[587] | 1396 | // FIXME |
---|
[608] | 1397 | #ifdef GEANT4_QT_DEBUG |
---|
[586] | 1398 | printf("saving EPS\n"); |
---|
[608] | 1399 | #endif |
---|
[586] | 1400 | |
---|
| 1401 | FILE* fp; |
---|
[587] | 1402 | |
---|
[649] | 1403 | if (aImage.bits () == NULL) |
---|
[588] | 1404 | return false; |
---|
[586] | 1405 | |
---|
[600] | 1406 | #if QT_VERSION < 0x040000 |
---|
| 1407 | fp = fopen (aFilename.ascii(), "w"); |
---|
| 1408 | #else |
---|
[602] | 1409 | fp = fopen (aFilename.toStdString().c_str(), "w"); |
---|
[600] | 1410 | #endif |
---|
[586] | 1411 | if (fp == NULL) { |
---|
[588] | 1412 | return false; |
---|
[586] | 1413 | } |
---|
| 1414 | |
---|
| 1415 | fprintf (fp, "%%!PS-Adobe-2.0 EPSF-1.2\n"); |
---|
[600] | 1416 | #if QT_VERSION < 0x040000 |
---|
| 1417 | fprintf (fp, "%%%%Title: %s\n", aFilename.ascii()); |
---|
| 1418 | #else |
---|
[602] | 1419 | fprintf (fp, "%%%%Title: %s\n", aFilename.toStdString().c_str()); |
---|
[600] | 1420 | #endif |
---|
[586] | 1421 | fprintf (fp, "%%%%Creator: OpenGL pixmap render output\n"); |
---|
[587] | 1422 | fprintf (fp, "%%%%BoundingBox: 0 0 %d %d\n", aImage.width(), aImage.height()); |
---|
[586] | 1423 | fprintf (fp, "%%%%EndComments\n"); |
---|
| 1424 | fprintf (fp, "gsave\n"); |
---|
| 1425 | fprintf (fp, "/bwproc {\n"); |
---|
| 1426 | fprintf (fp, " rgbproc\n"); |
---|
| 1427 | fprintf (fp, " dup length 3 idiv string 0 3 0 \n"); |
---|
| 1428 | fprintf (fp, " 5 -1 roll {\n"); |
---|
| 1429 | fprintf (fp, " add 2 1 roll 1 sub dup 0 eq\n"); |
---|
| 1430 | fprintf (fp, " { pop 3 idiv 3 -1 roll dup 4 -1 roll dup\n"); |
---|
| 1431 | fprintf (fp, " 3 1 roll 5 -1 roll } put 1 add 3 0 \n"); |
---|
| 1432 | fprintf (fp, " { 2 1 roll } ifelse\n"); |
---|
| 1433 | fprintf (fp, " }forall\n"); |
---|
| 1434 | fprintf (fp, " pop pop pop\n"); |
---|
| 1435 | fprintf (fp, "} def\n"); |
---|
| 1436 | fprintf (fp, "systemdict /colorimage known not {\n"); |
---|
| 1437 | fprintf (fp, " /colorimage {\n"); |
---|
| 1438 | fprintf (fp, " pop\n"); |
---|
| 1439 | fprintf (fp, " pop\n"); |
---|
| 1440 | fprintf (fp, " /rgbproc exch def\n"); |
---|
| 1441 | fprintf (fp, " { bwproc } image\n"); |
---|
| 1442 | fprintf (fp, " } def\n"); |
---|
| 1443 | fprintf (fp, "} if\n"); |
---|
[587] | 1444 | fprintf (fp, "/picstr %d string def\n", aImage.width() * aInColor); |
---|
| 1445 | fprintf (fp, "%d %d scale\n", aImage.width(), aImage.height()); |
---|
| 1446 | fprintf (fp, "%d %d %d\n", aImage.width(), aImage.height(), 8); |
---|
| 1447 | fprintf (fp, "[%d 0 0 %d 0 0]\n", aImage.width(), aImage.height()); |
---|
[586] | 1448 | fprintf (fp, "{currentfile picstr readhexstring pop}\n"); |
---|
| 1449 | fprintf (fp, "false %d\n", aInColor); |
---|
| 1450 | fprintf (fp, "colorimage\n"); |
---|
| 1451 | |
---|
| 1452 | |
---|
[588] | 1453 | int width = aImage.width(); |
---|
| 1454 | int height = aImage.height(); |
---|
| 1455 | int depth = aImage.depth(); |
---|
| 1456 | int size = width*height; |
---|
| 1457 | |
---|
[649] | 1458 | |
---|
[588] | 1459 | if (depth == 1) |
---|
| 1460 | size = (width+7)/8*height; |
---|
| 1461 | else if (aInColor == 1) |
---|
| 1462 | size = size*3; |
---|
| 1463 | |
---|
| 1464 | int i = 0; |
---|
[649] | 1465 | // if ( aInColor ==1 ) { |
---|
| 1466 | // FIXME : L. Garnier. For the moment 10 dec 2007, I could not find a way |
---|
| 1467 | // to save correctly grayscale Image. I mean that color or grayscale image |
---|
| 1468 | // have the same file save size ! |
---|
| 1469 | |
---|
| 1470 | /* } else*/ if (depth == 8) { |
---|
[588] | 1471 | for(int y=height-1; y >=0 ; y--) { |
---|
| 1472 | const uchar * s = aImage.scanLine(y); |
---|
| 1473 | for(int x=0; x <width; x++) { |
---|
| 1474 | QRgb rgb = aImage.color(s[x]); |
---|
| 1475 | if (aInColor == 1) { |
---|
| 1476 | fprintf (fp, " %02hx ",(unsigned char)qGray(rgb)); |
---|
| 1477 | i++; |
---|
| 1478 | } else { |
---|
| 1479 | fprintf (fp, " %02hx %02hx %02hx", |
---|
| 1480 | (unsigned char) qRed(rgb), |
---|
| 1481 | (unsigned char) qGreen(rgb), |
---|
| 1482 | (unsigned char) qBlue(rgb)); |
---|
| 1483 | i += 3; |
---|
| 1484 | } |
---|
| 1485 | } |
---|
[586] | 1486 | fprintf (fp, "\n"); |
---|
[588] | 1487 | } |
---|
| 1488 | } else { |
---|
[601] | 1489 | #if QT_VERSION < 0x040000 |
---|
[649] | 1490 | bool alpha = aImage.hasAlphaBuffer(); |
---|
[601] | 1491 | #else |
---|
[588] | 1492 | bool alpha = aImage.hasAlphaChannel(); |
---|
| 1493 | for(int y=height-1; y >=0 ; y--) { |
---|
| 1494 | QRgb * s = (QRgb*)(aImage.scanLine(y)); |
---|
| 1495 | for(int x=0; x <width; x++) { |
---|
| 1496 | QRgb rgb = (*s++); |
---|
| 1497 | if (alpha && qAlpha(rgb) < 0x40) // 25% alpha, convert to white - |
---|
| 1498 | rgb = qRgb(0xff, 0xff, 0xff); |
---|
| 1499 | if (aInColor == 1) { |
---|
| 1500 | fprintf (fp, " %02hx ",(unsigned char)qGray(rgb)); |
---|
| 1501 | i++; |
---|
| 1502 | } else { |
---|
| 1503 | fprintf (fp, " %02hx %02hx %02hx", |
---|
| 1504 | (unsigned char) qRed(rgb), |
---|
| 1505 | (unsigned char) qGreen(rgb), |
---|
| 1506 | (unsigned char) qBlue(rgb)); |
---|
| 1507 | i += 3; |
---|
| 1508 | } |
---|
[587] | 1509 | } |
---|
| 1510 | fprintf (fp, "\n"); |
---|
[588] | 1511 | } |
---|
[601] | 1512 | #endif |
---|
| 1513 | |
---|
[586] | 1514 | } |
---|
[588] | 1515 | |
---|
[586] | 1516 | fprintf (fp, "grestore\n"); |
---|
| 1517 | fprintf (fp, "showpage\n"); |
---|
| 1518 | fclose (fp); |
---|
[588] | 1519 | |
---|
| 1520 | return true; |
---|
[586] | 1521 | } |
---|
[588] | 1522 | /** |
---|
| 1523 | Generate Postscript or PDF form image |
---|
| 1524 | @param aFilename : name of file |
---|
| 1525 | @param aInColor : numbers of colors : 1->BW 2->RGB |
---|
| 1526 | @param aImage : Image to print |
---|
| 1527 | */ |
---|
| 1528 | bool G4OpenGLQtViewer::generatePS_PDF ( |
---|
| 1529 | QString aFilename |
---|
| 1530 | ,int aInColor |
---|
| 1531 | ,QImage aImage |
---|
| 1532 | ) |
---|
| 1533 | { |
---|
[638] | 1534 | |
---|
[600] | 1535 | #if QT_VERSION < 0x040000 |
---|
| 1536 | #ifdef Q_WS_MAC || Q_WS_X11 |
---|
[588] | 1537 | QPrinter printer; |
---|
| 1538 | // printer.setPageSize(pageSize); |
---|
| 1539 | if (aInColor == 1) { |
---|
| 1540 | printer.setColorMode(QPrinter::GrayScale); |
---|
| 1541 | } else { |
---|
| 1542 | printer.setColorMode(QPrinter::Color); |
---|
| 1543 | } |
---|
| 1544 | |
---|
[600] | 1545 | /* FIXME : I don't know which format it will save... |
---|
| 1546 | if (aFilename.endsWith(".ps")) { |
---|
| 1547 | printer.setOutputFormat(QPrinter::PostScriptFormat); |
---|
| 1548 | } else { |
---|
| 1549 | printer.setOutputFormat(QPrinter::PdfFormat); |
---|
| 1550 | } |
---|
| 1551 | */ |
---|
| 1552 | printer.setOutputFileName(aFilename); |
---|
| 1553 | // printer.setFullPage ( true); |
---|
| 1554 | QPainter paint(&printer); |
---|
| 1555 | paint.drawImage (0,0,aImage ); |
---|
| 1556 | paint.end(); |
---|
| 1557 | #else |
---|
[638] | 1558 | G4cerr << "This fonction is only supported on Mac OsX or X11 with Qt3. Full platform supported with Qt4\n" << G4endl; |
---|
[600] | 1559 | #endif |
---|
| 1560 | #else |
---|
| 1561 | QPrinter printer; |
---|
| 1562 | // printer.setPageSize(pageSize); |
---|
[637] | 1563 | |
---|
| 1564 | // FIXME : L. Garnier 4/12/07 |
---|
| 1565 | // This is not working, it does nothing. Image is staying in color mode |
---|
| 1566 | // So I have desactivate the B/W button in GUI |
---|
| 1567 | if ((!aImage.isGrayscale ()) &&(aInColor ==1 )) { |
---|
| 1568 | #if QT_VERSION < 0x040000 |
---|
| 1569 | aImage = aImage.convertDepth(1,Qt::MonoOnly); |
---|
| 1570 | #else |
---|
| 1571 | aImage = aImage.convertToFormat ( aImage.format(), Qt::MonoOnly); |
---|
| 1572 | #endif |
---|
[600] | 1573 | } |
---|
| 1574 | |
---|
[637] | 1575 | |
---|
[588] | 1576 | if (aFilename.endsWith(".ps")) { |
---|
[606] | 1577 | #if QT_VERSION > 0x040200 |
---|
[588] | 1578 | printer.setOutputFormat(QPrinter::PostScriptFormat); |
---|
[606] | 1579 | #endif |
---|
[588] | 1580 | } else { |
---|
[606] | 1581 | #if QT_VERSION > 0x040100 |
---|
[588] | 1582 | printer.setOutputFormat(QPrinter::PdfFormat); |
---|
[606] | 1583 | #endif |
---|
[588] | 1584 | } |
---|
[606] | 1585 | #if QT_VERSION > 0x040100 |
---|
[588] | 1586 | printer.setOutputFileName(aFilename); |
---|
[606] | 1587 | #endif |
---|
[588] | 1588 | // printer.setFullPage ( true); |
---|
| 1589 | QPainter paint(&printer); |
---|
[637] | 1590 | paint.drawImage (0,0,aImage); |
---|
[588] | 1591 | paint.end(); |
---|
[600] | 1592 | #endif |
---|
[588] | 1593 | return true; |
---|
| 1594 | } |
---|
| 1595 | |
---|
[530] | 1596 | #endif |
---|
[588] | 1597 | |
---|
| 1598 | /* |
---|
| 1599 | |
---|
| 1600 | void MultiLayer::exportToSVG(const QString& fname) |
---|
| 1601 | { |
---|
| 1602 | QPicture picture; |
---|
| 1603 | QPainter p(&picture); |
---|
| 1604 | for (int i=0;i<(int)graphsList->count();i++) |
---|
| 1605 | { |
---|
| 1606 | Graph *gr=(Graph *)graphsList->at(i); |
---|
| 1607 | Plot *myPlot= (Plot *)gr->plotWidget(); |
---|
| 1608 | |
---|
| 1609 | QPoint pos=gr->pos(); |
---|
| 1610 | |
---|
| 1611 | int width=int(myPlot->frameGeometry().width()); |
---|
| 1612 | int height=int(myPlot->frameGeometry().height()); |
---|
| 1613 | |
---|
| 1614 | myPlot->print(&p, QRect(pos,QSize(width,height))); |
---|
| 1615 | } |
---|
| 1616 | |
---|
| 1617 | p.end(); |
---|
| 1618 | picture.save(fname, "svg"); |
---|
| 1619 | } |
---|
| 1620 | */ |
---|