/** * Route Manager for Rob's Moving Map package * @author Robert J Morton * @version 18 December 1997 */ class route implements navconst { private static route CR; // reference to current route object private aircraft ac; // reference to current aircraft object private butpanel bp; // reference to the button panel object private waypnt WR[]; // array of references to waypoints in route private int NWR; // total number of waypoints in this route private int nwr; // number of waypoints so far installed private int CWN; // number of last waypoint in route private int cwn; // current waypoint number private wpenc we; // reference to a waypoint encounter event object private waypnt pw; // reference to previous waypoint private waypnt cw; // reference to 'current' waypoint route(int x, aircraft ac, butpanel bp) { CR = this; // reference to current route object this.ac = ac; // reference to the aircraft object this.bp = bp; // reference to the button panel object NWR = x; // set total number of waypoints in new route WR = new waypnt[NWR]; //array for references to waypoints in new route nwr = 0; // no waypoints installed yet } void AddWayPnt(waypnt w) { // ADD A GIVEN WAYPOINT TO A GIVEN ROUTE if(nwr < NWR) // Provided there's still room, WR[nwr++] = w; // put new waypoint's object reference } // in next route array element. void init() { // INITIALISE THE CURRENTLY-SELECTED ROUTE if(nwr < 3) // if less than 3 waypoints, that's not return; // enough waypoints to make a route, so exit CWN = nwr - 1; // index number of the last waypoint in the route double R = ac.getTCR(); // radius of turning circle //for each waypoint in the route except the last for(cwn = CWN ; cwn > 0 ; cwn--) { cw = WR[cwn]; // object reference to current waypoint pw = WR[cwn - 1]; // object reference to 'previous' waypoint pw.setNext(cw); /* current waypoint is previous waypoint's next waypoint */ cw.setPrev(pw); /* previous waypoint is current waypoint's previous waypoint */ ac.reset(pw); // set 'aircraft' to previous waypoint we = new wpenc(cw,ac); /* create an encounter between 'aircraft' and current waypoint */ double InRad = cw.gettBrg(), /* bearing of previous waypoint ('aircraft') from current one */ D = cw.getDst(); /* distance of current waypoint from prev waypoint ('aircraft') */ boolean isDest = false; // means current waypoint is not destination /* If doing the last waypoint in the route, make this waypoint its own next waypoint, set the distance to run after this way point twice its turning circle diameter, set the destination runway heading as the outbound direction and set the flag to indicate that this is the destination waypoint. */ if(cwn == CWN) { cw.setNext(cw); cw.setDST(4 * R); cw.setOutRad(cw.getRunHdg()); isDest = true; } cw.setDest(isDest); // current waypoint is/is not the destination cw.setInRad(InRad); // set for drawing the approach corridor cw.setPWD(D); // set waypoint's distance from previous waypoint pw.setDST(D); // set previous waypoint distance to this waypoint double OutRad = cw.getrBrg(); // Outbound radial to next waypoint /* If close enough for Cartesian approach & turn geometry, subtract the steering offset from the inbound radial. */ if(D < cw.getRange()) OutRad += we.getStrOff(InRad); pw.setOutRad(OutRad); // set previous waypoint's outbound radial double // compute the half-width of this waypoint's approach corridor a = ac.BipAng(InRad - cw.getOutRad() + π), b = R * (1 - Math.cos(a)); if(a < 0) // make it the same sign as 'a' b = -b; cw.setDL(b); // store it as the width for the approach corridor /* If the current waypoint is the second waypoint in route, the previous waypoint is the first, whose previous is itself and whose inbound radial 'InRad' is its own take-off runway heading. */ if(cwn == 1) { pw.setPrev(pw); pw.setInRad(ac.getHdg()); } } // end of for() loop } // ADVANCE THE AIRCRAFT ALONG THE CURRENTLY SELECTED ROUTE boolean advance() { if(we.enRoute()) // if the current waypoint encounter return true; // is still in progress, then exit /* If this is not the last waypoint in the route, set up the next waypoint encounter event and return that the flight still in progress. */ if(cwn < CWN) { we = new wpenc(WR[++cwn],ac); return true; } bp.stop(); // otherwise, hit the stop button and return false; // return that the flight has terminated } //reset aircraft to start of currently selected route void reset() {setAircraftAt(cwn = 0);} void setNext() { // set aircraft to next waypoint en-route if(cwn < CWN) setAircraftAt(++cwn); } void setPrev() { // set aircraft to previous waypoint en-route if(cwn > 0) setAircraftAt(--cwn); } void setThis(int x) { setAircraftAt(x); } // REPOSITION AIRCRAFT TO GIVEN WAYPOINT IN CURRENT ROUTE private void setAircraftAt(int x) { ac.reset(cw = WR[x]); // set aircraft to given waypoint if(x > 0) // if not at start of route ac.setHdg(cw.getOutRad()); // set aircraft heading to next waypoint we = new wpenc(cw,ac); // set up [next] waypoint encounter event } // get the object reference of the currently selected route static route getCurrent() {return CR;} }