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