Changeset 30339 in osm for applications/editors


Ignore:
Timestamp:
2014-03-24T15:05:25+01:00 (11 years ago)
Author:
malcolmh
Message:

save

Location:
applications/editors/josm/plugins/smed2/src
Files:
4 edited

Legend:

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

    r30333 r30339  
    1818import s57.S57val.*;
    1919import s57.S57map;
     20import s57.S57att.Att;
    2021import s57.S57map.*;
    2122import symbols.Areas;
     
    346347                }
    347348        }
    348 
     349       
    349350        public static void labelText(Feature feature, String str, Font font, Color tc) {
    350351                labelText(feature, str, font, tc, LabelStyle.NONE, null, null, null);
  • applications/editors/josm/plugins/smed2/src/render/Rules.java

    r30333 r30339  
    7474        }
    7575
     76        public static void addName(Feature feature, int z, Font font) {
     77                addName(feature, z, font, Color.black, new Delta(Handle.CC, new AffineTransform()));
     78        }
     79        public static void addName(Feature feature, int z, Font font, Color colour) {
     80                addName(feature, z, font, colour, new Delta(Handle.CC, new AffineTransform()));
     81        }
     82        public static void addName(Feature feature, int z, Font font, Delta delta) {
     83                addName(feature, z, font, Color.black, delta);
     84        }
     85        public static void addName(Feature feature, int z, Font font, Color colour, Delta delta) {
     86                if (Renderer.zoom >= z) {
     87                        String name = getName(feature);
     88                        if (name != null) {
     89                                Renderer.labelText(feature, name, font,  colour, delta);
     90                        }
     91                }
     92        }
     93
    7694        static AttMap getAtts(Feature feature, Obj obj, int idx) {
    7795                HashMap<Integer, AttMap> objs = feature.objs.get(obj);
     
    109127        }
    110128       
    111         static boolean hasObject(Feature feature, Obj obj) {
    112                 return (feature.objs.containsKey(obj));
    113         }
    114        
    115         static boolean hasAttribute(Feature feature, Obj obj, Att att) {
    116                 AttMap atts = getAtts(feature, obj, 0);
    117                 return ((atts != null) && (atts.containsKey(att)));
    118         }
    119        
    120         static boolean testAttribute(Feature feature, Obj obj, Att att, Object val) {
    121                 AttMap atts = getAtts(feature, obj, 0);
     129        static boolean testAttribute(Feature feature, Obj obj, int idx, Att att, Object val) {
     130                AttMap atts = getAtts(feature, obj, idx);
    122131                if (atts != null) {
    123132                        AttVal item = atts.get(att);
     
    221230                        else
    222231                                Renderer.lineVector(feature, new LineStyle(Color.black, 8, new float[] { 25, 25 }));
    223                         if ((Renderer.zoom >= 12) && (name != null))
    224                                 Renderer.labelText(feature, name, new Font("Arial", Font.PLAIN, 100), Color.black);
     232                        addName(feature, 12, new Font("Arial", Font.PLAIN, 100), new Delta(Handle.CC, new AffineTransform()));
    225233                        break;
    226234                case FAIRWY:
     
    246254                        break;
    247255                case OSPARE:
    248                         if (testAttribute(feature, feature.type, Att.CATPRA, CatPRA.PRA_WFRM)) {
     256                        if (testAttribute(feature, feature.type, 0, Att.CATPRA, CatPRA.PRA_WFRM)) {
    249257                                Renderer.symbol(feature, Areas.WindFarm);
    250258                                Renderer.lineVector(feature, new LineStyle(Color.black, 20, new float[] { 40, 40 }));
    251                                 if ((Renderer.zoom >= 15) && (name != null))
    252                                         Renderer.labelText(feature, name, new Font("Arial", Font.BOLD, 80), Color.black, new Delta(Handle.TC, AffineTransform.getTranslateInstance(0, 10)));
     259                                addName(feature, 15, new Font("Arial", Font.BOLD, 80), new Delta(Handle.TC, AffineTransform.getTranslateInstance(0, 10)));
    253260                        }
    254261                        break;
    255262                case RESARE:
     263                case MIPARE:
    256264                        if (Renderer.zoom >= 12) {
    257265                                Renderer.lineSymbols(feature, Areas.Restricted, 1.0, null, null, 0, Mline);
    258                                 if (testAttribute(feature, feature.type, Att.CATREA, CatREA.REA_NWAK)) {
     266                                if (testAttribute(feature, feature.type, 0, Att.CATREA, CatREA.REA_NWAK)) {
    259267                                        Renderer.symbol(feature, Areas.NoWake);
    260268                                }
     
    302310                        case SEA_GAT:
    303311                        case SEA_NRRW:
    304                                 if ((Renderer.zoom >= 12) && (name != null))
    305                                         Renderer.labelText(feature, name, new Font("Arial", Font.PLAIN, 100), Color.black);
     312                                addName(feature, 12, new Font("Arial", Font.PLAIN, 100));
    306313                                break;
    307314                        default:
     
    317324                                Renderer.lineSymbols(feature, Areas.Restricted, 0.5, Areas.LinePlane, null, 10, Mline);
    318325                        }
    319                         if ((Renderer.zoom >= 15) && (name != null))
    320                                 Renderer.labelText(feature, name, new Font("Arial", Font.BOLD, 80), Color.black, new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, -90)));
     326                        addName(feature, 15, new Font("Arial", Font.BOLD, 80), new Delta(Handle.BC, AffineTransform.getTranslateInstance(0, -90)));
    321327                        break;
    322328                default:
     
    352358                        } else {
    353359                                Renderer.symbol(feature, Beacons.Shapes.get(shape), getScheme(feature, feature.type));
    354                                 if (hasObject(feature, Obj.TOPMAR)) {
     360                                if (feature.objs.containsKey(Obj.TOPMAR)) {
    355361                                        Symbol topmark = Topmarks.Shapes.get(feature.objs.get(Obj.TOPMAR).get(0).get(Att.TOPSHP).val);
    356362                                        if (topmark != null)
    357363                                                Renderer.symbol(feature, Topmarks.Shapes.get(feature.objs.get(Obj.TOPMAR).get(0).get(Att.TOPSHP).val), getScheme(feature, Obj.TOPMAR), Topmarks.BeaconDelta);
    358                                 } else  if (hasObject(feature, Obj.DAYMAR)) {
     364                                } else  if (feature.objs.containsKey(Obj.DAYMAR)) {
    359365                                        Symbol topmark = Topmarks.Shapes.get(feature.objs.get(Obj.DAYMAR).get(0).get(Att.TOPSHP).val);
    360366                                        if (topmark != null)
     
    370376                        BoySHP shape = (BoySHP) getAttVal(feature, feature.type, 0, Att.BOYSHP);
    371377                        Renderer.symbol(feature, Buoys.Shapes.get(shape), getScheme(feature, feature.type));
    372                         if (hasObject(feature, Obj.TOPMAR)) {
     378                        if (feature.objs.containsKey(Obj.TOPMAR)) {
    373379                                Symbol topmark = Topmarks.Shapes.get(feature.objs.get(Obj.TOPMAR).get(0).get(Att.TOPSHP).val);
    374380                                if (topmark != null)
    375381                                        Renderer.symbol(feature, topmark, getScheme(feature, Obj.TOPMAR), Topmarks.BuoyDeltas.get(shape));
    376                         } else if (hasObject(feature, Obj.DAYMAR)) {
     382                        } else if (feature.objs.containsKey(Obj.DAYMAR)) {
    377383                                Symbol topmark = Topmarks.Shapes.get(feature.objs.get(Obj.DAYMAR).get(0).get(Att.TOPSHP).val);
    378384                                if (topmark != null)
     
    446452        private static void distances(Feature feature) {
    447453                if (Renderer.zoom >= 14) {
    448                         if (!testAttribute(feature, Obj.DISMAR, Att.CATDIS, CatDIS.DIS_NONI)) {
     454                        if (!testAttribute(feature, Obj.DISMAR, 0, Att.CATDIS, CatDIS.DIS_NONI)) {
    449455                                Renderer.symbol(feature, Harbours.DistanceI);
    450456                        } else {
    451457                                Renderer.symbol(feature, Harbours.DistanceU);
    452458                        }
    453                         if ((Renderer.zoom >=15) && hasAttribute(feature, Obj.DISMAR, Att.WTWDIS)) {
    454                                 AttMap atts = feature.objs.get(Obj.DISMAR).get(0);
    455                                 Double dist = (Double) atts.get(Att.WTWDIS).val;
    456                                 String str = "";
    457                                 if (atts.containsKey(Att.HUNITS)) {
    458                                         switch ((UniHLU) atts.get(Att.HUNITS).val) {
    459                                         case HLU_METR:
    460                                                 str += "m ";
    461                                                 break;
    462                                         case HLU_FEET:
    463                                                 str += "ft ";
    464                                                 break;
    465                                         case HLU_HMTR:
    466                                                 str += "hm ";
    467                                                 break;
    468                                         case HLU_KMTR:
    469                                                 str += "km ";
    470                                                 break;
    471                                         case HLU_SMIL:
    472                                                 str += "M ";
    473                                                 break;
    474                                         case HLU_NMIL:
    475                                                 str += "NM ";
    476                                                 break;
    477                                         default:
    478                                                 break;
     459                        if (Renderer.zoom >= 15) {
     460                                AttMap atts = getAtts(feature, Obj.DISMAR, 0);
     461                                if ((atts != null) && (atts.containsKey(Att.WTWDIS))) {
     462                                        Double dist = (Double) atts.get(Att.WTWDIS).val;
     463                                        String str = "";
     464                                        if (atts.containsKey(Att.HUNITS)) {
     465                                                switch ((UniHLU) atts.get(Att.HUNITS).val) {
     466                                                case HLU_METR:
     467                                                        str += "m ";
     468                                                        break;
     469                                                case HLU_FEET:
     470                                                        str += "ft ";
     471                                                        break;
     472                                                case HLU_HMTR:
     473                                                        str += "hm ";
     474                                                        break;
     475                                                case HLU_KMTR:
     476                                                        str += "km ";
     477                                                        break;
     478                                                case HLU_SMIL:
     479                                                        str += "M ";
     480                                                        break;
     481                                                case HLU_NMIL:
     482                                                        str += "NM ";
     483                                                        break;
     484                                                default:
     485                                                        break;
     486                                                }
    479487                                        }
    480                                 }
    481                                 str += String.format("%1.0f", dist);
    482                                 Renderer.labelText(feature, str, new Font("Arial", Font.PLAIN, 40), Color.black, new Delta(Handle.CC, AffineTransform.getTranslateInstance(0, 45)));
     488                                        str += String.format("%1.0f", dist);
     489                                        Renderer.labelText(feature, str, new Font("Arial", Font.PLAIN, 40), Color.black, new Delta(Handle.CC, AffineTransform.getTranslateInstance(0, 45)));
     490                                }
    483491                        }
    484492                }
     
    535543                                        Renderer.lineSymbols(feature, Areas.Restricted, 1.0, Areas.LineAnchor, null, 10, Mline);
    536544                                }
    537                                 if ((Renderer.zoom >= 15) && ((name) != null)) {
    538                                         Renderer.labelText(feature, name, new Font("Arial", Font.BOLD, 60), Mline, new Delta(Handle.LC, AffineTransform.getTranslateInstance(70, 0)));
    539                                 }
     545                                addName(feature, 15, new Font("Arial", Font.BOLD, 60), Mline, new Delta(Handle.LC, AffineTransform.getTranslateInstance(70, 0)));
    540546                                ArrayList<StsSTS> sts = (ArrayList<StsSTS>)getAttVal(feature, Obj.ACHARE, 0, Att.STATUS);
    541547                                if ((Renderer.zoom >= 15) && (sts != null) && (sts.contains(StsSTS.STS_RESV))) {
     
    638644                Renderer.symbol(feature, catSym);
    639645                Renderer.symbol(feature, fncSym);
    640 /*  if (!has_attribute("function") && !has_attribute("category") && has_object("light")) {
    641     symbol("lighthouse");
    642     if ((zoom >= 15) && has_item_attribute("name"))
    643       text(item_attribute("name"), "font-family:Arial; font-weight:bold; font-size:80; text-anchor:middle", 0, -70);
    644   } else {
    645     if ((zoom >= 15) && has_item_attribute("name"))
    646       text(item_attribute("name"), "font-family:Arial; font-weight:bold; font-size:80; text-anchor:start", 60, -50);
    647   }
    648 }
    649 */
     646                addName(feature, 15, new Font("Arial", Font.BOLD, 80), new Delta(Handle.BL, AffineTransform.getTranslateInstance(60, -50)));
    650647                Signals.addSignals(feature);
    651         }
    652        
    653         private static void buildings(Feature feature) {
    654648        }
    655649       
     
    664658                        break;
    665659                case PILPNT:
    666                         if (hasObject(feature, Obj.LIGHTS))
     660                        if (feature.objs.containsKey(Obj.LIGHTS))
    667661                                Renderer.symbol(feature, Beacons.LightMinor);
    668662                        else
     
    680674        private static void marinas(Feature feature) {
    681675                if (Renderer.zoom >= 16) {
    682                        
    683                 }
    684         }
     676                ArrayList<Symbol> symbols = new ArrayList<Symbol>();
     677                ArrayList<CatSCF> scfs = (ArrayList<CatSCF>) getAttVal(feature, Obj.SMCFAC, 0, Att.CATSCF);
     678                for (CatSCF scf : scfs) {
     679                        symbols.add(Facilities.Cats.get(scf));
     680                }
     681                  Renderer.cluster(feature, symbols);
     682          }
     683        }
     684       
    685685        private static void moorings(Feature feature) {
    686686                switch ((CatMOR) getAttVal(feature, feature.type, 0, Att.CATMOR)) {
     
    700700                                shape = BoySHP.BOY_SPHR;
    701701                        Renderer.symbol(feature, Buoys.Shapes.get(shape), getScheme(feature, feature.type));
     702                        Renderer.symbol(feature, Topmarks.TopMooring, Topmarks.BuoyDeltas.get(shape));
    702703                        break;
    703704                }
     
    923924
    924925        private static void obstructions(Feature feature) {
     926                if ((Renderer.zoom >= 12) && (feature.type == Obj.OBSTRN)) {
     927                        switch ((CatOBS) getAttVal(feature, feature.type, 0, Att.CATOBS)) {
     928                        case OBS_BOOM:
     929                                Renderer.lineVector(feature, new LineStyle(Color.black, 5, new float[] { 20, 20 }, null));
     930                                if (Renderer.zoom >= 15) Renderer.lineText(feature, "Boom", new Font("Arial", Font.PLAIN, 80), Color.black, 0.5, -20);
     931              }
     932            }
    925933                if ((Renderer.zoom >= 14) && (feature.type == Obj.UWTROC)) {
    926934                        WatLEV lvl = (WatLEV) getAttVal(feature, feature.type, 0, Att.WATLEV);
     
    968976                else
    969977                        Renderer.symbol(feature, Landmarks.Platform);
    970                 String name = getName(feature);
    971                 if ((Renderer.zoom >= 15) && (name != null))
    972                         Renderer.labelText(feature, name, new Font("Arial", Font.BOLD, 40), Color.black, new Delta(Handle.BL, AffineTransform.getTranslateInstance(20, -50)));
     978                addName(feature, 15, new Font("Arial", Font.BOLD, 40), new Delta(Handle.BL, AffineTransform.getTranslateInstance(20, -50)));
    973979                Signals.addSignals(feature);
    974980        }
     
    983989                        } else if (feature.type == Obj.HULKES) {
    984990                                Renderer.lineVector(feature, new LineStyle(Color.black, 4, null, new Color(0xffe000)));
    985                                 String name = getName(feature);
    986                                 if ((Renderer.zoom >= 15) && (name != null))
    987                                         Renderer.labelText(feature, name, new Font("Arial", Font.BOLD, 80), Color.black);
     991                                addName(feature, 15, new Font("Arial", Font.BOLD, 80));
    988992                        }
    989993                }
     
    9991003                        else
    10001004                                Renderer.lineVector(feature, new LineStyle(new Color(0x80c48080, true), 20, null, null));
    1001                         String name = getName(feature);
    1002                         if ((Renderer.zoom >= 10) && (name != null))
    1003                                 Renderer.labelText(feature, name, new Font("Arial", Font.BOLD, 150), new Color(0x80c48080, true));
     1005                        addName(feature, 10, new Font("Arial", Font.BOLD, 150), new Color(0x80c48080, true));
    10041006                        break;
    10051007                case TSELNE:
     
    10321034                                if (Renderer.zoom >= 15)
    10331035                                        Renderer.lineText(feature, "Training Wall", new Font("Arial", Font.PLAIN, 80), Color.black, 0.5, -30);
     1036                                break;
     1037                        case SLC_SWAY:
     1038                                Renderer.lineVector(feature, new LineStyle(Color.black, 2, null, new Color(0xffe000)));
     1039                          if ((Renderer.zoom >= 16) && feature.objs.containsKey(Obj.SMCFAC))  {
     1040                                ArrayList<Symbol> symbols = new ArrayList<Symbol>();
     1041                                ArrayList<CatSCF> scfs = (ArrayList<CatSCF>) getAttVal(feature, Obj.SMCFAC, 0, Att.CATSCF);
     1042                                for (CatSCF scf : scfs) {
     1043                                        symbols.add(Facilities.Cats.get(scf));
     1044                                }
     1045                                  Renderer.cluster(feature, symbols);
     1046                          }
     1047                                break;
    10341048                        }
    10351049                }
  • applications/editors/josm/plugins/smed2/src/symbols/Symbols.java

    r30325 r30339  
    1818import java.util.ArrayList;
    1919
     20import s57.S57val.ColPAT;
     21
    2022public class Symbols {
    2123
    2224        public enum Form {
    23                 BBOX, STRK, COLR, FILL, LINE, RECT, RRCT, ELPS, EARC, PLIN, PGON, RSHP, TEXT, SYMB, P1, P2, H2, H3, H4, H5, V2, V3, D2, D3, D4, B2, S2, S3, S4, C2, X2
     25                BBOX, STRK, COLR, FILL, LINE, RECT, RRCT, ELPS, EARC, PLIN, PGON, RSHP, TEXT, SYMB, P1, P2, H2, H3, H4, H5, V2, V3, D2, D3, D4, B1, S2, S3, S4, C2, X2
    2426        }
    2527
     
    149151                int pn = 0;
    150152                int cn = 0;
     153                Patt bpat = Patt.Z;
     154                Color bcol = null;
    151155                g2.setPaint(Color.black);
    152156                if (cs != null) {
     157                        if ((cs.pat.size() > 0) && (cs.col.size() > 0) && (cs.pat.get(0) == Patt.B)) {
     158                                bpat = (cs.pat.remove(0));
     159                                bcol = (cs.col.remove(0));
     160                        }
    153161                        pn = cs.pat.size();
    154162                        cn = cs.col.size() - ((pn != 0) ? pn - 1 : 0);
     
    231239                                                                break;
    232240                                                        case H2:
    233                                                                 if ((cn > 1) && (cs.pat.get(0) == Patt.H)) {
     241                                                                if ((cn > 1) && (pn > 0) && (cs.pat.get(0) == Patt.H)) {
    234242                                                                        g2.setPaint(cs.col.get(cs.col.size() - pn));
    235243                                                                        g2.fill((Path2D.Double) patch.params);
     
    237245                                                                break;
    238246                                                        case H3:
    239                                                                 if ((cn == 3) && (cs.pat.get(0) == Patt.H)) {
     247                                                                if ((cn == 3) && (pn > 0) && (cs.pat.get(0) == Patt.H)) {
    240248                                                                        g2.setPaint(cs.col.get(1));
    241249                                                                        g2.fill((Path2D.Double) patch.params);
     
    243251                                                                break;
    244252                                                        case H4:
    245                                                                 if ((cn == 4) && (cs.pat.get(0) == Patt.H)) {
     253                                                                if ((cn == 4) && (pn > 0) && (cs.pat.get(0) == Patt.H)) {
    246254                                                                        g2.setPaint(cs.col.get(1));
    247255                                                                        g2.fill((Path2D.Double) patch.params);
     
    249257                                                                break;
    250258                                                        case H5:
    251                                                                 if ((cn == 4) && (cs.pat.get(0) == Patt.H)) {
     259                                                                if ((cn == 4) && (pn > 0) && (cs.pat.get(0) == Patt.H)) {
    252260                                                                        g2.setPaint(cs.col.get(2));
    253261                                                                        g2.fill((Path2D.Double) patch.params);
     
    255263                                                                break;
    256264                                                        case V2:
    257                                                                 if ((cn > 1) && (cs.pat.get(0) == Patt.V)) {
     265                                                                if ((cn > 1) && (pn > 0) && (cs.pat.get(0) == Patt.V)) {
    258266                                                                        g2.setPaint(cs.col.get(cs.col.size() - pn));
    259267                                                                        g2.fill((Path2D.Double) patch.params);
     
    261269                                                                break;
    262270                                                        case V3:
    263                                                                 if ((cn == 3) && (cs.pat.get(0) == Patt.V)) {
     271                                                                if ((cn == 3) && (pn > 0) && (cs.pat.get(0) == Patt.V)) {
    264272                                                                        g2.setPaint(cs.col.get(1));
     273                                                                        g2.fill((Path2D.Double) patch.params);
     274                                                                }
     275                                                                break;
     276                                                        case B1:
     277                                                                if (bpat == Patt.B) {
     278                                                                        g2.setPaint(bcol);
    265279                                                                        g2.fill((Path2D.Double) patch.params);
    266280                                                                }
  • applications/editors/josm/plugins/smed2/src/symbols/Topmarks.java

    r30325 r30339  
    190190                p = new Path2D.Double(); p.moveTo(-4.3,-1.0); p.lineTo(-4.3,-27.0); p.lineTo(4.3,-27.0); p.lineTo(4.3,-1.0); p.closePath();
    191191                colours.add(new Instr(Form.V3, p));
     192                p = new Path2D.Double(); p.setWindingRule(GeneralPath.WIND_EVEN_ODD);
     193                p.moveTo(-13.0,-1.0); p.lineTo(-13.0,-27.0); p.lineTo(13.0,-27.0); p.lineTo(13.0,-1.0); p.closePath();
     194                p.moveTo(-8.0,-6.0); p.lineTo(-8.0,-22.0); p.lineTo(8.0,-22.0); p.lineTo(8.0,-6.0); p.closePath();
     195                colours.add(new Instr(Form.B1, p));
    192196                TopSquare.add(new Instr(Form.COLR, colours));
    193197                TopSquare.add(new Instr(Form.STRK, new BasicStroke(2, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER)));
     
    206210                p = new Path2D.Double(); p.moveTo(-10.0,-19.7); p.lineTo(-15.0,-15.0); p.lineTo(-10.0,-10.3); p.lineTo(10.0,-10.3); p.lineTo(15.0,-15.0); p.lineTo(10.0,-19.7); p.closePath();
    207211                colours.add(new Instr(Form.H3, p));
     212                p = new Path2D.Double();  p.moveTo(0.0,-29.0); p.lineTo(0.0,-1.0); p.lineTo(15.0,-15.0); p.closePath();
     213                colours.add(new Instr(Form.V2, p));
     214                p = new Path2D.Double(); p.moveTo(0.0,-29.0); p.lineTo(-5.0,-24.3); p.lineTo(-5.0,-5.7); p.lineTo(0.0,-1.0); p.lineTo(5.0,-5.7); p.lineTo(5.0,-24.3); p.closePath();
     215                colours.add(new Instr(Form.V3, p));
     216                p = new Path2D.Double(); p.setWindingRule(GeneralPath.WIND_EVEN_ODD);
     217                p.moveTo(0.0,-29.0); p.lineTo(-15.0,-15.0); p.lineTo(0.0,-1.0); p.lineTo(15.0,-15.0); p.closePath();
     218                p.moveTo(0.0,-23.0); p.lineTo(-9.0,-15.0); p.lineTo(0.0,-7.0); p.lineTo(9.0,-15.0); p.closePath();
     219                colours.add(new Instr(Form.B1, p));
    208220                TopRhombus.add(new Instr(Form.COLR, colours));
    209221                TopRhombus.add(new Instr(Form.STRK, new BasicStroke(2, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER)));
Note: See TracChangeset for help on using the changeset viewer.