Changeset 3352 in josm for trunk/src/org


Ignore:
Timestamp:
2010-06-28T08:12:43+02:00 (14 years ago)
Author:
jttt
Message:

Fix #5018 DataIntegrityProblemException: Primitive must be part of the dataset

File:
1 edited

Legend:

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

    r3346 r3352  
    88import java.awt.Graphics;
    99import java.awt.Graphics2D;
    10 
    1110import java.util.Collection;
    1211import java.util.HashSet;
     
    6968            return;
    7069
    71         final Collection<OsmPrimitive> all = ds.allNonDeletedCompletePrimitives();
    72         // temporary set to collect the primitives returned by the search engine
    73         final Collection<OsmPrimitive> collect = new HashSet<OsmPrimitive>();
    74 
    75         // an auxiliary property to collect the results of the search engine
    76         class CollectProperty implements Property<OsmPrimitive,Boolean> {
    77             boolean collectValue;
    78             boolean hidden;
    79 
    80             /**
    81              * Depending on the parameters, there are 4 different instances
    82              * of this class.
    83              *
    84              * @param collectValue
    85              *          If true: collect only those primitives that are added
    86              *              by the search engine.
    87              *          If false: Collect only those primitives that are removed
    88              *              by the search engine.
    89              * @param hidden Whether the property refers to primitives that
    90              *          are disabled and hidden or to primitives
    91              *          that are disabled only.
    92              */
    93             public CollectProperty(boolean collectValue, boolean hidden) {
    94                 this.collectValue = collectValue;
    95                 this.hidden = hidden;
    96             }
    97 
    98             public Boolean get(OsmPrimitive osm) {
    99                 if (hidden)
    100                     return osm.isDisabledAndHidden();
    101                 else
    102                     return osm.isDisabled();
    103             }
    104 
    105             public void set(OsmPrimitive osm, Boolean value) {
    106                 if (collectValue == value.booleanValue()) {
    107                     collect.add(osm);
     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;
    10897                }
    109             }
    110         }
    111 
    112         clearFilterFlags();
    113 
    114         for (Filter flt : filters){
    115             if (flt.enable) {
    116                 collect.clear();
    117                 // Decide, whether primitives are collected that are added to the current
    118                 // selection or those that are removed from the current selection
    119                 boolean collectValue = flt.mode == SearchAction.SearchMode.replace || flt.mode == SearchAction.SearchMode.add;
    120                 Property<OsmPrimitive,Boolean> collectProp = new CollectProperty(collectValue, flt.hiding);
    121 
    122                 SearchAction.getSelection(flt, all, collectProp);
    123 
    124                 switch (flt.mode) {
     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);
     109                    }
     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) {
    125126                    case replace:
    126127                        for (OsmPrimitive osm : all) {
     
    137138                                if (osm instanceof Way) {
    138139                                    nodes:
    139                                     for (Node n : ((Way)osm).getNodes()) {
    140                                         // if node is already disabled, there is nothing to do
    141                                         if (n.isDisabledAndHidden() || (!flt.hiding && n.isDisabled()))
    142                                             continue;
    143 
    144                                         // if the node is tagged, don't disable it
    145                                         if (n.isTagged())
    146                                             continue;
    147 
    148                                         // if the node has undisabled parent ways, don't disable it
    149                                         for (OsmPrimitive ref : n.getReferrers()) {
    150                                             if (ref instanceof Way) {
    151                                                 if (!ref.isDisabled())
    152                                                     continue nodes;
    153                                                 if (flt.hiding && !ref.isDisabledAndHidden())
    154                                                     continue 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;
    155144                                            }
     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);
    156163                                        }
    157                                         n.setDisabledState(flt.hiding);
    158                                     }
    159164                                }
    160165                            }
     
    169174                            // update flags for nodes
    170175                            nodes:
    171                             for (OsmPrimitive osm : collect) {
    172                                 if (osm instanceof Node) {
    173                                     // if node is already disabled, there is nothing to do
    174                                     if (osm.isDisabledAndHidden() || (!flt.hiding && osm.isDisabled()))
    175                                         continue;
    176 
    177                                     // if the node has undisabled parent ways, don't disable it
    178                                     for (OsmPrimitive ref : osm.getReferrers()) {
    179                                         if (ref instanceof Way) {
    180                                             if (!ref.isDisabled())
    181                                                 continue nodes;
    182                                             if (flt.hiding && !ref.isDisabledAndHidden())
    183                                                 continue nodes;
     176                                for (OsmPrimitive osm : collect) {
     177                                    if (osm instanceof Node) {
     178                                        // if node is already disabled, there is nothing to do
     179                                        if (osm.isDisabledAndHidden() || (!flt.hiding && osm.isDisabled())) {
     180                                            continue;
    184181                                        }
     182
     183                                        // if the node has undisabled parent ways, don't disable it
     184                                        for (OsmPrimitive ref : osm.getReferrers()) {
     185                                            if (ref instanceof Way) {
     186                                                if (!ref.isDisabled()) {
     187                                                    continue nodes;
     188                                                }
     189                                                if (flt.hiding && !ref.isDisabledAndHidden()) {
     190                                                    continue nodes;
     191                                                }
     192                                            }
     193                                        }
     194                                        osm.setDisabledState(flt.hiding);
    185195                                    }
    186                                     osm.setDisabledState(flt.hiding);
    187196                                }
    188                             }
    189197                        }
    190198                        break;
     
    223231                    default:
    224232                        throw new IllegalStateException();
     233                    }
    225234                }
    226235            }
    227         }
    228 
    229         disabledCount = 0;
    230         disabledAndHiddenCount = 0;
    231         // collect disabled and selected the primitives
    232         final Collection<OsmPrimitive> deselect = new HashSet<OsmPrimitive>();
    233         for (OsmPrimitive osm : all) {
    234             if (osm.isDisabled()) {
    235                 disabledCount++;
    236                 if (osm.isSelected()) {
    237                     deselect.add(osm);
     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                    }
    238250                }
    239                 if (osm.isDisabledAndHidden()) {
    240                     disabledAndHiddenCount++;
    241                 }
    242             }
    243         }
    244         disabledCount -= disabledAndHiddenCount;
    245         if (!deselect.isEmpty()) {
    246             ds.clearSelection(deselect);
    247         }
    248 
    249         Main.map.mapView.repaint();
    250         Main.map.filterDialog.updateDialogHeader();
     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        }
    251262    }
    252263
Note: See TracChangeset for help on using the changeset viewer.