Search in sources :

Example 21 with CircuitState

use of com.cburch.logisim.circuit.CircuitState in project logisim-evolution by reds-heig.

the class ComponentDrawContext method drawPin.

public void drawPin(Component comp, int i, String label, Direction dir) {
    Color curColor = g.getColor();
    if (i < 0 || i >= comp.getEnds().size())
        return;
    EndData e = comp.getEnd(i);
    Location pt = e.getLocation();
    int x = pt.getX();
    int y = pt.getY();
    if (getShowState()) {
        CircuitState state = getCircuitState();
        g.setColor(state.getValue(pt).getColor());
    } else {
        g.setColor(Color.BLACK);
    }
    g.fillOval(x - PIN_OFFS, y - PIN_OFFS, PIN_RAD, PIN_RAD);
    g.setColor(curColor);
    if (dir == Direction.EAST) {
        GraphicsUtil.drawText(g, label, x + 3, y, GraphicsUtil.H_LEFT, GraphicsUtil.V_CENTER);
    } else if (dir == Direction.WEST) {
        GraphicsUtil.drawText(g, label, x - 3, y, GraphicsUtil.H_RIGHT, GraphicsUtil.V_CENTER);
    } else if (dir == Direction.SOUTH) {
        GraphicsUtil.drawText(g, label, x, y - 3, GraphicsUtil.H_CENTER, GraphicsUtil.V_BASELINE);
    } else if (dir == Direction.NORTH) {
        GraphicsUtil.drawText(g, label, x, y + 3, GraphicsUtil.H_CENTER, GraphicsUtil.V_TOP);
    }
}
Also used : CircuitState(com.cburch.logisim.circuit.CircuitState) Color(java.awt.Color) Location(com.cburch.logisim.data.Location)

Example 22 with CircuitState

use of com.cburch.logisim.circuit.CircuitState in project logisim-evolution by reds-heig.

the class Project method setCurrentCircuit.

public void setCurrentCircuit(Circuit circuit) {
    CircuitState circState = stateMap.get(circuit);
    if (circState == null) {
        circState = new CircuitState(this, circuit);
    }
    setCircuitState(circState);
}
Also used : CircuitState(com.cburch.logisim.circuit.CircuitState)

Example 23 with CircuitState

use of com.cburch.logisim.circuit.CircuitState in project logisim-evolution by reds-heig.

the class CanvasPainter method drawWithUserState.

private void drawWithUserState(Graphics base, Graphics g, Project proj) {
    Circuit circ = proj.getCurrentCircuit();
    Selection sel = proj.getSelection();
    Set<Component> hidden;
    Tool dragTool = canvas.getDragTool();
    if (dragTool == null) {
        hidden = NO_COMPONENTS;
    } else {
        hidden = dragTool.getHiddenComponents(canvas);
        if (hidden == null)
            hidden = NO_COMPONENTS;
    }
    // draw halo around component whose attributes we are viewing
    boolean showHalo = AppPreferences.ATTRIBUTE_HALO.getBoolean();
    if (showHalo && haloedComponent != null && haloedCircuit == circ && !hidden.contains(haloedComponent)) {
        GraphicsUtil.switchToWidth(g, 3);
        g.setColor(Canvas.HALO_COLOR);
        Bounds bds = haloedComponent.getBounds(g).expand(5);
        int w = bds.getWidth();
        int h = bds.getHeight();
        double a = Canvas.SQRT_2 * w;
        double b = Canvas.SQRT_2 * h;
        g.drawOval((int) Math.round(bds.getX() + w / 2.0 - a / 2.0), (int) Math.round(bds.getY() + h / 2.0 - b / 2.0), (int) Math.round(a), (int) Math.round(b));
        GraphicsUtil.switchToWidth(g, 1);
        g.setColor(Color.BLACK);
    }
    // draw circuit and selection
    CircuitState circState = proj.getCircuitState();
    boolean printerView = AppPreferences.PRINTER_VIEW.getBoolean();
    ComponentDrawContext context = new ComponentDrawContext(canvas, circ, circState, base, g, printerView);
    context.setHighlightedWires(highlightedWires);
    circ.draw(context, hidden);
    sel.draw(context, hidden);
    // draw tool
    Tool tool = dragTool != null ? dragTool : proj.getTool();
    if (tool != null && !canvas.isPopupMenuUp()) {
        Graphics gCopy = g.create();
        context.setGraphics(gCopy);
        tool.draw(canvas, context);
        gCopy.dispose();
    }
}
Also used : CircuitState(com.cburch.logisim.circuit.CircuitState) Graphics(java.awt.Graphics) ComponentDrawContext(com.cburch.logisim.comp.ComponentDrawContext) Bounds(com.cburch.logisim.data.Bounds) Circuit(com.cburch.logisim.circuit.Circuit) Component(com.cburch.logisim.comp.Component) Tool(com.cburch.logisim.tools.Tool)

