Search in sources :

Example 16 with Section

use of jmri.Section in project JMRI by JMRI.

the class AutoAllocate method autoNextSectionChoice.

/**
     * Entered to request a choice of Next Section when a Section is being
     * allocated and there are alternate Section choices for the next Section.
     *
     * @param sList the possible next Sections
     * @param ar    the section being allocated when a choice is needed
     * @return the allocated section
     */
protected Section autoNextSectionChoice(ArrayList<Section> sList, AllocationRequest ar) {
    // check if AutoAllocate has prepared for this question
    if ((savedAR != null) && (savedAR == ar)) {
        for (int j = 0; j < sList.size(); j++) {
            if (savedSection == sList.get(j)) {
                return savedSection;
            }
        }
        log.warn("Failure of prepared choice of next Section in AutoAllocate");
    }
    // Jay Janzen 
    // If there is an AP check to see if the AP's target is on the list of choices
    // and if so, return that.
    ActiveTrain at = ar.getActiveTrain();
    AllocationPlan ap = getPlanThisTrain(at);
    Section as = null;
    if (ap != null) {
        if (ap.getActiveTrain(1) == at) {
            as = ap.getTargetSection(1);
        } else if (ap.getActiveTrain(2) == at) {
            as = ap.getTargetSection(2);
        } else {
            return null;
        }
        for (int i = 0; i < sList.size(); i++) {
            if (as != null && as == sList.get(i)) {
                return as;
            }
        }
    }
    // we wind up skipping right over our end section.
    for (int i = 0; i < sList.size(); i++) {
        if (at.getEndBlockSection().getSystemName().equals(sList.get(i).getSystemName())) {
            return sList.get(i);
        }
    }
    // no prepared choice, or prepared choice failed, is there an unoccupied Section available
    for (int i = 0; i < sList.size(); i++) {
        if ((sList.get(i).getOccupancy() == Section.UNOCCUPIED) && (sList.get(i).getState() == Section.FREE) && (_dispatcher.getSignalType() == DispatcherFrame.SIGNALHEAD || (_dispatcher.getSignalType() == DispatcherFrame.SIGNALMAST && _dispatcher.checkBlocksNotInAllocatedSection(sList.get(i), ar) == null))) {
            return sList.get(i);
        }
    }
    // no unoccupied Section available, check for Section allocated in same direction as this request
    int dir = ar.getSectionDirection();
    ArrayList<AllocatedSection> allocatedSections = _dispatcher.getAllocatedSectionsList();
    for (int m = 0; m < sList.size(); m++) {
        boolean notFound = true;
        for (int k = 0; (k < allocatedSections.size()) && notFound; k++) {
            if (sList.get(m) == allocatedSections.get(k).getSection()) {
                notFound = false;
                if (allocatedSections.get(k).getSection().getState() == dir) {
                    return sList.get(m);
                }
            }
        }
    }
    // if all else fails, return null so Dispatcher will ask the dispatcher to choose
    return null;
}
Also used : Section(jmri.Section) TransitSection(jmri.TransitSection)

Example 17 with Section

use of jmri.Section in project JMRI by JMRI.

the class AutoAllocate method firstTrainLeadsSecond.

