Ignore:
Timestamp:
2013-01-19T15:50:02+01:00 (13 years ago)
Author:
malcolmh
Message:

save

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/smed2/src/seamap/Renderer.java

    r29202 r29204  
    1616import java.awt.Rectangle;
    1717import java.awt.RenderingHints;
    18 import java.awt.font.TextLayout;
     18import java.awt.geom.AffineTransform;
    1919import java.awt.geom.GeneralPath;
    2020import java.awt.geom.Path2D;
     
    2929import seamap.SeaMap;
    3030import seamap.SeaMap.*;
    31 import symbols.Areas;
    3231import symbols.Symbols;
    3332import symbols.Symbols.*;
     
    145144        }
    146145       
     146        private static Rectangle symbolSize(Symbol symbol) {
     147                Symbol ssymb = symbol;
     148                while (ssymb != null) {
     149                        for (Instr item : symbol) {
     150                                if (item.type == Prim.BBOX) {
     151                                        return (Rectangle) item.params;
     152                                }
     153                                if (item.type == Prim.SYMB) {
     154                                        ssymb = (Symbol) item.params;
     155                                        break;
     156                                }
     157                        }
     158                        if (ssymb == symbol)
     159                                break;
     160                }
     161                return null;
     162        }
     163       
    147164        public static void lineSymbols(Feature feature, Symbol prisymb, double space, Symbol secsymb, int ratio) {
    148165                if (feature.flag != Fflag.NODE) {
    149                         ArrayList<Long> way = map.ways.get(feature.refs);
    150                         for (long node : way) {
    151                                 Point2D point = helper.getPoint(map.nodes.get(node));
    152                                
    153                         }
    154                 }
    155         }
    156        
     166                        Rectangle prect = symbolSize(prisymb);
     167                        Rectangle srect = symbolSize(secsymb);
     168                        if (srect == null)
     169                                ratio = 0;
     170                        if (prect != null) {
     171                                ArrayList<Long> ways = new ArrayList<Long>();
     172                                double psize = Math.abs(prect.getY()) * sScale;
     173                                double ssize = (srect != null) ? Math.abs(srect.getY()) * sScale : 0;
     174                                if (map.outers.containsKey(feature.refs)) {
     175                                        ways.addAll(map.mpolys.get(map.outers.get(feature.refs)));
     176                                } else {
     177                                        if (map.mpolys.containsKey(feature.refs)) {
     178                                                ways.addAll(map.mpolys.get(feature.refs));
     179                                        } else {
     180                                                ways.add(feature.refs);
     181                                        }
     182                                }
     183                                Point2D prev = new Point2D.Double();
     184                                Point2D next = new Point2D.Double();
     185                                Point2D curr = new Point2D.Double();
     186                                Point2D succ = new Point2D.Double();
     187                                boolean gap = true;
     188                                boolean piv = false;
     189                                double len = 0;
     190                                double angle = 0;
     191                                int scount = ratio;
     192                                Symbol symbol = prisymb;
     193                                for (long way : ways) {
     194                                        boolean first = true;
     195                                        for (long node : map.ways.get(way)) {
     196                                                prev = next;
     197                                                next = helper.getPoint(map.nodes.get(node));
     198                                                angle = Math.atan2(next.getY() - prev.getY(), next.getX() - prev.getX());
     199                                                piv = true;
     200                                                if (first) {
     201                                                        curr = succ = next;
     202                                                        gap  = (space > 0);
     203                                                        scount  = ratio;
     204                                                        symbol  = prisymb;
     205                                                        len = gap ? psize * space * 0.5 : psize;
     206                                                        first = false;
     207                                                } else {
     208                                                        while (curr.distance(next) >= len) {
     209                                                                if (piv) {
     210                                                                        succ = new Point2D.Double(prev.getX() + (len * Math.cos(angle)), prev.getY() + (len * Math.sin(angle)));
     211                                                                        piv = false;
     212                                                                } else {
     213                                                                        succ = new Point2D.Double(curr.getX() + (len * Math.cos(angle)), curr.getY() + (len * Math.sin(angle)));
     214                                                                }
     215                                                                if (!gap) {
     216                                                                        Symbols.drawSymbol(g2, symbol, sScale, curr.getX(), curr.getY(), new Delta(Handle.BC, AffineTransform.getRotateInstance(Math.atan2(succ.getY() - curr.getY(), succ.getX() - curr.getX())+Math.toRadians(90))), null);
     217                                                                }
     218                                                                if (space > 0) gap = !gap;
     219                                                                curr = succ;
     220                                        len = gap ? (psize * space) : (--scount == 0) ? ssize : psize;
     221                                        if (scount == 0) {
     222                                          symbol = secsymb;
     223                                          scount = ratio;
     224                                        } else {
     225                                          symbol = prisymb;
     226                                        }
     227                                                        }
     228                                                }
     229                                        }
     230                                }
     231                        }
     232                }
     233        }
     234
    157235        public static void lineVector (Feature feature, LineStyle style) {
    158236                if (feature.flag != Fflag.NODE) {
     
    202280        }
    203281       
    204         public static void labelText (Feature feature, String str, Font font, Delta delta) {
     282        public static void labelText (Feature feature, String str, Font font, Color colour, Delta delta) {
    205283                Symbol label = new Symbol();
    206                 label.add(new Instr(Prim.FILL, Color.black));
    207                 label.add(new Instr(Prim.TEXT, new Caption(str, font, delta)));
     284                label.add(new Instr(Prim.TEXT, new Caption(str, font, colour
     285                                , delta)));
    208286                Point2D point = helper.getPoint(findCentroid(feature));
    209287                Symbols.drawSymbol(g2, label, tScale, point.getX(), point.getY(), delta, null);
Note: See TracChangeset for help on using the changeset viewer.