Ignore:
Timestamp:
18.08.2008 01:27:58 (4 years ago)
Author:
stoecker
Message:

Added virtual nodes in select mode. Closes #595.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/SimplePaintVisitor.java

    r804 r805  
    2727 
    2828/** 
    29  * A visitor that paints a simple scheme of every primitive it visits to a  
     29 * A visitor that paints a simple scheme of every primitive it visits to a 
    3030 * previous set graphic environment. 
    31  *  
     31 * 
    3232 * @author imi 
    3333 */ 
     
    4747         */ 
    4848        protected NavigatableComponent nc; 
    49          
     49 
    5050        public boolean inactive; 
    5151 
    5252        protected static final double PHI = Math.toRadians(20); 
    53          
     53 
    5454        /** 
    5555         * Preferences 
     
    6363        protected Color incompleteColor; 
    6464        protected Color backgroundColor; 
    65     protected boolean showDirectionArrow; 
    66     protected boolean showRelevantDirectionsOnly; 
     65        protected boolean showDirectionArrow; 
     66        protected boolean showRelevantDirectionsOnly; 
    6767        protected boolean showOrderNumber; 
    68          
    69         private boolean fillSelectedNode; 
    70  
    71         private boolean fillUnselectedNode; 
    72  
    73         private int selectedNodeRadius; 
    74  
    75         private int unselectedNodeRadius; 
    76  
    77         private int selectedNodeSize; 
    78  
    79         private int unselectedNodeSize; 
    80  
    81         private int defaultSegmentWidth = 2; 
     68        protected boolean fillSelectedNode; 
     69        protected boolean fillUnselectedNode; 
     70        protected int selectedNodeRadius; 
     71        protected int unselectedNodeRadius; 
     72        protected int selectedNodeSize; 
     73        protected int unselectedNodeSize; 
     74        protected int defaultSegmentWidth = 2; 
     75        protected int virtualNodeSize; 
     76        protected int virtualNodeSpace; 
     77        protected int taggedNodeRadius; 
     78        protected int taggedNodeSize; 
    8279 
    8380        /** 
     
    8885 
    8986        Rectangle bbox = new Rectangle(); 
    90         private int taggedNodeRadius; 
    91         private int taggedNodeSize; 
    92  
    93         public void visitAll(DataSet data) { 
     87 
     88        protected void getSettings(Boolean virtual) { 
    9489                inactiveColor = Main.pref.getColor(marktr("inactive"), Color.DARK_GRAY); 
    9590                selectedColor = Main.pref.getColor(marktr("selected"), Color.WHITE); 
     
    10398                showRelevantDirectionsOnly = Main.pref.getBoolean("draw.segment.relevant_directions_only"); 
    10499                showOrderNumber = Main.pref.getBoolean("draw.segment.order_number"); 
    105                  
    106                 selectedNodeRadius = Main.pref.getInteger("mappaint.node.selected-size", 
    107                         5) / 2; 
     100                selectedNodeRadius = Main.pref.getInteger("mappaint.node.selected-size", 5) / 2; 
    108101                selectedNodeSize = selectedNodeRadius * 2; 
    109                 unselectedNodeRadius = Main.pref.getInteger( 
    110                         "mappaint.node.unselected-size", 3) / 2; 
     102                unselectedNodeRadius = Main.pref.getInteger("mappaint.node.unselected-size", 3) / 2; 
    111103                unselectedNodeSize = unselectedNodeRadius * 2; 
    112  
    113                 taggedNodeRadius = Main.pref.getInteger( 
    114                                 "mappaint.node.tagged-size", 5) / 2; 
     104                taggedNodeRadius = Main.pref.getInteger("mappaint.node.tagged-size", 5) / 2; 
    115105                taggedNodeSize = taggedNodeRadius * 2; 
    116  
    117                 defaultSegmentWidth = Main.pref.getInteger( 
    118                         "mappaint.segment.default-width", 2); 
    119  
    120                 fillSelectedNode = Main.pref.getBoolean("mappaint.node.fill-selected", 
    121                         true); 
    122                 fillUnselectedNode = Main.pref.getBoolean( 
    123                         "mappaint.node.fill-unselected", false); 
     106                defaultSegmentWidth = Main.pref.getInteger("mappaint.segment.default-width", 2); 
     107                fillSelectedNode = Main.pref.getBoolean("mappaint.node.fill-selected", true); 
     108                fillUnselectedNode = Main.pref.getBoolean("mappaint.node.fill-unselected", false); 
     109                virtualNodeSize = virtual ? Main.pref.getInteger("mappaint.node.virtual-size", 4) / 2 : 0; 
     110                virtualNodeSpace = Main.pref.getInteger("mappaint.node.virtual-space", 50); 
    124111 
    125112                ((Graphics2D)g) 
    126                         .setRenderingHint( 
    127                                 RenderingHints.KEY_ANTIALIASING, 
    128                                 Main.pref.getBoolean("mappaint.use-antialiasing", true) ? RenderingHints.VALUE_ANTIALIAS_ON 
    129                                         : RenderingHints.VALUE_ANTIALIAS_OFF); 
    130  
     113                                .setRenderingHint( 
     114                                                RenderingHints.KEY_ANTIALIASING, 
     115                                                Main.pref.getBoolean("mappaint.use-antialiasing", true) ? RenderingHints.VALUE_ANTIALIAS_ON 
     116                                                                : RenderingHints.VALUE_ANTIALIAS_OFF); 
     117        } 
     118 
     119        public void visitAll(DataSet data, Boolean virtual) { 
     120                getSettings(virtual); 
    131121                // draw tagged ways first, then untagged ways. takes 
    132122                // time to iterate through list twice, OTOH does not 
     
    141131                displaySegments(null); 
    142132 
    143             for (final OsmPrimitive osm : data.ways) 
     133                for (final OsmPrimitive osm : data.ways) 
    144134                        if (!osm.deleted && !osm.selected && !osm.tagged) 
    145135                                osm.visit(this); 
    146136                displaySegments(null); 
    147              
     137 
    148138                for (final OsmPrimitive osm : data.nodes) 
    149139                        if (!osm.deleted && !osm.selected) 
    150140                                osm.visit(this); 
    151          
     141 
    152142                for (final OsmPrimitive osm : data.getSelected()) 
    153143                        if (!osm.deleted) 
    154144                                osm.visit(this); 
    155145                displaySegments(null); 
    156         } 
    157  
    158         /** 
    159          * Draw a small rectangle.  
     146        } 
     147 
     148        /** 
     149         * Draw a small rectangle. 
    160150         * White if selected (as always) or red otherwise. 
    161          *  
     151         * 
    162152         * @param n The node to draw. 
    163153         */ 
     
    171161                else if(n.tagged) 
    172162                        drawNode(n, nodeColor, taggedNodeSize, taggedNodeRadius, fillUnselectedNode); 
    173                 else  
     163                else 
    174164                        drawNode(n, nodeColor, unselectedNodeSize, unselectedNodeRadius, fillUnselectedNode); 
    175165        } 
     
    182172                if (w.incomplete) return; 
    183173 
    184                 // show direction arrows, if draw.segment.relevant_directions_only is not set, the way is tagged with a direction key 
    185                 // (even if the tag is negated as in oneway=false) or the way is selected 
    186  
    187                 boolean showThisDirectionArrow = w.selected 
    188                                                 || (showDirectionArrow 
    189                                                     && (!showRelevantDirectionsOnly || w.hasDirectionKeys)); 
     174                                // show direction arrows, if draw.segment.relevant_directions_only is not set, the way is tagged with a direction key 
     175                                // (even if the tag is negated as in oneway=false) or the way is selected 
     176 
     177                                boolean showThisDirectionArrow = w.selected 
     178                                                                                                || (showDirectionArrow 
     179                                                                                                        && (!showRelevantDirectionsOnly || w.hasDirectionKeys)); 
    190180                Color wayColor; 
    191                  
     181 
    192182                if (inactive) { 
    193183                        wayColor = inactiveColor; 
     
    254244                } 
    255245        } 
    256          
     246 
    257247        /** 
    258248         * Draw an number of the order of the two consecutive nodes within the 
     
    271261                        g.drawString(""+orderNumber, x, y); 
    272262                } 
    273     } 
     263        } 
    274264 
    275265        /** 
     
    283273                        Point p = nc.getPoint(n.eastNorth); 
    284274                        if ((p.x < 0) || (p.y < 0) || (p.x > nc.getWidth()) 
    285                                 || (p.y > nc.getHeight())) 
     275                                        || (p.y > nc.getHeight())) 
    286276                                return; 
    287277                        g.setColor(color); 
     
    294284        } 
    295285 
     286        protected void drawVirtualNode(Point p1, Point p2, Color col) 
     287        { 
     288                if(virtualNodeSize > 0) 
     289                { 
     290                        int xd = p2.x-p1.x; if(xd < 0) xd = -xd; 
     291                        int yd = p2.y-p1.y; if(yd < 0) yd = -yd; 
     292                        if(xd+yd > virtualNodeSpace) 
     293                        { 
     294                                int x = (p1.x+p2.x)/2; 
     295                                int y = (p1.y+p2.y)/2; 
     296                                currentPath.moveTo(x-5, y); 
     297                                currentPath.lineTo(x+5, y); 
     298                                currentPath.moveTo(x, y-5); 
     299                                currentPath.lineTo(x, y+5); 
     300                        } 
     301                } 
     302        } 
     303 
    296304        /** 
    297305         * Draw a line with the given color. 
     
    300308 
    301309                if (col != currentColor) displaySegments(col); 
    302                  
     310 
    303311                if (isSegmentVisible(p1, p2)) { 
     312                        drawVirtualNode(p1, p2, col); 
     313 
    304314                        currentPath.moveTo(p1.x, p1.y); 
    305315                        currentPath.lineTo(p2.x, p2.y); 
    306                          
     316 
    307317                        if (showDirection) { 
    308318                                double t = Math.atan2(p2.y-p1.y, p2.x-p1.x) + Math.PI; 
    309319                                currentPath.lineTo((int)(p2.x + 10*Math.cos(t-PHI)), (int)(p2.y + 10*Math.sin(t-PHI))); 
    310320                                currentPath.moveTo((int)(p2.x + 10*Math.cos(t+PHI)), (int)(p2.y + 10*Math.sin(t+PHI))); 
    311                                 currentPath.lineTo(p2.x, p2.y);   
     321                                currentPath.lineTo(p2.x, p2.y); 
    312322                        } 
    313323                } 
    314324        } 
    315          
    316     private boolean isSegmentVisible(Point p1, Point p2) { 
    317         if ((p1.x < 0) && (p2.x < 0)) return false; 
    318         if ((p1.y < 0) && (p2.y < 0)) return false; 
    319         if ((p1.x > nc.getWidth()) && (p2.x > nc.getWidth())) return false; 
    320         if ((p1.y > nc.getHeight()) && (p2.y > nc.getHeight())) return false; 
    321         return true; 
    322     } 
    323          
     325 
     326        protected boolean isSegmentVisible(Point p1, Point p2) { 
     327                if ((p1.x < 0) && (p2.x < 0)) return false; 
     328                if ((p1.y < 0) && (p2.y < 0)) return false; 
     329                if ((p1.x > nc.getWidth()) && (p2.x > nc.getWidth())) return false; 
     330                if ((p1.y > nc.getHeight()) && (p2.y > nc.getHeight())) return false; 
     331                return true; 
     332        } 
     333 
    324334        public void setGraphics(Graphics g) { 
    325335                this.g = g; 
     
    327337 
    328338        public void setNavigatableComponent(NavigatableComponent nc) { 
    329         this.nc = nc; 
    330     } 
     339                this.nc = nc; 
     340        } 
    331341 
    332342        protected void displaySegments(Color newColor) { 
     
    338348                } 
    339349        } 
    340          
    341         /** 
    342          * Provided for backwards compatibility only. 
    343          * FIXME: remove this once not used by plugins any longer. 
    344          */ 
    345         public static Color getPreferencesColor(String name, Color dflt) { 
    346                 return Main.pref.getColor(name, dflt); 
    347         } 
    348350} 
Note: See TracChangeset for help on using the changeset viewer.