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