Skip to content

Commit

Permalink
Sketcher: Fix double icons not selectable
Browse files Browse the repository at this point in the history
=========================================

The scaling factor used  was the one of the ViewProviderSketch, however ZoomTranslation uses its own scaling factor.

fixes FreeCAD#6283
  • Loading branch information
abdullahtahiriyo committed Apr 20, 2023
1 parent 9e46de3 commit e786999
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/Mod/Sketcher/Gui/EditModeConstraintCoinManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1743,24 +1743,30 @@ std::set<int> EditModeConstraintCoinManager::detectPreselectionConstr(const SoPi

SbVec3f absPos;
SbVec3f trans;
float scaleFactor;

auto translation = static_cast<SoZoomTranslation *>(static_cast<SoSeparator *>(tailFather)->getChild( static_cast<int>(ConstraintNodePosition::FirstTranslationIndex)));

absPos = translation->abPos.getValue();

trans = translation->translation.getValue();

scaleFactor = translation->getScaleFactor();

if (tail != sep->getChild(static_cast<int>(ConstraintNodePosition::FirstIconIndex))) {
Base::Console().Log("SecondIcon\n");

auto translation2 = static_cast<SoZoomTranslation *>(static_cast<SoSeparator *>(tailFather)->getChild( static_cast<int>(ConstraintNodePosition::SecondTranslationIndex)));

absPos += translation2->abPos.getValue();

trans += translation2->translation.getValue();

scaleFactor = translation2->getScaleFactor();
}

// TODO: Is this calculation actually sound? Why the absolute position is not scaled and the translation is? Review.
SbVec3f constrPos = absPos + trans*ViewProviderSketchCoinAttorney::getScaleFactor(viewProvider);
// Only the translation is scaled because this is how SoZoomTranslation works
SbVec3f constrPos = absPos + scaleFactor*trans;

SbVec2f iconCoords = ViewProviderSketchCoinAttorney::getScreenCoordinates(viewProvider, SbVec2f(constrPos[0],constrPos[1]));

Expand All @@ -1785,16 +1791,20 @@ std::set<int> EditModeConstraintCoinManager::detectPreselectionConstr(const SoPi

if (b->first.contains(iconX, iconY)) {
// We've found a bounding box that contains the mouse pointer!
for (std::set<int>::iterator k = b->second.begin(); k != b->second.end(); ++k)
for (std::set<int>::iterator k = b->second.begin(); k != b->second.end(); ++k) {
constrIndices.insert(*k);
}
}
}
}
else {
// It's a constraint icon, not a combined one
QStringList constrIdStrings = constrIdsStr.split(QString::fromLatin1(","));
while (!constrIdStrings.empty())
constrIndices.insert(constrIdStrings.takeAt(0).toInt());
while (!constrIdStrings.empty()) {
auto constraintid = constrIdStrings.takeAt(0).toInt();
constrIndices.insert(constraintid);

}
}
}
}
Expand Down

0 comments on commit e786999

Please sign in to comment.