Changeset 4628 in josm for trunk/src/org


Ignore:
Timestamp:
2011-12-03T01:54:59+01:00 (13 years ago)
Author:
Don-vip
Message:

see #6987 - fixed rendering bug on selection change + optim (MP cache clear not needed on tags change)

Location:
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/relations
Files:
2 edited

Legend:

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

    r4627 r4628  
    99import java.util.ArrayList;
    1010import java.util.Collection;
     11import java.util.Collections;
    1112import java.util.List;
    1213
     
    172173
    173174        public final Path2D.Double poly;
    174         public final boolean selected;
     175        public boolean selected;
    175176        private Rectangle2D bounds;
    176 
    177         public PolyData(JoinedWay joinedWay) {
    178             this(joinedWay.getNodes(), joinedWay.isSelected());
    179         }
    180 
    181         public PolyData(List<Node> nodes, boolean selected) {
     177        private final Collection<Way> ways;
     178
     179        public PolyData(JoinedWay joinedWay, Collection<Way> refWays) {
     180            this(joinedWay.getNodes(), joinedWay.isSelected(), refWays);
     181        }
     182
     183        public PolyData(List<Node> nodes, boolean selected, Collection<Way> refWays) {
     184            this.ways = Collections.unmodifiableCollection(refWays);
    182185            this.selected = selected;
    183186            boolean initial = true;
     
    200203            this.selected = copy.selected;
    201204            this.poly = (Double) copy.poly.clone();
     205            this.ways = new ArrayList<Way>(copy.ways);
    202206        }
    203207       
     
    235239            return bounds;
    236240        }
     241       
     242        public Collection<Way> getWays() {
     243            return ways;
     244        }
    237245    }
    238246
     
    282290        for (Way way: ways) {
    283291            if (way.isClosed()) {
    284                 result.add(new PolyData(way.getNodes(), way.isSelected()));
     292                result.add(new PolyData(way.getNodes(), way.isSelected(), Collections.singleton(way)));
    285293            } else {
    286294                waysToJoin.add(way);
     
    289297
    290298        for (JoinedWay jw: joinWays(waysToJoin)) {
    291             result.add(new PolyData(jw));
     299            result.add(new PolyData(jw, waysToJoin));
    292300        }
    293301    }
     
    449457            }
    450458        }
     459       
     460        // Clear inner and outer polygons to reduce memory footprint
     461        innerPolygons.clear();
     462        outerPolygons.clear();
    451463    }
    452464
     
    458470        return innerWays;
    459471    }
    460 
     472/*
    461473    public List<PolyData> getInnerPolygons() {
    462474        return innerPolygons;
     
    466478        return outerPolygons;
    467479    }
    468 
     480*/
    469481    public List<PolyData> getCombinedPolygons() {
    470482        return combinedPolygons;
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/relations/MultipolygonCache.java

    r4627 r4628  
    44import java.util.Collection;
    55import java.util.HashMap;
     6import java.util.Iterator;
    67import java.util.List;
    78import java.util.Map;
    89
    910import org.openstreetmap.josm.Main;
     11import org.openstreetmap.josm.data.SelectionChangedListener;
    1012import org.openstreetmap.josm.data.osm.DataSet;
    1113import org.openstreetmap.josm.data.osm.Node;
     
    2224import org.openstreetmap.josm.data.osm.event.TagsChangedEvent;
    2325import org.openstreetmap.josm.data.osm.event.WayNodesChangedEvent;
     26import org.openstreetmap.josm.data.osm.visitor.paint.relations.Multipolygon.PolyData;
    2427import org.openstreetmap.josm.data.projection.Projection;
    2528import org.openstreetmap.josm.data.projection.ProjectionChangeListener;
     
    3336 *
    3437 */
    35 public class MultipolygonCache implements DataSetListener, LayerChangeListener, ProjectionChangeListener {
     38public class MultipolygonCache implements DataSetListener, LayerChangeListener, ProjectionChangeListener, SelectionChangedListener {
    3639
    3740    private static final MultipolygonCache instance = new MultipolygonCache();
    3841   
    3942    private final Map<NavigatableComponent, Map<DataSet, Map<Relation, Multipolygon>>> cache;
     43   
     44    private final Collection<PolyData> selectedPolyData;
    4045   
    4146    private MultipolygonCache() {
    4247        this.cache = new HashMap<NavigatableComponent, Map<DataSet, Map<Relation, Multipolygon>>>();
     48        this.selectedPolyData = new ArrayList<Multipolygon.PolyData>();
    4349        Main.addProjectionChangeListener(this);
     50        DataSet.addSelectionListener(this);
    4451    }
    4552
     
    6673            if (multipolygon == null || forceRefresh) {
    6774                map2.put(r, multipolygon = new Multipolygon(r));
     75                for (PolyData pd : multipolygon.getCombinedPolygons()) {
     76                    if (pd.selected) {
     77                        selectedPolyData.add(pd);
     78                    }
     79                }
    6880            }
    6981        }
     
    157169    @Override
    158170    public void primitivesRemoved(PrimitivesRemovedEvent event) {
    159         removeMultipolygonsReferringTo(event);
     171        removeMultipolygonsReferringTo(event);// FIXME: See if it is possible to update only concerned PolyData
    160172    }
    161173
    162174    @Override
    163175    public void tagsChanged(TagsChangedEvent event) {
    164         removeMultipolygonsReferringTo(event);
     176        //removeMultipolygonsReferringTo(event);
    165177    }
    166178
    167179    @Override
    168180    public void nodeMoved(NodeMovedEvent event) {
    169         removeMultipolygonsReferringTo(event);
     181        removeMultipolygonsReferringTo(event);// FIXME: See if it is possible to update only concerned PolyData
    170182    }
    171183
    172184    @Override
    173185    public void wayNodesChanged(WayNodesChangedEvent event) {
    174         removeMultipolygonsReferringTo(event);
     186        removeMultipolygonsReferringTo(event);// FIXME: See if it is possible to update only concerned PolyData
    175187    }
    176188
    177189    @Override
    178190    public void relationMembersChanged(RelationMembersChangedEvent event) {
    179         removeMultipolygonsReferringTo(event);
     191        removeMultipolygonsReferringTo(event);// FIXME: See if it is possible to update only concerned PolyData
    180192    }
    181193
    182194    @Override
    183195    public void otherDatasetChange(AbstractDatasetChangedEvent event) {
    184         removeMultipolygonsReferringTo(event);
     196        removeMultipolygonsReferringTo(event);// FIXME: See if it is possible to update only concerned PolyData
    185197    }
    186198
    187199    @Override
    188200    public void dataChanged(DataChangedEvent event) {
    189         removeMultipolygonsReferringTo(event);
     201        removeMultipolygonsReferringTo(event);// FIXME: See if it is possible to update only concerned PolyData
    190202    }
    191203
     
    211223        clear();
    212224    }
     225
     226    @Override
     227    public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) {
     228       
     229        for (Iterator<PolyData> it = selectedPolyData.iterator(); it.hasNext();) {
     230            it.next().selected = false;
     231            it.remove();
     232        }
     233       
     234        DataSet ds = null;
     235        Collection<Map<Relation, Multipolygon>> maps = null;
     236        for (OsmPrimitive p : newSelection) {
     237            if (p instanceof Way && p.getDataSet() != null) {
     238                if (ds == null) {
     239                    ds = p.getDataSet();
     240                }
     241                for (OsmPrimitive ref : p.getReferrers()) {
     242                    if (isMultipolygon(ref)) {
     243                        if (maps == null) {
     244                            maps = getMapsFor(ds);
     245                        }
     246                        for (Map<Relation, Multipolygon> map : maps) {
     247                            Multipolygon multipolygon = map.get(ref);
     248                            if (multipolygon != null) {
     249                                for (PolyData pd : multipolygon.getCombinedPolygons()) {
     250                                    if (pd.getWays().contains(p)) {
     251                                        pd.selected = true;
     252                                        selectedPolyData.add(pd);
     253                                    }
     254                                }
     255                            }
     256                        }
     257                    }
     258                }
     259            }
     260        }
     261    }
    213262}
Note: See TracChangeset for help on using the changeset viewer.