Changeset 180 in tmcsimulator for trunk/src/atmsdriver/model/Highways.java


Ignore:
Timestamp:
10/27/2017 01:38:13 PM (9 years ago)
Author:
jdalbey
Message:

ATMSDriver.java Refactored for cleaner design. DotColor? enum moved to LoopDetector? class. ConsoleDriver? renamed ConsoleTrafficDriver? (and associated project configurations updated), build.xml package-jars target updated, ConsoleTrafficDriver? logic improved to allow more user control, runtraffic.bash script created for automating traffic display tests.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/atmsdriver/model/Highways.java

    r176 r180  
    109109        return highways; 
    110110    } 
    111      
     111        /** 
     112     * Applies specified color to the specified highway stretch. Route number and 
     113     * direction specify the highway. Postmile and range specify the stretch of 
     114     * specified highway. Dot color is the color to be applied to the stretch. 
     115     *  
     116     * @param routeNumber highway route number 
     117     * @param direction highway direction 
     118     * @param postmile origin postmile value 
     119     * @param range range from origin postmile 
     120     * @param dotColor the color to be applied to specified highway stretch 
     121     */ 
     122    public void applyColorToHighwayStretch(Integer routeNumber, Station.DIRECTION direction,  
     123            Double postmile, Double range, LoopDetector.DOTCOLOR dotColor) { 
     124        System.out.println("Applying " + dotColor.name() + " dots to highway "  
     125                + routeNumber + " " + direction.name() + " at postmile "  
     126                + postmile + " with a range of " + range + " miles..."); 
     127         
     128        // Get the highway by route number 
     129        Highway highway = getHighwayByRouteNumber(routeNumber); 
     130         
     131        // start value for highway section, and end value for highway section 
     132        // by postmile 
     133        Double startPost; 
     134        Double endPost; 
     135         
     136        // postmiles increase from s to n and w to e 
     137         
     138        // if the direction is south or west 
     139        if(direction.equals(Station.DIRECTION.SOUTH) || direction.equals(Station.DIRECTION.WEST)) 
     140        { 
     141            // add range value to startPost to get 
     142            // the end postmile value of the highway section 
     143            startPost = postmile; 
     144            endPost = postmile + range; 
     145             
     146            // iterate through the stations, if within the specified highway 
     147            // stretch, update the station by direction and apply dot color 
     148            for(Station station : highway.stations) 
     149            { 
     150                if(station.postmile >= startPost && station.postmile <= endPost) 
     151                { 
     152                    station.updateByDirection(direction, dotColor); 
     153                } 
     154            } 
     155        } 
     156        // if the direction is north or east  
     157        else 
     158        { 
     159            //subtract range value from startPost 
     160            // to get the end postmile value of the highway section 
     161            startPost = postmile; 
     162            endPost = postmile - range; 
     163             
     164            // iterate through the stations, if within the specified highway 
     165            // section, update the station by direction and apply dot color 
     166            for(Station station : highway.stations) 
     167            { 
     168                if(station.postmile <= startPost && station.postmile >= endPost) 
     169                { 
     170                    station.updateByDirection(direction, dotColor); 
     171                } 
     172            } 
     173        } 
     174        System.out.println(""); 
     175    } 
     176 
    112177    /* 
    113178     private ArrayList<FEPLine> loadLines(String highwayMetaFileName) { 
Note: See TracChangeset for help on using the changeset viewer.