Merge pull request #25848 from PaddleStroke/sk_scale_distances
Sketcher: Distance constraints: scale label distance on creation.
This commit is contained in:
@@ -2304,6 +2304,8 @@ int SketchObject::addConstraints(const std::vector<Constraint*>& ConstraintList)
|
||||
}
|
||||
|
||||
addGeometryState(cnew);
|
||||
|
||||
signalConstraintAdded(cnew);
|
||||
}
|
||||
|
||||
this->Constraints.setValues(std::move(newVals));
|
||||
@@ -2377,6 +2379,8 @@ int SketchObject::addConstraint(std::unique_ptr<Constraint> constraint)
|
||||
|
||||
addGeometryState(constNew);
|
||||
|
||||
signalConstraintAdded(constNew);
|
||||
|
||||
newVals.push_back(constNew);// add new constraint at the back
|
||||
|
||||
this->Constraints.setValues(std::move(newVals));
|
||||
|
||||
@@ -973,6 +973,7 @@ public:
|
||||
// Signaled when solver has done update
|
||||
fastsignals::signal<void()> signalSolverUpdate;
|
||||
fastsignals::signal<void()> signalElementsChanged;
|
||||
fastsignals::signal<void(Constraint*)> signalConstraintAdded;
|
||||
|
||||
Part::TopoShape buildInternals(const Part::TopoShape& edges) const;
|
||||
|
||||
|
||||
@@ -107,7 +107,6 @@ void finishDatumConstraint(Gui::Command* cmd,
|
||||
|
||||
// Guess some reasonable distance for placing the datum text
|
||||
Gui::Document* doc = cmd->getActiveGuiDocument();
|
||||
float scaleFactor = 1.0;
|
||||
double labelPosition = 0.0;
|
||||
float labelPositionRandomness = 0.0;
|
||||
|
||||
@@ -131,13 +130,10 @@ void finishDatumConstraint(Gui::Command* cmd,
|
||||
&& doc->getInEdit()->isDerivedFrom<SketcherGui::ViewProviderSketch>()) {
|
||||
SketcherGui::ViewProviderSketch* vp =
|
||||
static_cast<SketcherGui::ViewProviderSketch*>(doc->getInEdit());
|
||||
scaleFactor = vp->getScaleFactor();
|
||||
|
||||
int firstConstraintIndex = lastConstraintIndex - numberofconstraints + 1;
|
||||
|
||||
for (int i = lastConstraintIndex; i >= firstConstraintIndex; i--) {
|
||||
ConStr[i]->LabelDistance = 2. * scaleFactor;
|
||||
|
||||
if (lastConstraintType == Radius || lastConstraintType == Diameter) {
|
||||
const Part::Geometry* geo = sketch->getGeometry(ConStr[i]->First);
|
||||
|
||||
|
||||
@@ -3314,6 +3314,23 @@ void ViewProviderSketch::slotSolverUpdate()
|
||||
}
|
||||
}
|
||||
|
||||
void ViewProviderSketch::slotConstraintAdded(Sketcher::Constraint* constraint)
|
||||
{
|
||||
if (!constraint) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Auto-scale label distance for dimensional constraints
|
||||
if (constraint->Type == Distance || constraint->Type == DistanceX || constraint->Type == DistanceY) {
|
||||
// If label distance is default (10.0), scale it based on view.
|
||||
// We use a small epsilon for float comparison.
|
||||
if (std::abs(constraint->LabelDistance - 10.f) < 1e-5) {
|
||||
float scale = getScaleFactor();
|
||||
constraint->LabelDistance = 2.f * scale;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ViewProviderSketch::onChanged(const App::Property* prop)
|
||||
{
|
||||
ViewProvider2DObject::onChanged(prop);
|
||||
@@ -3605,6 +3622,8 @@ bool ViewProviderSketch::setEdit(int ModNum)
|
||||
}
|
||||
|
||||
//NOLINTBEGIN
|
||||
connectConstraintAdded = getSketchObject()->signalConstraintAdded.connect(
|
||||
std::bind(&ViewProviderSketch::slotConstraintAdded, this, sp::_1));
|
||||
connectUndoDocument = getDocument()->signalUndoDocument.connect(
|
||||
std::bind(&ViewProviderSketch::slotUndoDocument, this, sp::_1));
|
||||
connectRedoDocument = getDocument()->signalRedoDocument.connect(
|
||||
@@ -3821,6 +3840,7 @@ void ViewProviderSketch::unsetEdit(int ModNum)
|
||||
connectUndoDocument.disconnect();
|
||||
connectRedoDocument.disconnect();
|
||||
connectSolverUpdate.disconnect();
|
||||
connectConstraintAdded.disconnect();
|
||||
|
||||
// when pressing ESC make sure to close the dialog
|
||||
Gui::Control().closeDialog();
|
||||
|
||||
@@ -773,6 +773,7 @@ protected:
|
||||
void slotUndoDocument(const Gui::Document&);
|
||||
void slotRedoDocument(const Gui::Document&);
|
||||
void slotSolverUpdate();
|
||||
void slotConstraintAdded(Sketcher::Constraint* constraint);
|
||||
void forceUpdateData();
|
||||
//@}
|
||||
|
||||
@@ -972,6 +973,7 @@ private:
|
||||
fastsignals::connection connectUndoDocument;
|
||||
fastsignals::connection connectRedoDocument;
|
||||
fastsignals::connection connectSolverUpdate;
|
||||
fastsignals::connection connectConstraintAdded;
|
||||
|
||||
QMetaObject::Connection screenChangeConnection;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user