Add further details into the splitWay relations handling section
[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               // FIXME make this reversible
28               // FIXME needs to copy roles as well
29               // FIXME needs to insert the new way in the correct position in 
30               //        the relation, in order to not destroy ordered route relations.
31               //        This will either be before, or after, the selectedWay, depending
32               //        on the relative sequence of the relation members compared to the 
33               //        direction of selectedWay.
34               for each (var r:Relation in selectedWay.parentRelations) {
35                   r.appendMember(new RelationMember(newWay, ''));
36               }
37             }
38             newWay.suspend();
39             selectedWay.suspend();
40             super.doAction();
41             newWay.resume();
42             selectedWay.resume();
43             return SUCCESS;
44         }
45         
46         public override function undoAction():uint {
47             selectedWay.suspend();
48             newWay.suspend();
49             
50             super.undoAction();
51             
52             newWay.resume();
53             selectedWay.resume();
54             return SUCCESS;
55         }
56     }
57
58 }