use of com.cburch.logisim.comp.EndData in project logisim-evolution by reds-heig.
the class Splitter method configureComponent.
private synchronized void configureComponent() {
SplitterAttributes attrs = (SplitterAttributes) getAttributeSet();
SplitterParameters parms = attrs.getParameters();
int fanout = attrs.fanout;
byte[] bit_end = attrs.bit_end;
// compute width of each end
bit_thread = new byte[bit_end.length];
byte[] end_width = new byte[fanout + 1];
end_width[0] = (byte) bit_end.length;
for (int i = 0; i < bit_end.length; i++) {
byte thr = bit_end[i];
if (thr > 0) {
bit_thread[i] = end_width[thr];
end_width[thr]++;
} else {
bit_thread[i] = -1;
}
}
// compute end positions
Location origin = getLocation();
int x = origin.getX() + parms.getEnd0X();
int y = origin.getY() + parms.getEnd0Y();
int dx = parms.getEndToEndDeltaX();
int dy = parms.getEndToEndDeltaY();
EndData[] ends = new EndData[fanout + 1];
ends[0] = new EndData(origin, BitWidth.create(bit_end.length), EndData.INPUT_OUTPUT);
for (int i = 0; i < fanout; i++) {
ends[i + 1] = new EndData(Location.create(x, y), BitWidth.create(end_width[i + 1]), EndData.INPUT_OUTPUT);
x += dx;
y += dy;
}
wire_data = new CircuitWires.SplitterData(fanout);
setEnds(ends);
recomputeBounds();
fireComponentInvalidated(new ComponentEvent(this));
}
use of com.cburch.logisim.comp.EndData in project logisim-evolution by reds-heig.
the class InstanceStateImpl method setPort.
public void setPort(int portIndex, Value value, int delay) {
EndData end = component.getEnd(portIndex);
circuitState.setValue(end.getLocation(), value, component, delay);
}
use of com.cburch.logisim.comp.EndData in project logisim-evolution by reds-heig.
the class InstanceComponent method getToolTip.
public String getToolTip(ComponentUserEvent e) {
int x = e.getX();
int y = e.getY();
int i = -1;
for (EndData end : endArray) {
i++;
if (end.getLocation().manhattanDistanceTo(x, y) < 10) {
Port p = portList.get(i);
return p.getToolTip();
}
}
StringGetter defaultTip = factory.getDefaultToolTip();
return defaultTip == null ? null : defaultTip.toString();
}
use of com.cburch.logisim.comp.EndData in project logisim-evolution by reds-heig.
the class InstanceComponent method computeEnds.
private void computeEnds() {
List<Port> ports = portList;
EndData[] esOld = endArray;
int esOldLength = esOld == null ? 0 : esOld.length;
EndData[] es = esOld;
if (es == null || es.length != ports.size()) {
es = new EndData[ports.size()];
if (esOldLength > 0) {
int toCopy = Math.min(esOldLength, es.length);
System.arraycopy(esOld, 0, es, 0, toCopy);
}
}
HashSet<Attribute<BitWidth>> wattrs = null;
boolean toolTipFound = false;
ArrayList<EndData> endsChangedOld = null;
ArrayList<EndData> endsChangedNew = null;
Iterator<Port> pit = ports.iterator();
for (int i = 0; pit.hasNext() || i < esOldLength; i++) {
Port p = pit.hasNext() ? pit.next() : null;
EndData oldEnd = i < esOldLength ? esOld[i] : null;
EndData newEnd = p == null ? null : p.toEnd(loc, attrs);
if (oldEnd == null || !oldEnd.equals(newEnd)) {
if (newEnd != null)
es[i] = newEnd;
if (endsChangedOld == null) {
endsChangedOld = new ArrayList<EndData>();
endsChangedNew = new ArrayList<EndData>();
}
endsChangedOld.add(oldEnd);
endsChangedNew.add(newEnd);
}
if (p != null) {
Attribute<BitWidth> attr = p.getWidthAttribute();
if (attr != null) {
if (wattrs == null) {
wattrs = new HashSet<Attribute<BitWidth>>();
}
wattrs.add(attr);
}
if (p.getToolTip() != null)
toolTipFound = true;
}
}
if (!attrListenRequested) {
HashSet<Attribute<BitWidth>> oldWattrs = widthAttrs;
if (wattrs == null && oldWattrs != null) {
getAttributeSet().removeAttributeListener(this);
} else if (wattrs != null && oldWattrs == null) {
getAttributeSet().addAttributeListener(this);
}
}
if (es != esOld) {
endArray = es;
endList = new UnmodifiableList<EndData>(es);
}
widthAttrs = wattrs;
hasToolTips = toolTipFound;
if (endsChangedOld != null) {
fireEndsChanged(endsChangedOld, endsChangedNew);
}
}
use of com.cburch.logisim.comp.EndData 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;
}
Aggregations