Search in sources :

Example 1 with Instance

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;
}
Also used : EndData(com.cburch.logisim.comp.EndData) CircuitAttributes(com.cburch.logisim.circuit.CircuitAttributes) Instance(com.cburch.logisim.instance.Instance) SubcircuitFactory(com.cburch.logisim.circuit.SubcircuitFactory)

Example 2 with Instance

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();
}
Also used : CircuitState(com.cburch.logisim.circuit.CircuitState) AppearancePort(com.cburch.logisim.circuit.appear.AppearancePort) PopupFactory(javax.swing.PopupFactory) Instance(com.cburch.logisim.instance.Instance) JViewport(javax.swing.JViewport) Popup(javax.swing.Popup) ArrayList(java.util.ArrayList) Point(java.awt.Point) Dimension(java.awt.Dimension) Point(java.awt.Point)

Example 3 with Instance

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);
    }
}
Also used : Graphics(java.awt.Graphics) ComponentDrawContext(com.cburch.logisim.comp.ComponentDrawContext) Instance(com.cburch.logisim.instance.Instance) Bounds(com.cburch.logisim.data.Bounds) Circuit(com.cburch.logisim.circuit.Circuit) Dimension(java.awt.Dimension) Graphics2D(java.awt.Graphics2D)

Example 4 with Instance

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);
}
Also used : Graphics(java.awt.Graphics) Instance(com.cburch.logisim.instance.Instance) FontMetrics(java.awt.FontMetrics) Bounds(com.cburch.logisim.data.Bounds) Direction(com.cburch.logisim.data.Direction)

Example 5 with Instance

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));
    }
}
Also used : Instance(com.cburch.logisim.instance.Instance) Component(com.cburch.logisim.comp.Component) Location(com.cburch.logisim.data.Location)

Aggregations

Instance (com.cburch.logisim.instance.Instance)28 ArrayList (java.util.ArrayList)14 Map (java.util.Map)10 Direction (com.cburch.logisim.data.Direction)9 Location (com.cburch.logisim.data.Location)9 HashMap (java.util.HashMap)9 Graphics (java.awt.Graphics)5 CanvasObject (com.cburch.draw.model.CanvasObject)4 Component (com.cburch.logisim.comp.Component)4 Bounds (com.cburch.logisim.data.Bounds)4 InstanceState (com.cburch.logisim.instance.InstanceState)4 List (java.util.List)4 TreeMap (java.util.TreeMap)4 Rectangle (com.cburch.draw.shapes.Rectangle)3 Text (com.cburch.draw.shapes.Text)3 CircuitState (com.cburch.logisim.circuit.CircuitState)3 Value (com.cburch.logisim.data.Value)3 Font (java.awt.Font)3 FontMetrics (java.awt.FontMetrics)3 Graphics2D (java.awt.Graphics2D)3