-// Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
+// 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.
+// 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
#include <QToolBar>
#include <QEvent>
#include <QFileInfo>
+#include <QSignalMapper>
#include <QXmlStreamWriter>
#include <QXmlStreamReader>
#include <QXmlStreamAttributes>
#include "SUIT_ViewManager.h"
#include "QtxActionToolMgr.h"
#include "QtxMultiAction.h"
+#include "QtxActionGroup.h"
#include "VTKViewer_Utilities.h"
#include "VTKViewer_Trihedron.h"
*/
void SVTK_ViewWindow::Initialize(SVTK_ViewModelBase* theModel)
{
+ myModel = theModel;
myInteractor = new SVTK_RenderWindowInteractor(this,"SVTK_RenderWindowInteractor");
- SVTK_Selector* aSelector = SVTK_Selector::New();
- aSelector->SetDynamicPreSelection( SUIT_Session::session()->resourceMgr()->
- booleanValue( "VTKViewer", "dynamic_preselection", true ) );
-
+ 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);
/*!
Redirect the request to #SVTK_Renderer::OnViewTrihedron
*/
-void SVTK_ViewWindow::onViewTrihedron()
+void SVTK_ViewWindow::onViewTrihedron(bool show)
{
- GetRenderer()->OnViewTrihedron();
+ GetRenderer()->SetTrihedronVisibility(show);
Repaint();
}
}
/*!
- Switch dynamic preselection on / off
- \param theDynPreselection - dynamic pre-selection mode
+ 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::SetDynamicPreSelection( bool theDynPreselection )
+void SVTK_ViewWindow::SetSelectionEnabled( bool theEnable )
{
- onSwitchDynamicPreSelection( theDynPreselection );
+ 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 );
}
/*!
}
/*!
- Toogles dynamic preselection on/off
+ Switch preselection mode.
+ \param theMode the preselection mode
*/
-void SVTK_ViewWindow::onSwitchDynamicPreSelection( bool theOn )
+void SVTK_ViewWindow::onSwitchPreSelectionMode( int theMode )
{
- GetSelector()->SetDynamicPreSelection( theOn );
+ GetSelector()->SetDynamicPreSelection( theMode == Dynamic_Preselection );
+ GetSelector()->SetPreSelectionEnabled( theMode != Preselection_Disabled );
// update action state if method is called outside
- QtxAction* a = getAction( SwitchDynamicPreselectionId );
- if ( a->isChecked() != theOn )
- a->setChecked( theOn );
+ QtxAction* a = getAction( StandardPreselectionId + theMode );
+ if ( a && !a->isChecked() )
+ a->setChecked( true );
+}
+
+/*!
+ Enables/disables selection.
+ \param theOn if true - selection will be enabled
+*/
+void SVTK_ViewWindow::onEnableSelection( bool on )
+{
+ SVTK_Viewer* aViewer = dynamic_cast<SVTK_Viewer*>(myModel);
+ if(aViewer)
+ aViewer->enableSelection(on);
}
/*!
bool theIsAdjustActors )
{
GetRenderer()->RemoveActor(theActor, theIsAdjustActors);
+ if ( myDefaultInteractorStyle )
+ myDefaultInteractorStyle->FreeActors();
+ if ( myKeyFreeInteractorStyle )
+ myKeyFreeInteractorStyle->FreeActors();
if(theUpdate)
Repaint();
emit actorRemoved(theActor);
}
/*!
- Set the point selected by user as a rotation point
+ Set the gravity center of element selected by user as a rotation point
*/
-void SVTK_ViewWindow::activateStartPointSelection()
+void SVTK_ViewWindow::activateStartPointSelection( Selection_Mode theSelectionMode )
{
+ SetSelectionMode( theSelectionMode );
myEventDispatcher->InvokeEvent(SVTK::StartPointSelection,0);
}
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(activated()), this, SLOT(onViewTrihedron()));
+ connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onViewTrihedron(bool)));
mgr->registerAction( anAction, ViewTrihedronId );
// onNonIsometric: Manage non-isometric params
connect(anAction, SIGNAL(toggled(bool)), this, SLOT(onSwitchZoomingStyle(bool)));
mgr->registerAction( anAction, SwitchZoomingStyleId );
- // Turn on/off dynamic pre-selection
- anAction = new QtxAction(tr("MNU_SVTK_DYNAMIC_PRESLECTION_SWITCH"),
- theResourceMgr->loadPixmap( "VTKViewer", tr( "ICON_SVTK_DYNAMIC_PRESLECTION_SWITCH" ) ),
- tr( "MNU_SVTK_DYNAMIC_PRESLECTION_SWITCH" ), 0, this);
- anAction->setStatusTip(tr("DSC_SVTK_DYNAMIC_PRESLECTION_SWITCH"));
+ // 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(toggled(bool)), this, SLOT(onSwitchDynamicPreSelection(bool)));
- mgr->registerAction( anAction, SwitchDynamicPreselectionId );
+ 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"),
mgr->append( DumpId, myToolBar );
mgr->append( SwitchInteractionStyleId, myToolBar );
mgr->append( SwitchZoomingStyleId, myToolBar );
- mgr->append( SwitchDynamicPreselectionId, 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 );
double anAxialScale[3];
aCamera->OrthogonalizeViewUp();
- aCamera->GetFocalPoint(aFocalPoint);
- aCamera->GetPosition(aPosition);
- aCamera->GetViewUp(aViewUp);
+ 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());
+ 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)
+ if ( aProps.getProjection() == SUIT_CameraProperties::PrjPerspective )
{
- aProps.setViewAngle(aCamera->GetViewAngle());
+ aProps.setViewAngle( aCamera->GetViewAngle() );
}
- GetRenderer()->GetScale(anAxialScale);
- aProps.setAxialScale(anAxialScale[0], anAxialScale[1], anAxialScale[2]);
+ GetRenderer()->GetScale( anAxialScale );
+ aProps.setAxialScale( anAxialScale[0], anAxialScale[1], anAxialScale[2] );
return aProps;
}
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]);
+ 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());
+ aCamera->SetViewUp( aViewUp );
+ aCamera->SetPosition( aPosition );
+ aCamera->SetFocalPoint( aFocalPoint );
+ aCamera->SetParallelScale( aProps.getMappingScale() / 2.0 );
- if (aProps.getProjection() == SUIT_CameraProperties::PrjPerspective)
+ if ( aProps.getProjection() == SUIT_CameraProperties::PrjPerspective )
{
- aCamera->SetViewAngle(aProps.getViewAngle());
+ aCamera->SetViewAngle( aProps.getViewAngle() );
}
- GetRenderer()->SetScale(anAxialScale);
+ GetRenderer()->SetScale( anAxialScale );
getRenderer()->ResetCameraClippingRange();
- Repaint(false);
+ Repaint( false );
blockSignals( blocked );
}