Search in sources :

Example 1 with DefaultRoute

use of jmri.implementation.DefaultRoute in project JMRI by JMRI.

the class SensorGroup method addPressed.

void addPressed() {
    log.debug("start with " + sensorList.size() + " lines");
    RouteManager rm = InstanceManager.getDefault(jmri.RouteManager.class);
    String group = name.toUpperCase();
    // remove the old routes
    List<String> l = rm.getSystemNameList();
    String prefix = (namePrefix + group + nameDivider).toUpperCase();
    for (int i = 0; i < l.size(); i++) {
        String routeName = l.get(i);
        if (routeName.startsWith(prefix)) {
            // OK, kill this one
            Route r = rm.getBySystemName(l.get(i));
            r.deActivateRoute();
            rm.deleteRoute(r);
        }
    }
    // add the new routes
    for (int i = 0; i < sensorList.size(); i++) {
        String sensor = sensorList.get(i);
        String routeName = namePrefix + group + nameDivider + sensor;
        Route r = new DefaultRoute(routeName);
        // add the control sensor
        r.addSensorToRoute(sensor, Route.ONACTIVE);
        // add the output sensors
        for (int j = 0; j < sensorList.size(); j++) {
            String outSensor = sensorList.get(j);
            int mode = Sensor.INACTIVE;
            if (i == j) {
                mode = Sensor.ACTIVE;
            }
            r.addOutputSensor(outSensor, mode);
        }
        // make it persistant & activate
        r.activateRoute();
        rm.register(r);
    }
}
Also used : DefaultRoute(jmri.implementation.DefaultRoute) Route(jmri.Route) DefaultRoute(jmri.implementation.DefaultRoute) RouteManager(jmri.RouteManager)

Example 2 with DefaultRoute

use of jmri.implementation.DefaultRoute in project JMRI by JMRI.

the class DefaultRouteManager method provideRoute.

/**
     * Method to provide a Route whether or not is already exists.
     */
@Override
public Route provideRoute(String systemName, String userName) {
    Route r;
    r = getByUserName(systemName);
    if (r != null) {
        return r;
    }
    r = getBySystemName(systemName);
    if (r != null) {
        return r;
    }
    // Route does not exist, create a new route
    r = new DefaultRoute(systemName, userName);
    // save in the maps
    register(r);
    /*The following keeps trace of the last created auto system name.  
         currently we do not reuse numbers, although there is nothing to stop the 
         user from manually recreating them*/
    if (systemName.startsWith("IR:AUTO:")) {
        try {
            int autoNumber = Integer.parseInt(systemName.substring(8));
            if (autoNumber > lastAutoRouteRef) {
                lastAutoRouteRef = autoNumber;
            }
        } catch (NumberFormatException e) {
            log.warn("Auto generated SystemName " + systemName + " is not in the correct format");
        }
    }
    return r;
}
Also used : DefaultRoute(jmri.implementation.DefaultRoute) Route(jmri.Route) DefaultRoute(jmri.implementation.DefaultRoute)

Example 3 with DefaultRoute

use of jmri.implementation.DefaultRoute in project JMRI by JMRI.

the class Follower method instantiate.

/**
     * Create the underlying objects that implement this
     */
public void instantiate() {
    String nameT = namePrefix + "T" + nameDivider + output;
    String nameC = namePrefix + "C" + nameDivider + output;
    RouteManager rm = InstanceManager.getDefault(jmri.RouteManager.class);
    Route rt = rm.getBySystemName(nameT);
    // if an old one exists, remove it
    if (rt != null) {
        rt.deActivateRoute();
        rm.deleteRoute(rt);
    }
    Route rc = rm.getBySystemName(nameC);
    // if an old one exists, remove it
    if (rc != null) {
        rc.deActivateRoute();
        rm.deleteRoute(rc);
    }
    // create a new one
    rt = new DefaultRoute(nameT);
    rc = new DefaultRoute(nameC);
    // add trigger Sensor
    rt.addSensorToRoute(sensor, invert ? Route.ONINACTIVE : Route.ONACTIVE);
    rc.addSensorToRoute(sensor, !invert ? Route.ONINACTIVE : Route.ONACTIVE);
    // optionally, add veto
    if (!veto.equals("")) {
        rt.addSensorToRoute(veto, Route.VETOACTIVE);
        rc.addSensorToRoute(veto, Route.VETOACTIVE);
    }
    // add output
    rt.addOutputTurnout(output, Turnout.THROWN);
    rc.addOutputTurnout(output, Turnout.CLOSED);
    // and put Route into operation
    rt.activateRoute();
    rc.activateRoute();
    rm.register(rt);
    rm.register(rc);
}
Also used : DefaultRoute(jmri.implementation.DefaultRoute) Route(jmri.Route) DefaultRoute(jmri.implementation.DefaultRoute) RouteManager(jmri.RouteManager)

Aggregations

Route (jmri.Route)3 DefaultRoute (jmri.implementation.DefaultRoute)3 RouteManager (jmri.RouteManager)2