Salome HOME
updated copyright message
[modules/gui.git] / src / VTKViewer / VTKViewer_RenderWindowInteractor.cxx
old mode 100755 (executable)
new mode 100644 (file)
index db601ab..b25bca9
@@ -1,40 +1,35 @@
-// Copyright (C) 2005  OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
-// 
+// Copyright (C) 2007-2023  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
+//
 // 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 
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// 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 
+// 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/
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+
 #include "VTKViewer_RenderWindowInteractor.h"
 #include "VTKViewer_RenderWindow.h"
 #include "VTKViewer_InteractorStyle.h"
 #include "SUIT_ViewModel.h"
 #include "VTKViewer_ViewWindow.h"
 
-//#include "SUIT_Application.h"
-//#include "SUIT_Desktop.h"
-
-//#include "SALOME_Selection.h"
 #include "VTKViewer_Actor.h"
 #include "VTKViewer_Algorithm.h"
 #include "VTKViewer_Functor.h"
 
-//#include <stdio.h>
-//#include <stdlib.h>
-//#include <string.h>
-//#include <math.h>
-
 // VTK Includes
 #include <vtkAssemblyNode.h>
 #include <vtkActor.h>
 #include <vtkVertex.h>
 #include <vtkRendererCollection.h>
 #include <vtkPolyDataWriter.h>
+#include <vtkProperty.h>
 
 // QT Includes
-#include <qkeycode.h>
+#include <QTimer>
+#include <QMouseEvent>
+#include <QKeyEvent>
+#include <QContextMenuEvent>
 
 /*! Create new instance of VTKViewer_RenderWindowInteractor*/
 VTKViewer_RenderWindowInteractor* VTKViewer_RenderWindowInteractor::New() 
@@ -117,6 +116,11 @@ VTKViewer_RenderWindowInteractor::~VTKViewer_RenderWindowInteractor()
   myPointPicker->Delete();
 }
 
+/*!
+  Print interactor to stream
+  \param os - stream
+  \param indent
+*/
 void VTKViewer_RenderWindowInteractor::PrintSelf(ostream& os, vtkIndent indent) 
 {
   vtkRenderWindowInteractor::PrintSelf(os, indent) ;
@@ -213,34 +217,6 @@ void VTKViewer_RenderWindowInteractor::SetInteractorStyle(vtkInteractorObserver
   vtkRenderWindowInteractor::SetInteractorStyle(theInteractor);
 }
 
-
-/*
-void VTKViewer_RenderWindowInteractor::SetSelectionMode(Selection_Mode theMode)
-{
-  myCellActor->SetVisibility(false);
-  myEdgeActor->SetVisibility(false);
-  myPointActor->SetVisibility(false);
-
-  switch(theMode){
-  case ActorSelection:
-    this->SetPicker(myBasicPicker);
-    break;
-  case NodeSelection:
-    this->SetPicker(myPointPicker);
-    break;
-  case CellSelection:
-  case EdgeSelection:
-  case FaceSelection:
-  case VolumeSelection:
-  case EdgeOfCellSelection:
-    this->SetPicker(myCellPicker);
-    break;
-  }
-
-  myInteractorStyle->OnSelectionModeChanged();
-}
-*/
-
 /*!Sets selection properties.
  *\param theRed - red component of color
  *\param theGreen - green component of color
@@ -346,12 +322,14 @@ int VTKViewer_RenderWindowInteractor::CreateTimer(int vtkNotUsed(timertype))
   ///
   /// Start a one-shot timer for 10ms.
   ///
-  mTimer->start(10, TRUE) ;
+  mTimer->setSingleShot(true) ;
+  mTimer->start(10) ;
   return 1 ;
 }
 
-/**@see CreateTimer(int )
- *\retval 1
+/*! 
+  \sa CreateTimer(int )
+  \retval 1
  */
 int VTKViewer_RenderWindowInteractor::DestroyTimer(void)
 {
@@ -381,7 +359,7 @@ void VTKViewer_RenderWindowInteractor::TimerFunc()
     return ;
   }
   
-  ((vtkInteractorStyle*)this->InteractorStyle)->OnTimer() ;
+  ((vtkInteractorStyle*)this->InteractorStyle.Get())->OnTimer() ;
   emit RenderWindowModified() ;
 }
 
