]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
optimization of the polylines drag-n-drop
authorasl <asl@opencascade.com>
Wed, 4 Dec 2013 07:54:20 +0000 (07:54 +0000)
committerasl <asl@opencascade.com>
Wed, 4 Dec 2013 07:54:20 +0000 (07:54 +0000)
src/HYDROCurveCreator/CurveCreator_Widget.cxx

index 41f2485f80c61615ec7acf8a137a45b1f0c57925..bbf25b998de005c583f30e98f5f3f0933c3ab5c0 100644 (file)
 #include <AIS_Shape.hxx>
 #include <AIS_Point.hxx>
 #include <AIS_Line.hxx>
+#include <AIS_LocalContext.hxx>
 #include <Geom_Point.hxx>
 #include <Geom_BSplineCurve.hxx>
 #include <Geom_Line.hxx>
 #include <StdSelect_BRepOwner.hxx>
+#include <SelectMgr_Selection.hxx>
+#include <Select3D_SensitivePoint.hxx>
 
 #include <QHBoxLayout>
 #include <QVBoxLayout>
 #include <QMouseEvent>
 #include <QApplication>
 #include <QTableWidget>
+#include <QTime>
+
+#define MEASURE_TIME
+
+#ifdef MEASURE_TIME
+
+  #define START_MEASURE_TIME \
+    QTime aTimer;            \
+    aTimer.start();          \
+
+  #define END_MEASURE_TIME( theMsg )                      \
+    double aTime = aTimer.elapsed() * 0.001;              \
+    FILE* aFile = fopen( "performance", "a" );            \
+    fprintf( aFile, "%s = %.3lf sec\n", theMsg, aTime );  \
+    fclose( aFile );                                      \
+
+#else
+
+  #define START_MEASURE_TIME
+  #define END_MEASURE_TIME( theMsg )
+
+#endif
+
+
+
+
+
 
 const double LOCAL_SELECTION_TOLERANCE = 0.0001;
 
@@ -982,7 +1012,11 @@ void CurveCreator_Widget::onMouseRelease( SUIT_ViewWindow*, QMouseEvent* theEven
     setDragStarted( false );
     // if the drag of some points has happened, restore the drag selection
     if ( aDraggedPoints.size() > 0 )
+    {
+      START_MEASURE_TIME;
       setSelectedPonts( aDraggedPoints );
+      END_MEASURE_TIME( "drop" );
+    }
   }
   else // check whether the segment is clicked an a new point should be added to the segment
     insertPointToSelectedSegment( theEvent->pos().x(), theEvent->pos().y() );
@@ -1005,8 +1039,12 @@ void CurveCreator_Widget::onMouseMove( SUIT_ViewWindow*, QMouseEvent* theEvent )
   if ( (aPos - myDragStartPosition).manhattanLength() < QApplication::startDragDistance() )
     return;
 
+  START_MEASURE_TIME;
+
   moveSelectedPoints( aPos.x(), aPos.y() );
   myDragStartPosition = aPos;
