partly fix splitway for relations (still lots of FIXMEs, but the perfect is the enemy...
authorRichard Fairhurst <richard@systemed.net>
Fri, 14 May 2010 13:14:29 +0000 (13:14 +0000)
committerRichard Fairhurst <richard@systemed.net>
Fri, 14 May 2010 13:14:29 +0000 (13:14 +0000)
net/systemeD/halcyon/connection/Entity.as
net/systemeD/halcyon/connection/actions/SplitWayAction.as

index 8f9d5ac..b11a5b2 100644 (file)
@@ -189,6 +189,20 @@ package net.systemeD.halcyon.connection {
             return parents[entity] == true;
         }
 
+               public function get memberships():Array {
+                       var list:Array=[];
+                       for (var o:Object in parents) {
+                               if (o is Relation) {
+                                       for (var i:uint=0; i<o.length; i++) {
+                                               if (o.getMember(i).entity==this) {
+                                                       list.push( { relation:o, position:i, role: o.getMember(i).role } );
+                                               }
+                                       }
+                               }
+                       }
+                       return list;
+               }
+
                // Resume/suspend redraw
                
                public function suspend():void {
index ef1e8db..c3d5509 100644 (file)
@@ -1,6 +1,7 @@
 package net.systemeD.halcyon.connection.actions {
 
     import net.systemeD.halcyon.connection.*;
+       import net.systemeD.halcyon.Globals;
     
     public class SplitWayAction extends CompositeUndoableAction {
     
@@ -16,24 +17,25 @@ package net.systemeD.halcyon.connection.actions {
     
         public override function doAction():uint {
             if (newWay==null) {
-              newWay = Connection.getConnection().createWay(
-                  selectedWay.getTagsCopy(), 
-                  selectedWay.sliceNodes(selectedWay.indexOfNode(selectedNode),selectedWay.length),
-                  push);
+                               newWay = Connection.getConnection().createWay(
+                                       selectedWay.getTagsCopy(), 
+                                       selectedWay.sliceNodes(selectedWay.indexOfNode(selectedNode),selectedWay.length),
+                                       push);
 
-              selectedWay.deleteNodesFrom(selectedWay.indexOfNode(selectedNode)+1, push);
-              
-              // copy relations
-              // FIXME make this reversible
-              // FIXME needs to copy roles as well
-              // FIXME needs to insert the new way in the correct position in 
-              //        the relation, in order to not destroy ordered route relations.
-              //        This will either be before, or after, the selectedWay, depending
-              //        on the relative sequence of the relation members compared to the 
-              //        direction of selectedWay.
-              for each (var r:Relation in selectedWay.parentRelations) {
-                  r.appendMember(new RelationMember(newWay, ''));
-              }
+                               selectedWay.deleteNodesFrom(selectedWay.indexOfNode(selectedNode)+1, push);
+
+                               // copy relations
+                               // FIXME make this reversible
+                               // FIXME should be more clever about the position (for ordered relations).
+                               //        It should either be before, or after, the selectedWay, depending
+                               //        on the relative sequence of the relation members compared to the 
+                               //        direction of selectedWay.
+                               // FIXME if we insert twice into the same relation, the position may become
+                               //        boggled (i.e. "10th position" is no longer valid if we previously
+                               //        inserted something earlier).
+                               for each (var o:Object in selectedWay.memberships) {
+                                       o.relation.insertMember(o.position, new RelationMember(newWay, o.role));
+                               }
             }
             newWay.suspend();
             selectedWay.suspend();