Search in sources :

Example 56 with BitWidth

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);
}
Also used : Instance(com.cburch.logisim.instance.Instance) Port(com.cburch.logisim.instance.Port) Direction(com.cburch.logisim.data.Direction) BitWidth(com.cburch.logisim.data.BitWidth) HashMap(java.util.HashMap) Map(java.util.Map) Location(com.cburch.logisim.data.Location)

Example 57 with BitWidth

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;
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) Location(com.cburch.logisim.data.Location)

Example 58 with BitWidth

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);
    }
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) EndData(com.cburch.logisim.comp.EndData)

Example 59 with BitWidth

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();
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth)

Example 60 with BitWidth

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();
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth)

Aggregations

BitWidth (com.cburch.logisim.data.BitWidth)106 Value (com.cburch.logisim.data.Value)30 Bounds (com.cburch.logisim.data.Bounds)21 Direction (com.cburch.logisim.data.Direction)20 Location (com.cburch.logisim.data.Location)16 Graphics (java.awt.Graphics)15 Port (com.cburch.logisim.instance.Port)12 EndData (com.cburch.logisim.comp.EndData)3 AttributeSet (com.cburch.logisim.data.AttributeSet)3 Font (java.awt.Font)3 FontMetrics (java.awt.FontMetrics)3 AttributeOption (com.cburch.logisim.data.AttributeOption)2 Graphics2D (java.awt.Graphics2D)2 ArrayList (java.util.ArrayList)2 TreeMap (java.util.TreeMap)2 WidthIncompatibilityData (com.cburch.logisim.circuit.WidthIncompatibilityData)1 Attribute (com.cburch.logisim.data.Attribute)1 Instance (com.cburch.logisim.instance.Instance)1 InstanceState (com.cburch.logisim.instance.InstanceState)1 Dimension (java.awt.Dimension)1