// 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.awt.*; import java.io.*; import java.net.*; import java.lang.Runtime; import java.text.*; class RouteC { static int nRT=0; static int maxRT=100; static Route routes[] = new Route[maxRT]; static public void flushList(List rl){ int nr; if (rl!=null){ if (rl.getItemCount() >0){ rl.removeAll(); } for (nr=0;nr0 && inputLine.charAt(0)=='R') { int routeNo; nRoute = new Route(); routeNo = Integer.valueOf(CAux.getCol(inputLine,1, (filf==Pone.ffGPSTRANS)?'\t':' ')).intValue(); if (filf==Pone.ffGPSTRANS){ nRoute.name = CAux.getCol(inputLine,2,(filf==Pone.ffGPSTRANS)?'\t':' '); nRoute.name = nRoute.name.toUpperCase(); } else { inputLine = ChartFrame1.readline(dis); inputLine = ChartFrame1.readline(dis); // H line nRoute.name = "GRM Route "+routeNo; } insertRoute(err,rl,nRoute); inputLine = ChartFrame1.readline(dis); while (inputLine != null && (inputLine.length()==0|| (inputLine.charAt(0)=='W')) ) { String WPname; WayPoint thisWP; WPname = CAux.getCol(inputLine,1,(filf==Pone.ffGPSTRANS)?'\t':' '); WPname = WPname.toUpperCase(); thisWP = aWP.theWP.findWP(WPname); if (thisWP == null) { thisWP = aWP.theWP.readWP(err,null,inputLine, posFmt,filf,true); thisWP.wpos.theDatum = pDatum; try { err.append("Waypoint "+ WPname+ " found in route, " + " added to Waypoints\n"); } catch (NoSuchMethodError ex) { CAux.perr("Waypoint "+ WPname+ " found in route, " + " added to Waypoints",1); } aWP.theWP.flushList(wlist,false); } //System.out.println("new rt:nRT " +nRT + "" + nRoute.name + ": " // + thisWP.toString(1)); if (thisWP != null) { nRoute.wpts.insertWP(err, null, thisWP, true); } inputLine = ChartFrame1.readline(dis); } nRoute.wpts.flushList(routeWPList,true); } } else { //RWP int pRoute=-1, rn; WayPoint thisWP; String WPname; inputLine = ChartFrame1.readline(dis); while (inputLine !=null) { rn = Integer.valueOf(CAux.getCol(inputLine,0,' ')).intValue(); if (pRoute<0 || rn != pRoute){ nRoute= new Route(); nRoute.name = "Route" + rn; insertRoute(err,rl,nRoute); pRoute=rn; } WPname = CAux.getCol(inputLine,1,' '); thisWP = aWP.theWP.findWP(WPname); if (thisWP == null) { thisWP = aWP.theWP.readWP(err,null,inputLine, posFmt,filf,true); try { err.append("Waypoint "+ WPname+ " Found in route, " + " added to Waypoints" +"\n"); } catch (NoSuchMethodError ex) { CAux.perr("Waypoint "+ WPname+ " Found in route, " + " added to Waypoints",0); } aWP.theWP.flushList(wlist,false); } nRoute.wpts.insertWP(err,routeWPList, thisWP, false); inputLine = ChartFrame1.readline(dis); } } dis.close(); } catch (MalformedURLException me) { System.out.println("MalformedURLException: " + me); } catch (FileNotFoundException fe) { System.out.println("Route file not found: " + fe); } catch (IOException ioe) { System.out.println("Route Not found " + ioe); } catch (StringIndexOutOfBoundsException ioe) { System.out.println("Could not read route file " + "\""+rtfile+"\" "+ ioe); ioe.printStackTrace(); } catch (NumberFormatException ioe) { System.out.println("Could not read route file " + ioe); } catch (SecurityException ioe) { System.out.println("Could not read route file (SE)" + ioe); ioe.printStackTrace(); } } static public Route findWPinRoute(WayPoint wp){ int nrt=0; while (nrt < nRT) { if (routes[nrt].wpts.findWP(wp)!=null){ return(routes[nrt]); } nrt++; } return(null); } static public void insertRoute(TextArea err, List rl, Route ro ){ int xi; int newMax = 2*maxRT; Route r0[]; MenuItem ri = new MenuItem(ro.name); if (findRT(ro.name)!=null){ if (err!= null) { try { err.append("Route \""+ro.name+ "\" already exist:" + "\n"); //throw (new Error("Route already exist")); } catch (NoSuchMethodError ex) { CAux.perr("ROUTE \""+ro.name+ "\" already exist:",0); ex.printStackTrace(); } } else { System.out.println("Route \""+ro.name+ "\" already exist:" + "\n"); } return; } if (nRT >= maxRT) { r0 = routes; routes = new Route[newMax]; for (xi=0;xi