Potlatch 2 in progress. Haven't figured out the mouse events still...
authorRichard Fairhurst <richard@systemed.net>
Sun, 15 Nov 2009 21:34:49 +0000 (21:34 +0000)
committerRichard Fairhurst <richard@systemed.net>
Sun, 15 Nov 2009 21:34:49 +0000 (21:34 +0000)
net/systemeD/halcyon/Map.as
net/systemeD/halcyon/NodeUI.as [moved from net/systemeD/halcyon/POI.as with 67% similarity]
net/systemeD/halcyon/WayUI.as
net/systemeD/halcyon/connection/Entity.as
net/systemeD/halcyon/connection/XMLConnection.as
net/systemeD/halcyon/styleparser/MapCSS.as
net/systemeD/halcyon/styleparser/StyleChooser.as
net/systemeD/potlatch2/controller/DragWayNode.as
net/systemeD/potlatch2/controller/SelectedWay.as

index d0d719f..d99d97e 100755 (executable)
@@ -67,6 +67,8 @@ package net.systemeD.halcyon {
                private var dragging:Boolean=false;                             // dragging map?
                private var lastxmouse:Number;                                  //  |
                private var lastymouse:Number;                                  //  |
+               private var firstxmouse:Number;                                 //  |
+               private var firstymouse:Number;                                 //  |
                
                public var initparams:Object;                                   // object containing 
 
@@ -198,8 +200,8 @@ package net.systemeD.halcyon {
                        edge_l=coord2lon(-x          );
                        edge_r=coord2lon(-x+mapwidth );
                        setCentre();
-                       addDebug("Lon "+edge_l+"-"+edge_r);
-                       addDebug("Lat "+edge_b+"-"+edge_t);
+//                     addDebug("Lon "+edge_l+"-"+edge_r);
+//                     addDebug("Lat "+edge_b+"-"+edge_t);
 
                        tileset.update();
                }
@@ -262,7 +264,7 @@ package net.systemeD.halcyon {
                                edge_b>=bigedge_b && edge_t<=bigedge_t) { return; }     // we have already loaded this area, so ignore
                        bigedge_l=edge_l; bigedge_r=edge_r;
                        bigedge_b=edge_b; bigedge_t=edge_t;
-                       addDebug("Calling with "+edge_l+"-"+edge_r+", "+edge_t+"-"+edge_b);
+                       addDebug("Calling download with "+edge_l+"-"+edge_r+", "+edge_t+"-"+edge_b);
                        connection.loadBbox(edge_l,edge_r,edge_t,edge_b);
                }
 
