Salome HOME
Feature #102: Display of Lambert coordinates.
[modules/hydro.git] / src / HYDROCurveCreator / CurveCreator_Widget.cxx
index 719a58a7274e519524af45f511c931d909a86030..37a4c78279bf0a7c9d205c4b9f37038c2c1ef90b 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;
 
 CurveCreator_Widget::CurveCreator_Widget(QWidget* parent,
                                          CurveCreator_ICurve *theCurve,
-                                         Qt::WindowFlags fl)
+                                         Qt::WindowFlags fl,
+                                         int theLocalPointRowLimit )
 : QWidget(parent), myNewSectionEditor(NULL), myCurve(theCurve), mySection(0),
   myDragStarted( false ), myDragInteractionStyle( SUIT_ViewModel::STANDARD ),
-  myOCCViewer( 0 )
+  myOCCViewer( 0 ), myLocalPointRowLimit( theLocalPointRowLimit )
 {
   myNewSectionEditor = new CurveCreator_NewSectionDlg( this );
   myNewSectionEditor->hide();
@@ -982,7 +1013,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 +1040,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" );
 }
 
 /**
@@ -1215,6 +1254,11 @@ void CurveCreator_Widget::updateLocalPointView()
     return;
 
   std::list<float> aSelectedList = CurveCreator_Utils::getSelectedPoints( aContext );
+  int aNbPoints = aSelectedList.size()/3;
+  bool isRowLimit = aNbPoints > myLocalPointRowLimit;
+  myLocalPointView->setVisible( !isRowLimit );
+  if ( isRowLimit )
+    return;
 
   std::list<float>::const_iterator anIt = aSelectedList.begin(), aLast = aSelectedList.end();
 
@@ -1298,51 +1342,108 @@ void CurveCreator_Widget::setSelectedPonts( const CurveCreator_ICurve::SectionTo
 {
   if ( myDragStarted )
     return;
+
   Handle(AIS_InteractiveContext) ic = getAISContext();
   if ( ic.IsNull() || !ic->HasOpenedContext() )
     return;
 
   AIS_ListOfInteractive aListToSelect;
-
   AIS_ListOfInteractive aDisplayedList;
   ic->DisplayedObjects( aDisplayedList );
   ic->ClearSelected( Standard_False );
 
+  bool isSelectedVertex = false;
+
+  //ASL: std::vector<TopoDS_Vertex> aVetexVec;
+  for ( AIS_ListIteratorOfListOfInteractive it( aDisplayedList ); it.More(); it.Next() )
+  {
+    Handle(AIS_InteractiveObject) anAIS = it.Value();
+    if ( anAIS.IsNull() )
+      continue;
+    Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast( anAIS );
+    if ( anAISShape.IsNull() )
+      continue;
+
+
+    /*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;
+        }
+      }
+    }
+  }
+
+  /*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();
   CurveCreator_ICurve::SectionToPoint aSToPoint;
-  bool isSelectedVertex = false;
+  int anAddedSize = 0;
   for( ; anIt != aLast; anIt++ ) {
     aSToPoint = *anIt;
-    for ( AIS_ListIteratorOfListOfInteractive it( aDisplayedList ); it.More(); it.Next() )
+
+    for ( aVecIt = aVetexVec.begin(); aVecIt != aVecLast; aVecIt++ )
     {
-      Handle(AIS_InteractiveObject) anAIS = it.Value();
-      if ( anAIS.IsNull() )
-        continue;
-      Handle(AIS_Point) anAISPoint = Handle(AIS_Point)::DownCast( anAIS );
-      if ( !anAISPoint.IsNull() ) {
-        TopoDS_Vertex aVertex = TopoDS::Vertex( anAISPoint->Vertex() );
-        if ( isIntersectVertexToPoint( aVertex, aSToPoint ) )
-          aListToSelect.Append( anAIS );
-      }
-      else {
-        Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast( anAIS );
-        if ( anAISShape.IsNull() )
-          continue;
-        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() );
-          if ( isIntersectVertexToPoint( aVertex, aSToPoint ) ) {
-            ic->AddOrRemoveSelected( aVertex, Standard_False );
-            isSelectedVertex = true;
-          }
-        }
+      TopoDS_Vertex aVertex = TopoDS::Vertex( *aVecIt );
+      if ( isIntersectVertexToPoint( aVertex, aSToPoint ) ) {
+        ic->AddOrRemoveSelected( aVertex, Standard_False );
+        isSelectedVertex = true;
+        anAddedSize++;
       }
     }
-  }
-  ic->UpdateCurrentViewer();
+  }*/
+
+  //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();
   if ( !isSelectedVertex )
     setObjectsSelected( aListToSelect );
   updateLocalPointView();