Search in sources :

Example 1 with LogisimFile

use of com.cburch.logisim.file.LogisimFile in project logisim-evolution by reds-heig.

the class SelectionActions method getReplacementMap.

private static HashMap<Component, Component> getReplacementMap(Project proj) {
    HashMap<Component, Component> replMap;
    replMap = new HashMap<Component, Component>();
    LogisimFile file = proj.getLogisimFile();
    ArrayList<Library> libs = new ArrayList<Library>();
    libs.add(file);
    libs.addAll(file.getLibraries());
    ArrayList<String> dropped = null;
    Clipboard clip = Clipboard.get();
    Collection<Component> comps = clip.getComponents();
    HashMap<ComponentFactory, ComponentFactory> factoryReplacements;
    factoryReplacements = new HashMap<ComponentFactory, ComponentFactory>();
    for (Component comp : comps) {
        if (comp instanceof Wire)
            continue;
        ComponentFactory compFactory = comp.getFactory();
        ComponentFactory copyFactory = findComponentFactory(compFactory, libs, false);
        if (factoryReplacements.containsKey(compFactory)) {
            copyFactory = factoryReplacements.get(compFactory);
        } else if (copyFactory == null) {
            ComponentFactory candidate = findComponentFactory(compFactory, libs, true);
            if (candidate == null) {
                if (dropped == null) {
                    dropped = new ArrayList<String>();
                }
                dropped.add(compFactory.getDisplayName());
            } else {
                String msg = Strings.get("pasteCloneQuery", compFactory.getName());
                Object[] opts = { Strings.get("pasteCloneReplace"), Strings.get("pasteCloneIgnore"), Strings.get("pasteCloneCancel") };
                int select = JOptionPane.showOptionDialog(proj.getFrame(), msg, Strings.get("pasteCloneTitle"), 0, JOptionPane.QUESTION_MESSAGE, null, opts, opts[0]);
                if (select == 0) {
                    copyFactory = candidate;
                } else if (select == 1) {
                    copyFactory = null;
                } else {
                    return null;
                }
                factoryReplacements.put(compFactory, copyFactory);
            }
        }
        if (copyFactory == null) {
            replMap.put(comp, null);
        } else if (copyFactory != compFactory) {
            Location copyLoc = comp.getLocation();
            AttributeSet copyAttrs = (AttributeSet) comp.getAttributeSet().clone();
            Component copy = copyFactory.createComponent(copyLoc, copyAttrs);
            replMap.put(comp, copy);
        }
    }
    if (dropped != null) {
        Collections.sort(dropped);
        StringBuilder droppedStr = new StringBuilder();
        droppedStr.append(Strings.get("pasteDropMessage"));
        String curName = dropped.get(0);
        int curCount = 1;
        int lines = 1;
        for (int i = 1; i <= dropped.size(); i++) {
            String nextName = i == dropped.size() ? "" : dropped.get(i);
            if (nextName.equals(curName)) {
                curCount++;
            } else {
                lines++;
                droppedStr.append("\n  ");
                droppedStr.append(curName);
                if (curCount > 1) {
                    droppedStr.append(" \u00d7 " + curCount);
                }
                curName = nextName;
                curCount = 1;
            }
        }
        lines = Math.max(3, Math.min(7, lines));
        JTextArea area = new JTextArea(lines, 60);
        area.setEditable(false);
        area.setText(droppedStr.toString());
        area.setCaretPosition(0);
        JScrollPane areaPane = new JScrollPane(area);
        JOptionPane.showMessageDialog(proj.getFrame(), areaPane, Strings.get("pasteDropTitle"), JOptionPane.WARNING_MESSAGE);
    }
    return replMap;
}
Also used : JScrollPane(javax.swing.JScrollPane) JTextArea(javax.swing.JTextArea) ComponentFactory(com.cburch.logisim.comp.ComponentFactory) ArrayList(java.util.ArrayList) Wire(com.cburch.logisim.circuit.Wire) LogisimFile(com.cburch.logisim.file.LogisimFile) AttributeSet(com.cburch.logisim.data.AttributeSet) Library(com.cburch.logisim.tools.Library) Component(com.cburch.logisim.comp.Component) Location(com.cburch.logisim.data.Location)

Example 2 with LogisimFile

use of com.cburch.logisim.file.LogisimFile in project logisim-evolution by reds-heig.

the class RegTabContent method fillArray.

