Salome HOME
Add some missing math.h include (fix compilation error).
[modules/gui.git] / src / VTKViewer / VTKViewer_InteractorStyle.cxx
index e27b74b55c5cb002280e166d4f0f3f3ad9bdc409..1d5ae02277dd939dd3141d2228f94b14de47fb7e 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2022  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
@@ -74,7 +74,7 @@ static int GetEdgeId(vtkPicker *thePicker, SALOME_Actor *theActor, int theObjId)
 }
 */
 
-vtkStandardNewMacro(VTKViewer_InteractorStyle);
+vtkStandardNewMacro(VTKViewer_InteractorStyle)
 
 
 /*!Constructor.*/
@@ -628,6 +628,28 @@ void  VTKViewer_InteractorStyle::ViewFitAll() {
   ::ResetCameraClippingRange(CurrentRenderer);
 }
 
+/*!View fit selection.*/
+void  VTKViewer_InteractorStyle::ViewFitSelection() {
+
+  vtkActorCollection* aSelectedCollection = vtkActorCollection::New();
+
+  VTK::ActorCollectionCopy aCopy( CurrentRenderer->GetActors() );
+  vtkActorCollection* aCollection = aCopy.GetActors();
+  aCollection->InitTraversal();
+  while ( vtkActor* aProp = aCollection->GetNextActor() )
+    if ( VTKViewer_Actor* anActor = VTKViewer_Actor::SafeDownCast( aProp ) )
+      if ( anActor->isPreselected() )
+        aSelectedCollection->AddItem( aProp );
+
+  double bounds[6];
+  ::ComputeBounds( aSelectedCollection, bounds );
+
+  if ( aSelectedCollection->GetNumberOfItems() && ::isBoundValid( bounds ) ) {
+    CurrentRenderer->ResetCamera( bounds );
+    CurrentRenderer->ResetCameraClippingRange( bounds );
+  }
+}
+
 
 /*! starts Global Panning operation (e.g. through menu command)*/
 void VTKViewer_InteractorStyle::startGlobalPan()
@@ -652,7 +674,7 @@ void VTKViewer_InteractorStyle::startGlobalPan()
 }
 
 
-/*!\retval TRUE if needs redrawing*/
+/*!\retval \c true if needs redrawing*/
 bool VTKViewer_InteractorStyle::needsRedrawing()
 {
   return State == VTK_INTERACTOR_STYLE_CAMERA_ZOOM   ||
@@ -1175,7 +1197,7 @@ void VTKViewer_InteractorStyle::onOperation(QPoint mousePos)
     {
       if (!myCursorState)
         setCursor(VTK_INTERACTOR_STYLE_CAMERA_SELECT);
-    }
+    } // fall through!
   case VTK_INTERACTOR_STYLE_CAMERA_FIT:
     {
       myOtherPoint = mousePos;
@@ -1199,7 +1221,7 @@ void VTKViewer_InteractorStyle::OnSelectionModeChanged()
 /*! called when user moves mouse inside viewer window and there is no active viewer operation \n
  * (!put necessary processing here!)
  */
-void VTKViewer_InteractorStyle::onCursorMove(QPoint mousePos) {
+void VTKViewer_InteractorStyle::onCursorMove(QPoint /*mousePos*/) {
   // processing highlighting
 //  SUIT_Study* anActiveStudy = SUIT_Application::getDesktop()->getActiveStudy();
 //  SALOME_Selection* Sel = SALOME_Selection::Selection( anActiveStudy->getSelection() );
@@ -1460,10 +1482,10 @@ void  VTKViewer_InteractorStyle::RemoveFilter( const int theId )
 /*!Checks: is valid cell(node) with id \a theId in actor \a theActor.
  *\param theActor - VTKViewer_Actor pointer.
  *\param theId    - cell id.
- *\param theIsNode - boolean flag, if true - node, else - cell.
+ *\param theIsNode - boolean flag, if \c true - node, else - cell.
  */
 bool VTKViewer_InteractorStyle::IsValid( VTKViewer_Actor* theActor,
-                                               const int     theId,
+                                               const vtkIdType theId,
                                                const bool    theIsNode )
 {
   std::map<int, Handle(VTKViewer_Filter)>::const_iterator anIter;