X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchSolver%2FSketchSolver_ConstraintGroup.cpp;h=7c0bd37845879ea5df3015d550a1645a013eefdb;hb=a25996a80f13f4af8bd60a90edc3811bbbee3b2d;hp=944d4ce4b90a4f7082049a0559a8b3c64bb6aeee;hpb=c9770e53785962f70c0b1c10dcc03a23980048c9;p=modules%2Fshaper.git diff --git a/src/SketchSolver/SketchSolver_ConstraintGroup.cpp b/src/SketchSolver/SketchSolver_ConstraintGroup.cpp index 944d4ce4b..7c0bd3784 100644 --- a/src/SketchSolver/SketchSolver_ConstraintGroup.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintGroup.cpp @@ -203,47 +203,11 @@ bool SketchSolver_ConstraintGroup::changeConstraint( { // Several points may be coincident, it is not necessary to store all constraints between them. // Try to find sequence of coincident points which connects the points of new constraint - if (aConstrType == SLVS_C_POINTS_COINCIDENT) + if (aConstrType == SLVS_C_POINTS_COINCIDENT && + !addCoincidentPoints(aConstrEnt[0], aConstrEnt[1])) { - std::vector< std::set >::iterator aCoPtIter = myCoincidentPoints.begin(); - std::vector< std::set >::iterator aFirstFound = myCoincidentPoints.end(); - for ( ; aCoPtIter != myCoincidentPoints.end(); aCoPtIter++) - { - bool isFound[2] = { // indicate which point ID was already in coincidence constraint - aCoPtIter->find(aConstrEnt[0]) != aCoPtIter->end(), - aCoPtIter->find(aConstrEnt[1]) != aCoPtIter->end(), - }; - if (isFound[0] && isFound[1]) // points are already connected by coincidence constraints => no need additional one - { - myExtraCoincidence.insert(theConstraint); // the constraint is stored for further purposes - return false; - } - if ((isFound[0] && !isFound[1]) || (!isFound[0] && isFound[1])) - { - if (aFirstFound != myCoincidentPoints.end()) - { // there are two groups of coincident points connected by created constraint => merge them - int aFirstFoundShift = aFirstFound - myCoincidentPoints.begin(); - int aCurrentShift = aCoPtIter - myCoincidentPoints.begin(); - aFirstFound->insert(aCoPtIter->begin(), aCoPtIter->end()); - myCoincidentPoints.erase(aCoPtIter); - aFirstFound = myCoincidentPoints.begin() + aFirstFoundShift; - aCoPtIter = myCoincidentPoints.begin() + aCurrentShift; - } - else - { - aCoPtIter->insert(aConstrEnt[isFound[0] ? 1 : 0]); - aFirstFound = aCoPtIter; - } - } - } - // No points were found, need to create new set - if (aFirstFound == myCoincidentPoints.end()) - { - std::set aNewSet; - aNewSet.insert(aConstrEnt[0]); - aNewSet.insert(aConstrEnt[1]); - myCoincidentPoints.push_back(aNewSet); - } + myExtraCoincidence.insert(theConstraint); // the constraint is stored for further purposes + return false; } // Create SolveSpace constraint structure @@ -663,6 +627,7 @@ void SketchSolver_ConstraintGroup::splitGroup(std::vectorptA, aConstrIter->ptB, aConstrIter->entityA, aConstrIter->entityB}; + std::vector anIndexes; // Go through the groupped entities and find even one of entities of current constraint std::vector< std::set >::iterator aGrEntIter; for (aGrEntIter = aGroupsEntities.begin(); aGrEntIter != aGroupsEntities.end(); aGrEntIter++) @@ -672,18 +637,10 @@ void SketchSolver_ConstraintGroup::splitGroup(std::vectorfind(aConstrEnt[i]) != aGrEntIter->end()); if (isFound) - { - for (int i = 0; i < 4; i++) - if (aConstrEnt[i] != 0) - aGrEntIter->insert(aConstrEnt[i]); - aGroupsConstr[aGrEntIter - aGroupsEntities.begin()].insert(aConstrIter->h); - if (aGrEntIter->size() > aGroupsEntities[aMaxNbEntities].size()) - aMaxNbEntities = aGrEntIter - aGroupsEntities.begin(); - break; - } + anIndexes.push_back(aGrEntIter - aGroupsEntities.begin()); } // Add new group if no one is found - if (aGrEntIter == aGroupsEntities.end()) + if (anIndexes.empty()) { std::set aNewGrEnt; for (int i = 0; i < 4; i++) @@ -697,6 +654,37 @@ void SketchSolver_ConstraintGroup::splitGroup(std::vector aGroupsEntities[aMaxNbEntities].size()) aMaxNbEntities = aGroupsEntities.size() - 1; } + else if (anIndexes.size() == 1) + { // Add entities indexes into the found group + aGrEntIter = aGroupsEntities.begin() + anIndexes.front(); + for (int i = 0; i < 4; i++) + if (aConstrEnt[i] != 0) + aGrEntIter->insert(aConstrEnt[i]); + aGroupsConstr[anIndexes.front()].insert(aConstrIter->h); + if (aGrEntIter->size() > aGroupsEntities[aMaxNbEntities].size()) + aMaxNbEntities = aGrEntIter - aGroupsEntities.begin(); + } + else + { // There are found several connected groups, merge them + std::vector< std::set >::iterator aFirstGroup = + aGroupsEntities.begin() + anIndexes.front(); + std::vector< std::set >::iterator aFirstConstr = + aGroupsConstr.begin() + anIndexes.front(); + std::vector::iterator anInd = anIndexes.begin(); + for (++anInd; anInd != anIndexes.end(); anInd++) + { + aFirstGroup->insert(aGroupsEntities[*anInd].begin(), aGroupsEntities[*anInd].end()); + aFirstConstr->insert(aGroupsConstr[*anInd].begin(), aGroupsConstr[*anInd].end()); + } + if (aFirstGroup->size() > aGroupsEntities[aMaxNbEntities].size()) + aMaxNbEntities = anIndexes.front(); + // Remove merged groups + for (anInd = anIndexes.end() - 1; anInd != anIndexes.begin(); anInd--) + { + aGroupsEntities.erase(aGroupsEntities.begin() + (*anInd)); + aGroupsConstr.erase(aGroupsConstr.begin() + (*anInd)); + } + } } if (aGroupsEntities.size() <= 1) @@ -1048,6 +1036,58 @@ void SketchSolver_ConstraintGroup::removeConstraint(boost::shared_ptr >::iterator aCoPtIter = myCoincidentPoints.begin(); + std::vector< std::set >::iterator aFirstFound = myCoincidentPoints.end(); + while (aCoPtIter != myCoincidentPoints.end()) + { + bool isFound[2] = { // indicate which point ID was already in coincidence constraint + aCoPtIter->find(thePoint1) != aCoPtIter->end(), + aCoPtIter->find(thePoint2) != aCoPtIter->end(), + }; + if (isFound[0] && isFound[1]) // points are already connected by coincidence constraints => no need additional one + return false; + if ((isFound[0] && !isFound[1]) || (!isFound[0] && isFound[1])) + { + if (aFirstFound != myCoincidentPoints.end()) + { // there are two groups of coincident points connected by created constraint => merge them + int aFirstFoundShift = aFirstFound - myCoincidentPoints.begin(); + int aCurrentShift = aCoPtIter - myCoincidentPoints.begin(); + aFirstFound->insert(aCoPtIter->begin(), aCoPtIter->end()); + myCoincidentPoints.erase(aCoPtIter); + aFirstFound = myCoincidentPoints.begin() + aFirstFoundShift; + aCoPtIter = myCoincidentPoints.begin() + aCurrentShift; + continue; + } + else + { + aCoPtIter->insert(isFound[0] ? thePoint2 : thePoint1); + aFirstFound = aCoPtIter; + } + } + aCoPtIter++; + } + // No points were found, need to create new set + if (aFirstFound == myCoincidentPoints.end()) + { + std::set aNewSet; + aNewSet.insert(thePoint1); + aNewSet.insert(thePoint2); + myCoincidentPoints.push_back(aNewSet); + } + + return true; +} + + + // ======================================================== // ========= Auxiliary functions ===============