Salome HOME
size of image is limited by 7000 pixels
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_Overview.cxx
index a72155b62fffcc03271496c5e44263e6c2fa8e8a..f7185a2fa587e21e7bfc29fc0612b1cf77eef8aa 100644 (file)
@@ -23,6 +23,7 @@
 #include <QApplication>
 #include <QPainter>
 #include <QMouseEvent>
+#include <QLayout>
 
 class HYDROGUI_OverviewBand : public QtxPolyRubberBand
 {
@@ -172,11 +173,15 @@ void HYDROGUI_OverviewBand::update( bool isFromMain )
     int h = main->height();
 
     QPolygon poly;
-    poly.append( myOverview->fromMain( 0, 0 ) );
-    poly.append( myOverview->fromMain( w, 0 ) );
-    poly.append( myOverview->fromMain( w, h ) );
-    poly.append( myOverview->fromMain( 0, h ) );
-    poly.append( myOverview->fromMain( 0, 0 ) );
+    QPoint p1 = myOverview->fromMain( 0, 0 );
+    QPoint p2 = myOverview->fromMain( w, 0 );
+    QPoint p3 = myOverview->fromMain( w, h );
+    QPoint p4 = myOverview->fromMain( 0, h );
+    poly.append( p1 );
+    poly.append( p2 );
+    poly.append( p3 );
+    poly.append( p4 );
+    poly.append( p1 );
     initGeometry( poly );
   }
   else
@@ -185,11 +190,41 @@ void HYDROGUI_OverviewBand::update( bool isFromMain )
     QPoint c = center();
     double x1, y1, z1, x2, y2, z2;
     main->getView()->Convert( main->width()/2, main->height()/2, x1, y1, z1 );
+
+    // Patch for OCCT 6.9.1, on 7.0.0 the moving of point to plane XY is not necessary
+    gp_Dir dm = main->getView()->Camera()->Direction();
+    double t1 = -z1/dm.Z();
+    x1 += dm.X()*t1;
+    y1 += dm.Y()*t1;
+    z1 += dm.Z()*t1;
+
     overview->getView()->Convert( c.x(), c.y(), x2, y2, z2 );
+    gp_Dir dov = overview->getView()->Camera()->Direction();
+    double t2 = -z2/dov.Z();
+    x2 += dov.X()*t2;
+    y2 += dov.Y()*t2;
+    z2 += dov.Z()*t2;
 
     gp_Trsf aTrsf;
     aTrsf.SetTranslation( gp_Pnt( x1, y1, z1 ), gp_Pnt( x2, y2, z2 ) );
-    main->getView()->Camera()->Transform( aTrsf );
+
+    // Temporary patch for bug in OCCT 6.9.1
+    Handle(Graphic3d_Camera) cam = main->getView()->Camera();
+    gp_Dir u = cam->Up(), nu = u.Transformed (aTrsf);
+    gp_Pnt e = cam->Eye(), ne = e.Transformed (aTrsf);
+    gp_Pnt cen = cam->Center(), ncen = cen.Transformed (aTrsf);
+
+    if (!nu.IsEqual (u, 0.0))
+      cam->SetUp(nu);
+
+    if (!ne.IsEqual (e, 0.0))
+      cam->SetEye(ne);
+
+    if (!ncen.IsEqual(cen, 0.0))
+      cam->SetCenter (ncen);
+
+    //version for new OCCT:
+    //main->getView()->Camera()->Transform( aTrsf );
     main->repaint();
   }
 }
@@ -213,10 +248,15 @@ void HYDROGUI_OverviewBand::paintEvent( QPaintEvent* thePaintEvent )
 
 
 HYDROGUI_Overview::HYDROGUI_Overview( const QString& theTitle, int theMargin, QWidget* theParent )
-  : QDockWidget( theParent ), myMargin( theMargin ),
+  : QFrame( theParent ), myMargin( theMargin ),
     myMainView( 0 ), myViewPort( 0 ), myBand( 0 )
 {
   setWindowTitle( theTitle );
+  myLayout = new QGridLayout( this );
+  myLayout->setMargin( 0 );
+  myLayout->setSpacing( 0 );
+  myLayout->setRowStretch( 0, 1 );
+  myLayout->setColumnStretch( 0, 1 );
 }
 
 HYDROGUI_Overview::~HYDROGUI_Overview()
