Пример #1
0
  public Transit createTransit() throws JmriException {
    TransitManager tm = InstanceManager.transitManagerInstance();
    String transitName =
        "From "
            + list.get(0).getDisplayName()
            + " to "
            + list.get(list.size() - 1).getDisplayName();
    Transit t = tm.createNewTransit(transitName);
    if (t == null) {
      log.error("Unable to create transit " + transitName);
      throw new JmriException(Bundle.getMessage("TCTErrorUnableToCreate", transitName));
    }

    if (list.get(0) instanceof SignalMast) {
      jmri.SignalMastLogicManager smlm = InstanceManager.signalMastLogicManagerInstance();
      for (int i = 1; i <= list.size() - 1; i++) {
        jmri.SignalMastLogic sml = smlm.getSignalMastLogic((SignalMast) list.get(i - 1));
        Section sec = sml.getAssociatedSection((SignalMast) list.get(i));
        // In theory sec being null would already have been tested when the signal was added.
        if (sec == null) {
          String error =
              Bundle.getMessage(
                  "TCTErrorMastPairsNoSection",
                  list.get(i - 1).getDisplayName(),
                  list.get(i).getDisplayName());
          log.error(error);
          tm.deregister(t);
          t.dispose();
          cancelTransitCreate();
          throw new JmriException(error);
        }
        t.addTransitSection(new jmri.TransitSection(sec, i, Section.FORWARD));
      }
    }
    // Once created clear the list for a fresh start.
    list = new ArrayList<NamedBean>();
    return t;
  }
Пример #2
0
 public void addNamedBean(NamedBean nb) throws JmriException {
   if (!list.isEmpty()) {
     if (list.get(list.size() - 1) == nb) {
       log.debug("Bean is the same as the last one so will not add or error");
       return;
     }
     // Run through a series of checks that this bean is reachable from the previous
     if ((nb instanceof SignalMast) && (list.get(list.size() - 1) instanceof SignalMast)) {
       jmri.SignalMastLogicManager smlm = InstanceManager.signalMastLogicManagerInstance();
       jmri.SignalMastLogic sml =
           smlm.getSignalMastLogic(((SignalMast) list.get(list.size() - 1)));
       if (sml == null || !sml.isDestinationValid((SignalMast) nb)) {
         String error =
             Bundle.getMessage(
                 "TCTErrorMastPairsNotValid",
                 nb.getDisplayName(),
                 list.get(list.size() - 1).getDisplayName());
         log.error(error);
         throw new JmriException(error);
       }
       if (sml.getAssociatedSection((SignalMast) nb) == null) {
         String error =
             Bundle.getMessage(
                 "TCTErrorMastPairsNoSection",
                 list.get(list.size() - 1).getDisplayName(),
                 nb.getDisplayName());
         log.error(error);
         throw new JmriException(error);
       }
     } else {
       // Need to add the method to get layout block connectivity.  Also work checking that the
       // Layout Block routing has been initialised.
     }
   }
   list.add(nb);
 }