]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
Save for a list of the local selected points.
authornds <nds@opencascade.com>
Wed, 4 Dec 2013 10:15:34 +0000 (10:15 +0000)
committernds <nds@opencascade.com>
Wed, 4 Dec 2013 10:15:34 +0000 (10:15 +0000)
src/HYDROCurveCreator/CurveCreator_TableView.cxx
src/HYDROCurveCreator/CurveCreator_TableView.h
src/HYDROCurveCreator/CurveCreator_Utils.cxx
src/HYDROCurveCreator/CurveCreator_Utils.h
src/HYDROCurveCreator/CurveCreator_UtilsICurve.cxx
src/HYDROCurveCreator/CurveCreator_UtilsICurve.hxx
src/HYDROCurveCreator/CurveCreator_Widget.cxx
src/HYDROCurveCreator/CurveCreator_Widget.h

index 4d5bd272bf2340463d1cd811801ed11cc93b5ec5..b0c4d527f87186dd5aee432a3011ae31536ffa66 100644 (file)
@@ -20,6 +20,8 @@
 #include "CurveCreator_TableView.h"
 #include "CurveCreator_UtilsICurve.hxx"
 
+#include <gp_Pnt.hxx>
+
 #include <QTableWidget>
 #include <QTableWidgetItem>
 
@@ -110,60 +112,42 @@ void CurveCreator_TableView::setCurve( CurveCreator_ICurve* theCurve )
   myCurve = theCurve;
 }
 
-void CurveCreator_TableView::addLocalPointToTable( const double theX, const double theY )
+void CurveCreator_TableView::addLocalPointToTable(
+                     const CurveCreator_ICurve::SectionToPoint& theSToPoint )
 {
-  CurveCreator_ICurve::SectionToPointList aPoints;
-  CurveCreator_UtilsICurve::findSectionsToPoints( myCurve, theX, theY, aPoints );
-
-  CurveCreator_ICurve::SectionToPointList aSkipList;
-  // table could not contain two equal value rows
   int aRowId = rowCount();
-  double aCurrentX, aCurrentY;
-  int aSectionId, aPointId;
-  CurveCreator_ICurve::SectionToPoint aPoint;
-  for ( int i = 0; i < aRowId; i++ ) {
-    aCurrentX = item( i, 2 )->data( Qt::UserRole ).toDouble();
-    aCurrentY = item( i, 3 )->data( Qt::UserRole ).toDouble();
-    if ( fabs( aCurrentX - theX ) < LOCAL_SELECTION_TOLERANCE &&
-         fabs( aCurrentY - theY ) < LOCAL_SELECTION_TOLERANCE ) {
-      aPoint = std::make_pair<int, int>( getSectionId( i ), getPointId( i ) );
-      if ( !CurveCreator_UtilsICurve::contains( aSkipList, aPoint ) )
-        aSkipList.push_back( aPoint );
-    }
-  }
-  if ( aSkipList.size() == aPoints.size() )
+  int anISection = theSToPoint.first;
+  int anIPoint = theSToPoint.second;
+  bool isFoundPoint = false;
+  for ( int i = 0; i < aRowId && !isFoundPoint; i++ )
+    isFoundPoint = getSectionId( i ) == anISection && 
+                   getPointId( i ) == anIPoint;
+  if ( isFoundPoint )
     return;
 
+  setRowCount( aRowId+1 );
+
   QTableWidgetItem* anItem;
-  CurveCreator_ICurve::SectionToPointList::const_iterator anIt = aPoints.begin(),
-                                                          aLast = aPoints.end();
-  for ( ; anIt != aLast; anIt++ ) {
-    aPoint = *anIt;
-    if ( CurveCreator_UtilsICurve::contains( aSkipList, aPoint ) )
-      continue;
-
-    setRowCount( aRowId+1 );
-    aSectionId = aPoint.first;
-    aPointId = aPoint.second;
-
-    anItem = new QTableWidgetItem( myCurve->getSectionName( aSectionId ).c_str() );
-    anItem->setFlags( anItem->flags() & ~Qt::ItemIsEnabled );
-    anItem->setData( Qt::UserRole, aSectionId );
-    setItem( aRowId, 0, anItem );
-
-    anItem = new QTableWidgetItem( QString::number( aPointId + 1 ) );
-    anItem->setFlags( anItem->flags() & ~Qt::ItemIsEnabled );
-    anItem->setData( Qt::UserRole, aPointId );
-    setItem( aRowId, 1, anItem );
-  
-    anItem = new QTableWidgetItem( QString::number( theX, 'f', 2 ) );
-    anItem->setData( Qt::UserRole, theX );
-    setItem( aRowId, 2, anItem );
-
-    anItem = new QTableWidgetItem( QString::number( theY, 'f', 2 ) );
-    anItem->setData( Qt::UserRole, theY );
-    setItem( aRowId, 3, anItem );
-  }
+  anItem = new QTableWidgetItem( myCurve->getSectionName( anISection ).c_str() );
+  anItem->setFlags( anItem->flags() & ~Qt::ItemIsEnabled );
+  anItem->setData( Qt::UserRole, anISection );
+  setItem( aRowId, 0, anItem );
+
+  anItem = new QTableWidgetItem( QString::number( anIPoint + 1 ) );
+  anItem->setFlags( anItem->flags() & ~Qt::ItemIsEnabled );
+  anItem->setData( Qt::UserRole, anIPoint );
+  setItem( aRowId, 1, anItem );
+
+  gp_Pnt aPoint;
+  CurveCreator_UtilsICurve::getPoint( myCurve, anISection, anIPoint, aPoint );
+
+  anItem = new QTableWidgetItem( QString::number( aPoint.X(), 'f', 2 ) );
+  anItem->setData( Qt::UserRole, aPoint.X() );
+  setItem( aRowId, 2, anItem );
+
+  anItem = new QTableWidgetItem( QString::number( aPoint.Y(), 'f', 2 ) );
+  anItem->setData( Qt::UserRole, aPoint.Y() );
+  setItem( aRowId, 3, anItem );
 }
 
 int CurveCreator_TableView::getSectionId( const int theRowId ) const
