change relation.appendMember to use the undo system, and update various places as...
[potlatch2.git] / net / systemeD / halcyon / connection / actions / AddNodeToWayAction.as
1 package net.systemeD.halcyon.connection.actions {
2
3     import net.systemeD.halcyon.connection.*;
4         import net.systemeD.halcyon.Globals;
5     
6     public class AddNodeToWayAction extends UndoableEntityAction {
7         private var node:Node;
8         private var nodeList:Array;
9         private var index:int;
10         
11         public function AddNodeToWayAction(way:Way, node:Node, nodeList:Array, index:int) {
12             super(way, "Add node "+node.id+" to");
13             this.node = node;
14             this.nodeList = nodeList;
15             this.index = index;
16         }
17             
18         public override function doAction():uint {
19             var way:Way = entity as Way;
20             if ( index == -1 )
21                 index = nodeList.length;
22             node.addParent(way);
23             nodeList.splice(index, 0, node);
24             markDirty();
25                         way.expandBbox(node);
26             way.dispatchEvent(new WayNodeEvent(Connection.WAY_NODE_ADDED, node, way, index));
27             
28             return SUCCESS;
29         }
30             
31         public override function undoAction():uint {
32             var way:Way = entity as Way;
33             var removed:Array=nodeList.splice(index, 1);
34                         if (nodeList.indexOf(removed[0])==-1) { removed[0].removeParent(way); }
35                         markClean();
36             way.dispatchEvent(new WayNodeEvent(Connection.WAY_NODE_REMOVED, removed[0], way, index));
37             
38             return SUCCESS;
39         }
40     }
41 }
42