Search in sources :

Example 31 with Component

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

the class LogisimFile method getUnloadLibraryMessage.

public String getUnloadLibraryMessage(Library lib) {
    HashSet<ComponentFactory> factories = new HashSet<ComponentFactory>();
    for (Tool tool : lib.getTools()) {
        if (tool instanceof AddTool) {
            factories.add(((AddTool) tool).getFactory());
        }
    }
    for (Circuit circuit : getCircuits()) {
        for (Component comp : circuit.getNonWires()) {
            if (factories.contains(comp.getFactory())) {
                return StringUtil.format(Strings.get("unloadUsedError"), circuit.getName());
            }
        }
    }
    ToolbarData tb = options.getToolbarData();
    MouseMappings mm = options.getMouseMappings();
    for (Tool t : lib.getTools()) {
        if (tb.usesToolFromSource(t)) {
            return Strings.get("unloadToolbarError");
        }
        if (mm.usesToolFromSource(t)) {
            return Strings.get("unloadMappingError");
        }
    }
    return null;
}
Also used : ComponentFactory(com.cburch.logisim.comp.ComponentFactory) Circuit(com.cburch.logisim.circuit.Circuit) AddTool(com.cburch.logisim.tools.AddTool) Component(com.cburch.logisim.comp.Component) HashSet(java.util.HashSet) Tool(com.cburch.logisim.tools.Tool) AddTool(com.cburch.logisim.tools.AddTool)

Example 32 with Component

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

the class CircuitPins method transactionCompleted.

public void transactionCompleted(ReplacementMap repl) {
    // determine the changes
    Set<Instance> adds = new HashSet<Instance>();
    Set<Instance> removes = new HashSet<Instance>();
    Map<Instance, Instance> replaces = new HashMap<Instance, Instance>();
    for (Component comp : repl.getAdditions()) {
        if (comp.getFactory() instanceof Pin) {
            Instance in = Instance.getInstanceFor(comp);
            boolean added = pins.add(in);
            if (added) {
                comp.addComponentListener(myComponentListener);
                in.getAttributeSet().addAttributeListener(myComponentListener);
                adds.add(in);
            }
        }
    }
    for (Component comp : repl.getRemovals()) {
        if (comp.getFactory() instanceof Pin) {
            Instance in = Instance.getInstanceFor(comp);
            boolean removed = pins.remove(in);
            if (removed) {
                comp.removeComponentListener(myComponentListener);
                in.getAttributeSet().removeAttributeListener(myComponentListener);
                Collection<Component> rs = repl.getComponentsReplacing(comp);
                if (rs.isEmpty()) {
                    removes.add(in);
                } else {
                    Component r = rs.iterator().next();
                    Instance rin = Instance.getInstanceFor(r);
                    adds.remove(rin);
                    replaces.put(in, rin);
                }
            }
        }
    }
    appearanceManager.updatePorts(adds, removes, replaces, getPins());
}
Also used : Pin(com.cburch.logisim.std.wiring.Pin) Instance(com.cburch.logisim.instance.Instance) HashMap(java.util.HashMap) Component(com.cburch.logisim.comp.Component) HashSet(java.util.HashSet)

Example 33 with Component

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

the class WireUtil method mergeExclusive.

