Search in sources :

Example 1 with BuilderExpressionCreator

use of de.neemann.digital.gui.components.table.BuilderExpressionCreator in project Digital by hneemann.

the class GenerateFile method generate.

@Override
public void generate(JDialog parent, File circuitFile, TruthTable table, ExpressionListenerStore expressions) throws Exception {
    ModelAnalyserInfo mai = table.getModelAnalyzerInfo();
    if (mai == null) {
        JOptionPane.showMessageDialog(parent, new LineBreaker().toHTML().breakLines(Lang.get("msg_circuitIsRequired")), Lang.get("msg_warning"), JOptionPane.WARNING_MESSAGE);
        return;
    } else {
        ArrayList<String> pinsWithoutNumber = mai.getPinsWithoutNumber();
        if (!pinsWithoutNumber.isEmpty()) {
            int res = JOptionPane.showConfirmDialog(parent, new LineBreaker().toHTML().breakLines(Lang.get("msg_thereAreMissingPinNumbers", pinsWithoutNumber)), Lang.get("msg_warning"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);
            if (res != JOptionPane.OK_OPTION)
                return;
        }
    }
    if (circuitFile == null)
        circuitFile = new File("circuit." + suffix);
    else
        circuitFile = SaveAsHelper.checkSuffix(circuitFile, suffix);
    JFileChooser fileChooser = new MyFileChooser();
    fileChooser.setFileFilter(new FileNameExtensionFilter("JEDEC", suffix));
    fileChooser.setSelectedFile(circuitFile);
    if (fileChooser.showSaveDialog(parent) == JFileChooser.APPROVE_OPTION) {
        ExpressionToFileExporter expressionExporter = factory.create();
        expressionExporter.getPinMapping().addAll(mai.getPins());
        expressionExporter.getPinMapping().setClockPin(mai.getClockPinInt());
        new BuilderExpressionCreator(expressionExporter.getBuilder(), ExpressionModifier.IDENTITY).create(expressions);
        expressionExporter.export(SaveAsHelper.checkSuffix(fileChooser.getSelectedFile(), suffix));
    }
}
Also used : MyFileChooser(de.neemann.gui.MyFileChooser) ModelAnalyserInfo(de.neemann.digital.analyse.ModelAnalyserInfo) ExpressionToFileExporter(de.neemann.digital.builder.ExpressionToFileExporter) LineBreaker(de.neemann.gui.LineBreaker) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) File(java.io.File) BuilderExpressionCreator(de.neemann.digital.gui.components.table.BuilderExpressionCreator)

Example 2 with BuilderExpressionCreator

use of de.neemann.digital.gui.components.table.BuilderExpressionCreator 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)

Example 3 with BuilderExpressionCreator

use of de.neemann.digital.gui.components.table.BuilderExpressionCreator in project Digital by hneemann.

the class GenerateCUPL method generate.

@Override
public void generate(JDialog parent, File circuitFile, TruthTable table, ExpressionListenerStore expressions) throws Exception {
    File cuplPath;
    if (circuitFile == null) {
        JFileChooser fc = new MyFileChooser();
        fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        fc.setDialogTitle(Lang.get("msg_selectAnEmptyFolder"));
        if (fc.showSaveDialog(parent) == JFileChooser.APPROVE_OPTION) {
            cuplPath = fc.getSelectedFile();
            circuitFile = cuplPath;
        } else {
            return;
        }
    } else {
        if (circuitFile.isDirectory()) {
            cuplPath = circuitFile;
        } else {
            String name = circuitFile.getName();
            if (name.length() > 3 && name.charAt(name.length() - 4) == '.')
                name = name.substring(0, name.length() - 4);
            cuplPath = new File(circuitFile.getParentFile(), "CUPL_" + name);
        }
    }
    if (!cuplPath.mkdirs())
        if (!cuplPath.exists())
            throw new IOException(Lang.get("err_couldNotCreateFolder_N0", cuplPath.getPath()));
    File f = new File(cuplPath, "CUPL.PLD");
    CuplExporter cuplExporter = cuplExporterFactory.create();
    cuplExporter.setProjectName(circuitFile.getName());
    final ModelAnalyserInfo modelAnalyzerInfo = table.getModelAnalyzerInfo();
    if (modelAnalyzerInfo != null)
        cuplExporter.getPinMapping().addAll(modelAnalyzerInfo.getPins());
    new BuilderExpressionCreator(cuplExporter.getBuilder(), ExpressionModifier.IDENTITY).create(expressions);
    try (FileOutputStream out = new FileOutputStream(f)) {
        cuplExporter.writeTo(out);
    }
}
Also used : MyFileChooser(de.neemann.gui.MyFileChooser) ModelAnalyserInfo(de.neemann.digital.analyse.ModelAnalyserInfo) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) File(java.io.File) BuilderExpressionCreator(de.neemann.digital.gui.components.table.BuilderExpressionCreator) CuplExporter(de.neemann.digital.builder.Gal16v8.CuplExporter)

Aggregations

BuilderExpressionCreator (de.neemann.digital.gui.components.table.BuilderExpressionCreator)3 ModelAnalyserInfo (de.neemann.digital.analyse.ModelAnalyserInfo)2 MyFileChooser (de.neemann.gui.MyFileChooser)2 File (java.io.File)2 ModelAnalyser (de.neemann.digital.analyse.ModelAnalyser)1 TruthTable (de.neemann.digital.analyse.TruthTable)1 ExpressionToFileExporter (de.neemann.digital.builder.ExpressionToFileExporter)1 CuplExporter (de.neemann.digital.builder.Gal16v8.CuplExporter)1 Circuit (de.neemann.digital.draw.elements.Circuit)1 VisualElement (de.neemann.digital.draw.elements.VisualElement)1 ExpressionCreator (de.neemann.digital.gui.components.table.ExpressionCreator)1 ExpressionListenerStore (de.neemann.digital.gui.components.table.ExpressionListenerStore)1 ToBreakRunner (de.neemann.digital.integration.ToBreakRunner)1 LineBreaker (de.neemann.gui.LineBreaker)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 FileNameExtensionFilter (javax.swing.filechooser.FileNameExtensionFilter)1