Issue with moving surface edits - duplicating/overwriting operations
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I've been working on a tool that would move the surface edits up or down the list after some other code it being run. The tool does some translations so that internally I'm storing some tracking info for each operation so that I can move the operations based on some user interactions in a dialog box. My current problem is that when I move an item and rebuild the surface, it appears to make the changes fine but if I then move the item again and rebuild, it makes a copy of the item that was moved and overwrites the one at the index it was supposed to move to.
I've used several different functions to do this, thinking maybe one was causing the issue over another.
The first used the SurfaceOperation.Swap, then the next used SurfaceOperation.SwapAt. Finally, I'm using a loop that looks at the original index and the user selected index of the item and moves it using the MoveToTop/MoveToBottom and steps it up/down with the MoveUp/MoveDown commands until it's in the right place. This option takes a little longer to process but all three options end up with the same results: Rebuilt 1 works, Rebuild 2 results in a duplicated SurfaceOperation.
Here's the code for updating the SurfaceOperations in the surface:
public void ApplyChanges()
{
if (_hasEditsToUpdate)
{
if (_surfaceId != ObjectId.Null)
{
for (int i = 0; i < Edits.Count; i++)
{
bool matches = true;
try
{ matches = Edits[i].MatchesCivilOperation(); }
catch (System.Exception ex)
{ }
if (matches == false)
{
try
{
Edits[i].Update(_surfaceId);
}
catch (System.Exception ex)
{ }
}
Edits[i].MoveToIndex();
Edits[i].ResetIndex();
}
}
}
// rebuild the surface to include the new edits
RebuildSurface();
//// reset the edits list with the new list of edits, using new base data for each
Edits = GetEdits();
// reset the tracking flag
HasEditsToUpdate = false;
}
Here's the code that moves the edits up or down in the surface:
public void MoveToIndex()
{
if (_surfaceId != ObjectId.Null)
{
CivilDocument doc = CivilApplication.ActiveDocument;
using (Transaction tr = Application.DocumentManager.MdiActiveDocument.TransactionManager.StartTransaction())
{
Autodesk.Civil.DatabaseServices.TinSurface surf = tr.GetObject(_surfaceId, OpenMode.ForRead, false, true) as Autodesk.Civil.DatabaseServices.TinSurface;
int editCount = surf.Operations.Count;
int mid = editCount / 2;
if (_currentIndex < mid)
{
// move the operation to 0
_operation.MoveToTop();
if (_currentIndex > 0)
{
// move the operation down until at the index
for (int i = 0; i < _currentIndex; i++)
{
_operation.MoveDown();
}
}
}
else if (_currentIndex >= mid)
{
// move the operation to the end
_operation.MoveToBottom();
if (_currentIndex < editCount)
{
// move the operation up until at the index
for (int i = editCount; i > _currentIndex; i--)
{
_operation.MoveUp();
}
}
}
}
}
}
public void ResetIndex()
{
_originalIndex = _currentIndex;
}
Here's what the output looks like:
I've been wracking the grey matter on this one for several days and I can't seem to nail down the issue, so I'm hoping someone else has seen something like it or has an idea that I can test out.