Index: applications/editors/josm/plugins/smed2/js57toosm/src/js57toosm/Js57toosm.java
===================================================================
--- applications/editors/josm/plugins/smed2/js57toosm/src/js57toosm/Js57toosm.java	(revision 30197)
+++ applications/editors/josm/plugins/smed2/js57toosm/src/js57toosm/Js57toosm.java	(revision 30215)
@@ -11,5 +11,11 @@
 
 import java.io.*;
-
+import java.util.Map;
+
+import s57.S57obj;
+import s57.S57att;
+import s57.S57att.*;
+import s57.S57val;
+import s57.S57val.*;
 import s57.S57dat;
 import s57.S57dat.*;
@@ -34,4 +40,5 @@
 		int len;
 		int pos;
+		boolean inFeature = false;
 		
 		double comf = 1;
@@ -39,4 +46,6 @@
 		long name = 0;
 		S57map.Nflag nflag = Nflag.ANON;
+		S57map.Pflag prim = S57map.Pflag.NOSP;
+		long objl = 0;
 		S57map map = new S57map();
 		double minlat = 90, minlon = 180, maxlat = -90, maxlon = -180;
@@ -67,8 +76,4 @@
 						}
 						break;
-					case "DSID":
-						break;
-					case "DSSI":
-						break;
 					case "DSPM":
 						comf = (double) (Long) S57dat.getSubf(record, fields + pos, S57field.DSPM, S57subf.COMF);
@@ -76,21 +81,47 @@
 						break;
 					case "FRID":
+						inFeature = true;
+						switch ((int)((long)S57dat.getSubf(record, fields + pos, S57field.FRID, S57subf.PRIM))) {
+						case 1:
+							prim = S57map.Pflag.POINT;
+							break;
+						case 2:
+							prim = S57map.Pflag.LINE;
+							break;
+						case 3:
+							prim = S57map.Pflag.AREA;
+							break;
+						default:
+							prim = S57map.Pflag.NOSP;
+						}
+						objl = (long)S57dat.getSubf(S57subf.OBJL);
 						break;
 					case "FOID":
+						name = (long) S57dat.getSubf(record, fields + pos, S57field.FOID, S57subf.LNAM);
+						map.newFeature(name, prim, objl);
 						break;
 					case "ATTF":
-						break;
-					case "NATF":
-						break;
-					case "FFPC":
+						S57dat.setField(record, fields + pos, S57field.ATTF, len);
+						do {
+							long attl = (long) S57dat.getSubf(S57subf.ATTL);
+							String atvl = (String) S57dat.getSubf(S57subf.ATVL);
+							map.newAtt(attl, atvl);
+						} while (S57dat.more());
 						break;
 					case "FFPT":
-						break;
-					case "FSPC":
+						name = (long) S57dat.getSubf(record, fields + pos, S57field.FFPT, S57subf.LNAM);
+						int rind = ((Long) S57dat.getSubf(S57subf.RIND)).intValue();
+						map.newObj(name, rind);
 						break;
 					case "FSPT":
+						S57dat.setField(record, fields + pos, S57field.FSPT, len);
+						do {
+							name = (Long) S57dat.getSubf(S57subf.NAME) << 16;
+							map.newPrim(name, (long) S57dat.getSubf(S57subf.ORNT), (long) S57dat.getSubf(S57subf.USAG));
+						} while (S57dat.more());
 						break;
 					case "VRID":
-						name = (Long) S57dat.getSubf(record, fields + pos, S57field.VRID, S57subf.RCNM);
+						inFeature = false;
+						name = (long) S57dat.getSubf(record, fields + pos, S57field.VRID, S57subf.RCNM);
 						switch ((int) name) {
 						case 110:
@@ -105,5 +136,5 @@
 						}
 						name <<= 32;
-						name += (Long) S57dat.getSubf(record, fields + pos, S57field.VRID, S57subf.RCID);
+						name += (Long) S57dat.getSubf(S57subf.RCID);
 						name <<= 16;
 						if (nflag == Nflag.ANON) {
@@ -111,21 +142,15 @@
 						}
 						break;
