partly fix splitway for relations (still lots of FIXMEs, but the perfect is the enemy...
[potlatch2.git] / net / systemeD / halcyon / connection / actions / SplitWayAction.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 SplitWayAction extends CompositeUndoableAction {
7     
8         private var selectedWay:Way;
9         private var selectedNode:Node;
10         private var newWay:Way;
11     
12         public function SplitWayAction(selectedWay:Way, selectedNode:Node) {
13             super("Split way "+selectedWay.id);
14             this.selectedWay = selectedWay;
15             this.selectedNode = selectedNode;
16         }
17     
18         public override function doAction():uint {
19             if (newWay==null) {
20                                 newWay = Connection.getConnection().createWay(
21                                         selectedWay.getTagsCopy(), 
22                                         selectedWay.sliceNodes(selectedWay.indexOfNode(selectedNode),selectedWay.length),
23                                         push);
24
25                                 selectedWay.deleteNodesFrom(selectedWay.indexOfNode(selectedNode)+1, push);
26
27                                 // copy relations
28                                 // FIXME make this reversible
29                                 // FIXME should be more clever about the position (for ordered relations).
30                                 //        It should either be before, or after, the selectedWay, depending
31                                 //        on the relative sequence of the relation members compared to the 
32                                 //        direction of selectedWay.
33                                 // FIXME if we insert twice into the same relation, the position may become
34                                 //        boggled (i.e. "10th position" is no longer valid if we previously
35                                 //        inserted something earlier).
36                                 for each (var o:Object in selectedWay.memberships) {
37                                         o.relation.insertMember(o.position, new RelationMember(newWay, o.role));
38                                 }
39             }
40             newWay.suspend();
41             selectedWay.suspend();
42             super.doAction();
43             newWay.resume();
44             selectedWay.resume();
45             return SUCCESS;
46         }
47         
48         public override function undoAction():uint {
49             selectedWay.suspend();
50             newWay.suspend();
51             
52             super.undoAction();
53             
54             newWay.resume();
55             selectedWay.resume();
56             return SUCCESS;
57         }
58     }
59
60 }