use of com.cburch.logisim.data.AttributeSet in project logisim-evolution by reds-heig.
the class CircuitBuilder method placeOutput.
//
// placeOutput
//
private static void placeOutput(CircuitMutation result, Location loc, String name) {
ComponentFactory factory = Pin.FACTORY;
AttributeSet attrs = factory.createAttributeSet();
attrs.setValue(StdAttr.FACING, Direction.WEST);
attrs.setValue(Pin.ATTR_TYPE, Boolean.TRUE);
attrs.setValue(StdAttr.LABEL, name);
attrs.setValue(Pin.ATTR_LABEL_LOC, Direction.NORTH);
result.add(factory.createComponent(loc, attrs));
}
use of com.cburch.logisim.data.AttributeSet in project logisim-evolution by reds-heig.
the class CircuitBuilder method layoutGatesSub.
private static Layout layoutGatesSub(CircuitDetermination det) {
if (det instanceof CircuitDetermination.Input) {
CircuitDetermination.Input input = (CircuitDetermination.Input) det;
return new Layout(input.getName());
} else if (det instanceof CircuitDetermination.Value) {
CircuitDetermination.Value value = (CircuitDetermination.Value) det;
ComponentFactory factory = Constant.FACTORY;
AttributeSet attrs = factory.createAttributeSet();
attrs.setValue(Constant.ATTR_VALUE, Integer.valueOf(value.getValue()));
Bounds bds = factory.getOffsetBounds(attrs);
return new Layout(bds.getWidth(), bds.getHeight(), -bds.getY(), factory, attrs, new Layout[0], 0);
}
// We know det is a Gate. Determine sublayouts.
CircuitDetermination.Gate gate = (CircuitDetermination.Gate) det;
ComponentFactory factory = gate.getFactory();
ArrayList<CircuitDetermination> inputs = gate.getInputs();
// Handle a NOT implemented with a NAND as a special case
if (gate.isNandNot()) {
CircuitDetermination subDet = inputs.get(0);
if (!(subDet instanceof CircuitDetermination.Input)) {
Layout[] sub = new Layout[1];
sub[0] = layoutGatesSub(subDet);
sub[0].y = 0;
AttributeSet attrs = factory.createAttributeSet();
attrs.setValue(GateAttributes.ATTR_SIZE, GateAttributes.SIZE_NARROW);
attrs.setValue(GateAttributes.ATTR_INPUTS, Integer.valueOf(2));
// determine layout's width
Bounds bds = factory.getOffsetBounds(attrs);
int betweenWidth = 40;
if (sub[0].width == 0)
betweenWidth = 0;
int width = sub[0].width + betweenWidth + bds.getWidth();
// determine outputY and layout's height.
int outputY = sub[0].y + sub[0].outputY;
int height = sub[0].height;
int minOutputY = roundUp(-bds.getY());
if (minOutputY > outputY) {
// we have to shift everything down because otherwise
// the component will peek over the rectangle's top.
int dy = minOutputY - outputY;
sub[0].y += dy;
height += dy;
outputY += dy;
}
int minHeight = outputY + bds.getY() + bds.getHeight();
if (minHeight > height)
height = minHeight;
// ok; create and return the layout.
return new Layout(width, height, outputY, factory, attrs, sub, sub[0].width);
}
}
Layout[] sub = new Layout[inputs.size()];
// maximum width of sublayouts
int subWidth = 0;
// total height of sublayouts
int subHeight = 0;
for (int i = 0; i < sub.length; i++) {
sub[i] = layoutGatesSub(inputs.get(i));
if (sub.length % 2 == 0 && i == (sub.length + 1) / 2 && sub[i - 1].height + sub[i].height == 0) {
// if there are an even number of inputs, then there is a
// 20-tall gap between the middle two inputs. Ensure the two
// middle inputs are at least 20 pixels apart.
subHeight += 10;
}
sub[i].y = subHeight;
subWidth = Math.max(subWidth, sub[i].width);
subHeight += sub[i].height + 10;
}
subHeight -= 10;
AttributeSet attrs = factory.createAttributeSet();
if (factory == NotGate.FACTORY) {
attrs.setValue(NotGate.ATTR_SIZE, NotGate.SIZE_NARROW);
} else {
attrs.setValue(GateAttributes.ATTR_SIZE, GateAttributes.SIZE_NARROW);
int ins = sub.length;
attrs.setValue(GateAttributes.ATTR_INPUTS, Integer.valueOf(ins));
}
// determine layout's width
Bounds bds = factory.getOffsetBounds(attrs);
int betweenWidth = 40 + 10 * (sub.length / 2 - 1);
if (sub.length == 1)
betweenWidth = 20;
if (subWidth == 0)
betweenWidth = 0;
int width = subWidth + betweenWidth + bds.getWidth();
// determine outputY and layout's height.
int outputY;
if (sub.length % 2 == 1) {
// odd number - match the middle input
int i = (sub.length - 1) / 2;
outputY = sub[i].y + sub[i].outputY;
} else {
// even number - halfway between middle two inputs
int i0 = (sub.length / 2) - 1;
int i1 = (sub.length / 2);
int o0 = sub[i0].y + sub[i0].outputY;
int o1 = sub[i1].y + sub[i1].outputY;
outputY = roundDown((o0 + o1) / 2);
}
int height = subHeight;
int minOutputY = roundUp(-bds.getY());
if (minOutputY > outputY) {
// we have to shift everything down because otherwise
// the component will peek over the rectangle's top.
int dy = minOutputY - outputY;
for (int i = 0; i < sub.length; i++) sub[i].y += dy;
height += dy;
outputY += dy;
}
int minHeight = outputY + bds.getY() + bds.getHeight();
if (minHeight > height)
height = minHeight;
// ok; create and return the layout.
return new Layout(width, height, outputY, factory, attrs, sub, subWidth);
}
use of com.cburch.logisim.data.AttributeSet in project logisim-evolution by reds-heig.
the class VhdlHDLGeneratorFactory 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();
VhdlContent content = attrs.getValue(VhdlEntity.CONTENT_ATTR);
Port[] inputs = content.getInputs();
Port[] outputs = content.getOutputs();
for (int i = 0; i < inputs.length; i++) PortMap.putAll(GetNetMap(inputs[i].getToolTip(), true, ComponentInfo, i, Reporter, HDLType, Nets));
for (int i = 0; i < outputs.length; i++) PortMap.putAll(GetNetMap(outputs[i].getToolTip(), true, ComponentInfo, i + inputs.length, Reporter, HDLType, Nets));
return PortMap;
}
use of com.cburch.logisim.data.AttributeSet in project logisim-evolution by reds-heig.
the class ComparatorHDLGeneratorFactory method GetParameterMap.
@Override
public SortedMap<String, Integer> GetParameterMap(Netlist Nets, NetlistComponent ComponentInfo, FPGAReport Reporter) {
SortedMap<String, Integer> ParameterMap = new TreeMap<String, Integer>();
int nrOfBits = ComponentInfo.GetComponent().getEnd(0).getWidth().getWidth();
int IsSigned = 0;
AttributeSet attrs = ComponentInfo.GetComponent().getAttributeSet();
if (attrs.containsAttribute(Comparator.MODE_ATTRIBUTE)) {
if (attrs.getValue(Comparator.MODE_ATTRIBUTE).equals(Comparator.SIGNED_OPTION))
IsSigned = 1;
}
if (nrOfBits > 1) {
ParameterMap.put(NrOfBitsStr, nrOfBits);
}
ParameterMap.put(TwosComplementStr, IsSigned);
return ParameterMap;
}
use of com.cburch.logisim.data.AttributeSet in project logisim-evolution by reds-heig.
the class Frame method viewAttributes.
private void viewAttributes(Tool oldTool, Tool newTool, boolean force) {
AttributeSet newAttrs;
if (newTool == null) {
newAttrs = null;
if (!force) {
return;
}
} else {
newAttrs = newTool.getAttributeSet(layoutCanvas);
}
if (newAttrs == null) {
AttrTableModel oldModel = attrTable.getAttrTableModel();
boolean same = oldModel instanceof AttrTableToolModel && ((AttrTableToolModel) oldModel).getTool() == oldTool;
if (!force && !same && !(oldModel instanceof AttrTableCircuitModel)) {
return;
}
}
if (newAttrs == null) {
Circuit circ = proj.getCurrentCircuit();
if (circ != null) {
setAttrTableModel(new AttrTableCircuitModel(proj, circ));
} else if (force) {
setAttrTableModel(null);
}
} else if (newAttrs instanceof SelectionAttributes) {
setAttrTableModel(attrTableSelectionModel);
} else {
setAttrTableModel(new AttrTableToolModel(proj, newTool));
}
}
Aggregations