Ignore:
Timestamp:
2008-07-14T22:21:09+02:00 (16 years ago)
Author:
ramack
Message:

patch from Henry Loenwind, closes #720 and #966

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java

    r650 r721  
    7777        protected static final double PHI = Math.toRadians(15);
    7878        private boolean computeCacheInSync;
    79         private int computeCacheMaxLineLingthUsed;
     79        private int computeCacheMaxLineLengthUsed;
     80        private Color computeCacheColorUsed;
     81        private boolean computeCacheColored;
    8082       
    8183        public GpxLayer(GpxData d) {
     
    352354
    353355        @Override public void paint(Graphics g, MapView mv) {
     356
     357                /****************************************************************
     358                 ********** STEP 1 - GET CONFIG VALUES **************************
     359                 ****************************************************************/
     360                Long startTime = System.currentTimeMillis();
    354361                String gpsCol = Main.pref.get("color.gps point");
    355362                String gpsColSpecial = Main.pref.get("color.layer "+name);
     
    362369                        neutralColor = Color.GRAY;
    363370                }
    364                 g.setColor(neutralColor);
    365                
    366371                boolean forceLines = Main.pref.getBoolean("draw.rawgps.lines.force");                     // also draw lines between points belonging to different segments
    367372                boolean direction = Main.pref.getBoolean("draw.rawgps.direction");                        // draw direction arrows on the lines
    368                 int maxLineLength = Integer.parseInt(Main.pref.get("draw.rawgps.max-line-length", "-1")); // don't draw lines if longer than x meters
     373                int maxLineLength = -1;
     374                try {
     375                        maxLineLength = Integer.parseInt(Main.pref.get("draw.rawgps.max-line-length", "-1"));   // don't draw lines if longer than x meters
     376                } catch (java.lang.NumberFormatException e) {
     377                        Main.pref.put("draw.rawgps.max-line-length", "-1");
     378                }
    369379                boolean lines = Main.pref.getBoolean("draw.rawgps.lines");                                // draw line between points, global setting
    370380                String linesKey = "draw.rawgps.lines.layer "+name;
     
    374384                boolean colored = Main.pref.getBoolean("draw.rawgps.colors");                             // color the lines
    375385                boolean alternatedirection = Main.pref.getBoolean("draw.rawgps.alternatedirection");      // paint direction arrow with alternate math. may be faster
    376                 boolean trianglelines = Main.pref.getBoolean("draw.rawgps.trianglelines");                // paint lines as 2 lines
    377 
    378                 if (computeCacheInSync && computeCacheMaxLineLingthUsed != maxLineLength) {
     386
     387                /****************************************************************
     388                 ********** STEP 2a - CHECK CACHE VALIDITY **********************
     389                 ****************************************************************/
     390                if (computeCacheInSync && ((computeCacheMaxLineLengthUsed != maxLineLength) ||
     391                                           (!neutralColor.equals(computeCacheColorUsed)) ||
     392                                           (computeCacheColored != colored))) {
     393                        System.out.println("(re-)computing gpx line styles, reason: CCIS=" + computeCacheInSync + " CCMLLU=" + (computeCacheMaxLineLengthUsed != maxLineLength) + " CCCU=" +  (!neutralColor.equals(computeCacheColorUsed)) + " CCC=" + (computeCacheColored != colored));
     394                        computeCacheMaxLineLengthUsed = maxLineLength;
    379395                        computeCacheInSync = false;
    380                 }
    381 
    382                 if (!computeCacheInSync && lines) { // don't compute if the cache is good or if there are no lines to draw at all
    383                         //System.out.println("(re-)computing gpx line styles, reason: CCIS=" + computeCacheInSync + " L=" + lines);
     396                        computeCacheColorUsed = neutralColor;
     397                        computeCacheColored = colored;
     398                }
     399
     400                /****************************************************************
     401                 ********** STEP 2b - RE-COMPUTE CACHE DATA *********************
     402                 ****************************************************************/
     403                if (!computeCacheInSync) { // don't compute if the cache is good
    384404                WayPoint oldWp = null;
    385405                for (GpxTrack trk : data.tracks) {
     
    397417                                                double vel = dist/dtime;
    398418
    399                                                         if (dtime <= 0 || vel < 0 || vel > 36) { // attn: bad case first
     419                                                        if (!colored) {
     420                                                                trkPnt.speedLineColor = neutralColor;
     421                                                        } else if (dtime <= 0 || vel < 0 || vel > 36) { // attn: bad case first
    400422                                                                trkPnt.speedLineColor = colors[255];
    401423                                                        } else {
     
    417439                        }
    418440                        computeCacheInSync = true;
    419                         computeCacheMaxLineLingthUsed = maxLineLength;
    420441                }
    421442                                               
     443                /****************************************************************
     444                 ********** STEP 3a - DRAW LINES ********************************
     445                 ****************************************************************/
     446                if (lines) {
    422447                Point old = null;
    423448                for (GpxTrack trk : data.tracks) {
     
    427452                                                continue;
    428453                                        Point screen = mv.getPoint(trkPnt.eastNorth);
    429                                         if (lines && trkPnt.drawLine) {
    430                                                 if ((old.x != screen.x) || (old.y != screen.y)) { // skip points that are on the same screenposition
    431                                                         if (colored) {
     454                                                if (trkPnt.drawLine) {
     455                                                        if (old != null && ((old.x != screen.x) || (old.y != screen.y))) { // skip points that are on the same screenposition
    432456                                                                g.setColor(trkPnt.speedLineColor);
    433                                                         }
    434                                                         if (trianglelines) { // fast
    435                                                                 g.drawLine(screen.x, screen.y, old.x + dir[trkPnt.dir][0], old.y + dir[trkPnt.dir][1]);
    436                                                                 g.drawLine(screen.x, screen.y, old.x + dir[trkPnt.dir][2], old.y + dir[trkPnt.dir][3]);
    437                                                         } else { // slow
    438457                                                g.drawLine(old.x, old.y, screen.x, screen.y);
    439458                                                        }
    440                                                 if (direction) {
    441                                                                 if (alternatedirection) { // a little bit faster
    442                                                                         g.drawLine(screen.x, screen.y, screen.x + dir[trkPnt.dir][0], screen.y + dir[trkPnt.dir][1]);
    443                                                                         g.drawLine(screen.x, screen.y, screen.x + dir[trkPnt.dir][2], screen.y + dir[trkPnt.dir][3]);
    444                                                                 } else { // a tiny bit slower, may not make a difference at all
     459                                                }
     460                                                old = screen;
     461                                        } // end for trkpnt
     462                                } // end for segment
     463                        } // end for trk
     464                } // end if lines
     465
     466                /****************************************************************
     467                 ********** STEP 3b - DRAW NICE ARROWS **************************
     468                 ****************************************************************/
     469                if (lines && direction && !alternatedirection) {
     470                        Point old = null;
     471                        for (GpxTrack trk : data.tracks) {
     472                                for (Collection<WayPoint> segment : trk.trackSegs) {
     473                                        for (WayPoint trkPnt : segment) {
     474                                                if (Double.isNaN(trkPnt.latlon.lat()) || Double.isNaN(trkPnt.latlon.lon()))
     475                                                        continue;
     476                                                if (trkPnt.drawLine) {
     477                                                        Point screen = mv.getPoint(trkPnt.eastNorth);
     478                                                        if (old != null && ((old.x != screen.x) || (old.y != screen.y))) { // skip points that are on the same screenposition
     479                                                                g.setColor(trkPnt.speedLineColor);
    445480                                                    double t = Math.atan2(screen.y-old.y, screen.x-old.x) + Math.PI;
    446481                                                    g.drawLine(screen.x,screen.y, (int)(screen.x + 10*Math.cos(t-PHI)), (int)(screen.y + 10*Math.sin(t-PHI)));
    447482                                                    g.drawLine(screen.x,screen.y, (int)(screen.x + 10*Math.cos(t+PHI)), (int)(screen.y + 10*Math.sin(t+PHI)));
    448483                                                }
     484                                                        old = screen;
    449485                                                        }
     486                                        } // end for trkpnt
     487                                } // end for segment
     488                        } // end for trk
     489                } // end if lines
     490
     491                /****************************************************************
     492                 ********** STEP 3c - DRAW FAST ARROWS **************************
     493                 ****************************************************************/
     494                if (lines && direction && alternatedirection) {
     495                        Point old = null;
     496                        for (GpxTrack trk : data.tracks) {
     497                                for (Collection<WayPoint> segment : trk.trackSegs) {
     498                                        for (WayPoint trkPnt : segment) {
     499                                                if (Double.isNaN(trkPnt.latlon.lat()) || Double.isNaN(trkPnt.latlon.lon()))
     500                                                        continue;
     501                                                if (trkPnt.drawLine) {
     502                                                        Point screen = mv.getPoint(trkPnt.eastNorth);
     503                                                        if (old != null && ((old.x != screen.x) || (old.y != screen.y))) { // skip points that are on the same screenposition
     504                                                                g.setColor(trkPnt.speedLineColor);
     505                                                                g.drawLine(screen.x, screen.y, screen.x + dir[trkPnt.dir][0], screen.y + dir[trkPnt.dir][1]);
     506                                                                g.drawLine(screen.x, screen.y, screen.x + dir[trkPnt.dir][2], screen.y + dir[trkPnt.dir][3]);
    450507                                                }
    451                                             }else{
    452                                                 if (colored) { // reset color for non-line drawing if lines are variable colored
    453                                                         g.setColor(neutralColor);
     508                                                        old = screen;
    454509                                            }
     510                                        } // end for trkpnt
     511                                } // end for segment
     512                        } // end for trk
     513                } // end if lines
     514
     515                /****************************************************************
     516                 ********** STEP 3d - DRAW LARGE POINTS *************************
     517                 ****************************************************************/
    455518                                                if (large) {
     519                        g.setColor(neutralColor);
     520                        for (GpxTrack trk : data.tracks) {
     521                                for (Collection<WayPoint> segment : trk.trackSegs) {
     522                                        for (WayPoint trkPnt : segment) {
     523                                                if (Double.isNaN(trkPnt.latlon.lat()) || Double.isNaN(trkPnt.latlon.lon()))
     524                                                        continue;
     525                                                Point screen = mv.getPoint(trkPnt.eastNorth);
    456526                                                        g.fillRect(screen.x-1, screen.y-1, 3, 3);
    457                                                 } else {
     527                                        } // end for trkpnt
     528                                } // end for segment
     529                        } // end for trk
     530                } // end if large
     531
     532                /****************************************************************
     533                 ********** STEP 3e - DRAW SMALL POINTS FOR LINES ***************
     534                 ****************************************************************/
     535                if (!large && lines){
     536                        g.setColor(neutralColor);
     537                        for (GpxTrack trk : data.tracks) {
     538                                for (Collection<WayPoint> segment : trk.trackSegs) {
     539                                        for (WayPoint trkPnt : segment) {
     540                                                if (Double.isNaN(trkPnt.latlon.lat()) || Double.isNaN(trkPnt.latlon.lon()))
     541                                                        continue;
     542                                                if (!trkPnt.drawLine) {
     543                                                        Point screen = mv.getPoint(trkPnt.eastNorth);
    458544                                                g.drawRect(screen.x, screen.y, 0, 0);
    459545                                        }
    460                                         }
    461                                         old = screen;
    462                                 }
    463                         }
    464                 }
    465         }
     546                                        } // end for trkpnt
     547                                } // end for segment
     548                        } // end for trk
     549                } // end if large
     550
     551                /****************************************************************
     552                 ********** STEP 3f - DRAW SMALL POINTS INSTEAD OF LINES ********
     553                 ****************************************************************/
     554                if (!large && !lines){
     555                        g.setColor(neutralColor);
     556                        for (GpxTrack trk : data.tracks) {
     557                                for (Collection<WayPoint> segment : trk.trackSegs) {
     558                                        for (WayPoint trkPnt : segment) {
     559                                                if (Double.isNaN(trkPnt.latlon.lat()) || Double.isNaN(trkPnt.latlon.lon()))
     560                                                        continue;
     561                                                Point screen = mv.getPoint(trkPnt.eastNorth);
     562                                                g.drawRect(screen.x, screen.y, 0, 0);
     563                                        } // end for trkpnt
     564                                } // end for segment
     565                        } // end for trk
     566                } // end if large
     567
     568        Long duration = System.currentTimeMillis() - startTime;
     569        //System.out.println(duration);
     570
     571        } // end paint
    466572
    467573        @Override public void visitBoundingBox(BoundingXYVisitor v) {
  • trunk/src/org/openstreetmap/josm/gui/preferences/DrawingPreference.java

    r627 r721  
    88
    99import javax.swing.JCheckBox;
     10import javax.swing.JLabel;
     11import javax.swing.JTextField;
    1012
    1113import org.openstreetmap.josm.Main;
     
    1517
    1618        private JCheckBox drawRawGpsLines = new JCheckBox(tr("Draw lines between raw gps points."));
     19        private JTextField drawRawGpsMaxLineLength = new JTextField(8);
    1720        private JCheckBox forceRawGpsLines = new JCheckBox(tr("Force lines if no segments imported."));
    1821        private JCheckBox largeGpsPoints = new JCheckBox(tr("Draw large GPS points."));
     
    2023        private JCheckBox directionHint = new JCheckBox(tr("Draw Direction Arrows"));
    2124        private JCheckBox drawGpsArrows = new JCheckBox(tr("Draw Direction Arrows"));
     25        private JCheckBox drawGpsArrowsFast = new JCheckBox(tr("Fast drawing (looks uglier)"));
    2226        private JCheckBox interestingDirections = new JCheckBox(tr("Only interesting direction hints (e.g. with oneway tag)."));
    2327        private JCheckBox segmentOrderNumber = new JCheckBox(tr("Draw segment order numbers"));
     
    2933                drawRawGpsLines.addActionListener(new ActionListener(){
    3034                        public void actionPerformed(ActionEvent e) {
    31                             if (!drawRawGpsLines.isSelected()){
    32                                 forceRawGpsLines.setSelected(false);
    33                                 drawGpsArrows.setSelected(false);
    34                             }
    3535                            forceRawGpsLines.setEnabled(drawRawGpsLines.isSelected());
     36                            drawRawGpsMaxLineLength.setEnabled(drawRawGpsLines.isSelected());
    3637                            drawGpsArrows.setEnabled(drawRawGpsLines.isSelected());
     38                            drawGpsArrowsFast.setEnabled(drawGpsArrows.isSelected() && drawGpsArrows.isEnabled());
    3739                            colorTracks.setEnabled(drawRawGpsLines.isSelected());
    3840                        }
     
    4143                drawRawGpsLines.setToolTipText(tr("If your gps device draw too few lines, select this to draw lines along your way."));
    4244                gui.display.add(drawRawGpsLines, GBC.eol().insets(20,0,0,0));
     45
     46                // drawRawGpsMaxLineLength
     47                drawRawGpsMaxLineLength.setText(Main.pref.get("draw.rawgps.max-line-length", "-1"));
     48                drawRawGpsMaxLineLength.setToolTipText(tr("Maximum length (in meters) to draw lines. Set to '-1' to draw all lines."));
     49                drawRawGpsMaxLineLength.setEnabled(drawRawGpsLines.isSelected());
     50                gui.display.add(new JLabel(tr("Maximum length (meters)")), GBC.std().insets(40,0,0,0));
     51                gui.display.add(drawRawGpsMaxLineLength, GBC.eol().fill(GBC.HORIZONTAL).insets(5,0,0,5));
    4352
    4453                // forceRawGpsLines
     
    4958               
    5059                // drawGpsArrows
     60                drawGpsArrows.addActionListener(new ActionListener(){
     61                        public void actionPerformed(ActionEvent e) {
     62                            drawGpsArrowsFast.setEnabled(drawGpsArrows.isSelected() && drawGpsArrows.isEnabled());
     63                        }
     64                });
    5165                drawGpsArrows.setToolTipText(tr("Draw direction arrows for lines, connecting GPS points."));
    5266                drawGpsArrows.setSelected(Main.pref.getBoolean("draw.rawgps.direction"));
    5367                drawGpsArrows.setEnabled(drawRawGpsLines.isSelected());
    5468                gui.display.add(drawGpsArrows, GBC.eop().insets(40,0,0,0));
     69
     70                // drawGpsArrowsFast
     71                drawGpsArrowsFast.setToolTipText(tr("Draw the direction arrows using table lookups instead of complex math."));
     72                drawGpsArrowsFast.setSelected(Main.pref.getBoolean("draw.rawgps.alternatedirection"));
     73                drawGpsArrowsFast.setEnabled(drawGpsArrows.isSelected() && drawGpsArrows.isEnabled());
     74                gui.display.add(drawGpsArrowsFast, GBC.eop().insets(60,0,0,0));
    5575
    5676                // colorTracks
     
    7696                        }
    7797                });
    78                 directionHint.setToolTipText(tr("Draw direction hints for segments."));
     98                directionHint.setToolTipText(tr("Draw direction hints for way segments."));
    7999                directionHint.setSelected(Main.pref.getBoolean("draw.segment.direction"));
    80100                gui.display.add(directionHint, GBC.eop().insets(20,0,0,0));
     
    104124        public void ok() {
    105125                Main.pref.put("draw.rawgps.lines", drawRawGpsLines.isSelected());
     126                Main.pref.put("draw.rawgps.max-line-length", drawRawGpsMaxLineLength.getText());
    106127                Main.pref.put("draw.rawgps.lines.force", forceRawGpsLines.isSelected());
    107128                Main.pref.put("draw.rawgps.direction", drawGpsArrows.isSelected());
     129                Main.pref.put("draw.rawgps.alternatedirection", drawGpsArrowsFast.isSelected());
    108130                Main.pref.put("draw.rawgps.colors", colorTracks.isSelected());
    109131                Main.pref.put("draw.rawgps.large", largeGpsPoints.isSelected());
Note: See TracChangeset for help on using the changeset viewer.