Ignore:
Timestamp:
2013-01-08T21:26:40+01:00 (12 years ago)
Author:
malcolmh
Message:

save

Location:
applications/editors/josm/plugins/smed2/src/seamap
Files:
3 edited

Legend:

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

    r29175 r29184  
    1414import java.awt.geom.Point2D;
    1515import java.util.ArrayList;
    16 import java.util.EnumMap;
    1716import java.util.HashMap;
    1817
     
    4342                        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    4443                        g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);
    45                         Rules.MainRules(map, zoom);
     44                        Rules.rules(map, zoom);
    4645                }
    4746        }
    4847       
    49         public static EnumMap<Att, AttItem> getAtts(Feature feature, Obj obj, int idx) {
    50                 HashMap<Integer, EnumMap<Att, AttItem>> objs = feature.objs.get(obj);
     48        public static AttMap getAtts(Feature feature, Obj obj, int idx) {
     49                HashMap<Integer, AttMap> objs = feature.objs.get(obj);
    5150                if (objs == null) return null;
    5251                else return objs.get(idx);
     
    5453       
    5554        public static Object getAttVal(Feature feature, Obj obj, int idx, Att att) {
    56                 EnumMap<Att, AttItem> atts = getAtts(feature, obj, idx);
     55                AttMap atts = getAtts(feature, obj, idx);
    5756                if (atts == null) return  S57val.nullVal(att);
    5857                else {
     
    6261                }
    6362        }
     63
     64        public static Coord findCentroid(Feature feature) {
     65    double slon = 0.0;
     66    double slat = 0.0;
     67    double sarc = 0.0;
     68    double llon = 0.0;
     69    double llat = 0.0;
     70                if (feature.flag == Fflag.NODE) {
     71                        return map.nodes.get(feature.refs);
     72                }
     73                ArrayList<Long> way = map.ways.get(feature.refs);
     74                if (feature.flag == Fflag.WAY) {
     75                        llon = map.nodes.get(way.get(1)).lon;
     76                        llat = map.nodes.get(way.get(1)).lat;
     77                } else {
     78                        llon = map.nodes.get(way.get(0)).lon;
     79                        llat = map.nodes.get(way.get(0)).lat;
     80                }
     81                for (long node : way) {
     82      double lon = map.nodes.get(node).lon;
     83      double lat = map.nodes.get(node).lat;
     84      double arc = Math.sqrt(Math.pow((lon-llon), 2) + Math.pow((lat-llat), 2));
     85      slon += (lon * arc);
     86      slat += (lat * arc);
     87      sarc += arc;
     88      llon = lon;
     89      llat = lat;
     90                }
     91                return map.new Coord((sarc > 0.0 ? slat/sarc : 0.0), (sarc > 0.0 ? slon/sarc : 0.0));
     92        }
    6493       
    6594        public static void symbol(Feature feature, ArrayList<Instr> symbol, Obj obj) {
    66                 Point2D point = helper.getPoint(map.nodes.get(feature.refs));
     95                Point2D point = helper.getPoint(findCentroid(feature));
    6796                ArrayList<ColCOL> colours = (ArrayList<ColCOL>) getAttVal(feature, obj, 0, Att.COLOUR);
    6897                ArrayList<ColPAT> pattern = (ArrayList<ColPAT>) getAttVal(feature, obj, 0, Att.COLPAT);
  • applications/editors/josm/plugins/smed2/src/seamap/Rules.java

    r29176 r29184  
    2828        static int zoom;
    2929       
    30         public static void MainRules (SeaMap m, int z) {
     30        public static void rules (SeaMap m, int z) {
    3131                map = m;
    3232                zoom = z;
     
    123123                        ArrayList<Instr> fncSym = Landmarks.Funcs.get(fncs.get(0));
    124124                        if ((fncs.get(0) == FncFNC.FNC_CHCH) && (cats.get(0) == CatLMK.LMK_TOWR)) catSym = Landmarks.ChurchTower;
     125                        if ((cats.get(0) == CatLMK.LMK_UNKN) && (fncs.get(0) == FncFNC.FNC_UNKN)) catSym = Beacons.LightMajor;
    125126                        Renderer.symbol(feature, catSym, feature.type);
    126127                        Renderer.symbol(feature, fncSym, feature.type);
  • applications/editors/josm/plugins/smed2/src/seamap/SeaMap.java

    r29174 r29184  
    1515
    1616import s57.S57att;
    17 import s57.S57att.*;
     17import s57.S57att.Att;
    1818import s57.S57obj;
    1919import s57.S57obj.*;
     
    3737        }
    3838
     39        public class AttMap extends EnumMap<Att, AttItem> {
     40                private static final long serialVersionUID = 1L;
     41                public AttMap() {
     42                        super(Att.class);
     43                }
     44        }
     45       
     46        public class ObjTab extends HashMap<Integer, AttMap> {
     47                private static final long serialVersionUID = 1L;
     48                public ObjTab() {
     49                        super();
     50                }
     51        }
     52       
     53        public class ObjMap extends EnumMap<Obj, ObjTab> {
     54                private static final long serialVersionUID = 1L;
     55                public ObjMap() {
     56                        super(Obj.class);
     57                }
     58        }
     59       
     60        public class NodeTab extends HashMap<Long, Coord> {
     61                private static final long serialVersionUID = 1L;
     62                public NodeTab() {
     63                        super();
     64                }
     65        }
     66       
     67        public class WayTab extends HashMap<Long, ArrayList<Long>> {
     68                private static final long serialVersionUID = 1L;
     69                public WayTab() {
     70                        super();
     71                }
     72        }
     73       
     74        public class FtrMap extends EnumMap<Obj, ArrayList<Feature>> {
     75                private static final long serialVersionUID = 1L;
     76                public FtrMap() {
     77                        super(Obj.class);
     78                }
     79        }
     80       
     81        public class FtrTab extends HashMap<Long, Feature> {
     82                private static final long serialVersionUID = 1L;
     83                public FtrTab() {
     84                        super();
     85                }
     86        }
     87       
    3988        public class Feature {
    4089                public Fflag flag;
    4190                public long refs;
    4291                public Obj type;
    43                 public EnumMap<Att, AttItem> atts;
    44                 public EnumMap<Obj, HashMap<Integer, EnumMap<Att, AttItem>>> objs;
     92                public AttMap atts;
     93                public ObjMap objs;
    4594
    4695                Feature() {
     
    4897                        refs = 0;
    4998                        type = Obj.UNKOBJ;
    50                         atts = new EnumMap<Att, AttItem>(Att.class);
    51                         objs = new EnumMap<Obj, HashMap<Integer, EnumMap<Att, AttItem>>>(Obj.class);
     99                        atts = new AttMap();
     100                        objs = new ObjMap();
    52101                }
    53102        }
     
    57106                public double lon;
    58107
    59                 Coord(double ilat, double ilon) {
     108                public Coord(double ilat, double ilon) {
    60109                        lat = ilat;
    61110                        lon = ilon;
     
    63112        }
    64113
    65         public HashMap<Long, Coord> nodes;
    66         public HashMap<Long, ArrayList<Long>> ways;
    67         public HashMap<Long, ArrayList<Long>> mpolys;
    68         public EnumMap<Obj, ArrayList<Feature>> features;
     114        public NodeTab nodes;
     115        public WayTab ways;
     116        public WayTab mpolys;
     117        public FtrMap features;
     118        public FtrTab index;
    69119
    70120        private Feature feature;
     
    72122
    73123        public SeaMap() {
    74                 nodes = new HashMap<Long, Coord>();
    75                 ways = new HashMap<Long, ArrayList<Long>>();
    76                 mpolys = new HashMap<Long, ArrayList<Long>>();
     124                nodes = new NodeTab();
     125                ways = new WayTab();
     126                mpolys = new WayTab();
    77127                feature = new Feature();
    78                 features = new EnumMap<Obj, ArrayList<Feature>>(Obj.class);
     128                features = new FtrMap();
     129                index = new FtrTab();
    79130        }
    80131
     
    84135                feature.refs = id;
    85136                feature.flag = Fflag.NODE;
     137        }
     138
     139        public void moveNode(long id, double lat, double lon) {
     140                nodes.put(id, new Coord(lat, lon));
    86141        }
    87142
     
    110165        }
    111166
    112         public void tagsDone() {
    113                 if (feature.type != Obj.UNKOBJ) {
    114                         if ((feature.flag == Fflag.WAY) && (list.size() > 0) && (list.get(0) == list.get(list.size() - 1))) {
     167        public void tagsDone(long id) {
     168                if ((feature.type != Obj.UNKOBJ) && !((feature.flag == Fflag.WAY) && (list.size() < 2))) {
     169                        index.put(id, feature);
     170                        if ((feature.flag == Fflag.WAY) && (list.size() > 0) && (list.get(0).equals(list.get(list.size() - 1)))) {
    115171                                feature.flag = Fflag.AREA;
    116172                        }
     
    137193                                        att = S57att.enumAttribute(subkeys[2], obj);
    138194                                }
    139                                 HashMap<Integer, EnumMap<Att, AttItem>> items = feature.objs.get(obj);
     195                                ObjTab items = feature.objs.get(obj);
    140196                                if (items == null) {
    141                                         items = new HashMap<Integer, EnumMap<Att, AttItem>>();
     197                                        items = new ObjTab();
    142198                                        feature.objs.put(obj, items);
    143199                                }
    144                                 EnumMap<Att, AttItem> atts = items.get(idx);
     200                                AttMap atts = items.get(idx);
    145201                                if (atts == null) {
    146                                         atts = new EnumMap<Att, AttItem>(Att.class);
     202                                        atts = new AttMap();
    147203                                        items.put(idx, atts);
    148204                                }
Note: See TracChangeset for help on using the changeset viewer.