Search in sources :

Example 16 with VisualElement

use of de.neemann.digital.draw.elements.VisualElement in project Digital by hneemann.

the class TestSelect method testSelect.

public void testSelect() throws Exception {
    Circuit c = new ToBreakRunner("dig/selectOuter.dig").getCircuit();
    // don't select by clicking in label size bounding box
    VisualElement el = c.getElementAt(new Vector(65, 15));
    assertNull(el);
    // select by clicking in shape size bounding box
    el = c.getElementAt(new Vector(55, 15));
    assertNotNull(el);
    assertEquals("selectInnerLongName.dig", el.getElementName());
    // select output by clicking in shape size bounding box
    el = c.getElementAt(new Vector(195, 20));
    assertNotNull(el);
    assertEquals(Out.DESCRIPTION.getName(), el.getElementName());
    // don't select output by clicking in label text
    el = c.getElementAt(new Vector(250, 20));
    assertNull(el);
    // select text by clicking in text size bounding box
    el = c.getElementAt(new Vector(20, 110));
    assertNotNull(el);
    assertEquals(DummyElement.TEXTDESCRIPTION.getName(), el.getElementName());
}
Also used : Circuit(de.neemann.digital.draw.elements.Circuit) VisualElement(de.neemann.digital.draw.elements.VisualElement) Vector(de.neemann.digital.draw.graphics.Vector)

Example 17 with VisualElement

use of de.neemann.digital.draw.elements.VisualElement in project Digital by hneemann.

the class ModifyMoveAndRotElement method modify.

@Override
public void modify(Circuit circuit, ElementLibrary library) {
    VisualElement ve = getVisualElement(circuit);
    ve.setPos(pos);
    ve.setRotation(rotation);
}
Also used : VisualElement(de.neemann.digital.draw.elements.VisualElement)

Example 18 with VisualElement

use of de.neemann.digital.draw.elements.VisualElement in project Digital by hneemann.

the class ModifyMoveSelected method rotateElements.

/**
 * Rotates the given elements
 *
 * @param elements the elements to rotate
 * @param center   the center position
 */
public static void rotateElements(ArrayList<Movable> elements, Vector center) {
    Transform transform = new TransformRotate(center, 1) {

        @Override
        public Vector transform(Vector v) {
            return super.transform(v.sub(center));
        }

        @Override
        public VectorFloat transform(VectorFloat v) {
            return super.transform(v.sub(center));
        }
    };
    for (Movable m : elements) {
        if (m instanceof VisualElement) {
            VisualElement ve = (VisualElement) m;
            ve.rotate();
            ve.setPos(transform.transform(ve.getPos()));
        } else if (m instanceof Wire) {
            Wire w = (Wire) m;
            w.p1 = transform.transform(w.p1);
            w.p2 = transform.transform(w.p2);
        } else {
            Vector p = m.getPos();
            Vector t = transform.transform(p);
            m.move(t.sub(p));
        }
    }
}
Also used : TransformRotate(de.neemann.digital.draw.graphics.TransformRotate) Movable(de.neemann.digital.draw.elements.Movable) VisualElement(de.neemann.digital.draw.elements.VisualElement) Transform(de.neemann.digital.draw.graphics.Transform) Wire(de.neemann.digital.draw.elements.Wire) Vector(de.neemann.digital.draw.graphics.Vector) VectorFloat(de.neemann.digital.draw.graphics.VectorFloat)

Example 19 with VisualElement

use of de.neemann.digital.draw.elements.VisualElement 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)

Example 20 with VisualElement

use of de.neemann.digital.draw.elements.VisualElement in project Digital by hneemann.

the class CircuitBuilderTest method testBus.

public void testBus() throws Exception {
    final ToBreakRunner runner = new ToBreakRunner("dig/circuitBuilder/busTest.dig", false);
    // create truth table incl. ModelAnalyzerInfo
    TruthTable tt = new ModelAnalyser(runner.getModel()).analyse();
    assertEquals(8, tt.getVars().size());
    assertEquals(8, tt.getResultCount());
    // create expressions based on truth table
    ExpressionListenerStore expr = new ExpressionListenerStore(null);
    new ExpressionCreator(tt).create(expr);
    // build a new circuit
    CircuitBuilder circuitBuilder = new CircuitBuilder(runner.getLibrary().getShapeFactory(), false, tt.getVars()).setModelAnalyzerInfo(tt.getModelAnalyzerInfo());
    new BuilderExpressionCreator(circuitBuilder).create(expr);
    Circuit circuit = circuitBuilder.createCircuit();
    // check
    List<VisualElement> in = circuit.findElements(v -> v.equalsDescription(In.DESCRIPTION));
    assertEquals(2, in.size());
    checkPin(in.get(0), "A", "1,2,3,4");
    checkPin(in.get(1), "B", "5,6,7,8");
    List<VisualElement> out = circuit.findElements(v -> v.equalsDescription(Out.DESCRIPTION));
    assertEquals(2, out.size());
    checkPin(out.get(0), "S", "9,10,11,12");
    checkPin(out.get(1), "U", "13,14,15,16");
}
Also used : ModelAnalyser(de.neemann.digital.analyse.ModelAnalyser) TruthTable(de.neemann.digital.analyse.TruthTable) ToBreakRunner(de.neemann.digital.integration.ToBreakRunner) Circuit(de.neemann.digital.draw.elements.Circuit) VisualElement(de.neemann.digital.draw.elements.VisualElement) BuilderExpressionCreator(de.neemann.digital.gui.components.table.BuilderExpressionCreator) ExpressionListenerStore(de.neemann.digital.gui.components.table.ExpressionListenerStore) ExpressionCreator(de.neemann.digital.gui.components.table.ExpressionCreator) BuilderExpressionCreator(de.neemann.digital.gui.components.table.BuilderExpressionCreator)

Aggregations

VisualElement (de.neemann.digital.draw.elements.VisualElement)25 Vector (de.neemann.digital.draw.graphics.Vector)11 Wire (de.neemann.digital.draw.elements.Wire)8 Circuit (de.neemann.digital.draw.elements.Circuit)7 ElementLibrary (de.neemann.digital.draw.library.ElementLibrary)5 ElementTypeDescription (de.neemann.digital.core.element.ElementTypeDescription)4 TestCaseDescription (de.neemann.digital.testing.TestCaseDescription)4 File (java.io.File)4 ElementAttributes (de.neemann.digital.core.element.ElementAttributes)3 Main (de.neemann.digital.gui.Main)3 ExpressionListenerStore (de.neemann.digital.gui.components.table.ExpressionListenerStore)3 ToBreakRunner (de.neemann.digital.integration.ToBreakRunner)3 ErrorMessage (de.neemann.gui.ErrorMessage)3 IOException (java.io.IOException)3 Expression (de.neemann.digital.analyse.expression.Expression)2 Signal (de.neemann.digital.core.Signal)2 And (de.neemann.digital.core.basic.And)2 Keys (de.neemann.digital.core.element.Keys)2 External (de.neemann.digital.core.extern.External)2 In (de.neemann.digital.core.io.In)2