From: apo Date: Thu, 8 Sep 2005 14:33:59 +0000 (+0000) Subject: To improve SVTK package class hierarchy X-Git-Tag: BR-D5-38-2003_D2005-12-09~4 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=f5cbb87cf9692176b633e98e9748353178a518a2;p=modules%2Fgui.git To improve SVTK package class hierarchy --- diff --git a/src/SALOME_PY/SalomePy.cxx b/src/SALOME_PY/SalomePy.cxx index 6fa4c4516..69ef49106 100755 --- a/src/SALOME_PY/SalomePy.cxx +++ b/src/SALOME_PY/SalomePy.cxx @@ -130,7 +130,7 @@ public: virtual void Execute() { if( SVTK_ViewWindow* aVTKViewWindow = GetVTKViewWindow() ) { PyObject* aPyClass = GetPyClass("vtkRenderWindow"); - vtkRenderWindow* aVTKObject = aVTKViewWindow->getView()->GetRenderWindow(); + vtkRenderWindow* aVTKObject = aVTKViewWindow->getRenderWindow(); myResult = PyVTKObject_New(aPyClass,aVTKObject); } } @@ -151,7 +151,7 @@ public: virtual void Execute() { if( SVTK_ViewWindow* aVTKViewWindow = GetVTKViewWindow() ) { PyObject* aPyClass = GetPyClass("vtkRenderWindowInteractor"); - vtkRenderWindowInteractor* aVTKObject = aVTKViewWindow->getView()->GetRenderWindowInteractor(); + vtkRenderWindowInteractor* aVTKObject = aVTKViewWindow->getInteractor(); myResult = PyVTKObject_New(aPyClass,aVTKObject); } } diff --git a/src/SVTK/SVTK_View.cxx b/src/SVTK/SVTK_View.cxx index 6c162f8a0..1e2ddf707 100644 --- a/src/SVTK/SVTK_View.cxx +++ b/src/SVTK/SVTK_View.cxx @@ -39,45 +39,190 @@ #include "VTKViewer_Algorithm.h" #include "SVTK_Functor.h" + //---------------------------------------------------------------------------- -SVTK_RendererHolder -::SVTK_RendererHolder(QWidget* theParent, - const char* theName): - QMainWindow(theParent,theName,0), - myRenderer(SVTK_Renderer::New()) +SVTK_MainWindow +::SVTK_MainWindow(QWidget* theParent, + const char* theName, + SUIT_ResourceMgr* theResourceMgr) : + QMainWindow(theParent,theName,0) { - myRenderer->Delete(); + myToolBar = new QToolBar(this); + myToolBar->setCloseMode(QDockWindow::Undocked); + myToolBar->setLabel(tr("LBL_TOOLBAR_LABEL")); + + createActions(theResourceMgr); + createToolBar(); } -SVTK_RendererHolder -::~SVTK_RendererHolder() +//---------------------------------------------------------------------------- +SVTK_MainWindow +::~SVTK_MainWindow() {} + //---------------------------------------------------------------------------- -vtkRenderer* -SVTK_RendererHolder -::GetRenderer() +void +SVTK_MainWindow +::SetInteractor(SVTK_RenderWindowInteractor* theInteractor) +{ + myInteractor = theInteractor; + SetEventDispatcher(myInteractor->GetDevice()); + + setCentralWidget(myInteractor); + + myInteractor->setFocusPolicy(StrongFocus); + myInteractor->setFocus(); + setFocusProxy(myInteractor); +} + +SVTK_RenderWindowInteractor* +SVTK_MainWindow +::GetInteractor() +{ + return myInteractor; +} + +vtkRenderWindowInteractor* +SVTK_MainWindow +::getInteractor() +{ + return GetInteractor()->GetDevice(); +} + +//---------------------------------------------------------------------------- +void +SVTK_MainWindow +::Repaint() +{ + Repaint( true ); +} + +//---------------------------------------------------------------------------- +void +SVTK_MainWindow +::Repaint(bool theUpdateTrihedron) +{ + if(theUpdateTrihedron) + GetRenderer()->onAdjustTrihedron(); + + GetInteractor()->update(); +} + +//---------------------------------------------------------------------------- +void +SVTK_MainWindow +::InvokeEvent(unsigned long theEvent, void* theCallData) +{ + myInteractor->InvokeEvent(theEvent,theCallData); +} + +//---------------------------------------------------------------------------- +SVTK_InteractorStyle* +SVTK_MainWindow +::GetInteractorStyle() +{ + return myInteractor->GetInteractorStyle(); +} + +void +SVTK_MainWindow +::PushInteractorStyle(SVTK_InteractorStyle* theStyle) +{ + myInteractor->PushInteractorStyle(theStyle); +} + +void +SVTK_MainWindow +::PopInteractorStyle() +{ + myInteractor->PopInteractorStyle(); +} + +//---------------------------------------------------------------------------- +SVTK_Selector* +SVTK_MainWindow +::GetSelector() +{ + return myInteractor->GetSelector(); +} + +void +SVTK_MainWindow +::SetSelector(SVTK_Selector* theSelector) +{ + myInteractor->SetSelector(theSelector); +} + +Selection_Mode +SVTK_MainWindow +::SelectionMode() +{ + return GetSelector()->SelectionMode(); +} + +void +SVTK_MainWindow +::SetSelectionMode(Selection_Mode theMode) { - return myRenderer.GetPointer(); + GetSelector()->SetSelectionMode(theMode); } + //---------------------------------------------------------------------------- void -SVTK_RendererHolder -::setBackgroundColor(const QColor& theColor) +SVTK_MainWindow +::SetRenderWindow(SVTK_RenderWindow *theRenderWindow) +{ + myRenderWindow = theRenderWindow; +} + +SVTK_RenderWindow* +SVTK_MainWindow +::GetRenderWindow() +{ + return myRenderWindow.GetPointer(); +} + +vtkRenderWindow* +SVTK_MainWindow +::getRenderWindow() { - myRenderer->SetBackground(theColor.red()/255.0, - theColor.green()/255.0, - theColor.blue()/255.0); + return myRenderWindow.GetPointer(); } + //---------------------------------------------------------------------------- +SVTK_Renderer* +SVTK_MainWindow +::GetRenderer() +{ + return GetRenderWindow()->GetRenderer(); +} + +vtkRenderer* +SVTK_MainWindow +::getRenderer() +{ + return GetRenderWindow()->GetRenderer(); +} + +//---------------------------------------------------------------------------- +void +SVTK_MainWindow +::SetBackgroundColor(const QColor& theColor) +{ + GetRenderer()->SetBackground(theColor.red()/255.0, + theColor.green()/255.0, + theColor.blue()/255.0); +} + QColor -SVTK_RendererHolder -::backgroundColor() const +SVTK_MainWindow +::BackgroundColor() { float aBackgroundColor[3]; - myRenderer->GetBackground(aBackgroundColor); + GetRenderer()->GetBackground(aBackgroundColor); return QColor(int(aBackgroundColor[0]*255), int(aBackgroundColor[1]*255), int(aBackgroundColor[2]*255)); @@ -85,37 +230,39 @@ SVTK_RendererHolder //---------------------------------------------------------------------------- void -SVTK_RendererHolder +SVTK_MainWindow ::GetScale( double theScale[3] ) { - myRenderer->GetScale( theScale ); + GetRenderer()->GetScale( theScale ); } void -SVTK_RendererHolder +SVTK_MainWindow ::SetScale( double theScale[3] ) { - myRenderer->SetScale( theScale ); + GetRenderer()->SetScale( theScale ); Repaint(); } //---------------------------------------------------------------------------- void -SVTK_RendererHolder -::AddActor(VTKViewer_Actor* theActor, bool theIsUpdate) +SVTK_MainWindow +::AddActor(VTKViewer_Actor* theActor, + bool theIsUpdate) { - myRenderer->AddActor(theActor); + GetRenderer()->AddActor(theActor); if(theIsUpdate) Repaint(); } //---------------------------------------------------------------------------- void -SVTK_RendererHolder -::RemoveActor(VTKViewer_Actor* theActor, bool theIsUpdate) +SVTK_MainWindow +::RemoveActor(VTKViewer_Actor* theActor, + bool theIsUpdate) { - myRenderer->RemoveActor(theActor); + GetRenderer()->RemoveActor(theActor); if(theIsUpdate) Repaint(); } @@ -123,18 +270,18 @@ SVTK_RendererHolder //---------------------------------------------------------------------------- int -SVTK_RendererHolder -::GetTrihedronSize() const +SVTK_MainWindow +::GetTrihedronSize() { - return myRenderer->GetTrihedronSize(); + return GetRenderer()->GetTrihedronSize(); } //---------------------------------------------------------------------------- void -SVTK_RendererHolder +SVTK_MainWindow ::SetTrihedronSize( const int theSize ) { - myRenderer->SetTrihedronSize(theSize); + GetRenderer()->SetTrihedronSize(theSize); Repaint(); } @@ -144,69 +291,57 @@ SVTK_RendererHolder * trihedron and cube axes, even if trihedron and cube axes is invisible. */ void -SVTK_RendererHolder +SVTK_MainWindow ::AdjustTrihedrons(const bool theIsForced) { - myRenderer->AdjustTrihedrons(theIsForced); + GetRenderer()->AdjustTrihedrons(theIsForced); Repaint(); } //---------------------------------------------------------------------------- bool -SVTK_RendererHolder -::isTrihedronDisplayed() +SVTK_MainWindow +::IsTrihedronDisplayed() { - return myRenderer->isTrihedronDisplayed(); + return GetRenderer()->isTrihedronDisplayed(); } //---------------------------------------------------------------------------- bool -SVTK_RendererHolder -::isCubeAxesDisplayed() +SVTK_MainWindow +::IsCubeAxesDisplayed() { - return myRenderer->isCubeAxesDisplayed(); + return GetRenderer()->isCubeAxesDisplayed(); } //---------------------------------------------------------------------------- VTKViewer_Trihedron* -SVTK_RendererHolder +SVTK_MainWindow ::GetTrihedron() { - return myRenderer->GetTrihedron(); + return GetRenderer()->GetTrihedron(); } //---------------------------------------------------------------------------- SVTK_CubeAxesActor2D* -SVTK_RendererHolder +SVTK_MainWindow ::GetCubeAxes() { - return myRenderer->GetCubeAxes(); + return GetRenderer()->GetCubeAxes(); } //---------------------------------------------------------------------------- -SVTK_ActionHolder -::SVTK_ActionHolder(QWidget* theParent, - const char* theName, - SUIT_ResourceMgr* theResourceMgr) : - SVTK_RendererHolder(theParent,theName) +QToolBar* +SVTK_MainWindow +::getToolBar() { - myToolBar = new QToolBar(this); - myToolBar->setCloseMode(QDockWindow::Undocked); - myToolBar->setLabel(tr("LBL_TOOLBAR_LABEL")); - - createActions(theResourceMgr); - createToolBar(); + return myToolBar; } -//---------------------------------------------------------------------------- -SVTK_ActionHolder -::~SVTK_ActionHolder() -{} - //---------------------------------------------------------------------------- void -SVTK_ActionHolder +SVTK_MainWindow ::SetEventDispatcher(vtkObject* theDispatcher) { myEventDispatcher = theDispatcher; @@ -214,7 +349,7 @@ SVTK_ActionHolder //---------------------------------------------------------------------------- void -SVTK_ActionHolder +SVTK_MainWindow ::createActions(SUIT_ResourceMgr* theResourceMgr) { if(!myActionsMap.isEmpty()) @@ -340,7 +475,7 @@ SVTK_ActionHolder //---------------------------------------------------------------------------- void -SVTK_ActionHolder +SVTK_MainWindow ::createToolBar() { myActionsMap[DumpId]->addTo(myToolBar); @@ -368,17 +503,9 @@ SVTK_ActionHolder myActionsMap[ResetId]->addTo(myToolBar); } -//---------------------------------------------------------------------------- -QToolBar* -SVTK_ActionHolder -::getToolBar() -{ - return myToolBar; -} - //---------------------------------------------------------------------------- void -SVTK_ActionHolder +SVTK_MainWindow ::activateZoom() { myEventDispatcher->InvokeEvent(SVTK::StartZoom,0); @@ -386,7 +513,7 @@ SVTK_ActionHolder //---------------------------------------------------------------------------- void -SVTK_ActionHolder +SVTK_MainWindow ::activatePanning() { myEventDispatcher->InvokeEvent(SVTK::StartPan,0); @@ -394,7 +521,7 @@ SVTK_ActionHolder //---------------------------------------------------------------------------- void -SVTK_ActionHolder +SVTK_MainWindow ::activateRotation() { myEventDispatcher->InvokeEvent(SVTK::StartRotate,0); @@ -402,7 +529,7 @@ SVTK_ActionHolder //---------------------------------------------------------------------------- void -SVTK_ActionHolder +SVTK_MainWindow ::activateGlobalPanning() { myEventDispatcher->InvokeEvent(SVTK::StartGlobalPan,0); @@ -410,7 +537,7 @@ SVTK_ActionHolder //---------------------------------------------------------------------------- void -SVTK_ActionHolder +SVTK_MainWindow ::activateWindowFit() { myEventDispatcher->InvokeEvent(SVTK::StartFitArea,0); @@ -418,113 +545,113 @@ SVTK_ActionHolder //---------------------------------------------------------------------------- void -SVTK_ActionHolder +SVTK_MainWindow ::onFrontView() { - myRenderer->onFrontView(); + GetRenderer()->onFrontView(); } //---------------------------------------------------------------------------- void -SVTK_ActionHolder +SVTK_MainWindow ::onBackView() { - myRenderer->onBackView(); + GetRenderer()->onBackView(); } //---------------------------------------------------------------------------- void -SVTK_ActionHolder +SVTK_MainWindow ::onTopView() { - myRenderer->onTopView(); + GetRenderer()->onTopView(); } //---------------------------------------------------------------------------- void -SVTK_ActionHolder +SVTK_MainWindow ::onBottomView() { - myRenderer->onBottomView(); + GetRenderer()->onBottomView(); } //---------------------------------------------------------------------------- void -SVTK_ActionHolder +SVTK_MainWindow ::onLeftView() { - myRenderer->onLeftView(); + GetRenderer()->onLeftView(); } //---------------------------------------------------------------------------- void -SVTK_ActionHolder +SVTK_MainWindow ::onRightView() { - myRenderer->onRightView(); + GetRenderer()->onRightView(); } //---------------------------------------------------------------------------- void -SVTK_ActionHolder +SVTK_MainWindow ::onResetView() { - myRenderer->onResetView(); + GetRenderer()->onResetView(); Repaint(); } //---------------------------------------------------------------------------- void -SVTK_ActionHolder +SVTK_MainWindow ::onFitAll() { - myRenderer->onFitAll(); + GetRenderer()->onFitAll(); Repaint(); } //---------------------------------------------------------------------------- void -SVTK_ActionHolder +SVTK_MainWindow ::onViewTrihedron() { - myRenderer->onViewTrihedron(); + GetRenderer()->onViewTrihedron(); Repaint(); } //---------------------------------------------------------------------------- void -SVTK_ActionHolder +SVTK_MainWindow ::onViewCubeAxes() { - myRenderer->onViewCubeAxes(); + GetRenderer()->onViewCubeAxes(); Repaint(); } //---------------------------------------------------------------------------- void -SVTK_ActionHolder +SVTK_MainWindow ::onAdjustTrihedron() { - myRenderer->onAdjustTrihedron(); + GetRenderer()->onAdjustTrihedron(); } //---------------------------------------------------------------------------- void -SVTK_ActionHolder +SVTK_MainWindow ::onAdjustCubeAxes() { - myRenderer->onAdjustCubeAxes(); + GetRenderer()->onAdjustCubeAxes(); } //---------------------------------------------------------------------------- void -SVTK_ActionHolder +SVTK_MainWindow ::onDumpView() {} //---------------------------------------------------------------------------- QImage -SVTK_ActionHolder +SVTK_MainWindow ::dumpView() { QPixmap px = QPixmap::grabWindow( winId() ); @@ -533,193 +660,92 @@ SVTK_ActionHolder //---------------------------------------------------------------------------- -SVTK_InteractorHolder -::SVTK_InteractorHolder(QWidget* theParent, - const char* theName, - SUIT_ResourceMgr* theResourceMgr) : - SVTK_ActionHolder(theParent,theName,theResourceMgr), - myRenderWindow(SVTK_RenderWindow::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) +SVTK_SignalHandler +::SVTK_SignalHandler(SVTK_MainWindow* theMainWindow): + QObject(theMainWindow), + myMainWindow(theMainWindow) { - myInteractor = theInteractor; + SVTK_RenderWindow* aRenderWindow = SVTK_RenderWindow::New(); + theMainWindow->SetRenderWindow(aRenderWindow); + aRenderWindow->Delete(); - if(myInteractor){ - 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); - - myInteractor->SetRenderWindow(myRenderWindow.GetPointer()); - } -} + aRenderWindow->SetRenderer(SVTK_Renderer::New()); -//---------------------------------------------------------------------------- -SVTK_RenderWindowInteractor* -SVTK_InteractorHolder -::GetInteractor() -{ - return myInteractor; -} + SVTK_RenderWindowInteractor* anInteractor = + new SVTK_RenderWindowInteractor(theMainWindow,"SVTK_RenderWindowInteractor"); + anInteractor->SetRenderWindow(aRenderWindow); -//---------------------------------------------------------------------------- -vtkRenderWindowInteractor* -SVTK_InteractorHolder -::GetRenderWindowInteractor() -{ - return myInteractor->GetDevice(); -} + theMainWindow->SetInteractor(anInteractor); -//---------------------------------------------------------------------------- -void -SVTK_InteractorHolder -::Repaint( bool theUpdateTrihedron ) -{ - if(theUpdateTrihedron) - myRenderer->onAdjustTrihedron(); - - myInteractor->update(); -} - -//---------------------------------------------------------------------------- -void -SVTK_InteractorHolder -::Repaint() -{ - Repaint( true ); -} + anInteractor->PushInteractorStyle(SVTK_InteractorStyle::New()); -//---------------------------------------------------------------------------- -void -SVTK_InteractorHolder -::InvokeEvent(unsigned long theEvent, void* theCallData) -{ - myInteractor->InvokeEvent(theEvent,theCallData); + connect(anInteractor,SIGNAL(KeyPressed(QKeyEvent*)), + this,SIGNAL(KeyPressed(QKeyEvent*)) ); + connect(anInteractor,SIGNAL(KeyReleased(QKeyEvent*)), + this,SIGNAL(KeyReleased(QKeyEvent*))); + connect(anInteractor,SIGNAL(MouseButtonPressed(QMouseEvent*)), + this,SIGNAL(MouseButtonPressed(QMouseEvent*))); + connect(anInteractor,SIGNAL(MouseButtonReleased(QMouseEvent*)), + this,SIGNAL(MouseButtonReleased(QMouseEvent*))); + connect(anInteractor,SIGNAL(MouseDoubleClicked(QMouseEvent*)), + this,SIGNAL(MouseDoubleClicked(QMouseEvent*))); + connect(anInteractor,SIGNAL(MouseMove(QMouseEvent*)), + this,SIGNAL(MouseMove(QMouseEvent*))); + connect(anInteractor,SIGNAL(contextMenuRequested(QContextMenuEvent*)), + this,SIGNAL(contextMenuRequested(QContextMenuEvent*))); + connect(anInteractor,SIGNAL(selectionChanged()), + this,SIGNAL(selectionChanged())); } -//---------------------------------------------------------------------------- -void -SVTK_InteractorHolder -::SetRenderWindow(vtkRenderWindow *theRenderWindow) -{ - myRenderWindow = theRenderWindow; - - if(myInteractor) - myInteractor->SetRenderWindow(myRenderWindow.GetPointer()); -} +SVTK_SignalHandler +::~SVTK_SignalHandler() +{} -//---------------------------------------------------------------------------- -vtkRenderWindow* -SVTK_InteractorHolder -::GetRenderWindow() +SVTK_MainWindow* +SVTK_SignalHandler +::GetMainWindow() { - return myRenderWindow.GetPointer(); + return myMainWindow; } -//---------------------------------------------------------------------------- -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) +SVTK_SignalHandler +::Repaint() { - myInteractor->PushInteractorStyle(theStyle); + myMainWindow->Repaint(); } -//---------------------------------------------------------------------------- void -SVTK_InteractorHolder -::PopInteractorStyle() +SVTK_SignalHandler +::Repaint(bool theUpdateTrihedron) { - myInteractor->PopInteractorStyle(); + myMainWindow->Repaint(theUpdateTrihedron); } - //---------------------------------------------------------------------------- -SVTK_InteractorStyle* -SVTK_InteractorHolder -::GetInteractorStyle() -{ - return myInteractor->GetInteractorStyle(); -} - - -//---------------------------------------------------------------- -void -SVTK_InteractorHolder -::SetSelectionMode(int theMode) +SVTK_Renderer* +SVTK_SignalHandler +::GetRenderer() { - myInteractor->SetSelectionMode(theMode); + return myMainWindow->GetRenderer(); } - -//---------------------------------------------------------------- -int -SVTK_InteractorHolder -::SelectionMode() const +vtkRenderer* +SVTK_SignalHandler +::getRenderer() { - return myInteractor->SelectionMode(); + return myMainWindow->GetRenderer(); } - //---------------------------------------------------------------- struct THighlightAction { bool myIsHighlight; - int mySelectionMode; - THighlightAction( bool theIsHighlight, int theSelectionMode = ActorSelection ): + Selection_Mode mySelectionMode; + THighlightAction( bool theIsHighlight, + Selection_Mode theSelectionMode = ActorSelection ): myIsHighlight( theIsHighlight ), mySelectionMode( theSelectionMode ) {} @@ -733,36 +759,33 @@ struct THighlightAction } }; -//---------------------------------------------------------------- void -SVTK_InteractorHolder +SVTK_SignalHandler ::onSelectionChanged() { - vtkActorCollection* anActors = GetRenderer()->GetActors(); + vtkActorCollection* anActors = myMainWindow->GetRenderer()->GetActors(); using namespace VTK; ForEach(anActors, THighlightAction( false )); - - const SALOME_ListIO& aListIO = GetSelector()->StoredIObjects(); + SVTK_Selector* aSelector = myMainWindow->GetSelector(); + const SALOME_ListIO& aListIO = aSelector->StoredIObjects(); SALOME_ListIteratorOfListIO anIter(aListIO); - int aSelectionMode = SelectionMode(); + Selection_Mode aSelectionMode = aSelector->SelectionMode(); for(; anIter.More(); anIter.Next()){ ForEachIf(anActors, TIsSameIObject(anIter.Value()), THighlightAction(true,aSelectionMode)); } - Repaint(); + myMainWindow->Repaint(); } //---------------------------------------------------------------------------- SVTK_View -::SVTK_View(QWidget* theParent, - const char* theName, - SUIT_ResourceMgr* theResourceMgr) : - SVTK_InteractorHolder(theParent,theName,theResourceMgr) +::SVTK_View(SVTK_MainWindow* theMainWindow) : + SVTK_SignalHandler(theMainWindow) {} //---------------------------------------------------------------------------- @@ -790,9 +813,10 @@ SVTK_View bool theIsUpdate ) { using namespace VTK; + SVTK_Selector* aSelector = myMainWindow->GetSelector(); ForEachIf(GetRenderer()->GetActors(), TIsSameIObject( theIO ), - THighlightAction( theIsHighlight, GetSelector()->SelectionMode() )); + THighlightAction( theIsHighlight, aSelector->SelectionMode() )); Repaint(); } diff --git a/src/SVTK/SVTK_View.h b/src/SVTK/SVTK_View.h index f5ef4d6c3..c00d97160 100644 --- a/src/SVTK/SVTK_View.h +++ b/src/SVTK/SVTK_View.h @@ -6,7 +6,7 @@ #endif #include "SVTK.h" - +#include "SVTK_Selection.h" #include "SALOME_InteractiveObject.hxx" #include @@ -42,70 +42,126 @@ class SVTK_RenderWindowInteractor; class SALOME_Actor; //---------------------------------------------------------------------------- -class SVTK_EXPORT SVTK_RendererHolder: public QMainWindow +class SVTK_EXPORT SVTK_MainWindow: public QMainWindow { Q_OBJECT; public: - SVTK_RendererHolder(QWidget* theParent, - const char* theName); + SVTK_MainWindow(QWidget* theParent, + const char* theName, + SUIT_ResourceMgr* theResourceMgr); virtual - ~SVTK_RendererHolder(); + ~SVTK_MainWindow(); - vtkRenderer* GetRenderer(); + //---------------------------------------------------------------------------- + void + SetInteractor(SVTK_RenderWindowInteractor* theInteractor); - virtual void Repaint() = 0; + SVTK_RenderWindowInteractor* + GetInteractor(); - void setBackgroundColor( const QColor& ); - QColor backgroundColor() const; + vtkRenderWindowInteractor* + getInteractor(); - //apply existing transformation on adding SALOME_Actor - void SetScale( double theScale[3] ); - void GetScale( double theScale[3] ); + void + Repaint(); - void AddActor(VTKViewer_Actor* theActor, bool theIsUpdate = false); - void RemoveActor(VTKViewer_Actor* theActor, bool theIsUpdate = false); + void + Repaint(bool theUpdateTrihedron); - int GetTrihedronSize() const; - void SetTrihedronSize( const int ); - void AdjustTrihedrons( const bool forced ); + void + InvokeEvent(unsigned long theEvent, void* theCallData); - bool isTrihedronDisplayed(); - bool isCubeAxesDisplayed(); + //---------------------------------------------------------------------------- + SVTK_InteractorStyle* + GetInteractorStyle(); - VTKViewer_Trihedron* GetTrihedron(); - SVTK_CubeAxesActor2D* GetCubeAxes(); + void + PushInteractorStyle(SVTK_InteractorStyle* theStyle); - protected: - vtkSmartPointer myRenderer; -}; + void + PopInteractorStyle(); + //---------------------------------------------------------------------------- + SVTK_Selector* + GetSelector(); -//---------------------------------------------------------------------------- -class SVTK_EXPORT SVTK_ActionHolder: public SVTK_RendererHolder -{ - Q_OBJECT; + void + SetSelector(SVTK_Selector* theSelector); -public: - SVTK_ActionHolder(QWidget* theParent, - const char* theName, - SUIT_ResourceMgr* theResourceMgr); + Selection_Mode + SelectionMode(); - virtual - ~SVTK_ActionHolder(); + void + SetSelectionMode(Selection_Mode theMode); + //---------------------------------------------------------------------------- void - SetEventDispatcher(vtkObject* theDispatcher); + SetRenderWindow(SVTK_RenderWindow *theRenderWindow); + + SVTK_RenderWindow* + GetRenderWindow(); + + vtkRenderWindow* + getRenderWindow(); + + //---------------------------------------------------------------------------- + SVTK_Renderer* + GetRenderer(); + + vtkRenderer* + getRenderer(); + void + SetBackgroundColor(const QColor& theColor); + + QColor + BackgroundColor(); + + 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(); + + void + SetTrihedronSize(const int theSize); + + void + AdjustTrihedrons(const bool theIsForced); + + bool + IsTrihedronDisplayed(); + + bool + IsCubeAxesDisplayed(); + + VTKViewer_Trihedron* + GetTrihedron(); + + SVTK_CubeAxesActor2D* + GetCubeAxes(); + + //---------------------------------------------------------------------------- QToolBar* getToolBar(); public slots: - virtual void activateZoom(); - virtual void activateWindowFit(); - virtual void activateRotation(); - virtual void activatePanning(); - virtual void activateGlobalPanning(); + void activateZoom(); + void activateWindowFit(); + void activateRotation(); + void activatePanning(); + void activateGlobalPanning(); void onFrontView(); void onBackView(); @@ -135,6 +191,9 @@ public: void createToolBar(); + void + SetEventDispatcher(vtkObject* theDispatcher); + enum { DumpId, FitAllId, FitRectId, ZoomId, PanId, GlobalPanId, RotationId, FrontId, BackId, TopId, BottomId, LeftId, RightId, ResetId, ViewTrihedronId }; typedef QMap TActionsMap; @@ -142,59 +201,41 @@ public: vtkSmartPointer myEventDispatcher; TActionsMap myActionsMap; QToolBar* myToolBar; + + SVTK_RenderWindowInteractor* myInteractor; + vtkSmartPointer myRenderWindow; }; //---------------------------------------------------------------------------- -class SVTK_EXPORT SVTK_InteractorHolder : public SVTK_ActionHolder +class SVTK_EXPORT SVTK_SignalHandler : public QObject { Q_OBJECT; public: - SVTK_InteractorHolder(QWidget* theParent, - const char* theName, - SUIT_ResourceMgr* theResourceMgr); + SVTK_SignalHandler(SVTK_MainWindow* theMainWindow); virtual - ~SVTK_InteractorHolder(); - - void - SetInteractor(SVTK_RenderWindowInteractor* theInteractor); + ~SVTK_SignalHandler(); - SVTK_RenderWindowInteractor* - GetInteractor(); - - vtkRenderWindowInteractor* - GetRenderWindowInteractor(); - - virtual void Repaint(); - void Repaint( bool theUpdateTrihedron ); + SVTK_MainWindow* + GetMainWindow(); + //---------------------------------------------------------------------------- void - InvokeEvent(unsigned long theEvent, void* theCallData); + Repaint(); void - SetRenderWindow(vtkRenderWindow *theRenderWindow); - - vtkRenderWindow* - GetRenderWindow(); - - vtkRenderWindow* - getRenderWindow() - { - return GetRenderWindow(); - } - - SVTK_Selector* GetSelector(); - void SetSelector(SVTK_Selector* theSelector); + Repaint(bool theUpdateTrihedron); - SVTK_InteractorStyle* GetInteractorStyle(); - void PushInteractorStyle(SVTK_InteractorStyle* theStyle); - void PopInteractorStyle(); + //---------------------------------------------------------------------------- + SVTK_Renderer* + GetRenderer(); - int SelectionMode() const; - void SetSelectionMode(int theMode); + vtkRenderer* + getRenderer(); + //---------------------------------------------------------------------------- public slots: void onSelectionChanged(); @@ -210,24 +251,20 @@ public: void KeyPressed( QKeyEvent* ); void KeyReleased( QKeyEvent* ); void contextMenuRequested( QContextMenuEvent *e ); - void selectionChanged(); - protected: - SVTK_RenderWindowInteractor* myInteractor; - vtkSmartPointer myRenderWindow; + protected: + SVTK_MainWindow* myMainWindow; }; //---------------------------------------------------------------------------- -class SVTK_EXPORT SVTK_View : public SVTK_InteractorHolder +class SVTK_EXPORT SVTK_View : public SVTK_SignalHandler { Q_OBJECT; public: - SVTK_View(QWidget* theParent, - const char* theName, - SUIT_ResourceMgr* theResourceMgr); + SVTK_View(SVTK_MainWindow* theMainWindow); virtual ~SVTK_View(); diff --git a/src/SVTK/SVTK_ViewModel.cxx b/src/SVTK/SVTK_ViewModel.cxx index 743345d4c..7fb8feb09 100644 --- a/src/SVTK/SVTK_ViewModel.cxx +++ b/src/SVTK/SVTK_ViewModel.cxx @@ -138,7 +138,7 @@ SVTK_Viewer thePopup->insertSeparator(); if(TViewWindow* aView = dynamic_cast(myViewManager->getActiveView())){ - if ( !aView->getView()->getToolBar()->isVisible() ){ + if ( !aView->getView()->GetMainWindow()->getToolBar()->isVisible() ){ thePopup->insertItem( VTKViewer_Viewer::tr( "MEN_SHOW_TOOLBAR" ), this, SLOT( onShowToolbar() ) ); } } @@ -207,7 +207,7 @@ SVTK_Viewer QPtrVector aViews = myViewManager->getViews(); for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){ if(TViewWindow* aView = dynamic_cast(aViews.at(i))){ - aView->getView()->getToolBar()->show(); + aView->getView()->GetMainWindow()->getToolBar()->show(); } } } @@ -239,7 +239,7 @@ SVTK_Viewer if(SVTK_View* aView = aViewWindow->getView()){ aView->Display(anAct,false); if(anAct->IsSetCamera()){ - vtkRenderer* aRenderer = aView->GetRenderer(); + vtkRenderer* aRenderer = aView->getRenderer(); anAct->SetCamera( aRenderer->GetActiveCamera() ); } } @@ -296,7 +296,7 @@ SVTK_Viewer for(int i = 0, iEnd = aViews.size(); i < iEnd; i++){ if(SVTK_ViewWindow* aViewWindow = dynamic_cast(aViews.at(i))) if(SVTK_View* aView = aViewWindow->getView()){ - vtkRenderer* aRenderer = aView->GetRenderer(); + vtkRenderer* aRenderer = aView->getRenderer(); vtkActorCollection* anActorCollection = aRenderer->GetActors(); anActorCollection->InitTraversal(); while(vtkActor* anActor = anActorCollection->GetNextActor()){ @@ -334,7 +334,7 @@ SVTK_Viewer if ( entry ) { if(SVTK_ViewWindow* aViewWindow = dynamic_cast(getViewManager()->getActiveView())) if(SVTK_View* aView = aViewWindow->getView()){ - vtkRenderer* aRenderer = aView->GetRenderer(); + vtkRenderer* aRenderer = aView->getRenderer(); vtkActorCollection* theActors = aRenderer->GetActors(); theActors->InitTraversal(); vtkActor* ac; @@ -389,5 +389,5 @@ SVTK_Viewer for(int i = 0, iEnd = aViews.size(); i < iEnd; i++) if(SVTK_ViewWindow* aViewWindow = dynamic_cast(aViews.at(i))) if(SVTK_View* aView = aViewWindow->getView()) - aView->update(); + aView->Repaint(); } diff --git a/src/SVTK/SVTK_ViewWindow.cxx b/src/SVTK/SVTK_ViewWindow.cxx index 037340fab..38ea4162c 100755 --- a/src/SVTK/SVTK_ViewWindow.cxx +++ b/src/SVTK/SVTK_ViewWindow.cxx @@ -29,12 +29,11 @@ #include "SVTK_Event.h" #include "SVTK_ViewWindow.h" #include "SVTK_ViewModelBase.h" -#include "SVTK_RenderWindowInteractor.h" -#include "SVTK_InteractorStyle.h" #include "SALOME_ListIteratorOfListIO.hxx" #include "SVTK_Selector.h" +#include "SVTK_View.h" #include "VTKViewer_Algorithm.h" #include "SVTK_Functor.h" @@ -51,9 +50,10 @@ SVTK_ViewWindow ::Initialize(SVTK_ViewModelBase* theModel) { if(SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr()){ - myView = new SVTK_View(this,"SVTK_View",aResourceMgr); - setCentralWidget(myView); + myMainWindow = new SVTK_MainWindow(this,"SVTK_MainWindow",aResourceMgr); + setCentralWidget(myMainWindow); + myView = new SVTK_View(myMainWindow); Initialize(myView,theModel); } } @@ -64,8 +64,6 @@ SVTK_ViewWindow ::Initialize(SVTK_View* theView, SVTK_ViewModelBase* theModel) { - onResetView(); - connect(theView,SIGNAL(KeyPressed(QKeyEvent*)), this,SLOT(onKeyPressed(QKeyEvent*)) ); connect(theView,SIGNAL(KeyReleased(QKeyEvent*)), @@ -91,34 +89,57 @@ SVTK_ViewWindow //---------------------------------------------------------------------------- +//---------------------------------------------------------------------------- +//---------------------------------------------------------------------------- +SVTK_View* +SVTK_ViewWindow +::getView() +{ + return myView; +} + +SVTK_MainWindow* +SVTK_ViewWindow +::getMainWindow() +{ + return myMainWindow; +} + +vtkRenderWindow* +SVTK_ViewWindow +::getRenderWindow() +{ + return getMainWindow()->getRenderWindow(); +} + +vtkRenderWindowInteractor* +SVTK_ViewWindow +::getInteractor() +{ + return getMainWindow()->getInteractor(); +} + vtkRenderer* SVTK_ViewWindow ::getRenderer() { - return myView->GetRenderer(); + return myMainWindow->getRenderer(); } -//---------------------------------------------------------------------------- SVTK_Selector* SVTK_ViewWindow ::GetSelector() { - return myView->GetSelector(); + return myMainWindow->GetSelector(); } -//---------------------------------------------------------------------------- -SVTK_View* -SVTK_ViewWindow -::getView() { - return myView; -} //---------------------------------------------------------------------------- void SVTK_ViewWindow ::onFrontView() { - myView->onFrontView(); + myMainWindow->onFrontView(); } //---------------------------------------------------------------------------- @@ -126,7 +147,7 @@ void SVTK_ViewWindow ::onBackView() { - myView->onBackView(); + myMainWindow->onBackView(); } //---------------------------------------------------------------------------- @@ -134,7 +155,7 @@ void SVTK_ViewWindow ::onTopView() { - myView->onTopView(); + myMainWindow->onTopView(); } //---------------------------------------------------------------------------- @@ -142,7 +163,7 @@ void SVTK_ViewWindow ::onBottomView() { - myView->onBottomView(); + myMainWindow->onBottomView(); } //---------------------------------------------------------------------------- @@ -150,7 +171,7 @@ void SVTK_ViewWindow ::onLeftView() { - myView->onLeftView(); + myMainWindow->onLeftView(); } //---------------------------------------------------------------------------- @@ -158,7 +179,7 @@ void SVTK_ViewWindow ::onRightView() { - myView->onRightView(); + myMainWindow->onRightView(); } //---------------------------------------------------------------------------- @@ -166,7 +187,7 @@ void SVTK_ViewWindow ::onResetView() { - myView->onResetView(); + myMainWindow->onResetView(); } //---------------------------------------------------------------------------- @@ -174,7 +195,7 @@ void SVTK_ViewWindow ::onFitAll() { - myView->onFitAll(); + myMainWindow->onFitAll(); } //---------------------------------------------------------------- @@ -190,7 +211,7 @@ void SVTK_ViewWindow ::SetSelectionMode(Selection_Mode theMode) { - myView->SetSelectionMode( theMode ); + myMainWindow->SetSelectionMode( theMode ); } //---------------------------------------------------------------- @@ -198,7 +219,7 @@ Selection_Mode SVTK_ViewWindow ::SelectionMode() const { - return Selection_Mode(myView->SelectionMode()); + return myMainWindow->SelectionMode(); } //---------------------------------------------------------------- @@ -240,7 +261,7 @@ void SVTK_ViewWindow ::setBackgroundColor( const QColor& color ) { - myView->setBackgroundColor( color ); + myMainWindow->SetBackgroundColor( color ); } //---------------------------------------------------------------------------- @@ -248,7 +269,7 @@ QColor SVTK_ViewWindow ::backgroundColor() const { - return myView->backgroundColor(); + return myMainWindow->BackgroundColor(); } //---------------------------------------------------------------------------- @@ -256,7 +277,7 @@ void SVTK_ViewWindow ::Repaint(bool theUpdateTrihedron) { - myView->Repaint( theUpdateTrihedron ); + myMainWindow->Repaint( theUpdateTrihedron ); } //---------------------------------------------------------------------------- @@ -264,7 +285,7 @@ void SVTK_ViewWindow ::GetScale( double theScale[3] ) { - myView->GetScale( theScale ); + myMainWindow->GetScale( theScale ); } //---------------------------------------------------------------------------- @@ -272,7 +293,7 @@ void SVTK_ViewWindow ::SetScale( double theScale[3] ) { - myView->SetScale( theScale ); + myMainWindow->SetScale( theScale ); } //---------------------------------------------------------------------------- @@ -280,14 +301,14 @@ bool SVTK_ViewWindow ::isTrihedronDisplayed() { - return myView->isTrihedronDisplayed(); + return myMainWindow->IsTrihedronDisplayed(); } bool SVTK_ViewWindow ::isCubeAxesDisplayed() { - return myView->isCubeAxesDisplayed(); + return myMainWindow->IsCubeAxesDisplayed(); } //---------------------------------------------------------------------------- @@ -295,35 +316,43 @@ void SVTK_ViewWindow ::onViewTrihedron() { - myView->onViewTrihedron(); + myMainWindow->onViewTrihedron(); } void SVTK_ViewWindow ::onViewCubeAxes() { - myView->onViewCubeAxes(); + myMainWindow->onViewCubeAxes(); } //---------------------------------------------------------------------------- -VTKViewer_Trihedron* SVTK_ViewWindow::GetTrihedron() +VTKViewer_Trihedron* +SVTK_ViewWindow:: +GetTrihedron() { - return myView->GetTrihedron(); + return myMainWindow->GetTrihedron(); } -SVTK_CubeAxesActor2D* SVTK_ViewWindow::GetCubeAxes() +SVTK_CubeAxesActor2D* +SVTK_ViewWindow +::GetCubeAxes() { - return myView->GetCubeAxes(); + return myMainWindow->GetCubeAxes(); } -int SVTK_ViewWindow::GetTrihedronSize() const +int +SVTK_ViewWindow +::GetTrihedronSize() const { - return myView->GetTrihedronSize(); + return myMainWindow->GetTrihedronSize(); } -void SVTK_ViewWindow::SetTrihedronSize( const int sz ) +void +SVTK_ViewWindow +::SetTrihedronSize(const int theSize) { - myView->SetTrihedronSize( sz ); + myMainWindow->SetTrihedronSize(theSize); } /*! If parameter theIsForcedUpdate is true, recalculate parameters for @@ -333,7 +362,7 @@ void SVTK_ViewWindow ::AdjustTrihedrons(const bool theIsForcedUpdate) { - myView->AdjustTrihedrons( theIsForcedUpdate ); + myMainWindow->AdjustTrihedrons( theIsForcedUpdate ); } //---------------------------------------------------------------------------- @@ -341,14 +370,14 @@ void SVTK_ViewWindow ::onAdjustTrihedron() { - myView->onAdjustTrihedron(); + myMainWindow->onAdjustTrihedron(); } void SVTK_ViewWindow ::onAdjustCubeAxes() { - myView->onAdjustCubeAxes(); + myMainWindow->onAdjustCubeAxes(); } //======================================================================= @@ -402,17 +431,19 @@ SVTK_ViewWindow //---------------------------------------------------------------------------- void SVTK_ViewWindow -::AddActor( VTKViewer_Actor* theActor, bool theUpdate ) +::AddActor( VTKViewer_Actor* theActor, + bool theUpdate ) { - myView->AddActor( theActor, theUpdate ); + myMainWindow->AddActor( theActor, theUpdate ); } //---------------------------------------------------------------------------- void SVTK_ViewWindow -::RemoveActor( VTKViewer_Actor* theActor, bool theUpdate ) +::RemoveActor( VTKViewer_Actor* theActor, + bool theUpdate ) { - myView->RemoveActor( theActor, theUpdate ); + myMainWindow->RemoveActor( theActor, theUpdate ); } //---------------------------------------------------------------------------- @@ -420,7 +451,7 @@ QImage SVTK_ViewWindow ::dumpView() { - return myView->dumpView(); + return myMainWindow->dumpView(); } //---------------------------------------------------------------------------- @@ -469,7 +500,7 @@ SVTK_ViewWindow if ( accelAction == SUIT_Accel::ZoomFit ) onFitAll(); else { - int svtkEvent = convertAction( accelAction ); - myView->InvokeEvent( svtkEvent, 0 ); + int anEvent = convertAction( accelAction ); + myMainWindow->InvokeEvent( anEvent, 0 ); } } diff --git a/src/SVTK/SVTK_ViewWindow.h b/src/SVTK/SVTK_ViewWindow.h index 2a5072f3c..b5efe0519 100755 --- a/src/SVTK/SVTK_ViewWindow.h +++ b/src/SVTK/SVTK_ViewWindow.h @@ -6,11 +6,8 @@ #endif #include "SVTK.h" -#include "SVTK_View.h" #include "SVTK_Selection.h" - #include "SUIT_ViewWindow.h" - #include "SALOME_InteractiveObject.hxx" class SUIT_Desktop; @@ -19,7 +16,9 @@ class VTKViewer_Actor; class VTKViewer_Trihedron; class SVTK_ViewModelBase; +class SVTK_MainWindow; class SVTK_Selector; +class SVTK_View; class SVTK_InteractorStyle; class SVTK_CubeAxesActor2D; @@ -27,6 +26,10 @@ class SVTK_CubeAxesActor2D; class SVTK_RenderWindow; class SVTK_RenderWindowInteractor; +class vtkRenderer; +class vtkRenderWindow; +class vtkRenderWindowInteractor; + class SVTK_EXPORT SVTK_ViewWindow : public SUIT_ViewWindow { Q_OBJECT; @@ -44,17 +47,26 @@ class SVTK_EXPORT SVTK_ViewWindow : public SUIT_ViewWindow SVTK_View* getView(); - SVTK_View* + SVTK_MainWindow* + getMainWindow(); + + vtkRenderWindow* getRenderWindow(); + vtkRenderWindowInteractor* + getInteractor(); + vtkRenderer* getRenderer(); SVTK_Selector* GetSelector(); - Selection_Mode SelectionMode() const; - void SetSelectionMode(Selection_Mode theMode); + Selection_Mode + SelectionMode() const; + + void + SetSelectionMode(Selection_Mode theMode); void setBackgroundColor( const QColor& ); QColor backgroundColor() const; @@ -144,6 +156,7 @@ protected: virtual void action( const int ); SVTK_View* myView; + SVTK_MainWindow* myMainWindow; SVTK_ViewModelBase* myModel; };