Skip to content

Commit 30b74b6

Browse files
author
stoecker
committed
fix #20600 - add Fix coloring for NMEA, patch by Bjoeni
git-svn-id: https://josm.openstreetmap.de/svn/trunk@18396 0c6e7542-c601-0410-84e7-c038aed88b3b
1 parent 21e57ad commit 30b74b6

File tree

5 files changed

+95
-8
lines changed

5 files changed

+95
-8
lines changed

src/org/openstreetmap/josm/data/gpx/GpxConstants.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import java.awt.Color;
55
import java.util.Arrays;
6-
import java.util.Collection;
76
import java.util.Collections;
87
import java.util.List;
98
import java.util.Map;
@@ -252,7 +251,7 @@ static Map<String, String> getExtensionAbbreviations() {
252251
/**
253252
* Possible fix values. NMEA 0183 Version 4.00
254253
*/
255-
Collection<String> FIX_VALUES = Collections.unmodifiableList(
254+
List<String> FIX_VALUES = Collections.unmodifiableList(
256255
Arrays.asList("none", "2d", "3d", "dgps", "pps", "rtk", "float rtk", "estimated", "manual", "simulated"));
257256

258257
/**

src/org/openstreetmap/josm/gui/layer/gpx/GpxDrawHelper.java

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ public class GpxDrawHelper implements SoMChangeListener, MapViewPaintable.LayerP
132132
/** Colors (without custom alpha channel, if given) for HDOP painting. **/
133133
private ColorScale hdopScale;
134134
private ColorScale qualityScale;
135+
private ColorScale fixScale;
135136
private ColorScale dateScale;
136137
private ColorScale directionScale;
137138

@@ -190,6 +191,44 @@ public class GpxDrawHelper implements SoMChangeListener, MapViewPaintable.LayerP
190191
Color.CYAN // PPP
191192
};
192193

194+
private static final String[] rtkLibQualityNames = {
195+
tr("1 - Fixed"),
196+
tr("2 - Float"),
197+
tr("3 - Reserved"),
198+
tr("4 - DGPS"),
199+
tr("5 - Single"),
200+
tr("6 - PPP")
201+
};
202+
203+
/**
204+
* @see GpxConstants#FIX_VALUES
205+
*/
206+
private static final Color[] gpsFixQualityColors = {
207+
Color.MAGENTA, //None
208+
new Color(255, 125, 0), //2D (orange-red)
209+
Color.ORANGE, //3D
210+
Color.CYAN, //DGPS
211+
new Color(150, 255, 150), //PPS (light-green)
212+
Color.GREEN, //RTK
213+
Color.YELLOW, //Float RTK
214+
Color.RED, //Estimated
215+
Color.BLUE, //Manual
216+
Color.GRAY //Simulated
217+
};
218+
219+
private static final String[] gpsFixQualityNames = {
220+
tr("None"),
221+
tr("2D"),
222+
tr("3D"),
223+
tr("DGPS"),
224+
tr("PPS"),
225+
tr("RTK"),
226+
tr("Float RTK"),
227+
tr("Estimated"),
228+
tr("Manual"),
229+
tr("Simulated")
230+
};
231+
193232
// user defined heatmap color
194233
private Color[] heatMapLutColor = createColorLut(0, Color.BLACK, Color.WHITE);
195234

@@ -201,7 +240,8 @@ private void setupColors() {
201240
velocityScale = ColorScale.createHSBScale(256);
202241
/** Colors (without custom alpha channel, if given) for HDOP painting. **/
203242
hdopScale = ColorScale.createHSBScale(256).makeReversed().addTitle(tr("HDOP"));
204-
qualityScale = ColorScale.createFixedScale(rtkLibQualityColors).addTitle(tr("Quality"));
243+
qualityScale = ColorScale.createFixedScale(rtkLibQualityColors).addTitle(tr("Quality")).addColorBarTitles(rtkLibQualityNames);
244+
fixScale = ColorScale.createFixedScale(gpsFixQualityColors).addTitle(tr("GPS fix")).addColorBarTitles(gpsFixQualityNames);
205245
dateScale = ColorScale.createHSBScale(256).addTitle(tr("Time"));
206246
directionScale = ColorScale.createCyclicScale(256).setIntervalCount(4).addTitle(tr("Direction"));
207247

@@ -246,7 +286,11 @@ public enum ColorMode {
246286
/**
247287
* Color by quality (RTKLib)
248288
*/
249-
QUALITY;
289+
QUALITY,
290+
/**
291+
* Color by GPS fix
292+
*/
293+
FIX;
250294

251295
static ColorMode fromIndex(final int index) {
252296
return values()[index];
@@ -347,6 +391,7 @@ public void readPreferences() {
347391
dateScale.setNoDataColor(neutralColor);
348392
hdopScale.setNoDataColor(neutralColor);
349393
qualityScale.setNoDataColor(neutralColor);
394+
fixScale.setNoDataColor(neutralColor);
350395
directionScale.setNoDataColor(neutralColor);
351396

352397
largesize += lineWidth;
@@ -562,6 +607,7 @@ public void calculateColors() {
562607
velocityScale.setRange(0, velocityTune);
563608
hdopScale.setRange(0, hdoprange);
564609
qualityScale.setRange(1, rtkLibQualityColors.length);
610+
fixScale.setRange(0, gpsFixQualityColors.length);
565611
}
566612
double now = System.currentTimeMillis()/1000.0;
567613
if (colored == ColorMode.TIME) {
@@ -589,6 +635,14 @@ public void calculateColors() {
589635
color = hdopScale.getColor((Float) trkPnt.get(GpxConstants.PT_HDOP));
590636
} else if (colored == ColorMode.QUALITY) {
591637
color = qualityScale.getColor((Integer) trkPnt.get(GpxConstants.RTKLIB_Q));
638+
} else if (colored == ColorMode.FIX) {
639+
Object fixval = trkPnt.get(GpxConstants.PT_FIX);
640+
if (fixval != null) {
641+
int fix = GpxConstants.FIX_VALUES.indexOf(fixval);
642+
if (fix >= 0) {
643+
color = fixScale.getColor(fix);
644+
}
645+
}
592646
}
593647
if (oldWp != null) { // other coloring modes need segment for calcuation
594648
double dist = c.greatCircleDistance(oldWp.getCoor());
@@ -1516,6 +1570,8 @@ public void drawColorBar(Graphics2D g, MapView mv) {
15161570
hdopScale.drawColorBar(g, w-30, 50, 20, 100, 1.0);
15171571
} else if (colored == ColorMode.QUALITY) {
15181572
qualityScale.drawColorBar(g, w-30, 50, 20, 100, 1.0);
1573+
} else if (colored == ColorMode.FIX) {
1574+
fixScale.drawColorBar(g, w-30, 50, 20, 175, 1.0);
15191575
} else if (colored == ColorMode.VELOCITY) {
15201576
SystemOfMeasurement som = SystemOfMeasurement.getSystemOfMeasurement();
15211577
velocityScale.drawColorBar(g, w-30, 50, 20, 100, som.speedValue);

src/org/openstreetmap/josm/gui/preferences/display/GPXSettingsPanel.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public class GPXSettingsPanel extends JPanel implements ValidationListener {
7070
private final JRadioButton colorTypeDirection = new JRadioButton(tr("Direction (red = west, yellow = north, green = east, blue = south)"));
7171
private final JRadioButton colorTypeDilution = new JRadioButton(tr("Dilution of Position (red = high, green = low, if available)"));
7272
private final JRadioButton colorTypeQuality = new JRadioButton(tr("Quality (RTKLib only, if available)"));
73+
private final JRadioButton colorTypeFix = new JRadioButton(tr("GPS fix value"));
7374
private final JRadioButton colorTypeTime = new JRadioButton(tr("Track date"));
7475
private final JRadioButton colorTypeHeatMap = new JRadioButton(tr("Heat Map (dark = few, bright = many)"));
7576
private final JRadioButton colorTypeNone = new JRadioButton(tr("Single Color (can be customized in the layer manager)"));
@@ -452,6 +453,7 @@ private void initComponents() {
452453
colorGroup.add(colorTypeDirection);
453454
colorGroup.add(colorTypeDilution);
454455
colorGroup.add(colorTypeQuality);
456+
colorGroup.add(colorTypeFix);
455457
colorGroup.add(colorTypeTime);
456458
colorGroup.add(colorTypeHeatMap);
457459

@@ -462,6 +464,7 @@ private void initComponents() {
462464
tr("Colors points and track segments by dilution of position (HDOP). Your capture device needs to log that information."));
463465
colorTypeQuality.setToolTipText(
464466
tr("Colors points and track segments by RTKLib quality flag (Q). Your capture device needs to log that information."));
467+
colorTypeFix.setToolTipText(tr("Colors points and track segments by GPS fix value."));
465468
colorTypeTime.setToolTipText(tr("Colors points and track segments by its timestamp."));
466469
colorTypeHeatMap.setToolTipText(tr("Collected points and track segments for a position and displayed as heat map."));
467470

@@ -483,6 +486,7 @@ private void initComponents() {
483486
add(colorTypeDirection, GBC.eol().insets(40, 0, 0, 0));
484487
add(colorTypeDilution, GBC.eol().insets(40, 0, 0, 0));
485488
add(colorTypeQuality, GBC.eol().insets(40, 0, 0, 0));
489+
add(colorTypeFix, GBC.eol().insets(40, 0, 0, 0));
486490
add(colorTypeTime, GBC.eol().insets(40, 0, 0, 0));
487491
add(colorTypeHeatMap, GBC.std().insets(40, 0, 0, 0));
488492
add(colorTypeHeatIconLabel, GBC.std().insets(5, 0, 0, 5));
@@ -636,6 +640,7 @@ public final void loadPreferences() {
636640
case 4: colorTypeTime.setSelected(true); break;
637641
case 5: colorTypeHeatMap.setSelected(true); break;
638642
case 6: colorTypeQuality.setSelected(true); break;
643+
case 7: colorTypeFix.setSelected(true); break;
639644
default: Logging.warn("Unknown color type: " + colorType);
640645
}
641646
int ccts = prefInt("colormode.velocity.tune");
@@ -712,6 +717,8 @@ public boolean savePreferences() {
712717
putPref("colormode", 5);
713718
} else if (colorTypeQuality.isSelected()) {
714719
putPref("colormode", 6);
720+
} else if (colorTypeFix.isSelected()) {
721+
putPref("colormode", 7);
715722
} else {
716723
putPref("colormode", 0);
717724
}

src/org/openstreetmap/josm/io/GpxReader.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@ public void endElement(String namespaceURI, String localName, String qName) {
464464
case "urlname":
465465
case "cmt":
466466
case "desc":
467+
case "fix":
467468
currentWayPoint.put(localName, accumulator.toString());
468469
break;
469470
case "hdop":

src/org/openstreetmap/josm/tools/ColorScale.java

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.awt.Color;
55
import java.awt.FontMetrics;
66
import java.awt.Graphics2D;
7+
import java.util.Arrays;
78

89
/**
910
* Utility class that helps to work with color scale for coloring GPX tracks etc.
@@ -16,6 +17,7 @@ public final class ColorScale {
1617
private Color aboveMaxColor;
1718

1819
private Color[] colors;
20+
private String[] colorBarTitles;
1921
private String title = "";
2022
private int intervalCount = 5;
2123

@@ -182,6 +184,18 @@ public ColorScale addTitle(String title) {
182184
return this;
183185
}
184186

187+
/**
188+
* Adds titles to the color bar for a fixed scale
189+
* @param titles Array of String, same length as the colors array
190+
* @return This scale, for chaining
191+
* @since 18396
192+
*/
193+
public ColorScale addColorBarTitles(String[] titles) {
194+
this.intervalCount = titles.length - 1;
195+
this.colorBarTitles = titles;
196+
return this;
197+
}
198+
185199
/**
186200
* Sets the interval count for this scale
187201
* @param intervalCount The interval count hint
@@ -234,16 +248,26 @@ public void drawColorBar(Graphics2D g, int x, int y, int w, int h, double valueS
234248
int fw, fh;
235249
FontMetrics fm = g.getFontMetrics();
236250
fh = fm.getHeight()/2;
237-
fw = fm.stringWidth(String.valueOf(Math.max((int) Math.abs(max*valueScale),
238-
(int) Math.abs(min*valueScale)))) + fm.stringWidth("0.123");
251+
if (colorBarTitles != null && colorBarTitles.length > 0) {
252+
fw = Arrays.asList(colorBarTitles).stream().mapToInt(title -> fm.stringWidth(title)).max().orElse(50);
253+
} else {
254+
fw = fm.stringWidth(
255+
String.valueOf(Math.max((int) Math.abs(max * valueScale), (int) Math.abs(min * valueScale))))
256+
+ fm.stringWidth("0.123");
257+
}
239258
g.setColor(noDataColor);
240259
if (title != null) {
241260
g.drawString(title, x-fw-3, y-fh*3/2);
242261
}
243262
for (int i = 0; i <= intervalCount; i++) {
244263
g.setColor(colors[(int) (1.0*i*n/intervalCount-1e-10)]);
245-
final double val = min+i*(max-min)/intervalCount;
246-
final String txt = String.format("%.3f", val*valueScale);
264+
String txt;
265+
if (colorBarTitles != null && i < colorBarTitles.length) {
266+
txt = colorBarTitles[i];
267+
} else {
268+
final double val = min+i*(max-min)/intervalCount;
269+
txt = String.format("%.3f", val*valueScale);
270+
}
247271
if (w < h) {
248272
g.drawString(txt, x-fw-3, y+i*h/intervalCount+fh/2);
249273
} else {

0 commit comments

Comments
 (0)