Ignore:
Timestamp:
2010-02-06T18:17:56+01:00 (14 years ago)
Author:
petrdlouhy
Message:

fixes and minor modifications
alt key not to add building tag

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/tracer/src/org/openstreetmap/josm/plugins/tracer/TracerAction.java

    r19881 r19892  
    2424import org.openstreetmap.josm.command.Command;
    2525import org.openstreetmap.josm.command.DeleteCommand;
     26import org.openstreetmap.josm.command.MoveCommand;
    2627import org.openstreetmap.josm.command.SequenceCommand;
    2728import org.openstreetmap.josm.data.coor.LatLon;
     
    4748    protected TracerServer server = new TracerServer();
    4849
     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
    4955    public TracerAction(MapFrame mapFrame) {
    5056        super(tr("Tracer"), "tracer-sml", tr("Tracer."), Shortcut.registerShortcut("tools:tracer", tr("Tool: {0}", tr("Tracer")), KeyEvent.VK_T, Shortcut.GROUP_EDIT), mapFrame, getCursor());
     
    123129     */
    124130    private Command connectObjects(Way way) {
    125         final double MIN_DISTANCE = 0.000015;
    126131
    127132        List<Command> cmds = new LinkedList<Command>();
    128133        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);
    130138            LatLon ll = n.getCoor();
    131139            BBox bbox = new BBox(
     
    151159
    152160            //System.out.println("Nearest: " + nearestNode);
    153             //System.out.println("-------");
    154161            if (nearestNode == null) {
    155162                cmds.addAll(tryConnectNodeToAnyWay(n));
    156163            } 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)));
    163169
    164170        Command cmd = new SequenceCommand(tr("Merge objects nodes"), cmds);
     
    171177     * @param n2 Second node
    172178     * @param way Way containing first node
    173      * @return Command
     179     * @return List of Commands.
    174180     */
    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
    177188        int j = way.getNodes().indexOf(n1);
    178189        way.addNode(j, n2);
     
    182193        }
    183194        way.removeNode(n1);
    184         return new DeleteCommand(n1);
     195
     196        cmds.add(new DeleteCommand(n1));
     197        return cmds;
    185198    }
    186199
    187200    /**
    188      * Try connect node "node" from way "way" to way of other building.
     201     * Try connect node "node" to way of other building.
    189202     *
    190203     * Zkusi zjistit, zda node neni tak blizko nejake usecky existujici budovy,
     
    199212            throws IllegalStateException, IndexOutOfBoundsException {
    200213       
    201         final double MIN_DISTANCE = 0.000015;
    202214        List<Command> cmds = new LinkedList<Command>();
    203215
    204216        LatLon ll = node.getCoor();
    205217        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);
    210222
    211223        // node nebyl slouceny s jinym
     
    228240            }
    229241        }
    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) {
    232244            Way newNWay = new Way(nearestWay);
    233245            newNWay.addNode(nearestNodeIndex + 1, node);
    234246            //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);
    236250        }
    237251        return cmds;
     
    260274            LatLon n2 = way.getNodes().get((i + 1) % way.getNodesCount()).getCoor();
    261275            //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;
    264278            List<Node> nodes = Main.main.getCurrentDataSet().searchNodes(new BBox(
    265279                Math.min(n1.getX(), n2.getX()) - minDistanceSq,
     
    276290                double dist = TracerGeometry.distanceFromSegment(nn, n1, n2);
    277291                double angle = TracerGeometry.angleOfLines(n1, nn, nn, n2);
     292                //System.out.println("Angle: " + angle + " distance: " + dist + " Node: " + nod);
    278293                if (!n1.equalsEpsilon(nn) && !n2.equalsEpsilon(nn) && dist < minDistanceSq && Math.abs(angle) < maxAngle) {
    279294                    maxAngle = angle;
     
    297312
    298313    private void tagBuilding(Way way) {
    299         if(alt) way.put("building", "yes");
     314        if(!alt) way.put("building", "yes");
    300315        way.put("source", "cuzk:km");
    301316    }
     
    388403    }
    389404}
     405
Note: See TracChangeset for help on using the changeset viewer.