Sketcher.scale: Scale label of modified constraints (#26442)

* Sketcher.scale: Scale label of modified constraints

* Sketcher.scale: Narrowing conversion on constraint index
This commit is contained in:
theo-vt
2025-12-29 15:38:12 -05:00
committed by GitHub
parent 20b2f791e2
commit 4b0cd7f034
2 changed files with 40 additions and 16 deletions

View File

@@ -140,6 +140,7 @@ public:
reassignFacadeIds();
}
scaleLabels();
Gui::Command::commitCommand();
}
catch (const Base::Exception& e) {
@@ -273,7 +274,15 @@ private:
}
private:
struct LabelToScale
{
int constrId;
float position;
float distance;
};
std::vector<int> listOfGeoIds;
std::vector<LabelToScale> listOfLabelsToScale;
std::vector<long> listOfFacadeIds;
Base::Vector2d referencePoint, startPoint, endPoint;
bool deleteOriginal;
@@ -336,6 +345,25 @@ private:
Base::Console().error("%s\n", e.what());
}
}
void scaleLabels()
{
SketchObject* sketch = sketchgui->getSketchObject();
for (auto toScale : listOfLabelsToScale) {
sketch->setLabelDistance(toScale.constrId, toScale.distance * scaleFactor);
// Label position or radii and diameters represent an angle, so
// they should not be scaled
Sketcher::ConstraintType type = sketch->Constraints[toScale.constrId]->Type;
if (type == Sketcher::ConstraintType::Radius
|| type == Sketcher::ConstraintType::Diameter) {
sketch->setLabelPosition(toScale.constrId, toScale.position);
}
else {
sketch->setLabelPosition(toScale.constrId, toScale.position * scaleFactor);
}
}
}
void createShape(bool onlyeditoutline) override
{
@@ -467,7 +495,8 @@ private:
const std::vector<Constraint*>& vals = Obj->Constraints.getValues();
for (auto& cstr : vals) {
for (size_t i = 0; i < vals.size(); ++i) {
auto cstr = vals[i];
if (skipConstraint(cstr)) {
continue;
}
@@ -478,6 +507,16 @@ private:
auto newConstr = std::unique_ptr<Constraint>(cstr->copy());
if (firstIndex != GeoEnum::GeoUndef) {
listOfLabelsToScale.push_back(
LabelToScale {
.constrId = static_cast<int>(i),
.position = cstr->LabelPosition,
.distance = cstr->LabelDistance
}
);
}
if ((cstr->Type == Symmetric || cstr->Type == Tangent || cstr->Type == Perpendicular
|| cstr->Type == Angle)
&& firstIndex != GeoEnum::GeoUndef && secondIndex != GeoEnum::GeoUndef

View File

@@ -436,26 +436,11 @@ void EditDatumDialog::performAutoScale(double newDatum)
double oldDatum = sketch->getDatum(ConstrNbr);
double scaleFactor = newDatum / oldDatum;
float initLabelDistance = sketch->Constraints[ConstrNbr]->LabelDistance;
float initLabelPosition = sketch->Constraints[ConstrNbr]->LabelPosition;
centerScale(scaleFactor);
// Some constraints cannot be scaled so the actual datum constraint
// might change index
ConstrNbr = sketch->getSingleScaleDefiningConstraint();
sketch->setLabelDistance(ConstrNbr, initLabelDistance * scaleFactor);
// Label position or radii and diameters represent an angle, so
// they should not be scaled
Sketcher::ConstraintType type = sketch->Constraints[ConstrNbr]->Type;
if (type == Sketcher::ConstraintType::Radius
|| type == Sketcher::ConstraintType::Diameter) {
sketch->setLabelPosition(ConstrNbr, initLabelPosition);
}
else {
sketch->setLabelPosition(ConstrNbr, initLabelPosition * scaleFactor);
}
}
catch (const Base::Exception& e) {
Base::Console().error("Exception performing autoscale: %s\n", e.what());