[Bprocessor-commit] model/src/net/sourceforge/bprocessor/model Project.java, 1.107, 1.108
Status: Pre-Alpha
Brought to you by:
henryml
|
From: Nikolaj B. <nbr...@us...> - 2007-01-08 12:31:34
|
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv20304/src/net/sourceforge/bprocessor/model Modified Files: Project.java Log Message: Implemented import for csv files with points from landmålergården Index: Project.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Project.java,v retrieving revision 1.107 retrieving revision 1.108 diff -C2 -d -r1.107 -r1.108 *** Project.java 6 Jan 2007 21:06:59 -0000 1.107 --- Project.java 8 Jan 2007 12:31:26 -0000 1.108 *************** *** 11,14 **** --- 11,15 ---- import java.io.File; import java.io.FileInputStream; + import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; *************** *** 1128,1131 **** --- 1129,1188 ---- return copyBuffer; } + + /** + * Load a file + * @param lfile The file to load + * @throws IOException + * @exception IOException Thrown if an exception occurs + */ + public void importCSV(File lfile) throws IOException { + BufferedReader bf; + bf = new BufferedReader( + new InputStreamReader(new FileInputStream(lfile))); + String current = ""; + Vertex firstVer = null; + Vertex fromVer = null; + Vertex toVer; + double x = 0; + double y = 0; + double z = 0; + int curId = 0; + int lastId = 0; + int i = 0; + List<Edge> newEdges = new LinkedList<Edge>(); + current = bf.readLine(); + while (current != null) { + StringTokenizer st = new StringTokenizer(current, ";"); + st.nextToken(); + st.nextToken(); + y = Double.parseDouble(st.nextToken()); + x = Double.parseDouble(st.nextToken()); + z = Double.parseDouble(st.nextToken()); + st.nextToken(); + curId = Integer.parseInt(st.nextToken()); + + if (curId <= lastId) { + newEdges.add(new Edge(fromVer, firstVer)); + lastId = 0; + } + + if (curId == 1) { + firstVer = new Vertex(x, y, z); + fromVer = new Vertex(x, y, z); + lastId = curId; + } + + if (curId >= lastId && curId > 1) { + toVer = new Vertex(x, y, z); + newEdges.add(new Edge(fromVer, toVer)); + fromVer = toVer; + lastId = curId; + } + current = bf.readLine(); + } + for (Edge e : newEdges) { + Project.getInstance().world().insert(e); + } + } } |