Ignore:
Timestamp:
2016-06-23T14:17:55+02:00 (9 years ago)
Author:
malcolmh
Message:

updates

Location:
applications/editors/josm/plugins/seachart/src/render
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified applications/editors/josm/plugins/seachart/src/render/Renderer.java

    r32101 r32380  
    391391                if ((str == null) || (str.isEmpty())) str = " ";
    392392    FontRenderContext frc = g2.getFontRenderContext();
    393     GlyphVector gv = font.deriveFont((float)(font.getSize())).createGlyphVector(frc, str.equals(" ") ? "!" : str);
     393    GlyphVector gv = font.deriveFont((float)(font.getSize())).createGlyphVector(frc, str.equals(" ") ? "M" : str);
    394394    Rectangle2D bounds = gv.getVisualBounds();
    395395    double width = bounds.getWidth();
     
    485485        }
    486486
    487         public static void lineText(String str, Font font, Color colour, double offset, double dy) {
     487        public static void lineText(String str, Font font, Color colour, double dy) {
    488488                if (!str.isEmpty()) {
    489489                        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    490             g2.setPaint(colour);
    491             FontRenderContext frc = g2.getFontRenderContext();
    492             GlyphVector gv = font.deriveFont(font.getSize2D() * (float)sScale).createGlyphVector(frc, (" " + str));
    493             GeneralPath path = new GeneralPath();
    494                         Point2D prev = new Point2D.Double();
    495                         Point2D next = new Point2D.Double();
    496                         Point2D curr = new Point2D.Double();
    497                         Point2D succ = new Point2D.Double();
    498                         boolean piv = false;
    499                         double angle = 0;
    500                         int index = 0;
    501                         double gwidth = offset * (Rules.feature.geom.length * context.mile(Rules.feature) - gv.getLogicalBounds().getWidth()) + gv.getGlyphMetrics(0).getAdvance();
    502                         GeomIterator git = map.new GeomIterator(Rules.feature.geom);
    503                         while (git.hasComp()) {
    504                                 git.nextComp();
    505                                 boolean first = true;
    506                                 while (git.hasEdge()) {
    507                                         git.nextEdge();
    508                                         while (git.hasNode()) {
    509                                                 Snode node = git.next();
    510                                                 if (node == null) continue;
    511                                                 prev = next;
    512                                                 next = context.getPoint(node);
    513                                                 angle = Math.atan2(next.getY() - prev.getY(), next.getX() - prev.getX());
    514                                                 piv = true;
    515                                                 if (first) {
    516                                                         curr = succ = next;
    517                                                         first = false;
    518                                                 } else {
    519                                                         while (curr.distance(next) >= gwidth) {
    520                                                                 if (piv) {
    521                                                                         double rem = gwidth;
    522                                                                         double s = prev.distance(next);
    523                                                                         double p = curr.distance(prev);
    524                                                                         if ((s > 0) && (p > 0)) {
    525                                                                                 double n = curr.distance(next);
    526                                                                                 double theta = Math.acos((s * s + p * p - n * n) / 2 / s / p);
    527                                                                                 double phi = Math.asin(p / gwidth * Math.sin(theta));
    528                                                                                 rem = gwidth * Math.sin(Math.PI - theta - phi) / Math.sin(theta);
    529                                                                         }
    530                                                                         succ = new Point2D.Double(prev.getX() + (rem * Math.cos(angle)), prev.getY() + (rem * Math.sin(angle)));
    531                                                                         piv = false;
     490                        g2.setPaint(colour);
     491                        FontRenderContext frc = g2.getFontRenderContext();
     492                        GlyphVector gv = font.deriveFont(font.getSize2D() * (float) sScale).createGlyphVector(frc, str);
     493                        double width = gv.getVisualBounds().getWidth();
     494                        double height = gv.getVisualBounds().getHeight();
     495                        double offset = (Rules.feature.geom.length * context.mile(Rules.feature) - width) / 2;
     496                        if (offset > 0) {
     497                                Point2D before = null;
     498                                Point2D after = null;
     499                                ArrayList<Point2D> between = new ArrayList<>();
     500                                Point2D prev = null;
     501                                Point2D next = null;
     502                                double length = 0;
     503                                double lb = 0;
     504                                double la = 0;
     505                                GeomIterator git = map.new GeomIterator(Rules.feature.geom);
     506                                if (git.hasComp()) {
     507                                        git.nextComp();
     508                                        while (git.hasEdge()) {
     509                                                git.nextEdge();
     510                                                while (git.hasNode()) {
     511                                                        Snode node = git.next();
     512                                                        if (node == null)
     513                                                                continue;
     514                                                        prev = next;
     515                                                        next = context.getPoint(node);
     516                                                        if (prev != null)
     517                                                                length += Math.sqrt(Math.pow((next.getX() - prev.getX()), 2) + Math.pow((next.getY() - prev.getY()), 2));
     518                                                        if (length < offset) {
     519                                                                before = next;
     520                                                                lb = la = length;
     521                                                        } else if (after == null) {
     522                                                                if (length > (offset + width)) {
     523                                                                        after = next;
     524                                                                        la = length;
     525                                                                        break;
    532526                                                                } else {
    533                                                                         succ = new Point2D.Double(curr.getX() + (gwidth * Math.cos(angle)), curr.getY() + (gwidth * Math.sin(angle)));
    534                                                                 }
    535                                                                 Shape shape = gv.getGlyphOutline(index);
    536                                                                 Point2D point = gv.getGlyphPosition(index);
    537                                                                 AffineTransform at = AffineTransform.getTranslateInstance(curr.getX(), curr.getY());
    538                                                                 at.rotate(Math.atan2((succ.getY() - curr.getY()), (succ.getX() - curr.getX())));
    539                                                                 at.translate(-point.getX(), -point.getY() + (dy * sScale));
    540                                                                 path.append(at.createTransformedShape(shape), false);
    541                                                                 curr = succ;
    542                                                                 if (++index < gv.getNumGlyphs()) {
    543                                                                         gwidth = gv.getGlyphMetrics(index).getAdvance();
    544                                                                 } else {
    545                                                                         g2.fill(path);
    546                                                                         return;
     527                                                                        between.add(next);
    547528                                                                }
    548529                                                        }
    549530                                                }
     531                                                if (after != null)
     532                                                        break;
    550533                                        }
     534                                }
     535                                if (after != null) {
     536                                        double angle = Math.atan2((after.getY() - before.getY()), (after.getX() - before.getX()));
     537                                        double rotate = Math.abs(angle) < (Math.PI / 2) ? angle : angle + Math.PI;
     538                                        Point2D mid = new Point2D.Double((before.getX() + after.getX()) / 2, (before.getY() + after.getY()) / 2);
     539                                        Point2D centre = context.getPoint(Rules.feature.geom.centre);
     540                                        AffineTransform pos = AffineTransform.getTranslateInstance(-dy * Math.sin(rotate), dy * Math.cos(rotate));
     541                                        pos.rotate(rotate);
     542                                        pos.translate((mid.getX() - centre.getX()), (mid.getY() - centre.getY()));
     543                                        Symbol label = new Symbol();
     544                                        label.add(new Instr(Form.BBOX, new Rectangle2D.Double((-width / 2), (-height), width, height)));
     545                                        label.add(new Instr(Form.TEXT, new Caption(str, font, colour, new Delta(Handle.BC))));
     546                                        Symbols.drawSymbol(g2, label, sScale, centre.getX(), centre.getY(), null, new Delta(Handle.BC, pos));
    551547                                }
    552548                        }
     
    580576                }
    581577                if ((str != null) && (!str.isEmpty())) {
    582                         FontRenderContext frc = g2.getFontRenderContext();
    583578                        Font font = new Font("Arial", Font.PLAIN, 40);
    584                         GlyphVector gv = font.deriveFont(font.getSize2D() * (float)sScale).createGlyphVector(frc, str);
    585579                        double arc = (s2 > s1) ? (s2 - s1) : (s2 - s1 + 360);
    586580                        double awidth = (Math.toRadians(arc) * radial);
     
    589583                        radial += 30 * sScale;
    590584                        AffineTransform at = AffineTransform.getTranslateInstance(-radial * Math.sin(phi) / sScale, radial * Math.cos(phi) / sScale);
    591                         if (gv.getLogicalBounds().getWidth() < awidth) {
     585                        if ((font.getSize() * sScale * str.length()) < awidth) {
    592586                                at.rotate(Math.toRadians(mid + (hand ? 0 : 180)));
    593                                 Renderer.labelText(str, font, Color.black, new Delta(Handle.CC, at));
    594                         } else if (gv.getLogicalBounds().getHeight() < awidth) {
     587                                labelText(str, font, Color.black, new Delta(Handle.CC, at));
     588                        } else if ((font.getSize() * sScale) < awidth) {
    595589                                hand = (mid < 180);
    596590                                at.rotate(Math.toRadians(mid + (hand ? -90 : 90)));
    597                                 Renderer.labelText(str, font, Color.black, hand ? new Delta(Handle.RC, at) : new Delta(Handle.LC, at));
     591                                labelText(str, font, Color.black, hand ? new Delta(Handle.RC, at) : new Delta(Handle.LC, at));
    598592                        }
    599593                        if (dir != null) {
     
    605599                                at = AffineTransform.getTranslateInstance(-radial * Math.sin(phi) / sScale, radial * Math.cos(phi) / sScale);
    606600                                at.rotate(Math.toRadians(dir + (hand ? 90 : -90)));
    607                                 Renderer.labelText(str, font, Color.black, hand ? new Delta(Handle.BR, at) : new Delta(Handle.BL, at));
     601                                labelText(str, font, Color.black, hand ? new Delta(Handle.BR, at) : new Delta(Handle.BL, at));
    608602                        }
    609603                }
  • TabularUnified applications/editors/josm/plugins/seachart/src/render/Rules.java

    r32105 r32380  
    215215                        if (testObject(Obj.ROADWY)) for (Feature f : objects) if (testFeature(f)) highways();
    216216                        if (testObject(Obj.RAILWY)) for (Feature f : objects) if (testFeature(f)) highways();
     217                }
     218                if (Renderer.context.ruleset() == RuleSet.ALL) {
     219                        if (testObject(Obj.SOUNDG)) for (Feature f : objects) if (testFeature(f)) depths();
     220                        if (testObject(Obj.DEPCNT)) for (Feature f : objects) if (testFeature(f)) depths();
    217221                }
    218222                if (testObject(Obj.SLCONS)) for (Feature f : objects) if (testFeature(f)) shoreline();
     
    388392                                if ((Renderer.zoom >= 10) && (name != null))
    389393                                        if (feature.geom.prim == Pflag.LINE) {
    390                                                 Renderer.lineText(name, new Font("Arial", Font.PLAIN, 150), Color.black, 0.5, -40);
     394                                                Renderer.lineText(name, new Font("Arial", Font.PLAIN, 150), Color.black, -40);
    391395                                        } else {
    392396                                                Renderer.labelText(name, new Font("Arial", Font.PLAIN, 150), Color.black, new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, -40)));
     
    396400                                if ((Renderer.zoom >= 12) && (name != null))
    397401                                        if (feature.geom.prim == Pflag.LINE) {
    398                                                 Renderer.lineText(name, new Font("Arial", Font.PLAIN, 150), Color.black, 0.5, -40);
     402                                                Renderer.lineText(name, new Font("Arial", Font.PLAIN, 150), Color.black, -40);
    399403                                        } else {
    400404                                                Renderer.labelText(name, new Font("Arial", Font.PLAIN, 150), Color.black, new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, -40)));
     
    411415                                        } else if (feature.geom.prim == Pflag.LINE) {
    412416                                                if (name != null) {
    413                                                         Renderer.lineText(name, new Font("Arial", Font.ITALIC, 75), Color.black, 0.5, -40);
    414                                                         Renderer.lineText("(Shoal)", new Font("Arial", Font.PLAIN, 60), Color.black, 0.5, 0);
     417                                                        Renderer.lineText(name, new Font("Arial", Font.ITALIC, 75), Color.black, -40);
     418                                                        Renderer.lineText("(Shoal)", new Font("Arial", Font.PLAIN, 60), Color.black, 0);
    415419                                                }
    416420                                        } else {
     
    503507                                }
    504508                        }
     509                        if (hasObject(Obj.NOTMRK))
     510                                notices();
    505511                        addName(15, new Font("Arial", Font.BOLD, 40), new Delta(Handle.BL, AffineTransform.getTranslateInstance(60, -50)));
    506512                        Signals.addSignals();
     
    608614                                Renderer.labelText(("Ch." + chn), new Font("Arial", Font.PLAIN, 50), Color.black, new Delta(Handle.TC, AffineTransform.getTranslateInstance(0,50)));
    609615                        }
     616                }
     617        }
     618       
     619        private static void depths() {
     620                switch (feature.type) {
     621                case SOUNDG:
     622                        if ((Renderer.zoom >= 14) && hasAttribute(Obj.SOUNDG, Att.VALSOU)) {
     623                                double depth = (double)getAttVal(Obj.SOUNDG, Att.VALSOU);
     624                                String dstr = df.format(depth);
     625                                String tok[] = dstr.split("[-.]");
     626                                String ul = "";
     627                                String id = tok[0];
     628                                String dd = "";
     629                                if (tok[0].equals("")) {
     630                                        for (int i = 0; i <  tok[1].length(); i++)
     631                                                ul += "_";
     632                                        id = tok[1];
     633                                        dd = (tok.length == 3) ? tok[2] : "";
     634                                } else {
     635                                        dd = (tok.length == 2) ? tok[1] : "";
     636                                }
     637                                Renderer.labelText(ul, new Font("Arial", Font.PLAIN, 30), Color.black, new Delta(Handle.RC, AffineTransform.getTranslateInstance(10,15)));
     638                                Renderer.labelText(id, new Font("Arial", Font.PLAIN, 30), Color.black, new Delta(Handle.RC, AffineTransform.getTranslateInstance(10,0)));
     639                                Renderer.labelText(dd, new Font("Arial", Font.PLAIN, 20), Color.black, new Delta(Handle.LC, AffineTransform.getTranslateInstance(15,10)));
     640                        }
     641                        break;
     642                case DEPCNT:
     643                        break;
     644                default:
     645                        break;
    610646                }
    611647        }
     
    700736                case ACHBRT:
    701737                        if (Renderer.zoom >= 14) {
    702                                 Renderer.symbol(Harbours.Anchorage, new Scheme(Symbols.Mline));
     738                                Renderer.symbol(Harbours.Anchor, new Scheme(Symbols.Msymb));
    703739                                if (Renderer.zoom >= 15) {
    704                                         Renderer.labelText(name == null ? "" : name, new Font("Arial", Font.PLAIN, 30), Symbols.Msymb, LabelStyle.RRCT, Symbols.Mline, Color.white, new Delta(Handle.BC));
     740                                        Renderer.labelText(name == null ? "" : name, new Font("Arial", Font.PLAIN, 30), Symbols.Msymb, LabelStyle.RRCT, Symbols.Msymb, Color.white, new Delta(Handle.BC));
    705741                                }
    706742                        }
     
    9931029        }
    9941030
     1031        @SuppressWarnings("unchecked")
    9951032        private static void notices() {
    9961033                if (Renderer.zoom >= 14) {
     
    10021039                        case BCNSAW:
    10031040                        case BCNSPP:
    1004                                 dy = 45.0;
     1041                                if (testAttribute(Obj.TOPMAR, Att.TOPSHP, TopSHP.TOP_BORD) || testAttribute(Obj.DAYMAR, Att.TOPSHP, TopSHP.TOP_BORD)) {
     1042                                        dy = -100.0;
     1043                                } else {
     1044                                        dy = -45.0;
     1045                                }
    10051046                                break;
    10061047                        case NOTMRK:
     
    10231064                                int i = 0;
    10241065                                for (AttMap atts : objs.values()) {
    1025                                         if (atts.get(Att.MARSYS) != null) sys = (MarSYS)(getAttEnum(Obj.NOTMRK, Att.MARSYS));
    1026                                         if (atts.get(Att.BNKWTW) != null) bnk = (BnkWTW)(getAttEnum(Obj.NOTMRK, Att.BNKWTW));
     1066                                        if (atts.get(Att.MARSYS) != null) sys = ((ArrayList<MarSYS>)(atts.get(Att.MARSYS).val)).get(0);
     1067                                        if (atts.get(Att.BNKWTW) != null) bnk = ((ArrayList<BnkWTW>)(atts.get(Att.BNKWTW).val)).get(0);
    10271068                                        CatNMK cat = CatNMK.NMK_UNKN;
    1028                                         if (atts.get(Att.CATNMK) != null) cat = (CatNMK)(getAttEnum(Obj.NOTMRK, Att.CATNMK));
     1069                                        if (atts.get(Att.CATNMK) != null) cat = ((ArrayList<CatNMK>)(atts.get(Att.CATNMK).val)).get(0);
    10291070                                        Symbol sym = Notices.getNotice(cat, sys, bnk);
    10301071                                        Scheme sch = Notices.getScheme(sys, bnk);
     1072                                        ArrayList<AddMRK> add = new ArrayList<>();
     1073                                        if (atts.get(Att.ADDMRK) != null) add = (ArrayList<AddMRK>)(atts.get(Att.ADDMRK).val);
    10311074                                        Handle h = Handle.CC;
     1075                                        double ax = 0.0;
     1076                                        double ay = 0.0;
    10321077                                        switch (i) {
    10331078                                        case 0:
     
    10351080                                                break;
    10361081                                        case 1:
    1037                                                 if (n <= 3)
     1082                                                if (n <= 3) {
    10381083                                                        h = Handle.RC;
    1039                                                 else
     1084                                                        ax = -30;
     1085                                                        ay = dy;
     1086                                                }
     1087                                                else {
    10401088                                                        h = Handle.BR;
     1089                                                }
    10411090                                                break;
    10421091                                        case 2:
     
    10561105                                                break;
    10571106                                        }
    1058                                         if (h != null) Renderer.symbol(sym, sch, new Delta(h, AffineTransform.getTranslateInstance(dx, dy)));
     1107                                        if (h != null) {
     1108                                                Renderer.symbol(sym, sch, new Delta(h, AffineTransform.getTranslateInstance(dx, dy)));
     1109                                                if (!add.isEmpty()) Renderer.symbol(Notices.NoticeBoard, new Delta(Handle.BC, AffineTransform.getTranslateInstance(ax, ay - 30)));
     1110                                        }
    10591111                                        i++;
    10601112                                }
     
    10691121                                Renderer.lineVector(new LineStyle(Color.black, 5, new float[] { 20, 20 }, null));
    10701122                                if (Renderer.zoom >= 15) {
    1071                                         Renderer.lineText("Boom", new Font("Arial", Font.PLAIN, 80), Color.black, 0.5, -20);
     1123                                        Renderer.lineText("Boom", new Font("Arial", Font.PLAIN, 80), Color.black, -20);
    10721124                                }
    10731125                        default:
     
    11861238                                                Renderer.lineVector(new LineStyle(Color.black, 10, new float[] { 40, 40 }, null));
    11871239                                                if (Renderer.zoom >= 15)
    1188                                                         Renderer.lineText("(covers)", new Font("Arial", Font.PLAIN, 60), Color.black, 0.5, 80);
     1240                                                        Renderer.lineText("(covers)", new Font("Arial", Font.PLAIN, 60), Color.black, 80);
    11891241                                        } else {
    11901242                                                Renderer.lineVector(new LineStyle(Color.black, 10, null, null));
    11911243                                        }
    11921244                                        if (Renderer.zoom >= 15)
    1193                                                 Renderer.lineText("Training Wall", new Font("Arial", Font.PLAIN, 60), Color.black, 0.5, -30);
     1245                                                Renderer.lineText("Training Wall", new Font("Arial", Font.PLAIN, 60), Color.black, -30);
    11941246                                        break;
    11951247                                case SLC_SWAY:
     
    13331385                                str += df.format(ort) + "º";
    13341386                                if (!str.isEmpty())
    1335                                         Renderer.lineText(str, new Font("Arial", Font.PLAIN, 80), Color.black, 0.5, -20);
     1387                                        Renderer.lineText(str, new Font("Arial", Font.PLAIN, 80), Color.black, -20);
    13361388                        }
    13371389                }
Note: See TracChangeset for help on using the changeset viewer.