SVTK_Selector.h
SVTK_SpaceMouse.h
SVTK_Utils.h
+ SVTK_Hash.h
)
# header files / no moc processing / internal
if(mySelectionMode != ActorSelection){
TColStd_IndexedMapOfInteger aMapIndex;
mySelector->GetIndex( getIO(), aMapIndex );
- switch( mySelectionMode ){
+ switch( mySelectionMode ) {
case NodeSelection:
- case EdgeOfCellSelection:
myHighlightActor->GetProperty()->SetRepresentationToPoints();
myHighlightActor->MapPoints( this, aMapIndex );
break;
myHighlightActor->GetProperty()->SetRepresentationToSurface();
myHighlightActor->MapCells( this, aMapIndex );
break;
+ case EdgeOfCellSelection:
+ SVTK_IndexedMapOfIds aMapCompositeIndex;
+ mySelector->GetCompositeIndex( getIO(), aMapCompositeIndex );
+ myHighlightActor->GetProperty()->SetRepresentationToWireframe();
+ myHighlightActor->MapEdge( this, aMapCompositeIndex );
+ break;
}
myHighlightActor->SetVisibility( GetVisibility() && theIsHighlight );
}
int anEdgeId = GetEdgeAndNodesId(this,myCellPicker.GetPointer(),anObjId,aFNId,aSNId);
myIsPreselected = anEdgeId < 0;
if(myIsPreselected){
- const TColStd_IndexedMapOfInteger& aMapIndex = myPreHighlightActor->GetMapIndex();
- int anExtent = aMapIndex.Extent();
- anIsChanged |= (anExtent == 0 || anExtent == 1);
- anIsChanged |= (anExtent == 2 && (anObjId != aMapIndex(1) || anEdgeId != aMapIndex(2)));
- if(anIsChanged){
- TColStd_IndexedMapOfInteger aMapIndex;
- aMapIndex.Add( anObjId );
- aMapIndex.Add( anEdgeId );
-
+ int aFNObjId = GetNodeObjId( aFNId );
+ int aSNObjId = GetNodeObjId( aSNId );
+ const SVTK_IndexedMapOfIds& aMapIds = myPreHighlightActor->GetMapCompositeIndex();
+ int anExtent = aMapIds.Extent();
+ anIsChanged |= (anExtent == 0 || (anExtent > 0 && aMapIds(1).size() == 2 &&
+ (aFNObjId != aMapIds(1)[0] || aSNObjId != aMapIds(1)[1] ) ) );
+ if( anIsChanged ) {
+ SVTK_IndexedMapOfIds aMapIds;
+ SVTK_ListOfInteger aCompositeID;
+ aCompositeID.push_back( aFNObjId );
+ aCompositeID.push_back( aSNObjId );
+ aMapIds.Add( aCompositeID );
myPreHighlightActor->GetProperty()->SetRepresentationToWireframe();
- myPreHighlightActor->MapEdge( this, aMapIndex );
+ myPreHighlightActor->MapEdge( this, aMapIds );
}
myPreHighlightActor->SetVisibility( true );
}
const SVTK_AreaPicker::TVectorIdsMap& aVectorIdsMap = myCellAreaPicker->GetCellIdsMap();
SVTK_AreaPicker::TVectorIdsMap::const_iterator aMapIter = aVectorIdsMap.find(this);
- TColStd_MapOfInteger anIndexes;
+ SVTK_IndexedMapOfIds anIndexes;
if(aMapIter != aVectorIdsMap.end()){
const SVTK_AreaPicker::TVectorIds& aVectorIds = aMapIter->second;
vtkIdType anEnd = aVectorIds.size();
int aFNId, aSNId;
int anEdgeId = GetEdgeAndNodesId(this,myCellPicker.GetPointer(),anObjId,aFNId,aSNId);
if( anEdgeId < 0 ) {
- anIndexes.Add(GetNodeObjId(aFNId));
- anIndexes.Add(GetNodeObjId(aSNId));
+ SVTK_ListOfInteger aCompositeID;
+ aCompositeID.push_back( GetNodeObjId( aFNId ) );
+ aCompositeID.push_back( GetNodeObjId( aSNId ) );
+ anIndexes.Add( aCompositeID );
}
}
}
if ( hasIO() ) {
if( !anIndexes.IsEmpty() ) {
- mySelector->AddOrRemoveIndex( myIO, anIndexes, anIsShift );
+ mySelector->AddOrRemoveCompositeIndex( myIO, anIndexes, anIsShift );
mySelector->AddIObject( this );
anIndexes.Clear();
}
int aFNId, aSNId;
int anEdgeId = GetEdgeAndNodesId(this,myCellPicker.GetPointer(),anObjId,aFNId,aSNId);
if( hasIO() && anEdgeId < 0 ) {
- bool isFNSelected = mySelector->IsIndexSelected( myIO, GetNodeObjId(aFNId) );
- bool isSNSelected = mySelector->IsIndexSelected( myIO, GetNodeObjId(aSNId) );
- if ( isFNSelected == isSNSelected ) {
- mySelector->AddOrRemoveIndex( myIO, GetNodeObjId(aFNId), anIsShift );
- mySelector->AddOrRemoveIndex( myIO, GetNodeObjId(aSNId), true );
- }
- else if ( isFNSelected ) {
- mySelector->AddOrRemoveIndex( myIO, GetNodeObjId(aSNId), anIsShift );
- }
- else if ( isSNSelected ) {
- mySelector->AddOrRemoveIndex( myIO, GetNodeObjId(aFNId), anIsShift );
- }
- mySelector->AddIObject( this );
+ SVTK_ListOfInteger aCompositeID;
+ aCompositeID.push_back( GetNodeObjId( aFNId ) );
+ aCompositeID.push_back( GetNodeObjId( aSNId ) );
+ mySelector->AddOrRemoveCompositeIndex( myIO, aCompositeID, anIsShift );
+ mySelector->AddIObject( this );
}
}
}
return myMapIndex;
}
+
+const SVTK_IndexedMapOfIds&
+SVTK_Actor
+::GetMapCompositeIndex() const
+{
+ return myMapCompositeIndex;
+}
+
void
SVTK_Actor
::MapCells(SALOME_Actor* theMapActor,
myMapIndex = theMapIndex;
}
+void
+SVTK_Actor
+::MapEdge( SALOME_Actor* theMapActor,
+ const SVTK_IndexedMapOfIds& theMapCompositeIndex) {
+ myUnstructuredGrid->Initialize();
+ myUnstructuredGrid->Allocate();
+
+ vtkUnstructuredGrid * aSourceGrid = ( vtkUnstructuredGrid * )theMapActor->GetInput();
+ GetSource()->SetPoints( aSourceGrid->GetPoints() );
+
+ int aNbOfParts = theMapCompositeIndex.Extent();
+ for(int ind = 1; ind <= aNbOfParts; ind++){
+ std::vector<int> aNodesIds = theMapCompositeIndex( ind );
+ vtkSmartPointer<vtkIdList> ids = vtkSmartPointer<vtkIdList>::New();
+ ids->InsertNextId(theMapActor->GetNodeVtkId( aNodesIds[0] ) );
+ ids->InsertNextId(theMapActor->GetNodeVtkId( aNodesIds[1] ) );
+ myUnstructuredGrid->InsertNextCell(VTK_LINE,ids);
+ }
+
+ UnShrink();
+ if(theMapActor->IsShrunk()){
+ SetShrinkFactor(theMapActor->GetShrinkFactor());
+ SetShrink();
+ }
+
+ myMapCompositeIndex = theMapCompositeIndex;
+}
+
/*!
To publish the actor an all its internal devices
*/
#ifndef SVTK_ACTOR_H
#define SVTK_ACTOR_H
+#include "SVTK_Selector.h"
#include <TColStd_IndexedMapOfInteger.hxx>
class vtkRenderer;
MapEdge(SALOME_Actor* theMapActor,
const TColStd_IndexedMapOfInteger& theMapIndex);
+//! Allow to recostruct selected edges from source SALOME_Actor and map of subindexes using corner node ids
+ virtual void
+ MapEdge(SALOME_Actor* theMapActor,
+ const SVTK_IndexedMapOfIds& theMapCompositeIndex);
+
+
const TColStd_IndexedMapOfInteger&
GetMapIndex() const;
+ const SVTK_IndexedMapOfIds&
+ GetMapCompositeIndex() const;
+
protected:
TColStd_IndexedMapOfInteger myMapIndex;
+ SVTK_IndexedMapOfIds myMapCompositeIndex;
vtkSmartPointer<vtkUnstructuredGrid> myUnstructuredGrid;
--- /dev/null
+// 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, 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 :
+// File : SVTK_Hash.h
+// Author : Roman NIKOLAEV
+
+#ifndef SVTK_HASH_H
+#define SVTK_HASH_H
+
+#include <vector>
+#include <Standard_Integer.hxx>
+
+inline Standard_Integer HashCode( const std::vector<Standard_Integer> ids, const Standard_Integer upper ) {
+
+ Standard_Integer seed = ids.size();
+ for( Standard_Integer i = 0; i < (Standard_Integer) ids.size(); i++ ) {
+ Standard_Integer v = ids[i];
+ seed ^= v + 0x9e3779b9 + ( seed << 6 ) + ( seed >> 2 );
+ }
+ return HashCode(seed,upper);
+}
+
+#endif // SVTK_HASH_H
// SALOME SALOMEGUI : implementation of desktop and GUI kernel
// File : SALOME_Selection.cxx
// Author : Nicolas REJNERI
-
#include "SVTK_SelectorDef.h"
#include <VTKViewer_Filter.h>
if(mySelectionMode != theMode){
mySelectionMode = theMode;
myMapIOSubIndex.clear();
+ myMapIOSubCompositeIndex.clear();
this->EndPickCallback();
}
}
myIO2Actors.clear();
myIObjects.clear();
myMapIOSubIndex.clear();
+ myMapIOSubCompositeIndex.clear();
}
/*!
myIObjects.erase(theIO);
myIO2Actors.erase(theIO);
myMapIOSubIndex.erase(theIO);
+ myMapIOSubCompositeIndex.erase(theIO);
return anIsIOBound;
}
return anId != 0;
}
+static bool removeCompositeIndex( SVTK_IndexedMapOfIds& theMapIndex, const SVTK_ListOfInteger theIds )
+{
+ int anId = theMapIndex.FindIndex( theIds ); // i==0 if Index is not in the MapIndex
+ if( anId ) {
+ // only the last key can be removed
+ SVTK_ListOfInteger aLastIds = theMapIndex.FindKey( theMapIndex.Extent() );
+ if( aLastIds == theIds )
+ theMapIndex.RemoveLast();
+ else {
+ SVTK_IndexedMapOfIds aNewMap;
+ aNewMap.ReSize(theMapIndex.Extent()-1);
+ for( int j = 1; j <= theMapIndex.Extent(); j++ ){
+ SVTK_ListOfInteger anIds = theMapIndex( j );
+ if ( anIds != theIds )
+ aNewMap.Add( anIds );
+ }
+ theMapIndex = aNewMap;
+ }
+ }
+ return anId != 0;
+}
+
+
/*!
Changes indices of subselection for SALOME_InteractiveObject
\param theIO - SALOME_InteractiveObject
myMapIOSubIndex.clear();
}
+/*!
+ \return true if the SALOME_InteractiveObject has a composite index subselection
+ \param theIO - SALOME_InteractiveObject
+*/
+bool
+SVTK_SelectorDef
+::HasCompositeIndex( const Handle(SALOME_InteractiveObject)& theIO ) const
+{
+ return myMapIOSubCompositeIndex.find( theIO ) != myMapIOSubCompositeIndex.end();
+}
+
+/*!
+ Gets composite indices of subselection for SALOME_InteractiveObject
+ \param theIO - SALOME_InteractiveObject
+*/
+void
+SVTK_SelectorDef
+::GetCompositeIndex( const Handle(SALOME_InteractiveObject)& theIO,
+ SVTK_IndexedMapOfIds& theIds )
+{
+ TMapIOSubCompositeIndex::const_iterator anIter = myMapIOSubCompositeIndex.find( theIO );
+ if( anIter != myMapIOSubCompositeIndex.end() )
+ theIds = anIter->second;
+ else
+ theIds.Clear();
+}
+
+/*!
+ Changes composite indices of subselection for SALOME_InteractiveObject
+ \param theIO - SALOME_InteractiveObject
+ \param theIndices - composite id
+ \param theIsModeShift - if it is false, then map will be cleared before indices are added
+*/
+bool
+SVTK_SelectorDef
+::AddOrRemoveCompositeIndex( const Handle( SALOME_InteractiveObject )& theIO,
+ const SVTK_IndexedMapOfIds& theIds,
+ bool theIsModeShift)
+{
+ TMapIOSubCompositeIndex::iterator aMapIter = myMapIOSubCompositeIndex.find( theIO );
+ if( aMapIter == myMapIOSubCompositeIndex.end() ) {
+ SVTK_IndexedMapOfIds anEmpty;
+ aMapIter = myMapIOSubCompositeIndex.insert( TMapIOSubCompositeIndex::value_type( theIO, anEmpty ) ).first;
+ }
+ SVTK_IndexedMapOfIds& aMapIndex = aMapIter->second;
+
+ if( !theIsModeShift )
+ aMapIndex.Clear();
+
+ for( int i = 1, iEnd = theIds.Extent(); i <= iEnd; i++ )
+ aMapIndex.Add( theIds( i ) );
+
+ if( aMapIndex.IsEmpty() ) {
+ myMapIOSubCompositeIndex.erase( theIO );
+ return false;
+ }
+ return true;
+}
+
+/*!
+ Changes indices of subselection for SALOME_InteractiveObject
+ \param theIO - SALOME_InteractiveObject
+ \param theIds - composite ids
+ \param theIsModeShift - if it is false, then map will be cleared before indices are added
+*/
+bool
+SVTK_SelectorDef
+::AddOrRemoveCompositeIndex( const Handle(SALOME_InteractiveObject)& theIO,
+ SVTK_ListOfInteger theIds,
+ bool theIsModeShift)
+{
+ TMapIOSubCompositeIndex::iterator anIter = myMapIOSubCompositeIndex.find( theIO );
+ if( anIter == myMapIOSubCompositeIndex.end() ) {
+ SVTK_IndexedMapOfIds anEmpty;
+ anIter = myMapIOSubCompositeIndex.insert(TMapIOSubCompositeIndex::value_type( theIO,anEmpty ) ).first;
+ }
+
+ SVTK_IndexedMapOfIds& aMapIndex = anIter->second;
+
+ bool anIsContains = aMapIndex.Contains( theIds ) == Standard_True;
+ if ( anIsContains )
+ removeCompositeIndex( aMapIndex, theIds );
+
+ if ( !theIsModeShift )
+ aMapIndex.Clear();
+
+ if ( !anIsContains )
+ aMapIndex.Add( theIds );
+
+ if ( aMapIndex.IsEmpty() )
+ myMapIOSubIndex.erase( theIO );
+
+ return false;
+}
+
+/*!
+ Removes composite index of subselection for SALOME_InteractiveObject
+ \param theIO - SALOME_InteractiveObject
+ \param theIds - index
+*/
+void
+SVTK_SelectorDef
+::RemoveCompositeIndex( const Handle(SALOME_InteractiveObject)& theIO,
+ SVTK_ListOfInteger theIds )
+{
+ if(IsCompositeIndexSelected( theIO, theIds ) ) {
+ TMapIOSubCompositeIndex::iterator anIter = myMapIOSubCompositeIndex.find( theIO );
+ SVTK_IndexedMapOfIds& aMapIndex = anIter->second;
+ removeCompositeIndex( aMapIndex,theIds );
+ }
+}
+
+/*!
+ \return true if the composite index presents in subselection
+ \param theIO - SALOME_InteractiveObject
+ \param theIds - index
+*/
+bool
+SVTK_SelectorDef
+::IsCompositeIndexSelected( const Handle(SALOME_InteractiveObject)& theIO,
+ SVTK_ListOfInteger theIds ) const
+{
+ TMapIOSubCompositeIndex::const_iterator anIter = myMapIOSubCompositeIndex.find( theIO );
+ if( anIter != myMapIOSubCompositeIndex.end() ) {
+ const SVTK_IndexedMapOfIds& aMapIndex = anIter->second;
+ return aMapIndex.Contains( theIds ) == Standard_True;
+ }
+ return false;
+}
+
+/*!
+ Clears all composite indices of subselection
+*/
+void
+SVTK_SelectorDef
+::ClearCompositeIndex()
+{
+ myMapIOSubCompositeIndex.clear();
+}
+
+
/*!
To apply a filter on the selection
\param theFilter - new filter
#define SVTK_SELECTOR_H
#include "SVTK.h"
+#include "SVTK_Hash.h"
#include "SVTK_Selection.h"
#include "SALOME_ListIO.hxx"
class vtkActorCollection;
class vtkRenderer;
+#include <vector>
+
+typedef std::vector<Standard_Integer> SVTK_ListOfInteger;
+typedef NCollection_DefaultHasher<SVTK_ListOfInteger> SVTK_MapOfIdsHasher;
+typedef NCollection_IndexedMap<SVTK_ListOfInteger,SVTK_MapOfIdsHasher> SVTK_IndexedMapOfIds;
+
//! Define an abstract interface for selection in SVTK package
/*!
The class implements selection functionality through storing corresponding
void
ClearIndex() = 0;
+ /// ! Composite indexes
+ virtual
+ bool
+ HasCompositeIndex(const Handle(SALOME_InteractiveObject)& theIO ) const = 0;
+
+ //! Get composite indexes of subslection for given #SALOME_InteractiveObject
+ virtual
+ void
+ GetCompositeIndex( const Handle(SALOME_InteractiveObject)& theIO,
+ SVTK_IndexedMapOfIds& theIds ) = 0;
+
+ //! Change composite indices of subselection for given #SALOME_InteractiveObject
+ virtual
+ bool
+ AddOrRemoveCompositeIndex( const Handle(SALOME_InteractiveObject)& theIO,
+ const SVTK_IndexedMapOfIds& theIds,
+ bool theIsModeShift) = 0;
+
+ //! Change composite index of subslection for given #SALOME_InteractiveObject
+ virtual
+ bool
+ AddOrRemoveCompositeIndex( const Handle(SALOME_InteractiveObject)& theIO,
+ SVTK_ListOfInteger ids,
+ bool theIsModeShift) = 0;
+
+ //! Change composite index of subslection for given #SALOME_InteractiveObject
+ virtual
+ void
+ RemoveCompositeIndex( const Handle(SALOME_InteractiveObject)& theIO,
+ SVTK_ListOfInteger ids ) = 0;
+
+ //! Check, if the given composite index is present in subselection
+ virtual
+ bool
+ IsCompositeIndexSelected(const Handle(SALOME_InteractiveObject)& theIO,
+ SVTK_ListOfInteger ids ) const = 0;
+
+ //! Clear composite indexes subselection
+ virtual
+ void
+ ClearCompositeIndex() = 0;
+
//----------------------------------------------------------------------------
typedef int TFilterID;
#ifndef SVTK_SELECTORDEF_H
#define SVTK_SELECTORDEF_H
+#include "SVTK_Selector.h"
+
#include <set>
#include <map>
#include "SALOME_InteractiveObject.hxx"
-#include "SVTK_Selector.h"
-
class SALOME_Actor;
class SVTK_Viewer;
void
ClearIndex();
+ //----------------------------------------------------------------------------
+ /// ! Composite indexes
+ virtual
+ bool
+ HasCompositeIndex(const Handle(SALOME_InteractiveObject)& theIO ) const;
+
+ virtual
+ void
+ GetCompositeIndex( const Handle(SALOME_InteractiveObject)& theIO,
+ SVTK_IndexedMapOfIds& theIds );
+ virtual
+ bool
+ AddOrRemoveCompositeIndex( const Handle(SALOME_InteractiveObject)& theIO,
+ const SVTK_IndexedMapOfIds& theIds,
+ bool theIsModeShift);
+
+ virtual
+ bool
+ AddOrRemoveCompositeIndex( const Handle(SALOME_InteractiveObject)& theIO,
+ SVTK_ListOfInteger theIds,
+ bool theIsModeShift);
+
+ virtual
+ void
+ RemoveCompositeIndex( const Handle(SALOME_InteractiveObject)& theIO,
+ SVTK_ListOfInteger theIds );
+
+ virtual
+ bool
+ IsCompositeIndexSelected(const Handle(SALOME_InteractiveObject)& theIO,
+ SVTK_ListOfInteger theIds ) const;
+
+ virtual
+ void
+ ClearCompositeIndex();
+
//----------------------------------------------------------------------------
virtual
void
TIOLessThan> TMapIOSubIndex;
TMapIOSubIndex myMapIOSubIndex;
+ typedef std::map<Handle(SALOME_InteractiveObject),
+ SVTK_IndexedMapOfIds,
+ TIOLessThan> TMapIOSubCompositeIndex;
+ TMapIOSubCompositeIndex myMapIOSubCompositeIndex;
+
+
typedef std::map<TFilterID,Handle(VTKViewer_Filter)> TFilters;
TFilters myFilters;
return GetInput()->GetPoint(theObjID);
}
+/*!
+ Maps object index of a node to corresponding VTK index
+*/
+int
+VTKViewer_Actor
+::GetNodeVtkId( int theObjID )
+{
+ return theObjID;
+}
+
+
/*!
Get corresponding #vtkCell for given object index
*/
double*
GetNodeCoord(int theObjID);
+ //! Maps object index of a node to corresponding VTK index
+ virtual
+ int
+ GetNodeVtkId(int theObjID);
+
//! Maps VTK index of a cell to corresponding object index
virtual
int