Search in sources :

Example 21 with ComponentFactory

use of com.cburch.logisim.comp.ComponentFactory in project logisim-evolution by reds-heig.

the class FileStatistics method doUniqueCounts.

private static void doUniqueCounts(Map<ComponentFactory, Count> counts, Map<Circuit, Map<ComponentFactory, Count>> circuitCounts) {
    for (Count count : counts.values()) {
        ComponentFactory factory = count.getFactory();
        int unique = 0;
        for (Circuit circ : circuitCounts.keySet()) {
            Count subcount = circuitCounts.get(circ).get(factory);
            if (subcount != null) {
                unique += subcount.simpleCount;
            }
        }
        count.uniqueCount = unique;
    }
}
Also used : ComponentFactory(com.cburch.logisim.comp.ComponentFactory) Circuit(com.cburch.logisim.circuit.Circuit)

Example 22 with ComponentFactory

use of com.cburch.logisim.comp.ComponentFactory 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 23 with ComponentFactory

use of com.cburch.logisim.comp.ComponentFactory in project logisim-evolution by reds-heig.

the class Circuit method mutatorAdd.

void mutatorAdd(Component c) {
    // logger.debug("mutatorAdd: {}", c);
    locker.checkForWritePermission("add");
    Annotated = false;
    MyNetList.clear();
    if (c instanceof Wire) {
        Wire w = (Wire) c;
        if (w.getEnd0().equals(w.getEnd1()))
            return;
        boolean added = wires.add(w);
        if (!added)
            return;
    } else {
        // add it into the circuit
        boolean added = comps.add(c);
        if (!added)
            return;
        wires.add(c);
        ComponentFactory factory = c.getFactory();
        if (factory instanceof Clock) {
            clocks.add(c);
        } else if (factory instanceof SubcircuitFactory) {
            SubcircuitFactory subcirc = (SubcircuitFactory) factory;
            subcirc.getSubcircuit().circuitsUsingThis.put(c, this);
        }
        c.addComponentListener(myComponentListener);
    }
    RemoveWrongLabels(c.getFactory().getName());
    fireEvent(CircuitEvent.ACTION_ADD, c);
}
Also used : ComponentFactory(com.cburch.logisim.comp.ComponentFactory) Clock(com.cburch.logisim.std.wiring.Clock)

Example 24 with ComponentFactory

use of com.cburch.logisim.comp.ComponentFactory in project logisim-evolution by reds-heig.

the class FileStatistics method getTotal.

private static Count getTotal(List<Count> counts, Set<Circuit> exclude) {
    Count ret = new Count(null);
    for (Count count : counts) {
        ComponentFactory factory = count.getFactory();
        Circuit factoryCirc = null;
        if (factory instanceof SubcircuitFactory) {
            factoryCirc = ((SubcircuitFactory) factory).getSubcircuit();
        }
        if (exclude == null || !exclude.contains(factoryCirc)) {
            ret.simpleCount += count.simpleCount;
            ret.uniqueCount += count.uniqueCount;
            ret.recursiveCount += count.recursiveCount;
        }
    }
    return ret;
}
Also used : ComponentFactory(com.cburch.logisim.comp.ComponentFactory) SubcircuitFactory(com.cburch.logisim.circuit.SubcircuitFactory) Circuit(com.cburch.logisim.circuit.Circuit)

Example 25 with ComponentFactory

use of com.cburch.logisim.comp.ComponentFactory in project logisim-evolution by reds-heig.

the class CircuitBuilder method placeInputs.

