Salome HOME
BndBox for Geom_Line. In the algorithm of the point search on the segment, a projecti...
authornds <nds@opencascade.com>
Tue, 19 Nov 2013 17:07:35 +0000 (17:07 +0000)
committernds <nds@opencascade.com>
Tue, 19 Nov 2013 17:07:35 +0000 (17:07 +0000)
Drag&drop correction to don't show selection bounding rect. To restore selection after drag operation.

src/HYDROCurveCreator/CurveCreator_Widget.cxx
src/HYDROCurveCreator/CurveCreator_Widget.h

index ec33d24990a920e03bb8affe7e50858369d74676..f59fb1e8139aea601e7984590e3bbf1772024cc4 100644 (file)
@@ -77,7 +77,8 @@ const int SCENE_PIXEL_TOLERANCE = 10;
 CurveCreator_Widget::CurveCreator_Widget(QWidget* parent,
                                          CurveCreator_ICurve *theCurve,
                                          Qt::WindowFlags fl)
-: QWidget(parent), myNewSectionEditor(NULL), myCurve(theCurve), mySection(0), myDragStarted( false ),
+: QWidget(parent), myNewSectionEditor(NULL), myCurve(theCurve), mySection(0),
+  myDragStarted( false ), myDragInteractionStyle( SUIT_ViewModel::STANDARD ),
   myOCCViewer( 0 )
 {
   myNewSectionEditor = new CurveCreator_NewSectionDlg( this );
@@ -236,9 +237,6 @@ void CurveCreator_Widget::setOCCViewer( OCCViewer_Viewer* theViewer )
 
   myOCCViewer = theViewer;
   if ( myOCCViewer ) {
-    //OCCViewer_ViewWindow* aWnd = dynamic_cast<OCCViewer_ViewWindow*>(myOCCViewer->getViewManager()->getActiveView());
-    //if ( aWnd )
-    //  aWnd->installEventFilter( this );
     OCCViewer_ViewManager* aViewManager = dynamic_cast<OCCViewer_ViewManager*>
                                                     ( myOCCViewer->getViewManager() );
     connect( aViewManager, SIGNAL( mousePress( SUIT_ViewWindow*, QMouseEvent* ) ),
@@ -258,27 +256,6 @@ OCCViewer_Viewer* CurveCreator_Widget::getOCCViewer()
   return myOCCViewer;
 }
 
-/*!
-  \brief Customize event handling
-  \param watched event receiver object
-  \param e event
-  \return \c true if the event processing should be stopped
-*/
-/*bool CurveCreator_Widget::eventFilter( QObject* theWatched, QEvent* theEvent )
-{
-  OCCViewer_Viewer* aViewer = getOCCViewer();
-  if ( !aViewer )
-    return;
-  Handle(AIS_InteractiveContext) aContext = aViewer->getAISContext();
-  bool isLocalContext = aContext->HasOpenedContext();
-  if ( !isLocalContext )
-    return QWidget::eventFilter( theWatched, theEvent );
-
-  bool isProcessed = true;
-
-  return isProcessed;
-}*/
-
 //=======================================================================
 // function: getUniqSectionName
 // purpose: return unique section name
@@ -920,8 +897,11 @@ void CurveCreator_Widget::onMouseRelease( SUIT_ViewWindow*, QMouseEvent* theEven
   if ( getActionMode() != ModificationMode )
     return;
 
-  if ( myDragStarted )
+  if ( myDragStarted ) {
+    if ( myDragged ) // if the drag of some points has happened, restore the drag selection
+      setSelectedPonts( 0, myDragPoints );
     setDragStarted( false );
+  }
   else // check whether the segment is clicked an a new point should be added to the segment
     insertPointToSelectedSegment( theEvent->pos().x(), theEvent->pos().y() );
 
@@ -1121,6 +1101,7 @@ void CurveCreator_Widget::moveSelectedPoints( const int theXPosition,
     aChangedPos[1] = aChangedPos[1] - anYDelta;
     myCurve->setPoint( aSectionId, aPointId, aChangedPos );
   }
+  myDragged = true;
   finishCurveModification( myDragPoints );
 }
 
@@ -1258,15 +1239,24 @@ void CurveCreator_Widget::addLocalPointToTable( const double theX, const double
  */
 void CurveCreator_Widget::setDragStarted( const bool theState, const QPoint& thePoint )
 {
-  if ( !theState ) {
-    myDragStarted = false;
-    myDragPoints.clear();
-  }
-  else {
+  OCCViewer_Viewer* aViewer = getOCCViewer();
+  if ( theState ) {
     getSelectedPonts( 0, myDragPoints );
     myDragStarted = myDragPoints.size();
     myDragStartPosition = thePoint;
+    if ( aViewer && myDragStarted ) {
+      // change a viewer interaction style in order to avoid a select rectangle build
+      myDragInteractionStyle = aViewer->interactionStyle();
+      aViewer->setInteractionStyle(SUIT_ViewModel::KEY_FREE);
+    }
+  }
+  else {
+    if ( aViewer && myDragStarted )
+      aViewer->setInteractionStyle( myDragInteractionStyle );
+    myDragStarted = false;
+    myDragPoints.clear();
   }
+  myDragged = false;
 }
 
 void CurveCreator_Widget::getSelectedPonts( int theSectionId, QList<int>& thePoints )
@@ -1319,6 +1309,7 @@ void CurveCreator_Widget::setSelectedPonts( const int theSectionId, const QList<
       aListToSelect.Append( anAIS );
   }
 
+  ic->ClearSelected( Standard_False );
   aViewer->setObjectsSelected( aListToSelect );
   updateLocalPointView();
 }
@@ -1376,6 +1367,11 @@ int CurveCreator_Widget::findLocalPointIndex( int theSectionId, float theX, floa
   return aPntIndex;
 }
 
+void CurveCreator_Widget::findSections( int thePointId, QList<int>& theSections )
+{
+  
+}
+
 /**
  * Checks whether the point belongs to the OCC object
  * \param theObject a line or shape with a bspline inside
@@ -1405,12 +1401,18 @@ bool CurveCreator_Widget::pointOnObject( Handle(AIS_InteractiveObject) theObject
     isFound = hasProjectPointOnCurve( theX, theY, aGLine, aParameter );
     if ( isFound ) {
       aPoint = aGLine->Value( aParameter );
-      
-    Handle(Geom_Point) aPStart;
-    Handle(Geom_Point) aPEnd;
-    aLine->Points( aPStart, aPEnd );
-    aPnt1 = aPStart->Pnt();
-    aPnt2 = aPEnd->Pnt();
+
+      Handle(Geom_Point) aPStart;
+      Handle(Geom_Point) aPEnd;
+      aLine->Points( aPStart, aPEnd );
+      aPnt1 = aPStart->Pnt();
+      aPnt2 = aPEnd->Pnt();
+
+      // in case of Geom line a projection is performed to the infinite line,
+      // so it is necessary to bound it by the line size
+      Bnd_Box aLineBox;
+      aLineBox.Set( aPnt1, gp_Vec( aPnt1, aPnt2 ) );
+      isFound = !aLineBox.IsOut( aPoint );
     }
   }
   else {
index 5ca56c675ea76857cc389f4927f1b74174886477..f17cf3d17f567238a4f2f6fd6798965141e3740e 100644 (file)
@@ -157,6 +157,7 @@ private:
 
   // curve algorithm
   int  findLocalPointIndex( int theSectionId, float theX, float theY );
+  void findSections( int thePointId, QList<int>& theSections );
 
   // OCC algorithm
   bool pointOnObject( Handle(AIS_InteractiveObject) theObject,
@@ -176,8 +177,10 @@ private:
   int                         mySection;
   int                         myPointNum;
   bool                        myDragStarted;
-  QList<int>                  myDragPoints;
   QPoint                      myDragStartPosition;
+  int                         myDragInteractionStyle;
+  QList<int>                  myDragPoints;
+  bool                        myDragged;
   QByteArray                  myGuiState;
 };