]> git.openstreetmap.org Git - potlatch2.git/blob - net/systemeD/halcyon/connection/actions/MergeNodesAction.as
ADD ability to merge one node with another (including POI nodes)
[potlatch2.git] / net / systemeD / halcyon / connection / actions / MergeNodesAction.as
1 package net.systemeD.halcyon.connection.actions\r
2 {\r
3         import net.systemeD.halcyon.connection.*;\r
4 \r
5 \r
6         public class MergeNodesAction extends CompositeUndoableAction {\r
7         // Node2's tags are merged into node1, then node2 is deleted.       \r
8         private var node1:Node;\r
9         private var node2:Node;\r
10         static public var lastProblemTags:Array;\r
11     \r
12         public function MergeNodesAction(destnode:Node, sourcenode:Node) {\r
13             super("Merge nodes "+destnode.id+" "+sourcenode.id);\r
14             this.node1 = destnode;\r
15             this.node2 = sourcenode;\r
16             lastProblemTags=null;\r
17         }\r
18         \r
19         public override function doAction():uint {\r
20 \r
21             super.clearActions();\r
22             node1.suspend();\r
23 \r
24 //            mergeRelations(); TODO\r
25             lastProblemTags= node1.mergeTags(node2,push); // TODO use to warn user\r
26             node2.replaceWith(node1, push);\r
27             node2.remove(push);\r
28 \r
29             super.doAction();\r
30             node1.resume();\r
31             \r
32             return SUCCESS;\r
33         }\r
34 \r
35         public override function undoAction():uint {\r
36             node1.suspend();\r
37             super.undoAction();\r
38             node1.resume();\r
39             \r
40             return SUCCESS;\r
41         }\r
42         \r
43         public function mergeRelations():void {\r
44             for each (var r:Relation in node2.parentRelations) {\r
45                 // ** needs to copy roles as well\r
46                 if (r.findEntityMemberIndex(node1)==-1) {\r
47                     r.appendMember(new RelationMember(node1, ''), push);\r
48                 }\r
49             }\r
50         }\r
51     }\r
52 \r
53 }