diff --git a/dsc.h b/dsc.h index 9b5b4c12..249fc4cf 100644 --- a/dsc.h +++ b/dsc.h @@ -84,7 +84,7 @@ public: return &(elem[i].t); } } - dbp("failed to look up item %16lx, searched %d items", h.v); + dbp("failed to look up item %16lx, searched %d items", h.v, elems); oops(); } @@ -115,6 +115,7 @@ public: void Clear(void) { elemsAllocated = elems = 0; if(elem) free(elem); + elem = NULL; } }; diff --git a/entity.cpp b/entity.cpp index 030c0e88..55b64223 100644 --- a/entity.cpp +++ b/entity.cpp @@ -31,10 +31,9 @@ double Entity::GetDistance(Point2d mp) { } void Entity::DrawOrGetDistance(void) { + if(!visible) return; switch(type) { case CSYS_2D: { - if(!SS.GW.show2dCsyss) break; - Vector p; p = SS.point.FindById(point(16))->GetCoords(); diff --git a/graphicswin.cpp b/graphicswin.cpp index 96afb21b..ca75c443 100644 --- a/graphicswin.cpp +++ b/graphicswin.cpp @@ -302,6 +302,7 @@ void GraphicsWindow::ToggleBool(int link, DWORD v) { bool *vb = (bool *)v; *vb = !*vb; + SS.GenerateForUserInterface(); InvalidateGraphics(); SS.TW.Show(); } @@ -312,6 +313,7 @@ void GraphicsWindow::ToggleAnyDatumShown(int link, DWORD v) { SS.GW.showAxes = t; SS.GW.showPoints = t; + SS.GenerateForUserInterface(); InvalidateGraphics(); SS.TW.Show(); } diff --git a/sketch.cpp b/sketch.cpp index 1ef1d0cb..397e933e 100644 --- a/sketch.cpp +++ b/sketch.cpp @@ -17,14 +17,17 @@ char *Group::DescriptionString(void) { return ret; } -void Request::AddParam(Entity *e, int index) { +void Request::AddParam(IdList *param, Entity *e, int index) { Param pa; memset(&pa, 0, sizeof(pa)); pa.h = e->param(index); - SS.param.Add(&pa); + param->Add(&pa); } -void Request::Generate(void) { +void Request::Generate(IdList *entity, + IdList *point, + IdList *param) +{ int points = 0; int params = 0; int type = 0; @@ -36,16 +39,19 @@ void Request::Generate(void) { memset(&e, 0, sizeof(e)); e.h = this->entity(0); + bool shown = true; switch(type) { case Request::CSYS_2D: - type = Entity::CSYS_2D; points = 1; params = 4; goto c; + type = Entity::CSYS_2D; points = 1; params = 4; + if(!SS.GW.show2dCsyss) shown = false; + goto c; case Request::LINE_SEGMENT: type = Entity::LINE_SEGMENT; points = 2; params = 0; goto c; c: { // Common routines, for all the requests that generate a single // entity that's defined by a simple combination of pts and params. for(i = 0; i < params; i++) { - AddParam(&e, i); + AddParam(param, &e, i); } for(i = 0; i < points; i++) { Point pt; @@ -54,21 +60,23 @@ c: { if(g->csys.v == Entity::NO_CSYS.v) { pt.type = Point::IN_FREE_SPACE; // params for x y z - AddParam(&e, 16 + 3*i + 0); - AddParam(&e, 16 + 3*i + 1); - AddParam(&e, 16 + 3*i + 2); + AddParam(param, &e, 16 + 3*i + 0); + AddParam(param, &e, 16 + 3*i + 1); + AddParam(param, &e, 16 + 3*i + 2); } else { pt.type = Point::IN_2D_CSYS; pt.csys = g->csys; // params for u v - AddParam(&e, 16 + 3*i + 0); - AddParam(&e, 16 + 3*i + 1); + AddParam(param, &e, 16 + 3*i + 0); + AddParam(param, &e, 16 + 3*i + 1); } - SS.point.Add(&pt); + pt.visible = shown; + point->Add(&pt); } e.type = type; - SS.entity.Add(&e); + e.visible = shown; + entity->Add(&e); break; } @@ -122,6 +130,8 @@ Vector Point::GetCoords(void) { } void Point::Draw(void) { + if(!visible) return; + Vector v = GetCoords(); double s = 4; @@ -137,6 +147,8 @@ void Point::Draw(void) { } double Point::GetDistance(Point2d mp) { + if(!visible) return 1e12; + Vector v = GetCoords(); Point2d pp = SS.GW.ProjectPoint(v); diff --git a/sketch.h b/sketch.h index d4b054f4..0f98a38a 100644 --- a/sketch.h +++ b/sketch.h @@ -2,13 +2,15 @@ #ifndef __SKETCH_H #define __SKETCH_H -class hEntity; -class hPoint; -class hRequest; -class hParam; class hGroup; +class hRequest; +class hEntity; +class hParam; +class hPoint; class Entity; +class Param; +class Point; // All of the hWhatever handles are a 32-bit ID, that is used to represent // some data structure in the sketch. @@ -83,8 +85,10 @@ public: inline hEntity entity(int i) { hEntity r; r.v = ((this->h.v) << 11) | i; return r; } - void AddParam(Entity *e, int index); - void Generate(void); + void AddParam(IdList *param, Entity *e, int index); + void Generate(IdList *entity, + IdList *point, + IdList *param); char *DescriptionString(void); }; @@ -99,6 +103,8 @@ public: hEntity h; + bool visible; + Expr *expr[16]; inline hRequest request(void) @@ -139,6 +145,7 @@ public: static const int BY_EXPR = 2; // three Expr *, could be anything hEntity csys; + bool visible; inline hEntity entity(void) { hEntity r; r.v = (h.v >> 8); return r; } diff --git a/solvespace.cpp b/solvespace.cpp index 4ee4fcbc..90ce6d84 100644 --- a/solvespace.cpp +++ b/solvespace.cpp @@ -49,17 +49,23 @@ void SolveSpace::Init(void) { request.Add(&r); TW.Show(); - Solve(); + GenerateForUserInterface(); } -void SolveSpace::Solve(void) { +void SolveSpace::GenerateForUserInterface(void) { int i; entity.Clear(); + param.Clear(); + point.Clear(); for(i = 0; i < request.elems; i++) { - request.elem[i].t.Generate(); + request.elem[i].t.Generate(&entity, &point, ¶m); } + ForceReferences(); +} + +void SolveSpace::ForceReferences(void) { // Force the values of the paramters that define the three reference // coordinate systems. static const struct { @@ -70,7 +76,7 @@ void SolveSpace::Solve(void) { { Request::HREQUEST_REFERENCE_YZ, 0.5, -0.5, -0.5, -0.5, }, { Request::HREQUEST_REFERENCE_ZX, 0.5, 0.5, 0.5, 0.5, }, }; - for(i = 0; i < 3; i++) { + for(int i = 0; i < 3; i++) { hEntity he; he = request.FindById(Quat[i].hr)->entity(0); Entity *e = entity.FindById(he); @@ -85,3 +91,6 @@ void SolveSpace::Solve(void) { } } +void SolveSpace::Solve(void) { +} + diff --git a/solvespace.h b/solvespace.h index 3bc3fd46..6a99a1a7 100644 --- a/solvespace.h +++ b/solvespace.h @@ -60,6 +60,9 @@ public: hGroup activeGroup; + void GenerateForUserInterface(void); + void ForceReferences(void); + void Init(void); void Solve(void); };