use of jmri.Turnout in project JMRI by JMRI.
the class OPath method fireTurnouts.
void fireTurnouts(List<BeanSetting> list, boolean set, int lockState, boolean lock) {
for (int i = 0; i < list.size(); i++) {
BeanSetting bs = list.get(i);
Turnout t = (Turnout) bs.getBean();
if (t == null) {
log.error("Invalid turnout on path {}", toString());
} else {
if (set) {
t.setCommandedState(bs.getSetting());
}
if (lockState > 0) {
t.setLocked(lockState, lock);
}
}
}
}
use of jmri.Turnout in project JMRI by JMRI.
the class OBlockManagerXml method loadPath.
OPath loadPath(Element elem, OBlock block) {
String pName = elem.getAttribute("pathName").getValue();
OPath path = getPath(block, pName);
try {
Attribute attr = elem.getAttribute("fromDirection");
if (attr != null) {
path.setFromBlockDirection(attr.getIntValue());
}
attr = elem.getAttribute("toDirection");
if (attr != null) {
path.setToBlockDirection(attr.getIntValue());
}
attr = elem.getAttribute("length");
if (attr != null) {
path.setLength(attr.getFloatValue());
}
} catch (org.jdom2.DataConversionException e) {
log.error("Could not parse attribute of path (" + pName + ") block (" + block.getSystemName() + ")");
}
Attribute attr = elem.getAttribute("fromPortal");
if (attr != null) {
Portal portal = getPortal(attr.getValue());
if (portal != null) {
path.setFromPortal(portal);
portal.addPath(path);
}
}
attr = elem.getAttribute("toPortal");
if (attr != null) {
Portal portal = getPortal(attr.getValue());
if (portal != null) {
path.setToPortal(portal);
portal.addPath(path);
}
}
List<Element> settings = elem.getChildren("setting");
if (log.isDebugEnabled()) {
log.debug("Path (" + pName + ") has " + settings.size() + " settings.");
}
java.util.HashSet<String> turnouts = new java.util.HashSet<String>();
int dups = 0;
for (int i = 0; i < settings.size(); i++) {
Element setElem = settings.get(i);
int setting = 0;
try {
setting = setElem.getAttribute("set").getIntValue();
} catch (org.jdom2.DataConversionException e) {
log.error("Could not parse 'set' attribute for path (" + pName + ") block (" + block.getSystemName() + ")");
}
String sysName = setElem.getAttribute("turnout").getValue();
if (!turnouts.contains(sysName)) {
Turnout to = InstanceManager.turnoutManagerInstance().provideTurnout(sysName);
turnouts.add(sysName);
BeanSetting bs = new BeanSetting(to, sysName, setting);
path.addSetting(bs);
} else {
dups++;
}
}
if (dups > 0) {
log.warn(dups + " duplicate settings not loaded for path \"" + pName + "\"");
}
return path;
}
use of jmri.Turnout in project JMRI by JMRI.
the class ZTC611XNetTurnoutManager method createNewTurnout.
// XNet-specific methods
@Override
public Turnout createNewTurnout(String systemName, String userName) {
int addr = Integer.valueOf(systemName.substring(2)).intValue();
Turnout t = new ZTC611XNetTurnout(prefix, addr, tc);
t.setUserName(userName);
return t;
}
use of jmri.Turnout in project JMRI by JMRI.
the class AbstractTurnoutManager method getNextValidAddress.
@Override
public String getNextValidAddress(String curAddress, String prefix) throws JmriException {
//If the hardware address past does not already exist then this can
//be considered the next valid address.
String tmpSName = "";
try {
tmpSName = createSystemName(curAddress, prefix);
} catch (JmriException ex) {
jmri.InstanceManager.getDefault(jmri.UserPreferencesManager.class).showErrorMessage("Error", "Unable to convert " + curAddress + " to a valid Hardware Address", "" + ex, "", true, false);
return null;
}
Turnout t = getBySystemName(tmpSName);
if (t == null) {
return curAddress;
}
// This bit deals with handling the curAddress, and how to get the next address.
int iName = 0;
try {
iName = Integer.parseInt(curAddress);
} catch (NumberFormatException ex) {
log.error("Unable to convert " + curAddress + " Hardware Address to a number");
jmri.InstanceManager.getDefault(jmri.UserPreferencesManager.class).showErrorMessage("Error", "Unable to convert " + curAddress + " to a valid Hardware Address", "" + ex, "", true, false);
return null;
}
//The Number of Output Bits of the previous turnout will help determine the next
//valid address.
iName = iName + t.getNumberOutputBits();
//Check to determine if the systemName is in use, return null if it is,
//otherwise return the next valid address.
t = getBySystemName(prefix + typeLetter() + iName);
if (t != null) {
for (int x = 1; x < 10; x++) {
iName = iName + t.getNumberOutputBits();
t = getBySystemName(prefix + typeLetter() + iName);
if (t == null) {
return Integer.toString(iName);
}
}
return null;
} else {
return Integer.toString(iName);
}
}
use of jmri.Turnout in project JMRI by JMRI.
the class DefaultSignalMastLogicManagerXml method loadSignalMastLogic.
public boolean loadSignalMastLogic(Element signalMastLogic) {
List<Element> logicList = signalMastLogic.getChildren("signalmastlogic");
if (log.isDebugEnabled()) {
log.debug("Found " + logicList.size() + " signal mast logics");
}
SignalMastManager sm = InstanceManager.getDefault(jmri.SignalMastManager.class);
SignalMastLogicManager sml = InstanceManager.getDefault(jmri.SignalMastLogicManager.class);
try {
String logicDelay = signalMastLogic.getChild("logicDelay").getText();
sml.setSignalLogicDelay(Long.parseLong(logicDelay));
} catch (java.lang.NullPointerException e) {
//Considered normal if it doesn't exists
}
boolean loadOk = true;
for (Element so : logicList) {
String source = so.getChild("sourceSignalMast").getText();
SignalMast sourceMast = sm.getSignalMast(source);
if (sourceMast != null) {
SignalMastLogic logic = sml.newSignalMastLogic(sourceMast);
List<Element> destList = so.getChildren("destinationMast");
for (Element s : destList) {
String destination = s.getChild("destinationSignalMast").getText();
SignalMast dest = sm.getSignalMast(destination);
if (dest != null) {
logic.setDestinationMast(dest);
if (s.getChild("comment") != null) {
logic.setComment(s.getChild("comment").getText(), dest);
}
if (s.getChild("enabled") != null) {
if (s.getChild("enabled").getText().equals("yes")) {
logic.setEnabled(dest);
} else {
logic.setDisabled(dest);
}
}
if (s.getChild("allowAutoMaticSignalMastGeneration") != null) {
if (s.getChild("allowAutoMaticSignalMastGeneration").getText().equals("no")) {
logic.allowAutoMaticSignalMastGeneration(false, dest);
} else {
logic.allowAutoMaticSignalMastGeneration(true, dest);
}
}
boolean useLayoutEditorTurnout = true;
boolean useLayoutEditorBlock = true;
if (s.getChild("useLayoutEditorTurnouts") != null) {
if (s.getChild("useLayoutEditorTurnouts").getText().equals("no")) {
useLayoutEditorTurnout = false;
}
}
if (s.getChild("useLayoutEditorBlocks") != null) {
if (s.getChild("useLayoutEditorBlocks").getText().equals("no")) {
useLayoutEditorBlock = false;
}
}
try {
logic.useLayoutEditorDetails(useLayoutEditorTurnout, useLayoutEditorBlock, dest);
} catch (jmri.JmriException ex) {
}
if (s.getChild("useLayoutEditor") != null) {
try {
if (s.getChild("useLayoutEditor").getText().equals("yes")) {
logic.useLayoutEditor(true, dest);
} else {
logic.useLayoutEditor(false, dest);
}
} catch (jmri.JmriException e) {
//Considered normal if layout editor hasn't yet been set up.
}
}
if (s.getChild("associatedSection") != null) {
Section sect = InstanceManager.getDefault(jmri.SectionManager.class).getSection(s.getChild("associatedSection").getText());
logic.setAssociatedSection(sect, dest);
}
Element turnoutElem = s.getChild("turnouts");
if (turnoutElem != null) {
List<Element> turnoutList = turnoutElem.getChildren("turnout");
if (turnoutList.size() > 0) {
Hashtable<NamedBeanHandle<Turnout>, Integer> list = new Hashtable<NamedBeanHandle<Turnout>, Integer>();
for (Element t : turnoutList) {
String turnout = t.getChild("turnoutName").getText();
String state = t.getChild("turnoutState").getText();
int value = Turnout.CLOSED;
if (state.equals("thrown")) {
value = Turnout.THROWN;
}
Turnout turn = InstanceManager.turnoutManagerInstance().getTurnout(turnout);
if (turn != null) {
NamedBeanHandle<Turnout> namedTurnout = nbhm.getNamedBeanHandle(turnout, turn);
list.put(namedTurnout, value);
}
log.debug("Unable to add Turnout {} as it does not exist in the panel file", turnout);
}
logic.setTurnouts(list, dest);
}
}
Element sensorElem = s.getChild("sensors");
if (sensorElem != null) {
List<Element> sensorList = sensorElem.getChildren("sensor");
if (sensorList.size() > 0) {
Hashtable<NamedBeanHandle<Sensor>, Integer> list = new Hashtable<NamedBeanHandle<Sensor>, Integer>();
for (Element sl : sensorList) {
String sensorName = sl.getChild("sensorName").getText();
String state = sl.getChild("sensorState").getText();
int value = Sensor.INACTIVE;
if (state.equals("active")) {
value = Sensor.ACTIVE;
}
Sensor sen = InstanceManager.sensorManagerInstance().getSensor(sensorName);
if (sen != null) {
NamedBeanHandle<Sensor> namedSensor = nbhm.getNamedBeanHandle(sensorName, sen);
list.put(namedSensor, value);
}
log.debug("Unable to add sensor {} as it does not exist in the panel file", sensorName);
}
logic.setSensors(list, dest);
}
}
Element blockElem = s.getChild("blocks");
if (blockElem != null) {
List<Element> blockList = blockElem.getChildren("block");
if (blockList.size() > 0) {
Hashtable<Block, Integer> list = new Hashtable<Block, Integer>();
for (Element b : blockList) {
String block = b.getChild("blockName").getText();
String state = b.getChild("blockState").getText();
int value = 0x03;
if (state.equals("occupied")) {
value = Block.OCCUPIED;
} else if (state.equals("unoccupied")) {
value = Block.UNOCCUPIED;
}
Block blk = InstanceManager.getDefault(jmri.BlockManager.class).getBlock(block);
if (blk != null) {
list.put(blk, value);
}
log.debug("Unable to add Block {} as it does not exist in the panel file", block);
}
logic.setBlocks(list, dest);
}
}
Element mastElem = s.getChild("masts");
if (mastElem != null) {
List<Element> mastList = mastElem.getChildren("mast");
if (mastList.size() > 0) {
Hashtable<SignalMast, String> list = new Hashtable<SignalMast, String>();
for (Element m : mastList) {
String mast = m.getChild("mastName").getText();
String state = m.getChild("mastState").getText();
SignalMast mst = InstanceManager.getDefault(jmri.SignalMastManager.class).getSignalMast(mast);
if (mst != null) {
list.put(mst, state);
}
log.debug("Unable to add Signal Mast {} as it does not exist in the panel file", mast);
}
logic.setMasts(list, dest);
}
}
} else {
log.error("Destination Mast " + destination + " Not found, logic not loaded");
loadOk = false;
}
}
} else {
log.error("Source Mast " + source + " Not found, logic not loaded");
loadOk = false;
}
}
sml.initialise();
return loadOk;
}
Aggregations