Salome HOME
Join modifications from branch OCC_development_for_3_2_0a2
[modules/gui.git] / src / SVTK / SVTK_ViewModel.cxx
index 5ff0869507f953700ef9fe215b312a1bd7c674a0..03b8ca4a141736e22b0dbbbd652ec9cd6bd50e36 100644 (file)
@@ -1,3 +1,21 @@
+// Copyright (C) 2005  OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
+// 
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either 
+// version 2.1 of the License.
+// 
+// This library is distributed in the hope that it will be useful 
+// but WITHOUT ANY WARRANTY; without even the implied warranty of 
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public  
+// License along with this library; if not, write to the Free Software 
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/
+//
 #include <qpopupmenu.h>
 #include <qcolordialog.h>
 
 #include "SVTK_Selection.h"
 #include "SVTK_ViewModel.h"
 #include "SVTK_ViewWindow.h"
+#include "SVTK_View.h"
+#include "SVTK_MainWindow.h"
 #include "SVTK_Prs.h"
 
-#include "SVTK_RenderWindowInteractor.h"
-#include "SVTK_RenderWindow.h"
+#include "VTKViewer_ViewModel.h"
 
-#include "ToolsGUI.h"
-
-#include "SALOME_Actor.h"
-#include "SALOME_InteractiveObject.hxx"
-
-#include "Utils_ORB_INIT.hxx"
-#include "Utils_SINGLETON.hxx"
-#include "SALOME_ModuleCatalog_impl.hxx"
-#include "SALOME_NamingService.hxx"
-
-#include "SALOMEDSClient.hxx"
-#include "SALOMEDS_StudyManager.hxx"
+#include <SALOME_Actor.h>
+#include <SALOME_InteractiveObject.hxx>
 
 // 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. 
 
-static _PTR(Study) getStudyDS() 
-{
-  SALOMEDSClient_Study* aStudy = NULL;
-  _PTR(StudyManager) aMgr( new SALOMEDS_StudyManager() );
-
+// 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
+//  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 );
-}
+//  return aMgr->GetStudyByID( id );
+//}
 
 //==========================================================
 SVTK_Viewer::SVTK_Viewer()
 {
+  myTrihedronSize = 105;
+  myTrihedronRelative = true;
 }
 
 //==========================================================
@@ -58,23 +71,69 @@ SVTK_Viewer::~SVTK_Viewer()
 {
 }
 
-QColor SVTK_Viewer::backgroundColor() const
+QColor
+SVTK_Viewer
+::backgroundColor() const
 {
   return myBgColor;
 }
 
-void SVTK_Viewer::setBackgroundColor( const QColor& c )
+void
+SVTK_Viewer
+::setBackgroundColor( const QColor& theColor )
 {
-  if ( c.isValid() )
-    myBgColor = c;
+  if ( !theColor.isValid() )
+    return;
+
+  QPtrVector<SUIT_ViewWindow> aViews = myViewManager->getViews();
+  for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){
+    if(SUIT_ViewWindow* aViewWindow = aViews.at(i)){
+      if(TViewWindow* aView = dynamic_cast<TViewWindow*>(aViewWindow)){
+       aView->setBackgroundColor(theColor);
+      }
+    }
+  }
+
+  myBgColor = theColor;
 }
 
 //==========================================================
-SUIT_ViewWindow* SVTK_Viewer::createView( SUIT_Desktop* theDesktop )
+SUIT_ViewWindow*
+SVTK_Viewer::
+createView( SUIT_Desktop* theDesktop )
 {
-  SVTK_ViewWindow* vw = new SVTK_ViewWindow( theDesktop, this );
-  vw->setBackgroundColor( backgroundColor() );
-  return vw;
+  TViewWindow* aViewWindow = new TViewWindow(theDesktop);
+  aViewWindow->Initialize(this);
+
+  aViewWindow->setBackgroundColor( backgroundColor() );
+  aViewWindow->SetTrihedronSize( trihedronSize(), trihedronRelative() );
+
+  return aViewWindow;
+}
+
+int SVTK_Viewer::trihedronSize() const
+{
+  return myTrihedronSize;
+}
+
+bool SVTK_Viewer::trihedronRelative() const
+{
+  return myTrihedronRelative;
+}
+
+void SVTK_Viewer::setTrihedronSize( const int theSize, const bool theRelative )
+{
+  myTrihedronSize = theSize;
+  myTrihedronRelative = theRelative;
+
+  if (SUIT_ViewManager* aViewManager = getViewManager()) {
+    QPtrVector<SUIT_ViewWindow> aViews = aViewManager->getViews();
+    for (int i = 0; i < aViews.count(); i++) {
+      if (TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at(i))) {
+       aView->SetTrihedronSize(theSize, theRelative);
+      }
+    }
+  }
 }
 
 //==========================================================
