public static Action setAttribute(AttributeSet attrs, Attribute<?> attr, Object value) { Object oldValue = attrs.getValue(attr); if (!oldValue.equals(value)) { return new SetAction(attrs, attr, value); } else { return null; } }
@Override public Bounds getOffsetBounds(AttributeSet attrs) { Object value = attrs.getValue(ATTR_SIZE); if (value == SIZE_NARROW) { Direction facing = attrs.getValue(StdAttr.FACING); if (facing == Direction.SOUTH) return Bounds.create(-9, -20, 18, 20); if (facing == Direction.NORTH) return Bounds.create(-9, 0, 18, 20); if (facing == Direction.WEST) return Bounds.create(0, -9, 20, 18); return Bounds.create(-20, -9, 20, 18); } else { Direction facing = attrs.getValue(StdAttr.FACING); if (facing == Direction.SOUTH) return Bounds.create(-9, -30, 18, 30); if (facing == Direction.NORTH) return Bounds.create(-9, 0, 18, 30); if (facing == Direction.WEST) return Bounds.create(0, -9, 30, 18); return Bounds.create(-30, -9, 30, 18); } }
@Override public boolean contains(Location loc, AttributeSet attrs) { if (super.contains(loc, attrs)) { Direction facing = attrs.getValue(StdAttr.FACING); Location center = Location.create(0, 0).translate(facing, -20); return center.manhattanDistanceTo(loc) < 24; } else { return false; } }
public EndData toEnd(Location loc, AttributeSet attrs) { Location pt = loc.translate(dx, dy); if (widthFixed != null) { return new EndData(pt, widthFixed, type, exclude); } else { Object val = attrs.getValue(widthAttr); if (!(val instanceof BitWidth)) { throw new IllegalArgumentException("Width attribute not set"); } return new EndData(pt, (BitWidth) val, type, exclude); } }
@Override public Bounds getOffsetBounds(AttributeSet attrs) { Direction facing = attrs.getValue(StdAttr.FACING); if (facing == Direction.EAST) { return Bounds.create(-42, -6, 42, 12); } else if (facing == Direction.WEST) { return Bounds.create(0, -6, 42, 12); } else if (facing == Direction.NORTH) { return Bounds.create(-6, 0, 12, 42); } else { return Bounds.create(-6, -42, 12, 42); } }
@Override public void propagate(InstanceState state) { GateAttributes attrs = (GateAttributes) state.getAttributeSet(); int inputCount = attrs.inputs; int negated = attrs.negated; AttributeSet opts = state.getProject().getOptions().getAttributeSet(); boolean errorIfUndefined = opts.getValue(Options.ATTR_GATE_UNDEFINED).equals(Options.GATE_UNDEFINED_ERROR); Value[] inputs = new Value[inputCount]; int numInputs = 0; boolean error = false; for (int i = 1; i <= inputCount; i++) { if (state.isPortConnected(i)) { int negatedBit = (negated >> (i - 1)) & 1; if (negatedBit == 1) { inputs[numInputs] = state.getPort(i).not(); } else { inputs[numInputs] = state.getPort(i); } numInputs++; } else { if (errorIfUndefined) { error = true; } } } Value out = null; if (numInputs == 0 || error) { out = Value.createError(attrs.width); } else { out = computeOutput(inputs, numInputs, state); out = pullOutput(out, attrs.out); } state.setPort(0, out, GateAttributes.DELAY); }
@Override public Bounds getOffsetBounds(AttributeSet attrs) { return Bounds.create(0, -8, 14, 16) .rotate(Direction.EAST, attrs.getValue(StdAttr.FACING), 0, 0); }
@Override public Bounds getOffsetBounds(AttributeSet attrs) { Direction facing = attrs.getValue(StdAttr.FACING); return Bounds.create(0, -20, 40, 40).rotate(Direction.WEST, facing, 0, 0); }
private static Value getPullValue(AttributeSet attrs) { AttributeOption opt = attrs.getValue(ATTR_PULL_TYPE); return (Value) opt.getValue(); }
public <E> E getAttributeValue(Attribute<E> attr) { InstanceComponent c = comp; AttributeSet as = c == null ? attrs : c.getAttributeSet(); return as.getValue(attr); }
private String getType(AttributeSet attrs) { AttributeOption topt = attrs.getValue(ATTR_TYPE); return (String) topt.getValue(); }
@Override public void doIt(Project proj) { oldval = attrs.getValue(attr); attrs.setValue(attr, newval); }