first stab at unjoin - problems with the UIs not matching up
authorAndy Allan <gravitystorm@gmail.com>
Thu, 4 Nov 2010 16:38:42 +0000 (16:38 +0000)
committerAndy Allan <gravitystorm@gmail.com>
Thu, 4 Nov 2010 16:38:42 +0000 (16:38 +0000)
net/systemeD/halcyon/connection/Node.as
net/systemeD/halcyon/connection/actions/UnjoinNodeAction.as [new file with mode: 0644]
net/systemeD/potlatch2/controller/SelectedWayNode.as

index d8f88a47fa8fa5a90e7a57e52c0fd25c228323e0..54117d6f6a89f326c1290b4e3704b36492bf29bf 100644 (file)
@@ -71,6 +71,14 @@ package net.systemeD.halcyon.connection {
                        if (_lon<left || _lon>right || _lat<bottom || _lat>top || deleted) { return false; }
                        return true;
                }
+
+        public function unjoin(selectedWay:Way, performAction:Function):void {
+            if (parentWays.length > 1) {
+              performAction(new UnjoinNodeAction(this, selectedWay));
+            } else {
+              trace("not enough ways");
+            }
+        }
                
                internal override function isEmpty():Boolean {
                        return deleted;
diff --git a/net/systemeD/halcyon/connection/actions/UnjoinNodeAction.as b/net/systemeD/halcyon/connection/actions/UnjoinNodeAction.as
new file mode 100644 (file)
index 0000000..59f62e9
--- /dev/null
@@ -0,0 +1,53 @@
+package net.systemeD.halcyon.connection.actions {
+
+    import net.systemeD.halcyon.connection.*;
+       import net.systemeD.halcyon.Globals;
+    
+    public class UnjoinNodeAction extends CompositeUndoableAction {
+
+        private var node:Node;
+        private var selectedWay:Way;
+
+        public function UnjoinNodeAction(node:Node, selectedWay:Way) {
+            super("Unjoin node "+node.id);
+            this.node = node;
+            this.selectedWay = selectedWay;
+        }
+            
+        public override function doAction():uint {
+            trace("unjoining node "+node.id);
+            if (node.parentWays.length < 2) {
+              return NO_CHANGE;
+            }
+
+            node.suspend();
+            for each (var way:Way in node.parentWays) {
+              way.suspend();
+              if (way == selectedWay) {
+                trace("skipping selected way");
+                continue;
+              } else {
+                trace("need to fettle way: "+way);
+                var newNode:Node = Connection.getConnection().createNode(node.getTagsCopy(), node.lat, node.lon, push);
+                for (var i:int = 0; i < way.length; i++) {
+                  if(way.getNode(i) == node) {
+                    way.removeNodeByIndex(i, push);
+                    way.insertNode(i, newNode, push);
+                    trace("inserted node at" +i); 
+                  }
+                }
+              }
+              way.resume();
+            }
+            node.resume();
+            return SUCCESS;
+        }
+            
+        public override function undoAction():uint {
+            trace("fail");
+            
+            return FAIL;
+        }
+    }
+}
+
index f1e5c9ddc50cd1400840ad19f27f74a6bbf1853b..d5e248208a867b304abca435e03ed7e389176c34 100644 (file)
@@ -68,6 +68,7 @@ package net.systemeD.potlatch2.controller {
                                case 88:                                        return splitWay();                                              // 'X'
                                case 82:                                        repeatTags(firstSelected); return this; // 'R'
                                case 87:                                        return new SelectedWay(parentWay);              // 'W'
+                case 74:                    if (event.shiftKey) { return unjoin() };// 'J'
                                case Keyboard.BACKSPACE:        return deleteNode();
                                case Keyboard.DELETE:           return deleteNode();
                        }
@@ -133,5 +134,10 @@ package net.systemeD.potlatch2.controller {
                        return new SelectedWay(parentWay);
                }
 
+        public function unjoin():ControllerState {
+            Node(firstSelected).unjoin(parentWay, MainUndoStack.getGlobalStack().addAction);
+            return this;
+        }
+
     }
 }