From 0914a27ff46e127e944cb5de86c1957b46d277fc Mon Sep 17 00:00:00 2001 From: Jonathan Westhues Date: Thu, 22 Oct 2009 06:02:08 -0800 Subject: [PATCH] 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] --- group.cpp | 59 ++++++---------------- modify.cpp | 12 +---- mouse.cpp | 6 ++- request.cpp | 140 +++++++++++++++++++++++++++------------------------ sketch.h | 24 +++++++++ wishlist.txt | 2 +- 6 files changed, 120 insertions(+), 123 deletions(-) diff --git a/group.cpp b/group.cpp index 62d200e..fa087f9 100644 --- a/group.cpp +++ b/group.cpp @@ -634,7 +634,7 @@ void Group::CopyEntity(IdList *el, bool asTrans, bool asAxisAngle) { Entity en; - memset(&en, 0, sizeof(en)); + ZERO(&en); en.type = ep->type; en.extraPoints = ep->extraPoints; en.h = Remap(ep->h, remap); @@ -642,53 +642,14 @@ void Group::CopyEntity(IdList *el, en.group = h; en.construction = ep->construction; en.style = ep->style; + en.str.strcpy(ep->str.str); + en.font.strcpy(ep->font.str); switch(ep->type) { case Entity::WORKPLANE: // Don't copy these. 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_TRANS: case Entity::POINT_N_ROT_TRANS: @@ -781,8 +742,18 @@ void Group::CopyEntity(IdList *el, } break; - default: - oops(); + default: { + 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 diff --git a/modify.cpp b/modify.cpp index 03963dc..1958cef 100644 --- a/modify.cpp +++ b/modify.cpp @@ -351,17 +351,9 @@ hEntity GraphicsWindow::SplitEntity(hEntity he, Vector pinter) { } // Finally, delete the request that generated the original entity. - int reqType; - 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; + int reqType = EntReqTable::GetRequestForEntity(entityType); 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]); if(r->group.v != activeGroup.v) continue; if(r->type != reqType) continue; diff --git a/mouse.cpp b/mouse.cpp index cb768e9..886655a 100644 --- a/mouse.cpp +++ b/mouse.cpp @@ -645,9 +645,14 @@ void GraphicsWindow::MouseLeftDown(double mx, double my) { } case MNU_CIRCLE: hr = AddRequest(Request::CIRCLE); + // Centered where we clicked SK.GetEntity(hr.entity(1))->PointForceTo(v); + // Normal to the screen SK.GetEntity(hr.entity(32))->NormalForceTo( Quaternion::From(SS.GW.projRight, SS.GW.projUp)); + // Initial radius zero + SK.GetEntity(hr.entity(64))->DistanceForceTo(0); + ConstrainPointByHovered(hr.entity(1)); ClearSuper(); @@ -655,7 +660,6 @@ void GraphicsWindow::MouseLeftDown(double mx, double my) { pending.operation = DRAGGING_NEW_RADIUS; pending.circle = hr.entity(0); pending.description = "click to set radius"; - SK.GetParam(hr.param(0))->val = 0; break; case MNU_ARC: { diff --git a/request.cpp b/request.cpp index 895c8ed..09b3a09 100644 --- a/request.cpp +++ b/request.cpp @@ -4,68 +4,89 @@ const hRequest Request::HREQUEST_REFERENCE_XY = { 1 }; const hRequest Request::HREQUEST_REFERENCE_YZ = { 2 }; 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, IdList *param) { int points = 0; - int params = 0; int et = 0; bool hasNormal = false; bool hasDistance = false; int i; Entity e; - memset(&e, 0, sizeof(e)); - switch(type) { - case Request::WORKPLANE: - 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(); - } + ZERO(&e); + EntReqTable::GetRequestInfo(type, extraPoints, + &et, &points, &hasNormal, &hasDistance); // Generate the entity that's specific to this request. e.type = et; @@ -140,11 +161,6 @@ void Request::Generate(IdList *entity, entity->Add(&d); 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); } @@ -158,17 +174,7 @@ char *Request::DescriptionString(void) { } else if(h.v == Request::HREQUEST_REFERENCE_ZX.v) { s = "#ZX"; } else { - switch(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; - } + s = EntReqTable::DescriptionForRequest(type); } static char ret[100]; sprintf(ret, "r%03x-%s", h.v, s); diff --git a/sketch.h b/sketch.h index 7f3476c..3087156 100644 --- a/sketch.h +++ b/sketch.h @@ -446,6 +446,30 @@ public: 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 { public: int tag; diff --git a/wishlist.txt b/wishlist.txt index 6081c8e..48abf98 100644 --- a/wishlist.txt +++ b/wishlist.txt @@ -1,11 +1,11 @@ multi-drag copy and paste +filled contours for export associative entities from solid model, as a special group ----- some kind of import -filled contours for export faster triangulation loop detection IGES export