Search in sources :

Example 21 with AttributeSet

use of com.cburch.logisim.data.AttributeSet in project logisim-evolution by reds-heig.

the class AbstractGate method paintRectangular.

protected void paintRectangular(InstancePainter painter, int width, int height) {
    int don = negateOutput ? 10 : 0;
    AttributeSet attrs = painter.getAttributeSet();
    painter.drawRectangle(-width, -height / 2, width - don, height, getRectangularLabel(attrs));
    if (negateOutput) {
        painter.drawDongle(-5, 0);
    }
}
Also used : AttributeSet(com.cburch.logisim.data.AttributeSet)

Example 22 with AttributeSet

use of com.cburch.logisim.data.AttributeSet in project logisim-evolution by reds-heig.

the class AbstractGateHDLGenerator method GetParameterMap.

@Override
public SortedMap<String, Integer> GetParameterMap(Netlist Nets, NetlistComponent ComponentInfo, FPGAReport Reporter) {
    SortedMap<String, Integer> ParameterMap = new TreeMap<String, Integer>();
    boolean is_bus = is_bus(ComponentInfo.GetComponent().getAttributeSet());
    AttributeSet Myattrs = ComponentInfo.GetComponent().getAttributeSet();
    int NrOfInputs = Myattrs.containsAttribute(GateAttributes.ATTR_INPUTS) ? Myattrs.getValue(GateAttributes.ATTR_INPUTS) : 1;
    int bubleMask, mask;
    if (is_bus) {
        ParameterMap.put(BitWidthString, Myattrs.getValue(StdAttr.WIDTH).getWidth());
    }
    if (NrOfInputs > 1) {
        bubleMask = 0;
        mask = 1;
        for (int i = 0; i < NrOfInputs; i++) {
            boolean input_is_inverted = ComponentInfo.GetComponent().getAttributeSet().getValue(new NegateAttribute(i, null));
            if (input_is_inverted)
                bubleMask |= mask;
            mask <<= 1;
        }
        ParameterMap.put(BubblesString, bubleMask);
    }
    return ParameterMap;
}
Also used : AttributeSet(com.cburch.logisim.data.AttributeSet) TreeMap(java.util.TreeMap)

Example 23 with AttributeSet

use of com.cburch.logisim.data.AttributeSet in project logisim-evolution by reds-heig.

the class CircuitBuilder method placeComponents.

// 
// placeComponents
// 
/**
 * @param circuit
 *            the circuit where to place the components.
 * @param layout
 *            the layout specifying the gates to place there.
 * @param x
 *            the left edge of where the layout should be placed.
 * @param y
 *            the top edge of where the layout should be placed.
 * @param inputData
 *            information about how to reach inputs.
 * @param output
 *            a point to which the output should be connected.
 */
private static void placeComponents(CircuitMutation result, Layout layout, int x, int y, InputData inputData, Location output) {
    if (layout.inputName != null) {
        int inputX = inputData.getSpineX(layout.inputName);
        Location input = Location.create(inputX, output.getY());
        inputData.registerConnection(layout.inputName, input);
        result.add(Wire.create(input, output));
        return;
    }
    Location compOutput = Location.create(x + layout.width, output.getY());
    Component parent = layout.factory.createComponent(compOutput, layout.attrs);
    result.add(parent);
    if (!compOutput.equals(output)) {
        result.add(Wire.create(compOutput, output));
    }
    // handle a NOT gate pattern implemented with NAND as a special case
    if (layout.factory == NandGate.FACTORY && layout.subLayouts.length == 1 && layout.subLayouts[0].inputName == null) {
        Layout sub = layout.subLayouts[0];
        Location input0 = parent.getEnd(1).getLocation();
        Location input1 = parent.getEnd(2).getLocation();
        int midX = input0.getX() - 20;
        Location subOutput = Location.create(midX, output.getY());
        Location midInput0 = Location.create(midX, input0.getY());
        Location midInput1 = Location.create(midX, input1.getY());
        result.add(Wire.create(subOutput, midInput0));
        result.add(Wire.create(midInput0, input0));
        result.add(Wire.create(subOutput, midInput1));
        result.add(Wire.create(midInput1, input1));
        int subX = x + layout.subX - sub.width;
        placeComponents(result, sub, subX, y + sub.y, inputData, subOutput);
        return;
    }
    if (layout.subLayouts.length == parent.getEnds().size() - 2) {
        int index = layout.subLayouts.length / 2 + 1;
        Object factory = parent.getFactory();
        if (factory instanceof AbstractGate) {
            Value val = ((AbstractGate) factory).getIdentity();
            Integer valInt = Integer.valueOf(val.toIntValue());
            Location loc = parent.getEnd(index).getLocation();
            AttributeSet attrs = Constant.FACTORY.createAttributeSet();
            attrs.setValue(Constant.ATTR_VALUE, valInt);
            result.add(Constant.FACTORY.createComponent(loc, attrs));
        }
    }
    for (int i = 0; i < layout.subLayouts.length; i++) {
        Layout sub = layout.subLayouts[i];
        int inputIndex = i + 1;
        Location subDest = parent.getEnd(inputIndex).getLocation();
        int subOutputY = y + sub.y + sub.outputY;
        if (sub.inputName != null) {
            int destY = subDest.getY();
            if (i == 0 && destY < subOutputY || i == layout.subLayouts.length - 1 && destY > subOutputY) {
                subOutputY = destY;
            }
        }
        Location subOutput;
        int numSubs = layout.subLayouts.length;
        if (subOutputY == subDest.getY()) {
            subOutput = subDest;
        } else {
            int back;
            if (i < numSubs / 2) {
                if (subOutputY < subDest.getY()) {
                    // bending upward
                    back = i;
                } else {
                    back = ((numSubs - 1) / 2) - i;
                }
            } else {
                if (subOutputY > subDest.getY()) {
                    // bending downward
                    back = numSubs - 1 - i;
                } else {
                    back = i - (numSubs / 2);
                }
            }
            int subOutputX = subDest.getX() - 20 - 10 * back;
            subOutput = Location.create(subOutputX, subOutputY);
            Location mid = Location.create(subOutputX, subDest.getY());
            result.add(Wire.create(subOutput, mid));
            result.add(Wire.create(mid, subDest));
        }
        int subX = x + layout.subX - sub.width;
        int subY = y + sub.y;
        placeComponents(result, sub, subX, subY, inputData, subOutput);
    }
}
Also used : AttributeSet(com.cburch.logisim.data.AttributeSet) Value(com.cburch.logisim.data.Value) Component(com.cburch.logisim.comp.Component) Location(com.cburch.logisim.data.Location)

