Changeset 1263 in josm for trunk/src


Ignore:
Timestamp:
2009-01-14T23:46:14+01:00 (15 years ago)
Author:
ulfl
Message:

from Dirk Stoecker: fix multipolygon display after (my) performance tweaks

from myself: some minor changes like adding a "mappaint.showname" option to be able to globally switch off icon annotations

Location:
trunk/src/org/openstreetmap/josm
Files:
3 edited

Legend:

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

    r1254 r1263  
    3939    public Map<String, String> keys;
    4040
    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;
    4447    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 */
    4561
    4662    /**
     
    140156    private static Collection<String> directionKeys = null;
    141157
    142        
    143     /* mappaint style cache */
    144     public ElemStyle mappaintStyle = null;
    145     public boolean isMappaintArea = false;
    146        
    147158    /**
    148159     * Implementation of the visitor scheme. Subclasses have to call the correct
     
    331342        }
    332343    }
    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     }
    345344}
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/MapPaintVisitor.java

    r1255 r1263  
    4040    protected boolean fillAreas;
    4141    protected boolean drawMultipolygon;
     42    protected boolean showName;
    4243    protected int fillAlpha;
    4344    protected Color untaggedColor;
     
    5152    protected String regionalNameOrder[];
    5253    protected Boolean selectedCall;
    53     protected Collection<OsmPrimitive> alreadyDrawn;
    54     protected Collection<Way> alreadyDrawnAreas;
    5554    protected Boolean useStyleCache;
    56    
     55    private static int paintid = 0;
     56    private static int viewid = 0;
     57
    5758    protected int profilerVisibleNodes;
    5859    protected int profilerVisibleWays;
    5960    protected int profilerVisibleAreas;
     61    protected int profilerSegments;
     62    protected int profilerVisibleSegments;
     63    protected boolean profilerOmitDraw;
    6064
    6165    protected boolean isZoomOk(ElemStyle e) {
     
    105109        // check, if the node is visible at all
    106110        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
    110118        profilerVisibleNodes++;
    111119       
    112120        IconElemStyle nodeStyle = (IconElemStyle)getPrimitiveStyle(n);
     121
     122        if(profilerOmitDraw)
     123            return;
     124           
    113125        if (nodeStyle != null && isZoomOk(nodeStyle))
    114126            drawNode(n, nodeStyle.icon, nodeStyle.annotate, n.selected);
     
    126138     */
    127139    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;
    129143            return;
     144        }
    130145
    131146        // check, if the way is visible at all
    132147        Polygon polygon = getPolygon(w);
    133148        if(!isPolygonVisible(polygon))
     149        {
     150            w.mappaintVisibleCode = viewid;
    134151            return;
    135            
     152        }
     153
    136154        ElemStyle wayStyle = getPrimitiveStyle(w);
    137155
    138156        if(!isZoomOk(wayStyle))
     157        {
     158            w.mappaintVisibleCode = viewid;
    139159            return;
     160        }
     161
     162        w.mappaintVisibleCode = 0;
    140163
    141164        if(wayStyle==null)
     
    143166            // way without style
    144167            profilerVisibleWays++;
    145             drawWay(w, null, untaggedColor, w.selected);
     168            if(!profilerOmitDraw)
     169                drawWay(w, null, untaggedColor, w.selected);
    146170        }
    147171        else if(wayStyle instanceof LineElemStyle)
     
    149173            // way with line style
    150174            profilerVisibleWays++;
    151             drawWay(w, (LineElemStyle)wayStyle, untaggedColor, w.selected);
     175            if(!profilerOmitDraw)
     176                drawWay(w, (LineElemStyle)wayStyle, untaggedColor, w.selected);
    152177        }
    153178        else if (wayStyle instanceof AreaElemStyle)
    154179        {
    155180            // 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            }
    162190        }
    163191    }
     
    360388                    drawSelected(m.member, styles != null ? styles.get(m.member)
    361389                    : null, true, true);
    362                 alreadyDrawn.add(m.member);
    363390            }
    364391        }
     
    390417                drawNode((Node)osm, selectedColor, selectedNodeSize, selectedNodeRadius, fillSelectedNode);
    391418        }
     419        osm.mappaintDrawnCode = paintid;
    392420    }
    393421
    394422    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
    395431        // draw multipolygon relations including their ways
    396432        // 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;
    413444        }
    414445        if (!drawMultipolygon || r.keys == null || !"multipolygon".equals(r.keys.get("type")))
     
    429460        for (RelationMember m : r.members)
    430461        {
    431             if(m.member == null) /* Should not happen, must be a bug elsewhere */
     462            if(m.member == null)
    432463                r.putError(tr("Empty member in relation."), true);
    433464            else if(m.member.deleted)
     
    462493                else
    463494                {
    464                     /* nodes drawn on second call */
    465495                    r.putError(tr("Non-Way ''{0}'' in multipolygon.",
    466496                    m.member.getName()), true);
     
    470500
    471501        ElemStyle wayStyle = styles != null ? styles.get(r) : null;
    472         /* find one wayStyle, prefer the style from Relation or take the first
    473         one of outer rings */
    474502        if(styles != null && (wayStyle == null || !(wayStyle instanceof AreaElemStyle)))
    475503        {
     
    486514            Collection<Way> join = new LinkedList<Way>();
    487515
    488             /* parse all outer rings and join them */
    489516            for (Way w : outer)
    490517            {
     
    498525            }
    499526
    500             /* parse all inner rings and join them */
    501527            join.clear();
    502528            for (Way w : inner)
     
    516542                r.getName()), true);
    517543            }
    518             else if(zoomok) /* draw */
     544            else if(zoomok)
    519545            {
    520546                class PolyData {
     
    540566                                --contains;
    541567                        }
    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;
    545571                    }
    546572                    public void addInner(Polygon p)
     
    627653                        || r.selected);
    628654                    }
    629                     alreadyDrawn.add(wInner);
     655                    wInner.mappaintDrawnCode = paintid;
    630656                }
    631657                else
     
    635661                        drawSelected(wInner, innerStyle,
    636662                        !wayStyle.equals(innerStyle), wInner.selected);
    637                         alreadyDrawn.add(wInner);
    638663                    }
    639664                    if(wayStyle.equals(innerStyle))
     
    642667                        wInner.getName()), false);
    643668                        if(!r.selected)
    644                             alreadyDrawnAreas.add(wInner);
     669                            wInner.mappaintDrawnAreaCode = paintid;
    645670                    }
    646671                }
     
    657682                        || r.selected);
    658683                    }
    659                     alreadyDrawn.add(wOuter);
     684                    wOuter.mappaintDrawnCode = paintid;
    660685                }
    661686                else
     
    670695                    {
    671696                        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;
    676700                }
    677701            }
     
    705729        int w = icon.getIconWidth(), h=icon.getIconHeight();
    706730        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            }
    715742        }
    716743        if (selected)
     
    733760
    734761    private void drawSeg(Node n1, Node n2, Color col, boolean showDirection, int width, boolean dashed) {
     762        profilerSegments++;
    735763        if (col != currentColor || width != currentWidth || dashed != currentDashed) {
    736764            displaySegments(col, width, dashed);
     
    742770            return;
    743771        }
     772        profilerVisibleSegments++;
    744773        currentPath.moveTo(p1.x, p1.y);
    745774        currentPath.lineTo(p2.x, p2.y);
     
    797826                g.drawRect(p.x - radius, p.y - radius, size, size);
    798827
    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                }
    807839            }
    808840        }
     
    820852
    821853        boolean profiler = Main.pref.getBoolean("mappaint.profiler",false);
     854        profilerOmitDraw = Main.pref.getBoolean("mappaint.profiler.omitdraw",false);
     855       
    822856        useStyleCache = Main.pref.getBoolean("mappaint.cache",true);
    823857        fillAreas = Main.pref.getBoolean("mappaint.fillareas", true);
    824858        fillAlpha = Math.min(255, Math.max(0, Integer.valueOf(Main.pref.getInteger("mappaint.fillalpha", 50))));
     859        showName = Main.pref.getBoolean("mappaint.showname", true);
    825860
    826861        long profilerStart = java.lang.System.currentTimeMillis();
     
    838873        circum = Main.map.mapView.getScale()*100*Main.proj.scaleFactor()*40041455; // circumference of the earth in meter
    839874        styles = MapPaintStyles.getStyles().getStyleSet();
    840         drawMultipolygon = Main.pref.getBoolean("mappaint.multipolygon",false);
     875        drawMultipolygon = Main.pref.getBoolean("mappaint.multipolygon",true);
    841876        orderFont = new Font(Main.pref.get("mappaint.font","Helvetica"), Font.PLAIN, Main.pref.getInteger("mappaint.fontsize", 8));
    842877        String currentLocale = Locale.getDefault().getLanguage();
    843878        regionalNameOrder = Main.pref.get("mappaint.nameOrder", "name:"+currentLocale+";name;int_name;ref;operator;brand").split(";");
    844879
    845         alreadyDrawn = new LinkedList<OsmPrimitive>();
    846         alreadyDrawnAreas = new LinkedList<Way>();
    847880        selectedCall = false;
    848        
     881        ++paintid;
     882        viewid = nc.getViewID();
     883
    849884        profilerVisibleNodes = 0;
    850885        profilerVisibleWays = 0;
    851886        profilerVisibleAreas = 0;
     887        profilerSegments = 0;
     888        profilerVisibleSegments = 0;
    852889
    853890        if(profiler)
     
    864901            for (final Relation osm : data.relations)
    865902            {
    866                 if(!osm.deleted && !osm.incomplete)
     903                if(!osm.deleted && !osm.incomplete && osm.mappaintVisibleCode != viewid)
    867904                {
    868905                    osm.visit(this);
     
    873910            if(profiler)
    874911            {
    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);
    876913                profilerLast = java.lang.System.currentTimeMillis();
    877914            }
     
    881918            for (final Way osm : data.ways)
    882919            {
    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)
    888924                    {
    889925                        osm.visit(this);
     
    893929                }
    894930            }
    895             alreadyDrawnAreas = null;
    896931
    897932            if(profiler)
    898933            {
    899                 System.out.format("Areas    : %4dms, n=%5d, visible=%d\n",
     934                System.out.format("Areas    : %4dms, calls=%5d, visible=%d\n",
    900935                    (java.lang.System.currentTimeMillis()-profilerLast), profilerN, profilerVisibleAreas);
    901936                profilerLast = java.lang.System.currentTimeMillis();
     
    913948            if(profiler)
    914949            {
    915                 System.out.format("Ways     : %4dms, n=%5d, visible=%d\n",
     950                System.out.format("Ways     : %4dms, calls=%5d, visible=%d\n",
    916951                    (java.lang.System.currentTimeMillis()-profilerLast), profilerN, profilerVisibleWays);
    917952                profilerLast = java.lang.System.currentTimeMillis();
     
    923958            profilerN = 0;
    924959            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 )
    926962                {
    927963                    osm.visit(this);
     
    931967            if(profiler)
    932968            {
    933                 System.out.format("Ways     : %4dms, n=%5d, visible=%d\n",
     969                System.out.format("Ways     : %4dms, calls=%5d, visible=%d\n",
    934970                    (java.lang.System.currentTimeMillis()-profilerLast), profilerN, profilerVisibleWays);
    935971                profilerLast = java.lang.System.currentTimeMillis();
     
    941977        profilerN = 0;
    942978        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)
    946981            {
    947982                osm.visit(this);
     
    952987        if(profiler)
    953988        {
    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);
    955990            profilerLast = java.lang.System.currentTimeMillis();
    956991        }
     
    9671002        profilerN = 0;
    9681003        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)
    9711006            {
    9721007                osm.visit(this);
     
    9761011        if(profiler)
    9771012        {
    978             System.out.format("Nodes    : %4dms, n=%5d, visible=%d\n",
     1013            System.out.format("Nodes    : %4dms, calls=%5d, visible=%d\n",
    9791014                (java.lang.System.currentTimeMillis()-profilerLast), profilerN, profilerVisibleNodes);
    9801015            profilerLast = java.lang.System.currentTimeMillis();
    9811016        }
    982 
    983         alreadyDrawn = null;
    9841017
    9851018        /*** VIRTUAL  ***/
     
    9891022            currentColor = nodeColor;
    9901023            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);
    9941030                    profilerN++;
    9951031                }
     
    9971033            if(profiler)
    9981034            {
    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);
    10001036                profilerLast = java.lang.System.currentTimeMillis();
    10011037            }
     
    10111047        if(profiler)
    10121048        {
     1049            System.out.format("Segments :         calls=%5d, visible=%d\n", profilerSegments, profilerVisibleSegments);
    10131050            System.out.format("All      : %4dms\n", (profilerLast-profilerStart));
    10141051        }
  • trunk/src/org/openstreetmap/josm/gui/NavigatableComponent.java

    r1169 r1263  
    6767                return zoom;
    6868        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();
    6981    }
    7082
Note: See TracChangeset for help on using the changeset viewer.