/**
 * This function will clear and fill the registers tab and refresh their
 * value. It will start by iterate over all circuits of the current project
 * to register all the "Register" components (providing their attributes are
 * correctly set). It will then fill the panel with each register found,
 * including their current value.
 */
private void fillArray() {
    int y = 0;
    MyLabel col1 = new MyLabel("Circuit", Font.ITALIC | Font.BOLD);
    MyLabel col2 = new MyLabel("Reg name", Font.BOLD);
    MyLabel col3 = new MyLabel("Value", Font.BOLD);
    registers.clear();
    panel.removeAll();
    for (Circuit circ : proj.getLogisimFile().getCircuits()) {
        getAllRegisters(circ);
    }
    if (proj.getLogisimFile().getLibrary("prodis_v1.3") instanceof LoadedLibrary) {
        if (((LoadedLibrary) proj.getLogisimFile().getLibrary("prodis_v1.3")).getBase() instanceof LogisimFile) {
            for (Circuit circ : ((LogisimFile) ((LoadedLibrary) proj.getLogisimFile().getLibrary("prodis_v1.3")).getBase()).getCircuits()) {
                getAllRegisters(circ);
            }
        }
    }
    col1.setColor(Color.LIGHT_GRAY);
    col2.setColor(Color.LIGHT_GRAY);
    col3.setColor(Color.LIGHT_GRAY);
    c.fill = GridBagConstraints.HORIZONTAL;
    c.anchor = GridBagConstraints.FIRST_LINE_START;
    c.ipady = 2;
    c.weighty = 0;
    c.gridy = y;
    c.gridx = 0;
    c.weightx = 0.3;
    panel.add(col1, c);
    c.gridx++;
    c.weightx = 0.5;
    panel.add(col2, c);
    c.gridx++;
    c.weightx = 0.2;
    panel.add(col3, c);
    y++;
    if (!registers.isEmpty()) {
        Object[] objArr = registers.keySet().toArray();
        Arrays.sort(objArr);
        for (Object name : objArr) {
            c.gridy = y;
            c.gridx = 0;
            String circuitName = name.toString().split("/")[0];
            panel.add(new MyLabel(circuitName, Font.ITALIC, true), c);
            c.gridx++;
            String registerName = name.toString().split("/")[1];
            panel.add(new MyLabel(registerName), c);
            c.gridx++;
            Component selReg = registers.get(name.toString());
            CircuitState mainCircState = proj.getCircuitState();
            while (mainCircState.getParentState() != null) {
                // Get the main
                // circuit
                mainCircState = mainCircState.getParentState();
            }
            Value val = findVal(mainCircState, circuitName, selReg.getEnd(0).getLocation());
            if (val != null) {
                panel.add(new MyLabel(val.toHexString()), c);
            } else {
                panel.add(new MyLabel("-"), c);
            }
            y++;
        }
    }
    c.weighty = 1;
    c.gridy++;
    c.gridx = 0;
    c.weightx = 1;
    panel.add(new MyLabel(""), c);
    panel.validate();
}
Also used : CircuitState(com.cburch.logisim.circuit.CircuitState) LogisimFile(com.cburch.logisim.file.LogisimFile) Value(com.cburch.logisim.data.Value) Circuit(com.cburch.logisim.circuit.Circuit) LoadedLibrary(com.cburch.logisim.file.LoadedLibrary) Component(com.cburch.logisim.comp.Component)

Example 3 with LogisimFile

use of com.cburch.logisim.file.LogisimFile in project logisim-evolution by reds-heig.

the class Project method setLogisimFile.

public void setLogisimFile(LogisimFile value) {
    LogisimFile old = this.file;
    if (old != null) {
        for (LibraryListener l : fileListeners) {
            old.removeLibraryListener(l);
        }
    }
    file = value;
    stateMap.clear();
    depends = new Dependencies(file);
    undoLog.clear();
    redoLog.clear();
    undoMods = 0;
    fireEvent(ProjectEvent.ACTION_SET_FILE, old, file);
    setCurrentCircuit(file.getMainCircuit());
    if (file != null) {
        for (LibraryListener l : fileListeners) {
            file.addLibraryListener(l);
        }
    }
    // toggle it so that everybody hears the file is
    file.setDirty(true);
    // fresh
    file.setDirty(false);
}
Also used : LogisimFile(com.cburch.logisim.file.LogisimFile) LibraryListener(com.cburch.logisim.file.LibraryListener)

Example 4 with LogisimFile

use of com.cburch.logisim.file.LogisimFile in project logisim-evolution by reds-heig.

