From 9bba9425be892d51f1b810610b3203e0a1544301 Mon Sep 17 00:00:00 2001 From: Jonathan Westhues Date: Thu, 12 Jun 2008 00:58:58 -0800 Subject: [PATCH] Add a special constraint type for comments; no equations, just user-visible text. And make points hoverable/selectable even when GW.showPoints is false, and zoom to fit before regenerating on file open, because then we're at the right zoom level (and will use the right pwl tolerance). [git-p4: depot-paths = "//depot/solvespace/": change = 1788] --- constraint.cpp | 13 ++++++++++++- draw.cpp | 15 ++++++++++++--- drawconstraint.cpp | 20 ++++++++++++++++---- drawentity.cpp | 3 ++- dsc.h | 2 +- file.cpp | 1 + glhelper.cpp | 2 +- graphicswin.cpp | 2 ++ sketch.h | 4 ++++ solvespace.cpp | 5 +++-- ui.h | 1 + wishlist.txt | 8 +++++++- 12 files changed, 62 insertions(+), 14 deletions(-) diff --git a/constraint.cpp b/constraint.cpp index 9c60c0c..f5b7abe 100644 --- a/constraint.cpp +++ b/constraint.cpp @@ -29,6 +29,7 @@ char *Constraint::DescriptionString(void) { case ANGLE: s = "angle"; break; case PARALLEL: s = "parallel"; break; case EQUAL_RADIUS: s = "eq-radius"; break; + case COMMENT: s = "comment"; break; default: s = "???"; break; } @@ -311,7 +312,7 @@ void Constraint::MenuConstrain(int id) { case GraphicsWindow::MNU_REFERENCE: if(gs.constraints == 1 && gs.n == 0) { Constraint *c = SS.GetConstraint(gs.constraint[0]); - if(c->HasLabel()) { + if(c->HasLabel() && c->type != COMMENT) { (c->reference) = !(c->reference); SS.GetGroup(c->group)->clean = false; SS.GenerateAll(); @@ -348,6 +349,13 @@ void Constraint::MenuConstrain(int id) { AddConstraint(&c); break; + case GraphicsWindow::MNU_COMMENT: + c.type = COMMENT; + c.comment.strcpy("NEW COMMENT -- DOUBLE-CLICK TO EDIT"); + c.disp.offset = SS.GW.offset; + AddConstraint(&c); + break; + case GraphicsWindow::MNU_SOLVE_NOW: SS.ReloadAllImported(); SS.GenerateAll(0, INT_MAX); @@ -856,6 +864,9 @@ void Constraint::GenerateReal(IdList *l) { break; } + case COMMENT: + break; + default: oops(); } } diff --git a/draw.cpp b/draw.cpp index f73053d..5910ac5 100644 --- a/draw.cpp +++ b/draw.cpp @@ -555,20 +555,29 @@ void GraphicsWindow::MouseLeftDoubleClick(double mx, double my) { Vector p3 = c->GetLabelPos(); Point2d p2 = ProjectPoint(p3); - ShowGraphicsEditControl((int)p2.x, (int)p2.y, c->exprA->Print()); + char *s = (c->type == Constraint::COMMENT) ? c->comment.str : + c->exprA->Print(); + ShowGraphicsEditControl((int)p2.x, (int)p2.y, s); } } void GraphicsWindow::EditControlDone(char *s) { + HideGraphicsEditControl(); + Constraint *c = SS.GetConstraint(constraintBeingEdited); + + if(c->type == Constraint::COMMENT) { + SS.UndoRemember(); + c->comment.strcpy(s); + return; + } + Expr *e = Expr::From(s); if(e) { SS.UndoRemember(); - Constraint *c = SS.GetConstraint(constraintBeingEdited); Expr::FreeKeep(&(c->exprA)); c->exprA = e->DeepCopyKeep(); - HideGraphicsEditControl(); SS.MarkGroupDirty(c->group); SS.GenerateAll(); } else { diff --git a/drawconstraint.cpp b/drawconstraint.cpp index 9ad7728..85ac15d 100644 --- a/drawconstraint.cpp +++ b/drawconstraint.cpp @@ -9,6 +9,7 @@ bool Constraint::HasLabel(void) { case DIAMETER: case LENGTH_RATIO: case ANGLE: + case COMMENT: return true; default: @@ -46,6 +47,8 @@ char *Constraint::Label(void) { sprintf(Ret, "%.2f", exprA->Eval()); } else if(type == LENGTH_RATIO) { sprintf(Ret, "%.3f:1", exprA->Eval()); + } else if(type == COMMENT) { + strcpy(Ret, comment.str); } else { // exprA has units of distance strcpy(Ret, SS.GW.ToString(exprA->Eval())); @@ -58,11 +61,12 @@ char *Constraint::Label(void) { void Constraint::DoLabel(Vector ref, Vector *labelPos, Vector gr, Vector gu) { char *s = Label(); + double swidth = glxStrWidth(s), sheight = glxStrHeight(); if(labelPos) { // labelPos is from the top left corner (for the text box used to // edit things), but ref is from the center. - *labelPos = ref.Minus(gr.WithMagnitude(glxStrWidth(s)/2)).Minus( - gu.WithMagnitude(glxStrHeight()/2)); + *labelPos = ref.Minus(gr.WithMagnitude(swidth/2)).Minus( + gu.WithMagnitude(sheight/2)); } if(dogd.drawing) { @@ -72,8 +76,12 @@ void Constraint::DoLabel(Vector ref, Vector *labelPos, Vector gr, Vector gu) { glxWriteTextRefCenter(s); glPopMatrix(); } else { - Point2d o = SS.GW.ProjectPoint(ref); - dogd.dmin = min(dogd.dmin, o.DistanceTo(dogd.mp) - 10); + double l = swidth/2 - sheight/2; + Point2d a = SS.GW.ProjectPoint(ref.Minus(gr.WithMagnitude(l))); + Point2d b = SS.GW.ProjectPoint(ref.Plus (gr.WithMagnitude(l))); + double d = dogd.mp.DistanceToLine(a, b.Minus(a), true); + + dogd.dmin = min(dogd.dmin, d - 3); dogd.refp = ref; } } @@ -532,6 +540,10 @@ s: } break; + case COMMENT: + DoLabel(disp.offset, labelPos, gr, gu); + break; + default: oops(); } } diff --git a/drawentity.cpp b/drawentity.cpp index a60ad5e..ea4e2fd 100644 --- a/drawentity.cpp +++ b/drawentity.cpp @@ -114,7 +114,8 @@ bool Entity::IsVisible(void) { if(!g->visible) return false; if(SS.GroupsInOrder(SS.GW.activeGroup, group)) return false; - if(IsPoint() && !SS.GW.showPoints) return false; + // Don't check if points are hidden; this gets called only for + // selected or hovered points, and those should always be shown. if(IsWorkplane() && !SS.GW.showWorkplanes) return false; if(IsNormal() && !SS.GW.showNormals) return false; diff --git a/dsc.h b/dsc.h index 92f97f2..efce50a 100644 --- a/dsc.h +++ b/dsc.h @@ -212,7 +212,7 @@ public: class NameStr { public: - char str[20]; + char str[64]; inline void strcpy(char *in) { memcpy(str, in, min(strlen(in)+1, sizeof(str))); diff --git a/file.cpp b/file.cpp index 2362b15..9278bf0 100644 --- a/file.cpp +++ b/file.cpp @@ -142,6 +142,7 @@ const SolveSpace::SaveTable SolveSpace::SAVED[] = { { 'c', "Constraint.entityB.v", 'x', &(SS.sv.c.entityB.v) }, { 'c', "Constraint.otherAngle", 'b', &(SS.sv.c.otherAngle) }, { 'c', "Constraint.reference", 'b', &(SS.sv.c.reference) }, + { 'c', "Constraint.comment", 'N', &(SS.sv.c.comment) }, { 'c', "Constraint.disp.offset.x", 'f', &(SS.sv.c.disp.offset.x) }, { 'c', "Constraint.disp.offset.y", 'f', &(SS.sv.c.disp.offset.y) }, { 'c', "Constraint.disp.offset.z", 'f', &(SS.sv.c.disp.offset.z) }, diff --git a/glhelper.cpp b/glhelper.cpp index 87b2520..cad7e55 100644 --- a/glhelper.cpp +++ b/glhelper.cpp @@ -5,7 +5,7 @@ static bool ColorLocked; -#define FONT_SCALE (0.5) +#define FONT_SCALE (0.55) double glxStrWidth(char *str) { int w = 0; for(; *str; str++) { diff --git a/graphicswin.cpp b/graphicswin.cpp index a4a2e9c..ce17bec 100644 --- a/graphicswin.cpp +++ b/graphicswin.cpp @@ -81,6 +81,8 @@ const GraphicsWindow::MenuEntry GraphicsWindow::menu[] = { { 1, "Para&llel\tShift+L", MNU_PARALLEL, 'L'|S, mCon }, { 1, "Same Orient&ation\tShift+A", MNU_ORIENTED_SAME, 'A'|S, mCon }, { 1, NULL, 0, NULL }, +{ 1, "Comment\tShift+C", MNU_COMMENT, 'C'|S, mCon }, +{ 1, NULL, 0, NULL }, { 1, "Solve Once Now\tSpace", MNU_SOLVE_NOW, ' ', mCon }, { 0, "&Help", 0, NULL }, diff --git a/sketch.h b/sketch.h index 04fa75b..fb1d367 100644 --- a/sketch.h +++ b/sketch.h @@ -430,6 +430,8 @@ public: static const int PARALLEL = 121; static const int EQUAL_RADIUS = 130; + static const int COMMENT = 1000; + int tag; hConstraint h; @@ -449,6 +451,8 @@ public: bool reference; // a ref dimension, that generates no eqs + NameStr comment; // since comments are represented as constraints + // These define how the constraint is drawn on-screen. struct { Vector offset; diff --git a/solvespace.cpp b/solvespace.cpp index 8490107..36d45d7 100644 --- a/solvespace.cpp +++ b/solvespace.cpp @@ -96,14 +96,15 @@ void SolveSpace::AfterNewFile(void) { GW.Init(); unsaved = false; - GenerateAll(0, INT_MAX); - later.showTW = true; int w, h; GetGraphicsWindowSize(&w, &h); GW.width = w; GW.height = h; GW.ZoomToFit(); + + GenerateAll(0, INT_MAX); + later.showTW = true; } void SolveSpace::MarkGroupDirtyByEntity(hEntity he) { diff --git a/ui.h b/ui.h index a8962ea..8c75ffe 100644 --- a/ui.h +++ b/ui.h @@ -178,6 +178,7 @@ public: MNU_VERTICAL, MNU_PARALLEL, MNU_ORIENTED_SAME, + MNU_COMMENT, MNU_SOLVE_NOW, } MenuId; typedef void MenuHandler(int id); diff --git a/wishlist.txt b/wishlist.txt index b1b0ee3..19e3c21 100644 --- a/wishlist.txt +++ b/wishlist.txt @@ -8,6 +8,12 @@ display with proper formatting/units some kind of rounding / chamfer remove back button in browser? clean up user-created workplanes -incremental regen of entities? graphic export +relative paths for import +auto-generate circles and faces when lathing + + +long term +----- +incremental regen of entities?