Salome HOME
Copyright update 2022
[modules/geom.git] / src / MeasureGUI / MeasureGUI_DimensionInteractor.cxx
index 536774c0bf268311e66f3ec29f32011583583bc3..29a12a13166e9c2eadfe35d49c97f58fb58bc29d 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
@@ -35,6 +35,8 @@
 #include <SUIT_ViewWindow.h>
 #include <SUIT_Desktop.h>
 
+#include <Basics_OCCTVersion.hxx>
+
 #include <QMouseEvent>
 
 #include <AIS_InteractiveContext.hxx>
@@ -55,6 +57,7 @@
 #include <Geom_Line.hxx>
 #include <Geom_Plane.hxx>
 #include <NCollection_Sequence.hxx>
+#include <Quantity_Length.hxx>
 
 //=================================================================================
 // function : Constructor
@@ -131,12 +134,14 @@ void MeasureGUI_DimensionInteractor::Disable()
 
   myIsEnabled = false;
 
-  // remove event filtering from viewer windows
-  QVector<SUIT_ViewWindow*>           aViews  = myVM->getViews();
-  QVector<SUIT_ViewWindow*>::iterator aViewIt = aViews.begin();
-  for ( ; aViewIt != aViews.end(); ++aViewIt )
-  {
-    DisconnectView( *aViewIt );
+  if (myVM) {
+    // remove event filtering from viewer windows
+    QVector<SUIT_ViewWindow*>           aViews  = myVM->getViews();
+    QVector<SUIT_ViewWindow*>::iterator aViewIt = aViews.begin();
+    for ( ; aViewIt != aViews.end(); ++aViewIt )
+    {
+      DisconnectView( *aViewIt );
+    }
   }
 }
 
@@ -154,17 +159,25 @@ MeasureGUI_DimensionInteractor::Operation
     return Operation_None;
   }
 
+#if OCC_VERSION_LARGE >= 0x070400ff
+  Handle(PrsDim_DimensionOwner) anOwner = Handle(PrsDim_DimensionOwner)::DownCast( theEntity );
+#else
   Handle(AIS_DimensionOwner) anOwner = Handle(AIS_DimensionOwner)::DownCast( theEntity );
+#endif
   if ( anOwner.IsNull() )
   {
     return Operation_None;
   }
 
-  Standard_Real anAngTolerance = M_PI / 30.0; // 6 degree tolerance
+  //Standard_Real anAngTolerance = M_PI / 30.0; // 6 degree tolerance
 
   switch ( anOwner->SelectionMode() )
   {
+#if OCC_VERSION_LARGE >= 0x070400ff
+    case PrsDim_DimensionSelectionMode_Line :
+#else
     case AIS_DSM_Line :
+#endif
     {
       if ( ( theKeys & Qt::ControlModifier ) == 0 )
       {
@@ -181,7 +194,11 @@ MeasureGUI_DimensionInteractor::Operation
       return Operation_MoveFlyoutFree;
     }
 
+#if OCC_VERSION_LARGE >= 0x070400ff
+    case PrsDim_DimensionSelectionMode_Text : return Operation_MoveText;
+#else
     case AIS_DSM_Text : return Operation_MoveText;
+#endif
     default :           return Operation_None;
   }
 }
