Ignore:
Timestamp:
2014-03-14T12:32:18+01:00 (12 years ago)
Author:
malcolmh
Message:

save

File:
1 edited

Legend:

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

    r30317 r30323  
    1414import java.awt.geom.*;
    1515import java.util.ArrayList;
     16import java.util.EnumMap;
    1617
    1718import s57.S57att.*;
     
    2526public class Signals {
    2627
     28        static final EnumMap<ColCOL, Color> lightColours = new EnumMap<ColCOL, Color>(ColCOL.class);
     29        static {
     30                lightColours.put(ColCOL.COL_WHT, new Color(0xffff00));
     31                lightColours.put(ColCOL.COL_RED, new Color(0xff0000));
     32                lightColours.put(ColCOL.COL_GRN, new Color(0x00ff00));
     33                lightColours.put(ColCOL.COL_BLU, new Color(0x0000ff));
     34                lightColours.put(ColCOL.COL_YEL, new Color(0xffff00));
     35                lightColours.put(ColCOL.COL_AMB, new Color(0xfbf00f));
     36                lightColours.put(ColCOL.COL_VIO, new Color(0xee82ee));
     37                lightColours.put(ColCOL.COL_ORG, Color.orange);
     38                lightColours.put(ColCOL.COL_MAG, Color.magenta);
     39        }
     40
     41        static final EnumMap<ColCOL, String> lightLetters = new EnumMap<ColCOL, String>(ColCOL.class);
     42        static {
     43                lightLetters.put(ColCOL.COL_WHT, "W");
     44                lightLetters.put(ColCOL.COL_RED, "R");
     45                lightLetters.put(ColCOL.COL_GRN, "G");
     46                lightLetters.put(ColCOL.COL_BLU, "Bu");
     47                lightLetters.put(ColCOL.COL_YEL, "Y");
     48                lightLetters.put(ColCOL.COL_AMB, "Am");
     49                lightLetters.put(ColCOL.COL_VIO, "Vi");
     50                lightLetters.put(ColCOL.COL_ORG, "Or");
     51        }
     52
     53        static final EnumMap<LitCHR, String> lightCharacters = new EnumMap<LitCHR, String>(LitCHR.class);
     54        static {
     55                lightCharacters.put(LitCHR.CHR_F, "W");
     56                lightCharacters.put(LitCHR.CHR_FL, "Fl");
     57                lightCharacters.put(LitCHR.CHR_LFL, "LFl");
     58                lightCharacters.put(LitCHR.CHR_Q, "Q");
     59                lightCharacters.put(LitCHR.CHR_VQ, "VQ");
     60                lightCharacters.put(LitCHR.CHR_UQ, "UQ");
     61                lightCharacters.put(LitCHR.CHR_ISO, "Iso");
     62                lightCharacters.put(LitCHR.CHR_OC, "Oc");
     63                lightCharacters.put(LitCHR.CHR_IQ, "IQ");
     64                lightCharacters.put(LitCHR.CHR_IVQ, "IVQ");
     65                lightCharacters.put(LitCHR.CHR_IUQ, "IUQ");
     66                lightCharacters.put(LitCHR.CHR_MO, "Mo");
     67                lightCharacters.put(LitCHR.CHR_FFL, "FFl");
     68                lightCharacters.put(LitCHR.CHR_FLLFL, "FlLFl");
     69                lightCharacters.put(LitCHR.CHR_OCFL, "OcFl");
     70                lightCharacters.put(LitCHR.CHR_FLFL, "FLFl");
     71                lightCharacters.put(LitCHR.CHR_ALOC, "Al.Oc");
     72                lightCharacters.put(LitCHR.CHR_ALLFL, "Al.LFl");
     73                lightCharacters.put(LitCHR.CHR_ALFL, "Al.Fl");
     74                lightCharacters.put(LitCHR.CHR_ALGR, "Al.Gr");
     75                lightCharacters.put(LitCHR.CHR_QLFL, "Q+LFl");
     76                lightCharacters.put(LitCHR.CHR_VQLFL, "VQ+LFl");
     77                lightCharacters.put(LitCHR.CHR_UQLFL, "UQ+LFl");
     78                lightCharacters.put(LitCHR.CHR_AL, "Al");
     79                lightCharacters.put(LitCHR.CHR_ALFFL, "Al.FFl");
     80        }
     81       
    2782        public static void addSignals(Feature feature) {
    2883          if (feature.objs.containsKey(Obj.FOGSIG)) fogSignals(feature);
     
    3388        }
    3489       
     90        static final EnumMap<CatFOG, String> fogSignals = new EnumMap<CatFOG, String>(CatFOG.class);
     91        static {
     92                fogSignals.put(CatFOG.FOG_EXPL, "Explos");
     93                fogSignals.put(CatFOG.FOG_DIA, "Dia");
     94                fogSignals.put(CatFOG.FOG_SIRN, "Siren");
     95                fogSignals.put(CatFOG.FOG_NAUT, "Horn");
     96                fogSignals.put(CatFOG.FOG_REED, "Horn");
     97                fogSignals.put(CatFOG.FOG_TYPH, "Horn");
     98                fogSignals.put(CatFOG.FOG_BELL, "Bell");
     99                fogSignals.put(CatFOG.FOG_WHIS, "Whis");
     100                fogSignals.put(CatFOG.FOG_GONG, "Gong");
     101                fogSignals.put(CatFOG.FOG_HORN, "Horn");
     102        }
     103
    35104        public static void fogSignals(Feature feature) {
    36                
     105                Renderer.symbol(feature, Beacons.FogSignal);
     106                AttMap atts = feature.objs.get(Obj.FOGSIG).get(0);
     107                String str = "";
     108                if (atts.containsKey(Att.CATFOG)) {
     109                        str += fogSignals.get(atts.get(Att.CATFOG).val);
     110                }
     111                if (atts.containsKey(Att.SIGGRP)) {
     112                        str += "(" + atts.get(Att.SIGGRP).val + ")";
     113                } else {
     114                        str += " ";
     115                }
     116                if (atts.containsKey(Att.SIGPER)) {
     117                        str += atts.get(Att.SIGPER).val + "s";
     118                }
     119                if (atts.containsKey(Att.VALMXR)) {
     120                        str += atts.get(Att.VALMXR).val + "M";
     121                }
     122                if ((Renderer.zoom >= 15) && !str.isEmpty()) {
     123                        Renderer.labelText(feature, str, new Font("Arial", Font.PLAIN, 40),Color.black, new Delta(Handle.TR, AffineTransform.getTranslateInstance(-60, -30)));
     124                }
    37125        }
    38126
     
    63151                }
    64152                if ((Renderer.zoom >= 15) && !bstr.isEmpty()) {
    65                         Renderer.labelText(feature, bstr, new Font("Arial", Font.PLAIN, 40),Color.black, new Delta(Handle.BR, AffineTransform.getTranslateInstance(-30, -30)));
     153                        Renderer.labelText(feature, bstr, new Font("Arial", Font.PLAIN, 40),Color.black, new Delta(Handle.TR, AffineTransform.getTranslateInstance(-30, -70)));
    66154                }
    67155        }
     
    177265                        }
    178266                        if (!bstr.isEmpty()) {
    179                                 Renderer.labelText(feature, bstr, new Font("Arial", Font.PLAIN, 40), Color.black, new Delta(Handle.BR, AffineTransform.getTranslateInstance(-30, -70)));
     267                                Renderer.labelText(feature, bstr, new Font("Arial", Font.PLAIN, 40), Color.black, new Delta(Handle.TR, AffineTransform.getTranslateInstance(-30, -110)));
    180268                        }
    181269                }
     
    183271
    184272        public static void lights(Feature feature) {
    185                
    186         }
    187 
    188 //      private static Point2D.Double radial(Feature feature, Snode centre, double radius, double angle) {
    189 //              Point2D origin = Renderer.context.getPoint(centre);
    190 //              return new Point2D.Double(origin.getX() - (radius * Renderer.context.mile(feature) * Math.sin(angle)), origin.getY() - (radius * Renderer.context.mile(feature) * Math.cos(angle)));
    191 //      }
    192 /*
    193 void renderFlare(Item_t *item) {
    194   char *col = light_colours[COL_MAG];
    195   Obj_t *obj = getObj(item, LIGHTS, 0);
    196   Att_t *att;
    197   if (((att = getAtt(obj, COLOUR)) != NULL) && (att->val.val.l->next == NULL)) {
    198     col = light_colours[att->val.val.l->val];
    199   }
    200   renderSymbol(item, LIGHTS, "light", "", col, CC, 0, 0, 120);
    201 }
    202 
     273                Enum<ColCOL> col = null;
     274                Enum<ColCOL> tcol = null;
     275                ObjTab objs = feature.objs.get(Obj.LIGHTS);
     276                for (AttMap atts : objs.values()) {
     277                        if (atts.containsKey(Att.COLOUR)) {
     278                                ArrayList<Enum<ColCOL>> cols = (ArrayList<Enum<ColCOL>>) atts.get(Att.COLOUR).val;
     279                                if (cols.size() == 1) {
     280                                        tcol = cols.get(0);
     281                                        if (col == null) {
     282                                                col = tcol;
     283                                        } else if (tcol != col) {
     284                                                col = ColCOL.COL_MAG;
     285                                                break;
     286                                        }
     287                                } else {
     288                                        col = ColCOL.COL_MAG;
     289                                        break;
     290                                }
     291                        }
     292                }
     293                Renderer.symbol(feature, Beacons.LightFlare, new Scheme(lightColours.get(col)), new Delta(Handle.BC, AffineTransform.getRotateInstance(Math.toRadians(120))));
     294                if (objs.get(1) != null) {
     295                        for (AttMap atts : objs.values()) {
     296                                Enum<ColCOL> col1 = null;
     297                                Enum<ColCOL> col2 = null;
     298                                double radius = 0.2;
     299                                double s1 = 0;
     300                                double s2 = 0;
     301                                boolean dir = false;
     302                                if (atts.containsKey(Att.COLOUR)) {
     303                                        ArrayList<Enum<ColCOL>> cols = (ArrayList<Enum<ColCOL>>) atts.get(Att.COLOUR).val;
     304                                        col1 = cols.get(0);
     305                                        if (cols.size() > 1) col2 = cols.get(1);
     306                                } else {
     307                                        continue;
     308                                }
     309                                if (atts.containsKey(Att.RADIUS)) {
     310                                        radius = (Double) atts.get(Att.RADIUS).val;
     311                                }
     312                                if (atts.containsKey(Att.SECTR1)) {
     313                                        s1 = (Double) atts.get(Att.SECTR1).val;
     314                                } else {
     315                                        continue;
     316                                }
     317                                if (atts.containsKey(Att.SECTR2)) {
     318                                        s1 = (Double) atts.get(Att.SECTR2).val;
     319                                } else {
     320                                        continue;
     321                                }
     322                                if (atts.containsKey(Att.CATLIT)) {
     323                                        ArrayList<CatLIT> cats = (ArrayList<CatLIT>) atts.get(Att.CATLIT).val;
     324                                        if (cats.contains(CatLIT.LIT_DIR)) {
     325                                                dir = true;
     326                                        }
     327                                }
     328                                Renderer.lightSector(feature, lightColours.get(col1), lightColours.get(col2), radius, s1, s2, dir, "");
     329                        }
     330                }
     331        }
     332
     333        /*
    203334void renderSector(Item_t *item, int s, char *text, char *style, double offset, int dy) {
    204335  Obj_t *sector;
     
    356487  Obj_t *obj = getObj(item, enumType(type), idx);
    357488  switch (enumType(type)) {
    358     case CGUSTA:
    359       strcpy(string1, "CG");
    360       if ((obj != NULL) && (att = getAtt(obj, COMCHA)) != NULL)
    361         sprintf(strchr(string1, 0), " Ch.%s", stringValue(att->val));
    362       break;
    363     case FOGSIG:
    364       if (obj != NULL) {
    365         if ((att = getAtt(obj, CATFOG)) != NULL)
    366           strcat(string1, fog_signals[att->val.val.e]);
    367         if ((att = getAtt(obj, SIGGRP)) != NULL)
    368           sprintf(strchr(string1, 0), "(%s)", stringValue(att->val));
    369         else
    370           strcat(string1, " ");
    371         if ((att = getAtt(obj, SIGPER)) != NULL)
    372           sprintf(strchr(string1, 0), "%ss ", stringValue(att->val));
    373         if ((att = getAtt(obj, VALMXR)) != NULL)
    374           sprintf(strchr(string1, 0), "%sM", stringValue(att->val));
    375       }
    376       break;
    377     case SISTAT:
    378       strcpy(string1, "SS");
    379       if (obj != NULL) {
    380         if ((att = getAtt(obj, CATSIT)) != NULL)
    381           strcat(string1, sit_map[att->val.val.l->val]);
    382         if ((att = getAtt(obj, COMCHA)) != NULL)
    383           sprintf(strchr(string1, 0), "\nCh.%s", stringValue(att->val));
    384       }
    385       break;
    386     case SISTAW:
    387       strcpy(string1, "SS");
    388       if (obj != NULL) {
    389         if ((att = getAtt(obj, CATSIW)) != NULL)
    390           strcat(string1, siw_map[att->val.val.l->val]);
    391         if ((att = getAtt(obj, COMCHA)) != NULL)
    392           sprintf(strchr(string1, 0), "\nCh.%s", stringValue(att->val));
    393       }
    394       break;
    395489    case LIGHTS:
    396490    {
Note: See TracChangeset for help on using the changeset viewer.