| 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.3 2007/11/08 17:00:51 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 | #include "G4OpenGLQtViewer.hh"
|
|---|
| 39 |
|
|---|
| 40 | #include "G4ios.hh"
|
|---|
| 41 | #include "G4VisExtent.hh"
|
|---|
| 42 | #include "G4LogicalVolume.hh"
|
|---|
| 43 | #include "G4VSolid.hh"
|
|---|
| 44 | #include "G4Point3D.hh"
|
|---|
| 45 | #include "G4Normal3D.hh"
|
|---|
| 46 | #include "G4Scene.hh"
|
|---|
| 47 | #include "G4OpenGLQtExportDialog.hh"
|
|---|
| 48 |
|
|---|
| 49 | #include "G4Qt.hh"
|
|---|
| 50 | #include "G4UIsession.hh"
|
|---|
| 51 | #include "G4UImanager.hh"
|
|---|
| 52 | #include <qapplication.h>
|
|---|
| 53 | #include <qboxLayout.h>
|
|---|
| 54 | #include <qdialog.h>
|
|---|
| 55 | #include <qmenu.h>
|
|---|
| 56 | #include <qimagewriter.h>
|
|---|
| 57 | #include <qmessagebox.h>
|
|---|
| 58 | #include <qfiledialog.h>
|
|---|
| 59 | #include <qprinter.h>
|
|---|
| 60 | #include <qpainter.h>
|
|---|
| 61 | #include <qgl.h> // include <qglwidget.h>
|
|---|
| 62 | #include <qdialog.h>
|
|---|
| 63 | #include <qevent.h> //include <qcontextmenuevent.h>
|
|---|
| 64 | #include <qmenu.h>
|
|---|
| 65 | #include <qimage.h>
|
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 69 | /**
|
|---|
| 70 | Implementation of virtual method of G4VViewer
|
|---|
| 71 | */
|
|---|
| 72 | void G4OpenGLQtViewer::SetView (
|
|---|
| 73 | )
|
|---|
| 74 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 75 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
|---|
| 76 | {
|
|---|
| 77 | printf("G4OpenGLQtViewer::SetView ++++++++++++++++++++\n");
|
|---|
| 78 | // if(!fHDC) return;
|
|---|
| 79 | // if(!fHGLRC) return;
|
|---|
| 80 | // ::wglMakeCurrent(fHDC,fHGLRC);
|
|---|
| 81 | // fWindow->makeCurrent();
|
|---|
| 82 | G4OpenGLViewer::SetView ();
|
|---|
| 83 | printf("G4OpenGLQtViewer::SetView --------------------\n");
|
|---|
| 84 | }
|
|---|
| 85 |
|
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 89 | /**
|
|---|
| 90 | Implementation of virtual method of G4VViewer
|
|---|
| 91 | */
|
|---|
| 92 | void G4OpenGLQtViewer::ShowView (
|
|---|
| 93 | )
|
|---|
| 94 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 95 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
|---|
| 96 | {
|
|---|
| 97 | printf("G4OpenGLQtViewer::ShowView +++++++++++++++++++++\n");
|
|---|
| 98 | glFlush ();
|
|---|
| 99 | if (!GLWindow) {
|
|---|
| 100 | G4cerr << "Visualization window not defined, please choose one before" << G4endl;
|
|---|
| 101 | } else {
|
|---|
| 102 | GLWindow->activateWindow();
|
|---|
| 103 | printf("G4OpenGLQtViewer::ShowView -----------------------\n");
|
|---|
| 104 | }
|
|---|
| 105 | // // Empty the Windows message queue :
|
|---|
| 106 | // MSG event;
|
|---|
| 107 | // while ( ::PeekMessage(&event, NULL, 0, 0, PM_REMOVE) ) {
|
|---|
| 108 | // ::TranslateMessage(&event);
|
|---|
| 109 | // ::DispatchMessage (&event);
|
|---|
| 110 | // }
|
|---|
| 111 | }
|
|---|
| 112 |
|
|---|
| 113 |
|
|---|
| 114 |
|
|---|
| 115 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 116 | void G4OpenGLQtViewer::CreateGLQtContext (
|
|---|
| 117 | )
|
|---|
| 118 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 119 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
|---|
| 120 | {
|
|---|
| 121 | printf("G4OpenGLQtViewer::CreateGLQtContext \n");
|
|---|
| 122 | }
|
|---|
| 123 |
|
|---|
| 124 |
|
|---|
| 125 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 126 | void G4OpenGLQtViewer::CreateMainWindow (
|
|---|
| 127 | QGLWidget* glWidget
|
|---|
| 128 | )
|
|---|
| 129 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 130 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
|---|
| 131 | {
|
|---|
| 132 |
|
|---|
| 133 | if(fWindow) return; //Done.
|
|---|
| 134 | printf("G4OpenGLQtViewer::CreateMainWindow glWidget\n");
|
|---|
| 135 |
|
|---|
| 136 | // launch Qt if not
|
|---|
| 137 | G4Qt* interactorManager = G4Qt::getInstance ();
|
|---|
| 138 | // G4UImanager* UI = G4UImanager::GetUIpointer();
|
|---|
| 139 |
|
|---|
| 140 | fWindow = glWidget ;
|
|---|
| 141 | // fWindow->makeCurrent();
|
|---|
| 142 |
|
|---|
| 143 | // create window
|
|---|
| 144 | if (((QApplication*)interactorManager->GetMainInteractor())) {
|
|---|
| 145 | // look for the main window
|
|---|
| 146 | bool found = false;
|
|---|
| 147 | foreach (QWidget *widget, QApplication::allWidgets()) {
|
|---|
| 148 | if ((found== false) && (widget->inherits("QMainWindow"))) {
|
|---|
| 149 | printf("G4OpenGLQtViewer::CreateMainWindow case Qapp exist\n");
|
|---|
| 150 | GLWindow = new QDialog(widget,Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint);
|
|---|
| 151 | found = true;
|
|---|
| 152 | }
|
|---|
| 153 | }
|
|---|
| 154 | if (found==false) {
|
|---|
| 155 | printf("G4OpenGLQtViewer::CreateMainWindow case Qapp exist, but not found\n");
|
|---|
| 156 | GLWindow = new QDialog();
|
|---|
| 157 | }
|
|---|
| 158 | } else {
|
|---|
| 159 | printf("G4OpenGLQtViewer::CreateMainWindow case Qapp exist\n");
|
|---|
| 160 | GLWindow = new QDialog();
|
|---|
| 161 | }
|
|---|
| 162 |
|
|---|
| 163 | QHBoxLayout *mainLayout = new QHBoxLayout;
|
|---|
| 164 |
|
|---|
| 165 | mainLayout->addWidget(fWindow);
|
|---|
| 166 | GLWindow->setLayout(mainLayout);
|
|---|
| 167 | GLWindow->setWindowTitle("QGl Viewer");
|
|---|
| 168 | GLWindow->resize(300, 300);
|
|---|
| 169 | GLWindow->move(900,300);
|
|---|
| 170 | GLWindow->show();
|
|---|
| 171 |
|
|---|
| 172 | // delete the pointer if close this
|
|---|
| 173 | // GLWindow->setAttribute(Qt::WA_DeleteOnClose);
|
|---|
| 174 |
|
|---|
| 175 | QObject ::connect(GLWindow,
|
|---|
| 176 | SIGNAL(rejected()),
|
|---|
| 177 | this,
|
|---|
| 178 | SLOT(dialogClosed()));
|
|---|
| 179 |
|
|---|
| 180 | WinSize_x = 400;
|
|---|
| 181 | WinSize_y = 400;
|
|---|
| 182 | if (WinSize_x < fVP.GetWindowSizeHintX ())
|
|---|
| 183 | WinSize_x = fVP.GetWindowSizeHintX ();
|
|---|
| 184 | if (WinSize_y < fVP.GetWindowSizeHintY ())
|
|---|
| 185 | WinSize_y = fVP.GetWindowSizeHintY ();
|
|---|
| 186 |
|
|---|
| 187 | if(!fWindow) return;
|
|---|
| 188 | printf("G4OpenGLQtViewer::CreateMainWindow glWidget END\n");
|
|---|
| 189 |
|
|---|
| 190 | if (!fContextMenu)
|
|---|
| 191 | createPopupMenu();
|
|---|
| 192 |
|
|---|
| 193 | }
|
|---|
| 194 |
|
|---|
| 195 | /** Close the dialog and set the pointer to NULL
|
|---|
| 196 | */
|
|---|
| 197 | void G4OpenGLQtViewer::dialogClosed() {
|
|---|
| 198 | GLWindow = NULL;
|
|---|
| 199 | }
|
|---|
| 200 |
|
|---|
| 201 |
|
|---|
| 202 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 203 | G4OpenGLQtViewer::G4OpenGLQtViewer (
|
|---|
| 204 | G4OpenGLSceneHandler& scene
|
|---|
| 205 | )
|
|---|
| 206 | :G4VViewer (scene, -1)
|
|---|
| 207 | ,G4OpenGLViewer (scene)
|
|---|
| 208 | ,fWindow(0)
|
|---|
| 209 | ,fContextMenu(0)
|
|---|
| 210 | ,fMouseAction(true)
|
|---|
| 211 | {
|
|---|
| 212 | printf("G4OpenGLQtViewer::G4OpenGLQtViewer \n");
|
|---|
| 213 | }
|
|---|
| 214 |
|
|---|
| 215 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 216 | G4OpenGLQtViewer::~G4OpenGLQtViewer (
|
|---|
| 217 | )
|
|---|
| 218 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 219 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
|---|
| 220 | {
|
|---|
| 221 | printf("G4OpenGLQtViewer::~G4OpenGLQtViewer \n");
|
|---|
| 222 | delete fContextMenu;
|
|---|
| 223 | }
|
|---|
| 224 |
|
|---|
| 225 |
|
|---|
| 226 | /**
|
|---|
| 227 | Create a popup menu for the widget. This menu is activated by right-mouse click
|
|---|
| 228 | */
|
|---|
| 229 | void G4OpenGLQtViewer::createPopupMenu() {
|
|---|
| 230 |
|
|---|
| 231 | fContextMenu = new QMenu("All");
|
|---|
| 232 |
|
|---|
| 233 | QMenu *mMouseAction = fContextMenu->addMenu("&Mouse action");
|
|---|
| 234 | QAction *rotate = mMouseAction->addAction("&Rotate scene");
|
|---|
| 235 | QAction *move = mMouseAction->addAction("&Move scene");
|
|---|
| 236 | // INIT mMouse
|
|---|
| 237 | createRadioAction(rotate,move,SLOT(toggleMouseAction(bool)),1);
|
|---|
| 238 |
|
|---|
| 239 | //Style Menu
|
|---|
| 240 | QMenu *mStyle = fContextMenu->addMenu("&Style");
|
|---|
| 241 |
|
|---|
| 242 | QMenu *mRepresentation = mStyle->addMenu("&Representation");
|
|---|
| 243 | QAction *polyhedron = mRepresentation->addAction("Polyhedron");
|
|---|
| 244 | QAction *nurbs = mRepresentation->addAction("NURBS");
|
|---|
| 245 | // INIT mStyle
|
|---|
| 246 | G4ViewParameters::RepStyle style;
|
|---|
| 247 | style = fVP.GetRepStyle();
|
|---|
| 248 | if (style == G4ViewParameters::polyhedron) {
|
|---|
| 249 | createRadioAction(polyhedron,nurbs,SLOT(toggleRepresentation(bool)),1);
|
|---|
| 250 | } else if (style == G4ViewParameters::nurbs) {
|
|---|
| 251 | createRadioAction(polyhedron,nurbs,SLOT(toggleRepresentation(bool)),2);
|
|---|
| 252 | } else {
|
|---|
| 253 | mRepresentation->clear();
|
|---|
| 254 | }
|
|---|
| 255 |
|
|---|
| 256 |
|
|---|
| 257 | QMenu *mDrawing = mStyle->addMenu("&Drawing");
|
|---|
| 258 | fDrawingWireframe = mDrawing->addAction("Wireframe");
|
|---|
| 259 | fDrawingWireframe->setCheckable(true);
|
|---|
| 260 | fDrawingWireframe->setChecked(true);
|
|---|
| 261 | fDrawingLineRemoval = mDrawing->addAction("Hidden line removal");
|
|---|
| 262 | fDrawingLineRemoval->setCheckable(true);
|
|---|
| 263 | fDrawingSurfaceRemoval = mDrawing->addAction("Hidden Surface removal");
|
|---|
| 264 | fDrawingSurfaceRemoval->setCheckable(true);
|
|---|
| 265 | fDrawingLineSurfaceRemoval = mDrawing->addAction("Hidden line and surface removal");
|
|---|
| 266 | fDrawingLineSurfaceRemoval->setCheckable(true);
|
|---|
| 267 | // INIT Drawing
|
|---|
| 268 | G4ViewParameters::DrawingStyle d_style;
|
|---|
| 269 | d_style = fVP.GetDrawingStyle();
|
|---|
| 270 |
|
|---|
| 271 | fDrawingWireframe->setCheckable(true);
|
|---|
| 272 | fDrawingLineRemoval->setCheckable(true);
|
|---|
| 273 | fDrawingSurfaceRemoval->setCheckable(true);
|
|---|
| 274 | fDrawingLineSurfaceRemoval->setCheckable(true);
|
|---|
| 275 |
|
|---|
| 276 | if (d_style == G4ViewParameters::wireframe) {
|
|---|
| 277 | fDrawingWireframe->setChecked(true);
|
|---|
| 278 | } else if (d_style == G4ViewParameters::hlr) {
|
|---|
| 279 | fDrawingLineRemoval->setChecked(true);
|
|---|
| 280 | } else if (d_style == G4ViewParameters::hsr) {
|
|---|
| 281 | fDrawingSurfaceRemoval->setChecked(true);
|
|---|
| 282 | } else if (d_style == G4ViewParameters::hlhsr) {
|
|---|
| 283 | fDrawingLineSurfaceRemoval->setChecked(true);
|
|---|
| 284 | } else {
|
|---|
| 285 | mDrawing->clear();
|
|---|
| 286 | }
|
|---|
| 287 |
|
|---|
| 288 | QObject ::connect(fDrawingWireframe,
|
|---|
| 289 | SIGNAL(triggered(bool)),
|
|---|
| 290 | this,
|
|---|
| 291 | SLOT(actionDrawingWireframe()));
|
|---|
| 292 | QObject ::connect(fDrawingLineRemoval,
|
|---|
| 293 | SIGNAL(triggered(bool)),
|
|---|
| 294 | this,
|
|---|
| 295 | SLOT(actionDrawingLineRemoval()));
|
|---|
| 296 | QObject ::connect(fDrawingSurfaceRemoval,
|
|---|
| 297 | SIGNAL(triggered(bool)),
|
|---|
| 298 | this,
|
|---|
| 299 | SLOT(actionDrawingSurfaceRemoval()));
|
|---|
| 300 | QObject ::connect(fDrawingLineSurfaceRemoval,
|
|---|
| 301 | SIGNAL(triggered(bool)),
|
|---|
| 302 | this,
|
|---|
| 303 | SLOT(actionDrawingLineSurfaceRemoval()));
|
|---|
| 304 |
|
|---|
| 305 |
|
|---|
| 306 | QMenu *mBackground = mStyle->addMenu("&Background color");
|
|---|
| 307 | QAction *white = mBackground->addAction("White");
|
|---|
| 308 | QAction *black = mBackground->addAction("Black");
|
|---|
| 309 | if (background.GetRed() == 1. &&
|
|---|
| 310 | background.GetGreen() == 1. &&
|
|---|
| 311 | background.GetBlue() == 1.) {
|
|---|
| 312 | createRadioAction(white,black,SLOT(toggleBackground(bool)),1);
|
|---|
| 313 | } else {
|
|---|
| 314 | createRadioAction(white,black,SLOT(toggleBackground(bool)),2);
|
|---|
| 315 | }
|
|---|
| 316 |
|
|---|
| 317 |
|
|---|
| 318 | // Action Menu
|
|---|
| 319 | QMenu *mActions = fContextMenu->addMenu("&Actions");
|
|---|
| 320 | QAction *controlPanels = mActions->addAction("Control panels");
|
|---|
| 321 | QAction *exitG4 = mActions->addAction("Exit to G4Vis >");
|
|---|
| 322 | QAction *createEPS = mActions->addAction("Save as ...");
|
|---|
| 323 | QObject ::connect(controlPanels,
|
|---|
| 324 | SIGNAL(triggered()),
|
|---|
| 325 | this,
|
|---|
| 326 | SLOT(actionControlPanels()));
|
|---|
| 327 | QObject ::connect(exitG4,
|
|---|
| 328 | SIGNAL(triggered()),
|
|---|
| 329 | this,
|
|---|
| 330 | SLOT(actionExitG4()));
|
|---|
| 331 | QObject ::connect(createEPS,
|
|---|
| 332 | SIGNAL(triggered()),
|
|---|
| 333 | this,
|
|---|
| 334 | SLOT(actionCreateEPS()));
|
|---|
| 335 |
|
|---|
| 336 |
|
|---|
| 337 | // Special Menu
|
|---|
| 338 | QMenu *mSpecial = fContextMenu->addMenu("S&pecial");
|
|---|
| 339 | QMenu *transparency = mSpecial->addMenu("Transparency");
|
|---|
| 340 | QAction *transparencyOn = transparency->addAction("On");
|
|---|
| 341 | QAction *transparencyOff = transparency->addAction("Off");
|
|---|
| 342 | if (transparency_enabled == false) {
|
|---|
| 343 | createRadioAction(transparencyOn,transparencyOff,SLOT(toggleTransparency(bool)),2);
|
|---|
| 344 | } else if (transparency_enabled == true) {
|
|---|
| 345 | createRadioAction(transparencyOn,transparencyOff,SLOT(toggleTransparency(bool)),1);
|
|---|
| 346 | } else {
|
|---|
| 347 | mSpecial->clear();
|
|---|
| 348 | }
|
|---|
| 349 |
|
|---|
| 350 |
|
|---|
| 351 | QMenu *mAntialiasing = mSpecial->addMenu("Antialiasing");
|
|---|
| 352 | QAction *antialiasingOn = mAntialiasing->addAction("On");
|
|---|
| 353 | QAction *antialiasingOff = mAntialiasing->addAction("Off");
|
|---|
| 354 | if (antialiasing_enabled == false) {
|
|---|
| 355 | createRadioAction(antialiasingOn,antialiasingOff,SLOT(toggleAntialiasing(bool)),2);
|
|---|
| 356 | } else if (antialiasing_enabled == true) {
|
|---|
| 357 | createRadioAction(antialiasingOn,antialiasingOff,SLOT(toggleAntialiasing(bool)),1);
|
|---|
| 358 | } else {
|
|---|
| 359 | mAntialiasing->clear();
|
|---|
| 360 | }
|
|---|
| 361 |
|
|---|
| 362 | QMenu *mHaloing = mSpecial->addMenu("Haloing");
|
|---|
| 363 | QAction *haloingOn = mHaloing->addAction("On");
|
|---|
| 364 | QAction *haloingOff = mHaloing->addAction("Off");
|
|---|
| 365 | if (haloing_enabled == false) {
|
|---|
| 366 | createRadioAction(haloingOn,haloingOff,SLOT(toggleHaloing(bool)),2);
|
|---|
| 367 | } else if (haloing_enabled == true) {
|
|---|
| 368 | createRadioAction(haloingOn,haloingOff,SLOT(toggleHaloing(bool)),1);
|
|---|
| 369 | } else {
|
|---|
| 370 | mHaloing->clear();
|
|---|
| 371 | }
|
|---|
| 372 |
|
|---|
| 373 | QMenu *mAux = mSpecial->addMenu("Auxiliary edges");
|
|---|
| 374 | QAction *auxOn = mAux->addAction("On");
|
|---|
| 375 | QAction *auxOff = mAux->addAction("Off");
|
|---|
| 376 | if (!fVP.IsAuxEdgeVisible()) {
|
|---|
| 377 | createRadioAction(auxOn,auxOff,SLOT(toggleAux(bool)),1);
|
|---|
| 378 | } else {
|
|---|
| 379 | createRadioAction(auxOn,auxOff,SLOT(toggleAux(bool)),2);
|
|---|
| 380 | }
|
|---|
| 381 |
|
|---|
| 382 |
|
|---|
| 383 | QMenu *mFullScreen = mSpecial->addMenu("Full screen");
|
|---|
| 384 | QAction *fullOn = mFullScreen->addAction("On");
|
|---|
| 385 | QAction *fullOff = mFullScreen->addAction("Off");
|
|---|
| 386 | createRadioAction(fullOn,fullOff,SLOT(toggleFullScreen(bool)),2);
|
|---|
| 387 |
|
|---|
| 388 | }
|
|---|
| 389 |
|
|---|
| 390 | void G4OpenGLQtViewer::manageContextMenuEvent(QContextMenuEvent *e)
|
|---|
| 391 | {
|
|---|
| 392 | if (!GLWindow) {
|
|---|
| 393 | G4cerr << "Visualization window not defined, please choose one before" << G4endl;
|
|---|
| 394 | } else {
|
|---|
| 395 |
|
|---|
| 396 | if (!fContextMenu)
|
|---|
| 397 | createPopupMenu();
|
|---|
| 398 |
|
|---|
| 399 | // launch menu
|
|---|
| 400 | if ( fContextMenu ) {
|
|---|
| 401 | fContextMenu->exec( e->globalPos() );
|
|---|
| 402 | // delete fContextMenu;
|
|---|
| 403 | }
|
|---|
| 404 | }
|
|---|
| 405 | e->accept();
|
|---|
| 406 | }
|
|---|
| 407 |
|
|---|
| 408 |
|
|---|
| 409 | /**
|
|---|
| 410 | Create a radio button menu. The two menu will be connected. When click on one,
|
|---|
| 411 | eatch state will be invert and callback method will be called.
|
|---|
| 412 | @param action1 first action to connect
|
|---|
| 413 | @param action2 second action to connect
|
|---|
| 414 | @param method callback method
|
|---|
| 415 | @param nCheck: 1 : first action will be set true. 2 : second action will be set true
|
|---|
| 416 | */
|
|---|
| 417 | void G4OpenGLQtViewer::createRadioAction(QAction *action1,QAction *action2, const std::string& method,unsigned int nCheck) {
|
|---|
| 418 |
|
|---|
| 419 | action1->setCheckable(true);
|
|---|
| 420 | action2->setCheckable(true);
|
|---|
| 421 |
|
|---|
| 422 | if (nCheck ==1)
|
|---|
| 423 | action1->setChecked (true);
|
|---|
| 424 | else
|
|---|
| 425 | action2->setChecked (true);
|
|---|
| 426 |
|
|---|
| 427 | QObject ::connect(action1, SIGNAL(triggered(bool)),action2, SLOT(toggle()));
|
|---|
| 428 | QObject ::connect(action2, SIGNAL(triggered(bool)),action1, SLOT(toggle()));
|
|---|
| 429 |
|
|---|
| 430 | QObject ::connect(action1, SIGNAL(toggled(bool)),this, method.c_str());
|
|---|
| 431 |
|
|---|
| 432 | }
|
|---|
| 433 |
|
|---|
| 434 | /**
|
|---|
| 435 | Slot activate when drawing->wireframe menu is set
|
|---|
| 436 | */
|
|---|
| 437 | void G4OpenGLQtViewer::actionDrawingWireframe() {
|
|---|
| 438 | emit toggleDrawingAction(1);
|
|---|
| 439 | }
|
|---|
| 440 |
|
|---|
| 441 | /**
|
|---|
| 442 | Slot activate when drawing->line removal menu is set
|
|---|
| 443 | */
|
|---|
| 444 | void G4OpenGLQtViewer::actionDrawingLineRemoval() {
|
|---|
| 445 | emit toggleDrawingAction(2);
|
|---|
| 446 | }
|
|---|
| 447 |
|
|---|
| 448 | /**
|
|---|
| 449 | Slot activate when drawing->surface removal menu is set
|
|---|
| 450 | */
|
|---|
| 451 | void G4OpenGLQtViewer::actionDrawingSurfaceRemoval() {
|
|---|
| 452 | emit toggleDrawingAction(3);
|
|---|
| 453 | }
|
|---|
| 454 |
|
|---|
| 455 | /**
|
|---|
| 456 | Slot activate when drawing->wireframe menu is set
|
|---|
| 457 | */
|
|---|
| 458 | void G4OpenGLQtViewer::actionDrawingLineSurfaceRemoval() {
|
|---|
| 459 | emit toggleDrawingAction(4);
|
|---|
| 460 | }
|
|---|
| 461 |
|
|---|
| 462 |
|
|---|
| 463 | /**
|
|---|
| 464 | Slot activated when drawing menu is toggle
|
|---|
| 465 | Warning : When G4OpenGLStoredQtViewer::DrawView() method call,
|
|---|
| 466 | KernelVisitDecision () will be call and will set the fNeedKernelVisit
|
|---|
| 467 | to 1. See G4XXXStoredViewer::CompareForKernelVisit for explanations.
|
|---|
| 468 | It will cause a redraw of the view
|
|---|
| 469 | @param aAction : 1 wireframe, 2 line removal, 3 surface removal, 4 line & surface removal
|
|---|
| 470 | @see G4OpenGLStoredQtViewer::DrawView
|
|---|
| 471 | @see G4XXXStoredViewer::CompareForKernelVisit
|
|---|
| 472 | */
|
|---|
| 473 | void G4OpenGLQtViewer::toggleDrawingAction(int aAction) {
|
|---|
| 474 |
|
|---|
| 475 | G4ViewParameters::DrawingStyle d_style;
|
|---|
| 476 |
|
|---|
| 477 |
|
|---|
| 478 | if (aAction ==1) {
|
|---|
| 479 | fDrawingWireframe->setChecked (true);
|
|---|
| 480 | fDrawingLineRemoval->setChecked (false);
|
|---|
| 481 | fDrawingSurfaceRemoval->setChecked (false);
|
|---|
| 482 | fDrawingLineSurfaceRemoval->setChecked (false);
|
|---|
| 483 |
|
|---|
| 484 | d_style = G4ViewParameters::wireframe;
|
|---|
| 485 |
|
|---|
| 486 | } else if (aAction ==2) {
|
|---|
| 487 | fDrawingWireframe->setChecked (false);
|
|---|
| 488 | fDrawingLineRemoval->setChecked (true);
|
|---|
| 489 | fDrawingSurfaceRemoval->setChecked (false);
|
|---|
| 490 | fDrawingLineSurfaceRemoval->setChecked (false);
|
|---|
| 491 |
|
|---|
| 492 | d_style = G4ViewParameters::hlr;
|
|---|
| 493 |
|
|---|
| 494 | } else if (aAction ==3) {
|
|---|
| 495 | fDrawingWireframe->setChecked (false);
|
|---|
| 496 | fDrawingLineRemoval->setChecked (false);
|
|---|
| 497 | fDrawingSurfaceRemoval->setChecked (true);
|
|---|
| 498 | fDrawingLineSurfaceRemoval->setChecked (false);
|
|---|
| 499 |
|
|---|
| 500 | d_style = G4ViewParameters::hsr;
|
|---|
| 501 |
|
|---|
| 502 | } else if (aAction ==4) {
|
|---|
| 503 | fDrawingWireframe->setChecked (false);
|
|---|
| 504 | fDrawingLineRemoval->setChecked (false);
|
|---|
| 505 | fDrawingSurfaceRemoval->setChecked (false);
|
|---|
| 506 | fDrawingLineSurfaceRemoval->setChecked (true);
|
|---|
| 507 |
|
|---|
| 508 | d_style = G4ViewParameters::hlhsr;
|
|---|
| 509 | }
|
|---|
| 510 | fVP.SetDrawingStyle(d_style);
|
|---|
| 511 |
|
|---|
| 512 | updateQWidget();
|
|---|
| 513 | printf("G4OpenGLQtViewer::toggleDrawingAction\n");
|
|---|
| 514 | }
|
|---|
| 515 |
|
|---|
| 516 |
|
|---|
| 517 | /**
|
|---|
| 518 | SLOT Activate by a click on the representation menu
|
|---|
| 519 | Warning : When G4OpenGLStoredQtViewer::DrawView() method call,
|
|---|
| 520 | KernelVisitDecision () will be call and will set the fNeedKernelVisit
|
|---|
| 521 | to 1. See G4XXXStoredViewer::CompareForKernelVisit for explanations.
|
|---|
| 522 | It will cause a redraw of the view
|
|---|
| 523 | @param check : 1 polyhedron, 0 nurbs
|
|---|
| 524 | @see G4OpenGLStoredQtViewer::DrawView
|
|---|
| 525 | @see G4XXXStoredViewer::CompareForKernelVisit
|
|---|
| 526 | */
|
|---|
| 527 | void G4OpenGLQtViewer::toggleRepresentation(bool check) {
|
|---|
| 528 |
|
|---|
| 529 | G4ViewParameters::RepStyle style;
|
|---|
| 530 | if (check == 1) {
|
|---|
| 531 | style = G4ViewParameters::polyhedron;
|
|---|
| 532 | } else {
|
|---|
| 533 | style = G4ViewParameters::nurbs;
|
|---|
| 534 | }
|
|---|
| 535 | fVP.SetRepStyle (style);
|
|---|
| 536 |
|
|---|
| 537 | printf("G4OpenGLQtViewer::toggleRepresentation 3%d\n",check);
|
|---|
| 538 | updateQWidget();
|
|---|
| 539 | printf("G4OpenGLQtViewer::toggleRepresentation 4%d\n",check);
|
|---|
| 540 | }
|
|---|
| 541 |
|
|---|
| 542 | /**
|
|---|
| 543 | SLOT Activate by a click on the background menu
|
|---|
| 544 | @param check : 1 white, 0 black
|
|---|
| 545 | */
|
|---|
| 546 | void G4OpenGLQtViewer::toggleBackground(bool check) {
|
|---|
| 547 |
|
|---|
| 548 | // //I need to revisit the kernel if the background colour changes and
|
|---|
| 549 | // //hidden line removal is enabled, because hlr drawing utilises the
|
|---|
| 550 | // //background colour in its drawing...
|
|---|
| 551 | // // (Note added by JA 13/9/2005) Background now handled in view
|
|---|
| 552 | // // parameters. A kernel visit is triggered on change of background.
|
|---|
| 553 | if (check == 1) {
|
|---|
| 554 | ((G4ViewParameters&)this->GetViewParameters()).
|
|---|
| 555 | SetBackgroundColour(G4Colour(1.,1.,1.)); // White
|
|---|
| 556 | } else {
|
|---|
| 557 | ((G4ViewParameters&)this->GetViewParameters()).
|
|---|
| 558 | SetBackgroundColour(G4Colour(0.,0.,0.)); // Black
|
|---|
| 559 | }
|
|---|
| 560 | updateQWidget();
|
|---|
| 561 | }
|
|---|
| 562 |
|
|---|
| 563 | /**
|
|---|
| 564 | SLOT Activate by a click on the transparency menu
|
|---|
| 565 | @param check : 1 , 0
|
|---|
| 566 | */
|
|---|
| 567 | void G4OpenGLQtViewer::toggleTransparency(bool check) {
|
|---|
| 568 |
|
|---|
| 569 | if (check) {
|
|---|
| 570 | transparency_enabled = false;
|
|---|
| 571 | } else {
|
|---|
| 572 | transparency_enabled = true;
|
|---|
| 573 | }
|
|---|
| 574 | SetNeedKernelVisit (true);
|
|---|
| 575 | updateQWidget();
|
|---|
| 576 | }
|
|---|
| 577 |
|
|---|
| 578 | /**
|
|---|
| 579 | SLOT Activate by a click on the antialiasing menu
|
|---|
| 580 | @param check : 1 , 0
|
|---|
| 581 | */
|
|---|
| 582 | void G4OpenGLQtViewer::toggleAntialiasing(bool check) {
|
|---|
| 583 |
|
|---|
| 584 | if (!check) {
|
|---|
| 585 | antialiasing_enabled = false;
|
|---|
| 586 | glDisable (GL_LINE_SMOOTH);
|
|---|
| 587 | glDisable (GL_POLYGON_SMOOTH);
|
|---|
| 588 | } else {
|
|---|
| 589 | antialiasing_enabled = true;
|
|---|
| 590 | glEnable (GL_LINE_SMOOTH);
|
|---|
| 591 | glHint (GL_LINE_SMOOTH_HINT, GL_NICEST);
|
|---|
| 592 | glEnable (GL_POLYGON_SMOOTH);
|
|---|
| 593 | glHint (GL_POLYGON_SMOOTH_HINT, GL_NICEST);
|
|---|
| 594 | }
|
|---|
| 595 |
|
|---|
| 596 | updateQWidget();
|
|---|
| 597 | printf("G4OpenGLQtViewer::toggleRepresentation %d\n",check);
|
|---|
| 598 | }
|
|---|
| 599 |
|
|---|
| 600 | /**
|
|---|
| 601 | SLOT Activate by a click on the haloing menu
|
|---|
| 602 | @param check : 1 , 0
|
|---|
| 603 | */
|
|---|
| 604 | //FIXME : I SEE NOTHING...
|
|---|
| 605 | void G4OpenGLQtViewer::toggleHaloing(bool check) {
|
|---|
| 606 | if (check) {
|
|---|
| 607 | haloing_enabled = false;
|
|---|
| 608 | } else {
|
|---|
| 609 | haloing_enabled = true;
|
|---|
| 610 | }
|
|---|
| 611 |
|
|---|
| 612 | updateQWidget();
|
|---|
| 613 |
|
|---|
| 614 | printf("G4OpenGLQtViewer::toggleRepresentation %d\n",check);
|
|---|
| 615 | }
|
|---|
| 616 |
|
|---|
| 617 | /**
|
|---|
| 618 | SLOT Activate by a click on the auxiliaire edges menu
|
|---|
| 619 | @param check : 1 , 0
|
|---|
| 620 | */
|
|---|
| 621 | void G4OpenGLQtViewer::toggleAux(bool check) {
|
|---|
| 622 | if (check) {
|
|---|
| 623 | fVP.SetAuxEdgeVisible(false);
|
|---|
| 624 | } else {
|
|---|
| 625 | fVP.SetAuxEdgeVisible(true);
|
|---|
| 626 | }
|
|---|
| 627 | SetNeedKernelVisit (true);
|
|---|
| 628 | updateQWidget();
|
|---|
| 629 |
|
|---|
| 630 | printf("G4OpenGLQtViewer::toggleRepresentation %d\n",check);
|
|---|
| 631 | }
|
|---|
| 632 |
|
|---|
| 633 | /**
|
|---|
| 634 | SLOT Activate by a click on the full screen menu
|
|---|
| 635 | @param check : 1 , 0
|
|---|
| 636 | */
|
|---|
| 637 | void G4OpenGLQtViewer::toggleFullScreen(bool check) {
|
|---|
| 638 | GLWindow->setWindowState(GLWindow->windowState() ^ Qt::WindowFullScreen);
|
|---|
| 639 |
|
|---|
| 640 | printf("G4OpenGLQtViewer::toggleRepresentation %d\n",check);
|
|---|
| 641 | }
|
|---|
| 642 |
|
|---|
| 643 | /**
|
|---|
| 644 | SLOT Activate by a click on the mouse action menu
|
|---|
| 645 | @param check : 1 , 0
|
|---|
| 646 | */
|
|---|
| 647 | void G4OpenGLQtViewer::toggleMouseAction(bool check) {
|
|---|
| 648 | if (check) { // rotate scene
|
|---|
| 649 | fMouseAction = true;
|
|---|
| 650 | } else { // move scene
|
|---|
| 651 | fMouseAction = false;
|
|---|
| 652 | }
|
|---|
| 653 |
|
|---|
| 654 | printf("G4OpenGLQtViewer::toggleRepresentation %d\n",check);
|
|---|
| 655 | }
|
|---|
| 656 |
|
|---|
| 657 |
|
|---|
| 658 | void G4OpenGLQtViewer::actionControlPanels() {
|
|---|
| 659 | printf("G4OpenGLQtViewer::actionControlPanels \n");
|
|---|
| 660 | }
|
|---|
| 661 |
|
|---|
| 662 | void G4OpenGLQtViewer::actionExitG4() {
|
|---|
| 663 | printf("G4OpenGLQtViewer::actionExitG4() \n");
|
|---|
| 664 | }
|
|---|
| 665 |
|
|---|
| 666 | void G4OpenGLQtViewer::actionCreateEPS() {
|
|---|
| 667 | QString filters;
|
|---|
| 668 | QList<QByteArray> formats = QImageWriter::supportedImageFormats ();
|
|---|
| 669 | for (int i = 0; i < formats.size(); ++i) {
|
|---|
| 670 | filters +=formats.at(i)+";;";
|
|---|
| 671 | // if ((i+1) <formats.size()) {
|
|---|
| 672 | // filters += ";;";
|
|---|
| 673 | // }
|
|---|
| 674 | }
|
|---|
| 675 | filters += "eps;;";
|
|---|
| 676 | filters += "ps;;";
|
|---|
| 677 | filters += "pdf";
|
|---|
| 678 | QString* selectedFilter = new QString();
|
|---|
| 679 | QString nomFich = QFileDialog::getSaveFileName ( GLWindow,
|
|---|
| 680 | tr("Save as ..."),
|
|---|
| 681 | ".",
|
|---|
| 682 | filters,
|
|---|
| 683 | selectedFilter );
|
|---|
| 684 | // bmp jpg jpeg png ppm xbm xpm
|
|---|
| 685 | if (nomFich == "") {
|
|---|
| 686 | return;
|
|---|
| 687 | }
|
|---|
| 688 | nomFich += "."+selectedFilter->toLower();
|
|---|
| 689 | printf("G4OpenGLQtViewer::name %s\n",nomFich.toStdString().c_str());
|
|---|
| 690 | G4OpenGLQtExportDialog* exportDialog= new G4OpenGLQtExportDialog(GLWindow,nomFich,fWindow->height(),fWindow->width());
|
|---|
| 691 | if( exportDialog->exec()) {
|
|---|
| 692 |
|
|---|
| 693 | QImage image;
|
|---|
| 694 | // if ((exportDialog->getWidth() !=fWindow->width()) ||
|
|---|
| 695 | // (exportDialog->getHeight() !=fWindow->height())) {
|
|---|
| 696 |
|
|---|
| 697 | // rescaleImage(exportDialog->getWidth(),exportDialog->getHeight());// re-scale image
|
|---|
| 698 | printf("rescaling\n");
|
|---|
| 699 | QGLWidget* glResized = fWindow;
|
|---|
| 700 | fWindow->renderPixmap (exportDialog->getWidth()*2,exportDialog->getHeight()*2 ).save("/Users/laurentgarnier/Desktop/zzz.jpg","jpg");
|
|---|
| 701 | QPixmap * pixmap = new QPixmap(fWindow->renderPixmap (exportDialog->getWidth(),exportDialog->getHeight() )) ;
|
|---|
| 702 | // image = pixmap.toImage();
|
|---|
| 703 | // glResized->resize(exportDialog->getWidth()*2,exportDialog->getHeight()*2);
|
|---|
| 704 | printf("rescaling after\n");
|
|---|
| 705 | // image = glResized->grabFrameBuffer();
|
|---|
| 706 |
|
|---|
| 707 | // } else {
|
|---|
| 708 | // image = fWindow->grabFrameBuffer();
|
|---|
| 709 | // }
|
|---|
| 710 | // jpeg format
|
|---|
| 711 | if (nomFich.endsWith(".jpg") ||
|
|---|
| 712 | nomFich.endsWith(".jpeg")) {
|
|---|
| 713 | // grabFrameBuffer() :: Returns an image of the frame buffer. If withAlpha is true the alpha channel is included.
|
|---|
| 714 | image.save(nomFich,0,exportDialog->getSliderValue());
|
|---|
| 715 | printf("saving jpeg quality : %d\n",exportDialog->getSliderValue());
|
|---|
| 716 | } else if (nomFich.endsWith(".eps")) {
|
|---|
| 717 | generateEPS(nomFich,exportDialog->getNbColor(),image);
|
|---|
| 718 | } else if (nomFich.endsWith(".ps") ||nomFich.endsWith(".pdf")) {
|
|---|
| 719 | generatePS_PDF(nomFich,exportDialog->getNbColor(),image);
|
|---|
| 720 | } else if (nomFich.endsWith(".tif") ||
|
|---|
| 721 | nomFich.endsWith(".tiff") ||
|
|---|
| 722 | nomFich.endsWith(".jpg") ||
|
|---|
| 723 | nomFich.endsWith(".png") ||
|
|---|
| 724 | nomFich.endsWith(".bmp") ||
|
|---|
| 725 | nomFich.endsWith(".xpm")) {
|
|---|
| 726 | image.save(nomFich,0,exportDialog->getSliderValue());
|
|---|
| 727 | printf("saving ELSE\n");
|
|---|
| 728 | } else {
|
|---|
| 729 | G4cerr << "This version of G4UI Could not generate the selected format" << G4endl;
|
|---|
| 730 | }
|
|---|
| 731 |
|
|---|
| 732 | } else { // cancel selected
|
|---|
| 733 | return;
|
|---|
| 734 | }
|
|---|
| 735 |
|
|---|
| 736 | printf("G4OpenGLQtViewer::actionCreateEPS() \n");
|
|---|
| 737 | }
|
|---|
| 738 |
|
|---|
| 739 | /*
|
|---|
| 740 | // 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
|
|---|
| 741 |
|
|---|
| 742 | void Graph::exportToSVG(const QString& fname)
|
|---|
| 743 | {
|
|---|
| 744 | // enable workaround for Qt3 misalignments
|
|---|
| 745 | QwtPainter::setSVGMode(true);
|
|---|
| 746 | QPicture picture;
|
|---|
| 747 | QPainter p(&picture);
|
|---|
| 748 | d_plot->print(&p, d_plot->rect());
|
|---|
| 749 | p.end();
|
|---|
| 750 |
|
|---|
| 751 | picture.save(fname, "svg");
|
|---|
| 752 | }
|
|---|
| 753 | */
|
|---|
| 754 |
|
|---|
| 755 |
|
|---|
| 756 |
|
|---|
| 757 |
|
|---|
| 758 | /**
|
|---|
| 759 | Save the current mouse press point
|
|---|
| 760 | @param p mouse click point
|
|---|
| 761 | */
|
|---|
| 762 | void G4OpenGLQtViewer::G4MousePressEvent(QPoint p)
|
|---|
| 763 | {
|
|---|
| 764 | lastPos = p;
|
|---|
| 765 | }
|
|---|
| 766 |
|
|---|
| 767 | /**
|
|---|
| 768 | @param pos_x mouse x position
|
|---|
| 769 | @param pos_y mouse y position
|
|---|
| 770 | @param mButtons mouse button active
|
|---|
| 771 | */
|
|---|
| 772 | void G4OpenGLQtViewer::G4MouseMoveEvent(int pos_x, int pos_y,Qt::MouseButtons mButtons)
|
|---|
| 773 | {
|
|---|
| 774 | int dx = pos_x - lastPos.x();
|
|---|
| 775 | int dy = pos_y - lastPos.y();
|
|---|
| 776 |
|
|---|
| 777 | if (fMouseAction) { // rotate
|
|---|
| 778 | if (mButtons & Qt::LeftButton) {
|
|---|
| 779 | //phi spin stuff here
|
|---|
| 780 |
|
|---|
| 781 | G4Vector3D vp = fVP.GetViewpointDirection ().unit ();
|
|---|
| 782 | G4Vector3D up = fVP.GetUpVector ().unit ();
|
|---|
| 783 |
|
|---|
| 784 | G4Vector3D yprime = (up.cross(vp)).unit();
|
|---|
| 785 | G4Vector3D zprime = (vp.cross(yprime)).unit();
|
|---|
| 786 |
|
|---|
| 787 | G4double delta_alpha;
|
|---|
| 788 | G4double delta_theta;
|
|---|
| 789 |
|
|---|
| 790 | if (fVP.GetLightsMoveWithCamera()) {
|
|---|
| 791 | delta_alpha = dy;
|
|---|
| 792 | delta_theta = -dx;
|
|---|
| 793 | } else {
|
|---|
| 794 | delta_alpha = -dy;
|
|---|
| 795 | delta_theta = dx;
|
|---|
| 796 | }
|
|---|
| 797 |
|
|---|
| 798 | delta_alpha *= deg;
|
|---|
| 799 | delta_theta *= deg;
|
|---|
| 800 |
|
|---|
| 801 | G4Vector3D new_vp = std::cos(delta_alpha) * vp + std::sin(delta_alpha) * zprime;
|
|---|
| 802 |
|
|---|
| 803 | G4Vector3D new_up;
|
|---|
| 804 | if (fVP.GetLightsMoveWithCamera()) {
|
|---|
| 805 | new_up = (new_vp.cross(yprime)).unit();
|
|---|
| 806 | fVP.SetUpVector(new_up);
|
|---|
| 807 | } else {
|
|---|
| 808 | new_up = up;
|
|---|
| 809 | }
|
|---|
| 810 | ////////////////
|
|---|
| 811 | // Rotates by fixed azimuthal angle delta_theta.
|
|---|
| 812 |
|
|---|
| 813 | G4double cosalpha = new_up.dot (new_vp.unit());
|
|---|
| 814 | G4double sinalpha = std::sqrt (1. - std::pow (cosalpha, 2));
|
|---|
| 815 | yprime = (new_up.cross (new_vp.unit())).unit ();
|
|---|
| 816 | G4Vector3D xprime = yprime.cross (new_up);
|
|---|
| 817 | // Projection of vp on plane perpendicular to up...
|
|---|
| 818 | G4Vector3D a1 = sinalpha * xprime;
|
|---|
| 819 | // Required new projection...
|
|---|
| 820 | G4Vector3D a2 =
|
|---|
| 821 | sinalpha * (std::cos (delta_theta) * xprime + std::sin (delta_theta) * yprime);
|
|---|
| 822 | // Required Increment vector...
|
|---|
| 823 | G4Vector3D delta = a2 - a1;
|
|---|
| 824 | // So new viewpoint is...
|
|---|
| 825 | G4Vector3D viewPoint = new_vp.unit() + delta;
|
|---|
| 826 |
|
|---|
| 827 | fVP.SetViewAndLights (viewPoint);
|
|---|
| 828 | updateQWidget();
|
|---|
| 829 |
|
|---|
| 830 | } else if (mButtons & Qt::RightButton) {
|
|---|
| 831 | // NEVER DONE BECAUSE OF MOUSE MENU
|
|---|
| 832 | // printf("G4OpenGLQtViewer::mouseMoveEvent Right \n");
|
|---|
| 833 | // setXRotation(xRot + dy/2);
|
|---|
| 834 | // setZRotation(zRot + dx/2);
|
|---|
| 835 | // updateQWidget();
|
|---|
| 836 | }
|
|---|
| 837 | } else { // move
|
|---|
| 838 |
|
|---|
| 839 | float dx = pos_x - lastPos.x();
|
|---|
| 840 | float dy = pos_y - lastPos.y();
|
|---|
| 841 |
|
|---|
| 842 | G4Point3D stp
|
|---|
| 843 | = GetSceneHandler()->GetScene()->GetStandardTargetPoint();
|
|---|
| 844 |
|
|---|
| 845 | G4Point3D tp = stp + fVP.GetCurrentTargetPoint ();
|
|---|
| 846 |
|
|---|
| 847 | const G4Vector3D& upVector = fVP.GetUpVector ();
|
|---|
| 848 | const G4Vector3D& vpVector = fVP.GetViewpointDirection ();
|
|---|
| 849 |
|
|---|
| 850 | G4Vector3D unitRight = (upVector.cross (vpVector)).unit();
|
|---|
| 851 | G4Vector3D unitUp = (vpVector.cross (unitRight)).unit();
|
|---|
| 852 |
|
|---|
| 853 | tp += -dx * unitRight + dy * unitUp;
|
|---|
| 854 | fVP.SetCurrentTargetPoint (tp - stp);
|
|---|
| 855 |
|
|---|
| 856 | updateQWidget();
|
|---|
| 857 | }
|
|---|
| 858 | lastPos = QPoint(pos_x, pos_y);
|
|---|
| 859 | }
|
|---|
| 860 |
|
|---|
| 861 | void G4OpenGLQtViewer::rescaleImage(
|
|---|
| 862 | int aWidth
|
|---|
| 863 | ,int aHeight
|
|---|
| 864 | ){
|
|---|
| 865 | printf("should rescale \n");
|
|---|
| 866 | }
|
|---|
| 867 |
|
|---|
| 868 | /**
|
|---|
| 869 | Generate Postscript form image
|
|---|
| 870 | @param aFilename : name of file
|
|---|
| 871 | @param aInColor : numbers of colors : 1->BW 2->RGB 3->RGB+Alpha
|
|---|
| 872 | @param aImage : Image to print
|
|---|
| 873 | */
|
|---|
| 874 | bool G4OpenGLQtViewer::generateEPS (
|
|---|
| 875 | QString aFilename
|
|---|
| 876 | ,int aInColor
|
|---|
| 877 | ,QImage aImage
|
|---|
| 878 | )
|
|---|
| 879 | {
|
|---|
| 880 | // FIXME
|
|---|
| 881 | printf("saving EPS\n");
|
|---|
| 882 |
|
|---|
| 883 | FILE* fp;
|
|---|
| 884 |
|
|---|
| 885 | if ((!aImage.isGrayscale ()) &&(aInColor ==1 )) {
|
|---|
| 886 | aImage.convertToFormat ( aImage.format(), Qt::MonoOnly);
|
|---|
| 887 | }
|
|---|
| 888 | const uchar * pixels = aImage.bits ();
|
|---|
| 889 |
|
|---|
| 890 | if (pixels == NULL)
|
|---|
| 891 | return false;
|
|---|
| 892 |
|
|---|
| 893 | fp = fopen (aFilename.toStdString().c_str(), "w");
|
|---|
| 894 | if (fp == NULL) {
|
|---|
| 895 | return false;
|
|---|
| 896 | }
|
|---|
| 897 |
|
|---|
| 898 | fprintf (fp, "%%!PS-Adobe-2.0 EPSF-1.2\n");
|
|---|
| 899 | fprintf (fp, "%%%%Title: %s\n", aFilename.toStdString().c_str());
|
|---|
| 900 | fprintf (fp, "%%%%Creator: OpenGL pixmap render output\n");
|
|---|
| 901 | fprintf (fp, "%%%%BoundingBox: 0 0 %d %d\n", aImage.width(), aImage.height());
|
|---|
| 902 | fprintf (fp, "%%%%EndComments\n");
|
|---|
| 903 | fprintf (fp, "gsave\n");
|
|---|
| 904 | fprintf (fp, "/bwproc {\n");
|
|---|
| 905 | fprintf (fp, " rgbproc\n");
|
|---|
| 906 | fprintf (fp, " dup length 3 idiv string 0 3 0 \n");
|
|---|
| 907 | fprintf (fp, " 5 -1 roll {\n");
|
|---|
| 908 | fprintf (fp, " add 2 1 roll 1 sub dup 0 eq\n");
|
|---|
| 909 | fprintf (fp, " { pop 3 idiv 3 -1 roll dup 4 -1 roll dup\n");
|
|---|
| 910 | fprintf (fp, " 3 1 roll 5 -1 roll } put 1 add 3 0 \n");
|
|---|
| 911 | fprintf (fp, " { 2 1 roll } ifelse\n");
|
|---|
| 912 | fprintf (fp, " }forall\n");
|
|---|
| 913 | fprintf (fp, " pop pop pop\n");
|
|---|
| 914 | fprintf (fp, "} def\n");
|
|---|
| 915 | fprintf (fp, "systemdict /colorimage known not {\n");
|
|---|
| 916 | fprintf (fp, " /colorimage {\n");
|
|---|
| 917 | fprintf (fp, " pop\n");
|
|---|
| 918 | fprintf (fp, " pop\n");
|
|---|
| 919 | fprintf (fp, " /rgbproc exch def\n");
|
|---|
| 920 | fprintf (fp, " { bwproc } image\n");
|
|---|
| 921 | fprintf (fp, " } def\n");
|
|---|
| 922 | fprintf (fp, "} if\n");
|
|---|
| 923 | fprintf (fp, "/picstr %d string def\n", aImage.width() * aInColor);
|
|---|
| 924 | fprintf (fp, "%d %d scale\n", aImage.width(), aImage.height());
|
|---|
| 925 | fprintf (fp, "%d %d %d\n", aImage.width(), aImage.height(), 8);
|
|---|
| 926 | fprintf (fp, "[%d 0 0 %d 0 0]\n", aImage.width(), aImage.height());
|
|---|
| 927 | fprintf (fp, "{currentfile picstr readhexstring pop}\n");
|
|---|
| 928 | fprintf (fp, "false %d\n", aInColor);
|
|---|
| 929 | fprintf (fp, "colorimage\n");
|
|---|
| 930 |
|
|---|
| 931 |
|
|---|
| 932 | int width = aImage.width();
|
|---|
| 933 | int height = aImage.height();
|
|---|
| 934 | int depth = aImage.depth();
|
|---|
| 935 | int size = width*height;
|
|---|
| 936 |
|
|---|
| 937 | if (depth == 1)
|
|---|
| 938 | size = (width+7)/8*height;
|
|---|
| 939 | else if (aInColor == 1)
|
|---|
| 940 | size = size*3;
|
|---|
| 941 |
|
|---|
| 942 | int i = 0;
|
|---|
| 943 | if (depth == 1) {
|
|---|
| 944 | // To be implemented
|
|---|
| 945 | // QImage::Endian bitOrder = aImage.bitOrder();
|
|---|
| 946 | /* for(int y=0; y < height; y++) {
|
|---|
| 947 | const uchar * s = aImage.scanLine(y);
|
|---|
| 948 | for(int x=0; x < width; x++) {
|
|---|
| 949 | // need to copy bit for bit...
|
|---|
| 950 | bool b = (bitOrder == QImage::LittleEndian) ?
|
|---|
| 951 | (*(s + (x >> 3)) >> (x & 7)) & 1 :
|
|---|
| 952 | (*(s + (x >> 3)) << (x & 7)) & 0x80 ;
|
|---|
| 953 | if (b)
|
|---|
| 954 | pixel[i >> 3] ^= (0x80 >> (i & 7));
|
|---|
| 955 | i++;
|
|---|
| 956 | }
|
|---|
| 957 | // we need to align to 8 bit here
|
|---|
| 958 | i = (i+7) & 0xffffff8;
|
|---|
| 959 | }
|
|---|
| 960 | */
|
|---|
| 961 | } else if (depth == 8) {
|
|---|
| 962 | printf("has 8 bit\n");
|
|---|
| 963 | for(int y=height-1; y >=0 ; y--) {
|
|---|
| 964 | const uchar * s = aImage.scanLine(y);
|
|---|
| 965 | for(int x=0; x <width; x++) {
|
|---|
| 966 | QRgb rgb = aImage.color(s[x]);
|
|---|
| 967 | if (aInColor == 1) {
|
|---|
| 968 | fprintf (fp, " %02hx ",(unsigned char)qGray(rgb));
|
|---|
| 969 | i++;
|
|---|
| 970 | } else {
|
|---|
| 971 | fprintf (fp, " %02hx %02hx %02hx",
|
|---|
| 972 | (unsigned char) qRed(rgb),
|
|---|
| 973 | (unsigned char) qGreen(rgb),
|
|---|
| 974 | (unsigned char) qBlue(rgb));
|
|---|
| 975 | i += 3;
|
|---|
| 976 | }
|
|---|
| 977 | }
|
|---|
| 978 | fprintf (fp, "\n");
|
|---|
| 979 | }
|
|---|
| 980 | } else {
|
|---|
| 981 | bool alpha = aImage.hasAlphaChannel();
|
|---|
| 982 | printf("has else %d alpha %d\n",depth,alpha);
|
|---|
| 983 | for(int y=height-1; y >=0 ; y--) {
|
|---|
| 984 | QRgb * s = (QRgb*)(aImage.scanLine(y));
|
|---|
| 985 | for(int x=0; x <width; x++) {
|
|---|
| 986 | QRgb rgb = (*s++);
|
|---|
| 987 | if (alpha && qAlpha(rgb) < 0x40) // 25% alpha, convert to white -
|
|---|
| 988 | rgb = qRgb(0xff, 0xff, 0xff);
|
|---|
| 989 | if (aInColor == 1) {
|
|---|
| 990 | fprintf (fp, " %02hx ",(unsigned char)qGray(rgb));
|
|---|
| 991 | i++;
|
|---|
| 992 | } else {
|
|---|
| 993 | fprintf (fp, " %02hx %02hx %02hx",
|
|---|
| 994 | (unsigned char) qRed(rgb),
|
|---|
| 995 | (unsigned char) qGreen(rgb),
|
|---|
| 996 | (unsigned char) qBlue(rgb));
|
|---|
| 997 | i += 3;
|
|---|
| 998 | }
|
|---|
| 999 | }
|
|---|
| 1000 | fprintf (fp, "\n");
|
|---|
| 1001 | }
|
|---|
| 1002 | }
|
|---|
| 1003 |
|
|---|
| 1004 | fprintf (fp, "grestore\n");
|
|---|
| 1005 | fprintf (fp, "showpage\n");
|
|---|
| 1006 | fclose (fp);
|
|---|
| 1007 |
|
|---|
| 1008 | return true;
|
|---|
| 1009 | }
|
|---|
| 1010 | /**
|
|---|
| 1011 | Generate Postscript or PDF form image
|
|---|
| 1012 | @param aFilename : name of file
|
|---|
| 1013 | @param aInColor : numbers of colors : 1->BW 2->RGB
|
|---|
| 1014 | @param aImage : Image to print
|
|---|
| 1015 | */
|
|---|
| 1016 | bool G4OpenGLQtViewer::generatePS_PDF (
|
|---|
| 1017 | QString aFilename
|
|---|
| 1018 | ,int aInColor
|
|---|
| 1019 | ,QImage aImage
|
|---|
| 1020 | )
|
|---|
| 1021 | {
|
|---|
| 1022 | QPrinter printer;
|
|---|
| 1023 | // printer.setPageSize(pageSize);
|
|---|
| 1024 | if (aInColor == 1) {
|
|---|
| 1025 | printer.setColorMode(QPrinter::GrayScale);
|
|---|
| 1026 | } else {
|
|---|
| 1027 | printer.setColorMode(QPrinter::Color);
|
|---|
| 1028 | }
|
|---|
| 1029 |
|
|---|
| 1030 | if (aFilename.endsWith(".ps")) {
|
|---|
| 1031 | printer.setOutputFormat(QPrinter::PostScriptFormat);
|
|---|
| 1032 | } else {
|
|---|
| 1033 | printer.setOutputFormat(QPrinter::PdfFormat);
|
|---|
| 1034 | }
|
|---|
| 1035 | printer.setOutputFileName(aFilename);
|
|---|
| 1036 | // printer.setFullPage ( true);
|
|---|
| 1037 | QPainter paint(&printer);
|
|---|
| 1038 | paint.drawImage (0,0,aImage );
|
|---|
| 1039 | paint.end();
|
|---|
| 1040 | return true;
|
|---|
| 1041 | }
|
|---|
| 1042 |
|
|---|
| 1043 | #endif
|
|---|
| 1044 |
|
|---|
| 1045 | /*
|
|---|
| 1046 |
|
|---|
| 1047 | void MultiLayer::exportToSVG(const QString& fname)
|
|---|
| 1048 | {
|
|---|
| 1049 | QPicture picture;
|
|---|
| 1050 | QPainter p(&picture);
|
|---|
| 1051 | for (int i=0;i<(int)graphsList->count();i++)
|
|---|
| 1052 | {
|
|---|
| 1053 | Graph *gr=(Graph *)graphsList->at(i);
|
|---|
| 1054 | Plot *myPlot= (Plot *)gr->plotWidget();
|
|---|
| 1055 |
|
|---|
| 1056 | QPoint pos=gr->pos();
|
|---|
| 1057 |
|
|---|
| 1058 | int width=int(myPlot->frameGeometry().width());
|
|---|
| 1059 | int height=int(myPlot->frameGeometry().height());
|
|---|
| 1060 |
|
|---|
| 1061 | myPlot->print(&p, QRect(pos,QSize(width,height)));
|
|---|
| 1062 | }
|
|---|
| 1063 |
|
|---|
| 1064 | p.end();
|
|---|
| 1065 | picture.save(fname, "svg");
|
|---|
| 1066 | }
|
|---|
| 1067 | */
|
|---|