Sketcher: Only autoscale if the datum being edited is the scale defining datum (#22419)

This commit is contained in:
theo-vt
2025-07-18 10:58:30 -04:00
committed by GitHub
parent 48785dfd0e
commit b0dcce6c66
3 changed files with 19 additions and 10 deletions

View File

@@ -7600,21 +7600,21 @@ int SketchObject::getGeoIdFromCompleteGeometryIndex(int completeGeometryIndex) c
else
return (completeGeometryIndex - completeGeometryCount);
}
bool SketchObject::hasSingleScaleDefiningConstraint() const
int SketchObject::getSingleScaleDefiningConstraint() const
{
const std::vector<Constraint*>& vals = this->Constraints.getValues();
bool foundOne = false;
for (auto val : vals) {
int found = -1;
for (size_t i = 0; i < vals.size(); ++i) {
// An angle does not define scale
if (val->isDimensional() && val->Type != Angle) {
if (foundOne) {
return false;
if (vals[i]->isDimensional() && vals[i]->Type != Angle) {
if (found != -1) { // More than one scale defining constraint
return -1;
}
foundOne = true;
found = i;
}
}
return foundOne;
return found;
}
std::unique_ptr<const GeometryFacade> SketchObject::getGeometryFacade(int GeoId) const

View File

@@ -272,7 +272,9 @@ public:
int getGeoIdFromCompleteGeometryIndex(int completeGeometryIndex) const;
bool hasSingleScaleDefiningConstraint() const;
// Returns the index of the scale defining constraint if
// there is only one and -1 otherwise
int getSingleScaleDefiningConstraint() const;
/// returns non zero if the sketch contains conflicting constraints
int hasConflicts() const;

View File

@@ -409,8 +409,15 @@ void EditDatumDialog::performAutoScale(double newDatum)
|| (autoScaleMode
== static_cast<int>(SketcherGui::AutoScaleMode::WhenNoScaleFeatureIsVisible)
&& !hasVisualFeature(sketch, nullptr, Gui::Application::Instance->activeDocument())))
&& sketch->getExternalGeometryCount() <= 2 && sketch->hasSingleScaleDefiningConstraint()) {
&& sketch->getExternalGeometryCount() <= 2) {
try {
// Handle the case where multiple datum constraints are present but only one is scale
// defining e.g. a bunch of angle constraints and a single length constraint
int scaleDefiningConstraint = sketch->getSingleScaleDefiningConstraint();
if (scaleDefiningConstraint != ConstrNbr) {
return;
}
double oldDatum = sketch->getDatum(ConstrNbr);
double scaleFactor = newDatum / oldDatum;
float initLabelDistance = sketch->Constraints[ConstrNbr]->LabelDistance;