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=2d7c1848056cc0e0b2e11fe0d0debc33a9460665;hpb=4a44de22b62d2855f9c8b77131a30ad09855c0dc;p=modules%2Fgui.git diff --git a/src/SVTK/SVTK_Selector.cxx b/src/SVTK/SVTK_Selector.cxx index 2d7c18480..51b32f21e 100644 --- a/src/SVTK/SVTK_Selector.cxx +++ b/src/SVTK/SVTK_Selector.cxx @@ -1,60 +1,118 @@ -// SALOME SALOMEGUI : implementation of desktop and GUI kernel +// 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 // -// 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// 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 -#include "SALOME_Actor.h" -#include "SVTK_ViewModel.h" -#include "SVTK_ViewWindow.h" -#include "SVTK_SelectorDef.h" -#include "utilities.h" +/*! + \return new SVTK_Selector +*/ +SVTK_Selector* +SVTK_Selector +::New() +{ + return new SVTK_SelectorDef(); +} +/*! + 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(); } +/*! + Destructor +*/ SVTK_SelectorDef ::~SVTK_SelectorDef() { } +/*! + To invoke selectionChanged signals +*/ +void +SVTK_SelectorDef +::StartPickCallback() +{ + this->InvokeEvent(vtkCommand::StartPickEvent,NULL); +} + +/*! + To invoke selectionChanged signals +*/ +void +SVTK_SelectorDef +::EndPickCallback() +{ + this->InvokeEvent(vtkCommand::EndPickEvent,NULL); +} + +/*! + To change current Selection_Mode (as outside effect, it invokes selectionChange signal) +*/ void SVTK_SelectorDef ::SetSelectionMode(Selection_Mode theMode) { - mySelectionMode = theMode; + if(mySelectionMode != theMode){ + mySelectionMode = theMode; + myMapIOSubIndex.clear(); + this->EndPickCallback(); + } } +/*! + Clear selection +*/ void SVTK_SelectorDef ::ClearIObjects() @@ -64,14 +122,19 @@ SVTK_SelectorDef myMapIOSubIndex.clear(); } -//---------------------------------------------------------------------------- +/*! + \return true if the SALOME_InteractiveObject presents into selection +*/ bool SVTK_SelectorDef ::IsSelected(const Handle(SALOME_InteractiveObject)& theIO) const { - return myIObjects.find(theIO) != myIObjects.end(); + return !theIO.IsNull() && (myIObjects.find(theIO) != myIObjects.end()); } +/*! + \return true if the SALOME_Actor presents into selection +*/ bool SVTK_SelectorDef ::IsSelected(SALOME_Actor* theActor) const @@ -80,6 +143,10 @@ SVTK_SelectorDef return IsSelected(anIO) && myIO2Actors.find(anIO) != myIO2Actors.end(); } +/*! + \return corresponding SALOME_Actor for SALOME_InteractiveObject + \param theIO - SALOME_InteractiveObject +*/ SALOME_Actor* SVTK_SelectorDef ::GetActor(const Handle(SALOME_InteractiveObject)& theIO) const @@ -90,7 +157,10 @@ SVTK_SelectorDef return NULL; } -//---------------------------------------------------------------------------- +/*! + Adds SALOME_InteractiveObject into selection + \param theIO - SALOME_InteractiveObject +*/ bool SVTK_SelectorDef ::AddIObject(const Handle(SALOME_InteractiveObject)& theIO) @@ -102,6 +172,10 @@ SVTK_SelectorDef return false; } +/*! + Adds SALOME_Actor into selection + \param theActor - SALOME_Actor +*/ bool SVTK_SelectorDef ::AddIObject(SALOME_Actor* theActor) @@ -119,7 +193,10 @@ SVTK_SelectorDef return !anIsIOBound || !anIsActorBound; } -//---------------------------------------------------------------------------- +/*! + Removes SALOME_InteractiveObject from selection + \param theIO - SALOME_InteractiveObject +*/ bool SVTK_SelectorDef ::RemoveIObject(const Handle(SALOME_InteractiveObject)& theIO) @@ -133,6 +210,10 @@ SVTK_SelectorDef return anIsIOBound; } +/*! + Removes SALOME_Actor from selection + \param theActor - SALOME_Actor +*/ bool SVTK_SelectorDef ::RemoveIObject(SALOME_Actor* theActor) @@ -146,7 +227,9 @@ SVTK_SelectorDef return RemoveIObject(anIO) || anIsActorBound; } -//---------------------------------------------------------------------------- +/*! + \return list of all SALOME_InteractiveObject presenting in selection +*/ const SALOME_ListIO& SVTK_SelectorDef ::StoredIObjects() const @@ -160,6 +243,9 @@ SVTK_SelectorDef return myIObjectList; } +/*! + \return number of selected objects +*/ int SVTK_SelectorDef ::IObjectCount() const @@ -167,6 +253,10 @@ SVTK_SelectorDef return myIObjects.size(); } +/*! + \return true if the SALOME_InteractiveObject has a subselection + \param theIO - SALOME_InteractiveObject +*/ bool SVTK_SelectorDef ::HasIndex( const Handle(SALOME_InteractiveObject)& theIO) const @@ -174,10 +264,14 @@ SVTK_SelectorDef return myMapIOSubIndex.find(theIO) != myMapIOSubIndex.end(); } +/*! + Gets indices of subselection for SALOME_InteractiveObject + \param theIO - SALOME_InteractiveObject +*/ 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()) @@ -186,24 +280,26 @@ SVTK_SelectorDef theIndex.Clear(); } +/*! + \return true if the index presents in subselection + \param theIO - SALOME_InteractiveObject + \param theIndex - index +*/ 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){ @@ -222,15 +318,20 @@ removeIndex(TColStd_IndexedMapOfInteger& theMapIndex, theMapIndex = aNewMap; } } - return anId; + return anId != 0; } - +/*! + Changes indices of subselection for SALOME_InteractiveObject + \param theIO - SALOME_InteractiveObject + \param theIndices - indices + \param theIsModeShift - if it is false, then map will be cleared before indices are added +*/ 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()){ @@ -243,21 +344,29 @@ SVTK_SelectorDef if(!theIsModeShift) aMapIndex.Clear(); - for(int i = 0, iEnd = theIndices.Extent(); i < iEnd; i++) + for(int i = 1, iEnd = theIndices.Extent(); i <= iEnd; i++) aMapIndex.Add(theIndices(i)); - if(aMapIndex.IsEmpty()) - RemoveIObject(theIO); + if(aMapIndex.IsEmpty()) { + myMapIOSubIndex.erase(theIO); + return false; + } - return !aMapIndex.IsEmpty(); + return true; } +/*! + Changes indices of subselection for SALOME_InteractiveObject + \param theIO - SALOME_InteractiveObject + \param theIndices - indices + \param theIsModeShift - if it is false, then map will be cleared before indices are added +*/ 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()){ @@ -274,18 +383,26 @@ SVTK_SelectorDef for(; anIter.More(); anIter.Next()) aMapIndex.Add(anIter.Key()); - if(aMapIndex.IsEmpty()) - RemoveIObject(theIO); + if(aMapIndex.IsEmpty()) { + myMapIOSubIndex.erase(theIO); + return false; + } - return !aMapIndex.IsEmpty(); + return true; } +/*! + Changes indices of subselection for SALOME_InteractiveObject + \param theIO - SALOME_InteractiveObject + \param theIndex - index + \param theIsModeShift - if it is false, then map will be cleared before indices are added +*/ 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()){ @@ -295,27 +412,32 @@ 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()) - RemoveIObject(theIO); + if ( aMapIndex.IsEmpty() ) + myMapIOSubIndex.erase( theIO ); return false; } +/*! + Removes index of subselection for SALOME_InteractiveObject + \param theIO - SALOME_InteractiveObject + \param theIndex - index +*/ void SVTK_SelectorDef ::RemoveIndex( const Handle(SALOME_InteractiveObject)& theIO, - int theIndex) + int theIndex) { if(IsIndexSelected(theIO,theIndex)){ TMapIOSubIndex::iterator anIter = myMapIOSubIndex.find(theIO); @@ -324,9 +446,160 @@ SVTK_SelectorDef } } +/*! + Clears all indices of subselection +*/ void SVTK_SelectorDef ::ClearIndex() { myMapIOSubIndex.clear(); } + +/*! + To apply a filter on the selection + \param theFilter - new filter +*/ +void +SVTK_SelectorDef +::SetFilter(const Handle(VTKViewer_Filter)& theFilter) +{ + myFilters.insert(TFilters::value_type(theFilter->GetId(),theFilter)); +} + +/*! + \return true if filter with given number is applyed + \param theId - filter id +*/ +bool +SVTK_SelectorDef +::IsFilterPresent(const TFilterID theId) const +{ + return myFilters.find(theId) != myFilters.end(); +} + +/*! + To remove a filter from the selection + \param theId - filter id +*/ +void +SVTK_SelectorDef +::RemoveFilter(const TFilterID theId) +{ + if(IsFilterPresent(theId)) + myFilters.erase(theId); +} + +/*! + \return true if the index satisfy installed filters + \param theActor - actor + \param theId - filter id + \param theIsNode - whether it is node +*/ +bool +SVTK_SelectorDef +::IsValid(SALOME_Actor* theActor, + const TFilterID theId, + const bool theIsNode) const +{ + TFilters::const_iterator anIter = myFilters.begin(); + for(; anIter != myFilters.end(); ++anIter){ + const Handle(VTKViewer_Filter)& aFilter = anIter->second; + if(theIsNode == aFilter->IsNodeFilter() && + !aFilter->IsValid(theActor,theId)) + return false; + } + return true; +} + +/*! + \return filter by it's id + \param theId - filter id +*/ +Handle(VTKViewer_Filter) +SVTK_SelectorDef +::GetFilter(const TFilterID theId) const +{ + TFilters::const_iterator anIter = myFilters.find(theId); + if(anIter != myFilters.end()){ + const Handle(VTKViewer_Filter)& aFilter = anIter->second; + return aFilter; + } + 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; +}