From 19be9767fcf937a1c52f52733bfcb4de1fb4c864 Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Thu, 24 Dec 2020 07:27:32 +0100 Subject: [PATCH] Sketcher: Fix block constraint with several dependency groups ============================================================= Fixes: https://forum.freecadweb.org/viewtopic.php?f=8&t=53466&p=460513#p460270 When a parameter belonging to a blocked geometry is present in several dependency groups and there are other fixed parameters one or more of the dependency groups, it is not enough to remove that parameter, from the one or more dependency groups. The removal of a parameter may only satisfy one dependency group. Removing a single parameter creates a new different dependency group. Solution: If the first blocked parameter in a group is already set for removal, continue searching for other blocked parameters, until one not searched for removal is found. --- src/Mod/Sketcher/App/Sketch.cpp | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/Mod/Sketcher/App/Sketch.cpp b/src/Mod/Sketcher/App/Sketch.cpp index 27f9d1e16c..0a3fe6a213 100644 --- a/src/Mod/Sketcher/App/Sketch.cpp +++ b/src/Mod/Sketcher/App/Sketch.cpp @@ -62,8 +62,8 @@ #include "Sketch.h" -#define DEBUG_BLOCK_CONSTRAINT -//#undef DEBUG_BLOCK_CONSTRAINT +//#define DEBUG_BLOCK_CONSTRAINT +#undef DEBUG_BLOCK_CONSTRAINT using namespace Sketcher; using namespace Base; @@ -265,17 +265,25 @@ int Sketch::setUpSketch(const std::vector &GeoList, auto blocked = std::find(blockedGeoIds.begin(),blockedGeoIds.end(),element->second.first); - if( blocked != blockedGeoIds.end()) { // this dependent parameter group contains a parameter that should be blocked - params_to_block.push_back(thisparam); + if( blocked != blockedGeoIds.end()) { + // This dependent parameter group contains a parameter that should be blocked. + // + // One parameter per group is enough to fix the group, but it must be a different one for each group or + // it will create a different dependency group + auto already_in = std::find(params_to_block.begin(),params_to_block.end(), thisparam); + + if( already_in == params_to_block.end()) { + params_to_block.push_back(thisparam); #ifdef DEBUG_BLOCK_CONSTRAINT - Base::Console().Log("\nBlocking: Param=%x ,GeoId=%d, GeoPos=%d", - element->first, - element->second.first, - element->second.second); + Base::Console().Log("\nBlocking: Param=%x ,GeoId=%d, GeoPos=%d", + element->first, + element->second.first, + element->second.second); #endif //DEBUG_BLOCK_CONSTRAINT - break; // one parameter per group is enough to fix the group + break; + } } } }