Changeset 16321 in josm
- Timestamp:
- 2020-04-17T17:54:04+02:00 (5 years ago)
- Location:
- trunk
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/scripts/TagInfoExtract.java
r16272 r16321 622 622 DeleteCommand.setDeletionCallback(DeleteAction.defaultDeletionCallback); 623 623 Territories.initializeInternalData(); 624 RightAndLefthandTraffic.initialize();625 624 Files.createDirectories(options.imageDir); 626 625 } -
trunk/src/org/openstreetmap/josm/gui/MainInitialization.java
r16111 r16321 39 39 import org.openstreetmap.josm.tools.OverpassTurboQueryWizard; 40 40 import org.openstreetmap.josm.tools.PlatformManager; 41 import org.openstreetmap.josm.tools.RightAndLefthandTraffic;42 41 import org.openstreetmap.josm.tools.Shortcut; 43 42 import org.openstreetmap.josm.tools.Tag2Link; … … 82 81 MainApplication.registerActionShortcut(MainApplication.menu.help, 83 82 Shortcut.registerShortcut("system:help", tr("Help"), KeyEvent.VK_F1, Shortcut.DIRECT)); 84 }), 85 // This needs to be done before RightAndLefthandTraffic::initialize is called 86 new InitializationTask(tr("Initializing internal boundaries data"), Territories::initialize) 83 }) 87 84 ); 88 85 } … … 114 111 } 115 112 }), 116 new InitializationTask(tr("Initializing internal traffic data"), RightAndLefthandTraffic::initialize),117 new InitializationTask(tr("Initializing numbering format"), () -> {113 new InitializationTask(tr("Initializing internal boundaries data"), () -> { 114 Territories.initialize(); 118 115 if (Config.getPref().getBoolean("override.numbering.format", true)) { 119 116 I18n.initializeNumberingFormat(); -
trunk/src/org/openstreetmap/josm/gui/mappaint/RenderingCLI.java
r14419 r16321 44 44 import org.openstreetmap.josm.tools.OptionParser.OptionCount; 45 45 import org.openstreetmap.josm.tools.OptionParser.OptionParseException; 46 import org.openstreetmap.josm.tools. RightAndLefthandTraffic;46 import org.openstreetmap.josm.tools.Territories; 47 47 48 48 /** … … 439 439 ProjectionRegistry.setProjection(Projections.getProjectionByCode(projCode.toUpperCase(Locale.US))); 440 440 441 RightAndLefthandTraffic.initialize();441 Territories.initialize(); 442 442 } 443 443 -
trunk/src/org/openstreetmap/josm/gui/preferences/advanced/AdvancedPreference.java
r15780 r16321 90 90 } 91 91 92 /** 93 * Requires {@link Logging#isDebugEnabled()}, otherwise dataset is unloaded 94 * @see Territories#initializeInternalData() 95 */ 92 96 private static final class EditBoundariesAction extends AbstractAction { 93 97 EditBoundariesAction() { … … 391 395 menu.addSeparator(); 392 396 menu.add(getProfileMenu()); 393 menu.addSeparator(); 394 menu.add(new EditBoundariesAction()); 397 if (Logging.isDebugEnabled()) { 398 menu.addSeparator(); 399 menu.add(new EditBoundariesAction()); 400 } 395 401 menu.addSeparator(); 396 402 menu.add(new ResetPreferencesAction()); -
trunk/src/org/openstreetmap/josm/tools/RightAndLefthandTraffic.java
r14720 r16321 2 2 package org.openstreetmap.josm.tools; 3 3 4 import java.util.ArrayList;5 4 import java.util.Collection; 6 5 import java.util.Collections; … … 8 7 9 8 import org.openstreetmap.josm.data.coor.LatLon; 10 import org.openstreetmap.josm.data.osm.DataSet;11 9 import org.openstreetmap.josm.data.osm.OsmPrimitive; 12 10 import org.openstreetmap.josm.data.osm.Relation; … … 43 41 /** 44 42 * Initializes Right and lefthand traffic data. 43 * @param geoProperty the property containing the traffic data 45 44 * TODO: Synchronization can be refined inside the {@link GeoPropertyIndex} as most look-ups are read-only. 46 45 */ 47 public static synchronized void initialize() {48 rlCache = new GeoPropertyIndex<>( computeLeftDrivingBoundaries(), 24);46 static synchronized void initialize(DefaultGeoProperty geoProperty) { 47 rlCache = new GeoPropertyIndex<>(geoProperty, 24); 49 48 } 50 49 51 private static DefaultGeoProperty computeLeftDrivingBoundaries() { 52 Collection<Way> ways = new ArrayList<>(); 50 static void appendLeftDrivingBoundaries(OsmPrimitive osm, Collection<Way> ways) { 53 51 // Find all outer ways of left-driving countries. Many of them are adjacent (African and Asian states) 54 DataSet data = Territories.getDataSet();55 for (Way w : data.getWays()) {56 if (LEFT.equals(w.get(DRIVING_SIDE))) {52 if (LEFT.equals(osm.get(DRIVING_SIDE))) { 53 if (osm instanceof Way) { 54 Way w = (Way) osm; 57 55 addWayIfNotInner(ways, w); 58 } 59 } 60 for (Relation r : data.getRelations()) { 61 if (r.isMultipolygon() && LEFT.equals(r.get(DRIVING_SIDE))) { 56 } else if (osm instanceof Relation && osm.isMultipolygon()) { 57 Relation r = (Relation) osm; 62 58 for (RelationMember rm : r.getMembers()) { 63 59 if (rm.isWay() && "outer".equals(rm.getRole()) && !RIGHT.equals(rm.getMember().get(DRIVING_SIDE))) { … … 67 63 } 68 64 } 69 // Combine adjacent countries into a single polygon70 return new DefaultGeoProperty(ways);71 65 } 72 66 -
trunk/src/org/openstreetmap/josm/tools/Territories.java
r16272 r16321 32 32 import org.openstreetmap.josm.data.coor.LatLon; 33 33 import org.openstreetmap.josm.data.osm.DataSet; 34 import org.openstreetmap.josm.data.osm.Node; 34 35 import org.openstreetmap.josm.data.osm.OsmPrimitive; 35 36 import org.openstreetmap.josm.data.osm.Relation; 36 37 import org.openstreetmap.josm.data.osm.TagMap; 37 38 import org.openstreetmap.josm.data.osm.Way; 39 import org.openstreetmap.josm.data.osm.visitor.paint.relations.MultipolygonCache; 38 40 import org.openstreetmap.josm.io.CachedFile; 39 41 import org.openstreetmap.josm.io.IllegalDataException; … … 114 116 115 117 /** 116 * Returns a copy of the territories dataset.117 * @return a copy of the territories dataset118 */119 public static synchronized DataSet getDataSet() {120 return new DataSet(dataSet);121 }122 123 /**124 118 * Initializes territories. 125 119 * TODO: Synchronization can be refined inside the {@link GeoPropertyIndex} as most look-ups are read-only. … … 138 132 taginfoCache = new TreeMap<>(); 139 133 customTagsCache = new TreeMap<>(); 134 Collection<Way> traffic = new ArrayList<>(); 140 135 try (CachedFile cf = new CachedFile("resource://data/" + FILENAME); 141 136 InputStream is = cf.getInputStream()) { 142 137 dataSet = OsmReader.parseDataSet(is, null); 143 Collection<OsmPrimitive> candidates = new ArrayList<>(dataSet.getWays()); 144 candidates.addAll(dataSet.getRelations()); 145 for (OsmPrimitive osm : candidates) { 138 for (OsmPrimitive osm : dataSet.allPrimitives()) { 139 if (osm instanceof Node) { 140 continue; 141 } 146 142 String iso1 = osm.get(ISO3166_1); 147 143 String iso2 = osm.get(ISO3166_2); … … 165 161 } 166 162 } 167 } 163 RightAndLefthandTraffic.appendLeftDrivingBoundaries(osm, traffic); 164 } 165 RightAndLefthandTraffic.initialize(new DefaultGeoProperty(traffic)); 168 166 } catch (IOException | IllegalDataException ex) { 169 167 throw new JosmRuntimeException(ex); 168 } finally { 169 MultipolygonCache.getInstance().clear(dataSet); 170 if (!Logging.isDebugEnabled()) { 171 // unset dataSet to save memory, see #18907 172 dataSet = null; 173 } else { 174 Logging.debug("Retaining {0} to allow editing via advanced preferences", FILENAME); 175 } 170 176 } 171 177 } -
trunk/test/unit/org/openstreetmap/josm/gui/dialogs/properties/TagEditHelperTest.java
r15947 r16321 51 51 @Rule 52 52 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 53 public JOSMTestRules test = new JOSMTestRules().territories(). rlTraffic().projection();53 public JOSMTestRules test = new JOSMTestRules().territories().projection(); 54 54 55 55 private static TagEditHelper newTagEditHelper() { -
trunk/test/unit/org/openstreetmap/josm/testutils/JOSMTestRules.java
r16272 r16321 65 65 import org.openstreetmap.josm.tools.Logging; 66 66 import org.openstreetmap.josm.tools.MemoryManagerTest; 67 import org.openstreetmap.josm.tools.RightAndLefthandTraffic;68 67 import org.openstreetmap.josm.tools.Territories; 69 68 import org.openstreetmap.josm.tools.bugreport.ReportedException; … … 100 99 private boolean useHttps; 101 100 private boolean territories; 102 private boolean rlTraffic;103 101 private boolean metric; 104 102 private boolean main; … … 270 268 * @return this instance, for easy chaining 271 269 * @since 12556 272 */ 270 * @deprecated Use {@link #territories} 271 */ 272 @Deprecated 273 273 public JOSMTestRules rlTraffic() { 274 274 territories(); 275 rlTraffic = true;276 275 return this; 277 276 } … … 551 550 if (territories) { 552 551 Territories.initializeInternalData(); 553 }554 555 if (rlTraffic) {556 RightAndLefthandTraffic.initialize();557 552 } 558 553 -
trunk/test/unit/org/openstreetmap/josm/tools/RightAndLefthandTrafficTest.java
r16182 r16321 21 21 @Rule 22 22 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 23 public JOSMTestRules rules = new JOSMTestRules().projection(). rlTraffic();23 public JOSMTestRules rules = new JOSMTestRules().projection().territories(); 24 24 25 25 /**
Note:
See TracChangeset
for help on using the changeset viewer.