use of com.cburch.logisim.data.BitWidth in project logisim-evolution by reds-heig.
the class SubcircuitFactory method computePorts.
void computePorts(Instance instance) {
Direction facing = instance.getAttributeValue(StdAttr.FACING);
Map<Location, Instance> portLocs = source.getAppearance().getPortOffsets(facing);
Port[] ports = new Port[portLocs.size()];
Instance[] pins = new Instance[portLocs.size()];
int i = -1;
for (Map.Entry<Location, Instance> portLoc : portLocs.entrySet()) {
i++;
Location loc = portLoc.getKey();
Instance pin = portLoc.getValue();
String type = Pin.FACTORY.isInputPin(pin) ? Port.INPUT : Port.OUTPUT;
BitWidth width = pin.getAttributeValue(StdAttr.WIDTH);
ports[i] = new Port(loc.getX(), loc.getY(), type, width);
pins[i] = pin;
String label = pin.getAttributeValue(StdAttr.LABEL);
if (label != null && label.length() > 0) {
ports[i].setToolTip(StringUtil.constantGetter(label));
}
}
CircuitAttributes attrs = (CircuitAttributes) instance.getAttributeSet();
attrs.setPinInstances(pins);
instance.setPorts(ports);
instance.recomputeBounds();
// since this affects the circuit's bounds
configureLabel(instance);
}
use of com.cburch.logisim.data.BitWidth in project logisim-evolution by reds-heig.
the class WidthIncompatibilityData method equals.
@Override
public boolean equals(Object other) {
if (!(other instanceof WidthIncompatibilityData))
return false;
if (this == other)
return true;
WidthIncompatibilityData o = (WidthIncompatibilityData) other;
if (this.size() != o.size())
return false;
for (int i = 0; i < this.size(); i++) {
Location p = this.getPoint(i);
BitWidth w = this.getBitWidth(i);
boolean matched = false;
for (int j = 0; j < o.size(); j++) {
Location q = this.getPoint(j);
BitWidth x = this.getBitWidth(j);
if (p.equals(q) && w.equals(x)) {
matched = true;
break;
}
}
if (!matched)
return false;
}
return true;
}
use of com.cburch.logisim.data.BitWidth in project logisim-evolution by reds-heig.
the class CircuitPoints method computeIncompatibilityData.
private void computeIncompatibilityData(Location loc, LocationData locData) {
WidthIncompatibilityData error = null;
if (locData != null) {
BitWidth width = BitWidth.UNKNOWN;
for (EndData endData : locData.ends) {
if (endData != null) {
BitWidth endWidth = endData.getWidth();
if (width == BitWidth.UNKNOWN) {
width = endWidth;
} else if (width != endWidth && endWidth != BitWidth.UNKNOWN) {
if (error == null) {
error = new WidthIncompatibilityData();
error.add(loc, width);
}
error.add(loc, endWidth);
}
}
}
locData.width = width;
}
if (error == null) {
incompatibilityData.remove(loc);
} else {
incompatibilityData.put(loc, error);
}
}
use of com.cburch.logisim.data.BitWidth in project logisim-evolution by reds-heig.
the class AbstractGate method getHDLName.
@Override
public String getHDLName(AttributeSet attrs) {
GateAttributes myattrs = (GateAttributes) attrs;
StringBuffer CompleteName = new StringBuffer();
CompleteName.append(CorrectLabel.getCorrectLabel(this.getName()).toUpperCase());
BitWidth width = myattrs.getValue(StdAttr.WIDTH);
if (width.getWidth() > 1)
CompleteName.append("_BUS");
Integer inputCount = myattrs.getValue(GateAttributes.ATTR_INPUTS);
if (inputCount > 2) {
CompleteName.append("_" + inputCount.toString() + "_INPUTS");
}
if (myattrs.containsAttribute(GateAttributes.ATTR_XOR)) {
if (myattrs.getValue(GateAttributes.ATTR_XOR).equals(GateAttributes.XOR_ONE)) {
CompleteName.append("_ONEHOT");
}
}
return CompleteName.toString();
}
use of com.cburch.logisim.data.BitWidth in project logisim-evolution by reds-heig.
the class Buffer method getHDLName.
@Override
public String getHDLName(AttributeSet attrs) {
StringBuffer CompleteName = new StringBuffer();
CompleteName.append(CorrectLabel.getCorrectLabel(this.getName()).toUpperCase());
CompleteName.append("_COMPONENT");
BitWidth width = attrs.getValue(StdAttr.WIDTH);
if (width.getWidth() > 1)
CompleteName.append("_BUS");
return CompleteName.toString();
}
Aggregations