index ffbd3da7fd92602a0bdb11da5b5cbc8a2b0a10c2..bb8f73240fa1c2baf49768d7474fd7c5c31279ca 100644 (file)
@@ -47,7 +47,7 @@ public:
 
   void setCurve( CurveCreator_ICurve* theCurve );
 
-  void addLocalPointToTable( const double theX, const double theY );
+  void addLocalPointToTable( const CurveCreator_ICurve::SectionToPoint& thePoint );
 
   /**
    * Returns a section index from the table
index 2a29176e94c899b25fc16fff340a6ac7352b3fba..a8514964c58c1de6407973e694eb8a292b870345 100644 (file)
@@ -173,13 +173,17 @@ private:
   gp_Pnt myPoint;
 };
 
-std::list<float> CurveCreator_Utils::getSelectedPoints( Handle(AIS_InteractiveContext) theContext )
+void CurveCreator_Utils::getSelectedPoints( Handle(AIS_InteractiveContext) theContext,
+                                            const CurveCreator_ICurve* theCurve,
+                                            CurveCreator_ICurve::SectionToPointList& thePoints )
 {
-  std::list<float> aSelectedPoints;
+  thePoints.clear();
 
+  std::list<float> aSelectedPoints;
   gp_Pnt aPnt;
   std::map<ComparePnt, int> aPntMap;
 
+  CurveCreator_ICurve::SectionToPointList aPoints;
   for ( theContext->InitSelected(); theContext->MoreSelected(); theContext->NextSelected() ) {
     TopoDS_Vertex aVertex;
     TopoDS_Shape aShape = theContext->SelectedShape();
@@ -192,13 +196,15 @@ std::list<float> CurveCreator_Utils::getSelectedPoints( Handle(AIS_InteractiveCo
     if ( aPntMap.find( aPnt ) != aPntMap.end() )
       continue;
     aPntMap[aPnt] = 0;
-    aSelectedPoints.push_back( aPnt.X() );
-    aSelectedPoints.push_back( aPnt.Y() );
-    aSelectedPoints.push_back( aPnt.Z() );
-  }
 
-  return aSelectedPoints;
+    CurveCreator_UtilsICurve::findSectionsToPoints( theCurve, aPnt.X(), aPnt.Y(), aPoints );
+    CurveCreator_ICurve::SectionToPointList::const_iterator anIt = aPoints.begin(),
+                                                            aLast = aPoints.end();
+    for ( ; anIt != aLast; anIt++ )
+      thePoints.push_back( *anIt );
+  }
 }
+
 //=======================================================================
 // function : setLocalPointContext
 // purpose  : Open/close the viewer local context
index 0182d19b16611005a20cd09fbbcb3325969b7a81..0bdf5d5957cf428ebf944321fa3cff35db0012fc 100644 (file)
@@ -21,6 +21,7 @@
 #define CURVECREATOR_UTILS_H
 
 #include "CurveCreator_Macro.hxx"
+#include "CurveCreator_ICurve.hxx"
 
 #include <AIS_InteractiveContext.hxx>
 #include <AIS_InteractiveObject.hxx> // TODO: remove
@@ -32,7 +33,6 @@
 #include <list>
 #include <vector> // TODO: remove
 
-class CurveCreator_ICurve;
 
 class CurveCreator_Utils
 {
@@ -73,8 +73,9 @@ public:
    * Find selected points in the context
    * \param theContext the viewer context
    */
