Changeset 15496 in josm for trunk/src/org/openstreetmap/josm/gui/layer/gpx/GpxDrawHelper.java
- Timestamp:
- 2019-11-02T15:11:34+01:00 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/layer/gpx/GpxDrawHelper.java
r15292 r15496 28 28 import java.util.LinkedList; 29 29 import java.util.List; 30 import java.util.Objects; 30 31 import java.util.Random; 31 32 … … 33 34 34 35 import org.openstreetmap.josm.data.Bounds; 35 import org.openstreetmap.josm.data.PreferencesUtils;36 36 import org.openstreetmap.josm.data.SystemOfMeasurement; 37 37 import org.openstreetmap.josm.data.SystemOfMeasurement.SoMChangeListener; … … 52 52 import org.openstreetmap.josm.gui.layer.MapViewPaintable.PaintableInvalidationEvent; 53 53 import org.openstreetmap.josm.gui.layer.MapViewPaintable.PaintableInvalidationListener; 54 import org.openstreetmap.josm.gui.preferences.display.GPXSettingsPanel; 54 55 import org.openstreetmap.josm.io.CachedFile; 55 56 import org.openstreetmap.josm.spi.preferences.Config; … … 66 67 67 68 /** 68 * The colorthat is used for drawing GPX points.69 * @since 1 082470 */ 71 public static final NamedColorProperty DEFAULT_COLOR = new NamedColorProperty(marktr("gps point"), Color.magenta); 69 * The default color property that is used for drawing GPX points. 70 * @since 15496 71 */ 72 public static final NamedColorProperty DEFAULT_COLOR_PROPERTY = new NamedColorProperty(marktr("gps point"), Color.magenta); 72 73 73 74 private final GpxData data; … … 79 80 private boolean alphaLines; 80 81 // draw direction arrows on the lines 81 private boolean direction;82 private boolean arrows; 82 83 /** width of line for paint **/ 83 84 private int lineWidth; … … 91 92 private boolean hdopCircle; 92 93 /** paint direction arrow with alternate math. may be faster **/ 93 private boolean a lternateDirection;94 private boolean arrowsFast; 94 95 /** don't draw arrows nearer to each other than this **/ 95 private int delta;96 private int arrowsDelta; 96 97 private double minTrackDurationForTimeColoring; 97 98 … … 107 108 private boolean computeCacheColorDynamic; 108 109 private ColorMode computeCacheColored; 109 private int computeCache ColorTracksTune;110 private int computeCacheVelocityTune; 110 111 private int computeCacheHeatMapDrawColorTableIdx; 111 112 private boolean computeCacheHeatMapDrawPointMode; … … 113 114 private int computeCacheHeatMapDrawLowerLimit; 114 115 116 private Color colorCache; 117 private Color colorCacheTransparent; 118 115 119 //// Color-related fields 116 120 /** Mode of the line coloring **/ 117 121 private ColorMode colored; 118 122 /** max speed for coloring - allows to tweak line coloring for different speed levels. **/ 119 private int colorTracksTune;123 private int velocityTune; 120 124 private boolean colorModeDynamic; 121 125 private Color neutralColor; … … 146 150 /** heat map parameters **/ 147 151 148 // enabled or not (override by settings)149 private boolean heatMapEnabled;150 152 // draw small extra line 151 153 private boolean heatMapDrawExtraLine; … … 269 271 } 270 272 271 private static String specName(String layerName) {272 return "layer " + layerName;273 }274 275 /**276 * Get the default color for gps tracks for specified layer277 * @param layerName name of the GpxLayer278 * @param ignoreCustom do not use preferences279 * @return the color or null if the color is not constant280 */281 public Color getColor(String layerName, boolean ignoreCustom) {282 if (ignoreCustom || getColorMode(layerName) == ColorMode.NONE) {283 return DEFAULT_COLOR.getChildColor(284 NamedColorProperty.COLOR_CATEGORY_LAYER,285 layerName,286 DEFAULT_COLOR.getName()).get();287 } else {288 return null;289 }290 }291 292 273 /** 293 274 * Read coloring mode for specified layer from preferences 294 * @param layerName name of the GpxLayer295 275 * @return coloring mode 296 276 */ 297 public ColorMode getColorMode( String layerName) {277 public ColorMode getColorMode() { 298 278 try { 299 int i = PreferencesUtils.getInteger(Config.getPref(), "draw.rawgps.colors", specName(layerName), 0); 279 int i = optInt("colormode"); 280 if (i == -1) i = 0; //global 300 281 return ColorMode.fromIndex(i); 301 282 } catch (IndexOutOfBoundsException e) { … … 305 286 } 306 287 307 /** Reads generic color from preferences (usually gray) 308 * @return the color 288 private String opt(String key) { 289 return GPXSettingsPanel.getLayerPref(layer, key); 290 } 291 292 private boolean optBool(String key) { 293 return Boolean.parseBoolean(opt(key)); 294 } 295 296 private int optInt(String key) { 297 return GPXSettingsPanel.getLayerPrefInt(layer, key); 298 } 299 300 /** 301 * Read all drawing-related settings from preferences 309 302 **/ 310 public static Color getGenericColor() { 311 return DEFAULT_COLOR.get(); 312 } 313 314 /** 315 * Read all drawing-related settings from preferences 316 * @param layerName layer name used to access its specific preferences 317 **/ 318 public void readPreferences(String layerName) { 319 String spec = specName(layerName); 320 forceLines = PreferencesUtils.getBoolean(Config.getPref(), "draw.rawgps.lines.force", spec, false); 321 direction = PreferencesUtils.getBoolean(Config.getPref(), "draw.rawgps.direction", spec, false); 322 lineWidth = PreferencesUtils.getInteger(Config.getPref(), "draw.rawgps.linewidth", spec, 0); 323 alphaLines = PreferencesUtils.getBoolean(Config.getPref(), "draw.rawgps.lines.alpha-blend", spec, false); 324 303 public void readPreferences() { 304 forceLines = optBool("lines.force"); 305 arrows = optBool("lines.arrows"); 306 arrowsFast = optBool("lines.arrows.fast"); 307 arrowsDelta = optInt("lines.arrows.min-distance"); 308 lineWidth = optInt("lines.width"); 309 alphaLines = optBool("lines.alpha-blend"); 310 311 int l = optInt("lines"); 325 312 if (!data.fromServer) { 326 maxLineLength = PreferencesUtils.getInteger(Config.getPref(), "draw.rawgps.max-line-length.local", spec, -1);327 lines = PreferencesUtils.getBoolean(Config.getPref(), "draw.rawgps.lines.local", spec, true);313 maxLineLength = optInt("lines.max-length.local"); 314 lines = l != 0; //draw for -1 (default), 1 (local) and 2 (all) 328 315 } else { 329 maxLineLength = PreferencesUtils.getInteger(Config.getPref(), "draw.rawgps.max-line-length", spec, 200); 330 lines = PreferencesUtils.getBoolean(Config.getPref(), "draw.rawgps.lines", spec, true); 331 } 332 large = PreferencesUtils.getBoolean(Config.getPref(), "draw.rawgps.large", spec, false); 333 largesize = PreferencesUtils.getInteger(Config.getPref(), "draw.rawgps.large.size", spec, 3); 334 hdopCircle = PreferencesUtils.getBoolean(Config.getPref(), "draw.rawgps.hdopcircle", spec, false); 335 colored = getColorMode(layerName); 336 alternateDirection = PreferencesUtils.getBoolean(Config.getPref(), "draw.rawgps.alternatedirection", spec, false); 337 delta = PreferencesUtils.getInteger(Config.getPref(), "draw.rawgps.min-arrow-distance", spec, 40); 338 colorTracksTune = PreferencesUtils.getInteger(Config.getPref(), "draw.rawgps.colorTracksTune", spec, 45); 339 colorModeDynamic = PreferencesUtils.getBoolean(Config.getPref(), "draw.rawgps.colors.dynamic", spec, false); 316 maxLineLength = optInt("lines.max-length"); 317 lines = l == 2; //draw only for 2 (all) 318 } 319 large = optBool("points.large"); 320 largesize = optInt("points.large.size"); 321 hdopCircle = optBool("points.hdopcircle"); 322 colored = getColorMode(); 323 velocityTune = optInt("colormode.velocity.tune"); 324 colorModeDynamic = optBool("colormode.dynamic-range"); 340 325 /* good HDOP's are between 1 and 3, very bad HDOP's go into 3 digit values */ 341 326 hdoprange = Config.getPref().getInt("hdop.range", 7); 342 minTrackDurationForTimeColoring = Config.getPref().getInt("draw.rawgps.date-coloring-min-dt", 60);343 largePointAlpha = Config.getPref().getInt("draw.rawgps.large.alpha", -1) & 0xFF;327 minTrackDurationForTimeColoring = optInt("colormode.time.min-distance"); 328 largePointAlpha = optInt("points.large.alpha") & 0xFF; 344 329 345 330 // get heatmap parameters 346 heatMapEnabled = PreferencesUtils.getBoolean(Config.getPref(), "draw.rawgps.heatmap.enabled", spec, false); 347 heatMapDrawExtraLine = PreferencesUtils.getBoolean(Config.getPref(), "draw.rawgps.heatmap.line-extra", spec, false); 348 heatMapDrawColorTableIdx = PreferencesUtils.getInteger(Config.getPref(), "draw.rawgps.heatmap.colormap", spec, 0); 349 heatMapDrawPointMode = PreferencesUtils.getBoolean(Config.getPref(), "draw.rawgps.heatmap.use-points", spec, false); 350 heatMapDrawGain = PreferencesUtils.getInteger(Config.getPref(), "draw.rawgps.heatmap.gain", spec, 0); 351 heatMapDrawLowerLimit = PreferencesUtils.getInteger(Config.getPref(), "draw.rawgps.heatmap.lower-limit", spec, 0); 331 heatMapDrawExtraLine = optBool("colormode.heatmap.line-extra"); 332 heatMapDrawColorTableIdx = optInt("colormode.heatmap.colormap"); 333 heatMapDrawPointMode = optBool("colormode.heatmap.use-points"); 334 heatMapDrawGain = optInt("colormode.heatmap.gain"); 335 heatMapDrawLowerLimit = optInt("colormode.heatmap.lower-limit"); 352 336 353 337 // shrink to range 354 338 heatMapDrawGain = Utils.clamp(heatMapDrawGain, -10, 10); 355 356 neutralColor = getColor(layerName, true); 339 neutralColor = DEFAULT_COLOR_PROPERTY.get(); 357 340 velocityScale.setNoDataColor(neutralColor); 358 341 dateScale.setNoDataColor(neutralColor); … … 369 352 List<WayPoint> visibleSegments = listVisibleSegments(clipBounds); 370 353 if (!visibleSegments.isEmpty()) { 371 readPreferences( layer.getName());354 readPreferences(); 372 355 drawAll(graphics.getDefaultGraphics(), graphics.getMapView(), visibleSegments, clipBounds); 373 356 if (graphics.getMapView().getLayerManager().getActiveLayer() == layer) { … … 431 414 * @since 14748 : new parameter clipBounds 432 415 */ 433 434 416 public void drawAll(Graphics2D g, MapView mv, List<WayPoint> visibleSegments, Bounds clipBounds) { 435 417 … … 463 445 464 446 // global enabled or select via color 465 boolean useHeatMap = heatMapEnabled ||ColorMode.HEATMAP == colored;447 boolean useHeatMap = ColorMode.HEATMAP == colored; 466 448 467 449 // default global alpha level … … 571 553 oldWp = null; 572 554 } else { // color mode not dynamic 573 velocityScale.setRange(0, colorTracksTune);555 velocityScale.setRange(0, velocityTune); 574 556 hdopScale.setRange(0, hdoprange); 575 557 qualityScale.setRange(1, rtkLibQualityColors.length); … … 595 577 for (WayPoint trkPnt : segment) { 596 578 LatLon c = trkPnt.getCoor(); 597 trkPnt.customColoring = neutralColor;579 trkPnt.customColoring = segment.getColor(); 598 580 if (Double.isNaN(c.lat()) || Double.isNaN(c.lon())) { 599 581 continue; … … 643 625 } else { // make sure we reset outdated data 644 626 trkPnt.drawLine = false; 645 color = neutralColor;627 color = segment.getColor(); 646 628 } 647 629 if (color != null) { … … 701 683 ********** STEP 3b - DRAW NICE ARROWS ************************** 702 684 ****************************************************************/ 703 if (lines && direction && !alternateDirection) {685 if (lines && arrows && !arrowsFast) { 704 686 Point old = null; 705 687 Point oldA = null; // last arrow painted … … 713 695 // skip points that are on the same screenposition 714 696 if (old != null 715 && (oldA == null || screen.x < oldA.x - delta || screen.x > oldA.x +delta716 || screen.y < oldA.y - delta || screen.y > oldA.y +delta)) {697 && (oldA == null || screen.x < oldA.x - arrowsDelta || screen.x > oldA.x + arrowsDelta 698 || screen.y < oldA.y - arrowsDelta || screen.y > oldA.y + arrowsDelta)) { 717 699 g.setColor(trkPnt.customColoring); 718 700 double t = Math.atan2((double) screen.y - old.y, (double) screen.x - old.x) + Math.PI; … … 731 713 ********** STEP 3c - DRAW FAST ARROWS ************************** 732 714 ****************************************************************/ 733 if (lines && direction && alternateDirection) {715 if (lines && arrows && arrowsFast) { 734 716 Point old = null; 735 717 Point oldA = null; // last arrow painted … … 743 725 // skip points that are on the same screenposition 744 726 if (old != null 745 && (oldA == null || screen.x < oldA.x - delta || screen.x > oldA.x +delta746 || screen.y < oldA.y - delta || screen.y > oldA.y +delta)) {727 && (oldA == null || screen.x < oldA.x - arrowsDelta || screen.x > oldA.x + arrowsDelta 728 || screen.y < oldA.y - arrowsDelta || screen.y > oldA.y + arrowsDelta)) { 747 729 g.setColor(trkPnt.customColoring); 748 730 g.drawLine(screen.x, screen.y, screen.x + dir[trkPnt.dir][0], screen.y … … 795 777 // color the large GPS points like the gps lines 796 778 if (trkPnt.customColoring != null) { 797 Color customColoringTransparent = largePointAlpha < 0 ? trkPnt.customColoring : 798 new Color((trkPnt.customColoring.getRGB() & 0x00ffffff) | (largePointAlpha << 24), true); 799 800 g.setColor(customColoringTransparent); 779 if (trkPnt.customColoring.equals(colorCache) && colorCacheTransparent != null) { 780 g.setColor(colorCacheTransparent); 781 } else { 782 Color customColoringTransparent = largePointAlpha < 0 ? trkPnt.customColoring : 783 new Color((trkPnt.customColoring.getRGB() & 0x00ffffff) | (largePointAlpha << 24), true); 784 785 g.setColor(customColoringTransparent); 786 colorCache = trkPnt.customColoring; 787 colorCacheTransparent = customColoringTransparent; 788 } 801 789 } 802 790 g.fillRect(screen.x-halfSize, screen.y-halfSize, largesize, largesize); … … 816 804 } 817 805 if (!trkPnt.drawLine) { 806 g.setColor(trkPnt.customColoring); 818 807 Point screen = mv.getPoint(trkPnt); 819 808 g.drawRect(screen.x, screen.y, 0, 0); … … 1481 1470 if ((computeCacheMaxLineLengthUsed != maxLineLength) 1482 1471 || (computeCacheColored != colored) 1483 || (computeCache ColorTracksTune !=colorTracksTune)1472 || (computeCacheVelocityTune != velocityTune) 1484 1473 || (computeCacheColorDynamic != colorModeDynamic) 1485 1474 || (computeCacheHeatMapDrawColorTableIdx != heatMapDrawColorTableIdx) 1486 || (!neutralColor.equals(computeCacheColorUsed)1475 || !Objects.equals(neutralColor, computeCacheColorUsed) 1487 1476 || (computeCacheHeatMapDrawPointMode != heatMapDrawPointMode) 1488 || (computeCacheHeatMapDrawGain != heatMapDrawGain) )1477 || (computeCacheHeatMapDrawGain != heatMapDrawGain) 1489 1478 || (computeCacheHeatMapDrawLowerLimit != heatMapDrawLowerLimit) 1490 1479 ) { … … 1494 1483 computeCacheColorUsed = neutralColor; 1495 1484 computeCacheColored = colored; 1496 computeCache ColorTracksTune =colorTracksTune;1485 computeCacheVelocityTune = velocityTune; 1497 1486 computeCacheColorDynamic = colorModeDynamic; 1498 1487 computeCacheHeatMapDrawColorTableIdx = heatMapDrawColorTableIdx;
Note:
See TracChangeset
for help on using the changeset viewer.
