From 3c2b1529ef9816cd91d213181258c13a9383ba37 Mon Sep 17 00:00:00 2001 From: ouv Date: Fri, 5 Aug 2005 05:27:14 +0000 Subject: [PATCH] Preselection implemented --- src/SVTK/SALOME_Actor.cxx | 200 ++++++++++---- src/SVTK/SALOME_Actor.h | 27 +- src/SVTK/SVTK_InteractorStyle.cxx | 327 ++++++++++++----------- src/SVTK/SVTK_InteractorStyle.h | 23 +- src/SVTK/SVTK_RenderWindowInteractor.cxx | 160 ++++------- src/SVTK/SVTK_RenderWindowInteractor.h | 14 +- src/SVTK/SVTK_ViewWindow.cxx | 92 +++++-- src/SVTK/SVTK_ViewWindow.h | 10 + 8 files changed, 492 insertions(+), 361 deletions(-) diff --git a/src/SVTK/SALOME_Actor.cxx b/src/SVTK/SALOME_Actor.cxx index 2148371cc..c3f217771 100644 --- a/src/SVTK/SALOME_Actor.cxx +++ b/src/SVTK/SALOME_Actor.cxx @@ -48,6 +48,7 @@ // VTK Includes #include +#include #include #include #include @@ -99,6 +100,10 @@ SALOME_Actor::SALOME_Actor(){ myPassFilter.push_back(VTKViewer_PassThroughFilter::New()); // from VISU + myPointPicker = vtkPointPicker::New(); + myCellPicker = vtkCellPicker::New(); + myCellRectPicker = VTKViewer_CellRectPicker::New(); + myPreHighlightActor = SVTK_Actor::New(); myPreHighlightActor->GetProperty()->SetColor(0,1,0); myPreHighlightActor->GetProperty()->SetPointSize(15); @@ -144,6 +149,9 @@ SALOME_Actor::~SALOME_Actor(){ myProperty->Delete(); // from VISU + myPointPicker->Delete(); + myCellPicker->Delete(); + myCellRectPicker->Delete(); myHighlightActor->SetProperty( NULL ); } @@ -365,31 +373,139 @@ void SALOME_Actor::highlight( bool theHighlight ) //---------------------------------------------------------------- void SALOME_Actor::SetVisibility( int theVisibility ) { + cout << "SALOME_Actor::SetVisibility " << ( theVisibility ? "on" : "off" ) << endl; vtkProp::SetVisibility( theVisibility ); myHighlightActor->SetVisibility( theVisibility && isHighlighted() ); } //---------------------------------------------------------------- -bool SALOME_Actor::PreHighlight( SVTK_InteractorStyle* theInteractorStyle, - const int& theIndex ) +int SALOME_Actor::GetEdgeId( vtkPicker* thePicker, int theObjId ) { - //cout << "SALOME_Actor::PreHighlight : " << theIndex << endl; + int anEdgeId = -1; + if (vtkCell* aPickedCell = GetElemCell(theObjId)) { + float aPickPosition[3]; + thePicker->GetPickPosition(aPickPosition); + float aMinDist = 1000000.0, aDist = 0; + for (int i = 0, iEnd = aPickedCell->GetNumberOfEdges(); i < iEnd; i++){ + if(vtkLine* aLine = vtkLine::SafeDownCast(aPickedCell->GetEdge(i))){ + int subId; float pcoords[3], closestPoint[3], weights[3]; + aLine->EvaluatePosition(aPickPosition,closestPoint,subId,pcoords,aDist,weights); + if (aDist < aMinDist) { + aMinDist = aDist; + anEdgeId = i; + } + } + } + } + return anEdgeId; +} - if( theIndex == -1 ) +//---------------------------------------------------------------- +bool SALOME_Actor::PreHighlight( SVTK_InteractorStyle* theInteractorStyle, + SVTK_Selector* theSelector, + vtkRenderer* theRenderer, + SVTK_SelectionEvent theSelectionEvent, + bool theIsHighlight ) +{ + Selection_Mode aSelectionMode = theSelectionEvent.SelectionMode; + float x = theSelectionEvent.X; + float y = theSelectionEvent.Y; + float z = 0.0; + /* + cout << "SALOME_Actor::PreHighlight" << endl; + cout << "SelectionMode : "; + switch( aSelectionMode ) + { + case NodeSelection: cout << "Nodes" << endl; break; + case CellSelection: cout << "Cells" << endl; break; + case ActorSelection: cout << "Actor" << endl; break; + default: cout << "Other" << endl; break; + } + cout << "IsHighlight : " << ( theIsHighlight ? "true" : "false" ) << endl; + */ + if( !theIsHighlight ) { myPreHighlightActor->SetVisibility( false ); + + vtkActorCollection* theActors = theRenderer->GetActors(); + theActors->InitTraversal(); + while( vtkActor *ac = theActors->GetNextActor() ) + if( SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac ) ) + anActor->SetPreSelected( false ); + + return false; } - else + + if( aSelectionMode == NodeSelection ) { - TColStd_IndexedMapOfInteger aMapIndex; - aMapIndex.Add( theIndex ); + myPointPicker->Pick( x, y, z, theRenderer ); - myPreHighlightActor->SetVisibility( true ); - myPreHighlightActor->MapPoints( this, aMapIndex ); + int aVtkId = myPointPicker->GetPointId(); + if( aVtkId >= 0 && theInteractorStyle->IsValid( this, aVtkId, true ) && hasIO() ) + { + int anObjId = GetNodeObjId( aVtkId ); + TColStd_IndexedMapOfInteger aMapIndex; + aMapIndex.Add( anObjId ); + //cout << "Index : " << anObjId << endl; + + myPreHighlightActor->GetProperty()->SetRepresentationToPoints(); + myPreHighlightActor->SetVisibility( true ); + myPreHighlightActor->MapPoints( this, aMapIndex ); + } } + else if( aSelectionMode == CellSelection ) + { + myCellPicker->Pick( x, y, z, theRenderer ); - return false; + int aVtkId = myCellPicker->GetCellId(); + if ( aVtkId >= 0 && theInteractorStyle->IsValid( this, aVtkId ) && hasIO() ) + { + int anObjId = GetElemObjId (aVtkId ); + TColStd_IndexedMapOfInteger aMapIndex; + aMapIndex.Add( anObjId ); + //cout << "Index : " << anObjId << endl; + + myPreHighlightActor->GetProperty()->SetRepresentationToSurface(); + myPreHighlightActor->SetVisibility( true ); + myPreHighlightActor->MapCells( this, aMapIndex ); + } + } + else if( aSelectionMode == EdgeOfCellSelection ) + { + myCellPicker->Pick( x, y, z, theRenderer ); + + int aVtkId = myCellPicker->GetCellId(); + if ( aVtkId >= 0 && theInteractorStyle->IsValid( this, aVtkId ) && hasIO() ) + { + int anObjId = GetElemObjId( aVtkId ); + int anEdgeId = GetEdgeId( myCellPicker, anObjId ); + TColStd_IndexedMapOfInteger aMapIndex; + aMapIndex.Add( anObjId ); + aMapIndex.Add( anEdgeId ); + //cout << "Index : " << anObjId << " " << anEdgeId << endl; + + myPreHighlightActor->GetProperty()->SetRepresentationToWireframe(); + myPreHighlightActor->SetVisibility( true ); + myPreHighlightActor->MapEdge( this, aMapIndex ); + } + } + else + { + if( hasIO() && !theSelector->IsSelected( myIO ) ) + { + vtkActorCollection* theActors = theRenderer->GetActors(); + theActors->InitTraversal(); + while( vtkActor *ac = theActors->GetNextActor() ) + { + if( SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac ) ) + if( anActor->hasIO() && myIO->isSame( anActor->getIO() ) ) + anActor->SetPreSelected( true ); + } + } + } + + return true; } //---------------------------------------------------------------- @@ -397,8 +513,7 @@ bool SALOME_Actor::Highlight( SVTK_InteractorStyle* theInteractorStyle, SVTK_Selector* theSelector, vtkRenderer* theRenderer, SVTK_SelectionEvent theSelectionEvent, - bool theIsHighlight, - bool theIsUpdate ) + bool theIsHighlight ) { Selection_Mode aSelectionMode = theSelectionEvent.SelectionMode; float x1 = theSelectionEvent.X; @@ -409,20 +524,14 @@ bool SALOME_Actor::Highlight( SVTK_InteractorStyle* theInteractorStyle, float z2 = 0.0; bool isShift = theSelectionEvent.IsShift; bool isRectangle = theSelectionEvent.IsRectangle; - /* - cout << x1 << " " << y1; - if( isRectangle ) - cout << " " << x2 << " " << y2; - cout << endl; - */ + if( !isRectangle ) { if( aSelectionMode == NodeSelection ) { - vtkPointPicker* aPicker = vtkPointPicker::New(); - aPicker->Pick( x1, y1, z1, theRenderer ); + myPointPicker->Pick( x1, y1, z1, theRenderer ); - int aVtkId = aPicker->GetPointId(); + int aVtkId = myPointPicker->GetPointId(); if( aVtkId >= 0 && hasIO() && theInteractorStyle->IsValid( this, aVtkId, true ) ) { int anObjId = GetNodeObjId( aVtkId ); @@ -442,14 +551,12 @@ bool SALOME_Actor::Highlight( SVTK_InteractorStyle* theInteractorStyle, } } } - aPicker->Delete(); } else if( aSelectionMode == CellSelection ) { - vtkCellPicker* aPicker = vtkCellPicker::New(); - aPicker->Pick( x1, y1, z1, theRenderer ); + myCellPicker->Pick( x1, y1, z1, theRenderer ); - int aVtkId = aPicker->GetCellId(); + int aVtkId = myCellPicker->GetCellId(); if( aVtkId >= 0 && hasIO() && theInteractorStyle->IsValid( this, aVtkId ) ) { int anObjId = GetElemObjId( aVtkId ); @@ -472,14 +579,12 @@ bool SALOME_Actor::Highlight( SVTK_InteractorStyle* theInteractorStyle, } } } - aPicker->Delete(); } else if( aSelectionMode == EdgeOfCellSelection ) { - vtkCellPicker* aPicker = vtkCellPicker::New(); - aPicker->Pick( x1, y1, z1, theRenderer ); + myCellPicker->Pick( x1, y1, z1, theRenderer ); - int aVtkId = aPicker->GetCellId(); + int aVtkId = myCellPicker->GetCellId(); if( aVtkId >= 0 && hasIO() && theInteractorStyle->IsValid( this, aVtkId ) ) { int anObjId = GetElemObjId( aVtkId ); @@ -490,7 +595,7 @@ bool SALOME_Actor::Highlight( SVTK_InteractorStyle* theInteractorStyle, theInteractorStyle->HighlightProp( NULL ); theSelector->ClearIObjects(); } - int anEdgeId = 0;//theInteractorStyle->GetEdgeId( aPicker, this, anObjId ); + int anEdgeId = 0;//theInteractorStyle->GetEdgeId( myCellPicker, this, anObjId ); if( anEdgeId >= 0 ) { theSelector->AddOrRemoveIndex( myIO, anObjId, false ); @@ -499,7 +604,6 @@ bool SALOME_Actor::Highlight( SVTK_InteractorStyle* theInteractorStyle, } } } - aPicker->Delete(); } else if( aSelectionMode == ActorSelection ) { @@ -524,7 +628,6 @@ bool SALOME_Actor::Highlight( SVTK_InteractorStyle* theInteractorStyle, { if( aSelectionMode == NodeSelection && hasIO() && !myIO.IsNull() ) { - vtkPointPicker* aPicker = vtkPointPicker::New(); if( vtkDataSet* aDataSet = GetInput() ) { TColStd_MapOfInteger anIndices; @@ -547,14 +650,14 @@ bool SALOME_Actor::Highlight( SVTK_InteractorStyle* theInteractorStyle, theRenderer->WorldToDisplay(); theRenderer->GetDisplayPoint( aDisp ); - if( aPicker->Pick( aDisp[0], aDisp[1], 0.0, theRenderer ) ) + if( myPointPicker->Pick( aDisp[0], aDisp[1], 0.0, theRenderer ) ) { - if( vtkActorCollection* anActorCollection = aPicker->GetActors() ) + if( vtkActorCollection* anActorCollection = myPointPicker->GetActors() ) { if( anActorCollection->IsItemPresent( this ) ) { float aPickedPoint[3]; - aPicker->GetMapperPosition( aPickedPoint ); + myPointPicker->GetMapperPosition( aPickedPoint ); vtkIdType aVtkId = aDataSet->FindPoint( aPickedPoint ); if( aVtkId >= 0 && theInteractorStyle->IsValid( this, aVtkId, true ) ) { @@ -575,15 +678,13 @@ bool SALOME_Actor::Highlight( SVTK_InteractorStyle* theInteractorStyle, else theSelector->RemoveIObject( this ); } - aPicker->Delete(); } else if( aSelectionMode != ActorSelection && hasIO() ) { - VTKViewer_CellRectPicker* aPicker = VTKViewer_CellRectPicker::New(); - aPicker->SetTolerance( 0.001 ); - aPicker->Pick( x2, y2, z2, x1, y1, z1, theRenderer ); + myCellRectPicker->SetTolerance( 0.001 ); + myCellRectPicker->Pick( x2, y2, z2, x1, y1, z1, theRenderer ); - VTKViewer_CellDataSet cellList = aPicker->GetCellData( this ); + VTKViewer_CellDataSet cellList = myCellRectPicker->GetCellData( this ); TColStd_MapOfInteger anIndexes; if( !cellList.empty() ) { @@ -604,8 +705,6 @@ bool SALOME_Actor::Highlight( SVTK_InteractorStyle* theInteractorStyle, } theSelector->AddOrRemoveIndex( myIO, anIndexes, true ); theSelector->AddIObject( this ); - - aPicker->Delete(); } else if( aSelectionMode == ActorSelection && hasIO() ) { @@ -630,16 +729,13 @@ bool SALOME_Actor::Highlight( SVTK_InteractorStyle* theInteractorStyle, } cout << "IsRectangle : " << ( isRectangle ? "true" : "false" ) << endl; cout << "IsHighlight : " << ( theIsHighlight ? "true" : "false" ) << endl; - cout << "IsUpdate : " << ( theIsUpdate ? "true" : "false" ) << endl; */ + if( GetVisibility() && theIsHighlight ) theInteractorStyle->HighlightProp( this ); else if( !theIsHighlight ) theInteractorStyle->HighlightProp( NULL ); - //if( aSelectionMode != ActorSelection && !hasHighlight() ) - // return false; - switch( aSelectionMode ) { case NodeSelection: @@ -665,17 +761,7 @@ bool SALOME_Actor::Highlight( SVTK_InteractorStyle* theInteractorStyle, break; } - return false; -} - -//---------------------------------------------------------------- -bool SALOME_Actor::Unhighlight( SVTK_InteractorStyle* theInteractorStyle, - SVTK_Selector* theSelector, - bool theIsUpdate ) -{ - - theInteractorStyle->HighlightProp( NULL ); - theSelector->ClearIObjects(); + return true; } /* diff --git a/src/SVTK/SALOME_Actor.h b/src/SVTK/SALOME_Actor.h index 39633d3d7..0bb64057d 100644 --- a/src/SVTK/SALOME_Actor.h +++ b/src/SVTK/SALOME_Actor.h @@ -44,6 +44,9 @@ #include class vtkCell; +class vtkPicker; +class vtkPointPicker; +class vtkCellPicker; class vtkDataSet; class vtkPolyData; class vtkCamera; @@ -53,6 +56,7 @@ class VTKViewer_Transform; class VTKViewer_GeometryFilter; class VTKViewer_TransformFilter; class VTKViewer_PassThroughFilter; +class VTKViewer_CellRectPicker; extern int SALOME_POINT_SIZE; @@ -199,12 +203,21 @@ class SALOME_OBJECT_EXPORT SALOME_Actor : public VTKViewer_Actor { virtual void AddToRender( vtkRenderer* ); virtual void RemoveFromRender( vtkRenderer* ); - virtual bool PreHighlight( SVTK_InteractorStyle*, const int& ); + virtual bool PreHighlight( SVTK_InteractorStyle*, SVTK_Selector*, vtkRenderer*, SVTK_SelectionEvent, bool ); + virtual bool Highlight( SVTK_InteractorStyle*, SVTK_Selector*, vtkRenderer*, SVTK_SelectionEvent, bool ); + + vtkProperty* getPointProperty() const { return myPointProperty; } + vtkProperty* getCellProperty() const { return myCellProperty; } + vtkProperty* getEdgeProperty() const { return myEdgeProperty; } + + vtkPointPicker* getPointPicker() const { return myPointPicker; } + vtkCellPicker* getCellPicker() const { return myCellPicker; } + VTKViewer_CellRectPicker* getCellRectPicker() const { return myCellRectPicker; } - virtual bool Highlight( SVTK_InteractorStyle*, SVTK_Selector*, vtkRenderer*, SVTK_SelectionEvent, bool, bool ); - virtual bool Unhighlight( SVTK_InteractorStyle*, SVTK_Selector*, bool ); - /* protected: + int GetEdgeId( vtkPicker*, int ); + + /* bool IsInRect(vtkActor* theActor, const int left, const int top, const int right, const int bottom); @@ -220,10 +233,12 @@ class SALOME_OBJECT_EXPORT SALOME_Actor : public VTKViewer_Actor { vtkProperty* myCellProperty; vtkProperty* myEdgeProperty; + vtkPointPicker* myPointPicker; + vtkCellPicker* myCellPicker; + VTKViewer_CellRectPicker* myCellRectPicker; + SVTK_Actor* myPreHighlightActor; SVTK_Actor* myHighlightActor; }; - #endif // SALOME_ACTOR_H - diff --git a/src/SVTK/SVTK_InteractorStyle.cxx b/src/SVTK/SVTK_InteractorStyle.cxx index 89e522ea3..c87a9072d 100644 --- a/src/SVTK/SVTK_InteractorStyle.cxx +++ b/src/SVTK/SVTK_InteractorStyle.cxx @@ -35,13 +35,11 @@ #include "VTKViewer_Utilities.h" #include "VTKViewer_RectPicker.h" -#include "SVTK_RenderWindowInteractor.h" #include "SVTK_RenderWindow.h" #include "SVTK_ViewWindow.h" #include "SVTK_Selection.h" #include "SALOME_Actor.h" -#include "SVTK_Actor.h" #include "SVTK_Selector.h" #include "SALOME_ListIteratorOfListIO.hxx" @@ -63,6 +61,7 @@ #include #include #include +#include #include //VRV: porting on Qt 3.0.5 @@ -83,30 +82,6 @@ static int MYDEBUG = 0; namespace { - int - GetEdgeId(vtkPicker *thePicker, SALOME_Actor *theActor, int theObjId) - { - int anEdgeId = -1; - if (vtkCell* aPickedCell = theActor->GetElemCell(theObjId)) { - float aPickPosition[3]; - thePicker->GetPickPosition(aPickPosition); - float aMinDist = 1000000.0, aDist = 0; - for (int i = 0, iEnd = aPickedCell->GetNumberOfEdges(); i < iEnd; i++){ - if(vtkLine* aLine = vtkLine::SafeDownCast(aPickedCell->GetEdge(i))){ - int subId; float pcoords[3], closestPoint[3], weights[3]; - aLine->EvaluatePosition(aPickPosition,closestPoint,subId,pcoords,aDist,weights); - if (aDist < aMinDist) { - aMinDist = aDist; - anEdgeId = i; - } - } - } - } - return anEdgeId; - } - - - bool CheckDimensionId(Selection_Mode theMode, SALOME_Actor *theActor, vtkIdType theObjId){ switch(theMode){ case CellSelection: @@ -136,11 +111,6 @@ SVTK_InteractorStyle this->ForcedState = VTK_INTERACTOR_STYLE_CAMERA_NONE; loadCursors(); - myPreSelectionActor = SVTK_Actor::New(); - myPreSelectionActor->GetProperty()->SetColor(0,1,1); - myPreSelectionActor->GetProperty()->SetLineWidth(5); - myPreSelectionActor->GetProperty()->SetPointSize(5); - OnSelectionModeChanged(); } @@ -149,7 +119,6 @@ SVTK_InteractorStyle ::~SVTK_InteractorStyle() { if(MYDEBUG) INFOS("SVTK_InteractorStyle::~SVTK_InteractorStyle()"); - myViewWindow->RemoveActor(myPreSelectionActor); } //---------------------------------------------------------------------------- @@ -168,28 +137,40 @@ SVTK_InteractorStyle const double& theBlue, const int& theWidth) { + /* if ( myPreSelectionActor->GetProperty() == 0 ) return; myPreSelectionActor->GetProperty()->SetColor(theRed, theGreen, theBlue); myPreSelectionActor->GetProperty()->SetLineWidth(theWidth); myPreSelectionActor->GetProperty()->SetPointSize(theWidth); + */ } //---------------------------------------------------------------------------- -void +int SVTK_InteractorStyle -::SetInteractor(vtkRenderWindowInteractor *theInteractor) +::GetState() { - myInteractor = dynamic_cast(theInteractor); - Superclass::SetInteractor(theInteractor); + return State | ForcedState; } //---------------------------------------------------------------------------- -int +SVTK_SelectionEvent SVTK_InteractorStyle -::GetState() +::GetSelectionEvent() { - return State | ForcedState; + SVTK_SelectionEvent aSelectionEvent; + + int x, y, w, h; + Interactor->GetEventPosition( x, y ); + Interactor->GetSize( w, h ); + + aSelectionEvent.X = x; + aSelectionEvent.Y = h - y - 1; + aSelectionEvent.IsCtrl = Interactor->GetControlKey(); + aSelectionEvent.IsShift = Interactor->GetShiftKey(); + + return aSelectionEvent; } //---------------------------------------------------------------------------- @@ -198,8 +179,6 @@ SVTK_InteractorStyle ::setViewWindow(SVTK_ViewWindow* theViewWindow) { myViewWindow = theViewWindow; - myViewWindow->AddActor(myPreSelectionActor); - myPreSelectionActor->Delete(); } //---------------------------------------------------------------------------- @@ -304,6 +283,119 @@ SVTK_InteractorStyle } +//---------------------------------------------------------------------------- +void +SVTK_InteractorStyle +::OnMouseMove() +{ + //cout << "void SVTK_InteractorStyle::OnMouseMove()" << endl; + + int x, y; + this->Interactor->GetEventPosition( x, y ); + this->OnMouseMove( this->Interactor->GetControlKey(), + this->Interactor->GetShiftKey(), + x, y ); +} + + +//---------------------------------------------------------------------------- +void +SVTK_InteractorStyle +::OnLeftButtonDown() +{ + //cout << "void SVTK_InteractorStyle::OnLeftButtonDown()" << endl; + + int x, y; + this->Interactor->GetEventPosition( x, y ); + this->OnLeftButtonDown( this->Interactor->GetControlKey(), + this->Interactor->GetShiftKey(), + x, y ); +} + + +//---------------------------------------------------------------------------- +void +SVTK_InteractorStyle +::OnLeftButtonUp() +{ + //cout << "void SVTK_InteractorStyle::OnLeftButtonUp()" << endl; + + int x, y; + this->Interactor->GetEventPosition( x, y ); + this->OnLeftButtonUp( this->Interactor->GetControlKey(), + this->Interactor->GetShiftKey(), + x, y ); +} + + +//---------------------------------------------------------------------------- +void +SVTK_InteractorStyle +::OnMiddleButtonDown() +{ + //cout << "void SVTK_InteractorStyle::OnMiddleButtonDown()" << endl; + + int x, y; + this->Interactor->GetEventPosition( x, y ); + this->OnMiddleButtonDown( this->Interactor->GetControlKey(), + this->Interactor->GetShiftKey(), + x, y ); +} + + +//---------------------------------------------------------------------------- +void +SVTK_InteractorStyle +::OnMiddleButtonUp() +{ + //cout << "void SVTK_InteractorStyle::OnMiddleButtonUp()" << endl; + + int x, y; + this->Interactor->GetEventPosition( x, y ); + this->OnMiddleButtonUp( this->Interactor->GetControlKey(), + this->Interactor->GetShiftKey(), + x, y ); +} + + +//---------------------------------------------------------------------------- +void +SVTK_InteractorStyle +::OnRightButtonDown() +{ + //cout << "void SVTK_InteractorStyle::OnRightButtonDown()" << endl; + + int x, y; + this->Interactor->GetEventPosition( x, y ); + this->OnRightButtonDown( this->Interactor->GetControlKey(), + this->Interactor->GetShiftKey(), + x, y ); +} + +//---------------------------------------------------------------------------- +void +SVTK_InteractorStyle +::OnRightButtonUp() +{ + //cout << "void SVTK_InteractorStyle::OnRightButtonUp()" << endl; + + int x, y; + this->Interactor->GetEventPosition( x, y ); + this->OnRightButtonUp( this->Interactor->GetControlKey(), + this->Interactor->GetShiftKey(), + x, y ); + /* + if( State == VTK_INTERACTOR_STYLE_CAMERA_NONE ) + { + QContextMenuEvent aEvent( QContextMenuEvent::Mouse, + event->pos(), event->globalPos(), + event->state() ); + emit contextMenuRequested( &aEvent ); + } + */ +} + + //---------------------------------------------------------------------------- void SVTK_InteractorStyle @@ -316,6 +408,9 @@ SVTK_InteractorStyle onOperation(QPoint(x, y)); else if (ForcedState == VTK_INTERACTOR_STYLE_CAMERA_NONE) onCursorMove(QPoint(x, y)); + + if( needsRedrawing() ) + emit RenderWindowModified() ; } @@ -880,7 +975,7 @@ SVTK_InteractorStyle if (State == VTK_INTERACTOR_STYLE_CAMERA_FIT) { // making fit rect opeation int w, h; - myInteractor->GetSize(w, h); + Interactor->GetSize(w, h); int x1, y1, x2, y2; x1 = rect.left(); y1 = h - rect.top() - 1; @@ -893,35 +988,35 @@ SVTK_InteractorStyle if (myPoint == myOtherPoint) { // process point selection int w, h, x, y; - myInteractor->GetSize(w, h); + Interactor->GetSize(w, h); x = myPoint.x(); y = h - myPoint.y() - 1; this->FindPokedRenderer(x, y); - myInteractor->StartPickCallback(); + Interactor->StartPickCallback(); - vtkPicker* aPicker = vtkPicker::SafeDownCast(myInteractor->GetPicker()); + vtkPicker* aPicker = vtkPicker::SafeDownCast(Interactor->GetPicker()); aPicker->Pick(x, y, 0.0, this->CurrentRenderer); SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast(aPicker->GetActor()); - SVTK_SelectionEvent aSelectionEvent = myInteractor->GetSelectionEvent(); + SVTK_SelectionEvent aSelectionEvent = GetSelectionEvent(); aSelectionEvent.SelectionMode = aSelectionMode; aSelectionEvent.IsRectangle = false; if( aSActor ) - aSActor->Highlight( this, GetSelector(), this->CurrentRenderer, aSelectionEvent, true, true ); + aSActor->Highlight( this, GetSelector(), this->CurrentRenderer, aSelectionEvent, true ); else { this->HighlightProp( NULL ); GetSelector()->ClearIObjects(); } - myInteractor->EndPickCallback(); + Interactor->EndPickCallback(); } else { //processing rectangle selection if(aSelActiveCompOnly && aComponentDataType.isEmpty()) return; - myInteractor->StartPickCallback(); + Interactor->StartPickCallback(); if (!myShiftState) { this->PropPicked = 0; @@ -934,14 +1029,14 @@ SVTK_InteractorStyle QRect rect(myPoint, myOtherPoint); rect = rect.normalize(); int w, h; - myInteractor->GetSize(w, h); + Interactor->GetSize(w, h); int x1, y1, x2, y2; x1 = rect.left(); y1 = h - rect.top() - 1; x2 = rect.right(); y2 = h - rect.bottom() - 1; - SVTK_SelectionEvent aSelectionEvent = myInteractor->GetSelectionEvent(); + SVTK_SelectionEvent aSelectionEvent = GetSelectionEvent(); aSelectionEvent.SelectionMode = aSelectionMode; aSelectionEvent.IsRectangle = true; aSelectionEvent.LastX = x1; @@ -949,16 +1044,16 @@ SVTK_InteractorStyle switch (aSelectionMode) { case NodeSelection: { - if ( vtkPointPicker* aPointPicker = vtkPointPicker::SafeDownCast(myInteractor->GetPicker()) ) { + //if ( vtkPointPicker* aPointPicker = vtkPointPicker::SafeDownCast(Interactor->GetPicker()) ) { vtkActorCollection* aListActors = this->CurrentRenderer->GetActors(); aListActors->InitTraversal(); while (vtkActor* aActor = aListActors->GetNextActor()) { if (!aActor->GetVisibility()) continue; if(SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast(aActor)) - aSActor->Highlight( this, GetSelector(), this->CurrentRenderer, aSelectionEvent, true, true ); + aSActor->Highlight( this, GetSelector(), this->CurrentRenderer, aSelectionEvent, true ); } - } + //} break; } case CellSelection: @@ -975,7 +1070,7 @@ SVTK_InteractorStyle aListActors->InitTraversal(); while(vtkActor* aActor = aListActors->GetNextActor()) if (SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast(aActor)) - aSActor->Highlight( this, GetSelector(), this->CurrentRenderer, aSelectionEvent, true, true ); + aSActor->Highlight( this, GetSelector(), this->CurrentRenderer, aSelectionEvent, true ); } break; case ActorSelection: // objects selection @@ -988,10 +1083,10 @@ SVTK_InteractorStyle aListActors->InitTraversal(); while(vtkActor* aActor = aListActors->GetNextActor()) if (SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast(aActor)) - aSActor->Highlight( this, GetSelector(), this->CurrentRenderer, aSelectionEvent, true, true ); + aSActor->Highlight( this, GetSelector(), this->CurrentRenderer, aSelectionEvent, true ); } // end case 4 } //end switch - myInteractor->EndPickCallback(); + Interactor->EndPickCallback(); } //myViewWindow->onSelectionChanged(); } @@ -1005,7 +1100,7 @@ SVTK_InteractorStyle case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN: { int w, h, x, y; - myInteractor->GetSize(w, h); + Interactor->GetSize(w, h); x = myPoint.x(); y = h - myPoint.y() - 1; Place(x, y); @@ -1088,7 +1183,6 @@ SVTK_InteractorStyle ::OnSelectionModeChanged() { - myPreSelectionActor->SetVisibility(false); myElemId = myEdgeId = myNodeId = -1; mySelectedActor = NULL; } @@ -1103,18 +1197,23 @@ SVTK_InteractorStyle Selection_Mode aSelectionMode = myViewWindow->SelectionMode(); int w, h, x, y; - myInteractor->GetSize(w, h); + Interactor->GetSize(w, h); x = mousePos.x(); y = h - mousePos.y() - 1; this->FindPokedRenderer(x,y); - myInteractor->StartPickCallback(); - myPreSelectionActor->SetVisibility(false); + Interactor->StartPickCallback(); - vtkPicker* aPicker = vtkPicker::SafeDownCast(myInteractor->GetPicker()); + vtkPicker* aPicker = vtkPicker::SafeDownCast(Interactor->GetPicker()); SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast(aPicker->GetActor()); + + SVTK_SelectionEvent aSelectionEvent = GetSelectionEvent(); + aSelectionEvent.X = x; + aSelectionEvent.Y = y; + aSelectionEvent.SelectionMode = aSelectionMode; + if( aSActor ) - aSActor->PreHighlight( this, -1 ); + aSActor->PreHighlight( this, GetSelector(), this->CurrentRenderer, aSelectionEvent, false ); //cout << "onCursorMove : " << ( aSActor ? "1" : "0" ) << " "; aPicker->Pick(x, y, 0.0, this->CurrentRenderer); @@ -1123,97 +1222,18 @@ SVTK_InteractorStyle //cout << ( aSActor ? "1" : "0" ) << endl; if (vtkCellPicker* picker = vtkCellPicker::SafeDownCast(aPicker)) { - int aVtkId = picker->GetCellId(); - if ( aVtkId >= 0 ) { - int anObjId = aSActor->GetElemObjId(aVtkId); - if ( aSActor && aSActor->hasIO() && IsValid( aSActor, aVtkId ) ) { - bool anIsSameObjId = (mySelectedActor == aSActor && myElemId == anObjId); - bool aResult = anIsSameObjId; - if(!anIsSameObjId) { - if(aSelectionMode != EdgeOfCellSelection) { - aResult = CheckDimensionId(aSelectionMode,aSActor,anObjId); - if(aResult){ - mySelectedActor = aSActor; - myElemId = anObjId; - if(MYDEBUG) INFOS(" CellId : "<setCellData(anObjId,aSActor,myPreSelectionActor); - } - } - } - if(aSelectionMode == EdgeOfCellSelection){ - int anEdgeId = GetEdgeId(picker,aSActor,anObjId); - bool anIsSameEdgeId = (myEdgeId != anEdgeId) && anIsSameObjId; - aResult = anIsSameEdgeId; - if(!anIsSameEdgeId) { - aResult = (anEdgeId >= 0); - if (aResult) { - mySelectedActor = aSActor; - myEdgeId = anEdgeId; - myElemId = anObjId; - if(MYDEBUG) INFOS(" CellId : "<setEdgeData(anObjId,aSActor,-anEdgeId-1,myPreSelectionActor); - } - } - } - if(aResult) { - myPreSelectionActor->GetProperty()->SetRepresentationToSurface(); - myPreSelectionActor->SetVisibility(true); - } - } - } + if ( aSActor ) + aSActor->PreHighlight( this, GetSelector(), this->CurrentRenderer, aSelectionEvent, true ); } else if (vtkPointPicker* picker = vtkPointPicker::SafeDownCast(aPicker)) { - int aVtkId = picker->GetPointId(); - //cout << "vtkPointPicker" << endl; - //cout << aSActor << endl; - //cout << aVtkId << endl; - if ( aVtkId >= 0 && IsValid( aSActor, aVtkId, true ) ) { - if ( aSActor && aSActor->hasIO() ) { - int anObjId = aSActor->GetNodeObjId(aVtkId); - aSActor->PreHighlight( this, anObjId ); - /* - bool anIsSameObjId = (mySelectedActor == aSActor && myNodeId == anObjId); - if(!anIsSameObjId) { - mySelectedActor = aSActor; - myNodeId = anObjId; - if(MYDEBUG) INFOS(" PointId : "<setPointData(anObjId,aSActor,myPreSelectionActor); - aSActor->PreHighlight( this, anObjId ); - } - myPreSelectionActor->GetProperty()->SetRepresentationToSurface(); - myPreSelectionActor->SetVisibility(true); - */ - } - } + if ( aSActor ) + aSActor->PreHighlight( this, GetSelector(), this->CurrentRenderer, aSelectionEvent, true ); } else if ( vtkPicker::SafeDownCast(aPicker) ) { - if ( aSActor ) { - if ( myPreViewActor != aSActor ) { - if ( myPreViewActor != NULL ) { - myPreViewActor->SetPreSelected( false ); - } - myPreViewActor = aSActor; - - if ( aSActor->hasIO() ) { - Handle( SALOME_InteractiveObject) IO = aSActor->getIO(); - if ( !GetSelector()->IsSelected(IO) ) { - // Find All actors with same IO - vtkActorCollection* theActors = this->CurrentRenderer->GetActors(); - theActors->InitTraversal(); - while( vtkActor *ac = theActors->GetNextActor() ) { - if ( SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac ) ) { - if ( anActor->hasIO() ) { - Handle(SALOME_InteractiveObject) IOS = anActor->getIO(); - if(IO->isSame(IOS)) { - anActor->SetPreSelected( true ); - } - } - } - } - } - } - } - } else { + if( aSActor ) + aSActor->PreHighlight( this, GetSelector(), this->CurrentRenderer, aSelectionEvent, true ); + /* + else { myPreViewActor = NULL; vtkActorCollection* theActors = this->CurrentRenderer->GetActors(); theActors->InitTraversal(); @@ -1223,9 +1243,10 @@ SVTK_InteractorStyle } } } + */ } - myInteractor->EndPickCallback(); - //myInteractor->Render(); + Interactor->EndPickCallback(); + //Interactor->Render(); myGUIWindow->update(); this->LastPos[0] = x; diff --git a/src/SVTK/SVTK_InteractorStyle.h b/src/SVTK/SVTK_InteractorStyle.h index e9896b6d8..3e04e1483 100644 --- a/src/SVTK/SVTK_InteractorStyle.h +++ b/src/SVTK/SVTK_InteractorStyle.h @@ -38,19 +38,20 @@ class vtkRenderWindowInteractor; #include #include +#include #include #include "VTKViewer_Filter.h" +#include "SVTK_SelectionEvent.h" + class VTKViewer_Trihedron; class SALOME_Actor; -class SVTK_Actor; class SVTK_Viewer; class SVTK_Selector; class SVTK_ViewWindow; -class SVTK_RenderWindowInteractor; #define VTK_INTERACTOR_STYLE_CAMERA_NONE 0 #define VTK_INTERACTOR_STYLE_CAMERA_ROTATE 1 @@ -74,18 +75,28 @@ class SVTK_EXPORT SVTK_InteractorStyle : public QObject, static SVTK_InteractorStyle *New(); vtkTypeMacro(SVTK_InteractorStyle, vtkInteractorStyle); - virtual void SetInteractor(vtkRenderWindowInteractor *theInteractor); void setViewWindow(SVTK_ViewWindow* theViewWindow); void setGUIWindow(QWidget* theWindow); virtual int GetState(); + SVTK_SelectionEvent GetSelectionEvent(); + //merge with V2_2_0_VISU_improvements:void setTriedron(VTKViewer_Trihedron* theTrihedron); void setPreselectionProp(const double& theRed = 0, const double& theGreen = 1, const double& theBlue = 1, const int& theWidth = 5); + // VTK events + virtual void OnMouseMove(); + virtual void OnLeftButtonDown(); + virtual void OnLeftButtonUp(); + virtual void OnMiddleButtonDown(); + virtual void OnMiddleButtonUp(); + virtual void OnRightButtonDown(); + virtual void OnRightButtonUp(); + // Generic event bindings must be overridden in subclasses void OnMouseMove (int ctrl, int shift, int x, int y); void OnLeftButtonDown(int ctrl, int shift, int x, int y); @@ -133,7 +144,6 @@ class SVTK_EXPORT SVTK_InteractorStyle : public QObject, SALOME_Actor* myPreViewActor; - SVTK_Actor* myPreSelectionActor; SALOME_Actor* mySelectedActor; int myElemId; int myEdgeId; @@ -158,6 +168,10 @@ class SVTK_EXPORT SVTK_InteractorStyle : public QObject, void onCursorMove(QPoint mousePos); void setCursor(const int operation); + signals: + void RenderWindowModified() ; + void contextMenuRequested( QContextMenuEvent *e ); + protected: QCursor myDefCursor; QCursor myPanCursor; @@ -172,7 +186,6 @@ class SVTK_EXPORT SVTK_InteractorStyle : public QObject, bool myShiftState; int ForcedState; - SVTK_RenderWindowInteractor* myInteractor; SVTK_ViewWindow* myViewWindow; //merge with V2_2_0_VISU_improvements:VTKViewer_Trihedron* myTrihedron; QWidget* myGUIWindow; diff --git a/src/SVTK/SVTK_RenderWindowInteractor.cxx b/src/SVTK/SVTK_RenderWindowInteractor.cxx index 10e8cb5a4..bfc3eb3d5 100644 --- a/src/SVTK/SVTK_RenderWindowInteractor.cxx +++ b/src/SVTK/SVTK_RenderWindowInteractor.cxx @@ -28,7 +28,6 @@ #include "SVTK_RenderWindowInteractor.h" -#include "SVTK_InteractorStyle.h" #include "SVTK_RenderWindow.h" #include "SVTK_Selection.h" @@ -46,8 +45,10 @@ #include #include #include +#include #include #include +#include // QT Includes #include @@ -162,69 +163,6 @@ SVTK_RenderWindowInteractor return ; } -//---------------------------------------------------------------------------- -void -SVTK_RenderWindowInteractor -::SetInteractorStyle(vtkInteractorObserver *theInteractor) -{ - myInteractorStyle = dynamic_cast(theInteractor); - vtkRenderWindowInteractor::SetInteractorStyle(theInteractor); -} - - -void -SVTK_RenderWindowInteractor -::SetSelectionMode(Selection_Mode theMode) -{ - 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(); -} - -void -SVTK_RenderWindowInteractor -::SetSelectionProp(const double& theRed, - const double& theGreen, - const double& theBlue, - const int& theWidth) -{ - /* - myCellActor->GetProperty()->SetColor(theRed, theGreen, theBlue); - myCellActor->GetProperty()->SetLineWidth(theWidth); - - myPointActor->GetProperty()->SetColor(theRed, theGreen, theBlue); - myPointActor->GetProperty()->SetPointSize(theWidth); - */ -} - -void -SVTK_RenderWindowInteractor -::SetSelectionTolerance(const double& theTolNodes, - const double& theTolItems) -{ - myTolNodes = theTolNodes; - myTolItems = theTolItems; - - myBasicPicker->SetTolerance(myTolItems); - myCellPicker->SetTolerance(myTolItems); - myPointPicker->SetTolerance(myTolNodes); - -} - // ================================== void SVTK_RenderWindowInteractor @@ -289,7 +227,8 @@ SVTK_RenderWindowInteractor return ; } - myInteractorStyle->OnTimer(); + vtkInteractorStyle* aStyle = vtkInteractorStyle::SafeDownCast( InteractorStyle ); + aStyle->OnTimer(); emit RenderWindowModified(); } @@ -301,9 +240,13 @@ SVTK_RenderWindowInteractor if( ! this->Enabled ) { return ; } - myInteractorStyle->OnMouseMove(0, 0, event->x(), event->y()/*this->Size[1] - event->y() - 1*/) ; - if (myInteractorStyle->needsRedrawing() ) - emit RenderWindowModified() ; + + this->SetEventInformation( event->x(), event->y(), + ( event->state() & ControlButton ), + ( event->state() & ShiftButton ) ); + + if( this->HasObserver( vtkCommand::MouseMoveEvent ) ) + this->InvokeEvent( vtkCommand::MouseMoveEvent, NULL ); } void @@ -313,9 +256,13 @@ SVTK_RenderWindowInteractor if( ! this->Enabled ) { return ; } - myInteractorStyle->OnLeftButtonDown((event->state() & ControlButton), - (event->state() & ShiftButton), - event->x(), event->y()); + + this->SetEventInformation( event->x(), event->y(), + ( event->state() & ControlButton ), + ( event->state() & ShiftButton ) ); + + if( this->HasObserver( vtkCommand::LeftButtonPressEvent ) ) + this->InvokeEvent( vtkCommand::LeftButtonPressEvent, NULL ); } void @@ -324,13 +271,13 @@ SVTK_RenderWindowInteractor if( ! this->Enabled ) { return ; } - this->SetEventInformationFlipY( event->x(), event->y(), - ( event->state() & ControlButton ), - ( event->state() & ShiftButton ) ); - myInteractorStyle->OnLeftButtonUp( (event->state() & ControlButton), - (event->state() & ShiftButton), - event->x(), event->y() ) ; + this->SetEventInformation( event->x(), event->y(), + ( event->state() & ControlButton ), + ( event->state() & ShiftButton ) ); + + if( this->HasObserver( vtkCommand::LeftButtonReleaseEvent ) ) + this->InvokeEvent( vtkCommand::LeftButtonReleaseEvent, NULL ); } void @@ -340,9 +287,13 @@ SVTK_RenderWindowInteractor if( ! this->Enabled ) { return ; } - myInteractorStyle->OnMiddleButtonDown((event->state() & ControlButton), - (event->state() & ShiftButton), - event->x(), event->y() ) ; + + this->SetEventInformation( event->x(), event->y(), + ( event->state() & ControlButton ), + ( event->state() & ShiftButton ) ); + + if( this->HasObserver( vtkCommand::MiddleButtonPressEvent ) ) + this->InvokeEvent( vtkCommand::MiddleButtonPressEvent, NULL ); } void @@ -352,9 +303,13 @@ SVTK_RenderWindowInteractor if( ! this->Enabled ) { return ; } - myInteractorStyle->OnMiddleButtonUp( (event->state() & ControlButton), - (event->state() & ShiftButton), - event->x(), event->y() ) ; + + this->SetEventInformation( event->x(), event->y(), + ( event->state() & ControlButton ), + ( event->state() & ShiftButton ) ); + + if( this->HasObserver( vtkCommand::MiddleButtonReleaseEvent ) ) + this->InvokeEvent( vtkCommand::MiddleButtonReleaseEvent, NULL ); } void @@ -364,9 +319,13 @@ SVTK_RenderWindowInteractor if( ! this->Enabled ) { return ; } - myInteractorStyle->OnRightButtonDown( (event->state() & ControlButton), - (event->state() & ShiftButton), - event->x(), event->y() ) ; + + this->SetEventInformation( event->x(), event->y(), + ( event->state() & ControlButton ), + ( event->state() & ShiftButton ) ); + + if( this->HasObserver( vtkCommand::RightButtonPressEvent ) ) + this->InvokeEvent( vtkCommand::RightButtonPressEvent, NULL ); } void @@ -376,11 +335,15 @@ SVTK_RenderWindowInteractor if( ! this->Enabled ) { return ; } - myInteractorStyle->OnRightButtonUp( (event->state() & ControlButton), - (event->state() & ShiftButton), - event->x(), event->y() ) ; - if(myInteractorStyle->GetState() == VTK_INTERACTOR_STYLE_CAMERA_NONE && !( event->state() & KeyButtonMask )){ + this->SetEventInformation( event->x(), event->y(), + ( event->state() & ControlButton ), + ( event->state() & ShiftButton ) ); + + if( this->HasObserver( vtkCommand::RightButtonReleaseEvent ) ) + this->InvokeEvent( vtkCommand::RightButtonReleaseEvent, NULL ); + + if(/*myInteractorStyle->GetState() == VTK_INTERACTOR_STYLE_CAMERA_NONE && */!( event->state() & KeyButtonMask )){ QContextMenuEvent aEvent( QContextMenuEvent::Mouse, event->pos(), event->globalPos(), event->state() ); @@ -752,20 +715,3 @@ SVTK_RenderWindowInteractor TSetFunction (&SALOME_Actor::setName,theName.latin1())); } - -SVTK_SelectionEvent -SVTK_RenderWindowInteractor -::GetSelectionEvent() -{ - SVTK_SelectionEvent aSelectionEvent; - - int x, y; - this->GetEventPosition( x, y ); - - aSelectionEvent.X = x; - aSelectionEvent.Y = y; - aSelectionEvent.IsCtrl = this->GetControlKey(); - aSelectionEvent.IsShift = this->GetShiftKey(); - - return aSelectionEvent; -} diff --git a/src/SVTK/SVTK_RenderWindowInteractor.h b/src/SVTK/SVTK_RenderWindowInteractor.h index 61ad36d5c..6207cec54 100644 --- a/src/SVTK/SVTK_RenderWindowInteractor.h +++ b/src/SVTK/SVTK_RenderWindowInteractor.h @@ -30,7 +30,7 @@ #define SVTK_RenderWindowInteractor_h #include "SVTK.h" -#include "SVTK_SelectionEvent.h" +#include "SVTK_Selection.h" #include "SALOME_InteractiveObject.hxx" @@ -56,7 +56,6 @@ class SALOME_Actor; class SVTK_ViewWindow; class SVTK_RenderWindow; -class SVTK_InteractorStyle; // ------------------------------------------------------------ // :TRICKY: Fri Apr 21 22:19:27 2000 Pagey @@ -82,9 +81,6 @@ public: // want to have mouse interaction. virtual void Initialize(); - virtual void SetInteractorStyle(vtkInteractorObserver *); - SVTK_InteractorStyle* GetSInteractorStyle(){ return myInteractorStyle;} - // Description: // This will start up the X event loop and never return. If you // call this method it will loop processing X events until the @@ -108,7 +104,7 @@ public: bool isInViewer( const Handle(SALOME_InteractiveObject)& IObject); bool isVisible( const Handle(SALOME_InteractiveObject)& IObject); void rename(const Handle(SALOME_InteractiveObject)& IObject, QString newName); - + /* void SetSelectionMode(Selection_Mode mode); void SetSelectionProp(const double& theRed = 1, const double& theGreen = 1, @@ -116,7 +112,7 @@ public: const int& theWidth = 5); void SetSelectionTolerance(const double& theTolNodes = 0.025, const double& theTolCell = 0.001); - + */ // Displaymode management int GetDisplayMode(); void SetDisplayMode(int); @@ -164,15 +160,11 @@ public: vtkRenderer* GetRenderer(); - SVTK_SelectionEvent GetSelectionEvent(); - protected: SVTK_RenderWindowInteractor(); ~SVTK_RenderWindowInteractor(); - SVTK_InteractorStyle* myInteractorStyle; - // Timer used during various mouse events to figure // out mouse movements. QTimer *mTimer ; diff --git a/src/SVTK/SVTK_ViewWindow.cxx b/src/SVTK/SVTK_ViewWindow.cxx index 69eda9c15..30c000a44 100755 --- a/src/SVTK/SVTK_ViewWindow.cxx +++ b/src/SVTK/SVTK_ViewWindow.cxx @@ -7,6 +7,8 @@ #include #include #include +#include +#include #include "QtxAction.h" @@ -19,6 +21,7 @@ #include "VTKViewer_Transform.h" #include "VTKViewer_Utilities.h" +#include "VTKViewer_CellRectPicker.h" #include "SVTK_Trihedron.h" #include "SVTK_CubeAxesActor2D.h" @@ -80,15 +83,15 @@ SVTK_ViewWindow myRWInteractor->SetRenderWindow( myRenderWindow->getRenderWindow() ); //myRWInteractor->setViewWindow( this ); - SVTK_InteractorStyle* RWS = SVTK_InteractorStyle::New(); - RWS->setGUIWindow( myRenderWindow ); - RWS->setViewWindow( this ); + myInteractorStyle = SVTK_InteractorStyle::New(); + myInteractorStyle->setGUIWindow( myRenderWindow ); + myInteractorStyle->setViewWindow( this ); - myRWInteractor->SetInteractorStyle( RWS ); + myRWInteractor->SetInteractorStyle( myInteractorStyle ); myRWInteractor->Initialize(); - //merge with V2_2_0_VISU_improvements:RWS->setTriedron( myTrihedron ); - RWS->FindPokedRenderer( 0, 0 ); + //merge with V2_2_0_VISU_improvements:myInteractorStyle->setTriedron( myTrihedron ); + myInteractorStyle->FindPokedRenderer( 0, 0 ); SetSelectionMode(ActorSelection); @@ -135,6 +138,8 @@ SVTK_ViewWindow connect( myRenderWindow, SIGNAL(MouseMove( QMouseEvent* )), this, SLOT(onMouseMoving( QMouseEvent* )) ); + connect( myInteractorStyle, SIGNAL(RenderWindowModified()), + myRenderWindow, SLOT(update()) ); connect( myRWInteractor, SIGNAL(RenderWindowModified()), myRenderWindow, SLOT(update()) ); connect( myRWInteractor, SIGNAL(contextMenuRequested( QContextMenuEvent * )), @@ -166,7 +171,7 @@ void SVTK_ViewWindow ::activateZoom() { - myRWInteractor->GetSInteractorStyle()->startZoom(); + myInteractorStyle->startZoom(); } //---------------------------------------------------------------------------- @@ -174,7 +179,7 @@ void SVTK_ViewWindow ::activatePanning() { - myRWInteractor->GetSInteractorStyle()->startPan(); + myInteractorStyle->startPan(); } //---------------------------------------------------------------------------- @@ -182,7 +187,7 @@ void SVTK_ViewWindow ::activateRotation() { - myRWInteractor->GetSInteractorStyle()->startRotate(); + myInteractorStyle->startRotate(); } //---------------------------------------------------------------------------- @@ -191,7 +196,7 @@ SVTK_ViewWindow ::activateGlobalPanning() { if(myTrihedron->GetVisibleActorCount(myRenderer)) - myRWInteractor->GetSInteractorStyle()->startGlobalPan(); + myInteractorStyle->startGlobalPan(); } //---------------------------------------------------------------------------- @@ -199,7 +204,7 @@ void SVTK_ViewWindow ::activateWindowFit() { - myRWInteractor->GetSInteractorStyle()->startFitArea(); + myInteractorStyle->startFitArea(); } //---------------------------------------------------------------------------- @@ -522,7 +527,7 @@ SVTK_ViewWindow { mySelector->SetSelectionMode(theMode); - myRWInteractor->SetSelectionMode(theMode); + //myRWInteractor->SetSelectionMode(theMode); } //---------------------------------------------------------------- @@ -830,7 +835,7 @@ void SVTK_ViewWindow ::onPanLeft() { - myRWInteractor->GetSInteractorStyle()->IncrementalPan( -INCREMENT_FOR_OP, 0 ); + myInteractorStyle->IncrementalPan( -INCREMENT_FOR_OP, 0 ); } //======================================================================= @@ -841,7 +846,7 @@ void SVTK_ViewWindow ::onPanRight() { - myRWInteractor->GetSInteractorStyle()->IncrementalPan( INCREMENT_FOR_OP, 0 ); + myInteractorStyle->IncrementalPan( INCREMENT_FOR_OP, 0 ); } //======================================================================= @@ -852,7 +857,7 @@ void SVTK_ViewWindow ::onPanUp() { - myRWInteractor->GetSInteractorStyle()->IncrementalPan( 0, INCREMENT_FOR_OP ); + myInteractorStyle->IncrementalPan( 0, INCREMENT_FOR_OP ); } //======================================================================= @@ -863,7 +868,7 @@ void SVTK_ViewWindow ::onPanDown() { - myRWInteractor->GetSInteractorStyle()->IncrementalPan( 0, -INCREMENT_FOR_OP ); + myInteractorStyle->IncrementalPan( 0, -INCREMENT_FOR_OP ); } //======================================================================= @@ -874,7 +879,7 @@ void SVTK_ViewWindow ::onZoomIn() { - myRWInteractor->GetSInteractorStyle()->IncrementalZoom( INCREMENT_FOR_OP ); + myInteractorStyle->IncrementalZoom( INCREMENT_FOR_OP ); } //======================================================================= @@ -885,7 +890,7 @@ void SVTK_ViewWindow ::onZoomOut() { - myRWInteractor->GetSInteractorStyle()->IncrementalZoom( -INCREMENT_FOR_OP ); + myInteractorStyle->IncrementalZoom( -INCREMENT_FOR_OP ); } //======================================================================= @@ -896,7 +901,7 @@ void SVTK_ViewWindow ::onRotateLeft() { - myRWInteractor->GetSInteractorStyle()->IncrementalRotate( -INCREMENT_FOR_OP, 0 ); + myInteractorStyle->IncrementalRotate( -INCREMENT_FOR_OP, 0 ); } //======================================================================= @@ -907,7 +912,7 @@ void SVTK_ViewWindow ::onRotateRight() { - myRWInteractor->GetSInteractorStyle()->IncrementalRotate( INCREMENT_FOR_OP, 0 ); + myInteractorStyle->IncrementalRotate( INCREMENT_FOR_OP, 0 ); } //======================================================================= @@ -918,7 +923,7 @@ void SVTK_ViewWindow ::onRotateUp() { - myRWInteractor->GetSInteractorStyle()->IncrementalRotate( 0, -INCREMENT_FOR_OP ); + myInteractorStyle->IncrementalRotate( 0, -INCREMENT_FOR_OP ); } //======================================================================= @@ -977,7 +982,7 @@ void SVTK_ViewWindow ::onRotateDown() { - myRWInteractor->GetSInteractorStyle()->IncrementalRotate( 0, INCREMENT_FOR_OP ); + myInteractorStyle->IncrementalRotate( 0, INCREMENT_FOR_OP ); } //---------------------------------------------------------------------------- @@ -1033,3 +1038,46 @@ SVTK_ViewWindow QPixmap px = QPixmap::grabWindow( myRenderWindow->winId() ); return px.convertToImage(); } + +void +SVTK_ViewWindow +::SetSelectionProp(const double& theRed, + const double& theGreen, + const double& theBlue, + const int& theWidth) +{ + vtkActorCollection* anActors = getRenderer()->GetActors(); + anActors->InitTraversal(); + while( vtkActor* anActor = anActors->GetNextActor() ) + { + if( SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast( anActor ) ) + { + aSActor->getPointProperty()->SetColor( theRed, theGreen, theBlue ); + aSActor->getPointProperty()->SetLineWidth( theWidth ); + + aSActor->getCellProperty()->SetColor( theRed, theGreen, theBlue ); + aSActor->getCellProperty()->SetLineWidth( theWidth ); + + aSActor->getEdgeProperty()->SetColor( theRed, theGreen, theBlue ); + aSActor->getEdgeProperty()->SetLineWidth( theWidth ); + } + } +} + +void +SVTK_ViewWindow +::SetSelectionTolerance(const double& theTolNodes, + const double& theTolItems) +{ + vtkActorCollection* anActors = getRenderer()->GetActors(); + anActors->InitTraversal(); + while( vtkActor* anActor = anActors->GetNextActor() ) + { + if( SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast( anActor ) ) + { + aSActor->getPointPicker()->SetTolerance( theTolNodes ); + aSActor->getCellPicker()->SetTolerance( theTolItems ); + aSActor->getCellRectPicker()->SetTolerance( theTolItems ); + } + } +} diff --git a/src/SVTK/SVTK_ViewWindow.h b/src/SVTK/SVTK_ViewWindow.h index 18a9dc768..4c7585b92 100755 --- a/src/SVTK/SVTK_ViewWindow.h +++ b/src/SVTK/SVTK_ViewWindow.h @@ -28,6 +28,7 @@ class SVTK_CubeAxesActor2D; class SVTK_RenderWindow; class SVTK_InteractorStyle; class SVTK_RenderWindowInteractor; +class SVTK_InteractorStyle; class SVTK_EXPORT SVTK_ViewWindow : public SUIT_ViewWindow { @@ -46,6 +47,7 @@ public: SVTK_Selector* GetSelector() {return mySelector;} SVTK_RenderWindow* getRenderWindow() {return myRenderWindow;} SVTK_RenderWindowInteractor* getRWInteractor() {return myRWInteractor;} + SVTK_InteractorStyle* getInteractorStyle(){ return myInteractorStyle;} Selection_Mode SelectionMode() const; void SetSelectionMode(Selection_Mode theMode); @@ -89,6 +91,13 @@ public: VTKViewer_Trihedron* GetTrihedron() {return this->myTrihedron;}; SVTK_CubeAxesActor2D* GetCubeAxes() {return this->myCubeAxes;}; + void SetSelectionProp(const double& theRed = 1, + const double& theGreen = 1, + const double& theBlue = 0, + const int& theWidth = 5); + void SetSelectionTolerance(const double& theTolNodes = 0.025, + const double& theTolCell = 0.001); + public slots: void onSelectionChanged(); @@ -161,6 +170,7 @@ private: SVTK_RenderWindow* myRenderWindow; SVTK_RenderWindowInteractor* myRWInteractor; + SVTK_InteractorStyle* myInteractorStyle; VTKViewer_Transform* myTransform; VTKViewer_Trihedron* myTrihedron; -- 2.39.2