Salome HOME
updated copyright message
[modules/gui.git] / src / SVTK / SVTK_ViewModel.cxx
index 2f2477e9965f81284ada715bf90b25ec6fb64d07..998464b940c1e7f49f92341277d4613578c17379 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2023  CEA, EDF, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -23,6 +23,7 @@
 #include <QMenu>
 #include <QColorDialog>
 #include <QToolBar>
+#include <QTimer>
 
 #include <vtkCamera.h>
 #include <vtkRenderer.h>
 // VSR: Uncomment below line to allow texture background support in VTK viewer
 #define VTK_ENABLE_TEXTURED_BACKGROUND
 
-
-// in order NOT TO link with SalomeApp, here the code returns SALOMEDS_Study.
-// SalomeApp_Study::studyDS() does it as well, but -- here it is retrieved from 
-// SALOMEDS::StudyManager - no linkage with SalomeApp. 
-
-// Temporarily commented to avoid awful dependecy on SALOMEDS
-// TODO: better mechanism of storing display/erse status in a study
-// should be provided...
-//static _PTR(Study) getStudyDS() 
-//{
-//  SALOMEDSClient_Study* aStudy = NULL;
-//  _PTR(StudyManager) aMgr( new SALOMEDS_StudyManager() );
-  // get id of SUIT_Study, if it's a SalomeApp_Study, it will return
-  //    id of its underlying SALOMEDS::Study
-//  SUIT_Application* app = SUIT_Session::session()->activeApplication();
-//  if ( !app )  return _PTR(Study)(aStudy); 
-//  SUIT_Study* stud = app->activeStudy();
-//  if ( !stud ) return _PTR(Study)(aStudy);  
-//  const int id = stud->id(); // virtual method, must return SALOMEDS_Study id
-  // get SALOMEDS_Study with this id from StudyMgr
-//  return aMgr->GetStudyByID( id );
-//}
-
 /*!
   Constructor
 */
@@ -84,6 +62,8 @@ SVTK_Viewer::SVTK_Viewer()
   myIncrementSpeed = 10;
   myIncrementMode = 0;
   myProjMode = 0;
+  myStereoType = 0;
+  myAnaglyphFilter = 0;
   myStyle = 0;
   myZoomingStyle = 0;
   mySelectionEnabled = true;
@@ -92,6 +72,7 @@ SVTK_Viewer::SVTK_Viewer()
   mySpaceBtn[1] = 2;
   mySpaceBtn[2] = 9;
   myDefaultBackground = Qtx::BackgroundData( Qt::black );
+  myQuadBufferSupport = false;
 }
 
 /*!
@@ -126,6 +107,21 @@ QString SVTK_Viewer::backgroundData( QStringList& gradList, QIntList& idList, QI
   return tr("BG_IMAGE_FILES");
 }
 
+/*! Get data for supported background modes: gradient types, identifiers and supported image formats */
+void SVTK_Viewer::stereoData( QStringList& typeList, QIntList& idList )
+{
+  typeList << tr("ST_CRYSTALEYES") << tr("ST_REDBLUE")      <<
+              tr("ST_INTERLACED")  << tr("ST_LEFT")         <<
+              tr("ST_RIGHT")       << tr("ST_DRESDEN")      <<
+              tr("ST_ANAGLYPH")    << tr("ST_CHECKERBOARD") <<
+              tr("ST_SPLITVIEWPORTHORIZONTAL");
+  idList   << CrystalEyesType << RedBlueType      <<
+              InterlacedType  << LeftType         <<
+              RightType       << DresdenType      <<
+              AnaglyphType    << CheckerboardType <<
+              SplitViewPortHorizontalType;
+}
+
 //! Get background color of the viewer [obsolete]
 QColor SVTK_Viewer::backgroundColor() const
 {
@@ -177,6 +173,9 @@ SUIT_ViewWindow* SVTK_Viewer::createView( SUIT_Desktop* theDesktop )
   aViewWindow->SetTrihedronSize( trihedronSize(), trihedronRelative() );
   aViewWindow->SetStaticTrihedronVisible( isStaticTrihedronVisible() );
   aViewWindow->SetProjectionMode( projectionMode() );
+  aViewWindow->SetStereoType( stereoType() );
+  aViewWindow->SetAnaglyphFilter( anaglyphFilter() );
+  aViewWindow->SetQuadBufferSupport( isQuadBufferSupport() );
   aViewWindow->SetInteractionStyle( interactionStyle() );
   aViewWindow->SetZoomingStyle( zoomingStyle() );
   aViewWindow->SetPreSelectionMode( preSelectionMode() );
@@ -188,7 +187,7 @@ SUIT_ViewWindow* SVTK_Viewer::createView( SUIT_Desktop* theDesktop )
           this,  SLOT(onActorAdded(VTKViewer_Actor*)));
   connect(aViewWindow, SIGNAL( actorRemoved(VTKViewer_Actor*) ), 
           this,  SLOT(onActorRemoved(VTKViewer_Actor*)));
