00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifdef G4VIS_BUILD_OPENGLQT_DRIVER
00034
00035 #include "G4OpenGLStoredQtViewer.hh"
00036
00037 #include "G4OpenGLStoredSceneHandler.hh"
00038 #include "G4ios.hh"
00039
00040 #include <qapplication.h>
00041
00042 G4OpenGLStoredQtViewer::G4OpenGLStoredQtViewer
00043 (G4OpenGLStoredSceneHandler& sceneHandler,
00044 const G4String& name):
00045 G4VViewer (sceneHandler, sceneHandler.IncrementViewCount (), name),
00046 G4OpenGLViewer (sceneHandler),
00047 G4OpenGLQtViewer (sceneHandler),
00048 G4OpenGLStoredViewer (sceneHandler),
00049 QGLWidget()
00050 {
00051
00052 setFocusPolicy(Qt::StrongFocus);
00053 fHasToRepaint = false;
00054 fIsRepainting = false;
00055
00056 resize(fVP.GetWindowSizeHintX(),fVP.GetWindowSizeHintY());
00057
00058 if (fViewId < 0) return;
00059 }
00060
00061 G4OpenGLStoredQtViewer::~G4OpenGLStoredQtViewer() {
00062 makeCurrent();
00063
00064
00065
00066 }
00067
00068 void G4OpenGLStoredQtViewer::Initialise() {
00069 #ifdef G4DEBUG_VIS_OGL
00070 printf("G4OpenGLStoredQtViewer::Initialise 1\n");
00071 #endif
00072 fReadyToPaint = false;
00073 CreateMainWindow (this,QString(GetName()));
00074
00075 glDrawBuffer (GL_BACK);
00076
00077 fReadyToPaint = true;
00078 }
00079
00080 void G4OpenGLStoredQtViewer::initializeGL () {
00081
00082 InitializeGLView ();
00083
00084 #ifdef G4DEBUG_VIS_OGL
00085 printf("G4OpenGLStoredQtViewer::InitialiseGL () 1 %d\n", this);
00086 #endif
00087
00088 if (fSceneHandler.GetScene() == 0) {
00089 fHasToRepaint =false;
00090 } else {
00091 fHasToRepaint =true;
00092 }
00093
00094
00095 setVisible(true) ;
00096
00097
00098 QCoreApplication::sendPostedEvents () ;
00099
00100 #ifdef G4DEBUG_VIS_OGL
00101 printf("G4OpenGLStoredQtViewer::InitialiseGL END\n");
00102 #endif
00103 }
00104
00105 G4bool G4OpenGLStoredQtViewer::CompareForKernelVisit(G4ViewParameters& lastVP)
00106 {
00107
00108
00109
00110
00111 if (
00112 (lastVP.GetDrawingStyle () != fVP.GetDrawingStyle ()) ||
00113 (lastVP.IsAuxEdgeVisible () != fVP.IsAuxEdgeVisible ()) ||
00114 (lastVP.GetRepStyle () != fVP.GetRepStyle ()) ||
00115 (lastVP.IsCulling () != fVP.IsCulling ()) ||
00116 (lastVP.IsCullingInvisible () != fVP.IsCullingInvisible ()) ||
00117 (lastVP.IsDensityCulling () != fVP.IsDensityCulling ()) ||
00118 (lastVP.IsCullingCovered () != fVP.IsCullingCovered ()) ||
00119 (lastVP.IsSection () != fVP.IsSection ()) ||
00120
00121
00122
00123 (lastVP.IsCutaway () != fVP.IsCutaway ()) ||
00124
00125
00126 (lastVP.IsExplode () != fVP.IsExplode ()) ||
00127 (lastVP.GetNoOfSides () != fVP.GetNoOfSides ()) ||
00128 (lastVP.GetDefaultVisAttributes()->GetColour() !=
00129 fVP.GetDefaultVisAttributes()->GetColour()) ||
00130 (lastVP.GetDefaultTextVisAttributes()->GetColour() !=
00131 fVP.GetDefaultTextVisAttributes()->GetColour()) ||
00132 (lastVP.GetBackgroundColour ()!= fVP.GetBackgroundColour ())||
00133 (lastVP.IsPicking () != fVP.IsPicking ())
00134
00135
00136
00137 )
00138 return true;
00139
00140 if (lastVP.IsDensityCulling () &&
00141 (lastVP.GetVisibleDensity () != fVP.GetVisibleDensity ()))
00142 return true;
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164 if (lastVP.IsExplode () &&
00165 (lastVP.GetExplodeFactor () != fVP.GetExplodeFactor ()))
00166 return true;
00167
00168 return false;
00169 }
00170
00171 G4bool G4OpenGLStoredQtViewer::POSelected(size_t POListIndex)
00172 {
00173 return isTouchableVisible(POListIndex);
00174 }
00175
00176 G4bool G4OpenGLStoredQtViewer::TOSelected(size_t)
00177 {
00178 return true;
00179 }
00180
00181 void G4OpenGLStoredQtViewer::DrawView () {
00182 updateQWidget();
00183 }
00184
00185 void G4OpenGLStoredQtViewer::ComputeView () {
00186
00187 #ifdef G4DEBUG_VIS_OGL
00188 printf("G4OpenGLStoredQtViewer::ComputeView %d %d VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n",getWinWidth(), getWinHeight());
00189 #endif
00190 makeCurrent();
00191 G4ViewParameters::DrawingStyle dstyle = GetViewParameters().GetDrawingStyle();
00192
00193
00194
00195
00196
00197
00198
00199 if (!fNeedKernelVisit) {
00200 KernelVisitDecision ();
00201 }
00202 G4bool kernelVisitWasNeeded = fNeedKernelVisit;
00203 ProcessView ();
00204
00205
00206 if(dstyle!=G4ViewParameters::hlr &&
00207 haloing_enabled) {
00208 #ifdef G4DEBUG_VIS_OGL
00209 printf("G4OpenGLStoredQtViewer::ComputeView DANS LE IF\n");
00210 #endif
00211
00212 HaloingFirstPass ();
00213 DrawDisplayLists ();
00214 glFlush ();
00215
00216 HaloingSecondPass ();
00217
00218 DrawDisplayLists ();
00219 FinishView ();
00220
00221 } else {
00222
00223
00224
00225 if (!kernelVisitWasNeeded) {
00226 #ifdef G4DEBUG_VIS_OGL
00227 printf("************************** G4OpenGLStoredQtViewer::ComputeView Don't need kernel Visit \n");
00228 #endif
00229 DrawDisplayLists ();
00230 FinishView ();
00231 } else {
00232 #ifdef G4DEBUG_VIS_OGL
00233 printf("************************** G4OpenGLStoredQtViewer::ComputeView need kernel Visit \n");
00234 #endif
00235
00236
00237 if (fVP.IsCutaway() &&
00238 fVP.GetCutawayMode() == G4ViewParameters::cutawayUnion) {
00239 ClearView();
00240 DrawDisplayLists ();
00241 FinishView ();
00242 #ifdef G4DEBUG_VIS_OGL
00243 printf("*************************** CASE 4 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
00244 #endif
00245 } else {
00246 DrawDisplayLists ();
00247 FinishView ();
00248 }
00249 }
00250 }
00251
00252 if (isRecording()) {
00253 savePPMToTemp();
00254 }
00255
00256 #ifdef G4DEBUG_VIS_OGL
00257 printf("G4OpenGLStoredQtViewer::ComputeView %d %d ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n",getWinWidth(), getWinHeight());
00258 #endif
00259 fHasToRepaint = true;
00260 }
00261
00262
00266 void G4OpenGLStoredQtViewer::resizeGL(
00267 int aWidth
00268 ,int aHeight)
00269 {
00270
00271 if ((aWidth > 0) && (aHeight > 0)) {
00272 ResizeWindow(aWidth,aHeight);
00273 fHasToRepaint = sizeHasChanged();
00274 }
00275 }
00276
00277
00278
00279
00280
00281
00282
00283 void G4OpenGLStoredQtViewer::paintGL()
00284 {
00285 updateToolbarAndMouseContextMenu();
00286
00287 #ifdef G4DEBUG_VIS_OGL
00288 printf("G4OpenGLStoredQtViewer::paintGL \n");
00289 #endif
00290 if (fIsRepainting) {
00291
00292 }
00293 fIsRepainting = true;
00294 #ifdef G4DEBUG_VIS_OGL
00295 printf("G4OpenGLStoredQtViewer::paintGL ready:%d fHasTo:%d??\n",fReadyToPaint,fHasToRepaint);
00296 #endif
00297 if (!fReadyToPaint) {
00298 fReadyToPaint= true;
00299 return;
00300 }
00301
00302
00303
00304 if ( !fHasToRepaint) {
00305
00306
00307 int sw = 0;
00308 int sh = 0;
00309 if (!isMaximized() && !isFullScreen()) {
00310 sw = normalGeometry().width();
00311 sh = normalGeometry().height();
00312 } else {
00313 sw = frameGeometry().width();
00314 sh = frameGeometry().height();
00315 }
00316 if ((getWinWidth() == (unsigned int)sw) &&(getWinHeight() == (unsigned int)sh)) {
00317 return;
00318 }
00319 }
00320 #ifdef G4DEBUG_VIS_OGL
00321 printf("G4OpenGLStoredQtViewer::paintGL VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV ready %d\n",fReadyToPaint);
00322 #endif
00323
00324 SetView();
00325
00326 ClearView ();
00327 ComputeView();
00328
00329 fHasToRepaint = false;
00330
00331
00332 displaySceneTreeComponent();
00333 #ifdef G4DEBUG_VIS_OGL
00334 printf("G4OpenGLStoredQtViewer::paintGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ready %d\n",fReadyToPaint);
00335 #endif
00336 fIsRepainting = false;
00337 }
00338
00339 void G4OpenGLStoredQtViewer::paintEvent(QPaintEvent *) {
00340 if ( fHasToRepaint) {
00341 updateGL();
00342 }
00343 }
00344
00345 void G4OpenGLStoredQtViewer::mousePressEvent(QMouseEvent *event)
00346 {
00347 G4MousePressEvent(event);
00348 }
00349
00350 void G4OpenGLStoredQtViewer::keyPressEvent (QKeyEvent * event)
00351 {
00352 G4keyPressEvent(event);
00353 }
00354
00355 void G4OpenGLStoredQtViewer::wheelEvent (QWheelEvent * event)
00356 {
00357 G4wheelEvent(event);
00358 }
00359
00360 void G4OpenGLStoredQtViewer::showEvent (QShowEvent *)
00361 {
00362 fHasToRepaint = true;
00363 }
00364
00369 void G4OpenGLStoredQtViewer::mouseDoubleClickEvent(QMouseEvent *)
00370 {
00371 G4MouseDoubleClickEvent();
00372 }
00373
00374 void G4OpenGLStoredQtViewer::mouseReleaseEvent(QMouseEvent *)
00375 {
00376 G4MouseReleaseEvent();
00377 }
00378
00379 void G4OpenGLStoredQtViewer::mouseMoveEvent(QMouseEvent *event)
00380 {
00381 G4MouseMoveEvent(event);
00382 }
00383
00384
00385 void G4OpenGLStoredQtViewer::contextMenuEvent(QContextMenuEvent *e)
00386 {
00387 G4manageContextMenuEvent(e);
00388 }
00389
00390 void G4OpenGLStoredQtViewer::updateQWidget() {
00391 fHasToRepaint= true;
00392 updateGL();
00393 fHasToRepaint= false;
00394 }
00395
00396 void G4OpenGLStoredQtViewer::ShowView (
00397 )
00398
00399
00400 {
00401
00402
00403
00404 ClearView();
00405 DrawView();
00406 activateWindow();
00407 glFlush();
00408
00409 }
00410
00411
00412 void G4OpenGLStoredQtViewer::DisplayTimePOColourModification (
00413 G4Colour& c,
00414 size_t poIndex) {
00415 c = getColorForPoIndex(poIndex);
00416 }
00417
00418 #endif