X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDROCurveCreator%2FCurveCreator_Widget.cxx;h=f55d43d4eb32a881c14cb3f66b40b20bff7d532b;hb=1f844eb06506171b54541cc0caf1a0c237fe0dbf;hp=94f41248773476f7ddaa35ab4782afb0d6bccc93;hpb=9c2092abf45b47c9c3512397341f7f114f07cc30;p=modules%2Fhydro.git diff --git a/src/HYDROCurveCreator/CurveCreator_Widget.cxx b/src/HYDROCurveCreator/CurveCreator_Widget.cxx index 94f41248..f55d43d4 100644 --- a/src/HYDROCurveCreator/CurveCreator_Widget.cxx +++ b/src/HYDROCurveCreator/CurveCreator_Widget.cxx @@ -292,6 +292,8 @@ void CurveCreator_Widget::onSelectionChanged() QList anEnabledAct; if( myCurve ){ anEnabledAct << NEW_SECTION_ID << MODIFICATION_MODE_ID; + if ( getActionMode() == ModificationMode ) + anEnabledAct << REMOVE_ID; QList aSelSections = mySectionView->getSelectedSections(); QList< QPair< int, int > > aSelPoints = mySectionView->getSelectedPoints(); CurveCreator_TreeView::SelectionType aSelType = mySectionView->getSelectionType(); @@ -730,7 +732,11 @@ void CurveCreator_Widget::onUndo() { if( !myCurve ) return; + + CurveCreator_Widget::SectionToPointList aPoints; + startCurveModification( aPoints, false ); myCurve->undo(); + finishCurveModification(); mySectionView->reset(); updateUndoRedo(); } @@ -739,7 +745,10 @@ void CurveCreator_Widget::onRedo() { if( !myCurve ) return; + CurveCreator_Widget::SectionToPointList aPoints; + startCurveModification( aPoints, false ); myCurve->redo(); + finishCurveModification(); mySectionView->reset(); updateUndoRedo(); } @@ -993,15 +1002,22 @@ void CurveCreator_Widget::removePoint() startCurveModification( aSelPoints, false ); // the points should be removed in a decreased order - qSort( aPoints ); - SectionToPointList::const_iterator anIt = aPoints.end(), aFirst = aPoints.begin(); - anIt--; - for ( ; anIt != aFirst; anIt-- ) { - int aSectionId = anIt->first; - int aPointId = anIt->second; - myCurve->removePoint( aSectionId, aPointId ); - mySectionView->pointsRemoved( aSectionId, aPointId ); + QMap > aConvPoints; + convert( aPoints, aConvPoints ); + QMap >::const_iterator anIt = aConvPoints.begin(), + aLast = aConvPoints.end(); + for ( ; anIt != aLast; anIt++ ) { + int aSectionId = anIt.key(); + + QList aSectionPoints = anIt.value(); + qSort( aSectionPoints ); + for( int i = aSectionPoints.size()-1; i >= 0; i-- ){ + int aPntIndx = aSectionPoints[i]; + myCurve->removePoint( aSectionId, aPntIndx ); + mySectionView->pointsRemoved( aSectionId, aPntIndx ); + } } + finishCurveModification( SectionToPointList() ); } @@ -1227,9 +1243,9 @@ void CurveCreator_Widget::addLocalPointToTable( const double theX, const double aCurrentY = myLocalPointView->item( i, 3 )->data( Qt::UserRole ).toDouble(); if ( fabs( aCurrentX - theX ) < LOCAL_SELECTION_TOLERANCE && fabs( aCurrentY - theY ) < LOCAL_SELECTION_TOLERANCE ) { - aPoint = qMakePair( getSectionId( i ), getPointId( i ) ); - if ( !aSkipList.contains( aPoint ) ) - aSkipList.append( aPoint ); + aPoint = std::make_pair( getSectionId( i ), getPointId( i ) ); + if ( !contains( aSkipList, aPoint ) ) + aSkipList.push_back( aPoint ); } } if ( aSkipList.size() == aPoints.size() ) @@ -1239,7 +1255,7 @@ void CurveCreator_Widget::addLocalPointToTable( const double theX, const double SectionToPointList::const_iterator anIt = aPoints.begin(), aLast = aPoints.end(); for ( ; anIt != aLast; anIt++ ) { aPoint = *anIt; - if ( aSkipList.contains( aPoint ) ) + if ( contains( aSkipList, aPoint ) ) continue; myLocalPointView->setRowCount( aRowId+1 ); @@ -1297,7 +1313,7 @@ void CurveCreator_Widget::getSelectedPonts( CurveCreator_Widget::SectionToPointL { thePoints.clear(); for ( int i = 0, aNb = myLocalPointView->rowCount(); i < aNb; i++ ) - thePoints.append( qMakePair( getSectionId( i ), getPointId( i ) ) ); + thePoints.push_back( std::make_pair( getSectionId( i ), getPointId( i ) ) ); } void CurveCreator_Widget::setSelectedPonts( const CurveCreator_Widget::SectionToPointList& thePoints ) @@ -1337,7 +1353,7 @@ void CurveCreator_Widget::setSelectedPonts( const CurveCreator_Widget::SectionTo SectionToPoint aPoint; for ( ; anIt != aLast; anIt++ ) { aPoint = *anIt; - if ( thePoints.contains( aPoint ) ) + if ( contains( thePoints, aPoint ) ) aListToSelect.Append( anAIS ); } } @@ -1375,8 +1391,8 @@ void CurveCreator_Widget::startCurveModification( void CurveCreator_Widget::finishCurveModification( const CurveCreator_Widget::SectionToPointList& thePoints ) { - setLocalPointContext( true ); - int aSectionId = 0; + if ( getActionMode() == ModificationMode ) + setLocalPointContext( true ); setSelectedPonts( thePoints ); } @@ -1412,9 +1428,30 @@ void CurveCreator_Widget::findSectionsToPoints( const double theX, const double aPointId = findLocalPointIndex( i, theX, theY ); if ( aPointId < 0 ) continue; - SectionToPoint aPoint = qMakePair( i, aPointId ); - if ( !thePoints.contains( aPoint ) ) - thePoints.append( aPoint ); + SectionToPoint aPoint = std::make_pair( i, aPointId ); + if ( !contains( thePoints, aPoint ) ) + thePoints.push_back( aPoint ); + } +} + +void CurveCreator_Widget::convert( const SectionToPointList& thePoints, + QMap >& theConvPoints ) +{ + theConvPoints.clear(); + + SectionToPointList::const_iterator anIt = thePoints.begin(), aLast = thePoints.end(); + QList aPoints; + int aSectionId, aPointId; + for ( ; anIt != aLast; anIt++ ) { + aSectionId = anIt->first; + aPointId = anIt->second; + aPoints.clear(); + if ( theConvPoints.contains( aSectionId ) ) + aPoints = theConvPoints[aSectionId]; + if ( aPoints.contains( aPointId ) ) + continue; + aPoints.append( aPointId ); + theConvPoints[aSectionId] = aPoints; } } @@ -1495,12 +1532,8 @@ bool CurveCreator_Widget::pointOnObject( Handle(AIS_InteractiveObject) theObject } if ( isFound ) { thePoint = aPoint; - thePoint1 = aPnt1; thePoint2 = aPnt2; - //thePoint1 = findLocalPointIndex( 0, aPnt1.X(), aPnt1.Y() ); - //thePoint2 = findLocalPointIndex( 0, aPnt2.X(), aPnt2.Y() ); - //isFound = thePoint1 >= 0 && thePoint2 >= 0; } return isFound; } @@ -1561,3 +1594,20 @@ int CurveCreator_Widget::getPointId( const int theRowId ) const { return myLocalPointView->item( theRowId, 1 )->data( Qt::UserRole ).toInt(); } + +/** + * Returns whethe the container has the value + * \param theList a container of values + * \param theValue a value + */ +bool CurveCreator_Widget::contains( const CurveCreator_Widget::SectionToPointList& theList, + const CurveCreator_Widget::SectionToPoint& theValue ) const +{ + bool isFound = false; + + SectionToPointList::const_iterator anIt = theList.begin(), aLast = theList.end(); + for ( ; anIt != aLast && !isFound; anIt++ ) + isFound = anIt->first == theValue.first && anIt->second == theValue.second; + + return isFound; +}