From 4628048d45d575451ca3348ccabfdfee34605391 Mon Sep 17 00:00:00 2001 From: Jonathan Westhues Date: Mon, 3 May 2010 21:11:52 -0800 Subject: [PATCH] Add "lock point where dragged" constraint, in either 2d or 3d. And call the cubic things splines, not segments, since that's what they are now. [git-p4: depot-paths = "//depot/solvespace/": change = 2135] --- constraint.cpp | 14 ++++++++++++++ constrainteq.cpp | 18 ++++++++++++++++++ describescreen.cpp | 7 +++++-- drawconstraint.cpp | 19 +++++++++++++++++++ graphicswin.cpp | 3 ++- sketch.h | 1 + toolbar.cpp | 2 +- ui.h | 1 + wishlist.txt | 3 +-- 9 files changed, 62 insertions(+), 6 deletions(-) diff --git a/constraint.cpp b/constraint.cpp index 2812c1fe..28032c5a 100644 --- a/constraint.cpp +++ b/constraint.cpp @@ -36,6 +36,7 @@ char *Constraint::DescriptionString(void) { case EQUAL_RADIUS: s = "eq-radius"; break; case EQUAL_ANGLE: s = "eq-angle"; break; case EQUAL_LINE_ARC_LEN:s = "eq-line-len-arc-len"; break; + case WHERE_DRAGGED: s = "lock-where-dragged"; break; case COMMENT: s = "comment"; break; default: s = "???"; break; } @@ -646,6 +647,19 @@ void Constraint::MenuConstrain(int id) { AddConstraint(&c); break; + case GraphicsWindow::MNU_WHERE_DRAGGED: + if(gs.points == 1 && gs.n == 1) { + c.type = WHERE_DRAGGED; + c.ptA = gs.point[0]; + } else { + Error("Bad selection for lock point where dragged constraint. " + "This constraint can apply to:\n\n" + " * a point\n"); + return; + } + AddConstraint(&c); + break; + case GraphicsWindow::MNU_COMMENT: SS.GW.pending.operation = GraphicsWindow::MNU_COMMENT; SS.GW.pending.description = "click center of comment text"; diff --git a/constrainteq.cpp b/constrainteq.cpp index e6e256ab..d456cc83 100644 --- a/constrainteq.cpp +++ b/constrainteq.cpp @@ -690,6 +690,24 @@ void ConstraintBase::GenerateReal(IdList *l) { break; } + case WHERE_DRAGGED: { + EntityBase *ep = SK.GetEntity(ptA); + if(workplane.v == EntityBase::FREE_IN_3D.v) { + ExprVector ev = ep->PointGetExprs(); + Vector v = ep->PointGetNum(); + + AddEq(l, ev.x->Minus(Expr::From(v.x)), 0); + AddEq(l, ev.y->Minus(Expr::From(v.y)), 1); + AddEq(l, ev.z->Minus(Expr::From(v.z)), 2); + } else { + Expr *u, *v; + ep->PointGetExprsInWorkplane(workplane, &u, &v); + AddEq(l, u->Minus(Expr::From(u->Eval())), 0); + AddEq(l, v->Minus(Expr::From(v->Eval())), 1); + } + break; + } + case COMMENT: break; diff --git a/describescreen.cpp b/describescreen.cpp index dd428e18..08dcdb30 100644 --- a/describescreen.cpp +++ b/describescreen.cpp @@ -284,10 +284,13 @@ void TextWindow::DescribeSelection(void) { Printf(true, " distance = %Fi%s", SS.MmToString(d)); } } else if(gs.n == 0 && gs.stylables > 0) { - Printf(true, "%FtSELECTED:%E comment text"); + Printf(false, "%FtSELECTED:%E comment text"); + } else if(gs.n == 0 && gs.constraints == 1) { + Printf(false, "%FtSELECTED:%E %s", + SK.GetConstraint(gs.constraint[0])->DescriptionString()); } else { int n = SS.GW.selection.n; - Printf(true, "%FtSELECTED:%E %d item%s", n, n == 1 ? "" : "s"); + Printf(false, "%FtSELECTED:%E %d item%s", n, n == 1 ? "" : "s"); } if(shown.screen == SCREEN_STYLE_INFO && diff --git a/drawconstraint.cpp b/drawconstraint.cpp index fb0f18ae..a8a31e41 100644 --- a/drawconstraint.cpp +++ b/drawconstraint.cpp @@ -601,6 +601,25 @@ void Constraint::DrawOrGetDistance(Vector *labelPos) { break; } + case WHERE_DRAGGED: { + Vector p = SK.GetEntity(ptA)->PointGetNum(), + u = p.Plus(gu.WithMagnitude(8/SS.GW.scale)).Plus( + gr.WithMagnitude(8/SS.GW.scale)), + uu = u.Minus(gu.WithMagnitude(5/SS.GW.scale)), + ur = u.Minus(gr.WithMagnitude(5/SS.GW.scale)); + // Draw four little crop marks, uniformly spaced (by ninety + // degree rotations) around the point. + int i; + for(i = 0; i < 4; i++) { + LineDrawOrGetDistance(u, uu); + LineDrawOrGetDistance(u, ur); + u = u.RotatedAbout(p, gn, PI/2); + ur = ur.RotatedAbout(p, gn, PI/2); + uu = uu.RotatedAbout(p, gn, PI/2); + } + break; + } + case SAME_ORIENTATION: { for(int i = 0; i < 2; i++) { Entity *e = SK.GetEntity(i == 0 ? entityA : entityB); diff --git a/graphicswin.cpp b/graphicswin.cpp index 0869a648..abe15801 100644 --- a/graphicswin.cpp +++ b/graphicswin.cpp @@ -92,7 +92,7 @@ const GraphicsWindow::MenuEntry GraphicsWindow::menu[] = { { 1, "&Rectangle\tR", MNU_RECTANGLE, 'R', mReq }, { 1, "&Circle\tC", MNU_CIRCLE, 'C', mReq }, { 1, "&Arc of a Circle\tA", MNU_ARC, 'A', mReq }, -{ 1, "&Bezier Cubic Segment\tB", MNU_CUBIC, 'B', mReq }, +{ 1, "&Bezier Cubic Spline\tB", MNU_CUBIC, 'B', mReq }, { 1, NULL, 0, NULL }, { 1, "&Text in TrueType Font\tT", MNU_TTF_TEXT, 'T', mReq }, { 1, NULL, 0, NULL }, @@ -116,6 +116,7 @@ const GraphicsWindow::MenuEntry GraphicsWindow::menu[] = { { 1, "Para&llel / Tangent\tL", MNU_PARALLEL, 'L', mCon }, { 1, "&Perpendicular\t[", MNU_PERPENDICULAR, '[', mCon }, { 1, "Same Orient&ation\tX", MNU_ORIENTED_SAME, 'X', mCon }, +{ 1, "Lock Point Where &Dragged\t]", MNU_WHERE_DRAGGED, ']', mCon }, { 1, NULL, 0, NULL }, { 1, "Comment\t;", MNU_COMMENT, ';', mCon }, diff --git a/sketch.h b/sketch.h index 17cac4d5..3e4361b0 100644 --- a/sketch.h +++ b/sketch.h @@ -545,6 +545,7 @@ public: static const int ARC_LINE_TANGENT = 123; static const int CUBIC_LINE_TANGENT = 124; static const int EQUAL_RADIUS = 130; + static const int WHERE_DRAGGED = 200; static const int COMMENT = 1000; diff --git a/toolbar.cpp b/toolbar.cpp index 9eee4d69..77ddcae7 100644 --- a/toolbar.cpp +++ b/toolbar.cpp @@ -11,7 +11,7 @@ static const struct { { Icon_rectangle, GraphicsWindow::MNU_RECTANGLE, "Sketch rectangle" }, { Icon_circle, GraphicsWindow::MNU_CIRCLE, "Sketch circle" }, { Icon_arc, GraphicsWindow::MNU_ARC, "Sketch arc, or tangent arc at selected point" }, - { Icon_bezier, GraphicsWindow::MNU_CUBIC, "Sketch cubic Bezier section" }, + { Icon_bezier, GraphicsWindow::MNU_CUBIC, "Sketch cubic Bezier spline" }, { Icon_point, GraphicsWindow::MNU_DATUM_POINT, "Sketch datum point" }, { Icon_construction, GraphicsWindow::MNU_CONSTRUCTION, "Toggle construction" }, { Icon_trim, GraphicsWindow::MNU_SPLIT_CURVES, "Split lines / curves where they intersect" }, diff --git a/ui.h b/ui.h index bc36601c..fa8f1a86 100644 --- a/ui.h +++ b/ui.h @@ -363,6 +363,7 @@ public: MNU_PARALLEL, MNU_PERPENDICULAR, MNU_ORIENTED_SAME, + MNU_WHERE_DRAGGED, MNU_COMMENT, // Analyze MNU_VOLUME, diff --git a/wishlist.txt b/wishlist.txt index cf7e981d..58ecfe86 100644 --- a/wishlist.txt +++ b/wishlist.txt @@ -1,7 +1,6 @@ add checked/unchecked checkbox and radio button fix bug with rotation in plane where green line stays displayed -lock point where dragged constraint -expose transformed point stuff in library, and email McNeel +expose transformed point stuff in library ----- rounding, as a special group