1 | package S57;
|
---|
2 |
|
---|
3 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
4 |
|
---|
5 | import java.awt.Dimension;
|
---|
6 | import java.awt.event.ActionListener;
|
---|
7 | import java.io.File;
|
---|
8 | import java.io.FileInputStream;
|
---|
9 | import java.io.FileNotFoundException;
|
---|
10 | import java.io.IOException;
|
---|
11 |
|
---|
12 | import javax.swing.*;
|
---|
13 |
|
---|
14 | import org.openstreetmap.josm.Main;
|
---|
15 | import org.openstreetmap.josm.gui.layer.OsmDataLayer;
|
---|
16 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
17 |
|
---|
18 | import panels.PanelMain;
|
---|
19 |
|
---|
20 | import smed2.Smed2Action;
|
---|
21 |
|
---|
22 | import S57.S57obj;
|
---|
23 | import S57.S57att;
|
---|
24 | import S57.S57val;
|
---|
25 |
|
---|
26 | public class S57dat extends JPanel {
|
---|
27 |
|
---|
28 | private enum S57field { DSID, DSSI, DSPM, DSPR, DSRC, DSHT, DSAC, CATD, CATX, DDDF, DDDR, DDDI, DDOM, DDRF, DDSI, DDSC,
|
---|
29 | FRID, FOID, ATTF, NATF, FFPC, FFPT, FSPC, FSPT, VRID, ATTV, VRPC, VRPT, SGCC, SG2D, SG3D, ARCC, AR2D, EL2D, CT2D }
|
---|
30 | private enum S57dsid { RCNM, RCID, EXPP, INTU, DSNM, EDTN, UPDN, UADT, ISDT, STED, PRSP, PSDN, PRED, PROF, AGEN, COMT }
|
---|
31 | private enum S57dssi { DSTR, AALL, NALL, NOMR, NOCR, NOGR, NOLR, NOIN, NOCN, NOED, NOFA }
|
---|
32 | private enum S57dspm { RCNM, RCID, HDAT, VDAT, SDAT, CSCL, DUNO, HUNI, PUNI, COUN, COMF, SOMF, COMT }
|
---|
33 | private enum S57dspr { PROJ, PRP1, PRP2, PRP3, PRP4, FEAS, FNOR, FPMF, COMT }
|
---|
34 | private enum S57dsrc { RPID, RYCO, RXCO, CURP, FPMF, RXVL, RYVL, COMT }
|
---|
35 | private enum S57dsht { RCNM, RCID, PRCO, ESDT, LSDT, DCRT, CODT, COMT }
|
---|
36 | private enum S57dsac { RCNM, RCID, PACC, HACC, SACC, FPMF, COMT }
|
---|
37 | private enum S57catd { RCNM, RCID, FILE, LFIL, VOLM, IMPL, SLAT, WLON, NLAT, ELON, CRCS, COMT }
|
---|
38 | private enum S57catx { RCNM, RCID, NAM1, NAM2, COMT }
|
---|
39 | private enum S57dddf { RCNM, RCID, OORA, OAAC, OACO, OALL, OATY, DEFN, AUTH, COMT }
|
---|
40 | private enum S57dddr { RFTP, RFVL }
|
---|
41 | private enum S57dddi { RCNM, RCID, ATLB, ATDO, ADMU, ADFT, AUTH, COMT }
|
---|
42 | private enum S57ddom { RAVA, DVAL, DVSD, DEFN, AUTH }
|
---|
43 | private enum S57ddrf { RFTP, RFVL }
|
---|
44 | private enum S57ddsi { RCNM, RCID, OBLB }
|
---|
45 | private enum S57ddsc { ATLB, ASET, AUTH }
|
---|
46 | private enum S57frid { RCNM, RCID, PRIM, GRUP, OBJL, RVER, RUIN }
|
---|
47 | private enum S57foid { AGEN, FIDN, FIDS }
|
---|
48 | private enum S57attf { ATTL, ATVL }
|
---|
49 | private enum S57natf { ATTL, ATVL }
|
---|
50 | private enum S57ffpc { FFUI, FFIX, NFPT }
|
---|
51 | private enum S57ffpt { LNAM, RIND, COMT }
|
---|
52 | private enum S57fspc { FSUI, FSIX, NSPT }
|
---|
53 | private enum S57fspt { NAME, ORNT, USAG, MASK }
|
---|
54 | private enum S57vrid { RCNM, RCID, RVER, RUIN }
|
---|
55 | private enum S57attv { ATTL, ATVL }
|
---|
56 | private enum S57vrpc { VPUI, VPIX, NVPT }
|
---|
57 | private enum S57vrpt { NAME, ORNT, USAG, TOPI, MASK }
|
---|
58 | private enum S57sgcc { CCUI, CCIX, CCNC }
|
---|
59 | private enum S57sg2d { YCOO, XCOO }
|
---|
60 | private enum S57sg3d { YCOO, XCOO, VE3D }
|
---|
61 | private enum S57arcc { ATYP, SURF, ORDR, RESO, FPMF }
|
---|
62 | private enum S57ar2d { STPT, CTPT, ENPT, YCOO, XCOO }
|
---|
63 | private enum S57el2d { STPT, CTPT, ENPT, CDPM, CDPR, YCOO, XCOO }
|
---|
64 | private enum S57ct2d { YCOO, XCOO }
|
---|
65 |
|
---|
66 | private File importFile;
|
---|
67 | private FileInputStream inp;
|
---|
68 | private OsmDataLayer layer;
|
---|
69 | private DataSet data;
|
---|
70 |
|
---|
71 | private JButton importButton;
|
---|
72 | private ActionListener alImport = new ActionListener() {
|
---|
73 | public void actionPerformed(java.awt.event.ActionEvent e) {
|
---|
74 | if (e.getSource() == importButton) {
|
---|
75 | readFile();
|
---|
76 | Smed2Action.panelS57.setVisible(false);
|
---|
77 | Smed2Action.panelMain.setVisible(true);
|
---|
78 | PanelMain.messageBar.setText("File imported");
|
---|
79 | }
|
---|
80 | }
|
---|
81 | };
|
---|
82 | private JButton cancelButton;
|
---|
83 | private ActionListener alCancel = new ActionListener() {
|
---|
84 | public void actionPerformed(java.awt.event.ActionEvent e) {
|
---|
85 | if (e.getSource() == cancelButton) {
|
---|
86 | try {
|
---|
87 | inp.close();
|
---|
88 | } catch (IOException e1) {}
|
---|
89 | Smed2Action.panelS57.setVisible(false);
|
---|
90 | Smed2Action.panelMain.setVisible(true);
|
---|
91 | PanelMain.messageBar.setText("Import cancelled");
|
---|
92 | }
|
---|
93 | }
|
---|
94 | };
|
---|
95 |
|
---|
96 | public S57dat() {
|
---|
97 |
|
---|
98 | setLayout(null);
|
---|
99 | setSize(new Dimension(480, 480));
|
---|
100 | cancelButton = new JButton();
|
---|
101 | cancelButton.setBounds(250, 430, 100, 20);
|
---|
102 | cancelButton.setText(tr("Cancel"));
|
---|
103 | cancelButton.addActionListener(alCancel);
|
---|
104 | add(cancelButton);
|
---|
105 | importButton = new JButton();
|
---|
106 | importButton.setBounds(370, 430, 100, 20);
|
---|
107 | importButton.setText(tr("Import"));
|
---|
108 | importButton.addActionListener(alImport);
|
---|
109 | add(importButton);
|
---|
110 | }
|
---|
111 |
|
---|
112 | public void startImport(File file) {
|
---|
113 | importFile = file;
|
---|
114 | try {
|
---|
115 | inp = new FileInputStream(file);
|
---|
116 | } catch (IOException e) {
|
---|
117 | PanelMain.messageBar.setText("Failed to open file");
|
---|
118 | return;
|
---|
119 | }
|
---|
120 | Smed2Action.panelMain.setVisible(false);
|
---|
121 | Smed2Action.panelS57.setVisible(true);
|
---|
122 | }
|
---|
123 |
|
---|
124 | private void readFile() {
|
---|
125 | // Read & convert file.
|
---|
126 | // read record at a time
|
---|
127 | // read leader
|
---|
128 | // if DDR, build conversion tables
|
---|
129 | // if DR, build data structures
|
---|
130 | // Extract list of features & present on chooser panel
|
---|
131 | }
|
---|
132 |
|
---|
133 | private void importData() {
|
---|
134 | data = new DataSet();
|
---|
135 | // Transfer selected features
|
---|
136 | layer = new OsmDataLayer(data, importFile.getName(), null);
|
---|
137 | layer.setUploadDiscouraged(true);
|
---|
138 | Main.main.addLayer(layer);
|
---|
139 |
|
---|
140 | }
|
---|
141 | }
|
---|