X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDROCurveCreator%2FCurveCreator_Curve.cxx;h=cccf4a20302532beeecfd8c54a4e79c9cc11cbc2;hb=e38481b5d965c3736d2c8eda39b1a30bd125147b;hp=51cf063e266a9aba11549e002ed9997ad5976529;hpb=820c913e913881f2581eedce5995579ef0ad12d0;p=modules%2Fhydro.git diff --git a/src/HYDROCurveCreator/CurveCreator_Curve.cxx b/src/HYDROCurveCreator/CurveCreator_Curve.cxx index 51cf063e..cccf4a20 100644 --- a/src/HYDROCurveCreator/CurveCreator_Curve.cxx +++ b/src/HYDROCurveCreator/CurveCreator_Curve.cxx @@ -23,6 +23,7 @@ #include "CurveCreator_Curve.hxx" #include "CurveCreator.hxx" +#include "CurveCreator_PosPoint.hxx" #include "CurveCreator_Section.hxx" #include "CurveCreator_Displayer.h" @@ -398,6 +399,25 @@ bool CurveCreator_Curve::moveSection(const int theISection, return res; } +void CurveCreator_Curve::convert( const SectionToPointList& thePoints, + std::map< int, std::list >& theConvPoints ) +{ + theConvPoints.clear(); + + SectionToPointList::const_iterator anIt = thePoints.begin(), aLast = thePoints.end(); + std::list aPoints; + int aSectionId, aPointId; + for ( ; anIt != aLast; anIt++ ) { + aSectionId = anIt->first; + aPointId = anIt->second; + aPoints.clear(); + if ( theConvPoints.find( aSectionId ) != theConvPoints.end() ) + aPoints = theConvPoints[aSectionId]; + aPoints.push_back( aPointId ); + theConvPoints[aSectionId] = aPoints; + } +} + /************ Implementation of INTERFACE methods ************/ /***********************************************/ @@ -500,12 +520,13 @@ bool CurveCreator_Curve::joinInternal( const int theISectionTo, return res; } -//! Join range of sections to one section (join all sections if -1 is passed in one of arguments) +//! Join range of sections to one section (join all sections if -1 is passed in theISectionFrom argument) bool CurveCreator_Curve::join( const int theISectionTo, const int theISectionFrom ) { + //TODO bool res = false; - if (theISectionTo != theISectionFrom) { + if ( theISectionTo != theISectionFrom ) { startOperation(); if (addEmptyDiff()) myListDiffs.back().init(this, CurveCreator_Operation::Join, theISectionTo, theISectionFrom); @@ -634,7 +655,8 @@ int CurveCreator_Curve::getNbPoints( const int theISection ) const aNbCoords += mySections[i]->myPoints.size(); } } else { - aNbCoords = mySections.at(theISection)->myPoints.size(); + if ( ( theISection >= 0 ) && ( theISection < mySections.size() ) ) + aNbCoords = mySections.at(theISection)->myPoints.size(); } return aNbCoords/myDimension; @@ -775,35 +797,35 @@ bool CurveCreator_Curve::setSectionType( const int theISection, /***********************************************/ //! For internal use only! Undo/Redo are not used here. -bool CurveCreator_Curve::addPointsInternal( const CurveCreator::Coordinates& theCoords, - const std::vector &theISections, - const std::vector &theIPnts ) +bool CurveCreator_Curve::addPointsInternal( const CurveCreator::SectionsMap &theSectionsMap ) { bool res = false; - if( (theCoords.size()/getDimension()) == theISections.size() == theIPnts.size() ) { - for( int ind = 0; ind < theISections.size(); ind++ ) { - int anISection = theISections.at(ind); - CurveCreator_Section *aSection = - (anISection == -1 ? mySections.back() : mySections.at(anISection)); - - if( aSection ) { - int anIPnt = theIPnts.at(ind); + CurveCreator::SectionsMap::const_iterator anIt = theSectionsMap.begin(); + CurveCreator_Section *aSection = 0; + for ( ; anIt != theSectionsMap.end(); anIt++ ) { + int anISection = anIt->first; + aSection = mySections.at(anISection); + if( aSection ) { + CurveCreator::PosPointsList aSectionPoints = anIt->second; + CurveCreator::PosPointsList::const_iterator aPntIt = aSectionPoints.begin(); + for( ; aPntIt != aSectionPoints.end(); aPntIt++ ){ + int anIPnt = (*aPntIt)->myID; + CurveCreator::Coordinates aCoords = (*aPntIt)->myCoords; CurveCreator::Coordinates::iterator anIterPosition; if(anIPnt == -1) anIterPosition = aSection->myPoints.end(); else anIterPosition = aSection->myPoints.begin() + toICoord(anIPnt); CurveCreator::Coordinates::const_iterator aFirstPosition = - theCoords.begin() + toICoord(ind); + aCoords.begin(); aSection->myPoints.insert(anIterPosition, - aFirstPosition, - aFirstPosition + getDimension()); - res = true; + aCoords.begin(), aCoords.end()); } + res = true; } - if(res) - redisplayCurve(); } + if(res) + redisplayCurve(); return res; } @@ -820,34 +842,48 @@ bool CurveCreator_Curve::addPoints( const CurveCreator::Coordinates& theCoords, // Set the difference. startOperation(); if (addEmptyDiff()) { + CurveCreator_ICurve::SectionToPointCoordsList aList; + aList.push_back(std::make_pair(std::make_pair(theISection, theIPnt), theCoords)); myListDiffs.back().init(this, CurveCreator_Operation::InsertPoints, - theCoords, theISection, theIPnt); + aList); } - std::vector anISections, anIPnts; - anISections.push_back( theISection ); - anIPnts.push_back( theIPnt ); - res = addPointsInternal( theCoords, anISections, anIPnts ); + CurveCreator::SectionsMap aSectionsMap; + CurveCreator::PosPointsList aPoints; + CurveCreator_PosPoint* aPosPoint = new CurveCreator_PosPoint( theIPnt, theCoords ); + aPoints.push_back( aPosPoint ); + aSectionsMap[theISection] = aPoints; + + res = addPointsInternal( aSectionsMap ); + finishOperation(); return res; } //! For internal use only! Undo/Redo are not used here. -bool CurveCreator_Curve::setPointInternal( const int theISection, - const int theIPnt, - const CurveCreator::Coordinates& theNewCoords ) +bool CurveCreator_Curve::setPointInternal( const CurveCreator::SectionsMap &theSectionsMap ) { bool res = false; // Update the curve. - if (theNewCoords.size() == myDimension) { - CurveCreator_Section *aSection = mySections.at(theISection); - int i; - for (i = 0; i < myDimension; i++) { - aSection->myPoints.at(toICoord(theIPnt) + i) = theNewCoords[i]; + CurveCreator::SectionsMap::const_iterator anIt = theSectionsMap.begin(); + CurveCreator_Section *aSection = 0; + for ( ; anIt != theSectionsMap.end(); anIt++ ) { + int anISection = anIt->first; + aSection = mySections.at(anISection); + if( aSection ) { + CurveCreator::PosPointsList aSectionPoints = anIt->second; + CurveCreator::PosPointsList::const_iterator aPntIt = aSectionPoints.begin(); + for( ; aPntIt != aSectionPoints.end(); aPntIt++ ){ + int anIPnt = (*aPntIt)->myID; + CurveCreator::Coordinates aCoords = (*aPntIt)->myCoords; + for ( int i = 0; i < myDimension; i++) + aSection->myPoints.at(toICoord(anIPnt) + i) = aCoords[i]; + } + res = true; } - redisplayCurve(); - - res = true; } + if(res) + redisplayCurve(); + return res; } @@ -860,10 +896,21 @@ bool CurveCreator_Curve::setPoint( const int theISection, // Set the difference. startOperation(); if (addEmptyDiff()) { + CurveCreator_ICurve::SectionToPointCoordsList aList; + aList.push_back(std::make_pair(std::make_pair(theISection, theIPnt), theNewCoords)); myListDiffs.back().init(this, CurveCreator_Operation::SetCoordinates, - theNewCoords, theISection, theIPnt); + aList); } - res = setPointInternal( theISection, theIPnt, theNewCoords ); + CurveCreator::SectionsMap aSectionsMap; + CurveCreator::PosPointsList aPoints; + CurveCreator_PosPoint* aPosPoint = new CurveCreator_PosPoint( theIPnt, theNewCoords ); + aPoints.push_back( aPosPoint ); + aSectionsMap[theISection] = aPoints; + + int aSize1 = getNbPoints( theISection ); + res = setPointInternal( aSectionsMap ); + int aSize2 = getNbPoints( theISection ); + finishOperation(); return res; @@ -872,32 +919,67 @@ bool CurveCreator_Curve::setPoint( const int theISection, //! Set coordinates of specified points from different sections bool CurveCreator_Curve::setSeveralPoints( const SectionToPointCoordsList &theSectionToPntCoords) { - return false; + bool res = false; + // Set the difference. + startOperation(); + if (addEmptyDiff()) { + myListDiffs.back().init(this, CurveCreator_Operation::SetCoordinates, + theSectionToPntCoords); + } + CurveCreator::SectionsMap aSectionsMap; + CurveCreator::PosPointsList aPosPoints; + CurveCreator_ICurve::SectionToPointCoordsList::const_iterator anIt = + theSectionToPntCoords.begin(), aLast = theSectionToPntCoords.end(); + int aSectionId, aPointId; + for ( ; anIt != aLast; anIt++ ) { + aPosPoints.clear(); + aSectionId = anIt->first.first; + aPointId = anIt->first.second; + CurveCreator::Coordinates aNewCoords = anIt->second; + CurveCreator_PosPoint* aPosPoint = + new CurveCreator_PosPoint( aPointId, aNewCoords ); + if( aSectionsMap.find(aSectionId) != aSectionsMap.end() ) + aPosPoints = aSectionsMap[aSectionId]; + aPosPoints.push_back( aPosPoint ); + aSectionsMap[aSectionId] = aPosPoints; + + } + res = setPointInternal( aSectionsMap ); + finishOperation(); + + return res; } //! For internal use only! Undo/Redo are not used here. -bool CurveCreator_Curve::removePointsInternal( const std::vector &theISections, - const std::vector &theIPnts ) +bool CurveCreator_Curve::removePointsInternal( const SectionToPointList &thePoints ) { bool res = false; - if( theISections.size() == theIPnts.size() ) { - for( int ind = 0; ind < theISections.size(); ind++ ) { - int anISection = theISections.at(ind); - CurveCreator_Section *aSection = mySections.at(anISection); - if( aSection ) { - int anIPnt = theIPnts.at(ind); + std::map > aConvPoints; + convert( thePoints, aConvPoints ); + std::map >::const_iterator anIt = aConvPoints.begin(), + aLast = aConvPoints.end(); + CurveCreator_Section *aSection = 0; + for ( ; anIt != aLast; anIt++ ) { + int aSectionId = anIt->first; + aSection = mySections.at(aSectionId); + if( aSection ) { + std::list aSectionPoints = anIt->second; + aSectionPoints.sort(); + std::list::const_reverse_iterator aPntIt = aSectionPoints.rbegin(); + for( ; aPntIt != aSectionPoints.rend(); aPntIt++ ){ + int aPntIndx = *aPntIt; CurveCreator::Coordinates::iterator aFirstPosition; - if(anIPnt == -1) - aFirstPosition = aSection->myPoints.end(); + if(aPntIndx == -1) + aFirstPosition = aSection->myPoints.end() - getDimension(); else - aFirstPosition = aSection->myPoints.begin() + toICoord(anIPnt); + aFirstPosition = aSection->myPoints.begin() + toICoord(aPntIndx); aSection->myPoints.erase( aFirstPosition, aFirstPosition + getDimension() ); res = true; } } - if(res) - redisplayCurve(); } + if(res) + redisplayCurve(); return res; } @@ -911,10 +993,9 @@ bool CurveCreator_Curve::removePoint( const int theISection, const int theIPnt ) myListDiffs.back().init(this, CurveCreator_Operation::RemovePoints, theISection, theIPnt); } - std::vector anISections, anIPnts; - anISections.push_back( theISection ); - anIPnts.push_back( theIPnt ); - res = removePointsInternal( anISections, anIPnts ); + SectionToPointList aListOfSectionsToPoints; + aListOfSectionsToPoints.push_back(std::make_pair(theISection, theIPnt)); + res = removePointsInternal( aListOfSectionsToPoints ); finishOperation(); return res; } @@ -922,7 +1003,16 @@ bool CurveCreator_Curve::removePoint( const int theISection, const int theIPnt ) //! Remove several points from different sections with given ids bool CurveCreator_Curve::removeSeveralPoints( const SectionToPointList &theSectionToPntIDs) { - return false; + bool res = false; + // Set the difference. + startOperation(); + if (addEmptyDiff()) { + myListDiffs.back().init(this, CurveCreator_Operation::RemovePoints, + theSectionToPntIDs); + } + res = removePointsInternal( theSectionToPntIDs ); + finishOperation(); + return res; } //======================================================================= @@ -946,7 +1036,12 @@ CurveCreator::Coordinates CurveCreator_Curve::getPoint( const int theISection, //======================================================================= CurveCreator::Coordinates CurveCreator_Curve::getPoints( const int theISection ) const { - return mySections.at(theISection)->myPoints; + CurveCreator::Coordinates aCoords; + if ( ( theISection >= 0 ) && ( theISection < mySections.size() ) ) + { + aCoords = mySections.at(theISection)->myPoints; + } + return aCoords; }