diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp index ba51a70b3..b67b4ab4b 100644 --- a/src/Mod/Sketcher/App/SketchObject.cpp +++ b/src/Mod/Sketcher/App/SketchObject.cpp @@ -3205,17 +3205,30 @@ bool SketchObject::arePointsCoincident(int GeoId1, PointPos PosId1, { if (GeoId1 == GeoId2 && PosId1 == PosId2) return true; - - const std::vector &constraints = this->Constraints.getValues(); - for (std::vector::const_iterator it=constraints.begin(); - it != constraints.end(); ++it) { - if ((*it)->Type == Sketcher::Coincident) - if (((*it)->First == GeoId1 && (*it)->FirstPos == PosId1 && - (*it)->Second == GeoId2 && (*it)->SecondPos == PosId2) || - ((*it)->First == GeoId2 && (*it)->FirstPos == PosId2 && - (*it)->Second == GeoId1 && (*it)->SecondPos == PosId1)) - return true; + + const std::vector< std::map > coincidenttree = getCoincidenceGroups(); + + for(std::vector< std::map >::const_iterator it = coincidenttree.begin(); it != coincidenttree.end(); ++it) { + + std::map::const_iterator geoId1iterator; + + geoId1iterator = (*it).find(GeoId1); + + if( geoId1iterator != (*it).end()) { + // If First is in this set + std::map::const_iterator geoId2iterator; + + geoId2iterator = (*it).find(GeoId2); + + if( geoId2iterator != (*it).end()) { + // If Second is in this set + if ((*geoId1iterator).second == PosId1 && + (*geoId2iterator).second == PosId2) + return true; + } + } } + return false; } diff --git a/src/Mod/Sketcher/Gui/CommandConstraints.cpp b/src/Mod/Sketcher/Gui/CommandConstraints.cpp index e3a593fd3..789f1e0d4 100644 --- a/src/Mod/Sketcher/Gui/CommandConstraints.cpp +++ b/src/Mod/Sketcher/Gui/CommandConstraints.cpp @@ -862,7 +862,6 @@ void CmdSketcherConstrainCoincident::activated(int iMsg) // get the needed lists and objects const std::vector &SubNames = selection[0].getSubNames(); Sketcher::SketchObject* Obj = dynamic_cast(selection[0].getObject()); - const std::vector< Sketcher::Constraint * > &vals = Obj->Constraints.getValues(); if (SubNames.size() < 2) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), @@ -891,19 +890,8 @@ void CmdSketcherConstrainCoincident::activated(int iMsg) for (std::size_t i=1; i::const_iterator it= vals.begin(); it != vals.end(); ++it) { - if ((*it)->Type == Sketcher::Coincident && ( - ((*it)->First == GeoId1 && (*it)->FirstPos == PosId1 && - (*it)->Second == GeoId2 && (*it)->SecondPos == PosId2 ) || - ((*it)->First == GeoId2 && (*it)->FirstPos == PosId2 && - (*it)->Second == GeoId1 && (*it)->SecondPos == PosId1 ) ) ) { - constraintExists=true; - break; - } - } + // check if this coincidence is already enforced (even indirectly) + bool constraintExists=Obj->arePointsCoincident(GeoId1,PosId1,GeoId2,PosId2); if (!constraintExists) { constraintsAdded = true;