Changeset 19892 in osm for applications/editors/josm/plugins/tracer
- Timestamp:
- 2010-02-06T18:17:56+01:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/tracer/src/org/openstreetmap/josm/plugins/tracer/TracerAction.java
r19881 r19892 24 24 import org.openstreetmap.josm.command.Command; 25 25 import org.openstreetmap.josm.command.DeleteCommand; 26 import org.openstreetmap.josm.command.MoveCommand; 26 27 import org.openstreetmap.josm.command.SequenceCommand; 27 28 import org.openstreetmap.josm.data.coor.LatLon; … … 47 48 protected TracerServer server = new TracerServer(); 48 49 50 final double MIN_DISTANCE = 0.000015; //Minimal distance, when nodes are merged 51 final double MIN_DISTANCE_TW = 0.000015; //Minimal distance, when node is connected to other way 52 final double MIN_DISTANCE_SQ = 0.000015; //Minimal distance, when other node is connected this way 53 final double MAX_ANGLE = 30; //Minimal angle, when other node is connected this way 54 49 55 public TracerAction(MapFrame mapFrame) { 50 56 super(tr("Tracer"), "tracer-sml", tr("Tracer."), Shortcut.registerShortcut("tools:tracer", tr("Tool: {0}", tr("Tracer")), KeyEvent.VK_T, Shortcut.GROUP_EDIT), mapFrame, getCursor()); … … 123 129 */ 124 130 private Command connectObjects(Way way) { 125 final double MIN_DISTANCE = 0.000015;126 131 127 132 List<Command> cmds = new LinkedList<Command>(); 128 133 Way newWay = new Way(way); 129 for (Node n : way.getNodes()) { 134 for (int i = 0; i < way.getNodesCount() - 1; i++) { 135 Node n = way.getNode(i); 136 //System.out.println("-------"); 137 //System.out.println("Node: " + n); 130 138 LatLon ll = n.getCoor(); 131 139 BBox bbox = new BBox( … … 151 159 152 160 //System.out.println("Nearest: " + nearestNode); 153 //System.out.println("-------");154 161 if (nearestNode == null) { 155 162 cmds.addAll(tryConnectNodeToAnyWay(n)); 156 163 } else { 157 cmds.add(mergeNodes(nearestNode, n, newWay)); 158 } 159 } 160 newWay = trySplitWayByAnyNodes(way); 161 162 cmds.add(new ChangeCommand(way, newWay)); 164 cmds.addAll(mergeNodes(n, nearestNode, newWay)); 165 } 166 } 167 168 cmds.add(new ChangeCommand(way, trySplitWayByAnyNodes(newWay))); 163 169 164 170 Command cmd = new SequenceCommand(tr("Merge objects nodes"), cmds); … … 171 177 * @param n2 Second node 172 178 * @param way Way containing first node 173 * @return Command179 * @return List of Commands. 174 180 */ 175 private Command mergeNodes(Node n1, Node n2, Way way){ 176 n2.setCoor(n1.getCoor().getCenter(n2.getCoor())); 181 private List<Command> mergeNodes(Node n1, Node n2, Way way){ 182 List<Command> cmds = new LinkedList<Command>(); 183 cmds.add(new MoveCommand(n2, 184 (n1.getEastNorth().getX() - n2.getEastNorth().getX())/2, 185 (n1.getEastNorth().getY() - n2.getEastNorth().getY())/2 186 )); 187 177 188 int j = way.getNodes().indexOf(n1); 178 189 way.addNode(j, n2); … … 182 193 } 183 194 way.removeNode(n1); 184 return new DeleteCommand(n1); 195 196 cmds.add(new DeleteCommand(n1)); 197 return cmds; 185 198 } 186 199 187 200 /** 188 * Try connect node "node" from way "way"to way of other building.201 * Try connect node "node" to way of other building. 189 202 * 190 203 * Zkusi zjistit, zda node neni tak blizko nejake usecky existujici budovy, … … 199 212 throws IllegalStateException, IndexOutOfBoundsException { 200 213 201 final double MIN_DISTANCE = 0.000015;202 214 List<Command> cmds = new LinkedList<Command>(); 203 215 204 216 LatLon ll = node.getCoor(); 205 217 BBox bbox = new BBox( 206 ll.getX() - MIN_DISTANCE ,207 ll.getY() - MIN_DISTANCE ,208 ll.getX() + MIN_DISTANCE ,209 ll.getY() + MIN_DISTANCE );218 ll.getX() - MIN_DISTANCE_TW, 219 ll.getY() - MIN_DISTANCE_TW, 220 ll.getX() + MIN_DISTANCE_TW, 221 ll.getY() + MIN_DISTANCE_TW); 210 222 211 223 // node nebyl slouceny s jinym … … 228 240 } 229 241 } 230 //System.out.println("Nearest way: " + nearestWay);231 if (minDist < MIN_DISTANCE ) {242 //System.out.println("Nearest way: " + nearestWay + " distance: " + minDist); 243 if (minDist < MIN_DISTANCE_TW) { 232 244 Way newNWay = new Way(nearestWay); 233 245 newNWay.addNode(nearestNodeIndex + 1, node); 234 246 //System.out.println("New way:" + newNWay); 235 cmds.add(new ChangeCommand(nearestWay, newNWay)); 247 Command c = new ChangeCommand(nearestWay, newNWay); 248 c.executeCommand(); 249 cmds.add(c); 236 250 } 237 251 return cmds; … … 260 274 LatLon n2 = way.getNodes().get((i + 1) % way.getNodesCount()).getCoor(); 261 275 //System.out.println(way.getNodes().get(i) + "-----" + way.getNodes().get((i + 1) % way.getNodesCount())); 262 double minDistanceSq = 0.000015;263 double maxAngle = 15;276 double minDistanceSq = MIN_DISTANCE_SQ; 277 double maxAngle = MAX_ANGLE; 264 278 List<Node> nodes = Main.main.getCurrentDataSet().searchNodes(new BBox( 265 279 Math.min(n1.getX(), n2.getX()) - minDistanceSq, … … 276 290 double dist = TracerGeometry.distanceFromSegment(nn, n1, n2); 277 291 double angle = TracerGeometry.angleOfLines(n1, nn, nn, n2); 292 //System.out.println("Angle: " + angle + " distance: " + dist + " Node: " + nod); 278 293 if (!n1.equalsEpsilon(nn) && !n2.equalsEpsilon(nn) && dist < minDistanceSq && Math.abs(angle) < maxAngle) { 279 294 maxAngle = angle; … … 297 312 298 313 private void tagBuilding(Way way) { 299 if( alt) way.put("building", "yes");314 if(!alt) way.put("building", "yes"); 300 315 way.put("source", "cuzk:km"); 301 316 } … … 388 403 } 389 404 } 405
Note:
See TracChangeset
for help on using the changeset viewer.