From: asl Date: Wed, 4 Dec 2013 07:54:20 +0000 (+0000) Subject: optimization of the polylines drag-n-drop X-Git-Tag: BR_hydro_v_0_4~62 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=3e0c2c74ed6b41312cb059488d97b2dcdc86c64a;p=modules%2Fhydro.git optimization of the polylines drag-n-drop --- diff --git a/src/HYDROCurveCreator/CurveCreator_Widget.cxx b/src/HYDROCurveCreator/CurveCreator_Widget.cxx index 41f2485f..bbf25b99 100644 --- a/src/HYDROCurveCreator/CurveCreator_Widget.cxx +++ b/src/HYDROCurveCreator/CurveCreator_Widget.cxx @@ -54,10 +54,13 @@ #include #include #include +#include #include #include #include #include +#include +#include #include #include @@ -71,6 +74,33 @@ #include #include #include +#include + +#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 aVetexVec; + bool isSelectedVertex = false; + + //ASL: std::vector 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 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; iAddOrRemoveSelected( anOwner, Standard_False ); + break; + } + } } } - bool isSelectedVertex = false; - std::vector::const_iterator aVecIt = aVetexVec.begin(), aVecLast = aVetexVec.end(); + /*ASL: std::vector::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();