Search in sources :

Example 1 with ShapeFactory

use of de.neemann.digital.draw.shapes.ShapeFactory in project Digital by hneemann.

the class Main method createViewMenu.

private void createViewMenu(JMenuBar menuBar, JToolBar toolBar) {
    ToolTipAction maximize = new ToolTipAction(Lang.get("menu_maximize"), ICON_EXPAND) {

        @Override
        public void actionPerformed(ActionEvent e) {
            circuitComponent.fitCircuit();
        }
    }.setAccelerator("F1");
    ToolTipAction zoomIn = new ToolTipAction(Lang.get("menu_zoomIn"), ICON_ZOOM_IN) {

        @Override
        public void actionPerformed(ActionEvent e) {
            circuitComponent.scaleCircuit(1 / 0.9);
        }
    }.setAccelerator("control PLUS");
    // enable [+] which is SHIFT+[=] on english keyboard layout
    circuitComponent.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_EQUALS, KeyEvent.CTRL_DOWN_MASK, false), zoomIn);
    circuitComponent.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ADD, KeyEvent.CTRL_DOWN_MASK, false), zoomIn);
    circuitComponent.getActionMap().put(zoomIn, zoomIn);
    ToolTipAction zoomOut = new ToolTipAction(Lang.get("menu_zoomOut"), ICON_ZOOM_OUT) {

        @Override
        public void actionPerformed(ActionEvent e) {
            circuitComponent.scaleCircuit(0.9);
        }
    }.setAccelerator("control MINUS");
    // enable [+] which is SHIFT+[=] on english keyboard layout
    circuitComponent.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_SUBTRACT, KeyEvent.CTRL_DOWN_MASK, false), zoomOut);
    circuitComponent.getActionMap().put(zoomOut, zoomOut);
    ToolTipAction viewHelp = new ToolTipAction(Lang.get("menu_viewHelp"), ICON_HELP) {

        @Override
        public void actionPerformed(ActionEvent e) {
            final Circuit circuit = circuitComponent.getCircuit();
            final String name = Lang.get("msg_actualCircuit");
            File file = filename;
            if (file == null)
                file = new File(name);
            try {
                ElementLibrary.ElementTypeDescriptionCustom description = new ElementLibrary.ElementTypeDescriptionCustom(file, attributes -> new CustomElement(circuit, library), circuit);
                description.setShortName(name);
                description.setDescription(circuit.getAttributes().get(Keys.DESCRIPTION));
                new ElementHelpDialog(Main.this, description, circuit.getAttributes()).setVisible(true);
            } catch (PinException | NodeException e1) {
                new ErrorMessage(Lang.get("msg_creatingHelp")).addCause(e1).show(Main.this);
            }
        }
    }.setToolTip(Lang.get("menu_viewHelp_tt"));
    JCheckBoxMenuItem treeCheckBox = new JCheckBoxMenuItem(Lang.get("menu_treeSelect"));
    treeCheckBox.setToolTipText(Lang.get("menu_treeSelect_tt"));
    treeCheckBox.addActionListener(actionEvent -> {
        getContentPane().remove(componentOnPane);
        if (treeCheckBox.isSelected()) {
            JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
            treeModel = new LibraryTreeModel(library);
            split.setLeftComponent(new JScrollPane(new SelectTree(treeModel, circuitComponent, shapeFactory, insertHistory)));
            split.setRightComponent(circuitComponent);
            getContentPane().add(split);
            componentOnPane = split;
        } else {
            if (treeModel != null) {
                library.removeListener(treeModel);
                treeModel = null;
            }
            getContentPane().add(circuitComponent);
            componentOnPane = circuitComponent;
        }
        revalidate();
    });
    treeCheckBox.setAccelerator(KeyStroke.getKeyStroke("F5"));
    if (Settings.getInstance().get(Keys.SETTINGS_DEFAULT_TREESELECT))
        SwingUtilities.invokeLater(treeCheckBox::doClick);
    toolBar.add(viewHelp.createJButtonNoText());
    toolBar.add(zoomIn.createJButtonNoText());
    toolBar.add(zoomOut.createJButtonNoText());
    toolBar.add(maximize.createJButtonNoText());
    JMenu view = new JMenu(Lang.get("menu_view"));
    menuBar.add(view);
    view.add(maximize.createJMenuItem());
    view.add(zoomOut.createJMenuItem());
    view.add(zoomIn.createJMenuItem());
    view.addSeparator();
    view.add(treeCheckBox);
    view.addSeparator();
    view.add(viewHelp.createJMenuItem());
}
Also used : de.neemann.digital.draw.graphics(de.neemann.digital.draw.graphics) URL(java.net.URL) Sync(de.neemann.digital.gui.sync.Sync) LoggerFactory(org.slf4j.LoggerFactory) de.neemann.digital.gui.components(de.neemann.digital.gui.components) TestingDataException(de.neemann.digital.testing.TestingDataException) TestCaseElement(de.neemann.digital.testing.TestCaseElement) VHDLGenerator(de.neemann.digital.hdl.vhdl2.VHDLGenerator) CheckForNewRelease(de.neemann.digital.gui.release.CheckForNewRelease) TableDialog(de.neemann.digital.gui.components.table.TableDialog) ElementAttributes(de.neemann.digital.core.element.ElementAttributes) ModelCreator(de.neemann.digital.draw.model.ModelCreator) Clipboard(java.awt.datatransfer.Clipboard) FormatToExpression(de.neemann.digital.analyse.expression.format.FormatToExpression) GifExporter(de.neemann.digital.draw.gif.GifExporter) ElementNotFoundException(de.neemann.digital.draw.library.ElementNotFoundException) LockSync(de.neemann.digital.gui.sync.LockSync) CodePrinter(de.neemann.digital.hdl.printer.CodePrinter) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) SelectTree(de.neemann.digital.gui.components.tree.SelectTree) Lang(de.neemann.digital.lang.Lang) LibraryTreeModel(de.neemann.digital.gui.components.tree.LibraryTreeModel) InvocationTargetException(java.lang.reflect.InvocationTargetException) de.neemann.digital.core(de.neemann.digital.core) State(de.neemann.digital.gui.state.State) ValueTableDialog(de.neemann.digital.gui.components.testing.ValueTableDialog) List(java.util.List) de.neemann.gui(de.neemann.gui) de.neemann.digital.draw.elements(de.neemann.digital.draw.elements) java.awt.event(java.awt.event) Drawable(de.neemann.digital.draw.shapes.Drawable) NoSync(de.neemann.digital.gui.sync.NoSync) CustomElement(de.neemann.digital.draw.library.CustomElement) RealTimeClock(de.neemann.digital.draw.model.RealTimeClock) Clock(de.neemann.digital.core.wiring.Clock) ExpressionDialog(de.neemann.digital.gui.components.expression.ExpressionDialog) DataFlavor(java.awt.datatransfer.DataFlavor) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) RemoteSever(de.neemann.digital.gui.remote.RemoteSever) SIZE(de.neemann.digital.draw.shapes.GenericShape.SIZE) NumberFormat(java.text.NumberFormat) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ModifyAttribute(de.neemann.digital.gui.components.modification.ModifyAttribute) ModelAnalyser(de.neemann.digital.analyse.ModelAnalyser) Button(de.neemann.digital.core.io.Button) Modifications(de.neemann.digital.gui.components.modification.Modifications) JOptionPane.showInputDialog(javax.swing.JOptionPane.showInputDialog) GraphDialog(de.neemann.digital.gui.components.data.GraphDialog) Keys(de.neemann.digital.core.element.Keys) OutputStream(java.io.OutputStream) Logger(org.slf4j.Logger) TruthTable(de.neemann.digital.analyse.TruthTable) DecimalFormat(java.text.DecimalFormat) FileOutputStream(java.io.FileOutputStream) ROM(de.neemann.digital.core.memory.ROM) IOException(java.io.IOException) DigitalHandler(de.neemann.digital.gui.remote.DigitalHandler) File(java.io.File) java.awt(java.awt) AnalyseException(de.neemann.digital.analyse.AnalyseException) de.neemann.digital.core.io(de.neemann.digital.core.io) RemoteException(de.neemann.digital.gui.remote.RemoteException) StateManager(de.neemann.digital.gui.state.StateManager) ElementLibrary(de.neemann.digital.draw.library.ElementLibrary) ModifyMeasurementOrdering(de.neemann.digital.gui.components.modification.ModifyMeasurementOrdering) ShapeFactory(de.neemann.digital.draw.shapes.ShapeFactory) javax.swing(javax.swing) SelectTree(de.neemann.digital.gui.components.tree.SelectTree) CustomElement(de.neemann.digital.draw.library.CustomElement) ElementLibrary(de.neemann.digital.draw.library.ElementLibrary) LibraryTreeModel(de.neemann.digital.gui.components.tree.LibraryTreeModel) File(java.io.File)

