Changeset 29152 in osm


Ignore:
Timestamp:
2013-01-01T16:08:15+01:00 (12 years ago)
Author:
malcolmh
Message:

save

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

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/smed2/src/s57/S57val.java

    r29150 r29152  
    2727       
    2828        public static class AttVal {
    29                 Att att;
    30                 Conv conv;
    31                 Object val;
     29                public Att att;
     30                public Conv conv;
     31                public Object val;
    3232                AttVal(Att a, Conv c, Object v) {
    3333                        att = a; conv = c; val = v;
  • applications/editors/josm/plugins/smed2/src/seamap/Map.java

    r29151 r29152  
    1414import java.util.HashMap;
    1515
    16 import s57.S57att.Att;
    17 import s57.S57obj.Obj;
    18 import s57.S57val.Conv;
     16import s57.S57att;
     17import s57.S57att.*;
     18import s57.S57obj;
     19import s57.S57obj.*;
     20import s57.S57val;
     21import s57.S57val.*;
    1922
    2023public class Map {
    2124
    22         public enum Fflag { NODE, WAY, AREA     }
     25        public enum Fflag {
     26                UNKN, NODE, WAY, AREA
     27        }
    2328
    2429        public class AttItem {
    2530                Conv conv;
    2631                Object val;
    27         }
    2832
    29         public class ObjItem {
    30                 int idx;
    31                 ArrayList<EnumMap<Att, AttItem>> atts;
     33                AttItem(Conv iconv, Object ival) {
     34                        conv = iconv;
     35                        val = ival;
     36                }
    3237        }
    3338
     
    3843                public Obj type;
    3944                public EnumMap<Att, AttItem> atts;
    40                 public EnumMap<Obj, ArrayList<ObjItem>> objs;
     45                public EnumMap<Obj, HashMap<Integer, EnumMap<Att, AttItem>>> objs;
     46
     47                Feature() {
     48                        clean();
     49                }
     50               
     51                void clean() {
     52                        id = 0;
     53                        flag = Fflag.UNKN;
     54                        refs = new ArrayList<Long>();
     55                        type = Obj.UNKOBJ;
     56                        atts = new EnumMap<Att, AttItem>(Att.class);
     57                        objs = new EnumMap<Obj, HashMap<Integer, EnumMap<Att, AttItem>>>(Obj.class);
     58                }
    4159        }
    42        
     60
    4361        public class Coord {
    4462                double lat;
    4563                double lon;
    46                 Coord (double ilat, double ilon) {
     64
     65                Coord(double ilat, double ilon) {
    4766                        lat = ilat;
    4867                        lon = ilon;
    4968                }
    5069        }
    51        
     70
    5271        public HashMap<Long, Coord> nodes;
    5372        public HashMap<Long, ArrayList<Long>> ways;
    5473        public HashMap<Long, ArrayList<Long>> mpolys;
    5574        public ArrayList<Feature> features;
    56        
    57         public Map () {
     75
     76        private Feature feature;
     77
     78        public Map() {
    5879                nodes = new HashMap<Long, Coord>();
    5980                ways = new HashMap<Long, ArrayList<Long>>();
    6081                mpolys = new HashMap<Long, ArrayList<Long>>();
     82                feature = new Feature();
    6183                features = new ArrayList<Feature>();
     84                features.add(feature);
    6285        }
    63        
     86
    6487        public void addNode(long id, double lat, double lon) {
    6588                nodes.put(id, new Coord(lat, lon));
     89                if (feature.type == Obj.UNKOBJ) {
     90                        feature.clean();
     91                } else {
     92                        feature = new Feature();
     93                        features.add(feature);
     94                }
    6695        }
    67        
     96
    6897        public void addWay(long id) {
    6998                ways.put(id, new ArrayList<Long>());
     99                if (feature.type == Obj.UNKOBJ) {
     100                        feature.clean();
     101                } else {
     102                        feature = new Feature();
     103                        features.add(feature);
     104                }
    70105        }
    71        
     106
    72107        public void addToWay(long way, long node) {
    73108                ways.get(way).add(node);
    74109        }
    75         public void addRelation(long id) {
     110
     111        public void addMpoly(long id) {
    76112                mpolys.put(id, new ArrayList<Long>());
    77113        }
    78        
    79         public void addToRelation(long rel, long way) {
    80                 mpolys.get(rel).add(way);
     114
     115        public void addToMpoly(long id, long way) {
     116                mpolys.get(id).add(way);
     117        }
     118
     119        public void addTag(String key, String val) {
     120                String subkeys[] = key.split(":");
     121                if ((subkeys.length > 1) && subkeys[0].equals("seamark")) {
     122                        Obj obj = S57obj.enumType(subkeys[1]);
     123                        if ((subkeys.length > 2) && (obj != Obj.UNKOBJ)) {
     124                                int idx = 0;
     125                                Att att = Att.UNKATT;
     126                                try {
     127                                        idx = Integer.parseInt(subkeys[2]);
     128                                        if (subkeys.length == 4) {
     129                                                att = s57.S57att.enumAttribute(subkeys[3], obj);
     130                                        }
     131                                } catch (Exception e) {
     132                                        att = S57att.enumAttribute(subkeys[2], obj);
     133                                }
     134                                HashMap<Integer, EnumMap<Att, AttItem>> items = feature.objs.get(obj);
     135                                if (items == null) {
     136                                        items = new HashMap<Integer, EnumMap<Att, AttItem>>();
     137                                        feature.objs.put(obj, items);
     138                                }
     139                                EnumMap<Att, AttItem> atts = items.get(idx);
     140                                if (atts == null) {
     141                                        atts = new EnumMap<Att, AttItem>(Att.class);
     142                                }
     143                                AttVal attval = S57val.convertValue(val, att);
     144                                atts.put(att, new AttItem(attval.conv, attval.val));
     145                        } else {
     146                                if (subkeys[1].equals("type")) {
     147                                        feature.type = S57obj.enumType(val);
     148                                } else {
     149                                        Att att = S57att.enumAttribute(subkeys[1], Obj.UNKOBJ);
     150                                        if (att != Att.UNKATT) {
     151                                                AttVal attval = S57val.convertValue(val, att);
     152                                                feature.atts.put(att, new AttItem(attval.conv, attval.val));
     153                                        }
     154                                }
     155                        }
     156                }
    81157        }
    82158}
  • applications/editors/josm/plugins/smed2/src/smed2/Smed2Action.java

    r29151 r29152  
    11package smed2;
    22
    3 import java.awt.Dimension;
    4 import java.awt.event.ActionEvent;
    5 import java.util.Collection;
     3import java.awt.*;
     4import java.awt.event.*;
     5import java.util.*;
     6import java.util.Map.Entry;
    67
    7 import javax.swing.JFrame;
    8 import javax.swing.SwingUtilities;
    9 import javax.swing.WindowConstants;
     8import javax.swing.*;
    109
    1110import static org.openstreetmap.josm.tools.I18n.tr;
     
    1716import org.openstreetmap.josm.data.SelectionChangedListener;
    1817import org.openstreetmap.josm.data.imagery.ImageryInfo;
    19 import org.openstreetmap.josm.data.osm.DataSet;
    20 import org.openstreetmap.josm.data.osm.Node;
    21 import org.openstreetmap.josm.data.osm.OsmPrimitive;
    22 import org.openstreetmap.josm.data.osm.event.AbstractDatasetChangedEvent;
    23 import org.openstreetmap.josm.data.osm.event.DataChangedEvent;
    24 import org.openstreetmap.josm.data.osm.event.DataSetListener;
    25 import org.openstreetmap.josm.data.osm.event.DataSetListenerAdapter;
    26 import org.openstreetmap.josm.data.osm.event.DatasetEventManager.FireMode;
    27 import org.openstreetmap.josm.data.osm.event.NodeMovedEvent;
    28 import org.openstreetmap.josm.data.osm.event.PrimitivesAddedEvent;
    29 import org.openstreetmap.josm.data.osm.event.PrimitivesRemovedEvent;
    30 import org.openstreetmap.josm.data.osm.event.RelationMembersChangedEvent;
    31 import org.openstreetmap.josm.data.osm.event.TagsChangedEvent;
    32 import org.openstreetmap.josm.data.osm.event.WayNodesChangedEvent;
     18import org.openstreetmap.josm.data.osm.*;
     19import org.openstreetmap.josm.data.osm.event.*;
    3320import org.openstreetmap.josm.Main;
    3421
    3522import s57.S57dat;
     23import seamap.Map;
    3624
    3725import panels.PanelMain;
     
    4634        public static PanelMain panelMain = null;
    4735        public ImageryLayer rendering;
     36        public Map map = null;
    4837        public Collection<OsmPrimitive> data = null;
    4938
     
    130119                panelS57.setVisible(false);
    131120                frame.add(panelS57);
    132                 System.out.println("hello");
     121//              System.out.println("hello");
    133122                rendering = ImageryLayer.create(new ImageryInfo("OpenSeaMap"));
    134123                Main.main.addLayer(rendering);
     
    140129                        frame.setVisible(false);
    141130                        frame.dispose();
     131                        data = null;
     132                        map = null;
    142133                }
    143134                isOpen = false;
     
    146137        @Override
    147138        public void editLayerChanged(OsmDataLayer oldLayer, OsmDataLayer newLayer) {
    148                 System.out.println(newLayer);
    149139                if (oldLayer != null) {
    150140                        oldLayer.data.removeDataSetListener(dataSetListener);
    151141                }
    152 
    153142                if (newLayer != null) {
    154143                        newLayer.data.addDataSetListener(dataSetListener);
    155144                        data = newLayer.data.allPrimitives();
    156                 } else {
     145                        map = new Map();
     146                        for (OsmPrimitive osm : data) {
     147                                if (osm instanceof Node) {
     148                                        map.addNode(((Node)osm).getId(), ((Node)osm).getCoor().lat(), ((Node)osm).getCoor().lon());
     149                                } else if (osm instanceof Way) {
     150                                        map.addWay(((Way)osm).getId());
     151                                }
     152                                for (Entry<String, String> entry : osm.getKeys().entrySet()) {
     153                                        map.addTag(entry.getKey(), entry.getValue());
     154                                }
     155                        }
     156                } else {
    157157                        data = null;
     158                        map = null;
    158159                }
    159160        }
Note: See TracChangeset for help on using the changeset viewer.