Changeset 16321 in josm for trunk/src/org


Ignore:
Timestamp:
2020-04-17T17:54:04+02:00 (4 years ago)
Author:
simon04
Message:

fix #18907 - Initialize Territories+RightAndLefthandTraffic together, remove "Edit boundaries" to save memory (unless started with --debug)

Location:
trunk/src/org/openstreetmap/josm
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/MainInitialization.java

    r16111 r16321  
    3939import org.openstreetmap.josm.tools.OverpassTurboQueryWizard;
    4040import org.openstreetmap.josm.tools.PlatformManager;
    41 import org.openstreetmap.josm.tools.RightAndLefthandTraffic;
    4241import org.openstreetmap.josm.tools.Shortcut;
    4342import org.openstreetmap.josm.tools.Tag2Link;
     
    8281                MainApplication.registerActionShortcut(MainApplication.menu.help,
    8382                        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            })
    8784        );
    8885    }
     
    114111                    }
    115112                }),
    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();
    118115                if (Config.getPref().getBoolean("override.numbering.format", true)) {
    119116                    I18n.initializeNumberingFormat();
  • trunk/src/org/openstreetmap/josm/gui/mappaint/RenderingCLI.java

    r14419 r16321  
    4444import org.openstreetmap.josm.tools.OptionParser.OptionCount;
    4545import org.openstreetmap.josm.tools.OptionParser.OptionParseException;
    46 import org.openstreetmap.josm.tools.RightAndLefthandTraffic;
     46import org.openstreetmap.josm.tools.Territories;
    4747
    4848/**
     
    439439        ProjectionRegistry.setProjection(Projections.getProjectionByCode(projCode.toUpperCase(Locale.US)));
    440440
    441         RightAndLefthandTraffic.initialize();
     441        Territories.initialize();
    442442    }
    443443
  • trunk/src/org/openstreetmap/josm/gui/preferences/advanced/AdvancedPreference.java

    r15780 r16321  
    9090    }
    9191
     92    /**
     93     * Requires {@link Logging#isDebugEnabled()}, otherwise dataset is unloaded
     94     * @see Territories#initializeInternalData()
     95     */
    9296    private static final class EditBoundariesAction extends AbstractAction {
    9397        EditBoundariesAction() {
     
    391395        menu.addSeparator();
    392396        menu.add(getProfileMenu());
    393         menu.addSeparator();
    394         menu.add(new EditBoundariesAction());
     397        if (Logging.isDebugEnabled()) {
     398            menu.addSeparator();
     399            menu.add(new EditBoundariesAction());
     400        }
    395401        menu.addSeparator();
    396402        menu.add(new ResetPreferencesAction());
  • trunk/src/org/openstreetmap/josm/tools/RightAndLefthandTraffic.java

    r14720 r16321  
    22package org.openstreetmap.josm.tools;
    33
    4 import java.util.ArrayList;
    54import java.util.Collection;
    65import java.util.Collections;
     
    87
    98import org.openstreetmap.josm.data.coor.LatLon;
    10 import org.openstreetmap.josm.data.osm.DataSet;
    119import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1210import org.openstreetmap.josm.data.osm.Relation;
     
    4341    /**
    4442     * Initializes Right and lefthand traffic data.
     43     * @param geoProperty the property containing the traffic data
    4544     * TODO: Synchronization can be refined inside the {@link GeoPropertyIndex} as most look-ups are read-only.
    4645     */
    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);
    4948    }
    5049
    51     private static DefaultGeoProperty computeLeftDrivingBoundaries() {
    52         Collection<Way> ways = new ArrayList<>();
     50    static void appendLeftDrivingBoundaries(OsmPrimitive osm, Collection<Way> ways) {
    5351        // 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;
    5755                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;
    6258                for (RelationMember rm : r.getMembers()) {
    6359                    if (rm.isWay() && "outer".equals(rm.getRole()) && !RIGHT.equals(rm.getMember().get(DRIVING_SIDE))) {
     
    6763            }
    6864        }
    69         // Combine adjacent countries into a single polygon
    70         return new DefaultGeoProperty(ways);
    7165    }
    7266
  • trunk/src/org/openstreetmap/josm/tools/Territories.java

    r16272 r16321  
    3232import org.openstreetmap.josm.data.coor.LatLon;
    3333import org.openstreetmap.josm.data.osm.DataSet;
     34import org.openstreetmap.josm.data.osm.Node;
    3435import org.openstreetmap.josm.data.osm.OsmPrimitive;
    3536import org.openstreetmap.josm.data.osm.Relation;
    3637import org.openstreetmap.josm.data.osm.TagMap;
    3738import org.openstreetmap.josm.data.osm.Way;
     39import org.openstreetmap.josm.data.osm.visitor.paint.relations.MultipolygonCache;
    3840import org.openstreetmap.josm.io.CachedFile;
    3941import org.openstreetmap.josm.io.IllegalDataException;
     
    114116
    115117    /**
    116      * Returns a copy of the territories dataset.
    117      * @return a copy of the territories dataset
    118      */
    119     public static synchronized DataSet getDataSet() {
    120         return new DataSet(dataSet);
    121     }
    122 
    123     /**
    124118     * Initializes territories.
    125119     * TODO: Synchronization can be refined inside the {@link GeoPropertyIndex} as most look-ups are read-only.
     
    138132        taginfoCache = new TreeMap<>();
    139133        customTagsCache = new TreeMap<>();
     134        Collection<Way> traffic = new ArrayList<>();
    140135        try (CachedFile cf = new CachedFile("resource://data/" + FILENAME);
    141136                InputStream is = cf.getInputStream()) {
    142137            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                }
    146142                String iso1 = osm.get(ISO3166_1);
    147143                String iso2 = osm.get(ISO3166_2);
     
    165161                    }
    166162                }
    167             }
     163                RightAndLefthandTraffic.appendLeftDrivingBoundaries(osm, traffic);
     164            }
     165            RightAndLefthandTraffic.initialize(new DefaultGeoProperty(traffic));
    168166        } catch (IOException | IllegalDataException ex) {
    169167            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            }
    170176        }
    171177    }
Note: See TracChangeset for help on using the changeset viewer.