From: nds Date: Wed, 4 Dec 2013 10:15:34 +0000 (+0000) Subject: Save for a list of the local selected points. X-Git-Tag: BR_hydro_v_0_4~55 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=5de801b5e40ccbf7761fd4a0f115e117123fb12e;p=modules%2Fhydro.git Save for a list of the local selected points. --- diff --git a/src/HYDROCurveCreator/CurveCreator_TableView.cxx b/src/HYDROCurveCreator/CurveCreator_TableView.cxx index 4d5bd272..b0c4d527 100644 --- a/src/HYDROCurveCreator/CurveCreator_TableView.cxx +++ b/src/HYDROCurveCreator/CurveCreator_TableView.cxx @@ -20,6 +20,8 @@ #include "CurveCreator_TableView.h" #include "CurveCreator_UtilsICurve.hxx" +#include + #include #include @@ -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( 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 diff --git a/src/HYDROCurveCreator/CurveCreator_TableView.h b/src/HYDROCurveCreator/CurveCreator_TableView.h index ffbd3da7..bb8f7324 100644 --- a/src/HYDROCurveCreator/CurveCreator_TableView.h +++ b/src/HYDROCurveCreator/CurveCreator_TableView.h @@ -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 diff --git a/src/HYDROCurveCreator/CurveCreator_Utils.cxx b/src/HYDROCurveCreator/CurveCreator_Utils.cxx index 2a29176e..a8514964 100644 --- a/src/HYDROCurveCreator/CurveCreator_Utils.cxx +++ b/src/HYDROCurveCreator/CurveCreator_Utils.cxx @@ -173,13 +173,17 @@ private: gp_Pnt myPoint; }; -std::list 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 aSelectedPoints; + thePoints.clear(); + std::list aSelectedPoints; gp_Pnt aPnt; std::map 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 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 diff --git a/src/HYDROCurveCreator/CurveCreator_Utils.h b/src/HYDROCurveCreator/CurveCreator_Utils.h index 0182d19b..0bdf5d59 100644 --- a/src/HYDROCurveCreator/CurveCreator_Utils.h +++ b/src/HYDROCurveCreator/CurveCreator_Utils.h @@ -21,6 +21,7 @@ #define CURVECREATOR_UTILS_H #include "CurveCreator_Macro.hxx" +#include "CurveCreator_ICurve.hxx" #include #include // TODO: remove @@ -32,7 +33,6 @@ #include #include // 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 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. diff --git a/src/HYDROCurveCreator/CurveCreator_UtilsICurve.cxx b/src/HYDROCurveCreator/CurveCreator_UtilsICurve.cxx index d8b5d2de..cc717a08 100644 --- a/src/HYDROCurveCreator/CurveCreator_UtilsICurve.cxx +++ b/src/HYDROCurveCreator/CurveCreator_UtilsICurve.cxx @@ -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 ) { diff --git a/src/HYDROCurveCreator/CurveCreator_UtilsICurve.hxx b/src/HYDROCurveCreator/CurveCreator_UtilsICurve.hxx index 9681552e..60e78683 100644 --- a/src/HYDROCurveCreator/CurveCreator_UtilsICurve.hxx +++ b/src/HYDROCurveCreator/CurveCreator_UtilsICurve.hxx @@ -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, diff --git a/src/HYDROCurveCreator/CurveCreator_Widget.cxx b/src/HYDROCurveCreator/CurveCreator_Widget.cxx index 580cab49..66534638 100644 --- a/src/HYDROCurveCreator/CurveCreator_Widget.cxx +++ b/src/HYDROCurveCreator/CurveCreator_Widget.cxx @@ -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 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::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(); } diff --git a/src/HYDROCurveCreator/CurveCreator_Widget.h b/src/HYDROCurveCreator/CurveCreator_Widget.h index 5e714532..e3ac5af0 100644 --- a/src/HYDROCurveCreator/CurveCreator_Widget.h +++ b/src/HYDROCurveCreator/CurveCreator_Widget.h @@ -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;