use of com.cburch.logisim.data.AttributeSet in project logisim-evolution by reds-heig.
the class CircuitMutatorImpl method setForCircuit.
public void setForCircuit(Circuit circuit, Attribute<?> attr, Object newValue) {
@SuppressWarnings("unchecked") Attribute<Object> a = (Attribute<Object>) attr;
AttributeSet attrs = circuit.getStaticAttributes();
Object oldValue = attrs.getValue(a);
log.add(CircuitChange.setForCircuit(circuit, attr, oldValue, newValue));
attrs.setValue(a, newValue);
if (attr == CircuitAttributes.NAME_ATTR || attr == CircuitAttributes.NAMED_CIRCUIT_BOX) {
circuit.getAppearance().recomputeDefaultAppearance();
}
}
use of com.cburch.logisim.data.AttributeSet in project logisim-evolution by reds-heig.
the class AbstractGate method propagate.
@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.getPortValue(i).not();
} else {
inputs[numInputs] = state.getPortValue(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);
}
use of com.cburch.logisim.data.AttributeSet in project logisim-evolution by reds-heig.
the class AbstractGateHDLGenerator method GetPortMap.
@Override
public SortedMap<String, String> GetPortMap(Netlist Nets, NetlistComponent ComponentInfo, FPGAReport Reporter, String HDLType) {
SortedMap<String, String> PortMap = new TreeMap<String, String>();
AttributeSet attrs = ComponentInfo.GetComponent().getAttributeSet();
int NrOfInputs = attrs.containsAttribute(GateAttributes.ATTR_INPUTS) ? attrs.getValue(GateAttributes.ATTR_INPUTS) : 1;
boolean[] InputFloatingValues = new boolean[NrOfInputs];
if (NrOfInputs == 1) {
InputFloatingValues[0] = true;
} else {
for (int i = 1; i <= NrOfInputs; i++) {
boolean input_is_inverted = attrs.getValue(new NegateAttribute(i - 1, null));
InputFloatingValues[i - 1] = GetFloatingValue(input_is_inverted);
}
}
for (int i = 1; i <= NrOfInputs; i++) {
PortMap.putAll(GetNetMap("Input_" + Integer.toString(i), InputFloatingValues[i - 1], ComponentInfo, i, Reporter, HDLType, Nets));
}
PortMap.putAll(GetNetMap("Result", true, ComponentInfo, 0, Reporter, HDLType, Nets));
return PortMap;
}
use of com.cburch.logisim.data.AttributeSet in project logisim-evolution by reds-heig.
the class Buffer method repair.
//
// static methods - shared with other classes
//
static Value repair(InstanceState state, Value v) {
AttributeSet opts = state.getProject().getOptions().getAttributeSet();
Object onUndefined = opts.getValue(Options.ATTR_GATE_UNDEFINED);
boolean errorIfUndefined = onUndefined.equals(Options.GATE_UNDEFINED_ERROR);
Value repaired;
if (errorIfUndefined) {
int vw = v.getWidth();
BitWidth w = state.getAttributeValue(StdAttr.WIDTH);
int ww = w.getWidth();
if (vw == ww && v.isFullyDefined())
return v;
Value[] vs = new Value[w.getWidth()];
for (int i = 0; i < vs.length; i++) {
Value ini = i < vw ? v.get(i) : Value.ERROR;
vs[i] = ini.isFullyDefined() ? ini : Value.ERROR;
}
repaired = Value.create(vs);
} else {
repaired = v;
}
Object outType = state.getAttributeValue(GateAttributes.ATTR_OUTPUT);
return AbstractGate.pullOutput(repaired, outType);
}
use of com.cburch.logisim.data.AttributeSet in project logisim-evolution by reds-heig.
the class CircuitBuilder method placeInputs.
//
// placeInputs
//
private static void placeInputs(CircuitMutation result, InputData inputData) {
ArrayList<Location> forbiddenYs = new ArrayList<Location>();
Comparator<Location> compareYs = new CompareYs();
int curX = 40;
int curY = 30;
for (int i = 0; i < inputData.names.length; i++) {
String name = inputData.names[i];
SingleInput singleInput = inputData.inputs.get(name);
// determine point where we can intersect with spine
int spineX = singleInput.spineX;
Location spineLoc = Location.create(spineX, curY);
if (singleInput.ys.size() > 0) {
// search for a Y that won't intersect with others
// (we needn't bother if the pin doesn't connect
// with anything anyway.)
Collections.sort(forbiddenYs, compareYs);
while (Collections.binarySearch(forbiddenYs, spineLoc, compareYs) >= 0) {
curY += 10;
spineLoc = Location.create(spineX, curY);
}
singleInput.ys.add(spineLoc);
}
Location loc = Location.create(curX, curY);
// now create the pin
ComponentFactory factory = Pin.FACTORY;
AttributeSet attrs = factory.createAttributeSet();
attrs.setValue(StdAttr.FACING, Direction.EAST);
attrs.setValue(Pin.ATTR_TYPE, Boolean.FALSE);
attrs.setValue(Pin.ATTR_TRISTATE, Boolean.FALSE);
attrs.setValue(StdAttr.LABEL, name);
attrs.setValue(Pin.ATTR_LABEL_LOC, Direction.NORTH);
result.add(factory.createComponent(loc, attrs));
ArrayList<Location> spine = singleInput.ys;
if (spine.size() > 0) {
// create wire connecting pin to spine
/*
* This should no longer matter - the wires will be repaired
* anyway by the circuit's WireRepair class. if (spine.size() ==
* 2 && spine.get(0).equals(spine.get(1))) { // a freak accident
* where the input is used just once, // and it happens that the
* pin is placed where no // spine is necessary Iterator<Wire>
* it = circuit.getWires(spineLoc).iterator(); Wire existing =
* it.next(); Wire replace = Wire.create(loc,
* existing.getEnd1()); result.replace(existing, replace); }
* else {
*/
result.add(Wire.create(loc, spineLoc));
// }
// create spine
Collections.sort(spine, compareYs);
Location prev = spine.get(0);
for (int k = 1, n = spine.size(); k < n; k++) {
Location cur = spine.get(k);
if (!cur.equals(prev)) {
result.add(Wire.create(prev, cur));
prev = cur;
}
}
}
// advance y and forbid spine intersections for next pin
forbiddenYs.addAll(singleInput.ys);
curY += 50;
}
}
Aggregations