Salome HOME
Merge branch 'ASL_TREE_STATE' into asl/hydro_porting_741
[modules/gui.git] / src / SVTK / SVTK_ViewWindow.cxx
index fba7c6f7637c19b03d2c310ef553c0fd12360c62..d56dde955cb163a7d2ecb1ae12e500e2f75d6d9c 100755 (executable)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2013  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
@@ -6,7 +6,7 @@
 // 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
@@ -148,6 +148,7 @@ SVTK_ViewWindow::SVTK_ViewWindow(SUIT_Desktop* theDesktop):
 */
 void SVTK_ViewWindow::Initialize(SVTK_ViewModelBase* theModel)
 {
+  myModel = theModel;
   myInteractor = new SVTK_RenderWindowInteractor(this,"SVTK_RenderWindowInteractor");
   
   SVTK_Selector* aSelector = SVTK_Selector::New();
@@ -798,9 +799,9 @@ bool SVTK_ViewWindow::isCubeAxesDisplayed()
 /*!
   Redirect the request to #SVTK_Renderer::OnViewTrihedron
 */
-void SVTK_ViewWindow::onViewTrihedron()
+void SVTK_ViewWindow::onViewTrihedron(bool show)
 {
-  GetRenderer()->OnViewTrihedron();
+  GetRenderer()->SetTrihedronVisibility(show);
   Repaint();
 }
 
@@ -912,7 +913,14 @@ void SVTK_ViewWindow::SetPreSelectionMode( Preselection_Mode theMode )
 */
 void SVTK_ViewWindow::SetSelectionEnabled( bool theEnable )
 {
-  onEnableSelection( 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 );
 }
 
 /*!
@@ -982,16 +990,9 @@ void SVTK_ViewWindow::onSwitchPreSelectionMode( int theMode )
 */
 void SVTK_ViewWindow::onEnableSelection( bool on )
 {
-  GetSelector()->SetSelectionEnabled( on );
-
-  // update action state if method is called outside
-  QtxAction* a = getAction( EnableSelectionId );
-  if ( a->isChecked() != on )
-    a->setChecked( on );
-  QtxActionGroup* aPreselectionGroup = 
-    dynamic_cast<QtxActionGroup*>( getAction( PreselectionId ) );
-  if ( aPreselectionGroup )
-    aPreselectionGroup->setEnabled( on );
+  SVTK_Viewer* aViewer = dynamic_cast<SVTK_Viewer*>(myModel);
+  if(aViewer)
+    aViewer->enableSelection(on);  
 }
 
 /*!
@@ -1865,10 +1866,11 @@ void SVTK_ViewWindow::activateSetRotationSelected(void* theData)
 }
 
 /*!
-  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);
 }
 
@@ -2048,8 +2050,11 @@ void SVTK_ViewWindow::createActions(SUIT_ResourceMgr* theResourceMgr)
   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
@@ -2489,22 +2494,22 @@ SUIT_CameraProperties SVTK_ViewWindow::cameraProperties()
   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;
 }
@@ -2534,26 +2539,26 @@ void SVTK_ViewWindow::synchronize( SUIT_ViewWindow* theView )
   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 );
 }