Example 24 with AttributeSet

use of com.cburch.logisim.data.AttributeSet in project logisim-evolution by reds-heig.

the class ControlledBuffer method propagate.

@Override
public void propagate(InstanceState state) {
    Value control = state.getPortValue(2);
    BitWidth width = state.getAttributeValue(StdAttr.WIDTH);
    if (control == Value.TRUE) {
        Value in = state.getPortValue(1);
        state.setPort(0, isInverter ? in.not() : in, GateAttributes.DELAY);
    } else if (control == Value.ERROR || control == Value.UNKNOWN) {
        state.setPort(0, Value.createError(width), GateAttributes.DELAY);
    } else {
        Value out;
        if (control == Value.UNKNOWN || control == Value.NIL) {
            AttributeSet opts = state.getProject().getOptions().getAttributeSet();
            if (opts.getValue(Options.ATTR_GATE_UNDEFINED).equals(Options.GATE_UNDEFINED_ERROR)) {
                out = Value.createError(width);
            } else {
                out = Value.createUnknown(width);
            }
        } else {
            out = Value.createUnknown(width);
        }
        state.setPort(0, out, GateAttributes.DELAY);
    }
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) AttributeSet(com.cburch.logisim.data.AttributeSet) Value(com.cburch.logisim.data.Value)

Example 25 with AttributeSet

use of com.cburch.logisim.data.AttributeSet in project logisim-evolution by reds-heig.

the class AbstractFlipFlopHDLGeneratorFactory method GetParameterMap.

@Override
public SortedMap<String, Integer> GetParameterMap(Netlist Nets, NetlistComponent ComponentInfo, FPGAReport Reporter) {
    SortedMap<String, Integer> ParameterMap = new TreeMap<String, Integer>();
    int ActivityLevel = 1;
    Boolean GatedClock = false;
    Boolean ActiveLow = false;
    AttributeSet attrs = ComponentInfo.GetComponent().getAttributeSet();
    String ClockNetName = GetClockNetName(ComponentInfo, ComponentInfo.NrOfEnds() - 5, Nets);
    if (ClockNetName.isEmpty()) {
        GatedClock = true;
    }
    if (attrs.containsAttribute(StdAttr.EDGE_TRIGGER)) {
        if (attrs.getValue(StdAttr.EDGE_TRIGGER) == StdAttr.TRIG_FALLING)
            ActiveLow = true;
    } else {
        if (attrs.containsAttribute(StdAttr.TRIGGER)) {
            if (attrs.getValue(StdAttr.TRIGGER) == StdAttr.TRIG_FALLING || attrs.getValue(StdAttr.TRIGGER) == StdAttr.TRIG_LOW)
                ActiveLow = true;
        }
    }
    if (GatedClock && ActiveLow) {
        ActivityLevel = 0;
    }
    ParameterMap.put(ActivityLevelStr, ActivityLevel);
    return ParameterMap;
}
Also used : AttributeSet(com.cburch.logisim.data.AttributeSet) TreeMap(java.util.TreeMap)

Aggregations

AttributeSet (com.cburch.logisim.data.AttributeSet)65 ComponentFactory (com.cburch.logisim.comp.ComponentFactory)16 Component (com.cburch.logisim.comp.Component)13 TreeMap (java.util.TreeMap)13 Attribute (com.cburch.logisim.data.Attribute)12 Location (com.cburch.logisim.data.Location)9 HashMap (java.util.HashMap)7 Value (com.cburch.logisim.data.Value)6 Circuit (com.cburch.logisim.circuit.Circuit)5 Direction (com.cburch.logisim.data.Direction)4 Graphics (java.awt.Graphics)4 Map (java.util.Map)4 CircuitMutation (com.cburch.logisim.circuit.CircuitMutation)3 Wire (com.cburch.logisim.circuit.Wire)3 AbstractAttributeSet (com.cburch.logisim.data.AbstractAttributeSet)3 BitWidth (com.cburch.logisim.data.BitWidth)3 Bounds (com.cburch.logisim.data.Bounds)3 ToolAttributeAction (com.cburch.logisim.gui.main.ToolAttributeAction)3 Action (com.cburch.logisim.proj.Action)3 Project (com.cburch.logisim.proj.Project)3