Sketcher: Rectangular Array Snap mode
===================================== Rectangular Array gets a snap mode every 10 degrees when pressing CTRL (for consistency with Multiline arc, which also snaps using CTRL). Request: https://forum.freecadweb.org/viewtopic.php?p=535691#p535691
This commit is contained in:
@@ -1801,6 +1801,7 @@ public:
|
||||
int rows, int cols, bool constraintSeparation,
|
||||
bool equalVerticalHorizontalSpacing)
|
||||
: Mode(STATUS_SEEK_First)
|
||||
, snapMode(SnapMode::Free)
|
||||
, geoIdList(geoidlist)
|
||||
, OriginGeoId(origingeoid)
|
||||
, OriginPos(originpos)
|
||||
@@ -1821,6 +1822,11 @@ public:
|
||||
STATUS_End
|
||||
};
|
||||
|
||||
enum class SnapMode {
|
||||
Free,
|
||||
Snap10Degree
|
||||
};
|
||||
|
||||
virtual void activated(ViewProviderSketch *sketchgui)
|
||||
{
|
||||
setCursor(QPixmap(cursor_createrectangulararray), 7, 7);
|
||||
@@ -1831,15 +1837,29 @@ public:
|
||||
virtual void mouseMove(Base::Vector2d onSketchPos)
|
||||
{
|
||||
if (Mode==STATUS_SEEK_First) {
|
||||
|
||||
if(QApplication::keyboardModifiers() == Qt::ControlModifier)
|
||||
snapMode = SnapMode::Snap10Degree;
|
||||
else
|
||||
snapMode = SnapMode::Free;
|
||||
|
||||
float length = (onSketchPos - EditCurve[0]).Length();
|
||||
float angle = (onSketchPos - EditCurve[0]).GetAngle(Base::Vector2d(1.f, 0.f));
|
||||
|
||||
Base::Vector2d endpoint = onSketchPos;
|
||||
|
||||
if (snapMode == SnapMode::Snap10Degree) {
|
||||
angle = round(angle / (M_PI/18)) * M_PI/18;
|
||||
endpoint = EditCurve[0] + length * Base::Vector2d(cos(angle),sin(angle));
|
||||
}
|
||||
|
||||
SbString text;
|
||||
text.sprintf(" (%.1f, %.1fdeg)", length, angle * 180 / M_PI);
|
||||
setPositionText(onSketchPos, text);
|
||||
setPositionText(endpoint, text);
|
||||
|
||||
EditCurve[1] = onSketchPos;
|
||||
EditCurve[1] = endpoint;
|
||||
sketchgui->drawEdit(EditCurve);
|
||||
if (seekAutoConstraint(sugConstr1, onSketchPos, Base::Vector2d(0.0, 0.0), AutoConstraint::VERTEX))
|
||||
if (seekAutoConstraint(sugConstr1, endpoint, Base::Vector2d(0.0, 0.0), AutoConstraint::VERTEX))
|
||||
{
|
||||
renderSuggestConstraintsCursor(sugConstr1);
|
||||
return;
|
||||
@@ -1849,10 +1869,9 @@ public:
|
||||
applyCursor();
|
||||
}
|
||||
|
||||
virtual bool pressButton(Base::Vector2d onSketchPos)
|
||||
virtual bool pressButton(Base::Vector2d)
|
||||
{
|
||||
if (Mode == STATUS_SEEK_First) {
|
||||
EditCurve[1] = onSketchPos;
|
||||
sketchgui->drawEdit(EditCurve);
|
||||
Mode = STATUS_End;
|
||||
}
|
||||
@@ -1901,6 +1920,7 @@ public:
|
||||
}
|
||||
protected:
|
||||
SelectMode Mode;
|
||||
SnapMode snapMode;
|
||||
string geoIdList;
|
||||
Base::Vector3d Origin;
|
||||
int OriginGeoId;
|
||||
|
||||
Reference in New Issue
Block a user