Changeset 29538 in osm for applications/editors
- Timestamp:
- 2013-04-26T01:46:15+02:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/undelete/src/org/openstreetmap/josm/plugins/undelete/UndeleteAction.java
r29474 r29538 47 47 Main.pref.put("undelete.newlayer", dialog.isNewLayerSelected()); 48 48 Main.pref.put("undelete.osmid", dialog.getOsmIdsString()); 49 undelete(dialog.isNewLayerSelected(), dialog.getOsmIds(), 0);49 undelete(dialog.isNewLayerSelected(), dialog.getOsmIds(), null); 50 50 } 51 51 … … 53 53 * // TODO: undelete relation members if necessary 54 54 */ 55 public void undelete(boolean newLayer, final List<PrimitiveId> ids, final long parent) { 55 public void undelete(boolean newLayer, final List<PrimitiveId> ids, final OsmPrimitive parent) { 56 57 Main.info("Undeleting "+ids+(parent==null?"":" with parent "+parent)); 58 56 59 OsmDataLayer tmpLayer = Main.main.getEditLayer(); 57 60 if ((tmpLayer == null) || newLayer) { … … 60 63 } 61 64 62 final DataSet datas = tmpLayer.data;63 65 final OsmDataLayer layer = tmpLayer; 64 66 … … 75 77 List<Node> nodes = new ArrayList<Node>(); 76 78 for (PrimitiveId pid : ids) { 79 OsmPrimitive primitive = layer.data.getPrimitiveById(pid); 80 if (primitive == null) { 81 try { 82 final Long id = pid.getUniqueId(); 83 final OsmPrimitiveType type = pid.getType(); 77 84 78 final Long id = pid.getUniqueId(); 79 final OsmPrimitiveType type = pid.getType(); 85 History h = HistoryDataSet.getInstance().getHistory(id, type); 80 86 81 History h = HistoryDataSet.getInstance().getHistory(id, type); 82 83 OsmPrimitive primitive; 84 HistoryOsmPrimitive hPrimitive1 = h.getLatest(); 85 HistoryOsmPrimitive hPrimitive2; 86 87 boolean visible = hPrimitive1.isVisible(); 88 89 if (visible) { 90 // If the object is not deleted we get the real object 91 DownloadPrimitivesTask download = new DownloadPrimitivesTask(layer, Collections.singletonList(pid), true); 92 System.out.println(tr("Will get {0}", pid)); 93 download.run(); 94 95 System.out.println(tr("Looking for {0}", pid)); 96 primitive = datas.getPrimitiveById(id, type); 97 System.out.println(tr("Found {0}", String.valueOf(primitive.getId()))); 98 if (parent > 0 && type.equals(OsmPrimitiveType.NODE)) { 99 nodes.add((Node) primitive); 100 } 101 } else { 102 if (type.equals(OsmPrimitiveType.NODE)) { 103 // We get version and user from the latest version, 104 // coordinates and tags from n-1 version 105 hPrimitive2 = h.getByVersion(h.getNumVersions() - 1); 106 107 Node node = new Node(id, (int) hPrimitive1.getVersion()); 108 109 HistoryNode hNode = (HistoryNode) hPrimitive2; 110 node.setCoor(hNode.getCoords()); 111 112 primitive = node; 113 if (parent > 0) { 114 nodes.add(node); 115 } 116 } else if (type.equals(OsmPrimitiveType.WAY)) { 117 // We get version and user from the latest version, 118 // nodes and tags from n-1 version 119 hPrimitive1 = h.getLatest(); 120 hPrimitive2 = h.getByVersion(h.getNumVersions() - 1); 121 122 Way way = new Way(id, (int) hPrimitive1.getVersion()); 123 124 HistoryWay hWay = (HistoryWay) hPrimitive2; 125 // System.out.println(tr("Primitive {0} version {1}: {2} nodes", 126 // hPrimitive2.getId(), hPrimitive2.getVersion(), 127 // hWay.getNumNodes())); 128 List<PrimitiveId> nodeIds = new ArrayList<PrimitiveId>(); 129 for (Long i : hWay.getNodes()) { 130 nodeIds.add(new SimplePrimitiveId(i, OsmPrimitiveType.NODE)); 131 } 132 undelete(false, nodeIds, id); 133 134 primitive = way; 135 } else { 136 primitive = new Relation(); 137 hPrimitive1 = h.getLatest(); 138 hPrimitive2 = h.getByVersion(h.getNumVersions() - 1); 139 140 Relation rel = new Relation(id,(int) hPrimitive1.getVersion()); 141 142 HistoryRelation hRel = (HistoryRelation) hPrimitive2; 143 144 List<RelationMember> members = new ArrayList<RelationMember>(hRel.getNumMembers()); 145 for (RelationMemberData m : hRel.getMembers()) { 146 OsmPrimitive p = datas.getPrimitiveById(m.getMemberId(), m.getMemberType()); 147 if (p == null) { 148 switch (m.getMemberType()) { 149 case NODE: 150 p = new Node(m.getMemberId()); 151 break; 152 case CLOSEDWAY: 153 case WAY: 154 p = new Way(m.getMemberId()); 155 break; 156 case MULTIPOLYGON: 157 case RELATION: 158 p = new Relation(m.getMemberId()); 159 break; 87 HistoryOsmPrimitive hPrimitive1 = h.getLatest(); 88 HistoryOsmPrimitive hPrimitive2; 89 90 boolean visible = hPrimitive1.isVisible(); 91 92 if (visible) { 93 // If the object is not deleted we get the real object 94 DownloadPrimitivesTask download = new DownloadPrimitivesTask(layer, Collections.singletonList(pid), true); 95 download.run(); 96 97 primitive = layer.data.getPrimitiveById(id, type); 98 } else { 99 if (type.equals(OsmPrimitiveType.NODE)) { 100 // We get version and user from the latest version, 101 // coordinates and tags from n-1 version 102 hPrimitive2 = h.getByVersion(h.getNumVersions() - 1); 103 104 Node node = new Node(id, (int) hPrimitive1.getVersion()); 105 106 HistoryNode hNode = (HistoryNode) hPrimitive2; 107 node.setCoor(hNode.getCoords()); 108 109 primitive = node; 110 } else if (type.equals(OsmPrimitiveType.WAY)) { 111 // We get version and user from the latest version, 112 // nodes and tags from n-1 version 113 hPrimitive1 = h.getLatest(); 114 hPrimitive2 = h.getByVersion(h.getNumVersions() - 1); 115 116 Way way = new Way(id, (int) hPrimitive1.getVersion()); 117 118 HistoryWay hWay = (HistoryWay) hPrimitive2; 119 // System.out.println(tr("Primitive {0} version {1}: {2} nodes", 120 // hPrimitive2.getId(), hPrimitive2.getVersion(), 121 // hWay.getNumNodes())); 122 List<PrimitiveId> nodeIds = new ArrayList<PrimitiveId>(); 123 for (Long i : hWay.getNodes()) { 124 nodeIds.add(new SimplePrimitiveId(i, OsmPrimitiveType.NODE)); 160 125 } 161 datas.addPrimitive(p); 126 undelete(false, nodeIds, way); 127 128 primitive = way; 129 } else { 130 primitive = new Relation(); 131 hPrimitive1 = h.getLatest(); 132 hPrimitive2 = h.getByVersion(h.getNumVersions() - 1); 133 134 Relation rel = new Relation(id,(int) hPrimitive1.getVersion()); 135 136 HistoryRelation hRel = (HistoryRelation) hPrimitive2; 137 138 List<RelationMember> members = new ArrayList<RelationMember>(hRel.getNumMembers()); 139 for (RelationMemberData m : hRel.getMembers()) { 140 OsmPrimitive p = layer.data.getPrimitiveById(m.getMemberId(), m.getMemberType()); 141 if (p == null) { 142 switch (m.getMemberType()) { 143 case NODE: 144 p = new Node(m.getMemberId()); 145 break; 146 case CLOSEDWAY: 147 case WAY: 148 p = new Way(m.getMemberId()); 149 break; 150 case MULTIPOLYGON: 151 case RELATION: 152 p = new Relation(m.getMemberId()); 153 break; 154 } 155 layer.data.addPrimitive(p); 156 } 157 members.add(new RelationMember(m.getRole(), p)); 158 } 159 160 rel.setMembers(members); 161 162 primitive = rel; 162 163 } 163 members.add(new RelationMember(m.getRole(), p)); 164 165 primitive.setUser(hPrimitive1.getUser()); 166 primitive.setKeys(hPrimitive2.getTags()); 167 primitive.put("history", "retrieved using undelete JOSM plugin"); 168 primitive.setModified(true); 169 170 layer.data.addPrimitive(primitive); 164 171 } 165 172 166 rel.setMembers(members);167 168 primitive = rel;173 // HistoryBrowserDialogManager.getInstance().show(h); 174 } catch (Throwable t) { 175 t.printStackTrace(); 169 176 } 170 171 primitive.setUser(hPrimitive1.getUser());172 primitive.setKeys(hPrimitive2.getTags());173 primitive.put("history", "retrieved using undelete JOSM plugin");174 primitive.setModified(true);175 176 datas.addPrimitive(primitive);177 177 } 178 179 // HistoryBrowserDialogManager.getInstance().show(h); 178 if (parent != null && primitive instanceof Node) { 179 nodes.add((Node) primitive); 180 } 180 181 } 181 if (parent > 0 && !ids.isEmpty() && ids.iterator().next().getType().equals(OsmPrimitiveType.NODE)) {182 Way parentWay = (Way) datas.getPrimitiveById(parent, OsmPrimitiveType.WAY);183 parentWay.setNodes(nodes);182 if (parent instanceof Way && !nodes.isEmpty()) { 183 ((Way) parent).setNodes(nodes); 184 Main.map.repaint(); 184 185 } 185 186 }
Note:
See TracChangeset
for help on using the changeset viewer.