use of com.cburch.logisim.instance.Instance in project logisim-evolution by reds-heig.
the class Netlist method ProcessSubcircuit.
private boolean ProcessSubcircuit(Component comp, FPGAReport Reporter) {
NetlistComponent Subcircuit = new NetlistComponent(comp);
SubcircuitFactory sub = (SubcircuitFactory) comp.getFactory();
Instance[] subPins = ((CircuitAttributes) comp.getAttributeSet()).getPinInstances();
Netlist subNetlist = sub.getSubcircuit().getNetList();
for (EndData ThisPin : comp.getEnds()) {
Net Connection = FindConnectedNet(ThisPin.getLocation());
int PinId = comp.getEnds().indexOf(ThisPin);
int SubPortIndex = subNetlist.GetPortInfo(subPins[PinId].getAttributeValue(StdAttr.LABEL));
if (SubPortIndex < 0) {
Reporter.AddFatalError("BUG: Unable to find pin in sub-circuit\n ==> " + this.getClass().getName().replaceAll("\\.", "/") + ":" + Thread.currentThread().getStackTrace()[2].getLineNumber() + "\n");
return false;
}
if (Connection != null) {
boolean PinIsSink = ThisPin.isInput();
Net RootNet = GetRootNet(Connection);
if (RootNet == null) {
Reporter.AddFatalError("BUG: Unable to find a root net for sub-circuit\n ==> " + this.getClass().getName().replaceAll("\\.", "/") + ":" + Thread.currentThread().getStackTrace()[2].getLineNumber() + "\n");
return false;
}
for (byte bitid = 0; bitid < ThisPin.getWidth().getWidth(); bitid++) {
Byte RootNetBitIndex = GetRootNetIndex(Connection, bitid);
if (RootNetBitIndex < 0) {
Reporter.AddFatalError("BUG: Unable to find a root-net bit-index for sub-circuit\n ==> " + this.getClass().getName().replaceAll("\\.", "/") + ":" + Thread.currentThread().getStackTrace()[2].getLineNumber() + "\n");
return false;
}
Subcircuit.getEnd(PinId).GetConnection(bitid).SetParrentNet(RootNet, RootNetBitIndex);
if (PinIsSink) {
RootNet.addSink(RootNetBitIndex, Subcircuit.getEnd(PinId).GetConnection(bitid));
} else {
RootNet.addSource(RootNetBitIndex, Subcircuit.getEnd(PinId).GetConnection(bitid));
}
/*
* Special handling for sub-circuits; we have to find out
* the connection to the corresponding net in the underlying
* net-list; At this point the underlying net-lists have
* already been generated.
*/
Subcircuit.getEnd(PinId).GetConnection(bitid).setChildsPortIndex(SubPortIndex);
}
} else {
for (byte bitid = 0; bitid < ThisPin.getWidth().getWidth(); bitid++) {
Subcircuit.getEnd(PinId).GetConnection(bitid).setChildsPortIndex(SubPortIndex);
}
}
}
MySubCircuits.add(Subcircuit);
return true;
}
use of com.cburch.logisim.instance.Instance in project logisim-evolution by reds-heig.
the class LayoutPopupManager method showPopup.
private void showPopup(Set<AppearancePort> portObjects) {
dragStart = null;
CircuitState circuitState = canvas.getCircuitState();
if (circuitState == null)
return;
ArrayList<Instance> ports = new ArrayList<Instance>(portObjects.size());
for (AppearancePort portObject : portObjects) {
ports.add(portObject.getPin());
}
hideCurrentPopup();
LayoutThumbnail layout = new LayoutThumbnail();
layout.setCircuit(circuitState, ports);
JViewport owner = canvasPane.getViewport();
Point ownerLoc = owner.getLocationOnScreen();
Dimension ownerDim = owner.getSize();
Dimension layoutDim = layout.getPreferredSize();
int x = ownerLoc.x + Math.max(0, ownerDim.width - layoutDim.width - 5);
int y = ownerLoc.y + Math.max(0, ownerDim.height - layoutDim.height - 5);
PopupFactory factory = PopupFactory.getSharedInstance();
Popup popup = factory.getPopup(canvasPane.getViewport(), layout, x, y);
popup.show();
curPopup = popup;
curPopupTime = System.currentTimeMillis();
}
use of com.cburch.logisim.instance.Instance in project logisim-evolution by reds-heig.
the class LayoutThumbnail method paintComponent.
@Override
protected void paintComponent(Graphics g) {
if (circuitState != null) {
Circuit circuit = circuitState.getCircuit();
Bounds bds = circuit.getBounds(g);
Dimension size = getSize();
double scaleX = (double) (size.width - 2 * BORDER) / bds.getWidth();
double scaleY = (double) (size.height - 2 * BORDER) / bds.getHeight();
double scale = Math.min(1.0, Math.min(scaleX, scaleY));
Graphics gCopy = g.create();
int borderX = (int) ((size.width - bds.getWidth() * scale) / 2);
int borderY = (int) ((size.height - bds.getHeight() * scale) / 2);
gCopy.translate(borderX, borderY);
if (scale != 1.0 && g instanceof Graphics2D) {
((Graphics2D) gCopy).scale(scale, scale);
}
gCopy.translate(-bds.getX(), -bds.getY());
ComponentDrawContext context = new ComponentDrawContext(this, circuit, circuitState, g, gCopy);
context.setShowState(false);
context.setShowColor(false);
circuit.draw(context, Collections.<Component>emptySet());
if (ports != null) {
gCopy.setColor(AppearancePort.COLOR);
int width = Math.max(4, (int) ((2 / scale) + 0.5));
GraphicsUtil.switchToWidth(gCopy, width);
for (Instance port : ports) {
Bounds b = port.getBounds();
int x = b.getX();
int y = b.getY();
int w = b.getWidth();
int h = b.getHeight();
if (Pin.FACTORY.isInputPin(port)) {
gCopy.drawRect(x, y, w, h);
} else {
if (b.getWidth() > 25) {
gCopy.drawRoundRect(x, y, w, h, 4, 4);
} else {
gCopy.drawOval(x, y, w, h);
}
}
}
}
gCopy.dispose();
g.setColor(Color.BLACK);
GraphicsUtil.switchToWidth(g, 2);
g.drawRect(0, 0, size.width - 2, size.height - 2);
}
}
use of com.cburch.logisim.instance.Instance in project logisim-evolution by reds-heig.
the class Tunnel method paintGhost.
//
// graphics methods
//
@Override
public void paintGhost(InstancePainter painter) {
TunnelAttributes attrs = (TunnelAttributes) painter.getAttributeSet();
Direction facing = attrs.getFacing();
String label = attrs.getLabel();
Graphics g = painter.getGraphics();
g.setFont(attrs.getFont());
FontMetrics fm = g.getFontMetrics();
Bounds bds = computeBounds(attrs, fm.stringWidth(label), fm.getAscent() + fm.getDescent(), g, label);
if (attrs.setOffsetBounds(bds)) {
Instance instance = painter.getInstance();
if (instance != null)
instance.recomputeBounds();
}
int x0 = bds.getX();
int y0 = bds.getY();
int x1 = x0 + bds.getWidth();
int y1 = y0 + bds.getHeight();
int mw = ARROW_MAX_WIDTH / 2;
int[] xp;
int[] yp;
if (facing == Direction.NORTH) {
int yb = y0 + ARROW_DEPTH;
if (x1 - x0 <= ARROW_MAX_WIDTH) {
xp = new int[] { x0, 0, x1, x1, x0 };
yp = new int[] { yb, y0, yb, y1, y1 };
} else {
xp = new int[] { x0, -mw, 0, mw, x1, x1, x0 };
yp = new int[] { yb, yb, y0, yb, yb, y1, y1 };
}
} else if (facing == Direction.SOUTH) {
int yb = y1 - ARROW_DEPTH;
if (x1 - x0 <= ARROW_MAX_WIDTH) {
xp = new int[] { x0, x1, x1, 0, x0 };
yp = new int[] { y0, y0, yb, y1, yb };
} else {
xp = new int[] { x0, x1, x1, mw, 0, -mw, x0 };
yp = new int[] { y0, y0, yb, yb, y1, yb, yb };
}
} else if (facing == Direction.EAST) {
int xb = x1 - ARROW_DEPTH;
if (y1 - y0 <= ARROW_MAX_WIDTH) {
xp = new int[] { x0, xb, x1, xb, x0 };
yp = new int[] { y0, y0, 0, y1, y1 };
} else {
xp = new int[] { x0, xb, xb, x1, xb, xb, x0 };
yp = new int[] { y0, y0, -mw, 0, mw, y1, y1 };
}
} else {
int xb = x0 + ARROW_DEPTH;
if (y1 - y0 <= ARROW_MAX_WIDTH) {
xp = new int[] { xb, x1, x1, xb, x0 };
yp = new int[] { y0, y0, y1, y1, 0 };
} else {
xp = new int[] { xb, x1, x1, xb, xb, x0, xb };
yp = new int[] { y0, y0, y1, y1, mw, 0, -mw };
}
}
GraphicsUtil.switchToWidth(g, 2);
g.drawPolygon(xp, yp, xp.length);
}
use of com.cburch.logisim.instance.Instance in project logisim-evolution by reds-heig.
the class CircuitWires method connectPullResistors.
private void connectPullResistors(BundleMap ret) {
for (Component comp : pulls) {
Location loc = comp.getEnd(0).getLocation();
WireBundle b = ret.getBundleAt(loc);
if (b == null) {
b = ret.createBundleAt(loc);
b.points.add(loc);
ret.setBundleAt(loc, b);
}
Instance instance = Instance.getInstanceFor(comp);
b.addPullValue(PullResistor.getPullValue(instance));
}
}
Aggregations