Changeset 673 for trunk


Ignore:
Timestamp:
Jan 9, 2008, 12:07:04 PM (16 years ago)
Author:
garnier
Message:

debut de correction du ticket #105

Location:
trunk/geant4/visualization/OpenGL
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/geant4/visualization/OpenGL/include/G4OpenGLQtViewer.hh

    r656 r673  
    6868  void ShowView ();
    6969  virtual void updateQWidget()=0;
     70  void setupViewport(int, int);
    7071
    7172protected:
     
    7475  void manageContextMenuEvent(QContextMenuEvent *e);
    7576  void G4MousePressEvent(QPoint);
     77  void G4MouseReleaseEvent(QPoint p);
     78  void G4MouseDoubleClickEvent(QPoint p);
    7679#if QT_VERSION < 0x040000
    7780  void G4MouseMoveEvent(int, int, Qt::ButtonState);
     
    119122  void actionDrawingSurfaceRemoval();
    120123  void actionDrawingLineSurfaceRemoval();
    121   void actionControlPanels();
    122   void actionExitG4();
     124//   void actionControlPanels();
     125//   void actionExitG4();
    123126  void actionCreateEPS();
    124127
  • trunk/geant4/visualization/OpenGL/include/G4OpenGLStoredQtViewer.hh

    r600 r673  
    6666  void mousePressEvent(QMouseEvent *event);
    6767  void mouseMoveEvent(QMouseEvent *event);
     68  void mouseDoubleClickEvent(QMouseEvent *event);
     69  void mouseReleaseEvent(QMouseEvent *event);
    6870  void contextMenuEvent(QContextMenuEvent *e);
    6971
     
    7173  bool hasToRepaint;
    7274  bool readyToPaint;
     75  bool zoomAction;
    7376  int nbPaint;
     77  QPoint beginZoom;
     78  QPoint endZoom;
     79  QImage glBufferImage;
    7480};
    7581
  • trunk/geant4/visualization/OpenGL/src/G4OpenGLImmediateQtViewer.cc

    r608 r673  
    139139   //Make sure current viewer is attached and clean...
    140140   //Qt version needed
    141    glViewport (0, 0, WinSize_x, WinSize_y);
     141   //   glViewport (0, 0, WinSize_x, WinSize_y);
    142142
    143143   if(style!=G4ViewParameters::hlr &&
     
    191191,int height)
    192192
    193   int side = width;
    194   if (width > height) {
    195     side = height;
    196   }
    197   glViewport((width - side) / 2, (height - side) / 2, side, side);
    198   glMatrixMode(GL_PROJECTION);
    199   glLoadIdentity();
    200   glOrtho(-0.5, +0.5, +0.5, -0.5, 4.0, 15.0);
    201   glMatrixMode(GL_MODELVIEW);
     193  setupViewport(width,height);
    202194#ifdef GEANT4_QT_DEBUG
    203195  printf("G4OpenGLImmediateQtViewer::resizeGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
     
    223215   WinSize_y = (G4int) height();
    224216
    225    glViewport (0, 0, width(), height());
     217   setupViewport(width(),height());
    226218
    227219   SetView();
  • trunk/geant4/visualization/OpenGL/src/G4OpenGLQtViewer.cc

    r660 r673  
    9797}
    9898
     99/**
     100 * Set the viewport of the scene
     101 */
     102void G4OpenGLQtViewer::setupViewport(int aWidth, int aHeight)
     103{
     104  int side = qMin(aWidth, aHeight);
     105  glViewport((aWidth - side) / 2, (aHeight - side) / 2, side, side);
     106 
     107  glMatrixMode(GL_PROJECTION);
     108  glLoadIdentity();
     109  glOrtho(-0.5, +0.5, +0.5, -0.5, 4.0, 15.0);
     110  glMatrixMode(GL_MODELVIEW);
     111}
    99112
    100113
     
    514527
    515528#if QT_VERSION < 0x030200
    516   QAction *controlPanels = new QAction("&Control panels","&Control panels",CTRL+Key_C,mActions);
    517   QAction *exitG4 =  new QAction("&Exit to G4Vis >","&Exit to G4Vis >",CTRL+Key_E,mActions);
     529//   QAction *controlPanels = new QAction("&Control panels","&Control panels",CTRL+Key_C,mActions);
     530//   QAction *exitG4 =  new QAction("&Exit to G4Vis >","&Exit to G4Vis >",CTRL+Key_E,mActions);
    518531  QAction *createEPS =  new QAction("&Save as ...","&Save as ...",CTRL+Key_S,mActions);
    519532#else
    520   QAction *controlPanels = new QAction("&Control panels",CTRL+Key_C,mActions);
    521   QAction *exitG4 =  new QAction("&Exit to G4Vis >",CTRL+Key_E,mActions);
     533//   QAction *controlPanels = new QAction("&Control panels",CTRL+Key_C,mActions);
     534//   QAction *exitG4 =  new QAction("&Exit to G4Vis >",CTRL+Key_E,mActions);
    522535  QAction *createEPS =  new QAction("&Save as ...",CTRL+Key_S,mActions);
    523536#endif
    524   controlPanels->addTo(mActions);
    525   exitG4->addTo(mActions);
     537//   controlPanels->addTo(mActions);
     538//   exitG4->addTo(mActions);
    526539  createEPS->addTo(mActions);
    527   QObject ::connect(controlPanels,
    528                     SIGNAL(activated()),
    529                     this,
    530                     SLOT(actionControlPanels()));
    531   QObject ::connect(exitG4,
    532                     SIGNAL(activated()),
    533                     this,
    534                     SLOT(actionExitG4()));
     540//   QObject ::connect(controlPanels,
     541//                     SIGNAL(activated()),
     542//                     this,
     543//                     SLOT(actionControlPanels()));
     544//   QObject ::connect(exitG4,
     545//                     SIGNAL(activated()),
     546//                     this,
     547//                     SLOT(actionExitG4()));
    535548  QObject ::connect(createEPS,
    536549                    SIGNAL(activated()),
     
    541554  // === Action Menu ===
    542555  QMenu *mActions = fContextMenu->addMenu("&Actions");
    543   QAction *controlPanels = mActions->addAction("Control panels");
    544   QAction *exitG4 = mActions->addAction("Exit to G4Vis >");
     556//   QAction *controlPanels = mActions->addAction("Control panels");
     557//   QAction *exitG4 = mActions->addAction("Exit to G4Vis >");
    545558  QAction *createEPS = mActions->addAction("Save as ...");
    546   QObject ::connect(controlPanels,
    547                     SIGNAL(triggered()),
    548                     this,
    549                     SLOT(actionControlPanels()));
    550   QObject ::connect(exitG4,
    551                     SIGNAL(triggered()),
    552                     this,
    553                     SLOT(actionExitG4()));
     559//   QObject ::connect(controlPanels,
     560//                     SIGNAL(triggered()),
     561//                     this,
     562//                     SLOT(actionControlPanels()));
     563//   QObject ::connect(exitG4,
     564//                     SIGNAL(triggered()),
     565//                     this,
     566//                     SLOT(actionExitG4()));
    554567  QObject ::connect(createEPS,
    555568                    SIGNAL(triggered()),
     
    10311044
    10321045
    1033 void G4OpenGLQtViewer::actionControlPanels() {
    1034 #ifdef GEANT4_QT_DEBUG
    1035   printf("G4OpenGLQtViewer::actionControlPanels \n");
    1036 #endif
    1037 }
    1038 
    1039 void G4OpenGLQtViewer::actionExitG4() {
    1040 #ifdef GEANT4_QT_DEBUG
    1041   printf("G4OpenGLQtViewer::actionExitG4() \n");
    1042 #endif
    1043 }
     1046// void G4OpenGLQtViewer::actionControlPanels() {
     1047// #ifdef GEANT4_QT_DEBUG
     1048//   printf("G4OpenGLQtViewer::actionControlPanels \n");
     1049// #endif
     1050// }
     1051
     1052// void G4OpenGLQtViewer::actionExitG4() {
     1053// #ifdef GEANT4_QT_DEBUG
     1054//   printf("G4OpenGLQtViewer::actionExitG4() \n");
     1055// #endif
     1056// }
    10441057
    10451058void G4OpenGLQtViewer::actionCreateEPS() {
     
    11941207}
    11951208
     1209
    11961210/**
    11971211   @param pos_x mouse x position
     
    12031217void G4OpenGLQtViewer::G4MouseMoveEvent(int pos_x, int pos_y,Qt::ButtonState mButtons)
    12041218#else
    1205 void G4OpenGLQtViewer::G4MouseMoveEvent(int pos_x, int pos_y,Qt::MouseButtons mButtons)
     1219  void G4OpenGLQtViewer::G4MouseMoveEvent(int pos_x, int pos_y,Qt::MouseButtons mButtons)
    12061220#endif
    12071221{
    12081222  int dx = pos_x - lastPos.x();
    12091223  int dy = pos_y - lastPos.y();
    1210  
    12111224  if (fMouseAction) {  // rotate
    12121225    if (mButtons & Qt::LeftButton) {
     
    12921305}
    12931306
    1294 
    12951307/** This is the benning of a rescale function. It does nothing for the moment
    12961308    @param aWidth : new width
     
    13081320  FILE* file;
    13091321 
    1310   feedback_buffer = new GLfloat[size];
    1311   glFeedbackBuffer (size, GL_3D_COLOR, feedback_buffer);
    1312   glRenderMode (GL_FEEDBACK);
    1313  
    1314   glViewport (0, 0, aWidth, aHeight);
    1315   DrawView();
    1316   returned = glRenderMode (GL_RENDER);
     1322//   feedback_buffer = new GLfloat[size];
     1323//   glFeedbackBuffer (size, GL_3D_COLOR, feedback_buffer);
     1324//   glRenderMode (GL_FEEDBACK);
     1325 
     1326//   glViewport (0, 0, aWidth, aHeight);
     1327//   DrawView();
     1328//   returned = glRenderMode (GL_RENDER);
    13171329
    13181330}
     
    13581370  } else {
    13591371#if QT_VERSION < 0x040000
    1360     G4cerr << "Could not open "<< file.ascii()<<"\n" << G4endl;
    1361 #else
    1362     G4cerr << "Could not open "<< file.toStdString().c_str()<<"\n" << G4endl;
     1372    G4cerr << "Could not open "<< aFilename.ascii()<<"\n" << G4endl;
     1373#else
     1374    G4cerr << "Could not open "<< aFilename.toStdString().c_str()<<"\n" << G4endl;
    13631375#endif
    13641376  }
  • trunk/geant4/visualization/OpenGL/src/G4OpenGLStoredQtViewer.cc

    r652 r673  
    4343//#include <qmouseevent.h>
    4444#include <qevent.h> // include <qcontextmenuevent.h>
     45#include <qpainter.h>
    4546
    4647G4OpenGLStoredQtViewer::G4OpenGLStoredQtViewer
     
    5354 QGLWidget()                      // FIXME : gerer le pb du parent !
    5455 {
     56   zoomAction = false;
    5557   nbPaint =0;
    5658   hasToRepaint =false;
     
    230232,int aHeight)
    231233
    232   glViewport(0, 0, aWidth, aHeight);
    233   glMatrixMode(GL_PROJECTION);
    234   glMatrixMode(GL_MODELVIEW);
     234  setupViewport(aWidth,aHeight);
     235
     236//   glViewport(0, 0, aWidth, aHeight);
     237//   glMatrixMode(GL_PROJECTION);
     238//   glMatrixMode(GL_MODELVIEW);
    235239
    236240   if (((WinSize_x != (G4int)aWidth)) || (WinSize_y != (G4int) aHeight)) {
     
    246250
    247251
     252/**
     253@see :
     254*/
    248255
    249256void G4OpenGLStoredQtViewer::paintGL()
    250257 {
    251    if (!readyToPaint) {
    252 #ifdef GEANT4_QT_DEBUG
    253      printf("G4OpenGLStoredQtViewer::paintGL ============  Not ready %d\n",readyToPaint);
    254 #endif
    255      readyToPaint= true;
    256      return;
    257    }
    258    // DO NOT RESIZE IF SIZE HAS NOT CHANGE :
    259    //    WHEN CLICK ON THE FRAME FOR EXAMPLE
    260    //    EXECEPT WHEN MOUSE MOVE EVENT
    261    if ( !hasToRepaint) {
    262      if (((WinSize_x == (G4int)width())) &&(WinSize_y == (G4int) height())) {
    263 #ifdef GEANT4_QT_DEBUG
    264        printf("G4OpenGLStoredQtViewer::paintGL ============  Dont repaint\n");
    265 #endif
     258   if (zoomAction) {
     259     QPainter painter;
     260     painter.begin(this);
     261     //     painter.setRenderHint(QPainter::Antialiasing);
     262     QColor bg = QColor(glBufferImage.pixel(0,0));
     263     printf("%d+%d+%d+%d %d+%d+%d+%d",bg.red(),bg.green(),bg.blue(),bg.alpha(),qAlpha(glBufferImage.pixel(0,0)),qRed(glBufferImage.pixel(0,0)),qGreen(glBufferImage.pixel(0,0)),qBlue(glBufferImage.pixel(0,0)));
     264     painter.setBackground(QBrush(bg));
     265     //     painter.drawRect(10,10,50,80);
     266//      QImage test = grabFrameBuffer().copy();
     267//      painter.drawImage(0, 0,test);
     268     for (int ay=0;ay<glBufferImage.height();ay++) {
     269       for (int ax=0;ax<glBufferImage.width();ax++) {
     270         if(QColor(glBufferImage.pixel(ax,ay)) != bg) {
     271//            painter.setPen(QColor(glBufferImage.pixel(ax,ay)));
     272//            painter.drawPoint(ax,glBufferImage.height()-ay);
     273         } else {
     274           printf("o");
     275         }
     276         //          printf("%d+%d+%d+%d ",QColor(glBufferImage.pixel(ax,ay)).red(),QColor(glBufferImage.pixel(ax,ay)).green(),QColor(glBufferImage.pixel(ax,ay)).blue(),QColor(glBufferImage.pixel(ax,ay)).alpha());
     277//          if (glBufferImage.pixel(ax,ay) == 255) {
     278//            test.setPixel(ax,ay,1);
     279//          } else {
     280//            test.setPixel(ax,ay,0);
     281//          }
     282       }
     283       //       printf("\n");
     284     }
     285//      for (int ay=0;ay<test.height();ay++) {
     286//        for (int ax=0;ax<test.width();ax++) {
     287//          if (test.pixel(ax,ay) == 1) {
     288//            printf(".");
     289//          } else if (!test.pixel(ax,ay)) {
     290//            printf("X");
     291//          } else {
     292//            printf("%d",test.pixel(ax,ay));
     293//          }
     294//        }
     295//        printf("\n");
     296//      }
     297     
     298     //     painter.drawImage(0, 0, glBufferImage);
     299     //     painter.drawImage(0, 0, test,0,0,-1,-1,Qt::ColorOnly);
     300     
     301     printf("paint event zoom \n");
     302     //     painter.drawRect(beginZoom.x(),beginZoom.y(),endZoom.x()-beginZoom.x(),endZoom.y()-beginZoom.y());
     303     painter.end();
     304   } else {
     305     
     306     if (!readyToPaint) {
     307#ifdef GEANT4_QT_DEBUG
     308       printf("G4OpenGLStoredQtViewer::paintGL ============  Not ready %d\n",readyToPaint);
     309#endif
     310       readyToPaint= true;
    266311       return;
    267312     }
     313     // DO NOT RESIZE IF SIZE HAS NOT CHANGE :
     314     //    WHEN CLICK ON THE FRAME FOR EXAMPLE
     315     //    EXECEPT WHEN MOUSE MOVE EVENT
     316     if ( !hasToRepaint) {
     317       if (((WinSize_x == (G4int)width())) &&(WinSize_y == (G4int) height())) {
     318#ifdef GEANT4_QT_DEBUG
     319         printf("G4OpenGLStoredQtViewer::paintGL ============  Dont repaint\n");
     320#endif
     321         return;
     322       }
     323     }
     324     nbPaint++;
     325#ifdef GEANT4_QT_DEBUG
     326     printf("G4OpenGLStoredQtViewer::paintGL VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV %d ready %d\n",nbPaint,readyToPaint);
     327#endif
     328     WinSize_x = (G4int) width();
     329     WinSize_y = (G4int) height();
     330     
     331     setupViewport(width(),height());
     332     //     glViewport (0, 0, width(), height());
     333     //   glLoadIdentity();
     334     
     335     
     336     SetView();
     337     
     338     //   //  printf("before ClearView\n");
     339#ifdef GEANT4_QT_DEBUG
     340     printf("    ClearView\n");
     341#endif
     342     
     343     ClearView (); //ok, put the background correct
     344     DrawView();
     345     
     346     hasToRepaint =false;
     347     
     348#ifdef GEANT4_QT_DEBUG
     349     printf("G4OpenGLStoredQtViewer::paintGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ %d ready %d\n",nbPaint,readyToPaint);
     350#endif
    268351   }
    269    nbPaint++;
    270 #ifdef GEANT4_QT_DEBUG
    271    printf("G4OpenGLStoredQtViewer::paintGL VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV %d ready %d\n",nbPaint,readyToPaint);
    272 #endif
    273    WinSize_x = (G4int) width();
    274    WinSize_y = (G4int) height();
    275    
    276    glViewport (0, 0, width(), height());
    277    //   glLoadIdentity();
    278    
    279 
    280    SetView();
    281 
    282 //   //  printf("before ClearView\n");
    283 #ifdef GEANT4_QT_DEBUG
    284    printf("    ClearView\n");
    285 #endif
    286    
    287    ClearView (); //ok, put the background correct
    288    DrawView();
    289 
    290    hasToRepaint =false;
    291 
    292 #ifdef GEANT4_QT_DEBUG
    293    printf("G4OpenGLStoredQtViewer::paintGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ %d ready %d\n",nbPaint,readyToPaint);
    294 #endif
    295352 }
    296353
     
    300357  printf("G4OpenGLStoredQtViewer::mousePressEvent\n");
    301358#endif
     359  setMouseTracking(true);
    302360  G4MousePressEvent(event->pos());
    303361}
    304362
     363void G4OpenGLStoredQtViewer::mouseDoubleClickEvent(QMouseEvent *event)
     364{
     365#ifdef GEANT4_QT_DEBUG
     366  printf("G4OpenGLStoredQtViewer::mouseDoubleClickEvent\n");
     367#endif
     368  setMouseTracking(true);
     369  zoomAction=true;
     370  makeCurrent();
     371  glBufferImage = QImage( width(), height(), QImage::Format_ARGB32_Premultiplied );
     372  glReadPixels( 0, 0, width(), height(), GL_RGBA, GL_UNSIGNED_BYTE, glBufferImage.bits() );
     373  //  glBufferImage = grabFrameBuffer(false).convertToFormat(QImage::Format_RGB16); //QImage::Format_ARGB32_Premultiplied
     374 
     375#ifdef GEANT4_QT_DEBUG
     376//   for (int ay=0;ay<glBufferImage.height();ay++) {
     377//     for (int ax=0;ax<glBufferImage.width();ax++) {
     378//       if (glBufferImage.pixel(ax,ay) == 255) {
     379//         printf(".");
     380//       } else if (!glBufferImage.pixel(ax,ay)) {
     381//         printf("X");
     382//       } else {
     383//         printf("%d",glBufferImage.pixel(ax,ay));
     384//       }
     385//     }
     386//     printf("\n");
     387//   }
     388#endif
     389  beginZoom.setX(event->x());
     390  beginZoom.setY(event->y());
     391}
     392
     393void G4OpenGLStoredQtViewer::mouseReleaseEvent(QMouseEvent *event)
     394{
     395#ifdef GEANT4_QT_DEBUG
     396  printf("G4OpenGLStoredQtViewer::mouseReleaseEvent\n");
     397#endif
     398  setMouseTracking(false);
     399  zoomAction =false;
     400}
     401
    305402void G4OpenGLStoredQtViewer::mouseMoveEvent(QMouseEvent *event)
    306403{
     404  // special case of mouse zoom action, it should draw a rect on
     405  // the openGL buffer, so it could only be done in this class
     406  // and sould be reimplemented in G4OpenGLImmediateQtViewer
     407  if (!zoomAction) {
    307408#if QT_VERSION < 0x040000
    308   G4MouseMoveEvent(event->x(),event->y(),event->state());
     409    G4MouseMoveEvent(event->x(),event->y(),event->state());
    309410#else
    310   G4MouseMoveEvent(event->x(),event->y(),event->buttons());
    311 #endif
     411    G4MouseMoveEvent(event->x(),event->y(),event->buttons());
     412#endif
     413  } else {
     414#ifdef GEANT4_QT_DEBUG
     415    printf("G4OpenGLStoredQtViewer::mouseMoveEvent zoom\n");
     416#endif
     417    endZoom.setX(event->x());
     418    endZoom.setY(event->y());
     419    updateGL();
     420  }
    312421  //  DrawView();
    313422}
     
    328437}
    329438
    330 #endif
     439
     440#endif
Note: See TracChangeset for help on using the changeset viewer.