Search in sources :

Example 66 with Component

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

the class CircuitState method setValueByWire.

void setValueByWire(Location p, Value v) {
    // for CircuitWires - to set value at point
    boolean changed;
    if (v == Value.NIL) {
        Object old = values.remove(p);
        changed = (old != null && old != Value.NIL);
    } else {
        Object old = values.put(p, v);
        changed = !v.equals(old);
    }
    if (changed) {
        boolean found = false;
        for (Component comp : circuit.getComponents(p)) {
            if (!(comp instanceof Wire) && !(comp instanceof Splitter)) {
                found = true;
                markComponentAsDirty(comp);
            }
        }
        if (found && base != null)
            base.locationTouched(this, p);
    }
}
Also used : Component(com.cburch.logisim.comp.Component)

Example 67 with Component

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

the class Circuit method draw.

// 
// Graphics methods
// 
public void draw(ComponentDrawContext context, Collection<Component> hidden) {
    Graphics g = context.getGraphics();
    Graphics g_copy = g.create();
    context.setGraphics(g_copy);
    wires.draw(context, hidden);
    if (hidden == null || hidden.size() == 0) {
        for (Component c : comps) {
            Graphics g_new = g.create();
            context.setGraphics(g_new);
            g_copy.dispose();
            g_copy = g_new;
            c.draw(context);
        }
    } else {
        for (Component c : comps) {
            if (!hidden.contains(c)) {
                Graphics g_new = g.create();
                context.setGraphics(g_new);
                g_copy.dispose();
                g_copy = g_new;
                try {
                    c.draw(context);
                } catch (RuntimeException e) {
                    // this is a JAR developer error - display it and move
                    // on
                    e.printStackTrace();
                }
            }
        }
    }
    context.setGraphics(g);
    g_copy.dispose();
}
Also used : Graphics(java.awt.Graphics) Component(com.cburch.logisim.comp.Component)

Example 68 with Component

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

the class Circuit method IsExistingLabel.

private static boolean IsExistingLabel(String Name, AttributeSet me, Set<Component> comps, Boolean ShowDialog) {
    if (Name.isEmpty())
        return false;
    for (Component comp : comps) {
        if (!comp.getAttributeSet().equals(me) && !(comp.getFactory() instanceof Tunnel)) {
            String Label = (comp.getAttributeSet().containsAttribute(StdAttr.LABEL)) ? comp.getAttributeSet().getValue(StdAttr.LABEL) : "";
            if (Label.toUpperCase().equals(Name.toUpperCase())) {
                if (ShowDialog) {
                    String msg = com.cburch.logisim.circuit.Strings.get("UsedLabelNameError");
                    JOptionPane.showMessageDialog(null, "\"" + Name + "\" : " + msg);
                }
                return true;
            }
        }
    }
    /* we do not have to check the wires as (1) Wire is a reserved keyword, and (2) they cannot have a label */
    return false;
}
Also used : Tunnel(com.cburch.logisim.std.wiring.Tunnel) Component(com.cburch.logisim.comp.Component)

Example 69 with Component

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

the class Circuit method ClearAnnotationLevel.

// 
// Annotation module for all components that require a non-zero-length label
public void ClearAnnotationLevel() {
    Annotated = false;
    MyNetList.clear();
    for (Component comp : this.getNonWires()) {
        if (comp.getFactory() instanceof SubcircuitFactory) {
            SubcircuitFactory sub = (SubcircuitFactory) comp.getFactory();
            sub.getSubcircuit().ClearAnnotationLevel();
        }
    }
}
Also used : Component(com.cburch.logisim.comp.Component)

Example 70 with Component

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

the class CircuitChange method execute.

void execute(CircuitMutator mutator, ReplacementMap prevReplacements) {
    switch(type) {
        case CLEAR:
            mutator.clear(circuit);
            prevReplacements.reset();
            break;
        case ADD:
            prevReplacements.add(comp);
            break;
        case ADD_ALL:
            for (Component comp : comps) prevReplacements.add(comp);
            break;
        case REMOVE:
            prevReplacements.remove(comp);
            break;
        case REMOVE_ALL:
            for (Component comp : comps) prevReplacements.remove(comp);
            break;
        case REPLACE:
            prevReplacements.append((ReplacementMap) newValue);
            break;
        case SET:
            mutator.replace(circuit, prevReplacements);
            prevReplacements.reset();
            mutator.set(circuit, comp, attr, newValue);
            break;
        case SET_FOR_CIRCUIT:
            mutator.replace(circuit, prevReplacements);
            prevReplacements.reset();
            mutator.setForCircuit(circuit, attr, newValue);
            break;
        default:
            throw new IllegalArgumentException("unknown change type " + type);
    }
}
Also used : 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