Changeset 5719 in josm


Ignore:
Timestamp:
2013-02-15T21:58:25+01:00 (12 years ago)
Author:
Don-vip
Message:

see #8431 - Align in circle: Do not allow "regular polygon" mode for way nodes being referred by another primitives. The initial problem (way being reverted) remains.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/AlignInCircleAction.java

    r5125 r5719  
    1010import java.math.MathContext;
    1111import java.util.Collection;
     12import java.util.HashSet;
    1213import java.util.LinkedList;
    1314import java.util.List;
     15import java.util.Set;
    1416
    1517import javax.swing.JOptionPane;
     
    116118            // distance between two nodes.
    117119            if (nodes.size() > 0) {
    118                 if (nodes.size() == 1 && way.containsNode(nodes.get(0))) {
     120                if (nodes.size() == 1 && way.containsNode(nodes.get(0)) && allowRegularPolygon(way.getNodes())) {
    119121                    regular = true;
    120                 } else {
    121 
     122                } else if (nodes.size() >= 2) {
    122123                    center = nodes.get(way.containsNode(nodes.get(0)) ? 1 : 0).getEastNorth();
    123124                    if (nodes.size() == 2) {
     
    125126                    }
    126127                }
    127                 nodes = new LinkedList<Node>();
     128                nodes.clear();
    128129            }
    129130
     
    239240        setEnabled(selection != null && !selection.isEmpty());
    240241    }
     242   
     243    /**
     244     * Determines if a regular polygon is allowed to be created with the given nodes collection.
     245     * @param nodes The nodes collection to check.
     246     * @return true if all nodes in the given collection are referred by the same object, and no other one (see #8431)
     247     */
     248    protected boolean allowRegularPolygon(Collection<Node> nodes) {
     249        Set<OsmPrimitive> allReferrers = new HashSet<OsmPrimitive>();
     250        for (Node n : nodes) {
     251            List<OsmPrimitive> referrers = n.getReferrers();
     252            if (referrers.size() > 1 || (allReferrers.addAll(referrers) && allReferrers.size() > 1)) {
     253                return false;
     254            }
     255        }
     256        return true;
     257    }
    241258}
Note: See TracChangeset for help on using the changeset viewer.