@@ -82,7 +141,7 @@ void SVTK_Viewer::setViewManager(SUIT_ViewManager* theViewManager)
 {
   SUIT_ViewModel::setViewManager(theViewManager);
 
-  if(!theViewManager)
+  if ( !theViewManager )
     return;
 
   connect(theViewManager, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)), 
@@ -96,75 +155,39 @@ void SVTK_Viewer::setViewManager(SUIT_ViewManager* theViewManager)
 }
 
 //==========================================================
-void SVTK_Viewer::contextMenuPopup( QPopupMenu* thePopup )
+void
+SVTK_Viewer
+::contextMenuPopup( QPopupMenu* thePopup )
 {
   thePopup->insertItem( VTKViewer_Viewer::tr( "MEN_DUMP_VIEW" ), this, SLOT( onDumpView() ) );
   thePopup->insertItem( VTKViewer_Viewer::tr( "MEN_CHANGE_BACKGROUD" ), this, SLOT( onChangeBgColor() ) );
 
   thePopup->insertSeparator();
 
-  SVTK_ViewWindow* aView = (SVTK_ViewWindow*)(myViewManager->getActiveView());
-  if ( aView && !aView->getToolBar()->isVisible() )
-    thePopup->insertItem( VTKViewer_Viewer::tr( "MEN_SHOW_TOOLBAR" ), this, SLOT( onShowToolbar() ) );
-}
-
-//==========================================================
-void SVTK_Viewer::onMousePress(SUIT_ViewWindow* vw, QMouseEvent* event)
-{
-  if(SVTK_ViewWindow* aVW = dynamic_cast<SVTK_ViewWindow*>(vw)){
-    if(SVTK_RenderWindowInteractor* aRWI = aVW->getRWInteractor()){
-      switch(event->button()) {
-      case LeftButton:
-       aRWI->LeftButtonPressed(event) ;
-       break ;
-      case MidButton:
-       aRWI->MiddleButtonPressed(event) ;
-       break ;
-      case RightButton:
-       aRWI->RightButtonPressed(event) ;
-       break;
-      default:
-       break ;
-      }
+  if(TViewWindow* aView = dynamic_cast<TViewWindow*>(myViewManager->getActiveView())){
+    if ( !aView->getMainWindow()->getToolBar()->isVisible() ){
+      thePopup->insertItem( VTKViewer_Viewer::tr( "MEN_SHOW_TOOLBAR" ), this, SLOT( onShowToolbar() ) );
     }
   }
 }
 
+//==========================================================
+void 
+SVTK_Viewer
+::onMousePress(SUIT_ViewWindow* vw, QMouseEvent* event)
+{}
+
 //==========================================================
 void 
 SVTK_Viewer
 ::onMouseMove(SUIT_ViewWindow* vw, QMouseEvent* event)
-{
-  if(SVTK_ViewWindow* aVW = dynamic_cast<SVTK_ViewWindow*>(vw)){
-    if(SVTK_RenderWindowInteractor* aRWI = aVW->getRWInteractor()){
-      aRWI->MouseMove( event );
-    }
-  }
-}
+{}
 
 //==========================================================
 void 
 SVTK_Viewer
 ::onMouseRelease(SUIT_ViewWindow* vw, QMouseEvent* event)
-{
-  if(SVTK_ViewWindow* aVW = dynamic_cast<SVTK_ViewWindow*>(vw)){
-    if(SVTK_RenderWindowInteractor* aRWI = aVW->getRWInteractor()){
-      switch(event->button()) {
-      case LeftButton:
-       aRWI->LeftButtonReleased(event) ;
-       break ;
-      case MidButton:
-       aRWI->MiddleButtonReleased(event) ;
-       break ;
-      case RightButton:
-       aRWI->RightButtonReleased(event) ;
-       break;
-      default:
-       break ;
-      }
-    }
-  }
-}
+{}
 
 //==========================================================
 void 
@@ -184,24 +207,23 @@ SVTK_Viewer
   //!! To be done for view windows
 }
 
-void SVTK_Viewer::onDumpView()
+void
+SVTK_Viewer
+::onDumpView()
 {
-  SVTK_ViewWindow* aView = (SVTK_ViewWindow*)(myViewManager->getActiveView());
-  if ( aView )
+  if(SUIT_ViewWindow* aView = myViewManager->getActiveView())
     aView->onDumpView();
 }
 
 //==========================================================
-void SVTK_Viewer::onChangeBgColor()
+void
+SVTK_Viewer
+::onChangeBgColor()
 {
-  QPtrVector<SUIT_ViewWindow> aViews = myViewManager->getViews();
-  for(int i = 0, iEnd = aViews.size(); i < iEnd; i++)
-    if(SUIT_ViewWindow* aViewWindow = aViews.at(i))
-      if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow)){
-       QColor aColor = QColorDialog::getColor( aView->backgroundColor(), aView);
-       if ( aColor.isValid() )
-         aView->setBackgroundColor(aColor);
-      }
+  if(SUIT_ViewWindow* aView = myViewManager->getActiveView()){
+    QColor aColor = QColorDialog::getColor( backgroundColor(), aView);
+    setBackgroundColor(aColor);
+  }
 }
 
 //==========================================================
