Fix memory corruption in the IdList stuff (stupid freeing), and

tweak the way that things are hidden and shown.

[git-p4: depot-paths = "//depot/solvespace/": change = 1664]
solver
Jonathan Westhues 2008-04-12 08:28:48 -08:00
parent d36c70216a
commit d76e708c17
7 changed files with 58 additions and 25 deletions

3
dsc.h
View File

@ -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;
}
};

View File

@ -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();

View File

@ -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();
}

View File

@ -17,14 +17,17 @@ char *Group::DescriptionString(void) {
return ret;
}
void Request::AddParam(Entity *e, int index) {
void Request::AddParam(IdList<Param,hParam> *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,hEntity> *entity,
IdList<Point,hPoint> *point,
IdList<Param,hParam> *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);

View File

@ -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,hParam> *param, Entity *e, int index);
void Generate(IdList<Entity,hEntity> *entity,
IdList<Point,hPoint> *point,
IdList<Param,hParam> *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; }

View File

@ -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, &param);
}
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) {
}

View File

@ -60,6 +60,9 @@ public:
hGroup activeGroup;
void GenerateForUserInterface(void);
void ForceReferences(void);
void Init(void);
void Solve(void);
};