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