Changeset 18396 in josm for trunk


Ignore:
Timestamp:
2022-03-13T13:27:16+01:00 (2 years ago)
Author:
stoecker
Message:

fix #20600 - add Fix coloring for NMEA, patch by Bjoeni

Location:
trunk/src/org/openstreetmap/josm
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/gpx/GpxConstants.java

    r18287 r18396  
    44import java.awt.Color;
    55import java.util.Arrays;
    6 import java.util.Collection;
    76import java.util.Collections;
    87import java.util.List;
     
    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
  • trunk/src/org/openstreetmap/josm/gui/layer/gpx/GpxDrawHelper.java

    r18253 r18396  
    133133    private ColorScale hdopScale;
    134134    private ColorScale qualityScale;
     135    private ColorScale fixScale;
    135136    private ColorScale dateScale;
    136137    private ColorScale directionScale;
     
    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);
     
    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"));
     
    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) {
     
    348392        hdopScale.setNoDataColor(neutralColor);
    349393        qualityScale.setNoDataColor(neutralColor);
     394        fixScale.setNoDataColor(neutralColor);
    350395        directionScale.setNoDataColor(neutralColor);
    351396
     
    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;
     
    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
     
    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();
  • trunk/src/org/openstreetmap/josm/gui/preferences/display/GPXSettingsPanel.java

    r18287 r18396  
    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)"));
     
    453454        colorGroup.add(colorTypeDilution);
    454455        colorGroup.add(colorTypeQuality);
     456        colorGroup.add(colorTypeFix);
    455457        colorGroup.add(colorTypeTime);
    456458        colorGroup.add(colorTypeHeatMap);
     
    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."));
     
    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));
     
    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            }
     
    713718        } else if (colorTypeQuality.isSelected()) {
    714719            putPref("colormode", 6);
     720        } else if (colorTypeFix.isSelected()) {
     721            putPref("colormode", 7);
    715722        } else {
    716723            putPref("colormode", 0);
  • trunk/src/org/openstreetmap/josm/io/GpxReader.java

    r18211 r18396  
    465465                case "cmt":
    466466                case "desc":
     467                case "fix":
    467468                    currentWayPoint.put(localName, accumulator.toString());
    468469                    break;
  • trunk/src/org/openstreetmap/josm/tools/ColorScale.java

    r15586 r18396  
    55import java.awt.FontMetrics;
    66import java.awt.Graphics2D;
     7import java.util.Arrays;
    78
    89/**
     
    1718
    1819    private Color[] colors;
     20    private String[] colorBarTitles;
    1921    private String title = "";
    2022    private int intervalCount = 5;
     
    184186
    185187    /**
     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
     199    /**
    186200     * Sets the interval count for this scale
    187201     * @param intervalCount The interval count hint
     
    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) {
     
    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);
Note: See TracChangeset for help on using the changeset viewer.