Removing Nodes

There are two ways to remove nodes in NaroCAD:
1. Document.Root.Remove(nodeIndex)
2. NodeBuilderUtils.DeleteNode(node, Document);

The second method performs checks to see if the node is referring or is being referred by other nodes by calling document.OptimizeTree(). The first method removes the node without performing any checks and can cause problems – if the ShapeGraph is not updated correctly, a deleted node remains in the Referred or Referring lists. When it is encountered later on, a node is created with that index but with no real content or interpreters.

The Referring and Referred lists in ShapeGraph are used to see which nodes use the node to be deleted and which should be removed along with the node:

– if we delete a line that has no connections to other shapes, both points are deleted, as well (they are referred only by the line)
– if we delete a line that has one point in common with another line, only the ‘free’ point is deleted
– if we delete a line that is in a constraint and has no common points, we first need to remove the constraint outside of the OptimizeTree method because in the current form of the Document class, it has no information about the type of nodes and it doesn’t differentiate between constraints referring to a node or another shape. After the constraint is deleted, the shape references are correctly handled in OptimizeTree.

In conclusion, the second method should be used only for temporary or auxiliary nodes.

  1 COMMENT
Documentation

Leave a Reply

Pages
Blogroll





The best Android Market
AndroidPit