Skip to content

Commit

Permalink
[Sketcher]make cursor coord display unit aware
Browse files Browse the repository at this point in the history
  • Loading branch information
WandererFan committed Aug 31, 2022
1 parent 16ff6df commit dd14b42
Show file tree
Hide file tree
Showing 19 changed files with 538 additions and 217 deletions.
20 changes: 14 additions & 6 deletions src/Mod/Sketcher/Gui/CommandSketcherTools.cpp
Expand Up @@ -1125,9 +1125,13 @@ class DrawSketchHandlerCopy: public DrawSketchHandler
endpoint = EditCurve[0] + length * Base::Vector2d(cos(angle),sin(angle));
}

SbString text;
text.sprintf(" (%.1f, %.1fdeg)", length, angle * 180 / M_PI);
setPositionText(endpoint, text);
if (showCursorCoords()) {
SbString text;
std::string lengthString = lengthToDisplayFormat(length, 1);
std::string angleString = angleToDisplayFormat(angle * 180.0 / M_PI, 1);
text.sprintf(" (%s, %.s°)", lengthString.c_str(), angleString.c_str());
setPositionText(endpoint, text);
}

EditCurve[1] = endpoint;
drawEdit(EditCurve);
Expand Down Expand Up @@ -1674,9 +1678,13 @@ class DrawSketchHandlerRectangularArray: public DrawSketchHandler
endpoint = EditCurve[0] + length * Base::Vector2d(cos(angle),sin(angle));
}

SbString text;
text.sprintf(" (%.1f, %.1fdeg)", length, angle * 180 / M_PI);
setPositionText(endpoint, text);
if (showCursorCoords()) {
SbString text;
std::string lengthString = lengthToDisplayFormat(length, 1);
std::string angleString = angleToDisplayFormat(angle *180.0 / M_PI, 1);
text.sprintf(" (%s, %s)", lengthString.c_str(), angleString.c_str());
setPositionText(endpoint, text);
}

EditCurve[1] = endpoint;
drawEdit(EditCurve);
Expand Down
11 changes: 8 additions & 3 deletions src/Mod/Sketcher/Gui/DrawSketchHandler.cpp
Expand Up @@ -53,6 +53,7 @@
#include "DrawSketchHandler.h"
#include "ViewProviderSketch.h"
#include "CommandConstraints.h"
#include "Utils.h"

using namespace SketcherGui;
using namespace Sketcher;
Expand Down Expand Up @@ -957,9 +958,13 @@ void DrawSketchHandler::drawDirectionAtCursor(const Base::Vector2d & position, c
float length = (position - origin).Length();
float angle = (position - origin).GetAngle(Base::Vector2d(1.f,0.f));

SbString text;
text.sprintf(" (%.1f,%.1fdeg)", length, angle * 180 / M_PI);
setPositionText(position, text);
if (showCursorCoords()) {
SbString text;
std::string lengthString = lengthToDisplayFormat(length, 1);
std::string angleString = angleToDisplayFormat(angle * 180.0 / M_PI, 1);
text.sprintf(" (%s, %s)", lengthString.c_str(), angleString.c_str());
setPositionText(position, text);
}
}

void DrawSketchHandler::drawEditMarkers(const std::vector<Base::Vector2d> &EditMarkers, unsigned int augmentationlevel)
Expand Down
40 changes: 28 additions & 12 deletions src/Mod/Sketcher/Gui/DrawSketchHandlerArc.h
Expand Up @@ -81,9 +81,13 @@ class DrawSketchHandlerArc : public DrawSketchHandler
float radius = (onSketchPos - EditCurve[0]).Length();
float angle = atan2f(dy_ , dx_);

SbString text;
text.sprintf(" (%.1fR,%.1fdeg)", radius, angle * 180 / M_PI);
setPositionText(onSketchPos, text);
if (showCursorCoords()) {
SbString text;
std::string radiusString = lengthToDisplayFormat(radius, 1);
std::string angleString = angleToDisplayFormat(angle * 180.0 / M_PI, 1);
text.sprintf(" (R%s, %s)", radiusString.c_str(), angleString.c_str());
setPositionText(onSketchPos, text);
}