private boolean firstTrainLeadsSecond(ActiveTrain at, ActiveTrain nt) {
    int aSeq = getCurrentSequenceNumber(at);
    Section aSec = getCurSection();
    int nSeq = getCurrentSequenceNumber(nt);
    Section nSec = getCurSection();
    ArrayList<TransitSection> atsList = at.getTransit().getTransitSectionList();
    if (!at.isTransitReversed()) {
        for (int i = 0; i < atsList.size(); i++) {
            if (atsList.get(i).getSequenceNumber() > aSeq) {
                if (atsList.get(i).getSection() == nSec) {
                    // first train has not yet reached second train position
                    return false;
                }
            }
        }
    } else {
        for (int i = atsList.size() - 1; i <= 0; i--) {
            if (atsList.get(i).getSequenceNumber() < aSeq) {
                if (atsList.get(i).getSection() == nSec) {
                    // first train has not yet reached second train position
                    return false;
                }
            }
        }
    }
    ArrayList<TransitSection> ntsList = nt.getTransit().getTransitSectionList();
    if (!nt.isTransitReversed()) {
        for (int i = 0; i < ntsList.size(); i++) {
            if (ntsList.get(i).getSequenceNumber() > nSeq) {
                if (ntsList.get(i).getSection() == aSec) {
                    // second train has found first train in its on coming Sections
                    return true;
                }
            }
        }
    } else {
        for (int i = ntsList.size() - 1; i <= 0; i--) {
            if (ntsList.get(i).getSequenceNumber() < nSeq) {
                if (ntsList.get(i).getSection() == aSec) {
                    // second train has found first train in its on coming Sections
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : TransitSection(jmri.TransitSection) Section(jmri.Section) TransitSection(jmri.TransitSection)

Example 18 with Section

use of jmri.Section in project JMRI by JMRI.

the class AutoAllocate method willTrainsCross.

private boolean willTrainsCross(ActiveTrain at, ActiveTrain nt) {
    // returns true if both trains will eventually reach the others position
    int aSeq = getCurrentSequenceNumber(at);
    Section aSec = getCurSection();
    int nSeq = getCurrentSequenceNumber(nt);
    Section nSec = getCurSection();
    ArrayList<TransitSection> atsList = at.getTransit().getTransitSectionList();
    boolean found = false;
    if (!at.isTransitReversed()) {
        for (int i = 0; (i < atsList.size()) && (!found); i++) {
            if (atsList.get(i).getSequenceNumber() > aSeq) {
                if (atsList.get(i).getSection() == nSec) {
                    // first train has reached second train position
                    found = true;
                }
            }
        }
    } else {
        for (int i = atsList.size() - 1; (i <= 0) && (!found); i--) {
            if (atsList.get(i).getSequenceNumber() < aSeq) {
                if (atsList.get(i).getSection() == nSec) {
                    // first train has reached second train position
                    found = true;
                }
            }
        }
    }
    if (!found) {
        return false;
    }
    ArrayList<TransitSection> ntsList = nt.getTransit().getTransitSectionList();
    if (!nt.isTransitReversed()) {
        for (int i = 0; i < ntsList.size(); i++) {
            if (ntsList.get(i).getSequenceNumber() > nSeq) {
                if (ntsList.get(i).getSection() == aSec) {
                    // second train has found first train in its on coming Sections
                    return true;
                }
            }
        }
    } else {
        for (int i = ntsList.size() - 1; i <= 0; i--) {
            if (ntsList.get(i).getSequenceNumber() < nSeq) {
                if (ntsList.get(i).getSection() == aSec) {
                    // second train has found first train in its on coming Sections
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : TransitSection(jmri.TransitSection) Section(jmri.Section) TransitSection(jmri.TransitSection)

Example 19 with Section

use of jmri.Section in project JMRI by JMRI.

the class TransitManagerXml method store.

/**
     * Default implementation for storing the contents of a TransitManager
     *
     * @param o Object to store, of type TransitManager
     * @return Element containing the complete info
     */
@Override
public Element store(Object o) {
    Element transits = new Element("transits");
    setStoreElementClass(transits);
    TransitManager tm = (TransitManager) o;
    if (tm != null) {
        java.util.Iterator<String> iter = tm.getSystemNameList().iterator();
        // don't return an element if there are not Transits to include
        if (!iter.hasNext()) {
            return null;
        }
        // store the Transit
        while (iter.hasNext()) {
            String sname = iter.next();
            if (sname == null) {
                log.error("System name null during store");
            } else {
                log.debug("Transit system name is " + sname);
                Transit x = tm.getBySystemName(sname);
                Element elem = new Element("transit");
                elem.addContent(new Element("systemName").addContent(sname));
                // store common part
                storeCommon(x, elem);
                // save child transitsection entries
                ArrayList<TransitSection> tsList = x.getTransitSectionList();
                Element tsElem = null;
                for (int k = 0; k < tsList.size(); k++) {
                    TransitSection ts = tsList.get(k);
                    if (ts != null && !ts.isTemporary()) {
                        tsElem = new Element("transitsection");
                        Section tSection = ts.getSection();
                        if (tSection != null) {
                            tsElem.setAttribute("sectionname", tSection.getSystemName());
                        } else {
                            tsElem.setAttribute("sectionname", "null");
                        }
                        tsElem.setAttribute("sequence", Integer.toString(ts.getSequenceNumber()));
                        tsElem.setAttribute("direction", Integer.toString(ts.getDirection()));
                        tsElem.setAttribute("alternate", "" + (ts.isAlternate() ? "yes" : "no"));
                        // save child transitsectionaction entries if any
                        ArrayList<TransitSectionAction> tsaList = ts.getTransitSectionActionList();
                        if (tsaList.size() > 0) {
                            Element tsaElem = null;
                            for (int m = 0; m < tsaList.size(); m++) {
                                TransitSectionAction tsa = tsaList.get(m);
                                if (tsa != null) {
                                    tsaElem = new Element("transitsectionaction");
                                    tsaElem.setAttribute("whencode", Integer.toString(tsa.getWhenCode()));
                                    tsaElem.setAttribute("whatcode", Integer.toString(tsa.getWhatCode()));
                                    tsaElem.setAttribute("whendata", Integer.toString(tsa.getDataWhen()));
                                    tsaElem.setAttribute("whenstring", tsa.getStringWhen());
                                    tsaElem.setAttribute("whatdata1", Integer.toString(tsa.getDataWhat1()));
                                    tsaElem.setAttribute("whatdata2", Integer.toString(tsa.getDataWhat2()));
                                    tsaElem.setAttribute("whatstring", tsa.getStringWhat());
                                    tsElem.addContent(tsaElem);
                                }
                            }
                        }
                        elem.addContent(tsElem);
                    }
                }
                transits.addContent(elem);
            }
        }
    }
    return (transits);
}
Also used : TransitSection(jmri.TransitSection) TransitManager(jmri.TransitManager) Element(org.jdom2.Element) TransitSectionAction(jmri.TransitSectionAction) Transit(jmri.Transit) Section(jmri.Section) TransitSection(jmri.TransitSection)

Example 20 with Section

use of jmri.Section in project JMRI by JMRI.

the class SectionTableAction method updatePressed.

void updatePressed(ActionEvent e) {
    if (!checkSectionInformation()) {
        return;
    }
    // check if user name has been changed
    String uName = userName.getText();
    if (uName.equals("")) {
        uName = null;
    }
    if ((uName != null) && (!uName.equals(curSection.getUserName()))) {
        // check that new user name is unique
        Section tSection = sectionManager.getByUserName(uName);
        if (tSection != null) {
            javax.swing.JOptionPane.showMessageDialog(addFrame, rbx.getString("Message2"), Bundle.getMessage("ErrorTitle"), javax.swing.JOptionPane.ERROR_MESSAGE);
            return;
        }
    }
    curSection.setUserName(uName);
    if (setSectionInformation()) {
        // successful update
        addFrame.setVisible(false);
        addFrame.dispose();
        addFrame = null;
    }
}
Also used : Section(jmri.Section)

Aggregations

Section (jmri.Section)33 TransitSection (jmri.TransitSection)22 EntryPoint (jmri.EntryPoint)19 ArrayList (java.util.ArrayList)5 Block (jmri.Block)5 SectionManager (jmri.SectionManager)5 SignalMast (jmri.SignalMast)4 Transit (jmri.Transit)4 Element (org.jdom2.Element)4 NamedBean (jmri.NamedBean)3 Sensor (jmri.Sensor)3 SignalMastLogic (jmri.SignalMastLogic)2 TransitManager (jmri.TransitManager)2 FlowLayout (java.awt.FlowLayout)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 Hashtable (java.util.Hashtable)1 BoxLayout (javax.swing.BoxLayout)1 JButton (javax.swing.JButton)1 JDialog (javax.swing.JDialog)1