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