// Merge all parallel endpoint-to-endpoint wires within the given set.
public static Collection<? extends Component> mergeExclusive(Collection<? extends Component> toMerge) {
    if (toMerge.size() <= 1)
        return toMerge;
    HashSet<Component> ret = new HashSet<Component>(toMerge);
    CircuitPoints points = computeCircuitPoints(toMerge);
    HashSet<Wire> wires = new HashSet<Wire>();
    for (Location loc : points.getSplitLocations()) {
        Collection<? extends Component> at = points.getComponents(loc);
        if (at.size() == 2) {
            Iterator<? extends Component> atIt = at.iterator();
            Component o0 = atIt.next();
            Component o1 = atIt.next();
            if (o0 instanceof Wire && o1 instanceof Wire) {
                Wire w0 = (Wire) o0;
                Wire w1 = (Wire) o1;
                if (w0.is_x_equal == w1.is_x_equal) {
                    wires.add(w0);
                    wires.add(w1);
                }
            }
        }
    }
    points = null;
    ret.removeAll(wires);
    while (!wires.isEmpty()) {
        Iterator<Wire> it = wires.iterator();
        Wire w = it.next();
        Location e0 = w.e0;
        Location e1 = w.e1;
        it.remove();
        boolean found;
        do {
            found = false;
            for (it = wires.iterator(); it.hasNext(); ) {
                Wire cand = it.next();
                if (cand.e0.equals(e1)) {
                    e1 = cand.e1;
                    found = true;
                    it.remove();
                } else if (cand.e1.equals(e0)) {
                    e0 = cand.e0;
                    found = true;
                    it.remove();
                }
            }
        } while (found);
        ret.add(Wire.create(e0, e1));
    }
    return ret;
}
Also used : Component(com.cburch.logisim.comp.Component) HashSet(java.util.HashSet) Location(com.cburch.logisim.data.Location)

Example 34 with Component

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

the class ReplacementMap method print.

public void print(PrintStream out) {
    boolean found = false;
    for (Component c : getRemovals()) {
        if (!found)
            out.println("  removals:");
        found = true;
        out.println("    " + c.toString());
    }
    if (!found)
        out.println("  removals: none");
    found = false;
    for (Component c : getAdditions()) {
        if (!found)
            out.println("  additions:");
        found = true;
        out.println("    " + c.toString());
    }
    if (!found)
        out.println("  additions: none");
}
Also used : Component(com.cburch.logisim.comp.Component)

Example 35 with Component

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

the class Circuit method RemoveWrongLabels.

private void RemoveWrongLabels(String Label) {
    boolean HaveAChange = false;
    for (Component comp : comps) {
        AttributeSet attrs = comp.getAttributeSet();
        if (attrs.containsAttribute(StdAttr.LABEL)) {
            String CompLabel = attrs.getValue(StdAttr.LABEL);
            if (Label.toUpperCase().equals(CompLabel.toUpperCase())) {
                attrs.setValue(StdAttr.LABEL, "");
                HaveAChange = true;
            }
        }
    }
    /* we do not have to check the wires as (1) Wire is a reserved keyword, and (2) they cannot have a label */
    if (HaveAChange)
        JOptionPane.showMessageDialog(null, "\"" + Label + "\" : " + Strings.get("ComponentLabelCollisionError"));
}
Also used : AttributeSet(com.cburch.logisim.data.AttributeSet) Component(com.cburch.logisim.comp.Component)

Aggregations

Component (com.cburch.logisim.comp.Component)97 Location (com.cburch.logisim.data.Location)26 ArrayList (java.util.ArrayList)20 Circuit (com.cburch.logisim.circuit.Circuit)19 AttributeSet (com.cburch.logisim.data.AttributeSet)13 Wire (com.cburch.logisim.circuit.Wire)12 Bounds (com.cburch.logisim.data.Bounds)11 HashMap (java.util.HashMap)11 HashSet (java.util.HashSet)11 SubcircuitFactory (com.cburch.logisim.circuit.SubcircuitFactory)8 ComponentFactory (com.cburch.logisim.comp.ComponentFactory)8 EndData (com.cburch.logisim.comp.EndData)8 InstanceComponent (com.cburch.logisim.instance.InstanceComponent)8 Project (com.cburch.logisim.proj.Project)7 Pin (com.cburch.logisim.std.wiring.Pin)7 Graphics (java.awt.Graphics)7 CircuitState (com.cburch.logisim.circuit.CircuitState)6 Splitter (com.cburch.logisim.circuit.Splitter)6 Selection (com.cburch.logisim.gui.main.Selection)6 InstanceState (com.cburch.logisim.instance.InstanceState)5