+
+  END_MEASURE_TIME( "drag" );
 }
 
 /**
@@ -1298,6 +1336,7 @@ void CurveCreator_Widget::setSelectedPonts( const CurveCreator_ICurve::SectionTo
 {
   if ( myDragStarted )
     return;
+
   Handle(AIS_InteractiveContext) ic = getAISContext();
   if ( ic.IsNull() || !ic->HasOpenedContext() )
     return;
@@ -1307,7 +1346,9 @@ void CurveCreator_Widget::setSelectedPonts( const CurveCreator_ICurve::SectionTo
   ic->DisplayedObjects( aDisplayedList );
   ic->ClearSelected( Standard_False );
 
-  std::vector<TopoDS_Vertex> aVetexVec;
+  bool isSelectedVertex = false;
+
+  //ASL: std::vector<TopoDS_Vertex> aVetexVec;
   for ( AIS_ListIteratorOfListOfInteractive it( aDisplayedList ); it.More(); it.Next() )
   {
     Handle(AIS_InteractiveObject) anAIS = it.Value();
@@ -1316,17 +1357,62 @@ void CurveCreator_Widget::setSelectedPonts( const CurveCreator_ICurve::SectionTo
     Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast( anAIS );
     if ( anAISShape.IsNull() )
       continue;
-    const TopoDS_Shape& aShape = anAISShape->Shape();
+
+
+    /*ASL: const TopoDS_Shape& aShape = anAISShape->Shape();
     TopExp_Explorer aExpV( aShape, TopAbs_VERTEX);
     for ( ; aExpV.More(); aExpV.Next() )
     {
       const TopoDS_Vertex& aVertex = TopoDS::Vertex( aExpV.Current() );
       aVetexVec.push_back( aVertex );
+    }*/
+
+
+    //ASL: we convert list of point indices to list of points coordinates
+    int aSize = thePoints.size();
+    std::vector<gp_Pnt> aPntsToSelect( aSize );
+
+    CurveCreator_ICurve::SectionToPointList::const_iterator
+      aPIt = thePoints.begin(), aPLast = thePoints.end();
+    CurveCreator_ICurve::SectionToPoint aSToPoint;
+    for( int i=0; aPIt != aPLast; aPIt++, i++ )
+    {
+      gp_Pnt aPntToSelect;
+      CurveCreator_UtilsICurve::getPoint( myCurve, aPIt->first, aPIt->second, aPntToSelect );
+      aPntsToSelect[i] = aPntToSelect;
+    }
+
+
+    //ASL: we switch off automatic highlight to improve performance of selection
+    ic->SetAutomaticHilight( Standard_False );
+
+    Handle_SelectMgr_Selection aSelection = anAISShape->Selection( AIS_Shape::SelectionMode( TopAbs_VERTEX ) );
+    for( aSelection->Init(); aSelection->More(); aSelection->Next() )
+    {
+      Handle_SelectBasics_SensitiveEntity aSenEntity = aSelection->Sensitive();
+      Handle_Select3D_SensitivePoint aSenPnt = Handle_Select3D_SensitivePoint::DownCast( aSenEntity );
+
+      gp_Pnt anOwnerPnt = aSenPnt->Point();
+      Handle_SelectMgr_EntityOwner anOwner = Handle_SelectMgr_EntityOwner::DownCast( aSenPnt->OwnerId() );
+
+
+      CurveCreator_ICurve::SectionToPointList::const_iterator anIt = thePoints.begin(),
+                                                                     aLast = thePoints.end();
+      bool isFound = false;
+      for( int i=0; i<aSize; i++ )
+      {
+        bool isIntersect = fabs( aPntsToSelect[i].X() - anOwnerPnt.X() ) < LOCAL_SELECTION_TOLERANCE &&
+                           fabs( aPntsToSelect[i].Y() - anOwnerPnt.Y() ) < LOCAL_SELECTION_TOLERANCE;
+        if( isIntersect )
+        {
+          ic->AddOrRemoveSelected( anOwner, Standard_False );
+          break;
+        }
+      }
     }
   }
-  bool isSelectedVertex = false;
 
-  std::vector<TopoDS_Vertex>::const_iterator aVecIt = aVetexVec.begin(), aVecLast = aVetexVec.end(); 
+  /*ASL: std::vector<TopoDS_Vertex>::const_iterator aVecIt = aVetexVec.begin(), aVecLast = aVetexVec.end(); 
   CurveCreator_ICurve::SectionToPointList::const_iterator anIt = thePoints.begin(),
                                                           aLast = thePoints.end();
   int aSize = aVetexVec.size();
@@ -1344,9 +1430,14 @@ void CurveCreator_Widget::setSelectedPonts( const CurveCreator_ICurve::SectionTo
         anAddedSize++;
       }
     }
-  }
+  }*/
+
+  //ASL: we switch on again automatic highlight (otherwise selection will not be shown)
+  //     and call HilightPicked to draw selected owners
+  ic->SetAutomaticHilight( Standard_True );
+  ic->LocalContext()->HilightPicked( Standard_True );
 
-  ic->UpdateCurrentViewer();
+  //ic->UpdateCurrentViewer();
   if ( !isSelectedVertex )
     setObjectsSelected( aListToSelect );
   updateLocalPointView();