Changeset 34477 in osm for applications/editors/josm/plugins/routes/src
- Timestamp:
- 2018-08-15T13:48:45+02:00 (7 years ago)
- Location:
- applications/editors/josm/plugins/routes
- Files:
-
- 6 deleted
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/routes
- Property svn:ignore
-
old new 1 1 build 2 3 2 bin 3 javadoc
-
- Property svn:ignore
-
applications/editors/josm/plugins/routes/src/org/openstreetmap/josm/plugins/routes/ConvertedWay.java
r30737 r34477 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.routes; 2 3 … … 8 9 import org.openstreetmap.josm.data.osm.Node; 9 10 import org.openstreetmap.josm.data.osm.Way; 10 11 11 12 12 public class ConvertedWay { … … 22 22 public boolean equals(Object o) { 23 23 if (o instanceof WayEnd) { 24 WayEnd otherEnd = (WayEnd)o; 24 WayEnd otherEnd = (WayEnd) o; 25 25 return end.equals(otherEnd.end) && routes.equals(otherEnd.getRoutes()); 26 26 } else { … … 61 61 /** 62 62 * Connects way to this way. Other ways internal representation is destroyed!!! 63 * @param way 63 * @param way way 64 64 */ 65 65 public void connect(ConvertedWay way) { 66 for (int i =0; i<2; i++) {66 for (int i = 0; i < 2; i++) { 67 67 if (way.nodes.get(0).equals(nodes.get(nodes.size() - 1))) { 68 68 way.nodes.remove(0); … … 88 88 return routes; 89 89 } 90 91 92 90 } -
applications/editors/josm/plugins/routes/src/org/openstreetmap/josm/plugins/routes/PathBuilder.java
r30737 r34477 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.routes; 2 3 … … 6 7 import java.util.HashSet; 7 8 import java.util.Map; 9 import java.util.Map.Entry; 8 10 import java.util.Set; 9 import java.util.Map.Entry;10 11 11 12 import org.openstreetmap.josm.data.osm.Way; -
applications/editors/josm/plugins/routes/src/org/openstreetmap/josm/plugins/routes/RouteDefinition.java
r33532 r34477 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.routes; 2 3 … … 4 5 5 6 import org.openstreetmap.josm.data.osm.OsmPrimitive; 6 import org.openstreetmap.josm.data.osm.search.SearchParseError;7 7 import org.openstreetmap.josm.data.osm.search.SearchCompiler; 8 8 import org.openstreetmap.josm.data.osm.search.SearchCompiler.Match; 9 import org.openstreetmap.josm.data.osm.search.SearchParseError; 9 10 10 11 public class RouteDefinition { -
applications/editors/josm/plugins/routes/src/org/openstreetmap/josm/plugins/routes/RouteLayer.java
r33532 r34477 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.routes; 2 3 … … 10 11 import javax.swing.Icon; 11 12 12 import org.openstreetmap.josm.Main;13 13 import org.openstreetmap.josm.data.Bounds; 14 14 import org.openstreetmap.josm.data.osm.DataSet; … … 29 29 import org.openstreetmap.josm.plugins.routes.xml.RoutesXMLLayer; 30 30 import org.openstreetmap.josm.plugins.routes.xml.RoutesXMLRoute; 31 import org.openstreetmap.josm.spi.preferences.Config; 31 32 import org.openstreetmap.josm.tools.ColorHelper; 32 33 import org.openstreetmap.josm.tools.ImageProvider; … … 34 35 public class RouteLayer extends Layer implements DataSetListenerAdapter.Listener { 35 36 36 37 38 39 37 private final PathPainter pathPainter; 38 private final PathBuilder pathBuilder = new PathBuilder(); 39 private final List<RouteDefinition> routes = new ArrayList<>(); 40 private volatile boolean datasetChanged = true; 40 41 41 42 42 public RouteLayer(RoutesXMLLayer xmlLayer) { 43 super(xmlLayer.getName()); 43 44 44 45 46 47 48 49 50 51 52 53 54 45 int index = 0; 46 for (RoutesXMLRoute route:xmlLayer.getRoute()) { 47 if (route.isEnabled()) { 48 Color color = ColorHelper.html2color(route.getColor()); 49 if (color == null) { 50 color = Color.RED; 51 System.err.printf("Routes plugin - unable to convert color (%s)\n", route.getColor()); 52 } 53 routes.add(new RouteDefinition(index++, color, route.getPattern())); 54 } 55 } 55 56 56 Main.pref.get("routes.painter"))) {57 58 59 60 57 if ("wide".equals(Config.getPref().get("routes.painter"))) { 58 pathPainter = new WideLinePainter(this); 59 } else { 60 pathPainter = new NarrowLinePainter(this); 61 } 61 62 62 63 63 DatasetEventManager.getInstance().addDatasetListener(new DataSetListenerAdapter(this), FireMode.IMMEDIATELY); 64 } 64 65 65 66 67 68 66 @Override 67 public Icon getIcon() { 68 return ImageProvider.get("layer", "osmdata_small"); 69 } 69 70 70 71 72 73 71 @Override 72 public Object getInfoComponent() { 73 return null; 74 } 74 75 75 76 77 78 76 @Override 77 public Action[] getMenuEntries() { 78 return new Action[0]; 79 } 79 80 80 81 82 83 81 @Override 82 public String getToolTipText() { 83 return "Hiking routes"; 84 } 84 85 85 86 87 88 86 @Override 87 public boolean isMergable(Layer other) { 88 return false; 89 } 89 90 90 91 92 93 91 @Override 92 public void mergeFrom(Layer from) { 93 // Merging is not supported 94 } 94 95 95 96 97 98 99 100 101 102 96 private void addRelation(Relation relation, RouteDefinition route) { 97 for (RelationMember member:relation.getMembers()) { 98 if (member.getMember() instanceof Way) { 99 Way way = (Way) member.getMember(); 100 pathBuilder.addWay(way, route); 101 } 102 } 103 } 103 104 104 105 105 @Override 106 public void paint(Graphics2D g, MapView mv, Bounds bounds) { 106 107 107 108 DataSet dataset = MainApplication.getLayerManager().getEditDataSet(); 108 109 109 110 111 110 if (dataset == null) { 111 return; 112 } 112 113 113 114 115 114 if (datasetChanged) { 115 datasetChanged = false; 116 pathBuilder.clear(); 116 117 117 118 119 120 121 122 123 118 for (Relation relation:dataset.getRelations()) { 119 for (RouteDefinition route:routes) { 120 if (route.matches(relation)) { 121 addRelation(relation, route); 122 } 123 } 124 } 124 125 125 126 127 128 129 130 131 132 126 for (Way way:dataset.getWays()) { 127 for (RouteDefinition route:routes) { 128 if (route.matches(way)) { 129 pathBuilder.addWay(way, route); 130 } 131 } 132 } 133 } 133 134 134 135 136 137 138 139 140 135 Stroke stroke = g.getStroke(); 136 Color color = g.getColor(); 137 for (ConvertedWay way:pathBuilder.getConvertedWays()) { 138 pathPainter.drawWay(way, mv, g); 139 } 140 g.setStroke(stroke); 141 g.setColor(color); 141 142 142 143 } 143 144 144 145 145 @Override 146 public void visitBoundingBox(BoundingXYVisitor v) { 146 147 147 148 } 148 149 149 150 151 150 public List<RouteDefinition> getRoutes() { 151 return routes; 152 } 152 153 153 154 155 156 154 @Override 155 public void processDatasetEvent(AbstractDatasetChangedEvent event) { 156 datasetChanged = true; 157 } 157 158 158 159 160 161 159 @Override 160 public synchronized void destroy() { 161 /* layer is reused, don't destroy it at all */ 162 } 162 163 } -
applications/editors/josm/plugins/routes/src/org/openstreetmap/josm/plugins/routes/RoutesPlugin.java
r33896 r34477 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.routes; 2 3 … … 61 62 Routes.class.getPackage().getName(), Routes.class.getClassLoader()); 62 63 Unmarshaller unmarshaller = context.createUnmarshaller(); 63 Routes routes = (Routes)unmarshaller.unmarshal( 64 Routes routes = (Routes) unmarshaller.unmarshal( 64 65 new FileInputStream(getPluginDirs().getUserDataDirectory(false) + File.separator + "routes.xml")); 65 66 for (RoutesXMLLayer layer:routes.getLayer()) { … … 69 70 } 70 71 } catch (Exception e) { 71 e.printStackTrace();72 Logging.error(e); 72 73 } 73 74 } … … 97 98 public void layerRemoving(LayerRemoveEvent e) { 98 99 for (Layer layer : e.getSource().getLayers()) { 99 if (layer instanceof OsmDataLayer) 100 if (layer instanceof OsmDataLayer) { 100 101 return; /* at least one OSM layer left, do nothing */ 101 102 } 102 103 } 103 if(!e.isLastLayer()) { 104 if (!e.isLastLayer()) { 104 105 SwingUtilities.invokeLater(() -> { 105 106 for (RouteLayer routeLayer : routeLayers) { -
applications/editors/josm/plugins/routes/src/org/openstreetmap/josm/plugins/routes/paint/AbstractLinePainter.java
r32842 r34477 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.routes.paint; 2 3 … … 17 18 protected boolean getLineLineIntersection(Line2D.Double l1, 18 19 Line2D.Double l2, 19 Point intersection) 20 { 20 Point intersection) { 21 21 double x1 = l1.getX1(), y1 = l1.getY1(), 22 x2 = l1.getX2(), y2 = l1.getY2(), 23 x3 = l2.getX1(), y3 = l2.getY1(), 24 x4 = l2.getX2(), y4 = l2.getY2(); 22 x2 = l1.getX2(), y2 = l1.getY2(), 23 x3 = l2.getX1(), y3 = l2.getY1(), 24 x4 = l2.getX2(), y4 = l2.getY2(); 25 25 double dx1 = x2 - x1; 26 26 double dx2 = x4 - x3; … … 31 31 32 32 if (Math.abs(dy2 * dx1 - dx2 * dy1) < 0.0001) { 33 intersection.x = (int)l1.x2; 34 intersection.y = (int)l1.y2; 33 intersection.x = (int) l1.x2; 34 intersection.y = (int) l1.y2; 35 35 return false; 36 36 } else { 37 intersection.x = (int)(x1 + ua * (x2 - x1)); 38 intersection.y = (int)(y1 + ua * (y2 - y1)); 37 intersection.x = (int) (x1 + ua * (x2 - x1)); 38 intersection.y = (int) (y1 + ua * (y2 - y1)); 39 39 } 40 40 … … 42 42 } 43 43 44 protected double det(double a, double b, double c, double d) 45 { 44 protected double det(double a, double b, double c, double d) { 46 45 return a * d - b * c; 47 46 } … … 60 59 ndy = ndy / length; 61 60 62 return new Point((int)(p1.getX() + shift * ndx), (int)(p1.getY() + shift * ndy)); 61 return new Point((int) (p1.getX() + shift * ndx), (int) (p1.getY() + shift * ndy)); 63 62 } 64 63 … … 117 116 int dx = p.x - p2.x; 118 117 int dy = p.y - p2.y; 119 int distance = (int)Math.sqrt(dx * dx + dy * dy); 118 int distance = (int) Math.sqrt(dx * dx + dy * dy); 120 119 if (distance > 10) { 121 120 p.x = p2.x + dx / (distance / 10); -
applications/editors/josm/plugins/routes/src/org/openstreetmap/josm/plugins/routes/paint/NarrowLinePainter.java
r23189 r34477 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.routes.paint; 2 3 … … 21 22 } 22 23 24 @Override 23 25 public void drawWay(ConvertedWay way, MapView mapView, Graphics2D g) { 24 26 List<Node> nodes = way.getNodes(); … … 33 35 //double shift = -totalWidth / 2 + width / 2; 34 36 double width = LINE_WIDTH; 35 double shift = - 37 double shift = -(LINE_WIDTH * routes.cardinality()) / 2 + width / 2; 36 38 37 for (int k =0; k<routes.length(); k++) {39 for (int k = 0; k < routes.length(); k++) { 38 40 39 41 if (!routes.get(k)) { -
applications/editors/josm/plugins/routes/src/org/openstreetmap/josm/plugins/routes/paint/PathPainter.java
r23189 r34477 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.routes.paint; 2 3 … … 8 9 public interface PathPainter { 9 10 10 publicvoid drawWay(ConvertedWay way, MapView mapView, Graphics2D g);11 void drawWay(ConvertedWay way, MapView mapView, Graphics2D g); 11 12 12 13 } -
applications/editors/josm/plugins/routes/src/org/openstreetmap/josm/plugins/routes/paint/WideLinePainter.java
r23189 r34477 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.routes.paint; 2 3 … … 22 23 } 23 24 25 @Override 24 26 public void drawWay(ConvertedWay way, MapView mapView, Graphics2D g) { 25 27 List<Node> nodes = way.getNodes(); … … 34 36 double shift = -totalWidth / 2 + width / 2; 35 37 36 for (int k =0; k<routes.length(); k++) {38 for (int k = 0; k < routes.length(); k++) { 37 39 38 40 if (!routes.get(k)) {
Note:
See TracChangeset
for help on using the changeset viewer.