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