From 28dd4273a4633c0b2e5dd6fd5d372371dfb32878 Mon Sep 17 00:00:00 2001 From: ouv Date: Wed, 10 Aug 2005 14:10:19 +0000 Subject: [PATCH] Refactoring of SVTK_ViewWindow --- src/SVTK/Makefile.in | 3 + src/SVTK/SVTK_InteractorStyle.cxx | 23 +- src/SVTK/SVTK_InteractorStyle.h | 2 +- src/SVTK/SVTK_RenderWindow.cxx | 624 ++++++++++++++++++++--- src/SVTK/SVTK_RenderWindow.h | 113 ++-- src/SVTK/SVTK_RenderWindowInteractor.cxx | 441 ++++++++-------- src/SVTK/SVTK_RenderWindowInteractor.h | 73 +-- src/SVTK/SVTK_View.cxx | 6 +- src/SVTK/SVTK_View.h | 6 +- src/SVTK/SVTK_ViewModel.cxx | 35 +- src/SVTK/SVTK_ViewWindow.cxx | 608 +++------------------- src/SVTK/SVTK_ViewWindow.h | 66 +-- 12 files changed, 1026 insertions(+), 974 deletions(-) diff --git a/src/SVTK/Makefile.in b/src/SVTK/Makefile.in index 009ed5d9f..7a5f2ad6a 100755 --- a/src/SVTK/Makefile.in +++ b/src/SVTK/Makefile.in @@ -18,6 +18,7 @@ EXPORT_HEADERS= SVTK.h \ SALOME_Actor.h \ SVTK_CubeAxesActor2D.h \ SVTK_Functor.h \ + SVTK_View.h \ SVTK_ViewManager.h \ SVTK_ViewModel.h \ SVTK_ViewWindow.h \ @@ -36,6 +37,7 @@ LIB_SRC= SVTK_Prs.cxx \ SALOME_Actor.cxx \ SVTK_CubeAxesActor2D.cxx \ SVTK_Trihedron.cxx \ + SVTK_View.cxx \ SVTK_ViewManager.cxx \ SVTK_ViewModel.cxx \ SVTK_ViewWindow.cxx \ @@ -47,6 +49,7 @@ LIB_SRC= SVTK_Prs.cxx \ LIB_MOC = SVTK_RenderWindowInteractor.h \ SVTK_InteractorStyle.h \ SVTK_RenderWindow.h \ + SVTK_View.h \ SVTK_ViewWindow.h \ SVTK_ViewModel.h \ SVTK_ViewManager.h diff --git a/src/SVTK/SVTK_InteractorStyle.cxx b/src/SVTK/SVTK_InteractorStyle.cxx index c87a9072d..83739be27 100644 --- a/src/SVTK/SVTK_InteractorStyle.cxx +++ b/src/SVTK/SVTK_InteractorStyle.cxx @@ -288,7 +288,7 @@ void SVTK_InteractorStyle ::OnMouseMove() { - //cout << "void SVTK_InteractorStyle::OnMouseMove()" << endl; + //cout << "SVTK_InteractorStyle::OnMouseMove" << endl; int x, y; this->Interactor->GetEventPosition( x, y ); @@ -303,7 +303,7 @@ void SVTK_InteractorStyle ::OnLeftButtonDown() { - //cout << "void SVTK_InteractorStyle::OnLeftButtonDown()" << endl; + //cout << "SVTK_InteractorStyle::OnLeftButtonDown" << endl; int x, y; this->Interactor->GetEventPosition( x, y ); @@ -318,7 +318,7 @@ void SVTK_InteractorStyle ::OnLeftButtonUp() { - //cout << "void SVTK_InteractorStyle::OnLeftButtonUp()" << endl; + //cout << "SVTK_InteractorStyle::OnLeftButtonUp" << endl; int x, y; this->Interactor->GetEventPosition( x, y ); @@ -333,7 +333,7 @@ void SVTK_InteractorStyle ::OnMiddleButtonDown() { - //cout << "void SVTK_InteractorStyle::OnMiddleButtonDown()" << endl; + //cout << "SVTK_InteractorStyle::OnMiddleButtonDown" << endl; int x, y; this->Interactor->GetEventPosition( x, y ); @@ -348,7 +348,7 @@ void SVTK_InteractorStyle ::OnMiddleButtonUp() { - //cout << "void SVTK_InteractorStyle::OnMiddleButtonUp()" << endl; + //cout << "SVTK_InteractorStyle::OnMiddleButtonUp" << endl; int x, y; this->Interactor->GetEventPosition( x, y ); @@ -363,7 +363,7 @@ void SVTK_InteractorStyle ::OnRightButtonDown() { - //cout << "void SVTK_InteractorStyle::OnRightButtonDown()" << endl; + //cout << "SVTK_InteractorStyle::OnRightButtonDown" << endl; int x, y; this->Interactor->GetEventPosition( x, y ); @@ -377,22 +377,13 @@ void SVTK_InteractorStyle ::OnRightButtonUp() { - //cout << "void SVTK_InteractorStyle::OnRightButtonUp()" << endl; + //cout << "SVTK_InteractorStyle::OnRightButtonUp" << endl; int x, y; this->Interactor->GetEventPosition( x, y ); this->OnRightButtonUp( this->Interactor->GetControlKey(), this->Interactor->GetShiftKey(), x, y ); - /* - if( State == VTK_INTERACTOR_STYLE_CAMERA_NONE ) - { - QContextMenuEvent aEvent( QContextMenuEvent::Mouse, - event->pos(), event->globalPos(), - event->state() ); - emit contextMenuRequested( &aEvent ); - } - */ } diff --git a/src/SVTK/SVTK_InteractorStyle.h b/src/SVTK/SVTK_InteractorStyle.h index 3e04e1483..9315ee233 100644 --- a/src/SVTK/SVTK_InteractorStyle.h +++ b/src/SVTK/SVTK_InteractorStyle.h @@ -65,7 +65,7 @@ class SVTK_ViewWindow; class SVTK_EXPORT SVTK_InteractorStyle : public QObject, public vtkInteractorStyle { - Q_OBJECT; + Q_OBJECT public: // Description: diff --git a/src/SVTK/SVTK_RenderWindow.cxx b/src/SVTK/SVTK_RenderWindow.cxx index f2472a730..4d64c2d05 100644 --- a/src/SVTK/SVTK_RenderWindow.cxx +++ b/src/SVTK/SVTK_RenderWindow.cxx @@ -1,13 +1,27 @@ #include "SVTK_RenderWindow.h" +#include "SVTK_Trihedron.h" +#include "SVTK_CubeAxesActor2D.h" +#include "SALOME_Actor.h" -#include -#include +#include "VTKViewer_Transform.h" +#include "VTKViewer_Utilities.h" + +#include "QtxAction.h" + +#include "SUIT_Session.h" +#include "SUIT_ToolButton.h" +#include "SUIT_MessageBox.h" + +#include "SUIT_Tools.h" +#include "SUIT_ResourceMgr.h" #include #include +#include #include #include +#include #include #ifndef WNT #include @@ -23,137 +37,617 @@ //========================================================== SVTK_RenderWindow ::SVTK_RenderWindow(QWidget* parent, const char* name) : - QWidget(parent, name, + QMainWindow(parent, name, Qt::WStyle_NoBorder | Qt::WDestructiveClose | - Qt::WResizeNoErase | Qt::WRepaintNoErase) + Qt::WResizeNoErase | Qt::WRepaintNoErase), + myTrihedronSize( 100 ) { - myRW = vtkRenderWindow::New(); + myRenderWindow = vtkRenderWindow::New(); #ifndef WNT - myRW->SetDisplayId((void*)x11Display()); + myRenderWindow->SetDisplayId((void*)x11Display()); #endif - myRW->SetWindowId((void*)winId()); - myRW->DoubleBufferOn(); + myRenderWindow->SetWindowId((void*)winId()); + myRenderWindow->DoubleBufferOn(); + //myRenderWindow->DebugOn(); setMouseTracking(true); + + myRenderer = vtkRenderer::New(); + myTransform = VTKViewer_Transform::New(); + myTrihedron = SVTK_Trihedron::New(); + myCubeAxes = SVTK_CubeAxesActor2D::New(); + + myTrihedron->AddToRender( myRenderer ); + myRenderer->AddProp(myCubeAxes); + + myRenderWindow->AddRenderer( myRenderer ); + myRenderer->GetActiveCamera()->ParallelProjectionOn(); + myRenderer->LightFollowCameraOn(); + myRenderer->TwoSidedLightingOn(); + + // Set BackgroundColor + QString BgrColorRed = "0";//SUIT_CONFIG->getSetting("VTKViewer:BackgroundColorRed"); + QString BgrColorGreen = "0";//SUIT_CONFIG->getSetting("VTKViewer:BackgroundColorGreen"); + QString BgrColorBlue = "0";//SUIT_CONFIG->getSetting("VTKViewer:BackgroundColorBlue"); + + if( !BgrColorRed.isEmpty() && !BgrColorGreen.isEmpty() && !BgrColorBlue.isEmpty() ) + myRenderer->SetBackground( BgrColorRed.toInt()/255., BgrColorGreen.toInt()/255., BgrColorBlue.toInt()/255. ); + else + myRenderer->SetBackground( 0, 0, 0 ); + + vtkTextProperty* tprop = vtkTextProperty::New(); + tprop->SetColor(1, 1, 1); + tprop->ShadowOn(); + + float bnd[6]; + bnd[0] = bnd[2] = bnd[4] = 0; + bnd[1] = bnd[3] = bnd[5] = myTrihedron->GetSize(); + myCubeAxes->SetLabelFormat("%6.4g"); + myCubeAxes->SetBounds(bnd); + myCubeAxes->SetCamera(myRenderer->GetActiveCamera()); + myCubeAxes->SetFlyModeToOuterEdges(); // ENK remarks: it must bee + myCubeAxes->SetFontFactor(0.8); + myCubeAxes->SetAxisTitleTextProperty(tprop); + myCubeAxes->SetAxisLabelTextProperty(tprop); + myCubeAxes->SetCornerOffset(0); + myCubeAxes->SetScaling(0); + myCubeAxes->SetNumberOfLabels(5); + myCubeAxes->VisibilityOff(); + myCubeAxes->SetTransform(myTransform); + tprop->Delete(); + + myToolBar = new QToolBar(this); + myToolBar->setCloseMode(QDockWindow::Undocked); + myToolBar->setLabel(tr("LBL_TOOLBAR_LABEL")); + + createActions(); + createToolBar(); } //========================================================== SVTK_RenderWindow ::~SVTK_RenderWindow() { - myRW->Delete(); + myRenderWindow->Delete(); + + myTransform->Delete(); + + //m_RW->Delete() ; + myRenderer->RemoveAllProps(); + //m_Renderer->Delete(); + myTrihedron->Delete(); + myCubeAxes->Delete(); } //========================================================== void SVTK_RenderWindow -::paintEvent(QPaintEvent* theEvent) +::createActions() { - myRW->Render(); + 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 -::resizeEvent(QResizeEvent* theEvent) -{ - int aWidth = myRW->GetSize()[0], aHeight = myRW->GetSize()[1]; - if(vtkRenderWindowInteractor* aRWI = myRW->GetInteractor()) - aRWI->UpdateSize(width(), height()); - if(aWidth != width() || aHeight != height()){ - vtkRendererCollection * aRenderers = myRW->GetRenderers(); - aRenderers->InitTraversal(); - double aCoeff = 1.0; - if(vtkRenderer *aRenderer = aRenderers->GetNextItem()){ - vtkCamera *aCamera = aRenderer->GetActiveCamera(); - double aScale = aCamera->GetParallelScale(); - if((aWidth - width())*(aHeight - height()) > 0) - aCoeff = sqrt(double(aWidth)/double(width())*double(height())/double(aHeight)); - else - aCoeff = double(aWidth)/double(width()); - aCamera->SetParallelScale(aScale*aCoeff); - } +::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 ) + onAdjustTrihedron(); + + update(); +} + +//---------------------------------------------------------------------------- +void +SVTK_RenderWindow +::setBackgroundColor( const QColor& color ) +{ + if( myRenderer ) + myRenderer->SetBackground( color.red()/255., color.green()/255., color.blue()/255. ); +} + +//---------------------------------------------------------------------------- +QColor +SVTK_RenderWindow +::backgroundColor() const +{ + float backint[3]; + if( myRenderer ) + { + myRenderer->GetBackground( backint ); + return QColor(int(backint[0]*255), int(backint[1]*255), int(backint[2]*255)); } + return QColor(); } -//========================================================== +//---------------------------------------------------------------------------- void SVTK_RenderWindow -::mouseMoveEvent(QMouseEvent* event) +::GetScale( double theScale[3] ) { - emit MouseMove(event) ; + myTransform->GetMatrixScale( theScale ); } -//========================================================== +//---------------------------------------------------------------------------- void SVTK_RenderWindow -::mousePressEvent(QMouseEvent* event) +::SetScale( double theScale[3] ) { - emit MouseButtonPressed( event ); + myTransform->SetMatrixScale( theScale[0], theScale[1], theScale[2] ); + //myRWInteractor->Render(); + Repaint(); } -//========================================================== +//---------------------------------------------------------------------------- +bool +SVTK_RenderWindow +::isTrihedronDisplayed() +{ + return myTrihedron->GetVisibility() == VTKViewer_Trihedron::eOn; +} + +//---------------------------------------------------------------------------- +bool +SVTK_RenderWindow +::isCubeAxesDisplayed() +{ + return myCubeAxes->GetVisibility() == 1; +} + +//---------------------------------------------------------------------------- void SVTK_RenderWindow -::mouseReleaseEvent( QMouseEvent *event ) +::activateZoom() { - emit MouseButtonReleased( event ); + //myInteractorStyle->startZoom(); } -//========================================================== +//---------------------------------------------------------------------------- void -SVTK_RenderWindow::mouseDoubleClickEvent( QMouseEvent* event ) +SVTK_RenderWindow +::activatePanning() { - emit MouseDoubleClicked( event ); + //myInteractorStyle->startPan(); } -//========================================================== +//---------------------------------------------------------------------------- void SVTK_RenderWindow -::keyPressEvent (QKeyEvent* event) +::activateRotation() { - emit KeyPressed(event) ; + //myInteractorStyle->startRotate(); } -//========================================================== +//---------------------------------------------------------------------------- void SVTK_RenderWindow -::keyReleaseEvent (QKeyEvent * event) +::activateGlobalPanning() { - emit KeyReleased(event) ; + //myInteractorStyle->startGlobalPan(); } -//========================================================== +//---------------------------------------------------------------------------- void SVTK_RenderWindow -::wheelEvent(QWheelEvent* event) +::activateWindowFit() { - emit WheelMoved(event) ; + //myInteractorStyle->startFitArea(); } -//========================================================== +//---------------------------------------------------------------------------- void SVTK_RenderWindow -::onChangeBackgroundColor() +::onFrontView() { - //float red, green, blue; - float backint[3]; + vtkCamera* camera = myRenderer->GetActiveCamera(); + camera->SetPosition(1,0,0); + camera->SetViewUp(0,0,1); + camera->SetFocalPoint(0,0,0); + onFitAll(); +} + +//---------------------------------------------------------------------------- +void +SVTK_RenderWindow +::onBackView() +{ + vtkCamera* camera = myRenderer->GetActiveCamera(); + camera->SetPosition(-1,0,0); + camera->SetViewUp(0,0,1); + camera->SetFocalPoint(0,0,0); + onFitAll(); +} + +//---------------------------------------------------------------------------- +void +SVTK_RenderWindow +::onTopView() +{ + vtkCamera* camera = myRenderer->GetActiveCamera(); + camera->SetPosition(0,0,1); + camera->SetViewUp(0,1,0); + camera->SetFocalPoint(0,0,0); + onFitAll(); +} + +//---------------------------------------------------------------------------- +void +SVTK_RenderWindow +::onBottomView() +{ + vtkCamera* camera = myRenderer->GetActiveCamera(); + camera->SetPosition(0,0,-1); + camera->SetViewUp(0,1,0); + camera->SetFocalPoint(0,0,0); + onFitAll(); +} + +//---------------------------------------------------------------------------- +void +SVTK_RenderWindow +::onLeftView() +{ + vtkCamera* camera = myRenderer->GetActiveCamera(); + camera->SetPosition(0,-1,0); + camera->SetViewUp(0,0,1); + camera->SetFocalPoint(0,0,0); + onFitAll(); +} - vtkRendererCollection * theRenderers = myRW->GetRenderers(); - theRenderers->InitTraversal(); - vtkRenderer * theRenderer = theRenderers->GetNextItem(); - theRenderer->GetBackground(backint); +//---------------------------------------------------------------------------- +void +SVTK_RenderWindow +::onRightView() +{ + vtkCamera* camera = myRenderer->GetActiveCamera(); + camera->SetPosition(0,1,0); + camera->SetViewUp(0,0,1); + camera->SetFocalPoint(0,0,0); + onFitAll(); +} - QColor selColor = QColorDialog::getColor ( QColor(int(backint[0]*255), int(backint[1]*255), int(backint[2]*255)), NULL ); - if ( selColor.isValid() ) { - theRenderer->SetBackground( selColor.red()/255., selColor.green()/255., selColor.blue()/255. ); +//---------------------------------------------------------------------------- +void +SVTK_RenderWindow +::onResetView() +{ + int aTrihedronIsVisible = isTrihedronDisplayed(); + int aCubeAxesIsVisible = isCubeAxesDisplayed(); + + myTrihedron->SetVisibility( VTKViewer_Trihedron::eOnlyLineOn ); + myCubeAxes->SetVisibility(0); + + ::ResetCamera(myRenderer,true); + vtkCamera* aCamera = myRenderer->GetActiveCamera(); + aCamera->SetPosition(1,-1,1); + aCamera->SetViewUp(0,0,1); + ::ResetCamera(myRenderer,true); + + if (aTrihedronIsVisible) myTrihedron->VisibilityOn(); + else myTrihedron->VisibilityOff(); + + if (aCubeAxesIsVisible) myCubeAxes->VisibilityOn(); + else myCubeAxes->VisibilityOff(); + + static float aCoeff = 3.0; + aCamera->SetParallelScale(aCoeff*aCamera->GetParallelScale()); + Repaint(); +} + +//---------------------------------------------------------------------------- +void +SVTK_RenderWindow +::onFitAll() +{ + int aTrihedronWasVisible = false; + int aCubeAxesWasVisible = false; + if (myTrihedron) { + aTrihedronWasVisible = isTrihedronDisplayed(); + if (aTrihedronWasVisible) + myTrihedron->VisibilityOff(); } + + if (myCubeAxes) { + aCubeAxesWasVisible = isCubeAxesDisplayed(); + if (aCubeAxesWasVisible) + myCubeAxes->VisibilityOff(); + } + + if (myTrihedron->GetVisibleActorCount(myRenderer)) { + myTrihedron->VisibilityOff(); + myCubeAxes->VisibilityOff(); + ::ResetCamera(myRenderer); + } else { + myTrihedron->SetVisibility(VTKViewer_Trihedron::eOnlyLineOn); + myCubeAxes->SetVisibility(2); + ::ResetCamera(myRenderer,true); + } + + if (aTrihedronWasVisible) + myTrihedron->VisibilityOn(); + else + myTrihedron->VisibilityOff(); + + if (aCubeAxesWasVisible) + myCubeAxes->VisibilityOn(); + else + myCubeAxes->VisibilityOff(); + + ::ResetCameraClippingRange(myRenderer); + + Repaint(); } -//========================================================== +//---------------------------------------------------------------------------- +void +SVTK_RenderWindow +::onViewTrihedron() +{ + if(!myTrihedron) + return; + + if(isTrihedronDisplayed()) + myTrihedron->VisibilityOff(); + else + myTrihedron->VisibilityOn(); + + Repaint(); +} + +//---------------------------------------------------------------------------- +void +SVTK_RenderWindow +::onViewCubeAxes() +{ + if(!myCubeAxes) + return; + + if(isCubeAxesDisplayed()) + myCubeAxes->VisibilityOff(); + else + myCubeAxes->VisibilityOn(); + + Repaint(); +} +//---------------------------------------------------------------------------- +int SVTK_RenderWindow::GetTrihedronSize() const +{ + return myTrihedronSize; +} + +//---------------------------------------------------------------------------- +void SVTK_RenderWindow::SetTrihedronSize( const int sz ) +{ + if ( myTrihedronSize == sz ) + return; + + myTrihedronSize = sz; + AdjustTrihedrons( true ); +} + +/*! If parameter theIsForcedUpdate is true, recalculate parameters for + * trihedron and cube axes, even if trihedron and cube axes is invisible. + */ void SVTK_RenderWindow -::contextMenuEvent ( QContextMenuEvent * e ) +::AdjustTrihedrons(const bool theIsForcedUpdate) { - if ( e->reason() != QContextMenuEvent::Mouse ) - emit contextMenuRequested( e ); + if ((!isCubeAxesDisplayed() && !isTrihedronDisplayed()) && !theIsForcedUpdate) + return; + + float bnd[ 6 ]; + float newbnd[6]; + newbnd[ 0 ] = newbnd[ 2 ] = newbnd[ 4 ] = VTK_LARGE_FLOAT; + newbnd[ 1 ] = newbnd[ 3 ] = newbnd[ 5 ] = -VTK_LARGE_FLOAT; + + myCubeAxes->GetBounds(bnd); + + int aVisibleNum = myTrihedron->GetVisibleActorCount( myRenderer ); + //if (aVisibleNum || theIsForcedUpdate) { + if (aVisibleNum) { + // if the new trihedron size have sufficient difference, then apply the value + double aNewSize = 100, anOldSize=myTrihedron->GetSize(); + bool aTDisplayed = isTrihedronDisplayed(); + bool aCDisplayed = isCubeAxesDisplayed(); + if(aTDisplayed) myTrihedron->VisibilityOff(); + if(aCDisplayed) myCubeAxes->VisibilityOff(); + + SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); + QString aSetting = aResMgr->stringValue("Viewer:TrihedronSize", "105"); + static float aSizeInPercents = aSetting.toFloat(); + + //bool isComputeTrihedronSize = + ::ComputeTrihedronSize(myRenderer, aNewSize, anOldSize, aSizeInPercents); + + myTrihedron->SetSize( aNewSize ); + + // iterate through displayed objects and set size if necessary + vtkActorCollection* anActors = getRenderer()->GetActors(); + anActors->InitTraversal(); + while (vtkActor* anActor = anActors->GetNextActor()) + { + if (SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast( anActor )) + { + if (aSActor->IsResizable()) + aSActor->SetSize( 0.5 * aNewSize ); + if (aSActor->GetVisibility() && !aSActor->IsInfinitive()) { + float *abounds = aSActor->GetBounds(); + if (abounds[0] > -VTK_LARGE_FLOAT && abounds[1] < VTK_LARGE_FLOAT && + abounds[2] > -VTK_LARGE_FLOAT && abounds[3] < VTK_LARGE_FLOAT && + abounds[4] > -VTK_LARGE_FLOAT && abounds[5] < VTK_LARGE_FLOAT) + for (int i = 0; i < 5; i = i + 2) { + if (abounds[i] < newbnd[i]) newbnd[i] = abounds[i]; + if (abounds[i+1] > newbnd[i+1]) newbnd[i+1] = abounds[i+1]; + } + } + } + } + if (aTDisplayed) myTrihedron->VisibilityOn(); + if (aCDisplayed) myCubeAxes->VisibilityOn(); + + } else { + double aSize = myTrihedron->GetSize(); + newbnd[0] = newbnd[2] = newbnd[4] = 0; + newbnd[1] = newbnd[3] = newbnd[5] = aSize; + } + + if (newbnd[0] < VTK_LARGE_FLOAT && newbnd[2] < VTK_LARGE_FLOAT && newbnd[4] < VTK_LARGE_FLOAT && + newbnd[1] >-VTK_LARGE_FLOAT && newbnd[3] >-VTK_LARGE_FLOAT && newbnd[5] >-VTK_LARGE_FLOAT) { + for(int i=0;i<6;i++) bnd[i] = newbnd[i]; + myCubeAxes->SetBounds(bnd); + } + + myCubeAxes->SetBounds(bnd); + + ::ResetCameraClippingRange(myRenderer); +} + +//---------------------------------------------------------------------------- +void +SVTK_RenderWindow +::onAdjustTrihedron() +{ + AdjustTrihedrons( false ); +} + +//---------------------------------------------------------------------------- +void +SVTK_RenderWindow +::onAdjustCubeAxes() +{ + AdjustTrihedrons(false); } diff --git a/src/SVTK/SVTK_RenderWindow.h b/src/SVTK/SVTK_RenderWindow.h index 35f5b6d21..371088351 100644 --- a/src/SVTK/SVTK_RenderWindow.h +++ b/src/SVTK/SVTK_RenderWindow.h @@ -29,55 +29,94 @@ #ifndef SVTK_RenderWindow_h #define SVTK_RenderWindow_h -#include +#include #include "SVTK.h" +class VTKViewer_Trihedron; +class VTKViewer_Transform; +class SVTK_CubeAxesActor2D; + +class QtxAction; + +class vtkRenderer; class vtkRenderWindow; -class SVTK_EXPORT SVTK_RenderWindow : public QWidget +class SVTK_EXPORT SVTK_RenderWindow : public QMainWindow { - Q_OBJECT; + Q_OBJECT -public: - SVTK_RenderWindow(QWidget *parent, const char *name); + public: + SVTK_RenderWindow( QWidget*, const char* ); virtual ~SVTK_RenderWindow() ; - vtkRenderWindow* getRenderWindow() { return myRW; } + QToolBar* getToolBar() { return myToolBar; } - protected: - 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 paintEvent( QPaintEvent* ); - virtual void resizeEvent( QResizeEvent* ); - virtual void onChangeBackgroundColor(); - virtual void contextMenuEvent( QContextMenuEvent * e ); - - signals: - void MouseMove( QMouseEvent* ); - void MouseButtonPressed( QMouseEvent* ); - void MouseButtonReleased( QMouseEvent* ); - void MouseDoubleClicked( QMouseEvent* ); - void WheelMoved( QWheelEvent* ); - void LeftButtonPressed(const QMouseEvent *event) ; - void LeftButtonReleased(const QMouseEvent *event) ; - void MiddleButtonPressed(const QMouseEvent *event) ; - void MiddleButtonReleased(const QMouseEvent *event) ; - void RightButtonPressed(const QMouseEvent *event) ; - void RightButtonReleased(const QMouseEvent *event) ; - void ButtonPressed(const QMouseEvent *event); - void ButtonReleased(const QMouseEvent *event); - void KeyPressed( QKeyEvent* ); - void KeyReleased( QKeyEvent* ); - void contextMenuRequested( QContextMenuEvent *e ); + vtkRenderer* getRenderer() { return myRenderer;} + vtkRenderWindow* getRenderWindow() { return myRenderWindow; } + + VTKViewer_Trihedron* GetTrihedron() { return myTrihedron; } + SVTK_CubeAxesActor2D* GetCubeAxes() { return myCubeAxes; } + + int GetTrihedronSize() const; + void SetTrihedronSize( const int ); + void AdjustTrihedrons( const bool forced ); + + bool isTrihedronDisplayed(); + bool isCubeAxesDisplayed(); + + void Repaint( bool theUpdateTrihedron = 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*, bool update = false ); + //void RemoveActor(VTKViewer_Actor*, bool update = 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(); protected: - vtkRenderWindow* myRW; + enum { DumpId, FitAllId, FitRectId, ZoomId, PanId, GlobalPanId, RotationId, + FrontId, BackId, TopId, BottomId, LeftId, RightId, ResetId, ViewTrihedronId }; + typedef QMap ActionsMap; + + void createActions(); + void createToolBar(); + + vtkRenderer* myRenderer; + vtkRenderWindow* myRenderWindow; + + VTKViewer_Transform* myTransform; + VTKViewer_Trihedron* myTrihedron; + int myTrihedronSize; + SVTK_CubeAxesActor2D* myCubeAxes; + + QToolBar* myToolBar; + ActionsMap myActionsMap; }; #endif diff --git a/src/SVTK/SVTK_RenderWindowInteractor.cxx b/src/SVTK/SVTK_RenderWindowInteractor.cxx index bfc3eb3d5..608265077 100644 --- a/src/SVTK/SVTK_RenderWindowInteractor.cxx +++ b/src/SVTK/SVTK_RenderWindowInteractor.cxx @@ -28,9 +28,6 @@ #include "SVTK_RenderWindowInteractor.h" -#include "SVTK_RenderWindow.h" -#include "SVTK_Selection.h" - #include "VTKViewer_Algorithm.h" #include "SVTK_Functor.h" #include "SALOME_Actor.h" @@ -42,18 +39,16 @@ // VTK Includes #include -#include -#include -#include #include #include #include +#include #include +#include +#include // QT Includes -#include - -#include +#include #include "utilities.h" @@ -65,28 +60,19 @@ static int MYDEBUG = 0; static int MYDEBUG = 0; #endif - -SVTK_RenderWindowInteractor* SVTK_RenderWindowInteractor -::New() +::SVTK_RenderWindowInteractor( QWidget* parent, const char* name ) : + SVTK_RenderWindow( parent, name ) { - vtkObject *ret = vtkObjectFactory::CreateInstance("SVTK_RenderWindowInteractor") ; - if( ret ) { - return dynamic_cast(ret) ; - } - return new SVTK_RenderWindowInteractor; -} + myInteractor = vtkGenericRenderWindowInteractor::New(); + //myInteractor->DebugOn(); -SVTK_RenderWindowInteractor -::SVTK_RenderWindowInteractor() -{ - this->Enabled = 0 ; - this->mTimer = new QTimer( this ) ; + myInteractor->SetRenderWindow( getRenderWindow() ); + + myInteractor->Disable(); + mTimer = new QTimer( this ) ; myDisplayMode = 0; - myBasicPicker = vtkPicker::New(); - myCellPicker = vtkCellPicker::New(); - myPointPicker = vtkPointPicker::New(); connect(mTimer, SIGNAL(timeout()), this, SLOT(TimerFunc())) ; } @@ -98,9 +84,7 @@ SVTK_RenderWindowInteractor delete mTimer ; - myBasicPicker->Delete(); - myCellPicker->Delete(); - myPointPicker->Delete(); + myInteractor->Delete(); } // @@ -115,8 +99,8 @@ SVTK_RenderWindowInteractor // We cannot do much unless there is a render window // associated with this interactor. // - if( ! RenderWindow ) { - vtkErrorMacro(<< "SVTK_RenderWindowInteractor::Initialize(): No render window attached!") ; + if( !getRenderWindow() ) { + //vtkErrorMacro(<< "SVTK_RenderWindowInteractor::Initialize(): No render window attached!") ; return ; } @@ -126,9 +110,9 @@ SVTK_RenderWindowInteractor // it works. If the dynamic_cast does not work, we flag an error // and get the hell out. // - vtkRenderWindow *aRenderWindow = dynamic_cast(RenderWindow) ; - if( !aRenderWindow ) { - vtkErrorMacro(<< "SVTK_RenderWindowInteractor::Initialize() can only handle VTKViewer_RenderWindow.") ; + //vtkRenderWindow *aRenderWindow = dynamic_cast(getRenderWindow()); + if( !getRenderWindow() ) { + //vtkErrorMacro(<< "SVTK_RenderWindowInteractor::Initialize() can only handle VTKViewer_RenderWindow.") ; return ; } @@ -136,29 +120,27 @@ SVTK_RenderWindowInteractor // If the render window has zero size, then set it to a default // value of 300x300. // - int* aSize = aRenderWindow->GetSize(); - this->Size[0] = ((aSize[0] > 0) ? aSize[0] : 300); - this->Size[1] = ((aSize[1] > 0) ? aSize[1] : 300); + int* aSize = getRenderWindow()->GetSize(); + myInteractor->SetSize( ((aSize[0] > 0) ? aSize[0] : 300), ((aSize[1] > 0) ? aSize[1] : 300) ); - this->SetPicker(myBasicPicker); - //this->SetPicker(vtkPicker::New()); + myInteractor->SetPicker(vtkPicker::New()); //SetSelectionTolerance(); // - // Enable the interactor. + // The interactor has been initialized. // - this->Enable() ; + myInteractor->Initialize() ; // - // Start the rendering of the window. + // Enable the interactor. // - aRenderWindow->Start() ; + myInteractor->Enable() ; // - // The interactor has been initialized. + // Start the rendering of the window. // - this->Initialized = 1 ; + getRenderWindow()->Start() ; return ; } @@ -173,7 +155,7 @@ SVTK_RenderWindowInteractor // event loop. Only the QtApplication objects are // allowed to do that. // - vtkErrorMacro(<<"SVTK_RenderWindowInteractor::Start() not allowed to start event loop.") ; + //vtkErrorMacro(<<"SVTK_RenderWindowInteractor::Start() not allowed to start event loop.") ; return ; } @@ -182,10 +164,9 @@ SVTK_RenderWindowInteractor ::UpdateSize(int w, int h) { // if the size changed send this on to the RenderWindow - if ((w != this->Size[0])||(h != this->Size[1])) { - this->Size[0] = w; - this->Size[1] = h; - this->RenderWindow->SetSize(w,h); + if ((w != myInteractor->GetSize()[0])||(h != myInteractor->GetSize()[1])) { + myInteractor->SetSize( w, h ); + getRenderWindow()->SetSize( w, h ); } } @@ -223,149 +204,16 @@ void SVTK_RenderWindowInteractor ::TimerFunc() { - if( ! this->Enabled ) { + if( ! myInteractor->GetEnabled() ) { return ; } - vtkInteractorStyle* aStyle = vtkInteractorStyle::SafeDownCast( InteractorStyle ); + vtkInteractorStyle* aStyle = vtkInteractorStyle::SafeDownCast( myInteractor->GetInteractorStyle() ); aStyle->OnTimer(); - emit RenderWindowModified(); -} - -void -SVTK_RenderWindowInteractor -::MouseMove(const QMouseEvent *event) -{ - if( ! this->Enabled ) { - return ; - } - - this->SetEventInformation( event->x(), event->y(), - ( event->state() & ControlButton ), - ( event->state() & ShiftButton ) ); - - if( this->HasObserver( vtkCommand::MouseMoveEvent ) ) - this->InvokeEvent( vtkCommand::MouseMoveEvent, NULL ); -} - -void -SVTK_RenderWindowInteractor -::LeftButtonPressed(const QMouseEvent *event) -{ - if( ! this->Enabled ) { - return ; - } - - this->SetEventInformation( event->x(), event->y(), - ( event->state() & ControlButton ), - ( event->state() & ShiftButton ) ); - - if( this->HasObserver( vtkCommand::LeftButtonPressEvent ) ) - this->InvokeEvent( vtkCommand::LeftButtonPressEvent, NULL ); -} - -void -SVTK_RenderWindowInteractor -::LeftButtonReleased(const QMouseEvent *event) { - if( ! this->Enabled ) { - return ; - } - - this->SetEventInformation( event->x(), event->y(), - ( event->state() & ControlButton ), - ( event->state() & ShiftButton ) ); - - if( this->HasObserver( vtkCommand::LeftButtonReleaseEvent ) ) - this->InvokeEvent( vtkCommand::LeftButtonReleaseEvent, NULL ); -} - -void -SVTK_RenderWindowInteractor -::MiddleButtonPressed(const QMouseEvent *event) -{ - if( ! this->Enabled ) { - return ; - } - - this->SetEventInformation( event->x(), event->y(), - ( event->state() & ControlButton ), - ( event->state() & ShiftButton ) ); - - if( this->HasObserver( vtkCommand::MiddleButtonPressEvent ) ) - this->InvokeEvent( vtkCommand::MiddleButtonPressEvent, NULL ); -} - -void -SVTK_RenderWindowInteractor -::MiddleButtonReleased(const QMouseEvent *event) -{ - if( ! this->Enabled ) { - return ; - } - - this->SetEventInformation( event->x(), event->y(), - ( event->state() & ControlButton ), - ( event->state() & ShiftButton ) ); - - if( this->HasObserver( vtkCommand::MiddleButtonReleaseEvent ) ) - this->InvokeEvent( vtkCommand::MiddleButtonReleaseEvent, NULL ); -} - -void -SVTK_RenderWindowInteractor -::RightButtonPressed(const QMouseEvent *event) -{ - if( ! this->Enabled ) { - return ; - } - - this->SetEventInformation( event->x(), event->y(), - ( event->state() & ControlButton ), - ( event->state() & ShiftButton ) ); - - if( this->HasObserver( vtkCommand::RightButtonPressEvent ) ) - this->InvokeEvent( vtkCommand::RightButtonPressEvent, NULL ); -} - -void -SVTK_RenderWindowInteractor -::RightButtonReleased(const QMouseEvent *event) -{ - if( ! this->Enabled ) { - return ; - } - - this->SetEventInformation( event->x(), event->y(), - ( event->state() & ControlButton ), - ( event->state() & ShiftButton ) ); - - if( this->HasObserver( vtkCommand::RightButtonReleaseEvent ) ) - this->InvokeEvent( vtkCommand::RightButtonReleaseEvent, NULL ); - - if(/*myInteractorStyle->GetState() == VTK_INTERACTOR_STYLE_CAMERA_NONE && */!( event->state() & KeyButtonMask )){ - QContextMenuEvent aEvent( QContextMenuEvent::Mouse, - event->pos(), event->globalPos(), - event->state() ); - emit contextMenuRequested( &aEvent ); - } -} - -void -SVTK_RenderWindowInteractor -::ButtonPressed(const QMouseEvent *event) -{ - return ; -} - -void -SVTK_RenderWindowInteractor -::ButtonReleased(const QMouseEvent *event) -{ - return ; + update(); } - int SVTK_RenderWindowInteractor ::GetDisplayMode() @@ -421,7 +269,7 @@ SVTK_RenderWindowInteractor ForEach(theCollection, TSetFunction (&SALOME_Actor::setDisplayMode,0)); - emit RenderWindowModified(); + update(); } void @@ -432,7 +280,7 @@ SVTK_RenderWindowInteractor ForEach(theCollection, TSetFunction (&SALOME_Actor::setDisplayMode,1)); - emit RenderWindowModified(); + update(); } @@ -440,7 +288,7 @@ vtkRenderer* SVTK_RenderWindowInteractor ::GetRenderer() { - vtkRendererCollection * theRenderers = this->RenderWindow->GetRenderers(); + vtkRendererCollection * theRenderers = getRenderWindow()->GetRenderers(); theRenderers->InitTraversal(); return theRenderers->GetNextItem(); } @@ -469,7 +317,7 @@ SVTK_RenderWindowInteractor ForEach(GetRenderer()->GetActors(), TErase()); - emit RenderWindowModified() ; + update(); } void @@ -480,33 +328,33 @@ SVTK_RenderWindowInteractor using namespace VTK; ForEach(aCollection,TSetVisibility(true)); - emit RenderWindowModified() ; + update(); } void SVTK_RenderWindowInteractor -::Erase(SALOME_Actor* theActor, bool update) +::Erase(SALOME_Actor* theActor, bool updateViewer) { TErase()(theActor); - if(update) - emit RenderWindowModified(); + if(updateViewer) + update(); } void SVTK_RenderWindowInteractor ::Erase(const Handle(SALOME_InteractiveObject)& theIObject, - bool update) + bool updateViewer) { using namespace VTK; ForEachIf(GetRenderer()->GetActors(), TIsSameIObject(theIObject), TErase()); - if(update) - emit RenderWindowModified(); + if(updateViewer) + update(); } @@ -521,7 +369,7 @@ struct TRemoveAction{ void SVTK_RenderWindowInteractor ::Remove(const Handle(SALOME_InteractiveObject)& theIObject, - bool update) + bool updateViewer) { vtkRenderer* aRen = GetRenderer(); @@ -539,7 +387,7 @@ SVTK_RenderWindowInteractor { GetRenderer()->RemoveProp( SActor ); if ( updateViewer ) - emit RenderWindowModified(); + update(); } } @@ -563,7 +411,7 @@ SVTK_RenderWindowInteractor } if ( updateViewer ) - emit RenderWindowModified(); + update(); } } @@ -598,35 +446,29 @@ SVTK_RenderWindowInteractor void SVTK_RenderWindowInteractor -::Display(SALOME_Actor* theActor, bool update) +::Display(SALOME_Actor* theActor, bool updateViewer) { GetRenderer()->AddActor(theActor); theActor->SetVisibility(true); - if(update) - emit RenderWindowModified(); + if(updateViewer) + update(); } void SVTK_RenderWindowInteractor -::Display(const Handle(SALOME_InteractiveObject)& theIObject, bool update) +::Display(const Handle(SALOME_InteractiveObject)& theIObject, bool updateViewer) { using namespace VTK; ForEachIf(GetRenderer()->GetActors(), TIsSameIObject(theIObject), TSetVisibility(true)); - if(update) - emit RenderWindowModified() ; + if(updateViewer) + update(); } - -void -SVTK_RenderWindowInteractor -::KeyPressed(QKeyEvent *event) -{} - struct TUpdateAction{ void operator()(vtkActor* theActor){ theActor->ApplyProperties(); @@ -644,7 +486,7 @@ SVTK_RenderWindowInteractor aRen->ResetCamera(); - emit RenderWindowModified(); + update(); } //----------------- @@ -715,3 +557,176 @@ SVTK_RenderWindowInteractor TSetFunction (&SALOME_Actor::setName,theName.latin1())); } + +//---------------------------------------------------------------------------- +void +SVTK_RenderWindowInteractor +::mouseMoveEvent( QMouseEvent* event ) +{ + //cout << "SVTK_RenderWindowInteractor::mouseMoveEvent" << endl; + + myInteractor->SetEventInformation( event->x(), event->y(), + ( event->state() & ControlButton ), + ( event->state() & ShiftButton ) ); + + myInteractor->MouseMoveEvent(); + + //emit MouseMove( event ) ; +} + +//---------------------------------------------------------------------------- +void +SVTK_RenderWindowInteractor +::mousePressEvent( QMouseEvent* event ) +{ + //cout << "SVTK_RenderWindowInteractor::mousePressEvent" << endl; + + myInteractor->SetEventInformation( event->x(), event->y(), + ( event->state() & ControlButton ), + ( event->state() & ShiftButton ) ); + + if( event->button() & LeftButton ) + myInteractor->LeftButtonPressEvent(); + else if( event->button() & MidButton ) + myInteractor->MiddleButtonPressEvent(); + else if( event->button() & RightButton ) + myInteractor->RightButtonPressEvent(); + + //emit MouseButtonPressed( event ); +} + +//---------------------------------------------------------------------------- +void +SVTK_RenderWindowInteractor +::mouseReleaseEvent( QMouseEvent *event ) +{ + //cout << "SVTK_RenderWindowInteractor::mouseReleaseEvent" << endl; + + myInteractor->SetEventInformation( event->x(), event->y(), + ( event->state() & ControlButton ), + ( event->state() & ShiftButton ) ); + + if( event->button() & LeftButton ) + myInteractor->LeftButtonReleaseEvent(); + else if( event->button() & MidButton ) + myInteractor->MiddleButtonReleaseEvent(); + else if( event->button() & RightButton ) + myInteractor->RightButtonReleaseEvent(); + + //emit MouseButtonReleased( event ); +} + +//---------------------------------------------------------------------------- +void +SVTK_RenderWindowInteractor +::mouseDoubleClickEvent( QMouseEvent* event ) +{ + //cout << "SVTK_RenderWindowInteractor::mouseDoubleClickEvent" << endl; + + //emit MouseDoubleClicked( event ); +} + +//---------------------------------------------------------------------------- +void +SVTK_RenderWindowInteractor +::keyPressEvent( QKeyEvent* event ) +{ + //cout << "SVTK_RenderWindowInteractor::keyPressEvent" << endl; + + myInteractor->SetKeyEventInformation( ( event->state() & ControlButton ), + ( event->state() & ShiftButton ), + 0 ); + + myInteractor->KeyPressEvent(); + + //emit KeyPressed(event) ; +} + +//---------------------------------------------------------------------------- +void +SVTK_RenderWindowInteractor +::keyReleaseEvent( QKeyEvent * event ) +{ + //cout << "SVTK_RenderWindowInteractor::keyReleaseEvent" << endl; + + myInteractor->SetKeyEventInformation( ( event->state() & ControlButton ), + ( event->state() & ShiftButton ), + 0 ); + + myInteractor->KeyReleaseEvent(); + + //emit KeyReleased(event) ; +} + +//---------------------------------------------------------------------------- +void +SVTK_RenderWindowInteractor +::wheelEvent( QWheelEvent* event ) +{ + //cout << "SVTK_RenderWindowInteractor::wheelEvent" << endl; + + //emit WheelMoved(event) ; +} + +//---------------------------------------------------------------------------- +void +SVTK_RenderWindowInteractor +::contextMenuEvent( QContextMenuEvent* event ) +{ + //cout << "SVTK_RenderWindowInteractor::contextMenuEvent" << endl; + + if( !( event->state() & KeyButtonMask ) ) + emit contextMenuRequested( event ); +} + +//---------------------------------------------------------------------------- +void +SVTK_RenderWindowInteractor +::paintEvent( QPaintEvent* theEvent ) +{ + getRenderWindow()->Render(); +} + +//---------------------------------------------------------------------------- +void +SVTK_RenderWindowInteractor +::resizeEvent( QResizeEvent* theEvent ) +{ + int aWidth = getRenderWindow()->GetSize()[0], aHeight = getRenderWindow()->GetSize()[1]; + + myInteractor->UpdateSize( width(), height() ); + + if( aWidth != width() || aHeight != height() ) + { + vtkRendererCollection * aRenderers = getRenderWindow()->GetRenderers(); + aRenderers->InitTraversal(); + double aCoeff = 1.0; + if(vtkRenderer *aRenderer = aRenderers->GetNextItem()) + { + vtkCamera *aCamera = aRenderer->GetActiveCamera(); + double aScale = aCamera->GetParallelScale(); + if((aWidth - width())*(aHeight - height()) > 0) + aCoeff = sqrt(double(aWidth)/double(width())*double(height())/double(aHeight)); + else + aCoeff = double(aWidth)/double(width()); + aCamera->SetParallelScale(aScale*aCoeff); + } + } +} + +//---------------------------------------------------------------------------- +void +SVTK_RenderWindowInteractor +::onChangeBackgroundColor() +{ + float backint[3]; + + vtkRendererCollection* theRenderers = getRenderWindow()->GetRenderers(); + theRenderers->InitTraversal(); + vtkRenderer* theRenderer = theRenderers->GetNextItem(); + theRenderer->GetBackground(backint); + + QColor selColor = QColorDialog::getColor ( QColor(int(backint[0]*255), int(backint[1]*255), int(backint[2]*255)), NULL ); + if ( selColor.isValid() ) + theRenderer->SetBackground( selColor.red()/255., selColor.green()/255., selColor.blue()/255. ); +} diff --git a/src/SVTK/SVTK_RenderWindowInteractor.h b/src/SVTK/SVTK_RenderWindowInteractor.h index 6207cec54..eea4a8a72 100644 --- a/src/SVTK/SVTK_RenderWindowInteractor.h +++ b/src/SVTK/SVTK_RenderWindowInteractor.h @@ -31,32 +31,21 @@ #include "SVTK.h" #include "SVTK_Selection.h" +#include "SVTK_RenderWindow.h" #include "SALOME_InteractiveObject.hxx" // QT Includes -#include #include // VTK Includes #include -#include -// Open CASCADE Includes -#include -#include -#include - -class vtkPicker; -class vtkCellPicker; -class vtkPointPicker; class vtkActorCollection; +class vtkGenericRenderWindowInteractor; class SALOME_Actor; -class SVTK_ViewWindow; -class SVTK_RenderWindow; - // ------------------------------------------------------------ // :TRICKY: Fri Apr 21 22:19:27 2000 Pagey // The Signal/Slot mechanism used by Qt requires that QObject @@ -64,16 +53,15 @@ class SVTK_RenderWindow; // Hence the order of the two classes QObject and vtkRenderWindowInteractor // matters here. Be careful not to change it by accident. // ------------------------------------------------------------ -class SVTK_EXPORT SVTK_RenderWindowInteractor: public QObject, - public vtkRenderWindowInteractor +class SVTK_EXPORT SVTK_RenderWindowInteractor: public SVTK_RenderWindow//, public vtkRenderWindowInteractor { - Q_OBJECT ; - friend class SVTK_ViewWindow; -public: + Q_OBJECT - static SVTK_RenderWindowInteractor *New() ; +public: + SVTK_RenderWindowInteractor( QWidget*, const char* ); + ~SVTK_RenderWindowInteractor(); - vtkTypeMacro(SVTK_RenderWindowInteractor,vtkRenderWindowInteractor); + vtkGenericRenderWindowInteractor* getInteractor() { return myInteractor; } // Description: // Initializes the event handlers without an XtAppContext. This is @@ -104,15 +92,7 @@ public: bool isInViewer( const Handle(SALOME_InteractiveObject)& IObject); bool isVisible( const Handle(SALOME_InteractiveObject)& IObject); void rename(const Handle(SALOME_InteractiveObject)& IObject, QString newName); - /* - void SetSelectionMode(Selection_Mode mode); - void SetSelectionProp(const double& theRed = 1, - const double& theGreen = 1, - const double& theBlue = 0, - const int& theWidth = 5); - void SetSelectionTolerance(const double& theTolNodes = 0.025, - const double& theTolCell = 0.001); - */ + // Displaymode management int GetDisplayMode(); void SetDisplayMode(int); @@ -161,33 +141,30 @@ public: vtkRenderer* GetRenderer(); protected: - - SVTK_RenderWindowInteractor(); - ~SVTK_RenderWindowInteractor(); + vtkGenericRenderWindowInteractor* myInteractor; // Timer used during various mouse events to figure // out mouse movements. QTimer *mTimer ; int myDisplayMode; - vtkPicker* myBasicPicker; - vtkCellPicker* myCellPicker; - vtkPointPicker* myPointPicker; // User for switching to stereo mode. int PositionBeforeStereo[2]; - public slots: - void MouseMove(const QMouseEvent *event) ; - void LeftButtonPressed(const QMouseEvent *event) ; - void LeftButtonReleased(const QMouseEvent *event) ; - void MiddleButtonPressed(const QMouseEvent *event) ; - void MiddleButtonReleased(const QMouseEvent *event) ; - void RightButtonPressed(const QMouseEvent *event) ; - void RightButtonReleased(const QMouseEvent *event) ; - void ButtonPressed(const QMouseEvent *event) ; - void ButtonReleased(const QMouseEvent *event) ; - void KeyPressed(QKeyEvent *event) ; + protected: + 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 ); + + virtual void paintEvent( QPaintEvent* ); + virtual void resizeEvent( QResizeEvent* ); + virtual void onChangeBackgroundColor(); private slots: // Not all of these slots are needed in VTK_MAJOR_VERSION=3, @@ -197,12 +174,8 @@ public: void TimerFunc() ; signals: - void RenderWindowModified() ; void contextMenuRequested( QContextMenuEvent *e ); - private: - double myTolNodes; - double myTolItems; }; diff --git a/src/SVTK/SVTK_View.cxx b/src/SVTK/SVTK_View.cxx index 33bb45867..0165f4104 100644 --- a/src/SVTK/SVTK_View.cxx +++ b/src/SVTK/SVTK_View.cxx @@ -281,13 +281,12 @@ SVTK_View { myInteractorStyle->IncrementalRotate( 0, INCREMENT_FOR_OP ); } -/* + //---------------------------------------------------------------------------- void SVTK_View ::InsertActor( VTKViewer_Actor* theActor, bool theMoveInternalActors ) { - //cout << "SVTK_View::InsertActor" << endl; theActor->AddToRender( getRenderer() ); //theActor->SetTransform(myTransform); @@ -310,7 +309,6 @@ void SVTK_View ::RemoveActor( VTKViewer_Actor* theActor, bool theUpdate ) { - //cout << "SVTK_View::RemoveActor" << endl; theActor->RemoveFromRender( getRenderer() ); if(theUpdate) @@ -325,7 +323,7 @@ SVTK_View RemoveActor(theActor); InsertActor(theActor,true); } -*/ + /* //---------------------------------------------------------------------------- QImage diff --git a/src/SVTK/SVTK_View.h b/src/SVTK/SVTK_View.h index 1c8fd0fa1..14daf12e5 100644 --- a/src/SVTK/SVTK_View.h +++ b/src/SVTK/SVTK_View.h @@ -58,12 +58,10 @@ public: void Repaint() { Repaint(true); } //apply existing transformation on adding SALOME_Actor - //void AddActor( VTKViewer_Actor*, bool update = false ); - //void RemoveActor(VTKViewer_Actor*, bool update = false); + void AddActor( VTKViewer_Actor*, bool update = false ); + void RemoveActor(VTKViewer_Actor*, bool update = false); void AdjustTrihedrons( const bool forced ); - //merge with V2_2_0_VISU_improvements:bool ComputeTrihedronSize( double& theNewSize, - //merge with V2_2_0_VISU_improvements: double& theOldSize ); void SetSelectionProp(const double& theRed = 1, const double& theGreen = 1, diff --git a/src/SVTK/SVTK_ViewModel.cxx b/src/SVTK/SVTK_ViewModel.cxx index 17f0ac85c..603e59ca1 100644 --- a/src/SVTK/SVTK_ViewModel.cxx +++ b/src/SVTK/SVTK_ViewModel.cxx @@ -10,6 +10,7 @@ #include "SVTK_Selection.h" #include "SVTK_ViewModel.h" #include "SVTK_ViewWindow.h" +#include "SVTK_View.h" #include "SVTK_Prs.h" #include "SVTK_RenderWindowInteractor.h" @@ -131,15 +132,16 @@ void SVTK_Viewer::contextMenuPopup( QPopupMenu* thePopup ) 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() ) ); + //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->getRWInteractor()){ + if(SVTK_RenderWindowInteractor* aRWI = aVW->getView()){ switch(event->button()) { case LeftButton: aRWI->LeftButtonPressed(event) ; @@ -155,6 +157,7 @@ void SVTK_Viewer::onMousePress(SUIT_ViewWindow* vw, QMouseEvent* event) } } } + */ } //========================================================== @@ -162,11 +165,13 @@ void SVTK_Viewer ::onMouseMove(SUIT_ViewWindow* vw, QMouseEvent* event) { + /* if(SVTK_ViewWindow* aVW = dynamic_cast(vw)){ - if(SVTK_RenderWindowInteractor* aRWI = aVW->getRWInteractor()){ + if(SVTK_RenderWindowInteractor* aRWI = aVW->getView()){ aRWI->MouseMove( event ); } } + */ } //========================================================== @@ -174,8 +179,9 @@ void SVTK_Viewer ::onMouseRelease(SUIT_ViewWindow* vw, QMouseEvent* event) { + /* if(SVTK_ViewWindow* aVW = dynamic_cast(vw)){ - if(SVTK_RenderWindowInteractor* aRWI = aVW->getRWInteractor()){ + if(SVTK_RenderWindowInteractor* aRWI = aVW->getView()){ switch(event->button()) { case LeftButton: aRWI->LeftButtonReleased(event) ; @@ -191,6 +197,7 @@ SVTK_Viewer } } } + */ } //========================================================== @@ -236,11 +243,13 @@ 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(); + aView->getToolBar()->show(); + */ } //========================================================== @@ -268,10 +277,10 @@ SVTK_Viewer 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->getRWInteractor()){ + if(SVTK_RenderWindowInteractor* aRWI = aView->getView()){ aRWI->Display(anAct,false); if(anAct->IsSetCamera()){ - vtkRenderer* aRenderer = aView->getRenderer(); + vtkRenderer* aRenderer = aView->getView()->getRenderer(); anAct->SetCamera( aRenderer->GetActiveCamera() ); } } @@ -309,7 +318,7 @@ SVTK_Viewer 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->getRWInteractor()) + if(SVTK_RenderWindowInteractor* aRWI = aView->getView()) if ( forced ) aRWI->Remove(anAct,false); else @@ -330,7 +339,7 @@ SVTK_Viewer 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->getRenderer(); + vtkRenderer* aRenderer = aView->getView()->getRenderer(); vtkActorCollection* anActorCollection = aRenderer->GetActors(); anActorCollection->InitTraversal(); while(vtkActor* anActor = anActorCollection->GetNextActor()){ @@ -367,7 +376,7 @@ SVTK_Viewer { SVTK_Prs* prs = new SVTK_Prs(); if ( entry ) { - vtkRenderer* rnr = ( (SVTK_ViewWindow*) getViewManager()->getActiveView() )->getRenderer(); + vtkRenderer* rnr = ( (SVTK_ViewWindow*) getViewManager()->getActiveView() )->getView()->getRenderer(); vtkActorCollection* theActors = rnr->GetActors(); theActors->InitTraversal(); vtkActor* ac; @@ -405,7 +414,7 @@ SVTK_Viewer 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->getRWInteractor()) + if(SVTK_RenderWindowInteractor* aRWI = aView->getView()) if(!aRWI->isVisible( io )) return false; return true; @@ -421,7 +430,7 @@ SVTK_Viewer 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->getRenderWindow()) + if(SVTK_RenderWindow* aRW = aView->getView()) aRW->update(); } diff --git a/src/SVTK/SVTK_ViewWindow.cxx b/src/SVTK/SVTK_ViewWindow.cxx index 30c000a44..fb5e34823 100755 --- a/src/SVTK/SVTK_ViewWindow.cxx +++ b/src/SVTK/SVTK_ViewWindow.cxx @@ -1,6 +1,8 @@ #include "SALOME_Actor.h" #include +#include +#include #include #include @@ -19,15 +21,12 @@ #include "SUIT_Tools.h" #include "SUIT_ResourceMgr.h" -#include "VTKViewer_Transform.h" #include "VTKViewer_Utilities.h" #include "VTKViewer_CellRectPicker.h" -#include "SVTK_Trihedron.h" -#include "SVTK_CubeAxesActor2D.h" +//#include "SVTK_View.h" #include "SVTK_ViewWindow.h" #include "SVTK_ViewModel.h" -#include "SVTK_RenderWindow.h" #include "SVTK_RenderWindowInteractor.h" #include "SVTK_InteractorStyle.h" @@ -42,89 +41,42 @@ SVTK_ViewWindow ::SVTK_ViewWindow( SUIT_Desktop* theDesktop, SVTK_Viewer* theModel) - : SUIT_ViewWindow( theDesktop ), - myTrihedronSize( 100 ) + : SUIT_ViewWindow( theDesktop ) { myModel = theModel; mySelector = new SVTK_SelectorDef(); connect(this,SIGNAL(selectionChanged()),theModel,SLOT(onSelectionChanged())); - myTransform = VTKViewer_Transform::New(); - myTrihedron = SVTK_Trihedron::New(); - myCubeAxes = SVTK_CubeAxesActor2D::New(); - myRenderer = vtkRenderer::New() ; + QWidget* aCentralWidget = new QWidget( this ); + setCentralWidget( aCentralWidget ); + QBoxLayout* aLayout = new QVBoxLayout( aCentralWidget ); + aLayout->setAutoAdd( true ); + QSplitter* aSplitter = new QSplitter( Qt::Vertical, aCentralWidget ); - myTrihedron->AddToRender( myRenderer ); - myRenderer->AddProp(myCubeAxes); - - myRenderWindow = new SVTK_RenderWindow( this, "RenderWindow" ); - setCentralWidget(myRenderWindow); - myRenderWindow->setFocusPolicy( StrongFocus ); - myRenderWindow->setFocus(); - - myRenderWindow->getRenderWindow()->AddRenderer( myRenderer ); - - myRenderer->GetActiveCamera()->ParallelProjectionOn(); - myRenderer->LightFollowCameraOn(); - myRenderer->TwoSidedLightingOn(); - - // Set BackgroundColor - QString BgrColorRed = "0";//SUIT_CONFIG->getSetting("VTKViewer:BackgroundColorRed"); - QString BgrColorGreen = "0";//SUIT_CONFIG->getSetting("VTKViewer:BackgroundColorGreen"); - QString BgrColorBlue = "0";//SUIT_CONFIG->getSetting("VTKViewer:BackgroundColorBlue"); - - if( !BgrColorRed.isEmpty() && !BgrColorGreen.isEmpty() && !BgrColorBlue.isEmpty() ) - myRenderer->SetBackground( BgrColorRed.toInt()/255., BgrColorGreen.toInt()/255., BgrColorBlue.toInt()/255. ); - else - myRenderer->SetBackground( 0, 0, 0 ); - // Create an interactor. - myRWInteractor = SVTK_RenderWindowInteractor::New(); - myRWInteractor->SetRenderWindow( myRenderWindow->getRenderWindow() ); - //myRWInteractor->setViewWindow( this ); - + myView = new SVTK_View( aSplitter, "TopView" ); + /* + SVTK_View* bottomView = new SVTK_View( aSplitter, "BottomView" ); + bottomView->getInteractor()->SetInteractorStyle( myInteractorStyle ); + bottomView->Initialize(); + */ myInteractorStyle = SVTK_InteractorStyle::New(); - myInteractorStyle->setGUIWindow( myRenderWindow ); + myInteractorStyle->setGUIWindow( myView ); myInteractorStyle->setViewWindow( this ); - myRWInteractor->SetInteractorStyle( myInteractorStyle ); - myRWInteractor->Initialize(); + myView->SetInteractorStyle( myInteractorStyle ); + myView->SetSelector( mySelector ); + myView->Initialize(); //merge with V2_2_0_VISU_improvements:myInteractorStyle->setTriedron( myTrihedron ); myInteractorStyle->FindPokedRenderer( 0, 0 ); - SetSelectionMode(ActorSelection); - - vtkTextProperty* tprop = vtkTextProperty::New(); - tprop->SetColor(1, 1, 1); - tprop->ShadowOn(); - - float bnd[6]; - bnd[0] = bnd[2] = bnd[4] = 0; - bnd[1] = bnd[3] = bnd[5] = myTrihedron->GetSize(); - myCubeAxes->SetLabelFormat("%6.4g"); - myCubeAxes->SetBounds(bnd); - myCubeAxes->SetCamera(myRenderer->GetActiveCamera()); - myCubeAxes->SetFlyModeToOuterEdges(); // ENK remarks: it must bee - myCubeAxes->SetFontFactor(0.8); - myCubeAxes->SetAxisTitleTextProperty(tprop); - myCubeAxes->SetAxisLabelTextProperty(tprop); - myCubeAxes->SetCornerOffset(0); - myCubeAxes->SetScaling(0); - myCubeAxes->SetNumberOfLabels(5); - myCubeAxes->VisibilityOff(); - myCubeAxes->SetTransform(myTransform); - tprop->Delete(); - - setCentralWidget( myRenderWindow ); - - myToolBar = new QToolBar(this); - myToolBar->setCloseMode(QDockWindow::Undocked); - myToolBar->setLabel(tr("LBL_TOOLBAR_LABEL")); - - createActions(); - createToolBar(); + SetSelectionMode( ActorSelection ); + + myView->setFocusPolicy( StrongFocus ); + myView->setFocus(); + /* connect( myRenderWindow, SIGNAL(KeyPressed( QKeyEvent* )), this, SLOT(onKeyPressed( QKeyEvent* )) ); connect( myRenderWindow, SIGNAL(KeyReleased( QKeyEvent* )), @@ -137,13 +89,12 @@ SVTK_ViewWindow this, SLOT(onMouseDoubleClicked( QMouseEvent* )) ); connect( myRenderWindow, SIGNAL(MouseMove( QMouseEvent* )), this, SLOT(onMouseMoving( QMouseEvent* )) ); + */ connect( myInteractorStyle, SIGNAL(RenderWindowModified()), - myRenderWindow, SLOT(update()) ); - connect( myRWInteractor, SIGNAL(RenderWindowModified()), - myRenderWindow, SLOT(update()) ); - connect( myRWInteractor, SIGNAL(contextMenuRequested( QContextMenuEvent * )), - this, SIGNAL(contextMenuRequested( QContextMenuEvent * )) ); + myView, SLOT(update()) ); + connect( myView, SIGNAL(contextMenuRequested( QContextMenuEvent * )), + this, SIGNAL(contextMenuRequested( QContextMenuEvent * )) ); onResetView(); } @@ -152,201 +103,19 @@ SVTK_ViewWindow SVTK_ViewWindow ::~SVTK_ViewWindow() { - myTransform->Delete(); // In order to ensure that the interactor unregisters // this RenderWindow, we assign a NULL RenderWindow to // it before deleting it. - myRWInteractor->SetRenderWindow( NULL ); - myRWInteractor->Delete(); - - //m_RW->Delete() ; - myRenderer->RemoveAllProps(); - //m_Renderer->Delete(); - myTrihedron->Delete(); - myCubeAxes->Delete(); + //myView->SetRenderWindow( NULL ); + //delete myView; } //---------------------------------------------------------------------------- -void +vtkRenderer* SVTK_ViewWindow -::activateZoom() +::getRenderer() { - myInteractorStyle->startZoom(); -} - -//---------------------------------------------------------------------------- -void -SVTK_ViewWindow -::activatePanning() -{ - myInteractorStyle->startPan(); -} - -//---------------------------------------------------------------------------- -void -SVTK_ViewWindow -::activateRotation() -{ - myInteractorStyle->startRotate(); -} - -//---------------------------------------------------------------------------- -void -SVTK_ViewWindow -::activateGlobalPanning() -{ - if(myTrihedron->GetVisibleActorCount(myRenderer)) - myInteractorStyle->startGlobalPan(); -} - -//---------------------------------------------------------------------------- -void -SVTK_ViewWindow -::activateWindowFit() -{ - myInteractorStyle->startFitArea(); -} - -//---------------------------------------------------------------------------- -void -SVTK_ViewWindow -::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_ViewWindow -::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); + return myView->getRenderer(); } //---------------------------------------------------------------------------- @@ -354,11 +123,7 @@ void SVTK_ViewWindow ::onFrontView() { - vtkCamera* camera = myRenderer->GetActiveCamera(); - camera->SetPosition(1,0,0); - camera->SetViewUp(0,0,1); - camera->SetFocalPoint(0,0,0); - onFitAll(); + myView->onFrontView(); } //---------------------------------------------------------------------------- @@ -366,11 +131,7 @@ void SVTK_ViewWindow ::onBackView() { - vtkCamera* camera = myRenderer->GetActiveCamera(); - camera->SetPosition(-1,0,0); - camera->SetViewUp(0,0,1); - camera->SetFocalPoint(0,0,0); - onFitAll(); + myView->onBackView(); } //---------------------------------------------------------------------------- @@ -378,11 +139,7 @@ void SVTK_ViewWindow ::onTopView() { - vtkCamera* camera = myRenderer->GetActiveCamera(); - camera->SetPosition(0,0,1); - camera->SetViewUp(0,1,0); - camera->SetFocalPoint(0,0,0); - onFitAll(); + myView->onTopView(); } //---------------------------------------------------------------------------- @@ -390,11 +147,7 @@ void SVTK_ViewWindow ::onBottomView() { - vtkCamera* camera = myRenderer->GetActiveCamera(); - camera->SetPosition(0,0,-1); - camera->SetViewUp(0,1,0); - camera->SetFocalPoint(0,0,0); - onFitAll(); + myView->onBottomView(); } //---------------------------------------------------------------------------- @@ -402,11 +155,7 @@ void SVTK_ViewWindow ::onLeftView() { - vtkCamera* camera = myRenderer->GetActiveCamera(); - camera->SetPosition(0,-1,0); - camera->SetViewUp(0,0,1); - camera->SetFocalPoint(0,0,0); - onFitAll(); + myView->onLeftView(); } //---------------------------------------------------------------------------- @@ -414,11 +163,7 @@ void SVTK_ViewWindow ::onRightView() { - vtkCamera* camera = myRenderer->GetActiveCamera(); - camera->SetPosition(0,1,0); - camera->SetViewUp(0,0,1); - camera->SetFocalPoint(0,0,0); - onFitAll(); + myView->onRightView(); } //---------------------------------------------------------------------------- @@ -426,27 +171,7 @@ void SVTK_ViewWindow ::onResetView() { - int aTrihedronIsVisible = isTrihedronDisplayed(); - int aCubeAxesIsVisible = isCubeAxesDisplayed(); - - myTrihedron->SetVisibility( VTKViewer_Trihedron::eOnlyLineOn ); - myCubeAxes->SetVisibility(0); - - ::ResetCamera(myRenderer,true); - vtkCamera* aCamera = myRenderer->GetActiveCamera(); - aCamera->SetPosition(1,-1,1); - aCamera->SetViewUp(0,0,1); - ::ResetCamera(myRenderer,true); - - if (aTrihedronIsVisible) myTrihedron->VisibilityOn(); - else myTrihedron->VisibilityOff(); - - if (aCubeAxesIsVisible) myCubeAxes->VisibilityOn(); - else myCubeAxes->VisibilityOff(); - - static float aCoeff = 3.0; - aCamera->SetParallelScale(aCoeff*aCamera->GetParallelScale()); - Repaint(); + myView->onResetView(); } //---------------------------------------------------------------------------- @@ -454,70 +179,15 @@ void SVTK_ViewWindow ::onFitAll() { - int aTrihedronWasVisible = false; - int aCubeAxesWasVisible = false; - if (myTrihedron) { - aTrihedronWasVisible = isTrihedronDisplayed(); - if (aTrihedronWasVisible) - myTrihedron->VisibilityOff(); - } - - if (myCubeAxes) { - aCubeAxesWasVisible = isCubeAxesDisplayed(); - if (aCubeAxesWasVisible) - myCubeAxes->VisibilityOff(); - } - - if (myTrihedron->GetVisibleActorCount(myRenderer)) { - myTrihedron->VisibilityOff(); - myCubeAxes->VisibilityOff(); - ::ResetCamera(myRenderer); - } else { - myTrihedron->SetVisibility(VTKViewer_Trihedron::eOnlyLineOn); - myCubeAxes->SetVisibility(2); - ::ResetCamera(myRenderer,true); - } - - if (aTrihedronWasVisible) - myTrihedron->VisibilityOn(); - else - myTrihedron->VisibilityOff(); - - if (aCubeAxesWasVisible) - myCubeAxes->VisibilityOn(); - else - myCubeAxes->VisibilityOff(); - - ::ResetCameraClippingRange(myRenderer); - - Repaint(); + myView->onFitAll(); } -//---------------------------------------------------------------- -struct THighlightAction{ - bool myIsHighlight; - THighlightAction( bool theIsHighlight ): myIsHighlight(theIsHighlight) {} - void operator()( SALOME_Actor* theActor) { - if(theActor->GetMapper()){ - theActor->highlight( myIsHighlight ); - } - } -}; - //---------------------------------------------------------------- void SVTK_ViewWindow ::onSelectionChanged() { - unHighlightAll(); - - const SALOME_ListIO& aListIO = mySelector->StoredIObjects(); - SALOME_ListIteratorOfListIO anIter(aListIO); - for(; anIter.More(); anIter.Next()){ - highlight(anIter.Value(),true,!anIter.More()); - } - - emit selectionChanged(); + myView->onSelectionChanged(); } //---------------------------------------------------------------- @@ -525,9 +195,7 @@ void SVTK_ViewWindow ::SetSelectionMode(Selection_Mode theMode) { - mySelector->SetSelectionMode(theMode); - - //myRWInteractor->SetSelectionMode(theMode); + myView->SetSelectionMode( theMode ); } //---------------------------------------------------------------- @@ -535,7 +203,7 @@ Selection_Mode SVTK_ViewWindow ::SelectionMode() const { - return mySelector->SelectionMode(); + return myView->SelectionMode(); } //---------------------------------------------------------------- @@ -543,14 +211,7 @@ void SVTK_ViewWindow ::unHighlightAll() { - //cout << "--------------------------------------------------" << endl; - //cout << "SVTK_ViewWindow::unHighlightAll" << endl; - - using namespace VTK; - ForEach( myRenderer->GetActors(), - THighlightAction( false ) ); - - //myRenderWindow->update(); + myView->unHighlightAll(); } //---------------------------------------------------------------- @@ -560,12 +221,7 @@ SVTK_ViewWindow bool theIsHighlight, bool theIsUpdate ) { - using namespace VTK; - ForEachIf(myRenderer->GetActors(), - TIsSameIObject(theIO), - THighlightAction(theIsHighlight)); - - //myRenderWindow->update(); + myView->highlight( theIO, theIsHighlight, theIsUpdate ); } //---------------------------------------------------------------- @@ -573,7 +229,7 @@ bool SVTK_ViewWindow ::isInViewer( const Handle(SALOME_InteractiveObject)& theIO ) { - return myRWInteractor->isInViewer( theIO ); + return myView->isInViewer( theIO ); } //---------------------------------------------------------------- @@ -581,7 +237,7 @@ bool SVTK_ViewWindow ::isVisible( const Handle(SALOME_InteractiveObject)& theIO ) { - return myRWInteractor->isVisible( theIO ); + return myView->isVisible( theIO ); } //---------------------------------------------------------------------------- @@ -589,8 +245,7 @@ void SVTK_ViewWindow ::setBackgroundColor( const QColor& color ) { - if ( myRenderer ) - myRenderer->SetBackground( color.red()/255., color.green()/255., color.blue()/255. ); + myView->setBackgroundColor( color ); } //---------------------------------------------------------------------------- @@ -598,12 +253,7 @@ QColor SVTK_ViewWindow ::backgroundColor() const { - float backint[3]; - if ( myRenderer ) { - myRenderer->GetBackground( backint ); - return QColor(int(backint[0]*255), int(backint[1]*255), int(backint[2]*255)); - } - return SUIT_ViewWindow::backgroundColor(); + return myView->backgroundColor(); } //---------------------------------------------------------------------------- @@ -611,9 +261,7 @@ void SVTK_ViewWindow ::Repaint(bool theUpdateTrihedron) { - if (theUpdateTrihedron) - onAdjustTrihedron(); - myRenderWindow->update(); + myView->Repaint( theUpdateTrihedron ); } //---------------------------------------------------------------------------- @@ -621,7 +269,7 @@ void SVTK_ViewWindow ::GetScale( double theScale[3] ) { - myTransform->GetMatrixScale( theScale ); + myView->GetScale( theScale ); } //---------------------------------------------------------------------------- @@ -629,9 +277,7 @@ void SVTK_ViewWindow ::SetScale( double theScale[3] ) { - myTransform->SetMatrixScale( theScale[0], theScale[1], theScale[2] ); - myRWInteractor->Render(); - Repaint(); + myView->SetScale( theScale ); } //---------------------------------------------------------------------------- @@ -639,14 +285,14 @@ bool SVTK_ViewWindow ::isTrihedronDisplayed() { - return myTrihedron->GetVisibility() == VTKViewer_Trihedron::eOn; + return myView->isTrihedronDisplayed(); } bool SVTK_ViewWindow ::isCubeAxesDisplayed() { - return myCubeAxes->GetVisibility() == 1; + return myView->isCubeAxesDisplayed(); } //---------------------------------------------------------------------------- @@ -654,30 +300,14 @@ void SVTK_ViewWindow ::onViewTrihedron() { - if(!myTrihedron) - return; - - if(isTrihedronDisplayed()) - myTrihedron->VisibilityOff(); - else - myTrihedron->VisibilityOn(); - - Repaint(); + myView->onViewTrihedron(); } void SVTK_ViewWindow ::onViewCubeAxes() { - if(!myCubeAxes) - return; - - if(isCubeAxesDisplayed()) - myCubeAxes->VisibilityOff(); - else - myCubeAxes->VisibilityOn(); - - Repaint(); + myView->onViewCubeAxes(); } //---------------------------------------------------------------------------- @@ -719,18 +349,24 @@ SVTK_ViewWindow }*/ //---------------------------------------------------------------------------- +VTKViewer_Trihedron* SVTK_ViewWindow::GetTrihedron() +{ + return myView->GetTrihedron(); +} + +SVTK_CubeAxesActor2D* SVTK_ViewWindow::GetCubeAxes() +{ + return myView->GetCubeAxes(); +} + int SVTK_ViewWindow::GetTrihedronSize() const { - return myTrihedronSize; + return myView->GetTrihedronSize(); } void SVTK_ViewWindow::SetTrihedronSize( const int sz ) { - if ( myTrihedronSize == sz ) - return; - - myTrihedronSize = sz; - AdjustTrihedrons( true ); + myView->SetTrihedronSize( sz ); } /*! If parameter theIsForcedUpdate is true, recalculate parameters for @@ -740,74 +376,7 @@ void SVTK_ViewWindow ::AdjustTrihedrons(const bool theIsForcedUpdate) { - if ((!isCubeAxesDisplayed() && !isTrihedronDisplayed()) && !theIsForcedUpdate) - return; - - float bnd[ 6 ]; - float newbnd[6]; - newbnd[ 0 ] = newbnd[ 2 ] = newbnd[ 4 ] = VTK_LARGE_FLOAT; - newbnd[ 1 ] = newbnd[ 3 ] = newbnd[ 5 ] = -VTK_LARGE_FLOAT; - - myCubeAxes->GetBounds(bnd); - - int aVisibleNum = myTrihedron->GetVisibleActorCount( myRenderer ); - //if (aVisibleNum || theIsForcedUpdate) { - if (aVisibleNum) { - // if the new trihedron size have sufficient difference, then apply the value - double aNewSize = 100, anOldSize=myTrihedron->GetSize(); - bool aTDisplayed = isTrihedronDisplayed(); - bool aCDisplayed = isCubeAxesDisplayed(); - if(aTDisplayed) myTrihedron->VisibilityOff(); - if(aCDisplayed) myCubeAxes->VisibilityOff(); - - SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); - QString aSetting = aResMgr->stringValue("Viewer:TrihedronSize", "105"); - static float aSizeInPercents = aSetting.toFloat(); - - //bool isComputeTrihedronSize = - ::ComputeTrihedronSize(myRenderer, aNewSize, anOldSize, aSizeInPercents); - - myTrihedron->SetSize( aNewSize ); - - // iterate through displayed objects and set size if necessary - vtkActorCollection* anActors = getRenderer()->GetActors(); - anActors->InitTraversal(); - while (vtkActor* anActor = anActors->GetNextActor()) - { - if (SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast( anActor )) - { - if (aSActor->IsResizable()) - aSActor->SetSize( 0.5 * aNewSize ); - if (aSActor->GetVisibility() && !aSActor->IsInfinitive()) { - float *abounds = aSActor->GetBounds(); - if (abounds[0] > -VTK_LARGE_FLOAT && abounds[1] < VTK_LARGE_FLOAT && - abounds[2] > -VTK_LARGE_FLOAT && abounds[3] < VTK_LARGE_FLOAT && - abounds[4] > -VTK_LARGE_FLOAT && abounds[5] < VTK_LARGE_FLOAT) - for (int i = 0; i < 5; i = i + 2) { - if (abounds[i] < newbnd[i]) newbnd[i] = abounds[i]; - if (abounds[i+1] > newbnd[i+1]) newbnd[i+1] = abounds[i+1]; - } - } - } - } - if (aTDisplayed) myTrihedron->VisibilityOn(); - if (aCDisplayed) myCubeAxes->VisibilityOn(); - - } else { - double aSize = myTrihedron->GetSize(); - newbnd[0] = newbnd[2] = newbnd[4] = 0; - newbnd[1] = newbnd[3] = newbnd[5] = aSize; - } - - if (newbnd[0] < VTK_LARGE_FLOAT && newbnd[2] < VTK_LARGE_FLOAT && newbnd[4] < VTK_LARGE_FLOAT && - newbnd[1] >-VTK_LARGE_FLOAT && newbnd[3] >-VTK_LARGE_FLOAT && newbnd[5] >-VTK_LARGE_FLOAT) { - for(int i=0;i<6;i++) bnd[i] = newbnd[i]; - myCubeAxes->SetBounds(bnd); - } - - myCubeAxes->SetBounds(bnd); - - ::ResetCameraClippingRange(myRenderer); + myView->AdjustTrihedrons( theIsForcedUpdate ); } //---------------------------------------------------------------------------- @@ -815,14 +384,14 @@ void SVTK_ViewWindow ::onAdjustTrihedron() { - AdjustTrihedrons( false ); + myView->onAdjustTrihedron(); } void SVTK_ViewWindow ::onAdjustCubeAxes() { - AdjustTrihedrons(false); + myView->onAdjustCubeAxes(); } #define INCREMENT_FOR_OP 10 @@ -990,35 +559,23 @@ void SVTK_ViewWindow ::InsertActor( VTKViewer_Actor* theActor, bool theMoveInternalActors ) { - //cout << "SVTK_ViewWindow::InsertActor" << endl; - theActor->AddToRender(myRenderer); - - theActor->SetTransform(myTransform); - //if(theMoveInternalActors) - // myRWInteractor->MoveInternalActors(); + myView->InsertActor( theActor, theMoveInternalActors ); } //---------------------------------------------------------------------------- void SVTK_ViewWindow -::AddActor( VTKViewer_Actor* theActor, bool theUpdate /*=false*/ ) +::AddActor( VTKViewer_Actor* theActor, bool theUpdate ) { - InsertActor(theActor); - if(theUpdate) - Repaint(); + myView->AddActor( theActor, theUpdate ); } //---------------------------------------------------------------------------- void SVTK_ViewWindow -::RemoveActor( VTKViewer_Actor* theActor, bool theUpdate /*=false*/ ) +::RemoveActor( VTKViewer_Actor* theActor, bool theUpdate ) { - //cout << "SVTK_ViewWindow::RemoveActor" << endl; - theActor->RemoveFromRender(myRenderer); - - theActor->RemoveFromRender(myRenderer); - if(theUpdate) - Repaint(); + myView->RemoveActor( theActor, theUpdate ); } //---------------------------------------------------------------------------- @@ -1026,8 +583,7 @@ void SVTK_ViewWindow ::MoveActor( VTKViewer_Actor* theActor) { - RemoveActor(theActor); - InsertActor(theActor,true); + myView->MoveActor( theActor ); } //---------------------------------------------------------------------------- @@ -1035,10 +591,11 @@ QImage SVTK_ViewWindow ::dumpView() { - QPixmap px = QPixmap::grabWindow( myRenderWindow->winId() ); + QPixmap px = QPixmap::grabWindow( myView->winId() ); return px.convertToImage(); } +//---------------------------------------------------------------------------- void SVTK_ViewWindow ::SetSelectionProp(const double& theRed, @@ -1046,7 +603,7 @@ SVTK_ViewWindow const double& theBlue, const int& theWidth) { - vtkActorCollection* anActors = getRenderer()->GetActors(); + vtkActorCollection* anActors = myView->getRenderer()->GetActors(); anActors->InitTraversal(); while( vtkActor* anActor = anActors->GetNextActor() ) { @@ -1064,12 +621,13 @@ SVTK_ViewWindow } } +//---------------------------------------------------------------------------- void SVTK_ViewWindow ::SetSelectionTolerance(const double& theTolNodes, const double& theTolItems) { - vtkActorCollection* anActors = getRenderer()->GetActors(); + vtkActorCollection* anActors = myView->getRenderer()->GetActors(); anActors->InitTraversal(); while( vtkActor* anActor = anActors->GetNextActor() ) { diff --git a/src/SVTK/SVTK_ViewWindow.h b/src/SVTK/SVTK_ViewWindow.h index 4c7585b92..d598a25bb 100755 --- a/src/SVTK/SVTK_ViewWindow.h +++ b/src/SVTK/SVTK_ViewWindow.h @@ -6,48 +6,47 @@ #endif #include "SVTK.h" +#include "SVTK_View.h" +#include "SVTK_Selection.h" + #include "SUIT_ViewWindow.h" -#include "SVTK_Selection.h" #include "SALOME_InteractiveObject.hxx" -class vtkRenderer; - -class QtxAction; class SUIT_Desktop; -class VTKViewer_Trihedron; -class VTKViewer_Transform; - class VTKViewer_Actor; +class VTKViewer_Trihedron; class SVTK_Viewer; class SVTK_Selector; -class SVTK_CubeAxesActor2D; -class SVTK_RenderWindow; -class SVTK_InteractorStyle; -class SVTK_RenderWindowInteractor; +//class SVTK_View; +//class SVTK_RenderWindowInteractor; class SVTK_InteractorStyle; +class SVTK_CubeAxesActor2D; + +class vtkRenderer; class SVTK_EXPORT SVTK_ViewWindow : public SUIT_ViewWindow { - Q_OBJECT; + Q_OBJECT public: SVTK_ViewWindow( SUIT_Desktop*, SVTK_Viewer* ); virtual ~SVTK_ViewWindow(); - QToolBar* getToolBar() { return myToolBar; } - void setBackgroundColor( const QColor& ); QColor backgroundColor() const; - vtkRenderer* getRenderer() {return myRenderer;} + vtkRenderer* getRenderer(); SVTK_Selector* GetSelector() {return mySelector;} - SVTK_RenderWindow* getRenderWindow() {return myRenderWindow;} - SVTK_RenderWindowInteractor* getRWInteractor() {return myRWInteractor;} + + SVTK_View* getView() { return myView; } + SVTK_View* getRenderWindow() { return myView; } + SVTK_View* getRWInteractor() { return myView; } SVTK_InteractorStyle* getInteractorStyle(){ return myInteractorStyle;} + Selection_Mode SelectionMode() const; void SetSelectionMode(Selection_Mode theMode); @@ -85,12 +84,12 @@ public: //merge with V2_2_0_VISU_improvements:bool ComputeTrihedronSize( double& theNewSize, //merge with V2_2_0_VISU_improvements: double& theOldSize ); + VTKViewer_Trihedron* GetTrihedron(); + SVTK_CubeAxesActor2D* GetCubeAxes(); + int GetTrihedronSize() const; void SetTrihedronSize( const int ); - VTKViewer_Trihedron* GetTrihedron() {return this->myTrihedron;}; - SVTK_CubeAxesActor2D* GetCubeAxes() {return this->myCubeAxes;}; - void SetSelectionProp(const double& theRed = 1, const double& theGreen = 1, const double& theBlue = 0, @@ -111,7 +110,6 @@ public slots: void onBottomView(); void onRightView(); void onLeftView(); - void onResetView(); void onFitAll(); @@ -132,12 +130,6 @@ public slots: void onRotateUp(); void onRotateDown(); - void activateZoom(); - void activateWindowFit(); - void activateRotation(); - void activatePanning(); - void activateGlobalPanning(); - protected: QImage dumpView(); @@ -156,30 +148,12 @@ private: void MoveActor( VTKViewer_Actor* theActor ); private: - enum { DumpId, FitAllId, FitRectId, ZoomId, PanId, GlobalPanId, RotationId, - FrontId, BackId, TopId, BottomId, LeftId, RightId, ResetId, ViewTrihedronId }; - typedef QMap ActionsMap; - - void createActions(); - void createToolBar(); - - vtkRenderer* myRenderer; - SVTK_Viewer* myModel; SVTK_Selector* mySelector; - SVTK_RenderWindow* myRenderWindow; - SVTK_RenderWindowInteractor* myRWInteractor; + SVTK_View* myView; SVTK_InteractorStyle* myInteractorStyle; - VTKViewer_Transform* myTransform; - VTKViewer_Trihedron* myTrihedron; - int myTrihedronSize; - SVTK_CubeAxesActor2D* myCubeAxes; - - QToolBar* myToolBar; - ActionsMap myActionsMap; - double myCurScale; friend class SVTK_RenderWindowInteractor; -- 2.39.2