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