diff --git a/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableModel.java b/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableModel.java
index 32cb5b4..3ba7711 100644
|
a
|
b
|
import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetType;
|
| 45 | 45 | import org.openstreetmap.josm.gui.tagging.presets.TaggingPresets; |
| 46 | 46 | import org.openstreetmap.josm.gui.util.GuiHelper; |
| 47 | 47 | import org.openstreetmap.josm.gui.widgets.OsmPrimitivesTableModel; |
| | 48 | import org.openstreetmap.josm.tools.bugreport.BugReport; |
| 48 | 49 | |
| 49 | 50 | public class MemberTableModel extends AbstractTableModel |
| 50 | 51 | implements TableModelListener, SelectionChangedListener, DataSetListener, OsmPrimitivesTableModel { |
| … |
… |
implements TableModelListener, SelectionChangedListener, DataSetListener, OsmPri
|
| 806 | 807 | } |
| 807 | 808 | |
| 808 | 809 | WayConnectionType getWayConnection(int i) { |
| 809 | | if (connectionType == null) { |
| 810 | | connectionType = wayConnectionTypeCalculator.updateLinks(members); |
| | 810 | try { |
| | 811 | if (connectionType == null) { |
| | 812 | connectionType = wayConnectionTypeCalculator.updateLinks(members); |
| | 813 | } |
| | 814 | return connectionType.get(i); |
| | 815 | } catch (RuntimeException e) { |
| | 816 | throw BugReport.intercept(e).put("i", i).put("members", members).put("relation", relation); |
| 811 | 817 | } |
| 812 | | return connectionType.get(i); |
| 813 | 818 | } |
| 814 | 819 | |
| 815 | 820 | @Override |
diff --git a/src/org/openstreetmap/josm/gui/dialogs/relation/sort/WayConnectionTypeCalculator.java b/src/org/openstreetmap/josm/gui/dialogs/relation/sort/WayConnectionTypeCalculator.java
index dfa048d..2ee416f 100644
|
a
|
b
|
import org.openstreetmap.josm.data.osm.Node;
|
| 12 | 12 | import org.openstreetmap.josm.data.osm.RelationMember; |
| 13 | 13 | import org.openstreetmap.josm.data.osm.Way; |
| 14 | 14 | import org.openstreetmap.josm.gui.dialogs.relation.sort.WayConnectionType.Direction; |
| | 15 | import org.openstreetmap.josm.tools.bugreport.BugReport; |
| 15 | 16 | |
| 16 | 17 | public class WayConnectionTypeCalculator { |
| 17 | 18 | |
| … |
… |
public class WayConnectionTypeCalculator {
|
| 40 | 41 | WayConnectionType lastWct = null; |
| 41 | 42 | |
| 42 | 43 | for (int i = 0; i < members.size(); ++i) { |
| 43 | | final RelationMember m = members.get(i); |
| 44 | | if (!m.isWay() || m.getWay() == null || m.getWay().isIncomplete()) { |
| | 44 | try { |
| | 45 | lastWct = updateLinksFor(con, lastWct, i); |
| | 46 | } catch (RuntimeException e) { |
| | 47 | int index = i; |
| | 48 | throw BugReport.intercept(e).put("i", i).put("member", () -> members.get(index)).put("con", con); |
| | 49 | } |
| | 50 | } |
| | 51 | makeLoopIfNeeded(con, members.size()-1); |
| | 52 | |
| | 53 | return con; |
| | 54 | } |
| | 55 | |
| | 56 | private WayConnectionType updateLinksFor(final List<WayConnectionType> con, WayConnectionType lastWct, int i) { |
| | 57 | final RelationMember m = members.get(i); |
| | 58 | if (isNoHandleableWay(m)) { |
| | 59 | if (i > 0) { |
| | 60 | makeLoopIfNeeded(con, i-1); |
| | 61 | } |
| | 62 | con.set(i, new WayConnectionType()); |
| | 63 | firstGroupIdx = i; |
| | 64 | } else { |
| | 65 | WayConnectionType wct = computeNextWayConnection(con, lastWct, i, m); |
| | 66 | |
| | 67 | if (!wct.linkPrev) { |
| 45 | 68 | if (i > 0) { |
| 46 | 69 | makeLoopIfNeeded(con, i-1); |
| 47 | 70 | } |
| 48 | | con.set(i, new WayConnectionType()); |
| 49 | 71 | firstGroupIdx = i; |
| 50 | | continue; |
| 51 | 72 | } |
| | 73 | lastWct = wct; |
| | 74 | } |
| | 75 | return lastWct; |
| | 76 | } |
| 52 | 77 | |
| 53 | | WayConnectionType wct = new WayConnectionType(false); |
| 54 | | wct.linkPrev = i > 0 && con.get(i-1) != null && con.get(i-1).isValid(); |
| 55 | | wct.direction = NONE; |
| | 78 | private boolean isNoHandleableWay(final RelationMember m) { |
| | 79 | return !m.isWay() || m.getWay() == null || m.getWay().isIncomplete(); |
| | 80 | } |
| 56 | 81 | |
| 57 | | if (RelationSortUtils.isOneway(m)) { |
| 58 | | if (lastWct != null && lastWct.isOnewayTail) { |
| 59 | | wct.isOnewayHead = true; |
| 60 | | } |
| 61 | | if (lastBackwardWay == UNCONNECTED && lastForwardWay == UNCONNECTED) { //Beginning of new oneway |
| 62 | | wct.isOnewayHead = true; |
| 63 | | lastForwardWay = i-1; |
| 64 | | lastBackwardWay = i-1; |
| 65 | | onewayBeginning = true; |
| 66 | | } |
| 67 | | } |
| | 82 | private WayConnectionType computeNextWayConnection(final List<WayConnectionType> con, WayConnectionType lastWct, int i, |
| | 83 | final RelationMember m) { |
| | 84 | WayConnectionType wct = new WayConnectionType(false); |
| | 85 | wct.linkPrev = i > 0 && con.get(i-1) != null && con.get(i-1).isValid(); |
| | 86 | wct.direction = NONE; |
| 68 | 87 | |
| 69 | | if (wct.linkPrev) { |
| 70 | | if (lastBackwardWay != UNCONNECTED && lastForwardWay != UNCONNECTED) { |
| 71 | | determineOnewayConnectionType(con, m, i, wct); |
| 72 | | if (!wct.linkPrev) { |
| 73 | | firstGroupIdx = i; |
| 74 | | } |
| 75 | | } |
| | 88 | if (RelationSortUtils.isOneway(m)) { |
| | 89 | handleOneway(lastWct, i, wct); |
| | 90 | } |
| 76 | 91 | |
| 77 | | if (!RelationSortUtils.isOneway(m) && lastWct != null) { |
| 78 | | wct.direction = determineDirection(i-1, lastWct.direction, i); |
| 79 | | wct.linkPrev = wct.direction != NONE; |
| | 92 | if (wct.linkPrev) { |
| | 93 | if (lastBackwardWay != UNCONNECTED && lastForwardWay != UNCONNECTED) { |
| | 94 | determineOnewayConnectionType(con, m, i, wct); |
| | 95 | if (!wct.linkPrev) { |
| | 96 | firstGroupIdx = i; |
| 80 | 97 | } |
| 81 | 98 | } |
| 82 | 99 | |
| 83 | | if (!wct.linkPrev) { |
| 84 | | wct.direction = determineDirectionOfFirst(i, m); |
| 85 | | if (RelationSortUtils.isOneway(m)) { |
| 86 | | wct.isOnewayLoopForwardPart = true; |
| 87 | | lastForwardWay = i; |
| 88 | | } |
| | 100 | if (!RelationSortUtils.isOneway(m) && lastWct != null) { |
| | 101 | wct.direction = determineDirection(i-1, lastWct.direction, i); |
| | 102 | wct.linkPrev = wct.direction != NONE; |
| 89 | 103 | } |
| | 104 | } |
| 90 | 105 | |
| 91 | | wct.linkNext = false; |
| 92 | | if (lastWct != null) { |
| 93 | | lastWct.linkNext = wct.linkPrev; |
| | 106 | if (!wct.linkPrev) { |
| | 107 | wct.direction = determineDirectionOfFirst(i, m); |
| | 108 | if (RelationSortUtils.isOneway(m)) { |
| | 109 | wct.isOnewayLoopForwardPart = true; |
| | 110 | lastForwardWay = i; |
| 94 | 111 | } |
| 95 | | con.set(i, wct); |
| 96 | | lastWct = wct; |
| | 112 | } |
| 97 | 113 | |
| 98 | | if (!wct.linkPrev) { |
| 99 | | if (i > 0) { |
| 100 | | makeLoopIfNeeded(con, i-1); |
| 101 | | } |
| 102 | | firstGroupIdx = i; |
| 103 | | } |
| | 114 | wct.linkNext = false; |
| | 115 | if (lastWct != null) { |
| | 116 | lastWct.linkNext = wct.linkPrev; |
| 104 | 117 | } |
| 105 | | makeLoopIfNeeded(con, members.size()-1); |
| | 118 | con.set(i, wct); |
| | 119 | return wct; |
| | 120 | } |
| 106 | 121 | |
| 107 | | return con; |
| | 122 | private void handleOneway(WayConnectionType lastWct, int i, WayConnectionType wct) { |
| | 123 | if (lastWct != null && lastWct.isOnewayTail) { |
| | 124 | wct.isOnewayHead = true; |
| | 125 | } |
| | 126 | if (lastBackwardWay == UNCONNECTED && lastForwardWay == UNCONNECTED) { //Beginning of new oneway |
| | 127 | wct.isOnewayHead = true; |
| | 128 | lastForwardWay = i-1; |
| | 129 | lastBackwardWay = i-1; |
| | 130 | onewayBeginning = true; |
| | 131 | } |
| 108 | 132 | } |
| 109 | 133 | |
| 110 | 134 | private int firstGroupIdx; |