Put information about which requests generate which entities, and

how many points are associated with each, into a single table.

[git-p4: depot-paths = "//depot/solvespace/": change = 2056]
solver
Jonathan Westhues 2009-10-22 06:02:08 -08:00
parent 2ca5334bdf
commit 0914a27ff4
6 changed files with 120 additions and 123 deletions

View File

@ -634,7 +634,7 @@ void Group::CopyEntity(IdList<Entity,hEntity> *el,
bool asTrans, bool asAxisAngle) bool asTrans, bool asAxisAngle)
{ {
Entity en; Entity en;
memset(&en, 0, sizeof(en)); ZERO(&en);
en.type = ep->type; en.type = ep->type;
en.extraPoints = ep->extraPoints; en.extraPoints = ep->extraPoints;
en.h = Remap(ep->h, remap); en.h = Remap(ep->h, remap);
@ -642,53 +642,14 @@ void Group::CopyEntity(IdList<Entity,hEntity> *el,
en.group = h; en.group = h;
en.construction = ep->construction; en.construction = ep->construction;
en.style = ep->style; en.style = ep->style;
en.str.strcpy(ep->str.str);
en.font.strcpy(ep->font.str);
switch(ep->type) { switch(ep->type) {
case Entity::WORKPLANE: case Entity::WORKPLANE:
// Don't copy these. // Don't copy these.
return; return;
case Entity::LINE_SEGMENT:
en.point[0] = Remap(ep->point[0], remap);
en.point[1] = Remap(ep->point[1], remap);
break;
case Entity::CUBIC: {
int i;
for(i = 0; i < 4 + ep->extraPoints; i++) {
en.point[i] = Remap(ep->point[i], remap);
}
break;
}
case Entity::CUBIC_PERIODIC: {
int i;
for(i = 0; i < 3 + ep->extraPoints; i++) {
en.point[i] = Remap(ep->point[i], remap);
}
break;
}
case Entity::CIRCLE:
en.point[0] = Remap(ep->point[0], remap);
en.normal = Remap(ep->normal, remap);
en.distance = Remap(ep->distance, remap);
break;
case Entity::ARC_OF_CIRCLE:
en.point[0] = Remap(ep->point[0], remap);
en.point[1] = Remap(ep->point[1], remap);
en.point[2] = Remap(ep->point[2], remap);
en.normal = Remap(ep->normal, remap);
break;
case Entity::TTF_TEXT:
en.point[0] = Remap(ep->point[0], remap);
en.point[1] = Remap(ep->point[1], remap);
en.normal = Remap(ep->normal, remap);
en.str.strcpy(ep->str.str);
en.font.strcpy(ep->font.str);
break;
case Entity::POINT_N_COPY: case Entity::POINT_N_COPY:
case Entity::POINT_N_TRANS: case Entity::POINT_N_TRANS:
case Entity::POINT_N_ROT_TRANS: case Entity::POINT_N_ROT_TRANS:
@ -781,8 +742,18 @@ void Group::CopyEntity(IdList<Entity,hEntity> *el,
} }
break; break;
default: default: {
oops(); int i, points;
bool hasNormal, hasDistance;
EntReqTable::GetEntityInfo(ep->type, ep->extraPoints,
NULL, &points, &hasNormal, &hasDistance);
for(i = 0; i < points; i++) {
en.point[i] = Remap(ep->point[i], remap);
}
if(hasNormal) en.normal = Remap(ep->normal, remap);
if(hasDistance) en.distance = Remap(ep->distance, remap);
break;
}
} }
// If the entity came from an imported file where it was invisible then // If the entity came from an imported file where it was invisible then

View File

@ -351,17 +351,9 @@ hEntity GraphicsWindow::SplitEntity(hEntity he, Vector pinter) {
} }
// Finally, delete the request that generated the original entity. // Finally, delete the request that generated the original entity.
int reqType; int reqType = EntReqTable::GetRequestForEntity(entityType);
switch(entityType) {
case Entity::CIRCLE: reqType = Request::CIRCLE; break;
case Entity::ARC_OF_CIRCLE: reqType = Request::ARC_OF_CIRCLE; break;
case Entity::LINE_SEGMENT: reqType = Request::LINE_SEGMENT; break;
case Entity::CUBIC: reqType = Request::CUBIC; break;
default: oops();
}
int i;
SK.request.ClearTags(); SK.request.ClearTags();
for(i = 0; i < SK.request.n; i++) { for(int i = 0; i < SK.request.n; i++) {
Request *r = &(SK.request.elem[i]); Request *r = &(SK.request.elem[i]);
if(r->group.v != activeGroup.v) continue; if(r->group.v != activeGroup.v) continue;
if(r->type != reqType) continue; if(r->type != reqType) continue;

View File

@ -645,9 +645,14 @@ void GraphicsWindow::MouseLeftDown(double mx, double my) {
} }
case MNU_CIRCLE: case MNU_CIRCLE:
hr = AddRequest(Request::CIRCLE); hr = AddRequest(Request::CIRCLE);
// Centered where we clicked
SK.GetEntity(hr.entity(1))->PointForceTo(v); SK.GetEntity(hr.entity(1))->PointForceTo(v);
// Normal to the screen
SK.GetEntity(hr.entity(32))->NormalForceTo( SK.GetEntity(hr.entity(32))->NormalForceTo(
Quaternion::From(SS.GW.projRight, SS.GW.projUp)); Quaternion::From(SS.GW.projRight, SS.GW.projUp));
// Initial radius zero
SK.GetEntity(hr.entity(64))->DistanceForceTo(0);
ConstrainPointByHovered(hr.entity(1)); ConstrainPointByHovered(hr.entity(1));
ClearSuper(); ClearSuper();
@ -655,7 +660,6 @@ void GraphicsWindow::MouseLeftDown(double mx, double my) {
pending.operation = DRAGGING_NEW_RADIUS; pending.operation = DRAGGING_NEW_RADIUS;
pending.circle = hr.entity(0); pending.circle = hr.entity(0);
pending.description = "click to set radius"; pending.description = "click to set radius";
SK.GetParam(hr.param(0))->val = 0;
break; break;
case MNU_ARC: { case MNU_ARC: {

View File

@ -4,68 +4,89 @@ const hRequest Request::HREQUEST_REFERENCE_XY = { 1 };
const hRequest Request::HREQUEST_REFERENCE_YZ = { 2 }; const hRequest Request::HREQUEST_REFERENCE_YZ = { 2 };
const hRequest Request::HREQUEST_REFERENCE_ZX = { 3 }; const hRequest Request::HREQUEST_REFERENCE_ZX = { 3 };
const EntReqTable::TableEntry EntReqTable::Table[] = {
// request type entity type pts xtra? norml dist description
{ Request::WORKPLANE, Entity::WORKPLANE, 1, false, true, false, "workplane" },
{ Request::DATUM_POINT, 0, 1, false, false, false, "datum-point" },
{ Request::LINE_SEGMENT, Entity::LINE_SEGMENT, 2, false, false, false, "line-segment" },
{ Request::CUBIC, Entity::CUBIC, 4, true, false, false, "cubic-bezier" },
{ Request::CUBIC_PERIODIC, Entity::CUBIC_PERIODIC, 3, true, false, false, "periodic-cubic" },
{ Request::CIRCLE, Entity::CIRCLE, 1, false, true, true, "circle" },
{ Request::ARC_OF_CIRCLE, Entity::ARC_OF_CIRCLE, 3, false, true, false, "arc-of-circle" },
{ Request::TTF_TEXT, Entity::TTF_TEXT, 2, false, true, false, "ttf-text" },
{ 0 },
};
char *EntReqTable::DescriptionForRequest(int req) {
for(int i = 0; Table[i].reqType; i++) {
if(req == Table[i].reqType) {
return Table[i].description;
}
}
return "???";
}
void EntReqTable::CopyEntityInfo(const TableEntry *te, int extraPoints,
int *ent, int *req, int *pts, bool *hasNormal, bool *hasDistance)
{
int points = te->points;
if(te->useExtraPoints) points += extraPoints;
if(ent) *ent = te->entType;
if(req) *req = te->reqType;
if(pts) *pts = points;
if(hasNormal) *hasNormal = te->hasNormal;
if(hasDistance) *hasDistance = te->hasDistance;
}
void EntReqTable::GetRequestInfo(int req, int extraPoints,
int *ent, int *pts, bool *hasNormal, bool *hasDistance)
{
for(int i = 0; Table[i].reqType; i++) {
const TableEntry *te = &(Table[i]);
if(req == te->reqType) {
CopyEntityInfo(te, extraPoints,
ent, NULL, pts, hasNormal, hasDistance);
return;
}
}
oops();
}
void EntReqTable::GetEntityInfo(int ent, int extraPoints,
int *req, int *pts, bool *hasNormal, bool *hasDistance)
{
for(int i = 0; Table[i].reqType; i++) {
const TableEntry *te = &(Table[i]);
if(ent == te->entType) {
CopyEntityInfo(te, extraPoints,
NULL, req, pts, hasNormal, hasDistance);
return;
}
}
oops();
}
int EntReqTable::GetRequestForEntity(int ent) {
int req;
GetEntityInfo(ent, 0, &req, NULL, NULL, NULL);
return req;
}
void Request::Generate(IdList<Entity,hEntity> *entity, void Request::Generate(IdList<Entity,hEntity> *entity,
IdList<Param,hParam> *param) IdList<Param,hParam> *param)
{ {
int points = 0; int points = 0;
int params = 0;
int et = 0; int et = 0;
bool hasNormal = false; bool hasNormal = false;
bool hasDistance = false; bool hasDistance = false;
int i; int i;
Entity e; Entity e;
memset(&e, 0, sizeof(e)); ZERO(&e);
switch(type) { EntReqTable::GetRequestInfo(type, extraPoints,
case Request::WORKPLANE: &et, &points, &hasNormal, &hasDistance);
et = Entity::WORKPLANE;
points = 1;
hasNormal = true;
break;
case Request::DATUM_POINT:
et = 0;
points = 1;
break;
case Request::LINE_SEGMENT:
et = Entity::LINE_SEGMENT;
points = 2;
break;
case Request::CIRCLE:
et = Entity::CIRCLE;
points = 1;
params = 1;
hasNormal = true;
hasDistance = true;
break;
case Request::ARC_OF_CIRCLE:
et = Entity::ARC_OF_CIRCLE;
points = 3;
hasNormal = true;
break;
case Request::CUBIC:
et = Entity::CUBIC;
points = 4 + extraPoints;
break;
case Request::CUBIC_PERIODIC:
et = Entity::CUBIC_PERIODIC;
points = 3 + extraPoints;
break;
case Request::TTF_TEXT:
et = Entity::TTF_TEXT;
points = 2;
hasNormal = true;
break;
default: oops();
}
// Generate the entity that's specific to this request. // Generate the entity that's specific to this request.
e.type = et; e.type = et;
@ -140,11 +161,6 @@ void Request::Generate(IdList<Entity,hEntity> *entity,
entity->Add(&d); entity->Add(&d);
e.distance = d.h; e.distance = d.h;
} }
// And generate any params not associated with the point that
// we happen to need.
for(i = 0; i < params; i++) {
e.param[i] = AddParam(param, h.param(i));
}
if(et) entity->Add(&e); if(et) entity->Add(&e);
} }
@ -158,17 +174,7 @@ char *Request::DescriptionString(void) {
} else if(h.v == Request::HREQUEST_REFERENCE_ZX.v) { } else if(h.v == Request::HREQUEST_REFERENCE_ZX.v) {
s = "#ZX"; s = "#ZX";
} else { } else {
switch(type) { s = EntReqTable::DescriptionForRequest(type);
case WORKPLANE: s = "workplane"; break;
case DATUM_POINT: s = "datum-point"; break;
case LINE_SEGMENT: s = "line-segment"; break;
case CUBIC: s = "cubic-bezier"; break;
case CUBIC_PERIODIC: s = "periodic-cubic"; break;
case CIRCLE: s = "circle"; break;
case ARC_OF_CIRCLE: s = "arc-of-circle"; break;
case TTF_TEXT: s = "ttf-text"; break;
default: s = "???"; break;
}
} }
static char ret[100]; static char ret[100];
sprintf(ret, "r%03x-%s", h.v, s); sprintf(ret, "r%03x-%s", h.v, s);

View File

@ -446,6 +446,30 @@ public:
char *DescriptionString(void); char *DescriptionString(void);
}; };
class EntReqTable {
public:
typedef struct {
int reqType;
int entType;
int points;
bool useExtraPoints;
bool hasNormal;
bool hasDistance;
char *description;
} TableEntry;
static const TableEntry Table[];
static char *DescriptionForRequest(int req);
static void CopyEntityInfo(const TableEntry *te, int extraPoints,
int *ent, int *req, int *pts, bool *hasNormal, bool *hasDistance);
static void GetRequestInfo(int req, int extraPoints,
int *ent, int *pts, bool *hasNormal, bool *hasDistance);
static void GetEntityInfo(int ent, int extraPoints,
int *req, int *pts, bool *hasNormal, bool *hasDistance);
static int GetRequestForEntity(int ent);
};
class Param { class Param {
public: public:
int tag; int tag;

View File

@ -1,11 +1,11 @@
multi-drag multi-drag
copy and paste copy and paste
filled contours for export
associative entities from solid model, as a special group associative entities from solid model, as a special group
----- -----
some kind of import some kind of import
filled contours for export
faster triangulation faster triangulation
loop detection loop detection
IGES export IGES export