@@ -266,29 +306,38 @@ void HYDROGUI_Overview::setMainView( OCCViewer_ViewFrame* theMainView )
 
   OCCViewer_ViewWindow* aMainView = myMainView->getView( OCCViewer_ViewFrame::MAIN_VIEW );
   connect( aMainView, SIGNAL( vpTransformationFinished( OCCViewer_ViewWindow::OperationType ) ),
-           this,      SLOT( OnTransformation() ) );
+           this,      SLOT( OnTransformationAfterOp( OCCViewer_ViewWindow::OperationType ) ) );
   connect( aMainView->getViewPort(), SIGNAL( vpResizeEvent( QResizeEvent* ) ),
            this,       SLOT( OnResizeEvent( QResizeEvent* ) ) );
   connect( aMainView->getViewPort(), SIGNAL( vpTransformed( OCCViewer_ViewPort* ) ),
            this,       SLOT( OnTransformation() ) );
 
-  myViewPort = new OCCViewer_ViewPort3d( this, myMainView->getViewPort()->getViewer(), V3d_ORTHOGRAPHIC );
-  myViewPort->setBackgroundColor( Qt::white );
+  if( !myViewPort )
+  {
+    myViewPort = new OCCViewer_ViewPort3d( this, myMainView->getViewPort()->getViewer(), V3d_ORTHOGRAPHIC );
+    myViewPort->setBackgroundColor( myMainView->getViewPort()->backgroundColor() );
 
-  connect( myViewPort, SIGNAL( vpMouseEvent( QMouseEvent* ) ), 
-           this,       SLOT( OnMouseEvent( QMouseEvent* ) ) );
-  connect( myViewPort, SIGNAL( vpResizeEvent( QResizeEvent* ) ),
-           this,       SLOT( OnResizeEvent( QResizeEvent* ) ) );
+    connect( myViewPort, SIGNAL( vpMouseEvent( QMouseEvent* ) ), 
+            this,       SLOT( OnMouseEvent( QMouseEvent* ) ) );
+    connect( myViewPort, SIGNAL( vpResizeEvent( QResizeEvent* ) ),
+            this,       SLOT( OnResizeEvent( QResizeEvent* ) ) );
+
+    myLayout->addWidget( myViewPort, 0, 0 );
+  }
 
 #if defined(TEST_MODE) || defined(_DEBUG)
   //qApp->installEventFilter( this );
 #endif
 
-  setWidget( myViewPort );
+  qApp->processEvents();
+
   setTopView();
 
   qApp->processEvents();
-  myBand = new HYDROGUI_OverviewBand( this );
+
+  if( !myBand )
+    myBand = new HYDROGUI_OverviewBand( this );
+
   myBand->update( true );
 }
 
@@ -300,16 +349,29 @@ void HYDROGUI_Overview::setTopView()
   myViewPort->fitAll();
 
   // Apply margins for internal area in the view port
-  QRect aRect( -myMargin, -myMargin, myViewPort->width()+2*myMargin, myViewPort->height()+2*myMargin );
-  myViewPort->fitRect( aRect );
+  if( myMargin>0 )
+  {
+    QRect aRect( -myMargin, -myMargin, myViewPort->width()+2*myMargin, myViewPort->height()+2*myMargin );
+    myViewPort->fitRect( aRect );
+  }
 
   if( myBand )
     myBand->update( true );
 }
 
+void HYDROGUI_Overview::OnTransformationAfterOp( OCCViewer_ViewWindow::OperationType theOp )
+{
+  if( theOp>=OCCViewer_ViewWindow::WINDOWFIT )
+  {
+    myViewPort->fitAll();
+  }
+  OnTransformation();
+}
+
 void HYDROGUI_Overview::OnTransformation()
 {
-  myBand->update( true );
+  if( myBand )
+    myBand->update( true );
 }
 
 QPoint HYDROGUI_Overview::fromMain( int xp, int yp ) const
@@ -378,7 +440,7 @@ bool HYDROGUI_Overview::eventFilter( QObject* theObject, QEvent* theEvent )
     break;
   }*/
 #endif
-  return QDockWidget::eventFilter( theObject, theEvent );
+  return QFrame::eventFilter( theObject, theEvent );
 }
 
 void HYDROGUI_Overview::OnResizeEvent( QResizeEvent* )