Changeset 33297 in osm for applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap
- Timestamp:
- 2017-05-08T21:51:44+02:00 (8 years ago)
- Location:
- applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/SelectBoundaryAction.java
r32410 r33297 17 17 import org.openstreetmap.josm.actions.JosmAction; 18 18 import org.openstreetmap.josm.actions.SelectByInternalPointAction; 19 import org.openstreetmap.josm.data.osm.DataSet; 19 20 import org.openstreetmap.josm.data.osm.Node; 20 21 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 39 40 @Override 40 41 public void actionPerformed(ActionEvent e) { 41 Set<Way> selectedWays = OsmPrimitive.getFilteredSet(getLayerManager().getEditDataSet().getSelected(), Way.class); 42 Set<Node> selectedNodes = OsmPrimitive.getFilteredSet(getLayerManager().getEditDataSet().getSelected(), Node.class); 42 DataSet ds = getLayerManager().getEditDataSet(); 43 if (ds != null) { 44 Collection<Way> selectedWays = ds.getSelectedWays(); 45 Collection<Node> selectedNodes = ds.getSelectedNodes(); 43 46 44 Set<Way> newWays = new HashSet<>();47 Set<Way> newWays = new HashSet<>(); 45 48 46 Way w = null;49 Way w = null; 47 50 48 if (selectedWays.isEmpty()) { 49 if (selectedNodes.size() == 1) { 50 for (OsmPrimitive p : selectedNodes.iterator().next().getReferrers()) { 51 if (p instanceof Way && p.isSelectable()) { 52 w = (Way) p; 53 break; 51 if (selectedWays.isEmpty()) { 52 if (selectedNodes.size() == 1) { 53 for (OsmPrimitive p : selectedNodes.iterator().next().getReferrers()) { 54 if (p instanceof Way && p.isSelectable()) { 55 w = (Way) p; 56 break; 57 } 54 58 } 59 } else { 60 Point p = Main.map.mapView.getMousePosition(); 61 SelectByInternalPointAction.performSelection(Main.map.mapView.getEastNorth(p.x, p.y), false, false); 62 return; 55 63 } 64 } else if (selectedWays.size() == 1) { 65 w = selectedWays.iterator().next(); 66 } else if (selectedWays.contains(lastUsedStartingWay)) { 67 w = lastUsedStartingWay; //repeated call for selected way 68 lastUsedLeft = !lastUsedLeft; 69 } 70 71 if (w == null) return; //no starting way found 72 if (!w.isSelectable()) return; 73 if (w.isClosed()) return; 74 if (w.getNodesCount() < 2) return; 75 76 newWays.add(w); 77 lastUsedStartingWay = w; 78 79 // try going left at each turn 80 if (!NodeWayUtils.addAreaBoundary(w, newWays, lastUsedLeft)) { 81 NodeWayUtils.addAreaBoundary(w, newWays, !lastUsedLeft); // try going right at each turn 82 } 83 84 if (!newWays.isEmpty()) { 85 ds.setSelected(newWays); 56 86 } else { 57 Point p = Main.map.mapView.getMousePosition(); 58 SelectByInternalPointAction.performSelection(Main.map.mapView.getEastNorth(p.x, p.y), false, false); 59 return; 87 new Notification(tr("Nothing found. Please select way that is a part of some polygon formed by connected ways")) 88 .setIcon(JOptionPane.WARNING_MESSAGE).show(); 60 89 } 61 } else if (selectedWays.size() == 1) {62 w = selectedWays.iterator().next();63 } else if (selectedWays.contains(lastUsedStartingWay)) {64 w = lastUsedStartingWay; //repeated call for selected way65 lastUsedLeft = !lastUsedLeft;66 }67 68 69 if (w == null) return; //no starting way found70 if (!w.isSelectable()) return;71 if (w.isClosed()) return;72 if (w.getNodesCount() < 2) return;73 74 newWays.add(w);75 lastUsedStartingWay = w;76 77 // try going left at each turn78 if (!NodeWayUtils.addAreaBoundary(w, newWays, lastUsedLeft)) {79 NodeWayUtils.addAreaBoundary(w, newWays, !lastUsedLeft); // try going right at each turn80 }81 82 if (!newWays.isEmpty()) {83 getLayerManager().getEditDataSet().setSelected(newWays);84 } else {85 new Notification(tr("Nothing found. Please select way that is a part of some polygon formed by connected ways"))86 .setIcon(JOptionPane.WARNING_MESSAGE).show();87 90 } 88 91 } … … 95 98 @Override 96 99 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 97 if (selection == null) { 98 return; 99 } 100 setEnabled(true); 100 setEnabled(selection != null && !selection.isEmpty()); 101 101 } 102 102 } -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/SelectModNodesAction.java
r32410 r33297 37 37 public void actionPerformed(ActionEvent e) { 38 38 DataSet ds = getLayerManager().getEditDataSet(); 39 Collection<OsmPrimitive> selection = ds.getSelected();40 Set<Node> selectedNodes = OsmPrimitive.getFilteredSet(selection, Node.class);41 ds.clearSelection(selectedNodes);42 Command cmd = null;39 if (ds != null) { 40 Collection<OsmPrimitive> selection = ds.getSelected(); 41 ds.clearSelection(OsmPrimitive.getFilteredSet(selection, Node.class)); 42 Command cmd = null; 43 43 44 if (Main.main.undoRedo.commands == null) return; 45 int num = Main.main.undoRedo.commands.size(); 46 if (num == 0) return; 47 int k = 0, idx; 48 if (selection != null && !selection.isEmpty() && selection.hashCode() == lastHash) { 49 // we are selecting next command in history if nothing is selected 50 idx = Main.main.undoRedo.commands.indexOf(lastCmd); 51 } else { 52 idx = num; 44 if (Main.main.undoRedo.commands == null) return; 45 int num = Main.main.undoRedo.commands.size(); 46 if (num == 0) return; 47 int k = 0, idx; 48 if (selection != null && !selection.isEmpty() && selection.hashCode() == lastHash) { 49 // we are selecting next command in history if nothing is selected 50 idx = Main.main.undoRedo.commands.indexOf(lastCmd); 51 } else { 52 idx = num; 53 } 54 55 Set<Node> nodes = new HashSet<>(10); 56 do { // select next history element 57 if (idx > 0) idx--; else idx = num-1; 58 cmd = Main.main.undoRedo.commands.get(idx); 59 Collection<? extends OsmPrimitive> pp = cmd.getParticipatingPrimitives(); 60 nodes.clear(); 61 for (OsmPrimitive p : pp) { // find all affected ways 62 if (p instanceof Node && !p.isDeleted()) nodes.add((Node) p); 63 } 64 if (!nodes.isEmpty()) { 65 ds.setSelected(nodes); 66 lastCmd = cmd; // remember last used command and last selection 67 lastHash = ds.getSelected().hashCode(); 68 return; 69 } 70 k++; 71 } while (k < num); // try to find previous command if this affects nothing 72 lastCmd = null; lastHash = 0; 53 73 } 54 55 Set<Node> nodes = new HashSet<>(10);56 do { // select next history element57 if (idx > 0) idx--; else idx = num-1;58 cmd = Main.main.undoRedo.commands.get(idx);59 Collection<? extends OsmPrimitive> pp = cmd.getParticipatingPrimitives();60 nodes.clear();61 for (OsmPrimitive p : pp) { // find all affected ways62 if (p instanceof Node && !p.isDeleted()) nodes.add((Node) p);63 }64 if (!nodes.isEmpty()) {65 ds.setSelected(nodes);66 lastCmd = cmd; // remember last used command and last selection67 lastHash = ds.getSelected().hashCode();68 return;69 }70 k++;71 //System.out.println("no nodes found, previous...");72 } while (k < num); // try to find previous command if this affects nothing73 lastCmd = null; lastHash = 0;74 74 } 75 75 76 76 @Override 77 77 protected void updateEnabledState() { 78 updateEnabledStateOnCurrentSelection(); 79 } 80 81 @Override 82 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 83 setEnabled(true); 78 setEnabled(getLayerManager().getEditDataSet() != null); 84 79 } 85 80 } -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/SelectModWaysAction.java
r32410 r33297 38 38 public void actionPerformed(ActionEvent e) { 39 39 DataSet ds = getLayerManager().getEditDataSet(); 40 Collection<OsmPrimitive> selection = ds.getSelected();41 Set<Node> selectedNodes = OsmPrimitive.getFilteredSet(selection, Node.class);42 ds.clearSelection(selectedNodes);43 Command cmd;40 if (ds != null) { 41 Collection<OsmPrimitive> selection = ds.getSelected(); 42 ds.clearSelection(OsmPrimitive.getFilteredSet(selection, Node.class)); 43 Command cmd; 44 44 45 if (Main.main.undoRedo.commands == null) return; 46 int num = Main.main.undoRedo.commands.size(); 47 if (num == 0) return; 48 int k = 0, idx; 49 if (selection != null && !selection.isEmpty() && selection.hashCode() == lastHash) { 50 // we are selecting next command in history if nothing is selected 51 idx = Main.main.undoRedo.commands.indexOf(lastCmd); 52 } else { 53 idx = num; 45 if (Main.main.undoRedo.commands == null) return; 46 int num = Main.main.undoRedo.commands.size(); 47 if (num == 0) return; 48 int k = 0, idx; 49 if (selection != null && !selection.isEmpty() && selection.hashCode() == lastHash) { 50 // we are selecting next command in history if nothing is selected 51 idx = Main.main.undoRedo.commands.indexOf(lastCmd); 52 } else { 53 idx = num; 54 } 55 56 Set<Way> ways = new HashSet<>(10); 57 do { // select next history element 58 if (idx > 0) idx--; else idx = num-1; 59 cmd = Main.main.undoRedo.commands.get(idx); 60 Collection<? extends OsmPrimitive> pp = cmd.getParticipatingPrimitives(); 61 ways.clear(); 62 for (OsmPrimitive p : pp) { // find all affected ways 63 if (p instanceof Way && !p.isDeleted()) ways.add((Way) p); 64 } 65 if (!ways.isEmpty() && !ds.getSelected().containsAll(ways)) { 66 ds.setSelected(ways); 67 lastCmd = cmd; // remember last used command and last selection 68 lastHash = ds.getSelected().hashCode(); 69 return; 70 } 71 k++; 72 } while (k < num); // try to find previous command if this affects nothing 73 lastCmd = null; 74 lastHash = 0; 54 75 } 55 56 Set<Way> ways = new HashSet<>(10);57 do { // select next history element58 if (idx > 0) idx--; else idx = num-1;59 cmd = Main.main.undoRedo.commands.get(idx);60 Collection<? extends OsmPrimitive> pp = cmd.getParticipatingPrimitives();61 ways.clear();62 for (OsmPrimitive p : pp) { // find all affected ways63 if (p instanceof Way && !p.isDeleted()) ways.add((Way) p);64 }65 if (!ways.isEmpty() && !ds.getSelected().containsAll(ways)) {66 ds.setSelected(ways);67 lastCmd = cmd; // remember last used command and last selection68 lastHash = ds.getSelected().hashCode();69 return;70 }71 k++;72 } while (k < num); // try to find previous command if this affects nothing73 lastCmd = null;74 lastHash = 0;75 76 } 76 77 77 78 @Override 78 79 protected void updateEnabledState() { 79 updateEnabledStateOnCurrentSelection(); 80 } 81 82 @Override 83 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 84 setEnabled(true); 80 setEnabled(getLayerManager().getEditDataSet() != null); 85 81 } 86 82 } -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/UndoSelectionAction.java
r32410 r33297 36 36 public void actionPerformed(ActionEvent e) { 37 37 DataSet ds = getLayerManager().getEditDataSet(); 38 LinkedList<Collection<? extends OsmPrimitive>> history = ds.getSelectionHistory(); 39 if (history == null || history.isEmpty()) return; // empty history 40 int num = history.size(); 38 if (ds != null) { 39 LinkedList<Collection<? extends OsmPrimitive>> history = ds.getSelectionHistory(); 40 if (history == null || history.isEmpty()) return; // empty history 41 int num = history.size(); 41 42 42 Collection<OsmPrimitive> selection = ds.getSelected();43 Collection<OsmPrimitive> selection = ds.getSelected(); 43 44 44 if (selection != null && selection.hashCode() != myAutomaticSelectionHash) { 45 // manual selection or another pluging selection noticed 46 index = history.indexOf(lastSel); 47 // first is selected, next list is previous selection 45 if (selection != null && selection.hashCode() != myAutomaticSelectionHash) { 46 // manual selection or another pluging selection noticed 47 index = history.indexOf(lastSel); 48 // first is selected, next list is previous selection 49 } 50 int k = 0; 51 Set<OsmPrimitive> newsel = new HashSet<>(); 52 do { 53 if (index+1 < history.size()) index++; else index = 0; 54 Collection<? extends OsmPrimitive> histsel = history.get(index); 55 // remove deleted entities from selection 56 newsel.clear(); 57 newsel.addAll(histsel); 58 newsel.retainAll(ds.allNonDeletedPrimitives()); 59 if (!newsel.isEmpty()) break; 60 k++; 61 } while (k < num); 62 63 ds.setSelected(newsel); 64 lastSel = ds.getSelected(); 65 myAutomaticSelectionHash = lastSel.hashCode(); 66 // remember last automatic selection 48 67 } 49 int k = 0;50 Set<OsmPrimitive> newsel = new HashSet<>();51 do {52 if (index+1 < history.size()) index++; else index = 0;53 Collection<? extends OsmPrimitive> histsel = history.get(index);54 // remove deleted entities from selection55 newsel.clear();56 newsel.addAll(histsel);57 newsel.retainAll(ds.allNonDeletedPrimitives());58 if (newsel.size() > 0) break;59 k++;60 } while (k < num);61 62 ds.setSelected(newsel);63 lastSel = ds.getSelected();64 myAutomaticSelectionHash = lastSel.hashCode();65 // remeber last automatic selection66 68 } 67 69 68 70 @Override 69 71 protected void updateEnabledState() { 70 updateEnabledStateOnCurrentSelection(); 71 } 72 73 @Override 74 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 75 setEnabled(true); 72 setEnabled(getLayerManager().getEditDataSet() != null); 76 73 } 77 74 }
Note:
See TracChangeset
for help on using the changeset viewer.