Skip to content

Commit

Permalink
[Sketcher] Changes to drawing of constraint icons.
Browse files Browse the repository at this point in the history
* Change the formula to calculate maximum distance for merging of constraint icons.
* Ignore z coordinate while calculating the distance between icons. It is irrelevant but can slightly differ between icons.
* Choose first icon from the group of nearby icons as a location of the composite icon, instead of choosing icon closest to the average position. Fixes jittering of the icon while one of the constraints is moved.
  • Loading branch information
Neinei0k authored and wwmayer committed Oct 15, 2020
1 parent d752991 commit 71236cb
Showing 1 changed file with 7 additions and 22 deletions.
29 changes: 7 additions & 22 deletions src/Mod/Sketcher/Gui/ViewProviderSketch.cpp
Expand Up @@ -3198,8 +3198,7 @@ void ViewProviderSketch::drawConstraintIcons()
void ViewProviderSketch::combineConstraintIcons(IconQueue iconQueue)
{
// getScaleFactor gives us a ratio of pixels per some kind of real units
// (Translation: this number is somewhat made-up.)
float maxDistSquared = pow(0.05 * getScaleFactor(), 2);
float maxDistSquared = pow(getScaleFactor(), 2);

// There's room for optimisation here; we could reuse the combined icons...
edit->combinedConstrBoxes.clear();
Expand All @@ -3219,15 +3218,17 @@ void ViewProviderSketch::combineConstraintIcons(IconQueue iconQueue)
bool addedToGroup = false;

for(IconQueue::iterator j = thisGroup.begin();
j != thisGroup.end(); ++j)
if(i->position.equals(j->position, maxDistSquared) && (*i).type != QString::fromLatin1("small/Constraint_Symmetric_sm")) {
j != thisGroup.end(); ++j) {
float distSquared = pow(i->position[0]-j->position[0],2) + pow(i->position[1]-j->position[1],2);
if(distSquared <= maxDistSquared && (*i).type != QString::fromLatin1("small/Constraint_Symmetric_sm")) {
// Found an icon in iconQueue that's close enough to
// a member of thisGroup, so move it into thisGroup
thisGroup.push_back(*i);
i = iconQueue.erase(i);
addedToGroup = true;
break;
}
}

if(addedToGroup) {
if(i == iconQueue.end())
Expand All @@ -3253,17 +3254,13 @@ void ViewProviderSketch::combineConstraintIcons(IconQueue iconQueue)

void ViewProviderSketch::drawMergedConstraintIcons(IconQueue iconQueue)
{
SbVec3f avPos(0, 0, 0);
for(IconQueue::iterator i = iconQueue.begin(); i != iconQueue.end(); ++i) {
clearCoinImage(i->destination);
avPos = avPos + i->position;
}
avPos = avPos/iconQueue.size();

QImage compositeIcon;
float closest = FLT_MAX; // Closest distance between avPos and any icon
SoImage *thisDest = 0;
SoInfo *thisInfo = 0;
SoImage *thisDest = iconQueue[0].destination;
SoInfo *thisInfo = iconQueue[0].infoPtr;

// Tracks all constraint IDs that are combined into this icon
QString idString;
Expand Down Expand Up @@ -3299,25 +3296,13 @@ void ViewProviderSketch::drawMergedConstraintIcons(IconQueue iconQueue)
idString.append(QString::fromLatin1(","));
idString.append(QString::number(i->constraintId));

if((avPos - i->position).length() < closest) {
thisDest = i->destination;
thisInfo = i->infoPtr;
closest = (avPos - i->position).length();
}

i = iconQueue.erase(i);
while(i != iconQueue.end()) {
if(i->type != thisType) {
++i;
continue;
}

if((avPos - i->position).length() < closest) {
thisDest = i->destination;
thisInfo = i->infoPtr;
closest = (avPos - i->position).length();
}

labels.append(i->label);
ids.push_back(i->constraintId);
labelColors.append(constrColor(i->constraintId));
Expand Down

0 comments on commit 71236cb

Please sign in to comment.