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