1 | // License: GPL. Copyright 2007 by Immanuel Scholz and others
|
---|
2 | package org.openstreetmap.josm.data.osm;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.awt.geom.Area;
|
---|
7 | import java.util.ArrayList;
|
---|
8 | import java.util.Arrays;
|
---|
9 | import java.util.Collection;
|
---|
10 | import java.util.Collections;
|
---|
11 | import java.util.HashMap;
|
---|
12 | import java.util.Iterator;
|
---|
13 | import java.util.LinkedHashSet;
|
---|
14 | import java.util.LinkedList;
|
---|
15 | import java.util.List;
|
---|
16 | import java.util.Map;
|
---|
17 | import java.util.concurrent.CopyOnWriteArrayList;
|
---|
18 | import java.util.concurrent.locks.Lock;
|
---|
19 | import java.util.concurrent.locks.ReadWriteLock;
|
---|
20 | import java.util.concurrent.locks.ReentrantReadWriteLock;
|
---|
21 |
|
---|
22 | import org.openstreetmap.josm.data.SelectionChangedListener;
|
---|
23 | import org.openstreetmap.josm.data.coor.EastNorth;
|
---|
24 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
25 | import org.openstreetmap.josm.data.osm.event.AbstractDatasetChangedEvent;
|
---|
26 | import org.openstreetmap.josm.data.osm.event.ChangesetIdChangedEvent;
|
---|
27 | import org.openstreetmap.josm.data.osm.event.DataChangedEvent;
|
---|
28 | import org.openstreetmap.josm.data.osm.event.DataSetListener;
|
---|
29 | import org.openstreetmap.josm.data.osm.event.NodeMovedEvent;
|
---|
30 | import org.openstreetmap.josm.data.osm.event.PrimitivesAddedEvent;
|
---|
31 | import org.openstreetmap.josm.data.osm.event.PrimitivesRemovedEvent;
|
---|
32 | import org.openstreetmap.josm.data.osm.event.RelationMembersChangedEvent;
|
---|
33 | import org.openstreetmap.josm.data.osm.event.TagsChangedEvent;
|
---|
34 | import org.openstreetmap.josm.data.osm.event.WayNodesChangedEvent;
|
---|
35 | import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionManager;
|
---|
36 | import org.openstreetmap.josm.tools.FilteredCollection;
|
---|
37 | import org.openstreetmap.josm.tools.Predicate;
|
---|
38 | import org.openstreetmap.josm.tools.SubclassFilteredCollection;
|
---|
39 |
|
---|
40 | /**
|
---|
41 | * DataSet is the data behind the application. It can consists of only a few points up to the whole
|
---|
42 | * osm database. DataSet's can be merged together, saved, (up/down/disk)loaded etc.
|
---|
43 | *
|
---|
44 | * Note that DataSet is not an osm-primitive and so has no key association but a few members to
|
---|
45 | * store some information.
|
---|
46 | *
|
---|
47 | * Dataset is threadsafe - accessing Dataset simultaneously from different threads should never
|
---|
48 | * lead to data corruption or ConccurentModificationException. However when for example one thread
|
---|
49 | * removes primitive and other thread try to add another primitive reffering to the removed primitive,
|
---|
50 | * DataIntegrityException will occur.
|
---|
51 | *
|
---|
52 | * To prevent such situations, read/write lock is provided. While read lock is used, it's guaranteed that
|
---|
53 | * Dataset will not change. Sample usage:
|
---|
54 | * <code>
|
---|
55 | * ds.getReadLock().lock();
|
---|
56 | * try {
|
---|
57 | * // .. do something with dataset
|
---|
58 | * } finally {
|
---|
59 | * ds.getReadLock().unlock();
|
---|
60 | * }
|
---|
61 | * </code>
|
---|
62 | *
|
---|
63 | * Write lock should be used in case of bulk operations. In addition to ensuring that other threads can't
|
---|
64 | * use dataset in the middle of modifications it also stops sending of dataset events. That's good for performance
|
---|
65 | * reasons - GUI can be updated after all changes are done.
|
---|
66 | * Sample usage:
|
---|
67 | * <code>
|
---|
68 | * ds.beginUpdate()
|
---|
69 | * try {
|
---|
70 | * // .. do modifications
|
---|
71 | * } finally {
|
---|
72 | * ds.endUpdate();
|
---|
73 | * }
|
---|
74 | * </code>
|
---|
75 | *
|
---|
76 | * Note that it is not necessary to call beginUpdate/endUpdate for every dataset modification - dataset will get locked
|
---|
77 | * automatically.
|
---|
78 | *
|
---|
79 | * Note that locks cannot be upgraded - if one threads use read lock and and then write lock, dead lock will occur - see #5814 for
|
---|
80 | * sample ticket
|
---|
81 | *
|
---|
82 | * @author imi
|
---|
83 | */
|
---|
84 | public class DataSet implements Cloneable {
|
---|
85 |
|
---|
86 | /**
|
---|
87 | * Maximum number of events that can be fired between beginUpdate/endUpdate to be send as single events (ie without DatasetChangedEvent)
|
---|
88 | */
|
---|
89 | private static final int MAX_SINGLE_EVENTS = 30;
|
---|
90 |
|
---|
91 | /**
|
---|
92 | * Maximum number of events to kept between beginUpdate/endUpdate. When more events are created, that simple DatasetChangedEvent is sent)
|
---|
93 | */
|
---|
94 | private static final int MAX_EVENTS = 1000;
|
---|
95 |
|
---|
96 | private static class IdHash implements Hash<PrimitiveId,OsmPrimitive> {
|
---|
97 |
|
---|
98 | public int getHashCode(PrimitiveId k) {
|
---|
99 | return (int)k.getUniqueId() ^ k.getType().hashCode();
|
---|
100 | }
|
---|
101 |
|
---|
102 | public boolean equals(PrimitiveId key, OsmPrimitive value) {
|
---|
103 | if (key == null || value == null) return false;
|
---|
104 | return key.getUniqueId() == value.getUniqueId() && key.getType() == value.getType();
|
---|
105 | }
|
---|
106 | }
|
---|
107 |
|
---|
108 | private Storage<OsmPrimitive> allPrimitives = new Storage<OsmPrimitive>(new IdHash(), true);
|
---|
109 | private Map<PrimitiveId, OsmPrimitive> primitivesMap = allPrimitives.foreignKey(new IdHash());
|
---|
110 | private CopyOnWriteArrayList<DataSetListener> listeners = new CopyOnWriteArrayList<DataSetListener>();
|
---|
111 |
|
---|
112 | // Number of open calls to beginUpdate
|
---|
113 | private int updateCount;
|
---|
114 | // Events that occurred while dataset was locked but should be fired after write lock is released
|
---|
115 | private final List<AbstractDatasetChangedEvent> cachedEvents = new ArrayList<AbstractDatasetChangedEvent>();
|
---|
116 |
|
---|
117 | private int highlightUpdateCount;
|
---|
118 |
|
---|
119 | private final ReadWriteLock lock = new ReentrantReadWriteLock();
|
---|
120 | private final Object selectionLock = new Object();
|
---|
121 |
|
---|
122 | public Lock getReadLock() {
|
---|
123 | return lock.readLock();
|
---|
124 | }
|
---|
125 |
|
---|
126 | /**
|
---|
127 | * This method can be used to detect changes in highlight state of primitives. If highlighting was changed
|
---|
128 | * then the method will return different number.
|
---|
129 | * @return
|
---|
130 | */
|
---|
131 | public int getHighlightUpdateCount() {
|
---|
132 | return highlightUpdateCount;
|
---|
133 | }
|
---|
134 |
|
---|
135 | /**
|
---|
136 | * History of selections - shared by plugins and SelectionListDialog
|
---|
137 | */
|
---|
138 | private final LinkedList<Collection<? extends OsmPrimitive>> selectionHistory = new LinkedList<Collection<? extends OsmPrimitive>>();
|
---|
139 |
|
---|
140 | /**
|
---|
141 | * Replies the history of JOSM selections
|
---|
142 | *
|
---|
143 | * @return
|
---|
144 | */
|
---|
145 | public LinkedList<Collection<? extends OsmPrimitive>> getSelectionHistory() {
|
---|
146 | return selectionHistory;
|
---|
147 | }
|
---|
148 |
|
---|
149 | /**
|
---|
150 | * Clears selection history list
|
---|
151 | */
|
---|
152 | public void clearSelectionHistory() {
|
---|
153 | selectionHistory.clear();
|
---|
154 | }
|
---|
155 |
|
---|
156 | /**
|
---|
157 | * Maintain a list of used tags for autocompletion
|
---|
158 | */
|
---|
159 | private AutoCompletionManager autocomplete;
|
---|
160 |
|
---|
161 | public AutoCompletionManager getAutoCompletionManager() {
|
---|
162 | if (autocomplete == null) {
|
---|
163 | autocomplete = new AutoCompletionManager(this);
|
---|
164 | addDataSetListener(autocomplete);
|
---|
165 | }
|
---|
166 | return autocomplete;
|
---|
167 | }
|
---|
168 |
|
---|
169 | /**
|
---|
170 | * The API version that created this data set, if any.
|
---|
171 | */
|
---|
172 | private String version;
|
---|
173 |
|
---|
174 | /**
|
---|
175 | * Replies the API version this dataset was created from. May be null.
|
---|
176 | *
|
---|
177 | * @return the API version this dataset was created from. May be null.
|
---|
178 | */
|
---|
179 | public String getVersion() {
|
---|
180 | return version;
|
---|
181 | }
|
---|
182 |
|
---|
183 | /**
|
---|
184 | * Sets the API version this dataset was created from.
|
---|
185 | *
|
---|
186 | * @param version the API version, i.e. "0.5" or "0.6"
|
---|
187 | */
|
---|
188 | public void setVersion(String version) {
|
---|
189 | this.version = version;
|
---|
190 | }
|
---|
191 |
|
---|
192 | /**
|
---|
193 | * All nodes goes here, even when included in other data (ways etc). This enables the instant
|
---|
194 | * conversion of the whole DataSet by iterating over this data structure.
|
---|
195 | */
|
---|
196 | private QuadBuckets<Node> nodes = new QuadBuckets<Node>();
|
---|
197 |
|
---|
198 | private <T extends OsmPrimitive> Collection<T> getPrimitives(Predicate<OsmPrimitive> predicate) {
|
---|
199 | return new SubclassFilteredCollection<OsmPrimitive, T>(allPrimitives, predicate);
|
---|
200 | }
|
---|
201 |
|
---|
202 | /**
|
---|
203 | * Replies an unmodifiable collection of nodes in this dataset
|
---|
204 | *
|
---|
205 | * @return an unmodifiable collection of nodes in this dataset
|
---|
206 | */
|
---|
207 | public Collection<Node> getNodes() {
|
---|
208 | return getPrimitives(OsmPrimitive.nodePredicate);
|
---|
209 | }
|
---|
210 |
|
---|
211 | public List<Node> searchNodes(BBox bbox) {
|
---|
212 | lock.readLock().lock();
|
---|
213 | try {
|
---|
214 | return nodes.search(bbox);
|
---|
215 | } finally {
|
---|
216 | lock.readLock().unlock();
|
---|
217 | }
|
---|
218 | }
|
---|
219 |
|
---|
220 | /**
|
---|
221 | * All ways (Streets etc.) in the DataSet.
|
---|
222 | *
|
---|
223 | * The way nodes are stored only in the way list.
|
---|
224 | */
|
---|
225 | private QuadBuckets<Way> ways = new QuadBuckets<Way>();
|
---|
226 |
|
---|
227 | /**
|
---|
228 | * Replies an unmodifiable collection of ways in this dataset
|
---|
229 | *
|
---|
230 | * @return an unmodifiable collection of ways in this dataset
|
---|
231 | */
|
---|
232 | public Collection<Way> getWays() {
|
---|
233 | return getPrimitives(OsmPrimitive.wayPredicate);
|
---|
234 | }
|
---|
235 |
|
---|
236 | public List<Way> searchWays(BBox bbox) {
|
---|
237 | lock.readLock().lock();
|
---|
238 | try {
|
---|
239 | return ways.search(bbox);
|
---|
240 | } finally {
|
---|
241 | lock.readLock().unlock();
|
---|
242 | }
|
---|
243 | }
|
---|
244 |
|
---|
245 | /**
|
---|
246 | * All relations/relationships
|
---|
247 | */
|
---|
248 | private Collection<Relation> relations = new ArrayList<Relation>();
|
---|
249 |
|
---|
250 | /**
|
---|
251 | * Replies an unmodifiable collection of relations in this dataset
|
---|
252 | *
|
---|
253 | * @return an unmodifiable collection of relations in this dataset
|
---|
254 | */
|
---|
255 | public Collection<Relation> getRelations() {
|
---|
256 | return getPrimitives(OsmPrimitive.relationPredicate);
|
---|
257 | }
|
---|
258 |
|
---|
259 | public List<Relation> searchRelations(BBox bbox) {
|
---|
260 | lock.readLock().lock();
|
---|
261 | try {
|
---|
262 | // QuadBuckets might be useful here (don't forget to do reindexing after some of rm is changed)
|
---|
263 | List<Relation> result = new ArrayList<Relation>();
|
---|
264 | for (Relation r: relations) {
|
---|
265 | if (r.getBBox().intersects(bbox)) {
|
---|
266 | result.add(r);
|
---|
267 | }
|
---|
268 | }
|
---|
269 | return result;
|
---|
270 | } finally {
|
---|
271 | lock.readLock().unlock();
|
---|
272 | }
|
---|
273 | }
|
---|
274 |
|
---|
275 | /**
|
---|
276 | * All data sources of this DataSet.
|
---|
277 | */
|
---|
278 | public Collection<DataSource> dataSources = new LinkedList<DataSource>();
|
---|
279 |
|
---|
280 | /**
|
---|
281 | * @return A collection containing all primitives of the dataset. Data are not ordered
|
---|
282 | */
|
---|
283 | public Collection<OsmPrimitive> allPrimitives() {
|
---|
284 | return getPrimitives(OsmPrimitive.allPredicate);
|
---|
285 | }
|
---|
286 |
|
---|
287 | /**
|
---|
288 | * @return A collection containing all not-deleted primitives (except keys).
|
---|
289 | */
|
---|
290 | public Collection<OsmPrimitive> allNonDeletedPrimitives() {
|
---|
291 | return getPrimitives(OsmPrimitive.nonDeletedPredicate);
|
---|
292 | }
|
---|
293 |
|
---|
294 | public Collection<OsmPrimitive> allNonDeletedCompletePrimitives() {
|
---|
295 | return getPrimitives(OsmPrimitive.nonDeletedCompletePredicate);
|
---|
296 | }
|
---|
297 |
|
---|
298 | public Collection<OsmPrimitive> allNonDeletedPhysicalPrimitives() {
|
---|
299 | return getPrimitives(OsmPrimitive.nonDeletedPhysicalPredicate);
|
---|
300 | }
|
---|
301 |
|
---|
302 | public Collection<OsmPrimitive> allModifiedPrimitives() {
|
---|
303 | return getPrimitives(OsmPrimitive.modifiedPredicate);
|
---|
304 | }
|
---|
305 |
|
---|
306 | /**
|
---|
307 | * Adds a primitive to the dataset
|
---|
308 | *
|
---|
309 | * @param primitive the primitive.
|
---|
310 | */
|
---|
311 | public void addPrimitive(OsmPrimitive primitive) {
|
---|
312 | beginUpdate();
|
---|
313 | try {
|
---|
314 | if (getPrimitiveById(primitive) != null)
|
---|
315 | throw new DataIntegrityProblemException(
|
---|
316 | tr("Unable to add primitive {0} to the dataset because it is already included", primitive.toString()));
|
---|
317 |
|
---|
318 | primitive.updatePosition(); // Set cached bbox for way and relation (required for reindexWay and reinexRelation to work properly)
|
---|
319 | boolean success = false;
|
---|
320 | if (primitive instanceof Node) {
|
---|
321 | success = nodes.add((Node) primitive);
|
---|
322 | } else if (primitive instanceof Way) {
|
---|
323 | success = ways.add((Way) primitive);
|
---|
324 | } else if (primitive instanceof Relation) {
|
---|
325 | success = relations.add((Relation) primitive);
|
---|
326 | }
|
---|
327 | if (!success)
|
---|
328 | throw new RuntimeException("failed to add primitive: "+primitive);
|
---|
329 | allPrimitives.add(primitive);
|
---|
330 | primitive.setDataset(this);
|
---|
331 | firePrimitivesAdded(Collections.singletonList(primitive), false);
|
---|
332 | } finally {
|
---|
333 | endUpdate();
|
---|
334 | }
|
---|
335 | }
|
---|
336 |
|
---|
337 | /**
|
---|
338 | * Removes a primitive from the dataset. This method only removes the
|
---|
339 | * primitive form the respective collection of primitives managed
|
---|
340 | * by this dataset, i.e. from {@see #nodes}, {@see #ways}, or
|
---|
341 | * {@see #relations}. References from other primitives to this
|
---|
342 | * primitive are left unchanged.
|
---|
343 | *
|
---|
344 | * @param primitive the primitive
|
---|
345 | */
|
---|
346 | public void removePrimitive(PrimitiveId primitiveId) {
|
---|
347 | beginUpdate();
|
---|
348 | try {
|
---|
349 | OsmPrimitive primitive = getPrimitiveByIdChecked(primitiveId);
|
---|
350 | if (primitive == null)
|
---|
351 | return;
|
---|
352 | boolean success = false;
|
---|
353 | if (primitive instanceof Node) {
|
---|
354 | success = nodes.remove(primitive);
|
---|
355 | } else if (primitive instanceof Way) {
|
---|
356 | success = ways.remove(primitive);
|
---|
357 | } else if (primitive instanceof Relation) {
|
---|
358 | success = relations.remove(primitive);
|
---|
359 | }
|
---|
360 | if (!success)
|
---|
361 | throw new RuntimeException("failed to remove primitive: "+primitive);
|
---|
362 | synchronized (selectionLock) {
|
---|
363 | selectedPrimitives.remove(primitive);
|
---|
364 | selectionSnapshot = null;
|
---|
365 | }
|
---|
366 | allPrimitives.remove(primitive);
|
---|
367 | primitive.setDataset(null);
|
---|
368 | firePrimitivesRemoved(Collections.singletonList(primitive), false);
|
---|
369 | } finally {
|
---|
370 | endUpdate();
|
---|
371 | }
|
---|
372 | }
|
---|
373 |
|
---|
374 | /*---------------------------------------------------
|
---|
375 | * SELECTION HANDLING
|
---|
376 | *---------------------------------------------------*/
|
---|
377 |
|
---|
378 | /**
|
---|
379 | * A list of listeners to selection changed events. The list is static, as listeners register
|
---|
380 | * themselves for any dataset selection changes that occur, regardless of the current active
|
---|
381 | * dataset. (However, the selection does only change in the active layer)
|
---|
382 | * @deprecated Use addSelectionListener/removeSelectionListener instead
|
---|
383 | */
|
---|
384 | @Deprecated
|
---|
385 | public static final Collection<SelectionChangedListener> selListeners = new CopyOnWriteArrayList<SelectionChangedListener>();
|
---|
386 |
|
---|
387 | public static void addSelectionListener(SelectionChangedListener listener) {
|
---|
388 | ((CopyOnWriteArrayList<SelectionChangedListener>)selListeners).addIfAbsent(listener);
|
---|
389 | }
|
---|
390 |
|
---|
391 | public static void removeSelectionListener(SelectionChangedListener listener) {
|
---|
392 | selListeners.remove(listener);
|
---|
393 | }
|
---|
394 |
|
---|
395 | /**
|
---|
396 | * Notifies all registered {@see SelectionChangedListener} about the current selection in
|
---|
397 | * this dataset.
|
---|
398 | *
|
---|
399 | */
|
---|
400 | public void fireSelectionChanged(){
|
---|
401 | Collection<? extends OsmPrimitive> currentSelection = getSelected();
|
---|
402 | for (SelectionChangedListener l : selListeners) {
|
---|
403 | l.selectionChanged(currentSelection);
|
---|
404 | }
|
---|
405 | }
|
---|
406 |
|
---|
407 | private LinkedHashSet<OsmPrimitive> selectedPrimitives = new LinkedHashSet<OsmPrimitive>();
|
---|
408 | private Collection<OsmPrimitive> selectionSnapshot;
|
---|
409 |
|
---|
410 | public Collection<OsmPrimitive> getSelectedNodesAndWays() {
|
---|
411 | return new FilteredCollection<OsmPrimitive>(getSelected(), new Predicate<OsmPrimitive>() {
|
---|
412 | @Override
|
---|
413 | public boolean evaluate(OsmPrimitive primitive) {
|
---|
414 | return primitive instanceof Node || primitive instanceof Way;
|
---|
415 | }
|
---|
416 | });
|
---|
417 | }
|
---|
418 |
|
---|
419 | /**
|
---|
420 | * Replies an unmodifiable collection of primitives currently selected
|
---|
421 | * in this dataset. May be empty, but not null.
|
---|
422 | *
|
---|
423 | * @return unmodifiable collection of primitives
|
---|
424 | */
|
---|
425 | public Collection<OsmPrimitive> getSelected() {
|
---|
426 | Collection<OsmPrimitive> currentList;
|
---|
427 | synchronized (selectionLock) {
|
---|
428 | if (selectionSnapshot == null) {
|
---|
429 | selectionSnapshot = Collections.unmodifiableList(new ArrayList<OsmPrimitive>(selectedPrimitives));
|
---|
430 | }
|
---|
431 | currentList = selectionSnapshot;
|
---|
432 | }
|
---|
433 | return currentList;
|
---|
434 | }
|
---|
435 |
|
---|
436 | /**
|
---|
437 | * Return selected nodes.
|
---|
438 | */
|
---|
439 | public Collection<Node> getSelectedNodes() {
|
---|
440 | return new SubclassFilteredCollection<OsmPrimitive, Node>(getSelected(), OsmPrimitive.nodePredicate);
|
---|
441 | }
|
---|
442 |
|
---|
443 | /**
|
---|
444 | * Return selected ways.
|
---|
445 | */
|
---|
446 | public Collection<Way> getSelectedWays() {
|
---|
447 | return new SubclassFilteredCollection<OsmPrimitive, Way>(getSelected(), OsmPrimitive.wayPredicate);
|
---|
448 | }
|
---|
449 |
|
---|
450 | /**
|
---|
451 | * Return selected relations.
|
---|
452 | */
|
---|
453 | public Collection<Relation> getSelectedRelations() {
|
---|
454 | return new SubclassFilteredCollection<OsmPrimitive, Relation>(getSelected(), OsmPrimitive.relationPredicate);
|
---|
455 | }
|
---|
456 |
|
---|
457 | /**
|
---|
458 | * @return whether the selection is empty or not
|
---|
459 | */
|
---|
460 | public boolean selectionEmpty() {
|
---|
461 | return selectedPrimitives.isEmpty();
|
---|
462 | }
|
---|
463 |
|
---|
464 | public boolean isSelected(OsmPrimitive osm) {
|
---|
465 | return selectedPrimitives.contains(osm);
|
---|
466 | }
|
---|
467 |
|
---|
468 | public void toggleSelected(Collection<? extends PrimitiveId> osm) {
|
---|
469 | boolean changed = false;
|
---|
470 | synchronized (selectionLock) {
|
---|
471 | for (PrimitiveId o : osm) {
|
---|
472 | changed = changed | this.__toggleSelected(o);
|
---|
473 | }
|
---|
474 | if (changed) {
|
---|
475 | selectionSnapshot = null;
|
---|
476 | }
|
---|
477 | }
|
---|
478 | if (changed) {
|
---|
479 | fireSelectionChanged();
|
---|
480 | }
|
---|
481 | }
|
---|
482 | public void toggleSelected(PrimitiveId... osm) {
|
---|
483 | toggleSelected(Arrays.asList(osm));
|
---|
484 | }
|
---|
485 | private boolean __toggleSelected(PrimitiveId primitiveId) {
|
---|
486 | OsmPrimitive primitive = getPrimitiveByIdChecked(primitiveId);
|
---|
487 | if (primitive == null)
|
---|
488 | return false;
|
---|
489 | if (!selectedPrimitives.remove(primitive)) {
|
---|
490 | selectedPrimitives.add(primitive);
|
---|
491 | }
|
---|
492 | selectionSnapshot = null;
|
---|
493 | return true;
|
---|
494 | }
|
---|
495 |
|
---|
496 | /**
|
---|
497 | * Sets the current selection to the primitives in <code>selection</code>.
|
---|
498 | * Notifies all {@see SelectionChangedListener} if <code>fireSelectionChangeEvent</code> is true.
|
---|
499 | *
|
---|
500 | * @param selection the selection
|
---|
501 | * @param fireSelectionChangeEvent true, if the selection change listeners are to be notified; false, otherwise
|
---|
502 | */
|
---|
503 | public void setSelected(Collection<? extends PrimitiveId> selection, boolean fireSelectionChangeEvent) {
|
---|
504 | boolean changed;
|
---|
505 | synchronized (selectionLock) {
|
---|
506 | boolean wasEmpty = selectedPrimitives.isEmpty();
|
---|
507 | selectedPrimitives = new LinkedHashSet<OsmPrimitive>();
|
---|
508 | changed = addSelected(selection, false)
|
---|
509 | || (!wasEmpty && selectedPrimitives.isEmpty());
|
---|
510 | if (changed) {
|
---|
511 | selectionSnapshot = null;
|
---|
512 | }
|
---|
513 | }
|
---|
514 |
|
---|
515 | if (changed && fireSelectionChangeEvent) {
|
---|
516 | // If selection is not empty then event was already fired in addSelecteds
|
---|
517 | fireSelectionChanged();
|
---|
518 | }
|
---|
519 | }
|
---|
520 |
|
---|
521 | /**
|
---|
522 | * Sets the current selection to the primitives in <code>selection</code>
|
---|
523 | * and notifies all {@see SelectionChangedListener}.
|
---|
524 | *
|
---|
525 | * @param selection the selection
|
---|
526 | */
|
---|
527 | public void setSelected(Collection<? extends PrimitiveId> selection) {
|
---|
528 | setSelected(selection, true /* fire selection change event */);
|
---|
529 | }
|
---|
530 |
|
---|
531 | public void setSelected(PrimitiveId... osm) {
|
---|
532 | if (osm.length == 1 && osm[0] == null) {
|
---|
533 | setSelected();
|
---|
534 | return;
|
---|
535 | }
|
---|
536 | List<PrimitiveId> list = Arrays.asList(osm);
|
---|
537 | setSelected(list);
|
---|
538 | }
|
---|
539 |
|
---|
540 | /**
|
---|
541 | * Adds the primitives in <code>selection</code> to the current selection
|
---|
542 | * and notifies all {@see SelectionChangedListener}.
|
---|
543 | *
|
---|
544 | * @param selection the selection
|
---|
545 | */
|
---|
546 | public void addSelected(Collection<? extends PrimitiveId> selection) {
|
---|
547 | addSelected(selection, true /* fire selection change event */);
|
---|
548 | }
|
---|
549 |
|
---|
550 | public void addSelected(PrimitiveId... osm) {
|
---|
551 | addSelected(Arrays.asList(osm));
|
---|
552 | }
|
---|
553 |
|
---|
554 | /**
|
---|
555 | * Adds the primitives in <code>selection</code> to the current selection.
|
---|
556 | * Notifies all {@see SelectionChangedListener} if <code>fireSelectionChangeEvent</code> is true.
|
---|
557 | *
|
---|
558 | * @param selection the selection
|
---|
559 | * @param fireSelectionChangeEvent true, if the selection change listeners are to be notified; false, otherwise
|
---|
560 | * @return if the selection was changed in the process
|
---|
561 | */
|
---|
562 | private boolean addSelected(Collection<? extends PrimitiveId> selection, boolean fireSelectionChangeEvent) {
|
---|
563 | boolean changed = false;
|
---|
564 | synchronized (selectionLock) {
|
---|
565 | for (PrimitiveId id: selection) {
|
---|
566 | OsmPrimitive primitive = getPrimitiveByIdChecked(id);
|
---|
567 | if (primitive != null) {
|
---|
568 | changed = changed | selectedPrimitives.add(primitive);
|
---|
569 | }
|
---|
570 | }
|
---|
571 | if (changed) {
|
---|
572 | selectionSnapshot = null;
|
---|
573 | }
|
---|
574 | }
|
---|
575 | if (fireSelectionChangeEvent && changed) {
|
---|
576 | fireSelectionChanged();
|
---|
577 | }
|
---|
578 | return changed;
|
---|
579 | }
|
---|
580 |
|
---|
581 | /**
|
---|
582 | * Remove the selection from every value in the collection.
|
---|
583 | * @param list The collection to remove the selection from.
|
---|
584 | */
|
---|
585 | public void clearSelection(PrimitiveId... osm) {
|
---|
586 | clearSelection(Arrays.asList(osm));
|
---|
587 | }
|
---|
588 | public void clearSelection(Collection<? extends PrimitiveId> list) {
|
---|
589 | boolean changed = false;
|
---|
590 | synchronized (selectionLock) {
|
---|
591 | for (PrimitiveId id:list) {
|
---|
592 | OsmPrimitive primitive = getPrimitiveById(id);
|
---|
593 | if (primitive != null) {
|
---|
594 | changed = changed | selectedPrimitives.remove(primitive);
|
---|
595 | }
|
---|
596 | }
|
---|
597 | if (changed) {
|
---|
598 | selectionSnapshot = null;
|
---|
599 | }
|
---|
600 | }
|
---|
601 | if (changed) {
|
---|
602 | fireSelectionChanged();
|
---|
603 | }
|
---|
604 | }
|
---|
605 | public void clearSelection() {
|
---|
606 | if (!selectedPrimitives.isEmpty()) {
|
---|
607 | synchronized (selectionLock) {
|
---|
608 | selectedPrimitives.clear();
|
---|
609 | selectionSnapshot = null;
|
---|
610 | }
|
---|
611 | fireSelectionChanged();
|
---|
612 | }
|
---|
613 | }
|
---|
614 |
|
---|
615 | @Override public DataSet clone() {
|
---|
616 | getReadLock().lock();
|
---|
617 | try {
|
---|
618 | DataSet ds = new DataSet();
|
---|
619 | HashMap<OsmPrimitive, OsmPrimitive> primMap = new HashMap<OsmPrimitive, OsmPrimitive>();
|
---|
620 | for (Node n : nodes) {
|
---|
621 | Node newNode = new Node(n);
|
---|
622 | primMap.put(n, newNode);
|
---|
623 | ds.addPrimitive(newNode);
|
---|
624 | }
|
---|
625 | for (Way w : ways) {
|
---|
626 | Way newWay = new Way(w);
|
---|
627 | primMap.put(w, newWay);
|
---|
628 | List<Node> newNodes = new ArrayList<Node>();
|
---|
629 | for (Node n: w.getNodes()) {
|
---|
630 | newNodes.add((Node)primMap.get(n));
|
---|
631 | }
|
---|
632 | newWay.setNodes(newNodes);
|
---|
633 | ds.addPrimitive(newWay);
|
---|
634 | }
|
---|
635 | // Because relations can have other relations as members we first clone all relations
|
---|
636 | // and then get the cloned members
|
---|
637 | for (Relation r : relations) {
|
---|
638 | Relation newRelation = new Relation(r, r.isNew());
|
---|
639 | newRelation.setMembers(null);
|
---|
640 | primMap.put(r, newRelation);
|
---|
641 | ds.addPrimitive(newRelation);
|
---|
642 | }
|
---|
643 | for (Relation r : relations) {
|
---|
644 | Relation newRelation = (Relation)primMap.get(r);
|
---|
645 | List<RelationMember> newMembers = new ArrayList<RelationMember>();
|
---|
646 | for (RelationMember rm: r.getMembers()) {
|
---|
647 | newMembers.add(new RelationMember(rm.getRole(), primMap.get(rm.getMember())));
|
---|
648 | }
|
---|
649 | newRelation.setMembers(newMembers);
|
---|
650 | }
|
---|
651 | for (DataSource source : dataSources) {
|
---|
652 | ds.dataSources.add(new DataSource(source.bounds, source.origin));
|
---|
653 | }
|
---|
654 | ds.version = version;
|
---|
655 | return ds;
|
---|
656 | } finally {
|
---|
657 | getReadLock().unlock();
|
---|
658 | }
|
---|
659 | }
|
---|
660 |
|
---|
661 | /**
|
---|
662 | * Returns the total area of downloaded data (the "yellow rectangles").
|
---|
663 | * @return Area object encompassing downloaded data.
|
---|
664 | */
|
---|
665 | public Area getDataSourceArea() {
|
---|
666 | if (dataSources.isEmpty()) return null;
|
---|
667 | Area a = new Area();
|
---|
668 | for (DataSource source : dataSources) {
|
---|
669 | // create area from data bounds
|
---|
670 | a.add(new Area(source.bounds.asRect()));
|
---|
671 | }
|
---|
672 | return a;
|
---|
673 | }
|
---|
674 |
|
---|
675 | /**
|
---|
676 | * returns a primitive with a given id from the data set. null, if no such primitive
|
---|
677 | * exists
|
---|
678 | *
|
---|
679 | * @param id uniqueId of the primitive. Might be < 0 for newly created primitives
|
---|
680 | * @param type the type of the primitive. Must not be null.
|
---|
681 | * @return the primitive
|
---|
682 | * @exception NullPointerException thrown, if type is null
|
---|
683 | */
|
---|
684 | public OsmPrimitive getPrimitiveById(long id, OsmPrimitiveType type) {
|
---|
685 | return getPrimitiveById(new SimplePrimitiveId(id, type));
|
---|
686 | }
|
---|
687 |
|
---|
688 | public OsmPrimitive getPrimitiveById(PrimitiveId primitiveId) {
|
---|
689 | return primitivesMap.get(primitiveId);
|
---|
690 | }
|
---|
691 |
|
---|
692 | /**
|
---|
693 | *
|
---|
694 | * @param primitiveId
|
---|
695 | * @param createNew
|
---|
696 | * @return
|
---|
697 | * @deprecated This method can created inconsistent dataset when called for node with id < 0 and createNew=true. That will add
|
---|
698 | * complete node without coordinates to dataset which is not allowed.
|
---|
699 | */
|
---|
700 | @Deprecated
|
---|
701 | public OsmPrimitive getPrimitiveById(PrimitiveId primitiveId, boolean createNew) {
|
---|
702 | OsmPrimitive result = primitivesMap.get(primitiveId);
|
---|
703 |
|
---|
704 | if (result == null && createNew) {
|
---|
705 | switch (primitiveId.getType()) {
|
---|
706 | case NODE: result = new Node(primitiveId.getUniqueId(), true); break;
|
---|
707 | case WAY: result = new Way(primitiveId.getUniqueId(), true); break;
|
---|
708 | case RELATION: result = new Relation(primitiveId.getUniqueId(), true); break;
|
---|
709 | }
|
---|
710 | addPrimitive(result);
|
---|
711 | }
|
---|
712 |
|
---|
713 | return result;
|
---|
714 | }
|
---|
715 |
|
---|
716 | /**
|
---|
717 | * Show message and stack trace in log in case primitive is not found
|
---|
718 | * @param primitiveId
|
---|
719 | * @return Primitive by id.
|
---|
720 | */
|
---|
721 | private OsmPrimitive getPrimitiveByIdChecked(PrimitiveId primitiveId) {
|
---|
722 | OsmPrimitive result = getPrimitiveById(primitiveId);
|
---|
723 | if (result == null) {
|
---|
724 | System.out.println(tr("JOSM expected to find primitive [{0} {1}] in dataset but it is not there. Please report this "
|
---|
725 | + " at http://josm.openstreetmap.de . This is not a critical error, it should be safe to continue in your work.",
|
---|
726 | primitiveId.getType(), Long.toString(primitiveId.getUniqueId())));
|
---|
727 | new Exception().printStackTrace();
|
---|
728 | }
|
---|
729 |
|
---|
730 | return result;
|
---|
731 | }
|
---|
732 |
|
---|
733 | private void deleteWay(Way way) {
|
---|
734 | way.setNodes(null);
|
---|
735 | way.setDeleted(true);
|
---|
736 | }
|
---|
737 |
|
---|
738 | /**
|
---|
739 | * removes all references from ways in this dataset to a particular node
|
---|
740 | *
|
---|
741 | * @param node the node
|
---|
742 | */
|
---|
743 | public void unlinkNodeFromWays(Node node) {
|
---|
744 | beginUpdate();
|
---|
745 | try {
|
---|
746 | for (Way way: ways) {
|
---|
747 | List<Node> wayNodes = way.getNodes();
|
---|
748 | if (wayNodes.remove(node)) {
|
---|
749 | if (wayNodes.size() < 2) {
|
---|
750 | deleteWay(way);
|
---|
751 | } else {
|
---|
752 | way.setNodes(wayNodes);
|
---|
753 | }
|
---|
754 | }
|
---|
755 | }
|
---|
756 | } finally {
|
---|
757 | endUpdate();
|
---|
758 | }
|
---|
759 | }
|
---|
760 |
|
---|
761 | /**
|
---|
762 | * removes all references from relations in this dataset to this primitive
|
---|
763 | *
|
---|
764 | * @param primitive the primitive
|
---|
765 | */
|
---|
766 | public void unlinkPrimitiveFromRelations(OsmPrimitive primitive) {
|
---|
767 | beginUpdate();
|
---|
768 | try {
|
---|
769 | for (Relation relation : relations) {
|
---|
770 | List<RelationMember> members = relation.getMembers();
|
---|
771 |
|
---|
772 | Iterator<RelationMember> it = members.iterator();
|
---|
773 | boolean removed = false;
|
---|
774 | while(it.hasNext()) {
|
---|
775 | RelationMember member = it.next();
|
---|
776 | if (member.getMember().equals(primitive)) {
|
---|
777 | it.remove();
|
---|
778 | removed = true;
|
---|
779 | }
|
---|
780 | }
|
---|
781 |
|
---|
782 | if (removed) {
|
---|
783 | relation.setMembers(members);
|
---|
784 | }
|
---|
785 | }
|
---|
786 | } finally {
|
---|
787 | endUpdate();
|
---|
788 | }
|
---|
789 | }
|
---|
790 |
|
---|
791 | /**
|
---|
792 | * removes all references from other primitives to the
|
---|
793 | * referenced primitive
|
---|
794 | *
|
---|
795 | * @param referencedPrimitive the referenced primitive
|
---|
796 | */
|
---|
797 | public void unlinkReferencesToPrimitive(OsmPrimitive referencedPrimitive) {
|
---|
798 | beginUpdate();
|
---|
799 | try {
|
---|
800 | if (referencedPrimitive instanceof Node) {
|
---|
801 | unlinkNodeFromWays((Node)referencedPrimitive);
|
---|
802 | unlinkPrimitiveFromRelations(referencedPrimitive);
|
---|
803 | } else {
|
---|
804 | unlinkPrimitiveFromRelations(referencedPrimitive);
|
---|
805 | }
|
---|
806 | } finally {
|
---|
807 | endUpdate();
|
---|
808 | }
|
---|
809 | }
|
---|
810 |
|
---|
811 | /**
|
---|
812 | * Replies true if there is at least one primitive in this dataset with
|
---|
813 | * {@see OsmPrimitive#isModified()} == <code>true</code>.
|
---|
814 | *
|
---|
815 | * @return true if there is at least one primitive in this dataset with
|
---|
816 | * {@see OsmPrimitive#isModified()} == <code>true</code>.
|
---|
817 | */
|
---|
818 | public boolean isModified() {
|
---|
819 | for (OsmPrimitive p: allPrimitives) {
|
---|
820 | if (p.isModified())
|
---|
821 | return true;
|
---|
822 | }
|
---|
823 | return false;
|
---|
824 | }
|
---|
825 |
|
---|
826 | private void reindexNode(Node node, LatLon newCoor, EastNorth eastNorth) {
|
---|
827 | if (!nodes.remove(node))
|
---|
828 | throw new RuntimeException("Reindexing node failed to remove");
|
---|
829 | node.setCoorInternal(newCoor, eastNorth);
|
---|
830 | if (!nodes.add(node))
|
---|
831 | throw new RuntimeException("Reindexing node failed to add");
|
---|
832 | for (OsmPrimitive primitive: node.getReferrers()) {
|
---|
833 | if (primitive instanceof Way) {
|
---|
834 | reindexWay((Way)primitive);
|
---|
835 | } else {
|
---|
836 | reindexRelation((Relation) primitive);
|
---|
837 | }
|
---|
838 | }
|
---|
839 | }
|
---|
840 |
|
---|
841 | private void reindexWay(Way way) {
|
---|
842 | BBox before = way.getBBox();
|
---|
843 | if (!ways.remove(way))
|
---|
844 | throw new RuntimeException("Reindexing way failed to remove");
|
---|
845 | way.updatePosition();
|
---|
846 | if (!ways.add(way))
|
---|
847 | throw new RuntimeException("Reindexing way failed to add");
|
---|
848 | if (!way.getBBox().equals(before)) {
|
---|
849 | for (OsmPrimitive primitive: way.getReferrers()) {
|
---|
850 | reindexRelation((Relation)primitive);
|
---|
851 | }
|
---|
852 | }
|
---|
853 | }
|
---|
854 |
|
---|
855 | private void reindexRelation(Relation relation) {
|
---|
856 | BBox before = relation.getBBox();
|
---|
857 | relation.updatePosition();
|
---|
858 | if (!before.equals(relation.getBBox())) {
|
---|
859 | for (OsmPrimitive primitive: relation.getReferrers()) {
|
---|
860 | reindexRelation((Relation) primitive);
|
---|
861 | }
|
---|
862 | }
|
---|
863 | }
|
---|
864 |
|
---|
865 | public void addDataSetListener(DataSetListener dsl) {
|
---|
866 | listeners.addIfAbsent(dsl);
|
---|
867 | }
|
---|
868 |
|
---|
869 | public void removeDataSetListener(DataSetListener dsl) {
|
---|
870 | listeners.remove(dsl);
|
---|
871 | }
|
---|
872 |
|
---|
873 | /**
|
---|
874 | * Can be called before bigger changes on dataset. Events are disabled until {@link #endUpdate()}.
|
---|
875 | * {@link DataSetListener#dataChanged()} event is triggered after end of changes
|
---|
876 | * <br>
|
---|
877 | * Typical usecase should look like this:
|
---|
878 | * <pre>
|
---|
879 | * ds.beginUpdate();
|
---|
880 | * try {
|
---|
881 | * ...
|
---|
882 | * } finally {
|
---|
883 | * ds.endUpdate();
|
---|
884 | * }
|
---|
885 | * </pre>
|
---|
886 | */
|
---|
887 | public void beginUpdate() {
|
---|
888 | lock.writeLock().lock();
|
---|
889 | updateCount++;
|
---|
890 | }
|
---|
891 |
|
---|
892 | /**
|
---|
893 | * @see DataSet#beginUpdate()
|
---|
894 | */
|
---|
895 | public void endUpdate() {
|
---|
896 | if (updateCount > 0) {
|
---|
897 | updateCount--;
|
---|
898 | if (updateCount == 0) {
|
---|
899 | List<AbstractDatasetChangedEvent> eventsCopy = new ArrayList<AbstractDatasetChangedEvent>(cachedEvents);
|
---|
900 | cachedEvents.clear();
|
---|
901 | lock.writeLock().unlock();
|
---|
902 |
|
---|
903 | if (!eventsCopy.isEmpty()) {
|
---|
904 | lock.readLock().lock();
|
---|
905 | try {
|
---|
906 | if (eventsCopy.size() < MAX_SINGLE_EVENTS) {
|
---|
907 | for (AbstractDatasetChangedEvent event: eventsCopy) {
|
---|
908 | fireEventToListeners(event);
|
---|
909 | }
|
---|
910 | } else if (eventsCopy.size() == MAX_EVENTS) {
|
---|
911 | fireEventToListeners(new DataChangedEvent(this));
|
---|
912 | } else {
|
---|
913 | fireEventToListeners(new DataChangedEvent(this, eventsCopy));
|
---|
914 | }
|
---|
915 | } finally {
|
---|
916 | lock.readLock().unlock();
|
---|
917 | }
|
---|
918 | }
|
---|
919 | } else {
|
---|
920 | lock.writeLock().unlock();
|
---|
921 | }
|
---|
922 |
|
---|
923 | } else
|
---|
924 | throw new AssertionError("endUpdate called without beginUpdate");
|
---|
925 | }
|
---|
926 |
|
---|
927 | private void fireEventToListeners(AbstractDatasetChangedEvent event) {
|
---|
928 | for (DataSetListener listener: listeners) {
|
---|
929 | event.fire(listener);
|
---|
930 | }
|
---|
931 | }
|
---|
932 |
|
---|
933 | private void fireEvent(AbstractDatasetChangedEvent event) {
|
---|
934 | if (updateCount == 0)
|
---|
935 | throw new AssertionError("dataset events can be fired only when dataset is locked");
|
---|
936 | if (cachedEvents.size() < MAX_EVENTS) {
|
---|
937 | cachedEvents.add(event);
|
---|
938 | }
|
---|
939 | }
|
---|
940 |
|
---|
941 | void firePrimitivesAdded(Collection<? extends OsmPrimitive> added, boolean wasIncomplete) {
|
---|
942 | fireEvent(new PrimitivesAddedEvent(this, added, wasIncomplete));
|
---|
943 | }
|
---|
944 |
|
---|
945 | void firePrimitivesRemoved(Collection<? extends OsmPrimitive> removed, boolean wasComplete) {
|
---|
946 | fireEvent(new PrimitivesRemovedEvent(this, removed, wasComplete));
|
---|
947 | }
|
---|
948 |
|
---|
949 | void fireTagsChanged(OsmPrimitive prim, Map<String, String> originalKeys) {
|
---|
950 | fireEvent(new TagsChangedEvent(this, prim, originalKeys));
|
---|
951 | }
|
---|
952 |
|
---|
953 | void fireRelationMembersChanged(Relation r) {
|
---|
954 | reindexRelation(r);
|
---|
955 | fireEvent(new RelationMembersChangedEvent(this, r));
|
---|
956 | }
|
---|
957 |
|
---|
958 | void fireNodeMoved(Node node, LatLon newCoor, EastNorth eastNorth) {
|
---|
959 | reindexNode(node, newCoor, eastNorth);
|
---|
960 | fireEvent(new NodeMovedEvent(this, node));
|
---|
961 | }
|
---|
962 |
|
---|
963 | void fireWayNodesChanged(Way way) {
|
---|
964 | reindexWay(way);
|
---|
965 | fireEvent(new WayNodesChangedEvent(this, way));
|
---|
966 | }
|
---|
967 |
|
---|
968 | void fireChangesetIdChanged(OsmPrimitive primitive, int oldChangesetId, int newChangesetId) {
|
---|
969 | fireEvent(new ChangesetIdChangedEvent(this, Collections.singletonList(primitive), oldChangesetId, newChangesetId));
|
---|
970 | }
|
---|
971 |
|
---|
972 | void fireHighlightingChanged(OsmPrimitive primitive) {
|
---|
973 | highlightUpdateCount++;
|
---|
974 | }
|
---|
975 |
|
---|
976 | public void cleanupDeletedPrimitives() {
|
---|
977 | beginUpdate();
|
---|
978 | try {
|
---|
979 | if (cleanupDeleted(nodes.iterator())
|
---|
980 | | cleanupDeleted(ways.iterator())
|
---|
981 | | cleanupDeleted(relations.iterator())) {
|
---|
982 | fireSelectionChanged();
|
---|
983 | }
|
---|
984 | } finally {
|
---|
985 | endUpdate();
|
---|
986 | }
|
---|
987 | }
|
---|
988 |
|
---|
989 | private boolean cleanupDeleted(Iterator<? extends OsmPrimitive> it) {
|
---|
990 | boolean changed = false;
|
---|
991 | synchronized (selectionLock) {
|
---|
992 | while (it.hasNext()) {
|
---|
993 | OsmPrimitive primitive = it.next();
|
---|
994 | if (primitive.isDeleted() && (!primitive.isVisible() || primitive.isNew())) {
|
---|
995 | selectedPrimitives.remove(primitive);
|
---|
996 | selectionSnapshot = null;
|
---|
997 | allPrimitives.remove(primitive);
|
---|
998 | primitive.setDataset(null);
|
---|
999 | changed = true;
|
---|
1000 | it.remove();
|
---|
1001 | }
|
---|
1002 | }
|
---|
1003 | if (changed) {
|
---|
1004 | selectionSnapshot = null;
|
---|
1005 | }
|
---|
1006 | }
|
---|
1007 | return changed;
|
---|
1008 | }
|
---|
1009 |
|
---|
1010 | /**
|
---|
1011 | * Removes all primitives from the dataset and resets the currently selected primitives
|
---|
1012 | * to the empty collection. Also notifies selection change listeners if necessary.
|
---|
1013 | *
|
---|
1014 | */
|
---|
1015 | public void clear() {
|
---|
1016 | beginUpdate();
|
---|
1017 | try {
|
---|
1018 | clearSelection();
|
---|
1019 | for (OsmPrimitive primitive:allPrimitives) {
|
---|
1020 | primitive.setDataset(null);
|
---|
1021 | }
|
---|
1022 | nodes.clear();
|
---|
1023 | ways.clear();
|
---|
1024 | relations.clear();
|
---|
1025 | allPrimitives.clear();
|
---|
1026 | } finally {
|
---|
1027 | endUpdate();
|
---|
1028 | }
|
---|
1029 | }
|
---|
1030 |
|
---|
1031 | /**
|
---|
1032 | * Marks all "invisible" objects as deleted. These objects should be always marked as
|
---|
1033 | * deleted when downloaded from the server. They can be undeleted later if necessary.
|
---|
1034 | *
|
---|
1035 | */
|
---|
1036 | public void deleteInvisible() {
|
---|
1037 | for (OsmPrimitive primitive:allPrimitives) {
|
---|
1038 | if (!primitive.isVisible()) {
|
---|
1039 | primitive.setDeleted(true);
|
---|
1040 | }
|
---|
1041 | }
|
---|
1042 | }
|
---|
1043 | }
|
---|