-  CURVECREATOR_EXPORT static std::list<float> getSelectedPoints(
-                                        Handle(AIS_InteractiveContext) theContext );
+  CURVECREATOR_EXPORT static void getSelectedPoints( Handle(AIS_InteractiveContext) theContext,
+                                         const CurveCreator_ICurve* theCurve,
+                                         CurveCreator_ICurve::SectionToPointList& thePoints );
 
   /*!
    * \brief Sets the local point context for the 3D viewer.
index d8b5d2ded840c5b2d22643040b3f651e08333681..cc717a08d449fe7f5c91405139f7520976b1a257 100644 (file)
@@ -23,7 +23,7 @@
 
 const double LOCAL_SELECTION_TOLERANCE = 0.0001;
 
-int CurveCreator_UtilsICurve::findLocalPointIndex( CurveCreator_ICurve* theCurve,
+int CurveCreator_UtilsICurve::findLocalPointIndex( const CurveCreator_ICurve* theCurve,
                                              int theSectionId, float theX, float theY )
 {
   int aPntIndex = -1;
@@ -43,7 +43,7 @@ int CurveCreator_UtilsICurve::findLocalPointIndex( CurveCreator_ICurve* theCurve
   return aPntIndex;
 }
 
-void CurveCreator_UtilsICurve::findSectionsToPoints( CurveCreator_ICurve* theCurve,
+void CurveCreator_UtilsICurve::findSectionsToPoints( const CurveCreator_ICurve* theCurve,
                                  const double theX, const double theY,
                                  CurveCreator_ICurve::SectionToPointList& thePoints )
 {
index 9681552e663fae1dffef0dcff369b0e627c747e0..60e78683d12faa54607a5af23685b8b41819c8b7 100644 (file)
@@ -36,10 +36,10 @@ public:
    * \param theX the X coordinate of the point
    * \param theY the Y coordinate of the point
    */