drawEdit(EditCurve);
if (seekAutoConstraint(sugConstr2, onSketchPos, Base::Vector2d(0.f,0.f))) {
Expand All @@ -106,9 +110,13 @@ class DrawSketchHandlerArc : public DrawSketchHandler
// Display radius and arc angle
float radius = (onSketchPos - EditCurve[0]).Length();

SbString text;
text.sprintf(" (%.1fR,%.1fdeg)", radius, arcAngle * 180 / M_PI);
setPositionText(onSketchPos, text);
if (showCursorCoords()) {
SbString text;
std::string radiusString = lengthToDisplayFormat(radius, 1);
std::string angleString = angleToDisplayFormat(arcAngle * 180.0 / M_PI, 1);
text.sprintf(" (R%s, %s)", radiusString.c_str(), angleString.c_str());
setPositionText(onSketchPos, text);
}

drawEdit(EditCurve);
if (seekAutoConstraint(sugConstr3, onSketchPos, Base::Vector2d(0.0,0.0))) {
Expand Down Expand Up @@ -283,9 +291,13 @@ class DrawSketchHandler3PointArc : public DrawSketchHandler

// Display radius and start angle
// This lineAngle will report counter-clockwise from +X, not relatively
SbString text;
text.sprintf(" (%.1fR,%.1fdeg)", (float) radius, (float) lineAngle * 180 / M_PI);
setPositionText(onSketchPos, text);
if (showCursorCoords()) {
SbString text;
std::string radiusString = lengthToDisplayFormat(radius, 1);
std::string angleString = angleToDisplayFormat(lineAngle * 180.0 / M_PI, 1);
text.sprintf(" (R%s, %s)", radiusString.c_str(), angleString.c_str());
setPositionText(onSketchPos, text);
}

drawEdit(EditCurve);
if (seekAutoConstraint(sugConstr2, onSketchPos, Base::Vector2d(0.f,0.f))) {
Expand Down Expand Up @@ -353,9 +365,13 @@ class DrawSketchHandler3PointArc : public DrawSketchHandler
CenterPoint.y + radius*sin(angle));
}

SbString text;
text.sprintf(" (%.1fR,%.1fdeg)", (float) radius, (float) arcAngle * 180 / M_PI);
setPositionText(onSketchPos, text);
if (showCursorCoords()) {
SbString text;
std::string radiusString = lengthToDisplayFormat(radius, 1);
std::string angleString = angleToDisplayFormat(arcAngle * 180.0 / M_PI, 1);
text.sprintf(" (R%s, %s)", radiusString.c_str(), angleString.c_str());
setPositionText(onSketchPos, text);
}

drawEdit(EditCurve);
if (seekAutoConstraint(sugConstr3, onSketchPos, Base::Vector2d(0.0,0.0),
Expand Down
30 changes: 21 additions & 9 deletions src/Mod/Sketcher/Gui/DrawSketchHandlerArcOfEllipse.h
Expand Up @@ -75,9 +75,12 @@ class DrawSketchHandlerArcOfEllipse : public DrawSketchHandler
// Display radius for user
float radius = (onSketchPos - EditCurve[0]).Length();

SbString text;
text.sprintf(" (%.1fR,%.1fR)", radius,radius);
setPositionText(onSketchPos, text);
if (showCursorCoords()) {
SbString text;
std::string radiusString = lengthToDisplayFormat(radius, 1);
text.sprintf(" (R%s, R%s)", radiusString.c_str(), radiusString.c_str());
setPositionText(onSketchPos, text);
}

drawEdit(EditCurve);
if (seekAutoConstraint(sugConstr2, onSketchPos, onSketchPos - centerPoint,
Expand Down Expand Up @@ -106,9 +109,13 @@ class DrawSketchHandlerArcOfEllipse : public DrawSketchHandler
EditCurve[17] = EditCurve[16];

// Display radius for user
SbString text;
text.sprintf(" (%.1fR,%.1fR)", a, b);
setPositionText(onSketchPos, text);
if (showCursorCoords()) {
SbString text;
std::string aString = lengthToDisplayFormat(a, 1);
std::string bString = lengthToDisplayFormat(b, 1);
text.sprintf(" (R%s, R%s)", aString.c_str(), bString.c_str());
setPositionText(onSketchPos, text);
}

drawEdit(EditCurve);
if (seekAutoConstraint(sugConstr3, onSketchPos, Base::Vector2d(0.f,0.f))) {
Expand Down Expand Up @@ -145,9 +152,14 @@ class DrawSketchHandlerArcOfEllipse : public DrawSketchHandler
// EditCurve[17] = EditCurve[16];

// Display radii and angle for user
SbString text;
text.sprintf(" (%.1fR,%.1fR,%.1fdeg)", a, b, arcAngle * 180 / M_PI);
setPositionText(onSketchPos, text);
if (showCursorCoords()) {
SbString text;
std::string aString = lengthToDisplayFormat(a, 1);
std::string bString = lengthToDisplayFormat(b, 1);
std::string angleString = angleToDisplayFormat(arcAngle * 180.0 / M_PI, 1);
text.sprintf(" (R%s, R%s, %s)", aString.c_str(), bString.c_str(), angleString.c_str());
setPositionText(onSketchPos, text);
}

drawEdit(EditCurve);
if (seekAutoConstraint(sugConstr4, onSketchPos, Base::Vector2d(0.f,0.f))) {
Expand Down
40 changes: 25 additions & 15 deletions src/Mod/Sketcher/Gui/DrawSketchHandlerArcOfHyperbola.h
Expand Up @@ -65,10 +65,12 @@ class DrawSketchHandlerArcOfHyperbola : public DrawSketchHandler

// Display radius for user
float radius = (onSketchPos - centerPoint).Length();

SbString text;
text.sprintf(" (%.1fR,%.1fR)", radius,radius);
setPositionText(onSketchPos, text);
if (showCursorCoords()) {
SbString text;
std::string radiusString = lengthToDisplayFormat(radius, 1);
text.sprintf(" (R%s, R%s)", radiusString.c_str(), radiusString.c_str());
setPositionText(onSketchPos, text);
}

drawEdit(EditCurve);
if (seekAutoConstraint(sugConstr2, onSketchPos, Base::Vector2d(0.f,0.f),
Expand Down Expand Up @@ -97,15 +99,19 @@ class DrawSketchHandlerArcOfHyperbola : public DrawSketchHandler
}

// Display radius for user
SbString text;
text.sprintf(" (%.1fR,%.1fR)", a, b);
setPositionText(onSketchPos, text);
}
if (showCursorCoords()) {
SbString text;
std::string aString = lengthToDisplayFormat(a, 1);
std::string bString = lengthToDisplayFormat(b, 1);
text.sprintf(" (R%s, R%s)", aString.c_str(), bString.c_str());
setPositionText(onSketchPos, text);
}

drawEdit(EditCurve);
if (seekAutoConstraint(sugConstr3, onSketchPos, Base::Vector2d(0.f,0.f))) {
renderSuggestConstraintsCursor(sugConstr3);
return;
drawEdit(EditCurve);
if (seekAutoConstraint(sugConstr3, onSketchPos, Base::Vector2d(0.f,0.f))) {
renderSuggestConstraintsCursor(sugConstr3);
return;
}
}
}
else if (Mode==STATUS_SEEK_Fourth) {
Expand Down Expand Up @@ -144,9 +150,13 @@ class DrawSketchHandlerArcOfHyperbola : public DrawSketchHandler
}

// Display radius for user
SbString text;
text.sprintf(" (%.1fR,%.1fR)", a, b);
setPositionText(onSketchPos, text);
if (showCursorCoords()) {
SbString text;
std::string aString = lengthToDisplayFormat(a, 1);
std::string bString = lengthToDisplayFormat(b, 1);
text.sprintf(" (R%s, R%s)", aString.c_str(), bString.c_str());
setPositionText(onSketchPos, text);
}
}
else {
arcAngle=0.;
Expand Down
28 changes: 18 additions & 10 deletions src/Mod/Sketcher/Gui/DrawSketchHandlerArcOfParabola.h
Expand Up @@ -68,10 +68,12 @@ class DrawSketchHandlerArcOfParabola : public DrawSketchHandler

// Display radius for user
float radius = (onSketchPos - focusPoint).Length();

SbString text;
text.sprintf(" (F%.1f)", radius);
setPositionText(onSketchPos, text);
if (showCursorCoords()) {
SbString text;
std::string radiusString = lengthToDisplayFormat(radius, 1);
text.sprintf(" (F%s)", radiusString.c_str());
setPositionText(onSketchPos, text);
}

drawEdit(EditCurve);
if (seekAutoConstraint(sugConstr2, onSketchPos, Base::Vector2d(0.f,0.f))) {
Expand Down Expand Up @@ -101,9 +103,12 @@ class DrawSketchHandlerArcOfParabola : public DrawSketchHandler
}

// Display radius for user
SbString text;
text.sprintf(" (F%.1f)", focal);
setPositionText(onSketchPos, text);
if (showCursorCoords()) {
SbString text;
std::string focalString = lengthToDisplayFormat(focal, 1);
text.sprintf(" (F%s)", focalString.c_str());
setPositionText(onSketchPos, text);
}

drawEdit(EditCurve);

Expand Down Expand Up @@ -143,9 +148,12 @@ class DrawSketchHandlerArcOfParabola : public DrawSketchHandler
EditCurve[i] = Base::Vector2d(axisPoint.x + rx, axisPoint.y + ry);
}

SbString text;
text.sprintf(" (F%.1f)", focal);
setPositionText(onSketchPos, text);
if (showCursorCoords()) {
SbString text;
std::string focalString = lengthToDisplayFormat(focal, 1);
text.sprintf(" (F%s)", focalString.c_str());
setPositionText(onSketchPos, text);
}
}
else {
arcAngle=0.;
Expand Down
10 changes: 7 additions & 3 deletions src/Mod/Sketcher/Gui/DrawSketchHandlerBSpline.h
Expand Up @@ -357,9 +357,13 @@ class DrawSketchHandlerBSpline: public DrawSketchHandler
float length = (position - BSplinePoles.back()).Length();
float angle = (position - BSplinePoles.back()).GetAngle(Base::Vector2d(1.f,0.f));

SbString text;
text.sprintf(" (%.1f,%.1fdeg)", length, (angle != -FLOAT_MAX) ? angle * 180 / M_PI : 0);
setPositionText(position, text);
if (showCursorCoords()) {
SbString text;
std::string lengthString = lengthToDisplayFormat(length, 1);
std::string angleString = angleToDisplayFormat((angle != -FLOAT_MAX) ? angle * 180 / M_PI : 0, 1);
text.sprintf(" (%s, %s)", lengthString.c_str(), angleString.c_str());
setPositionText(position, text);
}
}
}

Expand Down
20 changes: 13 additions & 7 deletions src/Mod/Sketcher/Gui/DrawSketchHandlerCircle.h
Expand Up @@ -67,10 +67,12 @@ class DrawSketchHandlerCircle : public DrawSketchHandler

// Display radius for user
float radius = (onSketchPos - EditCurve[0]).Length();

SbString text;
text.sprintf(" (%.1fR)", radius);
setPositionText(onSketchPos, text);
if (showCursorCoords()) {
SbString text;
std::string radiusString = lengthToDisplayFormat(radius, 1);
text.sprintf(" (R%s)", radiusString.c_str());
setPositionText(onSketchPos, text);
}

drawEdit(EditCurve);
if (seekAutoConstraint(sugConstr2, onSketchPos, onSketchPos - EditCurve[0],
Expand Down Expand Up @@ -212,9 +214,13 @@ class DrawSketchHandler3PointCircle : public DrawSketchHandler

// Display radius and start angle
// This lineAngle will report counter-clockwise from +X, not relatively
SbString text;
text.sprintf(" (%.1fR,%.1fdeg)", (float) radius, (float) lineAngle * 180 / M_PI);
setPositionText(onSketchPos, text);
if (showCursorCoords()) {
SbString text;
std::string radiusString = lengthToDisplayFormat(radius, 1);
std::string angleString = angleToDisplayFormat( lineAngle * 180.0 / M_PI, 1);
text.sprintf(" (R%s, %s)", radiusString.c_str(), angleString.c_str());
setPositionText(onSketchPos, text);
}

drawEdit(EditCurve);
if (Mode == STATUS_SEEK_Second) {
Expand Down

0 comments on commit dd14b42

Please sign in to comment.