Index: /trunk/source/visualization/GNUmakefile
===================================================================
--- /trunk/source/visualization/GNUmakefile	(revision 1241)
+++ /trunk/source/visualization/GNUmakefile	(revision 1242)
@@ -26,7 +26,8 @@
 
 # For Debug mode
-# CPPFLAGS += -DG4DEBUG_VIS_OGL
+ CPPFLAGS += -DG4DEBUG_VIS_OGL
 # CPPFLAGS += -DG4DEBUG_VIS_OI
 # CPPFLAGS += -DG4DEBUG_VIS_MANAGEMENT
+
 
 ifdef G4VIS_BUILD
Index: /trunk/source/visualization/OpenGL/GNUmakefile
===================================================================
--- /trunk/source/visualization/OpenGL/GNUmakefile	(revision 1241)
+++ /trunk/source/visualization/OpenGL/GNUmakefile	(revision 1242)
@@ -12,4 +12,8 @@
 # For debug mode
  CPPFLAGS += -DG4DEBUG_VIS_OGL
+
+#CPPFLAGS += -DG4VIS_BUILD_OPTIMISE_1
+#CPPFLAGS += -DG4VIS_BUILD_OPTIMISE_2
+#CPPFLAGS += -DG4VIS_BUILD_OPTIMISE_3
 
 GLOBLIBS  = libG4vis_management.lib libG4modeling.lib libG4gl2ps.lib
Index: /trunk/source/visualization/OpenGL/History
===================================================================
--- /trunk/source/visualization/OpenGL/History	(revision 1241)
+++ /trunk/source/visualization/OpenGL/History	(revision 1242)
@@ -1,3 +1,3 @@
-$Id: History,v 1.163 2010/01/28 09:19:04 gcosmo Exp $
+$Id: History,v 1.164 2010/03/10 11:03:46 lgarnier Exp $
 -------------------------------------------------------------------
 
@@ -17,4 +17,14 @@
      * Reverse chronological order (last date on top), please *
      ----------------------------------------------------------
+9th March 2010 Laurent Garnier
+ - G4OpenGLViewer : Fix clipping when resizing non square size windows
+   Remove error message when no scene present.
+ - G4OpenGLImmediateQtViewer, G4OpenGLStoredQtViewer : 
+    - Add some protections if viewer is in tab
+    -  fix some redraw probems when focus was outside frame
+    - Add ShowView() and paintEvent() methods
+    - DrawView method is now the same in Store and Immediate mode
+ - G4OpenGLQtViewer : Add things for viewer in tabs
+
 3rd March 2010 Laurent Garnier
 - G4OpenGLViewer : Add protection against null pointer scene
Index: /trunk/source/visualization/OpenGL/include/G4OpenGLImmediateQtViewer.hh
===================================================================
--- /trunk/source/visualization/OpenGL/include/G4OpenGLImmediateQtViewer.hh	(revision 1241)
+++ /trunk/source/visualization/OpenGL/include/G4OpenGLImmediateQtViewer.hh	(revision 1242)
@@ -25,5 +25,5 @@
 //
 //
-// $Id: G4OpenGLImmediateQtViewer.hh,v 1.6 2009/10/14 13:27:30 lgarnier Exp $
+// $Id: G4OpenGLImmediateQtViewer.hh,v 1.7 2010/03/10 11:03:46 lgarnier Exp $
 // GEANT4 tag $Name:  $
 //
@@ -56,5 +56,4 @@
   void initializeGL ();
   void DrawView ();
-  //  void FinishView ();
   void resizeGL(int width,int height);
   void paintGL();
Index: /trunk/source/visualization/OpenGL/include/G4OpenGLSceneHandler.hh
===================================================================
--- /trunk/source/visualization/OpenGL/include/G4OpenGLSceneHandler.hh	(revision 1241)
+++ /trunk/source/visualization/OpenGL/include/G4OpenGLSceneHandler.hh	(revision 1242)
@@ -64,4 +64,5 @@
   void AddPrimitive (const G4Circle&);
   void AddPrimitive (const G4Square&);
+  void AddPrimitives (std::vector <G4VMarker>);
   void AddPrimitive (const G4Scale&);
   void AddPrimitive (const G4Polyhedron&);
@@ -105,4 +106,5 @@
 
   void AddCircleSquare (const G4VMarker&, G4OpenGLBitMapStore::Shape);
+  void AddCircleSquares (std::vector <G4VMarker>, G4OpenGLBitMapStore::Shape);
 
   void DrawXYPolygon
Index: /trunk/source/visualization/OpenGL/include/G4OpenGLStoredQtViewer.hh
===================================================================
--- /trunk/source/visualization/OpenGL/include/G4OpenGLStoredQtViewer.hh	(revision 1241)
+++ /trunk/source/visualization/OpenGL/include/G4OpenGLStoredQtViewer.hh	(revision 1242)
@@ -25,5 +25,5 @@
 //
 //
-// $Id: G4OpenGLStoredQtViewer.hh,v 1.9 2009/10/14 13:27:30 lgarnier Exp $
+// $Id: G4OpenGLStoredQtViewer.hh,v 1.10 2010/03/10 11:03:46 lgarnier Exp $
 // GEANT4 tag $Name:  $
 //
Index: /trunk/source/visualization/OpenGL/src/G4OpenGLImmediateQtViewer.cc
===================================================================
--- /trunk/source/visualization/OpenGL/src/G4OpenGLImmediateQtViewer.cc	(revision 1241)
+++ /trunk/source/visualization/OpenGL/src/G4OpenGLImmediateQtViewer.cc	(revision 1242)
@@ -25,5 +25,5 @@
 //
 //
