Ignore:
Timestamp:
2012-01-04T02:11:38+01:00 (13 years ago)
Author:
frederik
Message:

update license change plugin to support odbl=clean; modify display of way segments so that it becomes clearer whether a node itself is tainted or just the way that uses it. TODO: make it so that odbl=clean is honoured even if set after running the license check.

Location:
applications/editors/josm/plugins/licensechange
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/licensechange/src/org/openstreetmap/josm/plugins/licensechange/LicenseChangePlugin.java

    r27206 r27400  
    1313import java.util.ArrayList;
    1414import java.util.Collection;
     15import java.util.Collections;
    1516import java.util.HashMap;
    1617import java.util.List;
     
    162163                 HashMap<Long, HashMap<User, Severity>> userMap = ("node".equals(qName)) ? nodeUsers : ("way".equals(qName)) ? wayUsers : relationUsers;
    163164                 // we always overwrite a list that might already exist
    164                  userMap.put(Long.decode(atts.getValue("id")), theMap = new HashMap<User, Severity>());
     165                 Long id = Long.decode(atts.getValue("id"));
     166                 theMap = userMap.get(id);
     167                 if (theMap == null) userMap.put(id, theMap = new HashMap<User, Severity>());
    165168            }
    166169            else if ("user".equals(qName))
     
    197200            public void visit(Node n) {
    198201                if (!nodeUsers.containsKey(n.getId())) {
    199                     nodesToLoad.append(",");
    200                     nodesToLoad.append(n.getId());
     202                    if ("clean".equals(n.get("odbl"))) {
     203                        nodeUsers.put(new Long(n.getId()), new HashMap<User, Severity>(Collections.singletonMap(n.getUser(), Severity.CLEAN)));
     204                    } else {
     205                        nodesToLoad.append(",");
     206                        nodesToLoad.append(n.getId());
     207                    }
    201208                }
    202209            }
    203210            public void visit(Way n) {
    204211                if (!wayUsers.containsKey(n.getId())) {
    205                     waysToLoad.append(",");
    206                     waysToLoad.append(n.getId());
     212                    if ("clean".equals(n.get("odbl"))) {
     213                        wayUsers.put(new Long(n.getId()), new HashMap<User, Severity>(Collections.singletonMap(n.getUser(), Severity.CLEAN)));
     214                    } else {
     215                        waysToLoad.append(",");
     216                        waysToLoad.append(n.getId());
     217                    }
    207218                }
    208219            }
    209220            public void visit(Relation n) {
    210221                if (!relationUsers.containsKey(n.getId())) {
    211                     relationsToLoad.append(",");
    212                     relationsToLoad.append(n.getId());
     222                    if ("clean".equals(n.get("odbl"))) {
     223                        relationUsers.put(new Long(n.getId()), new HashMap<User, Severity>(Collections.singletonMap(n.getUser(), Severity.CLEAN)));
     224                    } else {
     225                        relationsToLoad.append(",");
     226                        relationsToLoad.append(n.getId());
     227                    }
    213228                }
    214229            }
  • applications/editors/josm/plugins/licensechange/src/org/openstreetmap/josm/plugins/licensechange/LicenseChangeVisitor.java

    r25955 r27400  
    1010public interface LicenseChangeVisitor {
    1111    void visit(OsmPrimitive p);
    12     void visit(WaySegment ws);
    1312    void visit(List<Node> nodes);
    1413}
  • applications/editors/josm/plugins/licensechange/src/org/openstreetmap/josm/plugins/licensechange/LicenseProblem.java

    r25955 r27400  
    1515import org.openstreetmap.josm.data.osm.Relation;
    1616import org.openstreetmap.josm.data.osm.Way;
    17 import org.openstreetmap.josm.data.osm.WaySegment;
    1817import org.openstreetmap.josm.data.osm.visitor.AbstractVisitor;
    1918import org.openstreetmap.josm.gui.MapView;
     
    126125            if (o instanceof OsmPrimitive)
    127126                v.visit((OsmPrimitive) o);
    128             else if (o instanceof WaySegment)
    129                 v.visit((WaySegment) o);
    130127            else if (o instanceof List<?>) {
    131128                v.visit((List<Node>)o);
     
    169166            g.setColor(color);
    170167            if (selected) {
    171                 g.fillOval(p.x - 5, p.y - 5, 10, 10);
     168                g.fillOval(p.x - 6, p.y - 6, 12, 12);
    172169            } else
    173                 g.drawOval(p.x - 5, p.y - 5, 10, 10);
    174         }
    175 
    176         public void drawSegment(Point p1, Point p2, Color color) {
     170                g.drawOval(p.x - 6, p.y - 6, 12, 12);
     171        }
     172
     173        public void drawSegment(Point p1, Point p2, boolean linecapStart, boolean linecapEnd, Color color) {
    177174            g.setColor(color);
    178175
     
    182179            int deg = (int) Math.toDegrees(t);
    183180            if (selected) {
    184                 int[] x = new int[] { (int) (p1.x + 5 * cosT), (int) (p2.x + 5 * cosT), (int) (p2.x - 5 * cosT),
    185                         (int) (p1.x - 5 * cosT) };
    186                 int[] y = new int[] { (int) (p1.y - 5 * sinT), (int) (p2.y - 5 * sinT), (int) (p2.y + 5 * sinT),
    187                         (int) (p1.y + 5 * sinT) };
     181                int[] x = new int[] { (int) (p1.x + 4 * cosT), (int) (p2.x + 4 * cosT), (int) (p2.x - 4 * cosT),
     182                        (int) (p1.x - 4 * cosT) };
     183                int[] y = new int[] { (int) (p1.y - 4 * sinT), (int) (p2.y - 4 * sinT), (int) (p2.y + 4 * sinT),
     184                        (int) (p1.y + 4 * sinT) };
    188185                g.fillPolygon(x, y, 4);
    189                 g.fillArc(p1.x - 5, p1.y - 5, 10, 10, deg, 180);
    190                 g.fillArc(p2.x - 5, p2.y - 5, 10, 10, deg, -180);
     186                if (linecapStart) g.fillArc(p1.x - 4, p1.y - 4, 8, 8, deg, 180);
     187                if (linecapEnd) g.fillArc(p2.x - 4, p2.y - 4, 8, 8, deg, -180);
    191188            } else {
    192                 g.drawLine((int) (p1.x + 5 * cosT), (int) (p1.y - 5 * sinT), (int) (p2.x + 5 * cosT),
    193                         (int) (p2.y - 5 * sinT));
    194                 g.drawLine((int) (p1.x - 5 * cosT), (int) (p1.y + 5 * sinT), (int) (p2.x - 5 * cosT),
    195                         (int) (p2.y + 5 * sinT));
    196                 g.drawArc(p1.x - 5, p1.y - 5, 10, 10, deg, 180);
    197                 g.drawArc(p2.x - 5, p2.y - 5, 10, 10, deg, -180);
     189                g.drawLine((int) (p1.x + 4 * cosT), (int) (p1.y - 4 * sinT), (int) (p2.x + 4 * cosT),
     190                        (int) (p2.y - 4 * sinT));
     191                g.drawLine((int) (p1.x - 4 * cosT), (int) (p1.y + 4 * sinT), (int) (p2.x - 4 * cosT),
     192                        (int) (p2.y + 4 * sinT));
     193                if (linecapStart) g.drawArc(p1.x - 4, p1.y - 4, 8, 8, deg, 180);
     194                if (linecapEnd) g.drawArc(p2.x - 4, p2.y - 4, 8, 8, deg, -180);
    198195            }
    199196        }
     
    205202         * @param color The color
    206203         */
    207         public void drawSegment(Node n1, Node n2, Color color) {
    208             drawSegment(mv.getPoint(n1), mv.getPoint(n2), color);
     204        public void drawSegment(Node n1, Node n2, boolean linecapStart, boolean linecapEnd, Color color) {
     205            drawSegment(mv.getPoint(n1), mv.getPoint(n2), linecapStart, linecapEnd, color);
    209206        }
    210207
     
    222219        public void visit(Way w) {
    223220            visit(w.getNodes());
    224         }
    225 
    226         public void visit(WaySegment ws) {
    227             if (ws.lowerIndex < 0 || ws.lowerIndex + 1 >= ws.way.getNodesCount())
    228                 return;
    229             Node a = ws.way.getNodes().get(ws.lowerIndex), b = ws.way.getNodes().get(ws.lowerIndex + 1);
    230             if (isSegmentVisible(a, b)) {
    231                 drawSegment(a, b, severity.getColor());
    232             }
    233221        }
    234222
     
    269257
    270258        public void visit(List<Node> nodes) {
    271             Node lastN = null;
     259            Node[] window = new Node[4];
     260            int index = 1;
     261            window[0] = null;
    272262            for (Node n : nodes) {
    273                 if (lastN == null) {
    274                     lastN = n;
     263                if (index == 1)
     264                {
     265                    window[1] = n;
     266                    index = 2;
    275267                    continue;
    276268                }
    277                 if (n.isDrawable() && isSegmentVisible(lastN, n)) {
    278                     drawSegment(lastN, n, severity.getColor());
     269                window[index++] = n;
     270                if (index==4)
     271                {
     272                    drawSegment(window[1], window[2], window[0] == null, !isSegmentVisible(window[2], window[3]), severity.getColor());
     273                    window[0] = window[1];
     274                    window[1] = window[2];
     275                    window[2] = window[3];
     276                    index = 3;
    279277                }
    280                 lastN = n;
    281             }
     278            }
     279            if (window[1] != null && window[2] != null) drawSegment(window[1], window[2], window[0] == null, true, severity.getColor());
    282280        }
    283281    }
  • applications/editors/josm/plugins/licensechange/src/org/openstreetmap/josm/plugins/licensechange/Severity.java

    r27206 r27400  
    1111/** The error severity */
    1212public enum Severity {
     13
     14    /** clean override */
     15    CLEAN(tr("overridden with odbl=clean"), "clean",           
     16        Main.pref.getColor(marktr("license check info"), Color.GREEN)),
    1317
    1418    /** Error messages */
Note: See TracChangeset for help on using the changeset viewer.