Make splitway reversible. TODO - fix relations bug
[potlatch2.git] / net / systemeD / halcyon / connection / actions / SplitWayAction.as
1 package net.systemeD.halcyon.connection.actions {
2
3     import net.systemeD.halcyon.connection.*;
4     
5     public class SplitWayAction extends CompositeUndoableAction {
6     
7         private var selectedWay:Way;
8         private var selectedNode:Node;
9         private var newWay:Way;
10     
11         public function SplitWayAction(selectedWay:Way, selectedNode:Node) {
12             super("Split way "+selectedWay.id);
13             this.selectedWay = selectedWay;
14             this.selectedNode = selectedNode;
15         }
16     
17         public override function doAction():uint {
18             if (newWay==null) {
19               newWay = Connection.getConnection().createWay(
20                   selectedWay.getTagsCopy(), 
21                   selectedWay.sliceNodes(selectedWay.indexOfNode(selectedNode),selectedWay.length),
22                   push);
23
24               selectedWay.deleteNodesFrom(selectedWay.indexOfNode(selectedNode)+1, push);
25               
26               // copy relations
27               // TODO make this reversible
28               for each (var r:Relation in selectedWay.parentRelations) {
29                   // ** needs to copy roles as well
30                   r.appendMember(new RelationMember(newWay, ''));
31               }
32             }
33             newWay.suspend();
34             selectedWay.suspend();
35             super.doAction();
36             newWay.resume();
37             selectedWay.resume();
38             return SUCCESS;
39         }
40         
41         public override function undoAction():uint {
42             selectedWay.suspend();
43             newWay.suspend();
44             
45             super.undoAction();
46             
47             newWay.resume();
48             selectedWay.resume();
49             return SUCCESS;
50         }
51     }
52
53 }