#include <vtkCamera.h>
#include <vtkPointPicker.h>
#include <vtkCellPicker.h>
+#include <vtkAxisActor2D.h>
#include "QtxAction.h"
#include "SVTK_InteractorStyle.h"
#include "SVTK_RenderWindowInteractor.h"
#include "SVTK_GenericRenderWindowInteractor.h"
+#include "SVTK_CubeAxesActor2D.h"
#include "SALOME_ListIteratorOfListIO.hxx"
#include "VTKViewer_Algorithm.h"
#include "SVTK_Functor.h"
-//----------------------------------------------------------------------------
+/*!
+ Constructor
+*/
SVTK_ViewWindow
::SVTK_ViewWindow(SUIT_Desktop* theDesktop):
SUIT_ViewWindow(theDesktop),
myView(NULL)
{}
+/*!
+ To initialize #SVTK_ViewWindow instance
+*/
void
SVTK_ViewWindow
::Initialize(SVTK_ViewModelBase* theModel)
}
}
+/*!
+ To initialize #SVTK_ViewWindow instance
+*/
void
SVTK_ViewWindow
::Initialize(SVTK_View* theView,
theModel,SLOT(onSelectionChanged()));
}
+/*!
+ Destructor
+*/
SVTK_ViewWindow
::~SVTK_ViewWindow()
{}
-//----------------------------------------------------------------------------
+/*!
+ \return corresponding view
+*/
SVTK_View*
SVTK_ViewWindow
::getView()
return myView;
}
+/*!
+ \return corresponding vtk main window
+*/
SVTK_MainWindow*
SVTK_ViewWindow
::getMainWindow()
return myMainWindow;
}
+/*!
+ \return corresponding vtk render window
+*/
vtkRenderWindow*
SVTK_ViewWindow
::getRenderWindow()
return getMainWindow()->getRenderWindow();
}
+/*!
+ \return corresponding vtk render window interactor
+*/
vtkRenderWindowInteractor*
SVTK_ViewWindow
::getInteractor()
return getMainWindow()->getInteractor();
}
+/*!
+ \return corresponding vtk renderer
+*/
vtkRenderer*
SVTK_ViewWindow
::getRenderer()
return myMainWindow->getRenderer();
}
+/*!
+ \return corresponding vtk selector
+*/
SVTK_Selector*
SVTK_ViewWindow
::GetSelector()
return myMainWindow->GetSelector();
}
-
-//----------------------------------------------------------------------------
+/*!
+ Processes transformation "front view"
+*/
void
SVTK_ViewWindow
::onFrontView()
myMainWindow->onFrontView();
}
-//----------------------------------------------------------------------------
+/*!
+ Processes transformation "back view"
+*/
void
SVTK_ViewWindow
::onBackView()
myMainWindow->onBackView();
}
-//----------------------------------------------------------------------------
+/*!
+ Processes transformation "top view"
+*/
void
SVTK_ViewWindow
::onTopView()
myMainWindow->onTopView();
}
-//----------------------------------------------------------------------------
+/*!
+ Processes transformation "bottom view"
+*/
void
SVTK_ViewWindow
::onBottomView()
myMainWindow->onBottomView();
}
-//----------------------------------------------------------------------------
+/*!
+ Processes transformation "left view"
+*/
void
SVTK_ViewWindow
::onLeftView()
myMainWindow->onLeftView();
}
-//----------------------------------------------------------------------------
+/*!
+ Processes transformation "right view"
+*/
void
SVTK_ViewWindow
::onRightView()
myMainWindow->onRightView();
}
-//----------------------------------------------------------------------------
+/*!
+ Processes transformation "reset view": sets default orientation of viewport camera
+*/
void
SVTK_ViewWindow
::onResetView()
myMainWindow->onResetView();
}
-//----------------------------------------------------------------------------
+/*!
+ Processes transformation "fit all"
+*/
void
SVTK_ViewWindow
::onFitAll()
myMainWindow->onFitAll();
}
-//----------------------------------------------------------------
+/*!
+ SLOT: called if selection is changed
+*/
void
SVTK_ViewWindow
::onSelectionChanged()
myView->onSelectionChanged();
}
-//----------------------------------------------------------------
+/*!
+ Change selection mode
+ \param theMode - new selection mode
+*/
void
SVTK_ViewWindow
::SetSelectionMode(Selection_Mode theMode)
myMainWindow->SetSelectionMode( theMode );
}
-//----------------------------------------------------------------
+/*!
+ \return selection mode
+*/
Selection_Mode
SVTK_ViewWindow
::SelectionMode() const
return myMainWindow->SelectionMode();
}
-//----------------------------------------------------------------
+/*!
+ Unhilights all objects in viewer
+*/
void
SVTK_ViewWindow
::unHighlightAll()
myView->unHighlightAll();
}
-//----------------------------------------------------------------
+/*!
+ Hilights/unhilights object in viewer
+ \param theIO - object to be updated
+ \param theIsHighlight - if it is true, object will be hilighted, otherwise it will be unhilighted
+ \param theIsUpdate - update current viewer
+*/
void
SVTK_ViewWindow
::highlight(const Handle(SALOME_InteractiveObject)& theIO,
myView->highlight( theIO, theIsHighlight, theIsUpdate );
}
-//----------------------------------------------------------------
+/*!
+ \return true if object is in viewer or in collector
+ \param theIO - object to be checked
+*/
bool
SVTK_ViewWindow
::isInViewer( const Handle(SALOME_InteractiveObject)& theIO )
return myView->isInViewer( theIO );
}
-//----------------------------------------------------------------
+/*!
+ \return true if object is displayed in viewer
+ \param theIO - object to be checked
+*/
bool
SVTK_ViewWindow
::isVisible( const Handle(SALOME_InteractiveObject)& theIO )
return myView->isVisible( theIO );
}
-//----------------------------------------------------------------
+/*!
+ Display object
+ \param theEntry - entry that corresponds to intractive objects
+*/
+Handle(SALOME_InteractiveObject)
+SVTK_ViewWindow
+::FindIObject(const char* theEntry)
+{
+ return myView->FindIObject(theEntry);
+}
+
+/*!
+ Display object
+ \param theIO - object
+ \param theImmediatly - update viewer
+*/
void
SVTK_ViewWindow
::Display(const Handle(SALOME_InteractiveObject)& theIO,
myView->Display(theIO,theImmediatly);
}
+/*!
+ Erase object
+ \param theIO - object
+ \param theImmediatly - update viewer
+*/
void
SVTK_ViewWindow
::Erase(const Handle(SALOME_InteractiveObject)& theIO,
myView->Erase(theIO,theImmediatly);
}
+/*!
+ Display only passed object
+ \param theIO - object
+*/
void
SVTK_ViewWindow
::DisplayOnly(const Handle(SALOME_InteractiveObject)& theIO)
myView->DisplayOnly(theIO);
}
+/*!
+ Display all objects in view
+*/
void
SVTK_ViewWindow
::DisplayAll()
myView->DisplayAll();
}
+/*!
+ Erase all objects in view
+*/
void
SVTK_ViewWindow
::EraseAll()
myView->EraseAll();
}
-//----------------------------------------------------------------------------
+/*!
+ Sets background color
+ \param color - new background color
+*/
void
SVTK_ViewWindow
::setBackgroundColor( const QColor& color )
myMainWindow->SetBackgroundColor( color );
}
-//----------------------------------------------------------------------------
+/*!
+ \return background color of viewer
+*/
QColor
SVTK_ViewWindow
::backgroundColor() const
return myMainWindow->BackgroundColor();
}
-//----------------------------------------------------------------------------
+/*!
+ Updates current viewer
+*/
void
SVTK_ViewWindow
::Repaint(bool theUpdateTrihedron)
myMainWindow->Repaint( theUpdateTrihedron );
}
-//----------------------------------------------------------------------------
+/*!
+ Redirect the request to #SVTK_Renderer::GetScale
+*/
void
SVTK_ViewWindow
::GetScale( double theScale[3] )
myMainWindow->GetScale( theScale );
}
-//----------------------------------------------------------------------------
+/*!
+ Redirect the request to #SVTK_Renderer::SetScale
+*/
void
SVTK_ViewWindow
::SetScale( double theScale[3] )
myMainWindow->SetScale( theScale );
}
-//----------------------------------------------------------------------------
+/*!
+ Redirect the request to #SVTK_Renderer::IsTrihedronDisplayed
+*/
bool
SVTK_ViewWindow
::isTrihedronDisplayed()
return myMainWindow->IsTrihedronDisplayed();
}
+/*!
+ Redirect the request to #SVTK_Renderer::IsCubeAxesDisplayed
+*/
bool
SVTK_ViewWindow
::isCubeAxesDisplayed()
return myMainWindow->IsCubeAxesDisplayed();
}
-//----------------------------------------------------------------------------
+/*!
+ Redirect the request to #SVTK_Renderer::OnViewTrihedron
+*/
void
SVTK_ViewWindow
::onViewTrihedron()
myMainWindow->onViewTrihedron();
}
+/*!
+ Redirect the request to #SVTK_Renderer::OnViewCubeAxes
+*/
void
SVTK_ViewWindow
::onViewCubeAxes()
myMainWindow->onViewCubeAxes();
}
-//----------------------------------------------------------------------------
+/*!
+ Redirect the request to #SVTK_Renderer::GetTrihedron
+*/
VTKViewer_Trihedron*
SVTK_ViewWindow::
GetTrihedron()
return myMainWindow->GetTrihedron();
}
+/*!
+ Redirect the request to #SVTK_Renderer::GetCubeAxes
+*/
SVTK_CubeAxesActor2D*
SVTK_ViewWindow
::GetCubeAxes()
return myMainWindow->GetCubeAxes();
}
+/*!
+ \return trihedron size
+*/
int
SVTK_ViewWindow
::GetTrihedronSize() const
return myMainWindow->GetTrihedronSize();
}
+/*!
+ Sets trihedron size
+ \param theSize - new trihedron size
+ \param theRelative - trihedron relativeness
+*/
void
SVTK_ViewWindow
::SetTrihedronSize(const int theSize, const bool theRelative)
myMainWindow->AdjustActors();
}
-//----------------------------------------------------------------------------
+/*!
+ Redirect the request to #SVTK_Renderer::OnAdjustTrihedron
+*/
void
SVTK_ViewWindow
::onAdjustTrihedron()
myMainWindow->onAdjustTrihedron();
}
+/*!
+ Redirect the request to #SVTK_Renderer::OnAdjustCubeAxes
+*/
void
SVTK_ViewWindow
::onAdjustCubeAxes()
myMainWindow->onAdjustCubeAxes();
}
-//=======================================================================
+/*!
+ Emits key pressed
+*/
void
SVTK_ViewWindow
::onKeyPressed(QKeyEvent* event)
emit keyPressed( this, event );
}
-//=======================================================================
+/*!
+ Emits key released
+*/
void
SVTK_ViewWindow
::onKeyReleased(QKeyEvent* event)
emit keyReleased( this, event );
}
-//=======================================================================
+/*!
+ Emits mouse pressed
+*/
void
SVTK_ViewWindow
::onMousePressed(QMouseEvent* event)
emit mousePressed(this, event);
}
-//=======================================================================
+/*!
+ Emits mouse released
+*/
void
SVTK_ViewWindow
::onMouseReleased(QMouseEvent* event)
emit mouseReleased( this, event );
}
-//=======================================================================
+/*!
+ Emits mouse moving
+*/
void
SVTK_ViewWindow
::onMouseMoving(QMouseEvent* event)
emit mouseMoving( this, event );
}
-//=======================================================================
+/*!
+ Emits mouse double clicked
+*/
void
SVTK_ViewWindow
::onMouseDoubleClicked( QMouseEvent* event )
emit mouseDoubleClicked( this, event );
}
-//----------------------------------------------------------------------------
+/*!
+ Redirect the request to #SVTK_Renderer::AddActor
+*/
void
SVTK_ViewWindow
::AddActor( VTKViewer_Actor* theActor,
myMainWindow->AddActor( theActor, theUpdate );
}
-//----------------------------------------------------------------------------
+/*!
+ Redirect the request to #SVTK_Renderer::RemoveActor
+*/
void
SVTK_ViewWindow
::RemoveActor( VTKViewer_Actor* theActor,
myMainWindow->RemoveActor( theActor, theUpdate );
}
-//----------------------------------------------------------------------------
+/*!
+ \return QImage, containing all scene rendering in window
+*/
QImage
SVTK_ViewWindow
::dumpView()
return myMainWindow->dumpView();
}
-//----------------------------------------------------------------------------
+/*!
+ Redirect the request to #SVTK_Renderer::SetSelectionProp
+*/
void
SVTK_ViewWindow
::SetSelectionProp(const double& theRed,
myView->SetSelectionProp(theRed,theGreen,theBlue,theWidth);
}
-//----------------------------------------------------------------------------
+/*!
+ Redirect the request to #SVTK_Renderer::SetSelectionProp
+*/
void
SVTK_ViewWindow
::SetPreselectionProp(const double& theRed,
myView->SetPreselectionProp(theRed,theGreen,theBlue,theWidth);
}
-//----------------------------------------------------------------------------
+/*!
+ Redirect the request to #SVTK_Renderer::SetSelectionTolerance
+*/
void
SVTK_ViewWindow
::SetSelectionTolerance(const double& theTolNodes,
myView->SetSelectionTolerance(theTolNodes,theTolItems);
}
-//----------------------------------------------------------------------------
int convertAction( const int accelAction )
{
switch ( accelAction ) {
return accelAction;
}
-//----------------------------------------------------------------------------
-void
+/*!
+ Performs action
+ \param accelAction - action
+*/
+bool
SVTK_ViewWindow
::action( const int accelAction )
{
+ if ( !myMainWindow->hasFocus() )
+ return false;
if ( accelAction == SUIT_Accel::ZoomFit )
onFitAll();
else {
int anEvent = convertAction( accelAction );
myMainWindow->InvokeEvent( anEvent, 0 );
}
+ return true;
+}
+
+// old visual parameters had 13 values. New format added additional
+// 76 values for graduated axes, so both numbers are processed.
+const int nNormalParams = 13; // number of view windows parameters excluding graduated axes params
+const int nGradAxisParams = 25; // number of parameters of ONE graduated axis (X, Y, or Z)
+const int nAllParams = nNormalParams + 3*nGradAxisParams + 1; // number of all visual parameters
+
+/*! The method returns visual parameters of a graduated axis actor (x,y,z axis of graduated axes)
+ */
+QString getGradAxisVisualParams( vtkAxisActor2D* actor )
+{
+ QString params;
+ if ( !actor )
+ return params;
+
+ // Name
+ bool isVisible = actor->GetTitleVisibility();
+ QString title ( actor->GetTitle() );
+ vtkFloatingPointType color[ 3 ];
+ int font = VTK_ARIAL;
+ int bold = 0;
+ int italic = 0;
+ int shadow = 0;
+
+ vtkTextProperty* txtProp = actor->GetTitleTextProperty();
+ if ( txtProp )
+ {
+ txtProp->GetColor( color );
+ font = txtProp->GetFontFamily();
+ bold = txtProp->GetBold();
+ italic = txtProp->GetItalic();
+ shadow = txtProp->GetShadow();
+ }
+ params.sprintf( "* Graduated Axis: * Name *%u*%s*%.2f*%.2f*%.2f*%u*%u*%u*%u", isVisible,
+ title.latin1(), color[0], color[1], color[2], font, bold, italic, shadow );
+
+ // Labels
+ isVisible = actor->GetLabelVisibility();
+ int labels = actor->GetNumberOfLabels();
+ int offset = actor->GetTickOffset();
+ font = VTK_ARIAL;
+ bold = false;
+ italic = false;
+ shadow = false;
+
+ txtProp = actor->GetLabelTextProperty();
+ if ( txtProp )
+ {
+ txtProp->GetColor( color );
+ font = txtProp->GetFontFamily();
+ bold = txtProp->GetBold();
+ italic = txtProp->GetItalic();
+ shadow = txtProp->GetShadow();
+ }
+ params += QString().sprintf( "* Labels *%u*%u*%u*%.2f*%.2f*%.2f*%u*%u*%u*%u", isVisible, labels, offset,
+ color[0], color[1], color[2], font, bold, italic, shadow );
+
+ // Tick marks
+ isVisible = actor->GetTickVisibility();
+ int length = actor->GetTickLength();
+
+ params += QString().sprintf( "* Tick marks *%u*%u", isVisible, length );
+
+ return params;
+}
+
+/*! 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 = QStringList::split( '*', params, true );
+
+ if ( paramsLst.size() == nGradAxisParams ) { // altogether name, lable, ticks parameters make up 25 values
+
+ // retrieve and set name parameters
+ bool isVisible = paramsLst[2].toUShort();
+ QString title = paramsLst[3];
+ vtkFloatingPointType color[3];
+ color[0] = paramsLst[4].toDouble();
+ color[1] = paramsLst[5].toDouble();
+ color[2] = paramsLst[6].toDouble();
+ int font = paramsLst[7].toInt();
+ int bold = paramsLst[8].toInt();
+ int italic = paramsLst[9].toInt();
+ int shadow = paramsLst[10].toInt();
+
+ actor->SetTitleVisibility( isVisible );
+ actor->SetTitle( title.latin1() );
+ vtkTextProperty* txtProp = actor->GetTitleTextProperty();
+ if ( txtProp ) {
+ txtProp->SetColor( color );
+ txtProp->SetFontFamily( font );
+ txtProp->SetBold( bold );
+ txtProp->SetItalic( italic );
+ txtProp->SetShadow( shadow );
+ }
+
+ // retrieve and set lable parameters
+ isVisible = paramsLst[12].toUShort();
+ int labels = paramsLst[13].toInt();
+ int offset = paramsLst[14].toInt();
+ color[0] = paramsLst[15].toDouble();
+ color[1] = paramsLst[16].toDouble();
+ color[2] = paramsLst[17].toDouble();
+ font = paramsLst[18].toInt();
+ bold = paramsLst[19].toInt();
+ italic = paramsLst[20].toInt();
+ shadow = paramsLst[21].toInt();
+
+ actor->SetLabelVisibility( isVisible );
+ actor->SetNumberOfLabels( labels );
+ actor->SetTickOffset( offset );
+ txtProp = actor->GetLabelTextProperty();
+ if ( txtProp ) {
+ txtProp->SetColor( color );
+ txtProp->SetFontFamily( font );
+ txtProp->SetBold( bold );
+ txtProp->SetItalic( italic );
+ txtProp->SetShadow( shadow );
+ }
+
+ // retrieve and set tick marks properties
+ isVisible = paramsLst[23].toUShort();
+ int length = paramsLst[24].toInt();
+
+ actor->SetTickVisibility( isVisible );
+ actor->SetTickLength( length );
+ }
}
/*! The method returns the visual parameters of this view as a formated string
::getVisualParameters()
{
double pos[3], focalPnt[3], viewUp[3], parScale, scale[3];
-
+
+ // save position, focal point, viewUp, scale
vtkCamera* camera = getRenderer()->GetActiveCamera();
camera->GetPosition( pos );
camera->GetFocalPoint( focalPnt );
parScale = camera->GetParallelScale();
GetScale( scale );
+ // Parameters are given in the following format:view position (3 digits), focal point position (3 digits)
+ // view up values (3 digits), parallel scale (1 digit), scale (3 digits,
+ // Graduated axes parameters (X, Y, Z axes parameters)
QString retStr;
retStr.sprintf( "%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e",
- pos[0], pos[1], pos[2], focalPnt[0], focalPnt[1], focalPnt[2], viewUp[0], viewUp[1],
- viewUp[2], parScale, scale[0], scale[1], scale[2] );
+ pos[0], pos[1], pos[2], focalPnt[0], focalPnt[1], focalPnt[2],
+ viewUp[0], viewUp[1], viewUp[2], parScale, scale[0], scale[1], scale[2] );
+
+ // save graduated axes parameters
+ if ( SVTK_CubeAxesActor2D* gradAxesActor = GetCubeAxes() ) {
+ retStr += QString( "*%1" ).arg( getMainWindow()->IsCubeAxesDisplayed() );
+ retStr += ::getGradAxisVisualParams( gradAxesActor->GetXAxisActor2D() );
+ retStr += ::getGradAxisVisualParams( gradAxesActor->GetYAxisActor2D() );
+ retStr += ::getGradAxisVisualParams( gradAxesActor->GetZAxisActor2D() );
+ }
+
return retStr;
}
-/* The method restores visual parameters of this view or postpones it untill the view is shown
- */
+/*!
+ The method restores visual parameters of this view or postpones it untill the view is shown
+*/
void
SVTK_ViewWindow
::setVisualParameters( const QString& parameters )
}
}
-/* The method restores visual parameters of this view from a formated string
- */
+/*!
+ The method restores visual parameters of this view from a formated string
+*/
void
SVTK_ViewWindow
::doSetVisualParameters( const QString& parameters )
{
QStringList paramsLst = QStringList::split( '*', parameters, true );
- if ( paramsLst.size() == 13 ) {
+ if ( paramsLst.size() >= nNormalParams ) {
// 'reading' list of parameters
double pos[3], focalPnt[3], viewUp[3], parScale, scale[3];
pos[0] = paramsLst[0].toDouble();
camera->SetParallelScale( parScale );
SetScale( scale );
- // resize( size() );
-
- // getRenderer()->ResetCameraClippingRange();
- // Repaint();
- // getMainWindow()->GetRenderer()->GetTransform()->SetMatrixScale( scale[0], scale[1], scale[2] );
+ // apply graduated axes parameters
+ SVTK_CubeAxesActor2D* gradAxesActor = GetCubeAxes();
+ if ( gradAxesActor && paramsLst.size() == nAllParams ) {
+
+ int i = nNormalParams+1, j = i + nGradAxisParams - 1;
+ ::setGradAxisVisualParams( gradAxesActor->GetXAxisActor2D(), parameters.section( '*', i, j ) );
+ i = j + 1; j += nGradAxisParams;
+ ::setGradAxisVisualParams( gradAxesActor->GetYAxisActor2D(), parameters.section( '*', i, j ) );
+ i = j + 1; j += nGradAxisParams;
+ ::setGradAxisVisualParams( gradAxesActor->GetZAxisActor2D(), parameters.section( '*', i, j ) );
+
+ if ( paramsLst[13].toUShort() )
+ gradAxesActor->VisibilityOn();
+ else
+ gradAxesActor->VisibilityOff();
+ }
}
}
-//================================================================
-// Function : eventFilter
-/*! Purpose : delayed setVisualParameters
+/*!
+ Delayed setVisualParameters
*/
-//================================================================
bool SVTK_ViewWindow::eventFilter( QObject* theWatched, QEvent* theEvent )
{
if ( theEvent->type() == QEvent::Show && theWatched->inherits( "SVTK_RenderWindowInteractor" ) ) {