Changeset 30738 in osm for applications/editors/josm/plugins/routes
- Timestamp:
- 2014-10-19T01:27:04+02:00 (10 years ago)
- Location:
- applications/editors/josm/plugins/routes
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/routes/.settings/org.eclipse.jdt.ui.prefs
r19532 r30738 1 #Fri Jan 15 16:11:57 CET 20102 1 eclipse.preferences.version=1 3 2 editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true … … 9 8 sp_cleanup.add_missing_nls_tags=false 10 9 sp_cleanup.add_missing_override_annotations=false 10 sp_cleanup.add_missing_override_annotations_interface_methods=false 11 11 sp_cleanup.add_serial_version_id=false 12 12 sp_cleanup.always_use_blocks=true … … 14 14 sp_cleanup.always_use_this_for_non_static_field_access=false 15 15 sp_cleanup.always_use_this_for_non_static_method_access=false 16 sp_cleanup.convert_functional_interfaces=false 16 17 sp_cleanup.convert_to_enhanced_for_loop=false 17 sp_cleanup.correct_indentation= true18 sp_cleanup.correct_indentation=false 18 19 sp_cleanup.format_source_code=false 19 20 sp_cleanup.format_source_code_changes_only=false 21 sp_cleanup.insert_inferred_type_arguments=false 20 22 sp_cleanup.make_local_variable_final=false 21 23 sp_cleanup.make_parameters_final=false … … 33 35 sp_cleanup.qualify_static_method_accesses_with_declaring_class=false 34 36 sp_cleanup.remove_private_constructors=true 37 sp_cleanup.remove_redundant_type_arguments=false 35 38 sp_cleanup.remove_trailing_whitespaces=true 36 39 sp_cleanup.remove_trailing_whitespaces_all=true … … 46 49 sp_cleanup.sort_members=false 47 50 sp_cleanup.sort_members_all=false 51 sp_cleanup.use_anonymous_class_creation=false 48 52 sp_cleanup.use_blocks=false 49 53 sp_cleanup.use_blocks_only_for_return_and_throw=false 54 sp_cleanup.use_lambda=false 50 55 sp_cleanup.use_parentheses_in_expressions=false 51 56 sp_cleanup.use_this_for_non_static_field_access=false … … 53 58 sp_cleanup.use_this_for_non_static_method_access=false 54 59 sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true 60 sp_cleanup.use_type_arguments=false -
applications/editors/josm/plugins/routes/src/org/openstreetmap/josm/plugins/routes/RoutesPlugin.java
r30737 r30738 19 19 import org.openstreetmap.josm.gui.layer.Layer; 20 20 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 21 22 21 import org.openstreetmap.josm.plugins.Plugin; 23 22 import org.openstreetmap.josm.plugins.PluginInformation; … … 36 35 File routesFile = new File(getPluginDir() + File.separator + "routes.xml"); 37 36 if (!routesFile.exists()) { 38 System.out.println("File with route definitions doesn't exist, using default");37 Main.info("File with route definitions doesn't exist, using default"); 39 38 40 39 try { 41 40 routesFile.getParentFile().mkdir(); 42 OutputStream outputStream = new FileOutputStream(routesFile); 43 InputStream inputStream = Routes.class.getResourceAsStream("routes.xml"); 44 45 byte[] b = new byte[512]; 46 int read; 47 while ((read = inputStream.read(b)) != -1) { 48 outputStream.write(b, 0, read); 41 try ( 42 OutputStream outputStream = new FileOutputStream(routesFile); 43 InputStream inputStream = Routes.class.getResourceAsStream("routes.xml"); 44 ) { 45 byte[] b = new byte[512]; 46 int read; 47 while ((read = inputStream.read(b)) != -1) { 48 outputStream.write(b, 0, read); 49 } 49 50 } 50 51 outputStream.close();52 inputStream.close();53 54 51 } catch (IOException e) { 55 e.printStackTrace();52 Main.error(e); 56 53 } 57 54 } … … 62 59 Unmarshaller unmarshaller = context.createUnmarshaller(); 63 60 Routes routes = (Routes)unmarshaller.unmarshal( 64 new FileInputStream(getPluginDir() + File.separator + "routes.xml"));61 new FileInputStream(getPluginDir() + File.separator + "routes.xml")); 65 62 for (RoutesXMLLayer layer:routes.getLayer()) { 66 63 if (layer.isEnabled()) { … … 77 74 78 75 public void activeLayerChange(Layer oldLayer, Layer newLayer) { 79 // TODO Auto-generated method stub76 // Do nothing 80 77 } 81 78 … … 117 114 checkLayers(); 118 115 } 119 120 116 } -
applications/editors/josm/plugins/routes/src/org/openstreetmap/josm/plugins/routes/paint/AbstractLinePainter.java
r23422 r30738 17 17 public abstract class AbstractLinePainter implements PathPainter { 18 18 19 20 21 22 23 24 25 26 27 28 29 30 31 19 // Following two method copied from http://blog.persistent.info/2004/03/java-lineline-intersections.html 20 protected boolean getLineLineIntersection(Line2D.Double l1, 21 Line2D.Double l2, 22 Point intersection) 23 { 24 double x1 = l1.getX1(), y1 = l1.getY1(), 25 x2 = l1.getX2(), y2 = l1.getY2(), 26 x3 = l2.getX1(), y3 = l2.getY1(), 27 x4 = l2.getX2(), y4 = l2.getY2(); 28 double dx1 = x2 - x1; 29 double dx2 = x4 - x3; 30 double dy1 = y2 - y1; 31 double dy2 = y4 - y3; 32 32 33 33 double ua = (dx2 * (y1 - y3) - dy2 * (x1 - x3)) / (dy2 * dx1 - dx2 * dy1); 34 34 35 36 37 38 39 40 41 42 35 if (Math.abs(dy2 * dx1 - dx2 * dy1) < 0.0001) { 36 intersection.x = (int)l1.x2; 37 intersection.y = (int)l1.y2; 38 return false; 39 } else { 40 intersection.x = (int)(x1 + ua * (x2 - x1)); 41 intersection.y = (int)(y1 + ua * (y2 - y1)); 42 } 43 43 44 45 44 return true; 45 } 46 46 47 48 49 50 47 protected double det(double a, double b, double c, double d) 48 { 49 return a * d - b * c; 50 } 51 51 52 53 54 52 protected Point shiftPoint(Point2D p1, Point2D p2, double shift) { 53 double dx = p2.getX() - p1.getX(); 54 double dy = p2.getY() - p1.getY(); 55 55 56 57 58 56 // Perpendicular vector 57 double ndx = -dy; 58 double ndy = dx; 59 59 60 61 62 63 60 // Normalize 61 double length = Math.sqrt(ndx * ndx + ndy * ndy); 62 ndx = ndx / length; 63 ndy = ndy / length; 64 64 65 66 65 return new Point((int)(p1.getX() + shift * ndx), (int)(p1.getY() + shift * ndy)); 66 } 67 67 68 69 70 68 protected Line2D.Double shiftLine(Point2D p1, Point2D p2, double shift) { 69 double dx = p2.getX() - p1.getX(); 70 double dy = p2.getY() - p1.getY(); 71 71 72 73 72 Point2D point1 = shiftPoint(p1, p2, shift); 73 Point2D point2 = new Point2D.Double(point1.getX() + dx, point1.getY() + dy); 74 74 75 76 77 75 return new Line2D.Double( 76 point1, point2); 77 } 78 78 79 79 protected GeneralPath getPath(Graphics2D g, MapView mapView, List<Node> nodes, double shift) { 80 80 81 81 GeneralPath path = new GeneralPath(); 82 82 83 84 85 83 if (nodes.size() < 2) { 84 return path; 85 } 86 86 87 88 89 90 87 Point p1 = null; 88 Point p2 = null; 89 Point p3 = null; 90 Point lastPoint = null; 91 91 92 93 92 for (Node n: nodes) { 93 Point p = mapView.getPoint(n); 94 94 95 96 97 98 99 100 101 95 if (!p.equals(p3)) { 96 p1 = p2; 97 p2 = p3; 98 p3 = p; 99 } else { 100 continue; 101 } 102 102 103 104 105 106 107 108 109 103 p = null; 104 if (p2 != null) { 105 if (p1 == null) { 106 p = shiftPoint(p2, p3, shift); 107 } else { 108 Line2D.Double line1 = shiftLine(p1, p2, shift); 109 Line2D.Double line2 = shiftLine(p2, p3, shift); 110 110 111 111 /*path.moveTo((float)line1.x1, (float)line1.y1); 112 112 path.lineTo((float)line1.x2, (float)line1.y2); 113 113 path.moveTo((float)line2.x1, (float)line2.y1); 114 114 path.lineTo((float)line2.x2, (float)line2.y2);*/ 115 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 116 p = new Point(); 117 if (!getLineLineIntersection(line1, line2, p)) { 118 p = null; 119 } else { 120 int dx = p.x - p2.x; 121 int dy = p.y - p2.y; 122 int distance = (int)Math.sqrt(dx * dx + dy * dy); 123 if (distance > 10) { 124 p.x = p2.x + dx / (distance / 10); 125 p.y = p2.y + dy / (distance / 10); 126 } 127 } 128 } 129 } 130 130 131 132 133 134 135 136 137 131 if (p != null && lastPoint != null) { 132 drawSegment(g, mapView, path, lastPoint, p); 133 } 134 if (p != null) { 135 lastPoint = p; 136 } 137 } 138 138 139 140 141 142 139 if (p2 != null && p3 != null && lastPoint != null) { 140 p3 = shiftPoint(p3, p2, -shift); 141 drawSegment(g, mapView, path, lastPoint, p3); 142 } 143 143 144 145 144 return path; 145 } 146 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 147 private void drawSegment(Graphics2D g, NavigatableComponent nc, GeneralPath path, Point p1, Point p2) { 148 boolean drawIt = false; 149 if (Main.isOpenjdk) { 150 /** 151 * Work around openjdk bug. It leads to drawing artefacts when zooming in a lot. (#4289, #4424) 152 * (It looks like int overflow when clipping.) We do custom clipping. 153 */ 154 Rectangle bounds = g.getClipBounds(); 155 bounds.grow(100, 100); // avoid arrow heads at the border 156 LineClip clip = new LineClip(p1, p2, bounds); 157 drawIt = clip.execute(); 158 if (drawIt) { 159 p1 = clip.getP1(); 160 p2 = clip.getP2(); 161 } 162 } else { 163 drawIt = isSegmentVisible(nc, p1, p2); 164 } 165 if (drawIt) { 166 /* draw segment line */ 167 path.moveTo(p1.x, p1.y); 168 path.lineTo(p2.x, p2.y); 169 } 170 } 171 171 172 173 174 175 176 177 178 172 private boolean isSegmentVisible(NavigatableComponent nc, Point p1, Point p2) { 173 if ((p1.x < 0) && (p2.x < 0)) return false; 174 if ((p1.y < 0) && (p2.y < 0)) return false; 175 if ((p1.x > nc.getWidth()) && (p2.x > nc.getWidth())) return false; 176 if ((p1.y > nc.getHeight()) && (p2.y > nc.getHeight())) return false; 177 return true; 178 } 179 179 180 180 -
applications/editors/josm/plugins/routes/src/org/openstreetmap/josm/plugins/routes/xml/routes.xml
r19345 r30738 2 2 <routes xmlns="http://www.example.org/routes" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.example.org/routes routes.xsd "> 3 3 <!-- pattern is the same pattern as used in SearchAction --> 4 5 6 7 8 9 10 11 12 13 </pattern> 14 15 16 17 18 19 20 21 22 23 </pattern> 24 25 26 27 28 29 30 31 32 4 <layer name="Czech hiking trails"> 5 <route color="#FF0000"> 6 <pattern> 7 ((type:relation | type:way) kct_red=*) | (color=red type=route route=hiking network="cz:kct") 8 </pattern> 9 </route> 10 <route color="#FFFF00"> 11 <pattern> 12 ((type:relation | type:way) kct_yellow=*) | (color=yellow type=route route=hiking network="cz:kct") 13 </pattern> 14 </route> 15 <route color="#0000FF"> 16 <pattern> 17 ((type:relation | type:way) kct_blue=*) | (color=blue type=route route=hiking network="cz:kct") 18 </pattern> 19 </route> 20 <route color="#00FF00"> 21 <pattern> 22 ((type:relation | type:way) kct_green=*) | (color=green type=route route=hiking network="cz:kct") 23 </pattern> 24 </route> 25 </layer> 26 <layer name="Cycle routes"> 27 <route color="#FF00FF"> 28 <pattern> 29 (type:way (ncn=* | (lcn=* | rcn=* ))) | (type:relation type=route route=bicycle) 30 </pattern> 31 </route> 32 </layer> 33 33 </routes> -
applications/editors/josm/plugins/routes/src/org/openstreetmap/josm/plugins/routes/xml/routes.xsd
r16593 r30738 11 11 12 12 <annotation> 13 14 <jxb:schemaBindings> 15 16 17 18 19 13 <appinfo> 14 <jxb:schemaBindings> 15 <jxb:nameXmlTransform> 16 <jxb:typeName prefix="RoutesXML"/> 17 </jxb:nameXmlTransform> 18 </jxb:schemaBindings> 19 </appinfo> 20 20 </annotation> 21 21 22 22 <element name="routes"> 23 24 25 26 27 23 <complexType> 24 <sequence> 25 <element name="layer" type="tns:layer" minOccurs="0" maxOccurs="unbounded"/> 26 </sequence> 27 </complexType> 28 28 </element> 29 29 30 30 <complexType name="layer"> 31 32 33 34 35 31 <sequence> 32 <element name="route" type="tns:route" minOccurs="0" maxOccurs="unbounded"/> 33 </sequence> 34 <attribute name="name" type="string"/> 35 <attribute name="enabled" type="boolean" default="true"/> 36 36 </complexType> 37 37 38 38 <complexType name="route"> 39 40 <element name="pattern" type="string"/> 41 42 43 39 <sequence> 40 <element name="pattern" type="string"/> 41 </sequence> 42 <attribute name="color" type="string"/> 43 <attribute name="enabled" type="boolean" default="true"/> 44 44 </complexType> 45 45
Note:
See TracChangeset
for help on using the changeset viewer.