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