use of de.neemann.digital.core.element.PinDescription in project Digital by hneemann.
the class ModelEntry method applyInputs.
/**
* Sets the Inputs of the element contained in this entry
*
* @throws PinException PinException
* @throws NodeException NodeException
*/
public void applyInputs() throws PinException, NodeException {
try {
HashMap<String, Pin> ins = pins.getInputs();
InverterConfig ic = visualElement.getElementAttributes().get(Keys.INVERTER_CONFIG);
ObservableValues values = ObservableValues.EMPTY_LIST;
ArrayList<ObservableValue> inputs = new ArrayList<>();
for (PinDescription inputName : inputNames) {
Pin pin = ins.get(inputName.getName());
if (pin == null)
throw new PinException(Lang.get("err_pin_N0_atElement_N1_notFound", inputName, visualElement), containingVisualElement);
ObservableValue value = pin.getValue();
if (value == null)
throw new PinException(Lang.get("err_noValueSetFor_N0_atElement_N1", inputName, visualElement), containingVisualElement);
inputs.add(ic.invert(inputName.getName(), value));
}
ArrayList<ObservableValue> bidirect = null;
for (Pin p : pins) {
if (p.getDirection() == Pin.Direction.both) {
if (bidirect == null)
bidirect = new ArrayList<>();
final ObservableValue readerValue = p.getReaderValue();
if (readerValue == null)
throw new PinException(Lang.get("err_noValueSetFor_N0_atElement_N1", p.getName(), visualElement), containingVisualElement);
bidirect.add(readerValue);
}
}
if (bidirect != null)
inputs.addAll(bidirect);
if (inputs.size() > 0) {
values = new ObservableValues(inputs);
element.setInputs(values);
}
ioState = new IOState(values, element.getOutputs(), element);
} catch (PinException | NodeException e) {
e.setOrigin(origin);
e.setVisualElement(containingVisualElement);
throw e;
}
}
Aggregations