vtkPicker* thePicker,
int theObjId)
{
- int anEdgeId = -1;
+ int anEdgeId = 0;
if (vtkCell* aPickedCell = theActor->GetElemCell(theObjId)) {
float aPickPosition[3];
thePicker->GetPickPosition(aPickPosition);
aLine->EvaluatePosition(aPickPosition,closestPoint,subId,pcoords,aDist,weights);
if (aDist < aMinDist) {
aMinDist = aDist;
- anEdgeId = i;
+ anEdgeId = -1 - i;
}
}
}
vtkRenderer *aRenderer = theInteractorStyle->GetCurrentRenderer();
//
myPreHighlightActor->SetVisibility( false );
-
+ bool anIsPreselected = myIsPreselected;
+
Selection_Mode aSelectionMode = theSelectionEvent->mySelectionMode;
bool anIsChanged = (mySelectionMode != aSelectionMode);
if( anActor->hasIO() && myIO->isSame( anActor->getIO() ) )
anActor->SetPreSelected( false );
- anIsChanged = true;
}else{
switch(aSelectionMode){
case NodeSelection:
int aVtkId = myPointPicker->GetPointId();
if( aVtkId >= 0 && mySelector->IsValid( this, aVtkId, true ) ) {
int anObjId = GetNodeObjId( aVtkId );
- if ( anObjId >= 0 ) {
- TColStd_IndexedMapOfInteger aMapIndex;
- aMapIndex.Add( anObjId );
-
- myPreHighlightActor->GetProperty()->SetRepresentationToPoints();
- myPreHighlightActor->SetVisibility( true );
- myPreHighlightActor->MapPoints( this, aMapIndex );
-
- myIsPreselected = theIsHighlight;
- anIsChanged = true;
+ myIsPreselected = (anObjId >= 0);
+ if(myIsPreselected){
+ const TColStd_IndexedMapOfInteger& aMapIndex = myPreHighlightActor->GetMapIndex();
+ int anExtent = aMapIndex.Extent();
+ anIsChanged |= (anExtent == 0 || anExtent > 0 && anObjId != aMapIndex(1));
+ if(anIsChanged){
+ TColStd_IndexedMapOfInteger aMapIndex;
+ aMapIndex.Add( anObjId );
+
+ myPreHighlightActor->GetProperty()->SetRepresentationToPoints();
+ myPreHighlightActor->SetVisibility( true );
+ myPreHighlightActor->MapPoints( this, aMapIndex );
+ }
}
}
break;
if ( aVtkId >= 0 && mySelector->IsValid( this, aVtkId ) && hasIO() ) {
int anObjId = GetElemObjId (aVtkId );
if ( anObjId >= 0 ) {
- if ( CheckDimensionId(aSelectionMode,this,anObjId) ) {
- TColStd_IndexedMapOfInteger aMapIndex;
- aMapIndex.Add( anObjId );
-
- myPreHighlightActor->GetProperty()->SetRepresentationToSurface();
- myPreHighlightActor->SetVisibility( true );
- myPreHighlightActor->MapCells( this, aMapIndex );
-
- myIsPreselected = theIsHighlight;
- anIsChanged = true;
+ myIsPreselected = CheckDimensionId(aSelectionMode,this,anObjId);
+ if(myIsPreselected){
+ const TColStd_IndexedMapOfInteger& aMapIndex = myPreHighlightActor->GetMapIndex();
+ int anExtent = aMapIndex.Extent();
+ anIsChanged |= (anExtent == 0 || anExtent > 0 && anObjId != aMapIndex(1));
+ if(anIsChanged){
+ TColStd_IndexedMapOfInteger aMapIndex;
+ aMapIndex.Add( anObjId );
+
+ myPreHighlightActor->GetProperty()->SetRepresentationToSurface();
+ myPreHighlightActor->SetVisibility( true );
+ myPreHighlightActor->MapCells( this, aMapIndex );
+ }
}
}
}
int anObjId = GetElemObjId( aVtkId );
if ( anObjId >= 0 ) {
int anEdgeId = GetEdgeId(this,myCellPicker.GetPointer(),anObjId);
- TColStd_IndexedMapOfInteger aMapIndex;
- aMapIndex.Add( anObjId );
- aMapIndex.Add( anEdgeId );
+ myIsPreselected = anEdgeId < 0;
+ if(myIsPreselected){
+ const TColStd_IndexedMapOfInteger& aMapIndex = myPreHighlightActor->GetMapIndex();
+ int anExtent = aMapIndex.Extent();
+ anIsChanged |= (anExtent != 2);
+ anIsChanged |= (anExtent == 0 && (anObjId != aMapIndex(1) || anEdgeId != aMapIndex(2)));
+ if(anIsChanged){
+ TColStd_IndexedMapOfInteger aMapIndex;
+ aMapIndex.Add( anObjId );
+ aMapIndex.Add( anEdgeId );
- myPreHighlightActor->GetProperty()->SetRepresentationToWireframe();
- myPreHighlightActor->SetVisibility( true );
- myPreHighlightActor->MapEdge( this, aMapIndex );
-
- myIsPreselected = theIsHighlight;
- anIsChanged = true;
+ myPreHighlightActor->GetProperty()->SetRepresentationToWireframe();
+ myPreHighlightActor->SetVisibility( true );
+ myPreHighlightActor->MapEdge( this, aMapIndex );
+ }
+ }
}
}
break;
anActor->SetPreSelected( true );
}
}
- anIsChanged = true;
}
default:
break;
}
mySelectionMode = aSelectionMode;
+ anIsChanged |= (anIsPreselected != myIsPreselected);
return anIsChanged;
}
#endif
-static void CopyPoints(vtkUnstructuredGrid* theGrid, vtkDataSet *theSourceDataSet){
+static
+void
+CopyPoints(vtkUnstructuredGrid* theGrid, vtkDataSet *theSourceDataSet)
+{
vtkPoints *aPoints = vtkPoints::New();
vtkIdType iEnd = theSourceDataSet->GetNumberOfPoints();
aPoints->SetNumberOfPoints(iEnd);
vtkStandardNewMacro(SVTK_Actor);
-SVTK_Actor::SVTK_Actor()
+SVTK_Actor
+::SVTK_Actor()
{
if(MYDEBUG) INFOS("SVTK_Actor - "<<this);
SetResolveCoincidentTopology(false);
}
-void SVTK_Actor::SetShrinkFactor(float theValue){
+void
+SVTK_Actor
+::SetShrinkFactor(float theValue)
+{
myShrinkFilter->SetShrinkFactor(theValue);
Modified();
}
-void SVTK_Actor::SetShrink()
+void
+SVTK_Actor
+::SetShrink()
{
if ( !myIsShrinkable ) return;
if ( vtkDataSet* aDataSet = myPassFilter[0]->GetOutput() )
}
}
-void SVTK_Actor::UnShrink()
+void
+SVTK_Actor
+::UnShrink()
{
if ( !myIsShrunk ) return;
if ( vtkDataSet* aDataSet = myPassFilter[0]->GetOutput() )
//----------------------------------------------------------------------------
-SVTK_Actor::~SVTK_Actor()
+SVTK_Actor
+::~SVTK_Actor()
{
if(MYDEBUG) INFOS("~SVTK_Actor()");
//----------------------------------------------------------------------------
-void SVTK_Actor::MapCells(SALOME_Actor* theMapActor,
- const TColStd_IndexedMapOfInteger& theMapIndex)
+const TColStd_IndexedMapOfInteger&
+SVTK_Actor
+::GetMapIndex() const
+{
+ return myMapIndex;
+}
+
+
+//----------------------------------------------------------------------------
+void
+SVTK_Actor
+::MapCells(SALOME_Actor* theMapActor,
+ const TColStd_IndexedMapOfInteger& theMapIndex)
{
myUnstructuredGrid->Reset();
int aPartId = theMapIndex( ind );
vtkCell* aCell = theMapActor->GetElemCell(aPartId);
myUnstructuredGrid->InsertNextCell(aCell->GetCellType(),aCell->GetPointIds());
- //for (int i = 0, iEnd = aCell->GetNumberOfEdges(); i < iEnd; i++){
- // vtkCell* anEdgeCell = aCell->GetEdge(i);
- // myUnstructuredGrid->InsertNextCell(VTK_LINE,anEdgeCell->GetPointIds());
- //}
}
UnShrink();
SetShrinkFactor(theMapActor->GetShrinkFactor());
SetShrink();
}
+
+ myMapIndex = theMapIndex;
}
//----------------------------------------------------------------------------
-void SVTK_Actor::MapPoints(SALOME_Actor* theMapActor,
- const TColStd_IndexedMapOfInteger& theMapIndex)
+void
+SVTK_Actor
+::MapPoints(SALOME_Actor* theMapActor,
+ const TColStd_IndexedMapOfInteger& theMapIndex)
{
myUnstructuredGrid->Reset();
if(int aNbOfParts = theMapIndex.Extent()){
}
UnShrink();
+
+ myMapIndex = theMapIndex;
}
//----------------------------------------------------------------------------
-void SVTK_Actor::MapEdge(SALOME_Actor* theMapActor,
- const TColStd_IndexedMapOfInteger& theMapIndex)
+void
+SVTK_Actor
+::MapEdge(SALOME_Actor* theMapActor,
+ const TColStd_IndexedMapOfInteger& theMapIndex)
{
myUnstructuredGrid->Reset();
SetShrinkFactor(theMapActor->GetShrinkFactor());
SetShrink();
}
+
+ myMapIndex = theMapIndex;
}
//----------------------------------------------------------------------------
void MapEdge(SALOME_Actor* theMapActor,
const TColStd_IndexedMapOfInteger& theMapIndex);
+ const TColStd_IndexedMapOfInteger&
+ GetMapIndex() const;
+
protected:
+ TColStd_IndexedMapOfInteger myMapIndex;
+
vtkUnstructuredGrid* myUnstructuredGrid;
vtkDataSetMapper* myMapper;
-
vtkRenderer* myRenderer;
vtkShrinkFilter* myShrinkFilter;
static int MYDEBUG = 0;
#endif
-static
- bool GetFirstSALOMEActor(vtkPicker *pPicker,
- SALOME_Actor*& pSA);
-
namespace
{
inline
theInteractor->GetEventPosition(theX,theY);
theY = theInteractor->GetSize()[1] - theY - 1;
}
-}
+
+ //==================================================================
+ // function : GetFirstSALOMEActor
+ // purpose :
+ //==================================================================
+ struct THaveIO
+ {
+ bool
+ operator()(SALOME_Actor* theActor)
+ {
+ return theActor->hasIO();
+ }
+ };
+
+ inline
+ SALOME_Actor*
+ GetFirstSALOMEActor(vtkPicker *thePicker)
+ {
+ return VTK::Find<SALOME_Actor>(thePicker->GetActors(),THaveIO());
+ }
+}
+
+
//----------------------------------------------------------------------------
vtkStandardNewMacro(SVTK_InteractorStyle);
//----------------------------------------------------------------------------
SVTK_InteractorStyle
::SVTK_InteractorStyle():
mySelectionEvent(new SVTK_SelectionEvent()),
- myPicker(vtkPicker::New())
+ myPicker(vtkPicker::New()),
+ myLastHighlitedActor(NULL),
+ myLastPreHighlitedActor(NULL)
{
myPicker->Delete();
0.0,
GetCurrentRenderer());
//
- SALOME_Actor* aSActor=NULL;
- //
- GetFirstSALOMEActor(myPicker.GetPointer(), aSActor);
- if (aSActor){
- //if(SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast(myPicker->GetActor())){
- if(aSActor->hasIO()){
- aSelectionEvent->myIsRectangle = false;
- aSActor->Highlight( this, aSelectionEvent, true );
- }
- }
- else{
+ SALOME_Actor* anActor = GetFirstSALOMEActor(myPicker.GetPointer());
+ aSelectionEvent->myIsRectangle = false;
+ if(anActor){
+ anActor->Highlight( this, aSelectionEvent, true );
+ }else{
+ if(myLastHighlitedActor && myLastHighlitedActor != anActor)
+ myLastHighlitedActor->Highlight( this, aSelectionEvent, false );
GetSelector()->ClearIObjects();
}
- }
+ myLastHighlitedActor = anActor;
+ }
else {
//processing rectangle selection
Interactor->StartPickCallback();
this->FindPokedRenderer(aSelectionEvent->myX,aSelectionEvent->myY);
bool anIsChanged = false;
- SALOME_Actor *aLastActor=NULL;
- //
- GetFirstSALOMEActor(myPicker.GetPointer(), aLastActor);
- if (aLastActor){
- anIsChanged |= aLastActor->PreHighlight( this, aSelectionEvent, false );
- }
+
myPicker->Pick(aSelectionEvent->myX,
aSelectionEvent->myY,
0.0,
GetCurrentRenderer());
- SALOME_Actor *anActor=NULL;
- //
- GetFirstSALOMEActor(myPicker.GetPointer(), anActor);
+ SALOME_Actor *anActor = GetFirstSALOMEActor(myPicker.GetPointer());
if (anActor){
anIsChanged |= anActor->PreHighlight( this, aSelectionEvent, true );
}
-
+
+ if(myLastPreHighlitedActor && myLastPreHighlitedActor != anActor)
+ anIsChanged |= myLastPreHighlitedActor->PreHighlight( this, aSelectionEvent, false );
+
+ myLastPreHighlitedActor = anActor;
+
if(anIsChanged)
this->Render();
}
void SVTK_InteractorStyle::OnChar()
{
}
-//==================================================================
-// function : GetFirstSALOMEActor
-// purpose :
-//==================================================================
-bool GetFirstSALOMEActor(vtkPicker *pPicker,
- SALOME_Actor*& pSA)
-{
- bool bRet=false;
- pSA=NULL;
- vtkActor *pA;
- //
- vtkActorCollection *pActors=pPicker->GetActors();
- //
- pActors->InitTraversal();
- while(1) {
- pA=pActors->GetNextActor();
- if (!pA) {
- break;
- }
- //
- pSA=SALOME_Actor::SafeDownCast(pA);
- if (pSA){
- bRet=!bRet;
- break;
- }
- }
- return bRet;
-}
class vtkCell;
class vtkPicker;
+class SALOME_Actor;
+
class SVTK_Selector;
class SVTK_GenericRenderWindowInteractor;
bool myShiftState;
int ForcedState;
+ SALOME_Actor* myLastHighlitedActor;
+ SALOME_Actor* myLastPreHighlitedActor;
+
//! "Increment" for pan/rotate/zoom operations
int mySpeedIncrement;