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]
This commit is contained in:
Jonathan Westhues 2008-06-12 00:58:58 -08:00
parent 650e9db150
commit 9bba9425be
12 changed files with 62 additions and 14 deletions

View File

@ -29,6 +29,7 @@ char *Constraint::DescriptionString(void) {
case ANGLE: s = "angle"; break; case ANGLE: s = "angle"; break;
case PARALLEL: s = "parallel"; break; case PARALLEL: s = "parallel"; break;
case EQUAL_RADIUS: s = "eq-radius"; break; case EQUAL_RADIUS: s = "eq-radius"; break;
case COMMENT: s = "comment"; break;
default: s = "???"; break; default: s = "???"; break;
} }
@ -311,7 +312,7 @@ void Constraint::MenuConstrain(int id) {
case GraphicsWindow::MNU_REFERENCE: case GraphicsWindow::MNU_REFERENCE:
if(gs.constraints == 1 && gs.n == 0) { if(gs.constraints == 1 && gs.n == 0) {
Constraint *c = SS.GetConstraint(gs.constraint[0]); Constraint *c = SS.GetConstraint(gs.constraint[0]);
if(c->HasLabel()) { if(c->HasLabel() && c->type != COMMENT) {
(c->reference) = !(c->reference); (c->reference) = !(c->reference);
SS.GetGroup(c->group)->clean = false; SS.GetGroup(c->group)->clean = false;
SS.GenerateAll(); SS.GenerateAll();
@ -348,6 +349,13 @@ void Constraint::MenuConstrain(int id) {
AddConstraint(&c); AddConstraint(&c);
break; 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: case GraphicsWindow::MNU_SOLVE_NOW:
SS.ReloadAllImported(); SS.ReloadAllImported();
SS.GenerateAll(0, INT_MAX); SS.GenerateAll(0, INT_MAX);
@ -856,6 +864,9 @@ void Constraint::GenerateReal(IdList<Equation,hEquation> *l) {
break; break;
} }
case COMMENT:
break;
default: oops(); default: oops();
} }
} }

View File

@ -555,20 +555,29 @@ void GraphicsWindow::MouseLeftDoubleClick(double mx, double my) {
Vector p3 = c->GetLabelPos(); Vector p3 = c->GetLabelPos();
Point2d p2 = ProjectPoint(p3); 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) { 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); Expr *e = Expr::From(s);
if(e) { if(e) {
SS.UndoRemember(); SS.UndoRemember();
Constraint *c = SS.GetConstraint(constraintBeingEdited);
Expr::FreeKeep(&(c->exprA)); Expr::FreeKeep(&(c->exprA));
c->exprA = e->DeepCopyKeep(); c->exprA = e->DeepCopyKeep();
HideGraphicsEditControl();
SS.MarkGroupDirty(c->group); SS.MarkGroupDirty(c->group);
SS.GenerateAll(); SS.GenerateAll();
} else { } else {

View File

@ -9,6 +9,7 @@ bool Constraint::HasLabel(void) {
case DIAMETER: case DIAMETER:
case LENGTH_RATIO: case LENGTH_RATIO:
case ANGLE: case ANGLE:
case COMMENT:
return true; return true;
default: default:
@ -46,6 +47,8 @@ char *Constraint::Label(void) {
sprintf(Ret, "%.2f", exprA->Eval()); sprintf(Ret, "%.2f", exprA->Eval());
} else if(type == LENGTH_RATIO) { } else if(type == LENGTH_RATIO) {
sprintf(Ret, "%.3f:1", exprA->Eval()); sprintf(Ret, "%.3f:1", exprA->Eval());
} else if(type == COMMENT) {
strcpy(Ret, comment.str);
} else { } else {
// exprA has units of distance // exprA has units of distance
strcpy(Ret, SS.GW.ToString(exprA->Eval())); 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) { void Constraint::DoLabel(Vector ref, Vector *labelPos, Vector gr, Vector gu) {
char *s = Label(); char *s = Label();
double swidth = glxStrWidth(s), sheight = glxStrHeight();
if(labelPos) { if(labelPos) {
// labelPos is from the top left corner (for the text box used to // labelPos is from the top left corner (for the text box used to
// edit things), but ref is from the center. // edit things), but ref is from the center.
*labelPos = ref.Minus(gr.WithMagnitude(glxStrWidth(s)/2)).Minus( *labelPos = ref.Minus(gr.WithMagnitude(swidth/2)).Minus(
gu.WithMagnitude(glxStrHeight()/2)); gu.WithMagnitude(sheight/2));
} }
if(dogd.drawing) { if(dogd.drawing) {
@ -72,8 +76,12 @@ void Constraint::DoLabel(Vector ref, Vector *labelPos, Vector gr, Vector gu) {
glxWriteTextRefCenter(s); glxWriteTextRefCenter(s);
glPopMatrix(); glPopMatrix();
} else { } else {
Point2d o = SS.GW.ProjectPoint(ref); double l = swidth/2 - sheight/2;
dogd.dmin = min(dogd.dmin, o.DistanceTo(dogd.mp) - 10); 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; dogd.refp = ref;
} }
} }
@ -532,6 +540,10 @@ s:
} }
break; break;
case COMMENT:
DoLabel(disp.offset, labelPos, gr, gu);
break;
default: oops(); default: oops();
} }
} }

