source: josm/trunk/src/org/openstreetmap/josm/actions/UpdateDataAction.java@ 11635

Last change on this file since 11635 was 11627, checked in by Don-vip, 7 years ago

fix #3346 - improve drastically the performance of fixing duplicate nodes by:

  • caching data sources area computation
  • moving layer invalidation from UndoRedoHandler.addNoRedraw to UndoRedoHandler.add
  • avoiding any EDT call when building tag conflict dialog if it's not meant to be displayed
  • Property svn:eol-style set to native
File size: 3.3 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.actions;
3
4import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
5import static org.openstreetmap.josm.tools.I18n.tr;
6
7import java.awt.event.ActionEvent;
8import java.awt.event.KeyEvent;
9import java.awt.geom.Area;
10import java.util.ArrayList;
11import java.util.List;
12import java.util.concurrent.Future;
13
14import org.openstreetmap.josm.Main;
15import org.openstreetmap.josm.actions.downloadtasks.DownloadTaskList;
16import org.openstreetmap.josm.data.DataSource;
17import org.openstreetmap.josm.gui.layer.OsmDataLayer;
18import org.openstreetmap.josm.gui.progress.PleaseWaitProgressMonitor;
19import org.openstreetmap.josm.io.OnlineResource;
20import org.openstreetmap.josm.tools.Shortcut;
21
22public class UpdateDataAction extends JosmAction {
23
24 /**
25 * Constructs a new {@code UpdateDataAction}.
26 */
27 public UpdateDataAction() {
28 super(tr("Update data"),
29 "updatedata",
30 tr("Updates the objects in the active data layer from the server."),
31 Shortcut.registerShortcut("file:updatedata",
32 tr("File: {0}", tr("Update data")),
33 KeyEvent.VK_U, Shortcut.CTRL),
34 true);
35 putValue("help", ht("/Action/UpdateData"));
36 }
37
38 /**
39 * Refreshes the enabled state
40 */
41 @Override
42 protected void updateEnabledState() {
43 setEnabled(getLayerManager().getEditLayer() != null && !Main.isOffline(OnlineResource.OSM_API));
44 }
45
46 @Override
47 public void actionPerformed(ActionEvent e) {
48 OsmDataLayer editLayer = getLayerManager().getEditLayer();
49 if (!isEnabled() || editLayer == null)
50 return;
51
52 List<Area> areas = new ArrayList<>();
53 for (DataSource ds : editLayer.data.getDataSources()) {
54 areas.add(new Area(ds.bounds.asRect()));
55 }
56
57 // The next two blocks removes every intersection from every DataSource Area
58 // This prevents downloading the same data numerous times at intersections
59 // and also skips smaller bounding boxes that are contained within larger ones entirely.
60 for (int i = 0; i < areas.size(); i++) {
61 for (int j = i+1; j < areas.size(); j++) {
62 areas.get(i).subtract(areas.get(j));
63 }
64 }
65
66 for (int i = areas.size()-1; i > 0; i--) {
67 for (int j = i-1; j > 0; j--) {
68 areas.get(i).subtract(areas.get(j));
69 }
70 }
71
72 List<Area> areasToDownload = new ArrayList<>();
73 for (Area a : areas) {
74 if (a.isEmpty()) {
75 continue;
76 }
77 areasToDownload.add(a);
78 }
79
80 if (areasToDownload.isEmpty()) {
81 // no bounds defined in the dataset? we update all primitives in the data set using a series of multi fetch requests
82 UpdateSelectionAction.updatePrimitives(editLayer.data.allPrimitives());
83 } else {
84 // bounds defined? => use the bbox downloader
85 final PleaseWaitProgressMonitor monitor = new PleaseWaitProgressMonitor(tr("Download data"));
86 final Future<?> future = new DownloadTaskList().download(false /* no new layer */, areasToDownload, true, false, monitor);
87 waitFuture(future, monitor);
88 }
89 }
90}
Note: See TracBrowser for help on using the repository browser.