Example 2 with ShapeFactory

use of de.neemann.digital.draw.shapes.ShapeFactory 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);
}
Also used : ModelEntry(de.neemann.digital.draw.model.ModelEntry) ElementLibrary(de.neemann.digital.draw.library.ElementLibrary) Node(de.neemann.digital.core.Node) Model(de.neemann.digital.core.Model) ShapeFactory(de.neemann.digital.draw.shapes.ShapeFactory) Circuit(de.neemann.digital.draw.elements.Circuit) TestExecuter(de.neemann.digital.TestExecuter) File(java.io.File) ModelCreator(de.neemann.digital.draw.model.ModelCreator)

Example 3 with ShapeFactory

use of de.neemann.digital.draw.shapes.ShapeFactory 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>");
}
Also used : ElementLibrary(de.neemann.digital.draw.library.ElementLibrary) ShapeFactory(de.neemann.digital.draw.shapes.ShapeFactory) VisualElement(de.neemann.digital.draw.elements.VisualElement)

Example 4 with ShapeFactory

use of de.neemann.digital.draw.shapes.ShapeFactory 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);
}
Also used : ElementLibrary(de.neemann.digital.draw.library.ElementLibrary) Variable(de.neemann.digital.analyse.expression.Variable) Expression(de.neemann.digital.analyse.expression.Expression) ShapeFactory(de.neemann.digital.draw.shapes.ShapeFactory) Circuit(de.neemann.digital.draw.elements.Circuit) TestExecuter(de.neemann.digital.TestExecuter) ModelCreator(de.neemann.digital.draw.model.ModelCreator)

