From: apo Date: Mon, 5 Sep 2005 07:24:29 +0000 (+0000) Subject: To improve SVTK Viewer architecture X-Git-Tag: BR-D5-38-2003_D2005-12-09~15 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b686027b2262e2cb2f9daf1c617b9edb9eb65fc0;p=modules%2Fgui.git To improve SVTK Viewer architecture --- diff --git a/src/SALOME_PY/SalomePy.cxx b/src/SALOME_PY/SalomePy.cxx index cfce008c9..ea2fcc976 100755 --- a/src/SALOME_PY/SalomePy.cxx +++ b/src/SALOME_PY/SalomePy.cxx @@ -132,7 +132,7 @@ public: virtual void Execute() { if( SVTK_ViewWindow* aVTKViewWindow = GetVTKViewWindow() ) { PyObject* aPyClass = GetPyClass("vtkRenderWindow"); - vtkRenderWindow* aVTKObject = aVTKViewWindow->getRenderWindow()->getRenderWindow(); + vtkRenderWindow* aVTKObject = aVTKViewWindow->getView()->GetRenderWindow(); myResult = PyVTKObject_New(aPyClass,aVTKObject); } } @@ -153,7 +153,7 @@ public: virtual void Execute() { if( SVTK_ViewWindow* aVTKViewWindow = GetVTKViewWindow() ) { PyObject* aPyClass = GetPyClass("vtkRenderWindowInteractor"); - vtkRenderWindowInteractor* aVTKObject = aVTKViewWindow->getRWInteractor()->getDevice(); + vtkRenderWindowInteractor* aVTKObject = aVTKViewWindow->getView()->GetRenderWindowInteractor(); myResult = PyVTKObject_New(aPyClass,aVTKObject); } } diff --git a/src/SVTK/SALOME_Actor.cxx b/src/SVTK/SALOME_Actor.cxx index 235972015..764b2a0d4 100644 --- a/src/SVTK/SALOME_Actor.cxx +++ b/src/SVTK/SALOME_Actor.cxx @@ -550,8 +550,7 @@ SALOME_Actor //---------------------------------------------------------------- bool SALOME_Actor -::PreHighlight( VTK::TValidator* theValidator, - SVTK_Selector* theSelector, +::PreHighlight( SVTK_Selector* theSelector, vtkRenderer* theRenderer, SVTK_SelectionEvent theSelectionEvent, bool theIsHighlight ) @@ -588,7 +587,7 @@ SALOME_Actor myPointPicker->Pick( x, y, z, theRenderer ); int aVtkId = myPointPicker->GetPointId(); - if( aVtkId >= 0 && theValidator->IsValid( this, aVtkId, true ) && hasIO() ) + if( aVtkId >= 0 && theSelector->IsValid( this, aVtkId, true ) && hasIO() ) { int anObjId = GetNodeObjId( aVtkId ); TColStd_IndexedMapOfInteger aMapIndex; @@ -608,7 +607,7 @@ SALOME_Actor myCellPicker->Pick( x, y, z, theRenderer ); int aVtkId = myCellPicker->GetCellId(); - if ( aVtkId >= 0 && theValidator->IsValid( this, aVtkId ) && hasIO() ) + if ( aVtkId >= 0 && theSelector->IsValid( this, aVtkId ) && hasIO() ) { int anObjId = GetElemObjId (aVtkId ); TColStd_IndexedMapOfInteger aMapIndex; @@ -628,7 +627,7 @@ SALOME_Actor myCellPicker->Pick( x, y, z, theRenderer ); int aVtkId = myCellPicker->GetCellId(); - if ( aVtkId >= 0 && theValidator->IsValid( this, aVtkId ) && hasIO() ) + if ( aVtkId >= 0 && theSelector->IsValid( this, aVtkId ) && hasIO() ) { int anObjId = GetElemObjId( aVtkId ); int anEdgeId = GetEdgeId( myCellPicker, anObjId ); @@ -673,8 +672,7 @@ SALOME_Actor //---------------------------------------------------------------- bool SALOME_Actor -::Highlight( VTK::TValidator* theValidator, - SVTK_Selector* theSelector, +::Highlight( SVTK_Selector* theSelector, vtkRenderer* theRenderer, SVTK_SelectionEvent theSelectionEvent, bool theIsHighlight ) @@ -696,7 +694,7 @@ SALOME_Actor myPointPicker->Pick( x1, y1, z1, theRenderer ); int aVtkId = myPointPicker->GetPointId(); - if( aVtkId >= 0 && hasIO() && theValidator->IsValid( this, aVtkId, true ) ) + if( aVtkId >= 0 && hasIO() && theSelector->IsValid( this, aVtkId, true ) ) { int anObjId = GetNodeObjId( aVtkId ); if( anObjId >= 0 ) @@ -720,7 +718,7 @@ SALOME_Actor myCellPicker->Pick( x1, y1, z1, theRenderer ); int aVtkId = myCellPicker->GetCellId(); - if( aVtkId >= 0 && hasIO() && theValidator->IsValid( this, aVtkId ) ) + if( aVtkId >= 0 && hasIO() && theSelector->IsValid( this, aVtkId ) ) { int anObjId = GetElemObjId( aVtkId ); if( anObjId >= 0 ) @@ -746,7 +744,7 @@ SALOME_Actor myCellPicker->Pick( x1, y1, z1, theRenderer ); int aVtkId = myCellPicker->GetCellId(); - if( aVtkId >= 0 && hasIO() && theValidator->IsValid( this, aVtkId ) ) + if( aVtkId >= 0 && hasIO() && theSelector->IsValid( this, aVtkId ) ) { int anObjId = GetElemObjId( aVtkId ); if( anObjId >= 0 ) @@ -815,7 +813,7 @@ SALOME_Actor float aPickedPoint[3]; myPointPicker->GetMapperPosition( aPickedPoint ); vtkIdType aVtkId = aDataSet->FindPoint( aPickedPoint ); - if( aVtkId >= 0 && theValidator->IsValid( this, aVtkId, true ) ) + if( aVtkId >= 0 && theSelector->IsValid( this, aVtkId, true ) ) { int anObjId = GetNodeObjId( aVtkId ); anIndices.Add( anObjId ); @@ -848,7 +846,7 @@ SALOME_Actor for( it = cellList.begin(); it != cellList.end(); ++it ) { int aCellId = (*it).cellId; - if ( !theValidator->IsValid( this, aCellId ) ) + if ( !theSelector->IsValid( this, aCellId ) ) continue; int anObjId = GetElemObjId( aCellId ); diff --git a/src/SVTK/SALOME_Actor.h b/src/SVTK/SALOME_Actor.h index cb9120cfe..12098a807 100644 --- a/src/SVTK/SALOME_Actor.h +++ b/src/SVTK/SALOME_Actor.h @@ -65,18 +65,6 @@ extern int SALOME_POINT_SIZE; class SALOME_Actor; -namespace VTK -{ - struct TValidator - { - virtual - bool - IsValid( SALOME_Actor* theActor, - const int theId, - const bool theIsNode = false ) = 0; - }; -} - class SVTK_EXPORT SALOME_Actor : public VTKViewer_Actor { public: @@ -342,15 +330,13 @@ class SVTK_EXPORT SALOME_Actor : public VTKViewer_Actor virtual bool - PreHighlight( VTK::TValidator*, - SVTK_Selector*, + PreHighlight( SVTK_Selector*, vtkRenderer*, SVTK_SelectionEvent, bool ); virtual bool - Highlight( VTK::TValidator*, - SVTK_Selector*, + Highlight( SVTK_Selector*, vtkRenderer*, SVTK_SelectionEvent, bool ); diff --git a/src/SVTK/SVTK_Event.h b/src/SVTK/SVTK_Event.h index 9bd10735b..460b7d3f5 100644 --- a/src/SVTK/SVTK_Event.h +++ b/src/SVTK/SVTK_Event.h @@ -31,28 +31,40 @@ #include -enum Event { - SpaceMouseMoveEvent = vtkCommand::UserEvent+1, - SpaceMouseButtonEvent, - PanLeftEvent, - PanRightEvent, - PanUpEvent, - PanDownEvent, - ZoomInEvent, - ZoomOutEvent, - RotateLeftEvent, - RotateRightEvent, - RotateUpEvent, - RotateDownEvent, - PlusSpeedIncrementEvent, - MinusSpeedIncrementEvent, - SetSpeedIncrementEvent, - SetSpaceMouseF1Event, - SetSpaceMouseF2Event, - SetSpaceMouseF3Event, - SetSpaceMouseF4Event, - SetSpaceMouseF5Event, - LastEvent -}; +namespace SVTK +{ + enum Event + { + SpaceMouseMoveEvent = vtkCommand::UserEvent + 1000, + SpaceMouseButtonEvent, + PanLeftEvent, + PanRightEvent, + PanUpEvent, + PanDownEvent, + ZoomInEvent, + ZoomOutEvent, + RotateLeftEvent, + RotateRightEvent, + RotateUpEvent, + RotateDownEvent, + PlusSpeedIncrementEvent, + MinusSpeedIncrementEvent, + SetSpeedIncrementEvent, + + SetSpaceMouseF1Event, + SetSpaceMouseF2Event, + SetSpaceMouseF3Event, + SetSpaceMouseF4Event, + SetSpaceMouseF5Event, + + StartZoom, + StartPan, + StartRotate, + StartGlobalPan, + StartFitArea, + + LastEvent + }; +} #endif diff --git a/src/SVTK/SVTK_InteractorStyle.cxx b/src/SVTK/SVTK_InteractorStyle.cxx index bb67274d4..d4ed7b4a9 100644 --- a/src/SVTK/SVTK_InteractorStyle.cxx +++ b/src/SVTK/SVTK_InteractorStyle.cxx @@ -192,21 +192,17 @@ void SVTK_InteractorStyle ::RotateXY(int dx, int dy) { - double rxf; - double ryf; - vtkCamera *cam; - - if (GetCurrentRenderer() == NULL) + if(GetCurrentRenderer() == NULL) return; int *size = GetCurrentRenderer()->GetRenderWindow()->GetSize(); - this->DeltaElevation = -20.0 / size[1]; - this->DeltaAzimuth = -20.0 / size[0]; + double aDeltaElevation = -20.0 / size[1]; + double aDeltaAzimuth = -20.0 / size[0]; - rxf = (double)dx * this->DeltaAzimuth * this->MotionFactor; - ryf = (double)dy * this->DeltaElevation * this->MotionFactor; + double rxf = double(dx) * aDeltaAzimuth * this->MotionFactor; + double ryf = double(dy) * aDeltaElevation * this->MotionFactor; - cam = GetCurrentRenderer()->GetActiveCamera(); + vtkCamera *cam = GetCurrentRenderer()->GetActiveCamera(); cam->Azimuth(rxf); cam->Elevation(ryf); cam->OrthogonalizeViewUp(); @@ -907,7 +903,7 @@ SVTK_InteractorStyle // VSV: LOD actor activisation // rwi->GetRenderWindow()->SetDesiredUpdateRate(rwi->GetStillUpdateRate()); - Selection_Mode aSelectionMode = GetSelector()->SelectionMode(); + int aSelectionMode = GetSelector()->SelectionMode(); switch (State) { case VTK_INTERACTOR_STYLE_CAMERA_SELECT: @@ -948,7 +944,7 @@ SVTK_InteractorStyle SVTK_SelectionEvent aSelectionEvent = GetSelectionEvent(); aSelectionEvent.mySelectionMode = aSelectionMode; aSelectionEvent.myIsRectangle = false; - aSActor->Highlight( this, GetSelector(), GetCurrentRenderer(), aSelectionEvent, true ); + aSActor->Highlight( GetSelector(), GetCurrentRenderer(), aSelectionEvent, true ); }else{ GetSelector()->ClearIObjects(); } @@ -988,7 +984,7 @@ SVTK_InteractorStyle aListActors->InitTraversal(); while(vtkActor* aActor = aListActors->GetNextActor()){ if(SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast(aActor)){ - aSActor->Highlight( this, GetSelector(), GetCurrentRenderer(), aSelectionEvent, true ); + aSActor->Highlight( GetSelector(), GetCurrentRenderer(), aSelectionEvent, true ); } } } @@ -1096,9 +1092,9 @@ SVTK_InteractorStyle myPicker->Pick(x, y, 0.0, GetCurrentRenderer()); if(SALOME_Actor* anActor = SALOME_Actor::SafeDownCast(myPicker->GetActor())){ - anIsChanged |= anActor->PreHighlight( this, GetSelector(), GetCurrentRenderer(), aSelectionEvent, true ); + anIsChanged |= anActor->PreHighlight( GetSelector(), GetCurrentRenderer(), aSelectionEvent, true ); if(aLastActor && aLastActor != anActor) - aLastActor->PreHighlight( this, GetSelector(), GetCurrentRenderer(), aSelectionEvent, false ); + aLastActor->PreHighlight( GetSelector(), GetCurrentRenderer(), aSelectionEvent, false ); } if(anIsChanged) @@ -1166,57 +1162,6 @@ SVTK_InteractorStyle motionVector[2] + viewPoint[2]); } -//---------------------------------------------------------------------------- -void -SVTK_InteractorStyle -::SetFilter( const Handle(VTKViewer_Filter)& theFilter ) -{ - myFilters[ theFilter->GetId() ] = theFilter; -} - -//---------------------------------------------------------------------------- -bool -SVTK_InteractorStyle -::IsFilterPresent( const int theId ) -{ - return myFilters.find( theId ) != myFilters.end(); -} - -//---------------------------------------------------------------------------- -void -SVTK_InteractorStyle -::RemoveFilter( const int theId ) -{ - if ( IsFilterPresent( theId ) ) - myFilters.erase( theId ); -} - -//---------------------------------------------------------------------------- -bool -SVTK_InteractorStyle -::IsValid( SALOME_Actor* theActor, - const int theId, - const bool theIsNode ) -{ - std::map::const_iterator anIter; - for ( anIter = myFilters.begin(); anIter != myFilters.end(); ++anIter ) - { - const Handle(VTKViewer_Filter)& aFilter = anIter->second; - if ( theIsNode == aFilter->IsNodeFilter() && - !aFilter->IsValid( theActor, theId ) ) - return false; - } - return true; -} - -//---------------------------------------------------------------------------- -Handle(VTKViewer_Filter) -SVTK_InteractorStyle -::GetFilter( const int theId ) -{ - return IsFilterPresent( theId ) ? myFilters[ theId ] : Handle(VTKViewer_Filter)(); -} - //---------------------------------------------------------------------------- void SVTK_InteractorStyle @@ -1254,26 +1199,33 @@ SVTK_InteractorStyle FindPokedRenderer( 0, 0 ); // register EventCallbackCommand as observer of custorm event (3d space mouse event) - interactor->AddObserver( SpaceMouseMoveEvent, EventCallbackCommand, Priority ); - interactor->AddObserver( SpaceMouseButtonEvent, EventCallbackCommand, Priority ); - interactor->AddObserver( PanLeftEvent, EventCallbackCommand, Priority ); - interactor->AddObserver( PanRightEvent, EventCallbackCommand, Priority ); - interactor->AddObserver( PanUpEvent, EventCallbackCommand, Priority ); - interactor->AddObserver( PanDownEvent, EventCallbackCommand, Priority ); - interactor->AddObserver( ZoomInEvent, EventCallbackCommand, Priority ); - interactor->AddObserver( ZoomOutEvent, EventCallbackCommand, Priority ); - interactor->AddObserver( RotateLeftEvent, EventCallbackCommand, Priority ); - interactor->AddObserver( RotateRightEvent, EventCallbackCommand, Priority ); - interactor->AddObserver( RotateUpEvent, EventCallbackCommand, Priority ); - interactor->AddObserver( RotateDownEvent, EventCallbackCommand, Priority ); - interactor->AddObserver( PlusSpeedIncrementEvent, EventCallbackCommand, Priority ); - interactor->AddObserver( MinusSpeedIncrementEvent, EventCallbackCommand, Priority ); - interactor->AddObserver( SetSpeedIncrementEvent, EventCallbackCommand, Priority ); - interactor->AddObserver( SetSpaceMouseF1Event, EventCallbackCommand, Priority ); - interactor->AddObserver( SetSpaceMouseF2Event, EventCallbackCommand, Priority ); - interactor->AddObserver( SetSpaceMouseF3Event, EventCallbackCommand, Priority ); - interactor->AddObserver( SetSpaceMouseF4Event, EventCallbackCommand, Priority ); - interactor->AddObserver( SetSpaceMouseF5Event, EventCallbackCommand, Priority ); + interactor->AddObserver( SVTK::SpaceMouseMoveEvent, EventCallbackCommand, Priority ); + interactor->AddObserver( SVTK::SpaceMouseButtonEvent, EventCallbackCommand, Priority ); + interactor->AddObserver( SVTK::PanLeftEvent, EventCallbackCommand, Priority ); + interactor->AddObserver( SVTK::PanRightEvent, EventCallbackCommand, Priority ); + interactor->AddObserver( SVTK::PanUpEvent, EventCallbackCommand, Priority ); + interactor->AddObserver( SVTK::PanDownEvent, EventCallbackCommand, Priority ); + interactor->AddObserver( SVTK::ZoomInEvent, EventCallbackCommand, Priority ); + interactor->AddObserver( SVTK::ZoomOutEvent, EventCallbackCommand, Priority ); + interactor->AddObserver( SVTK::RotateLeftEvent, EventCallbackCommand, Priority ); + interactor->AddObserver( SVTK::RotateRightEvent, EventCallbackCommand, Priority ); + interactor->AddObserver( SVTK::RotateUpEvent, EventCallbackCommand, Priority ); + interactor->AddObserver( SVTK::RotateDownEvent, EventCallbackCommand, Priority ); + interactor->AddObserver( SVTK::PlusSpeedIncrementEvent, EventCallbackCommand, Priority ); + interactor->AddObserver( SVTK::MinusSpeedIncrementEvent, EventCallbackCommand, Priority ); + interactor->AddObserver( SVTK::SetSpeedIncrementEvent, EventCallbackCommand, Priority ); + + interactor->AddObserver( SVTK::SetSpaceMouseF1Event, EventCallbackCommand, Priority ); + interactor->AddObserver( SVTK::SetSpaceMouseF2Event, EventCallbackCommand, Priority ); + interactor->AddObserver( SVTK::SetSpaceMouseF3Event, EventCallbackCommand, Priority ); + interactor->AddObserver( SVTK::SetSpaceMouseF4Event, EventCallbackCommand, Priority ); + interactor->AddObserver( SVTK::SetSpaceMouseF5Event, EventCallbackCommand, Priority ); + + interactor->AddObserver( SVTK::StartZoom, EventCallbackCommand, Priority ); + interactor->AddObserver( SVTK::StartPan, EventCallbackCommand, Priority ); + interactor->AddObserver( SVTK::StartRotate, EventCallbackCommand, Priority ); + interactor->AddObserver( SVTK::StartGlobalPan, EventCallbackCommand, Priority ); + interactor->AddObserver( SVTK::StartFitArea, EventCallbackCommand, Priority ); } } @@ -1365,66 +1317,83 @@ SVTK_InteractorStyle SVTK_InteractorStyle* self = dynamic_cast( anObject ); if ( self ) { switch ( event ) { - case SpaceMouseMoveEvent : + case SVTK::SpaceMouseMoveEvent : self->onSpaceMouseMove( (double*)callData ); break; - case SpaceMouseButtonEvent : + case SVTK::SpaceMouseButtonEvent : self->onSpaceMouseButton( *((int*)callData) ); break; - case PanLeftEvent: + case SVTK::PanLeftEvent: self->IncrementalPan( -self->mySpeedIncrement, 0 ); break; - case PanRightEvent: + case SVTK::PanRightEvent: self->IncrementalPan( self->mySpeedIncrement, 0 ); break; - case PanUpEvent: + case SVTK::PanUpEvent: self->IncrementalPan( 0, self->mySpeedIncrement ); break; - case PanDownEvent: + case SVTK::PanDownEvent: self->IncrementalPan( 0, -self->mySpeedIncrement ); break; - case ZoomInEvent: + case SVTK::ZoomInEvent: self->IncrementalZoom( self->mySpeedIncrement ); break; - case ZoomOutEvent: + case SVTK::ZoomOutEvent: self->IncrementalZoom( -self->mySpeedIncrement ); break; - case RotateLeftEvent: + case SVTK::RotateLeftEvent: self->IncrementalRotate( -self->mySpeedIncrement, 0 ); break; - case RotateRightEvent: + case SVTK::RotateRightEvent: self->IncrementalRotate( self->mySpeedIncrement, 0 ); break; - case RotateUpEvent: + case SVTK::RotateUpEvent: self->IncrementalRotate( 0, -self->mySpeedIncrement ); break; - case RotateDownEvent: + case SVTK::RotateDownEvent: self->IncrementalRotate( 0, self->mySpeedIncrement ); break; - case PlusSpeedIncrementEvent: + case SVTK::PlusSpeedIncrementEvent: ++(self->mySpeedIncrement); break; - case MinusSpeedIncrementEvent: + case SVTK::MinusSpeedIncrementEvent: --(self->mySpeedIncrement); break; - case SetSpeedIncrementEvent: + case SVTK::SetSpeedIncrementEvent: self->mySpeedIncrement = *((int*)callData); break; - case SetSpaceMouseF1Event: + + case SVTK::SetSpaceMouseF1Event: self->mySpaceMouseBtns[0] = *((int*)callData); break; - case SetSpaceMouseF2Event: + case SVTK::SetSpaceMouseF2Event: self->mySpaceMouseBtns[1] = *((int*)callData); break; - case SetSpaceMouseF3Event: + case SVTK::SetSpaceMouseF3Event: self->mySpaceMouseBtns[2] = *((int*)callData); break; - case SetSpaceMouseF4Event: + case SVTK::SetSpaceMouseF4Event: self->mySpaceMouseBtns[3] = *((int*)callData); break; - case SetSpaceMouseF5Event: + case SVTK::SetSpaceMouseF5Event: self->mySpaceMouseBtns[4] = *((int*)callData); break; + + case SVTK::StartZoom: + self->startZoom(); + break; + case SVTK::StartPan: + self->startPan(); + break; + case SVTK::StartRotate: + self->startRotate(); + break; + case SVTK::StartGlobalPan: + self->startGlobalPan(); + break; + case SVTK::StartFitArea: + self->startFitArea(); + break; } } } diff --git a/src/SVTK/SVTK_InteractorStyle.h b/src/SVTK/SVTK_InteractorStyle.h index ed11cf6d8..fc93a577d 100644 --- a/src/SVTK/SVTK_InteractorStyle.h +++ b/src/SVTK/SVTK_InteractorStyle.h @@ -43,10 +43,7 @@ class vtkRenderWindowInteractor; #include -#include "VTKViewer_Filter.h" - #include "SVTK_SelectionEvent.h" -#include "SALOME_Actor.h" class vtkPicker; class VTKViewer_RectPicker; @@ -67,7 +64,6 @@ class SVTK_ViewWindow; class SVTK_EXPORT SVTK_InteractorStyle : public QObject, - public VTK::TValidator, public vtkInteractorStyle { Q_OBJECT; @@ -106,23 +102,6 @@ class SVTK_EXPORT SVTK_InteractorStyle : virtual void OnRightButtonDown(); virtual void OnRightButtonUp(); - void - SetFilter( const Handle(VTKViewer_Filter)& ); - - Handle(VTKViewer_Filter) - GetFilter( const int ); - - bool - IsFilterPresent( const int ); - - void - RemoveFilter( const int ); - - bool - IsValid( SALOME_Actor* theActor, - const int theId, - const bool theIsNode = false ); - void IncrementalPan( const int incrX, const int incrY ); @@ -215,12 +194,6 @@ class SVTK_EXPORT SVTK_InteractorStyle : vtkSmartPointer myPicker; vtkSmartPointer myRectPicker; - - std::map myFilters; - - // members from old version - double DeltaElevation; - double DeltaAzimuth; }; #endif diff --git a/src/SVTK/SVTK_RenderWindow.cxx b/src/SVTK/SVTK_RenderWindow.cxx index 3cbce7af9..b90b3a30b 100644 --- a/src/SVTK/SVTK_RenderWindow.cxx +++ b/src/SVTK/SVTK_RenderWindow.cxx @@ -31,11 +31,9 @@ SVTK_RenderWindow Qt::WDestructiveClose | Qt::WResizeNoErase | Qt::WRepaintNoErase), - myRenderWindow(vtkRenderWindow::New()), - myRenderer(SVTK_Renderer::New()) + myRenderWindow(vtkRenderWindow::New()) { myRenderWindow->Delete(); - myRenderer->Delete(); #ifndef WNT myRenderWindow->SetDisplayId((void*)x11Display()); @@ -44,14 +42,6 @@ SVTK_RenderWindow myRenderWindow->DoubleBufferOn(); setMouseTracking(true); - myRenderWindow->AddRenderer(getRenderer()); - - myToolBar = new QToolBar(this); - myToolBar->setCloseMode(QDockWindow::Undocked); - myToolBar->setLabel(tr("LBL_TOOLBAR_LABEL")); - - createActions(); - createToolBar(); } SVTK_RenderWindow @@ -59,430 +49,9 @@ SVTK_RenderWindow {} -//---------------------------------------------------------------------------- -QToolBar* -SVTK_RenderWindow -::getToolBar() -{ - return myToolBar; -} - -vtkRenderer* -SVTK_RenderWindow -::getRenderer() -{ - return myRenderer.GetPointer(); -} - vtkRenderWindow* SVTK_RenderWindow ::getRenderWindow() { return myRenderWindow.GetPointer(); } - -VTKViewer_Trihedron* -SVTK_RenderWindow -::GetTrihedron() -{ - return myRenderer->GetTrihedron(); -} - -SVTK_CubeAxesActor2D* -SVTK_RenderWindow -::GetCubeAxes() -{ - return myRenderer->GetCubeAxes(); -} - -//---------------------------------------------------------------------------- -void -SVTK_RenderWindow -::createActions() -{ - if (!myActionsMap.isEmpty()) return; - - SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); - - QtxAction* aAction; - - // Dump view - aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_DUMP" ) ), - tr( "MNU_DUMP_VIEW" ), 0, this); - aAction->setStatusTip(tr("DSC_DUMP_VIEW")); - connect(aAction, SIGNAL(activated()), this, SLOT(onDumpView())); - myActionsMap[ DumpId ] = aAction; - - // FitAll - aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITALL" ) ), - tr( "MNU_FITALL" ), 0, this); - aAction->setStatusTip(tr("DSC_FITALL")); - connect(aAction, SIGNAL(activated()), this, SLOT(onFitAll())); - myActionsMap[ FitAllId ] = aAction; - - // FitRect - aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITAREA" ) ), - tr( "MNU_FITRECT" ), 0, this); - aAction->setStatusTip(tr("DSC_FITRECT")); - connect(aAction, SIGNAL(activated()), this, SLOT(activateWindowFit())); - myActionsMap[ FitRectId ] = aAction; - - // Zoom - aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ZOOM" ) ), - tr( "MNU_ZOOM_VIEW" ), 0, this); - aAction->setStatusTip(tr("DSC_ZOOM_VIEW")); - connect(aAction, SIGNAL(activated()), this, SLOT(activateZoom())); - myActionsMap[ ZoomId ] = aAction; - - // Panning - aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_PAN" ) ), - tr( "MNU_PAN_VIEW" ), 0, this); - aAction->setStatusTip(tr("DSC_PAN_VIEW")); - connect(aAction, SIGNAL(activated()), this, SLOT(activatePanning())); - myActionsMap[ PanId ] = aAction; - - // Global Panning - aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_GLOBALPAN" ) ), - tr( "MNU_GLOBALPAN_VIEW" ), 0, this); - aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW")); - connect(aAction, SIGNAL(activated()), this, SLOT(activateGlobalPanning())); - myActionsMap[ GlobalPanId ] = aAction; - - // Rotation - aAction = new QtxAction(tr("MNU_ROTATE_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ROTATE" ) ), - tr( "MNU_ROTATE_VIEW" ), 0, this); - aAction->setStatusTip(tr("DSC_ROTATE_VIEW")); - connect(aAction, SIGNAL(activated()), this, SLOT(activateRotation())); - myActionsMap[ RotationId ] = aAction; - - // Projections - aAction = new QtxAction(tr("MNU_FRONT_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FRONT" ) ), - tr( "MNU_FRONT_VIEW" ), 0, this); - aAction->setStatusTip(tr("DSC_FRONT_VIEW")); - connect(aAction, SIGNAL(activated()), this, SLOT(onFrontView())); - myActionsMap[ FrontId ] = aAction; - - aAction = new QtxAction(tr("MNU_BACK_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BACK" ) ), - tr( "MNU_BACK_VIEW" ), 0, this); - aAction->setStatusTip(tr("DSC_BACK_VIEW")); - connect(aAction, SIGNAL(activated()), this, SLOT(onBackView())); - myActionsMap[ BackId ] = aAction; - - aAction = new QtxAction(tr("MNU_TOP_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TOP" ) ), - tr( "MNU_TOP_VIEW" ), 0, this); - aAction->setStatusTip(tr("DSC_TOP_VIEW")); - connect(aAction, SIGNAL(activated()), this, SLOT(onTopView())); - myActionsMap[ TopId ] = aAction; - - aAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BOTTOM" ) ), - tr( "MNU_BOTTOM_VIEW" ), 0, this); - aAction->setStatusTip(tr("DSC_BOTTOM_VIEW")); - connect(aAction, SIGNAL(activated()), this, SLOT(onBottomView())); - myActionsMap[ BottomId ] = aAction; - - aAction = new QtxAction(tr("MNU_LEFT_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_LEFT" ) ), - tr( "MNU_LEFT_VIEW" ), 0, this); - aAction->setStatusTip(tr("DSC_LEFT_VIEW")); - connect(aAction, SIGNAL(activated()), this, SLOT(onLeftView())); - myActionsMap[ LeftId ] = aAction; - - aAction = new QtxAction(tr("MNU_RIGHT_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RIGHT" ) ), - tr( "MNU_RIGHT_VIEW" ), 0, this); - aAction->setStatusTip(tr("DSC_RIGHT_VIEW")); - connect(aAction, SIGNAL(activated()), this, SLOT(onRightView())); - myActionsMap[ RightId ] = aAction; - - // Reset - aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RESET" ) ), - tr( "MNU_RESET_VIEW" ), 0, this); - aAction->setStatusTip(tr("DSC_RESET_VIEW")); - connect(aAction, SIGNAL(activated()), this, SLOT(onResetView())); - myActionsMap[ ResetId ] = aAction; - - // onViewTrihedron: Shows - Hides Trihedron - aAction = new QtxAction(tr("MNU_SHOW_TRIHEDRON"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TRIHEDRON" ) ), - tr( "MNU_SHOW_TRIHEDRON" ), 0, this); - aAction->setStatusTip(tr("DSC_SHOW_TRIHEDRON")); - connect(aAction, SIGNAL(activated()), this, SLOT(onViewTrihedron())); - myActionsMap[ ViewTrihedronId ] = aAction; -} - -//========================================================== -void -SVTK_RenderWindow -::createToolBar() -{ - myActionsMap[DumpId]->addTo(myToolBar); - myActionsMap[ViewTrihedronId]->addTo(myToolBar); - - SUIT_ToolButton* aScaleBtn = new SUIT_ToolButton(myToolBar); - aScaleBtn->AddAction(myActionsMap[FitAllId]); - aScaleBtn->AddAction(myActionsMap[FitRectId]); - aScaleBtn->AddAction(myActionsMap[ZoomId]); - - SUIT_ToolButton* aPanningBtn = new SUIT_ToolButton(myToolBar); - aPanningBtn->AddAction(myActionsMap[PanId]); - aPanningBtn->AddAction(myActionsMap[GlobalPanId]); - - myActionsMap[RotationId]->addTo(myToolBar); - - SUIT_ToolButton* aViewsBtn = new SUIT_ToolButton(myToolBar); - aViewsBtn->AddAction(myActionsMap[FrontId]); - aViewsBtn->AddAction(myActionsMap[BackId]); - aViewsBtn->AddAction(myActionsMap[TopId]); - aViewsBtn->AddAction(myActionsMap[BottomId]); - aViewsBtn->AddAction(myActionsMap[LeftId]); - aViewsBtn->AddAction(myActionsMap[RightId]); - - myActionsMap[ResetId]->addTo(myToolBar); -} - -//---------------------------------------------------------------------------- -void -SVTK_RenderWindow -::Repaint( bool theUpdateTrihedron ) -{ - if(theUpdateTrihedron) - myRenderer->onAdjustTrihedron(); - - update(); -} - -//---------------------------------------------------------------------------- -void -SVTK_RenderWindow -::setBackgroundColor(const QColor& theColor) -{ - myRenderer->SetBackground(theColor.red()/255.0, - theColor.green()/255.0, - theColor.blue()/255.0); -} - -//---------------------------------------------------------------------------- -QColor -SVTK_RenderWindow -::backgroundColor() const -{ - float aBackgroundColor[3]; - myRenderer->GetBackground(aBackgroundColor); - return QColor(int(aBackgroundColor[0]*255), - int(aBackgroundColor[1]*255), - int(aBackgroundColor[2]*255)); -} - - -//---------------------------------------------------------------------------- -void -SVTK_RenderWindow -::GetScale( double theScale[3] ) -{ - myRenderer->GetScale( theScale ); -} - -void -SVTK_RenderWindow -::SetScale( double theScale[3] ) -{ - myRenderer->SetScale( theScale ); - Repaint(); -} - - -//---------------------------------------------------------------------------- -void -SVTK_RenderWindow -::AddActor(VTKViewer_Actor* theActor, bool theIsUpdate) -{ - myRenderer->AddActor(theActor); - if(theIsUpdate) - Repaint(); -} - -//---------------------------------------------------------------------------- -void -SVTK_RenderWindow -::RemoveActor(VTKViewer_Actor* theActor, bool theIsUpdate) -{ - myRenderer->RemoveActor(theActor); - if(theIsUpdate) - Repaint(); -} - -//---------------------------------------------------------------------------- -bool -SVTK_RenderWindow -::isTrihedronDisplayed() -{ - return myRenderer->isTrihedronDisplayed(); -} - -//---------------------------------------------------------------------------- -bool -SVTK_RenderWindow -::isCubeAxesDisplayed() -{ - return myRenderer->isCubeAxesDisplayed(); -} - -//---------------------------------------------------------------------------- -void -SVTK_RenderWindow -::activateZoom() -{} - -//---------------------------------------------------------------------------- -void -SVTK_RenderWindow -::activatePanning() -{} - -//---------------------------------------------------------------------------- -void -SVTK_RenderWindow -::activateRotation() -{} - -//---------------------------------------------------------------------------- -void -SVTK_RenderWindow -::activateGlobalPanning() -{} - -//---------------------------------------------------------------------------- -void -SVTK_RenderWindow -::activateWindowFit() -{} - -//---------------------------------------------------------------------------- -void -SVTK_RenderWindow -::onFrontView() -{ - myRenderer->onFrontView(); -} - -//---------------------------------------------------------------------------- -void -SVTK_RenderWindow -::onBackView() -{ - myRenderer->onBackView(); -} - -//---------------------------------------------------------------------------- -void -SVTK_RenderWindow -::onTopView() -{ - myRenderer->onTopView(); -} - -//---------------------------------------------------------------------------- -void -SVTK_RenderWindow -::onBottomView() -{ - myRenderer->onBottomView(); -} - -//---------------------------------------------------------------------------- -void -SVTK_RenderWindow -::onLeftView() -{ - myRenderer->onLeftView(); -} - -//---------------------------------------------------------------------------- -void -SVTK_RenderWindow -::onRightView() -{ - myRenderer->onRightView(); -} - -//---------------------------------------------------------------------------- -void -SVTK_RenderWindow -::onResetView() -{ - myRenderer->onResetView(); - Repaint(); -} - -//---------------------------------------------------------------------------- -void -SVTK_RenderWindow -::onFitAll() -{ - myRenderer->onFitAll(); - Repaint(); -} - -//---------------------------------------------------------------------------- -void -SVTK_RenderWindow -::onViewTrihedron() -{ - myRenderer->onViewTrihedron(); - Repaint(); -} - -//---------------------------------------------------------------------------- -void -SVTK_RenderWindow -::onViewCubeAxes() -{ - myRenderer->onViewCubeAxes(); - Repaint(); -} - -//---------------------------------------------------------------------------- -int SVTK_RenderWindow::GetTrihedronSize() const -{ - return myRenderer->GetTrihedronSize(); -} - -//---------------------------------------------------------------------------- -void SVTK_RenderWindow::SetTrihedronSize( const int theSize ) -{ - myRenderer->SetTrihedronSize(theSize); - Repaint(); -} - -/*! If parameter theIsForcedUpdate is true, recalculate parameters for - * trihedron and cube axes, even if trihedron and cube axes is invisible. - */ -void -SVTK_RenderWindow -::AdjustTrihedrons(const bool theIsForced) -{ - myRenderer->AdjustTrihedrons(theIsForced); - Repaint(); -} - -//---------------------------------------------------------------------------- -void -SVTK_RenderWindow -::onAdjustTrihedron() -{ - myRenderer->onAdjustTrihedron(); -} - -//---------------------------------------------------------------------------- -void -SVTK_RenderWindow -::onAdjustCubeAxes() -{ - myRenderer->onAdjustCubeAxes(); -} - -//---------------------------------------------------------------------------- -QImage -SVTK_RenderWindow -::dumpView() -{ - QPixmap px = QPixmap::grabWindow( winId() ); - return px.convertToImage(); -} diff --git a/src/SVTK/SVTK_RenderWindow.h b/src/SVTK/SVTK_RenderWindow.h index 020f2fceb..712f1fb6d 100644 --- a/src/SVTK/SVTK_RenderWindow.h +++ b/src/SVTK/SVTK_RenderWindow.h @@ -36,14 +36,8 @@ #include "SVTK.h" -class VTKViewer_Trihedron; -class VTKViewer_Transform; -class VTKViewer_Actor; - -class SVTK_CubeAxesActor2D; class SVTK_Renderer; -class QtxAction; class vtkRenderer; class vtkRenderWindow; @@ -56,76 +50,10 @@ class SVTK_EXPORT SVTK_RenderWindow : public QMainWindow SVTK_RenderWindow( QWidget*, const char* ); virtual ~SVTK_RenderWindow() ; - QToolBar* getToolBar(); - - vtkRenderer* getRenderer(); vtkRenderWindow* getRenderWindow(); - VTKViewer_Trihedron* GetTrihedron(); - SVTK_CubeAxesActor2D* GetCubeAxes(); - - int GetTrihedronSize() const; - void SetTrihedronSize( const int ); - void AdjustTrihedrons( const bool forced ); - - bool isTrihedronDisplayed(); - bool isCubeAxesDisplayed(); - - void Repaint( bool theUpdateTrihedron ); - void Repaint() { Repaint( true ); } - - void setBackgroundColor( const QColor& ); - QColor backgroundColor() const; - - //apply existing transformation on adding SALOME_Actor - void SetScale( double theScale[3] ); - void GetScale( double theScale[3] ); - - void AddActor(VTKViewer_Actor* theActor, bool theIsUpdate = false); - void RemoveActor(VTKViewer_Actor* theActor, bool theIsUpdate = false); - - public slots: - virtual void activateZoom(); - virtual void activateWindowFit(); - virtual void activateRotation(); - virtual void activatePanning(); - virtual void activateGlobalPanning(); - - void onFrontView(); - void onBackView(); - void onTopView(); - void onBottomView(); - void onRightView(); - void onLeftView(); - - void onResetView(); - void onFitAll(); - - void onViewTrihedron(); - void onViewCubeAxes(); - - void onAdjustTrihedron(); - void onAdjustCubeAxes(); - - void onDumpView(); - - public: - QImage dumpView(); - protected: - enum { DumpId, FitAllId, FitRectId, ZoomId, PanId, GlobalPanId, RotationId, - FrontId, BackId, TopId, BottomId, LeftId, RightId, ResetId, ViewTrihedronId }; - typedef QMap ActionsMap; - - void createActions(); - void createToolBar(); - - protected: - vtkSmartPointer myRenderer; vtkSmartPointer myRenderWindow; - - ActionsMap myActionsMap; - QToolBar* myToolBar; }; #endif diff --git a/src/SVTK/SVTK_RenderWindowInteractor.cxx b/src/SVTK/SVTK_RenderWindowInteractor.cxx index bcba8a938..ff0a517e7 100644 --- a/src/SVTK/SVTK_RenderWindowInteractor.cxx +++ b/src/SVTK/SVTK_RenderWindowInteractor.cxx @@ -28,6 +28,7 @@ #include "SVTK_RenderWindowInteractor.h" +#include "SVTK_InteractorStyle.h" #include "VTKViewer_Algorithm.h" #include "SVTK_Functor.h" #include "SALOME_Actor.h" @@ -41,10 +42,10 @@ // VTK Includes #include -#include #include #include #include +#include #include #include #include @@ -124,100 +125,82 @@ QtRenderWindowInteractor //---------------------------------------------------------------------------- -SVTK_RenderWindowInteractor -::SVTK_RenderWindowInteractor( QWidget* parent, const char* name ) : - SVTK_RenderWindow( parent, name ), +QVTK_RenderWindowInteractor +::QVTK_RenderWindowInteractor(QWidget* theParent, + const char* theName): + QWidget(theParent,theName), myInteractor(QtRenderWindowInteractor::New()) { myInteractor->Delete(); - myInteractor->SetRenderWindow( getRenderWindow() ); - myDisplayMode = 0; } -SVTK_RenderWindowInteractor -::~SVTK_RenderWindowInteractor() +QVTK_RenderWindowInteractor +::~QVTK_RenderWindowInteractor() { - if(MYDEBUG) INFOS("SVTK_RenderWindowInteractor::~SVTK_RenderWindowInteractor()"); - - // stop 3d space mouse driver - SVTK_SpaceMouse* sm = SVTK_SpaceMouse::getInstance(); - if ( sm->isSpaceMouseOn() ) - sm->close( x11Display() ); + if(SVTK_SpaceMouse* aSpaceMouse = SVTK_SpaceMouse::getInstance()) + if(aSpaceMouse->isSpaceMouseOn()) + aSpaceMouse->close(x11Display()); } - //---------------------------------------------------------------------------- vtkRenderWindowInteractor* -SVTK_RenderWindowInteractor -::getDevice() +QVTK_RenderWindowInteractor +::GetDevice() { return myInteractor.GetPointer(); } +//---------------------------------------------------------------------------- void -SVTK_RenderWindowInteractor -::Initialize() +QVTK_RenderWindowInteractor +::SetRenderWindow(vtkRenderWindow *theRenderWindow) { - myInteractor->Initialize(); -} + myInteractor->SetRenderWindow(theRenderWindow); +#ifndef WNT + theRenderWindow->SetDisplayId((void*)x11Display()); +#endif + theRenderWindow->SetWindowId((void*)winId()); + theRenderWindow->DoubleBufferOn(); + setMouseTracking(true); + Initialize(); +} -//---------------------------------------------------------------------------- -void -SVTK_RenderWindowInteractor -::UpdateSize(int w, int h) +vtkRenderWindow* +QVTK_RenderWindowInteractor +::GetRenderWindow() { - myInteractor->UpdateSize(w,h); + return myInteractor->GetRenderWindow(); } - //---------------------------------------------------------------------------- void -SVTK_RenderWindowInteractor -::Render() +QVTK_RenderWindowInteractor +::Initialize() { - myInteractor->Render(); + myInteractor->Initialize(); } - //---------------------------------------------------------------------------- -struct TUpdateAction -{ - void operator()(vtkActor* theActor){ - theActor->ApplyProperties(); - } -}; - void -SVTK_RenderWindowInteractor -::Update() +QVTK_RenderWindowInteractor +::InvokeEvent(unsigned long theEvent, void* theCallData) { - vtkRenderer* aRen = GetRenderer(); - - using namespace VTK; - ForEach(aRen->GetActors(),TUpdateAction()); - - aRen->ResetCamera(); - - update(); + myInteractor->InvokeEvent(theEvent,theCallData); } - //---------------------------------------------------------------------------- -vtkRenderer* -SVTK_RenderWindowInteractor -::GetRenderer() +void +QVTK_RenderWindowInteractor +::UpdateSize(int w, int h) { - vtkRendererCollection * theRenderers = getRenderWindow()->GetRenderers(); - theRenderers->InitTraversal(); - return theRenderers->GetNextItem(); + myInteractor->UpdateSize(w,h); } - //---------------------------------------------------------------------------- void -SVTK_RenderWindowInteractor +QVTK_RenderWindowInteractor ::paintEvent( QPaintEvent* theEvent ) { myInteractor->Render(); @@ -226,16 +209,18 @@ SVTK_RenderWindowInteractor //---------------------------------------------------------------------------- void -SVTK_RenderWindowInteractor +QVTK_RenderWindowInteractor ::resizeEvent( QResizeEvent* theEvent ) { - int aWidth = getRenderWindow()->GetSize()[0], aHeight = getRenderWindow()->GetSize()[1]; + int* aSize = GetRenderWindow()->GetSize(); + int aWidth = aSize[0]; + int aHeight = aSize[1]; - myInteractor->UpdateSize( width(), height() ); + UpdateSize( width(), height() ); if( aWidth != width() || aHeight != height() ) { - vtkRendererCollection * aRenderers = getRenderWindow()->GetRenderers(); + vtkRendererCollection * aRenderers = GetRenderWindow()->GetRenderers(); aRenderers->InitTraversal(); double aCoeff = 1.0; if(vtkRenderer *aRenderer = aRenderers->GetNextItem()) @@ -254,31 +239,26 @@ SVTK_RenderWindowInteractor //---------------------------------------------------------------------------- void -SVTK_RenderWindowInteractor +QVTK_RenderWindowInteractor ::contextMenuEvent( QContextMenuEvent* event ) -{ - if( !( event->state() & KeyButtonMask ) ) - emit contextMenuRequested( event ); -} +{} //---------------------------------------------------------------------------- void -SVTK_RenderWindowInteractor +QVTK_RenderWindowInteractor ::mouseMoveEvent( QMouseEvent* event ) { myInteractor->SetEventInformation( event->x(), event->y(), ( event->state() & ControlButton ), ( event->state() & ShiftButton ) ); myInteractor->MouseMoveEvent(); - - emit MouseMove( event ); } //---------------------------------------------------------------------------- void -SVTK_RenderWindowInteractor +QVTK_RenderWindowInteractor ::mousePressEvent( QMouseEvent* event ) { myInteractor->SetEventInformation( event->x(), event->y(), @@ -290,14 +270,12 @@ SVTK_RenderWindowInteractor myInteractor->MiddleButtonPressEvent(); else if( event->button() & RightButton ) myInteractor->RightButtonPressEvent(); - - emit MouseButtonPressed( event ); } //---------------------------------------------------------------------------- void -SVTK_RenderWindowInteractor +QVTK_RenderWindowInteractor ::mouseReleaseEvent( QMouseEvent *event ) { myInteractor->SetEventInformation( event->x(), event->y(), @@ -310,85 +288,77 @@ SVTK_RenderWindowInteractor myInteractor->MiddleButtonReleaseEvent(); else if( event->button() & RightButton ) myInteractor->RightButtonReleaseEvent(); - - emit MouseButtonReleased( event ); } //---------------------------------------------------------------------------- void -SVTK_RenderWindowInteractor +QVTK_RenderWindowInteractor ::mouseDoubleClickEvent( QMouseEvent* event ) -{ - emit MouseDoubleClicked( event ); -} +{} //---------------------------------------------------------------------------- void -SVTK_RenderWindowInteractor +QVTK_RenderWindowInteractor ::wheelEvent( QWheelEvent* event ) -{ - emit WheelMoved( event ); -} +{} //---------------------------------------------------------------------------- void -SVTK_RenderWindowInteractor +QVTK_RenderWindowInteractor ::keyPressEvent( QKeyEvent* event ) { myInteractor->SetKeyEventInformation( ( event->state() & ControlButton ), ( event->state() & ShiftButton ), event->key() ); myInteractor->KeyPressEvent(); - - emit KeyPressed( event ); } //---------------------------------------------------------------------------- void -SVTK_RenderWindowInteractor +QVTK_RenderWindowInteractor ::keyReleaseEvent( QKeyEvent * event ) { myInteractor->SetKeyEventInformation( ( event->state() & ControlButton ), ( event->state() & ShiftButton ), event->key() ); myInteractor->KeyReleaseEvent(); - - emit KeyReleased( event ); } //---------------------------------------------------------------------------- void -SVTK_RenderWindowInteractor +QVTK_RenderWindowInteractor ::focusInEvent ( QFocusEvent* event ) { QWidget::focusInEvent( event ); // register set space mouse events receiver - SVTK_SpaceMouse* sm = SVTK_SpaceMouse::getInstance(); - if ( !sm->isSpaceMouseOn() ) {// initialize 3D space mouse driver - sm->initialize( x11Display(), winId() ); - if ( !sm->isSpaceMouseOn() ) - printf( "\nError: 3D Space Mouse driver was not started.\n" ); + if(SVTK_SpaceMouse* aSpaceMouse = SVTK_SpaceMouse::getInstance()){ + if(!aSpaceMouse->isSpaceMouseOn()) {// initialize 3D space mouse driver + aSpaceMouse->initialize(x11Display(),winId()); + }else{ + aSpaceMouse->setWindow(x11Display(),winId()); + } } - else - SVTK_SpaceMouse::getInstance()->setWindow( x11Display(), winId() ); myInteractor->EnterEvent(); } //---------------------------------------------------------------------------- void -SVTK_RenderWindowInteractor +QVTK_RenderWindowInteractor ::focusOutEvent ( QFocusEvent* event ) { QWidget::focusInEvent( event ); + // unregister set space mouse events receiver - if ( SVTK_SpaceMouse::getInstance()->isSpaceMouseOn() ) - SVTK_SpaceMouse::getInstance()->setWindow( x11Display(), 0 ); + if(SVTK_SpaceMouse* aSpaceMouse = SVTK_SpaceMouse::getInstance()){ + if(aSpaceMouse->isSpaceMouseOn()) + aSpaceMouse->setWindow(x11Display(),0); + } myInteractor->LeaveEvent(); } @@ -396,354 +366,250 @@ SVTK_RenderWindowInteractor //---------------------------------------------------------------------------- bool -SVTK_RenderWindowInteractor +QVTK_RenderWindowInteractor ::x11Event( XEvent *xEvent ) { // handle 3d space mouse events - SVTK_SpaceMouse* sm = SVTK_SpaceMouse::getInstance(); - if ( sm->isSpaceMouseOn() && xEvent->type == ClientMessage ) { - SVTK_SpaceMouse::MoveEvent spaceMouseEvent; - int type = sm->translateEvent( x11Display(), xEvent, &spaceMouseEvent, 1.0, 1.0 ); - switch ( type ) - { - case SVTK_SpaceMouse::SpaceMouseMove : - myInteractor->InvokeEvent( SpaceMouseMoveEvent, spaceMouseEvent.data ); - break; - case SVTK_SpaceMouse::SpaceButtonPress : - myInteractor->InvokeEvent( SpaceMouseButtonEvent, &spaceMouseEvent.button ); - break; - case SVTK_SpaceMouse::SpaceButtonRelease : - break; + if(SVTK_SpaceMouse* aSpaceMouse = SVTK_SpaceMouse::getInstance()){ + if(aSpaceMouse->isSpaceMouseOn() && xEvent->type == ClientMessage){ + SVTK_SpaceMouse::MoveEvent anEvent; + int type = aSpaceMouse->translateEvent( x11Display(), xEvent, &anEvent, 1.0, 1.0 ); + switch( type ){ + case SVTK_SpaceMouse::SpaceMouseMove : + myInteractor->InvokeEvent(SVTK::SpaceMouseMoveEvent, anEvent.data ); + break; + case SVTK_SpaceMouse::SpaceButtonPress : + myInteractor->InvokeEvent( SVTK::SpaceMouseButtonEvent, &anEvent.button ); + break; + case SVTK_SpaceMouse::SpaceButtonRelease : + break; + } + return true; // stop handling the event } - return true; // stop handling the event } - return SVTK_RenderWindow::x11Event( xEvent ); -} - -//---------------------------------------------------------------------------- -int -SVTK_RenderWindowInteractor -::GetDisplayMode() -{ - return myDisplayMode; + return QWidget::x11Event( xEvent ); } //---------------------------------------------------------------------------- -void SVTK_RenderWindowInteractor -::SetDisplayMode(int theMode) +::SVTK_RenderWindowInteractor(QWidget* theParent, + const char* theName): + QVTK_RenderWindowInteractor(theParent,theName), + myEventCallbackCommand(vtkCallbackCommand::New()) { - if(theMode == 0) - ChangeRepresentationToWireframe(); - else - ChangeRepresentationToSurface(); - myDisplayMode = theMode; -} + myEventCallbackCommand->Delete(); + myEventCallbackCommand->SetClientData(this); + myPriority = 0.0; -void -SVTK_RenderWindowInteractor -::SetDisplayMode(const Handle(SALOME_InteractiveObject)& theIObject, - int theMode) -{ - using namespace VTK; - ForEachIf(GetRenderer()->GetActors(), - TIsSameIObject(theIObject), - TSetFunction - (&SALOME_Actor::setDisplayMode,theMode)); -} + myEventCallbackCommand->SetCallback(SVTK_RenderWindowInteractor::ProcessEvents); - -void -SVTK_RenderWindowInteractor -::ChangeRepresentationToWireframe() -{ - ChangeRepresentationToWireframe(GetRenderer()->GetActors()); + SetSelector(SVTK_Selector::New()); + GetSelector()->Delete(); } -void SVTK_RenderWindowInteractor -::ChangeRepresentationToSurface() -{ - ChangeRepresentationToSurface(GetRenderer()->GetActors()); -} - +::~SVTK_RenderWindowInteractor() +{} -void -SVTK_RenderWindowInteractor -::ChangeRepresentationToWireframe(vtkActorCollection* theCollection) -{ - using namespace VTK; - ForEach(theCollection, - TSetFunction - (&SALOME_Actor::setDisplayMode,0)); - update(); -} -void +//---------------------------------------------------------------------------- +SVTK_Selector* SVTK_RenderWindowInteractor -::ChangeRepresentationToSurface(vtkActorCollection* theCollection) -{ - using namespace VTK; - ForEach(theCollection, - TSetFunction - (&SALOME_Actor::setDisplayMode,1)); - update(); +::GetSelector() +{ + return mySelector.GetPointer(); } -//---------------------------------------------------------------------------- -struct TErase -{ - VTK::TSetFunction mySetFunction; - TErase(): - mySetFunction(&vtkActor::SetVisibility,false) - {} - void operator()(SALOME_Actor* theActor){ - theActor->SetVisibility(false); - // Erase dependent actors - vtkActorCollection* aCollection = vtkActorCollection::New(); - theActor->GetChildActors(aCollection); - VTK::ForEach(aCollection,mySetFunction); - aCollection->Delete(); - } -}; - void SVTK_RenderWindowInteractor -::EraseAll() -{ - using namespace VTK; - ForEach(GetRenderer()->GetActors(), - TErase()); +::SetSelector(SVTK_Selector* theSelector) +{ + if(mySelector.GetPointer()) + mySelector->RemoveObserver(myEventCallbackCommand.GetPointer()); - update(); + mySelector = theSelector; + + if(mySelector.GetPointer()) + mySelector->AddObserver(vtkCommand::EndPickEvent, + myEventCallbackCommand.GetPointer(), + myPriority); } -void + +//---------------------------------------------------------------------------- +void SVTK_RenderWindowInteractor -::DisplayAll() -{ - vtkActorCollection* aCollection = GetRenderer()->GetActors(); - using namespace VTK; - ForEach(aCollection,TSetVisibility(true)); +::ProcessEvents(vtkObject* vtkNotUsed(theObject), + unsigned long theEvent, + void* theClientData, + void* vtkNotUsed(theCallData)) +{ + SVTK_RenderWindowInteractor* self = reinterpret_cast(theClientData); - update(); + switch(theEvent){ + case vtkCommand::EndPickEvent: + self->onEmitSelectionChanged(); + break; + } } +//---------------------------------------------------------------------------- void SVTK_RenderWindowInteractor -::Erase(SALOME_Actor* theActor, bool updateViewer) +::InitInteractorStyle(SVTK_InteractorStyle* theStyle) { - TErase()(theActor); + GetDevice()->SetInteractorStyle(theStyle); + theStyle->FindPokedRenderer(0,0); - if(updateViewer) - update(); + theStyle->SetSelector(GetSelector()); + theStyle->SetRenderWidget(this); } +//---------------------------------------------------------------------------- void SVTK_RenderWindowInteractor -::Erase(const Handle(SALOME_InteractiveObject)& theIObject, - bool updateViewer) +::PushInteractorStyle(SVTK_InteractorStyle* theStyle) { - using namespace VTK; - ForEachIf(GetRenderer()->GetActors(), - TIsSameIObject(theIObject), - TErase()); - - if(updateViewer) - update(); + myInteractorStyles.push(PInteractorStyle(theStyle)); + InitInteractorStyle(theStyle); } -struct TRemoveAction -{ - vtkRenderer* myRen; - TRemoveAction(vtkRenderer* theRen): myRen(theRen){} - void operator()(SALOME_Actor* theActor){ - myRen->RemoveActor(theActor); - } -}; - +//---------------------------------------------------------------------------- void SVTK_RenderWindowInteractor -::Remove(const Handle(SALOME_InteractiveObject)& theIObject, - bool updateViewer) +::PopInteractorStyle() { - vtkRenderer* aRen = GetRenderer(); - - using namespace VTK; - ForEachIf(aRen->GetActors(), - TIsSameIObject(theIObject), - TRemoveAction(aRen)); + if(GetInteractorStyle()) + myInteractorStyles.pop(); + + if(GetInteractorStyle()) + InitInteractorStyle(GetInteractorStyle()); } -void + +//---------------------------------------------------------------------------- +SVTK_InteractorStyle* SVTK_RenderWindowInteractor -::Remove( SALOME_Actor* SActor, bool updateViewer ) +::GetInteractorStyle() { - if ( SActor != 0 ) - { - GetRenderer()->RemoveProp( SActor ); - if ( updateViewer ) - update(); - } + return myInteractorStyles.isEmpty() ? 0 : myInteractorStyles.top().GetPointer(); } + +//---------------------------------------------------------------- void SVTK_RenderWindowInteractor -::RemoveAll( const bool updateViewer ) +::SetSelectionMode(int theMode) { - vtkRenderer* aRenderer = GetRenderer(); - vtkActorCollection* anActors = aRenderer->GetActors(); - if ( anActors ) - { - anActors->InitTraversal(); - while ( vtkActor *anAct = anActors->GetNextActor() ) - { - if ( anAct->IsA( "SALOME_Actor" ) ) - { - SALOME_Actor* aSAct = (SALOME_Actor*)anAct; - if ( aSAct->hasIO() && aSAct->getIO()->hasEntry() ) - aRenderer->RemoveActor( anAct ); - } - } - - if ( updateViewer ) - update(); - } + mySelector->SetSelectionMode(theMode); } -float +//---------------------------------------------------------------- +int SVTK_RenderWindowInteractor -::GetTransparency(const Handle(SALOME_InteractiveObject)& theIObject) +::SelectionMode() const { - using namespace VTK; - SALOME_Actor* anActor = - Find(GetRenderer()->GetActors(), - TIsSameIObject(theIObject)); - if(anActor) - return 1.0 - anActor->GetOpacity(); - return -1.0; + return mySelector->SelectionMode(); } +//---------------------------------------------------------------- void SVTK_RenderWindowInteractor -::SetTransparency(const Handle(SALOME_InteractiveObject)& theIObject, - float theTrans) +::onEmitSelectionChanged() { - float anOpacity = 1.0 - theTrans; - using namespace VTK; - ForEachIf(GetRenderer()->GetActors(), - TIsSameIObject(theIObject), - TSetFunction - (&SALOME_Actor::SetOpacity,anOpacity)); + return emit selectionChanged(); } +//---------------------------------------------------------------------------- void SVTK_RenderWindowInteractor -::Display(SALOME_Actor* theActor, bool updateViewer) +::mouseMoveEvent( QMouseEvent* event ) { - GetRenderer()->AddActor(theActor); - theActor->SetVisibility(true); + QVTK_RenderWindowInteractor::mouseMoveEvent(event); - if(updateViewer) - update(); + emit MouseMove( event ); } +//---------------------------------------------------------------------------- void SVTK_RenderWindowInteractor -::Display(const Handle(SALOME_InteractiveObject)& theIObject, bool updateViewer) +::mousePressEvent( QMouseEvent* event ) { - using namespace VTK; - ForEachIf(GetRenderer()->GetActors(), - TIsSameIObject(theIObject), - TSetVisibility(true)); + QVTK_RenderWindowInteractor::mousePressEvent(event); - if(updateViewer) - update(); + emit MouseButtonPressed( event ); } -//----------------- -// Color methods -//----------------- +//---------------------------------------------------------------------------- void SVTK_RenderWindowInteractor -::SetColor(const Handle(SALOME_InteractiveObject)& theIObject,QColor theColor) +::mouseReleaseEvent( QMouseEvent *event ) { - float aColor[3] = {theColor.red()/255., theColor.green()/255., theColor.blue()/255.}; - using namespace VTK; - ForEachIf(GetRenderer()->GetActors(), - TIsSameIObject(theIObject), - TSetFunction - (&SALOME_Actor::SetColor,aColor)); + QVTK_RenderWindowInteractor::mouseReleaseEvent(event); + + emit MouseButtonReleased( event ); } -QColor +//---------------------------------------------------------------------------- +void SVTK_RenderWindowInteractor -::GetColor(const Handle(SALOME_InteractiveObject)& theIObject) -{ - using namespace VTK; - SALOME_Actor* anActor = - Find(GetRenderer()->GetActors(), - TIsSameIObject(theIObject)); - if(anActor){ - float r,g,b; - anActor->GetColor(r,g,b); - return QColor(int(r*255),int(g*255),int(b*255)); - } - return QColor(0,0,0); +::mouseDoubleClickEvent( QMouseEvent* event ) +{ + QVTK_RenderWindowInteractor::mouseDoubleClickEvent(event); + + emit MouseDoubleClicked( event ); } -bool +//---------------------------------------------------------------------------- +void SVTK_RenderWindowInteractor -::isInViewer(const Handle(SALOME_InteractiveObject)& theIObject) +::wheelEvent( QWheelEvent* event ) { - using namespace VTK; - SALOME_Actor* anActor = - Find(GetRenderer()->GetActors(), - TIsSameIObject(theIObject)); - return anActor != NULL; + QVTK_RenderWindowInteractor::wheelEvent(event); + + emit WheelMoved( event ); } -bool +//---------------------------------------------------------------------------- +void SVTK_RenderWindowInteractor -::isVisible(const Handle(SALOME_InteractiveObject)& theIObject) +::keyPressEvent( QKeyEvent* event ) { - using namespace VTK; - SALOME_Actor* anActor = - Find(GetRenderer()->GetActors(), - TIsSameIObject(theIObject)); - return anActor != NULL && anActor->GetVisibility(); -} + QVTK_RenderWindowInteractor::keyPressEvent(event); + emit KeyPressed( event ); +} +//---------------------------------------------------------------------------- void SVTK_RenderWindowInteractor -::rename(const Handle(SALOME_InteractiveObject)& theIObject, QString theName) +::keyReleaseEvent( QKeyEvent * event ) { - using namespace VTK; - ForEachIf(GetRenderer()->GetActors(), - TIsSameIObject(theIObject), - TSetFunction - (&SALOME_Actor::setName,theName.latin1())); + QVTK_RenderWindowInteractor::keyReleaseEvent(event); + + emit KeyReleased( event ); } +//---------------------------------------------------------------------------- void SVTK_RenderWindowInteractor -::FireEvent(const int svtkEvent, void* data) +::contextMenuEvent( QContextMenuEvent* event ) { - myInteractor->InvokeEvent( svtkEvent, data ); + if( !( event->state() & KeyButtonMask ) ) + emit contextMenuRequested( event ); } diff --git a/src/SVTK/SVTK_RenderWindowInteractor.h b/src/SVTK/SVTK_RenderWindowInteractor.h index a579e9b93..0a07e4332 100644 --- a/src/SVTK/SVTK_RenderWindowInteractor.h +++ b/src/SVTK/SVTK_RenderWindowInteractor.h @@ -38,12 +38,17 @@ #include #include +#include + class QTimer; +class vtkCallbackCommand; class vtkActorCollection; class vtkGenericRenderWindowInteractor; class SALOME_Actor; +class SVTK_Selector; +class SVTK_InteractorStyle; // ------------------------------------------------------------ // :TRICKY: Fri Apr 21 22:19:27 2000 Pagey @@ -58,6 +63,18 @@ class SVTK_EXPORT QtRenderWindowInteractor: { Q_OBJECT; + public: + static QtRenderWindowInteractor* New(); + vtkTypeMacro(QtRenderWindowInteractor,vtkGenericRenderWindowInteractor); + + virtual + int + CreateTimer( int ) ; + + virtual + int + DestroyTimer() ; + protected slots: virtual void @@ -68,50 +85,49 @@ class SVTK_EXPORT QtRenderWindowInteractor: ~QtRenderWindowInteractor(); QTimer* myTimer ; - - public: - - static QtRenderWindowInteractor* New(); - vtkTypeMacro(QtRenderWindowInteractor,vtkGenericRenderWindowInteractor); - - virtual int CreateTimer( int ) ; - virtual int DestroyTimer() ; }; // ------------------------------------------------------------ -class SVTK_EXPORT SVTK_RenderWindowInteractor: public SVTK_RenderWindow +class SVTK_EXPORT QVTK_RenderWindowInteractor: public QWidget { Q_OBJECT; public: - SVTK_RenderWindowInteractor( QWidget*, const char* ); - ~SVTK_RenderWindowInteractor(); + QVTK_RenderWindowInteractor(QWidget* theParent, + const char* theName); + + ~QVTK_RenderWindowInteractor(); - vtkRenderWindowInteractor* getDevice(); + vtkRenderWindowInteractor* + GetDevice(); + + void + SetRenderWindow(vtkRenderWindow *theRenderWindow); + + vtkRenderWindow* + GetRenderWindow(); // Description: // Initializes the event handlers without an XtAppContext. This is // good for when you don`t have a user interface, but you still // want to have mouse interaction. - virtual void Initialize(); + void + Initialize(); + + virtual + void + InvokeEvent(unsigned long theEvent, void* theCallData); // Description: // Event loop notification member for Window size change - virtual void UpdateSize(int x,int y); - - virtual void Render(); - - void Update(); - - vtkRenderer* GetRenderer(); + virtual + void + UpdateSize(int x,int y); protected: - vtkSmartPointer myInteractor; - virtual void paintEvent( QPaintEvent* ); virtual void resizeEvent( QResizeEvent* ); - virtual void contextMenuEvent( QContextMenuEvent * e ); virtual void mouseMoveEvent( QMouseEvent* ); virtual void mousePressEvent( QMouseEvent* ); @@ -120,83 +136,90 @@ class SVTK_EXPORT SVTK_RenderWindowInteractor: public SVTK_RenderWindow virtual void wheelEvent( QWheelEvent* ); virtual void keyPressEvent( QKeyEvent* ); virtual void keyReleaseEvent( QKeyEvent* ); + virtual void contextMenuEvent( QContextMenuEvent * e ); // reimplemented from QWidget in order to set window - receiver // of space mouse events. - virtual void focusInEvent ( QFocusEvent* ); + virtual void focusInEvent( QFocusEvent* ); virtual void focusOutEvent( QFocusEvent* ); virtual bool x11Event( XEvent *e ); + vtkSmartPointer myInteractor; +}; + + +// ------------------------------------------------------------ +class SVTK_EXPORT SVTK_RenderWindowInteractor: public QVTK_RenderWindowInteractor +{ + Q_OBJECT; + + public: + SVTK_RenderWindowInteractor(QWidget* theParent, + const char* theName); + + ~SVTK_RenderWindowInteractor(); + + SVTK_Selector* GetSelector(); + void SetSelector(SVTK_Selector* theSelector); + + SVTK_InteractorStyle* GetInteractorStyle(); + void PushInteractorStyle(SVTK_InteractorStyle* theStyle); + void PopInteractorStyle(); + + int SelectionMode() const; + void SetSelectionMode(int theMode); + + public: + void + onEmitSelectionChanged(); + public: signals: void MouseMove( QMouseEvent* ); void MouseButtonPressed( QMouseEvent* ); void MouseButtonReleased( QMouseEvent* ); void MouseDoubleClicked( QMouseEvent* ); - void WheelMoved( QWheelEvent* ); void ButtonPressed(const QMouseEvent *event); void ButtonReleased(const QMouseEvent *event); + void WheelMoved( QWheelEvent* ); void KeyPressed( QKeyEvent* ); void KeyReleased( QKeyEvent* ); void contextMenuRequested( QContextMenuEvent *e ); - public: - /* Selection Management */ - bool isInViewer( const Handle(SALOME_InteractiveObject)& IObject); - bool isVisible( const Handle(SALOME_InteractiveObject)& IObject); - void rename(const Handle(SALOME_InteractiveObject)& IObject, QString newName); - - // Displaymode management - int GetDisplayMode(); - void SetDisplayMode(int); - - // Switch representation wireframe/shading - void SetDisplayMode(const Handle(SALOME_InteractiveObject)& IObject, int theMode); - - // Change all actors to wireframe or surface - void ChangeRepresentationToWireframe(); - void ChangeRepresentationToSurface(); - - // Change to wireframe or surface a list of vtkactor - void ChangeRepresentationToWireframe(vtkActorCollection* ListofActors); - void ChangeRepresentationToSurface(vtkActorCollection* ListofActors); - - // Erase Display functions - void EraseAll(); - void DisplayAll(); - void RemoveAll( const bool immediatly ); - void Erase(const Handle(SALOME_InteractiveObject)& IObject, - bool immediatly=true); - void Remove(const Handle(SALOME_InteractiveObject)& IObject, - bool immediatly=true); - void Display(const Handle(SALOME_InteractiveObject)& IObject, - bool immediatly=true); - - void Display( SALOME_Actor* SActor, - bool immediatly = true ); - void Erase( SALOME_Actor* SActor, - bool immediatly = true ); - void Remove( SALOME_Actor* SActor, - bool updateViewer = true ); - - // Transparency - void SetTransparency(const Handle(SALOME_InteractiveObject)& IObject, - float trans); - float GetTransparency(const Handle(SALOME_InteractiveObject)& IObject); - - // Color - void SetColor(const Handle(SALOME_InteractiveObject)& IObject, - QColor thecolor); - QColor GetColor(const Handle(SALOME_InteractiveObject)& IObject); - - // SVTK events manamegent (key accelerators, speed increment, etc.) - void FireEvent( const int svtkAccelEvent, void* data ); + void selectionChanged(); protected: - int myDisplayMode; + virtual void mouseMoveEvent( QMouseEvent* ); + virtual void mousePressEvent( QMouseEvent* ); + virtual void mouseReleaseEvent( QMouseEvent* ); + virtual void mouseDoubleClickEvent( QMouseEvent* ); + virtual void wheelEvent( QWheelEvent* ); + virtual void keyPressEvent( QKeyEvent* ); + virtual void keyReleaseEvent( QKeyEvent* ); + virtual void contextMenuEvent( QContextMenuEvent * e ); -}; + void + InitInteractorStyle(SVTK_InteractorStyle* theStyle); + + // Main process VTK event method + static + void + ProcessEvents(vtkObject* theObject, + unsigned long theEvent, + void* theClientData, + void* theCallData); + // Used to process VTK events + vtkSmartPointer myEventCallbackCommand; + + // Priority at which events are processed + float myPriority; + + vtkSmartPointer mySelector; + + typedef vtkSmartPointer PInteractorStyle; + QValueStack myInteractorStyles; +}; #endif diff --git a/src/SVTK/SVTK_Selection.h b/src/SVTK/SVTK_Selection.h index ef5e662c6..de27e1582 100644 --- a/src/SVTK/SVTK_Selection.h +++ b/src/SVTK/SVTK_Selection.h @@ -30,16 +30,15 @@ #define SVTK_SELECTION_H -enum Selection_Mode -{ - NodeSelection, - CellSelection, - EdgeOfCellSelection, - EdgeSelection, - FaceSelection, - VolumeSelection, - ActorSelection -}; +typedef int Selection_Mode; + +const Selection_Mode NodeSelection = 0; +const Selection_Mode CellSelection = 1; +const Selection_Mode EdgeOfCellSelection = 2; +const Selection_Mode EdgeSelection = 3; +const Selection_Mode FaceSelection = 4; +const Selection_Mode VolumeSelection = 5; +const Selection_Mode ActorSelection = 6; #endif diff --git a/src/SVTK/SVTK_Selector.cxx b/src/SVTK/SVTK_Selector.cxx index 5ee296214..9a45517a2 100644 --- a/src/SVTK/SVTK_Selector.cxx +++ b/src/SVTK/SVTK_Selector.cxx @@ -78,7 +78,7 @@ SVTK_SelectorDef //---------------------------------------------------------------------------- void SVTK_SelectorDef -::SetSelectionMode(Selection_Mode theMode) +::SetSelectionMode(int theMode) { mySelectionMode = theMode; } @@ -357,3 +357,59 @@ SVTK_SelectorDef { myMapIOSubIndex.clear(); } + +//---------------------------------------------------------------------------- +void +SVTK_SelectorDef +::SetFilter(const Handle(VTKViewer_Filter)& theFilter) +{ + myFilters.insert(TFilters::value_type(theFilter->GetId(),theFilter)); +} + +//---------------------------------------------------------------------------- +bool +SVTK_SelectorDef +::IsFilterPresent(const TFilterID theId) const +{ + return myFilters.find(theId) != myFilters.end(); +} + +//---------------------------------------------------------------------------- +void +SVTK_SelectorDef +::RemoveFilter(const TFilterID theId) +{ + if(IsFilterPresent(theId)) + myFilters.erase(theId); +} + +//---------------------------------------------------------------------------- +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; +} + +//---------------------------------------------------------------------------- +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)(); +} + diff --git a/src/SVTK/SVTK_Selector.h b/src/SVTK/SVTK_Selector.h index cec7d3120..4813ab597 100644 --- a/src/SVTK/SVTK_Selector.h +++ b/src/SVTK/SVTK_Selector.h @@ -29,13 +29,14 @@ #ifndef SVTK_SELECTOR_H #define SVTK_SELECTOR_H -#include +#include "SVTK_Selection.h" +#include "SALOME_ListIO.hxx" +#include "VTKViewer_Filter.h" #include #include -#include "SVTK_Selection.h" -#include "SALOME_ListIO.hxx" +#include class SALOME_Actor; @@ -48,10 +49,10 @@ public: virtual void - SetSelectionMode( Selection_Mode theMode ) = 0; + SetSelectionMode( int theMode ) = 0; virtual - Selection_Mode + int SelectionMode() const = 0; virtual @@ -130,6 +131,32 @@ public: void ClearIndex() = 0; + //---------------------------------------------------------------------------- + typedef int TFilterID; + + virtual + void + SetFilter(const Handle(VTKViewer_Filter)& theFilter) = 0; + + virtual + Handle(VTKViewer_Filter) + GetFilter(const TFilterID theId) const = 0; + + virtual + bool + IsFilterPresent(const TFilterID theId) const = 0; + + virtual + void + RemoveFilter(const TFilterID theId) = 0; + + virtual + bool + IsValid(SALOME_Actor* theActor, + const TFilterID theId, + const bool theIsNode = false) const = 0; + + //---------------------------------------------------------------------------- virtual void StartPickCallback() = 0; diff --git a/src/SVTK/SVTK_SelectorDef.h b/src/SVTK/SVTK_SelectorDef.h index 5cff4c62c..9150a652a 100644 --- a/src/SVTK/SVTK_SelectorDef.h +++ b/src/SVTK/SVTK_SelectorDef.h @@ -51,10 +51,10 @@ public: virtual void - SetSelectionMode( Selection_Mode theMode ); + SetSelectionMode( int theMode ); virtual - Selection_Mode + int SelectionMode() const { return mySelectionMode; } virtual @@ -133,6 +133,30 @@ public: void ClearIndex(); + //---------------------------------------------------------------------------- + virtual + void + SetFilter(const Handle(VTKViewer_Filter)& theFilter); + + virtual + Handle(VTKViewer_Filter) + GetFilter(const TFilterID theId) const; + + virtual + bool + IsFilterPresent(const TFilterID theId) const; + + virtual + void + RemoveFilter(const int theId); + + virtual + bool + IsValid(SALOME_Actor* theActor, + const TFilterID theId, + const bool theIsNode = false) const; + + //---------------------------------------------------------------------------- virtual void StartPickCallback(); @@ -142,7 +166,7 @@ public: EndPickCallback(); private: - Selection_Mode mySelectionMode; + int mySelectionMode; struct TIOLessThan { @@ -154,7 +178,8 @@ private: } }; - struct TIndexedMapOfInteger{ + struct TIndexedMapOfInteger + { TColStd_IndexedMapOfInteger myMap; TIndexedMapOfInteger() {} @@ -178,7 +203,9 @@ private: TIndexedMapOfInteger, TIOLessThan> TMapIOSubIndex; TMapIOSubIndex myMapIOSubIndex; -}; + typedef std::map TFilters; + TFilters myFilters; +}; #endif diff --git a/src/SVTK/SVTK_View.cxx b/src/SVTK/SVTK_View.cxx index a29e0b4e7..4cef4ea32 100644 --- a/src/SVTK/SVTK_View.cxx +++ b/src/SVTK/SVTK_View.cxx @@ -1,15 +1,16 @@ #include "SALOME_Actor.h" #include +#include #include #include #include #include #include -#include #include -#include +#include +#include #include "QtxAction.h" @@ -24,8 +25,11 @@ #include "VTKViewer_CellRectPicker.h" #include "SVTK_View.h" +#include "SVTK_Event.h" +#include "SVTK_Renderer.h" #include "SVTK_ViewModel.h" #include "SVTK_InteractorStyle.h" +#include "SVTK_RenderWindowInteractor.h" #include "SALOME_ListIteratorOfListIO.hxx" @@ -35,161 +39,743 @@ #include "SVTK_Functor.h" //---------------------------------------------------------------------------- -SVTK_View -::SVTK_View( QWidget* parent, const char* name ) : - SVTK_RenderWindowInteractor( parent, name ) +SVTK_RendererHolder +::SVTK_RendererHolder(QWidget* theParent, + const char* theName): + QMainWindow(theParent,theName,0), + myRenderer(SVTK_Renderer::New()) { - myEventCallbackCommand = vtkCallbackCommand::New(); - myEventCallbackCommand->Delete(); + myRenderer->Delete(); +} - myEventCallbackCommand->SetClientData(this); - myPriority = 0.0; +SVTK_RendererHolder +::~SVTK_RendererHolder() +{} - myEventCallbackCommand->SetCallback(SVTK_View::ProcessEvents); +//---------------------------------------------------------------------------- +vtkRenderer* +SVTK_RendererHolder +::GetRenderer() +{ + return myRenderer.GetPointer(); +} - SetSelector(SVTK_Selector::New()); - GetSelector()->Delete(); +//---------------------------------------------------------------------------- +void +SVTK_RendererHolder +::setBackgroundColor(const QColor& theColor) +{ + myRenderer->SetBackground(theColor.red()/255.0, + theColor.green()/255.0, + theColor.blue()/255.0); +} - pushInteractorStyle( SVTK_InteractorStyle::New() ); +//---------------------------------------------------------------------------- +QColor +SVTK_RendererHolder +::backgroundColor() const +{ + float aBackgroundColor[3]; + myRenderer->GetBackground(aBackgroundColor); + return QColor(int(aBackgroundColor[0]*255), + int(aBackgroundColor[1]*255), + int(aBackgroundColor[2]*255)); } //---------------------------------------------------------------------------- -SVTK_View -::~SVTK_View() -{} +void +SVTK_RendererHolder +::GetScale( double theScale[3] ) +{ + myRenderer->GetScale( theScale ); +} + +void +SVTK_RendererHolder +::SetScale( double theScale[3] ) +{ + myRenderer->SetScale( theScale ); + Repaint(); +} + //---------------------------------------------------------------------------- -SVTK_Selector* -SVTK_View -::GetSelector() -{ - return mySelector.GetPointer(); +void +SVTK_RendererHolder +::AddActor(VTKViewer_Actor* theActor, bool theIsUpdate) +{ + myRenderer->AddActor(theActor); + if(theIsUpdate) + Repaint(); } +//---------------------------------------------------------------------------- void -SVTK_View -::SetSelector( SVTK_Selector* theSelector ) -{ - if(mySelector.GetPointer()) - mySelector->RemoveObserver(myEventCallbackCommand.GetPointer()); +SVTK_RendererHolder +::RemoveActor(VTKViewer_Actor* theActor, bool theIsUpdate) +{ + myRenderer->RemoveActor(theActor); + if(theIsUpdate) + Repaint(); +} - mySelector = theSelector; - if(mySelector.GetPointer()) - mySelector->AddObserver(vtkCommand::EndPickEvent, - myEventCallbackCommand.GetPointer(), - myPriority); +//---------------------------------------------------------------------------- +int +SVTK_RendererHolder +::GetTrihedronSize() const +{ + return myRenderer->GetTrihedronSize(); } //---------------------------------------------------------------------------- void -SVTK_View -::ProcessEvents(vtkObject* vtkNotUsed(theObject), - unsigned long theEvent, - void* theClientData, - void* vtkNotUsed(theCallData)) +SVTK_RendererHolder +::SetTrihedronSize( const int theSize ) { - SVTK_View* self = reinterpret_cast(theClientData); + myRenderer->SetTrihedronSize(theSize); + Repaint(); +} - switch(theEvent){ - case vtkCommand::EndPickEvent: - self->onEmitSelectionChanged(); - break; - } + +//---------------------------------------------------------------------------- +/*! If parameter theIsForcedUpdate is true, recalculate parameters for + * trihedron and cube axes, even if trihedron and cube axes is invisible. + */ +void +SVTK_RendererHolder +::AdjustTrihedrons(const bool theIsForced) +{ + myRenderer->AdjustTrihedrons(theIsForced); + Repaint(); +} + +//---------------------------------------------------------------------------- +bool +SVTK_RendererHolder +::isTrihedronDisplayed() +{ + return myRenderer->isTrihedronDisplayed(); } +//---------------------------------------------------------------------------- +bool +SVTK_RendererHolder +::isCubeAxesDisplayed() +{ + return myRenderer->isCubeAxesDisplayed(); +} + +//---------------------------------------------------------------------------- +VTKViewer_Trihedron* +SVTK_RendererHolder +::GetTrihedron() +{ + return myRenderer->GetTrihedron(); +} + +//---------------------------------------------------------------------------- +SVTK_CubeAxesActor2D* +SVTK_RendererHolder +::GetCubeAxes() +{ + return myRenderer->GetCubeAxes(); +} + + +//---------------------------------------------------------------------------- +SVTK_ActionHolder +::SVTK_ActionHolder(QWidget* theParent, + const char* theName, + SUIT_ResourceMgr* theResourceMgr) : + SVTK_RendererHolder(theParent,theName) +{ + myToolBar = new QToolBar(this); + myToolBar->setCloseMode(QDockWindow::Undocked); + myToolBar->setLabel(tr("LBL_TOOLBAR_LABEL")); + + createActions(theResourceMgr); + createToolBar(); +} + +//---------------------------------------------------------------------------- +SVTK_ActionHolder +::~SVTK_ActionHolder() +{} + //---------------------------------------------------------------------------- void -SVTK_View +SVTK_ActionHolder +::SetEventDispatcher(vtkObject* theDispatcher) +{ + myEventDispatcher = theDispatcher; +} + +//---------------------------------------------------------------------------- +void +SVTK_ActionHolder +::createActions(SUIT_ResourceMgr* theResourceMgr) +{ + if(!myActionsMap.isEmpty()) + return; + + QtxAction* aAction; + + // Dump view + aAction = new QtxAction(tr("MNU_DUMP_VIEW"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_DUMP" ) ), + tr( "MNU_DUMP_VIEW" ), 0, this); + aAction->setStatusTip(tr("DSC_DUMP_VIEW")); + connect(aAction, SIGNAL(activated()), this, SLOT(onDumpView())); + myActionsMap[ DumpId ] = aAction; + + // FitAll + aAction = new QtxAction(tr("MNU_FITALL"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITALL" ) ), + tr( "MNU_FITALL" ), 0, this); + aAction->setStatusTip(tr("DSC_FITALL")); + connect(aAction, SIGNAL(activated()), this, SLOT(onFitAll())); + myActionsMap[ FitAllId ] = aAction; + + // FitRect + aAction = new QtxAction(tr("MNU_FITRECT"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITAREA" ) ), + tr( "MNU_FITRECT" ), 0, this); + aAction->setStatusTip(tr("DSC_FITRECT")); + connect(aAction, SIGNAL(activated()), this, SLOT(activateWindowFit())); + myActionsMap[ FitRectId ] = aAction; + + // Zoom + aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ZOOM" ) ), + tr( "MNU_ZOOM_VIEW" ), 0, this); + aAction->setStatusTip(tr("DSC_ZOOM_VIEW")); + connect(aAction, SIGNAL(activated()), this, SLOT(activateZoom())); + myActionsMap[ ZoomId ] = aAction; + + // Panning + aAction = new QtxAction(tr("MNU_PAN_VIEW"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_PAN" ) ), + tr( "MNU_PAN_VIEW" ), 0, this); + aAction->setStatusTip(tr("DSC_PAN_VIEW")); + connect(aAction, SIGNAL(activated()), this, SLOT(activatePanning())); + myActionsMap[ PanId ] = aAction; + + // Global Panning + aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_GLOBALPAN" ) ), + tr( "MNU_GLOBALPAN_VIEW" ), 0, this); + aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW")); + connect(aAction, SIGNAL(activated()), this, SLOT(activateGlobalPanning())); + myActionsMap[ GlobalPanId ] = aAction; + + // Rotation + aAction = new QtxAction(tr("MNU_ROTATE_VIEW"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ROTATE" ) ), + tr( "MNU_ROTATE_VIEW" ), 0, this); + aAction->setStatusTip(tr("DSC_ROTATE_VIEW")); + connect(aAction, SIGNAL(activated()), this, SLOT(activateRotation())); + myActionsMap[ RotationId ] = aAction; + + // Projections + aAction = new QtxAction(tr("MNU_FRONT_VIEW"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FRONT" ) ), + tr( "MNU_FRONT_VIEW" ), 0, this); + aAction->setStatusTip(tr("DSC_FRONT_VIEW")); + connect(aAction, SIGNAL(activated()), this, SLOT(onFrontView())); + myActionsMap[ FrontId ] = aAction; + + aAction = new QtxAction(tr("MNU_BACK_VIEW"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BACK" ) ), + tr( "MNU_BACK_VIEW" ), 0, this); + aAction->setStatusTip(tr("DSC_BACK_VIEW")); + connect(aAction, SIGNAL(activated()), this, SLOT(onBackView())); + myActionsMap[ BackId ] = aAction; + + aAction = new QtxAction(tr("MNU_TOP_VIEW"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TOP" ) ), + tr( "MNU_TOP_VIEW" ), 0, this); + aAction->setStatusTip(tr("DSC_TOP_VIEW")); + connect(aAction, SIGNAL(activated()), this, SLOT(onTopView())); + myActionsMap[ TopId ] = aAction; + + aAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BOTTOM" ) ), + tr( "MNU_BOTTOM_VIEW" ), 0, this); + aAction->setStatusTip(tr("DSC_BOTTOM_VIEW")); + connect(aAction, SIGNAL(activated()), this, SLOT(onBottomView())); + myActionsMap[ BottomId ] = aAction; + + aAction = new QtxAction(tr("MNU_LEFT_VIEW"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_LEFT" ) ), + tr( "MNU_LEFT_VIEW" ), 0, this); + aAction->setStatusTip(tr("DSC_LEFT_VIEW")); + connect(aAction, SIGNAL(activated()), this, SLOT(onLeftView())); + myActionsMap[ LeftId ] = aAction; + + aAction = new QtxAction(tr("MNU_RIGHT_VIEW"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RIGHT" ) ), + tr( "MNU_RIGHT_VIEW" ), 0, this); + aAction->setStatusTip(tr("DSC_RIGHT_VIEW")); + connect(aAction, SIGNAL(activated()), this, SLOT(onRightView())); + myActionsMap[ RightId ] = aAction; + + // Reset + aAction = new QtxAction(tr("MNU_RESET_VIEW"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RESET" ) ), + tr( "MNU_RESET_VIEW" ), 0, this); + aAction->setStatusTip(tr("DSC_RESET_VIEW")); + connect(aAction, SIGNAL(activated()), this, SLOT(onResetView())); + myActionsMap[ ResetId ] = aAction; + + // onViewTrihedron: Shows - Hides Trihedron + aAction = new QtxAction(tr("MNU_SHOW_TRIHEDRON"), + theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TRIHEDRON" ) ), + tr( "MNU_SHOW_TRIHEDRON" ), 0, this); + aAction->setStatusTip(tr("DSC_SHOW_TRIHEDRON")); + connect(aAction, SIGNAL(activated()), this, SLOT(onViewTrihedron())); + myActionsMap[ ViewTrihedronId ] = aAction; +} + +//---------------------------------------------------------------------------- +void +SVTK_ActionHolder +::createToolBar() +{ + myActionsMap[DumpId]->addTo(myToolBar); + myActionsMap[ViewTrihedronId]->addTo(myToolBar); + + SUIT_ToolButton* aScaleBtn = new SUIT_ToolButton(myToolBar); + aScaleBtn->AddAction(myActionsMap[FitAllId]); + aScaleBtn->AddAction(myActionsMap[FitRectId]); + aScaleBtn->AddAction(myActionsMap[ZoomId]); + + SUIT_ToolButton* aPanningBtn = new SUIT_ToolButton(myToolBar); + aPanningBtn->AddAction(myActionsMap[PanId]); + aPanningBtn->AddAction(myActionsMap[GlobalPanId]); + + myActionsMap[RotationId]->addTo(myToolBar); + + SUIT_ToolButton* aViewsBtn = new SUIT_ToolButton(myToolBar); + aViewsBtn->AddAction(myActionsMap[FrontId]); + aViewsBtn->AddAction(myActionsMap[BackId]); + aViewsBtn->AddAction(myActionsMap[TopId]); + aViewsBtn->AddAction(myActionsMap[BottomId]); + aViewsBtn->AddAction(myActionsMap[LeftId]); + aViewsBtn->AddAction(myActionsMap[RightId]); + + myActionsMap[ResetId]->addTo(myToolBar); +} + +//---------------------------------------------------------------------------- +QToolBar* +SVTK_ActionHolder +::getToolBar() +{ + return myToolBar; +} + +//---------------------------------------------------------------------------- +void +SVTK_ActionHolder ::activateZoom() { - getInteractorStyle()->startZoom(); + myEventDispatcher->InvokeEvent(SVTK::StartZoom,0); } //---------------------------------------------------------------------------- void -SVTK_View +SVTK_ActionHolder ::activatePanning() { - getInteractorStyle()->startPan(); + myEventDispatcher->InvokeEvent(SVTK::StartPan,0); } //---------------------------------------------------------------------------- void -SVTK_View +SVTK_ActionHolder ::activateRotation() { - getInteractorStyle()->startRotate(); + myEventDispatcher->InvokeEvent(SVTK::StartRotate,0); } //---------------------------------------------------------------------------- void -SVTK_View +SVTK_ActionHolder ::activateGlobalPanning() { - getInteractorStyle()->startGlobalPan(); + myEventDispatcher->InvokeEvent(SVTK::StartGlobalPan,0); } //---------------------------------------------------------------------------- void -SVTK_View +SVTK_ActionHolder ::activateWindowFit() { - getInteractorStyle()->startFitArea(); + myEventDispatcher->InvokeEvent(SVTK::StartFitArea,0); +} + +//---------------------------------------------------------------------------- +void +SVTK_ActionHolder +::onFrontView() +{ + myRenderer->onFrontView(); +} + +//---------------------------------------------------------------------------- +void +SVTK_ActionHolder +::onBackView() +{ + myRenderer->onBackView(); +} + +//---------------------------------------------------------------------------- +void +SVTK_ActionHolder +::onTopView() +{ + myRenderer->onTopView(); +} + +//---------------------------------------------------------------------------- +void +SVTK_ActionHolder +::onBottomView() +{ + myRenderer->onBottomView(); +} + +//---------------------------------------------------------------------------- +void +SVTK_ActionHolder +::onLeftView() +{ + myRenderer->onLeftView(); +} + +//---------------------------------------------------------------------------- +void +SVTK_ActionHolder +::onRightView() +{ + myRenderer->onRightView(); +} + +//---------------------------------------------------------------------------- +void +SVTK_ActionHolder +::onResetView() +{ + myRenderer->onResetView(); + Repaint(); +} + +//---------------------------------------------------------------------------- +void +SVTK_ActionHolder +::onFitAll() +{ + myRenderer->onFitAll(); + Repaint(); +} + +//---------------------------------------------------------------------------- +void +SVTK_ActionHolder +::onViewTrihedron() +{ + myRenderer->onViewTrihedron(); + Repaint(); +} + +//---------------------------------------------------------------------------- +void +SVTK_ActionHolder +::onViewCubeAxes() +{ + myRenderer->onViewCubeAxes(); + Repaint(); +} + +//---------------------------------------------------------------------------- +void +SVTK_ActionHolder +::onAdjustTrihedron() +{ + myRenderer->onAdjustTrihedron(); +} + +//---------------------------------------------------------------------------- +void +SVTK_ActionHolder +::onAdjustCubeAxes() +{ + myRenderer->onAdjustCubeAxes(); +} + +//---------------------------------------------------------------------------- +void +SVTK_ActionHolder +::onDumpView() +{} + +//---------------------------------------------------------------------------- +QImage +SVTK_ActionHolder +::dumpView() +{ + QPixmap px = QPixmap::grabWindow( winId() ); + return px.convertToImage(); +} + + +//---------------------------------------------------------------------------- +SVTK_InteractorHolder +::SVTK_InteractorHolder(QWidget* theParent, + const char* theName, + SUIT_ResourceMgr* theResourceMgr) : + SVTK_ActionHolder(theParent,theName,theResourceMgr), + myRenderWindow(vtkRenderWindow::New()) +{ + myRenderWindow->Delete(); + + myRenderWindow->AddRenderer(GetRenderer()); + + myInteractor = new SVTK_RenderWindowInteractor(this,"SVTK_RenderWindowInteractor"); + + SetInteractor(myInteractor); + + myInteractor->PushInteractorStyle(SVTK_InteractorStyle::New()); +} + +//---------------------------------------------------------------------------- +SVTK_InteractorHolder +::~SVTK_InteractorHolder() +{} + +//---------------------------------------------------------------------------- +void +SVTK_InteractorHolder +::SetInteractor(SVTK_RenderWindowInteractor* theInteractor) +{ + myInteractor = theInteractor; + + if(myInteractor){ + myInteractor->SetRenderWindow(myRenderWindow.GetPointer()); + + connect(myInteractor,SIGNAL(KeyPressed(QKeyEvent*)), + this,SIGNAL(KeyPressed(QKeyEvent*)) ); + connect(myInteractor,SIGNAL(KeyReleased(QKeyEvent*)), + this,SIGNAL(KeyReleased(QKeyEvent*))); + connect(myInteractor,SIGNAL(MouseButtonPressed(QMouseEvent*)), + this,SIGNAL(MouseButtonPressed(QMouseEvent*))); + connect(myInteractor,SIGNAL(MouseButtonReleased(QMouseEvent*)), + this,SIGNAL(MouseButtonReleased(QMouseEvent*))); + connect(myInteractor,SIGNAL(MouseDoubleClicked(QMouseEvent*)), + this,SIGNAL(MouseDoubleClicked(QMouseEvent*))); + connect(myInteractor,SIGNAL(MouseMove(QMouseEvent*)), + this,SIGNAL(MouseMove(QMouseEvent*))); + connect(myInteractor,SIGNAL(contextMenuRequested(QContextMenuEvent*)), + this,SIGNAL(contextMenuRequested(QContextMenuEvent*))); + connect(myInteractor,SIGNAL(selectionChanged()), + this,SIGNAL(selectionChanged())); + + SetEventDispatcher(myInteractor->GetDevice()); + + setCentralWidget(myInteractor); + + myInteractor->setFocusPolicy(StrongFocus); + myInteractor->setFocus(); + setFocusProxy(myInteractor); + } +} + +//---------------------------------------------------------------------------- +SVTK_RenderWindowInteractor* +SVTK_InteractorHolder +::GetInteractor() +{ + return myInteractor; +} + +//---------------------------------------------------------------------------- +vtkRenderWindowInteractor* +SVTK_InteractorHolder +::GetRenderWindowInteractor() +{ + return myInteractor->GetDevice(); +} + +//---------------------------------------------------------------------------- +void +SVTK_InteractorHolder +::Repaint( bool theUpdateTrihedron ) +{ + if(theUpdateTrihedron) + myRenderer->onAdjustTrihedron(); + + myInteractor->update(); +} + +//---------------------------------------------------------------------------- +void +SVTK_InteractorHolder +::Repaint() +{ + Repaint( true ); +} + +//---------------------------------------------------------------------------- +void +SVTK_InteractorHolder +::InvokeEvent(unsigned long theEvent, void* theCallData) +{ + myInteractor->InvokeEvent(theEvent,theCallData); +} + +//---------------------------------------------------------------------------- +void +SVTK_InteractorHolder +::Initialize() +{ + myInteractor->Initialize(); +} + +//---------------------------------------------------------------------------- +void +SVTK_InteractorHolder +::SetRenderWindow(vtkRenderWindow *theRenderWindow) +{ + myRenderWindow = theRenderWindow; + + if(myInteractor) + myInteractor->SetRenderWindow(myRenderWindow.GetPointer()); +} + +//---------------------------------------------------------------------------- +vtkRenderWindow* +SVTK_InteractorHolder +::GetRenderWindow() +{ + return myRenderWindow.GetPointer(); +} + +//---------------------------------------------------------------------------- +SVTK_Selector* +SVTK_InteractorHolder +::GetSelector() +{ + return myInteractor->GetSelector(); +} + +void +SVTK_InteractorHolder +::SetSelector(SVTK_Selector* theSelector) +{ + myInteractor->SetSelector(theSelector); +} + +//---------------------------------------------------------------------------- +void +SVTK_InteractorHolder +::PushInteractorStyle(SVTK_InteractorStyle* theStyle) +{ + myInteractor->PushInteractorStyle(theStyle); +} + +//---------------------------------------------------------------------------- +void +SVTK_InteractorHolder +::PopInteractorStyle() +{ + myInteractor->PopInteractorStyle(); +} + + +//---------------------------------------------------------------------------- +SVTK_InteractorStyle* +SVTK_InteractorHolder +::GetInteractorStyle() +{ + return myInteractor->GetInteractorStyle(); +} + + +//---------------------------------------------------------------- +void +SVTK_InteractorHolder +::SetSelectionMode(int theMode) +{ + myInteractor->SetSelectionMode(theMode); } + +//---------------------------------------------------------------- +int +SVTK_InteractorHolder +::SelectionMode() const +{ + return myInteractor->SelectionMode(); +} + + //---------------------------------------------------------------- struct THighlightAction { bool myIsHighlight; - Selection_Mode myMode; - THighlightAction( bool theIsHighlight, Selection_Mode theMode = ActorSelection ) - : myIsHighlight( theIsHighlight ), - myMode( theMode ) {} - void operator()( SALOME_Actor* theActor) { + int mySelectionMode; + THighlightAction( bool theIsHighlight, int theSelectionMode = ActorSelection ): + myIsHighlight( theIsHighlight ), + mySelectionMode( theSelectionMode ) + {} + + void + operator()( SALOME_Actor* theActor) + { if(theActor->GetMapper()){ - theActor->highlight( myIsHighlight, myMode ); + theActor->highlight( myIsHighlight, mySelectionMode ); } } }; //---------------------------------------------------------------- void -SVTK_View +SVTK_InteractorHolder ::onSelectionChanged() { - unHighlightAll(); + vtkActorCollection* anActors = GetRenderer()->GetActors(); - const SALOME_ListIO& aListIO = mySelector->StoredIObjects(); + using namespace VTK; + ForEach(anActors, + THighlightAction( false )); + + const SALOME_ListIO& aListIO = GetSelector()->StoredIObjects(); SALOME_ListIteratorOfListIO anIter(aListIO); + int aSelectionMode = SelectionMode(); for(; anIter.More(); anIter.Next()){ - highlight(anIter.Value(),true,!anIter.More()); + ForEachIf(anActors, + TIsSameIObject(anIter.Value()), + THighlightAction(true,aSelectionMode)); } -} -//---------------------------------------------------------------- -void -SVTK_View -::onEmitSelectionChanged() -{ - emit selectionChanged(); + Repaint(); } -//---------------------------------------------------------------- -void + +//---------------------------------------------------------------------------- SVTK_View -::SetSelectionMode(Selection_Mode theMode) -{ - mySelector->SetSelectionMode(theMode); -} +::SVTK_View(QWidget* theParent, + const char* theName, + SUIT_ResourceMgr* theResourceMgr) : + SVTK_InteractorHolder(theParent,theName,theResourceMgr) +{} -//---------------------------------------------------------------- -Selection_Mode +//---------------------------------------------------------------------------- SVTK_View -::SelectionMode() const -{ - return mySelector->SelectionMode(); -} +::~SVTK_View() +{} //---------------------------------------------------------------- void @@ -197,10 +783,10 @@ SVTK_View ::unHighlightAll() { using namespace VTK; - ForEach( getRenderer()->GetActors(), - THighlightAction( false ) ); + ForEach(GetRenderer()->GetActors(), + THighlightAction( false )); - update(); + Repaint(); } //---------------------------------------------------------------- @@ -211,11 +797,11 @@ SVTK_View bool theIsUpdate ) { using namespace VTK; - ForEachIf( getRenderer()->GetActors(), - TIsSameIObject( theIO ), - THighlightAction( theIsHighlight, mySelector->SelectionMode() ) ); - - update(); + ForEachIf(GetRenderer()->GetActors(), + TIsSameIObject( theIO ), + THighlightAction( theIsHighlight, GetSelector()->SelectionMode() )); + + Repaint(); } //---------------------------------------------------------------------------- @@ -226,7 +812,7 @@ SVTK_View const double& theBlue, const int& theWidth) { - vtkActorCollection* anActors = getRenderer()->GetActors(); + vtkActorCollection* anActors = GetRenderer()->GetActors(); anActors->InitTraversal(); while( vtkActor* anActor = anActors->GetNextActor() ) { @@ -250,7 +836,7 @@ SVTK_View ::SetSelectionTolerance(const double& theTolNodes, const double& theTolItems) { - vtkActorCollection* anActors = getRenderer()->GetActors(); + vtkActorCollection* anActors = GetRenderer()->GetActors(); anActors->InitTraversal(); while( vtkActor* anActor = anActors->GetNextActor() ) { @@ -264,42 +850,312 @@ SVTK_View } //---------------------------------------------------------------------------- +bool +SVTK_View +::isInViewer(const Handle(SALOME_InteractiveObject)& theIObject) +{ + using namespace VTK; + SALOME_Actor* anActor = + Find(GetRenderer()->GetActors(), + TIsSameIObject(theIObject)); + return anActor != NULL; +} + +//---------------------------------------------------------------------------- +bool +SVTK_View +::isVisible(const Handle(SALOME_InteractiveObject)& theIObject) +{ + using namespace VTK; + SALOME_Actor* anActor = + Find(GetRenderer()->GetActors(), + TIsSameIObject(theIObject)); + return anActor != NULL && anActor->GetVisibility(); +} + +//---------------------------------------------------------------------------- +void +SVTK_View +::rename(const Handle(SALOME_InteractiveObject)& theIObject, + const QString& theName) +{ + using namespace VTK; + ForEachIf(GetRenderer()->GetActors(), + TIsSameIObject(theIObject), + TSetFunction + (&SALOME_Actor::setName,theName.latin1())); +} + +//---------------------------------------------------------------------------- +int +SVTK_View +::GetDisplayMode() +{ + return myDisplayMode; +} + +void +SVTK_View +::SetDisplayMode(int theMode) +{ + if(theMode == 0) + ChangeRepresentationToWireframe(); + else + ChangeRepresentationToSurface(); + myDisplayMode = theMode; +} + +void +SVTK_View +::SetDisplayMode(const Handle(SALOME_InteractiveObject)& theIObject, + int theMode) +{ + using namespace VTK; + ForEachIf(GetRenderer()->GetActors(), + TIsSameIObject(theIObject), + TSetFunction + (&SALOME_Actor::setDisplayMode,theMode)); +} + +//---------------------------------------------------------------------------- +void +SVTK_View +::ChangeRepresentationToWireframe() +{ + ChangeRepresentationToWireframe(GetRenderer()->GetActors()); +} + +void +SVTK_View +::ChangeRepresentationToSurface() +{ + ChangeRepresentationToSurface(GetRenderer()->GetActors()); +} + + +void +SVTK_View +::ChangeRepresentationToWireframe(vtkActorCollection* theCollection) +{ + using namespace VTK; + ForEach(theCollection, + TSetFunction + (&SALOME_Actor::setDisplayMode,0)); + Repaint(); +} + +void +SVTK_View +::ChangeRepresentationToSurface(vtkActorCollection* theCollection) +{ + using namespace VTK; + ForEach(theCollection, + TSetFunction + (&SALOME_Actor::setDisplayMode,1)); + Repaint(); +} + +//---------------------------------------------------------------------------- +struct TErase +{ + VTK::TSetFunction mySetFunction; + TErase(): + mySetFunction(&vtkActor::SetVisibility,false) + {} + void operator()(SALOME_Actor* theActor){ + theActor->SetVisibility(false); + // Erase dependent actors + vtkActorCollection* aCollection = vtkActorCollection::New(); + theActor->GetChildActors(aCollection); + VTK::ForEach(aCollection,mySetFunction); + aCollection->Delete(); + } +}; + +void +SVTK_View +::EraseAll() +{ + using namespace VTK; + ForEach(GetRenderer()->GetActors(), + TErase()); + Repaint(); +} + +void +SVTK_View +::DisplayAll() +{ + using namespace VTK; + ForEach(GetRenderer()->GetActors(), + TSetVisibility(true)); + Repaint(); +} + + +void +SVTK_View +::Erase(SALOME_Actor* theActor, + bool theIsUpdate) +{ + TErase()(theActor); + + if(theIsUpdate) + Repaint(); +} + + +void +SVTK_View +::Erase(const Handle(SALOME_InteractiveObject)& theIObject, + bool theIsUpdate) +{ + using namespace VTK; + ForEachIf(GetRenderer()->GetActors(), + TIsSameIObject(theIObject), + TErase()); + if(theIsUpdate) + Repaint(); +} + +//---------------------------------------------------------------------------- +void +SVTK_View +::Display(SALOME_Actor* theActor, + bool theIsUpdate) +{ + GetRenderer()->AddActor(theActor); + theActor->SetVisibility(true); + + if(theIsUpdate) + Repaint(); +} + + void SVTK_View -::initInteractorStyle( SVTK_InteractorStyle* interactorStyle ) +::Display(const Handle(SALOME_InteractiveObject)& theIObject, + bool theIsUpdate) { - getDevice()->SetInteractorStyle( interactorStyle ); - interactorStyle->FindPokedRenderer( 0, 0 ); + using namespace VTK; + ForEachIf(GetRenderer()->GetActors(), + TIsSameIObject(theIObject), + TSetVisibility(true)); - interactorStyle->SetSelector( GetSelector() ); - interactorStyle->SetRenderWidget( this ); + if(theIsUpdate) + Repaint(); } //---------------------------------------------------------------------------- +struct TRemoveAction +{ + vtkRenderer* myRen; + TRemoveAction(vtkRenderer* theRen): myRen(theRen){} + void operator()(SALOME_Actor* theActor){ + myRen->RemoveActor(theActor); + } +}; + +void +SVTK_View +::Remove(const Handle(SALOME_InteractiveObject)& theIObject, + bool theIsUpdate) +{ + using namespace VTK; + ForEachIf(GetRenderer()->GetActors(), + TIsSameIObject(theIObject), + TRemoveAction(GetRenderer())); + if(theIsUpdate) + Repaint(); +} + void SVTK_View -::pushInteractorStyle( SVTK_InteractorStyle* interactorStyle ) +::Remove(SALOME_Actor* theActor, + bool theIsUpdate) { - myInteractorStyles.push( PInteractorStyle(interactorStyle) ); - initInteractorStyle( interactorStyle ); + GetRenderer()->RemoveProp(theActor); + if(theIsUpdate) + Repaint(); +} + +void +SVTK_View +::RemoveAll(bool theIsUpdate) +{ + vtkRenderer* aRenderer = GetRenderer(); + if(vtkActorCollection* anActors = aRenderer->GetActors()){ + anActors->InitTraversal(); + while(vtkActor *anAct = anActors->GetNextActor()){ + if(SALOME_Actor* aSAct = SALOME_Actor::SafeDownCast(anAct)){ + if(aSAct->hasIO() && aSAct->getIO()->hasEntry()) + aRenderer->RemoveActor( anAct ); + } + } + + if(theIsUpdate) + Repaint(); + } } //---------------------------------------------------------------------------- +float +SVTK_View +::GetTransparency(const Handle(SALOME_InteractiveObject)& theIObject) +{ + using namespace VTK; + SALOME_Actor* anActor = + Find(GetRenderer()->GetActors(), + TIsSameIObject(theIObject)); + if(anActor) + return 1.0 - anActor->GetOpacity(); + return -1.0; +} + + void SVTK_View -::popInteractorStyle() +::SetTransparency(const Handle(SALOME_InteractiveObject)& theIObject, + float theTrans) { - if ( getInteractorStyle() ) - myInteractorStyles.pop(); - - if ( getInteractorStyle() ) - initInteractorStyle( getInteractorStyle() ); + float anOpacity = 1.0 - theTrans; + using namespace VTK; + ForEachIf(GetRenderer()->GetActors(), + TIsSameIObject(theIObject), + TSetFunction + (&SALOME_Actor::SetOpacity,anOpacity)); } //---------------------------------------------------------------------------- -SVTK_InteractorStyle* +void SVTK_View -::getInteractorStyle() +::SetColor(const Handle(SALOME_InteractiveObject)& theIObject, + const QColor& theColor) { - return myInteractorStyles.isEmpty() ? 0 : myInteractorStyles.top().GetPointer(); + float aColor[3] = {theColor.red()/255., theColor.green()/255., theColor.blue()/255.}; + + using namespace VTK; + ForEachIf(GetRenderer()->GetActors(), + TIsSameIObject(theIObject), + TSetFunction + (&SALOME_Actor::SetColor,aColor)); } + + +QColor +SVTK_View +::GetColor(const Handle(SALOME_InteractiveObject)& theIObject) +{ + using namespace VTK; + SALOME_Actor* anActor = + Find(GetRenderer()->GetActors(), + TIsSameIObject(theIObject)); + if(anActor){ + float r,g,b; + anActor->GetColor(r,g,b); + return QColor(int(r*255),int(g*255),int(b*255)); + } + + return QColor(0,0,0); +} + diff --git a/src/SVTK/SVTK_View.h b/src/SVTK/SVTK_View.h index e1229a18d..da0c89e14 100644 --- a/src/SVTK/SVTK_View.h +++ b/src/SVTK/SVTK_View.h @@ -7,107 +7,344 @@ #include "SVTK.h" -#include "SVTK_Selection.h" -#include "SVTK_RenderWindowInteractor.h" - - #include "SALOME_InteractiveObject.hxx" #include -#include +#include + +class QtxAction; + +class vtkRenderer; +class vtkRenderWindow; +class vtkRenderWindowInteractor; +class vtkObject; class vtkCallbackCommand; +class vtkActorCollection; + +class SUIT_ResourceMgr; class VTKViewer_Actor; class SVTK_Viewer; class SVTK_Selector; +class SVTK_CubeAxesActor2D; +class VTKViewer_Trihedron; +class VTKViewer_Transform; +class VTKViewer_Actor; +class SVTK_Renderer; + class SVTK_RenderWindow; class SVTK_InteractorStyle; +class SVTK_RenderWindowInteractor; + +class SALOME_Actor; -class SVTK_EXPORT SVTK_View : public SVTK_RenderWindowInteractor +//---------------------------------------------------------------------------- +class SVTK_EXPORT SVTK_RendererHolder: public QMainWindow { Q_OBJECT; public: - SVTK_View( QWidget*, const char* ); - virtual ~SVTK_View(); - - SVTK_Selector* GetSelector(); - void SetSelector( SVTK_Selector* theSelector ); + SVTK_RendererHolder(QWidget* theParent, + const char* theName); - SVTK_InteractorStyle* getInteractorStyle(); - void pushInteractorStyle( SVTK_InteractorStyle* ); - void popInteractorStyle(); + virtual + ~SVTK_RendererHolder(); - Selection_Mode SelectionMode() const; - void SetSelectionMode( Selection_Mode ); + vtkRenderer* GetRenderer(); - /* interactive object management */ - void highlight( const Handle(SALOME_InteractiveObject)& IObject, - bool highlight, bool immediatly = true ); - void unHighlightAll(); - bool isInViewer( const Handle(SALOME_InteractiveObject)& IObject ); - bool isVisible( const Handle(SALOME_InteractiveObject)& IObject ); - - /* selection */ - Handle(SALOME_InteractiveObject) FindIObject(const char* Entry); - - /* display */ - void Display( const Handle(SALOME_InteractiveObject)& IObject, - bool immediatly = true ); - void DisplayOnly( const Handle(SALOME_InteractiveObject)& IObject ); - void Erase( const Handle(SALOME_InteractiveObject)& IObject, - bool immediatly = true ); - void DisplayAll(); - void EraseAll(); + virtual void Repaint() = 0; + void setBackgroundColor( const QColor& ); + QColor backgroundColor() const; + + //apply existing transformation on adding SALOME_Actor + void SetScale( double theScale[3] ); + void GetScale( double theScale[3] ); + + void AddActor(VTKViewer_Actor* theActor, bool theIsUpdate = false); + void RemoveActor(VTKViewer_Actor* theActor, bool theIsUpdate = false); + + int GetTrihedronSize() const; + void SetTrihedronSize( const int ); void AdjustTrihedrons( const bool forced ); - 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); + bool isTrihedronDisplayed(); + bool isCubeAxesDisplayed(); -public slots: - void onSelectionChanged(); - void onEmitSelectionChanged(); + VTKViewer_Trihedron* GetTrihedron(); + SVTK_CubeAxesActor2D* GetCubeAxes(); -signals: - void selectionChanged(); + protected: + vtkSmartPointer myRenderer; +}; + + +//---------------------------------------------------------------------------- +class SVTK_EXPORT SVTK_ActionHolder: public SVTK_RendererHolder +{ + Q_OBJECT; + +public: + SVTK_ActionHolder(QWidget* theParent, + const char* theName, + SUIT_ResourceMgr* theResourceMgr); -public slots: + virtual + ~SVTK_ActionHolder(); + + void + SetEventDispatcher(vtkObject* theDispatcher); + + QToolBar* getToolBar(); + + public slots: virtual void activateZoom(); virtual void activateWindowFit(); virtual void activateRotation(); virtual void activatePanning(); virtual void activateGlobalPanning(); -protected: - // Main process VTK event method - static + void onFrontView(); + void onBackView(); + void onTopView(); + void onBottomView(); + void onRightView(); + void onLeftView(); + + void onResetView(); + void onFitAll(); + + void onViewTrihedron(); + void onViewCubeAxes(); + + void onAdjustTrihedron(); + void onAdjustCubeAxes(); + + void onDumpView(); + + public: + QImage dumpView(); + + protected: + void + createActions(SUIT_ResourceMgr* theResourceMgr); + + void + createToolBar(); + + enum { DumpId, FitAllId, FitRectId, ZoomId, PanId, GlobalPanId, RotationId, + FrontId, BackId, TopId, BottomId, LeftId, RightId, ResetId, ViewTrihedronId }; + typedef QMap TActionsMap; + + vtkSmartPointer myEventDispatcher; + TActionsMap myActionsMap; + QToolBar* myToolBar; +}; + + +//---------------------------------------------------------------------------- +class SVTK_EXPORT SVTK_InteractorHolder : public SVTK_ActionHolder +{ + Q_OBJECT; + +public: + SVTK_InteractorHolder(QWidget* theParent, + const char* theName, + SUIT_ResourceMgr* theResourceMgr); + + virtual + ~SVTK_InteractorHolder(); + void - ProcessEvents(vtkObject* theObject, - unsigned long theEvent, - void* theClientData, - void* theCallData); + SetInteractor(SVTK_RenderWindowInteractor* theInteractor); + + SVTK_RenderWindowInteractor* + GetInteractor(); + + vtkRenderWindowInteractor* + GetRenderWindowInteractor(); - SVTK_Viewer* myModel; + virtual void Repaint(); + void Repaint( bool theUpdateTrihedron ); - // Used to process VTK events - vtkSmartPointer myEventCallbackCommand; - // Priority at which events are processed - float myPriority; + void + InvokeEvent(unsigned long theEvent, void* theCallData); + + void + Initialize(); - vtkSmartPointer mySelector; + void + SetRenderWindow(vtkRenderWindow *theRenderWindow); - void initInteractorStyle( SVTK_InteractorStyle* ); + vtkRenderWindow* + GetRenderWindow(); + + vtkRenderWindow* + getRenderWindow() + { + return GetRenderWindow(); + } + + SVTK_Selector* GetSelector(); + void SetSelector(SVTK_Selector* theSelector); + + SVTK_InteractorStyle* GetInteractorStyle(); + void PushInteractorStyle(SVTK_InteractorStyle* theStyle); + void PopInteractorStyle(); + + int SelectionMode() const; + void SetSelectionMode(int theMode); + + public slots: + void onSelectionChanged(); + + public: + signals: + void MouseMove( QMouseEvent* ); + void MouseButtonPressed( QMouseEvent* ); + void MouseButtonReleased( QMouseEvent* ); + void MouseDoubleClicked( QMouseEvent* ); + void ButtonPressed(const QMouseEvent *event); + void ButtonReleased(const QMouseEvent *event); + void WheelMoved( QWheelEvent* ); + void KeyPressed( QKeyEvent* ); + void KeyReleased( QKeyEvent* ); + void contextMenuRequested( QContextMenuEvent *e ); + + void selectionChanged(); + + protected: + SVTK_RenderWindowInteractor* myInteractor; + vtkSmartPointer myRenderWindow; +}; + + +//---------------------------------------------------------------------------- +class SVTK_EXPORT SVTK_View : public SVTK_InteractorHolder +{ + Q_OBJECT; + +public: + SVTK_View(QWidget* theParent, + const char* theName, + SUIT_ResourceMgr* theResourceMgr); + + virtual + ~SVTK_View(); + + /* interactive object management */ + void + highlight(const Handle(SALOME_InteractiveObject)& IObject, + bool highlight, + bool immediatly = true); + void + unHighlightAll(); + + /* Selection Management */ + Handle(SALOME_InteractiveObject) + FindIObject(const char* Entry); + + bool + isInViewer(const Handle(SALOME_InteractiveObject)& IObject); + + bool + isVisible(const Handle(SALOME_InteractiveObject)& IObject); + + void + rename(const Handle(SALOME_InteractiveObject)& IObject, + const QString& newName); + + // Displaymode management + int + GetDisplayMode(); + + void + SetDisplayMode(int); + + // Switch representation wireframe/shading + void + SetDisplayMode(const Handle(SALOME_InteractiveObject)& IObject, + int theMode); + + // Change all actors to wireframe or surface + void + ChangeRepresentationToWireframe(); + + void + ChangeRepresentationToSurface(); + + // Change to wireframe or surface a list of vtkactor + void + ChangeRepresentationToWireframe(vtkActorCollection* theListofActors); + void + ChangeRepresentationToSurface(vtkActorCollection* theListofActors); + + // Transparency + void + SetTransparency(const Handle(SALOME_InteractiveObject)& theIObject, + float trans); + float + GetTransparency(const Handle(SALOME_InteractiveObject)& theIObject); + + // Color + void + SetColor(const Handle(SALOME_InteractiveObject)& theIObject, + const QColor& theColor); + + QColor + GetColor(const Handle(SALOME_InteractiveObject)& theIObject); + + // Erase Display functions + void + EraseAll(); + + void + DisplayAll(); + + void + RemoveAll( const bool immediatly ); + + void + Erase(const Handle(SALOME_InteractiveObject)& IObject, + bool immediatly = true); + void + Remove(const Handle(SALOME_InteractiveObject)& IObject, + bool immediatly = true); + + void + Display(const Handle(SALOME_InteractiveObject)& IObject, + bool immediatly = true); + + void + DisplayOnly(const Handle(SALOME_InteractiveObject)& IObject); + + void + Display(SALOME_Actor* SActor, + bool immediatly = true); + + void + Erase(SALOME_Actor* SActor, + bool immediatly = true); + + void + Remove(SALOME_Actor* SActor, + bool updateViewer = true); + + 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); - typedef vtkSmartPointer PInteractorStyle; - QValueStack myInteractorStyles; + protected: + int myDisplayMode; }; #ifdef WIN32 diff --git a/src/SVTK/SVTK_ViewModel.cxx b/src/SVTK/SVTK_ViewModel.cxx index 1eef62e4c..743345d4c 100644 --- a/src/SVTK/SVTK_ViewModel.cxx +++ b/src/SVTK/SVTK_ViewModel.cxx @@ -13,9 +13,6 @@ #include "SVTK_View.h" #include "SVTK_Prs.h" -#include "SVTK_RenderWindowInteractor.h" -#include "SVTK_RenderWindow.h" - #include "VTKViewer_ViewModel.h" #include "ToolsGUI.h" @@ -74,12 +71,17 @@ void SVTK_Viewer::setBackgroundColor( const QColor& c ) } //========================================================== -SUIT_ViewWindow* SVTK_Viewer::createView( SUIT_Desktop* theDesktop ) +SUIT_ViewWindow* +SVTK_Viewer:: +createView( SUIT_Desktop* theDesktop ) { - SVTK_ViewWindow* vw = new SVTK_ViewWindow( theDesktop, this ); - vw->setBackgroundColor( backgroundColor() ); - vw->SetTrihedronSize( trihedronSize() ); - return vw; + SVTK_ViewWindow* aViewWindow = new SVTK_ViewWindow(theDesktop); + aViewWindow->Initialize(this); + + aViewWindow->setBackgroundColor( backgroundColor() ); + aViewWindow->SetTrihedronSize( trihedronSize() ); + + return aViewWindow; } int SVTK_Viewer::trihedronSize() const @@ -126,81 +128,39 @@ void SVTK_Viewer::setViewManager(SUIT_ViewManager* theViewManager) } //========================================================== -void SVTK_Viewer::contextMenuPopup( QPopupMenu* thePopup ) +void +SVTK_Viewer +::contextMenuPopup( QPopupMenu* thePopup ) { thePopup->insertItem( VTKViewer_Viewer::tr( "MEN_DUMP_VIEW" ), this, SLOT( onDumpView() ) ); thePopup->insertItem( VTKViewer_Viewer::tr( "MEN_CHANGE_BACKGROUD" ), this, SLOT( onChangeBgColor() ) ); thePopup->insertSeparator(); - SVTK_ViewWindow* aView = (SVTK_ViewWindow*)(myViewManager->getActiveView()); - //if ( aView && !aView->getToolBar()->isVisible() ) - // thePopup->insertItem( VTKViewer_Viewer::tr( "MEN_SHOW_TOOLBAR" ), this, SLOT( onShowToolbar() ) ); -} - -//========================================================== -void SVTK_Viewer::onMousePress(SUIT_ViewWindow* vw, QMouseEvent* event) -{ - /* - if(SVTK_ViewWindow* aVW = dynamic_cast(vw)){ - if(SVTK_RenderWindowInteractor* aRWI = aVW->getView()){ - switch(event->button()) { - case LeftButton: - aRWI->LeftButtonPressed(event) ; - break ; - case MidButton: - aRWI->MiddleButtonPressed(event) ; - break ; - case RightButton: - aRWI->RightButtonPressed(event) ; - break; - default: - break ; - } + if(TViewWindow* aView = dynamic_cast(myViewManager->getActiveView())){ + if ( !aView->getView()->getToolBar()->isVisible() ){ + thePopup->insertItem( VTKViewer_Viewer::tr( "MEN_SHOW_TOOLBAR" ), this, SLOT( onShowToolbar() ) ); } } - */ } +//========================================================== +void +SVTK_Viewer +::onMousePress(SUIT_ViewWindow* vw, QMouseEvent* event) +{} + //========================================================== void SVTK_Viewer ::onMouseMove(SUIT_ViewWindow* vw, QMouseEvent* event) -{ - /* - if(SVTK_ViewWindow* aVW = dynamic_cast(vw)){ - if(SVTK_RenderWindowInteractor* aRWI = aVW->getView()){ - aRWI->MouseMove( event ); - } - } - */ -} +{} //========================================================== void SVTK_Viewer ::onMouseRelease(SUIT_ViewWindow* vw, QMouseEvent* event) -{ - /* - if(SVTK_ViewWindow* aVW = dynamic_cast(vw)){ - if(SVTK_RenderWindowInteractor* aRWI = aVW->getView()){ - switch(event->button()) { - case LeftButton: - aRWI->LeftButtonReleased(event) ; - break ; - case MidButton: - aRWI->MiddleButtonReleased(event) ; - break ; - case RightButton: - aRWI->RightButtonReleased(event) ; - break; - default: - break ; - } - } - } - */ -} +{} //========================================================== void @@ -220,24 +180,23 @@ SVTK_Viewer //!! To be done for view windows } -void SVTK_Viewer::onDumpView() +void +SVTK_Viewer +::onDumpView() { - SVTK_ViewWindow* aView = (SVTK_ViewWindow*)(myViewManager->getActiveView()); - if ( aView ) + if(SUIT_ViewWindow* aView = myViewManager->getActiveView()) aView->onDumpView(); } //========================================================== -void SVTK_Viewer::onChangeBgColor() +void +SVTK_Viewer +::onChangeBgColor() { - QPtrVector aViews = myViewManager->getViews(); - for(int i = 0, iEnd = aViews.size(); i < iEnd; i++) - if(SUIT_ViewWindow* aViewWindow = aViews.at(i)) - if(SVTK_ViewWindow* aView = dynamic_cast(aViewWindow)){ - QColor aColor = QColorDialog::getColor( aView->backgroundColor(), aView); - if ( aColor.isValid() ) - aView->setBackgroundColor(aColor); - } + if(SUIT_ViewWindow* aView = myViewManager->getActiveView()){ + QColor aColor = QColorDialog::getColor( backgroundColor(), aView); + setBackgroundColor(aColor); + } } //========================================================== @@ -245,13 +204,12 @@ void SVTK_Viewer ::onShowToolbar() { - /* QPtrVector aViews = myViewManager->getViews(); - for(int i = 0, iEnd = aViews.size(); i < iEnd; i++) - if(SUIT_ViewWindow* aViewWindow = aViews.at(i)) - if(SVTK_ViewWindow* aView = dynamic_cast(aViewWindow)) - aView->getToolBar()->show(); - */ + for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){ + if(TViewWindow* aView = dynamic_cast(aViews.at(i))){ + aView->getView()->getToolBar()->show(); + } + } } //========================================================== @@ -277,14 +235,12 @@ SVTK_Viewer // just display the object QPtrVector aViews = myViewManager->getViews(); for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){ - if(SUIT_ViewWindow* aViewWindow = aViews.at(i)){ - if(SVTK_ViewWindow* aView = dynamic_cast(aViewWindow)){ - if(SVTK_RenderWindowInteractor* aRWI = aView->getView()){ - aRWI->Display(anAct,false); - if(anAct->IsSetCamera()){ - vtkRenderer* aRenderer = aView->getView()->getRenderer(); - anAct->SetCamera( aRenderer->GetActiveCamera() ); - } + if(SVTK_ViewWindow* aViewWindow = dynamic_cast(aViews.at(i))){ + if(SVTK_View* aView = aViewWindow->getView()){ + aView->Display(anAct,false); + if(anAct->IsSetCamera()){ + vtkRenderer* aRenderer = aView->GetRenderer(); + anAct->SetCamera( aRenderer->GetActiveCamera() ); } } } @@ -318,13 +274,12 @@ SVTK_Viewer // just display the object QPtrVector aViews = myViewManager->getViews(); for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){ - if(SUIT_ViewWindow* aViewWindow = aViews.at(i)) - if(SVTK_ViewWindow* aView = dynamic_cast(aViewWindow)) - if(SVTK_RenderWindowInteractor* aRWI = aView->getView()) - if ( forced ) - aRWI->Remove(anAct,false); - else - aRWI->Erase(anAct,forced); + if(SVTK_ViewWindow* aViewWindow = dynamic_cast(aViews.at(i))) + if(SVTK_View* aView = aViewWindow->getView()) + if ( forced ) + aView->Remove(anAct,false); + else + aView->Erase(anAct,forced); } } } @@ -339,9 +294,9 @@ SVTK_Viewer _PTR(Study) aStudy(getStudyDS()); QPtrVector aViews = myViewManager->getViews(); for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){ - if(SUIT_ViewWindow* aViewWindow = aViews.at(i)){ - if(SVTK_ViewWindow* aView = dynamic_cast(aViewWindow)){ - vtkRenderer* aRenderer = aView->getView()->getRenderer(); + if(SVTK_ViewWindow* aViewWindow = dynamic_cast(aViews.at(i))) + if(SVTK_View* aView = aViewWindow->getView()){ + vtkRenderer* aRenderer = aView->GetRenderer(); vtkActorCollection* anActorCollection = aRenderer->GetActors(); anActorCollection->InitTraversal(); while(vtkActor* anActor = anActorCollection->GetNextActor()){ @@ -366,7 +321,6 @@ SVTK_Viewer } } } - } } Repaint(); } @@ -378,16 +332,19 @@ SVTK_Viewer { SVTK_Prs* prs = new SVTK_Prs(); if ( entry ) { - vtkRenderer* rnr = ( (SVTK_ViewWindow*) getViewManager()->getActiveView() )->getView()->getRenderer(); - vtkActorCollection* theActors = rnr->GetActors(); - theActors->InitTraversal(); - vtkActor* ac; - while( ( ac = theActors->GetNextActor() ) ) { - SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac ); - if ( anActor && anActor->hasIO() && !strcmp( anActor->getIO()->getEntry(), entry ) ) { - prs->AddObject( ac ); + if(SVTK_ViewWindow* aViewWindow = dynamic_cast(getViewManager()->getActiveView())) + if(SVTK_View* aView = aViewWindow->getView()){ + vtkRenderer* aRenderer = aView->GetRenderer(); + vtkActorCollection* theActors = aRenderer->GetActors(); + theActors->InitTraversal(); + vtkActor* ac; + while( ( ac = theActors->GetNextActor() ) ) { + SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac ); + if ( anActor && anActor->hasIO() && !strcmp( anActor->getIO()->getEntry(), entry ) ) { + prs->AddObject( ac ); + } + } } - } } return prs; } @@ -414,11 +371,11 @@ SVTK_Viewer { QPtrVector aViews = myViewManager->getViews(); for(int i = 0, iEnd = aViews.size(); i < iEnd; i++) - if(SUIT_ViewWindow* aViewWindow = aViews.at(i)) - if(SVTK_ViewWindow* aView = dynamic_cast(aViewWindow)) - if(SVTK_RenderWindowInteractor* aRWI = aView->getView()) - if(!aRWI->isVisible( io )) - return false; + if(SVTK_ViewWindow* aViewWindow = dynamic_cast(aViews.at(i))) + if(SVTK_View* aView = aViewWindow->getView()) + if(!aView->isVisible( io )) + return false; + return true; } @@ -430,8 +387,7 @@ SVTK_Viewer // if (theUpdateTrihedron) onAdjustTrihedron(); QPtrVector aViews = myViewManager->getViews(); for(int i = 0, iEnd = aViews.size(); i < iEnd; i++) - if(SUIT_ViewWindow* aViewWindow = aViews.at(i)) - if(SVTK_ViewWindow* aView = dynamic_cast(aViewWindow)) - if(SVTK_RenderWindow* aRW = aView->getView()) - aRW->update(); + if(SVTK_ViewWindow* aViewWindow = dynamic_cast(aViews.at(i))) + if(SVTK_View* aView = aViewWindow->getView()) + aView->update(); } diff --git a/src/SVTK/SVTK_ViewWindow.cxx b/src/SVTK/SVTK_ViewWindow.cxx index 4c3ad86a0..948d80f09 100755 --- a/src/SVTK/SVTK_ViewWindow.cxx +++ b/src/SVTK/SVTK_ViewWindow.cxx @@ -1,6 +1,7 @@ #include "SALOME_Actor.h" #include +#include #include #include @@ -40,48 +41,49 @@ //---------------------------------------------------------------------------- SVTK_ViewWindow -::SVTK_ViewWindow( SUIT_Desktop* theDesktop, - SVTK_ViewModelBase* theModel) - : SUIT_ViewWindow( theDesktop ) -{ - QWidget* aCentralWidget = new QWidget( this ); - setCentralWidget( aCentralWidget ); - QBoxLayout* aLayout = new QVBoxLayout( aCentralWidget ); - aLayout->setAutoAdd( true ); - QSplitter* aSplitter = new QSplitter( Qt::Vertical, aCentralWidget ); - - // Create SVTK_View (successor of RenderWindowInteractor). - myView = new SVTK_View( aSplitter, "SVTK_View" ); - myView->Initialize(); - myView->setFocusPolicy( StrongFocus ); - myView->setFocus(); - - /* - SVTK_View* bottomView = new SVTK_View( aSplitter, "BottomView" ); - bottomView->getInteractor()->SetInteractorStyle( myInteractorStyle ); - bottomView->Initialize(); - */ - - connect( myView, SIGNAL(KeyPressed( QKeyEvent* )), - this, SLOT(onKeyPressed( QKeyEvent* )) ); - connect( myView, SIGNAL(KeyReleased( QKeyEvent* )), - this, SLOT(onKeyReleased( QKeyEvent* )) ); - connect( myView, SIGNAL(MouseButtonPressed( QMouseEvent* )), - this, SLOT(onMousePressed( QMouseEvent* )) ); - connect( myView, SIGNAL(MouseButtonReleased( QMouseEvent* )), - this, SLOT(onMouseReleased( QMouseEvent* )) ); - connect( myView, SIGNAL(MouseDoubleClicked( QMouseEvent* )), - this, SLOT(onMouseDoubleClicked( QMouseEvent* )) ); - connect( myView, SIGNAL(MouseMove( QMouseEvent* )), - this, SLOT(onMouseMoving( QMouseEvent* )) ); - connect( myView, SIGNAL(contextMenuRequested( QContextMenuEvent * )), - this, SIGNAL(contextMenuRequested( QContextMenuEvent * )) ); - connect( myView, SIGNAL(selectionChanged()), - theModel,SLOT(onSelectionChanged())); +::SVTK_ViewWindow(SUIT_Desktop* theDesktop): + SUIT_ViewWindow(theDesktop) +{} + +//---------------------------------------------------------------------------- +void +SVTK_ViewWindow +::Initialize(SVTK_ViewModelBase* theModel) +{ + if(SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr()){ + myView = new SVTK_View(this,"SVTK_View",aResourceMgr); + setCentralWidget(myView); + + Initialize(myView,theModel); + } +} + + +void +SVTK_ViewWindow +::Initialize(SVTK_View* theView, + SVTK_ViewModelBase* theModel) +{ + theView->Initialize(); onResetView(); - setFocusProxy( myView ); // send focus events to myView (fixes a bug - // when on module activation myView received focusOutEvent + + connect(theView,SIGNAL(KeyPressed(QKeyEvent*)), + this,SLOT(onKeyPressed(QKeyEvent*)) ); + connect(theView,SIGNAL(KeyReleased(QKeyEvent*)), + this,SLOT(onKeyReleased(QKeyEvent*))); + connect(theView,SIGNAL(MouseButtonPressed(QMouseEvent*)), + this,SLOT(onMousePressed(QMouseEvent*))); + connect(theView,SIGNAL(MouseButtonReleased(QMouseEvent*)), + this,SLOT(onMouseReleased(QMouseEvent*))); + connect(theView,SIGNAL(MouseDoubleClicked(QMouseEvent*)), + this,SLOT(onMouseDoubleClicked(QMouseEvent*))); + connect(theView,SIGNAL(MouseMove(QMouseEvent*)), + this,SLOT(onMouseMoving(QMouseEvent*))); + connect(theView,SIGNAL(contextMenuRequested(QContextMenuEvent*)), + this,SIGNAL(contextMenuRequested(QContextMenuEvent *))); + connect(theView,SIGNAL(selectionChanged()), + theModel,SLOT(onSelectionChanged())); } //---------------------------------------------------------------------------- @@ -90,20 +92,12 @@ SVTK_ViewWindow {} -//---------------------------------------------------------------------------- -SVTK_InteractorStyle* -SVTK_ViewWindow -::getInteractorStyle() -{ - return myView->getInteractorStyle(); -} - //---------------------------------------------------------------------------- vtkRenderer* SVTK_ViewWindow ::getRenderer() { - return myView->getRenderer(); + return myView->GetRenderer(); } //---------------------------------------------------------------------------- @@ -121,20 +115,6 @@ SVTK_ViewWindow return myView; } -SVTK_RenderWindow* -SVTK_ViewWindow -::getRenderWindow() -{ - return myView; -} - -SVTK_RenderWindowInteractor* -SVTK_ViewWindow -::getRWInteractor() -{ - return myView; -} - //---------------------------------------------------------------------------- void SVTK_ViewWindow @@ -220,7 +200,7 @@ Selection_Mode SVTK_ViewWindow ::SelectionMode() const { - return myView->SelectionMode(); + return Selection_Mode(myView->SelectionMode()); } //---------------------------------------------------------------- @@ -453,22 +433,7 @@ SVTK_ViewWindow const double& theBlue, const int& theWidth) { - vtkActorCollection* anActors = myView->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 ); - } - } + myView->SetSelectionProp(theRed,theGreen,theBlue,theWidth); } //---------------------------------------------------------------------------- @@ -477,33 +442,23 @@ SVTK_ViewWindow ::SetSelectionTolerance(const double& theTolNodes, const double& theTolItems) { - vtkActorCollection* anActors = myView->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 ); - } - } + myView->SetSelectionTolerance(theTolNodes,theTolItems); } //---------------------------------------------------------------------------- int convertAction( const int accelAction ) { switch ( accelAction ) { - case SUIT_Accel::PanLeft : return PanLeftEvent; - case SUIT_Accel::PanRight : return PanRightEvent; - case SUIT_Accel::PanUp : return PanUpEvent; - case SUIT_Accel::PanDown : return PanDownEvent; - case SUIT_Accel::ZoomIn : return ZoomInEvent; - case SUIT_Accel::ZoomOut : return ZoomOutEvent; - case SUIT_Accel::RotateLeft : return RotateLeftEvent; - case SUIT_Accel::RotateRight : return RotateRightEvent; - case SUIT_Accel::RotateUp : return RotateUpEvent; - case SUIT_Accel::RotateDown : return RotateDownEvent; + case SUIT_Accel::PanLeft : return SVTK::PanLeftEvent; + case SUIT_Accel::PanRight : return SVTK::PanRightEvent; + case SUIT_Accel::PanUp : return SVTK::PanUpEvent; + case SUIT_Accel::PanDown : return SVTK::PanDownEvent; + case SUIT_Accel::ZoomIn : return SVTK::ZoomInEvent; + case SUIT_Accel::ZoomOut : return SVTK::ZoomOutEvent; + case SUIT_Accel::RotateLeft : return SVTK::RotateLeftEvent; + case SUIT_Accel::RotateRight : return SVTK::RotateRightEvent; + case SUIT_Accel::RotateUp : return SVTK::RotateUpEvent; + case SUIT_Accel::RotateDown : return SVTK::RotateDownEvent; } return accelAction; } @@ -517,6 +472,6 @@ SVTK_ViewWindow onFitAll(); else { int svtkEvent = convertAction( accelAction ); - myView->FireEvent( svtkEvent, 0 ); + myView->InvokeEvent( svtkEvent, 0 ); } } diff --git a/src/SVTK/SVTK_ViewWindow.h b/src/SVTK/SVTK_ViewWindow.h index 05afbb3a8..2a5072f3c 100755 --- a/src/SVTK/SVTK_ViewWindow.h +++ b/src/SVTK/SVTK_ViewWindow.h @@ -29,27 +29,36 @@ class SVTK_RenderWindowInteractor; class SVTK_EXPORT SVTK_ViewWindow : public SUIT_ViewWindow { - Q_OBJECT + Q_OBJECT; -public: - SVTK_ViewWindow( SUIT_Desktop*, SVTK_ViewModelBase* ); - virtual ~SVTK_ViewWindow(); - - void setBackgroundColor( const QColor& ); - QColor backgroundColor() const; + public: + SVTK_ViewWindow(SUIT_Desktop* theDesktop); - vtkRenderer* getRenderer(); - SVTK_Selector* GetSelector(); + virtual + ~SVTK_ViewWindow(); - SVTK_View* getView(); - SVTK_RenderWindow* getRenderWindow(); - SVTK_RenderWindowInteractor* getRWInteractor(); + virtual + void + Initialize(SVTK_ViewModelBase* theModel); + + SVTK_View* + getView(); + + SVTK_View* + getRenderWindow(); - SVTK_InteractorStyle* getInteractorStyle(); + vtkRenderer* + getRenderer(); + SVTK_Selector* + GetSelector(); + Selection_Mode SelectionMode() const; void SetSelectionMode(Selection_Mode theMode); + void setBackgroundColor( const QColor& ); + QColor backgroundColor() const; + bool isTrihedronDisplayed(); bool isCubeAxesDisplayed(); @@ -126,10 +135,16 @@ protected slots: void onMouseMoving(QMouseEvent* event); protected: + virtual + void + Initialize(SVTK_View* theView, + SVTK_ViewModelBase* theModel); + QImage dumpView(); - virtual void action( const int ); + virtual void action( const int ); SVTK_View* myView; + SVTK_ViewModelBase* myModel; }; #ifdef WIN32