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