@@ -404,9 +382,9 @@ void VTKViewer_RenderWindowInteractor::LeftButtonPressed(const QMouseEvent *even
   if( ! this->Enabled ) {
     return ;
   }
-  myInteractorStyle->OnLeftButtonDown((event->state() & ControlButton), 
-                                     (event->state() & ShiftButton), 
-                                     event->x(), event->y());
+  myInteractorStyle->OnLeftButtonDown((event->modifiers() & Qt::ControlModifier), 
+                                      (event->modifiers() & Qt::ShiftModifier), 
+                                      event->x(), event->y());
 }
 
 /*!Reaction on left button releases.\n
@@ -417,9 +395,9 @@ void VTKViewer_RenderWindowInteractor::LeftButtonReleased(const QMouseEvent *eve
   if( ! this->Enabled ) {
     return ;
   }
-  myInteractorStyle->OnLeftButtonUp( (event->state() & ControlButton), 
-                                    (event->state() & ShiftButton), 
-                                    event->x(), event->y() ) ;
+  myInteractorStyle->OnLeftButtonUp( (event->modifiers() & Qt::ControlModifier), 
+                                     (event->modifiers() & Qt::ShiftModifier), 
+                                     event->x(), event->y() ) ;
 }
 
 /*!Reaction on middle button pressed.\n
@@ -430,9 +408,9 @@ void VTKViewer_RenderWindowInteractor::MiddleButtonPressed(const QMouseEvent *ev
   if( ! this->Enabled ) {
     return ;
   }
-  myInteractorStyle->OnMiddleButtonDown((event->state() & ControlButton), 
-                                       (event->state() & ShiftButton), 
-                                       event->x(), event->y() ) ;
+  myInteractorStyle->OnMiddleButtonDown((event->modifiers() & Qt::ControlModifier), 
+                                        (event->modifiers() & Qt::ShiftModifier), 
+                                        event->x(), event->y() ) ;
 }
 
 /*!Reaction on middle button released.\n
@@ -443,9 +421,9 @@ void VTKViewer_RenderWindowInteractor::MiddleButtonReleased(const QMouseEvent *e
   if( ! this->Enabled ) {
     return ;
   }
-  myInteractorStyle->OnMiddleButtonUp( (event->state() & ControlButton), 
-                                      (event->state() & ShiftButton), 
-                                      event->x(), event->y() ) ;
+  myInteractorStyle->OnMiddleButtonUp( (event->modifiers() & Qt::ControlModifier), 
+                                       (event->modifiers() & Qt::ShiftModifier), 
+                                       event->x(), event->y() ) ;
 }
 
 /*!Reaction on right button pressed.\n
@@ -456,9 +434,9 @@ void VTKViewer_RenderWindowInteractor::RightButtonPressed(const QMouseEvent *eve
   if( ! this->Enabled ) {
     return ;
   }
-  myInteractorStyle->OnRightButtonDown( (event->state() & ControlButton), 
-                                       (event->state() & ShiftButton), 
-                                       event->x(), event->y() ) ;
+  myInteractorStyle->OnRightButtonDown( (event->modifiers() & Qt::ControlModifier), 
+                                        (event->modifiers() & Qt::ShiftModifier), 
+                                        event->x(), event->y() ) ;
 }
 
 /*!Reaction on right button released.\n
@@ -470,14 +448,13 @@ void VTKViewer_RenderWindowInteractor::RightButtonReleased(const QMouseEvent *ev
     return ;
   }
   bool isOperation = myInteractorStyle->CurrentState() != VTK_INTERACTOR_STYLE_CAMERA_NONE;
-  myInteractorStyle->OnRightButtonUp( (event->state() & ControlButton),
-                                     (event->state() & ShiftButton),
-                                     event->x(), event->y() );
+  myInteractorStyle->OnRightButtonUp( (event->modifiers() & Qt::ControlModifier),
+                                      (event->modifiers() & Qt::ShiftModifier),
+                                      event->x(), event->y() );
   if ( !isOperation )
   {
     QContextMenuEvent aEvent( QContextMenuEvent::Mouse,
-                              event->pos(), event->globalPos(),
-                              event->state() );
+                              event->pos(), event->globalPos() );
     emit contextMenuRequested( &aEvent );
   }
 }
@@ -485,14 +462,14 @@ void VTKViewer_RenderWindowInteractor::RightButtonReleased(const QMouseEvent *ev
 /*!Reaction on button pressed.
  *\warning Do nothing.
  */
