From b3fa8dca3747f1a55499ae6f418c0a5cc8079f00 Mon Sep 17 00:00:00 2001 From: whitequark Date: Thu, 18 Feb 2016 11:11:59 +0000 Subject: [PATCH] Allow removing active group. This is an artificial restriction that serves no useful purpose. Just switch to the previous group if asked to delete the current one. The ClearSuper() calls are reshuffled, since TW.ClearSuper() calls TW.Show() and so has to be called while the sketch is still valid, whereas GW.ClearSuper() also recreates the default group and thus it should be called after the first RemoveById+GenerateAll pair, or it'll recreate the default group before the entities on it have a chance to be pruned. --- src/graphicswin.cpp | 3 +++ src/textscreens.cpp | 18 +++++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/graphicswin.cpp b/src/graphicswin.cpp index 8f4d56c..12d57ec 100644 --- a/src/graphicswin.cpp +++ b/src/graphicswin.cpp @@ -605,6 +605,9 @@ void GraphicsWindow::EnsureValidActives(void) { // drawing group and activate that. They should never be able // to delete the references, though. activeGroup = SS.CreateDefaultDrawingGroup(); + // We've created the default group, but not the workplane entity; + // do it now so that drawing mode isn't switched to "Free in 3d". + SS.GenerateAll(SolveSpaceUI::GENERATE_ALL); } else { activeGroup = SK.groupOrder.elem[i]; } diff --git a/src/textscreens.cpp b/src/textscreens.cpp index 14fe13a..ef57793 100644 --- a/src/textscreens.cpp +++ b/src/textscreens.cpp @@ -63,7 +63,6 @@ void TextWindow::ScreenShowGroupsSpecial(int link, uint32_t v) { } } void TextWindow::ScreenActivateGroup(int link, uint32_t v) { - hGroup hg = { v }; SS.GW.activeGroup.v = v; SK.GetGroup(SS.GW.activeGroup)->Activate(); SS.GW.ClearSuper(); @@ -251,15 +250,20 @@ void TextWindow::ScreenDeleteGroup(int link, uint32_t v) { hGroup hg = SS.TW.shown.group; if(hg.v == SS.GW.activeGroup.v) { - Error("This group is currently active; activate a different group " - "before proceeding."); - return; + SS.GW.activeGroup = SK.GetGroup(SS.GW.activeGroup)->PreviousGroup()->h; } - SK.group.RemoveById(hg); - // This is a major change, so let's re-solve everything. + + // Reset the text window, since we're displaying information about + // the group that's about to get deleted. SS.TW.ClearSuper(); - SS.GW.ClearSuper(); + + // This is a major change, so let's re-solve everything. + SK.group.RemoveById(hg); SS.GenerateAll(SolveSpaceUI::GENERATE_ALL); + + // Reset the graphics window. This will also recreate the default + // group if it was removed. + SS.GW.ClearSuper(); } void TextWindow::ShowGroupInfo(void) { Group *g = SK.GetGroup(shown.group);