Changeset 26832 in osm for applications/editors/josm/plugins/reltoolbox/src/relcontext
- Timestamp:
- 2011-10-11T21:03:06+02:00 (13 years ago)
- Location:
- applications/editors/josm/plugins/reltoolbox/src/relcontext/actions
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/reltoolbox/src/relcontext/actions/ReconstructPolygonAction.java
r26802 r26832 11 11 import relcontext.ChosenRelationListener; 12 12 13 public class DeleteChosenRelationAction extends AbstractAction implements ChosenRelationListener { 13 /** 14 * Make a single polygon out of the multipolygon relation. The relation must have only outer members. 15 * @author Zverik 16 */ 17 public class ReconstructPolygonAction extends AbstractAction implements ChosenRelationListener { 14 18 private ChosenRelation rel; 15 19 16 public DeleteChosenRelationAction( ChosenRelation rel ) {17 super(tr(" Delete relation"));20 public ReconstructPolygonAction( ChosenRelation rel ) { 21 super(tr("Reconstruct polygon")); 18 22 putValue(SMALL_ICON, ImageProvider.get("dialogs", "delete")); 23 putValue(LONG_DESCRIPTION, "Reconstruct polygon from multipolygon relation"); 19 24 this.rel = rel; 20 25 rel.addChosenRelationListener(this); … … 25 30 Relation r = rel.get(); 26 31 rel.clear(); 27 Main.main.undoRedo.add(new DeleteCommand(r));32 // Main.main.undoRedo.add(new DeleteCommand(r)); 28 33 } 29 34 30 35 public void chosenRelationChanged( Relation oldRelation, Relation newRelation ) { 31 setEnabled(newRelation != null); 36 setEnabled(newRelation != null); //todo 32 37 } 33 38 } -
applications/editors/josm/plugins/reltoolbox/src/relcontext/actions/TheRing.java
r26820 r26832 26 26 segments.add(new RingSegment(source)); 27 27 } 28 28 29 29 public void collide( TheRing other ) { 30 30 boolean collideNoted = false; … … 32 32 if( !segments.get(i).isReference() ) { 33 33 for( int j = 0; j < other.segments.size(); j++ ) { 34 // not colliding referencing nodes: they've already collided, and35 // there should be no more than two ways passing through two points.36 34 if( !other.segments.get(j).isReference() ) { 37 List<Node> intersectionNodes = new ArrayList<Node>(); 38 boolean colliding = false; 39 List<Node> nodes1 = segments.get(i).getNodes(); 40 List<Node> nodes2 = other.segments.get(j).getNodes(); 41 for( int ni = 0; ni < nodes2.size(); ni++ ) { 42 if( nodes1.contains(nodes2.get(ni)) != colliding ) { 43 intersectionNodes.add(nodes2.get(colliding ? ni - 1 : ni)); 44 colliding = !colliding; 35 RingSegment seg1 = segments.get(i); 36 RingSegment seg2 = other.segments.get(j); 37 boolean firstSegmentIsNotARing = !seg1.isRing() && segments.size() == 1; 38 if( !seg2.isRing() && other.segments.size() == 1 ) { 39 if( firstSegmentIsNotARing ) 40 break; // not doing two arcs collision 41 RingSegment tmp = seg1; 42 seg1 = seg2; 43 seg2 = tmp; 44 firstSegmentIsNotARing = true; 45 } 46 if( firstSegmentIsNotARing ) { 47 if( seg2.getNodes().contains(seg1.getNodes().get(0)) && seg2.getNodes().contains(seg1.getNodes().get(seg1.getNodes().size()-2))) { 48 // segment touches a ring 49 45 50 } 51 } else { 52 // both are segments from rings, find intersection 46 53 } 47 if( colliding ) 48 intersectionNodes.add(nodes2.get(nodes2.size() - 1)); 49 // when an intersection of two rings spans a ring's beginning 50 if( segments.get(i).isRing() && other.segments.get(j).isRing() && intersectionNodes.contains(nodes2.get(0)) && intersectionNodes.contains(nodes2.get(nodes2.size() - 1)) ) { 51 intersectionNodes.remove(0); 52 intersectionNodes.remove(intersectionNodes.size() - 1); 53 intersectionNodes.add(intersectionNodes.get(0)); 54 intersectionNodes.remove(0); 55 } 56 System.out.print("Intersection nodes for segments " + segments.get(i) + " and " + other.segments.get(j) + ": "); 57 for( Node inode : intersectionNodes ) 58 System.out.print(inode.getUniqueId() + ","); 59 System.out.println(); 60 // unclosed ways produce duplicate nodes 61 int ni = 1; 62 while( ni < intersectionNodes.size() ) { 63 if( intersectionNodes.get(ni - 1).equals(intersectionNodes.get(ni)) ) 64 intersectionNodes.remove(ni - 1); 65 else 66 ni++; 67 } 68 if( intersectionNodes.size() > 1 ) { 54 55 56 Node[] intersection = getFirstIntersection(segments.get(i), other.segments.get(j)); 57 if( intersection.length > 1 ) { 69 58 if( !collideNoted ) { 70 59 System.out.println("Rings for ways " + source.getUniqueId() + " and " + other.source.getUniqueId() + " collide."); … … 76 65 other.segments.size() == 1 && !other.segments.get(0).isRing() 77 66 }; 78 RingSegment segment = splitRingAt(i, intersection Nodes.get(0), intersectionNodes.get(1));79 RingSegment otherSegment = other.splitRingAt(j, intersection Nodes.get(0), intersectionNodes.get(1));67 RingSegment segment = splitRingAt(i, intersection[0], intersection[1]); 68 RingSegment otherSegment = other.splitRingAt(j, intersection[0], intersection[1]); 80 69 if( !isarc[0] && !isarc[1] ) { 81 70 if( segments.size() > 2 && other.segments.size() > 2 ) … … 124 113 } 125 114 } 115 if( segments.get(i).isReference() ) 116 break; 126 117 } 127 if( segments.get(i).isReference() ) 128 break; 129 } 130 } 118 } 119 } 120 } 121 122 private Node[] getFirstIntersection( RingSegment seg1, RingSegment seg2 ) { 123 List<Node> intersectionNodes = new ArrayList<Node>(); 124 boolean colliding = false; 125 List<Node> nodes1 = seg1.getNodes(); 126 List<Node> nodes2 = seg2.getNodes(); 127 for( int ni = 0; ni < nodes2.size(); ni++ ) { 128 if( nodes1.contains(nodes2.get(ni)) != colliding ) { 129 intersectionNodes.add(nodes2.get(colliding ? ni - 1 : ni)); 130 colliding = !colliding; 131 } 132 } 133 if( colliding ) 134 intersectionNodes.add(nodes2.get(nodes2.size() - 1)); 135 // when an intersection of two rings spans a ring's beginning 136 if( seg1.isRing() && seg2.isRing() && intersectionNodes.contains(nodes2.get(0)) && intersectionNodes.contains(nodes2.get(nodes2.size() - 1)) ) { 137 intersectionNodes.remove(0); 138 intersectionNodes.remove(intersectionNodes.size() - 1); 139 intersectionNodes.add(intersectionNodes.get(0)); 140 intersectionNodes.remove(0); 141 } 142 System.out.print("Intersection nodes for segments " + seg1 + " and " + seg2 + ": "); 143 for( Node inode : intersectionNodes ) 144 System.out.print(inode.getUniqueId() + ","); 145 System.out.println(); 146 // unclosed ways produce duplicate nodes 147 int ni = 1; 148 while( ni < intersectionNodes.size() ) { 149 if( intersectionNodes.get(ni - 1).equals(intersectionNodes.get(ni)) ) 150 intersectionNodes.remove(ni - 1); 151 else 152 ni++; 153 } 154 return intersectionNodes.toArray(new Node[2]); 131 155 } 132 156
Note:
See TracChangeset
for help on using the changeset viewer.