@@ -313,7 +330,7 @@ void MeasureGUI_DimensionInteractor::MoveFlyoutFree( const Handle(V3d_View)& the
   gp_Pnt aPointOnBase = gp_Pnt( aFirstPoint.XYZ() + aBaseDir.XYZ() * aPointVector.Dot( aBaseDir ) );
 
   // snapping tolerance
-  Quantity_Length aSize[2];
+  Standard_Real aSize[2];
   theView->Size( aSize[0], aSize[1] );
   Standard_Real aSnapTolerance = 1e-2 * Max( aSize[0], aSize[1] );
 
@@ -373,7 +390,7 @@ void MeasureGUI_DimensionInteractor::MoveFlyoutFree( const Handle(V3d_View)& the
   if ( aNewFlyout <= Precision::Confusion() )
   {
     myInteractedIO->SetFlyout( 0.0 );
-    myViewer->getAISContext()->Redisplay( myInteractedIO );
+    myViewer->getAISContext()->Redisplay( myInteractedIO, Standard_True );
     return;
   }
 
@@ -382,7 +399,7 @@ void MeasureGUI_DimensionInteractor::MoveFlyoutFree( const Handle(V3d_View)& the
   myInteractedIO->SetFlyout( aNewFlyout );
   myInteractedIO->SetCustomPlane( aNewPlane );
 
-  myViewer->getAISContext()->Redisplay( myInteractedIO );
+  myViewer->getAISContext()->Redisplay( myInteractedIO, Standard_True );
 }
 
 //=================================================================================
@@ -496,7 +513,7 @@ void MeasureGUI_DimensionInteractor::MoveFlyoutInPlane( const Handle(V3d_View)&
 
   myInteractedIO->SetFlyout( aFlyout );
 
-  myViewer->getAISContext()->Redisplay( myInteractedIO );
+  myViewer->getAISContext()->Redisplay( myInteractedIO, Standard_True );
 }
 
 //=================================================================================
@@ -601,7 +618,7 @@ void MeasureGUI_DimensionInteractor::MoveText( const Handle(V3d_View)& theView,
     const gp_Pnt& aFirstPoint  = anAngle->FirstPoint();
     const gp_Pnt& aSecondPoint = anAngle->SecondPoint();
 
-    Standard_Boolean isPositive = anAngle->GetFlyout() > 0.0;
+    //Standard_Boolean isPositive = anAngle->GetFlyout() > 0.0;
 
     gp_Dir aFirstDir  = gce_MakeDir( aCenterPoint, aFirstPoint );
     gp_Dir aSecondDir = gce_MakeDir( aCenterPoint, aSecondPoint );
@@ -668,7 +685,7 @@ void MeasureGUI_DimensionInteractor::MoveText( const Handle(V3d_View)& theView,
   myInteractedIO->DimensionAspect()->SetArrowOrientation( aArrPos );
   myInteractedIO->SetToUpdate();
 
-  myViewer->getAISContext()->Redisplay( myInteractedIO );
+  myViewer->getAISContext()->Redisplay( myInteractedIO, Standard_True );
 }
 
 //=================================================================================
@@ -691,21 +708,29 @@ bool MeasureGUI_DimensionInteractor::eventFilter( QObject* theObject, QEvent* th
       QMouseEvent* aMouseEv = dynamic_cast<QMouseEvent*>( theEvent );
 
       // init detection
-      anAISContext->MoveTo( aMouseEv->x(), aMouseEv->y(), aView3d );
+      anAISContext->MoveTo( aMouseEv->x(), aMouseEv->y(), aView3d, Standard_True );
       if ( !anAISContext->HasDetected() )
       {
         return false;
       }
 
+      // commented by mpa 18.03.2015: since OCCT version 6.8.0 it's impossible
+      // to change position of the dimensions presentations (flyout, text),
+      // because anAISContext has 2 detected objects.
+
       // check that there is only one detected entity
-      anAISContext->InitDetected();
-      if ( anAISContext->MoreDetected() )
+      //anAISContext->InitDetected();
+      //if ( anAISContext->MoreDetected() )
+      //{
+      //  return false;
+      //}
+
+      Handle(SelectMgr_EntityOwner) aDetectedOwner = anAISContext->DetectedOwner();
+      if( aDetectedOwner.IsNull() )
       {
         return false;
       }
 
-      Handle(SelectMgr_EntityOwner) aDetectedOwner = anAISContext->DetectedOwner();
-
       myInteractedIO = Handle(AIS_Dimension)::DownCast( aDetectedOwner->Selectable() );
 
       // try to start operation for the detected entity
@@ -730,7 +755,7 @@ bool MeasureGUI_DimensionInteractor::eventFilter( QObject* theObject, QEvent* th
       }
 
       anAISContext->ClearSelected( Standard_False );
-      anAISContext->AddOrRemoveSelected( aDetectedOwner );
+      anAISContext->AddOrRemoveSelected( aDetectedOwner, Standard_True );
 
       emit InteractionStarted( myInteractedIO );
 
@@ -846,7 +871,7 @@ gp_Pnt MeasureGUI_DimensionInteractor::ProjectPlane( const Handle(V3d_View)& the
 Standard_Real MeasureGUI_DimensionInteractor::SensitivityTolerance( const Handle(V3d_View)& theView )
 {
   // snapping tolerance
-  Quantity_Length aSize[2];
+  Standard_Real aSize[2];
   theView->Size( aSize[0], aSize[1] );
   return 1e-2 * Max( aSize[0], aSize[1] );
 }