-  CURVECREATOR_EXPORT static int  findLocalPointIndex( CurveCreator_ICurve* theCurve,
+  CURVECREATOR_EXPORT static int  findLocalPointIndex( const CurveCreator_ICurve* theCurve,
                                           int theSectionId, float theX, float theY );
 
-  CURVECREATOR_EXPORT static void findSectionsToPoints( CurveCreator_ICurve* theCurve,
+  CURVECREATOR_EXPORT static void findSectionsToPoints( const CurveCreator_ICurve* theCurve,
                                           const double theX, const double theY,
                                           CurveCreator_ICurve::SectionToPointList& thePoints );
   CURVECREATOR_EXPORT static void convert( const CurveCreator_ICurve::SectionToPointList& thePoints,
index 580cab4907572f2956fb94ae808ef12caf3e4af1..66534638175a8a784e944b657fc2302d2a2edddf 100644 (file)
@@ -1015,7 +1015,7 @@ void CurveCreator_Widget::onMouseRelease( SUIT_ViewWindow*, QMouseEvent* theEven
     if ( aDraggedPoints.size() > 0 )
     {
       START_MEASURE_TIME;
-      setSelectedPonts( aDraggedPoints );
+      setSelectedPoints( aDraggedPoints );
       END_MEASURE_TIME( "drop" );
     }
   }
@@ -1129,7 +1129,7 @@ void CurveCreator_Widget::removeSection()
 void CurveCreator_Widget::removePoint()
 {
   CurveCreator_ICurve::SectionToPointList aPoints;
-  getSelectedPonts( aPoints );
+  getSelectedPoints( aPoints );
   if ( aPoints.size() == 0 )
     return;
 
@@ -1201,7 +1201,7 @@ void CurveCreator_Widget::insertPointToSelectedSegment( const int theX,
 
   finishCurveModification( aSelPoints );
 
-  setSelectedPonts();
+  setSelectedPoints();
 }
 
 void CurveCreator_Widget::moveSelectedPoints( const int theXPosition,
@@ -1253,27 +1253,21 @@ void CurveCreator_Widget::updateLocalPointView()
   if ( aContext.IsNull() )
     return;
 
-  std::list<float> aSelectedList = CurveCreator_Utils::getSelectedPoints( aContext );
-  /*int aNbPoints = aSelectedList.size()/3;
+  CurveCreator_Utils::getSelectedPoints( aContext, myCurve, myLocalPoints );
+  int aNbPoints = myLocalPoints.size();
   bool isRowLimit = aNbPoints > myLocalPointRowLimit;
   myLocalPointView->setVisible( !isRowLimit );
-  if ( isRowLimit )
-    return;
-  */
-  std::list<float>::const_iterator anIt = aSelectedList.begin(), aLast = aSelectedList.end();
 
-  bool isBlocked = myLocalPointView->blockSignals(true);
-  myLocalPointView->setRowCount( 0 );
-  for ( ; anIt != aLast; anIt++ )
-  {
-    float aX = *anIt;
-    anIt++;
-    float anY = *anIt;
-    anIt++;
-    float aZ = *anIt;
-    myLocalPointView->addLocalPointToTable( aX, anY );
+  if ( !isRowLimit ) {
+    bool isBlocked = myLocalPointView->blockSignals(true);
+    myLocalPointView->setRowCount( 0 );
+    CurveCreator_ICurve::SectionToPointList::const_iterator anIt = myLocalPoints.begin(),
+                                                            aLast = myLocalPoints.end();
+    for ( ; anIt != aLast; anIt++ )
+      myLocalPointView->addLocalPointToTable( *anIt );
+
+    myLocalPointView->blockSignals( isBlocked );
   }
-  myLocalPointView->blockSignals(isBlocked);
 }
 
 /**
@@ -1294,7 +1288,7 @@ void CurveCreator_Widget::setLocalPointContext( const bool theOpen, const bool i
 void CurveCreator_Widget::setDragStarted( const bool theState, const QPoint& thePoint )
 {
   if ( theState ) {
-    getSelectedPonts( myDragPoints );
+    getSelectedPoints( myDragPoints );
     myDragStarted = myDragPoints.size();
     myDragStartPosition = thePoint;
     if ( myDragStarted ) {
@@ -1311,12 +1305,10 @@ void CurveCreator_Widget::setDragStarted( const bool theState, const QPoint& the
   myDragged = false;
 }
 
-void CurveCreator_Widget::getSelectedPonts( CurveCreator_ICurve::SectionToPointList& thePoints )
+void CurveCreator_Widget::getSelectedPoints( CurveCreator_ICurve::SectionToPointList& thePoints )
 {
   thePoints.clear();
-  for ( int i = 0, aNb = myLocalPointView->rowCount(); i < aNb; i++ )
-    thePoints.push_back( std::make_pair( myLocalPointView->getSectionId( i ),
-                                         myLocalPointView->getPointId( i ) ) );
+  thePoints = myLocalPoints;
 }
 
 
@@ -1338,7 +1330,7 @@ bool CurveCreator_Widget::isIntersectVertexToPoint( const TopoDS_Vertex& theVert
 }
 
 
-void CurveCreator_Widget::setSelectedPonts( const CurveCreator_ICurve::SectionToPointList& thePoints )
+void CurveCreator_Widget::setSelectedPoints( const CurveCreator_ICurve::SectionToPointList& thePoints )
 {
   if ( myDragStarted )
     return;
@@ -1464,7 +1456,7 @@ void CurveCreator_Widget::startCurveModification(
 {
   if ( theFillPoints ) {
     thePoints.clear();
-    getSelectedPonts( thePoints );
+    getSelectedPoints( thePoints );
   }
   setLocalPointContext( false );
 }
@@ -1479,7 +1471,7 @@ void CurveCreator_Widget::finishCurveModification(
 {
   if ( getActionMode() == ModificationMode )
     setLocalPointContext( true );
-  setSelectedPonts( thePoints );
+  setSelectedPoints( thePoints );
   updateUndoRedo();
 }
 
index 5e714532bd1c984bde2b487c31d237481f5089f9..e3ac5af039514bd3cfe7040676abe86229b6a670 100644 (file)
@@ -165,10 +165,10 @@ private:
 
   void setDragStarted( const bool theState, const QPoint& thePoint = QPoint() );
 
-  void getSelectedPonts( CurveCreator_ICurve::SectionToPointList& thePoints );
+  void getSelectedPoints( CurveCreator_ICurve::SectionToPointList& thePoints );
   bool isIntersectVertexToPoint( const TopoDS_Vertex& theVertex,
                                const CurveCreator_ICurve::SectionToPoint& theSToPoint );
-  void setSelectedPonts( const CurveCreator_ICurve::SectionToPointList& =
+  void setSelectedPoints( const CurveCreator_ICurve::SectionToPointList& =
                                CurveCreator_ICurve::SectionToPointList() );
 
   void startCurveModification( CurveCreator_ICurve::SectionToPointList& thePoints,
@@ -191,6 +191,7 @@ private:
   CurveCreator_ICurve*        myCurve;
   CurveCreator_TreeView*      mySectionView;
   CurveCreator_TableView*     myLocalPointView;
+  CurveCreator_ICurve::SectionToPointList myLocalPoints;
   CurveCreator_NewSectionDlg* myNewSectionEditor;
   OCCViewer_Viewer*           myOCCViewer;
   int                         myLocalPointRowLimit;