Search in sources :

Example 11 with AddTool

use of com.cburch.logisim.tools.AddTool in project logisim-evolution by reds-heig.

the class FileStatistics method sortCounts.

private static List<Count> sortCounts(Map<ComponentFactory, Count> counts, LogisimFile file) {
    List<Count> ret = new ArrayList<Count>();
    for (AddTool tool : file.getTools()) {
        ComponentFactory factory = tool.getFactory();
        Count count = counts.get(factory);
        if (count != null) {
            count.library = file;
            ret.add(count);
        }
    }
    for (Library lib : file.getLibraries()) {
        for (Tool tool : lib.getTools()) {
            if (tool instanceof AddTool) {
                ComponentFactory factory = ((AddTool) tool).getFactory();
                Count count = counts.get(factory);
                if (count != null) {
                    count.library = lib;
                    ret.add(count);
                }
            }
        }
    }
    return ret;
}
Also used : ComponentFactory(com.cburch.logisim.comp.ComponentFactory) ArrayList(java.util.ArrayList) AddTool(com.cburch.logisim.tools.AddTool) Library(com.cburch.logisim.tools.Library) Tool(com.cburch.logisim.tools.Tool) AddTool(com.cburch.logisim.tools.AddTool)

Example 12 with AddTool

use of com.cburch.logisim.tools.AddTool in project logisim-evolution by reds-heig.

the class LoadedLibrary method resolveChanges.

private void resolveChanges(Library old) {
    if (listeners.isEmpty())
        return;
    if (!base.getDisplayName().equals(old.getDisplayName())) {
        fireLibraryEvent(LibraryEvent.SET_NAME, base.getDisplayName());
    }
    HashSet<Library> changes = new HashSet<Library>(old.getLibraries());
    changes.removeAll(base.getLibraries());
    for (Library lib : changes) {
        fireLibraryEvent(LibraryEvent.REMOVE_LIBRARY, lib);
    }
    changes.clear();
    changes.addAll(base.getLibraries());
    changes.removeAll(old.getLibraries());
    for (Library lib : changes) {
        fireLibraryEvent(LibraryEvent.ADD_LIBRARY, lib);
    }
    HashMap<ComponentFactory, ComponentFactory> componentMap;
    HashMap<Tool, Tool> toolMap;
    componentMap = new HashMap<ComponentFactory, ComponentFactory>();
    toolMap = new HashMap<Tool, Tool>();
    for (Tool oldTool : old.getTools()) {
        Tool newTool = base.getTool(oldTool.getName());
        toolMap.put(oldTool, newTool);
        if (oldTool instanceof AddTool) {
            ComponentFactory oldFactory = ((AddTool) oldTool).getFactory();
            if (newTool != null && newTool instanceof AddTool) {
                ComponentFactory newFactory = ((AddTool) newTool).getFactory();
                componentMap.put(oldFactory, newFactory);
            } else {
                componentMap.put(oldFactory, null);
            }
        }
    }
    replaceAll(componentMap, toolMap);
    HashSet<Tool> toolChanges = new HashSet<Tool>(old.getTools());
    toolChanges.removeAll(toolMap.keySet());
    for (Tool tool : toolChanges) {
        fireLibraryEvent(LibraryEvent.REMOVE_TOOL, tool);
    }
    toolChanges = new HashSet<Tool>(base.getTools());
    toolChanges.removeAll(toolMap.values());
    for (Tool tool : toolChanges) {
        fireLibraryEvent(LibraryEvent.ADD_TOOL, tool);
    }
}
Also used : ComponentFactory(com.cburch.logisim.comp.ComponentFactory) Library(com.cburch.logisim.tools.Library) AddTool(com.cburch.logisim.tools.AddTool) HashSet(java.util.HashSet) Tool(com.cburch.logisim.tools.Tool) AddTool(com.cburch.logisim.tools.AddTool)

Example 13 with AddTool

use of com.cburch.logisim.tools.AddTool in project logisim-evolution by reds-heig.

the class LogisimFile method removeCircuit.

public void removeCircuit(Circuit circuit) {
    if (tools.size() <= 1) {
        throw new RuntimeException("Cannot remove last circuit");
    }
    int index = getCircuits().indexOf(circuit);
    if (index >= 0) {
        Tool circuitTool = tools.remove(index);
        if (main == circuit) {
            AddTool dflt_tool = tools.get(0);
            SubcircuitFactory factory = (SubcircuitFactory) dflt_tool.getFactory();
            setMainCircuit(factory.getSubcircuit());
        }
        fireEvent(LibraryEvent.REMOVE_TOOL, circuitTool);
    }
}
Also used : SubcircuitFactory(com.cburch.logisim.circuit.SubcircuitFactory) AddTool(com.cburch.logisim.tools.AddTool) Tool(com.cburch.logisim.tools.Tool) AddTool(com.cburch.logisim.tools.AddTool)

Example 14 with AddTool

use of com.cburch.logisim.tools.AddTool in project logisim-evolution by reds-heig.

the class MouseMappings method replaceAll.

