Sketcher: Dimension tool : add arc length

This commit is contained in:
PaddleStroke
2024-04-11 08:26:27 +02:00
committed by Yorik van Havre
parent 44af4555c0
commit 4442fa709e

View File

@@ -2018,45 +2018,51 @@ protected:
int geoId = selCircleArc[0].GeoId;
bool reverseOrder = isRadiusDoF(geoId);
if (availableConstraint == AvailableConstraint::FIRST) {
if (!reverseOrder) {
if (reverseOrder) {
if (availableConstraint == AvailableConstraint::FIRST) {
restartCommand(QT_TRANSLATE_NOOP("Command", "Add arc angle constraint"));
createArcAngleConstrain(geoId, onSketchPos);
selAllowed = true;
}
if (availableConstraint == AvailableConstraint::SECOND) {
restartCommand(QT_TRANSLATE_NOOP("Command", "Add arc length constraint"));
createArcLengthConstrain(geoId, onSketchPos);
}
if (availableConstraint == AvailableConstraint::THIRD) {
restartCommand(QT_TRANSLATE_NOOP("Command", "Add Radius constraint"));
createRadiusDiameterConstrain(geoId, onSketchPos, true);
}
else {
restartCommand(QT_TRANSLATE_NOOP("Command", "Add arc angle constraint"));
createArcAngleConstrain(geoId, onSketchPos);
}
selAllowed = true;
}
if (availableConstraint == AvailableConstraint::SECOND) {
restartCommand(QT_TRANSLATE_NOOP("Command", "Add Radius constraint"));
createRadiusDiameterConstrain(geoId, onSketchPos, reverseOrder);
if (!isArcOfCircle(*Obj->getGeometry(geoId))) {
//This way if key is pressed again it goes back to FIRST
if (availableConstraint == AvailableConstraint::FOURTH) {
restartCommand(QT_TRANSLATE_NOOP("Command", "Add Radius constraint"));
createRadiusDiameterConstrain(geoId, onSketchPos, false);
availableConstraint = AvailableConstraint::RESET;
}
}
if (availableConstraint == AvailableConstraint::THIRD) {
if (!reverseOrder) {
restartCommand(QT_TRANSLATE_NOOP("Command", "Add arc angle constraint"));
createArcAngleConstrain(geoId, onSketchPos);
else {
if (availableConstraint == AvailableConstraint::FIRST) {
restartCommand(QT_TRANSLATE_NOOP("Command", "Add Radius constraint"));
createRadiusDiameterConstrain(geoId, onSketchPos, true);
selAllowed = true;
}
else {
if (availableConstraint == AvailableConstraint::SECOND) {
restartCommand(QT_TRANSLATE_NOOP("Command", "Add Radius constraint"));
createRadiusDiameterConstrain(geoId, onSketchPos, false);
}
availableConstraint = AvailableConstraint::RESET;
}
/*
bool firstCstr = true;
if (availableConstraint != AvailableConstraint::FIRST) {
firstCstr = false;
if (!isArcOfCircle(*geom)) {
if (!isArcOfCircle(*Obj->getGeometry(geoId))) {
//This way if key is pressed again it goes back to FIRST
availableConstraint = AvailableConstraint::RESET;
}
}*/
}
if (availableConstraint == AvailableConstraint::THIRD) {
restartCommand(QT_TRANSLATE_NOOP("Command", "Add arc angle constraint"));
createArcAngleConstrain(geoId, onSketchPos);
}
if (availableConstraint == AvailableConstraint::FOURTH) {
restartCommand(QT_TRANSLATE_NOOP("Command", "Add arc length constraint"));
createArcLengthConstrain(geoId, onSketchPos);
availableConstraint = AvailableConstraint::RESET;
}
}
}
void makeCts_2Circle(bool& selAllowed, Base::Vector2d onSketchPos)
@@ -2429,6 +2435,26 @@ protected:
moveConstraint(ConStr.size() - 1, onSketchPos);
}
void createArcLengthConstrain(int GeoId, Base::Vector2d onSketchPos) {
const Part::Geometry* geom = Obj->getGeometry(GeoId);
if (isArcOfCircle(*geom)) {
const auto* arc = static_cast<const Part::GeomArcOfCircle*>(geom);
double ActLength = arc->getAngle(false) * arc->getRadius();
Gui::cmdAppObjectArgs(Obj, "addConstraint(Sketcher.Constraint('Distance',%d,%f))",
GeoId, ActLength);
const std::vector<Sketcher::Constraint*>& ConStr = Obj->Constraints.getValues();
if (isPointOrSegmentFixed(Obj, GeoId) || constraintCreationMode == Reference) {
// it is a constraint on a external line, make it non-driving
Gui::cmdAppObjectArgs(Obj, "setDriving(%i,%s)", ConStr.size() - 1, "False");
}
numberOfConstraintsCreated++;
moveConstraint(ConStr.size() - 1, onSketchPos);
}
}
void createArcAngleConstrain(int GeoId, Base::Vector2d onSketchPos) {
const Part::Geometry* geom = Obj->getGeometry(GeoId);
if (isArcOfCircle(*geom)) {