View File

@ -114,7 +114,8 @@ bool Entity::IsVisible(void) {
if(!g->visible) return false; if(!g->visible) return false;
if(SS.GroupsInOrder(SS.GW.activeGroup, group)) 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(IsWorkplane() && !SS.GW.showWorkplanes) return false;
if(IsNormal() && !SS.GW.showNormals) return false; if(IsNormal() && !SS.GW.showNormals) return false;

2
dsc.h
View File

@ -212,7 +212,7 @@ public:
class NameStr { class NameStr {
public: public:
char str[20]; char str[64];
inline void strcpy(char *in) { inline void strcpy(char *in) {
memcpy(str, in, min(strlen(in)+1, sizeof(str))); memcpy(str, in, min(strlen(in)+1, sizeof(str)));

View File

@ -142,6 +142,7 @@ const SolveSpace::SaveTable SolveSpace::SAVED[] = {
{ 'c', "Constraint.entityB.v", 'x', &(SS.sv.c.entityB.v) }, { 'c', "Constraint.entityB.v", 'x', &(SS.sv.c.entityB.v) },
{ 'c', "Constraint.otherAngle", 'b', &(SS.sv.c.otherAngle) }, { 'c', "Constraint.otherAngle", 'b', &(SS.sv.c.otherAngle) },
{ 'c', "Constraint.reference", 'b', &(SS.sv.c.reference) }, { '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.x", 'f', &(SS.sv.c.disp.offset.x) },
{ 'c', "Constraint.disp.offset.y", 'f', &(SS.sv.c.disp.offset.y) }, { 'c', "Constraint.disp.offset.y", 'f', &(SS.sv.c.disp.offset.y) },
{ 'c', "Constraint.disp.offset.z", 'f', &(SS.sv.c.disp.offset.z) }, { 'c', "Constraint.disp.offset.z", 'f', &(SS.sv.c.disp.offset.z) },

View File

@ -5,7 +5,7 @@
static bool ColorLocked; static bool ColorLocked;
#define FONT_SCALE (0.5) #define FONT_SCALE (0.55)
double glxStrWidth(char *str) { double glxStrWidth(char *str) {
int w = 0; int w = 0;
for(; *str; str++) { for(; *str; str++) {

View File

@ -81,6 +81,8 @@ const GraphicsWindow::MenuEntry GraphicsWindow::menu[] = {
{ 1, "Para&llel\tShift+L", MNU_PARALLEL, 'L'|S, mCon }, { 1, "Para&llel\tShift+L", MNU_PARALLEL, 'L'|S, mCon },
{ 1, "Same Orient&ation\tShift+A", MNU_ORIENTED_SAME, 'A'|S, mCon }, { 1, "Same Orient&ation\tShift+A", MNU_ORIENTED_SAME, 'A'|S, mCon },
{ 1, NULL, 0, NULL }, { 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 }, { 1, "Solve Once Now\tSpace", MNU_SOLVE_NOW, ' ', mCon },
{ 0, "&Help", 0, NULL }, { 0, "&Help", 0, NULL },

View File

@ -430,6 +430,8 @@ public:
static const int PARALLEL = 121; static const int PARALLEL = 121;
static const int EQUAL_RADIUS = 130; static const int EQUAL_RADIUS = 130;
static const int COMMENT = 1000;
int tag; int tag;
hConstraint h; hConstraint h;
@ -449,6 +451,8 @@ public:
bool reference; // a ref dimension, that generates no eqs 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. // These define how the constraint is drawn on-screen.
struct { struct {
Vector offset; Vector offset;

View File

@ -96,14 +96,15 @@ void SolveSpace::AfterNewFile(void) {
GW.Init(); GW.Init();
unsaved = false; unsaved = false;
GenerateAll(0, INT_MAX);
later.showTW = true;
int w, h; int w, h;
GetGraphicsWindowSize(&w, &h); GetGraphicsWindowSize(&w, &h);
GW.width = w; GW.width = w;
GW.height = h; GW.height = h;
GW.ZoomToFit(); GW.ZoomToFit();
GenerateAll(0, INT_MAX);
later.showTW = true;
} }
void SolveSpace::MarkGroupDirtyByEntity(hEntity he) { void SolveSpace::MarkGroupDirtyByEntity(hEntity he) {

1
ui.h
View File

@ -178,6 +178,7 @@ public:
MNU_VERTICAL, MNU_VERTICAL,
MNU_PARALLEL, MNU_PARALLEL,
MNU_ORIENTED_SAME, MNU_ORIENTED_SAME,
MNU_COMMENT,
MNU_SOLVE_NOW, MNU_SOLVE_NOW,
} MenuId; } MenuId;
typedef void MenuHandler(int id); typedef void MenuHandler(int id);

View File

@ -8,6 +8,12 @@ display with proper formatting/units
some kind of rounding / chamfer some kind of rounding / chamfer
remove back button in browser? remove back button in browser?
clean up user-created workplanes clean up user-created workplanes
incremental regen of entities?
graphic export graphic export
relative paths for import
auto-generate circles and faces when lathing
long term
-----
incremental regen of entities?