Changeset 1263 in josm
- Timestamp:
- 2009-01-14T23:46:14+01:00 (16 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java
r1254 r1263 39 39 public Map<String, String> keys; 40 40 41 /** 42 * The key/value list for this primitive. 43 */ 41 /* mappaint data */ 42 public ElemStyle mappaintStyle = null; 43 public boolean isMappaintArea = false; 44 public Integer mappaintVisibleCode = 0; 45 public Integer mappaintDrawnCode = 0; 46 public Integer mappaintDrawnAreaCode = 0; 44 47 public Collection<String> errors; 48 49 public void putError(String text, Boolean isError) 50 { 51 if(errors == null) 52 errors = new ArrayList<String>(); 53 String s = isError ? tr("Error: {0}", text) : tr("Warning: {0}", text); 54 errors.add(s); 55 } 56 public void clearErrors() 57 { 58 errors = null; 59 } 60 /* end of mappaint data */ 45 61 46 62 /** … … 140 156 private static Collection<String> directionKeys = null; 141 157 142 143 /* mappaint style cache */144 public ElemStyle mappaintStyle = null;145 public boolean isMappaintArea = false;146 147 158 /** 148 159 * Implementation of the visitor scheme. Subclasses have to call the correct … … 331 342 } 332 343 } 333 334 public void putError(String text, Boolean isError)335 {336 if(errors == null)337 errors = new ArrayList<String>();338 String s = isError ? tr("Error: {0}", text) : tr("Warning: {0}", text);339 errors.add(s);340 }341 public void clearErrors()342 {343 errors = null;344 }345 344 } -
trunk/src/org/openstreetmap/josm/data/osm/visitor/MapPaintVisitor.java
r1255 r1263 40 40 protected boolean fillAreas; 41 41 protected boolean drawMultipolygon; 42 protected boolean showName; 42 43 protected int fillAlpha; 43 44 protected Color untaggedColor; … … 51 52 protected String regionalNameOrder[]; 52 53 protected Boolean selectedCall; 53 protected Collection<OsmPrimitive> alreadyDrawn;54 protected Collection<Way> alreadyDrawnAreas;55 54 protected Boolean useStyleCache; 56 55 private static int paintid = 0; 56 private static int viewid = 0; 57 57 58 protected int profilerVisibleNodes; 58 59 protected int profilerVisibleWays; 59 60 protected int profilerVisibleAreas; 61 protected int profilerSegments; 62 protected int profilerVisibleSegments; 63 protected boolean profilerOmitDraw; 60 64 61 65 protected boolean isZoomOk(ElemStyle e) { … … 105 109 // check, if the node is visible at all 106 110 Point p = nc.getPoint(n.eastNorth); 107 if ((!selectedCall && n.selected) || (p.x < 0) || (p.y < 0) 108 || (p.x > nc.getWidth()) || (p.y > nc.getHeight())) return; 109 111 if ((p.x < 0) || (p.y < 0) || (p.x > nc.getWidth()) || (p.y > nc.getHeight())) 112 { 113 n.mappaintVisibleCode = viewid; 114 return; 115 } 116 n.mappaintVisibleCode = 0; 117 110 118 profilerVisibleNodes++; 111 119 112 120 IconElemStyle nodeStyle = (IconElemStyle)getPrimitiveStyle(n); 121 122 if(profilerOmitDraw) 123 return; 124 113 125 if (nodeStyle != null && isZoomOk(nodeStyle)) 114 126 drawNode(n, nodeStyle.icon, nodeStyle.annotate, n.selected); … … 126 138 */ 127 139 public void visit(Way w) { 128 if(w.nodes.size() < 2 && (!selectedCall && w.selected)) 140 if(w.nodes.size() < 2) 141 { 142 w.mappaintVisibleCode = viewid; 129 143 return; 144 } 130 145 131 146 // check, if the way is visible at all 132 147 Polygon polygon = getPolygon(w); 133 148 if(!isPolygonVisible(polygon)) 149 { 150 w.mappaintVisibleCode = viewid; 134 151 return; 135 152 } 153 136 154 ElemStyle wayStyle = getPrimitiveStyle(w); 137 155 138 156 if(!isZoomOk(wayStyle)) 157 { 158 w.mappaintVisibleCode = viewid; 139 159 return; 160 } 161 162 w.mappaintVisibleCode = 0; 140 163 141 164 if(wayStyle==null) … … 143 166 // way without style 144 167 profilerVisibleWays++; 145 drawWay(w, null, untaggedColor, w.selected); 168 if(!profilerOmitDraw) 169 drawWay(w, null, untaggedColor, w.selected); 146 170 } 147 171 else if(wayStyle instanceof LineElemStyle) … … 149 173 // way with line style 150 174 profilerVisibleWays++; 151 drawWay(w, (LineElemStyle)wayStyle, untaggedColor, w.selected); 175 if(!profilerOmitDraw) 176 drawWay(w, (LineElemStyle)wayStyle, untaggedColor, w.selected); 152 177 } 153 178 else if (wayStyle instanceof AreaElemStyle) 154 179 { 155 180 // way with area style 156 if (fillAreas) 157 { 158 profilerVisibleAreas++; 159 drawArea(polygon, w.selected ? selectedColor : ((AreaElemStyle)wayStyle).color); 160 } 161 drawWay(w, ((AreaElemStyle)wayStyle).line, ((AreaElemStyle)wayStyle).color, w.selected); 181 if(!profilerOmitDraw) 182 { 183 if (fillAreas) 184 { 185 profilerVisibleAreas++; 186 drawArea(polygon, w.selected ? selectedColor : ((AreaElemStyle)wayStyle).color); 187 } 188 drawWay(w, ((AreaElemStyle)wayStyle).line, ((AreaElemStyle)wayStyle).color, w.selected); 189 } 162 190 } 163 191 } … … 360 388 drawSelected(m.member, styles != null ? styles.get(m.member) 361 389 : null, true, true); 362 alreadyDrawn.add(m.member);363 390 } 364 391 } … … 390 417 drawNode((Node)osm, selectedColor, selectedNodeSize, selectedNodeRadius, fillSelectedNode); 391 418 } 419 osm.mappaintDrawnCode = paintid; 392 420 } 393 421 394 422 public void visit(Relation r) { 423 424 r.mappaintVisibleCode = 0; 425 /* TODO implement visible handling for relations too */ 426 427 // TODO: is it possible to do this like the nodes/ways code? 428 if(profilerOmitDraw) 429 return; 430 395 431 // draw multipolygon relations including their ways 396 432 // other relations are only drawn when selected 397 if(r.selected) 398 { 399 if(selectedCall) 400 { 401 for (RelationMember m : r.members) 402 { 403 /* second call - draw nodes */ 404 if (m.member != null && !m.member.incomplete && !m.member.deleted 405 && m.member instanceof Node) 406 { 407 drawSelected(m.member, styles != null ? styles.get(m.member) : null, true, true); 408 alreadyDrawn.add(m.member); 409 } 410 } 411 return; 412 } 433 if(r.selected && selectedCall) 434 { 435 for (RelationMember m : r.members) 436 { 437 if (m.member != null && !m.member.incomplete && !m.member.deleted 438 && m.member instanceof Node) 439 { 440 drawSelected(m.member, styles != null ? styles.get(m.member) : null, true, true); 441 } 442 } 443 return; 413 444 } 414 445 if (!drawMultipolygon || r.keys == null || !"multipolygon".equals(r.keys.get("type"))) … … 429 460 for (RelationMember m : r.members) 430 461 { 431 if(m.member == null) /* Should not happen, must be a bug elsewhere */462 if(m.member == null) 432 463 r.putError(tr("Empty member in relation."), true); 433 464 else if(m.member.deleted) … … 462 493 else 463 494 { 464 /* nodes drawn on second call */465 495 r.putError(tr("Non-Way ''{0}'' in multipolygon.", 466 496 m.member.getName()), true); … … 470 500 471 501 ElemStyle wayStyle = styles != null ? styles.get(r) : null; 472 /* find one wayStyle, prefer the style from Relation or take the first473 one of outer rings */474 502 if(styles != null && (wayStyle == null || !(wayStyle instanceof AreaElemStyle))) 475 503 { … … 486 514 Collection<Way> join = new LinkedList<Way>(); 487 515 488 /* parse all outer rings and join them */489 516 for (Way w : outer) 490 517 { … … 498 525 } 499 526 500 /* parse all inner rings and join them */501 527 join.clear(); 502 528 for (Way w : inner) … … 516 542 r.getName()), true); 517 543 } 518 else if(zoomok) /* draw */544 else if(zoomok) 519 545 { 520 546 class PolyData { … … 540 566 --contains; 541 567 } 542 if(contains == 0) return 1; /* inside */543 if(contains == p.npoints) return 0; /* outside */544 return 2; /* mixed */568 if(contains == 0) return 1; 569 if(contains == p.npoints) return 0; 570 return 2; 545 571 } 546 572 public void addInner(Polygon p) … … 627 653 || r.selected); 628 654 } 629 alreadyDrawn.add(wInner);655 wInner.mappaintDrawnCode = paintid; 630 656 } 631 657 else … … 635 661 drawSelected(wInner, innerStyle, 636 662 !wayStyle.equals(innerStyle), wInner.selected); 637 alreadyDrawn.add(wInner);638 663 } 639 664 if(wayStyle.equals(innerStyle)) … … 642 667 wInner.getName()), false); 643 668 if(!r.selected) 644 alreadyDrawnAreas.add(wInner);669 wInner.mappaintDrawnAreaCode = paintid; 645 670 } 646 671 } … … 657 682 || r.selected); 658 683 } 659 alreadyDrawn.add(wOuter);684 wOuter.mappaintDrawnCode = paintid; 660 685 } 661 686 else … … 670 695 { 671 696 drawSelected(wOuter, outerStyle, false, false); 672 alreadyDrawn.add(wOuter); 673 } 674 // else if(outerStyle instanceof AreaElemStyle) 675 alreadyDrawnAreas.add(wOuter); 697 } 698 else if(outerStyle instanceof AreaElemStyle) 699 wOuter.mappaintDrawnAreaCode = paintid; 676 700 } 677 701 } … … 705 729 int w = icon.getIconWidth(), h=icon.getIconHeight(); 706 730 icon.paintIcon ( Main.map.mapView, g, p.x-w/2, p.y-h/2 ); 707 String name = getNodeName(n); 708 if (name!=null && annotate) 709 { 710 g.setColor(textColor); 711 Font defaultFont = g.getFont(); 712 g.setFont (orderFont); 713 g.drawString (name, p.x+w/2+2, p.y+h/2+2); 714 g.setFont(defaultFont); 731 if(showName) 732 { 733 String name = getNodeName(n); 734 if (name!=null && annotate) 735 { 736 g.setColor(textColor); 737 Font defaultFont = g.getFont(); 738 g.setFont (orderFont); 739 g.drawString (name, p.x+w/2+2, p.y+h/2+2); 740 g.setFont(defaultFont); 741 } 715 742 } 716 743 if (selected) … … 733 760 734 761 private void drawSeg(Node n1, Node n2, Color col, boolean showDirection, int width, boolean dashed) { 762 profilerSegments++; 735 763 if (col != currentColor || width != currentWidth || dashed != currentDashed) { 736 764 displaySegments(col, width, dashed); … … 742 770 return; 743 771 } 772 profilerVisibleSegments++; 744 773 currentPath.moveTo(p1.x, p1.y); 745 774 currentPath.lineTo(p2.x, p2.y); … … 797 826 g.drawRect(p.x - radius, p.y - radius, size, size); 798 827 799 String name = getNodeName(n); 800 if (name!=null /* && annotate */) 801 { 802 g.setColor(textColor); 803 Font defaultFont = g.getFont(); 804 g.setFont (orderFont); 805 g.drawString (name, p.x+radius+2, p.y+radius+2); 806 g.setFont(defaultFont); 828 if(showName) 829 { 830 String name = getNodeName(n); 831 if (name!=null /* && annotate */) 832 { 833 g.setColor(textColor); 834 Font defaultFont = g.getFont(); 835 g.setFont (orderFont); 836 g.drawString (name, p.x+radius+2, p.y+radius+2); 837 g.setFont(defaultFont); 838 } 807 839 } 808 840 } … … 820 852 821 853 boolean profiler = Main.pref.getBoolean("mappaint.profiler",false); 854 profilerOmitDraw = Main.pref.getBoolean("mappaint.profiler.omitdraw",false); 855 822 856 useStyleCache = Main.pref.getBoolean("mappaint.cache",true); 823 857 fillAreas = Main.pref.getBoolean("mappaint.fillareas", true); 824 858 fillAlpha = Math.min(255, Math.max(0, Integer.valueOf(Main.pref.getInteger("mappaint.fillalpha", 50)))); 859 showName = Main.pref.getBoolean("mappaint.showname", true); 825 860 826 861 long profilerStart = java.lang.System.currentTimeMillis(); … … 838 873 circum = Main.map.mapView.getScale()*100*Main.proj.scaleFactor()*40041455; // circumference of the earth in meter 839 874 styles = MapPaintStyles.getStyles().getStyleSet(); 840 drawMultipolygon = Main.pref.getBoolean("mappaint.multipolygon", false);875 drawMultipolygon = Main.pref.getBoolean("mappaint.multipolygon",true); 841 876 orderFont = new Font(Main.pref.get("mappaint.font","Helvetica"), Font.PLAIN, Main.pref.getInteger("mappaint.fontsize", 8)); 842 877 String currentLocale = Locale.getDefault().getLanguage(); 843 878 regionalNameOrder = Main.pref.get("mappaint.nameOrder", "name:"+currentLocale+";name;int_name;ref;operator;brand").split(";"); 844 879 845 alreadyDrawn = new LinkedList<OsmPrimitive>();846 alreadyDrawnAreas = new LinkedList<Way>();847 880 selectedCall = false; 848 881 ++paintid; 882 viewid = nc.getViewID(); 883 849 884 profilerVisibleNodes = 0; 850 885 profilerVisibleWays = 0; 851 886 profilerVisibleAreas = 0; 887 profilerSegments = 0; 888 profilerVisibleSegments = 0; 852 889 853 890 if(profiler) … … 864 901 for (final Relation osm : data.relations) 865 902 { 866 if(!osm.deleted && !osm.incomplete )903 if(!osm.deleted && !osm.incomplete && osm.mappaintVisibleCode != viewid) 867 904 { 868 905 osm.visit(this); … … 873 910 if(profiler) 874 911 { 875 System.out.format("Relations: %4dms, n=%5d\n", (java.lang.System.currentTimeMillis()-profilerLast), profilerN);912 System.out.format("Relations: %4dms, calls=%5d\n", (java.lang.System.currentTimeMillis()-profilerLast), profilerN); 876 913 profilerLast = java.lang.System.currentTimeMillis(); 877 914 } … … 881 918 for (final Way osm : data.ways) 882 919 { 883 //if (!osm.incomplete && !osm.deleted && !alreadyDrawn.contains(osm)) 884 if (!osm.incomplete && !osm.deleted) 885 { 886 //if(styles.isArea((Way)osm) && !alreadyDrawnAreas.contains(osm)) 887 if(isPrimitiveArea(osm)) 920 if (!osm.incomplete && !osm.deleted 921 && osm.mappaintVisibleCode != viewid && osm.mappaintDrawnCode != paintid) 922 { 923 if(isPrimitiveArea(osm) && osm.mappaintDrawnAreaCode != paintid) 888 924 { 889 925 osm.visit(this); … … 893 929 } 894 930 } 895 alreadyDrawnAreas = null;896 931 897 932 if(profiler) 898 933 { 899 System.out.format("Areas : %4dms, n=%5d, visible=%d\n",934 System.out.format("Areas : %4dms, calls=%5d, visible=%d\n", 900 935 (java.lang.System.currentTimeMillis()-profilerLast), profilerN, profilerVisibleAreas); 901 936 profilerLast = java.lang.System.currentTimeMillis(); … … 913 948 if(profiler) 914 949 { 915 System.out.format("Ways : %4dms, n=%5d, visible=%d\n",950 System.out.format("Ways : %4dms, calls=%5d, visible=%d\n", 916 951 (java.lang.System.currentTimeMillis()-profilerLast), profilerN, profilerVisibleWays); 917 952 profilerLast = java.lang.System.currentTimeMillis(); … … 923 958 profilerN = 0; 924 959 for (final OsmPrimitive osm : data.ways) 925 if (!osm.incomplete && !osm.deleted && !osm.selected) 960 if (!osm.incomplete && !osm.deleted && !osm.selected 961 && osm.mappaintVisibleCode != viewid ) 926 962 { 927 963 osm.visit(this); … … 931 967 if(profiler) 932 968 { 933 System.out.format("Ways : %4dms, n=%5d, visible=%d\n",969 System.out.format("Ways : %4dms, calls=%5d, visible=%d\n", 934 970 (java.lang.System.currentTimeMillis()-profilerLast), profilerN, profilerVisibleWays); 935 971 profilerLast = java.lang.System.currentTimeMillis(); … … 941 977 profilerN = 0; 942 978 for (final OsmPrimitive osm : data.getSelected()) { 943 if (!osm.incomplete && !osm.deleted 944 //&& !(osm instanceof Node) && !alreadyDrawn.contains(osm)) 945 && !(osm instanceof Node)) 979 if (!osm.incomplete && !osm.deleted && !(osm instanceof Node) 980 && osm.mappaintVisibleCode != viewid && osm.mappaintDrawnCode != paintid) 946 981 { 947 982 osm.visit(this); … … 952 987 if(profiler) 953 988 { 954 System.out.format("Selected : %4dms, n=%5d\n", (java.lang.System.currentTimeMillis()-profilerLast), profilerN);989 System.out.format("Selected : %4dms, calls=%5d\n", (java.lang.System.currentTimeMillis()-profilerLast), profilerN); 955 990 profilerLast = java.lang.System.currentTimeMillis(); 956 991 } … … 967 1002 profilerN = 0; 968 1003 for (final OsmPrimitive osm : data.nodes) 969 //if (!osm.incomplete && !osm.deleted && !alreadyDrawn.contains(osm))970 if (!osm.incomplete && !osm.deleted)1004 if (!osm.incomplete && !osm.deleted 1005 && osm.mappaintVisibleCode != viewid && osm.mappaintDrawnCode != paintid) 971 1006 { 972 1007 osm.visit(this); … … 976 1011 if(profiler) 977 1012 { 978 System.out.format("Nodes : %4dms, n=%5d, visible=%d\n",1013 System.out.format("Nodes : %4dms, calls=%5d, visible=%d\n", 979 1014 (java.lang.System.currentTimeMillis()-profilerLast), profilerN, profilerVisibleNodes); 980 1015 profilerLast = java.lang.System.currentTimeMillis(); 981 1016 } 982 983 alreadyDrawn = null;984 1017 985 1018 /*** VIRTUAL ***/ … … 989 1022 currentColor = nodeColor; 990 1023 for (final OsmPrimitive osm : data.ways) 991 if (!osm.incomplete && !osm.deleted) 992 { 993 visitVirtual((Way)osm); 1024 if (!osm.incomplete && !osm.deleted 1025 && osm.mappaintVisibleCode != viewid ) 1026 { 1027 // TODO: move this into the SimplePaint code? 1028 if(!profilerOmitDraw) 1029 visitVirtual((Way)osm); 994 1030 profilerN++; 995 1031 } … … 997 1033 if(profiler) 998 1034 { 999 System.out.format("Virtual : %4dms, n=%5d\n", (java.lang.System.currentTimeMillis()-profilerLast), profilerN);1035 System.out.format("Virtual : %4dms, calls=%5d\n", (java.lang.System.currentTimeMillis()-profilerLast), profilerN); 1000 1036 profilerLast = java.lang.System.currentTimeMillis(); 1001 1037 } … … 1011 1047 if(profiler) 1012 1048 { 1049 System.out.format("Segments : calls=%5d, visible=%d\n", profilerSegments, profilerVisibleSegments); 1013 1050 System.out.format("All : %4dms\n", (profilerLast-profilerStart)); 1014 1051 } -
trunk/src/org/openstreetmap/josm/gui/NavigatableComponent.java
r1169 r1263 67 67 return zoom; 68 68 return 32; 69 } 70 71 /** 72 * Return a ID which is unique as long as viewport dimensions are the same 73 */ 74 public Integer getViewID() 75 { 76 String x = center.east() + "_" + center.north() + "_" + scale + "_" + 77 getWidth() + "_" + getHeight(); 78 java.util.zip.CRC32 id = new java.util.zip.CRC32(); 79 id.update(x.getBytes()); 80 return new Long(id.getValue()).intValue(); 69 81 } 70 82
Note:
See TracChangeset
for help on using the changeset viewer.