change relation.appendMember to use the undo system, and update various places as...
[potlatch2.git] / net / systemeD / halcyon / connection / actions / UnjoinNodeAction.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 UnjoinNodeAction extends CompositeUndoableAction {
7
8         private var node:Node;
9         private var selectedWay:Way;
10
11         public function UnjoinNodeAction(node:Node, selectedWay:Way) {
12             super("Unjoin node "+node.id);
13             this.node = node;
14             this.selectedWay = selectedWay;
15         }
16             
17         public override function doAction():uint {
18             if (node.parentWays.length < 2) {
19               return NO_CHANGE;
20             }
21
22             var ways:Array=[];
23             for each (var way:Way in node.parentWays) {
24               way.suspend(); ways.push(way);
25               if (way == selectedWay) {
26                 way.dispatchEvent(new EntityEvent(Connection.WAY_REORDERED, way));      // no longer a junction, so force redraw
27                 continue;
28               } else {
29                 var newNode:Node = Connection.getConnection().createNode(node.getTagsCopy(), node.lat, node.lon, push);
30                 for (var i:int = 0; i < way.length; i++) {
31                   if(way.getNode(i) == node) {
32                     way.removeNodeByIndex(i, push);
33                     way.insertNode(i, newNode, push);
34                   }
35                 }
36               }
37             }
38             super.doAction();
39             for each (way in ways) { way.resume(); }
40
41             return SUCCESS;
42         }
43             
44         public override function undoAction():uint {
45             node.suspend();
46             selectedWay.suspend();
47             super.undoAction();
48             selectedWay.resume();
49             node.resume();
50             
51             return SUCCESS;
52         }
53     }
54 }
55