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;
}
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;
}
}
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;
}
}
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;
}
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);
}
}
Aggregations