Search in sources :

Example 61 with Location

use of com.cburch.logisim.data.Location in project logisim-evolution by reds-heig.

the class AbstractGate method paintBase.

private void paintBase(InstancePainter painter) {
    GateAttributes attrs = (GateAttributes) painter.getAttributeSet();
    Direction facing = attrs.facing;
    int inputs = attrs.inputs;
    int negated = attrs.negated;
    Object shape = painter.getGateShape();
    Location loc = painter.getLocation();
    Bounds bds = painter.getOffsetBounds();
    int width = bds.getWidth();
    int height = bds.getHeight();
    if (facing == Direction.NORTH || facing == Direction.SOUTH) {
        int t = width;
        width = height;
        height = t;
    }
    if (negated != 0) {
        width -= 10;
    }
    Graphics g = painter.getGraphics();
    Color baseColor = g.getColor();
    if (shape == AppPreferences.SHAPE_SHAPED && paintInputLines) {
        PainterShaped.paintInputLines(painter, this);
    } else if (negated != 0) {
        for (int i = 0; i < inputs; i++) {
            int negatedBit = (negated >> i) & 1;
            if (negatedBit == 1) {
                Location in = getInputOffset(attrs, i);
                Location cen = in.translate(facing, 5);
                painter.drawDongle(loc.getX() + cen.getX(), loc.getY() + cen.getY());
            }
        }
    }
    g.setColor(baseColor);
    g.translate(loc.getX(), loc.getY());
    double rotate = 0.0;
    if (facing != Direction.EAST && g instanceof Graphics2D) {
        rotate = -facing.toRadians();
        Graphics2D g2 = (Graphics2D) g;
        g2.rotate(rotate);
    }
    if (shape == AppPreferences.SHAPE_RECTANGULAR) {
        paintRectangular(painter, width, height);
    } else if (shape == AppPreferences.SHAPE_DIN40700) {
        paintDinShape(painter, width, height, inputs);
    } else {
        // SHAPE_SHAPED
        if (negateOutput) {
            g.translate(-10, 0);
            paintShape(painter, width - 10, height);
            painter.drawDongle(5, 0);
            g.translate(10, 0);
        } else {
            paintShape(painter, width, height);
        }
    }
    if (rotate != 0.0) {
        ((Graphics2D) g).rotate(-rotate);
    }
    g.translate(-loc.getX(), -loc.getY());
    painter.drawLabel();
}
Also used : Graphics(java.awt.Graphics) Bounds(com.cburch.logisim.data.Bounds) Color(java.awt.Color) Direction(com.cburch.logisim.data.Direction) Location(com.cburch.logisim.data.Location) Graphics2D(java.awt.Graphics2D)

Example 62 with Location

use of com.cburch.logisim.data.Location in project logisim-evolution by reds-heig.

the class Buffer method paintBase.

private void paintBase(InstancePainter painter) {
    Direction facing = painter.getAttributeValue(StdAttr.FACING);
    Location loc = painter.getLocation();
    int x = loc.getX();
    int y = loc.getY();
    Graphics g = painter.getGraphics();
    g.translate(x, y);
    double rotate = 0.0;
    if (facing != Direction.EAST && g instanceof Graphics2D) {
        rotate = -facing.toRadians();
        ((Graphics2D) g).rotate(rotate);
    }
    GraphicsUtil.switchToWidth(g, 2);
    int[] xp = new int[4];
    int[] yp = new int[4];
    xp[0] = 0;
    yp[0] = 0;
    xp[1] = -19;
    yp[1] = -7;
    xp[2] = -19;
    yp[2] = 7;
    xp[3] = 0;
    yp[3] = 0;
    g.drawPolyline(xp, yp, 4);
    if (rotate != 0.0) {
        ((Graphics2D) g).rotate(-rotate);
    }
    g.translate(-x, -y);
}
Also used : Graphics(java.awt.Graphics) Direction(com.cburch.logisim.data.Direction) Location(com.cburch.logisim.data.Location) Graphics2D(java.awt.Graphics2D)

Example 63 with Location

use of com.cburch.logisim.data.Location in project logisim-evolution by reds-heig.

the class CircuitBuilder method build.

public static CircuitMutation build(Circuit destCirc, AnalyzerModel model, boolean twoInputs, boolean useNands) {
    CircuitMutation result = new CircuitMutation(destCirc);
    result.clear();
    Layout[] layouts = new Layout[model.getOutputs().size()];
    int maxWidth = 0;
    for (int i = 0; i < layouts.length; i++) {
        String output = model.getOutputs().get(i);
        Expression expr = model.getOutputExpressions().getExpression(output);
        CircuitDetermination det = CircuitDetermination.create(expr);
        if (det != null) {
            if (twoInputs)
                det.convertToTwoInputs();
            if (useNands)
                det.convertToNands();
            det.repair();
            layouts[i] = layoutGates(det);
            maxWidth = Math.max(maxWidth, layouts[i].width);
        } else {
            layouts[i] = null;
        }
    }
    InputData inputData = computeInputData(model);
    int x = inputData.getStartX();
    int y = 10;
    int outputX = x + maxWidth + 20;
    for (int i = 0; i < layouts.length; i++) {
        String outputName = model.getOutputs().get(i);
        Layout layout = layouts[i];
        Location output;
        int height;
        if (layout == null) {
            output = Location.create(outputX, y + 20);
            height = 40;
        } else {
            int dy = 0;
            if (layout.outputY < 20)
                dy = 20 - layout.outputY;
            height = Math.max(dy + layout.height, 40);
            output = Location.create(outputX, y + dy + layout.outputY);
            placeComponents(result, layouts[i], x, y + dy, inputData, output);
        }
        placeOutput(result, output, outputName);
        y += height + 10;
    }
    placeInputs(result, inputData);
    return result;
}
Also used : Expression(com.cburch.logisim.analyze.model.Expression) CircuitMutation(com.cburch.logisim.circuit.CircuitMutation) Location(com.cburch.logisim.data.Location)

