-void SVTK_ViewWindow::synchronizeView( SVTK_ViewWindow* viewWindow, int id )
-{
- SVTK_ViewWindow* otherViewWindow = 0;
- QList<SVTK_ViewWindow*> compatibleViews;
-
- bool isSync = viewWindow->toolMgr()->action( SynchronizeId )->isChecked();
-
- int vwid = viewWindow->getId();
-
- SUIT_Application* app = SUIT_Session::session()->activeApplication();
- if ( !app ) return;
-
- QList<SUIT_ViewManager*> wmlist;
- app->viewManagers( viewWindow->getViewManager()->getType(), wmlist );
-
- foreach( SUIT_ViewManager* wm, wmlist ) {
- QVector<SUIT_ViewWindow*> vwlist = wm->getViews();
-
- foreach( SUIT_ViewWindow* vw, vwlist ) {
- SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( vw );
- if ( !vtkVW ) continue;
- if ( vtkVW->getId() == id )
- otherViewWindow = vtkVW;
- else if ( vtkVW != viewWindow )
- compatibleViews.append( vtkVW );
- }
- }
-
- if ( isSync && id ) {
- // remove all possible disconnections
- foreach( SVTK_ViewWindow* vw, compatibleViews ) {
- // disconnect target view
- vw->disconnect( SIGNAL( transformed( SVTK_ViewPort* ) ), viewWindow, SLOT( synchronize( SVTK_ViewPort* ) ) );
- viewWindow->disconnect( SIGNAL( transformed( SVTK_ViewPort* ) ), vw, SLOT( synchronize( SVTK_ViewPort* ) ) );
- if ( otherViewWindow ) {
- // disconnect source view
- vw->disconnect( SIGNAL( transformed( SVTK_ViewPort* ) ), otherViewWindow, SLOT( synchronize( SVTK_ViewPort* ) ) );
- otherViewWindow->disconnect( SIGNAL( transformed( SVTK_ViewPort* ) ), vw, SLOT( synchronize( SVTK_ViewPort* ) ) );
- }
- QAction* a = vw->toolMgr()->action( SynchronizeId );
- if ( a ) {
- int anid = a->data().toInt();
- if ( a->isChecked() && ( anid == id || anid == vwid ) ) {
- bool blocked = a->blockSignals( true );
- a->setChecked( false );
- a->blockSignals( blocked );
- }
- }
- }
- if ( otherViewWindow ) {
- // reconnect source and target view
- otherViewWindow->disconnect( SIGNAL( transformed( SVTK_ViewWindow* ) ), viewWindow, SLOT( synchronize( SVTK_ViewWindow* ) ) );
- viewWindow->disconnect( SIGNAL( transformed( SVTK_ViewWindow* ) ), otherViewWindow, SLOT( synchronize( SVTK_ViewWindow* ) ) );
- otherViewWindow->connect( viewWindow, SIGNAL( transformed( SVTK_ViewWindow* ) ), SLOT( synchronize( SVTK_ViewWindow* ) ) );
- viewWindow->connect( otherViewWindow, SIGNAL( transformed( SVTK_ViewWindow* ) ), SLOT( synchronize( SVTK_ViewWindow* ) ) );
- // synchronize target view with source view
- viewWindow->doSetVisualParameters( otherViewWindow->getVisualParameters(), true );
- viewWindow->toolMgr()->action( SynchronizeId )->setData( otherViewWindow->getId() );
- otherViewWindow->toolMgr()->action( SynchronizeId )->setData( viewWindow->getId() );
- if ( !otherViewWindow->toolMgr()->action( SynchronizeId )->isChecked() ) {
- bool blocked = otherViewWindow->toolMgr()->action( SynchronizeId )->blockSignals( true );
- otherViewWindow->toolMgr()->action( SynchronizeId )->setChecked( true );
- otherViewWindow->toolMgr()->action( SynchronizeId )->blockSignals( blocked );
- }
- }
- }
- else if ( otherViewWindow ) {
- // reconnect source and target view
- otherViewWindow->disconnect( SIGNAL( transformed( SVTK_ViewWindow* ) ), viewWindow, SLOT( synchronize( SVTK_ViewWindow* ) ) );
- viewWindow->disconnect( SIGNAL( transformed( SVTK_ViewWindow* ) ), otherViewWindow, SLOT( synchronize( SVTK_ViewWindow* ) ) );
- viewWindow->doSetVisualParameters( otherViewWindow->getVisualParameters(), true );
- viewWindow->toolMgr()->action( SynchronizeId )->setData( otherViewWindow->getId() );
- if ( otherViewWindow->toolMgr()->action( SynchronizeId )->data().toInt() == viewWindow->getId() && otherViewWindow->toolMgr()->action( SynchronizeId )->isChecked() ) {
- bool blocked = otherViewWindow->toolMgr()->action( SynchronizeId )->blockSignals( true );
- otherViewWindow->toolMgr()->action( SynchronizeId )->setChecked( false );
- otherViewWindow->toolMgr()->action( SynchronizeId )->blockSignals( blocked );
- }
- }
-}
-
-/*!
- "Synchronize View" action slot.
-*/
-void SVTK_ViewWindow::onSynchronizeView(bool checked)
-{
- QAction* a = qobject_cast<QAction*>( sender() );
- if ( a ) {
- synchronizeView( this, a->data().toInt() );
- }
-}
-
-/*!
- Update list of available view for the "Synchronize View" action
-*/
-void SVTK_ViewWindow::updateSyncViews()
-{
- QAction* anAction = toolMgr()->action( SynchronizeId );
- if ( anAction && anAction->menu() ) {
- int currentId = anAction->data().toInt();
- anAction->menu()->clear();
- SUIT_Application* app = SUIT_Session::session()->activeApplication();
- if ( app ) {
- QList<SUIT_ViewManager*> wmlist;
- app->viewManagers( getViewManager()->getType(), wmlist );
- foreach( SUIT_ViewManager* wm, wmlist ) {
- QVector<SUIT_ViewWindow*> vwlist = wm->getViews();
- foreach ( SUIT_ViewWindow* vw, vwlist ) {
- SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( vw );
- if ( !vtkVW || vtkVW == this ) continue;
- QAction* a = anAction->menu()->addAction( vtkVW->windowTitle() );
- if ( vtkVW->getId() == currentId ) {
- QFont f = a->font();
- f.setBold( true );
- a->setFont( f );
- }
- a->setData( vtkVW->getId() );
- connect( a, SIGNAL( triggered(bool) ), this, SLOT( onSynchronizeView(bool) ) );
- }
- }
- }
- if ( anAction->menu()->actions().isEmpty() ) {
- anAction->setData( 0 );
- anAction->menu()->addAction( tr( "MNU_SYNC_NO_VIEW" ) );
- }
- }
-}
-
-