Merge branch 'master' of github.com:systemed/potlatch2
[potlatch2.git] / net / systemeD / halcyon / connection / actions / UnjoinNodeAction.as
1 package net.systemeD.halcyon.connection.actions {
2
3     import net.systemeD.halcyon.connection.*;
4     
5     public class UnjoinNodeAction extends CompositeUndoableAction {
6
7         private var node:Node;
8         private var selectedWay:Way;
9
10         public function UnjoinNodeAction(node:Node, selectedWay:Way) {
11             super("Unjoin node "+node.id);
12             this.node = node;
13             this.selectedWay = selectedWay;
14         }
15             
16         public override function doAction():uint {
17             if (node.parentWays.length < 2) {
18               return NO_CHANGE;
19             }
20
21             var ways:Array=[];
22             for each (var way:Way in node.parentWays) {
23               way.suspend(); ways.push(way);
24               if (way == selectedWay) {
25                 way.dispatchEvent(new EntityEvent(Connection.WAY_REORDERED, way));      // no longer a junction, so force redraw
26                 continue;
27               } else {
28                 var newNode:Node = way.connection.createNode(node.getTagsCopy(), node.lat, node.lon, push);
29                 for (var i:int = 0; i < way.length; i++) {
30                   if(way.getNode(i) == node) {
31                     way.removeNodeByIndex(i, push);
32                     way.insertNode(i, newNode, push);
33                   }
34                 }
35               }
36             }
37             super.doAction();
38             for each (way in ways) { way.resume(); }
39
40             return SUCCESS;
41         }
42             
43         public override function undoAction():uint {
44             node.suspend();
45             selectedWay.suspend();
46             super.undoAction();
47             selectedWay.resume();
48             node.resume();
49             
50             return SUCCESS;
51         }
52     }
53 }
54