]> git.openstreetmap.org Git - potlatch2.git/blob - net/systemeD/halcyon/connection/actions/MergeWaysAction.as
33d5c8038f023f0c097be0682e52fbbd22bcbb8a
[potlatch2.git] / net / systemeD / halcyon / connection / actions / MergeWaysAction.as
1 package net.systemeD.halcyon.connection.actions {
2
3     import net.systemeD.halcyon.connection.*;
4     
5     public class MergeWaysAction extends CompositeUndoableAction {
6         private var way1:Way;
7         private var way2:Way;
8         private var toPos:uint;
9         private var fromPos:uint;
10         static public var lastProblemTags:Array;
11     
12         public function MergeWaysAction(way1:Way, way2:Way, toPos:uint, fromPos:uint) {
13             super("Merge ways "+way1.id+" "+way2.id);
14             this.way1 = way1;
15             this.way2 = way2;
16             this.toPos = toPos;
17             this.fromPos = fromPos;
18             lastProblemTags=null;
19         }
20         
21         public override function doAction():uint {
22             // subactions are added to the composite list -- we then
23             // execute them all at the bottom. Doing it this way gives
24             // us an automatic undo
25             super.clearActions();
26             way1.suspend();
27
28             mergeRelations();
29             lastProblemTags = way1.mergeTags(way2,push);
30                 mergeNodes();
31                         way2.remove(push);
32
33             super.doAction();
34                         way1.resume();
35             
36             return SUCCESS;
37         }
38
39         public override function undoAction():uint {
40             way1.suspend();
41             super.undoAction();
42             way1.resume();
43             
44             return SUCCESS;
45         }
46         
47         public function mergeRelations():void {
48                         for each (var r:Relation in way2.parentRelations) {
49                                 // ** needs to copy roles as well
50                                 if (r.findEntityMemberIndex(way1)==-1) {
51                                         r.appendMember(new RelationMember(way1, ''), push);
52                                 }
53                         }
54         }
55         
56         
57         public function mergeNodes():void {
58             var i:int;
59                 if (fromPos==0) {
60                     for (i = 0; i < way2.length; i++)
61                         way1.addToEnd(toPos, way2.getNode(i), push);
62                 } else {
63                     for (i = way2.length-1; i >= 0; i--)
64                         way1.addToEnd(toPos, way2.getNode(i), push);
65                 }
66         }   
67     }
68 }
69