From 45eb2468655dbf8f26b2a113810de0c62d3d0833 Mon Sep 17 00:00:00 2001 From: phkahler <14852918+phkahler@users.noreply.github.com> Date: Tue, 21 Apr 2020 00:44:27 -0400 Subject: [PATCH] Eliminate some entity copies in lathe groups. Eliminates a crash due to copy numbers going over 1000. May break some older files with constaints on lathed entities. (#582) --- src/group.cpp | 31 +++++++++++++------------------ src/sketch.h | 3 ++- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/src/group.cpp b/src/group.cpp index ac9ccf06..733a06ce 100644 --- a/src/group.cpp +++ b/src/group.cpp @@ -516,9 +516,6 @@ void Group::Generate(IdList *entity, Vector axis_pos = SK.GetEntity(predef.origin)->PointGetNum(); Vector axis_dir = SK.GetEntity(predef.entityB)->VectorGetNum(); - // Remapped entity index. - int ai = 1; - // Not using range-for here because we're changing the size of entity in the loop. for(i = 0; i < entity->n; i++) { Entity *e = &(entity->Get(i)); @@ -529,24 +526,22 @@ void Group::Generate(IdList *entity, // As soon as I call CopyEntity, e may become invalid! That // adds entities, which may cause a realloc. - CopyEntity(entity, SK.GetEntity(predef.origin), 0, ai, - NO_PARAM, NO_PARAM, NO_PARAM, - NO_PARAM, NO_PARAM, NO_PARAM, NO_PARAM, NO_PARAM, - CopyAs::NUMERIC); + // this is the regular copy of all entities CopyEntity(entity, SK.GetEntity(he), 0, REMAP_LATHE_START, NO_PARAM, NO_PARAM, NO_PARAM, NO_PARAM, NO_PARAM, NO_PARAM, NO_PARAM, NO_PARAM, CopyAs::NUMERIC); - CopyEntity(entity, SK.GetEntity(he), 0, REMAP_LATHE_END, - NO_PARAM, NO_PARAM, NO_PARAM, - NO_PARAM, NO_PARAM, NO_PARAM, NO_PARAM, NO_PARAM, - CopyAs::NUMERIC); - - MakeLatheCircles(entity, param, he, axis_pos, axis_dir, ai); + if (e->IsPoint()) { + // for points this copy is used for the circle centers + CopyEntity(entity, SK.GetEntity(he), 0, REMAP_LATHE_ARC_CENTER, + NO_PARAM, NO_PARAM, NO_PARAM, + NO_PARAM, NO_PARAM, NO_PARAM, NO_PARAM, NO_PARAM, + CopyAs::NUMERIC); + MakeLatheCircles(entity, param, he, axis_pos, axis_dir); + }; MakeLatheSurfacesSelectable(entity, he, axis_dir); - ai++; } return; } @@ -589,7 +584,7 @@ void Group::Generate(IdList *entity, } // Arcs are not generated for revolve groups, for now, because our current arc // entity is not chiral, and dragging a revolve may break the arc by inverting it. - // MakeLatheCircles(entity, param, he, axis_pos, axis_dir, ai); + // MakeLatheCircles(entity, param, he, axis_pos, axis_dir); MakeLatheSurfacesSelectable(entity, he, axis_dir); } @@ -853,15 +848,15 @@ void Group::MakeExtrusionLines(IdList *el, hEntity in) { } } -void Group::MakeLatheCircles(IdList *el, IdList *param, hEntity in, Vector pt, Vector axis, int ai) { +void Group::MakeLatheCircles(IdList *el, IdList *param, hEntity in, Vector pt, Vector axis) { Entity *ep = SK.GetEntity(in); Entity en = {}; if(ep->IsPoint()) { // A point gets revolved to form an arc. - en.point[0] = Remap(predef.origin, ai); + en.point[0] = Remap(ep->h, REMAP_LATHE_ARC_CENTER); en.point[1] = Remap(ep->h, REMAP_LATHE_START); - en.point[2] = Remap(ep->h, REMAP_LATHE_END); + en.point[2] = en.point[1]; //Remap(ep->h, REMAP_LATHE_END); // Get arc center and point on arc. Entity *pc = SK.GetEntity(en.point[0]); diff --git a/src/sketch.h b/src/sketch.h index 6cd4acaa..2465aefa 100644 --- a/src/sketch.h +++ b/src/sketch.h @@ -279,10 +279,11 @@ public: REMAP_LATHE_END = 1007, REMAP_PT_TO_ARC = 1008, REMAP_PT_TO_NORMAL = 1009, + REMAP_LATHE_ARC_CENTER = 1010, }; hEntity Remap(hEntity in, int copyNumber); void MakeExtrusionLines(EntityList *el, hEntity in); - void MakeLatheCircles(IdList *el, IdList *param, hEntity in, Vector pt, Vector axis, int ai); + void MakeLatheCircles(IdList *el, IdList *param, hEntity in, Vector pt, Vector axis); void MakeLatheSurfacesSelectable(IdList *el, hEntity in, Vector axis); void MakeExtrusionTopBottomFaces(EntityList *el, hEntity pt); void CopyEntity(EntityList *el,