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