Changeset 30753 in osm
- Timestamp:
- 2014-10-20T00:49:15+02:00 (10 years ago)
- Location:
- applications/editors/josm/plugins/michigan_left
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/michigan_left/.settings/org.eclipse.jdt.core.prefs
r30736 r30753 7 7 org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled 8 8 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 9 org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate 9 10 org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 11 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 10 12 org.eclipse.jdt.core.compiler.compliance=1.7 13 org.eclipse.jdt.core.compiler.debug.lineNumber=generate 14 org.eclipse.jdt.core.compiler.debug.localVariable=generate 15 org.eclipse.jdt.core.compiler.debug.sourceFile=generate 16 org.eclipse.jdt.core.compiler.doc.comment.support=enabled 11 17 org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning 12 18 org.eclipse.jdt.core.compiler.problem.assertIdentifier=error … … 32 38 org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=warning 33 39 org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore 40 org.eclipse.jdt.core.compiler.problem.invalidJavadoc=warning 41 org.eclipse.jdt.core.compiler.problem.invalidJavadocTags=enabled 42 org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsDeprecatedRef=disabled 43 org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsNotVisibleRef=disabled 44 org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsVisibility=public 34 45 org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore 35 46 org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning … … 38 49 org.eclipse.jdt.core.compiler.problem.missingEnumCaseDespiteDefault=disabled 39 50 org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=ignore 51 org.eclipse.jdt.core.compiler.problem.missingJavadocComments=warning 52 org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsOverriding=disabled 53 org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsVisibility=public 54 org.eclipse.jdt.core.compiler.problem.missingJavadocTagDescription=return_tag 55 org.eclipse.jdt.core.compiler.problem.missingJavadocTags=warning 56 org.eclipse.jdt.core.compiler.problem.missingJavadocTagsMethodTypeParameters=disabled 57 org.eclipse.jdt.core.compiler.problem.missingJavadocTagsOverriding=disabled 58 org.eclipse.jdt.core.compiler.problem.missingJavadocTagsVisibility=public 40 59 org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore 41 60 org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled 42 org.eclipse.jdt.core.compiler.problem.missingSerialVersion= warning61 org.eclipse.jdt.core.compiler.problem.missingSerialVersion=ignore 43 62 org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=ignore 44 63 org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning -
applications/editors/josm/plugins/michigan_left/README
r17647 r30753 2 2 ====== 3 3 4 P Lugin for easily creating turn restrictions at "Michigan left" intersections.4 Plugin for easily creating turn restrictions at "Michigan left" intersections. -
applications/editors/josm/plugins/michigan_left/src/MichiganLeft/MichiganLeft.java
r30737 r30753 1 //License: GPL 1 2 package MichiganLeft; 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 2 5 3 6 import java.awt.event.ActionEvent; 4 7 import java.awt.event.KeyEvent; 8 import java.util.ArrayList; 5 9 import java.util.Collection; 6 10 import java.util.Enumeration; 7 11 import java.util.Hashtable; 8 12 import java.util.LinkedList; 9 import java.util.ArrayList;10 13 11 14 import javax.swing.JMenuItem; 12 15 import javax.swing.JOptionPane; 13 14 import static org.openstreetmap.josm.tools.I18n.tr;15 16 16 17 import org.openstreetmap.josm.Main; … … 29 30 import org.openstreetmap.josm.tools.Shortcut; 30 31 32 /** 33 * Plugin for easily creating turn restrictions at "Michigan left" intersections. 34 */ 31 35 public class MichiganLeft extends Plugin { 32 JMenuItem MichiganLeft; 33 34 public MichiganLeft(PluginInformation info) { 35 super(info); 36 MichiganLeft = MainMenu.add(Main.main.menu.dataMenu, new MichiganLeftAction()); 37 } 38 39 private class MichiganLeftAction extends JosmAction { 36 JMenuItem MichiganLeft; 37 40 38 /** 41 * 42 */ 43 private static final long serialVersionUID = 1L; 44 private LinkedList<Command> cmds = new LinkedList<>(); 45 46 public MichiganLeftAction() { 47 super(tr("Michigan Left"), "michigan_left", 48 tr("Adds no left turn for sets of 4 or 5 ways."), 49 Shortcut.registerShortcut("tools:michigan_left", tr("Tool: {0}", 50 tr("Michigan Left")), KeyEvent.VK_N, Shortcut.ALT_SHIFT), true); 39 * Constructs a new {@code MichiganLeft} plugin. 40 * 41 * @param info plugin info 42 */ 43 public MichiganLeft(PluginInformation info) { 44 super(info); 45 MichiganLeft = MainMenu.add(Main.main.menu.dataMenu, new MichiganLeftAction()); 51 46 } 52 47 53 @Override 54 public void actionPerformed(ActionEvent e) { 55 Collection<OsmPrimitive> mainSelection = Main.main.getCurrentDataSet() 56 .getSelected(); 57 58 ArrayList<OsmPrimitive> selection = new ArrayList<>(); 59 60 for (OsmPrimitive prim: mainSelection) selection.add(prim); 61 62 int ways = 0; 63 for (OsmPrimitive prim : selection) { 64 if (prim instanceof Way) 65 ways++; 66 } 67 68 if ((ways != 4) && (ways != 5)) { 69 JOptionPane.showMessageDialog(Main.parent, 70 tr("Please select 4 or 5 ways to assign no left turns.")); 71 return; 72 } 73 74 if (ways == 4) { 75 // Find extremities of ways 76 Hashtable<Node, Integer> ExtremNodes = new Hashtable<>(); 77 for (OsmPrimitive prim : selection) { 78 if (prim instanceof Way) { 79 Way way = (Way) prim; 80 incrementHashtable(ExtremNodes, way.firstNode()); 81 incrementHashtable(ExtremNodes, way.lastNode()); 82 } 83 } 84 // System.out.println(tr("{0} extrem nodes.", ExtremNodes.size())); 85 if (ExtremNodes.size() != 4) { 86 JOptionPane.showMessageDialog(Main.parent, 87 tr("Please select 4 ways that form a closed relation.")); 88 return; 89 } 90 91 // order the ways 92 ArrayList<Way> orderedWays = new ArrayList<>(); 93 Way currentWay = (Way) selection.iterator().next(); 94 orderedWays.add((Way) currentWay); 95 selection.remove(currentWay); 96 while (selection.size() > 0) { 97 boolean found = false; 98 Node nextNode = currentWay.lastNode(); 99 for (OsmPrimitive prim : selection) { 100 Way tmpWay = (Way) prim; 101 if (tmpWay.firstNode() == nextNode) { 102 orderedWays.add(tmpWay); 103 selection.remove(prim); 104 currentWay = tmpWay; 105 found = true; 106 break; 107 } 108 } 109 if (!found) { 110 JOptionPane.showMessageDialog(Main.parent, 111 tr("Unable to order the ways. Please verify their directions")); 112 return; 113 } 114 } 115 116 // Build relations 117 for (int index = 0; index < 4; index++) { 118 Way firstWay = orderedWays.get(index); 119 Way lastWay = orderedWays.get((index + 1) % 4); 120 Node lastNode = firstWay.lastNode(); 121 122 buildRelation(firstWay, lastWay, lastNode); 123 } 124 Command c = new SequenceCommand( 125 tr("Create Michigan left turn restriction"), cmds); 126 Main.main.undoRedo.add(c); 127 cmds.clear(); 128 } 129 130 if (ways == 5) { 131 // Find extremities of ways 132 Hashtable<Node, Integer> ExtremNodes = new Hashtable<>(); 133 for (OsmPrimitive prim : selection) { 134 if (prim instanceof Way) { 135 Way way = (Way) prim; 136 incrementHashtable(ExtremNodes, way.firstNode()); 137 incrementHashtable(ExtremNodes, way.lastNode()); 138 } 139 } 140 // System.out.println(tr("{0} extrem nodes.", ExtremNodes.size())); 141 142 ArrayList<Node> viaNodes = new ArrayList<>(); 143 // find via nodes (they have 3 occurences in the list) 144 for (Enumeration<Node> enumKey = ExtremNodes.keys(); enumKey 145 .hasMoreElements();) { 146 Node extrem = enumKey.nextElement(); 147 Integer nb = (Integer) ExtremNodes.get(extrem); 148 // System.out.println(tr("Via node {0}, {1}", extrem.getId(), 149 // nb.intValue())); 150 if (nb.intValue() == 3) { 151 viaNodes.add(extrem); 152 } 153 } 154 // System.out.println(tr("{0} via nodes.", viaNodes.size())); 155 156 if (viaNodes.size() != 2) { 157 JOptionPane.showMessageDialog(Main.parent, 158 tr("Unable to find via nodes. Please check your selection")); 159 return; 160 } 161 162 Node viaFirst = viaNodes.get(0); 163 Node viaLast = viaNodes.get(1); // Find middle segment 164 165 Way middle = null; 166 for (OsmPrimitive prim : selection) { 167 if (prim instanceof Way) { 168 Way way = (Way) prim; 169 Node first = way.firstNode(); 170 Node last = way.lastNode(); 171 172 if ((first.equals(viaFirst) && last.equals(viaLast)) 173 || (first.equals(viaLast) && last.equals(viaFirst))) 174 middle = way; 175 } 176 } 177 // System.out.println(tr("Middle way: {0}", middle.getId())); 178 179 // Build relations 180 for (OsmPrimitive prim : selection) { 181 if (prim instanceof Way) { 182 Way way = (Way) prim; 183 if (way != middle) { 184 Node first = way.firstNode(); 185 Node last = way.lastNode(); 186 187 if (first == viaFirst) 188 buildRelation(middle, way, viaNodes.get(0)); 189 else if (first == viaLast) 190 buildRelation(middle, way, viaNodes.get(1)); 191 else if (last == viaFirst) 192 buildRelation(way, middle, viaNodes.get(0)); 193 else if (last == viaLast) 194 buildRelation(way, middle, viaNodes.get(1)); 195 } 196 } 197 } 198 Command c = new SequenceCommand( 199 tr("Create Michigan left turn restriction"), cmds); 200 Main.main.undoRedo.add(c); 201 cmds.clear(); 202 } 48 private class MichiganLeftAction extends JosmAction { 49 private LinkedList<Command> cmds = new LinkedList<>(); 50 51 public MichiganLeftAction() { 52 super(tr("Michigan Left"), "michigan_left", 53 tr("Adds no left turn for sets of 4 or 5 ways."), 54 Shortcut.registerShortcut("tools:michigan_left", 55 tr("Tool: {0}", tr("Michigan Left")), KeyEvent.VK_N, Shortcut.ALT_SHIFT), true); 56 } 57 58 @Override 59 public void actionPerformed(ActionEvent e) { 60 Collection<OsmPrimitive> mainSelection = Main.main.getCurrentDataSet().getSelected(); 61 62 ArrayList<OsmPrimitive> selection = new ArrayList<>(); 63 64 for (OsmPrimitive prim : mainSelection) 65 selection.add(prim); 66 67 int ways = 0; 68 for (OsmPrimitive prim : selection) { 69 if (prim instanceof Way) 70 ways++; 71 } 72 73 if ((ways != 4) && (ways != 5)) { 74 JOptionPane.showMessageDialog(Main.parent, 75 tr("Please select 4 or 5 ways to assign no left turns.")); 76 return; 77 } 78 79 if (ways == 4) { 80 // Find extremities of ways 81 Hashtable<Node, Integer> extremNodes = new Hashtable<>(); 82 for (OsmPrimitive prim : selection) { 83 if (prim instanceof Way) { 84 Way way = (Way) prim; 85 incrementHashtable(extremNodes, way.firstNode()); 86 incrementHashtable(extremNodes, way.lastNode()); 87 } 88 } 89 if (extremNodes.size() != 4) { 90 JOptionPane.showMessageDialog(Main.parent, 91 tr("Please select 4 ways that form a closed relation.")); 92 return; 93 } 94 95 // order the ways 96 ArrayList<Way> orderedWays = new ArrayList<>(); 97 Way currentWay = (Way) selection.iterator().next(); 98 orderedWays.add(currentWay); 99 selection.remove(currentWay); 100 while (selection.size() > 0) { 101 boolean found = false; 102 Node nextNode = currentWay.lastNode(); 103 for (OsmPrimitive prim : selection) { 104 Way tmpWay = (Way) prim; 105 if (tmpWay.firstNode() == nextNode) { 106 orderedWays.add(tmpWay); 107 selection.remove(prim); 108 currentWay = tmpWay; 109 found = true; 110 break; 111 } 112 } 113 if (!found) { 114 JOptionPane.showMessageDialog(Main.parent, 115 tr("Unable to order the ways. Please verify their directions")); 116 return; 117 } 118 } 119 120 // Build relations 121 for (int index = 0; index < 4; index++) { 122 Way firstWay = orderedWays.get(index); 123 Way lastWay = orderedWays.get((index + 1) % 4); 124 Node lastNode = firstWay.lastNode(); 125 126 buildRelation(firstWay, lastWay, lastNode); 127 } 128 Command c = new SequenceCommand(tr("Create Michigan left turn restriction"), cmds); 129 Main.main.undoRedo.add(c); 130 cmds.clear(); 131 } 132 133 if (ways == 5) { 134 // Find extremities of ways 135 Hashtable<Node, Integer> extremNodes = new Hashtable<>(); 136 for (OsmPrimitive prim : selection) { 137 if (prim instanceof Way) { 138 Way way = (Way) prim; 139 incrementHashtable(extremNodes, way.firstNode()); 140 incrementHashtable(extremNodes, way.lastNode()); 141 } 142 } 143 144 ArrayList<Node> viaNodes = new ArrayList<>(); 145 // find via nodes (they have 3 occurences in the list) 146 for (Enumeration<Node> enumKey = extremNodes.keys(); enumKey.hasMoreElements();) { 147 Node extrem = enumKey.nextElement(); 148 Integer nb = extremNodes.get(extrem); 149 if (nb.intValue() == 3) { 150 viaNodes.add(extrem); 151 } 152 } 153 154 if (viaNodes.size() != 2) { 155 JOptionPane.showMessageDialog(Main.parent, 156 tr("Unable to find via nodes. Please check your selection")); 157 return; 158 } 159 160 Node viaFirst = viaNodes.get(0); 161 Node viaLast = viaNodes.get(1); // Find middle segment 162 163 Way middle = null; 164 for (OsmPrimitive prim : selection) { 165 if (prim instanceof Way) { 166 Way way = (Way) prim; 167 Node first = way.firstNode(); 168 Node last = way.lastNode(); 169 170 if ((first.equals(viaFirst) && last.equals(viaLast)) 171 || (first.equals(viaLast) && last.equals(viaFirst))) 172 middle = way; 173 } 174 } 175 176 // Build relations 177 for (OsmPrimitive prim : selection) { 178 if (prim instanceof Way) { 179 Way way = (Way) prim; 180 if (way != middle) { 181 Node first = way.firstNode(); 182 Node last = way.lastNode(); 183 184 if (first == viaFirst) 185 buildRelation(middle, way, viaNodes.get(0)); 186 else if (first == viaLast) 187 buildRelation(middle, way, viaNodes.get(1)); 188 else if (last == viaFirst) 189 buildRelation(way, middle, viaNodes.get(0)); 190 else if (last == viaLast) 191 buildRelation(way, middle, viaNodes.get(1)); 192 } 193 } 194 } 195 Command c = new SequenceCommand(tr("Create Michigan left turn restriction"), cmds); 196 Main.main.undoRedo.add(c); 197 cmds.clear(); 198 } 199 } 200 201 public void incrementHashtable(Hashtable<Node, Integer> hash, Node node) { 202 if (hash.containsKey(node)) { 203 Integer nb = hash.get(node); 204 hash.put(node, new Integer(nb.intValue() + 1)); 205 } else { 206 hash.put(node, new Integer(1)); 207 } 208 } 209 210 public void buildRelation(Way fromWay, Way toWay, Node viaNode) { 211 Relation relation = new Relation(); 212 213 RelationMember from = new RelationMember("from", fromWay); 214 relation.addMember(from); 215 216 RelationMember to = new RelationMember("to", toWay); 217 relation.addMember(to); 218 219 RelationMember via = new RelationMember("via", viaNode); 220 relation.addMember(via); 221 222 relation.put("type", "restriction"); 223 relation.put("restriction", "no_left_turn"); 224 225 cmds.add(new AddCommand(relation)); 226 } 227 228 @Override 229 protected void updateEnabledState() { 230 setEnabled(getEditLayer() != null); 231 } 232 233 @Override 234 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 235 // do nothing 236 } 203 237 } 204 205 public void incrementHashtable(Hashtable<Node, Integer> hash, Node node) {206 // System.out.println(tr("Processing {0}", node.getId()));207 if (hash.containsKey(node)) {208 Integer nb = (Integer) hash.get(node);209 hash.put(node, new Integer(nb.intValue() + 1));210 // System.out.println(tr("Old value", nb.intValue()));211 } else212 hash.put(node, new Integer(1));213 }214 215 public void buildRelation(Way fromWay, Way toWay, Node viaNode) {216 // System.out.println(tr("Relation: from {0} to {1} via {2}",217 // fromWay.getId(), toWay.getId(), viaNode.getId()));218 219 Relation relation = new Relation();220 221 RelationMember from = new RelationMember("from", fromWay);222 relation.addMember(from);223 224 RelationMember to = new RelationMember("to", toWay);225 relation.addMember(to);226 227 RelationMember via = new RelationMember("via", viaNode);228 relation.addMember(via);229 230 relation.put("type", "restriction");231 relation.put("restriction", "no_left_turn");232 233 cmds.add(new AddCommand(relation));234 }235 236 @Override237 protected void updateEnabledState() {238 setEnabled(getEditLayer() != null);239 }240 241 @Override242 protected void updateEnabledState(243 Collection<? extends OsmPrimitive> selection) {244 // do nothing245 }246 247 }248 238 }
Note:
See TracChangeset
for help on using the changeset viewer.