// 
// placeInputs
// 
private static void placeInputs(CircuitMutation result, InputData inputData) {
    ArrayList<Location> forbiddenYs = new ArrayList<Location>();
    Comparator<Location> compareYs = new CompareYs();
    int curX = 40;
    int curY = 30;
    for (int i = 0; i < inputData.names.length; i++) {
        String name = inputData.names[i];
        SingleInput singleInput = inputData.inputs.get(name);
        // determine point where we can intersect with spine
        int spineX = singleInput.spineX;
        Location spineLoc = Location.create(spineX, curY);
        if (singleInput.ys.size() > 0) {
            // search for a Y that won't intersect with others
            // (we needn't bother if the pin doesn't connect
            // with anything anyway.)
            Collections.sort(forbiddenYs, compareYs);
            while (Collections.binarySearch(forbiddenYs, spineLoc, compareYs) >= 0) {
                curY += 10;
                spineLoc = Location.create(spineX, curY);
            }
            singleInput.ys.add(spineLoc);
        }
        Location loc = Location.create(curX, curY);
        // now create the pin
        ComponentFactory factory = Pin.FACTORY;
        AttributeSet attrs = factory.createAttributeSet();
        attrs.setValue(StdAttr.FACING, Direction.EAST);
        attrs.setValue(Pin.ATTR_TYPE, Boolean.FALSE);
        attrs.setValue(Pin.ATTR_TRISTATE, Boolean.FALSE);
        attrs.setValue(StdAttr.LABEL, name);
        attrs.setValue(Pin.ATTR_LABEL_LOC, Direction.NORTH);
        result.add(factory.createComponent(loc, attrs));
        ArrayList<Location> spine = singleInput.ys;
        if (spine.size() > 0) {
            // create wire connecting pin to spine
            /*
				 * This should no longer matter - the wires will be repaired
				 * anyway by the circuit's WireRepair class. if (spine.size() ==
				 * 2 && spine.get(0).equals(spine.get(1))) { // a freak accident
				 * where the input is used just once, // and it happens that the
				 * pin is placed where no // spine is necessary Iterator<Wire>
				 * it = circuit.getWires(spineLoc).iterator(); Wire existing =
				 * it.next(); Wire replace = Wire.create(loc,
				 * existing.getEnd1()); result.replace(existing, replace); }
				 * else {
				 */
            result.add(Wire.create(loc, spineLoc));
            // }
            // create spine
            Collections.sort(spine, compareYs);
            Location prev = spine.get(0);
            for (int k = 1, n = spine.size(); k < n; k++) {
                Location cur = spine.get(k);
                if (!cur.equals(prev)) {
                    result.add(Wire.create(prev, cur));
                    prev = cur;
                }
            }
        }
        // advance y and forbid spine intersections for next pin
        forbiddenYs.addAll(singleInput.ys);
        curY += 50;
    }
}
Also used : AttributeSet(com.cburch.logisim.data.AttributeSet) ComponentFactory(com.cburch.logisim.comp.ComponentFactory) ArrayList(java.util.ArrayList) Location(com.cburch.logisim.data.Location)

Aggregations

ComponentFactory (com.cburch.logisim.comp.ComponentFactory)37 AttributeSet (com.cburch.logisim.data.AttributeSet)16 AddTool (com.cburch.logisim.tools.AddTool)9 Tool (com.cburch.logisim.tools.Tool)9 Circuit (com.cburch.logisim.circuit.Circuit)8 SubcircuitFactory (com.cburch.logisim.circuit.SubcircuitFactory)8 Component (com.cburch.logisim.comp.Component)8 Library (com.cburch.logisim.tools.Library)8 ArrayList (java.util.ArrayList)6 Wire (com.cburch.logisim.circuit.Wire)4 Location (com.cburch.logisim.data.Location)4 ProjectExplorerToolNode (com.cburch.logisim.gui.generic.ProjectExplorerToolNode)4 HashSet (java.util.HashSet)4 Attribute (com.cburch.logisim.data.Attribute)3 Bounds (com.cburch.logisim.data.Bounds)3 ToolAttributeAction (com.cburch.logisim.gui.main.ToolAttributeAction)3 Action (com.cburch.logisim.proj.Action)3 HashMap (java.util.HashMap)3 CircuitMutation (com.cburch.logisim.circuit.CircuitMutation)2 Direction (com.cburch.logisim.data.Direction)2