Allow snapping constraint labels to grid.

This is pretty much the only way to get a sketch with tidily placed
dimensions.
pull/4/head
whitequark 2016-04-18 06:40:42 +00:00
parent 1142f85ff5
commit c17f1160dc
6 changed files with 27 additions and 9 deletions

View File

@ -299,7 +299,7 @@ void GraphicsWindow::GroupSelection(void) {
gs.constraint[(gs.constraints)++] = s->constraint;
Constraint *c = SK.GetConstraint(s->constraint);
if(c->IsStylable()) gs.stylables++;
if(c->type == Constraint::COMMENT) gs.comments++;
if(c->HasLabel()) gs.constraintLabels++;
}
}
}
@ -434,7 +434,7 @@ Vector GraphicsWindow::UnProjectPoint3(Vector p) {
double w = 1 + p.z * SS.CameraTangent() * scale;
p.x *= w / scale;
p.y *= w / scale;
Vector orig = offset.ScaledBy(-1);
orig = orig.Plus(projRight.ScaledBy(p.x)).Plus(
projUp. ScaledBy(p.y).Plus(

View File

@ -1229,3 +1229,21 @@ bool Constraint::IsStylable() {
return false;
}
bool Constraint::HasLabel() {
switch(type) {
case COMMENT:
case PT_PT_DISTANCE:
case PT_PLANE_DISTANCE:
case PT_LINE_DISTANCE:
case PT_FACE_DISTANCE:
case PROJ_PT_DISTANCE:
case LENGTH_RATIO:
case LENGTH_DIFFERENCE:
case DIAMETER:
case ANGLE:
return true;
default:
return false;
}
}

View File

@ -888,9 +888,10 @@ void GraphicsWindow::MenuEdit(int id) {
break;
}
SS.GW.GroupSelection();
if(SS.GW.gs.points == 0 && SS.GW.gs.comments == 0) {
Error("Can't snap these items to grid; select points or "
"text comments. To snap a line, select its endpoints.");
if(SS.GW.gs.points == 0 && SS.GW.gs.constraintLabels == 0) {
Error("Can't snap these items to grid; select points, "
"text comments, or constraints with a label. "
"To snap a line, select its endpoints.");
break;
}
SS.UndoRemember();
@ -908,8 +909,6 @@ void GraphicsWindow::MenuEdit(int id) {
SS.MarkGroupDirty(ep->group);
} else if(s->constraint.v) {
Constraint *c = SK.GetConstraint(s->constraint);
if(c->type != Constraint::COMMENT) continue;
c->disp.offset = SS.GW.SnapToGrid(c->disp.offset);
}
}

View File

@ -571,7 +571,7 @@ void GraphicsWindow::MouseRightUp(double x, double y) {
CMNU_OTHER_ANGLE);
}
}
if(gs.comments > 0 || gs.points > 0) {
if(gs.constraintLabels > 0 || gs.points > 0) {
AddContextMenuItem("Snap to Grid", CMNU_SNAP_TO_GRID);
}

View File

@ -682,6 +682,7 @@ public:
void Draw(void);
void GetEdges(SEdgeList *sel);
bool IsStylable();
bool HasLabel();
void LineDrawOrGetDistance(Vector a, Vector b);
bool IsVisible() const;

View File

@ -649,7 +649,7 @@ public:
int vectors;
int constraints;
int stylables;
int comments;
int constraintLabels;
int withEndpoints;
int n;
} gs;