change relation.appendMember to use the undo system, and update various places as...
[potlatch2.git] / net / systemeD / halcyon / connection / actions / SplitWayAction.as
index 983f830b25efc5a6d6ed0676c111ee04156601b7..b6b815f8e2c20290e20393293939aac0b14880fc 100644 (file)
@@ -22,12 +22,19 @@ package net.systemeD.halcyon.connection.actions {
                                        selectedWay.sliceNodes(selectedWay.indexOfNode(selectedNode),selectedWay.length),
                                        push);
 
-                               // copy relations
-                               // FIXME make this reversible
+                               // we reverse the list, which is already sorted by position. This way positions aren't affected
+                               // for previous inserts when all the inserts are eventually executed
+                               for each (var o:Object in selectedWay.memberships.reverse()) {
+                                       // don't add a turn restriction to the relation if it's no longer relevant
+                                       if (o.relation.tagIs('type','restriction')) {
+                                               var vias:Array=o.relation.findMembersByRole('via');
+                                               if (vias.length && vias[0] is Node) {
+                                                       if (newWay.indexOfNode(Node(vias[0]))==-1) { 
+                                                               continue;
+                                                       }
+                                               }
+                                       }
 
-                // we reverse the list, which is already sorted by position. This way positions aren't affected
-                // for previous inserts when all the inserts are eventually executed
-                for each (var o:Object in selectedWay.memberships.reverse()) {
                   // newWay should be added immediately after the selectedWay, unless the setup
                   // is arse-backwards. By that I mean either:
                   // a) The first node (0) of selectedWay is in the subsequentWay, or
@@ -60,14 +67,25 @@ package net.systemeD.halcyon.connection.actions {
                     offset++;
                   }
                   if (backwards) {
-                    o.relation.insertMember(o.position, new RelationMember(newWay, o.role)); //insert newWay before selectedWay
+                    o.relation.insertMember(o.position, new RelationMember(newWay, o.role), push); //insert newWay before selectedWay
                   } else {
-                    o.relation.insertMember(o.position + 1, new RelationMember(newWay, o.role)); // insert after
+                    o.relation.insertMember(o.position + 1, new RelationMember(newWay, o.role), push); // insert after
                   }
                 }
                 
                 // now that we're done with the selectedWay, remove the nodes
                 selectedWay.deleteNodesFrom(selectedWay.indexOfNode(selectedNode)+1, push);
+
+                               // and remove from any turn restrictions that aren't relevant
+                               for each (var r:Relation in selectedWay.findParentRelationsOfType('restriction')) {
+                                       vias=r.findMembersByRole('via');
+                                       if (vias.length && vias[0] is Node) {
+                                               if (selectedWay.indexOfNode(Node(vias[0]))==-1) { 
+                                                       r.removeMember(selectedWay,push);
+                                               }
+                                       }
+                               }
+
             }
             newWay.suspend();
             selectedWay.suspend();