use of jmri.EntryPoint in project JMRI by JMRI.
the class DispatcherFrame method connected.
private boolean connected(Section s1, Section s2) {
if ((s1 != null) && (s2 != null)) {
ArrayList<EntryPoint> s1Entries = (ArrayList<EntryPoint>) s1.getEntryPointList();
ArrayList<EntryPoint> s2Entries = (ArrayList<EntryPoint>) s2.getEntryPointList();
for (int i = 0; i < s1Entries.size(); i++) {
Block b = s1Entries.get(i).getFromBlock();
for (int j = 0; j < s2Entries.size(); j++) {
if (b == s2Entries.get(j).getBlock()) {
return true;
}
}
}
}
return false;
}
use of jmri.EntryPoint in project JMRI by JMRI.
the class TransitTableAction method reverseConnected.
private boolean reverseConnected(Section s1, Section s2, int restrictedDirection) {
if ((s1 != null) && (s2 != null)) {
List<EntryPoint> s1ReverseEntries = s1.getReverseEntryPointList();
List<EntryPoint> s2Entries = new ArrayList<>();
if (restrictedDirection == Section.FORWARD) {
s2Entries = s2.getReverseEntryPointList();
} else if (restrictedDirection == Section.REVERSE) {
s2Entries = s2.getForwardEntryPointList();
} else {
s2Entries = s2.getEntryPointList();
}
for (int i = 0; i < s1ReverseEntries.size(); i++) {
Block b1 = s1ReverseEntries.get(i).getFromBlock();
for (int j = 0; j < s2Entries.size(); j++) {
Block b2 = s2Entries.get(j).getFromBlock();
if ((b1 == s2Entries.get(j).getBlock()) && (b2 == s1ReverseEntries.get(i).getBlock())) {
return true;
}
}
}
}
return false;
}
use of jmri.EntryPoint in project JMRI by JMRI.
the class AutoActiveTrain method addAllocatedSection.
private void addAllocatedSection(AllocatedSection as) {
_allocatedSectionList.add(as);
if (!_initialized) {
// this is first allocated section, get things started
_initialized = true;
_nextSection = as.getSection();
_currentBlock = _activeTrain.getStartBlock();
if (as.getSection().containsBlock(_currentBlock)) {
// starting Block is in this allocated section - find next Block
setNewCurrentSection(as);
_nextBlock = getNextBlock(_currentBlock, as);
} else if (as.getSection().connectsToBlock(_currentBlock)) {
// starting Block is connected to a Block in this allocated section
EntryPoint ep = as.getSection().getEntryPointFromBlock(_currentBlock, as.getDirection());
if (ep != null) {
_nextBlock = ep.getBlock();
} else {
log.error("failure to get entry point to Transit from Block " + _currentBlock.getSystemName());
}
}
if (_nextBlock != null) {
// set up new current signal
setupNewCurrentSignal(as);
}
}
// if train is stopping for lack of an allocation, set flag to restart it
if (!_pausingActive && (_lastAllocatedSection == _currentAllocatedSection) && isStopping() && (_activeTrain.getStatus() == ActiveTrain.RUNNING)) {
_needSetSpeed = true;
}
// request next allocation if appropriate--Dispatcher must decide whether to allocate it and when
if ((!DispatcherFrame.instance().getAutoAllocate()) && ((_lastAllocatedSection == null) || (_lastAllocatedSection.getNextSection() == as.getSection()))) {
// if AutoAllocate, this is now done in DispatcherFrame.java for all trains
_lastAllocatedSection = as;
if (as.getNextSection() != null) {
Section nSection = as.getNextSection();
int nextSeq = as.getNextSectionSequence();
int nextDir = _activeTrain.getAllocationDirectionFromSectionAndSeq(nSection, nextSeq);
DispatcherFrame.instance().requestAllocation(_activeTrain, nSection, nextDir, nextSeq, true, null);
}
}
}
Aggregations