@@ -210,10 +232,11 @@ SVTK_Viewer
 ::onShowToolbar() 
 {
   QPtrVector<SUIT_ViewWindow> aViews = myViewManager->getViews();
-  for(int i = 0, iEnd = aViews.size(); i < iEnd; i++)
-    if(SUIT_ViewWindow* aViewWindow = aViews.at(i))
-      if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow))
-       aView->getToolBar()->show();    
+  for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){
+    if(TViewWindow* aView = dynamic_cast<TViewWindow*>(aViews.at(i))){
+      aView->getMainWindow()->getToolBar()->show();
+    }
+  }
 }
 
 //==========================================================
@@ -227,26 +250,30 @@ SVTK_Viewer
       return;
     if(vtkActorCollection* anActorCollection = aPrs->GetObjects()){
       // get SALOMEDS Study
-      _PTR(Study) aStudy(getStudyDS());
+      // 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)){
          // Set visibility flag
-         Handle(SALOME_InteractiveObject) anObj = anAct->getIO();
-         if(!anObj.IsNull() && anObj->hasEntry() && aStudy){
-           ToolsGUI::SetVisibility(aStudy,anObj->getEntry(),true,this);
-         }
+          // Temporarily commented to avoid awful dependecy on SALOMEDS
+          // 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);
+         //}
          // just display the object
          QPtrVector<SUIT_ViewWindow> aViews = myViewManager->getViews();
          for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){
-           if(SUIT_ViewWindow* aViewWindow = aViews.at(i)){
-             if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow)){
-               if(SVTK_RenderWindowInteractor* aRWI = aView->getRWInteractor()){
-                 aRWI->Display(anAct,false);
-                 if(anAct->IsSetCamera()){
-                   vtkRenderer* aRenderer =  aView->getRenderer();
-                   anAct->SetCamera( aRenderer->GetActiveCamera() );
-                 }
+           if(SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>(aViews.at(i))){
+             if(SVTK_View* aView = aViewWindow->getView()){
+               aView->Display(anAct,false);
+               if(anAct->IsSetCamera()){
+                 vtkRenderer* aRenderer = aView->getRenderer();
+                 anAct->SetCamera( aRenderer->GetActiveCamera() );
                }
              }
            }
@@ -268,25 +295,30 @@ SVTK_Viewer
       return;
     if(vtkActorCollection* anActorCollection = aPrs->GetObjects()){
       // get SALOMEDS Study
-      _PTR(Study) aStudy(getStudyDS());
+      // 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)){
          // Set visibility flag
-         Handle(SALOME_InteractiveObject) anObj = anAct->getIO();
-         if(!anObj.IsNull() && anObj->hasEntry() && aStudy){
-           ToolsGUI::SetVisibility(aStudy,anObj->getEntry(),false,this);
-         }
+          // Temporarily commented to avoid awful dependecy on SALOMEDS
+          // 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);
+         //}
          // just display the object
          QPtrVector<SUIT_ViewWindow> aViews = myViewManager->getViews();
          for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){
-           if(SUIT_ViewWindow* aViewWindow = aViews.at(i))
-             if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow))
-               if(SVTK_RenderWindowInteractor* aRWI = aView->getRWInteractor())
-                 if ( forced )
-                   aRWI->Remove(anAct,false);
-                 else
-                   aRWI->Erase(anAct,forced);
+           if(SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>(aViews.at(i)))
+             if(SVTK_View* aView = aViewWindow->getView())
+               if ( forced )
+                 aView->Remove(anAct,false);
+               else
+                 aView->Erase(anAct,forced);
          }
        }
     }