@@ -276,7 +278,8 @@ package net.systemeD.halcyon {
 
         private function newPOICreated(event:EntityEvent):void {
             var node:Node = event.entity as Node;
-            pois[node.id] = new POI(node, this);
+            pois[node.id] = new NodeUI(node, this);
+                       pois[node.id].redraw();
         }
 
         public function setHighlight(entity:Entity, stateType:String, isOn:Boolean):void {
@@ -305,11 +308,11 @@ package net.systemeD.halcyon {
                
                public function redraw():void {
                        for each (var w:WayUI in ways) { w.recalculate(); w.redraw(); }
-                       for each (var p:POI in pois) { p.redraw(); }
+                       for each (var p:NodeUI in pois) { p.redraw(); }
                }
 
                public function redrawPOIs():void {
-                       for each (var p:POI in pois) { p.redraw(); }
+                       for each (var p:NodeUI in pois) { p.redraw(); }
                }
 
                public function zoomIn():void {
@@ -363,14 +366,17 @@ package net.systemeD.halcyon {
                
                public function mouseDownHandler(event:MouseEvent):void {
                        dragging=true;
-                       lastxmouse=mouseX; lastymouse=mouseY;
+                       lastxmouse=firstxmouse=mouseX;
+                       lastymouse=firstymouse=mouseY;
                }
         
                public function mouseUpHandler(event:MouseEvent):void {
                        if (!dragging) { return; }
                        dragging=false;
                        updateCoords(x,y);
-                       download();
+                       if (Math.abs(firstxmouse-mouseX)>4 || Math.abs(firstymouse-mouseY)>4) {
+                               download();
+                       }
                }
         
                public function mouseMoveHandler(event:MouseEvent):void {
similarity index 67%
rename from net/systemeD/halcyon/POI.as
rename to net/systemeD/halcyon/NodeUI.as
index fb52f6f..b59c65f 100644 (file)
@@ -11,8 +11,9 @@ package net.systemeD.halcyon {
     import net.systemeD.halcyon.connection.Node;
     import net.systemeD.halcyon.connection.Connection;
        import net.systemeD.halcyon.styleparser.*;
+       import net.systemeD.halcyon.Globals;
        
-       public class POI extends Object {
+       public class NodeUI extends Object {
                
         private var node:Node;
                public var map:Map;                                                     // reference to parent map
@@ -31,11 +32,10 @@ package net.systemeD.halcyon {
 //             [Embed(source="fonts/DejaVuSans.ttf", fontFamily="DejaVu", fontWeight="normal", mimeType="application/x-font-truetype")]
 //             public static var DejaVu:Class;
 
-               public function POI(node:Node, map:Map, sl:StyleList=null, rotation:Number=0) {
+               public function NodeUI(node:Node, map:Map, rotation:Number=0) {
                        this.map = map;
                        this.node = node;
                        this.rotation = rotation;
-                       redraw(sl);
                        node.addEventListener(Connection.NODE_MOVED, nodeMoved);
                }
                
@@ -43,15 +43,57 @@ package net.systemeD.halcyon {
                    updatePosition();
                }
                
-               public function redraw(sl:StyleList=null):Boolean {
+               public function redraw(sl:StyleList=null,forceDraw:Boolean=false):Boolean {
                        var tags:Object = node.getTagsCopy();
                        tags['_heading']=heading;
                        // ** apply :hover etc.
                        if (!sl) { sl=map.ruleset.getStyles(this.node,tags); }
-                       if (!sl.hasStyles() && iconname=='') { return false; }
+
+                       var inWay:Boolean=node.hasParentWays;
+                       var hasStyles:Boolean=sl.hasStyles();
                        
+                       removePrevious();
+                       if (!hasStyles && !inWay) {
+                               // No styles, not in way; usually return, but render as green circle if showall set
+                               if (!map.showall) { return false; }
+                               return renderAsCircle();
+                       } else if (!hasStyles && inWay) {
+                               // No styles, in way; so render as highlight
+                               // *** needs to be blue/red depending on mouse-over
+                               if (forceDraw) {
+                                       return renderAsSquare();
+                               } else {
+                                       return false;
+                               }
+                       } else {
+                               // Styled, so render properly
+                               return renderFromStyle(sl,tags);
+                       }
+               }
+
+               private function renderAsSquare():Boolean {
+                       createIcon();
+                       icon.graphics.beginFill(0xFF0000);
+                       icon.graphics.drawRect(0,0,6,6);        // ** NODESIZE
+                       loaded=true;
+                       updatePosition();
+                       iconname='_square';
+                       return true;
+               }
+               
+               private function renderAsCircle():Boolean {
+                       createIcon();
+                       icon.graphics.lineStyle(1,0,1);
+                       icon.graphics.beginFill(0x00FF00);
+                       icon.graphics.drawCircle(4,4,4);        // ** NODESIZE
+                       loaded=true;
+                       updatePosition();
+                       iconname='_circle';
+                       return true;
+               }
+               
+               private function renderFromStyle(sl:StyleList,tags:Object):Boolean {
                        var r:Boolean=false;    // ** rendered
-                       var l:DisplayObject;
                        for (var sublayer:uint=0; sublayer<10; sublayer++) {
 
                                if (sl.pointStyles[sublayer]) {
@@ -79,32 +121,42 @@ package net.systemeD.halcyon {
                                        a=tags[t.text];
                                }
 
-                               var c:DisplayObject=map.getChildAt(map.NAMESPRITE);
                                if (a) { 
-                                       if (!name) { name=new Sprite(); Sprite(c).addChild(name); }
+                                       var l:DisplayObject=map.getChildAt(map.NAMESPRITE);
+                                       if (!name) { name=new Sprite(); Sprite(l).addChild(name); }
                                        t.writeNameLabel(name,a,map.lon2coord(node.lon),map.latp2coord(node.latp));
-                               } else if (name) {
-                                       Sprite(c).removeChild(name);
-                                       name=null;
                                }
                        }
-                       if (!r && iconname!='') {
-                               // not rendered any more, so remove
+                       return r;
+               }
+
+               private function removePrevious():void {
+                       var l:DisplayObject;
+                       
+                       if (icon) {
                                l=map.getChildAt(map.POISPRITE);
                                Sprite(l).removeChild(icon);
+                               icon=null;
                                iconname='';
                        }
-                       return true;
+                       if (name) {
+                               l=map.getChildAt(map.NAMESPRITE);
+                               Sprite(l).removeChild(name);
+                               name=null;
+                       }
                }
 
                private function loadedIcon(event:Event):void {
-                       icon = new Sprite();
+                       createIcon();
                        icon.addChild(Bitmap(event.target.content));
-                       var l:DisplayObject=map.getChildAt(map.POISPRITE);
-                       Sprite(l).addChild(icon);
                        loaded=true;
                        updatePosition();
+               }
 
+               private function createIcon():void {
+                       icon = new Sprite();
+                       var l:DisplayObject=map.getChildAt(map.POISPRITE);
+                       Sprite(l).addChild(icon);
             icon.addEventListener(MouseEvent.CLICK, mouseEvent);
             icon.addEventListener(MouseEvent.DOUBLE_CLICK, mouseEvent);
             icon.addEventListener(MouseEvent.MOUSE_OVER, mouseEvent);
@@ -114,7 +166,6 @@ package net.systemeD.halcyon {
             icon.addEventListener(MouseEvent.MOUSE_MOVE, mouseEvent);
             icon.buttonMode = true;
             icon.mouseEnabled = true;
-
                }
 
         private function mouseEvent(event:MouseEvent):void {
@@ -122,7 +173,7 @@ package net.systemeD.halcyon {
         }
 
                private function updatePosition():void {
-                       if (!loaded) { return; }
+                       if (!loaded || !icon) { return; }
                        icon.x=0; icon.y=0; icon.rotation=0;
 
                        var m:Matrix=new Matrix();
index 2647ae6..3d23747 100755 (executable)
@@ -11,6 +11,7 @@ package net.systemeD.halcyon {
        import flash.events.*;
        import net.systemeD.halcyon.styleparser.*;
     import net.systemeD.halcyon.connection.*;
+       import net.systemeD.halcyon.Globals;
 
        public class WayUI {
         private var way:Way;
@@ -41,6 +42,7 @@ package net.systemeD.halcyon {
                private const NODESPRITE:uint=4;
                private const CLICKSPRITE:uint=5;
 
+               private const NODESIZE:uint=6;
 
                public function WayUI(way:Way, map:Map) {
                        this.way = way;
@@ -209,42 +211,46 @@ package net.systemeD.halcyon {
                        }
 
                        // ** draw icons
+                       // ** this looks like it needs reworking
                        var r:Number;
+                       var highlight:Boolean=stateClasses["showNodes"] !=null;
                        for (var i:uint = 0; i < way.length; i++) {
                 var node:Node = way.getNode(i);
                    if (map.pois[node.id]) {
                                        if (map.pois[node.id].loaded) {
-                                               map.pois[node.id].redraw();
+                                               map.pois[node.id].redraw(null, highlight);
                                        }
                                } else if (node.hasTags()) {
                                        sl=map.ruleset.getStyles(node,node.getTagsHash());
                                        if (sl.hasStyles()) {
                                                if (i==0) { r= heading[i]; }
                                                     else { r=(heading[i]+heading[i-1])/2; }
-                                               map.pois[node.id]=new POI(node,map,sl,r);
+                                               map.pois[node.id]=new NodeUI(node,map,r);
+                                               map.pois[node.id].redraw(sl);
                                                // ** this should be done via the registerPOI/event listener mechanism,
                                                //    but that needs a bit of reworking so we can pass in a styleList
                                                //    (otherwise we end up computing the styles twice which is expensive)
                                        }
+                               } else if (highlight) {
+                                       map.pois[node.id]=new NodeUI(node,map);
+                                       map.pois[node.id].redraw(null, true);
                                }
                        }
                        
-                       
-
-                       // No styles, so add a thin trace
-            if (!drawn && map.showall) {
-                var def:Sprite = new Sprite();
-                def.graphics.lineStyle(0.5, 0x808080, 1, false, "normal");
-                solidLine(def.graphics);
-                addToLayer(def, STROKESPRITE);         // ** this probably needs a sublayer
-                               drawn=true;
-            }
+//                     // No styles, so add a thin trace
+//                     if (!drawn && map.showall) {
+//                             var def:Sprite = new Sprite();
+//                             def.graphics.lineStyle(0.5, 0x808080, 1, false, "normal");
+//                             solidLine(def.graphics);
+//                             addToLayer(def, STROKESPRITE, 10);
+//                             drawn=true;
+//                     }
             
-            if ( stateClasses["showNodes"] != null ) {
-                var nodes:Sprite = new Sprite();
-                drawNodes(nodes.graphics);
-                addToLayer(nodes, NODESPRITE);
-            }
+//            if ( stateClasses["showNodes"] != null ) {
+//                var nodes:Sprite = new Sprite();
+//                drawNodes(nodes.graphics);
+//                addToLayer(nodes, NODESPRITE);
+//            }
 
                        if (!drawn) { return; }
                        
@@ -276,16 +282,18 @@ package net.systemeD.halcyon {
                // Drawing support functions
 
                private function drawNodes(g:Graphics):void {
-            g.lineStyle(1, 0xff0000, 1, false, "normal", CapsStyle.ROUND, JointStyle.ROUND);
+// ***** these should be discreet anchorpoints (NodeUI?), not just sprites
+//          g.lineStyle(1, 0xff0000, 1, false, "normal", CapsStyle.ROUND, JointStyle.ROUND);
+                       g.beginFill(0xFF0000);
                        for (var i:uint = 0; i < way.length; i++) {
                 var node:Node = way.getNode(i);
                 var x:Number = map.lon2coord(node.lon);
                 var y:Number = map.latp2coord(node.latp);
-                g.moveTo(x-2, y-2);
-                g.lineTo(x+2, y-2);
-                g.lineTo(x+2, y+2);
-                g.lineTo(x-2, y+2);
-                g.lineTo(x-2, y-2);
+                g.moveTo(x-NODESIZE, y-NODESIZE);
+                g.lineTo(x+NODESIZE, y-NODESIZE);
+                g.lineTo(x+NODESIZE, y+NODESIZE);
+                g.lineTo(x-NODESIZE, y+NODESIZE);
+                g.lineTo(x-NODESIZE, y-NODESIZE);
                        }
                }
 
@@ -452,8 +460,8 @@ package net.systemeD.halcyon {
                 var node:Node = way.getNode(i);
                 var nodeX:Number = map.lon2coord(node.lon);
                 var nodeY:Number = map.latp2coord(node.latp);
-                if ( nodeX >= x-3 && nodeX <= x+3 &&
-                     nodeY >= y-3 && nodeY <= y+3 )
+                if ( nodeX >= x-NODESIZE && nodeX <= x+NODESIZE &&
+                     nodeY >= y-NODESIZE && nodeY <= y+NODESIZE )
                     return node;
             }
             return null;
index 5708328..5ecbba8 100644 (file)
@@ -129,6 +129,13 @@ package net.systemeD.halcyon.connection {
                        return a;
                }
                
+               public function get hasParentWays():Boolean {
+                       for (var o:Object in parents) {
+                               if (o is Way) { return true; }
+                       }
+                       return false;
+               }
+               
                public function get parentRelations():Array {
                        var a:Array=[];
                        for (var o:Object in parents) {
index 3d60345..5e46b82 100644 (file)
@@ -84,7 +84,7 @@ package net.systemeD.halcyon.connection {
         protected function registerPOINodes():void {
             for each (var nodeID:Number in getAllNodeIDs()) {
                 var node:Node = getNode(nodeID);
-                if ( node.parentWays.length == 0 )
+                if (!node.hasParentWays)
                     registerPOI(node);
             }
         }
index 6c0c9f6..5dc856e 100755 (executable)
@@ -20,6 +20,7 @@ package net.systemeD.halcyon.styleparser {
                private static const WHITESPACE:RegExp  =/^ \s+ /sx;
                private static const COMMENT:RegExp             =/^ \/\* .+? \*\/ \s* /sx;      /* */
                private static const CLASS:RegExp               =/^ ([\.:]\w+) \s* /sx;
+               private static const NOT_CLASS:RegExp   =/^ !([\.:]\w+) \s* /sx;
                private static const ZOOM:RegExp                =/^ \| \s* z([\d\-]+) \s* /isx;
                private static const GROUP:RegExp               =/^ , \s* /isx;
                private static const CONDITION:RegExp   =/^ \[(.+?)\] \s* /sx;
@@ -33,7 +34,7 @@ package net.systemeD.halcyon.styleparser {
                private static const ZOOM_SINGLE:RegExp =/^        (\d+) $/sx;
 
                private static const CONDITION_TRUE:RegExp      =/^ \s* (\w+) \s* = \s* yes \s*  $/isx;
-               private static const CONDITION_FALSE:RegExp     =/^ \s* (\w+) \s* = \s* no  \s*  $/isx;
+               private static const CONDITION_FALSE:RegExp     =/^ \s* (:\w+) \s* = \s* no  \s*  $/isx;
                private static const CONDITION_SET:RegExp       =/^ \s* (\w+) \s* $/sx;
                private static const CONDITION_UNSET:RegExp     =/^ \s* !(\w+) \s* $/sx;
                private static const CONDITION_EQ:RegExp        =/^ \s* (\w+) \s* =  \s* (.+) \s* $/sx;
@@ -237,6 +238,14 @@ package net.systemeD.halcyon.styleparser {
                                        sc.addCondition(new Condition('set',o[1]));
                                        previous=oCONDITION;
 
+                               // Not class - !.motorway, !.builtup, !:hover
+                               } else if ((o=NOT_CLASS.exec(css))) {
+                                       if (previous==oDECLARATION) { saveChooser(sc); sc=new StyleChooser(); }
+
+                                       css=css.replace(NOT_CLASS,'');
+                                       sc.addCondition(new Condition('unset',o[1]));
+                                       previous=oCONDITION;
+
                                // Zoom
                                } else if ((o=ZOOM.exec(css))) {
                                        if (previous!=oOBJECT && previous!=oCONDITION) { sc.newObject(); }
index cffeb30..504964c 100755 (executable)
@@ -56,6 +56,8 @@ package net.systemeD.halcyon.styleparser {
                                        }
                                        continue;
                                }
+                               if (a.width) { tags['stroked']='yes'; }
+                               if (a.width || a.fill_color || a.fill_image || a.casing_width) { tags['drawn']='yes'; }
 
                                r.runEvals(tags);
                                if (a[r.sublayer]) {
index dfb89ef..fc0b0a8 100644 (file)
@@ -2,6 +2,7 @@ package net.systemeD.potlatch2.controller {
        import flash.events.*;
     import net.systemeD.potlatch2.EditController;
     import net.systemeD.halcyon.connection.*;
+       import net.systemeD.halcyon.Globals;
 
     public class DragWayNode extends ControllerState {
         private var selectedWay:Way;
@@ -18,16 +19,21 @@ package net.systemeD.potlatch2.controller {
         }
  
         override public function processMouseEvent(event:MouseEvent, entity:Entity):ControllerState {
-            if ( event.type == MouseEvent.MOUSE_UP )
+            if ( event.type == MouseEvent.MOUSE_UP ) {
+                               Globals.vars.root.addDebug("dragwaynode - mouse-up");
                 return endDrag();
-
-            if ( !isDragging(event) )
-                return this;
+                       }
             
-            if ( event.type == MouseEvent.MOUSE_MOVE )
+            if ( !isDragging(event) ) {
+                               Globals.vars.root.addDebug("dragwaynode - not dragging");
+                return this;
+                       }
+
+            if ( event.type == MouseEvent.MOUSE_MOVE ) {
                 return dragTo(event);
-            else   
+                       } else {
                 return this;
+                       }
         }
 
         private function isDragging(event:MouseEvent):Boolean {
index 0dfe13b..6dfb25e 100644 (file)
@@ -2,6 +2,7 @@ package net.systemeD.potlatch2.controller {
        import flash.events.*;
     import net.systemeD.potlatch2.EditController;
     import net.systemeD.halcyon.connection.*;
+       import net.systemeD.halcyon.Globals;
 
     public class SelectedWay extends ControllerState {
         protected var selectedWay:Way;
@@ -51,30 +52,48 @@ package net.systemeD.potlatch2.controller {
         }
         
         override public function processMouseEvent(event:MouseEvent, entity:Entity):ControllerState {
+                       if (event.type==MouseEvent.MOUSE_MOVE || event.type==MouseEvent.MOUSE_OVER || event.type==MouseEvent.MOUSE_OUT) { return this; }
+
             var focus:Entity = NoSelection.getTopLevelFocusEntity(entity);
+                       if (entity) {
+                               Globals.vars.root.addDebug("entered SelectedWay pme "+event.type+":"+entity.getType());
+                       } else {
+                               Globals.vars.root.addDebug("entered SelectedWay pme "+event.type+":null");
+                       }
+                       
             if ( event.type == MouseEvent.CLICK ) {
-                if ( (entity is Node && entity.hasParent(selectedWay)) || focus == selectedWay )
+                               Globals.vars.root.addDebug("- is click");
+                               if ( entity is Node && event.shiftKey ) {
+                                       Globals.vars.root.addDebug("- start new way");
+                    var way:Way = controller.connection.createWay({}, [entity, entity]);
+                    return new DrawWay(way, true);
+                               } else if ( (entity is Node && entity.hasParent(selectedWay)) || focus == selectedWay ) {
+                                       Globals.vars.root.addDebug("- clicked on place within way");
                     return clickOnWay(event, entity);
-                else if ( focus is Way )
+                } else if ( focus is Way ) {
+                                       Globals.vars.root.addDebug("- selected way");
                     selectWay(focus as Way);
-                else if ( focus is Node )
+                } else if ( focus is Node ) {
+                                       Globals.vars.root.addDebug("- selected POI");
                     trace("select poi");
-                else if ( focus == null )
+                } else if ( focus == null ) {
+                                       Globals.vars.root.addDebug("- no selection");
                     return new NoSelection();
+                               }
             } else if ( event.type == MouseEvent.MOUSE_DOWN ) {
-                if ( entity is Node && entity.hasParent(selectedWay) )
+                               Globals.vars.root.addDebug("- is mousedown");
+                if ( entity is Node && entity.hasParent(selectedWay) ) {
+                                       Globals.vars.root.addDebug("- started dragging");
                     return new DragWayNode(selectedWay, Node(entity), event);
+                               }
             }
 
             return this;
         }
 
         public function clickOnWay(event:MouseEvent, entity:Entity):ControllerState {
-            if ( event.shiftKey ) {
-                if ( entity is Way )
-                    addNode(event);
-                else
-                    trace("start new way");
+            if ( entity is Way && event.shiftKey ) {
+                addNode(event);
             } else {
                 if ( entity is Node ) {
                     if ( selectedNode == entity ) {