Salome HOME
Merge branch 'V8_3_asterstudy' into V8_3_BR
[modules/gui.git] / src / OCCViewer / OCCViewer_ViewWindow.cxx
old mode 100755 (executable)
new mode 100644 (file)
index 8ad6be9..b7d38ea
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -24,6 +24,7 @@
 // Author :
 
 #include "OCCViewer_ViewWindow.h"
+#include "OCCViewer_ViewFrame.h"
 #include "OCCViewer_ViewModel.h"
 #include "OCCViewer_ViewPort3d.h"
 #include "OCCViewer_ViewManager.h"
 #include <Graphic3d_RenderingParams.hxx>
 #endif
 
+#if OCC_VERSION_MAJOR < 7
+  #include <Visual3d_View.hxx>
+#endif
 
-#include <Visual3d_View.hxx>
 #include <V3d_Plane.hxx>
 #include <V3d_Light.hxx>
 
 
 static QEvent* l_mbPressEvent = 0;
 
-#ifdef WIN32
-# include <QWindowsStyle>
-#endif
+//#ifdef WIN32
+//# include <QWindowsStyle>
+//#endif
 
+#ifdef __APPLE__
+#include <OpenGL/gl.h>
+#else
 #include <GL/gl.h>
+#endif
 
 // To avoid conflict between KeyPress from the X.h (define KeyPress 2)
 // and QEvent::KeyPress (qevent.h)
@@ -292,8 +299,8 @@ void OCCViewer_ViewWindow::initLayout()
   setCentralWidget(myViewPort);
   myOperation = NOTHING;
 
-  myCurrPointType = GRAVITY;
-  myPrevPointType = GRAVITY;
+  myCurrPointType = BBCENTER;
+  myPrevPointType = BBCENTER;
   mySelectedPoint = gp_Pnt(0.,0.,0.);
   myRotationPointSelection = false;
 