@@ -298,20 +330,26 @@ void
 SVTK_Viewer
 ::EraseAll( const bool forced )
 {
-  _PTR(Study) aStudy(getStudyDS());
+  // 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());
   QPtrVector<SUIT_ViewWindow> aViews = myViewManager->getViews();
   for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){
-    if(SUIT_ViewWindow* aViewWindow = aViews.at(i)){
-      if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow)){
+    if(SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>(aViews.at(i)))
+      if(SVTK_View* aView = aViewWindow->getView()){
        vtkRenderer* aRenderer =  aView->getRenderer();
        vtkActorCollection* anActorCollection = aRenderer->GetActors();
        anActorCollection->InitTraversal();
        while(vtkActor* anActor = anActorCollection->GetNextActor()){
          if(SALOME_Actor* anAct = SALOME_Actor::SafeDownCast(anActor)){
            // Set visibility flag
-           Handle(SALOME_InteractiveObject) anObj = anAct->getIO();
-           if(!anObj.IsNull() && anObj->hasEntry() && aStudy)
-             ToolsGUI::SetVisibility(aStudy,anObj->getEntry(),false,this);
+            // Temporarily commented to avoid awful dependecy on SALOMEDS
+            // 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(forced)
              aRenderer->RemoveActor(anAct);
            else{
@@ -328,7 +366,6 @@ SVTK_Viewer
          }
        }
       }
-    }
   }
   Repaint();
 }
@@ -340,16 +377,19 @@ SVTK_Viewer
 {
   SVTK_Prs* prs = new SVTK_Prs();
   if ( entry ) {
-    vtkRenderer* rnr =  ( (SVTK_ViewWindow*) getViewManager()->getActiveView() )->getRenderer();
-    vtkActorCollection* theActors = rnr->GetActors();
-    theActors->InitTraversal();
-    vtkActor* ac;
-    while( ( ac = theActors->GetNextActor() ) ) {
-      SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
-      if ( anActor && anActor->hasIO() && !strcmp( anActor->getIO()->getEntry(), entry ) ) {
-       prs->AddObject( ac );
+    if(SVTK_ViewWindow* aViewWindow = dynamic_cast<SVTK_ViewWindow*>(getViewManager()->getActiveView()))
+      if(SVTK_View* aView = aViewWindow->getView()){
+       vtkRenderer* aRenderer =  aView->getRenderer();
+       vtkActorCollection* theActors = aRenderer->GetActors();
+       theActors->InitTraversal();
+       vtkActor* ac;
+       while( ( ac = theActors->GetNextActor() ) ) {
+         SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
+         if ( anActor && anActor->hasIO() && !strcmp( anActor->getIO()->getEntry(), entry ) ) {
+           prs->AddObject( ac );
+         }
+       }
       }
-    }
   }
   return prs;
 }
@@ -377,10 +417,11 @@ SVTK_Viewer
   QPtrVector<SUIT_ViewWindow> aViews = myViewManager->getViews();
   for(int i = 0, iEnd = aViews.size(); i < iEnd; i++)
     if(SUIT_ViewWindow* aViewWindow = aViews.at(i))
-      if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow))
-       if(SVTK_RenderWindowInteractor* aRWI = aView->getRWInteractor())
-         if(!aRWI->isVisible( io ))
-           return false;
+      if(TViewWindow* aViewWnd = dynamic_cast<TViewWindow*>(aViewWindow))
+        if(SVTK_View* aView = aViewWnd->getView())
+          if(!aView->isVisible( io ))
+            return false;
+
   return true;
 }
 
@@ -392,16 +433,7 @@ SVTK_Viewer
 //  if (theUpdateTrihedron) onAdjustTrihedron();
   QPtrVector<SUIT_ViewWindow> aViews = myViewManager->getViews();
   for(int i = 0, iEnd = aViews.size(); i < iEnd; i++)
-    if(SUIT_ViewWindow* aViewWindow = aViews.at(i))
-      if(SVTK_ViewWindow* aView = dynamic_cast<SVTK_ViewWindow*>(aViewWindow))
-       if(SVTK_RenderWindow* aRW = aView->getRenderWindow())
-         aRW->update();
-}
-
-void 
-SVTK_Viewer
-::onSelectionChanged()
-{
-  emit selectionChanged();
+    if(TViewWindow* aViewWindow = dynamic_cast<TViewWindow*>(aViews.at(i)))
+      if(SVTK_View* aView = aViewWindow->getView())
+       aView->Repaint();
 }
-