]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/data/SourceInfo.java
Version 17, September 2014
[GpsPrune.git] / tim / prune / data / SourceInfo.java
1 package tim.prune.data;
2
3 import java.io.File;
4
5 /**
6  * Class to hold the source of the point data, including the original file
7  * and file type, and references to each of the point objects
8  */
9 public class SourceInfo
10 {
11         /** File type of source file */
12         public enum FILE_TYPE {TEXT, GPX, KML, NMEA, GPSBABEL, GPSIES};
13
14         /** Source file */
15         private File _sourceFile = null;
16         /** Name of source */
17         private String _sourceName = null;
18         /** File type */
19         private FILE_TYPE _fileType = null;
20
21         /** Array of datapoints */
22         private DataPoint[] _points = null;
23         /** Number of points */
24         private int _numPoints = 0;
25         /** Array of point indices (if necessary) */
26         private int[] _pointIndices = null;
27
28
29         /**
30          * Constructor
31          * @param inFile source file
32          * @param inType type of file
33          */
34         public SourceInfo(File inFile, FILE_TYPE inType)
35         {
36                 _sourceFile = inFile;
37                 _sourceName = inFile.getName();
38                 _fileType = inType;
39         }
40
41         /**
42          * Constructor
43          * @param inName name of source (without file)
44          * @param inType type of file
45          */
46         public SourceInfo(String inName, FILE_TYPE inType)
47         {
48                 _sourceFile = null;
49                 _sourceName = inName;
50                 _fileType = inType;
51         }
52
53         /**
54          * @return source file
55          */
56         public File getFile()
57         {
58                 return _sourceFile;
59         }
60
61         /**
62          * @return source name
63          */
64         public String getName()
65         {
66                 return _sourceName;
67         }
68
69         /**
70          * @return file type of source
71          */
72         public FILE_TYPE getFileType()
73         {
74                 return _fileType;
75         }
76
77         /**
78          * @return number of points from this source
79          */
80         public int getNumPoints()
81         {
82                 return _numPoints;
83         }
84
85         /**
86          * Set the indices of the points selected out of a loaded track
87          * @param inSelectedFlags array of booleans showing whether each point in the original data was loaded or not
88          */
89         public void setPointIndices(boolean[] inSelectedFlags)
90         {
91                 _numPoints = inSelectedFlags.length;
92                 _pointIndices = new int[_numPoints];
93                 int p=0;
94                 for (int i=0; i<_numPoints; i++) {
95                         if (inSelectedFlags[i]) {_pointIndices[p++] = i;}
96                 }
97                 // Now the point indices array holds the index of each of the selected points
98         }
99
100         /**
101          * Take the points from the given track and store
102          * @param inTrack track object containing points
103          * @param inNumPoints number of points loaded
104          */
105         public void populatePointObjects(Track inTrack, int inNumPoints)
106         {
107                 if (_numPoints == 0) {_numPoints = inNumPoints;}
108                 if (inNumPoints > 0)
109                 {
110                         _points = new DataPoint[inNumPoints];
111                         int trackLen = inTrack.getNumPoints();
112                         System.arraycopy(inTrack.cloneContents(), trackLen-inNumPoints, _points, 0, inNumPoints);
113                         // Note data copied twice here but still more efficient than looping
114                 }
115         }
116
117         /**
118          * Look for the given point in the array
119          * @param inPoint point to look for
120          * @return index, or -1 if not found
121          */
122         public int getIndex(DataPoint inPoint)
123         {
124                 int idx = -1;
125                 for (int i=0; i<_points.length; i++)
126                 {
127                         if (_points[i] == inPoint) {
128                                 idx = i;
129                                 break;
130                         }
131                 }
132                 if (idx == -1) {return idx;}             // point not found
133                 if (_pointIndices == null) {return idx;} // All points loaded
134                 return _pointIndices[idx]; // use point index mapping
135         }
136 }