Sketcher: add ConstraintLineByAngle helper. (#22273)
* Sketcher: add ConstraintLineByAngle helper. * Update src/Mod/Sketcher/Gui/Utils.cpp * Update src/Mod/Sketcher/Gui/Utils.cpp --------- Co-authored-by: Kacper Donat <kadet1090@gmail.com>
This commit is contained in:
@@ -673,28 +673,7 @@ void DSHLineController::addConstraints()
|
||||
};
|
||||
|
||||
auto constraintp4angle = [&]() {
|
||||
using std::numbers::pi;
|
||||
|
||||
double angle = Base::toRadians(p4);
|
||||
if (fabs(angle - pi) < Precision::Confusion() || fabs(angle + pi) < Precision::Confusion()
|
||||
|| fabs(angle) < Precision::Confusion()) {
|
||||
Gui::cmdAppObjectArgs(obj,
|
||||
"addConstraint(Sketcher.Constraint('Horizontal',%d)) ",
|
||||
firstCurve);
|
||||
}
|
||||
else if (fabs(angle - pi / 2) < Precision::Confusion()
|
||||
|| fabs(angle + pi / 2) < Precision::Confusion()) {
|
||||
Gui::cmdAppObjectArgs(obj,
|
||||
"addConstraint(Sketcher.Constraint('Vertical',%d)) ",
|
||||
firstCurve);
|
||||
}
|
||||
else {
|
||||
Gui::cmdAppObjectArgs(obj,
|
||||
"addConstraint(Sketcher.Constraint('Angle',%d,%d,%f)) ",
|
||||
Sketcher::GeoEnum::HAxis,
|
||||
firstCurve,
|
||||
angle);
|
||||
}
|
||||
ConstraintLineByAngle(firstCurve, Base::toRadians(p4), obj);
|
||||
};
|
||||
|
||||
auto constraintp4y = [&]() {
|
||||
|
||||
@@ -2607,26 +2607,7 @@ void DSHRectangleController::addConstraints()
|
||||
|
||||
if (handler->constructionMethod() == ConstructionMethod::ThreePoints) {
|
||||
if (angleSet) {
|
||||
if (fabs(angle - pi) < Precision::Confusion()
|
||||
|| fabs(angle + pi) < Precision::Confusion()
|
||||
|| fabs(angle) < Precision::Confusion()) {
|
||||
Gui::cmdAppObjectArgs(obj,
|
||||
"addConstraint(Sketcher.Constraint('Horizontal',%d)) ",
|
||||
firstCurve);
|
||||
}
|
||||
else if (fabs(angle - pi / 2) < Precision::Confusion()
|
||||
|| fabs(angle + pi / 2) < Precision::Confusion()) {
|
||||
Gui::cmdAppObjectArgs(obj,
|
||||
"addConstraint(Sketcher.Constraint('Vertical',%d)) ",
|
||||
firstCurve);
|
||||
}
|
||||
else {
|
||||
Gui::cmdAppObjectArgs(obj,
|
||||
"addConstraint(Sketcher.Constraint('Angle',%d,%d,%f)) ",
|
||||
Sketcher::GeoEnum::HAxis,
|
||||
firstCurve,
|
||||
angle);
|
||||
}
|
||||
ConstraintLineByAngle(firstCurve, angle, obj);
|
||||
}
|
||||
if (innerAngleSet) {
|
||||
if (fabs(innerAngle - pi / 2) > Precision::Confusion()) {
|
||||
|
||||
@@ -668,6 +668,59 @@ void SketcherGui::ConstraintToAttachment(Sketcher::GeoElementId element,
|
||||
}
|
||||
}
|
||||
|
||||
void SketcherGui::ConstraintLineByAngle(int geoId, double angle, App::DocumentObject* obj)
|
||||
{
|
||||
using std::numbers::pi;
|
||||
double angleModPi = std::fmod(angle, pi);
|
||||
double angleModHalfPi = std::fmod(angle, pi / 2);
|
||||
|
||||
if (fabs(angleModPi - pi) < Precision::Confusion()
|
||||
|| fabs(angleModPi + pi) < Precision::Confusion()
|
||||
|| fabs(angleModPi) < Precision::Confusion()) {
|
||||
Gui::cmdAppObjectArgs(obj, "addConstraint(Sketcher.Constraint('Horizontal',%d)) ", geoId);
|
||||
}
|
||||
else if (fabs(angleModHalfPi - pi / 2) < Precision::Confusion()
|
||||
|| fabs(angleModHalfPi + pi / 2) < Precision::Confusion()) {
|
||||
Gui::cmdAppObjectArgs(obj, "addConstraint(Sketcher.Constraint('Vertical',%d)) ", geoId);
|
||||
}
|
||||
else {
|
||||
Gui::cmdAppObjectArgs(obj,
|
||||
"addConstraint(Sketcher.Constraint('Angle',%d,%d,%f)) ",
|
||||
Sketcher::GeoEnum::HAxis,
|
||||
geoId,
|
||||
angle);
|
||||
}
|
||||
}
|
||||
|
||||
void SketcherGui::Constraint2LinesByAngle(int geoId1,
|
||||
int geoId2,
|
||||
double angle,
|
||||
App::DocumentObject* obj)
|
||||
{
|
||||
using std::numbers::pi;
|
||||
double angleModPi = std::fmod(angle, pi);
|
||||
double angleModHalfPi = std::fmod(angle, pi / 2);
|
||||
|
||||
if (fabs(angleModPi) < Precision::Confusion()) {
|
||||
Gui::cmdAppObjectArgs(obj,
|
||||
"addConstraint(Sketcher.Constraint('Parallel',%d,%d)) ",
|
||||
geoId1,
|
||||
geoId2);
|
||||
}
|
||||
else if (fabs(angleModHalfPi) < Precision::Confusion()) {
|
||||
Gui::cmdAppObjectArgs(obj,
|
||||
"addConstraint(Sketcher.Constraint('Perpendicular',%d,%d)) ",
|
||||
geoId1,
|
||||
geoId2);
|
||||
}
|
||||
else {
|
||||
Gui::cmdAppObjectArgs(obj,
|
||||
"addConstraint(Sketcher.Constraint('Angle',%d,%d,%f)) ",
|
||||
geoId1,
|
||||
geoId2,
|
||||
angle);
|
||||
}
|
||||
}
|
||||
|
||||
// convenience functions for cursor display
|
||||
bool SketcherGui::hideUnits()
|
||||
|
||||
@@ -199,6 +199,9 @@ void ConstraintToAttachment(Sketcher::GeoElementId element,
|
||||
double distance,
|
||||
App::DocumentObject* obj);
|
||||
|
||||
void ConstraintLineByAngle(int geoId, double angle, App::DocumentObject* obj);
|
||||
void Constraint2LinesByAngle(int geoId1, int geoId2, double angle, App::DocumentObject* obj);
|
||||
|
||||
// convenience functions for cursor coordinates
|
||||
bool hideUnits();
|
||||
bool showCursorCoords();
|
||||
|
||||
Reference in New Issue
Block a user