X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDROCurveCreator%2FCurveCreator_Operation.cxx;h=083e3323084fd1612fbea969b0042bf9f8b6f2d8;hb=1e9be94cc5ff4ad886099c507462d5b70f6d71f9;hp=7e87af79fd0e1e302d0d2c96609fe8d61bd0f3a3;hpb=2686c62a9139e3b8f81549e62063500ca52a8163;p=modules%2Fhydro.git diff --git a/src/HYDROCurveCreator/CurveCreator_Operation.cxx b/src/HYDROCurveCreator/CurveCreator_Operation.cxx index 7e87af79..083e3323 100644 --- a/src/HYDROCurveCreator/CurveCreator_Operation.cxx +++ b/src/HYDROCurveCreator/CurveCreator_Operation.cxx @@ -22,6 +22,7 @@ #include "CurveCreator_Operation.hxx" #include "CurveCreator_Curve.hxx" +#include "CurveCreator.hxx" #include #include @@ -46,6 +47,11 @@ CurveCreator_Operation::~CurveCreator_Operation() clear(); } +bool compId(CurveCreator_PosPoint* p1, CurveCreator_PosPoint* p2) +{ + return p1->myID < p2->myID; +} + //======================================================================= // function: Constructor // purpose: @@ -167,43 +173,6 @@ bool CurveCreator_Operation::init(const CurveCreator_Operation::Type theType, return isOK; } -//======================================================================= -// function: Constructor -// purpose: -//======================================================================= -bool CurveCreator_Operation::init(const CurveCreator_Operation::Type theType, - const CurveCreator::Coordinates &theCoords, - const int theIntParam1, - const int theIntParam2) -{ - bool isOK = false; - - if (theType == CurveCreator_Operation::AddSection || - theType == CurveCreator_Operation::InsertPoints || - theType == CurveCreator_Operation::SetCoordinates) { - const int aNbCoords = theCoords.size(); - const size_t aSize = - 3*sizeof(theIntParam1) + aNbCoords*sizeof(CurveCreator::TypeCoord); - int *pIntData = (int *)allocate(aSize); - - *pIntData++ = theIntParam1; - *pIntData++ = theIntParam2; - *pIntData++ = aNbCoords; - - CurveCreator::TypeCoord *pRealData = (CurveCreator::TypeCoord *)pIntData; - int i = 0; - - for (; i < aNbCoords; i++) { - *pRealData++ = theCoords[i]; - } - - myType = theType; - isOK = true; - } - - return isOK; -} - //======================================================================= // function: Constructor // purpose: @@ -235,7 +204,7 @@ bool CurveCreator_Operation::init(const CurveCreator_Operation::Type theType, pIntData = (int*)aStrPtr; *pIntData++ = aNbCoords; - CurveCreator::TypeCoord *pRealData = (CurveCreator::TypeCoord *)aStrPtr; + CurveCreator::TypeCoord *pRealData = (CurveCreator::TypeCoord *)pIntData; int i = 0; for (; i < aNbCoords; i++) { @@ -270,6 +239,84 @@ bool CurveCreator_Operation::init(const CurveCreator_Operation::Type theType, return false; } +bool CurveCreator_Operation::init(const CurveCreator_Operation::Type theType, + const CurveCreator_ICurve::SectionToPointCoordsList &theParamList1) +{ + bool isOK = false; + + if (theType == CurveCreator_Operation::InsertPoints || + theType == CurveCreator_Operation::SetCoordinates ) { + + const int aNbPoints = theParamList1.size(); + + CurveCreator_ICurve::SectionToPointCoordsList::const_iterator anIt = + theParamList1.begin(); + const int aNbCoords = anIt->second.size(); + + const size_t aSize = + sizeof(aNbPoints) + sizeof(aNbCoords) + + aNbPoints * (3*sizeof(int) + aNbCoords*sizeof(CurveCreator::TypeCoord)); + int *pIntData = (int *)allocate(aSize); + + *pIntData++ = aNbPoints; + *pIntData++ = aNbCoords; + int aSectionId, aPointId; + for ( ; anIt != theParamList1.end(); anIt++ ) { + aSectionId = anIt->first.first; + aPointId = anIt->first.second; + + *pIntData++ = aSectionId; + *pIntData++ = aPointId; + *pIntData++ = aNbCoords; + + const CurveCreator::Coordinates &aCoords = anIt->second; + CurveCreator::TypeCoord *pRealData = (CurveCreator::TypeCoord *)pIntData; + for (int i = 0; i < aNbCoords; i++) { + *pRealData++ = aCoords[i]; + } + pIntData = (int *)pRealData; + } + + myType = theType; + isOK = true; + } + + return isOK; +} + +bool CurveCreator_Operation::init(const CurveCreator_Operation::Type theType, + const CurveCreator_ICurve::SectionToPointList &theParamList1) +{ + bool isOK = false; + + if (theType == CurveCreator_Operation::RemovePoints) { + const int aNbPoints = theParamList1.size(); + + CurveCreator_ICurve::SectionToPointList::const_iterator anIt = + theParamList1.begin(); + + const size_t aSize = + sizeof(aNbPoints) + + aNbPoints * (2*sizeof(int)); + int *pIntData = (int *)allocate(aSize); + + *pIntData++ = aNbPoints; + int aSectionId, aPointId; + for ( ; anIt != theParamList1.end(); anIt++ ) { + aSectionId = anIt->first; + aPointId = anIt->second; + + *pIntData++ = aSectionId; + *pIntData++ = aPointId; + } + + myType = theType; + isOK = true; + } + + return isOK; +} + //======================================================================= // function: apply // purpose: @@ -282,22 +329,48 @@ void CurveCreator_Operation::apply(CurveCreator_Curve *theCurve) switch (myType) { case CurveCreator_Operation::AddPoints: case CurveCreator_Operation::InsertPoints: + case CurveCreator_Operation::SetCoordinates: { + int aSectionId, aPointId; + CurveCreator::SectionsMap aSectionsMap; + CurveCreator::PosPointsList aPoints; CurveCreator::Coordinates aCoords; - getCoords(&pInt[2], aCoords); - std::vector anISections, anIPnts; - anISections.push_back( pInt[0] ); - anIPnts.push_back( pInt[1] ); - theCurve->addPointsInternal(aCoords, anISections, anIPnts); + int nbPoints = pInt[0]; + int nbCoords = pInt[1]; + int nbParams = 3+nbCoords; + for (int i = 0; i < nbPoints*nbParams; i=i+nbParams) { + aCoords.clear(); + aPoints.clear(); + getCoords(&pInt[4+i], aCoords); + aSectionId = pInt[2+i]; + aPointId = pInt[3+i]; + if ( aSectionsMap.find( aSectionId ) != aSectionsMap.end() ) + aPoints = aSectionsMap[aSectionId]; + CurveCreator_PosPoint* aPosPoint = new CurveCreator_PosPoint( aPointId, aCoords ); + aPoints.push_back( aPosPoint ); + aPoints.sort(compId); + aSectionsMap[aSectionId] = aPoints; + } + switch (myType) { + case CurveCreator_Operation::AddPoints: + case CurveCreator_Operation::InsertPoints: + theCurve->addPointsInternal( aSectionsMap ); + break; + case CurveCreator_Operation::SetCoordinates: + theCurve->setPointInternal( aSectionsMap ); + break; + } } break; case CurveCreator_Operation::RemovePoints: { - std::vector anISections, anIPnts; - anISections.push_back( pInt[0] ); - anIPnts.push_back( pInt[1] ); - theCurve->removePointsInternal(anISections, anIPnts); + CurveCreator_ICurve::SectionToPointList aListOfSectionsToPoints; + int nbPoints = pInt[0]; + for (int i = 1; i < nbPoints*2; i=i+2) { + aListOfSectionsToPoints.push_back(std::make_pair(pInt[i], pInt[i+1])); + } + theCurve->removePointsInternal(aListOfSectionsToPoints); } break; case CurveCreator_Operation::SetType: @@ -310,16 +383,11 @@ void CurveCreator_Operation::apply(CurveCreator_Curve *theCurve) case CurveCreator_Operation::Clear: theCurve->clearInternal(); break; - case CurveCreator_Operation::SetCoordinates: - { - CurveCreator::Coordinates aCoords; - - getCoords(&pInt[2], aCoords); - theCurve->setPointInternal(pInt[0], pInt[1], aCoords); - } - break; case CurveCreator_Operation::SetClosed: - theCurve->setClosedInternal((pInt[0] != 0), pInt[1]); + theCurve->setClosedInternal(pInt[1], (pInt[0] != 0)); + break; + case CurveCreator_Operation::MoveSection: + theCurve->moveSectionInternal(pInt[0], pInt[1]); break; case CurveCreator_Operation::Join: if (myPData == NULL) {