Example 5 with ShapeFactory

use of de.neemann.digital.draw.shapes.ShapeFactory in project Digital by hneemann.

the class CircuitBuilderTest method testBuilderSequential.

public void testBuilderSequential() throws Exception {
    Variable y0 = new Variable("Y_0");
    Variable y1 = new Variable("Y_1");
    // counter
    Expression y0s = not(y0);
    Expression y1s = or(and(not(y0), y1), and(y0, not(y1)));
    ElementLibrary library = new ElementLibrary();
    Circuit circuit = new CircuitBuilder(new ShapeFactory(library)).addSequential("Y_0", y0s).addSequential("Y_1", y1s).createCircuit();
    ModelCreator m = new ModelCreator(circuit, library);
    TestExecuter te = new TestExecuter(m.createModel(false)).setUp(m);
    te.check(0, 0);
    te.checkC(1, 0);
    te.checkC(0, 1);
    te.checkC(1, 1);
    te.checkC(0, 0);
}
Also used : ElementLibrary(de.neemann.digital.draw.library.ElementLibrary) Variable(de.neemann.digital.analyse.expression.Variable) Expression(de.neemann.digital.analyse.expression.Expression) ShapeFactory(de.neemann.digital.draw.shapes.ShapeFactory) Circuit(de.neemann.digital.draw.elements.Circuit) TestExecuter(de.neemann.digital.TestExecuter) ModelCreator(de.neemann.digital.draw.model.ModelCreator)

Aggregations

ShapeFactory (de.neemann.digital.draw.shapes.ShapeFactory)13 ElementLibrary (de.neemann.digital.draw.library.ElementLibrary)12 Circuit (de.neemann.digital.draw.elements.Circuit)8 ModelCreator (de.neemann.digital.draw.model.ModelCreator)8 TestExecuter (de.neemann.digital.TestExecuter)5 Expression (de.neemann.digital.analyse.expression.Expression)5 Variable (de.neemann.digital.analyse.expression.Variable)4 File (java.io.File)4 Model (de.neemann.digital.core.Model)2 Vector (de.neemann.digital.draw.graphics.Vector)2 AnalyseException (de.neemann.digital.analyse.AnalyseException)1 ModelAnalyser (de.neemann.digital.analyse.ModelAnalyser)1 TruthTable (de.neemann.digital.analyse.TruthTable)1 FormatToExpression (de.neemann.digital.analyse.expression.format.FormatToExpression)1 Parser (de.neemann.digital.analyse.parser.Parser)1 CircuitBuilder (de.neemann.digital.builder.circuit.CircuitBuilder)1 de.neemann.digital.core (de.neemann.digital.core)1 Node (de.neemann.digital.core.Node)1 ElementAttributes (de.neemann.digital.core.element.ElementAttributes)1 Keys (de.neemann.digital.core.element.Keys)1