@@ -386,7 +393,7 @@ bool OCCViewer_ViewWindow::eventFilter( QObject* watched, QEvent* e )
 
         if ( aEvent->modifiers().testFlag(Qt::ControlModifier) ) {
           Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
-          if ( isPreselectionEnabled() && ic->HasOpenedContext() ) {
+          if ( isPreselectionEnabled() && myModel->useLocalSelection() ) {
             if ( aEvent->delta() > 0 ) {
               ic->HilightNextDetected( myViewPort->getView() );
             } else {
@@ -403,7 +410,9 @@ bool OCCViewer_ViewWindow::eventFilter( QObject* watched, QEvent* e )
           int x1 = (int)( aEvent->x() + width()*delta/100 );
           int y1 = (int)( aEvent->y() + height()*delta/100 );
           myViewPort->zoom( x, y, x1, y1 );
+#if OCC_VERSION_LARGE <= 0x07000000
           myViewPort->getView()->ZFitAll();
+#endif
           emit vpTransformationFinished ( ZOOMVIEW );
         }
       }
@@ -533,7 +542,7 @@ void OCCViewer_ViewWindow::vpMousePressEvent( QMouseEvent* theEvent )
         if ( theEvent->button() == Qt::LeftButton )
         {
           Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
-          ic->Select();
+          ic->Select( Standard_True );
           for ( ic->InitSelected(); ic->MoreSelected(); ic->NextSelected() )
           {
             TopoDS_Shape aShape = ic->SelectedShape();
@@ -572,7 +581,7 @@ void OCCViewer_ViewWindow::vpMousePressEvent( QMouseEvent* theEvent )
           }
           if ( ic->NbSelected() == 0 ) myCurrPointType = myPrevPointType;
           if ( mySetRotationPointDlg ) mySetRotationPointDlg->toggleChange();
-          ic->CloseAllContexts();
+          ic->CloseAllContexts( Standard_True );
           myOperation = NOTHING;
           myViewPort->setCursor( myCursor );
           myCursorIsHand = false;
@@ -767,7 +776,7 @@ void OCCViewer_ViewWindow::activateSetRotationGravity()
   if ( myRotationPointSelection )
   {
     Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
-    ic->CloseAllContexts();
+    ic->CloseAllContexts( Standard_True );
     myOperation = NOTHING;
     myViewPort->setCursor( myCursor );
     myCursorIsHand = false;
@@ -775,10 +784,10 @@ void OCCViewer_ViewWindow::activateSetRotationGravity()
   }
 
   myPrevPointType = myCurrPointType;
-  myCurrPointType = GRAVITY;
+  myCurrPointType = BBCENTER;
 
   Standard_Real Xcenter, Ycenter, Zcenter;
-  if ( computeGravityCenter( Xcenter, Ycenter, Zcenter ) )
+  if ( OCCViewer_Utilities::computeVisibleBBCenter( myViewPort->getView(), Xcenter, Ycenter, Zcenter ) )
     mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
 }
 
@@ -788,10 +797,10 @@ void OCCViewer_ViewWindow::activateSetRotationGravity()
 */
 void OCCViewer_ViewWindow::updateGravityCoords()
 {
-  if ( mySetRotationPointDlg && mySetRotationPointDlg->isVisible() && myCurrPointType == GRAVITY )
+  if ( mySetRotationPointDlg && mySetRotationPointDlg->isVisible() && myCurrPointType == BBCENTER )
   {
     Standard_Real Xcenter, Ycenter, Zcenter;
-    if ( computeGravityCenter( Xcenter, Ycenter, Zcenter ) )
+    if ( OCCViewer_Utilities::computeVisibleBBCenter( myViewPort->getView(), Xcenter, Ycenter, Zcenter ) )
       mySetRotationPointDlg->setCoords( Xcenter, Ycenter, Zcenter );
   }
 }
@@ -807,7 +816,7 @@ void OCCViewer_ViewWindow::activateSetRotationSelected( double theX, double theY
   if ( myRotationPointSelection )
   {
     Handle(AIS_InteractiveContext) ic = myModel->getAISContext();
-    ic->CloseAllContexts();
+    ic->CloseAllContexts( Standard_True );
     myOperation = NOTHING;
     myViewPort->setCursor( myCursor );
     myCursorIsHand = false;
@@ -1057,7 +1066,9 @@ void OCCViewer_ViewWindow::vpMouseReleaseEvent(QMouseEvent* theEvent)
 
   case PANVIEW:
   case ZOOMVIEW:
+#if OCC_VERSION_LARGE <= 0x07000000
     myViewPort->getView()->ZFitAll();
+#endif
     resetState();
     break;
 
@@ -1891,10 +1902,10 @@ void OCCViewer_ViewWindow::onSetRotationPoint( bool on )
     if (!mySetRotationPointDlg->isVisible())
     {
       //if (mySetRotationPointDlg->IsFirstShown())
-      if (myCurrPointType == GRAVITY)
+      if (myCurrPointType == BBCENTER)
       {
         Standard_Real Xcenter, Ycenter, Zcenter;
-        if (computeGravityCenter(Xcenter, Ycenter, Zcenter))
+        if (OCCViewer_Utilities::computeVisibleBBCenter(myViewPort->getView(), Xcenter, Ycenter, Zcenter))
           mySetRotationPointDlg->setCoords(Xcenter, Ycenter, Zcenter);
       }
       mySetRotationPointDlg->show();
@@ -1915,6 +1926,10 @@ void OCCViewer_ViewWindow::onCloneView()
   SUIT_ViewWindow* vw = myManager->createViewWindow();
   //vw->show();
   emit viewCloned( vw );
+  OCCViewer_ViewWindow* occVw = dynamic_cast<OCCViewer_ViewWindow*> (vw);
+  if(occVw && occVw->getView(OCCViewer_ViewFrame::MAIN_VIEW)) {
+    occVw->getView(OCCViewer_ViewFrame::MAIN_VIEW)->synchronize(this);
+  }
 }
 
 /*!
@@ -1923,7 +1938,7 @@ void OCCViewer_ViewWindow::onCloneView()
 void OCCViewer_ViewWindow::onAxialScale()
 {
   if ( !myScalingDlg )
-    myScalingDlg = new OCCViewer_AxialScaleDlg( this );
+    myScalingDlg = new OCCViewer_AxialScaleDlg( this , myModel );
 
   if ( !myScalingDlg->isVisible() )
   {
@@ -2273,7 +2288,11 @@ bool OCCViewer_ViewWindow::dumpViewToFormat( const QImage& img,
   if ( format != "PS" && format != "EPS")
    res = myViewPort->getView()->Dump( fileName.toStdString().c_str() );
 
+#if OCC_VERSION_MAJOR < 7
   Handle(Visual3d_View) a3dView = myViewPort->getView()->View();
+#else
+  Handle(Graphic3d_CView) a3dView = myViewPort->getView()->View();
+#endif
 
   if (format == "PS")
     res = a3dView->Export(strdup(qPrintable(fileName)), Graphic3d_EF_PostScript);
@@ -2318,10 +2337,15 @@ void OCCViewer_ViewWindow::setCuttingPlane( bool on, const double x,  const doub
     gp_Pln pln (gp_Pnt(x, y, z), gp_Dir(dx, dy, dz));
     double a, b, c, d;
     pln.Coefficients(a, b, c, d);
-
+#if OCC_VERSION_LARGE > 0x07000000 
+    Handle(Graphic3d_SequenceOfHClipPlane) aPlanes = view->ClipPlanes();
+    Graphic3d_SequenceOfHClipPlane::Iterator anIter (*aPlanes);
+    if(aPlanes->Size() > 0 ) {
+#else
     Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
+    Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
     if(aPlanes.Size() > 0 ) {
-      Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
+#endif
       Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
       aClipPlane->SetEquation(pln);
       aClipPlane->SetOn(Standard_True);
@@ -2330,8 +2354,13 @@ void OCCViewer_ViewWindow::setCuttingPlane( bool on, const double x,  const doub
     }
   }
   else {
+#if OCC_VERSION_LARGE > 0x07000000 
+    Handle(Graphic3d_SequenceOfHClipPlane) aPlanes = view->ClipPlanes();
+    Graphic3d_SequenceOfHClipPlane::Iterator anIter (*aPlanes);
+#else
     Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
     Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
+#endif
     for( ;anIter.More();anIter.Next() ){
       Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
       aClipPlane->SetOn(Standard_False);
@@ -2358,8 +2387,13 @@ bool OCCViewer_ViewWindow::isCuttingPlane()
 {
   Handle(V3d_View) view = myViewPort->getView();
   bool res = false;
-  Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
-  Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
+#if OCC_VERSION_LARGE > 0x07000000 
+  Handle(Graphic3d_SequenceOfHClipPlane) aPlanes = view->ClipPlanes();
+  Graphic3d_SequenceOfHClipPlane::Iterator anIter (*aPlanes);
+#else
+    Graphic3d_SequenceOfHClipPlane aPlanes = view->GetClipPlanes();
+    Graphic3d_SequenceOfHClipPlane::Iterator anIter (aPlanes);
+#endif
   for( ;anIter.More();anIter.Next() ) {
     Handle(Graphic3d_ClipPlane) aClipPlane = anIter.Value();
     if(aClipPlane->IsOn()) {
@@ -2779,7 +2813,9 @@ void OCCViewer_ViewWindow::setVisualParameters( const QString& parameters )
             aTexture = new Graphic3d_TextureEnv( TCollection_AsciiString( et_paramValue.toStdString().c_str() ) );
           Handle(V3d_View) aView = this->getViewPort()->getView();
           aView->SetTextureEnv( aTexture );
+#if OCC_VERSION_LARGE <= 0x07000000
           aView->SetSurfaceDetail( V3d_TEX_ENVIRONMENT );
+#endif
         }
       }
       else if ( paramName == "lightSource" )
@@ -2788,9 +2824,12 @@ void OCCViewer_ViewWindow::setVisualParameters( const QString& parameters )
         while ( myModel->getViewer3d()->MoreDefinedLights() )
         {
           Handle(V3d_Light) aLight = myModel->getViewer3d()->DefinedLight();
-          if( aLight->Type() != V3d_AMBIENT )
+          if( aLight->Type() != V3d_AMBIENT ) {
             myModel->getViewer3d()->DelLight( aLight );
-          myModel->getViewer3d()->NextDefinedLights();
+           myModel->getViewer3d()->InitDefinedLights();
+         } else {
+           myModel->getViewer3d()->NextDefinedLights();
+         }
         }
         double aX, aY, aZ;
         double cR, cG, cB;
@@ -3636,8 +3675,9 @@ void OCCViewer_ViewWindow::synchronize( SUIT_ViewWindow* theView )
 #endif
 
   getViewPort()->setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
-
+#if OCC_VERSION_LARGE <= 0x07000000
   aDestView->ZFitAll();
+#endif
   aDestView->SetImmediateUpdate( Standard_True );
   aDestView->Redraw();