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