Search in sources :

Example 6 with EndData

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

Example 7 with EndData

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

Example 8 with EndData

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

Example 9 with EndData

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

Example 10 with EndData

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

Aggregations

EndData (com.cburch.logisim.comp.EndData)20 Component (com.cburch.logisim.comp.Component)8 Location (com.cburch.logisim.data.Location)7 ArrayList (java.util.ArrayList)7 Splitter (com.cburch.logisim.circuit.Splitter)6 InstanceComponent (com.cburch.logisim.instance.InstanceComponent)5 BitWidth (com.cburch.logisim.data.BitWidth)3 SubcircuitFactory (com.cburch.logisim.circuit.SubcircuitFactory)2 Wire (com.cburch.logisim.circuit.Wire)2 Pin (com.cburch.logisim.std.wiring.Pin)2 HashSet (java.util.HashSet)2 NetlistComponent (com.bfh.logisim.designrulecheck.NetlistComponent)1 Circuit (com.cburch.logisim.circuit.Circuit)1 CircuitAttributes (com.cburch.logisim.circuit.CircuitAttributes)1 SplitterFactory (com.cburch.logisim.circuit.SplitterFactory)1 ComponentEvent (com.cburch.logisim.comp.ComponentEvent)1 Attribute (com.cburch.logisim.data.Attribute)1 Bounds (com.cburch.logisim.data.Bounds)1 Direction (com.cburch.logisim.data.Direction)1 Value (com.cburch.logisim.data.Value)1