Changeset 30351 in osm for applications/editors
- Timestamp:
- 2014-03-24T22:01:55+01:00 (11 years ago)
- Location:
- applications/editors/josm/plugins/livegps/src/livegps
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/livegps/src/livegps/LiveGpsAcquirer.java
r30234 r30351 128 128 } catch (IOException iox) { 129 129 fireGpsStatusChangeEvent( LiveGpsStatus.GpsStatus.CONNECTION_FAILED, tr("Connection Failed")); 130 131 132 133 134 135 130 try { 131 Thread.sleep(1000); 132 } catch (InterruptedException ignore) { 133 134 } 135 } 136 136 } 137 137 … … 195 195 break; 196 196 } catch (IOException e) { 197 197 Main.warn("LiveGps: Could not open connection to gpsd: " + e); 198 198 gpsdSocket = null; 199 199 } … … 220 220 Main.info("LiveGps: Connected to gpsd " + release); 221 221 } else 222 222 Main.info("LiveGps: Unexpected JSON in gpsd greeting: " + line); 223 223 } catch (JsonException jex) { 224 224 if (line.startsWith("GPSD,")) { … … 231 231 232 232 if (JSONProtocol == true) { 233 234 235 236 233 JsonObject Watch = Json.createObjectBuilder() 234 .add("enable", true) 235 .add("json", true) 236 .build(); 237 237 238 238 String Request = "?WATCH=" + Watch.toString() + ";\n"; … … 253 253 gpsdSocket = null; 254 254 } catch (Exception e) { 255 255 Main.warn("LiveGps: Unable to close socket; reconnection may not be possible"); 256 256 } 257 257 } … … 271 271 type = report.getString("class"); 272 272 } catch (JsonException jex) { 273 273 Main.warn("LiveGps: line read from gpsd is not a JSON object:" + line); 274 274 return null; 275 275 } … … 291 291 return new LiveGpsData(lat, lon, course, speed, epx, epy); 292 292 } catch (JsonException je) { 293 293 Main.debug(je.getMessage()); 294 294 } 295 295 -
applications/editors/josm/plugins/livegps/src/livegps/LiveGpsData.java
r26542 r30351 55 55 this.course = course; 56 56 this.speed = speed; 57 58 57 this.epx = epx; 58 this.epy = epy; 59 59 } 60 60 … … 123 123 124 124 public void setEpy(float epy) { 125 125 this.epy = epy; 126 126 } 127 127 128 128 public void setEpx(float epx) { 129 129 this.epx = epx; 130 130 } 131 131 132 132 public float getEpy() { 133 133 return this.epy; 134 134 } 135 135 136 136 public float getEpx() { 137 137 return this.epx; 138 138 } 139 139 … … 201 201 } 202 202 203 /* (non-Javadoc)204 * @see java.lang.Object#hashCode()205 */206 203 @Override 207 204 public int hashCode() { … … 213 210 return result; 214 211 } 215 /* (non-Javadoc) 216 * @see java.lang.Object#equals(java.lang.Object) 217 */ 212 218 213 @Override 219 214 public boolean equals(Object obj) { -
applications/editors/josm/plugins/livegps/src/livegps/LiveGpsDialog.java
r29769 r30351 61 61 } 62 62 63 /* (non-Javadoc)64 * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)65 */66 63 public void propertyChange(PropertyChangeEvent evt) { 67 64 if (!isVisible()) -
applications/editors/josm/plugins/livegps/src/livegps/LiveGpsLayer.java
r27024 r30351 62 62 data.tracks.add(trackBeingWritten); 63 63 64 64 initIntervals(); 65 65 } 66 66 … … 77 77 trackSegment.addWaypoint(lastPoint); 78 78 79 80 79 if (autocenter) 80 conditionalCenter(thisPos); 81 81 } 82 82 … … 87 87 88 88 public void conditionalCenter(LatLon Pos) { 89 90 91 92 93 94 95 96 97 98 99 89 Point2D P = Main.map.mapView.getPoint2D(Pos); 90 Rectangle rv = Main.map.mapView.getBounds(null); 91 Date date = new Date(); 92 long current = date.getTime(); 93 94 rv.grow(-(int)(rv.getHeight() * centerFactor), -(int)(rv.getWidth() * centerFactor)); 95 96 if (!rv.contains(P) || (centerInterval > 0 && current - lastCenter >= centerInterval)) { 97 Main.map.mapView.zoomTo(Pos); 98 lastCenter = current; 99 } 100 100 } 101 101 … … 108 108 super.paint(g, mv, bounds); 109 109 110 if (lastPoint == null) 111 return; 112 113 Point screen = mv.getPoint(lastPoint.getCoor()); 114 115 int TriaHeight = Main.pref.getInteger(C_CURSOR_H, 20); 116 int TriaWidth = Main.pref.getInteger(C_CURSOR_W, 10); 117 int TriaThick = Main.pref.getInteger(C_CURSOR_T, 4); 118 119 /* 120 * Draw a bold triangle. 121 * In case of deep zoom draw also a thin DOP oval. 122 */ 123 124 g.setColor(Main.pref.getColor(C_LIVEGPS_COLOR_POSITION_ESTIMATE, Color.CYAN)); 125 int w, h; 126 double ppm = 100 / mv.getDist100Pixel(); /* pixels per metre */ 127 128 w = (int )Math.round(lastData.getEpx() * ppm); 129 h = (int )Math.round(lastData.getEpy() * ppm); 130 131 if (w > TriaWidth || h > TriaWidth) { 132 int xo, yo; 133 134 yo = screen.y - Math.round(h/2); 135 xo = screen.x - Math.round(w/2); 136 137 g.drawOval(xo, yo, w, h); 138 } 139 140 int[] x = new int[4]; 141 int[] y = new int[4]; 142 float course = lastData.getCourse(); 143 float csin = (float )Math.sin(Math.toRadians(course)); 144 float ccos = (float )Math.cos(Math.toRadians(course)); 145 float csin120 = (float )Math.sin(Math.toRadians(course + 120)); 146 float ccos120 = (float )Math.cos(Math.toRadians(course + 120)); 147 float csin240 = (float )Math.sin(Math.toRadians(course + 240)); 148 float ccos240 = (float )Math.cos(Math.toRadians(course + 240)); 149 150 g.setColor(Main.pref.getColor(C_LIVEGPS_COLOR_POSITION, Color.RED)); 151 152 for (int i = 0; i < TriaThick; i++, TriaHeight--, TriaWidth--) { 153 154 x[0] = screen.x + Math.round(TriaHeight * csin); 155 y[0] = screen.y - Math.round(TriaHeight * ccos); 156 x[1] = screen.x + Math.round(TriaWidth * csin120); 157 y[1] = screen.y - Math.round(TriaWidth * ccos120); 158 x[2] = screen.x; 159 y[2] = screen.y; 160 x[3] = screen.x + Math.round(TriaWidth * csin240); 161 y[3] = screen.y - Math.round(TriaWidth * ccos240); 162 163 g.drawPolygon(x, y, 4); 164 } 165 166 } 167 168 /* (non-Javadoc) 169 * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent) 170 */ 110 if (lastPoint == null) 111 return; 112 113 Point screen = mv.getPoint(lastPoint.getCoor()); 114 115 int TriaHeight = Main.pref.getInteger(C_CURSOR_H, 20); 116 int TriaWidth = Main.pref.getInteger(C_CURSOR_W, 10); 117 int TriaThick = Main.pref.getInteger(C_CURSOR_T, 4); 118 119 /* 120 * Draw a bold triangle. 121 * In case of deep zoom draw also a thin DOP oval. 122 */ 123 124 g.setColor(Main.pref.getColor(C_LIVEGPS_COLOR_POSITION_ESTIMATE, Color.CYAN)); 125 int w, h; 126 double ppm = 100 / mv.getDist100Pixel(); /* pixels per metre */ 127 128 w = (int )Math.round(lastData.getEpx() * ppm); 129 h = (int )Math.round(lastData.getEpy() * ppm); 130 131 if (w > TriaWidth || h > TriaWidth) { 132 int xo, yo; 133 134 yo = screen.y - Math.round(h/2); 135 xo = screen.x - Math.round(w/2); 136 137 g.drawOval(xo, yo, w, h); 138 } 139 140 int[] x = new int[4]; 141 int[] y = new int[4]; 142 float course = lastData.getCourse(); 143 float csin = (float )Math.sin(Math.toRadians(course)); 144 float ccos = (float )Math.cos(Math.toRadians(course)); 145 float csin120 = (float )Math.sin(Math.toRadians(course + 120)); 146 float ccos120 = (float )Math.cos(Math.toRadians(course + 120)); 147 float csin240 = (float )Math.sin(Math.toRadians(course + 240)); 148 float ccos240 = (float )Math.cos(Math.toRadians(course + 240)); 149 150 g.setColor(Main.pref.getColor(C_LIVEGPS_COLOR_POSITION, Color.RED)); 151 152 for (int i = 0; i < TriaThick; i++, TriaHeight--, TriaWidth--) { 153 154 x[0] = screen.x + Math.round(TriaHeight * csin); 155 y[0] = screen.y - Math.round(TriaHeight * ccos); 156 x[1] = screen.x + Math.round(TriaWidth * csin120); 157 y[1] = screen.y - Math.round(TriaWidth * ccos120); 158 x[2] = screen.x; 159 y[2] = screen.y; 160 x[3] = screen.x + Math.round(TriaWidth * csin240); 161 y[3] = screen.y - Math.round(TriaWidth * ccos240); 162 163 g.drawPolygon(x, y, 4); 164 } 165 166 } 167 171 168 public void propertyChange(PropertyChangeEvent evt) { 172 169 if (!isVisible()) { … … 190 187 */ 191 188 private boolean allowRedraw() { 192 193 194 195 196 197 198 199 189 Date date = new Date(); 190 long current = date.getTime(); 191 192 if (current - lastRedraw >= refreshInterval) { 193 lastRedraw = current; 194 return true; 195 } else 196 return false; 200 197 } 201 198 … … 206 203 */ 207 204 private void initIntervals() { 208 209 210 211 212 213 214 215 216 217 218 219 Main.pref.putInteger(C_REFRESH_INTERVAL, refreshInterval);220 Main.pref.putInteger(C_CENTER_INTERVAL, centerInterval);221 222 223 224 225 226 227 228 229 205 if ((refreshInterval = Main.pref.getInteger(oldC_REFRESH_INTERVAL, 0)) != 0) { 206 refreshInterval *= 1000; 207 Main.pref.put(oldC_REFRESH_INTERVAL, null); 208 } else 209 refreshInterval = Main.pref.getInteger(C_REFRESH_INTERVAL, DEFAULT_REFRESH_INTERVAL); 210 211 centerInterval = Main.pref.getInteger(C_CENTER_INTERVAL, DEFAULT_CENTER_INTERVAL); 212 centerFactor = Main.pref.getInteger(C_CENTER_FACTOR, DEFAULT_CENTER_FACTOR); 213 if (centerFactor <= 1 || centerFactor >= 99) 214 centerFactor = DEFAULT_CENTER_FACTOR; 215 216 Main.pref.putInteger(C_REFRESH_INTERVAL, refreshInterval); 217 Main.pref.putInteger(C_CENTER_INTERVAL, centerInterval); 218 Main.pref.putInteger(C_CENTER_FACTOR, (int )centerFactor); 219 220 /* 221 * Do one time conversion of factor: user value means "how big is inner rectangle 222 * comparing to screen in percent", machine value means "what is the shrink ratio 223 * for each dimension on _both_ sides". 224 */ 225 226 centerFactor = (100 - centerFactor) / 2 / 100; 230 227 } 231 228 } -
applications/editors/josm/plugins/livegps/src/livegps/LiveGpsPlugin.java
r29854 r30351 102 102 public void layerRemoved(Layer oldLayer) { 103 103 if (oldLayer != lgpslayer) 104 104 return; 105 105 106 106 enableTracking(false); … … 159 159 */ 160 160 public void enableTracking(boolean enable) { 161 161 162 162 if (enable && !enabled) { 163 163 assert (acquirer == null); … … 167 167 acquirerThread = new Thread(acquirer); 168 168 169 170 171 172 173 174 169 if (lgpslayer == null) { 170 lgpslayer = new LiveGpsLayer(data); 171 Main.main.addLayer(lgpslayer); 172 MapView.addLayerChangeListener(this); 173 lgpslayer.setAutoCenter(isAutoCenter()); 174 } 175 175 176 176 acquirer.addPropertyChangeListener(lgpslayer); 177 177 acquirer.addPropertyChangeListener(lgpsdialog); 178 178 for (PropertyChangeListener listener : listenerQueue) 179 179 acquirer.addPropertyChangeListener(listener); 180 180 181 181 acquirerThread.start(); 182 182 183 183 enabled = true; 184 184 185 185 } else if (!enable && enabled) { 186 186 assert (lgpslayer != null); 187 187 assert (acquirer != null); 188 188 assert (acquirerThread != null); 189 189 190 191 192 193 194 195 190 acquirer.shutdown(); 191 acquirer = null; 192 acquirerThread = null; 193 194 enabled = false; 195 } 196 196 } 197 197 … … 220 220 } 221 221 222 /* (non-Javadoc)223 * @see org.openstreetmap.josm.plugins.Plugin#mapFrameInitialized(org.openstreetmap.josm.gui.MapFrame, org.openstreetmap.josm.gui.MapFrame)224 */225 222 @Override 226 223 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) {
Note:
See TracChangeset
for help on using the changeset viewer.