Ignore:
Timestamp:
2016-03-05T10:22:33+01:00 (8 years ago)
Author:
simon04
Message:

see #6401 - Orthogonalize objects based on selected nodes

This is done by assembling a virtual way from the selected nodes. This is sensitive to the selection order.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/OrthogonalizeAction.java

    r9923 r9925  
    180180                nodeList.add((Node) p);
    181181            } else if (p instanceof Way) {
    182                 wayDataList.add(new WayData((Way) p));
    183             } else
     182                wayDataList.add(new WayData(((Way) p).getNodes()));
     183            } else {
    184184                throw new InvalidUserInputException(tr("Selection must consist only of ways and nodes."));
    185         }
    186         if (wayDataList.isEmpty()) {
     185            }
     186        }
     187        if (wayDataList.isEmpty() && !nodeList.isEmpty()) {
     188            final WayData data = new WayData(nodeList);
     189            final Collection<Command> commands = orthogonalize(Collections.singletonList(data), Collections.<Node>emptyList());
     190            return new SequenceCommand(tr("Orthogonalize"), commands);
     191        } else if (wayDataList.isEmpty()) {
    187192            throw new InvalidUserInputException("usage");
    188193        } else  {
     
    235240            WayData candidate = remaining.get(i);
    236241            if (candidate == null) continue;
    237             if (!Collections.disjoint(candidate.way.getNodes(), newGroupMember.way.getNodes())) {
     242            if (!Collections.disjoint(candidate.wayNodes, newGroupMember.wayNodes)) {
    238243                remaining.set(i, null);
    239244                extendGroupRec(group, candidate, remaining);
     
    300305        final Set<Node> allNodes = new HashSet<>();
    301306        for (WayData w : wayDataList) {
    302             for (Node n : w.way.getNodes()) {
     307            for (Node n : w.wayNodes) {
    303308                allNodes.add(n);
    304309            }
     
    345350                    for (WayData w : wayDataList) {
    346351                        for (int i = 0; i < w.nSeg; ++i) {
    347                             Node n1 = w.way.getNodes().get(i);
    348                             Node n2 = w.way.getNodes().get(i+1);
     352                            Node n1 = w.wayNodes.get(i);
     353                            Node n2 = w.wayNodes.get(i+1);
    349354                            if (Arrays.asList(orientation).contains(w.segDirections[i])) {
    350355                                if (cs.contains(n1) && !cs.contains(n2)) {
     
    417422     */
    418423    private static class WayData {
    419         public final Way way;             // The assigned way
     424        public final List<Node> wayNodes;             // The assigned way
    420425        public final int nSeg;            // Number of Segments of the Way
    421426        public final int nNode;           // Number of Nodes of the Way
     
    426431        public double heading;            // heading of segSum == approximate heading of the way
    427432
    428         WayData(Way pWay) {
    429             way = pWay;
    430             nNode = way.getNodes().size();
    431             nSeg = nNode - 1;
     433        WayData(List<Node> wayNodes) {
     434            this.wayNodes = wayNodes;
     435            this.nNode = wayNodes.size();
     436            this.nSeg = nNode - 1;
    432437        }
    433438
     
    441446         */
    442447        public void calcDirections(Direction pInitialDirection) throws InvalidUserInputException {
    443             final EastNorth[] en = new EastNorth[nNode]; // alias: way.getNodes().get(i).getEastNorth() ---> en[i]
     448            final EastNorth[] en = new EastNorth[nNode]; // alias: wayNodes.get(i).getEastNorth() ---> en[i]
    444449            for (int i = 0; i < nNode; i++) {
    445                 en[i] = new EastNorth(way.getNodes().get(i).getEastNorth().east(), way.getNodes().get(i).getEastNorth().north());
     450                en[i] = wayNodes.get(i).getEastNorth();
    446451            }
    447452            segDirections = new Direction[nSeg];
Note: See TracChangeset for help on using the changeset viewer.