-void VTKViewer_RenderWindowInteractor::ButtonPressed(const QMouseEvent *event) {
+void VTKViewer_RenderWindowInteractor::ButtonPressed(const QMouseEvent* /*event*/) {
   return ;
 }
 
 /*!Reaction on button released..
  *\warning Do nothing.
  */
-void VTKViewer_RenderWindowInteractor::ButtonReleased(const QMouseEvent *event) {
+void VTKViewer_RenderWindowInteractor::ButtonReleased(const QMouseEvent* /*event*/) {
   return ;
 }
 
@@ -505,21 +482,37 @@ int VTKViewer_RenderWindowInteractor::GetDisplayMode() {
 void VTKViewer_RenderWindowInteractor::SetDisplayMode(int theMode) {
   if(theMode == 0)
     ChangeRepresentationToWireframe();
-  else
+  else if (theMode == 1)
     ChangeRepresentationToSurface();
+  else if (theMode == 2) {
+    ChangeRepresentationToSurfaceWithEdges();
+    theMode++;
+  }
   myDisplayMode = theMode;
 }
 
 /*!Change all actors to wireframe*/
 void VTKViewer_RenderWindowInteractor::ChangeRepresentationToWireframe()
 {
-  ChangeRepresentationToWireframe(GetRenderer()->GetActors());
+  using namespace VTK;
+  ActorCollectionCopy aCopy(GetRenderer()->GetActors());
+  ChangeRepresentationToWireframe(aCopy.GetActors());
 }
 
 /*!Change all actors to surface*/
 void VTKViewer_RenderWindowInteractor::ChangeRepresentationToSurface()
 {
-  ChangeRepresentationToSurface(GetRenderer()->GetActors());
+  using namespace VTK;
+  ActorCollectionCopy aCopy(GetRenderer()->GetActors());
+  ChangeRepresentationToSurface(aCopy.GetActors());
+}
+
+/*!Change all actors to surface with edges*/
+void VTKViewer_RenderWindowInteractor::ChangeRepresentationToSurfaceWithEdges()
+{
+  using namespace VTK;
+  ActorCollectionCopy aCopy(GetRenderer()->GetActors());
+  ChangeRepresentationToSurfaceWithEdges(aCopy.GetActors());
 }
 
 /*!Change all actors from \a theCollection to wireframe and
@@ -529,8 +522,8 @@ void VTKViewer_RenderWindowInteractor::ChangeRepresentationToWireframe(vtkActorC
 {
   using namespace VTK;
   ForEach<VTKViewer_Actor>(theCollection,
-                       TSetFunction<VTKViewer_Actor,int>
-                       (&VTKViewer_Actor::setDisplayMode,0));
+                        TSetFunction<VTKViewer_Actor,int>
+                        (&VTKViewer_Actor::setDisplayMode,0));
   emit RenderWindowModified();
 }
 
@@ -541,8 +534,20 @@ void VTKViewer_RenderWindowInteractor::ChangeRepresentationToSurface(vtkActorCol
 {
   using namespace VTK;
   ForEach<VTKViewer_Actor>(theCollection,
-                       TSetFunction<VTKViewer_Actor,int>
-                       (&VTKViewer_Actor::setDisplayMode,1));
+                        TSetFunction<VTKViewer_Actor,int>
+                        (&VTKViewer_Actor::setDisplayMode,1));
+  emit RenderWindowModified();
+}
+
+/*!Change all actors from \a theCollection to surface with edges and
+ * emit render window modified.
+ */
+void VTKViewer_RenderWindowInteractor::ChangeRepresentationToSurfaceWithEdges(vtkActorCollection* theCollection)
+{
+  using namespace VTK;
+  ForEach<VTKViewer_Actor>(theCollection,
+                        TSetFunction<VTKViewer_Actor,int>
+                        (&VTKViewer_Actor::setDisplayMode,3));
   emit RenderWindowModified();
 }
 
@@ -565,14 +570,14 @@ void VTKViewer_RenderWindowInteractor::EraseAll()
 void VTKViewer_RenderWindowInteractor::DisplayAll()
 {
   using namespace VTK;
-  vtkActorCollection* aCollection = GetRenderer()->GetActors();
-  ForEach<VTKViewer_Actor>(aCollection,TSetVisibility<VTKViewer_Actor>(true));
+  ActorCollectionCopy aCopy(GetRenderer()->GetActors());
+  ForEach<VTKViewer_Actor>(aCopy.GetActors(),TSetVisibility<VTKViewer_Actor>(true));
 
   emit RenderWindowModified() ;
 }
 
 /*!Do nothing*/
-void VTKViewer_RenderWindowInteractor::Erase( VTKViewer_Actor* SActor, bool update)
+void VTKViewer_RenderWindowInteractor::Erase( VTKViewer_Actor* /*SActor*/, bool /*update*/)
 {
 }
 
@@ -581,7 +586,7 @@ void VTKViewer_RenderWindowInteractor::Remove( VTKViewer_Actor* SActor, bool upd
 {
   if ( SActor != 0 )
   {
-    GetRenderer()->RemoveProp( SActor );
+    GetRenderer()->RemoveViewProp( SActor );
     if ( updateViewer )
       emit RenderWindowModified();
   }
@@ -592,8 +597,10 @@ void VTKViewer_RenderWindowInteractor::Remove( VTKViewer_Actor* SActor, bool upd
  */
 void VTKViewer_RenderWindowInteractor::RemoveAll( const bool updateViewer )
 {
+  using namespace VTK;
   vtkRenderer* aRenderer = GetRenderer();
-  vtkActorCollection* anActors = aRenderer->GetActors();
+  ActorCollectionCopy aCopy(aRenderer->GetActors());
+  vtkActorCollection* anActors = aCopy.GetActors();
   if ( anActors )
   {
     anActors->InitTraversal();
@@ -622,7 +629,10 @@ void VTKViewer_RenderWindowInteractor::Display( VTKViewer_Actor* theActor, bool
     emit RenderWindowModified();
 }
 
-void VTKViewer_RenderWindowInteractor::KeyPressed(QKeyEvent *event)
+/*!
+  default key press event (empty implementation)
+*/
+void VTKViewer_RenderWindowInteractor::KeyPressed(QKeyEvent* /*event*/)
 {
   /// NOT_IMPLEMENTED
 }
@@ -639,7 +649,8 @@ struct TUpdateAction{
 void VTKViewer_RenderWindowInteractor::Update() {
   using namespace VTK;
   vtkRenderer* aRen = GetRenderer();
-  ForEach<vtkActor>(aRen->GetActors(),TUpdateAction());
+  ActorCollectionCopy aCopy(aRen->GetActors());
+  ForEach<vtkActor>(aCopy.GetActors(),TUpdateAction());
 
   aRen->ResetCamera();
 
@@ -668,9 +679,9 @@ bool VTKViewer_RenderWindowInteractor::unHighlightAll(){
  * else sets visibility to false.
  * \li Emit render window modified, if flag \a update - true.
  */
-bool VTKViewer_RenderWindowInteractor::highlight(const TColStd_IndexedMapOfInteger& theMapIndex,
-                                                VTKViewer_Actor* theMapActor, VTKViewer_Actor* theActor,
-                                                TUpdateActor theFun, bool hilight, bool update)
+bool VTKViewer_RenderWindowInteractor::highlight(const TIndexedMapOfVtkId& theMapIndex,
+                                                 VTKViewer_Actor* theMapActor, VTKViewer_Actor* theActor,
+                                                 TUpdateActor theFun, bool hilight, bool update)
 {
   if(theMapIndex.Extent() == 0) return false;
 
@@ -691,13 +702,13 @@ bool VTKViewer_RenderWindowInteractor::highlight(const TColStd_IndexedMapOfInteg
 }
 
 /*!Sets actors data.*/
-void VTKViewer_RenderWindowInteractor::setActorData(const TColStd_IndexedMapOfInteger& theMapIndex,
-                                                   VTKViewer_Actor * theMapActor,
-                                                   VTKViewer_Actor * theActor,
-                                                   TUpdateActor theFun)
+void VTKViewer_RenderWindowInteractor::setActorData(const TIndexedMapOfVtkId& theMapIndex,
+                                                    VTKViewer_Actor * theMapActor,
+                                                    VTKViewer_Actor * theActor,
+                                                    TUpdateActor theFun)
 {
   (*theFun)(theMapIndex,theMapActor,theActor);
-  float aPos[3];
+  double aPos[3];
   theMapActor->GetPosition(aPos);
   theActor->SetPosition(aPos);
 }