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.
pull/4/head
whitequark 2016-02-18 11:11:59 +00:00
parent 27d0dedbd1
commit b3fa8dca37
2 changed files with 14 additions and 7 deletions

View File

@ -605,6 +605,9 @@ void GraphicsWindow::EnsureValidActives(void) {
// drawing group and activate that. They should never be able // drawing group and activate that. They should never be able
// to delete the references, though. // to delete the references, though.
activeGroup = SS.CreateDefaultDrawingGroup(); 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 { } else {
activeGroup = SK.groupOrder.elem[i]; activeGroup = SK.groupOrder.elem[i];
} }

View File

@ -63,7 +63,6 @@ void TextWindow::ScreenShowGroupsSpecial(int link, uint32_t v) {
} }
} }
void TextWindow::ScreenActivateGroup(int link, uint32_t v) { void TextWindow::ScreenActivateGroup(int link, uint32_t v) {
hGroup hg = { v };
SS.GW.activeGroup.v = v; SS.GW.activeGroup.v = v;
SK.GetGroup(SS.GW.activeGroup)->Activate(); SK.GetGroup(SS.GW.activeGroup)->Activate();
SS.GW.ClearSuper(); SS.GW.ClearSuper();
@ -251,15 +250,20 @@ void TextWindow::ScreenDeleteGroup(int link, uint32_t v) {
hGroup hg = SS.TW.shown.group; hGroup hg = SS.TW.shown.group;
if(hg.v == SS.GW.activeGroup.v) { if(hg.v == SS.GW.activeGroup.v) {
Error("This group is currently active; activate a different group " SS.GW.activeGroup = SK.GetGroup(SS.GW.activeGroup)->PreviousGroup()->h;
"before proceeding.");
return;
} }
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.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); 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) { void TextWindow::ShowGroupInfo(void) {
Group *g = SK.GetGroup(shown.group); Group *g = SK.GetGroup(shown.group);