Example 64 with Location

use of com.cburch.logisim.data.Location in project logisim-evolution by reds-heig.

the class CircuitBuilder method placeComponents.

// 
// placeComponents
// 
/**
 * @param circuit
 *            the circuit where to place the components.
 * @param layout
 *            the layout specifying the gates to place there.
 * @param x
 *            the left edge of where the layout should be placed.
 * @param y
 *            the top edge of where the layout should be placed.
 * @param inputData
 *            information about how to reach inputs.
 * @param output
 *            a point to which the output should be connected.
 */
private static void placeComponents(CircuitMutation result, Layout layout, int x, int y, InputData inputData, Location output) {
    if (layout.inputName != null) {
        int inputX = inputData.getSpineX(layout.inputName);
        Location input = Location.create(inputX, output.getY());
        inputData.registerConnection(layout.inputName, input);
        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 || i == layout.subLayouts.length - 1 && destY > subOutputY) {
                subOutputY = destY;
            }
        }
        Location subOutput;
        int numSubs = layout.subLayouts.length;
        if (subOutputY == subDest.getY()) {
            subOutput = subDest;
        } else {
            int back;
            if (i < numSubs / 2) {
                if (subOutputY < subDest.getY()) {
                    // bending upward
                    back = i;
                } else {
                    back = ((numSubs - 1) / 2) - i;
                }
            } else {
                if (subOutputY > subDest.getY()) {
                    // bending downward
                    back = numSubs - 1 - i;
                } else {
                    back = i - (numSubs / 2);
                }
            }
            int subOutputX = subDest.getX() - 20 - 10 * back;
            subOutput = Location.create(subOutputX, subOutputY);
            Location mid = Location.create(subOutputX, subDest.getY());
            result.add(Wire.create(subOutput, mid));
            result.add(Wire.create(mid, subDest));
        }
        int subX = x + layout.subX - sub.width;
        int subY = y + sub.y;
        placeComponents(result, sub, subX, subY, inputData, subOutput);
    }
}
Also used : AttributeSet(com.cburch.logisim.data.AttributeSet) Value(com.cburch.logisim.data.Value) Component(com.cburch.logisim.comp.Component) Location(com.cburch.logisim.data.Location)

Example 65 with Location

use of com.cburch.logisim.data.Location in project logisim-evolution by reds-heig.

the class ControlledBuffer method paintInstance.

@Override
public void paintInstance(InstancePainter painter) {
    Direction face = painter.getAttributeValue(StdAttr.FACING);
    Graphics g = painter.getGraphics();
    // draw control wire
    GraphicsUtil.switchToWidth(g, 3);
    Location pt0 = painter.getInstance().getPortLocation(2);
    Location pt1;
    if (painter.getAttributeValue(ATTR_CONTROL) == LEFT_HANDED) {
        pt1 = pt0.translate(face, 0, 6);
    } else {
        pt1 = pt0.translate(face, 0, -6);
    }
    if (painter.getShowState()) {
        g.setColor(painter.getPortValue(2).getColor());
    }
    g.drawLine(pt0.getX(), pt0.getY(), pt1.getX(), pt1.getY());
    // draw triangle
    g.setColor(Color.BLACK);
    paintShape(painter);
    // draw input and output pins
    if (!painter.isPrintView()) {
        painter.drawPort(0);
        painter.drawPort(1);
    }
    painter.drawLabel();
}
Also used : Graphics(java.awt.Graphics) Direction(com.cburch.logisim.data.Direction) Location(com.cburch.logisim.data.Location)

Aggregations

Location (com.cburch.logisim.data.Location)169 Direction (com.cburch.logisim.data.Direction)39 Graphics (java.awt.Graphics)35 Component (com.cburch.logisim.comp.Component)26 Bounds (com.cburch.logisim.data.Bounds)24 ArrayList (java.util.ArrayList)23 CanvasObject (com.cburch.draw.model.CanvasObject)17 BitWidth (com.cburch.logisim.data.BitWidth)16 Wire (com.cburch.logisim.circuit.Wire)13 HashMap (java.util.HashMap)10 Handle (com.cburch.draw.model.Handle)9 AttributeSet (com.cburch.logisim.data.AttributeSet)9 Value (com.cburch.logisim.data.Value)9 Instance (com.cburch.logisim.instance.Instance)9 Port (com.cburch.logisim.instance.Port)9 Color (java.awt.Color)9 Graphics2D (java.awt.Graphics2D)9 HashSet (java.util.HashSet)9 Circuit (com.cburch.logisim.circuit.Circuit)8 EndData (com.cburch.logisim.comp.EndData)7