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());
}
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);
}
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));
}
}
}
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);
}
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");
}
Aggregations