X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDROCurveCreator%2FCurveCreator_Widget.cxx;h=3cf3975e1ea1cb802678b31ea8431805548cf452;hb=db854002cff78b7b6eb6340b70990e5a6ddf56bf;hp=5df7014e834f9399a68e66b8e35f477818c4b016;hpb=250cc05073a53b76e9636df07bb6dace89a1e094;p=modules%2Fhydro.git diff --git a/src/HYDROCurveCreator/CurveCreator_Widget.cxx b/src/HYDROCurveCreator/CurveCreator_Widget.cxx index 5df7014e..3cf3975e 100644 --- a/src/HYDROCurveCreator/CurveCreator_Widget.cxx +++ b/src/HYDROCurveCreator/CurveCreator_Widget.cxx @@ -75,6 +75,8 @@ const int POINT_INDEX_COLUMN_WIDTH = 40; const int SCENE_PIXEL_TOLERANCE = 10; +//#define USE_SEVERAL_POINTS + CurveCreator_Widget::CurveCreator_Widget(QWidget* parent, CurveCreator_ICurve *theCurve, Qt::WindowFlags fl) @@ -292,6 +294,8 @@ void CurveCreator_Widget::onSelectionChanged() QList anEnabledAct; if( myCurve ){ anEnabledAct << NEW_SECTION_ID << MODIFICATION_MODE_ID; + if ( removeEnabled() ) + anEnabledAct << REMOVE_ID; QList aSelSections = mySectionView->getSelectedSections(); QList< QPair< int, int > > aSelPoints = mySectionView->getSelectedPoints(); CurveCreator_TreeView::SelectionType aSelType = mySectionView->getSelectionType(); @@ -305,7 +309,6 @@ void CurveCreator_Widget::onSelectionChanged() }*/ if( aSelSections.size() == 1 ){ anEnabledAct << ADDITION_MODE_ID << DETECTION_MODE_ID; - anEnabledAct << REMOVE_ID; } switch ( getActionMode() ) { case AdditionMode: { @@ -730,7 +733,11 @@ void CurveCreator_Widget::onUndo() { if( !myCurve ) return; + + CurveCreator_Widget::SectionToPointList aPoints; + startCurveModification( aPoints, false ); myCurve->undo(); + finishCurveModification(); mySectionView->reset(); updateUndoRedo(); } @@ -739,7 +746,10 @@ void CurveCreator_Widget::onRedo() { if( !myCurve ) return; + CurveCreator_Widget::SectionToPointList aPoints; + startCurveModification( aPoints, false ); myCurve->redo(); + finishCurveModification(); mySectionView->reset(); updateUndoRedo(); } @@ -817,6 +827,30 @@ QList< QPair< int, int > > CurveCreator_Widget::getSelectedPoints() return mySectionView->getSelectedPoints(); } +/** + * According to the widget state, performs the remove action + */ +void CurveCreator_Widget::removeSelected() +{ + onRemove(); +} + +/** + * Checks whether there are some selection to be removed + */ +bool CurveCreator_Widget::removeEnabled() +{ + bool isEnabled = getActionMode() == ModificationMode; + if ( !isEnabled ) { + QList aSelSections = mySectionView->getSelectedSections(); + CurveCreator_TreeView::SelectionType aSelType = mySectionView->getSelectionType(); + isEnabled = aSelType == CurveCreator_TreeView::ST_SECTIONS && + aSelSections.size() == 1; + } + return isEnabled; +} + + //================================================================================= // function : GeometryGUI::onGetCoordsByClick() // purpose : Manage mouse press events in Additon mode @@ -992,6 +1026,9 @@ void CurveCreator_Widget::removePoint() SectionToPointList aSelPoints; startCurveModification( aSelPoints, false ); +#ifdef USE_SEVERAL_POINTS + myCurve->removeSeveralPoints( aPoints ); +#else // the points should be removed in a decreased order QMap > aConvPoints; convert( aPoints, aConvPoints ); @@ -1001,14 +1038,14 @@ void CurveCreator_Widget::removePoint() int aSectionId = anIt.key(); QList aSectionPoints = anIt.value(); - qSort( aPoints ); + qSort( aSectionPoints ); for( int i = aSectionPoints.size()-1; i >= 0; i-- ){ int aPntIndx = aSectionPoints[i]; myCurve->removePoint( aSectionId, aPntIndx ); mySectionView->pointsRemoved( aSectionId, aPntIndx ); } } - +#endif finishCurveModification( SectionToPointList() ); } @@ -1104,20 +1141,23 @@ void CurveCreator_Widget::moveSelectedPoints( const int theXPosition, double aXDelta = aStartPnt.X() - anEndPnt.X(); double anYDelta = aStartPnt.Y() - anEndPnt.Y(); - int aSectionId; - int aPointId; + CurveCreator_ICurve::SectionToPointCoordsList aCoordList; std::deque aChangedPos; SectionToPointList::const_iterator anIt = myDragPoints.begin(), aLast = myDragPoints.end(); for ( ; anIt != aLast; anIt++ ) { - aSectionId = anIt->first; - aPointId = anIt->second; - aChangedPos = myCurve->getPoint( aSectionId, aPointId ); + aChangedPos = myCurve->getPoint( anIt->first, anIt->second ); if ( aChangedPos.size() < 2 ) continue; aChangedPos[0] = aChangedPos[0] - aXDelta; aChangedPos[1] = aChangedPos[1] - anYDelta; - myCurve->setPoint( aSectionId, aPointId, aChangedPos ); +#ifndef USE_SEVERAL_POINTS + myCurve->setPoint( anIt->first, anIt->second, aChangedPos ); +#endif } +#ifdef USE_SEVERAL_POINTS + myCurve->setSeveralPoints( aCoordList ); +#endif + myDragged = true; finishCurveModification( myDragPoints ); } @@ -1234,9 +1274,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() ) @@ -1246,7 +1286,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 ); @@ -1304,7 +1344,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 ) @@ -1344,7 +1384,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 ); } } @@ -1382,8 +1422,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 ); } @@ -1419,9 +1459,9 @@ 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 ); } } @@ -1585,3 +1625,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; +}