Example 24 with CircuitState

use of com.cburch.logisim.circuit.CircuitState in project logisim-evolution by reds-heig.

the class CanvasPainter method paintContents.

// 
// painting methods
// 
void paintContents(Graphics g, Project proj) {
    Rectangle clip = g.getClipBounds();
    Dimension size = canvas.getSize();
    double zoomFactor = canvas.getZoomFactor();
    if (canvas.ifPaintDirtyReset() || clip == null) {
        clip = new Rectangle(0, 0, size.width, size.height);
    }
    // YSY removed to don't overwrite background image
    // g.setColor(Color.magenta);
    // g.fillRect(clip.x, clip.y, clip.width, clip.height);
    grid.paintGrid(g);
    g.setColor(Color.black);
    Graphics gScaled = g.create();
    if (zoomFactor != 1.0 && gScaled instanceof Graphics2D) {
        ((Graphics2D) gScaled).scale(zoomFactor, zoomFactor);
    }
    drawWithUserState(g, gScaled, proj);
    drawWidthIncompatibilityData(g, gScaled, proj);
    Circuit circ = proj.getCurrentCircuit();
    CircuitState circState = proj.getCircuitState();
    ComponentDrawContext ptContext = new ComponentDrawContext(canvas, circ, circState, g, gScaled);
    ptContext.setHighlightedWires(highlightedWires);
    gScaled.setColor(Color.RED);
    circState.drawOscillatingPoints(ptContext);
    gScaled.setColor(Color.BLUE);
    proj.getSimulator().drawStepPoints(ptContext);
    gScaled.dispose();
}
Also used : Graphics(java.awt.Graphics) CircuitState(com.cburch.logisim.circuit.CircuitState) ComponentDrawContext(com.cburch.logisim.comp.ComponentDrawContext) Rectangle(java.awt.Rectangle) Circuit(com.cburch.logisim.circuit.Circuit) Dimension(java.awt.Dimension) Graphics2D(java.awt.Graphics2D)

Example 25 with CircuitState

use of com.cburch.logisim.circuit.CircuitState in project logisim-evolution by reds-heig.

the class AppearanceCanvas method computeSize.

private void computeSize(boolean immediate) {
    hidePopup();
    Bounds bounds;
    CircuitState circState = circuitState;
    if (circState == null) {
        bounds = Bounds.create(0, 0, 50, 50);
    } else {
        bounds = circState.getCircuit().getAppearance().getAbsoluteBounds();
    }
    int width = bounds.getX() + bounds.getWidth() + BOUNDS_BUFFER;
    int height = bounds.getY() + bounds.getHeight() + BOUNDS_BUFFER;
    Dimension dim;
    if (canvasPane == null) {
        dim = new Dimension(width, height);
    } else {
        dim = canvasPane.supportPreferredSize(width, height);
    }
    if (!immediate) {
        Bounds old = oldPreferredSize;
        if (old != null && Math.abs(old.getWidth() - dim.width) < THRESH_SIZE_UPDATE && Math.abs(old.getHeight() - dim.height) < THRESH_SIZE_UPDATE) {
            return;
        }
    }
    oldPreferredSize = Bounds.create(0, 0, dim.width, dim.height);
    setPreferredSize(dim);
    revalidate();
}
Also used : CircuitState(com.cburch.logisim.circuit.CircuitState) Bounds(com.cburch.logisim.data.Bounds) Dimension(java.awt.Dimension)

Aggregations

CircuitState (com.cburch.logisim.circuit.CircuitState)26 Component (com.cburch.logisim.comp.Component)6 Circuit (com.cburch.logisim.circuit.Circuit)5 ArrayList (java.util.ArrayList)4 ComponentDrawContext (com.cburch.logisim.comp.ComponentDrawContext)3 Location (com.cburch.logisim.data.Location)3 Instance (com.cburch.logisim.instance.Instance)3 InstanceState (com.cburch.logisim.instance.InstanceState)3 Color (java.awt.Color)3 Dimension (java.awt.Dimension)3 Simulator (com.cburch.logisim.circuit.Simulator)2 SubcircuitFactory (com.cburch.logisim.circuit.SubcircuitFactory)2 Bounds (com.cburch.logisim.data.Bounds)2 Value (com.cburch.logisim.data.Value)2 LogisimFile (com.cburch.logisim.file.LogisimFile)2 Graphics (java.awt.Graphics)2 TreePath (javax.swing.tree.TreePath)2 CircuitListener (com.cburch.logisim.circuit.CircuitListener)1 SimulatorEvent (com.cburch.logisim.circuit.SimulatorEvent)1 AppearancePort (com.cburch.logisim.circuit.appear.AppearancePort)1