Changeset 25751 in osm for applications/editors/josm/plugins/relcontext
- Timestamp:
- 2011-03-30T20:43:44+02:00 (14 years ago)
- Location:
- applications/editors/josm/plugins/relcontext/src/relcontext
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/relcontext/src/relcontext/ChosenRelation.java
r25748 r25751 63 63 */ 64 64 public boolean isMultipolygon() { 65 if( chosenRelation == null ) 65 return isMultipolygon(chosenRelation); 66 } 67 68 public static boolean isMultipolygon( Relation r ) { 69 if( r == null ) 66 70 return false; 67 String type = chosenRelation.get("type");71 String type = r.get("type"); 68 72 if( type == null ) 69 73 return false; -
applications/editors/josm/plugins/relcontext/src/relcontext/actions/AddRemoveMemberAction.java
r25717 r25751 9 9 import org.openstreetmap.josm.actions.JosmAction; 10 10 import org.openstreetmap.josm.command.ChangeCommand; 11 import org.openstreetmap.josm.command.Command; 11 12 import org.openstreetmap.josm.data.osm.Node; 12 13 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; … … 49 50 toAdd.removeAll(r.getMemberPrimitives()); 50 51 52 // 0. check if relation is broken (temporary) 53 boolean isBroken = !toAdd.isEmpty() && SortAndFixAction.needsFixing(r); 54 51 55 // 1. remove all present members 52 56 r.removeMembersFor(getCurrentDataSet().getSelected()); … … 60 64 r.addMember(pos, new RelationMember("", p)); 61 65 } 66 67 // 3. check for roles again (temporary) 68 Command roleFix = !isBroken && SortAndFixAction.needsFixing(r) ? SortAndFixAction.fixRelation(r) : null; 69 if( roleFix != null ) 70 roleFix.executeCommand(); 62 71 63 72 if( !r.getMemberPrimitives().equals(rel.get().getMemberPrimitives()) ) -
applications/editors/josm/plugins/relcontext/src/relcontext/actions/SortAndFixAction.java
r25698 r25751 8 8 import org.openstreetmap.josm.Main; 9 9 import org.openstreetmap.josm.command.ChangeCommand; 10 import org.openstreetmap.josm.command.Command; 10 11 import org.openstreetmap.josm.data.osm.*; 11 12 import org.openstreetmap.josm.tools.ImageProvider; … … 27 28 28 29 public void actionPerformed( ActionEvent e ) { 29 if( rel.get() == null ) return; 30 Relation r = rel.get(); 30 Command c = fixRelation(rel.get()); 31 if( c != null ) 32 Main.main.undoRedo.add(c); 33 } 34 35 public void chosenRelationChanged( Relation oldRelation, Relation newRelation ) { 36 setEnabled(newRelation != null && needsFixing( newRelation)); 37 } 38 39 public static boolean needsFixing( Relation rel ) { 40 return !isIncomplete(rel) && (areMultipolygonTagsEmpty(rel) || areBoundaryTagsNotRight(rel)); 41 } 42 43 public static Command fixRelation( Relation rel ) { 44 Relation r = rel; 31 45 boolean fixed = false; 32 46 // todo: sort members … … 44 58 } 45 59 46 if( fixed ) 47 Main.main.undoRedo.add(new ChangeCommand(rel.get(), r)); 60 return fixed ? new ChangeCommand(rel, r) : null; 48 61 } 49 62 50 public void chosenRelationChanged( Relation oldRelation, Relation newRelation ) { 51 setEnabled(newRelation != null && !isIncomplete(newRelation) && (areMultipolygonTagsEmpty() || areBoundaryTagsNotRight())); 52 } 53 54 protected boolean isIncomplete( Relation r ) { 63 protected static boolean isIncomplete( Relation r ) { 55 64 if( r == null || r.isIncomplete() || r.isDeleted() ) 56 65 return true; … … 64 73 * Check for ways that have roles different from "outer" and "inner". 65 74 */ 66 private boolean areMultipolygonTagsEmpty() { 67 Relation r = rel == null ? null : rel.get(); 68 if( r == null || r.getMembersCount() == 0 || !rel.isMultipolygon() ) 75 private static boolean areMultipolygonTagsEmpty( Relation r ) { 76 if( r == null || r.getMembersCount() == 0 || !ChosenRelation.isMultipolygon(r) ) 69 77 return false; 70 78 for( RelationMember m : r.getMembers() ) { … … 78 86 * Check for nodes and relations without needed roles. 79 87 */ 80 private boolean areBoundaryTagsNotRight() { 81 Relation r = rel == null ? null : rel.get(); 88 private static boolean areBoundaryTagsNotRight( Relation r ) { 82 89 if( r == null || r.getMembersCount() == 0 || !r.hasKey("type") || !r.get("type").equals("boundary") ) 83 90 return false; … … 94 101 * Basically, created multipolygon from scratch, and if successful, replace roles with new ones. 95 102 */ 96 private Relation fixMultipolygonRoles( Relation source ) {103 private static Relation fixMultipolygonRoles( Relation source ) { 97 104 Collection<Way> ways = new ArrayList<Way>(); 98 105 for( OsmPrimitive p : source.getMemberPrimitives() ) … … 131 138 } 132 139 133 private Relation fixBoundaryRoles( Relation source ) {140 private static Relation fixBoundaryRoles( Relation source ) { 134 141 Relation r = new Relation(source); 135 142 boolean fixed = false;
Note:
See TracChangeset
for help on using the changeset viewer.