Search in sources :

Example 56 with Component

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

the class SelectionAttributes method computeAttributes.

private static LinkedHashMap<Attribute<Object>, Object> computeAttributes(Collection<Component> newSel) {
    LinkedHashMap<Attribute<Object>, Object> attrMap;
    attrMap = new LinkedHashMap<Attribute<Object>, Object>();
    Iterator<Component> sit = newSel.iterator();
    if (sit.hasNext()) {
        AttributeSet first = sit.next().getAttributeSet();
        for (Attribute<?> attr : first.getAttributes()) {
            @SuppressWarnings("unchecked") Attribute<Object> attrObj = (Attribute<Object>) attr;
            attrMap.put(attrObj, first.getValue(attr));
        }
        while (sit.hasNext()) {
            AttributeSet next = sit.next().getAttributeSet();
            Iterator<Attribute<Object>> ait = attrMap.keySet().iterator();
            while (ait.hasNext()) {
                Attribute<Object> attr = ait.next();
                if (next.containsAttribute(attr)) {
                    Object v = attrMap.get(attr);
                    if (v != null && !v.equals(next.getValue(attr))) {
                        attrMap.put(attr, null);
                    }
                } else {
                    ait.remove();
                }
            }
        }
    }
    return attrMap;
}
Also used : Attribute(com.cburch.logisim.data.Attribute) AbstractAttributeSet(com.cburch.logisim.data.AbstractAttributeSet) AttributeSet(com.cburch.logisim.data.AttributeSet) Component(com.cburch.logisim.comp.Component)

Example 57 with Component

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

the class SelectionBase method computeBounds.

private static Bounds computeBounds(Collection<Component> components) {
    if (components.isEmpty()) {
        return Bounds.EMPTY_BOUNDS;
    } else {
        Iterator<Component> it = components.iterator();
        Bounds ret = it.next().getBounds();
        while (it.hasNext()) {
            Component comp = it.next();
            Bounds bds = comp.getBounds();
            ret = ret.add(bds);
        }
        return ret;
    }
}
Also used : Bounds(com.cburch.logisim.data.Bounds) Component(com.cburch.logisim.comp.Component)

Example 58 with Component

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

the class SelectionBase method print.

// debugging methods
public void print() {
    logger.debug(" shouldSnap: {}", shouldSnap());
    boolean hasPrinted = false;
    for (Component comp : selected) {
        if (hasPrinted)
            logger.debug("       : {}  [{}]", comp, comp.hashCode());
        else
            logger.debug(" select: {}  [{}]", comp, comp.hashCode());
        hasPrinted = true;
    }
    hasPrinted = false;
    for (Component comp : lifted) {
        if (hasPrinted)
            logger.debug("       : {}  [{}]", comp, comp.hashCode());
        else
            logger.debug(" lifted: {}  [{}]", comp, comp.hashCode());
        hasPrinted = true;
    }
}
Also used : Component(com.cburch.logisim.comp.Component)

Example 59 with Component

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

the class SelectionBase method hasConflictTranslated.

private boolean hasConflictTranslated(Collection<Component> components, int dx, int dy, boolean selfConflicts) {
    Circuit circuit = proj.getCurrentCircuit();
    if (circuit == null)
        return false;
    for (Component comp : components) {
        if (!(comp instanceof Wire)) {
            for (EndData endData : comp.getEnds()) {
                if (endData != null && endData.isExclusive()) {
                    Location endLoc = endData.getLocation().translate(dx, dy);
                    Component conflict = circuit.getExclusive(endLoc);
                    if (conflict != null) {
                        if (selfConflicts || !components.contains(conflict))
                            return true;
                    }
                }
            }
            Location newLoc = comp.getLocation().translate(dx, dy);
            Bounds newBounds = comp.getBounds().translate(dx, dy);
            for (Component comp2 : circuit.getAllContaining(newLoc)) {
                Bounds bds = comp2.getBounds();
                if (bds.equals(newBounds)) {
                    if (selfConflicts || !components.contains(comp2))
                        return true;
                }
            }
        }
    }
    return false;
}
Also used : EndData(com.cburch.logisim.comp.EndData) Bounds(com.cburch.logisim.data.Bounds) Circuit(com.cburch.logisim.circuit.Circuit) Component(com.cburch.logisim.comp.Component) Wire(com.cburch.logisim.circuit.Wire) Location(com.cburch.logisim.data.Location)

Example 60 with Component

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

the class WireRepair method doMergeSet.

private void doMergeSet(ArrayList<Wire> mergeSet, ReplacementMap replacements, Set<Location> splitLocs) {
    TreeSet<Location> ends = new TreeSet<Location>();
    for (Wire w : mergeSet) {
        ends.add(w.getEnd0());
        ends.add(w.getEnd1());
    }
    Wire whole = Wire.create(ends.first(), ends.last());
    TreeSet<Location> mids = new TreeSet<Location>();
    mids.add(whole.getEnd0());
    mids.add(whole.getEnd1());
    for (Location loc : whole) {
        if (splitLocs.contains(loc)) {
            for (Component comp : circuit.getComponents(loc)) {
                if (!mergeSet.contains(comp)) {
                    mids.add(loc);
                    break;
                }
            }
        }
    }
    ArrayList<Wire> mergeResult = new ArrayList<Wire>();
    if (mids.size() == 2) {
        mergeResult.add(whole);
    } else {
        Location e0 = mids.first();
        for (Location e1 : mids) {
            mergeResult.add(Wire.create(e0, e1));
            e0 = e1;
        }
    }
    for (Wire w : mergeSet) {
        ArrayList<Component> wRepl = new ArrayList<Component>(2);
        for (Wire w2 : mergeResult) {
            if (w2.overlaps(w, false)) {
                wRepl.add(w2);
            }
        }
        replacements.put(w, wRepl);
    }
}
Also used : TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) Component(com.cburch.logisim.comp.Component) Location(com.cburch.logisim.data.Location)

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