the class ProjectActions method doMerge.

public static void doMerge(Component parent, Project baseProject) {
    JFileChooser chooser;
    LogisimFile mergelib;
    Loader loader = null;
    if (baseProject != null) {
        Loader oldLoader = baseProject.getLogisimFile().getLoader();
        chooser = oldLoader.createChooser();
        if (oldLoader.getMainFile() != null) {
            chooser.setSelectedFile(oldLoader.getMainFile());
        }
    } else {
        chooser = JFileChoosers.create();
    }
    chooser.setFileFilter(Loader.LOGISIM_FILTER);
    chooser.setDialogTitle(Strings.get("FileMergeItem"));
    int returnVal = chooser.showOpenDialog(parent);
    if (returnVal != JFileChooser.APPROVE_OPTION)
        return;
    File selected = chooser.getSelectedFile();
    loader = new Loader(baseProject == null ? parent : baseProject.getFrame());
    try {
        mergelib = loader.openLogisimFile(selected);
        if (mergelib == null)
            return;
    } catch (LoadFailedException ex) {
        if (!ex.isShown()) {
            JOptionPane.showMessageDialog(parent, StringUtil.format(Strings.get("fileMergeError"), ex.toString()), Strings.get("FileMergeErrorItem"), JOptionPane.ERROR_MESSAGE);
        }
        return;
    }
    updatecircs(mergelib, baseProject);
    baseProject.doAction(LogisimFileActions.MergeFile(mergelib, baseProject.getLogisimFile()));
}
Also used : LogisimFile(com.cburch.logisim.file.LogisimFile) JFileChooser(javax.swing.JFileChooser) Loader(com.cburch.logisim.file.Loader) LogisimFile(com.cburch.logisim.file.LogisimFile) File(java.io.File) LoadFailedException(com.cburch.logisim.file.LoadFailedException)

Example 5 with LogisimFile

use of com.cburch.logisim.file.LogisimFile in project logisim-evolution by reds-heig.

the class ProjectActions method doNew.

public static Project doNew(SplashScreen monitor, boolean isStartupScreen) {
    if (monitor != null)
        monitor.setProgress(SplashScreen.FILE_CREATE);
    Loader loader = new Loader(monitor);
    InputStream templReader = AppPreferences.getTemplate().createStream();
    LogisimFile file = null;
    try {
        file = loader.openLogisimFile(templReader);
    } catch (IOException ex) {
        displayException(monitor, ex);
    } catch (LoadFailedException ex) {
        displayException(monitor, ex);
    } finally {
        try {
            templReader.close();
        } catch (IOException e) {
        }
    }
    if (file == null)
        file = createEmptyFile(loader, null);
    return completeProject(monitor, loader, file, isStartupScreen);
}
Also used : LogisimFile(com.cburch.logisim.file.LogisimFile) InputStream(java.io.InputStream) Loader(com.cburch.logisim.file.Loader) IOException(java.io.IOException) LoadFailedException(com.cburch.logisim.file.LoadFailedException)

Aggregations

LogisimFile (com.cburch.logisim.file.LogisimFile)18 Loader (com.cburch.logisim.file.Loader)7 Circuit (com.cburch.logisim.circuit.Circuit)6 LoadFailedException (com.cburch.logisim.file.LoadFailedException)6 ArrayList (java.util.ArrayList)6 Library (com.cburch.logisim.tools.Library)4 IOException (java.io.IOException)4 InputStream (java.io.InputStream)3 JScrollPane (javax.swing.JScrollPane)3 CircuitState (com.cburch.logisim.circuit.CircuitState)2 Component (com.cburch.logisim.comp.Component)2 LoadedLibrary (com.cburch.logisim.file.LoadedLibrary)2 Frame (com.cburch.logisim.gui.main.Frame)2 File (java.io.File)2 Netlist (com.bfh.logisim.designrulecheck.Netlist)1 AbstractHDLGeneratorFactory (com.bfh.logisim.hdlgenerator.AbstractHDLGeneratorFactory)1 HDLGeneratorFactory (com.bfh.logisim.hdlgenerator.HDLGeneratorFactory)1 TickComponentHDLGeneratorFactory (com.bfh.logisim.hdlgenerator.TickComponentHDLGeneratorFactory)1 ToplevelHDLGeneratorFactory (com.bfh.logisim.hdlgenerator.ToplevelHDLGeneratorFactory)1 Wire (com.cburch.logisim.circuit.Wire)1