-// $Id: G4OpenGLImmediateQtViewer.cc,v 1.17 2009/11/03 11:02:32 lgarnier Exp $
+// $Id: G4OpenGLImmediateQtViewer.cc,v 1.18 2010/03/10 11:03:46 lgarnier Exp $
 // GEANT4 tag $Name:  $
 //
@@ -67,29 +67,11 @@
 #endif
   fReadyToPaint = false;
-#ifdef G4DEBUG_VIS_OGL
-  printf("G4OpenGLImmediateQtViewer::Initialise VVVVVVVVVVVVVVVV \n");
-#endif
   CreateMainWindow (this,QString(fName));
-#ifdef G4DEBUG_VIS_OGL
-  printf("G4OpenGLImmediateQtViewer::Initialise ^^^^^^^^^^^^^^^^\n");
-#endif
   CreateFontLists ();
 
   fReadyToPaint = true;
-#ifdef G4DEBUG_VIS_OGL
-  printf("G4OpenGLImmediateQtViewer::InitialiseGLView * \n");
-#endif
-
-  // L.Garnier 01/2010 Force a update in order to Init GL
-  //  updateGL();
-#ifdef G4DEBUG_VIS_OGL
-  printf("G4OpenGLImmediateQtViewer::InitialiseGLView end * \n");
-#endif
 }
 
 void G4OpenGLImmediateQtViewer::initializeGL () {
-#ifdef G4DEBUG_VIS_OGL
-  printf("G4OpenGLImmediateQtViewer::InitialiseGL * \n");
-#endif
 
   InitializeGLView ();
@@ -115,18 +97,6 @@
 
 
-/** To ensure compatibility with DrawView method
- */
 void  G4OpenGLImmediateQtViewer::DrawView() {
-#ifdef G4DEBUG_VIS_OGL
-  printf("G4OpenGLImmediateQtViewer::DrawView  VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n");
-#endif
-  // That's no the same logic as Stored Viewer, I don't know why...
-  // see G4OpenGLStoredQtViewer::DrawView for more informations
-
   updateQWidget();
-
-#ifdef G4DEBUG_VIS_OGL
-  printf("G4OpenGLImmediateQtViewer::DrawView  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
-#endif
 }
 
@@ -135,5 +105,5 @@
 
 #ifdef G4DEBUG_VIS_OGL
-  printf("G4OpenGLImmediateQtViewer::ComputeView %d %d   VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n",getWinWidth(), getWinHeight());
+  printf("G4OpenGLImmediateQtViewer::ComputeView %d %d &:%d  VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n",getWinWidth(), getWinHeight(),this);
 #endif
   makeCurrent();
@@ -166,9 +136,8 @@
    
 #ifdef G4DEBUG_VIS_OGL
-  printf("G4OpenGLImmediateQtViewer::ComputeView %d %d hasTo:%d^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n",getWinWidth(), getWinHeight(),fHasToRepaint);
+  printf("G4OpenGLImmediateQtViewer::ComputeView %d %d ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n",getWinWidth(), getWinHeight());
 #endif
   fHasToRepaint = true;
 }
-
 
 /**
@@ -179,12 +148,6 @@
 ,int aHeight)
 {  
-#ifdef G4DEBUG_VIS_OGL
-  printf("\n\nG4OpenGLImmediateQtViewer::resizeGL VVVV recu : W:%d H:%d\n",aWidth,aHeight);
-#endif
   ResizeWindow(aWidth,aHeight);
   fHasToRepaint = sizeHasChanged();
-#ifdef G4DEBUG_VIS_OGL
-  printf("\n\nG4OpenGLImmediateQtViewer::resizeGL ^^^^^\n");
-#endif
 }
 
@@ -193,5 +156,5 @@
 {
 #ifdef G4DEBUG_VIS_OGL
-  printf("\n\nG4OpenGLImmediateQtViewer::paintGL ?? %d W:%d H:%d \n",fHasToRepaint,getWinWidth(),getWinHeight());
+  printf("\n\nG4OpenGLImmediateQtViewer::paintGL  &: %d??\n",this);
 #endif
   if (!fReadyToPaint) {
@@ -294,14 +257,7 @@
 
 void G4OpenGLImmediateQtViewer::paintEvent(QPaintEvent *event) {
-  //  fHasToRepaint= false;
-#ifdef G4DEBUG_VIS_OGL
-  printf("\n\nG4OpenGLImmediateQtViewer::paintEvent VVVVVVVVV %d\n",fHasToRepaint);
-#endif
   if ( fHasToRepaint) {
     updateGL();
   }
-#ifdef G4DEBUG_VIS_OGL
-  printf("\n\nG4OpenGLImmediateQtViewer::paintEvent ^^^^^^^^^ %d\n",fHasToRepaint);
-#endif
 }
 
@@ -309,12 +265,6 @@
 void G4OpenGLImmediateQtViewer::updateQWidget() {
   fHasToRepaint= true;
-#ifdef G4DEBUG_VIS_OGL
-  printf("\n\nG4OpenGLImmediateQtViewer::updateQWidget VVVVVVVVV HasTo:%d\n",fHasToRepaint);
-#endif
   updateGL();
   repaint();
-#ifdef G4DEBUG_VIS_OGL
-  printf("\n\nG4OpenGLImmediateQtViewer::updateQWidget ^^^^^^^^^\n");
-#endif
   fHasToRepaint= false;
 }
@@ -326,7 +276,4 @@
 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
 {
-#ifdef G4DEBUG_VIS_OGL
-  printf("\n\nG4OpenGLImmediateQtViewer::ShowView VVVV\n");
-#endif
   fHasToRepaint = true;
 #if QT_VERSION < 0x040000
@@ -335,7 +282,4 @@
   activateWindow();
 #endif
-#ifdef G4DEBUG_VIS_OGL
-  printf("\n\nG4OpenGLImmediateQtViewer::ShowView ^^^^^\n");
-#endif
-}
-#endif
+}
+#endif
Index: /trunk/source/visualization/OpenGL/src/G4OpenGLImmediateSceneHandler.cc
===================================================================
--- /trunk/source/visualization/OpenGL/src/G4OpenGLImmediateSceneHandler.cc	(revision 1241)
+++ /trunk/source/visualization/OpenGL/src/G4OpenGLImmediateSceneHandler.cc	(revision 1242)
@@ -157,5 +157,5 @@
 
   // See all primitives immediately...
-  //  glFlush ();
+  glFlush ();
 
   G4OpenGLSceneHandler::EndPrimitives ();
Index: /trunk/source/visualization/OpenGL/src/G4OpenGLQtViewer.cc
===================================================================
--- /trunk/source/visualization/OpenGL/src/G4OpenGLQtViewer.cc	(revision 1241)
+++ /trunk/source/visualization/OpenGL/src/G4OpenGLQtViewer.cc	(revision 1242)
@@ -25,5 +25,5 @@
 //
 //
-// $Id: G4OpenGLQtViewer.cc,v 1.47 2010/01/27 15:49:22 gcosmo Exp $
+// $Id: G4OpenGLQtViewer.cc,v 1.48 2010/03/10 11:03:46 lgarnier Exp $
 // GEANT4 tag $Name:  $
 //
@@ -165,28 +165,13 @@
       YPos = offset;
     }
-#ifdef G4DEBUG_VIS_OGL
-    printf("G4OpenGLQtViewer::CreateMainWindow :: before resizing to %d %d vvvvvvvvvvvvvvvvvvv\n",getWinWidth(), getWinHeight());
-#endif
     fGLWindow->resize(getWinWidth(), getWinHeight());
 #ifdef G4DEBUG_VIS_OGL
-    printf("G4OpenGLQtViewer::CreateMainWindow :: after resizing to %d %d ^^^^^^^^^^^^^^^^^^^^\n",getWinWidth(), getWinHeight());
+    printf("G4OpenGLQtViewer::CreateMainWindow :: resizing to %d %d \n",getWinWidth(), getWinHeight());
 #endif
     fGLWindow->move(fVP.GetWindowAbsoluteLocationHintX(QApplication::desktop()->width()),YPos);
     fGLWindow->show();
-#ifdef G4DEBUG_VIS_OGL
-    printf("G4OpenGLQtViewer::CreateMainWindow :: after show to %d %d --------------------\n",getWinWidth(), getWinHeight());
-#endif
-  } else {
-#ifdef G4DEBUG_VIS_OGL
-    printf("G4OpenGLQtViewer::AddTab VVVVVVVVVVVVVV\n");
-#endif
+  } else {
     fGLWindow = fWindow;
-#ifdef G4DEBUG_VIS_OGL
-    printf("G4OpenGLQtViewer::AddTab ->resize : %d %d\n",getWinWidth(), getWinHeight());
-#endif
     fGLWindow->resize(getWinWidth(), getWinHeight());
-#ifdef G4DEBUG_VIS_OGL
-    printf("G4OpenGLQtViewer::AddTab ^^^^^^^^^^^^^^\n");
-#endif
   }
 
@@ -196,7 +181,4 @@
     createPopupMenu();
 
-#ifdef G4DEBUG_VIS_OGL
-  printf("G4OpenGLQtViewer::CreateMainWindow :: END\n");
-#endif
 }
 
@@ -1436,7 +1418,4 @@
 void G4OpenGLQtViewer::FinishView()
 {
-#ifdef G4DEBUG_VIS_OGL
-  printf("G4OpenGLQtViewer::FinishView() flush \n");
-#endif
   glFlush ();
 
Index: /trunk/source/visualization/OpenGL/src/G4OpenGLSceneHandler.cc
===================================================================
--- /trunk/source/visualization/OpenGL/src/G4OpenGLSceneHandler.cc	(revision 1241)
+++ /trunk/source/visualization/OpenGL/src/G4OpenGLSceneHandler.cc	(revision 1242)
@@ -234,9 +234,19 @@
 // printf(" circle ");
 #endif
+#ifdef G4VIS_BUILD_OPTIMISE_3
+      std::vector <G4VMarker> circleV; 
+      // FIXME, must check attribute before doing a list
+#endif
       for (size_t iPoint = 0; iPoint < polymarker.size (); iPoint++) {
         G4Circle circle (polymarker);
+        // If not already drawn
         circle.SetPosition (polymarker[iPoint]);
-        G4OpenGLSceneHandler::AddPrimitive (circle);
-      }
+#ifdef G4VIS_BUILD_OPTIMISE_3
+        circleV.push_back(circle);
+#endif
+      }
+#ifdef G4VIS_BUILD_OPTIMISE_3
+      G4OpenGLSceneHandler::AddPrimitives (circleV);
+#endif
     }
     break;
@@ -246,9 +256,18 @@
 // printf(" square ");
 #endif
+#ifdef G4VIS_BUILD_OPTIMISE_3
+      std::vector <G4VMarker> squareV; 
+      // FIXME, must check attribute before doing a list
+#endif
       for (size_t iPoint = 0; iPoint < polymarker.size (); iPoint++) {
         G4Square square (polymarker);
         square.SetPosition (polymarker[iPoint]);
-        G4OpenGLSceneHandler::AddPrimitive (square);
-      }
+#ifdef G4VIS_BUILD_OPTIMISE_3
+        squareV.push_back(square);
+#endif
+      }
+#ifdef G4VIS_BUILD_OPTIMISE_3
+      G4OpenGLSceneHandler::AddPrimitives (squareV);
+#endif
     }
     break;
@@ -319,4 +338,9 @@
 }
 
+void G4OpenGLSceneHandler::AddPrimitives (std::vector <G4VMarker> square) {
+  glDisable (GL_POINT_SMOOTH);
+  AddCircleSquares (square, G4OpenGLBitMapStore::square);
+}
+
 void G4OpenGLSceneHandler::AddCircleSquare
 (const G4VMarker& marker,
@@ -398,4 +422,113 @@
      glBegin (GL_POINTS);
      glVertex3f(centre.x(),centre.y(),centre.z());
+     glEnd();
+     //Antialiasing
+     glEnable (GL_POINT_SMOOTH);
+     //Transparency
+     glEnable(GL_BLEND);
+     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+
+     // L. GARNIER 1 March 2009
+     // Old method, we draw a bitmap instead of a GL_POINT. 
+     // I remove it because it cost in term of computing performances
+     // and gl2ps can't draw bitmaps
+
+     //      glRasterPos3d(centre.x(),centre.y(),centre.z());
+     //      const GLubyte* marker =
+     //        G4OpenGLBitMapStore::GetBitMap(shape, size, filled);
+     //      glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
+     //      glBitmap(GLsizei(size), GLsizei(size), size/2., size/2., 0., 0., marker);
+   }
+}
+
+void G4OpenGLSceneHandler::AddCircleSquares
+(std::vector <G4VMarker> marker,
+ G4OpenGLBitMapStore::Shape shape) {
+
+  if (marker.size() == 0) {
+    return;
+  }
+
+  if (!fProcessingPolymarker) {  // Polymarker has already loaded atts.
+    // Loads G4Atts for picking...
+    if (fpViewer->GetViewParameters().IsPicking()) {
+      G4AttHolder* holder = new G4AttHolder;
+      LoadAtts(marker[0], holder);
+      fPickMap[fPickName] = holder;
+    }
+  }
+
+  // Note: colour treated in sub-class.
+
+  if (fpViewer -> GetViewParameters ().IsMarkerNotHidden ()) {
+#ifdef G4DEBUG_VIS_OGL
+    //    printf("+");
+#endif
+    glDisable (GL_DEPTH_TEST);
+  } else {
+#ifdef G4DEBUG_VIS_OGL
+    //    printf("-");
+#endif
+    glEnable (GL_DEPTH_TEST); glDepthFunc (GL_LESS);}
+  
+  glDisable (GL_LIGHTING);
+  
+  // Get vis attributes - pick up defaults if none.
+  const G4VisAttributes* pVA =
+    fpViewer -> GetApplicableVisAttributes (marker[0].GetVisAttributes ());
+
+  G4double lineWidth = GetLineWidth(pVA);
+  glLineWidth(lineWidth);
+
+  G4VMarker::FillStyle style = marker[0].GetFillStyle();
+
+  G4bool filled = false;
+  static G4bool hashedWarned = false;
+  
+  switch (style) {
+  case G4VMarker::noFill: 
+    glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
+    filled = false;
+    break;
+    
+  case G4VMarker::hashed:
+    if (!hashedWarned) {
+      G4cout << "Hashed fill style in G4OpenGLSceneHandler."
+	     << "\n  Not implemented.  Using G4VMarker::filled."
+	     << G4endl;
+      hashedWarned = true;
+    }
+    // Maybe use
+    //glPolygonStipple (fStippleMaskHashed);
+    // Drop through to filled...
+    
+  case G4VMarker::filled:
+    glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
+    filled = true;
+    break;
+    
+  }
+
+
+
+  MarkerSizeType sizeType;
+  G4double size = GetMarkerSize(marker[0], sizeType);
+
+  // Draw...
+   if (sizeType == world) {  // Size specified in world coordinates.
+
+     for (unsigned int a=0;a<marker.size();a++) {
+       G4Point3D centre = marker[a].GetPosition();
+       // A few useful quantities...
+       DrawXYPolygon (shape, size, centre, pVA);
+     }
+   } else { // Size specified in screen (window) coordinates.
+     // A few useful quantities...
+     glPointSize (size);
+     glBegin (GL_POINTS);
+     for (unsigned int a=0;a<marker.size();a++) {
+       G4Point3D centre = marker[a].GetPosition();
+       glVertex3f(centre.x(),centre.y(),centre.z());
+     }
      glEnd();
      //Antialiasing
Index: /trunk/source/visualization/OpenGL/src/G4OpenGLStoredQtViewer.cc
===================================================================
--- /trunk/source/visualization/OpenGL/src/G4OpenGLStoredQtViewer.cc	(revision 1241)
+++ /trunk/source/visualization/OpenGL/src/G4OpenGLStoredQtViewer.cc	(revision 1242)
@@ -25,5 +25,5 @@
 //
 //
-// $Id: G4OpenGLStoredQtViewer.cc,v 1.28 2009/11/03 11:02:32 lgarnier Exp $
+// $Id: G4OpenGLStoredQtViewer.cc,v 1.29 2010/03/10 11:03:46 lgarnier Exp $
 // GEANT4 tag $Name:  $
 //
@@ -103,18 +103,5 @@
 
 
-void G4OpenGLStoredQtViewer::DrawView () {
-#ifdef G4DEBUG_VIS_OGL
-  printf("G4OpenGLStoredQtViewer::DrawView  VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n");
-#endif
-  // That's no the same logic as Immediate Viewer, I don't know why...
-  // But if I send updateGL here, we go here :
-  //  updateQWidget -> paintGL -> ComputeView
-  // whih is not the same as ComputeView Directly
-  // And we loose the redraw of things !
-  
-  //  ComputeView();
-#ifdef G4DEBUG_VIS_OGL
-  printf("G4OpenGLStoredQtViewer::DrawView  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ llllllllllllllllllllllllllllllll\n");
-#endif
+void G4OpenGLStoredQtViewer::DrawView () {  
   updateQWidget();
 }
@@ -219,5 +206,5 @@
 {
 #ifdef G4DEBUG_VIS_OGL
-  printf("G4OpenGLStoredQtViewer::paintGL ready:%d fHasTo:%d?? context:%d\n",fReadyToPaint,fHasToRepaint,context());
+  printf("G4OpenGLStoredQtViewer::paintGL ready:%d fHasTo:%d??\n",fReadyToPaint,fHasToRepaint);
 #endif
   if (!fReadyToPaint) {
@@ -253,10 +240,10 @@
 
   SetView();
-
+          
   ClearView (); //ok, put the background correct
   ComputeView();
 
   fHasToRepaint =false;
-     
+
 #ifdef G4DEBUG_VIS_OGL
   printf("G4OpenGLStoredQtViewer::paintGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ready %d\n",fReadyToPaint);
@@ -265,13 +252,7 @@
 
 void G4OpenGLStoredQtViewer::paintEvent(QPaintEvent *event) {
-#ifdef G4DEBUG_VIS_OGL
-  printf("\n\nG4OpenGLStoredQtViewer::paintEvent VVVVVVVVV %d context : %d\n",fHasToRepaint,context());
-#endif
   if ( fHasToRepaint) {
     updateGL();
   }
-#ifdef G4DEBUG_VIS_OGL
-  printf("\n\nG4OpenGLStoredQtViewer::paintEvent ^^^^^^^^^\n");
-#endif
 }
 
Index: /trunk/source/visualization/OpenGL/src/G4OpenGLStoredViewer.cc
===================================================================
--- /trunk/source/visualization/OpenGL/src/G4OpenGLStoredViewer.cc	(revision 1241)
+++ /trunk/source/visualization/OpenGL/src/G4OpenGLStoredViewer.cc	(revision 1242)
@@ -126,5 +126,5 @@
 void G4OpenGLStoredViewer::DrawDisplayLists () {
 #ifdef G4DEBUG_VIS_OGL
-      printf("G4OpenGLStoredViewer::DrawDisplayLists \n");
+  //      printf("G4OpenGLStoredViewer::DrawDisplayLists \n");
 #endif
 
@@ -134,9 +134,9 @@
   size_t nPasses = cutawayUnion? cutaways.size(): 1;
 #ifdef G4DEBUG_VIS_OGL
-  printf("G4OpenGLStoredViewer::DrawDisplayLists");
+  //  printf("G4OpenGLStoredViewer::DrawDisplayLists");
 #endif
   for (size_t i = 0; i < nPasses; ++i) {
 #ifdef G4DEBUG_VIS_OGL
-    printf("+");
+    //    printf("+");
 #endif
 
@@ -156,5 +156,5 @@
     for (size_t i = 0; i < fG4OpenGLStoredSceneHandler.fTOList.size(); ++i) {
 #ifdef G4DEBUG_VIS_OGL
-      printf("-");
+      //      printf("-");
 #endif
       G4OpenGLStoredSceneHandler::TO& to =
@@ -179,5 +179,5 @@
   }
 #ifdef G4DEBUG_VIS_OGL
-      printf("\n");
+  //      printf("\n");
 #endif
 
Index: /trunk/source/visualization/OpenGL/src/G4OpenGLViewer.cc
===================================================================
--- /trunk/source/visualization/OpenGL/src/G4OpenGLViewer.cc	(revision 1241)
+++ /trunk/source/visualization/OpenGL/src/G4OpenGLViewer.cc	(revision 1242)
@@ -25,5 +25,5 @@
 //
 //
-// $Id: G4OpenGLViewer.cc,v 1.59 2009/10/20 12:47:45 lgarnier Exp $
+// $Id: G4OpenGLViewer.cc,v 1.60 2010/03/10 11:03:46 lgarnier Exp $
 // GEANT4 tag $Name:  $
 //
@@ -100,11 +100,8 @@
   //  glDisable (GL_LINE_SMOOTH);
   //  glDisable (GL_POLYGON_SMOOTH);
-}
-
-G4OpenGLViewer::~G4OpenGLViewer () {
-#ifdef G4DEBUG_VIS_OGL
-  printf("G4OpenGLViewer::~G4OpenGLViewer DELETING \n");
-#endif
-}
+
+}
+
+G4OpenGLViewer::~G4OpenGLViewer () {}
 
 void G4OpenGLViewer::InitializeGLView () 
@@ -118,12 +115,9 @@
   fWinSize_x = fVP.GetWindowSizeHintX();
   fWinSize_y = fVP.GetWindowSizeHintY();
-#ifdef G4DEBUG_VIS_OGL
-  printf("G4OpenGLViewer::InitializeGLView to W:%d H:%d pt:%d\n",fWinSize_x,fWinSize_y,this);
-#endif
 }  
 
 void G4OpenGLViewer::ClearView () {
 #ifdef G4DEBUG_VIS_OGL
-  printf("G4OpenGLViewer::ClearView\n");
+  printf("G4OpenGLViewer::ClearView &:%d\n",this);
 #endif
   glClearColor (background.GetRed(),
@@ -152,7 +146,4 @@
     fSizeHasChanged = false;
   }
-#ifdef G4DEBUG_VIS_OGL
-  printf("G4OpenGLViewer::ResizeWindow :W:%d H:%d changed?:%d set:W:%d H:%d pt:%d\n",fWinSize_x,fWinSize_y,fSizeHasChanged,aWidth,aHeight,this);
-#endif
 }
 
@@ -166,5 +157,5 @@
 {
 #ifdef G4DEBUG_VIS_OGL
-  printf("G4OpenGLViewer::ResizeGLView %d %d pt:%d\n",fWinSize_x,fWinSize_y,this);
+  printf("G4OpenGLViewer::ResizeGLView %d %d &:%d\n",fWinSize_x,fWinSize_y,this);
 #endif
   // Check size
@@ -172,18 +163,6 @@
   glGetIntegerv(GL_MAX_VIEWPORT_DIMS, dims);
 
-  // L.Garnier 01-2010: Some problems with mac 10.6
   if ((dims[0] !=0 ) && (dims[1] !=0)) {
 
-#ifdef G4DEBUG_VIS_OGL
-    GLenum err = glGetError();
-    if (err != GL_NO_ERROR) {                          \
-      printf("%s: %s at %s:%d\n",                      \
-             __FUNCTION__,                             \
-             gluErrorString(err),                      \
-             __FILE__, __LINE__);                      \
-      printf("G4OpenGLViewer::ResizeGLView ERRRRR\n");
-    }
-    printf("G4OpenGLViewer::ResizeGLView DIM X:%d Y:%d\n",dims[0],dims[1]);
-#endif
     if (fWinSize_x > (unsigned)dims[0]) {
       G4cerr << "Try to resize view greater than max X viewport dimension. Desired size "<<dims[0] <<" is resize to "<<  dims[0] << G4endl;
@@ -195,41 +174,6 @@
     }
   }
-//   GLsizei side = fWinSize_x;
-//   if (fWinSize_y < fWinSize_x) side = fWinSize_y;
-  
-  // SPECIAL CASE if fWinSize_x is even (69 for example) 
-  // Ex : X: 69 Y: 26
-  // side = 26
-  // width / 2 = 21,5
-  // height / 2 = 0
-  // Should be fixed to closed : 21 0 for ex
-  // Then size must by change to :
-  // X:68 Y: 26
-
-  // SPECIAL CASE
-//   if ((fWinSize_x - side)%2) {
-//     //    fWinSize_x --;
-
-//     side = fWinSize_x;
-//     if (fWinSize_y < fWinSize_x) side = fWinSize_y;
-//   }
-//   if ((fWinSize_y - side)%2) {
-//     //    fWinSize_y --;
-
-//     side = fWinSize_x;
-//     if (fWinSize_y < fWinSize_x) side = fWinSize_y;
-//   }
-  
-//   GLint X = (fWinSize_x - side) / 2;
-//   GLint Y = (fWinSize_y - side) / 2;
-  
-#ifdef G4DEBUG_VIS_OGL
-  //  printf("G4OpenGLViewer::ResizeGLView X:%d Y:%d W:%d H:%d --side%d\n",(fWinSize_x - side) / 2,(fWinSize_y - side) / 2,fWinSize_x,fWinSize_y,side);
-#endif
-
-  //  glViewport(X, Y, side, side);
+    
   glViewport(0, 0, fWinSize_x,fWinSize_y);  
-  
-
 }
 
@@ -284,11 +228,5 @@
   
   // FIXME
-#ifdef G4DEBUG_VIS_OGL
-  printf("G4OpenGLViewer::SetView Call ResizeGLView VVVVVV sizeX:%d sizeY:%d ratioX:%f ratioY:%f\n",fWinSize_x,fWinSize_y,ratioX,ratioY);
-#endif
   ResizeGLView();
-#ifdef G4DEBUG_VIS_OGL
-  printf("G4OpenGLViewer::SetView Call ResizeGLView ^^^^^^\n");
-#endif
   //SHOULD SetWindowsSizeHint()...
 
@@ -301,7 +239,4 @@
   if (fVP.GetFieldHalfAngle() == 0.) {
     glOrtho (left, right, bottom, top, pnear, pfar);
-#ifdef G4DEBUG_VIS_OGL
-    printf("G4OpenGLViewer::SetView glOrtho %f %f %f %f %f %f\n",left, right, bottom, top, pnear, pfar);
-#endif
   }
   else {
@@ -567,4 +502,7 @@
   }
 
+#ifdef G4DEBUG_VIS_OGL
+  printf("G4OpenGLViewer::printEPS END\n");
+#endif
 }
 
@@ -575,9 +513,10 @@
 bool G4OpenGLViewer::printNonVectoredEPS () {
 
+
   int width = getRealPrintSizeX();
   int height = getRealPrintSizeY();
 
 #ifdef G4DEBUG_VIS_OGL
-  printf("G4OpenGLViewer::printNonVectoredEPS file:%s Vec:%d X:%d Y:%d col:%d\n",getRealPrintFilename().c_str(),fVectoredPs,width,height,fPrintColour);
+  printf("G4OpenGLViewer::printNonVectoredEPS file:%s Vec:%d X:%d Y:%d col:%d fWinX:%d fWinY:%d\n",getRealPrintFilename().c_str(),fVectoredPs,width,height,fPrintColour,fWinSize_x,fWinSize_y);
 #endif
   FILE* fp;
@@ -671,27 +610,31 @@
   fGL2PSAction->setFileName(getRealPrintFilename().c_str());
   // try to resize
-  int X = fWinSize_x;
-  int Y = fWinSize_y;
-
-  fWinSize_x = width;
-  fWinSize_y = height;
+   int X = fWinSize_x;
+   int Y = fWinSize_y;
+
+   fWinSize_x = width;
+   fWinSize_y = height;
+#ifdef G4DEBUG_VIS_OGL
+  printf("G4OpenGLViewer::printgl2PS VVVV %d %d\n",getRealPrintSizeX(),getRealPrintSizeY());
+#endif
+  // Laurent G. 16/03/10 : Not the good way to do. 
+  // We should draw in a new offscreen context instead of
+  // resizing and drawing in current window...
+  // This should be solve when we will do an offscreen method
+  // to render OpenGL
+  // See : 
+  // http://developer.apple.com/Mac/library/documentation/GraphicsImaging/Conceptual/OpenGL-MacProgGuide/opengl_offscreen/opengl_offscreen.html
+  // http://www.songho.ca/opengl/gl_fbo.html
+
   ResizeGLView();
   if (fGL2PSAction->enableFileWriting()) {
 
+    // Set the viewport
+    //    fGL2PSAction->setViewport(0, 0, getRealPrintSizeX(),getRealPrintSizeY());  
     // By default, we choose the line width (trajectories...)
     fGL2PSAction->setLineWidth(1);
     // By default, we choose the point size (markers...)
-    
-#ifdef G4DEBUG_VIS_OGL
-    //  printf("G4OpenGLViewer::printGl2PS marker size:%f\n",    GetSceneHandler()->GetMarkerSize());
-#endif
-#ifdef G4DEBUG_VIS_OGL
-  //  printf("G4OpenGLViewer::printGl2PS marker2 size:%f\n",fpViewer -> GetViewParameters ()->GetDefaultMarker ().GetScreenSize());
-#endif
-    //    if (fpViewer -> GetViewParameters ().IsMarkerNotHidden ()) {
-    //      fGL2PSAction->setPointSize(fpViewer -> GetViewParameters ()->GetDefaultMarker ().GetScreenSize());
-    //    } else {
-      fGL2PSAction->setPointSize(2);
-      //    }
+    fGL2PSAction->setPointSize(2);
+
     DrawView ();
     fGL2PSAction->disableFileWriting();
@@ -700,5 +643,12 @@
   fWinSize_x = X;
   fWinSize_y = Y;
+#ifdef G4DEBUG_VIS_OGL
+  printf("G4OpenGLViewer::printgl2PS 22222 %d %d \n",fWinSize_x,fWinSize_y);
+#endif
   ResizeGLView();
+  DrawView ();
+#ifdef G4DEBUG_VIS_OGL
+  printf("G4OpenGLViewer::printgl2PS ^^^^\n");
+#endif
 
   // Reset for next time (useful is size change)
Index: /trunk/source/visualization/externals/gl2ps/include/G4OpenGL2PSAction.hh
===================================================================
--- /trunk/source/visualization/externals/gl2ps/include/G4OpenGL2PSAction.hh	(revision 1241)
+++ /trunk/source/visualization/externals/gl2ps/include/G4OpenGL2PSAction.hh	(revision 1242)
@@ -49,4 +49,6 @@
  void setLineWidth(int);
  void setPointSize(int);
+ void setViewport(int,int,int,int);
+
 
 protected:
Index: /trunk/source/visualization/externals/gl2ps/src/G4OpenGL2PSAction.cc
===================================================================
--- /trunk/source/visualization/externals/gl2ps/src/G4OpenGL2PSAction.cc	(revision 1241)
+++ /trunk/source/visualization/externals/gl2ps/src/G4OpenGL2PSAction.cc	(revision 1242)
@@ -76,4 +76,20 @@
 
 //////////////////////////////////////////////////////////////////////////////
+void G4OpenGL2PSAction::setViewport(
+int a
+,int b
+,int winSizeX
+,int winSizeY
+)
+//////////////////////////////////////////////////////////////////////////////
+//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
+{
+  fViewport[0] = a;
+  fViewport[1] = b;
+  fViewport[2] = winSizeX;
+  fViewport[3] = winSizeY;
+}
+
+//////////////////////////////////////////////////////////////////////////////
 void G4OpenGL2PSAction::setFileName(
  const char* aFileName
Index: /trunk/source/visualization/management/GNUmakefile
===================================================================
--- /trunk/source/visualization/management/GNUmakefile	(revision 1241)
+++ /trunk/source/visualization/management/GNUmakefile	(revision 1242)
@@ -11,4 +11,7 @@
 # For debug mode
 # CPPFLAGS += -DG4DEBUG_VIS_MANAGEMENT
+CPPFLAGS += -DG4VIS_BUILD_OPTIMISE_1
+CPPFLAGS += -DG4VIS_BUILD_OPTIMISE_2
+
 
 GLOBLIBS  = libG4modeling.lib
Index: /trunk/source/visualization/management/History
===================================================================
--- /trunk/source/visualization/management/History	(revision 1241)
+++ /trunk/source/visualization/management/History	(revision 1242)
@@ -26,4 +26,7 @@
 History file for visualization management sub-category
 ------------------------------------------------------
+9th March 2010 Laurent Garnier
+ - G4OpenGLViewer : Fix clipping when resizing non square size windows
+  
 8th March 2010 Laurent Garnier
 -G4VisManager.cc : Add protection against null pointer
Index: /trunk/source/visualization/management/src/G4VisManager.cc
===================================================================
--- /trunk/source/visualization/management/src/G4VisManager.cc	(revision 1241)
+++ /trunk/source/visualization/management/src/G4VisManager.cc	(revision 1242)
@@ -477,5 +477,7 @@
     fpSceneHandler -> BeginPrimitives (objectTransform);
     fpSceneHandler -> AddPrimitive (line);
+#ifndef G4VIS_BUILD_OPTIMISE_2
     fpSceneHandler -> EndPrimitives ();
+#endif
   }
 }
@@ -485,7 +487,13 @@
   if (IsValidView ()) {
     ClearTransientStoreIfMarked();
+#ifndef G4VIS_BUILD_OPTIMISE_2
+    // FIXME : test
     fpSceneHandler -> BeginPrimitives (objectTransform);
+#endif
     fpSceneHandler -> AddPrimitive (polymarker);
+    // FIXME : test
+#ifndef G4VIS_BUILD_OPTIMISE_2
     fpSceneHandler -> EndPrimitives ();
+#endif
   }
 }
@@ -515,6 +523,9 @@
   if (IsValidView ()) {
     ClearTransientStoreIfMarked();
+    // FIXME : test
+#ifndef G4VIS_BUILD_OPTIMISE_2
     fpSceneHandler -> BeginPrimitives (objectTransform);
     fpSceneHandler -> AddPrimitive (text);
+#endif
     fpSceneHandler -> EndPrimitives ();
   }
Index: /trunk/source/visualization/modeling/GNUmakefile
===================================================================
--- /trunk/source/visualization/modeling/GNUmakefile	(revision 1241)
+++ /trunk/source/visualization/modeling/GNUmakefile	(revision 1242)
@@ -17,4 +17,8 @@
 
 include $(G4INSTALL)/config/architecture.gmk
+
+#CPPFLAGS += -DG4VIS_BUILD_OPTIMISE_1
+#CPPFLAGS += -DG4VIS_BUILD_OPTIMISE_2
+#CPPFLAGS += -DG4VIS_BUILD_OPTIMISE_3
 
 CPPFLAGS += -I$(G4BASE)/global/management/include
Index: /trunk/source/visualization/modeling/src/G4TrajectoryDrawerUtils.cc
===================================================================
--- /trunk/source/visualization/modeling/src/G4TrajectoryDrawerUtils.cc	(revision 1241)
+++ /trunk/source/visualization/modeling/src/G4TrajectoryDrawerUtils.cc	(revision 1242)
@@ -33,4 +33,5 @@
 #include "G4Polyline.hh"
 #include "G4Polymarker.hh"
+#include "G4Text.hh"
 #include "G4VTrajectory.hh"
 #include "G4VTrajectoryPoint.hh"
@@ -56,12 +57,34 @@
 	for (size_t iAux=0; iAux<auxiliaries->size(); ++iAux) {
 	  const G4ThreeVector pos((*auxiliaries)[iAux]);
-	  trajectoryLine.push_back(pos);
-	  auxiliaryPoints.push_back(pos);
-	}
+#ifdef G4VIS_BUILD_OPTIMISE_1
+          if (trajectoryLine.size() >0) {
+            if (pos != trajectoryLine[trajectoryLine.size()-1]) {
+              trajectoryLine.push_back(pos);
+              auxiliaryPoints.push_back(pos);
+            }
+         } else {
+#endif
+            trajectoryLine.push_back(pos);
+            auxiliaryPoints.push_back(pos);
+#ifdef G4VIS_BUILD_OPTIMISE_1
+          }
+#endif
+        }
       }
       const G4ThreeVector pos(aTrajectoryPoint->GetPosition());
-      trajectoryLine.push_back(pos);
-      stepPoints.push_back(pos);
-    }    
+#ifdef G4VIS_BUILD_OPTIMISE_1
+      if (trajectoryLine.size() >0) {
+        if (pos != trajectoryLine[trajectoryLine.size()-1]) {
+          trajectoryLine.push_back(pos);
+          stepPoints.push_back(pos);
+        }
+      } else {
+#endif
+        trajectoryLine.push_back(pos);
+        stepPoints.push_back(pos);
+#ifdef G4VIS_BUILD_OPTIMISE_1
+      }
+#endif
+    }
   }
 
@@ -274,4 +297,8 @@
 
       pVVisManager->Draw(stepPoints);
+#ifdef G4VIS_BUILD_OPTIMISE_2
+      G4Text text = G4Text("");
+      pVVisManager->Draw(text);
+#endif
     }
   }