-					case "ATTV":
-						break;
-					case "VRPC":
-						break;
 					case "VRPT":
-						name = (Long) S57dat.getSubf(record, fields + pos, S57field.VRPT, S57subf.NAME) << 16;
-						int topi = ((Long) S57dat.getSubf(S57subf.TOPI)).intValue();
-						map.addConn(name, topi);
-						name = (Long) S57dat.getSubf(S57subf.NAME) << 16;
-						topi = ((Long) S57dat.getSubf(S57subf.TOPI)).intValue();
-						map.addConn(name, topi);
-						break;
-					case "SGCC":
+						S57dat.setField(record, fields + pos, S57field.VRPT, len);
+						do {
+							name = (Long) S57dat.getSubf(S57subf.NAME) << 16;
+							int topi = ((Long) S57dat.getSubf(S57subf.TOPI)).intValue();
+							map.addConn(name, topi);
+						} while (S57dat.more());
 						break;
 					case "SG2D":
 						S57dat.setField(record, fields + pos, S57field.SG2D, len);
-						while (S57dat.more()) {
+						do {
 							double lat = (double) ((Long) S57dat.getSubf(S57subf.YCOO)) / comf;
 							double lon = (double) ((Long) S57dat.getSubf(S57subf.XCOO)) / comf;
@@ -143,9 +168,9 @@
 							if (lon > maxlon)
 								maxlon = lon;
-						}
+						} while (S57dat.more());
 						break;
 					case "SG3D":
 						S57dat.setField(record, fields + pos, S57field.SG3D, len);
-						while (S57dat.more()) {
+						do {
 							double lat = (double) ((Long) S57dat.getSubf(S57subf.YCOO)) / comf;
 							double lon = (double) ((Long) S57dat.getSubf(S57subf.XCOO)) / comf;
@@ -160,10 +185,15 @@
 							if (lon > maxlon)
 								maxlon = lon;
-						}
+						} while (S57dat.more());
 						break;
 					}
 				}
-			}
-		}
+				if (inFeature) {
+					map.endFeature();
+					inFeature = false;
+				}
+			}
+		}
+		map.endFile();
 		in.close();
 		
@@ -172,4 +202,29 @@
 		out.println("<bounds minlat='" + minlat +"' minlon='" + minlon + "' maxlat='" + maxlat + "' maxlon='" + maxlon + "'/>");
 		
+		for (long id : map.index.keySet()) {
+			Feature feature = map.index.get(id);
+			if (feature.reln != Rflag.SLAVE) {
+				if (feature.geom.prim == Pflag.POINT) {
+					Snode node = map.nodes.get(feature.geom.elems.get(0).id);
+					String type = S57obj.stringType(feature.type);
+					out.format("  <node id='%d' lat='%f' lon='%f' version='1'>%n",-id,  Math.toDegrees(node.lat), Math.toDegrees(node.lon));
+					out.format("    <tag k='seamark:type' v=\"%s\"/>%n", type);
+					for (Map.Entry<Att, AttVal<?>> item : feature.atts.entrySet()) {
+						out.format("    <tag k='seamark:%s:%s' v=\"%s\"/>%n", type, S57att.stringAttribute(item.getKey()), S57val.stringValue(item.getValue()));
+					}
+					for (Reln rel : feature.rels) {
+						if (rel.reln == Rflag.SLAVE) {
+							Feature slave = map.index.get(rel.id);
+							type = S57obj.stringType(slave.type);
+							for (Map.Entry<Att, AttVal<?>> item : slave.atts.entrySet()) {
+								out.format("    <tag k='seamark:%s:%s' v=\"%s\"/>%n", type, S57att.stringAttribute(item.getKey()), S57val.stringValue(item.getValue()));
+							}
+						}
+					}
+					out.format("  </node>%n");
+				}
+			}
+		}
+/*		
 		for (long id : map.nodes.keySet()) {
 			Snode node = map.nodes.get(id);
@@ -194,5 +249,5 @@
 			out.format("  </way>%n");
 		}
-		
+*/		
 		out.println("</osm>\n");
 	}
