Changeset 28335 in osm for applications/editors/josm/plugins
- Timestamp:
- 2012-04-22T13:41:29+02:00 (13 years ago)
- Location:
- applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/replacegeometry
- Files:
-
- 2 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/replacegeometry/ReplaceGeometryAction.java
r28028 r28335 46 46 47 47 try { 48 ReplaceGeometryUtils.replaceWithNew(firstObject, secondObject); 48 ReplaceGeometryCommand replaceCommand = 49 ReplaceGeometryUtils.buildReplaceWithNewCommand(firstObject, secondObject); 50 51 // action was canceled 52 if (replaceCommand == null) 53 return; 54 55 Main.main.undoRedo.add(replaceCommand); 49 56 } catch (IllegalArgumentException ex) { 50 57 JOptionPane.showMessageDialog(Main.parent, 51 58 ex.getMessage(), TITLE, JOptionPane.INFORMATION_MESSAGE); 59 } catch (ReplaceGeometryException ex) { 60 JOptionPane.showMessageDialog(Main.parent, 61 ex.getMessage(), TITLE, JOptionPane.INFORMATION_MESSAGE); 52 62 } 53 54 63 } 55 64 -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/replacegeometry/ReplaceGeometryUtils.java
r28298 r28335 21 21 public final class ReplaceGeometryUtils { 22 22 private static final String TITLE = tr("Replace Geometry"); 23 24 23 /** 25 24 * Replace new or uploaded object with new object … … 29 28 * @return 30 29 */ 31 public static boolean replaceWithNew(OsmPrimitive firstObject, OsmPrimitive secondObject) {30 public static ReplaceGeometryCommand buildReplaceWithNewCommand(OsmPrimitive firstObject, OsmPrimitive secondObject) { 32 31 if (firstObject instanceof Node && secondObject instanceof Node) { 33 return replaceNodeWithNew((Node) firstObject, (Node) secondObject);32 return buildReplaceNodeWithNewCommand((Node) firstObject, (Node) secondObject); 34 33 } else if (firstObject instanceof Way && secondObject instanceof Way) { 35 return replaceWayWithNew(Arrays.asList((Way) firstObject, (Way) secondObject));34 return buildReplaceWayWithNewCommand(Arrays.asList((Way) firstObject, (Way) secondObject)); 36 35 } else if (firstObject instanceof Node) { 37 return upgradeNode((Node) firstObject, secondObject);36 return createUpgradeNodeCommand((Node) firstObject, secondObject); 38 37 } else if (secondObject instanceof Node) { 39 return upgradeNode((Node) secondObject, firstObject);38 return createUpgradeNodeCommand((Node) secondObject, firstObject); 40 39 } else { 41 40 throw new IllegalArgumentException(tr("This tool can only replace a node, upgrade a node to a way or a multipolygon, or replace a way with a way.")); … … 51 50 * @return 52 51 */ 53 public static boolean replace(OsmPrimitive subjectObject, OsmPrimitive referenceSubject) {52 public static ReplaceGeometryCommand buildReplaceCommand(OsmPrimitive subjectObject, OsmPrimitive referenceSubject) { 54 53 if (subjectObject instanceof Node && referenceSubject instanceof Node) { 55 return replaceNode((Node) subjectObject, (Node) referenceSubject);54 return buildReplaceNodeCommand((Node) subjectObject, (Node) referenceSubject); 56 55 } else if (subjectObject instanceof Way && referenceSubject instanceof Way) { 57 return replaceWay((Way) subjectObject, (Way) referenceSubject);56 return buildReplaceWayCommand((Way) subjectObject, (Way) referenceSubject); 58 57 } else if (subjectObject instanceof Node) { 59 return upgradeNode((Node) subjectObject, referenceSubject);58 return createUpgradeNodeCommand((Node) subjectObject, referenceSubject); 60 59 } else if (referenceSubject instanceof Node) { 61 60 // TODO: fix this illogical reversal? 62 return upgradeNode((Node) referenceSubject, subjectObject);61 return createUpgradeNodeCommand((Node) referenceSubject, subjectObject); 63 62 } else { 64 63 throw new IllegalArgumentException(tr("This tool can only replace a node, upgrade a node to a way or a multipolygon, or replace a way with a way.")); … … 72 71 * @return 73 72 */ 74 public static boolean replaceNodeWithNew(Node firstNode, Node secondNode) {73 public static ReplaceGeometryCommand buildReplaceNodeWithNewCommand(Node firstNode, Node secondNode) { 75 74 if (firstNode.isNew() && !secondNode.isNew()) 76 return replaceNode(secondNode, firstNode);75 return buildReplaceNodeCommand(secondNode, firstNode); 77 76 else if (!firstNode.isNew() && secondNode.isNew()) 78 return replaceNode(firstNode, secondNode);77 return buildReplaceNodeCommand(firstNode, secondNode); 79 78 else 80 79 // both nodes are new OR uploaded, act like MergeNodes, moving first 81 80 // node to second 82 return replaceNode(firstNode, secondNode);81 return buildReplaceNodeCommand(firstNode, secondNode); 83 82 } 84 83 … … 90 89 * @return 91 90 */ 92 public static boolean replaceNode(Node subjectNode, Node referenceNode) {91 public static ReplaceGeometryCommand buildReplaceNodeCommand(Node subjectNode, Node referenceNode) { 93 92 if (!OsmPrimitive.getFilteredList(subjectNode.getReferrers(), Way.class).isEmpty()) { 94 JOptionPane.showMessageDialog(Main.parent, tr("Node belongs to way(s), cannot replace."), 95 TITLE, JOptionPane.INFORMATION_MESSAGE); 96 return false; 93 throw new ReplaceGeometryException(tr("Node belongs to way(s), cannot replace.")); 97 94 } 98 95 // FIXME: handle different layers … … 100 97 commands.add(MergeNodesAction.mergeNodes(Main.main.getEditLayer(), Arrays.asList(subjectNode, referenceNode), referenceNode)); 101 98 102 Main.main.undoRedo.add(new SequenceCommand(99 return new ReplaceGeometryCommand( 103 100 tr("Replace geometry for node {0}", subjectNode.getDisplayName(DefaultNameFormatter.getInstance())), 104 commands)); 105 return true; 101 commands); 106 102 } 107 103 … … 112 108 * @param referenceObject object with greater spatial quality 113 109 */ 114 public static boolean upgradeNode(Node subjectNode, OsmPrimitive referenceObject) {110 public static ReplaceGeometryCommand createUpgradeNodeCommand(Node subjectNode, OsmPrimitive referenceObject) { 115 111 if (!OsmPrimitive.getFilteredList(subjectNode.getReferrers(), Way.class).isEmpty()) { 116 JOptionPane.showMessageDialog(Main.parent, tr("Node belongs to way(s), cannot replace."), 117 TITLE, JOptionPane.INFORMATION_MESSAGE); 118 return false; 112 throw new ReplaceGeometryException(tr("Node belongs to way(s), cannot replace.")); 119 113 } 120 114 121 115 if (referenceObject instanceof Relation && !((Relation) referenceObject).isMultipolygon()) { 122 JOptionPane.showMessageDialog(Main.parent, tr("Relation is not a multipolygon, cannot be used as a replacement."), 123 TITLE, JOptionPane.INFORMATION_MESSAGE); 124 return false; 116 throw new ReplaceGeometryException(tr("Relation is not a multipolygon, cannot be used as a replacement.")); 125 117 } 126 118 … … 154 146 if (tagResolutionCommands == null) { 155 147 // user canceled tag merge dialog 156 return false;148 return null; 157 149 } 158 150 commands.addAll(tagResolutionCommands); … … 187 179 Main.main.getCurrentDataSet().setSelected(referenceObject); 188 180 189 Main.main.undoRedo.add(new SequenceCommand(181 return new ReplaceGeometryCommand( 190 182 tr("Replace geometry for node {0}", subjectNode.getDisplayName(DefaultNameFormatter.getInstance())), 191 commands)); 192 return true; 193 } 194 195 public static boolean replaceWayWithNew(List<Way> selection) { 183 commands); 184 } 185 186 public static ReplaceGeometryCommand buildReplaceWayWithNewCommand(List<Way> selection) { 196 187 // determine which way will be replaced and which will provide the geometry 197 188 boolean overrideNewCheck = false; … … 217 208 218 209 if( !overrideNewCheck && (subjectWay.isNew() || !referenceWay.isNew()) ) { 219 JOptionPane.showMessageDialog(Main.parent, 220 tr("Please select one way that exists in the database and one new way with correct geometry."), 221 TITLE, JOptionPane.WARNING_MESSAGE); 222 return false; 223 } 224 return replaceWay(subjectWay, referenceWay); 225 } 226 227 public static boolean replaceWay(Way subjectWay, Way referenceWay) { 210 throw new ReplaceGeometryException( 211 tr("Please select one way that exists in the database and one new way with correct geometry.")); 212 } 213 return buildReplaceWayCommand(subjectWay, referenceWay); 214 } 215 216 public static ReplaceGeometryCommand buildReplaceWayCommand(Way subjectWay, Way referenceWay) { 228 217 229 218 Area a = Main.main.getCurrentDataSet().getDataSourceArea(); 230 219 if (!isInArea(subjectWay, a) || !isInArea(referenceWay, a)) { 231 JOptionPane.showMessageDialog(Main.parent, 232 tr("The ways must be entirely within the downloaded area."), 233 TITLE, JOptionPane.WARNING_MESSAGE); 234 return false; 220 throw new ReplaceGeometryException(tr("The ways must be entirely within the downloaded area.")); 235 221 } 236 222 237 223 if (hasImportantNode(referenceWay, subjectWay)) { 238 JOptionPane.showMessageDialog(Main.parent, 239 tr("The way to be replaced cannot have any nodes with properties or relation memberships unless they belong to both ways."), 240 TITLE, JOptionPane.WARNING_MESSAGE); 241 return false; 224 throw new ReplaceGeometryException( 225 tr("The way to be replaced cannot have any nodes with properties or relation memberships unless they belong to both ways.")); 242 226 } 243 227 … … 248 232 if (tagResolutionCommands == null) { 249 233 // user canceled tag merge dialog 250 return false;234 return null; 251 235 } 252 236 commands.addAll(tagResolutionCommands); … … 357 341 358 342 // Two items in undo stack: change original way and delete geometry way 359 Main.main.undoRedo.add(new SequenceCommand(343 return new ReplaceGeometryCommand( 360 344 tr("Replace geometry for way {0}", subjectWay.getDisplayName(DefaultNameFormatter.getInstance())), 361 commands)); 362 return true; 345 commands); 363 346 } 364 347
Note:
See TracChangeset
for help on using the changeset viewer.