// 
// package-protected methods
// 
void replaceAll(Map<Tool, Tool> toolMap) {
    boolean changed = false;
    for (Map.Entry<Integer, Tool> entry : map.entrySet()) {
        Integer key = entry.getKey();
        Tool tool = entry.getValue();
        if (tool instanceof AddTool) {
            ComponentFactory factory = ((AddTool) tool).getFactory();
            if (toolMap.containsKey(factory)) {
                changed = true;
                Tool newTool = toolMap.get(factory);
                if (newTool == null) {
                    map.remove(key);
                } else {
                    Tool clone = newTool.cloneTool();
                    LoadedLibrary.copyAttributes(clone.getAttributeSet(), tool.getAttributeSet());
                    map.put(key, clone);
                }
            }
        } else {
            if (toolMap.containsKey(tool)) {
                changed = true;
                Tool newTool = toolMap.get(tool);
                if (newTool == null) {
                    map.remove(key);
                } else {
                    Tool clone = newTool.cloneTool();
                    LoadedLibrary.copyAttributes(clone.getAttributeSet(), tool.getAttributeSet());
                    map.put(key, clone);
                }
            }
        }
    }
    if (changed)
        fireMouseMappingsChanged();
}
Also used : ComponentFactory(com.cburch.logisim.comp.ComponentFactory) AddTool(com.cburch.logisim.tools.AddTool) Map(java.util.Map) HashMap(java.util.HashMap) SelectTool(com.cburch.logisim.tools.SelectTool) Tool(com.cburch.logisim.tools.Tool) AddTool(com.cburch.logisim.tools.AddTool)

Example 15 with AddTool

use of com.cburch.logisim.tools.AddTool in project logisim-evolution by reds-heig.

the class XmlCircuitReader method getComponent.

/**
 * Get a circuit's component from a read XML file. If the component has a
 * non-null "trackercomp" field, it means that it is tracked, therefore it
 * is skipped in the non-tracked version to avoid errors.
 *
 * @param elt
 *            XML element to parse
 * @param reader
 *            XML file reader
 * @return the component built from its XML description
 * @throws XmlReaderException
 */
static Component getComponent(Element elt, XmlReader.ReadContext reader) throws XmlReaderException {
    if (elt.getAttribute("trackercomp") != "" && !Main.VERSION.hasTracker()) {
        return (null);
    }
    // Determine the factory that creates this element
    String name = elt.getAttribute("name");
    if (name == null || name.equals("")) {
        throw new XmlReaderException(Strings.get("compNameMissingError"));
    }
    String libName = elt.getAttribute("lib");
    Library lib = reader.findLibrary(libName);
    if (lib == null) {
        throw new XmlReaderException(Strings.get("compUnknownError", "no-lib"));
    }
    Tool tool = lib.getTool(name);
    if (tool == null || !(tool instanceof AddTool)) {
        if (libName == null || libName.equals("")) {
            throw new XmlReaderException(Strings.get("compUnknownError", name));
        } else {
            throw new XmlReaderException(Strings.get("compAbsentError", name, libName));
        }
    }
    ComponentFactory source = ((AddTool) tool).getFactory();
    // Determine attributes
    String loc_str = elt.getAttribute("loc");
    AttributeSet attrs = source.createAttributeSet();
    reader.initAttributeSet(elt, attrs, source);
    // Create component if location known
    if (loc_str == null || loc_str.equals("")) {
        throw new XmlReaderException(Strings.get("compLocMissingError", source.getName()));
    } else {
        try {
            Location loc = Location.parse(loc_str);
            return source.createComponent(loc, attrs);
        } catch (NumberFormatException e) {
            throw new XmlReaderException(Strings.get("compLocInvalidError", source.getName(), loc_str));
        }
    }
}
Also used : AttributeSet(com.cburch.logisim.data.AttributeSet) ComponentFactory(com.cburch.logisim.comp.ComponentFactory) Library(com.cburch.logisim.tools.Library) AddTool(com.cburch.logisim.tools.AddTool) Tool(com.cburch.logisim.tools.Tool) AddTool(com.cburch.logisim.tools.AddTool) Location(com.cburch.logisim.data.Location)

Aggregations

AddTool (com.cburch.logisim.tools.AddTool)16 Tool (com.cburch.logisim.tools.Tool)10 ComponentFactory (com.cburch.logisim.comp.ComponentFactory)9 SubcircuitFactory (com.cburch.logisim.circuit.SubcircuitFactory)7 Library (com.cburch.logisim.tools.Library)6 Circuit (com.cburch.logisim.circuit.Circuit)5 ProjectExplorerToolNode (com.cburch.logisim.gui.generic.ProjectExplorerToolNode)4 ProjectExplorerLibraryNode (com.cburch.logisim.gui.generic.ProjectExplorerLibraryNode)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 CircuitException (com.cburch.logisim.circuit.CircuitException)1 CircuitMutation (com.cburch.logisim.circuit.CircuitMutation)1 Component (com.cburch.logisim.comp.Component)1 AttributeSet (com.cburch.logisim.data.AttributeSet)1 Location (com.cburch.logisim.data.Location)1 AttrTableModel (com.cburch.logisim.gui.generic.AttrTableModel)1 Action (com.cburch.logisim.proj.Action)1 SelectTool (com.cburch.logisim.tools.SelectTool)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1