use of de.neemann.digital.draw.elements.VisualElement in project Digital by hneemann.
the class DocuTest method writeXML.
private void writeXML(Writer w, File images, String language, File libFile) throws IOException, NodeException, PinException {
w.append("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n");
w.append("<?xml-stylesheet type=\"text/xsl\" href=\"elem2html.xslt\"?>\n");
w.append("<root titel=\"").append(Lang.get("digital")).append("\" titleImage=\"").append(new File(Resources.getRoot(), "../../../screenshot.png").toURI().toString()).append("\" images=\"").append(new File(Resources.getRoot(), "docu/images/").toURI().toString()).append("\" toc=\"").append(Lang.get("tableOfContent")).append("\" lang=\"").append(language).append("\" rev=\"").append(System.getProperty("buildnumber")).append("\" revt=\"").append(Lang.get("revision")).append("\" date=\"").append(System.getProperty("buildtime")).append("\" datet=\"").append(Lang.get("date")).append("\" general=\"").append(Lang.get("general")).append("\" components=\"").append(Lang.get("menu_elements")).append("\" lib=\"").append(Lang.get("menu_library")).append("\" static=\"").append(new File(Resources.getRoot(), "docu/static_" + language + ".xml").toURI().toString()).append("\" library=\"").append(libFile.toURI().toString()).append("\">\n");
ElementLibrary library = new ElementLibrary();
ShapeFactory shapeFactory = new ShapeFactory(library, language.equals("en"));
String actPath = null;
for (ElementLibrary.ElementContainer e : library) {
String p = e.getTreePath();
if (!p.equals(actPath)) {
if (actPath != null)
w.append(" </lib>\n");
actPath = p;
w.append(" <lib name=\"").append(actPath).append("\">\n");
}
final ElementTypeDescription etd = e.getDescription();
String imageName = etd.getName() + "_" + language;
File imageFile = new File(images, imageName + ".svg");
w.append(" <element name=\"").append(escapeHTML(etd.getTranslatedName())).append("\" img=\"").append(imageFile.toURI().toString()).append("\">\n");
writeSVG(imageFile, new VisualElement(etd.getName()).setShapeFactory(shapeFactory));
final ElementAttributes attr = new ElementAttributes();
w.append(" <descr>").append(escapeHTML(etd.getDescription(attr))).append("</descr>\n");
final PinDescriptions inputDescription = etd.getInputDescription(attr);
if (!inputDescription.isEmpty()) {
w.append(" <inputs name=\"").append(Lang.get("elem_Help_inputs")).append("\">\n");
writePins(w, inputDescription);
w.append(" </inputs>\n");
}
final PinDescriptions outputDescriptions = etd.getOutputDescriptions(attr);
if (!outputDescriptions.isEmpty()) {
w.append(" <outputs name=\"").append(Lang.get("elem_Help_outputs")).append("\">\n");
writePins(w, outputDescriptions);
w.append(" </outputs>\n");
}
if (etd.getAttributeList().size() > 0) {
w.append(" <attributes name=\"").append(Lang.get("elem_Help_attributes")).append("\">\n");
for (Key k : etd.getAttributeList()) {
w.append(" <attr name=\"").append(escapeHTML(k.getName())).append("\">");
w.append(escapeHTML(k.getDescription()));
w.append("</attr>\n");
}
w.append(" </attributes>\n");
}
w.append(" </element>\n");
}
w.append(" </lib>\n");
w.append("</root>");
}
use of de.neemann.digital.draw.elements.VisualElement in project Digital by hneemann.
the class NetListTest method addTunnel.
private void addTunnel(Circuit c, Vector pos, String name) {
VisualElement ve = new VisualElement("Tunnel").setPos(pos);
ve.getElementAttributes().set(Keys.NETNAME, name);
c.add(ve);
}
use of de.neemann.digital.draw.elements.VisualElement in project Digital by hneemann.
the class TestExamples method check.
/**
* Loads the model and initializes and test it if test cases are present
*
* @param dig the model file
*/
public static void check(File dig) throws Exception {
boolean shouldFail = dig.getName().endsWith("Error.dig");
ToBreakRunner br;
try {
br = new ToBreakRunner(dig);
} catch (Exception e) {
if (shouldFail) {
return;
} else
throw e;
}
try {
boolean isLib = dig.getPath().replace('\\', '/').contains("/lib/");
assertTrue("wrong locked mode", isLib == br.getCircuit().getAttributes().get(Keys.LOCKED_MODE));
try {
for (VisualElement el : br.getCircuit().getElements()) if (el.equalsDescription(TestCaseElement.TESTCASEDESCRIPTION)) {
String label = el.getElementAttributes().getCleanLabel();
TestCaseDescription td = el.getElementAttributes().get(TestCaseElement.TESTDATA);
Model model = new ModelCreator(br.getCircuit(), br.getLibrary()).createModel(false);
try {
TestExecutor tr = new TestExecutor(td).create(model);
if (label.contains("Failing"))
assertFalse(dig.getName() + ":" + label, tr.allPassed());
else
assertTrue(dig.getName() + ":" + label, tr.allPassed());
testCasesInFiles++;
} finally {
model.close();
}
}
} catch (Exception e) {
if (shouldFail) {
return;
} else
throw e;
}
assertFalse("File should fail but doesn't!", shouldFail);
} finally {
br.close();
}
}
use of de.neemann.digital.draw.elements.VisualElement in project Digital by hneemann.
the class TestInGUI method testMoveSelectedComponent.
public void testMoveSelectedComponent() {
new GuiTester().mouseMove(110, 110).add(new GuiTester.WindowCheck<>(Main.class, (gt, main) -> {
final CircuitComponent cc = main.getCircuitComponent();
final VisualElement ve = new VisualElement(And.DESCRIPTION.getName()).setShapeFactory(cc.getLibrary().getShapeFactory());
cc.setPartToInsert(ve);
})).mouseClick(InputEvent.BUTTON1_MASK).mouseMove(100, 100).mouseClick(InputEvent.BUTTON1_MASK).mouseMove(400, 400).mouseClick(InputEvent.BUTTON1_MASK).add(new GuiTester.WindowCheck<>(Main.class, (gt, main) -> {
final Circuit c = main.getCircuitComponent().getCircuit();
assertEquals(1, c.getElements().size());
final Vector pos = c.getElements().get(0).getPos();
assertTrue(pos.x > 300);
assertTrue(pos.y > 300);
})).execute();
}
use of de.neemann.digital.draw.elements.VisualElement in project Digital by hneemann.
the class TestInGUI method testGroupEdit.
public void testGroupEdit() {
new GuiTester("dig/manualError/12_groupEdit.dig").add(new SelectAll()).mouseClick(InputEvent.BUTTON3_MASK).delay(500).press("TAB", 2).type("6").press("ENTER").delay(500).add(new GuiTester.WindowCheck<>(Main.class, (guiTester, main) -> {
ArrayList<VisualElement> l = main.getCircuitComponent().getCircuit().getElements();
assertEquals(8, l.size());
for (VisualElement e : l) assertEquals(16, (int) e.getElementAttributes().get(Keys.BITS));
})).execute();
}
Aggregations