Changeset 22758 in osm for applications/editors/josm/plugins/alignways/src
- Timestamp:
- 2010-08-24T17:26:10+02:00 (14 years ago)
- Location:
- applications/editors/josm/plugins/alignways/src/org/openstreetmap/josm/plugins/alignways
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/alignways/src/org/openstreetmap/josm/plugins/alignways/AlignWaysAction.java
r21619 r22758 56 56 if (!(c instanceof AlignWaysRotateCommand && 57 57 affectedNodes.equals(((AlignWaysRotateCommand) c).getRotatedNodes()))) { 58 Main.main.undoRedo.add(c = new AlignWaysRotateCommand()); 59 } 60 61 // Warn user if reference and alignee segment nodes are common: 62 // We cannot align two connected segment 63 if (((AlignWaysRotateCommand) c).areSegsConnected()) { 64 // Revert move 65 ((AlignWaysRotateCommand) c).undoCommand(); 66 JOptionPane.showMessageDialog(Main.parent, 67 tr("You cannot align connected segments.\n" 68 + "Please select two segments that don''t share any nodes."), 69 tr("AlignWayS message"), JOptionPane.WARNING_MESSAGE); 70 return; 71 } 72 73 for (Node n : affectedNodes) { 74 if (n.getCoor().isOutSideWorld()) { 75 // Revert move 76 ((AlignWaysRotateCommand) c).undoCommand(); 77 JOptionPane.showMessageDialog(Main.parent, 78 tr("Aligning would result nodes outside the world.\n" + 79 "Your action is being reverted."), 80 tr("AlignWayS message"), JOptionPane.WARNING_MESSAGE); 81 return; 58 c = new AlignWaysRotateCommand(); 59 if (actionValid((AlignWaysRotateCommand)c, affectedNodes)) { 60 Main.main.undoRedo.add(c); 82 61 } 83 84 62 } 85 63 … … 89 67 } 90 68 69 70 /** 71 * Validates the circumstances of the alignment (rotation) command to be executed. 72 * @param c Command to be verified. 73 * @param affectedNodes Nodes to be affected by the action. 74 * @return true if the aligning action can be done, false otherwise. 75 */ 76 private boolean actionValid(AlignWaysRotateCommand c, Collection<Node> affectedNodes) { 77 // Deny action if reference and alignee segment cannot be aligned 78 if (!c.areSegsAlignable()) { 79 JOptionPane.showMessageDialog(Main.parent, 80 tr("Please select two segments that don''t share any nodes or put the pivot on their common node.\n" + 81 "Your action is being igonred."), 82 tr("AlignWayS: Alignment not possible"), JOptionPane.WARNING_MESSAGE); 83 return false; 84 } 85 86 // Deny action if the nodes would end up outside world 87 for (Node n : affectedNodes) { 88 if (n.getCoor().isOutSideWorld()) { 89 // Revert move 90 (c).undoCommand(); 91 JOptionPane.showMessageDialog(Main.parent, 92 tr("Aligning would result nodes outside the world.\n" + 93 "Your action is being ignored."), 94 tr("AlignWayS: Alignment denied"), JOptionPane.WARNING_MESSAGE); 95 return false; 96 } 97 98 } 99 100 // Action valid 101 return true; 102 } 103 91 104 } -
applications/editors/josm/plugins/alignways/src/org/openstreetmap/josm/plugins/alignways/AlignWaysRotateCommand.java
r22050 r22758 81 81 this.nodes = algnSeg.getSegmentEndPoints(); 82 82 83 for (Node n : this.nodes) {84 OldState os = new OldState();85 os.latlon = new LatLon(n.getCoor());86 os.eastNorth = n.getEastNorth();87 os.ws = algnWS;88 os.modified = n.isModified();89 oldState.put(n, os);90 }91 oldWS.push(algnWS);92 93 83 EastNorth enRefNode1 = refWS.way.getNode(refWS.lowerIndex) 94 84 .getEastNorth(); … … 119 109 */ 120 110 121 rotateNodes(true);111 // rotateNodes(true); 122 112 123 113 } … … 130 120 */ 131 121 private void rotateNodes(boolean setModified) { 122 123 // "Backup" state 124 WaySegment algnWS = algnSeg.getSegment(); 125 for (Node n : this.nodes) { 126 OldState os = new OldState(); 127 os.latlon = new LatLon(n.getCoor()); 128 os.eastNorth = n.getEastNorth(); 129 os.ws = algnWS; 130 os.modified = n.isModified(); 131 oldState.put(n, os); 132 } 133 oldWS.push(algnWS); 134 135 // Rotate 132 136 for (Node n : nodes) { 133 137 double cosPhi = Math.cos(rotationAngle); … … 168 172 public JLabel getDescription() { 169 173 return new JLabel(tr("Align way segment"), ImageProvider.get( 170 174 "", "alignways"), SwingConstants.HORIZONTAL); 171 175 } 172 176 … … 216 220 } 217 221 218 public boolean areSegsConnected() { 222 /** Returns true if the two selected segments are alignable. 223 * They are not if they are connected *and* the pivot is not the connection node. 224 */ 225 public boolean areSegsAlignable() { 219 226 Collection<Node> algnNodes = nodes; 220 227 Collection<Node> refNodes = AlignWaysSegmentMgr.getInstance(Main.map.mapView) 221 228 .getRefSeg().getSegmentEndPoints(); 229 230 // First check if the pivot node of the alignee exists in the reference: 231 // in this case the pivot is the shared node and alignment is possible 232 for (Node nR : refNodes) { 233 if (nR.getEastNorth().equals(pivot)) 234 return true; 235 } 236 237 // Otherwise if the segments are connected, alignment is not possible 222 238 for (Node nA : algnNodes) { 223 239 for (Node nR : refNodes) { 224 240 if (nA.equals(nR)) 225 return true;241 return false; 226 242 } 227 243 } 228 244 229 return false;230 }231 245 // In all other cases alignment is possible 246 return true; 247 } 232 248 233 249 } -
applications/editors/josm/plugins/alignways/src/org/openstreetmap/josm/plugins/alignways/AlignWaysSelBothState.java
r21613 r22758 25 25 public void setHelpText() { 26 26 Main.map.statusLine 27 .setHelpText("Shift-A: Align segments; Alt-click: Clear selection"); 27 .setHelpText(AlignWaysPlugin.getAwAction().getShortcut().getKeyText() + 28 ": Align segments; Alt-click: Clear selection"); 28 29 } 29 30
Note:
See TracChangeset
for help on using the changeset viewer.