Changeset 3354 in josm for trunk/src/org


Ignore:
Timestamp:
2010-06-28T21:31:49+02:00 (14 years ago)
Author:
jttt
Message:

Fix #5193 josm got very slow recently (reverted fix for #5018)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/Filters.java

    r3352 r3354  
    6868            return;
    6969
    70         ds.beginUpdate(); // Modifies disabled/hidden state covered by write lock so read lock is not enough
    71         try {
    72             final Collection<OsmPrimitive> all = ds.allNonDeletedCompletePrimitives();
    73             // temporary set to collect the primitives returned by the search engine
    74             final Collection<OsmPrimitive> collect = new HashSet<OsmPrimitive>();
    75 
    76             // an auxiliary property to collect the results of the search engine
    77             class CollectProperty implements Property<OsmPrimitive,Boolean> {
    78                 boolean collectValue;
    79                 boolean hidden;
    80 
    81                 /**
    82                  * Depending on the parameters, there are 4 different instances
    83                  * of this class.
    84                  *
    85                  * @param collectValue
    86                  *          If true: collect only those primitives that are added
    87                  *              by the search engine.
    88                  *          If false: Collect only those primitives that are removed
    89                  *              by the search engine.
    90                  * @param hidden Whether the property refers to primitives that
    91                  *          are disabled and hidden or to primitives
    92                  *          that are disabled only.
    93                  */
    94                 public CollectProperty(boolean collectValue, boolean hidden) {
    95                     this.collectValue = collectValue;
    96                     this.hidden = hidden;
     70        final Collection<OsmPrimitive> all = ds.allNonDeletedCompletePrimitives();
     71        // temporary set to collect the primitives returned by the search engine
     72        final Collection<OsmPrimitive> collect = new HashSet<OsmPrimitive>();
     73
     74        // an auxiliary property to collect the results of the search engine
     75        class CollectProperty implements Property<OsmPrimitive,Boolean> {
     76            boolean collectValue;
     77            boolean hidden;
     78
     79            /**
     80             * Depending on the parameters, there are 4 different instances
     81             * of this class.
     82             *
     83             * @param collectValue
     84             *          If true: collect only those primitives that are added
     85             *              by the search engine.
     86             *          If false: Collect only those primitives that are removed
     87             *              by the search engine.
     88             * @param hidden Whether the property refers to primitives that
     89             *          are disabled and hidden or to primitives
     90             *          that are disabled only.
     91             */
     92            public CollectProperty(boolean collectValue, boolean hidden) {
     93                this.collectValue = collectValue;
     94                this.hidden = hidden;
     95            }
     96
     97            public Boolean get(OsmPrimitive osm) {
     98                if (hidden)
     99                    return osm.isDisabledAndHidden();
     100                else
     101                    return osm.isDisabled();
     102            }
     103
     104            public void set(OsmPrimitive osm, Boolean value) {
     105                if (collectValue == value.booleanValue()) {
     106                    collect.add(osm);
    97107                }
    98 
    99                 public Boolean get(OsmPrimitive osm) {
    100                     if (hidden)
    101                         return osm.isDisabledAndHidden();
    102                     else
    103                         return osm.isDisabled();
    104                 }
    105 
    106                 public void set(OsmPrimitive osm, Boolean value) {
    107                     if (collectValue == value.booleanValue()) {
    108                         collect.add(osm);
     108            }
     109        }
     110
     111        clearFilterFlags();
     112
     113        for (Filter flt : filters){
     114            if (flt.enable) {
     115                collect.clear();
     116                // Decide, whether primitives are collected that are added to the current
     117                // selection or those that are removed from the current selection
     118                boolean collectValue = flt.mode == SearchAction.SearchMode.replace || flt.mode == SearchAction.SearchMode.add;
     119                Property<OsmPrimitive,Boolean> collectProp = new CollectProperty(collectValue, flt.hiding);
     120
     121                SearchAction.getSelection(flt, all, collectProp);
     122
     123                switch (flt.mode) {
     124                case replace:
     125                    for (OsmPrimitive osm : all) {
     126                        osm.unsetDisabledState();
    109127                    }
    110                 }
    111             }
    112 
    113             clearFilterFlags();
    114 
    115             for (Filter flt : filters){
    116                 if (flt.enable) {
    117                     collect.clear();
    118                     // Decide, whether primitives are collected that are added to the current
    119                     // selection or those that are removed from the current selection
    120                     boolean collectValue = flt.mode == SearchAction.SearchMode.replace || flt.mode == SearchAction.SearchMode.add;
    121                     Property<OsmPrimitive,Boolean> collectProp = new CollectProperty(collectValue, flt.hiding);
    122 
    123                     SearchAction.getSelection(flt, all, collectProp);
    124 
    125                     switch (flt.mode) {
    126                     case replace:
    127                         for (OsmPrimitive osm : all) {
    128                             osm.unsetDisabledState();
    129                         }
    130                     case add:
    131                         if (!flt.inverted) {
    132                             for (OsmPrimitive osm : collect) {
    133                                 osm.setDisabledState(flt.hiding);
    134                             }
    135 
    136                             // Find child nodes of hidden ways and add them to the hidden nodes
    137                             for (OsmPrimitive osm : collect) {
    138                                 if (osm instanceof Way) {
    139                                     nodes:
    140                                         for (Node n : ((Way)osm).getNodes()) {
    141                                             // if node is already disabled, there is nothing to do
    142                                             if (n.isDisabledAndHidden() || (!flt.hiding && n.isDisabled())) {
    143                                                 continue;
    144                                             }
    145 
    146                                             // if the node is tagged, don't disable it
    147                                             if (n.isTagged()) {
    148                                                 continue;
    149                                             }
    150 
    151                                             // if the node has undisabled parent ways, don't disable it
    152                                             for (OsmPrimitive ref : n.getReferrers()) {
    153                                                 if (ref instanceof Way) {
    154                                                     if (!ref.isDisabled()) {
    155                                                         continue nodes;
    156                                                     }
    157                                                     if (flt.hiding && !ref.isDisabledAndHidden()) {
    158                                                         continue nodes;
    159                                                     }
    160                                                 }
    161                                             }
    162                                             n.setDisabledState(flt.hiding);
    163                                         }
    164                                 }
    165                             }
    166                         } else { // inverted filter in add mode
    167                             // update flags, except for nodes
    168                             for (OsmPrimitive osm : collect) {
    169                                 if (!(osm instanceof Node)) {
    170                                     osm.setDisabledState(flt.hiding);
    171                                 }
    172                             }
    173 
    174                             // update flags for nodes
    175                             nodes:
    176                                 for (OsmPrimitive osm : collect) {
    177                                     if (osm instanceof Node) {
     128                case add:
     129                    if (!flt.inverted) {
     130                        for (OsmPrimitive osm : collect) {
     131                            osm.setDisabledState(flt.hiding);
     132                        }
     133
     134                        // Find child nodes of hidden ways and add them to the hidden nodes
     135                        for (OsmPrimitive osm : collect) {
     136                            if (osm instanceof Way) {
     137                                nodes:
     138                                    for (Node n : ((Way)osm).getNodes()) {
    178139                                        // if node is already disabled, there is nothing to do
    179                                         if (osm.isDisabledAndHidden() || (!flt.hiding && osm.isDisabled())) {
     140                                        if (n.isDisabledAndHidden() || (!flt.hiding && n.isDisabled())) {
    180141                                            continue;
    181142                                        }
    182143
     144                                        // if the node is tagged, don't disable it
     145                                        if (n.isTagged()) {
     146                                            continue;
     147                                        }
     148
    183149                                        // if the node has undisabled parent ways, don't disable it
    184                                         for (OsmPrimitive ref : osm.getReferrers()) {
     150                                        for (OsmPrimitive ref : n.getReferrers()) {
    185151                                            if (ref instanceof Way) {
    186152                                                if (!ref.isDisabled()) {
     
    192158                                            }
    193159                                        }
    194                                         osm.setDisabledState(flt.hiding);
     160                                        n.setDisabledState(flt.hiding);
    195161                                    }
    196                                 }
    197                         }
    198                         break;
    199                     case remove:
    200                     case in_selection:
    201                         if (!flt.inverted) {
    202                             // make the described primitive undisabled again
     162                            }
     163                        }
     164                    } else { // inverted filter in add mode
     165                        // update flags, except for nodes
     166                        for (OsmPrimitive osm : collect) {
     167                            if (!(osm instanceof Node)) {
     168                                osm.setDisabledState(flt.hiding);
     169                            }
     170                        }
     171
     172                        // update flags for nodes
     173                        nodes:
    203174                            for (OsmPrimitive osm : collect) {
    204                                 osm.unsetDisabledState();
    205                             }
    206 
    207                             // Undisable the child nodes of undisabled ways
    208                             for (OsmPrimitive osm : collect) {
    209                                 if (osm instanceof Way) {
    210                                     for (Node n : ((Way) osm).getNodes()) {
    211                                         n.unsetDisabledState();
     175                                if (osm instanceof Node) {
     176                                    // if node is already disabled, there is nothing to do
     177                                    if (osm.isDisabledAndHidden() || (!flt.hiding && osm.isDisabled())) {
     178                                        continue;
    212179                                    }
     180
     181                                    // if the node has undisabled parent ways, don't disable it
     182                                    for (OsmPrimitive ref : osm.getReferrers()) {
     183                                        if (ref instanceof Way) {
     184                                            if (!ref.isDisabled()) {
     185                                                continue nodes;
     186                                            }
     187                                            if (flt.hiding && !ref.isDisabledAndHidden()) {
     188                                                continue nodes;
     189                                            }
     190                                        }
     191                                    }
     192                                    osm.setDisabledState(flt.hiding);
    213193                                }
    214194                            }
    215                         } else { // inverted filter in remove mode
    216                             // make the described primitive undisabled again
    217                             for (OsmPrimitive osm : collect) {
    218                                 osm.unsetDisabledState();
    219                             }
    220 
    221                             // Undisable the child nodes of undisabled ways
    222                             for (OsmPrimitive osm : collect) {
    223                                 if (osm instanceof Way) {
    224                                     for (Node n : ((Way) osm).getNodes()) {
    225                                         n.unsetDisabledState();
    226                                     }
     195                    }
     196                    break;
     197                case remove:
     198                case in_selection:
     199                    if (!flt.inverted) {
     200                        // make the described primitive undisabled again
     201                        for (OsmPrimitive osm : collect) {
     202                            osm.unsetDisabledState();
     203                        }
     204
     205                        // Undisable the child nodes of undisabled ways
     206                        for (OsmPrimitive osm : collect) {
     207                            if (osm instanceof Way) {
     208                                for (Node n : ((Way) osm).getNodes()) {
     209                                    n.unsetDisabledState();
    227210                                }
    228211                            }
    229212                        }
    230                         break;
    231                     default:
    232                         throw new IllegalStateException();
     213                    } else { // inverted filter in remove mode
     214                        // make the described primitive undisabled again
     215                        for (OsmPrimitive osm : collect) {
     216                            osm.unsetDisabledState();
     217                        }
     218
     219                        // Undisable the child nodes of undisabled ways
     220                        for (OsmPrimitive osm : collect) {
     221                            if (osm instanceof Way) {
     222                                for (Node n : ((Way) osm).getNodes()) {
     223                                    n.unsetDisabledState();
     224                                }
     225                            }
     226                        }
    233227                    }
     228                    break;
     229                default:
     230                    throw new IllegalStateException();
    234231                }
    235232            }
    236 
    237             disabledCount = 0;
    238             disabledAndHiddenCount = 0;
    239             // collect disabled and selected the primitives
    240             final Collection<OsmPrimitive> deselect = new HashSet<OsmPrimitive>();
    241             for (OsmPrimitive osm : all) {
    242                 if (osm.isDisabled()) {
    243                     disabledCount++;
    244                     if (osm.isSelected()) {
    245                         deselect.add(osm);
    246                     }
    247                     if (osm.isDisabledAndHidden()) {
    248                         disabledAndHiddenCount++;
    249                     }
     233        }
     234
     235        disabledCount = 0;
     236        disabledAndHiddenCount = 0;
     237        // collect disabled and selected the primitives
     238        final Collection<OsmPrimitive> deselect = new HashSet<OsmPrimitive>();
     239        for (OsmPrimitive osm : all) {
     240            if (osm.isDisabled()) {
     241                disabledCount++;
     242                if (osm.isSelected()) {
     243                    deselect.add(osm);
    250244                }
    251             }
    252             disabledCount -= disabledAndHiddenCount;
    253             if (!deselect.isEmpty()) {
    254                 ds.clearSelection(deselect);
    255             }
    256 
    257             Main.map.mapView.repaint();
    258             Main.map.filterDialog.updateDialogHeader();
    259         } finally {
    260             ds.endUpdate();
    261         }
     245                if (osm.isDisabledAndHidden()) {
     246                    disabledAndHiddenCount++;
     247                }
     248            }
     249        }
     250        disabledCount -= disabledAndHiddenCount;
     251        if (!deselect.isEmpty()) {
     252            ds.clearSelection(deselect);
     253        }
     254
     255        Main.map.mapView.repaint();
     256        Main.map.filterDialog.updateDialogHeader();
    262257    }
    263258
Note: See TracChangeset for help on using the changeset viewer.