Search in sources :

Example 1 with Element

use of de.neemann.digital.core.element.Element in project Digital by hneemann.

the class InputShape method applyStateMonitor.

@Override
public Interactor applyStateMonitor(IOState ioState, Observer guiObserver) {
    this.ioState = ioState;
    ioState.getOutput(0).addObserverToValue(guiObserver);
    return new Interactor() {

        @Override
        public boolean clicked(CircuitComponent cc, Point pos, IOState ioState, Element element, Sync modelSync) {
            ObservableValue value = ioState.getOutput(0);
            if (value.getBits() == 1) {
                modelSync.access(() -> {
                    if (isHighZ) {
                        if (value.isHighZ())
                            value.setValue(0);
                        else if (value.getValue() == 0)
                            value.setValue(1);
                        else
                            value.setToHighZ();
                    } else
                        value.setValue(1 - value.getValue());
                });
                return true;
            } else {
                if (dialog == null || !dialog.isVisible()) {
                    Model model = ((In) element).getModel();
                    dialog = new SingleValueDialog(model.getWindowPosManager().getMainFrame(), pos, label, value, isHighZ, cc, model, modelSync);
                    dialog.setVisible(true);
                } else
                    dialog.requestFocus();
                return false;
            }
        }
    };
}
Also used : CircuitComponent(de.neemann.digital.gui.components.CircuitComponent) In(de.neemann.digital.core.io.In) IOState(de.neemann.digital.draw.elements.IOState) Element(de.neemann.digital.core.element.Element) ObservableValue(de.neemann.digital.core.ObservableValue) Model(de.neemann.digital.core.Model) Sync(de.neemann.digital.gui.sync.Sync) SingleValueDialog(de.neemann.digital.gui.components.SingleValueDialog)

Example 2 with Element

use of de.neemann.digital.core.element.Element in project Digital by hneemann.

the class DipSwitchShape method applyStateMonitor.

@Override
public Interactor applyStateMonitor(IOState ioState, Observer guiObserver) {
    this.ioState = ioState;
    ioState.getOutput(0).addObserverToValue(guiObserver);
    return new Interactor() {

        @Override
        public boolean clicked(CircuitComponent cc, Point pos, IOState ioState, Element element, Sync modelSync) {
            ObservableValue value = ioState.getOutput(0);
            modelSync.access(() -> value.setValue(1 - value.getValue()));
            return true;
        }
    };
}
Also used : CircuitComponent(de.neemann.digital.gui.components.CircuitComponent) IOState(de.neemann.digital.draw.elements.IOState) Element(de.neemann.digital.core.element.Element) ObservableValue(de.neemann.digital.core.ObservableValue) Sync(de.neemann.digital.gui.sync.Sync)

Example 3 with Element

use of de.neemann.digital.core.element.Element in project Digital by hneemann.

the class DependencyAnalyserTest method testBacktrackCompleteness.

public void testBacktrackCompleteness() throws Exception {
    ToBreakRunner toBreakRunner = new ToBreakRunner("dig/backtrack/AllComponents.dig", false);
    // create a set of all components used in the circuit
    Circuit circuit = toBreakRunner.getCircuit();
    Set<String> set = new HashSet<>();
    for (VisualElement e : circuit.getElements()) set.add(e.getElementName());
    // ensure all available components are included in test circuit
    for (ElementLibrary.ElementContainer c : toBreakRunner.getLibrary()) {
        if (!set.contains(c.getDescription().getName())) {
            // nodes with state are allowed to be missing
            Element n = c.getDescription().createElement(new ElementAttributes());
            boolean ok = (n instanceof Node) && ((Node) n).hasState();
            assertTrue("component " + c.getDescription().getName() + " is missing in test/resources/dig/backtrack/AllComponents.dig!", ok);
        }
    }
    // check if backtracking is ok at all components!
    ModelAnalyser m = new ModelAnalyser(toBreakRunner.getModel());
    new DependencyAnalyser(m);
}
Also used : VisualElement(de.neemann.digital.draw.elements.VisualElement) Element(de.neemann.digital.core.element.Element) Circuit(de.neemann.digital.draw.elements.Circuit) VisualElement(de.neemann.digital.draw.elements.VisualElement) ElementAttributes(de.neemann.digital.core.element.ElementAttributes) ElementLibrary(de.neemann.digital.draw.library.ElementLibrary) ToBreakRunner(de.neemann.digital.integration.ToBreakRunner) HashSet(java.util.HashSet)

Aggregations

Element (de.neemann.digital.core.element.Element)3 ObservableValue (de.neemann.digital.core.ObservableValue)2 IOState (de.neemann.digital.draw.elements.IOState)2 CircuitComponent (de.neemann.digital.gui.components.CircuitComponent)2 Sync (de.neemann.digital.gui.sync.Sync)2 Model (de.neemann.digital.core.Model)1 ElementAttributes (de.neemann.digital.core.element.ElementAttributes)1 In (de.neemann.digital.core.io.In)1 Circuit (de.neemann.digital.draw.elements.Circuit)1 VisualElement (de.neemann.digital.draw.elements.VisualElement)1 ElementLibrary (de.neemann.digital.draw.library.ElementLibrary)1 SingleValueDialog (de.neemann.digital.gui.components.SingleValueDialog)1 ToBreakRunner (de.neemann.digital.integration.ToBreakRunner)1 HashSet (java.util.HashSet)1