X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSVTK%2FSVTK_Selector.cxx;h=51b32f21efb7c7cde2c229ad30b723669cd4ca5d;hb=refs%2Fheads%2Fngr%2Fpython3_dev_pv5.4;hp=78c94989d531f51a6a8eb21682456e7e94d828cd;hpb=399155730966dfc225fbb24f66204b05664385f2;p=modules%2Fgui.git diff --git a/src/SVTK/SVTK_Selector.cxx b/src/SVTK/SVTK_Selector.cxx index 78c94989d..51b32f21e 100644 --- a/src/SVTK/SVTK_Selector.cxx +++ b/src/SVTK/SVTK_Selector.cxx @@ -1,40 +1,45 @@ -// SALOME SALOMEGUI : implementation of desktop and GUI kernel +// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE // -// Copyright (C) 2003 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 -// 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/ or email : webmaster.salome@opencascade.com +// 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, 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 +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // + +// SALOME SALOMEGUI : implementation of desktop and GUI kernel // File : SALOME_Selection.cxx // Author : Nicolas REJNERI -// Module : SALOME -// $Header$ - #include "SVTK_SelectorDef.h" +#include + #include "SALOME_Actor.h" +#include +#include + #include #include #include +#include +#include + /*! \return new SVTK_Selector @@ -50,9 +55,17 @@ SVTK_Selector Default constructor */ SVTK_SelectorDef -::SVTK_SelectorDef() +::SVTK_SelectorDef(): + myPicker(vtkPicker::New()), + myCellPicker(vtkCellPicker::New()) { mySelectionMode = ActorSelection; + myDynamicPreselection = true; + myPreselectionEnabled = true; + mySelectionEnabled = true; + + myPicker->Delete(); + myCellPicker->Delete(); } /*! @@ -258,7 +271,7 @@ SVTK_SelectorDef void SVTK_SelectorDef ::GetIndex( const Handle(SALOME_InteractiveObject)& theIO, - TColStd_IndexedMapOfInteger& theIndex) + TColStd_IndexedMapOfInteger& theIndex) { TMapIOSubIndex::const_iterator anIter = myMapIOSubIndex.find(theIO); if(anIter != myMapIOSubIndex.end()) @@ -275,21 +288,18 @@ SVTK_SelectorDef bool SVTK_SelectorDef ::IsIndexSelected(const Handle(SALOME_InteractiveObject)& theIO, - int theIndex) const + int theIndex) const { TMapIOSubIndex::const_iterator anIter = myMapIOSubIndex.find(theIO); if(anIter != myMapIOSubIndex.end()){ const TColStd_IndexedMapOfInteger& aMapIndex = anIter->second.myMap; - return aMapIndex.Contains(theIndex); + return aMapIndex.Contains( theIndex ) == Standard_True; } return false; } -static -bool -removeIndex(TColStd_IndexedMapOfInteger& theMapIndex, - const int theIndex) +static bool removeIndex(TColStd_IndexedMapOfInteger& theMapIndex, const int theIndex) { int anId = theMapIndex.FindIndex(theIndex); // i==0 if Index is not in the MapIndex if(anId){ @@ -308,7 +318,7 @@ removeIndex(TColStd_IndexedMapOfInteger& theMapIndex, theMapIndex = aNewMap; } } - return anId; + return anId != 0; } /*! @@ -320,8 +330,8 @@ removeIndex(TColStd_IndexedMapOfInteger& theMapIndex, bool SVTK_SelectorDef ::AddOrRemoveIndex( const Handle(SALOME_InteractiveObject)& theIO, - const TColStd_IndexedMapOfInteger& theIndices, - bool theIsModeShift) + const TColStd_IndexedMapOfInteger& theIndices, + bool theIsModeShift) { TMapIOSubIndex::iterator aMapIter = myMapIOSubIndex.find(theIO); if(aMapIter == myMapIOSubIndex.end()){ @@ -355,8 +365,8 @@ SVTK_SelectorDef bool SVTK_SelectorDef ::AddOrRemoveIndex( const Handle(SALOME_InteractiveObject)& theIO, - const TColStd_MapOfInteger& theIndices, - bool theIsModeShift) + const TColStd_MapOfInteger& theIndices, + bool theIsModeShift) { TMapIOSubIndex::iterator aMapIter = myMapIOSubIndex.find(theIO); if(aMapIter == myMapIOSubIndex.end()){ @@ -391,8 +401,8 @@ SVTK_SelectorDef bool SVTK_SelectorDef ::AddOrRemoveIndex( const Handle(SALOME_InteractiveObject)& theIO, - int theIndex, - bool theIsModeShift) + int theIndex, + bool theIsModeShift) { TMapIOSubIndex::iterator anIter = myMapIOSubIndex.find(theIO); if(anIter == myMapIOSubIndex.end()){ @@ -402,18 +412,18 @@ SVTK_SelectorDef } TColStd_IndexedMapOfInteger& aMapIndex = anIter->second.myMap; - bool anIsConatains = aMapIndex.Contains(theIndex); - if(anIsConatains) - removeIndex(aMapIndex,theIndex); + bool anIsConatains = aMapIndex.Contains( theIndex ) == Standard_True; + if ( anIsConatains ) + removeIndex( aMapIndex, theIndex ); - if(!theIsModeShift) + if ( !theIsModeShift ) aMapIndex.Clear(); - if(!anIsConatains) + if ( !anIsConatains ) aMapIndex.Add( theIndex ); - if( aMapIndex.IsEmpty()) - myMapIOSubIndex.erase(theIO); + if ( aMapIndex.IsEmpty() ) + myMapIOSubIndex.erase( theIO ); return false; } @@ -427,7 +437,7 @@ SVTK_SelectorDef void SVTK_SelectorDef ::RemoveIndex( const Handle(SALOME_InteractiveObject)& theIO, - int theIndex) + int theIndex) { if(IsIndexSelected(theIO,theIndex)){ TMapIOSubIndex::iterator anIter = myMapIOSubIndex.find(theIO); @@ -489,8 +499,8 @@ SVTK_SelectorDef bool SVTK_SelectorDef ::IsValid(SALOME_Actor* theActor, - const TFilterID theId, - const bool theIsNode) const + const TFilterID theId, + const bool theIsNode) const { TFilters::const_iterator anIter = myFilters.begin(); for(; anIter != myFilters.end(); ++anIter){ @@ -518,3 +528,78 @@ SVTK_SelectorDef return Handle(VTKViewer_Filter)(); } +vtkActorCollection* +SVTK_SelectorDef +::Pick(const SVTK_SelectionEvent* theEvent, vtkRenderer* theRenderer) const +{ + vtkActorCollection* aListActors = NULL; + + if ( GetDynamicPreSelection() ) { + myCellPicker->Pick(theEvent->myX, + theEvent->myY, + 0.0, + theRenderer); + + aListActors = myCellPicker->GetActors(); + } + + if ( !aListActors || !aListActors->GetNumberOfItems() ) { + myPicker->Pick(theEvent->myX, + theEvent->myY, + 0.0, + theRenderer); + aListActors = myPicker->GetActors(); + } + + return aListActors; +} + +void +SVTK_SelectorDef +::SetTolerance(const double& theTolerance) +{ + myPicker->SetTolerance(theTolerance); + myCellPicker->SetTolerance(theTolerance); +} + +void +SVTK_SelectorDef +::SetDynamicPreSelection( bool theIsDynPreselect ) +{ + myDynamicPreselection = theIsDynPreselect; +} + +bool +SVTK_SelectorDef +::GetDynamicPreSelection() const +{ + return myDynamicPreselection; +} + +void +SVTK_SelectorDef +::SetPreSelectionEnabled( bool theEnabled ) +{ + myPreselectionEnabled = theEnabled; +} + +bool +SVTK_SelectorDef +::IsPreSelectionEnabled() const +{ + return mySelectionEnabled && myPreselectionEnabled; +} + +void +SVTK_SelectorDef +::SetSelectionEnabled( bool theEnabled ) +{ + mySelectionEnabled = theEnabled; +} + +bool +SVTK_SelectorDef +::IsSelectionEnabled() const +{ + return mySelectionEnabled; +}