+// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
#include "SALOME_Actor.h"
#include <qapplication.h>
+#include <qimage.h>
#include <vtkTextProperty.h>
#include <vtkActorCollection.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkCamera.h>
+#include <vtkPointPicker.h>
+#include <vtkCellPicker.h>
+#include <vtkAxisActor2D.h>
#include "QtxAction.h"
#include "SUIT_Session.h"
#include "SUIT_ToolButton.h"
#include "SUIT_MessageBox.h"
+#include "SUIT_Accel.h"
#include "SUIT_Tools.h"
#include "SUIT_ResourceMgr.h"
+#include "SUIT_Accel.h"
-#include "VTKViewer_Transform.h"
#include "VTKViewer_Utilities.h"
-#include "SVTK_Trihedron.h"
-#include "SVTK_CubeAxesActor2D.h"
+#include "SVTK_View.h"
+#include "SVTK_MainWindow.h"
+#include "SVTK_Selector.h"
+
+#include "SVTK_Event.h"
+#include "SVTK_Renderer.h"
#include "SVTK_ViewWindow.h"
-#include "SVTK_ViewModel.h"
-#include "SVTK_RenderWindow.h"
-#include "SVTK_RenderWindowInteractor.h"
+#include "SVTK_ViewModelBase.h"
#include "SVTK_InteractorStyle.h"
+#include "SVTK_RenderWindowInteractor.h"
+#include "SVTK_GenericRenderWindowInteractor.h"
+#include "SVTK_CubeAxesActor2D.h"
#include "SALOME_ListIteratorOfListIO.hxx"
-#include "SVTK_SelectorDef.h"
-
#include "VTKViewer_Algorithm.h"
#include "SVTK_Functor.h"
-//----------------------------------------------------------------------------
+/*!
+ Constructor
+*/
SVTK_ViewWindow
-::SVTK_ViewWindow( SUIT_Desktop* theDesktop,
- SVTK_Viewer* theModel)
- : SUIT_ViewWindow( theDesktop ),
- myTrihedronSize( 100 )
-{
- 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() ;
-
- 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 );
+::SVTK_ViewWindow(SUIT_Desktop* theDesktop):
+ SUIT_ViewWindow(theDesktop),
+ myMainWindow(NULL),
+ myView(NULL)
+{}
- SVTK_InteractorStyle* RWS = SVTK_InteractorStyle::New();
- RWS->setGUIWindow( myRenderWindow );
- RWS->setViewWindow( this );
+/*!
+ To initialize #SVTK_ViewWindow instance
+*/
+void
+SVTK_ViewWindow
+::Initialize(SVTK_ViewModelBase* theModel)
+{
+ if(SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr()){
+ myMainWindow = new SVTK_MainWindow(this,"SVTK_MainWindow",aResourceMgr,this);
- myRWInteractor->SetInteractorStyle( RWS );
- myRWInteractor->Initialize();
+ SVTK_RenderWindowInteractor* anIteractor =
+ new SVTK_RenderWindowInteractor(myMainWindow,"SVTK_RenderWindowInteractor");
- //merge with V2_2_0_VISU_improvements:RWS->setTriedron( myTrihedron );
- RWS->FindPokedRenderer( 0, 0 );
+ SVTK_Selector* aSelector = SVTK_Selector::New();
- SetSelectionMode(ActorSelection);
+ SVTK_GenericRenderWindowInteractor* aDevice =
+ SVTK_GenericRenderWindowInteractor::New();
+ aDevice->SetRenderWidget(anIteractor);
+ aDevice->SetSelector(aSelector);
- 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 );
+ SVTK_Renderer* aRenderer = SVTK_Renderer::New();
+ aRenderer->Initialize(aDevice,aSelector);
- myToolBar = new QToolBar(this);
- myToolBar->setCloseMode(QDockWindow::Undocked);
- myToolBar->setLabel(tr("LBL_TOOLBAR_LABEL"));
+ anIteractor->Initialize(aDevice,aRenderer,aSelector);
- createActions();
- createToolBar();
+ aDevice->Delete();
+ aRenderer->Delete();
+ aSelector->Delete();
- connect( myRenderWindow, SIGNAL(KeyPressed( QKeyEvent* )),
- this, SLOT(onKeyPressed( QKeyEvent* )) );
- connect( myRenderWindow, SIGNAL(KeyReleased( QKeyEvent* )),
- this, SLOT(onKeyReleased( QKeyEvent* )) );
- connect( myRenderWindow, SIGNAL(MouseButtonPressed( QMouseEvent* )),
- this, SLOT(onMousePressed( QMouseEvent* )) );
- connect( myRenderWindow, SIGNAL(MouseButtonReleased( QMouseEvent* )),
- this, SLOT(onMouseReleased( QMouseEvent* )) );
- connect( myRenderWindow, SIGNAL(MouseDoubleClicked( QMouseEvent* )),
- this, SLOT(onMouseDoubleClicked( QMouseEvent* )) );
- connect( myRenderWindow, SIGNAL(MouseMove( QMouseEvent* )),
- this, SLOT(onMouseMoving( QMouseEvent* )) );
+ myMainWindow->Initialize(anIteractor);
- connect( myRWInteractor, SIGNAL(RenderWindowModified()),
- myRenderWindow, SLOT(update()) );
- connect( myRWInteractor, SIGNAL(contextMenuRequested( QContextMenuEvent * )),
- this, SIGNAL(contextMenuRequested( QContextMenuEvent * )) );
+ SVTK_InteractorStyle* aStyle = SVTK_InteractorStyle::New();
+ anIteractor->PushInteractorStyle(aStyle);
+ aStyle->Delete();
- onResetView();
+ setCentralWidget(myMainWindow);
+
+ myView = new SVTK_View(myMainWindow);
+ Initialize(myView,theModel);
+ }
}
-//----------------------------------------------------------------------------
+/*!
+ To initialize #SVTK_ViewWindow instance
+*/
+void
SVTK_ViewWindow
-::~SVTK_ViewWindow()
+::Initialize(SVTK_View* theView,
+ SVTK_ViewModelBase* theModel)
{
- 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();
+ connect(theView,SIGNAL(KeyPressed(QKeyEvent*)),
+ this,SLOT(onKeyPressed(QKeyEvent*)) );
+ connect(theView,SIGNAL(KeyReleased(QKeyEvent*)),
+ this,SLOT(onKeyReleased(QKeyEvent*)));
+ connect(theView,SIGNAL(MouseButtonPressed(QMouseEvent*)),
+ this,SLOT(onMousePressed(QMouseEvent*)));
+ connect(theView,SIGNAL(MouseButtonReleased(QMouseEvent*)),
+ this,SLOT(onMouseReleased(QMouseEvent*)));
+ connect(theView,SIGNAL(MouseDoubleClicked(QMouseEvent*)),
+ this,SLOT(onMouseDoubleClicked(QMouseEvent*)));
+ connect(theView,SIGNAL(MouseMove(QMouseEvent*)),
+ this,SLOT(onMouseMoving(QMouseEvent*)));
+ connect(theView,SIGNAL(contextMenuRequested(QContextMenuEvent*)),
+ this,SIGNAL(contextMenuRequested(QContextMenuEvent *)));
+ connect(theView,SIGNAL(selectionChanged()),
+ theModel,SLOT(onSelectionChanged()));
}
-//----------------------------------------------------------------------------
-void
+/*!
+ Destructor
+*/
SVTK_ViewWindow
-::activateZoom()
-{
- myRWInteractor->GetSInteractorStyle()->startZoom();
-}
+::~SVTK_ViewWindow()
+{}
-//----------------------------------------------------------------------------
-void
+
+/*!
+ \return corresponding view
+*/
+SVTK_View*
SVTK_ViewWindow
-::activatePanning()
-{
- myRWInteractor->GetSInteractorStyle()->startPan();
+::getView()
+{
+ return myView;
}
-//----------------------------------------------------------------------------
-void
+/*!
+ \return corresponding vtk main window
+*/
+SVTK_MainWindow*
SVTK_ViewWindow
-::activateRotation()
-{
- myRWInteractor->GetSInteractorStyle()->startRotate();
+::getMainWindow()
+{
+ return myMainWindow;
}
-//----------------------------------------------------------------------------
-void
+/*!
+ \return corresponding vtk render window
+*/
+vtkRenderWindow*
SVTK_ViewWindow
-::activateGlobalPanning()
+::getRenderWindow()
{
- if(myTrihedron->GetVisibleActorCount(myRenderer))
- myRWInteractor->GetSInteractorStyle()->startGlobalPan();
+ return getMainWindow()->getRenderWindow();
}
-//----------------------------------------------------------------------------
-void
+/*!
+ \return corresponding vtk render window interactor
+*/
+vtkRenderWindowInteractor*
SVTK_ViewWindow
-::activateWindowFit()
+::getInteractor()
{
- myRWInteractor->GetSInteractorStyle()->startFitArea();
+ return getMainWindow()->getInteractor();
}
-//----------------------------------------------------------------------------
-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
+/*!
+ \return corresponding vtk renderer
+*/
+vtkRenderer*
SVTK_ViewWindow
-::createToolBar()
+::getRenderer()
{
- 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]);
+ return myMainWindow->getRenderer();
+}
- myActionsMap[ResetId]->addTo(myToolBar);
+/*!
+ \return corresponding vtk selector
+*/
+SVTK_Selector*
+SVTK_ViewWindow
+::GetSelector()
+{
+ return myMainWindow->GetSelector();
}
-//----------------------------------------------------------------------------
+/*!
+ Processes transformation "front view"
+*/
void
SVTK_ViewWindow
::onFrontView()
{
- vtkCamera* camera = myRenderer->GetActiveCamera();
- camera->SetPosition(1,0,0);
- camera->SetViewUp(0,0,1);
- camera->SetFocalPoint(0,0,0);
- onFitAll();
+ myMainWindow->onFrontView();
}
-//----------------------------------------------------------------------------
+/*!
+ Processes transformation "back view"
+*/
void
SVTK_ViewWindow
::onBackView()
{
- vtkCamera* camera = myRenderer->GetActiveCamera();
- camera->SetPosition(-1,0,0);
- camera->SetViewUp(0,0,1);
- camera->SetFocalPoint(0,0,0);
- onFitAll();
+ myMainWindow->onBackView();
}
-//----------------------------------------------------------------------------
+/*!
+ Processes transformation "top view"
+*/
void
SVTK_ViewWindow
::onTopView()
{
- vtkCamera* camera = myRenderer->GetActiveCamera();
- camera->SetPosition(0,0,1);
- camera->SetViewUp(0,1,0);
- camera->SetFocalPoint(0,0,0);
- onFitAll();
+ myMainWindow->onTopView();
}
-//----------------------------------------------------------------------------
+/*!
+ Processes transformation "bottom view"
+*/
void
SVTK_ViewWindow
::onBottomView()
{
- vtkCamera* camera = myRenderer->GetActiveCamera();
- camera->SetPosition(0,0,-1);
- camera->SetViewUp(0,1,0);
- camera->SetFocalPoint(0,0,0);
- onFitAll();
+ myMainWindow->onBottomView();
}
-//----------------------------------------------------------------------------
+/*!
+ Processes transformation "left view"
+*/
void
SVTK_ViewWindow
::onLeftView()
{
- vtkCamera* camera = myRenderer->GetActiveCamera();
- camera->SetPosition(0,-1,0);
- camera->SetViewUp(0,0,1);
- camera->SetFocalPoint(0,0,0);
- onFitAll();
+ myMainWindow->onLeftView();
}
-//----------------------------------------------------------------------------
+/*!
+ Processes transformation "right view"
+*/
void
SVTK_ViewWindow
::onRightView()
{
- vtkCamera* camera = myRenderer->GetActiveCamera();
- camera->SetPosition(0,1,0);
- camera->SetViewUp(0,0,1);
- camera->SetFocalPoint(0,0,0);
- onFitAll();
+ myMainWindow->onRightView();
}
-//----------------------------------------------------------------------------
+/*!
+ Processes transformation "reset view": sets default orientation of viewport camera
+*/
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();
+ myMainWindow->onResetView();
}
-//----------------------------------------------------------------------------
+/*!
+ Processes transformation "fit all"
+*/
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();
+ myMainWindow->onFitAll();
}
-//----------------------------------------------------------------
+/*!
+ SLOT: called if selection is changed
+*/
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();
}
-//----------------------------------------------------------------
+/*!
+ Change selection mode
+ \param theMode - new selection mode
+*/
void
SVTK_ViewWindow
::SetSelectionMode(Selection_Mode theMode)
{
- mySelector->SetSelectionMode(theMode);
- myRWInteractor->SetSelectionMode(theMode);
+ myMainWindow->SetSelectionMode( theMode );
}
-//----------------------------------------------------------------
+/*!
+ \return selection mode
+*/
Selection_Mode
SVTK_ViewWindow
::SelectionMode() const
{
- return mySelector->SelectionMode();
+ return myMainWindow->SelectionMode();
}
-//----------------------------------------------------------------
+/*!
+ Unhilights all objects in viewer
+*/
void
SVTK_ViewWindow
::unHighlightAll()
{
- myRWInteractor->unHighlightAll();
+ myView->unHighlightAll();
}
-//----------------------------------------------------------------
+/*!
+ Hilights/unhilights object in viewer
+ \param theIO - object to be updated
+ \param theIsHighlight - if it is true, object will be hilighted, otherwise it will be unhilighted
+ \param theIsUpdate - update current viewer
+*/
void
SVTK_ViewWindow
-::highlight( const Handle(SALOME_InteractiveObject)& theIO,
- bool theIsHighlight,
- bool theIsUpdate )
+::highlight(const Handle(SALOME_InteractiveObject)& theIO,
+ bool theIsHighlight,
+ bool theIsUpdate )
{
- myRWInteractor->highlight(theIO, theIsHighlight, theIsUpdate);
-
- if(mySelector->HasIndex(theIO) && theIO->hasEntry()){
- TColStd_IndexedMapOfInteger aMapIndex;
- mySelector->GetIndex(theIO,aMapIndex);
- using namespace VTK;
- const char* anEntry = theIO->getEntry();
- vtkActorCollection* aCollection = myRenderer->GetActors();
- if(SALOME_Actor* anActor = Find<SALOME_Actor>(aCollection,TIsSameEntry<SALOME_Actor>(anEntry))){
- switch (mySelector->SelectionMode()) {
- case NodeSelection:
- myRWInteractor->highlightPoint(aMapIndex,anActor,theIsHighlight,theIsUpdate);
- break;
- case EdgeOfCellSelection:
- myRWInteractor->highlightEdge(aMapIndex,anActor,theIsHighlight,theIsUpdate);
- break;
- case CellSelection:
- case EdgeSelection:
- case FaceSelection:
- case VolumeSelection:
- myRWInteractor->highlightCell(aMapIndex,anActor,theIsHighlight,theIsUpdate);
- break;
- }
- }
- }else{
- myRWInteractor->unHighlightSubSelection();
- }
+ myView->highlight( theIO, theIsHighlight, theIsUpdate );
}
-//----------------------------------------------------------------
+/*!
+ \return true if object is in viewer or in collector
+ \param theIO - object to be checked
+*/
bool
SVTK_ViewWindow
::isInViewer( const Handle(SALOME_InteractiveObject)& theIO )
{
- return myRWInteractor->isInViewer( theIO );
+ return myView->isInViewer( theIO );
}
-//----------------------------------------------------------------
+/*!
+ \return true if object is displayed in viewer
+ \param theIO - object to be checked
+*/
bool
SVTK_ViewWindow
::isVisible( const Handle(SALOME_InteractiveObject)& theIO )
{
- return myRWInteractor->isVisible( theIO );
+ return myView->isVisible( theIO );
+}
+
+/*!
+ Display object
+ \param theEntry - entry that corresponds to intractive objects
+*/
+Handle(SALOME_InteractiveObject)
+SVTK_ViewWindow
+::FindIObject(const char* theEntry)
+{
+ return myView->FindIObject(theEntry);
+}
+
+/*!
+ Display object
+ \param theIO - object
+ \param theImmediatly - update viewer
+*/
+void
+SVTK_ViewWindow
+::Display(const Handle(SALOME_InteractiveObject)& theIO,
+ bool theImmediatly)
+{
+ myView->Display(theIO,theImmediatly);
+}
+
+/*!
+ Erase object
+ \param theIO - object
+ \param theImmediatly - update viewer
+*/
+void
+SVTK_ViewWindow
+::Erase(const Handle(SALOME_InteractiveObject)& theIO,
+ bool theImmediatly)
+{
+ myView->Erase(theIO,theImmediatly);
}
-//----------------------------------------------------------------------------
+/*!
+ Display only passed object
+ \param theIO - object
+*/
+void
+SVTK_ViewWindow
+::DisplayOnly(const Handle(SALOME_InteractiveObject)& theIO)
+{
+ myView->DisplayOnly(theIO);
+}
+
+/*!
+ Display all objects in view
+*/
+void
+SVTK_ViewWindow
+::DisplayAll()
+{
+ myView->DisplayAll();
+}
+
+/*!
+ Erase all objects in view
+*/
+void
+SVTK_ViewWindow
+::EraseAll()
+{
+ myView->EraseAll();
+}
+
+/*!
+ Sets background color
+ \param color - new background color
+*/
void
SVTK_ViewWindow
::setBackgroundColor( const QColor& color )
{
- if ( myRenderer )
- myRenderer->SetBackground( color.red()/255., color.green()/255., color.blue()/255. );
+ myMainWindow->SetBackgroundColor( color );
}
-//----------------------------------------------------------------------------
+/*!
+ \return background color of viewer
+*/
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 myMainWindow->BackgroundColor();
}
-//----------------------------------------------------------------------------
+/*!
+ Updates current viewer
+*/
void
SVTK_ViewWindow
::Repaint(bool theUpdateTrihedron)
{
- if (theUpdateTrihedron)
- onAdjustTrihedron();
- myRenderWindow->update();
+ myMainWindow->Repaint( theUpdateTrihedron );
}
-//----------------------------------------------------------------------------
+/*!
+ Redirect the request to #SVTK_Renderer::GetScale
+*/
void
SVTK_ViewWindow
::GetScale( double theScale[3] )
{
- myTransform->GetMatrixScale( theScale );
+ myMainWindow->GetScale( theScale );
}
-//----------------------------------------------------------------------------
+/*!
+ Redirect the request to #SVTK_Renderer::SetScale
+*/
void
SVTK_ViewWindow
::SetScale( double theScale[3] )
{
- myTransform->SetMatrixScale( theScale[0], theScale[1], theScale[2] );
- myRWInteractor->Render();
- Repaint();
+ myMainWindow->SetScale( theScale );
}
-//----------------------------------------------------------------------------
+/*!
+ Redirect the request to #SVTK_Renderer::IsTrihedronDisplayed
+*/
bool
SVTK_ViewWindow
::isTrihedronDisplayed()
{
- return myTrihedron->GetVisibility() == VTKViewer_Trihedron::eOn;
+ return myMainWindow->IsTrihedronDisplayed();
}
+/*!
+ Redirect the request to #SVTK_Renderer::IsCubeAxesDisplayed
+*/
bool
SVTK_ViewWindow
::isCubeAxesDisplayed()
{
- return myCubeAxes->GetVisibility() == 1;
+ return myMainWindow->IsCubeAxesDisplayed();
}
-//----------------------------------------------------------------------------
+/*!
+ Redirect the request to #SVTK_Renderer::OnViewTrihedron
+*/
void
SVTK_ViewWindow
::onViewTrihedron()
{
- if(!myTrihedron)
- return;
-
- if(isTrihedronDisplayed())
- myTrihedron->VisibilityOff();
- else
- myTrihedron->VisibilityOn();
-
- Repaint();
+ myMainWindow->onViewTrihedron();
}
+/*!
+ Redirect the request to #SVTK_Renderer::OnViewCubeAxes
+*/
void
SVTK_ViewWindow
::onViewCubeAxes()
{
- if(!myCubeAxes)
- return;
-
- if(isCubeAxesDisplayed())
- myCubeAxes->VisibilityOff();
- else
- myCubeAxes->VisibilityOn();
+ myMainWindow->onViewCubeAxes();
+}
- Repaint();
+/*!
+ Redirect the request to #SVTK_Renderer::GetTrihedron
+*/
+VTKViewer_Trihedron*
+SVTK_ViewWindow::
+GetTrihedron()
+{
+ return myMainWindow->GetTrihedron();
}
-//----------------------------------------------------------------------------
-/*bool
+/*!
+ Redirect the request to #SVTK_Renderer::GetCubeAxes
+*/
+SVTK_CubeAxesActor2D*
SVTK_ViewWindow
-::ComputeTrihedronSize( double& theNewSize, double& theSize )
+::GetCubeAxes()
{
- // calculating diagonal of visible props of the renderer
- float aBndBox[ 6 ];
- myTrihedron->VisibilityOff();
-
- if ( ::ComputeVisiblePropBounds( myRenderer, aBndBox ) == 0 ) {
- aBndBox[ 1 ] = aBndBox[ 3 ] = aBndBox[ 5 ] = 100;
- aBndBox[ 0 ] = aBndBox[ 2 ] = aBndBox[ 4 ] = 0;
- }
-
- myTrihedron->VisibilityOn();
- float aLength = 0;
- static bool aCalcByDiag = false;
- if ( aCalcByDiag ) {
- aLength = sqrt( ( aBndBox[1]-aBndBox[0])*(aBndBox[1]-aBndBox[0] )+
- ( aBndBox[3]-aBndBox[2])*(aBndBox[3]-aBndBox[2] )+
- ( aBndBox[5]-aBndBox[4])*(aBndBox[5]-aBndBox[4] ) );
- } else {
- aLength = aBndBox[ 1 ]-aBndBox[ 0 ];
- aLength = max( ( aBndBox[ 3 ] - aBndBox[ 2 ] ),aLength );
- aLength = max( ( aBndBox[ 5 ] - aBndBox[ 4 ] ),aLength );
- }
-
- float aSizeInPercents = myTrihedronSize;
-
- static float EPS_SIZE = 5.0E-3;
- theSize = myTrihedron->GetSize();
- theNewSize = aLength * aSizeInPercents / 100.0;
-
- // if the new trihedron size have sufficient difference, then apply the value
- return fabs( theNewSize - theSize) > theSize * EPS_SIZE ||
- fabs( theNewSize-theSize ) > theNewSize * EPS_SIZE;
-}*/
+ return myMainWindow->GetCubeAxes();
+}
-//----------------------------------------------------------------------------
-int SVTK_ViewWindow::GetTrihedronSize() const
+/*!
+ \return trihedron size
+*/
+int
+SVTK_ViewWindow
+::GetTrihedronSize() const
{
- return myTrihedronSize;
+ return myMainWindow->GetTrihedronSize();
}
-void SVTK_ViewWindow::SetTrihedronSize( const int sz )
+/*!
+ Sets trihedron size
+ \param theSize - new trihedron size
+ \param theRelative - trihedron relativeness
+*/
+void
+SVTK_ViewWindow
+::SetTrihedronSize(const int theSize, const bool theRelative)
{
- if ( myTrihedronSize == sz )
- return;
-
- myTrihedronSize = sz;
- AdjustTrihedrons( true );
+ myMainWindow->SetTrihedronSize(theSize, theRelative);
}
/*! If parameter theIsForcedUpdate is true, recalculate parameters for
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);
+ myMainWindow->AdjustActors();
}
-//----------------------------------------------------------------------------
+/*!
+ Redirect the request to #SVTK_Renderer::OnAdjustTrihedron
+*/
void
SVTK_ViewWindow
::onAdjustTrihedron()
{
- AdjustTrihedrons( false );
+ myMainWindow->onAdjustTrihedron();
}
+/*!
+ Redirect the request to #SVTK_Renderer::OnAdjustCubeAxes
+*/
void
SVTK_ViewWindow
::onAdjustCubeAxes()
{
- AdjustTrihedrons(false);
+ myMainWindow->onAdjustCubeAxes();
}
-#define INCREMENT_FOR_OP 10
-
-//=======================================================================
-// name : onPanLeft
-// Purpose : Performs incremental panning to the left
-//=======================================================================
+/*!
+ Emits key pressed
+*/
void
SVTK_ViewWindow
-::onPanLeft()
+::onKeyPressed(QKeyEvent* event)
{
- myRWInteractor->GetSInteractorStyle()->IncrementalPan( -INCREMENT_FOR_OP, 0 );
+ emit keyPressed( this, event );
}
-//=======================================================================
-// name : onPanRight
-// Purpose : Performs incremental panning to the right
-//=======================================================================
+/*!
+ Emits key released
+*/
void
SVTK_ViewWindow
-::onPanRight()
+::onKeyReleased(QKeyEvent* event)
{
- myRWInteractor->GetSInteractorStyle()->IncrementalPan( INCREMENT_FOR_OP, 0 );
+ emit keyReleased( this, event );
}
-//=======================================================================
-// name : onPanUp
-// Purpose : Performs incremental panning to the top
-//=======================================================================
+/*!
+ Emits mouse pressed
+*/
void
SVTK_ViewWindow
-::onPanUp()
+::onMousePressed(QMouseEvent* event)
{
- myRWInteractor->GetSInteractorStyle()->IncrementalPan( 0, INCREMENT_FOR_OP );
+ emit mousePressed(this, event);
}
-//=======================================================================
-// name : onPanDown
-// Purpose : Performs incremental panning to the bottom
-//=======================================================================
+/*!
+ Emits mouse released
+*/
void
SVTK_ViewWindow
-::onPanDown()
+::onMouseReleased(QMouseEvent* event)
{
- myRWInteractor->GetSInteractorStyle()->IncrementalPan( 0, -INCREMENT_FOR_OP );
+ emit mouseReleased( this, event );
}
-//=======================================================================
-// name : onZoomIn
-// Purpose : Performs incremental zooming in
-//=======================================================================
+/*!
+ Emits mouse moving
+*/
void
SVTK_ViewWindow
-::onZoomIn()
+::onMouseMoving(QMouseEvent* event)
{
- myRWInteractor->GetSInteractorStyle()->IncrementalZoom( INCREMENT_FOR_OP );
+ emit mouseMoving( this, event );
}
-//=======================================================================
-// name : onZoomOut
-// Purpose : Performs incremental zooming out
-//=======================================================================
+/*!
+ Emits mouse double clicked
+*/
void
SVTK_ViewWindow
-::onZoomOut()
+::onMouseDoubleClicked( QMouseEvent* event )
{
- myRWInteractor->GetSInteractorStyle()->IncrementalZoom( -INCREMENT_FOR_OP );
+ emit mouseDoubleClicked( this, event );
}
-//=======================================================================
-// name : onRotateLeft
-// Purpose : Performs incremental rotating to the left
-//=======================================================================
+/*!
+ Redirect the request to #SVTK_Renderer::AddActor
+*/
void
SVTK_ViewWindow
-::onRotateLeft()
+::AddActor( VTKViewer_Actor* theActor,
+ bool theUpdate )
{
- myRWInteractor->GetSInteractorStyle()->IncrementalRotate( -INCREMENT_FOR_OP, 0 );
+ myMainWindow->AddActor( theActor, theUpdate );
}
-//=======================================================================
-// name : onRotateRight
-// Purpose : Performs incremental rotating to the right
-//=======================================================================
+/*!
+ Redirect the request to #SVTK_Renderer::RemoveActor
+*/
void
SVTK_ViewWindow
-::onRotateRight()
+::RemoveActor( VTKViewer_Actor* theActor,
+ bool theUpdate )
{
- myRWInteractor->GetSInteractorStyle()->IncrementalRotate( INCREMENT_FOR_OP, 0 );
+ myMainWindow->RemoveActor( theActor, theUpdate );
}
-//=======================================================================
-// name : onRotateUp
-// Purpose : Performs incremental rotating to the top
-//=======================================================================
-void
+/*!
+ \return QImage, containing all scene rendering in window
+*/
+QImage
SVTK_ViewWindow
-::onRotateUp()
+::dumpView()
{
- myRWInteractor->GetSInteractorStyle()->IncrementalRotate( 0, -INCREMENT_FOR_OP );
+ return myMainWindow->dumpView();
}
-//=======================================================================
+/*!
+ Redirect the request to #SVTK_Renderer::SetSelectionProp
+*/
void
SVTK_ViewWindow
-::onKeyPressed(QKeyEvent* event)
+::SetSelectionProp(const double& theRed,
+ const double& theGreen,
+ const double& theBlue,
+ const int& theWidth)
{
- emit keyPressed( this, event );
+ myView->SetSelectionProp(theRed,theGreen,theBlue,theWidth);
}
-//=======================================================================
+/*!
+ Redirect the request to #SVTK_Renderer::SetSelectionProp
+*/
void
SVTK_ViewWindow
-::onKeyReleased(QKeyEvent* event)
+::SetPreselectionProp(const double& theRed,
+ const double& theGreen,
+ const double& theBlue,
+ const int& theWidth)
{
- emit keyReleased( this, event );
+ myView->SetPreselectionProp(theRed,theGreen,theBlue,theWidth);
}
-//=======================================================================
+/*!
+ Redirect the request to #SVTK_Renderer::SetSelectionTolerance
+*/
void
SVTK_ViewWindow
-::onMousePressed(QMouseEvent* event)
+::SetSelectionTolerance(const double& theTolNodes,
+ const double& theTolItems)
{
- emit mousePressed(this, event);
+ myView->SetSelectionTolerance(theTolNodes,theTolItems);
}
-//=======================================================================
-void
-SVTK_ViewWindow
-::onMouseReleased(QMouseEvent* event)
+int convertAction( const int accelAction )
{
- emit mouseReleased( this, event );
+ switch ( accelAction ) {
+ case SUIT_Accel::PanLeft : return SVTK::PanLeftEvent;
+ case SUIT_Accel::PanRight : return SVTK::PanRightEvent;
+ case SUIT_Accel::PanUp : return SVTK::PanUpEvent;
+ case SUIT_Accel::PanDown : return SVTK::PanDownEvent;
+ case SUIT_Accel::ZoomIn : return SVTK::ZoomInEvent;
+ case SUIT_Accel::ZoomOut : return SVTK::ZoomOutEvent;
+ case SUIT_Accel::RotateLeft : return SVTK::RotateLeftEvent;
+ case SUIT_Accel::RotateRight : return SVTK::RotateRightEvent;
+ case SUIT_Accel::RotateUp : return SVTK::RotateUpEvent;
+ case SUIT_Accel::RotateDown : return SVTK::RotateDownEvent;
+ }
+ return accelAction;
}
-//=======================================================================
-void
+/*!
+ Performs action
+ \param accelAction - action
+*/
+bool
SVTK_ViewWindow
-::onMouseMoving(QMouseEvent* event)
+::action( const int accelAction )
{
- emit mouseMoving( this, event );
+ if ( !myMainWindow->hasFocus() )
+ return false;
+ if ( accelAction == SUIT_Accel::ZoomFit )
+ onFitAll();
+ else {
+ int anEvent = convertAction( accelAction );
+ myMainWindow->InvokeEvent( anEvent, 0 );
+ }
+ return true;
}
-//=======================================================================
-void
-SVTK_ViewWindow
-::onMouseDoubleClicked( QMouseEvent* event )
-{
- emit mouseDoubleClicked( this, event );
-}
+// old visual parameters had 13 values. New format added additional
+// 76 values for graduated axes, so both numbers are processed.
+const int nNormalParams = 13; // number of view windows parameters excluding graduated axes params
+const int nGradAxisParams = 25; // number of parameters of ONE graduated axis (X, Y, or Z)
+const int nAllParams = nNormalParams + 3*nGradAxisParams + 1; // number of all visual parameters
-//=======================================================================
-// name : onRotateDown
-// Purpose : Performs incremental rotating to the bottom
-//=======================================================================
-void
-SVTK_ViewWindow
-::onRotateDown()
-{
- myRWInteractor->GetSInteractorStyle()->IncrementalRotate( 0, INCREMENT_FOR_OP );
+/*! The method returns visual parameters of a graduated axis actor (x,y,z axis of graduated axes)
+ */
+QString getGradAxisVisualParams( vtkAxisActor2D* actor )
+{
+ QString params;
+ if ( !actor )
+ return params;
+
+ // Name
+ bool isVisible = actor->GetTitleVisibility();
+ QString title ( actor->GetTitle() );
+ vtkFloatingPointType color[ 3 ];
+ int font = VTK_ARIAL;
+ int bold = 0;
+ int italic = 0;
+ int shadow = 0;
+
+ vtkTextProperty* txtProp = actor->GetTitleTextProperty();
+ if ( txtProp )
+ {
+ txtProp->GetColor( color );
+ font = txtProp->GetFontFamily();
+ bold = txtProp->GetBold();
+ italic = txtProp->GetItalic();
+ shadow = txtProp->GetShadow();
+ }
+ params.sprintf( "* Graduated Axis: * Name *%u*%s*%.2f*%.2f*%.2f*%u*%u*%u*%u", isVisible,
+ title.latin1(), color[0], color[1], color[2], font, bold, italic, shadow );
+
+ // Labels
+ isVisible = actor->GetLabelVisibility();
+ int labels = actor->GetNumberOfLabels();
+ int offset = actor->GetTickOffset();
+ font = VTK_ARIAL;
+ bold = false;
+ italic = false;
+ shadow = false;
+
+ txtProp = actor->GetLabelTextProperty();
+ if ( txtProp )
+ {
+ txtProp->GetColor( color );
+ font = txtProp->GetFontFamily();
+ bold = txtProp->GetBold();
+ italic = txtProp->GetItalic();
+ shadow = txtProp->GetShadow();
+ }
+ params += QString().sprintf( "* Labels *%u*%u*%u*%.2f*%.2f*%.2f*%u*%u*%u*%u", isVisible, labels, offset,
+ color[0], color[1], color[2], font, bold, italic, shadow );
+
+ // Tick marks
+ isVisible = actor->GetTickVisibility();
+ int length = actor->GetTickLength();
+
+ params += QString().sprintf( "* Tick marks *%u*%u", isVisible, length );
+
+ return params;
}
-//----------------------------------------------------------------------------
-void
-SVTK_ViewWindow
-::InsertActor( SALOME_Actor* theActor, bool theMoveInternalActors )
+/*! The method restores visual parameters of a graduated axis actor (x,y,z axis)
+ */
+void setGradAxisVisualParams( vtkAxisActor2D* actor, const QString& params )
{
- theActor->AddToRender(myRenderer);
- theActor->SetTransform(myTransform);
- if(theMoveInternalActors)
- myRWInteractor->MoveInternalActors();
+ if ( !actor )
+ return;
+
+ QStringList paramsLst = QStringList::split( '*', params, true );
+
+ if ( paramsLst.size() == nGradAxisParams ) { // altogether name, lable, ticks parameters make up 25 values
+
+ // retrieve and set name parameters
+ bool isVisible = paramsLst[2].toUShort();
+ QString title = paramsLst[3];
+ vtkFloatingPointType color[3];
+ color[0] = paramsLst[4].toDouble();
+ color[1] = paramsLst[5].toDouble();
+ color[2] = paramsLst[6].toDouble();
+ int font = paramsLst[7].toInt();
+ int bold = paramsLst[8].toInt();
+ int italic = paramsLst[9].toInt();
+ int shadow = paramsLst[10].toInt();
+
+ actor->SetTitleVisibility( isVisible );
+ actor->SetTitle( title.latin1() );
+ vtkTextProperty* txtProp = actor->GetTitleTextProperty();
+ if ( txtProp ) {
+ txtProp->SetColor( color );
+ txtProp->SetFontFamily( font );
+ txtProp->SetBold( bold );
+ txtProp->SetItalic( italic );
+ txtProp->SetShadow( shadow );
+ }
+
+ // retrieve and set lable parameters
+ isVisible = paramsLst[12].toUShort();
+ int labels = paramsLst[13].toInt();
+ int offset = paramsLst[14].toInt();
+ color[0] = paramsLst[15].toDouble();
+ color[1] = paramsLst[16].toDouble();
+ color[2] = paramsLst[17].toDouble();
+ font = paramsLst[18].toInt();
+ bold = paramsLst[19].toInt();
+ italic = paramsLst[20].toInt();
+ shadow = paramsLst[21].toInt();
+
+ actor->SetLabelVisibility( isVisible );
+ actor->SetNumberOfLabels( labels );
+ actor->SetTickOffset( offset );
+ txtProp = actor->GetLabelTextProperty();
+ if ( txtProp ) {
+ txtProp->SetColor( color );
+ txtProp->SetFontFamily( font );
+ txtProp->SetBold( bold );
+ txtProp->SetItalic( italic );
+ txtProp->SetShadow( shadow );
+ }
+
+ // retrieve and set tick marks properties
+ isVisible = paramsLst[23].toUShort();
+ int length = paramsLst[24].toInt();
+
+ actor->SetTickVisibility( isVisible );
+ actor->SetTickLength( length );
+ }
}
-//----------------------------------------------------------------------------
-void
+/*! The method returns the visual parameters of this view as a formated string
+ */
+QString
SVTK_ViewWindow
-::AddActor( SALOME_Actor* theActor, bool theUpdate /*=false*/ )
+::getVisualParameters()
{
- InsertActor(theActor);
- if(theUpdate)
- Repaint();
+ double pos[3], focalPnt[3], viewUp[3], parScale, scale[3];
+
+ // save position, focal point, viewUp, scale
+ vtkCamera* camera = getRenderer()->GetActiveCamera();
+ camera->GetPosition( pos );
+ camera->GetFocalPoint( focalPnt );
+ camera->GetViewUp( viewUp );
+ parScale = camera->GetParallelScale();
+ GetScale( scale );
+
+ // Parameters are given in the following format:view position (3 digits), focal point position (3 digits)
+ // view up values (3 digits), parallel scale (1 digit), scale (3 digits,
+ // Graduated axes parameters (X, Y, Z axes parameters)
+ QString retStr;
+ retStr.sprintf( "%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e",
+ pos[0], pos[1], pos[2], focalPnt[0], focalPnt[1], focalPnt[2],
+ viewUp[0], viewUp[1], viewUp[2], parScale, scale[0], scale[1], scale[2] );
+
+ // save graduated axes parameters
+ if ( SVTK_CubeAxesActor2D* gradAxesActor = GetCubeAxes() ) {
+ retStr += QString( "*%1" ).arg( getMainWindow()->IsCubeAxesDisplayed() );
+ retStr += ::getGradAxisVisualParams( gradAxesActor->GetXAxisActor2D() );
+ retStr += ::getGradAxisVisualParams( gradAxesActor->GetYAxisActor2D() );
+ retStr += ::getGradAxisVisualParams( gradAxesActor->GetZAxisActor2D() );
+ }
+
+ return retStr;
}
-//----------------------------------------------------------------------------
+/*!
+ The method restores visual parameters of this view or postpones it untill the view is shown
+*/
void
SVTK_ViewWindow
-::RemoveActor( SALOME_Actor* theActor, bool theUpdate /*=false*/ )
+::setVisualParameters( const QString& parameters )
{
- theActor->RemoveFromRender(myRenderer);
- if(theUpdate)
- Repaint();
+ SVTK_RenderWindowInteractor* anInteractor = getMainWindow()->GetInteractor();
+ if ( anInteractor->isVisible() ) {
+ doSetVisualParameters( parameters );
+ }
+ else {
+ myVisualParams = parameters;
+ anInteractor->installEventFilter(this);
+ }
}
-//----------------------------------------------------------------------------
-void
-SVTK_ViewWindow
-::MoveActor( SALOME_Actor* theActor)
-{
- RemoveActor(theActor);
- InsertActor(theActor,true);
+/*!
+ The method restores visual parameters of this view from a formated string
+*/
+void
+SVTK_ViewWindow
+::doSetVisualParameters( const QString& parameters )
+{
+ QStringList paramsLst = QStringList::split( '*', parameters, true );
+ if ( paramsLst.size() >= nNormalParams ) {
+ // 'reading' list of parameters
+ double pos[3], focalPnt[3], viewUp[3], parScale, scale[3];
+ pos[0] = paramsLst[0].toDouble();
+ pos[1] = paramsLst[1].toDouble();
+ pos[2] = paramsLst[2].toDouble();
+ focalPnt[0] = paramsLst[3].toDouble();
+ focalPnt[1] = paramsLst[4].toDouble();
+ focalPnt[2] = paramsLst[5].toDouble();
+ viewUp[0] = paramsLst[6].toDouble();
+ viewUp[1] = paramsLst[7].toDouble();
+ viewUp[2] = paramsLst[8].toDouble();
+ parScale = paramsLst[9].toDouble();
+ scale[0] = paramsLst[10].toDouble();
+ scale[1] = paramsLst[11].toDouble();
+ scale[2] = paramsLst[12].toDouble();
+
+ // applying parameters
+ vtkCamera* camera = getRenderer()->GetActiveCamera();
+ camera->SetPosition( pos );
+ camera->SetFocalPoint( focalPnt );
+ camera->SetViewUp( viewUp );
+ camera->SetParallelScale( parScale );
+ SetScale( scale );
+
+ // apply graduated axes parameters
+ SVTK_CubeAxesActor2D* gradAxesActor = GetCubeAxes();
+ if ( gradAxesActor && paramsLst.size() == nAllParams ) {
+
+ int i = nNormalParams+1, j = i + nGradAxisParams - 1;
+ ::setGradAxisVisualParams( gradAxesActor->GetXAxisActor2D(), parameters.section( '*', i, j ) );
+ i = j + 1; j += nGradAxisParams;
+ ::setGradAxisVisualParams( gradAxesActor->GetYAxisActor2D(), parameters.section( '*', i, j ) );
+ i = j + 1; j += nGradAxisParams;
+ ::setGradAxisVisualParams( gradAxesActor->GetZAxisActor2D(), parameters.section( '*', i, j ) );
+
+ if ( paramsLst[13].toUShort() )
+ gradAxesActor->VisibilityOn();
+ else
+ gradAxesActor->VisibilityOff();
+ }
+ }
}
-//----------------------------------------------------------------------------
-QImage
-SVTK_ViewWindow
-::dumpView()
+
+/*!
+ Delayed setVisualParameters
+*/
+bool SVTK_ViewWindow::eventFilter( QObject* theWatched, QEvent* theEvent )
{
- QPixmap px = QPixmap::grabWindow( myRenderWindow->winId() );
- return px.convertToImage();
+ if ( theEvent->type() == QEvent::Show && theWatched->inherits( "SVTK_RenderWindowInteractor" ) ) {
+ SVTK_RenderWindowInteractor* anInteractor = (SVTK_RenderWindowInteractor*)theWatched;
+ if ( anInteractor->isVisible() ) {
+ doSetVisualParameters( myVisualParams );
+ anInteractor->removeEventFilter( this ); // theWatched = RenderWindowInteractor
+ }
+ }
+ return SUIT_ViewWindow::eventFilter( theWatched, theEvent );
}