X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FVTKViewer%2FVTKViewer_RenderWindowInteractor.cxx;h=88ba440a003eff26ca63daac81db9387992b1052;hb=refs%2Fheads%2Fngr%2Fpython3_dev_pv5.4;hp=daf93e15cb6c35a3af2ed82fcc1730827aab5d9e;hpb=9f1a66957ba9a2308f8fdc3f9397140af9df5fd0;p=modules%2Fgui.git diff --git a/src/VTKViewer/VTKViewer_RenderWindowInteractor.cxx b/src/VTKViewer/VTKViewer_RenderWindowInteractor.cxx index daf93e15c..88ba440a0 100755 --- a/src/VTKViewer/VTKViewer_RenderWindowInteractor.cxx +++ b/src/VTKViewer/VTKViewer_RenderWindowInteractor.cxx @@ -1,40 +1,35 @@ -// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D -// +// 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 +// // 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 -//#include -//#include -//#include - // VTK Includes #include #include @@ -54,7 +49,10 @@ #include // QT Includes -#include +#include +#include +#include +#include /*! Create new instance of VTKViewer_RenderWindowInteractor*/ VTKViewer_RenderWindowInteractor* VTKViewer_RenderWindowInteractor::New() @@ -118,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) ; @@ -214,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 @@ -347,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) { @@ -405,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 @@ -418,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 @@ -431,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 @@ -444,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 @@ -457,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 @@ -471,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 ); } } @@ -506,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 @@ -530,8 +522,8 @@ void VTKViewer_RenderWindowInteractor::ChangeRepresentationToWireframe(vtkActorC { using namespace VTK; ForEach(theCollection, - TSetFunction - (&VTKViewer_Actor::setDisplayMode,0)); + TSetFunction + (&VTKViewer_Actor::setDisplayMode,0)); emit RenderWindowModified(); } @@ -542,8 +534,20 @@ void VTKViewer_RenderWindowInteractor::ChangeRepresentationToSurface(vtkActorCol { using namespace VTK; ForEach(theCollection, - TSetFunction - (&VTKViewer_Actor::setDisplayMode,1)); + TSetFunction + (&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(theCollection, + TSetFunction + (&VTKViewer_Actor::setDisplayMode,3)); emit RenderWindowModified(); } @@ -566,8 +570,8 @@ void VTKViewer_RenderWindowInteractor::EraseAll() void VTKViewer_RenderWindowInteractor::DisplayAll() { using namespace VTK; - vtkActorCollection* aCollection = GetRenderer()->GetActors(); - ForEach(aCollection,TSetVisibility(true)); + ActorCollectionCopy aCopy(GetRenderer()->GetActors()); + ForEach(aCopy.GetActors(),TSetVisibility(true)); emit RenderWindowModified() ; } @@ -582,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(); } @@ -593,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(); @@ -623,6 +629,9 @@ void VTKViewer_RenderWindowInteractor::Display( VTKViewer_Actor* theActor, bool emit RenderWindowModified(); } +/*! + default key press event (empty implementation) +*/ void VTKViewer_RenderWindowInteractor::KeyPressed(QKeyEvent *event) { /// NOT_IMPLEMENTED @@ -640,7 +649,8 @@ struct TUpdateAction{ void VTKViewer_RenderWindowInteractor::Update() { using namespace VTK; vtkRenderer* aRen = GetRenderer(); - ForEach(aRen->GetActors(),TUpdateAction()); + ActorCollectionCopy aCopy(aRen->GetActors()); + ForEach(aCopy.GetActors(),TUpdateAction()); aRen->ResetCamera(); @@ -670,8 +680,8 @@ bool VTKViewer_RenderWindowInteractor::unHighlightAll(){ * \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) + VTKViewer_Actor* theMapActor, VTKViewer_Actor* theActor, + TUpdateActor theFun, bool hilight, bool update) { if(theMapIndex.Extent() == 0) return false; @@ -693,12 +703,12 @@ 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) + VTKViewer_Actor * theMapActor, + VTKViewer_Actor * theActor, + TUpdateActor theFun) { (*theFun)(theMapIndex,theMapActor,theActor); - float aPos[3]; + double aPos[3]; theMapActor->GetPosition(aPos); theActor->SetPosition(aPos); }