// EPS: Elgaard Positioning System: GPS navigation software. // Copyright (C) 1997 Niels Elgaard Larsen // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // Niels Elgaard Larsen, // import java.awt.*; // EPS: Elgaard Positioning System: GPS navigation software. // Copyright (C) 1997, 1999 Niels Elgaard Larsen // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // Niels Elgaard Larsen, // import java.io.*; import java.net.*; import java.lang.Runtime; import java.util.Date; import java.text.*; class WPC { int nWP=0, maxWP=500; WayPoint wayPoints[] = new WayPoint[maxWP]; public void flushList(List wpl, boolean isRoute){ int nw; double sumDist=0d; double dist=0d; if (wpl!=null){ // netscape problem if (wpl.getItemCount() >0){ CAux.perr("flushList ic = "+ wpl.getItemCount(), 2); wpl.removeAll(); } for (nw=0 ; nw0)?(" +" + CAux.frds(dist*GMenv.lengthMul,2) + GMenv.lengthUnitName):"" )+ "=" + CAux.frds(sumDist*GMenv.lengthMul,2) + " " + GMenv.lengthUnitName); if (nw < nWP-1){ dist = wayPoints[nw].wpos.dist(wayPoints[nw+1].wpos); sumDist += dist; } } else { wpl.add("" + wayPoints[nw].name); } } } } public void delete(int nd){ int nw; nWP--; for (nw=nd; nw < nWP; nw++){ wayPoints[nw] = wayPoints[nw+1]; } wayPoints[nWP]=null; } public void deleteAll(){ nWP = 0; } WayPoint readWP(TextArea err, List wl, String inputLine, int posFmt, int filf, boolean isRoute){ WayPoint nwp = new WayPoint(); if (filf==Pone.ffGARLINK){ int rOff = (isRoute)?1:0; nwp.name = CAux.getCol(inputLine,rOff,' '); if (nwp.name.length()>6){ nwp.name = nwp.name.substring(0,6); } nwp.wpos.y = Pone.str2Pone(inputLine,rOff+1,posFmt,filf); nwp.wpos.x = Pone.str2Pone(inputLine,rOff+2,posFmt,filf); } else if (filf==Pone.ffGPSTRANS){ int rOff = (isRoute)?0:1; nwp.name = CAux.getCol(inputLine,1,'\t'); nwp.wpos.y = Pone.str2Pone(inputLine,rOff+3,posFmt,filf); nwp.wpos.x = Pone.str2Pone(inputLine,rOff+4,posFmt,filf); if (!isRoute) { nwp.comment = CAux.getCol(inputLine,2,'\t'); if (nwp.comment != null) { nwp.comment = nwp.comment.toUpperCase(); } nwp.timestamp = CAux.readDate(CAux.getCol(inputLine,3,'\t')); } } else if (filf==Pone.ffGRM){ if (inputLine==null || inputLine.length()==0 || inputLine.charAt(0)!='W'){ return(null); } nwp.name = inputLine.substring(3,9); nwp.wpos.y = Pone.str2Pone(inputLine,2,posFmt,filf); nwp.wpos.x = Pone.str2Pone(inputLine,3,posFmt,filf); } nwp.name = nwp.name.toUpperCase(); // System.out.println("new wp " + wayPoints[nWP].name + // " "+wayPoints[nWP].toString(1)); insertWP(err,null,nwp,false); // ChartFrame.wlist.add("" + nWP + " "+ nwp.name); flushList(wl,false); return (nwp); } void readWayPoints (TextArea err, List wl,URL epsBase, String wpfile, int filf, GMenv menv) { int posFmt=Pone.DDD; URL tURL; Datum pDatum = Pos.WGS84; BufferedReader dis=null; String inputLine; //GMenv.wpfile = wpfile; try { CAux.perr("Read waypoints:"+wpfile, 2); tURL =new URL(epsBase, wpfile); CAux.perr("Read waypoints from URL: "+tURL, 2); if (GMenv.useFShield) { dis = ChartFrame1.fShield.getBuf(tURL); } else { dis = new BufferedReader(new InputStreamReader(tURL.openStream())); } CAux.perr("Read waypoints got DIS", 4); if (filf==Pone.ffGPSTRANS){ inputLine = ChartFrame1.readline(dis); CAux.perr("il ="+inputLine,2); if (inputLine!=null) { // System.out.println("0--7 " + inputLine.substring(0,7)); if (inputLine.substring(0,7).equals("Format:")){ // System.out.println("found Format"); if (inputLine.substring(8,11).equals("DDD")){ posFmt = Pone.DDD; } else { posFmt = Pone.MDD; } } } int datumNo; datumNo = Integer.parseInt(inputLine.substring(43,46)); pDatum = Pos.getGtDatum(datumNo); } //while ((inputLine = ChartFrame1.fShield.sreadLine(dis)) != null) { inputLine = ChartFrame1.readline(dis); while (inputLine != null) { WayPoint d; //System.out.println("now read " + inputLine + " ff="+filf+" pf="+posFmt); d = readWP(err,null,inputLine, posFmt, filf,false); d.wpos.theDatum = pDatum; inputLine = ChartFrame1.readline(dis); } flushList(wl,false); dis.close(); } catch (MalformedURLException me) { err.setText("MalformedURLException: " + me); } catch (FileNotFoundException fe) { err.setText("waypoint file not found: " + fe); } catch (IOException ioe) { err.setText("Could not find wayPoints:" + ioe); } catch (StringIndexOutOfBoundsException ioe) { err.setText("Could not read Waypoint file " + ioe); ioe.printStackTrace(); } catch (NumberFormatException ioe) { err.setText("Could not read Waypoint file " + ioe); } catch (SecurityException ioe) { err.setText("Could not read WP file " + ioe); } flushList(wl,false); } public void insertWP(TextArea err,List wl, WayPoint wp, boolean isRoute){ int oldInx=0; int nw; WayPoint ewp; ewp = findWP(wp.name); if (!isRoute && ewp!=null && ewp.wpos.eq(wp.wpos)){ if (err != null) { try { err.append("WP already exist:"+wp.name+"\n"); } catch (NoSuchMethodError ex) { CAux.perr("WP already exist:"+wp.name,0); } } return; } if (nWP >= maxWP) { int xi; WayPoint w0[] = wayPoints; wayPoints = new WayPoint[2*maxWP]; for (xi=0;xioldInx; nw--){ wayPoints[nw] = wayPoints[nw-1]; } nWP++; wayPoints[oldInx] = wp; if (wl!=null){ flushList(wl,isRoute); } } public WayPoint findWP(String wname){ int nwp=0; while (nwp < nWP) { if (wayPoints[nwp].name.equals(wname)){ return(wayPoints[nwp]); } nwp++; } return(null); } WayPoint findWP(WayPoint wp){ int nwp=0; while (nwp < nWP) { if (wayPoints[nwp]==wp){ return(wayPoints[nwp]); } nwp++; } return(null); } public void output(TextArea ta, int ff, int off,Datum datum,String fn, GMenv menv){ try { DataOutputStream dos; boolean ferr = false; String fn1 = fn; try { File oFile; oFile = new File(fn1); if (!oFile.isAbsolute()) { CAux.perr("WPS making abs: "+oFile + " base=" + menv.epsfBase,4); oFile = new File(menv.epsfBase,fn1); } CAux.perr("oFile="+oFile,4); dos = new DataOutputStream(ChartFrame1.fShield.fos(oFile)); CAux.perr("got dos="+dos,4); output(null,dos,ff,off, datum); } catch (SecurityException me) { System.out.println(" WPC SecurityException: " + me); me.printStackTrace(); ferr=true; } catch (IOException me) { System.out.println(" File IOException: uWP" + me); ferr=true; } if (ferr) { ta.setText(""); output(ta,null,ff,off, datum); } } catch (IOException me) { System.out.println(" File IOException: uWP" + me); } } public void output(TextArea ta, DataOutputStream dos, int ff,int off,Datum datum) throws IOException{ String dstr; int nw; if (ff==Pone.ffGPSTRANS){ String Soff = ""+off; String Sdatum = ""+datum.gpstransNo; CAux.fo( "Format: DDD UTC Offset:" + " ".substring(0,4-Soff.length()) + Soff + ".00 hrs Datum["+ "000".substring(0,3-Sdatum.length()) + Sdatum+ "]: "+datum.name+"\n",dos,ta); for (nw=0; nw < nWP; nw++){ Pos outPos = wayPoints[nw].wpos.toDatum(datum); dstr = CAux.localOutDefault.format(wayPoints[nw].timestamp); CAux.fo("W" + "\t" + wayPoints[nw].name+"\t"+ wayPoints[nw].comment + "\t"+ dstr + "\t"+ outPos.toString(ff)+"\n", dos, ta); } } else if (ff==Pone.ffGARLINK) { for (nw=0; nw < nWP; nw++){ CAux.fo( CAux.spad(wayPoints[nw].name,6,' ') + " " + wayPoints[nw].wpos.toString(Pone.pfGARLINK) + " ______________ \n",dos,ta); } } if (dos!=null){ dos.close(); } } }