-
+  
   return aViewWindow;
 }
 
@@ -220,7 +219,7 @@ void SVTK_Viewer::setTrihedronSize( const double theSize, const bool theRelative
 
   if (SUIT_ViewManager* aViewManager = getViewManager()) {
     QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
-    for ( uint i = 0; i < aViews.count(); i++ )
+    for ( int i = 0; i < aViews.count(); i++ )
     {
       if ( TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at( i )) )
               aView->SetTrihedronSize( theSize, theRelative );
@@ -246,7 +245,7 @@ void SVTK_Viewer::setStaticTrihedronVisible( const bool theIsVisible )
 
   if (SUIT_ViewManager* aViewManager = getViewManager()) {
     QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
-    for ( uint i = 0; i < aViews.count(); i++ )
+    for ( int i = 0; i < aViews.count(); i++ )
     {
       if ( TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at( i )) )
         aView->SetStaticTrihedronVisible( theIsVisible );
@@ -270,11 +269,11 @@ int SVTK_Viewer::projectionMode() const
 void SVTK_Viewer::setProjectionMode( const int theMode )
 {
   if ( myProjMode != theMode ) {
-    myProjMode = theMode;
-
+    if ( theMode != SVTK_ViewWindow::Stereo )
+      myProjMode = theMode;
     if (SUIT_ViewManager* aViewManager = getViewManager()) {
       QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
-      for ( uint i = 0; i < aViews.count(); i++ )
+      for ( int i = 0; i < aViews.count(); i++ )
       {
         if ( TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at( i )) )
           aView->SetProjectionMode( theMode );
@@ -283,6 +282,89 @@ void SVTK_Viewer::setProjectionMode( const int theMode )
   }
 }
 
+/*!
+  \return stereo type
+*/
+int SVTK_Viewer::stereoType() const
+{
+  return myStereoType;
+}
+
+/*!
+  Sets stereo type
+  \param theType - new stereo type
+*/
+void SVTK_Viewer::setStereoType( const int theType )
+{
+  if ( myStereoType != theType ) {
+    myStereoType = theType;
+
+    if (SUIT_ViewManager* aViewManager = getViewManager()) {
+      QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
+      for ( int i = 0; i < aViews.count(); i++ )
+      {
+        if ( TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at( i )) )
+          aView->SetStereoType( theType );
+      }
+    }
+  }
+}
+
+/*!
+  \return anaglyph filter
+*/
+int SVTK_Viewer::anaglyphFilter() const
+{
+  return myAnaglyphFilter;
+}
+
+/*!
+  Sets anaglyph filter
+  \param theFilter - new anaglyph filter
+*/
+void SVTK_Viewer::setAnaglyphFilter( const int theFilter )
+{
+  if ( myAnaglyphFilter != theFilter ) {
+         myAnaglyphFilter = theFilter;
+
+    if (SUIT_ViewManager* aViewManager = getViewManager()) {
+      QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
+      for ( int i = 0; i < aViews.count(); i++ )
+      {
+        if ( TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at( i )) )
+          aView->SetAnaglyphFilter( theFilter );
+      }
+    }
+  }
+}
+
+/*!
+  \return support quad-buffered stereo
+*/
+bool SVTK_Viewer::isQuadBufferSupport() const
+{
+  return myQuadBufferSupport;
+}
+
+/*!
+  Set support quad-buffered stereo
+  \param theEnable - enable/disable support quad-buffered stereo
+*/
+void SVTK_Viewer::setQuadBufferSupport( const bool theEnable )
+{
+  if ( myQuadBufferSupport != theEnable ) {
+    myQuadBufferSupport = theEnable;
+
+    if (SUIT_ViewManager* aViewManager = getViewManager()) {
+      QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
+      for ( int i = 0; i < aViews.count(); i++ )
+      {
+        if ( TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at( i )) )
+          aView->SetQuadBufferSupport( theEnable );
+      }
+    }
+  }
+}
 /*!
   \return interaction style
 */
@@ -301,7 +383,7 @@ void SVTK_Viewer::setInteractionStyle( const int theStyle )
   
   if (SUIT_ViewManager* aViewManager = getViewManager()) {
     QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
-    for ( uint i = 0; i < aViews.count(); i++ )
+    for ( int i = 0; i < aViews.count(); i++ )
     {
       if ( TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at( i )) )
         aView->SetInteractionStyle( theStyle );
@@ -327,7 +409,7 @@ void SVTK_Viewer::setZoomingStyle( const int theStyle )
   
   if (SUIT_ViewManager* aViewManager = getViewManager()) {
     QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
-    for ( uint i = 0; i < aViews.count(); i++ )
+    for ( int i = 0; i < aViews.count(); i++ )
     {
       if ( TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at( i )) )
         aView->SetZoomingStyle( theStyle );
@@ -353,7 +435,7 @@ void SVTK_Viewer::setPreSelectionMode( Preselection_Mode theMode )
   
   if (SUIT_ViewManager* aViewManager = getViewManager()) {
     QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
-    for ( uint i = 0; i < aViews.count(); i++ )
+    for ( int i = 0; i < aViews.count(); i++ )
     {
       if ( TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at( i )) )
         aView->SetPreSelectionMode( theMode );
@@ -389,7 +471,7 @@ void SVTK_Viewer::setIncrementalSpeed( const int theValue, const int theMode )
 
   if (SUIT_ViewManager* aViewManager = getViewManager()) {
     QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
-    for ( uint i = 0; i < aViews.count(); i++ )
+    for ( int i = 0; i < aViews.count(); i++ )
     {
       if ( TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at( i )) )
         aView->SetIncrementalSpeed( theValue, theMode );
@@ -420,7 +502,7 @@ void SVTK_Viewer::setSpacemouseButtons( const int theBtn1, const int theBtn2, co
 
   if (SUIT_ViewManager* aViewManager = getViewManager()) {
     QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
-    for ( uint i = 0; i < aViews.count(); i++ )
+    for ( int i = 0; i < aViews.count(); i++ )
     {
       if ( TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at( i )) )
         aView->SetSpacemouseButtons( theBtn1, theBtn2, theBtn3 );
@@ -447,6 +529,9 @@ void SVTK_Viewer::setViewManager(SUIT_ViewManager* theViewManager)
   
   connect(theViewManager, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)), 
           this, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));
+
+  connect(theViewManager, SIGNAL(viewCreated(SUIT_ViewWindow*)), 
+         this, SLOT(onViewCreated(SUIT_ViewWindow*)));
 }
 
 /*!
@@ -461,7 +546,7 @@ void SVTK_Viewer::contextMenuPopup( QMenu* thePopup )
 
   if(TViewWindow* aView = dynamic_cast<TViewWindow*>(myViewManager->getActiveView())){
     //Support of several toolbars in the popup menu
-    QList<QToolBar*> lst = qFindChildren<QToolBar*>( aView );
+    QList<QToolBar*> lst = aView->findChildren<QToolBar*>();
     QList<QToolBar*>::const_iterator it = lst.begin(), last = lst.end();
     for( ; it!=last; it++ )
       thePopup->addAction( (*it)->toggleViewAction() );
@@ -472,19 +557,19 @@ void SVTK_Viewer::contextMenuPopup( QMenu* thePopup )
 /*!
   SLOT: called on mouse button press, empty implementation
 */
-void SVTK_Viewer::onMousePress(SUIT_ViewWindow* vw, QMouseEvent* event)
+void SVTK_Viewer::onMousePress(SUIT_ViewWindow* /*vw*/, QMouseEvent* /*event*/)
 {}
 
 /*!
   SLOT: called on mouse move, empty implementation
 */
-void SVTK_Viewer::onMouseMove(SUIT_ViewWindow* vw, QMouseEvent* event)
+void SVTK_Viewer::onMouseMove(SUIT_ViewWindow* /*vw*/, QMouseEvent* /*event*/)
 {}
 
 /*!
   SLOT: called on mouse button release, empty implementation
 */
-void SVTK_Viewer::onMouseRelease(SUIT_ViewWindow* vw, QMouseEvent* event)
+void SVTK_Viewer::onMouseRelease(SUIT_ViewWindow* /*vw*/, QMouseEvent* /*event*/)
 {}
 
 /*!
@@ -498,7 +583,7 @@ void SVTK_Viewer::enableSelection(bool isEnabled)
    
   if (SUIT_ViewManager* aViewManager = getViewManager()) {
     QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
-    for ( uint i = 0; i < aViews.count(); i++ )
+    for ( int i = 0; i < aViews.count(); i++ )
     {
       if ( TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at( i )) )
         aView->SetSelectionEnabled( isEnabled );
@@ -584,11 +669,6 @@ void SVTK_Viewer::Display( const SALOME_VTKPrs* prs )
     if(aPrs->IsNull())
       return;
     if(vtkActorCollection* anActorCollection = aPrs->GetObjects()){
-      // get SALOMEDS Study
-      // Temporarily commented to avoid awful dependecy on SALOMEDS
-      // TODO: better mechanism of storing display/erse status in a study
-      // should be provided...
-      // _PTR(Study) aStudy(getStudyDS());
       anActorCollection->InitTraversal();
       while(vtkActor* anActor = anActorCollection->GetNextActor()){
         if(SALOME_Actor* anAct = SALOME_Actor::SafeDownCast(anActor)){
@@ -599,8 +679,8 @@ void SVTK_Viewer::Display( const SALOME_VTKPrs* prs )
           // TODO: better mechanism of storing display/erse status in a study
           // should be provided...
           //Handle(SALOME_InteractiveObject) anObj = anAct->getIO();
-          //if(!anObj.IsNull() && anObj->hasEntry() && aStudy){
-          //  ToolsGUI::SetVisibility(aStudy,anObj->getEntry(),true,this);
+          //if(!anObj.IsNull() && anObj->hasEntry()){
+          //  ToolsGUI::SetVisibility(anObj->getEntry(),true,this);
           //}
           // just display the object
           QVector<SUIT_ViewWindow*> aViews = myViewManager->getViews();
@@ -633,11 +713,6 @@ void SVTK_Viewer::Erase( const SALOME_VTKPrs* prs, const bool forced )
     if(aPrs->IsNull())
       return;
     if(vtkActorCollection* anActorCollection = aPrs->GetObjects()){
-      // get SALOMEDS Study
-      // Temporarily commented to avoid awful dependecy on SALOMEDS
-      // TODO: better mechanism of storing display/erase status in a study
-      // should be provided...
-      //_PTR(Study) aStudy(getStudyDS());
       anActorCollection->InitTraversal();
       while(vtkActor* anActor = anActorCollection->GetNextActor())
         if(SALOME_Actor* anAct = SALOME_Actor::SafeDownCast(anActor)){
@@ -646,8 +721,8 @@ void SVTK_Viewer::Erase( const SALOME_VTKPrs* prs, const bool forced )
           // TODO: better mechanism of storing display/erase status in a study
           // should be provided...
           //Handle(SALOME_InteractiveObject) anObj = anAct->getIO();
-          //if(!anObj.IsNull() && anObj->hasEntry() && aStudy){
-          //  ToolsGUI::SetVisibility(aStudy,anObj->getEntry(),false,this);
+          //if(!anObj.IsNull() && anObj->hasEntry()){
+          //  ToolsGUI::SetVisibility(anObj->getEntry(),false,this);
           //}
           // just display the object
           QVector<SUIT_ViewWindow*> aViews = myViewManager->getViews();
@@ -670,12 +745,8 @@ void SVTK_Viewer::Erase( const SALOME_VTKPrs* prs, const bool forced )
   Erase all presentations
   \param forced - removes all objects from view
 */
-void SVTK_Viewer::EraseAll( const bool forced )
+void SVTK_Viewer::EraseAll( SALOME_Displayer* d, const bool forced )
 {
-  // Temporarily commented to avoid awful dependecy on SALOMEDS
-  // TODO: better mechanism of storing display/erse status in a study
-  // should be provided...
-  //_PTR(Study) aStudy(getStudyDS());
   QVector<SUIT_ViewWindow*> aViews = myViewManager->getViews();
   for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){
     if(SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>(aViews.at(i)))
@@ -691,8 +762,8 @@ void SVTK_Viewer::EraseAll( const bool forced )
             // TODO: better mechanism of storing display/erse status in a study
             // should be provided...
             //Handle(SALOME_InteractiveObject) anObj = anAct->getIO();
-            //if(!anObj.IsNull() && anObj->hasEntry() && aStudy)
-            //  ToolsGUI::SetVisibility(aStudy,anObj->getEntry(),false,this);
+            //if(!anObj.IsNull() && anObj->hasEntry())
+            //  ToolsGUI::SetVisibility(anObj->getEntry(),false,this);
             if(forced){
               if(SVTK_Renderer* aRnd = aView->GetRenderer())
                 aRnd->RemoveActor(anAct);
@@ -711,6 +782,9 @@ void SVTK_Viewer::EraseAll( const bool forced )
         }
       }
   }
+
+  SALOME_View::EraseAll( d, forced );
+
   Repaint();
 }
 
@@ -720,7 +794,7 @@ void SVTK_Viewer::EraseAll( const bool forced )
 */
 SALOME_Prs* SVTK_Viewer::CreatePrs( const char* entry )
 {
-  SVTK_Prs* prs = new SVTK_Prs();
+  SVTK_Prs* prs = new SVTK_Prs( entry );
   if ( entry ) {
     if(SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>(getViewManager()->getActiveView()))
       if(SVTK_View* aView = aViewWindow->getView()){
@@ -795,3 +869,10 @@ void SVTK_Viewer::onActorRemoved(VTKViewer_Actor* theActor)
 {
   emit actorRemoved((SVTK_ViewWindow*)sender(), theActor);
 }
+
+void SVTK_Viewer::onViewCreated( SUIT_ViewWindow* view) {
+#ifdef VGL_WORKAROUND
+  if ( SVTK_ViewWindow* svw = dynamic_cast<SVTK_ViewWindow*>( view ) )
+    QTimer::singleShot(500, [svw] () { svw->Repaint(); } );
+#endif
+}