From 541155349f356778af7b8e044143ee7d5b9bab3d Mon Sep 17 00:00:00 2001 From: azv Date: Wed, 17 May 2017 17:40:17 +0300 Subject: [PATCH] Fix processing multiply point-point coincidences (fix for the model test cases) --- .../PlaneGCSSolver_UpdateCoincidence.cpp | 37 ++++++++++++------- .../PlaneGCSSolver_UpdateCoincidence.h | 3 ++ test.models/gear.py | 2 + 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_UpdateCoincidence.cpp b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_UpdateCoincidence.cpp index bad62522a..b44881bf8 100644 --- a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_UpdateCoincidence.cpp +++ b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_UpdateCoincidence.cpp @@ -13,6 +13,10 @@ #include #include +static bool hasSamePoint(const std::set& theList, + const EntityWrapperPtr& thePoint); + + void PlaneGCSSolver_UpdateCoincidence::attach(SketchSolver_Constraint* theObserver, const std::string& theType) { @@ -72,17 +76,21 @@ bool PlaneGCSSolver_UpdateCoincidence::addCoincidence( } else if (aFound[0] == aFound[1]) { // same group => already coincident isAccepted = false; } else { // merge two groups - EntityWrapperPtr anEntityToAdd = theEntity1; - if (theEntity1->isExternal()) { // swap found groups; - anEntityToAdd = theEntity2; - std::list::iterator aTempIt = aFound[0]; - aFound[0] = aFound[1]; - aFound[1] = aTempIt; + // first check the external points are equal + EntityWrapperPtr anExternal0 = aFound[0]->externalPoint(); + EntityWrapperPtr anExternal1 = aFound[1]->externalPoint(); + if (anExternal0 && anExternal1) { + std::set anExtList; + anExtList.insert(anExternal0); + if (hasSamePoint(anExtList, anExternal1)) { + // no need to add coincidence, because all points are + // already coincident to correct external points + isAccepted = false; + } } - aFound[1]->remove(anEntityToAdd); + // merge aFound[0]->merge(*aFound[1]); - isAccepted = aFound[0]->add(anEntityToAdd); myCoincident.erase(aFound[1]); } @@ -126,9 +134,7 @@ bool PlaneGCSSolver_UpdateCoincidence::addToGroupOfCoincidence( { if (theGroup.isExist(theEntity)) return false; - - theGroup.add(theEntity); - return true; + return theGroup.add(theEntity); } @@ -157,8 +163,8 @@ static bool hasSamePoint(const std::set& theList, const GCS::P return false; } -static bool hasSamePoint(const std::set& theList, - const EntityWrapperPtr& thePoint) +bool hasSamePoint(const std::set& theList, + const EntityWrapperPtr& thePoint) { return hasSamePoint(theList, toPoint(thePoint)); } @@ -225,3 +231,8 @@ bool PlaneGCSSolver_UpdateCoincidence::CoincidentEntities::isExist( { return hasSamePoint(myExternalPoints, thePoint) || hasSamePoint(myPoints, thePoint); } + +EntityWrapperPtr PlaneGCSSolver_UpdateCoincidence::CoincidentEntities::externalPoint() const +{ + return myExternalPoints.empty() ? EntityWrapperPtr() : *myExternalPoints.begin(); +} diff --git a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_UpdateCoincidence.h b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_UpdateCoincidence.h index d5acf494a..20ce3425a 100644 --- a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_UpdateCoincidence.h +++ b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_UpdateCoincidence.h @@ -73,6 +73,9 @@ private: /// Merge two groups void merge(const CoincidentEntities& theOther); + /// Returns any of external points + EntityWrapperPtr externalPoint() const; + private: std::set myPoints; ///< coincident points std::set myExternalPoints; //< external points coincident to other points diff --git a/test.models/gear.py b/test.models/gear.py index 5d3a6d31b..f49e7960d 100644 --- a/test.models/gear.py +++ b/test.models/gear.py @@ -145,6 +145,7 @@ SketchConstraintLength_10 = Sketch_3.setLength(SketchLine_83.result(), "2*R_fill model.do() Revolution_1 = model.addRevolution(Part_1_doc, [model.selection("FACE", "PartSet/Sketch_1")], model.selection("EDGE", "PartSet/Sketch_1/Edge-SketchLine_1"), 360, 0) Sketch_4 = model.addSketch(Part_1_doc, model.selection("FACE", "Revolution_1_1/Generated_Face_5")) +SketchPoint_4 = Sketch_4.addPoint(model.selection("VERTEX", "PartSet/Origin")) SketchLine_86 = Sketch_4.addLine(0, -13.49999999999519, 3.1, -13.49999999999519) SketchLine_87 = Sketch_4.addLine(model.selection("EDGE", "PartSet/OZ")) SketchConstraintCoincidence_51 = Sketch_4.setCoincident(SketchLine_86.startPoint(), SketchLine_87.result()) @@ -160,6 +161,7 @@ SketchConstraintLength_9 = Sketch_4.setLength(SketchLine_86.result(), 3.1) SketchConstraintMirror_2 = Sketch_4.addMirror(SketchLine_87.result(), [SketchLine_86.result(), SketchLine_88.result()]) [SketchLine_90, SketchLine_91] = SketchConstraintMirror_2.mirrored() SketchArc_62 = Sketch_4.addArc(0, 0, 3.1, -10.55414610473955, -3.100000000000001, -10.55414610473344, False) +SketchConstraintCoincidence_54 = Sketch_4.setCoincident(SketchPoint_4.coordinates(), SketchArc_62.center()) SketchConstraintCoincidence_55 = Sketch_4.setCoincident(SketchLine_87.startPoint(), SketchArc_62.center()) SketchConstraintCoincidence_56 = Sketch_4.setCoincident(SketchArc_62.startPoint(), SketchLine_88.result()) SketchConstraintCoincidence_57 = Sketch_4.setCoincident(SketchArc_62.endPoint(), SketchLine_91.result()) -- 2.39.2