Ignore:
Timestamp:
2011-12-03T03:08:44+01:00 (12 years ago)
Author:
Don-vip
Message:

see #6987 - optim: moving a node belonging to a MP only resets concerned PolyData objects

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/relations/Multipolygon.java

    r4628 r4629  
    1919import org.openstreetmap.josm.data.osm.RelationMember;
    2020import org.openstreetmap.josm.data.osm.Way;
     21import org.openstreetmap.josm.data.osm.event.NodeMovedEvent;
    2122import org.openstreetmap.josm.data.osm.visitor.paint.relations.Multipolygon.PolyData.Intersection;
    2223
     
    176177        private Rectangle2D bounds;
    177178        private final Collection<Way> ways;
     179        private final List<Node> nodes;
     180        private final List<PolyData> inners;
    178181
    179182        public PolyData(JoinedWay joinedWay, Collection<Way> refWays) {
     
    183186        public PolyData(List<Node> nodes, boolean selected, Collection<Way> refWays) {
    184187            this.ways = Collections.unmodifiableCollection(refWays);
     188            this.nodes = Collections.unmodifiableList(nodes);
    185189            this.selected = selected;
    186             boolean initial = true;
     190            this.inners = new ArrayList<Multipolygon.PolyData>();
    187191            this.poly = new Path2D.Double();
    188192            this.poly.setWindingRule(Path2D.WIND_EVEN_ODD);
     193            buildPoly();
     194        }
     195       
     196        private void buildPoly() {
     197            boolean initial = true;
    189198            for (Node n : nodes)
    190199            {
     
    198207            }
    199208            poly.closePath();
     209            for (PolyData inner : inners) {
     210                appendInner(inner.poly);
     211            }
    200212        }
    201213
     
    203215            this.selected = copy.selected;
    204216            this.poly = (Double) copy.poly.clone();
    205             this.ways = new ArrayList<Way>(copy.ways);
     217            this.ways = Collections.unmodifiableCollection(copy.ways);
     218            this.nodes = Collections.unmodifiableList(copy.nodes);
     219            this.inners = new ArrayList<Multipolygon.PolyData>(copy.inners);
    206220        }
    207221       
     
    225239        }
    226240
    227         public void addInner(Path2D.Double inner) {
     241        public void addInner(PolyData inner) {
     242            inners.add(inner);
     243            appendInner(inner.poly);
     244        }
     245       
     246        private void appendInner(Path2D.Double inner) {
    228247            poly.append(inner.getPathIterator(null), false);
    229248        }
     
    242261        public Collection<Way> getWays() {
    243262            return ways;
     263        }
     264       
     265        private void resetPoly() {
     266            poly.reset();
     267            buildPoly();
     268            bounds = null;
     269        }
     270       
     271        public void nodeMoved(NodeMovedEvent event) {
     272            final Node n = event.getNode();
     273            boolean innerChanged = false;
     274            for (PolyData inner : inners) {
     275                if (inner.nodes.contains(n)) {
     276                    inner.resetPoly();
     277                    innerChanged = true;
     278                }
     279            }
     280            if (nodes.contains(n) || innerChanged) {
     281                resetPoly();
     282            }
    244283        }
    245284    }
     
    441480            PolyData combinedOuter = new PolyData(outerPolygons.get(0));
    442481            for (PolyData inner: innerPolygons) {
    443                 combinedOuter.addInner(inner.poly);
     482                combinedOuter.addInner(inner);
    444483            }
    445484            combinedPolygons.add(combinedOuter);
     
    454493                    o = outerPolygons.get(0);
    455494                }
    456                 o.addInner(pdInner.poly);
     495                o.addInner(pdInner);
    457496            }
    458497        }
Note: See TracChangeset for help on using the changeset viewer.