From 90620081c77758df86baf70c566984a39e575624 Mon Sep 17 00:00:00 2001 From: Aesylwinn Date: Fri, 27 May 2016 13:15:35 -0400 Subject: [PATCH] Fix handling of deleted pathgrids. --- apps/opencs/view/render/pathgrid.cpp | 30 +++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/apps/opencs/view/render/pathgrid.cpp b/apps/opencs/view/render/pathgrid.cpp index b1c3be854..f2920d7fb 100644 --- a/apps/opencs/view/render/pathgrid.cpp +++ b/apps/opencs/view/render/pathgrid.cpp @@ -277,8 +277,31 @@ namespace CSVRender } else { - CSMWorld::CreatePathgridCommand* createCmd = new CSMWorld::CreatePathgridCommand(*model, mId); - commands.push(createCmd); + int index = mPathgridCollection.searchId(mId); + if (index == -1) + { + // Does not exist + commands.push(new CSMWorld::CreatePathgridCommand(*model, mId)); + } + else + { + source = &mPathgridCollection.getRecord(index).get(); + + // Deleted, so revert and remove all data + commands.push(new CSMWorld::RevertCommand(*model, mId)); + + int parentColumn = mPathgridCollection.findColumnIndex(CSMWorld::Columns::ColumnId_PathgridPoints); + for (int row = source->mPoints.size() - 1; row >= 0; --row) + { + commands.push(new CSMWorld::DeleteNestedCommand(*model, mId, row, parentColumn)); + } + + parentColumn = mPathgridCollection.findColumnIndex(CSMWorld::Columns::ColumnId_PathgridEdges); + for (int row = source->mEdges.size() - 1; row >= 0; --row) + { + commands.push(new CSMWorld::DeleteNestedCommand(*model, mId, row, parentColumn)); + } + } } } @@ -510,7 +533,8 @@ namespace CSVRender } else { - removeGeometry(); + removePathgridGeometry(); + removeSelectedGeometry(); } }