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:
parent
650e9db150
commit
9bba9425be
@ -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<Equation,hEquation> *l) {
|
||||
break;
|
||||
}
|
||||
|
||||
case COMMENT:
|
||||
break;
|
||||
|
||||
default: oops();
|
||||
}
|
||||
}
|
||||
|
15
draw.cpp
15
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 {
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
|
2
dsc.h
2
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)));
|
||||
|
1
file.cpp
1
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) },
|
||||
|
@ -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++) {
|
||||
|
@ -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 },
|
||||
|
4
sketch.h
4
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;
|
||||
|
@ -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) {
|
||||
|
1
ui.h
1
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);
|
||||
|
@ -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?
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user