use of de.neemann.digital.draw.library.ElementLibrary in project Digital by hneemann.
the class TestElemConsistence method testConsistence.
/**
* Checks if element descriptions are complete
*
* @throws NodeException
*/
public void testConsistence() throws NodeException, PinException {
ElementLibrary library = new ElementLibrary();
for (ElementLibrary.ElementContainer e : library) {
ElementTypeDescription etd = e.getDescription();
String key = "elem_" + etd.getName();
assertNotNull("Key " + key + " not found", Lang.getNull(key));
if (Lang.getNull(key + "_tt") == null)
missing(key + "_tt");
if (isNormalElement(etd)) {
checkPins(key, etd.getInputDescription(new ElementAttributes()));
checkPins(key, etd.getOutputDescriptions(new ElementAttributes()));
}
}
}
use of de.neemann.digital.draw.library.ElementLibrary in project Digital by hneemann.
the class TestAnd method testAnd.
/**
* Reads a file and sets up a model from it.
* After that the model - a simple AND gate - is tested to be a working AND gate.
*
* @throws Exception
*/
public void testAnd() throws Exception {
File filename = new File(Resources.getRoot(), "dig/and.dig");
Circuit circuit = Circuit.loadCircuit(filename, new ShapeFactory(new ElementLibrary()));
ModelCreator md = new ModelCreator(circuit, library);
Model model = md.createModel(false);
List<Node> nodes = model.getNodes();
assertEquals(1, nodes.size());
// get inputs and outputs
List<ModelEntry> inputs = md.getEntries("In");
assertEquals(2, inputs.size());
List<ModelEntry> outputs = md.getEntries("Out");
assertEquals(1, outputs.size());
// check the inputs state: the input itself has an output
assertEquals(0, inputs.get(0).getIoState().inputCount());
assertEquals(1, inputs.get(0).getIoState().outputCount());
assertEquals(0, inputs.get(1).getIoState().inputCount());
assertEquals(1, inputs.get(1).getIoState().outputCount());
// check the output state: the output itself has an input
assertEquals(1, outputs.get(0).getIoState().inputCount());
assertEquals(0, outputs.get(0).getIoState().outputCount());
// setup the test executer
TestExecuter te = new TestExecuter(model).setInputs(inputs).setOutputs(outputs);
te.check(0, 0, 0);
te.check(0, 1, 0);
te.check(1, 0, 0);
te.check(1, 1, 1);
}
use of de.neemann.digital.draw.library.ElementLibrary 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.library.ElementLibrary in project Digital by hneemann.
the class DocuTest method write74xx.
private void write74xx(File file) throws IOException {
TreeMap<String, String> map = new TreeMap<>(NumStringComparator.getInstance());
ElementLibrary library = new ElementLibrary();
LibraryNode node = library.getRoot().getChild(Lang.get("menu_library"));
if (node != null) {
node.traverse(libraryNode -> {
if (libraryNode.isLeaf()) {
try {
String key = libraryNode.getName();
if (key.endsWith(".dig"))
key = key.substring(0, key.length() - 4);
if (!key.endsWith("-inc")) {
String value = libraryNode.getDescription().getDescription(new ElementAttributes());
map.put(key, value);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
});
try (Writer w = new OutputStreamWriter(new FileOutputStream(file), "UTF-8")) {
w.append("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n");
w.append("<icRoot>\n");
for (Map.Entry<String, String> e : map.entrySet()) {
w.append(" <ic name=\"");
w.append(e.getKey());
w.append("\">");
w.append(e.getValue());
w.append("</ic>\n");
}
w.append("</icRoot>");
}
}
}
use of de.neemann.digital.draw.library.ElementLibrary in project Digital by hneemann.
the class CircuitBuilderTest method testBuilderCombinatorial.
public void testBuilderCombinatorial() throws Exception {
Variable a = new Variable("a");
Variable b = new Variable("b");
// xor
Expression y = and(or(a, b), not(and(a, b)));
ElementLibrary library = new ElementLibrary();
Circuit circuit = new CircuitBuilder(new ShapeFactory(library)).addCombinatorial("y", y).createCircuit();
ModelCreator m = new ModelCreator(circuit, library);
TestExecuter te = new TestExecuter(m.createModel(false)).setUp(m);
te.check(0, 0, 0);
te.check(0, 1, 1);
te.check(1, 0, 1);
te.check(1, 1, 0);
}
Aggregations