+// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// 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, or (at your option) any later version.
+//
+// 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 "SVTK_NonIsometricDlg.h"
+#include "SVTK_UpdateRateDlg.h"
+#include "SVTK_CubeAxesDlg.h"
+#include "SVTK_SetRotationPointDlg.h"
+#include "SVTK_ViewParameterDlg.h"
+#include "SVTK_ViewModel.h"
+#include "VTKViewer_Texture.h"
+#include "VTKViewer_OpenGLRenderer.h"
+
#include "SALOME_Actor.h"
-#include <qapplication.h>
+#include <QMenu>
+#include <QToolBar>
+#include <QEvent>
+#include <QFileInfo>
+#include <QSignalMapper>
+#include <QXmlStreamWriter>
+#include <QXmlStreamReader>
+#include <QXmlStreamAttributes>
#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 <vtkGL2PSExporter.h>
+#include <vtkInteractorStyle.h>
+#include <vtkProperty.h>
+#include <vtkCallbackCommand.h>
+#include <vtkJPEGReader.h>
+#include <vtkBMPReader.h>
+#include <vtkTIFFReader.h>
+#include <vtkPNGReader.h>
+#include <vtkMetaImageReader.h>
+#include <vtkImageMapToColors.h>
+#include <vtkTexture.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 "SUIT_OverrideCursor.h"
+#include "SUIT_ViewManager.h"
+#include "QtxActionToolMgr.h"
+#include "QtxMultiAction.h"
+#include "QtxActionGroup.h"
-#include "VTKViewer_Transform.h"
#include "VTKViewer_Utilities.h"
+#include "VTKViewer_Trihedron.h"
-#include "SVTK_Trihedron.h"
-#include "SVTK_CubeAxesActor2D.h"
+#include "SVTK_View.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_InteractorStyle.h"
+#include "SVTK_RenderWindowInteractor.h"
+#include "SVTK_GenericRenderWindowInteractor.h"
+#include "SVTK_CubeAxesActor2D.h"
+#include "SVTK_ComboAction.h"
+#include "SVTK_KeyFreeInteractorStyle.h"
+#include "SVTK_Selector.h"
+#include "SVTK_Recorder.h"
+#include "SVTK_RecorderDlg.h"
-#include "SALOME_ListIteratorOfListIO.hxx"
+#include "vtkPVAxesWidget.h"
+#include "vtkPVAxesActor.h"
-#include "SVTK_SelectorDef.h"
+#include "SALOME_ListIteratorOfListIO.hxx"
#include "VTKViewer_Algorithm.h"
#include "SVTK_Functor.h"
-//----------------------------------------------------------------------------
-SVTK_ViewWindow
-::SVTK_ViewWindow( SUIT_Desktop* theDesktop,
- SVTK_Viewer* theModel)
- : SUIT_ViewWindow( theDesktop ),
- myTrihedronSize( 100 )
+#include <OpenGLUtils_FrameBuffer.h>
+
+
+namespace SVTK
{
- myModel = theModel;
- mySelector = new SVTK_SelectorDef();
- connect(this,SIGNAL(selectionChanged()),theModel,SLOT(onSelectionChanged()));
+ int convertAction( const int accelAction )
+ {
+ 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;
+ }
+}
- 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();
+/*!
+ Constructor
+*/
+SVTK_ViewWindow::SVTK_ViewWindow(SUIT_Desktop* theDesktop):
+ SUIT_ViewWindow(theDesktop),
+ myView(NULL),
+ myDumpImage(QImage()),
+ myKeyFreeInteractorStyle(SVTK_KeyFreeInteractorStyle::New()),
+ myEventCallbackCommand(vtkCallbackCommand::New())
+{
+ setWindowFlags( windowFlags() & ~Qt::Window );
+ // specific of vtkSmartPointer
+ myKeyFreeInteractorStyle->Delete();
+}
+
+/*!
+ To initialize #SVTK_ViewWindow instance
+*/
+void SVTK_ViewWindow::Initialize(SVTK_ViewModelBase* theModel)
+{
+ myModel = theModel;
+ myInteractor = new SVTK_RenderWindowInteractor(this,"SVTK_RenderWindowInteractor");
+
+ SVTK_Selector* aSelector = SVTK_Selector::New();
+ int aPreselectionMode = SUIT_Session::session()->resourceMgr()->
+ integerValue( "VTKViewer", "preselection", Standard_Preselection );
+ aSelector->SetDynamicPreSelection( aPreselectionMode == Dynamic_Preselection );
+ aSelector->SetPreSelectionEnabled( aPreselectionMode != Preselection_Disabled );
+ bool isSelectionEnabled = SUIT_Session::session()->resourceMgr()->
+ booleanValue( "VTKViewer", "enable_selection", true );
+ aSelector->SetSelectionEnabled( isSelectionEnabled );
+
+ SVTK_GenericRenderWindowInteractor* aDevice = SVTK_GenericRenderWindowInteractor::New();
+ aDevice->SetRenderWidget(myInteractor);
+ aDevice->SetSelector(aSelector);
+
+ SVTK_Renderer* aRenderer = SVTK_Renderer::New();
+ aRenderer->Initialize(aDevice,aSelector);
+
+ myInteractor->Initialize(aDevice,aRenderer,aSelector);
+
+ aDevice->Delete();
+ aRenderer->Delete();
+ aSelector->Delete();
+
+ myToolBar = toolMgr()->createToolBar( tr("LBL_TOOLBAR_LABEL"), false, Qt::AllToolBarAreas, -1, this );
+ myRecordingToolBar = toolMgr()->createToolBar( tr("LBL_TOOLBAR_RECORD_LABEL"), false, Qt::AllToolBarAreas, -1, this );
+
+ createActions( SUIT_Session::session()->resourceMgr() );
+ createToolBar();
+
+ SetEventDispatcher(myInteractor->GetDevice());
+ myInteractor->setBackgroundRole( QPalette::NoRole );//NoBackground
+ myInteractor->setFocusPolicy(Qt::StrongFocus);
+ myInteractor->setFocus();
+ setFocusProxy(myInteractor);
+
+ myUpdateRateDlg = new SVTK_UpdateRateDlg( getAction( UpdateRate ), this, "SVTK_UpdateRateDlg" );
+ myNonIsometricDlg = new SVTK_NonIsometricDlg( getAction( NonIsometric ), this, "SVTK_NonIsometricDlg" );
+ myCubeAxesDlg = new SVTK_CubeAxesDlg( getAction( GraduatedAxes ), this, "SVTK_CubeAxesDlg" );
+ myCubeAxesDlg->initialize();
+ mySetRotationPointDlg = new SVTK_SetRotationPointDlg
+ ( getAction( ChangeRotationPointId ), this, "SVTK_SetRotationPointDlg" );
+ myViewParameterDlg = new SVTK_ViewParameterDlg
+ ( getAction( ViewParametersId ), this, "SVTK_ViewParameterDlg" );
+
+ myDefaultInteractorStyle = SVTK_InteractorStyle::New();
+ myInteractor->PushInteractorStyle(myDefaultInteractorStyle);
+ myDefaultInteractorStyle->Delete();
+
+ myRecorder = SVTK_Recorder::New();
+
+ myRecorder->SetNbFPS( 17.3 );
+ myRecorder->SetQuality( 100 );
+ myRecorder->SetProgressiveMode( true );
+ myRecorder->SetUseSkippedFrames( true );
+ myRecorder->SetRenderWindow( myInteractor->getRenderWindow() );
+
+ setCentralWidget(myInteractor);
+
+ myAxesWidget = vtkPVAxesWidget::New();
+ myAxesWidget->SetParentRenderer(aRenderer->GetDevice());
+ myAxesWidget->SetViewport(0, 0, 0.25, 0.25);
+ myAxesWidget->SetInteractor(myInteractor->GetDevice());
+ myAxesWidget->SetEnabled(1);
+ myAxesWidget->SetInteractive(0);
+
+ vtkPVAxesActor* anAxesActor = myAxesWidget->GetAxesActor();
+ anAxesActor->GetXAxisTipProperty()->SetColor( 1.0, 0.0, 0.0 );
+ anAxesActor->GetXAxisShaftProperty()->SetColor( 1.0, 0.0, 0.0 );
+ anAxesActor->GetXAxisLabelProperty()->SetColor( 1.0, 0.0, 0.0 );
+ anAxesActor->GetYAxisTipProperty()->SetColor( 0.0, 1.0, 0.0 );
+ anAxesActor->GetYAxisShaftProperty()->SetColor( 0.0, 1.0, 0.0 );
+ anAxesActor->GetYAxisLabelProperty()->SetColor( 0.0, 1.0, 0.0 );
+ anAxesActor->GetZAxisTipProperty()->SetColor( 0.0, 0.0, 1.0 );
+ anAxesActor->GetZAxisShaftProperty()->SetColor( 0.0, 0.0, 1.0 );
+ anAxesActor->GetZAxisLabelProperty()->SetColor( 0.0, 0.0, 1.0 );
+
+ myView = new SVTK_View(this);
+ Initialize(myView,theModel);
+
+
+ myEventCallbackCommand->SetClientData(this);
+ myEventCallbackCommand->SetCallback(SVTK_ViewWindow::ProcessEvents);
+ myEventCallbackCommand->Delete();
+
+ GetInteractor()->GetInteractorStyle()->AddObserver(SVTK::OperationFinished,
+ myEventCallbackCommand.GetPointer(), 0.0);
+ myKeyFreeInteractorStyle->AddObserver(SVTK::OperationFinished,
+ myEventCallbackCommand.GetPointer(), 0.0);
- // 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 );
+ myInteractor->getRenderWindow()->Render();
+ setBackground( Qtx::BackgroundData( Qt::black ) ); // set default background
+ onResetView();
+}
- SVTK_InteractorStyle* RWS = SVTK_InteractorStyle::New();
- RWS->setGUIWindow( myRenderWindow );
- RWS->setViewWindow( this );
+/*!
+ To initialize #SVTK_ViewWindow instance
+*/
+void SVTK_ViewWindow::Initialize(SVTK_View* theView,
+ SVTK_ViewModelBase* theModel)
+{
+ 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()));
+
+ connect( this, SIGNAL( transformed( SVTK_ViewWindow* ) ), SLOT( emitViewModified() ) );
+}
- myRWInteractor->SetInteractorStyle( RWS );
- myRWInteractor->Initialize();
+/*!
+ Destructor
+*/
+SVTK_ViewWindow::~SVTK_ViewWindow()
+{
+ myRecorder->Delete();
+ myAxesWidget->Delete();
+}
- //merge with V2_2_0_VISU_improvements:RWS->setTriedron( myTrihedron );
- RWS->FindPokedRenderer( 0, 0 );
- SetSelectionMode(ActorSelection);
+/*!
+ \return corresponding view
+*/
+SVTK_View* SVTK_ViewWindow::getView()
+{
+ return myView;
+}
- 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 );
+/*!
+ \return corresponding vtk render window
+*/
+vtkRenderWindow* SVTK_ViewWindow::getRenderWindow()
+{
+ return GetInteractor()->getRenderWindow();
+}
- myToolBar = new QToolBar(this);
- myToolBar->setCloseMode(QDockWindow::Undocked);
- myToolBar->setLabel(tr("LBL_TOOLBAR_LABEL"));
+/*!
+ \return corresponding vtk render window interactor
+*/
+SVTK_RenderWindowInteractor* SVTK_ViewWindow::GetInteractor() const
+{
+ return myInteractor;
+}
- createActions();
- createToolBar();
+/*!
+ \return corresponding vtk render window interactor
+*/
+vtkRenderWindowInteractor* SVTK_ViewWindow::getInteractor() const
+{
+ return myInteractor->GetDevice();
+}
- 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* )) );
-
- connect( myRWInteractor, SIGNAL(RenderWindowModified()),
- myRenderWindow, SLOT(update()) );
- connect( myRWInteractor, SIGNAL(contextMenuRequested( QContextMenuEvent * )),
- this, SIGNAL(contextMenuRequested( QContextMenuEvent * )) );
+/*!
+ \return corresponding vtk renderer
+*/
+vtkRenderer* SVTK_ViewWindow::getRenderer() const
+{
+ return GetInteractor()->getRenderer();
+}
- onResetView();
+/*!
+ Redirect the request to SVTK_RenderWindowInteractor::GetRenderer
+*/
+SVTK_Renderer* SVTK_ViewWindow::GetRenderer() const
+{
+ return GetInteractor()->GetRenderer();
}
-//----------------------------------------------------------------------------
-SVTK_ViewWindow
-::~SVTK_ViewWindow()
+/*!
+ \return corresponding vtk selector
+*/
+SVTK_Selector* SVTK_ViewWindow::GetSelector() const
+{
+ return GetInteractor()->GetSelector();
+}
+
+/*!
+ Processes transformation "front view"
+*/
+void SVTK_ViewWindow::onFrontView()
{
- 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();
+ GetRenderer()->OnFrontView();
+ Repaint();
+ emit transformed( this );
}
-//----------------------------------------------------------------------------
-void
-SVTK_ViewWindow
-::activateZoom()
+/*!
+ Processes transformation "back view"
+*/
+void SVTK_ViewWindow::onBackView()
{
- myRWInteractor->GetSInteractorStyle()->startZoom();
+ GetRenderer()->OnBackView();
+ Repaint();
+ emit transformed( this );
}
-//----------------------------------------------------------------------------
-void
-SVTK_ViewWindow
-::activatePanning()
+/*!
+ Processes transformation "top view"
+*/
+void SVTK_ViewWindow::onTopView()
{
- myRWInteractor->GetSInteractorStyle()->startPan();
+ GetRenderer()->OnTopView();
+ Repaint();
+ emit transformed( this );
}
-//----------------------------------------------------------------------------
-void
-SVTK_ViewWindow
-::activateRotation()
+/*!
+ Processes transformation "bottom view"
+*/
+void SVTK_ViewWindow::onBottomView()
{
- myRWInteractor->GetSInteractorStyle()->startRotate();
+ GetRenderer()->OnBottomView();
+ Repaint();
+ emit transformed( this );
}
-//----------------------------------------------------------------------------
-void
-SVTK_ViewWindow
-::activateGlobalPanning()
+/*!
+ Processes transformation "left view"
+*/
+void SVTK_ViewWindow::onLeftView()
{
- if(myTrihedron->GetVisibleActorCount(myRenderer))
- myRWInteractor->GetSInteractorStyle()->startGlobalPan();
+ GetRenderer()->OnLeftView();
+ Repaint();
+ emit transformed( this );
}
-//----------------------------------------------------------------------------
-void
-SVTK_ViewWindow
-::activateWindowFit()
+/*!
+ Processes transformation "right view"
+*/
+void SVTK_ViewWindow::onRightView()
{
- myRWInteractor->GetSInteractorStyle()->startFitArea();
+ GetRenderer()->OnRightView();
+ Repaint();
+ emit transformed( this );
}
-//----------------------------------------------------------------------------
-#if defined(WIN32) && !defined(_DEBUG)
-#pragma optimize( "", off )
-#endif
-void
-SVTK_ViewWindow
-::createActions()
+/*!
+ \brief Rotate view 90 degrees clockwise
+*/
+void SVTK_ViewWindow::onClockWiseView()
{
- if (!myActionsMap.isEmpty()) return;
-
- SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
-
- QtxAction* aAction;
+ GetRenderer()->onClockWiseView();
+ Repaint();
+ emit transformed( this );
+}
- // 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;
+/*!
+ \brief Rotate view 90 degrees conterclockwise
+*/
+void SVTK_ViewWindow::onAntiClockWiseView()
+{
+ GetRenderer()->onAntiClockWiseView();
+ Repaint();
+ emit transformed( this );
+}
- // 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;
+/*!
+ Processes transformation "reset view": sets default orientation of viewport camera
+*/
+void SVTK_ViewWindow::onResetView()
+{
+ GetRenderer()->OnResetView();
+ Repaint();
+ emit transformed( this );
+}
- // 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;
+/*!
+ Processes transformation "fit all"
+*/
+void SVTK_ViewWindow::onFitAll()
+{
+ GetRenderer()->OnFitAll();
+ Repaint();
+ emit transformed( this );
+}
- // 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;
+/*!
+ SLOT: called if selection is changed
+*/
+void SVTK_ViewWindow::onSelectionChanged()
+{
+ myView->onSelectionChanged();
+}
- // 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;
+/*!
+ Change selection mode
+ \param theMode - new selection mode
+*/
+void SVTK_ViewWindow::SetSelectionMode(Selection_Mode theMode)
+{
+ GetSelector()->SetSelectionMode(theMode);
+}
- // 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;
+/*!
+ \return selection mode
+*/
+Selection_Mode SVTK_ViewWindow::SelectionMode() const
+{
+ return GetSelector()->SelectionMode();
+}
- // 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;
+/*!
+ Unhilights all objects in viewer
+*/
+void SVTK_ViewWindow::unHighlightAll()
+{
+ myView->unHighlightAll();
+}
- // 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;
+/*!
+ 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 )
+{
+ myView->highlight( theIO, theIsHighlight, theIsUpdate );
+}
- // 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;
+/*!
+ \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 myView->isInViewer( theIO );
+}
- // 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;
+/*!
+ \return true if object is displayed in viewer
+ \param theIO - object to be checked
+*/
+bool SVTK_ViewWindow::isVisible( const Handle(SALOME_InteractiveObject)& theIO )
+{
+ return myView->isVisible( theIO );
}
-#if defined(WIN32) && !defined(_DEBUG)
-#pragma optimize( "", on )
-#endif
-
-//----------------------------------------------------------------------------
-void
-SVTK_ViewWindow
-::createToolBar()
+
+/*!
+ Display object
+ \param theEntry - entry that corresponds to intractive objects
+*/
+Handle(SALOME_InteractiveObject) SVTK_ViewWindow::FindIObject(const char* theEntry)
{
- myActionsMap[DumpId]->addTo(myToolBar);
- myActionsMap[ViewTrihedronId]->addTo(myToolBar);
+ return myView->FindIObject(theEntry);
+}
- SUIT_ToolButton* aScaleBtn = new SUIT_ToolButton(myToolBar);
- aScaleBtn->AddAction(myActionsMap[FitAllId]);
- aScaleBtn->AddAction(myActionsMap[FitRectId]);
- aScaleBtn->AddAction(myActionsMap[ZoomId]);
+/*!
+ Display object
+ \param theIO - object
+ \param theImmediatly - update viewer
+*/
+void SVTK_ViewWindow::Display(const Handle(SALOME_InteractiveObject)& theIO,
+ bool theImmediatly)
+{
+ myView->Display(theIO,theImmediatly);
+}
- SUIT_ToolButton* aPanningBtn = new SUIT_ToolButton(myToolBar);
- aPanningBtn->AddAction(myActionsMap[PanId]);
- aPanningBtn->AddAction(myActionsMap[GlobalPanId]);
+/*!
+ Erase object
+ \param theIO - object
+ \param theImmediatly - update viewer
+*/
+void SVTK_ViewWindow::Erase(const Handle(SALOME_InteractiveObject)& theIO,
+ bool theImmediatly)
+{
+ myView->Erase(theIO,theImmediatly);
+}
- myActionsMap[RotationId]->addTo(myToolBar);
+/*!
+ Display only passed object
+ \param theIO - object
+*/
+void SVTK_ViewWindow::DisplayOnly(const Handle(SALOME_InteractiveObject)& theIO)
+{
+ myView->DisplayOnly(theIO);
+}
- 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]);
+/*!
+ Display all objects in view
+*/
+void SVTK_ViewWindow::DisplayAll()
+{
+ myView->DisplayAll();
+}
- myActionsMap[ResetId]->addTo(myToolBar);
+/*!
+ Erase all objects in view
+*/
+void SVTK_ViewWindow::EraseAll()
+{
+ myView->EraseAll();
}
-//----------------------------------------------------------------------------
-void
-SVTK_ViewWindow
-::onFrontView()
+/*!
+ Sets background color [obsolete]
+ \param color - new background color
+*/
+void SVTK_ViewWindow::setBackgroundColor( const QColor& c )
{
- vtkCamera* camera = myRenderer->GetActiveCamera();
- camera->SetPosition(1,0,0);
- camera->SetViewUp(0,0,1);
- camera->SetFocalPoint(0,0,0);
- onFitAll();
+ Qtx::BackgroundData bg = background();
+ bg.setColor( c );
+ setBackground( bg );
}
-//----------------------------------------------------------------------------
-void
-SVTK_ViewWindow
-::onBackView()
+/*!
+ \return background color of viewer [obsolete]
+*/
+QColor SVTK_ViewWindow::backgroundColor() const
{
- vtkCamera* camera = myRenderer->GetActiveCamera();
- camera->SetPosition(-1,0,0);
- camera->SetViewUp(0,0,1);
- camera->SetFocalPoint(0,0,0);
- onFitAll();
+ return background().color();
}
-//----------------------------------------------------------------------------
-void
-SVTK_ViewWindow
-::onTopView()
+/*!
+ Sets background data
+ \param bgData - new background data
+*/
+void SVTK_ViewWindow::setBackground( const Qtx::BackgroundData& bgData )
{
- vtkCamera* camera = myRenderer->GetActiveCamera();
- camera->SetPosition(0,0,1);
- camera->SetViewUp(0,1,0);
- camera->SetFocalPoint(0,0,0);
- onFitAll();
+ bool ok = false;
+
+ if ( bgData.isValid() ) {
+ switch ( bgData.mode() ) {
+ case Qtx::ColorBackground:
+ {
+ QColor c = bgData.color();
+ if ( c.isValid() ) {
+ // show solid-colored background
+ getRenderer()->SetTexturedBackground( false ); // cancel texture mode
+ getRenderer()->SetGradientBackground( false ); // cancel gradient mode
+ getRenderer()->SetBackground( c.red()/255.0,
+ c.green()/255.0,
+ c.blue()/255.0 ); // set background color
+ ok = true;
+ }
+ break;
+ }
+ case Qtx::SimpleGradientBackground:
+ {
+ QColor c1, c2;
+ int type = bgData.gradient( c1, c2 );
+ if ( c1.isValid() )
+ {
+ if ( !c2.isValid() )
+ c2 = c1;
+
+ // show two-color gradient background
+ getRenderer()->SetTexturedBackground( false ); // cancel texture mode
+ getRenderer()->SetGradientBackground( true ); // switch to gradient mode
+
+ VTKViewer_OpenGLRenderer* aRenderer =
+ VTKViewer_OpenGLRenderer::SafeDownCast( getRenderer() );
+ if( aRenderer )
+ {
+ aRenderer->SetGradientType( type );
+ aRenderer->SetBackground( c1.redF(), c1.greenF(), c1.blueF() );
+ aRenderer->SetBackground2( c2.redF(), c2.greenF(), c2.blueF() );
+ ok = true;
+ }
+ }
+ break;
+ }
+ case Qtx::CustomGradientBackground:
+ {
+ // NOT IMPLEMENTED YET
+ getRenderer()->SetTexturedBackground( false ); // cancel texture mode
+ getRenderer()->SetGradientBackground( false ); // cancel gradient mode
+ // .........
+ break;
+ }
+ default:
+ break;
+ }
+ if ( bgData.isTextureShown() ) {
+ QString fileName;
+ int textureMode = bgData.texture( fileName );
+ QFileInfo fi( fileName );
+ if ( !fileName.isEmpty() && fi.exists() ) {
+ // read texture from file
+ QString extension = fi.suffix().toLower();
+ vtkImageReader2* aReader = 0;
+ if ( extension == "jpg" || extension == "jpeg" )
+ aReader = vtkJPEGReader::New();
+ else if ( extension == "bmp" )
+ aReader = vtkBMPReader::New();
+ else if ( extension == "tif" || extension == "tiff" )
+ aReader = vtkTIFFReader::New();
+ else if ( extension == "png" )
+ aReader = vtkPNGReader::New();
+ else if ( extension == "mhd" || extension == "mha" )
+ aReader = vtkMetaImageReader::New();
+ if ( aReader ) {
+ // create texture
+ aReader->SetFileName( fi.absoluteFilePath().toLatin1().constData() );
+ aReader->Update();
+ VTKViewer_Texture* aTexture = VTKViewer_Texture::New();
+ vtkImageMapToColors* aMap = 0;
+ vtkAlgorithmOutput* anOutput;
+ /*
+ // special processing for BMP reader
+ vtkBMPReader* aBMPReader = (vtkBMPReader*)aReader;
+ if ( aBMPReader ) {
+ // Special processing for BMP file
+ aBMPReader->SetAllow8BitBMP(1);
+
+ aMap = vtkImageMapToColors::New();
+ aMap->SetInputConnection( aBMPReader->GetOutputPort() );
+ aMap->SetLookupTable( (vtkScalarsToColors*)aBMPReader->GetLookupTable() );
+ aMap->SetOutputFormatToRGB();
+
+ anOutput = aMap->GetOutputPort();
+ }
+ else {
+ }
+ */
+ anOutput = aReader->GetOutputPort( 0 );
+ aTexture->SetInputConnection( anOutput );
+ // set texture mode
+ // VSR: Currently, VTK only supports Stretch mode, so below code will give
+ // the same results for all modes
+ switch ( textureMode ) {
+ case Qtx::TileTexture:
+ aTexture->SetPosition((int)VTKViewer_Texture::Tiled);
+ break;
+ case Qtx::StretchTexture:
+ aTexture->SetPosition((int)VTKViewer_Texture::Stretched);
+ break;
+ case Qtx::CenterTexture:
+ aTexture->SetPosition((int)VTKViewer_Texture::Centered);
+ default:
+ break;
+ }
+ // show textured background
+ getRenderer()->SetTexturedBackground( true );
+ getRenderer()->SetBackgroundTexture( aTexture );
+
+ // clean-up resources
+ if ( aMap )
+ aMap->Delete();
+ aReader->Delete();
+ aTexture->Delete();
+ ok = true;
+ }
+ }
+ }
+ }
+ if ( ok )
+ myBackground = bgData;
}
-//----------------------------------------------------------------------------
-void
-SVTK_ViewWindow
-::onBottomView()
+/*!
+ \return background data of viewer
+*/
+Qtx::BackgroundData SVTK_ViewWindow::background() const
{
- vtkCamera* camera = myRenderer->GetActiveCamera();
- camera->SetPosition(0,0,-1);
- camera->SetViewUp(0,1,0);
- camera->SetFocalPoint(0,0,0);
- onFitAll();
+ return myBackground;
}
-//----------------------------------------------------------------------------
-void
-SVTK_ViewWindow
-::onLeftView()
+
+/*!
+ Redirect the request to SVTK_RenderWindowInteractor::GetInteractorStyle
+*/
+vtkInteractorStyle* SVTK_ViewWindow::GetInteractorStyle() const
{
- vtkCamera* camera = myRenderer->GetActiveCamera();
- camera->SetPosition(0,-1,0);
- camera->SetViewUp(0,0,1);
- camera->SetFocalPoint(0,0,0);
- onFitAll();
+ return GetInteractor()->GetInteractorStyle();
}
-//----------------------------------------------------------------------------
-void
-SVTK_ViewWindow
-::onRightView()
+/*!
+ Redirect the request to SVTK_RenderWindowInteractor::PushInteractorStyle
+*/
+void SVTK_ViewWindow::PushInteractorStyle(vtkInteractorStyle* theStyle)
{
- vtkCamera* camera = myRenderer->GetActiveCamera();
- camera->SetPosition(0,1,0);
- camera->SetViewUp(0,0,1);
- camera->SetFocalPoint(0,0,0);
- onFitAll();
+ GetInteractor()->PushInteractorStyle(theStyle);
}
-//----------------------------------------------------------------------------
-void
-SVTK_ViewWindow
-::onResetView()
+/*!
+ Redirect the request to SVTK_RenderWindowInteractor::PopInteractorStyle
+*/
+void SVTK_ViewWindow::PopInteractorStyle()
{
- int aTrihedronIsVisible = isTrihedronDisplayed();
- int aCubeAxesIsVisible = isCubeAxesDisplayed();
+ GetInteractor()->PopInteractorStyle();
+}
- myTrihedron->SetVisibility( VTKViewer_Trihedron::eOnlyLineOn );
- myCubeAxes->SetVisibility(0);
+/*!
+ Updates current viewer
+*/
+void SVTK_ViewWindow::Repaint(bool theUpdateTrihedron)
+{
+ if(theUpdateTrihedron)
+ GetRenderer()->OnAdjustTrihedron();
- ::ResetCamera(myRenderer,true);
- vtkCamera* aCamera = myRenderer->GetActiveCamera();
- aCamera->SetPosition(1,-1,1);
- aCamera->SetViewUp(0,0,1);
- ::ResetCamera(myRenderer,true);
+ GetInteractor()->update();
- if (aTrihedronIsVisible) myTrihedron->VisibilityOn();
- else myTrihedron->VisibilityOff();
+ SVTK_InteractorStyle* aStyle = (SVTK_InteractorStyle*)getInteractor()->GetInteractorStyle();
+ if ( aStyle )
+ aStyle->OnTimer();
+}
- if (aCubeAxesIsVisible) myCubeAxes->VisibilityOn();
- else myCubeAxes->VisibilityOff();
+/*!
+ Redirect the request to #SVTK_Renderer::GetScale
+*/
+void SVTK_ViewWindow::GetScale( double theScale[3] )
+{
+ GetRenderer()->GetScale( theScale );
+}
- static float aCoeff = 3.0;
- aCamera->SetParallelScale(aCoeff*aCamera->GetParallelScale());
+/*!
+ Redirect the request to #SVTK_Renderer::SetScale
+*/
+void SVTK_ViewWindow::SetScale( double theScale[3] )
+{
+ GetRenderer()->SetScale( theScale );
Repaint();
+ emit transformed( this );
}
-//----------------------------------------------------------------------------
-void
-SVTK_ViewWindow
-::onFitAll()
+/*!
+ Redirect the request to #SVTK_Renderer::IsTrihedronDisplayed
+*/
+bool SVTK_ViewWindow::isTrihedronDisplayed()
{
- int aTrihedronWasVisible = false;
- int aCubeAxesWasVisible = false;
- if (myTrihedron) {
- aTrihedronWasVisible = isTrihedronDisplayed();
- if (aTrihedronWasVisible)
- myTrihedron->VisibilityOff();
- }
+ return GetRenderer()->IsTrihedronDisplayed();
+}
- if (myCubeAxes) {
- aCubeAxesWasVisible = isCubeAxesDisplayed();
- if (aCubeAxesWasVisible)
- myCubeAxes->VisibilityOff();
- }
+/*!
+ Redirect the request to #SVTK_Renderer::IsCubeAxesDisplayed
+*/
+bool SVTK_ViewWindow::isCubeAxesDisplayed()
+{
+ return GetRenderer()->IsCubeAxesDisplayed();
+}
- if (myTrihedron->GetVisibleActorCount(myRenderer)) {
- myTrihedron->VisibilityOff();
- myCubeAxes->VisibilityOff();
- ::ResetCamera(myRenderer);
- } else {
- myTrihedron->SetVisibility(VTKViewer_Trihedron::eOnlyLineOn);
- myCubeAxes->SetVisibility(2);
- ::ResetCamera(myRenderer,true);
- }
+/*!
+ Redirect the request to #SVTK_Renderer::OnViewTrihedron
+*/
+void SVTK_ViewWindow::onViewTrihedron(bool show)
+{
+ GetRenderer()->SetTrihedronVisibility(show);
+ Repaint();
+}
- if (aTrihedronWasVisible)
- myTrihedron->VisibilityOn();
- else
- myTrihedron->VisibilityOff();
+/*!
+ Redirect the request to #SVTK_Renderer::OnViewCubeAxes
+*/
+void SVTK_ViewWindow::onViewCubeAxes()
+{
+ GetRenderer()->OnViewCubeAxes();
+ Repaint();
+}
- if (aCubeAxesWasVisible)
- myCubeAxes->VisibilityOn();
- else
- myCubeAxes->VisibilityOff();
+/*!
+ Redirect the request to #SVTK_Renderer::GetTrihedron
+*/
+VTKViewer_Trihedron* SVTK_ViewWindow::GetTrihedron()
+{
+ return GetRenderer()->GetTrihedron();
+}
- ::ResetCameraClippingRange(myRenderer);
+/*!
+ Redirect the request to #SVTK_Renderer::GetCubeAxes
+*/
+SVTK_CubeAxesActor2D* SVTK_ViewWindow::GetCubeAxes()
+{
+ return GetRenderer()->GetCubeAxes();
+}
- Repaint();
+/*!
+ \return trihedron size
+*/
+double SVTK_ViewWindow::GetTrihedronSize() const
+{
+ return GetRenderer()->GetTrihedronSize();
}
-//----------------------------------------------------------------
-void
-SVTK_ViewWindow
-::onSelectionChanged()
+/*!
+ Sets projection mode
+ \param theMode - projection mode ( 0 - orthogonal, 1 - perspective )
+*/
+void SVTK_ViewWindow::SetProjectionMode(const int theMode)
{
- unHighlightAll();
+ activateProjectionMode( theMode );
+}
- const SALOME_ListIO& aListIO = mySelector->StoredIObjects();
- SALOME_ListIteratorOfListIO anIter(aListIO);
- for(; anIter.More(); anIter.Next()){
- highlight(anIter.Value(),true,!anIter.More());
- }
- emit selectionChanged();
+/*!
+ Set the gravity center as a focal point
+*/
+void SVTK_ViewWindow::activateSetFocalPointGravity()
+{
+ myEventDispatcher->InvokeEvent(SVTK::SetFocalPointGravity, 0);
}
-//----------------------------------------------------------------
-void
-SVTK_ViewWindow
-::SetSelectionMode(Selection_Mode theMode)
+/*!
+ Set the selected point as a focal point
+*/
+void SVTK_ViewWindow::activateSetFocalPointSelected()
{
- mySelector->SetSelectionMode(theMode);
- myRWInteractor->SetSelectionMode(theMode);
+ myEventDispatcher->InvokeEvent(SVTK::SetFocalPointSelected, 0);
}
-//----------------------------------------------------------------
-Selection_Mode
-SVTK_ViewWindow
-::SelectionMode() const
+/*!
+ Set the point selected by user as a focal point
+*/
+void SVTK_ViewWindow::activateStartFocalPointSelection()
{
- return mySelector->SelectionMode();
+ myEventDispatcher->InvokeEvent(SVTK::StartFocalPointSelection,0);
}
-//----------------------------------------------------------------
-void
-SVTK_ViewWindow
-::unHighlightAll()
+void SVTK_ViewWindow::activateProjectionMode(int theMode)
{
- myRWInteractor->unHighlightAll();
+ if (theMode)
+ toolMgr()->action( ProjectionModeId )->setChecked( true );
+ else
+ toolMgr()->action( ParallelModeId )->setChecked( true );
}
-//----------------------------------------------------------------
-void
-SVTK_ViewWindow
-::highlight( const Handle(SALOME_InteractiveObject)& theIO,
- bool theIsHighlight,
- bool theIsUpdate )
+/*!
+ Sets actual interaction style
+ \param theStyle - type of interaction style ( 0 - standard, 1 - keyboard free )
+*/
+void SVTK_ViewWindow::SetInteractionStyle(const int theStyle)
{
- myRWInteractor->highlight(theIO, theIsHighlight, theIsUpdate);
+ onSwitchInteractionStyle( theStyle==1 );
+}
- 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;
+/*!
+ Sets actual zooming style
+ \param theStyle - type of zooming style ( 0 - standard, 1 - advanced (at cursor) )
+*/
+void SVTK_ViewWindow::SetZoomingStyle(const int theStyle)
+{
+ onSwitchZoomingStyle( theStyle==1 );
+}
+
+/*!
+ Set preselection mode.
+ \param theMode the mode to set (standard, dynamic or disabled)
+*/
+void SVTK_ViewWindow::SetPreSelectionMode( Preselection_Mode theMode )
+{
+ onSwitchPreSelectionMode( theMode );
+}
+
+/*!
+ Enables/disables selection.
+ \param theEnable if true - selection will be enabled
+*/
+void SVTK_ViewWindow::SetSelectionEnabled( bool theEnable )
+{
+ GetSelector()->SetSelectionEnabled( theEnable );
+ QtxAction* a = getAction( EnableSelectionId );
+ if ( a->isChecked() != theEnable)
+ a->setChecked( theEnable );
+ QtxActionGroup* aPreselectionGroup =
+ dynamic_cast<QtxActionGroup*>( getAction( PreselectionId ) );
+ if ( aPreselectionGroup )
+ aPreselectionGroup->setEnabled( theEnable );
+}
+
+/*!
+ Switches "keyboard free" interaction style on/off
+*/
+void SVTK_ViewWindow::onSwitchInteractionStyle(bool theOn)
+{
+ if (theOn) {
+ // check if style is already set
+ if ( GetInteractorStyle() != myKeyFreeInteractorStyle.GetPointer() )
+ {
+ // keep the same style extensions
+ SVTK_InteractorStyle* aStyle = (SVTK_InteractorStyle*)GetInteractorStyle();
+ if ( aStyle ) {
+ myKeyFreeInteractorStyle->SetControllerIncrement(aStyle->ControllerIncrement());
+ myKeyFreeInteractorStyle->SetControllerOnKeyDown(aStyle->ControllerOnKeyDown());
}
+
+ PushInteractorStyle(myKeyFreeInteractorStyle.GetPointer());
}
- }else{
- myRWInteractor->unHighlightSubSelection();
}
+ else {
+ // pop only key free style
+ if ( GetInteractorStyle() == myKeyFreeInteractorStyle.GetPointer() )
+ PopInteractorStyle();
+ }
+
+ // update action state if method is called outside
+ QtxAction* a = getAction( SwitchInteractionStyleId );
+ if ( a->isChecked() != theOn ) a->setChecked( theOn );
}
-//----------------------------------------------------------------
-bool
-SVTK_ViewWindow
-::isInViewer( const Handle(SALOME_InteractiveObject)& theIO )
+/*!
+ Toogles advanced zooming style (relatively to the cursor position) on/off
+*/
+void SVTK_ViewWindow::onSwitchZoomingStyle( bool theOn )
{
- return myRWInteractor->isInViewer( theIO );
+ if( myDefaultInteractorStyle.GetPointer() )
+ myDefaultInteractorStyle->SetAdvancedZoomingEnabled( theOn );
+ if( myKeyFreeInteractorStyle.GetPointer() )
+ myKeyFreeInteractorStyle->SetAdvancedZoomingEnabled( theOn );
+
+ // update action state if method is called outside
+ QtxAction* a = getAction( SwitchZoomingStyleId );
+ if ( a->isChecked() != theOn )
+ a->setChecked( theOn );
}
-//----------------------------------------------------------------
-bool
-SVTK_ViewWindow
-::isVisible( const Handle(SALOME_InteractiveObject)& theIO )
+/*!
+ Switch preselection mode.
+ \param theMode the preselection mode
+*/
+void SVTK_ViewWindow::onSwitchPreSelectionMode( int theMode )
{
- return myRWInteractor->isVisible( theIO );
+ GetSelector()->SetDynamicPreSelection( theMode == Dynamic_Preselection );
+ GetSelector()->SetPreSelectionEnabled( theMode != Preselection_Disabled );
+
+ // update action state if method is called outside
+ QtxAction* a = getAction( StandardPreselectionId + theMode );
+ if ( a && !a->isChecked() )
+ a->setChecked( true );
}
-//----------------------------------------------------------------------------
-void
-SVTK_ViewWindow
-::setBackgroundColor( const QColor& color )
+/*!
+ Enables/disables selection.
+ \param theOn if true - selection will be enabled
+*/
+void SVTK_ViewWindow::onEnableSelection( bool on )
{
- if ( myRenderer )
- myRenderer->SetBackground( color.red()/255., color.green()/255., color.blue()/255. );
+ SVTK_Viewer* aViewer = dynamic_cast<SVTK_Viewer*>(myModel);
+ if(aViewer)
+ aViewer->enableSelection(on);
}
-//----------------------------------------------------------------------------
-QColor
-SVTK_ViewWindow
-::backgroundColor() const
+/*!
+ Sets incremental speed
+ \param theValue - new incremental speed
+ \param theMode - modification mode
+*/
+void SVTK_ViewWindow::SetIncrementalSpeed(const int theValue, const int theMode)
{
- 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();
+ if ( (SVTK_InteractorStyle*)GetInteractorStyle() )
+ ((SVTK_InteractorStyle*)GetInteractorStyle())->SetIncrementSpeed(theValue, theMode);
}
-//----------------------------------------------------------------------------
-void
-SVTK_ViewWindow
-::Repaint(bool theUpdateTrihedron)
+/*!
+ Sets spacemouse buttons for the functions
+ \param theBtn1 - spacemouse button for the "decrease speed increment"
+ \param theBtn2 - spacemouse button for the "increase speed increment"
+ \param theBtn3 - spacemouse button for the "dominant combined switch"
+*/
+void SVTK_ViewWindow::SetSpacemouseButtons(const int theBtn1,
+ const int theBtn2,
+ const int theBtn3)
{
- if (theUpdateTrihedron)
- onAdjustTrihedron();
- myRenderWindow->update();
+ int val = theBtn1;
+ myEventDispatcher->InvokeEvent(SVTK::SetSMDecreaseSpeedEvent, &val);
+ val = theBtn2;
+ myEventDispatcher->InvokeEvent(SVTK::SetSMIncreaseSpeedEvent, &val);
+ val = theBtn3;
+ myEventDispatcher->InvokeEvent(SVTK::SetSMDominantCombinedSwitchEvent, &val);
}
-//----------------------------------------------------------------------------
-void
-SVTK_ViewWindow
-::GetScale( double theScale[3] )
+/*!
+ Sets trihedron size
+ \param theSize - new trihedron size
+ \param theRelative - trihedron relativeness
+*/
+void SVTK_ViewWindow::SetTrihedronSize(const double theSize, const bool theRelative)
{
- myTransform->GetMatrixScale( theScale );
+ GetRenderer()->SetTrihedronSize(theSize, theRelative);
+ Repaint();
}
-//----------------------------------------------------------------------------
-void
-SVTK_ViewWindow
-::SetScale( double theScale[3] )
+/*! If parameter theIsForcedUpdate is true, recalculate parameters for
+ * trihedron and cube axes, even if trihedron and cube axes is invisible.
+ */
+void SVTK_ViewWindow::AdjustTrihedrons(const bool theIsForcedUpdate)
{
- myTransform->SetMatrixScale( theScale[0], theScale[1], theScale[2] );
- myRWInteractor->Render();
+ GetRenderer()->AdjustActors();
Repaint();
}
-//----------------------------------------------------------------------------
-bool
-SVTK_ViewWindow
-::isTrihedronDisplayed()
+/*!
+ Redirect the request to #SVTK_Renderer::OnAdjustTrihedron
+*/
+void SVTK_ViewWindow::onAdjustTrihedron()
+{
+ GetRenderer()->OnAdjustTrihedron();
+}
+
+/*!
+ Redirect the request to #SVTK_Renderer::OnAdjustCubeAxes
+*/
+void SVTK_ViewWindow::onAdjustCubeAxes()
+{
+ GetRenderer()->OnAdjustCubeAxes();
+}
+
+void SVTK_ViewWindow::synchronize(SVTK_ViewWindow* otherViewWindow )
{
- return myTrihedron->GetVisibility() == VTKViewer_Trihedron::eOn;
+ if ( otherViewWindow ) {
+ bool blocked = blockSignals( true );
+ doSetVisualParameters( otherViewWindow->getVisualParameters(), true );
+ blockSignals( blocked );
+ }
}
-bool
-SVTK_ViewWindow
-::isCubeAxesDisplayed()
+/*!
+ Emits key pressed
+*/
+void SVTK_ViewWindow::onKeyPressed(QKeyEvent* event)
{
- return myCubeAxes->GetVisibility() == 1;
+ emit keyPressed( this, event );
}
-//----------------------------------------------------------------------------
-void
-SVTK_ViewWindow
-::onViewTrihedron()
+/*!
+ Emits key released
+*/
+void SVTK_ViewWindow::onKeyReleased(QKeyEvent* event)
{
- if(!myTrihedron)
- return;
+ emit keyReleased( this, event );
+}
- if(isTrihedronDisplayed())
- myTrihedron->VisibilityOff();
- else
- myTrihedron->VisibilityOn();
+/*!
+ Emits mouse pressed
+*/
+void SVTK_ViewWindow::onMousePressed(QMouseEvent* event)
+{
+ emit mousePressed(this, event);
+}
- Repaint();
+/*!
+ Emits mouse released
+*/
+void SVTK_ViewWindow::onMouseReleased(QMouseEvent* event)
+{
+ emit mouseReleased( this, event );
}
-void
-SVTK_ViewWindow
-::onViewCubeAxes()
+/*!
+ Emits mouse moving
+*/
+void SVTK_ViewWindow::onMouseMoving(QMouseEvent* event)
{
- if(!myCubeAxes)
- return;
+ emit mouseMoving( this, event );
+}
- if(isCubeAxesDisplayed())
- myCubeAxes->VisibilityOff();
- else
- myCubeAxes->VisibilityOn();
+/*!
+ Emits mouse double clicked
+*/
+void SVTK_ViewWindow::onMouseDoubleClicked( QMouseEvent* event )
+{
+ emit mouseDoubleClicked( this, event );
+}
- Repaint();
+/*!
+ Redirect the request to #SVTK_Renderer::AddActor
+*/
+void SVTK_ViewWindow::AddActor( VTKViewer_Actor* theActor,
+ bool theUpdate,
+ bool theIsAdjustActors )
+{
+ GetRenderer()->AddActor(theActor, theIsAdjustActors);
+ if(theUpdate)
+ Repaint();
+ emit actorAdded(theActor);
+}
+
+/*!
+ Redirect the request to #SVTK_Renderer::RemoveActor
+*/
+void SVTK_ViewWindow::RemoveActor( VTKViewer_Actor* theActor,
+ bool theUpdate,
+ bool theIsAdjustActors )
+{
+ GetRenderer()->RemoveActor(theActor, theIsAdjustActors);
+ if ( myDefaultInteractorStyle )
+ myDefaultInteractorStyle->FreeActors();
+ if ( myKeyFreeInteractorStyle )
+ myKeyFreeInteractorStyle->FreeActors();
+ if(theUpdate)
+ Repaint();
+ emit actorRemoved(theActor);
}
-//----------------------------------------------------------------------------
-/*bool
-SVTK_ViewWindow
-::ComputeTrihedronSize( double& theNewSize, double& theSize )
+QImage SVTK_ViewWindow::dumpViewContent()
{
- // calculating diagonal of visible props of the renderer
- float aBndBox[ 6 ];
- myTrihedron->VisibilityOff();
+ vtkRenderWindow* aWindow = getRenderWindow();
+ int* aSize = aWindow->GetSize();
+ int aWidth = aSize[0];
+ int aHeight = aSize[1];
+
+ OpenGLUtils_FrameBuffer aFrameBuffer;
+ if( aFrameBuffer.init( aWidth, aHeight ) )
+ {
+ glPushAttrib( GL_VIEWPORT_BIT );
+ glViewport( 0, 0, aWidth, aHeight );
+ aFrameBuffer.bind();
+
+ // draw scene
+ aWindow->Render();
+
+ aFrameBuffer.unbind();
+ glPopAttrib();
+
+ QImage anImage( aWidth, aHeight, QImage::Format_RGB32 );
- if ( ::ComputeVisiblePropBounds( myRenderer, aBndBox ) == 0 ) {
- aBndBox[ 1 ] = aBndBox[ 3 ] = aBndBox[ 5 ] = 100;
- aBndBox[ 0 ] = aBndBox[ 2 ] = aBndBox[ 4 ] = 0;
+ aFrameBuffer.bind();
+ glReadPixels( 0, 0, aWidth, aHeight, GL_RGBA, GL_UNSIGNED_BYTE, anImage.bits() );
+ aFrameBuffer.unbind();
+
+ anImage = anImage.rgbSwapped();
+ anImage = anImage.mirrored();
+ return anImage;
}
- 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 );
+ // if frame buffers are unsupported, use old functionality
+ unsigned char *aData =
+ aWindow->GetRGBACharPixelData( 0, 0, aWidth-1, aHeight-1, 0 );
+
+ QImage anImage( aData, aWidth, aHeight, QImage::Format_ARGB32 );
+
+ anImage = anImage.rgbSwapped();
+ anImage = anImage.mirrored();
+ return anImage;
+}
+
+/*!
+ \return QImage, containing all scene rendering in window
+*/
+QImage SVTK_ViewWindow::dumpView()
+{
+ if( myDumpImage.isNull() )
+ return dumpViewContent();
+
+ RefreshDumpImage();
+ return myDumpImage;
+}
+
+QString SVTK_ViewWindow::filter() const
+{
+ return tr( "SVTK_IMAGE_FILES" );
+}
+
+bool SVTK_ViewWindow::dumpViewToFormat( const QImage& img, const QString& fileName, const QString& format )
+{
+ if ( format != "PS" && format != "EPS" && format != "PDF" )
+ return SUIT_ViewWindow::dumpViewToFormat( img, fileName, format );
+
+ SUIT_OverrideCursor wc;
+
+ vtkGL2PSExporter *anExporter = vtkGL2PSExporter::New();
+ anExporter->SetRenderWindow(getRenderWindow());
+
+ if ( format == "PS" ) {
+ anExporter->SetFileFormatToPS();
+ anExporter->CompressOff();
}
- float aSizeInPercents = myTrihedronSize;
+ if ( format == "EPS" ) {
+ anExporter->SetFileFormatToEPS();
+ anExporter->CompressOff();
+ }
- static float EPS_SIZE = 5.0E-3;
- theSize = myTrihedron->GetSize();
- theNewSize = aLength * aSizeInPercents / 100.0;
+ if ( format == "PDF" ) {
+ anExporter->SetFileFormatToPDF();
+ }
+
+ QString aFilePrefix(fileName);
+ QString anExtension(SUIT_Tools::extension(fileName));
+ aFilePrefix.truncate(aFilePrefix.length() - 1 - anExtension.length());
+ anExporter->SetFilePrefix(aFilePrefix.toLatin1().data());
+ anExporter->Write();
+ anExporter->Delete();
- // 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 true;
+}
-//----------------------------------------------------------------------------
-int SVTK_ViewWindow::GetTrihedronSize() const
+/*!
+ \refresh QImage, containing all scene rendering in window
+*/
+void SVTK_ViewWindow::RefreshDumpImage()
{
- return myTrihedronSize;
+ myDumpImage = dumpViewContent();
}
-void SVTK_ViewWindow::SetTrihedronSize( const int sz )
+/*!
+ Redirect the request to #SVTK_Renderer::SetSelectionProp
+*/
+void SVTK_ViewWindow::SetSelectionProp(const double& theRed,
+ const double& theGreen,
+ const double& theBlue,
+ const int& theWidth)
{
- if ( myTrihedronSize == sz )
- return;
+ myView->SetSelectionProp(theRed,theGreen,theBlue,theWidth);
+}
- myTrihedronSize = sz;
- AdjustTrihedrons( true );
+/*!
+ Redirect the request to #SVTK_Renderer::SetSelectionProp
+*/
+void SVTK_ViewWindow::SetPreselectionProp(const double& theRed,
+ const double& theGreen,
+ const double& theBlue,
+ const int& theWidth)
+{
+ myView->SetPreselectionProp(theRed,theGreen,theBlue,theWidth);
}
-/*! If parameter theIsForcedUpdate is true, recalculate parameters for
- * trihedron and cube axes, even if trihedron and cube axes is invisible.
+/*!
+ Redirect the request to #SVTK_Renderer::SetSelectionTolerance
+*/
+void SVTK_ViewWindow::SetSelectionTolerance(const double& theTolNodes,
+ const double& theTolItems,
+ const double& theTolObjects)
+{
+ myView->SetSelectionTolerance(theTolNodes, theTolItems, theTolObjects);
+}
+
+/*!
+ Get visibility status of the static trihedron
+*/
+bool SVTK_ViewWindow::IsStaticTrihedronVisible() const
+{
+ return (bool)myAxesWidget->GetEnabled();
+}
+
+/*!
+ Set visibility status of the static trihedron
+*/
+void SVTK_ViewWindow::SetStaticTrihedronVisible( const bool theIsVisible )
+{
+ myAxesWidget->SetEnabled( (int)theIsVisible );
+}
+
+/*!
+ Performs action
+ \param accelAction - action
+*/
+bool SVTK_ViewWindow::action( const int accelAction )
+{
+ if ( accelAction == SUIT_Accel::ZoomFit )
+ onFitAll();
+ else {
+ int anEvent = SVTK::convertAction( accelAction );
+ GetInteractor()->InvokeEvent(anEvent, 0);
+ }
+ return true;
+}
+
+/*!
+ \return action by it's id
+*/
+QtxAction* SVTK_ViewWindow::getAction( int id ) const
+{
+ return dynamic_cast<QtxAction*>( toolMgr()->action( id ) );
+}
+
+
+// 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 nTrihedronParams = 3; // number of parameters for Trihedron
+const int nAllParams = nNormalParams + 3*nGradAxisParams + nTrihedronParams + 1; // number of all visual parameters
+
+/*! The method returns visual parameters of a graduated axis actor (x,y,z axis of graduated axes)
*/
-void
-SVTK_ViewWindow
-::AdjustTrihedrons(const bool theIsForcedUpdate)
+void getGradAxisVisualParams( QXmlStreamWriter& writer, vtkAxisActor2D* actor, QString theAxis )
+{
+ //QString params;
+ if ( !actor )
+ return ;//params;
+
+ // Name
+ bool isVisible = actor->GetTitleVisibility();
+ QString title ( actor->GetTitle() );
+ double 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();
+ }
+ writer.writeStartElement("GraduatedAxis");
+ writer.writeAttribute("Axis", theAxis);
+
+ writer.writeStartElement("Title");
+ writer.writeAttribute("isVisible", QString("%1").arg(isVisible));
+ writer.writeAttribute("Text", title);
+ writer.writeAttribute("Font", QString("%1").arg(font));
+ writer.writeAttribute("Bold", QString("%1").arg(bold));
+ writer.writeAttribute("Italic", QString("%1").arg(italic));
+ writer.writeAttribute("Shadow", QString("%1").arg(shadow));
+
+ writer.writeStartElement("Color");
+ writer.writeAttribute("R", QString("%1").arg(color[0]));
+ writer.writeAttribute("G", QString("%1").arg(color[1]));
+ writer.writeAttribute("B", QString("%1").arg(color[2]));
+ writer.writeEndElement();
+ writer.writeEndElement();
+
+ //params.sprintf( "* Graduated Axis: * Name *%u*%s*%.2f*%.2f*%.2f*%u*%u*%u*%u", isVisible,
+ // title.toLatin1().data(), 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();
+ }
+
+ writer.writeStartElement("Labels");
+ writer.writeAttribute("isVisible", QString("%1").arg(isVisible));
+ writer.writeAttribute("Number", QString("%1").arg(labels));
+ writer.writeAttribute("Offset", QString("%1").arg(offset));
+ writer.writeAttribute("Font", QString("%1").arg(font));
+ writer.writeAttribute("Bold", QString("%1").arg(bold));
+ writer.writeAttribute("Italic", QString("%1").arg(italic));
+ writer.writeAttribute("Shadow", QString("%1").arg(shadow));
+
+ writer.writeStartElement("Color");
+ writer.writeAttribute("R", QString("%1").arg(color[0]));
+ writer.writeAttribute("G", QString("%1").arg(color[1]));
+ writer.writeAttribute("B", QString("%1").arg(color[2]));
+ writer.writeEndElement();
+ writer.writeEndElement();
+ // 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();
+ writer.writeStartElement("TickMarks");
+ writer.writeAttribute("isVisible", QString("%1").arg(isVisible));
+ writer.writeAttribute("Length", QString("%1").arg(length));
+ writer.writeEndElement();
+
+ //params += QString().sprintf( "* Tick marks *%u*%u", isVisible, length );
+
+ writer.writeEndElement();
+ //return params;
+}
+
+void setGradAxisVisualParams(QXmlStreamReader& reader, vtkAxisActor2D* actor)
{
- if ((!isCubeAxesDisplayed() && !isTrihedronDisplayed()) && !theIsForcedUpdate)
+ if ( !actor )
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;
+ do {
+ reader.readNext();
+ } while (!reader.isStartElement());
- myCubeAxes->GetBounds(bnd);
+ // Read title params
+ QXmlStreamAttributes aAttr = reader.attributes();
+ bool isVisible = aAttr.value("isVisible").toString().toUShort();
+ QString title = aAttr.value("Text").toString();
+ int font = aAttr.value("Font").toString().toInt();
+ int bold = aAttr.value("Bold").toString().toInt();
+ int italic = aAttr.value("Italic").toString().toInt();
+ int shadow = aAttr.value("Shadow").toString().toInt();
- 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();
+ //printf("#### TITLE: %i, %s, %i, %i, %i, %i\n", isVisible, qPrintable(title), font, bold, italic, shadow);
- SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
- QString aSetting = aResMgr->stringValue("Viewer", "TrihedronSize", "105");
- static float aSizeInPercents = aSetting.toFloat();
+ do {
+ reader.readNext();
+ } while (!reader.isStartElement());
+
+ // Read title color
+ aAttr = reader.attributes();
+
+ double color[3];
+ color[0] = aAttr.value("R").toString().toDouble();
+ color[1] = aAttr.value("G").toString().toDouble();
+ color[2] = aAttr.value("B").toString().toDouble();
+ //printf("#### Color: %f, %f, %f\n", color[0], color[1], color[2]);
+
+ actor->SetTitleVisibility( isVisible );
+ actor->SetTitle( title.toLatin1() );
+ vtkTextProperty* txtProp = actor->GetTitleTextProperty();
+ if ( txtProp ) {
+ txtProp->SetColor( color );
+ txtProp->SetFontFamily( font );
+ txtProp->SetBold( bold );
+ txtProp->SetItalic( italic );
+ txtProp->SetShadow( shadow );
+ }
- //bool isComputeTrihedronSize =
- ::ComputeTrihedronSize(myRenderer, aNewSize, anOldSize, aSizeInPercents);
+ // Labels
+
+ do {
+ reader.readNext();
+ } while (!reader.isStartElement());
+ // Read labels
+ aAttr = reader.attributes();
+ isVisible = aAttr.value("isVisible").toString().toUShort();
+ int labels = aAttr.value("Number").toString().toInt();
+ int offset = aAttr.value("Offset").toString().toInt();
+ font = aAttr.value("Font").toString().toInt();
+ bold = aAttr.value("Bold").toString().toInt();
+ italic = aAttr.value("Italic").toString().toInt();
+ shadow = aAttr.value("Shadow").toString().toInt();
+
+ do {
+ reader.readNext();
+ } while (!reader.isStartElement());
+ // Read Color
+ aAttr = reader.attributes();
+
+ color[0] = aAttr.value("R").toString().toDouble();
+ color[1] = aAttr.value("G").toString().toDouble();
+ color[2] = aAttr.value("B").toString().toDouble();
+
+ 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 );
+ }
- myTrihedron->SetSize( aNewSize );
+ // Tick Marks
+ do {
+ reader.readNext();
+ } while (!reader.isStartElement());
+ aAttr = reader.attributes();
- // 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];
- }
- }
- }
+ // retrieve and set tick marks properties
+ isVisible = aAttr.value("isVisible").toString().toUShort();
+ int length = aAttr.value("Length").toString().toInt();
+
+ actor->SetTickVisibility( isVisible );
+ actor->SetTickLength( length );
+}
+
+/*! The method restores visual parameters of a graduated axis actor (x,y,z axis)
+ */
+void setGradAxisVisualParams( vtkAxisActor2D* actor, const QString& params )
+{
+ if ( !actor )
+ return;
+
+ QStringList paramsLst = params.split( '*' );
+
+ 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];
+ double 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.toLatin1() );
+ vtkTextProperty* txtProp = actor->GetTitleTextProperty();
+ if ( txtProp ) {
+ txtProp->SetColor( color );
+ txtProp->SetFontFamily( font );
+ txtProp->SetBold( bold );
+ txtProp->SetItalic( italic );
+ txtProp->SetShadow( shadow );
}
- 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;
+
+ // 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 );
}
+}
+
+/*! The method returns the visual parameters of this view as a formated string
+ */
+QString SVTK_ViewWindow::getVisualParameters()
+{
+ double pos[3], focalPnt[3], viewUp[3], parScale, scale[3];
- 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);
+ // 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;
+ QXmlStreamWriter aWriter(&retStr);
+ aWriter.setAutoFormatting(true);
+
+ aWriter.writeStartDocument();
+ aWriter.writeStartElement("ViewState");
+
+ aWriter.writeStartElement("Position");
+ aWriter.writeAttribute("X", QString("%1").arg(pos[0]));
+ aWriter.writeAttribute("Y", QString("%1").arg(pos[1]));
+ aWriter.writeAttribute("Z", QString("%1").arg(pos[2]));
+ aWriter.writeEndElement();
+
+ aWriter.writeStartElement("FocalPoint");
+ aWriter.writeAttribute("X", QString::number(focalPnt[0]));
+ aWriter.writeAttribute("Y", QString::number(focalPnt[1]));
+ aWriter.writeAttribute("Z", QString::number(focalPnt[2]));
+ aWriter.writeEndElement();
+
+ aWriter.writeStartElement("ViewUp");
+ aWriter.writeAttribute("X", QString::number(viewUp[0]));
+ aWriter.writeAttribute("Y", QString::number(viewUp[1]));
+ aWriter.writeAttribute("Z", QString::number(viewUp[2]));
+ aWriter.writeEndElement();
+
+ aWriter.writeStartElement("ViewScale");
+ aWriter.writeAttribute("Parallel", QString::number(parScale));
+ aWriter.writeAttribute("X", QString::number(scale[0]));
+ aWriter.writeAttribute("Y", QString::number(scale[1]));
+ aWriter.writeAttribute("Z", QString::number(scale[2]));
+ aWriter.writeEndElement();
+
+ if ( SVTK_CubeAxesActor2D* gradAxesActor = GetCubeAxes() ) {
+ aWriter.writeStartElement("DisplayCubeAxis");
+ aWriter.writeAttribute("Show", QString( "%1" ).arg( GetRenderer()->IsCubeAxesDisplayed()));
+ aWriter.writeEndElement();
+
+ getGradAxisVisualParams(aWriter, gradAxesActor->GetXAxisActor2D(), "X");
+ getGradAxisVisualParams(aWriter, gradAxesActor->GetYAxisActor2D(), "Y");
+ getGradAxisVisualParams(aWriter, gradAxesActor->GetZAxisActor2D(), "Z");
+ }
+
+ aWriter.writeStartElement("Trihedron");
+ aWriter.writeAttribute("isShown", QString( "%1" ).arg( isTrihedronDisplayed()));
+ aWriter.writeAttribute("Size", QString::number(GetTrihedronSize()));
+ aWriter.writeEndElement();
+
+ aWriter.writeStartElement("Background");
+ aWriter.writeAttribute("Value", QString( "%1" ).arg( Qtx::backgroundToString(background()) ));
+ aWriter.writeEndElement();
+
+ aWriter.writeEndElement();
+ aWriter.writeEndDocument();
+
+ return retStr;
+}
+
+/*!
+ The method restores visual parameters of this view or postpones it untill the view is shown
+*/
+void SVTK_ViewWindow::setVisualParameters( const QString& parameters )
+{
+ //printf("#### %s\n", qPrintable(parameters));
+ SVTK_RenderWindowInteractor* anInteractor = GetInteractor();
+ if ( anInteractor->isVisible() ) {
+ doSetVisualParameters( parameters );
+ }
+ else {
+ myVisualParams = parameters;
+ anInteractor->installEventFilter(this);
}
+}
+
+/*!
+ The method restores visual parameters of this view from a formated string
+*/
+void SVTK_ViewWindow::doSetVisualParameters( const QString& parameters, bool baseParamsOnly )
+{
- myCubeAxes->SetBounds(bnd);
+ double pos[3], focalPnt[3], viewUp[3], parScale, scale[3];
+
+ QXmlStreamReader aReader(parameters);
+ SVTK_CubeAxesActor2D* gradAxesActor = GetCubeAxes();
+
+ while(!aReader.atEnd()) {
+ aReader.readNext();
+ if (aReader.isStartElement()) {
+ QXmlStreamAttributes aAttr = aReader.attributes();
+ //printf("### Name = %s\n", qPrintable(aReader.name().toString()));
+ if (aReader.name() == "Position") {
+ pos[0] = aAttr.value("X").toString().toDouble();
+ pos[1] = aAttr.value("Y").toString().toDouble();
+ pos[2] = aAttr.value("Z").toString().toDouble();
+ //printf("#### Position %f; %f; %f\n", pos[0], pos[1], pos[2]);
+ }
+ else if (aReader.name() == "FocalPoint") {
+ focalPnt[0] = aAttr.value("X").toString().toDouble();
+ focalPnt[1] = aAttr.value("Y").toString().toDouble();
+ focalPnt[2] = aAttr.value("Z").toString().toDouble();
+ //printf("#### FocalPoint %f; %f; %f\n", focalPnt[0], focalPnt[1], focalPnt[2]);
+ }
+ else if (aReader.name() == "ViewUp") {
+ viewUp[0] = aAttr.value("X").toString().toDouble();
+ viewUp[1] = aAttr.value("Y").toString().toDouble();
+ viewUp[2] = aAttr.value("Z").toString().toDouble();
+ //printf("#### ViewUp %f; %f; %f\n", viewUp[0], viewUp[1], viewUp[2]);
+ }
+ else if (aReader.name() == "ViewScale") {
+ parScale = aAttr.value("Parallel").toString().toDouble();
+ scale[0] = aAttr.value("X").toString().toDouble();
+ scale[1] = aAttr.value("Y").toString().toDouble();
+ scale[2] = aAttr.value("Z").toString().toDouble();
+ //printf("#### ViewScale %f; %f; %f\n", scale[0], scale[1], scale[2]);
+ }
+ else if (aReader.name() == "DisplayCubeAxis") {
+ if ( !baseParamsOnly ) {
+ if (aAttr.value("Show") == "0")
+ gradAxesActor->VisibilityOff();
+ else
+ gradAxesActor->VisibilityOn();
+ }
+ }
+ else if (aReader.name() == "GraduatedAxis") {
+ if ( !baseParamsOnly ) {
+ if(aAttr.value("Axis") == "X")
+ setGradAxisVisualParams(aReader, gradAxesActor->GetXAxisActor2D());
+ else if(aAttr.value("Axis") == "Y")
+ setGradAxisVisualParams(aReader, gradAxesActor->GetYAxisActor2D());
+ else if(aAttr.value("Axis") == "Z")
+ setGradAxisVisualParams(aReader, gradAxesActor->GetZAxisActor2D());
+ }
+ }
+ else if (aReader.name() == "Trihedron") {
+ if ( !baseParamsOnly ) {
+ if (aAttr.value("isShown") == "0")
+ GetTrihedron()->VisibilityOff();
+ else
+ GetTrihedron()->VisibilityOn();
+ SetTrihedronSize(aAttr.value("Size").toString().toDouble());
+ }
+ }
+ else if (aReader.name() == "Background") {
+ if ( !baseParamsOnly ) {
+ setBackground( Qtx::stringToBackground( aAttr.value("Value").toString() ) );
+ }
+ }
+ }
+ }
+ if (!aReader.hasError()) {
+ vtkCamera* camera = getRenderer()->GetActiveCamera();
+ camera->SetPosition( pos );
+ camera->SetFocalPoint( focalPnt );
+ camera->SetViewUp( viewUp );
+ camera->SetParallelScale( parScale );
+ GetRenderer()->SetScale( scale );
+ //SetScale( scale );
+ }
+ else {
+ QStringList paramsLst = parameters.split( '*' );
+ if ( paramsLst.size() >= nNormalParams ) {
+ // 'reading' list of parameters
+ 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 );
+ GetRenderer()->SetScale( scale );
+ //SetScale( scale );
+
+ // apply graduated axes parameters
+ if ( !baseParamsOnly ) {
+ 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();
+ }
+ else if ( paramsLst.size() == nAllParams ) {
+ if ( paramsLst[90].toUShort() )
+ GetTrihedron()->VisibilityOn();
+ else
+ GetTrihedron()->VisibilityOff();
+
+ SetTrihedronSize(paramsLst[91].toDouble());
+ }
+ }
+ }
+ }
+ Repaint();
+}
+
- ::ResetCameraClippingRange(myRenderer);
+/*!
+ Delayed setVisualParameters
+*/
+bool SVTK_ViewWindow::eventFilter( QObject* theWatched, QEvent* theEvent )
+{
+ 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 );
}
-//----------------------------------------------------------------------------
-void
-SVTK_ViewWindow
-::onAdjustTrihedron()
-{
- AdjustTrihedrons( false );
+
+/*!
+ Change rotation point
+*/
+void SVTK_ViewWindow::onChangeRotationPoint(bool theIsActivate)
+{
+ if(theIsActivate){
+ mySetRotationPointDlg->addObserver();
+ if ( mySetRotationPointDlg->IsFirstShown() )
+ activateSetRotationGravity();
+ mySetRotationPointDlg->show();
+ }else
+ mySetRotationPointDlg->hide();
}
-void
-SVTK_ViewWindow
-::onAdjustCubeAxes()
-{
- AdjustTrihedrons(false);
+/*!
+ Set the gravity center as a rotation point
+*/
+void SVTK_ViewWindow::activateSetRotationGravity()
+{
+ myEventDispatcher->InvokeEvent(SVTK::SetRotateGravity,0);
}
-#define INCREMENT_FOR_OP 10
+/*!
+ Set the selected point as a rotation point
+*/
+void SVTK_ViewWindow::activateSetRotationSelected(void* theData)
+{
+ myEventDispatcher->InvokeEvent(SVTK::ChangeRotationPoint,theData);
+}
-//=======================================================================
-// name : onPanLeft
-// Purpose : Performs incremental panning to the left
-//=======================================================================
-void
-SVTK_ViewWindow
-::onPanLeft()
+/*!
+ Set the gravity center of element selected by user as a rotation point
+*/
+void SVTK_ViewWindow::activateStartPointSelection( Selection_Mode theSelectionMode )
{
- myRWInteractor->GetSInteractorStyle()->IncrementalPan( -INCREMENT_FOR_OP, 0 );
+ SetSelectionMode( theSelectionMode );
+ myEventDispatcher->InvokeEvent(SVTK::StartPointSelection,0);
}
-//=======================================================================
-// name : onPanRight
-// Purpose : Performs incremental panning to the right
-//=======================================================================
-void
-SVTK_ViewWindow
-::onPanRight()
+/*!
+ Set the view projection mode: orthogonal or perspective
+*/
+void SVTK_ViewWindow::onPerspectiveMode()
{
- myRWInteractor->GetSInteractorStyle()->IncrementalPan( INCREMENT_FOR_OP, 0 );
+ bool anIsParallelMode = toolMgr()->action( ParallelModeId )->isChecked();
+
+ // advanced zooming is not available in perspective mode
+ if( QtxAction* anAction = getAction( SwitchZoomingStyleId ) )
+ anAction->setEnabled( anIsParallelMode );
+
+ vtkCamera* aCamera = getRenderer()->GetActiveCamera();
+ aCamera->SetParallelProjection(anIsParallelMode);
+ GetInteractor()->GetDevice()->CreateTimer(VTKI_TIMER_FIRST);
+
+ emit transformed( this );
}
-//=======================================================================
-// name : onPanUp
-// Purpose : Performs incremental panning to the top
-//=======================================================================
-void
-SVTK_ViewWindow
-::onPanUp()
+void SVTK_ViewWindow::SetEventDispatcher(vtkObject* theDispatcher)
{
- myRWInteractor->GetSInteractorStyle()->IncrementalPan( 0, INCREMENT_FOR_OP );
+ myEventDispatcher = theDispatcher;
}
-//=======================================================================
-// name : onPanDown
-// Purpose : Performs incremental panning to the bottom
-//=======================================================================
-void
-SVTK_ViewWindow
-::onPanDown()
+/*!
+ Creates all actions of svtk main window
+*/
+void SVTK_ViewWindow::createActions(SUIT_ResourceMgr* theResourceMgr)
{
- myRWInteractor->GetSInteractorStyle()->IncrementalPan( 0, -INCREMENT_FOR_OP );
+ QtxAction* anAction;
+ QtxActionToolMgr* mgr = toolMgr();
+
+ // Dump view
+ anAction = new QtxAction(tr("MNU_DUMP_VIEW"),
+ theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_DUMP" ) ),
+ tr( "MNU_DUMP_VIEW" ), 0, this);
+ anAction->setStatusTip(tr("DSC_DUMP_VIEW"));
+ connect(anAction, SIGNAL(activated()), this, SLOT(onDumpView()));
+ mgr->registerAction( anAction, DumpId );
+
+ // FitAll
+ anAction = new QtxAction(tr("MNU_FITALL"),
+ theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITALL" ) ),
+ tr( "MNU_FITALL" ), 0, this);
+ anAction->setStatusTip(tr("DSC_FITALL"));
+ connect(anAction, SIGNAL(activated()), this, SLOT(onFitAll()));
+ mgr->registerAction( anAction, FitAllId );
+
+ // FitRect
+ anAction = new QtxAction(tr("MNU_FITRECT"),
+ theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITAREA" ) ),
+ tr( "MNU_FITRECT" ), 0, this);
+ anAction->setStatusTip(tr("DSC_FITRECT"));
+ connect(anAction, SIGNAL(activated()), this, SLOT(activateWindowFit()));
+ mgr->registerAction( anAction, FitRectId );
+
+ // Zoom
+ anAction = new QtxAction(tr("MNU_ZOOM_VIEW"),
+ theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ZOOM" ) ),
+ tr( "MNU_ZOOM_VIEW" ), 0, this);
+ anAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
+ connect(anAction, SIGNAL(activated()), this, SLOT(activateZoom()));
+ mgr->registerAction( anAction, ZoomId );
+
+ // Panning
+ anAction = new QtxAction(tr("MNU_PAN_VIEW"),
+ theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_PAN" ) ),
+ tr( "MNU_PAN_VIEW" ), 0, this);
+ anAction->setStatusTip(tr("DSC_PAN_VIEW"));
+ connect(anAction, SIGNAL(activated()), this, SLOT(activatePanning()));
+ mgr->registerAction( anAction, PanId );
+
+ // Global Panning
+ anAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"),
+ theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_GLOBALPAN" ) ),
+ tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
+ anAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
+ connect(anAction, SIGNAL(activated()), this, SLOT(activateGlobalPanning()));
+ mgr->registerAction( anAction, GlobalPanId );
+
+ // Change rotation point
+ anAction = new QtxAction(tr("MNU_CHANGINGROTATIONPOINT_VIEW"),
+ theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_ROTATION_POINT" ) ),
+ tr( "MNU_CHANGINGROTATIONPOINT_VIEW" ), 0, this);
+ anAction->setStatusTip(tr("DSC_CHANGINGROTATIONPOINT_VIEW"));
+ anAction->setCheckable(true);
+ connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onChangeRotationPoint(bool)));
+ mgr->registerAction( anAction, ChangeRotationPointId );
+
+ // Rotation
+ anAction = new QtxAction(tr("MNU_ROTATE_VIEW"),
+ theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ROTATE" ) ),
+ tr( "MNU_ROTATE_VIEW" ), 0, this);
+ anAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
+ connect(anAction, SIGNAL(activated()), this, SLOT(activateRotation()));
+ mgr->registerAction( anAction, RotationId );
+
+ // Projections
+ anAction = new QtxAction(tr("MNU_FRONT_VIEW"),
+ theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FRONT" ) ),
+ tr( "MNU_FRONT_VIEW" ), 0, this, false, "Viewers:Front view");
+ anAction->setStatusTip(tr("DSC_FRONT_VIEW"));
+ connect(anAction, SIGNAL(activated()), this, SLOT(onFrontView()));
+ this->addAction(anAction);
+ mgr->registerAction( anAction, FrontId );
+
+ anAction = new QtxAction(tr("MNU_BACK_VIEW"),
+ theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BACK" ) ),
+ tr( "MNU_BACK_VIEW" ), 0, this, false, "Viewers:Back view");
+ anAction->setStatusTip(tr("DSC_BACK_VIEW"));
+ connect(anAction, SIGNAL(activated()), this, SLOT(onBackView()));
+ this->addAction(anAction);
+ mgr->registerAction( anAction, BackId );
+
+ anAction = new QtxAction(tr("MNU_TOP_VIEW"),
+ theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TOP" ) ),
+ tr( "MNU_TOP_VIEW" ), 0, this, false, "Viewers:Top view");
+ anAction->setStatusTip(tr("DSC_TOP_VIEW"));
+ connect(anAction, SIGNAL(activated()), this, SLOT(onTopView()));
+ this->addAction(anAction);
+ mgr->registerAction( anAction, TopId );
+
+ anAction = new QtxAction(tr("MNU_BOTTOM_VIEW"),
+ theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BOTTOM" ) ),
+ tr( "MNU_BOTTOM_VIEW" ), 0, this, false, "Viewers:Bottom view");
+ anAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
+ connect(anAction, SIGNAL(activated()), this, SLOT(onBottomView()));
+ this->addAction(anAction);
+ mgr->registerAction( anAction, BottomId );
+
+ anAction = new QtxAction(tr("MNU_LEFT_VIEW"),
+ theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_LEFT" ) ),
+ tr( "MNU_LEFT_VIEW" ), 0, this, false, "Viewers:Left view");
+ anAction->setStatusTip(tr("DSC_LEFT_VIEW"));
+ connect(anAction, SIGNAL(activated()), this, SLOT(onLeftView()));
+ this->addAction(anAction);
+ mgr->registerAction( anAction, LeftId );
+
+ anAction = new QtxAction(tr("MNU_RIGHT_VIEW"),
+ theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RIGHT" ) ),
+ tr( "MNU_RIGHT_VIEW" ), 0, this, false, "Viewers:Right view");
+ anAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
+ connect(anAction, SIGNAL(activated()), this, SLOT(onRightView()));
+ this->addAction(anAction);
+ mgr->registerAction( anAction, RightId );
+
+ // rotate anticlockwise
+ anAction = new QtxAction(tr("MNU_ANTICLOCKWISE_VIEW"),
+ theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ANTICLOCKWISE" ) ),
+ tr( "MNU_ANTICLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate anticlockwise");
+ anAction->setStatusTip(tr("DSC_ANTICLOCKWISE_VIEW"));
+ connect(anAction, SIGNAL(triggered()), this, SLOT(onAntiClockWiseView()));
+ this->addAction(anAction);
+ mgr->registerAction( anAction, AntiClockWiseId );
+
+ // rotate clockwise
+ anAction = new QtxAction(tr("MNU_CLOCKWISE_VIEW"),
+ theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_CLOCKWISE" ) ),
+ tr( "MNU_CLOCKWISE_VIEW" ), 0, this, false, "Viewers:Rotate clockwise");
+ anAction->setStatusTip(tr("DSC_CLOCKWISE_VIEW"));
+ connect(anAction, SIGNAL(triggered()), this, SLOT(onClockWiseView()));
+ this->addAction(anAction);
+ mgr->registerAction( anAction, ClockWiseId );
+
+ // Reset
+ anAction = new QtxAction(tr("MNU_RESET_VIEW"),
+ theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RESET" ) ),
+ tr( "MNU_RESET_VIEW" ), 0, this, false, "Viewers:Reset view");
+ anAction->setStatusTip(tr("DSC_RESET_VIEW"));
+ connect(anAction, SIGNAL(activated()), this, SLOT(onResetView()));
+ this->addAction(anAction);
+ mgr->registerAction( anAction, ResetId );
+
+ // onViewTrihedron: Shows - Hides Trihedron
+ anAction = new QtxAction(tr("MNU_SHOW_TRIHEDRON"),
+ theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TRIHEDRON" ) ),
+ tr( "MNU_SHOW_TRIHEDRON" ), 0, this);
+ anAction->setCheckable( true );
+ anAction->setChecked( true );
+
+ anAction->setStatusTip(tr("DSC_SHOW_TRIHEDRON"));
+ connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onViewTrihedron(bool)));
+ mgr->registerAction( anAction, ViewTrihedronId );
+
+ // onNonIsometric: Manage non-isometric params
+ anAction = new QtxAction(tr("MNU_SVTK_SCALING"),
+ theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_SCALING" ) ),
+ tr( "MNU_SVTK_SCALING" ), 0, this);
+ anAction->setStatusTip(tr("DSC_SVTK_SCALING"));
+ anAction->setCheckable(true);
+ connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onNonIsometric(bool)));
+ mgr->registerAction( anAction, NonIsometric );
+
+ // onGraduatedAxes: Manage graduated axes params
+ anAction = new QtxAction(tr("MNU_SVTK_GRADUATED_AXES"),
+ theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_GRADUATED_AXES" ) ),
+ tr( "MNU_SVTK_GRADUATED_AXES" ), 0, this);
+ anAction->setStatusTip(tr("DSC_SVTK_GRADUATED_AXES"));
+ anAction->setCheckable(true);
+ connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onGraduatedAxes(bool)));
+ mgr->registerAction( anAction, GraduatedAxes );
+
+ // onGraduatedAxes: Manage graduated axes params
+ anAction = new QtxAction(tr("MNU_SVTK_UPDATE_RATE"),
+ theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_UPDATE_RATE" ) ),
+ tr( "MNU_SVTK_UPDATE_RATE" ), 0, this);
+ anAction->setStatusTip(tr("DSC_SVTK_UPDATE_RATE"));
+ anAction->setCheckable(true);
+ connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onUpdateRate(bool)));
+ mgr->registerAction( anAction, UpdateRate );
+
+ // Set perspective mode group
+ anAction = new QtxAction(tr("MNU_SVTK_PARALLEL_MODE"),
+ theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_VIEW_PARALLEL" ) ),
+ tr( "MNU_SVTK_PARALLEL_MODE" ), 0, this);
+ anAction->setStatusTip(tr("DSC_SVTK_PARALLEL_MODE"));
+ anAction->setCheckable(true);
+ connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onPerspectiveMode()));
+ mgr->registerAction( anAction, ParallelModeId );
+
+ anAction = new QtxAction(tr("MNU_SVTK_PERSPECTIVE_MODE"),
+ theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_VIEW_PERSPECTIVE" ) ),
+ tr( "MNU_SVTK_PERSPECTIVE_MODE" ), 0, this);
+ anAction->setStatusTip(tr("DSC_SVTK_PERSPECTIVE_MODE"));
+ anAction->setCheckable(true);
+ connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onPerspectiveMode()));
+ mgr->registerAction( anAction, ProjectionModeId );
+
+ QActionGroup* aPerspectiveGroup = new QActionGroup( this );
+ aPerspectiveGroup->addAction( mgr->action( ParallelModeId ) );
+ aPerspectiveGroup->addAction( mgr->action( ProjectionModeId ) );
+
+ // View Parameters
+ anAction = new QtxAction(tr("MNU_VIEWPARAMETERS_VIEW"),
+ theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_VIEW_PARAMETERS" ) ),
+ tr( "MNU_VIEWPARAMETERS_VIEW" ), 0, this);
+ anAction->setStatusTip(tr("DSC_VIEWPARAMETERS_VIEW"));
+ anAction->setCheckable(true);
+ connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onViewParameters(bool)));
+ mgr->registerAction( anAction, ViewParametersId );
+
+ // Synchronize View
+ mgr->registerAction( synchronizeAction(), SynchronizeId );
+
+ // Switch between interaction styles
+ anAction = new QtxAction(tr("MNU_SVTK_STYLE_SWITCH"),
+ theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_STYLE_SWITCH" ) ),
+ tr( "MNU_SVTK_STYLE_SWITCH" ), 0, this);
+ anAction->setStatusTip(tr("DSC_SVTK_STYLE_SWITCH"));
+ anAction->setCheckable(true);
+ connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchInteractionStyle(bool)));
+ mgr->registerAction( anAction, SwitchInteractionStyleId );
+
+ // Switch between zooming styles
+ anAction = new QtxAction(tr("MNU_SVTK_ZOOMING_STYLE_SWITCH"),
+ theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_ZOOMING_STYLE_SWITCH" ) ),
+ tr( "MNU_SVTK_ZOOMING_STYLE_SWITCH" ), 0, this);
+ anAction->setStatusTip(tr("DSC_SVTK_ZOOMING_STYLE_SWITCH"));
+ anAction->setCheckable(true);
+ connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchZoomingStyle(bool)));
+ mgr->registerAction( anAction, SwitchZoomingStyleId );
+
+ // Pre-selection
+ QSignalMapper* aSignalMapper = new QSignalMapper( this );
+ connect(aSignalMapper, SIGNAL(mapped(int)), this, SLOT(onSwitchPreSelectionMode(int)));
+
+ anAction = new QtxAction(tr("MNU_SVTK_PRESELECTION_STANDARD"),
+ theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_PRESELECTION_STANDARD" ) ),
+ tr( "MNU_SVTK_PRESELECTION_STANDARD" ), 0, this);
+ anAction->setStatusTip(tr("DSC_SVTK_PRESELECTION_STANDARD"));
+ anAction->setCheckable(true);
+ connect(anAction, SIGNAL(activated()), aSignalMapper, SLOT(map()));
+ aSignalMapper->setMapping( anAction, Standard_Preselection );
+ mgr->registerAction( anAction, StandardPreselectionId );
+
+ anAction = new QtxAction(tr("MNU_SVTK_PRESELECTION_DYNAMIC"),
+ theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_PRESELECTION_DYNAMIC" ) ),
+ tr( "MNU_SVTK_PRESELECTION_DYNAMIC" ), 0, this);
+ anAction->setStatusTip(tr("DSC_SVTK_PRESELECTION_DYNAMIC"));
+ anAction->setCheckable(true);
+ connect(anAction, SIGNAL(activated()), aSignalMapper, SLOT(map()));
+ aSignalMapper->setMapping( anAction, Dynamic_Preselection );
+ mgr->registerAction( anAction, DynamicPreselectionId );
+
+ anAction = new QtxAction(tr("MNU_SVTK_PRESELECTION_DISABLED"),
+ theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_PRESELECTION_DISABLED" ) ),
+ tr( "MNU_SVTK_PRESELECTION_DISABLED" ), 0, this);
+ anAction->setStatusTip(tr("DSC_SVTK_PRESELECTION_DISABLED"));
+ anAction->setCheckable(true);
+ connect(anAction, SIGNAL(activated()), aSignalMapper, SLOT(map()));
+ aSignalMapper->setMapping( anAction, Preselection_Disabled );
+ mgr->registerAction( anAction, DisablePreselectionId );
+
+ QtxActionGroup* aPreselectionAction = new QtxActionGroup( this, true );
+ aPreselectionAction->add( getAction( StandardPreselectionId ) );
+ aPreselectionAction->add( getAction( DynamicPreselectionId ) );
+ aPreselectionAction->add( getAction( DisablePreselectionId ) );
+ mgr->registerAction( aPreselectionAction, PreselectionId );
+
+ // Selection
+ anAction = new QtxAction(tr("MNU_SVTK_ENABLE_SELECTION"),
+ theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_SELECTION" ) ),
+ tr( "MNU_SVTK_ENABLE_SELECTION" ), 0, this);
+ anAction->setStatusTip(tr("DSC_SVTK_ENABLE_SELECTION"));
+ anAction->setCheckable(true);
+ connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onEnableSelection(bool)));
+ mgr->registerAction( anAction, EnableSelectionId );
+
+ // Start recording
+ myStartAction = new QtxAction(tr("MNU_SVTK_RECORDING_START"),
+ theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_START" ) ),
+ tr( "MNU_SVTK_RECORDING_START" ), 0, this);
+ myStartAction->setStatusTip(tr("DSC_SVTK_RECORDING_START"));
+ connect( myStartAction, SIGNAL( triggered ( bool ) ), this, SLOT( onStartRecording() ) );
+ mgr->registerAction( myStartAction, StartRecordingId );
+
+ // Play recording
+ myPlayAction = new QtxAction(tr("MNU_SVTK_RECORDING_PLAY"),
+ theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_PLAY" ) ),
+ tr( "MNU_SVTK_RECORDING_PLAY" ), 0, this);
+ myPlayAction->setStatusTip(tr("DSC_SVTK_RECORDING_PLAY"));
+ myPlayAction->setEnabled( false );
+ connect( myPlayAction, SIGNAL( triggered ( bool ) ), this, SLOT( onPlayRecording() ) );
+ mgr->registerAction( myPlayAction, PlayRecordingId );
+
+ // Pause recording
+ myPauseAction = new QtxAction(tr("MNU_SVTK_RECORDING_PAUSE"),
+ theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_PAUSE" ) ),
+ tr( "MNU_SVTK_RECORDING_PAUSE" ), 0, this);
+ myPauseAction->setStatusTip(tr("DSC_SVTK_RECORDING_PAUSE"));
+ myPauseAction->setEnabled( false );
+ connect( myPauseAction, SIGNAL( triggered ( bool ) ), this, SLOT( onPauseRecording() ) );
+ mgr->registerAction( myPauseAction, PauseRecordingId );
+
+ // Stop recording
+ myStopAction = new QtxAction(tr("MNU_SVTK_RECORDING_STOP"),
+ theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_RECORDING_STOP" ) ),
+ tr( "MNU_SVTK_RECORDING_STOP" ), 0, this);
+ myStopAction->setStatusTip(tr("DSC_SVTK_RECORDING_STOP"));
+ myStopAction->setEnabled( false );
+ connect( myStopAction, SIGNAL( triggered ( bool ) ), this, SLOT( onStopRecording() ) );
+ mgr->registerAction( myStopAction, StopRecordingId );
}
-//=======================================================================
-// name : onZoomIn
-// Purpose : Performs incremental zooming in
-//=======================================================================
-void
-SVTK_ViewWindow
-::onZoomIn()
+/*!
+ Creates toolbar of svtk main window
+*/
+void SVTK_ViewWindow::createToolBar()
{
- myRWInteractor->GetSInteractorStyle()->IncrementalZoom( INCREMENT_FOR_OP );
+ QtxActionToolMgr* mgr = toolMgr();
+
+ mgr->append( DumpId, myToolBar );
+ mgr->append( SwitchInteractionStyleId, myToolBar );
+ mgr->append( SwitchZoomingStyleId, myToolBar );
+
+ mgr->append( mgr->separator(), myToolBar );
+
+ mgr->append( PreselectionId, myToolBar );
+ mgr->append( EnableSelectionId, myToolBar );
+
+ mgr->append( mgr->separator(), myToolBar );
+
+ mgr->append( ViewTrihedronId, myToolBar );
+
+ QtxMultiAction* aScaleAction = new QtxMultiAction( this );
+ aScaleAction->insertAction( getAction( FitAllId ) );
+ aScaleAction->insertAction( getAction( FitRectId ) );
+ aScaleAction->insertAction( getAction( ZoomId ) );
+ mgr->append( aScaleAction, myToolBar );
+
+ QtxMultiAction* aPanningAction = new QtxMultiAction( this );
+ aPanningAction->insertAction( getAction( PanId ) );
+ aPanningAction->insertAction( getAction( GlobalPanId ) );
+ mgr->append( aPanningAction, myToolBar );
+
+ mgr->append( ChangeRotationPointId, myToolBar );
+
+ mgr->append( RotationId, myToolBar );
+
+ QtxMultiAction* aViewsAction = new QtxMultiAction( this );
+ aViewsAction->insertAction( getAction( FrontId ) );
+ aViewsAction->insertAction( getAction( BackId ) );
+ aViewsAction->insertAction( getAction( TopId ) );
+ aViewsAction->insertAction( getAction( BottomId ) );
+ aViewsAction->insertAction( getAction( LeftId ) );
+ aViewsAction->insertAction( getAction( RightId ) );
+ mgr->append( aViewsAction, myToolBar );
+
+ mgr->append( AntiClockWiseId, myToolBar );
+ mgr->append( ClockWiseId, myToolBar );
+
+ mgr->append( ResetId, myToolBar );
+
+ mgr->append( UpdateRate, myToolBar );
+ mgr->append( NonIsometric, myToolBar );
+ mgr->append( GraduatedAxes, myToolBar );
+
+ mgr->append( ViewParametersId, myToolBar );
+ mgr->append( SynchronizeId, myToolBar );
+
+ mgr->append( toolMgr()->separator(), myToolBar );
+
+ mgr->append( ParallelModeId, myToolBar );
+ mgr->append( ProjectionModeId, myToolBar );
+
+ mgr->append( StartRecordingId, myRecordingToolBar );
+ mgr->append( PlayRecordingId, myRecordingToolBar );
+ mgr->append( PauseRecordingId, myRecordingToolBar );
+ mgr->append( StopRecordingId, myRecordingToolBar );
}
-//=======================================================================
-// name : onZoomOut
-// Purpose : Performs incremental zooming out
-//=======================================================================
-void
-SVTK_ViewWindow
-::onZoomOut()
+void SVTK_ViewWindow::onUpdateRate(bool theIsActivate)
{
- myRWInteractor->GetSInteractorStyle()->IncrementalZoom( -INCREMENT_FOR_OP );
+ if(theIsActivate){
+ myUpdateRateDlg->Update();
+ myUpdateRateDlg->show();
+ }else
+ myUpdateRateDlg->hide();
}
-//=======================================================================
-// name : onRotateLeft
-// Purpose : Performs incremental rotating to the left
-//=======================================================================
-void
-SVTK_ViewWindow
-::onRotateLeft()
+void SVTK_ViewWindow::onNonIsometric(bool theIsActivate)
{
- myRWInteractor->GetSInteractorStyle()->IncrementalRotate( -INCREMENT_FOR_OP, 0 );
+ if(theIsActivate){
+ myNonIsometricDlg->Update();
+ myNonIsometricDlg->show();
+ }else
+ myNonIsometricDlg->hide();
}
-//=======================================================================
-// name : onRotateRight
-// Purpose : Performs incremental rotating to the right
-//=======================================================================
-void
-SVTK_ViewWindow
-::onRotateRight()
+void SVTK_ViewWindow::onGraduatedAxes(bool theIsActivate)
{
- myRWInteractor->GetSInteractorStyle()->IncrementalRotate( INCREMENT_FOR_OP, 0 );
+ if(theIsActivate){
+ myCubeAxesDlg->Update();
+ myCubeAxesDlg->show();
+ }else
+ myCubeAxesDlg->hide();
}
-//=======================================================================
-// name : onRotateUp
-// Purpose : Performs incremental rotating to the top
-//=======================================================================
-void
-SVTK_ViewWindow
-::onRotateUp()
+/*!
+ Starts rotation transformation
+*/
+void SVTK_ViewWindow::activateRotation()
{
- myRWInteractor->GetSInteractorStyle()->IncrementalRotate( 0, -INCREMENT_FOR_OP );
+ myEventDispatcher->InvokeEvent(SVTK::StartRotate,0);
}
-//=======================================================================
-void
-SVTK_ViewWindow
-::onKeyPressed(QKeyEvent* event)
+
+/*!
+ Starts panning transformation
+*/
+void SVTK_ViewWindow::activatePanning()
{
- emit keyPressed( this, event );
+ myEventDispatcher->InvokeEvent(SVTK::StartPan,0);
}
-//=======================================================================
-void
-SVTK_ViewWindow
-::onKeyReleased(QKeyEvent* event)
+/*!
+ Starts zoom transformation
+*/
+void SVTK_ViewWindow::activateZoom()
{
- emit keyReleased( this, event );
+ myEventDispatcher->InvokeEvent(SVTK::StartZoom,0);
}
-//=======================================================================
-void
-SVTK_ViewWindow
-::onMousePressed(QMouseEvent* event)
+/*!
+ Starts window fit transformation
+*/
+void SVTK_ViewWindow::activateWindowFit()
{
- emit mousePressed(this, event);
+ myEventDispatcher->InvokeEvent(SVTK::StartFitArea,0);
}
-//=======================================================================
-void
-SVTK_ViewWindow
-::onMouseReleased(QMouseEvent* event)
+/*!
+ Starts global panning transformation
+*/
+void SVTK_ViewWindow::activateGlobalPanning()
{
- emit mouseReleased( this, event );
+ myEventDispatcher->InvokeEvent(SVTK::StartGlobalPan,0);
}
-//=======================================================================
-void
-SVTK_ViewWindow
-::onMouseMoving(QMouseEvent* event)
+void SVTK_ViewWindow::onStartRecording()
{
- emit mouseMoving( this, event );
+ myRecorder->CheckExistAVIMaker();
+ if (myRecorder->ErrorStatus()) {
+ SUIT_MessageBox::warning(this, tr("ERROR"), tr("MSG_NO_AVI_MAKER") );
+ }
+ else {
+ SVTK_RecorderDlg* aRecorderDlg = new SVTK_RecorderDlg( this, myRecorder );
+
+ if( !aRecorderDlg->exec() )
+ return;
+
+ myStartAction->setEnabled( false );
+ myPlayAction->setEnabled( false );
+ myPauseAction->setEnabled( true );
+ myStopAction->setEnabled( true );
+
+ // to prevent resizing the window while recording
+ myPreRecordingMinSize = minimumSize();
+ myPreRecordingMaxSize = maximumSize();
+ setFixedSize( size() );
+
+ myRecorder->Record();
+ }
}
-//=======================================================================
-void
-SVTK_ViewWindow
-::onMouseDoubleClicked( QMouseEvent* event )
+void SVTK_ViewWindow::onPlayRecording()
{
- emit mouseDoubleClicked( this, event );
+ myStartAction->setEnabled( false );
+ myPlayAction->setEnabled( false );
+ myPauseAction->setEnabled( true );
+ myStopAction->setEnabled( true );
+
+ myRecorder->Pause();
}
-//=======================================================================
-// name : onRotateDown
-// Purpose : Performs incremental rotating to the bottom
-//=======================================================================
-void
-SVTK_ViewWindow
-::onRotateDown()
+void SVTK_ViewWindow::onPauseRecording()
{
- myRWInteractor->GetSInteractorStyle()->IncrementalRotate( 0, INCREMENT_FOR_OP );
+ myStartAction->setEnabled( false );
+ myPlayAction->setEnabled( true );
+ myPauseAction->setEnabled( false );
+ myStopAction->setEnabled( true );
+
+ myRecorder->Pause();
}
-//----------------------------------------------------------------------------
-void
-SVTK_ViewWindow
-::InsertActor( SALOME_Actor* theActor, bool theMoveInternalActors )
+void SVTK_ViewWindow::onStopRecording()
{
- theActor->AddToRender(myRenderer);
- theActor->SetTransform(myTransform);
- if(theMoveInternalActors)
- myRWInteractor->MoveInternalActors();
+ myStartAction->setEnabled( true );
+ myPlayAction->setEnabled( false );
+ myPauseAction->setEnabled( false );
+ myStopAction->setEnabled( false );
+
+ myRecorder->Stop();
+
+ setMinimumSize( myPreRecordingMinSize );
+ setMaximumSize( myPreRecordingMaxSize );
}
-//----------------------------------------------------------------------------
-void
-SVTK_ViewWindow
-::AddActor( SALOME_Actor* theActor, bool theUpdate /*=false*/ )
+/*!
+ To invoke a VTK event on SVTK_RenderWindowInteractor instance
+*/
+void SVTK_ViewWindow::InvokeEvent(unsigned long theEvent, void* theCallData)
{
- InsertActor(theActor);
- if(theUpdate)
- Repaint();
+ GetInteractor()->InvokeEvent(theEvent,theCallData);
}
-//----------------------------------------------------------------------------
-void
-SVTK_ViewWindow
-::RemoveActor( SALOME_Actor* theActor, bool theUpdate /*=false*/ )
+/*!
+ Modify view parameters
+*/
+void SVTK_ViewWindow::onViewParameters(bool theIsActivate)
{
- theActor->RemoveFromRender(myRenderer);
- if(theUpdate)
- Repaint();
+ if(theIsActivate){
+ myViewParameterDlg->addObserver();
+ myViewParameterDlg->show();
+ }else
+ myViewParameterDlg->hide();
}
-//----------------------------------------------------------------------------
-void
-SVTK_ViewWindow
-::MoveActor( SALOME_Actor* theActor)
+/*!
+ Custom show event handler
+*/
+void SVTK_ViewWindow::showEvent( QShowEvent * theEvent )
{
- RemoveActor(theActor);
- InsertActor(theActor,true);
+ emit Show( theEvent );
}
-//----------------------------------------------------------------------------
-QImage
-SVTK_ViewWindow
-::dumpView()
+/*!
+ Custom hide event handler
+*/
+void SVTK_ViewWindow::hideEvent( QHideEvent * theEvent )
{
- QPixmap px = QPixmap::grabWindow( myRenderWindow->winId() );
- return px.convertToImage();
+ emit Hide( theEvent );
}
-//----------------------------------------------------------------------------
-void
-SVTK_ViewWindow
-::action( const int theAction )
+/*!
+ Emit transformed signal.
+*/
+void SVTK_ViewWindow::emitTransformed() {
+ transformed(this);
+}
+
+/*!
+ Processes events
+*/
+void SVTK_ViewWindow::ProcessEvents(vtkObject* vtkNotUsed(theObject),
+ unsigned long theEvent,
+ void* theClientData,
+ void* theCallData)
{
- switch ( theAction ) {
- case SUIT_Accel::PanLeft : onPanLeft(); break;
- case SUIT_Accel::PanRight : onPanRight(); break;
- case SUIT_Accel::PanUp : onPanUp(); break;
- case SUIT_Accel::PanDown : onPanDown(); break;
- case SUIT_Accel::ZoomIn : onZoomIn(); break;
- case SUIT_Accel::ZoomOut : onZoomOut(); break;
- case SUIT_Accel::ZoomFit : onFitAll(); break;
- case SUIT_Accel::RotateLeft : onRotateLeft(); break;
- case SUIT_Accel::RotateRight : onRotateRight(); break;
- case SUIT_Accel::RotateUp : onRotateUp(); break;
- case SUIT_Accel::RotateDown : onRotateDown(); break;
- }
+ SVTK_ViewWindow* self = reinterpret_cast<SVTK_ViewWindow*>(theClientData);
+ if(self)
+ self->emitTransformed();
+}
+
+/*!
+ Get camera properties for the SVTK view window.
+ \return shared pointer on camera properties.
+*/
+SUIT_CameraProperties SVTK_ViewWindow::cameraProperties()
+{
+ SUIT_CameraProperties aProps;
+
+ // get vtk camera
+ vtkCamera* aCamera = getRenderer()->GetActiveCamera();
+ if ( !aCamera )
+ return aProps;
+
+ aProps.setDimension( SUIT_CameraProperties::Dim3D );
+ if ( toolMgr()->action( ParallelModeId ) ) {
+ if ( toolMgr()->action( ParallelModeId )->isChecked() )
+ aProps.setProjection( SUIT_CameraProperties::PrjOrthogonal );
+ else
+ aProps.setProjection( SUIT_CameraProperties::PrjPerspective );
+ }
+
+ double aFocalPoint[3];
+ double aPosition[3];
+ double aViewUp[3];
+ double anAxialScale[3];
+
+ aCamera->OrthogonalizeViewUp();
+ aCamera->GetFocalPoint( aFocalPoint );
+ aCamera->GetPosition( aPosition );
+ aCamera->GetViewUp( aViewUp );
+
+ aProps.setFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
+ aProps.setPosition( aPosition[0], aPosition[1], aPosition[2] );
+ aProps.setViewUp( aViewUp[0], aViewUp[1], aViewUp[2] );
+ aProps.setMappingScale( aCamera->GetParallelScale() * 2.0 );
+
+ if ( aProps.getProjection() == SUIT_CameraProperties::PrjPerspective )
+ {
+ aProps.setViewAngle( aCamera->GetViewAngle() );
+ }
+
+ GetRenderer()->GetScale( anAxialScale );
+ aProps.setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
+
+ return aProps;
+}
+
+/*!
+ Synchronize views.
+ This implementation synchronizes camera propreties.
+*/
+void SVTK_ViewWindow::synchronize( SUIT_ViewWindow* theView )
+{
+ bool blocked = blockSignals( true );
+
+ SUIT_CameraProperties aProps = theView->cameraProperties();
+ if ( !cameraProperties().isCompatible( aProps ) ) {
+ // other view, this one is being currently synchronized to, seems has become incompatible
+ // we have to break synchronization
+ updateSyncViews();
+ return;
+ }
+
+ // get camera
+ vtkCamera* aCamera = getRenderer()->GetActiveCamera();
+
+ double aFocalPoint[3];
+ double aPosition[3];
+ double aViewUp[3];
+ double anAxialScale[3];
+
+ // get common properties
+ aProps.getViewUp( aViewUp[0], aViewUp[1], aViewUp[2] );
+ aProps.getPosition( aPosition[0], aPosition[1], aPosition[2] );
+ aProps.getFocalPoint( aFocalPoint[0], aFocalPoint[1], aFocalPoint[2] );
+ aProps.getAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
+
+ // restore properties to the camera
+ aCamera->SetViewUp( aViewUp );
+ aCamera->SetPosition( aPosition );
+ aCamera->SetFocalPoint( aFocalPoint );
+ aCamera->SetParallelScale( aProps.getMappingScale() / 2.0 );
+
+ if ( aProps.getProjection() == SUIT_CameraProperties::PrjPerspective )
+ {
+ aCamera->SetViewAngle( aProps.getViewAngle() );
+ }
+
+ GetRenderer()->SetScale( anAxialScale );
+
+ getRenderer()->ResetCameraClippingRange();
+ Repaint( false );
+
+ blockSignals( blocked );
}