Search in sources :

Example 66 with Direction

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

the class PainterShaped method paintInputLines.

static void paintInputLines(InstancePainter painter, AbstractGate factory) {
    Location loc = painter.getLocation();
    boolean printView = painter.isPrintView();
    GateAttributes attrs = (GateAttributes) painter.getAttributeSet();
    Direction facing = attrs.facing;
    int inputs = attrs.inputs;
    int negated = attrs.negated;
    int[] lengths = getInputLineLengths(attrs, factory);
    if (painter.getInstance() == null) {
        // only
        for (int i = 0; i < inputs; i++) {
            boolean iNegated = ((negated >> i) & 1) == 1;
            if (iNegated) {
                Location offs = factory.getInputOffset(attrs, i);
                Location loci = loc.translate(offs.getX(), offs.getY());
                Location cent = loci.translate(facing, lengths[i] + 5);
                painter.drawDongle(cent.getX(), cent.getY());
            }
        }
    } else {
        Graphics g = painter.getGraphics();
        Color baseColor = g.getColor();
        GraphicsUtil.switchToWidth(g, 3);
        for (int i = 0; i < inputs; i++) {
            Location offs = factory.getInputOffset(attrs, i);
            Location src = loc.translate(offs.getX(), offs.getY());
            int len = lengths[i];
            if (len != 0 && (!printView || painter.isPortConnected(i + 1))) {
                if (painter.getShowState()) {
                    Value val = painter.getPortValue(i + 1);
                    g.setColor(val.getColor());
                } else {
                    g.setColor(baseColor);
                }
                Location dst = src.translate(facing, len);
                g.drawLine(src.getX(), src.getY(), dst.getX(), dst.getY());
            }
            if (((negated >> i) & 1) == 1) {
                Location cent = src.translate(facing, lengths[i] + 5);
                g.setColor(baseColor);
                painter.drawDongle(cent.getX(), cent.getY());
                GraphicsUtil.switchToWidth(g, 3);
            }
        }
    }
}
Also used : Graphics(java.awt.Graphics) Color(java.awt.Color) Value(com.cburch.logisim.data.Value) Direction(com.cburch.logisim.data.Direction) Location(com.cburch.logisim.data.Location)

Example 67 with Direction

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

the class AppearanceEditHandler method delete.

@Override
public void delete() {
    Selection sel = canvas.getSelection();
    int n = sel.getSelected().size();
    List<CanvasObject> select = new ArrayList<CanvasObject>(n);
    List<CanvasObject> remove = new ArrayList<CanvasObject>(n);
    Location anchorLocation = null;
    Direction anchorFacing = null;
    for (CanvasObject o : sel.getSelected()) {
        if (o.canRemove()) {
            remove.add(o);
        } else {
            select.add(o);
            if (o instanceof AppearanceAnchor) {
                AppearanceAnchor anchor = (AppearanceAnchor) o;
                anchorLocation = anchor.getLocation();
                anchorFacing = anchor.getFacing();
            }
        }
    }
    if (!remove.isEmpty()) {
        canvas.getProject().doAction(new SelectionAction(canvas, Strings.getter("deleteSelectionAction"), remove, null, select, anchorLocation, anchorFacing));
    }
}
Also used : CanvasObject(com.cburch.draw.model.CanvasObject) Selection(com.cburch.draw.canvas.Selection) ArrayList(java.util.ArrayList) AppearanceAnchor(com.cburch.logisim.circuit.appear.AppearanceAnchor) Direction(com.cburch.logisim.data.Direction) Location(com.cburch.logisim.data.Location)

Example 68 with Direction

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

the class Power method drawInstance.

private void drawInstance(InstancePainter painter, boolean isGhost) {
    Graphics2D g = (Graphics2D) painter.getGraphics().create();
    Location loc = painter.getLocation();
    g.translate(loc.getX(), loc.getY());
    Direction from = painter.getAttributeValue(StdAttr.FACING);
    int degrees = Direction.EAST.toDegrees() - from.toDegrees();
    double radians = Math.toRadians((degrees + 360) % 360);
    g.rotate(radians);
    GraphicsUtil.switchToWidth(g, Wire.WIDTH);
    if (!isGhost && painter.getShowState()) {
        g.setColor(painter.getPortValue(0).getColor());
    }
    g.drawLine(0, 0, 5, 0);
    GraphicsUtil.switchToWidth(g, 1);
    if (!isGhost && painter.shouldDrawColor()) {
        BitWidth width = painter.getAttributeValue(StdAttr.WIDTH);
        g.setColor(Value.repeat(Value.TRUE, width.getWidth()).getColor());
    }
    g.drawPolygon(new int[] { 6, 14, 6 }, new int[] { -8, 0, 8 }, 3);
    g.dispose();
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) Direction(com.cburch.logisim.data.Direction) Graphics2D(java.awt.Graphics2D) Location(com.cburch.logisim.data.Location)

Example 69 with Direction

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

the class AddTool method getFacing.

private Direction getFacing() {
    ComponentFactory source = getFactory();
    if (source == null)
        return Direction.NORTH;
    AttributeSet base = getBaseAttributes();
    Object feature = source.getFeature(ComponentFactory.FACING_ATTRIBUTE_KEY, base);
    @SuppressWarnings("unchecked") Attribute<Direction> attr = (Attribute<Direction>) feature;
    if (attr != null)
        return base.getValue(attr);
    else
        return Direction.NORTH;
}
Also used : AttributeSet(com.cburch.logisim.data.AttributeSet) Attribute(com.cburch.logisim.data.Attribute) ComponentFactory(com.cburch.logisim.comp.ComponentFactory) Direction(com.cburch.logisim.data.Direction)

Example 70 with Direction

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

the class EditTool method getFacingAttribute.

private Attribute<Direction> getFacingAttribute(Component comp) {
    AttributeSet attrs = comp.getAttributeSet();
    Object key = ComponentFactory.FACING_ATTRIBUTE_KEY;
    Attribute<?> a = (Attribute<?>) comp.getFactory().getFeature(key, attrs);
    @SuppressWarnings("unchecked") Attribute<Direction> ret = (Attribute<Direction>) a;
    return ret;
}
Also used : AttributeSet(com.cburch.logisim.data.AttributeSet) Attribute(com.cburch.logisim.data.Attribute) Direction(com.cburch.logisim.data.Direction)

Aggregations

Direction (com.cburch.logisim.data.Direction)89 Location (com.cburch.logisim.data.Location)39 Bounds (com.cburch.logisim.data.Bounds)27 BitWidth (com.cburch.logisim.data.BitWidth)20 Graphics (java.awt.Graphics)20 Graphics2D (java.awt.Graphics2D)13 Port (com.cburch.logisim.instance.Port)10 Instance (com.cburch.logisim.instance.Instance)9 ArrayList (java.util.ArrayList)7 CanvasObject (com.cburch.draw.model.CanvasObject)5 Color (java.awt.Color)5 Font (java.awt.Font)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 AttributeSet (com.cburch.logisim.data.AttributeSet)4 FontMetrics (java.awt.FontMetrics)4 List (java.util.List)4 Wire (com.cburch.logisim.circuit.Wire)3 Attribute (com.cburch.logisim.data.Attribute)3 Value (com.cburch.logisim.data.Value)3