* [TD]add preferences for detail highlight snapping * [TD]fix highlight drag issues * Update src/Mod/TechDraw/Gui/TaskDetail.cpp minor format change from benj5378. Co-authored-by: Benjamin Bræstrup Sayoc <benj5378@outlook.com> --------- Co-authored-by: Benjamin Bræstrup Sayoc <benj5378@outlook.com>
This commit is contained in:
@@ -400,6 +400,13 @@ void DrawViewDetail::postHlrTasks(void)
|
||||
Scale.purgeTouched();
|
||||
detailExec(m_saveShape, m_saveDvp, m_saveDvs);
|
||||
}
|
||||
|
||||
auto* baseView = freecad_cast<DrawViewPart*>(BaseView.getValue());
|
||||
if (!baseView) {
|
||||
throw Base::RuntimeError("Detail has no base view!");
|
||||
}
|
||||
baseView->requestPaint(); // repaint the highlight on the base view.
|
||||
|
||||
overrideKeepUpdated(false);
|
||||
}
|
||||
|
||||
|
||||
@@ -718,6 +718,38 @@ void DrawViewPart::onFacesFinished()
|
||||
requestPaint();
|
||||
}
|
||||
|
||||
|
||||
//! returns the position of the first visible vertex within snap radius of newAnchorPoint. newAnchorPoint
|
||||
//! should be unscaled in conventional coordinates. if no suitable vertex is found, newAnchorPoint
|
||||
//! is returned. the result is unscaled and inverted?
|
||||
Base::Vector3d DrawViewPart::snapHighlightToVertex(Base::Vector3d newAnchorPoint,
|
||||
double radius) const
|
||||
{
|
||||
if (!Preferences::snapDetailHighlights()) {
|
||||
return newAnchorPoint;
|
||||
}
|
||||
|
||||
double snapRadius = radius * Preferences::detailSnapRadius();
|
||||
double dvpScale = getScale();
|
||||
std::vector<Base::Vector3d> vertexPoints;
|
||||
auto vertsAll = getVertexGeometry();
|
||||
double nearDistance{std::numeric_limits<double>::max()};
|
||||
Base::Vector3d nearPoint{newAnchorPoint};
|
||||
for (auto& vert: vertsAll) {
|
||||
if (vert->getHlrVisible()) {
|
||||
Base::Vector3d vertPointUnscaled = DU::invertY(vert->point()) / dvpScale;
|
||||
double distanceToVertex = (vertPointUnscaled - newAnchorPoint).Length();
|
||||
if (distanceToVertex < snapRadius &&
|
||||
distanceToVertex < nearDistance) {
|
||||
nearDistance = distanceToVertex;
|
||||
nearPoint = vertPointUnscaled;
|
||||
}
|
||||
}
|
||||
}
|
||||
return nearPoint;
|
||||
}
|
||||
|
||||
|
||||
//retrieve all the face hatches associated with this dvp
|
||||
std::vector<TechDraw::DrawHatch*> DrawViewPart::getHatches() const
|
||||
{
|
||||
|
||||
@@ -243,6 +243,9 @@ public:
|
||||
bool isCosmeticEdge(const std::string& element);
|
||||
bool isCenterLine(const std::string& element);
|
||||
|
||||
Base::Vector3d snapHighlightToVertex(Base::Vector3d newAnchorPoint, double radius) const;
|
||||
|
||||
|
||||
public Q_SLOTS:
|
||||
void onHlrFinished(void);
|
||||
void onFacesFinished(void);
|
||||
|
||||
@@ -693,3 +693,15 @@ bool Preferences::showUnits()
|
||||
}
|
||||
|
||||
|
||||
bool Preferences::snapDetailHighlights()
|
||||
{
|
||||
return Preferences::getPreferenceGroup("General")->GetBool("SnapHighlights", true);
|
||||
}
|
||||
|
||||
|
||||
//! distance within which we should snap a highlight to a vertex
|
||||
double Preferences::detailSnapRadius()
|
||||
{
|
||||
return getPreferenceGroup("General")->GetFloat("DetailSnapRadius", 0.6);
|
||||
}
|
||||
|
||||
|
||||
@@ -163,6 +163,9 @@ public:
|
||||
|
||||
static bool showUnits();
|
||||
|
||||
static bool snapDetailHighlights();
|
||||
static double detailSnapRadius();
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user