Search in sources :

Example 56 with Location

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

the class SelectTool method setMouse.

private void setMouse(Canvas canvas, int mx, int my, int mods) {
    lastMouseX = mx;
    lastMouseY = my;
    boolean shift = (mods & MouseEvent.SHIFT_DOWN_MASK) != 0;
    boolean ctrl = (mods & InputEvent.CTRL_DOWN_MASK) != 0;
    Location newEnd = Location.create(mx, my);
    dragEnd = newEnd;
    Location start = dragStart;
    int dx = newEnd.getX() - start.getX();
    int dy = newEnd.getY() - start.getY();
    if (!dragEffective) {
        if (Math.abs(dx) + Math.abs(dy) > DRAG_TOLERANCE) {
            dragEffective = true;
        } else {
            return;
        }
    }
    switch(curAction) {
        case MOVE_HANDLE:
            HandleGesture gesture = curGesture;
            if (ctrl) {
                Handle h = gesture.getHandle();
                dx = canvas.snapX(h.getX() + dx) - h.getX();
                dy = canvas.snapY(h.getY() + dy) - h.getY();
            }
            curGesture = new HandleGesture(gesture.getHandle(), dx, dy, mods);
            canvas.getSelection().setHandleGesture(curGesture);
            break;
        case MOVE_ALL:
            if (ctrl) {
                int minX = Integer.MAX_VALUE;
                int minY = Integer.MAX_VALUE;
                for (CanvasObject o : canvas.getSelection().getSelected()) {
                    for (Handle handle : o.getHandles(null)) {
                        int x = handle.getX();
                        int y = handle.getY();
                        if (x < minX)
                            minX = x;
                        if (y < minY)
                            minY = y;
                    }
                }
                dx = canvas.snapX(minX + dx) - minX;
                dy = canvas.snapY(minY + dy) - minY;
            }
            if (shift) {
                if (Math.abs(dx) > Math.abs(dy)) {
                    dy = 0;
                } else {
                    dx = 0;
                }
            }
            canvas.getSelection().setMovingDelta(dx, dy);
            break;
        default:
            break;
    }
    repaintArea(canvas);
}
Also used : HandleGesture(com.cburch.draw.model.HandleGesture) CanvasObject(com.cburch.draw.model.CanvasObject) Location(com.cburch.logisim.data.Location) Handle(com.cburch.draw.model.Handle)

Example 57 with Location

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

the class Analyze method propagateWires.

// propagates expressions down wires
private static void propagateWires(ExpressionMap expressionMap, HashSet<Location> pointsToProcess) throws AnalyzeException {
    expressionMap.currentCause = null;
    for (Location p : pointsToProcess) {
        Expression e = expressionMap.get(p);
        expressionMap.currentCause = expressionMap.causes.get(p);
        WireBundle bundle = expressionMap.circuit.wires.getWireBundle(p);
        if (e != null && bundle != null && bundle.points != null) {
            for (Location p2 : bundle.points) {
                if (p2.equals(p))
                    continue;
                Expression old = expressionMap.get(p2);
                if (old != null) {
                    Component eCause = expressionMap.currentCause;
                    Component oldCause = expressionMap.causes.get(p2);
                    if (eCause != oldCause && !old.equals(e)) {
                        throw new AnalyzeException.Conflict();
                    }
                }
                expressionMap.put(p2, e);
            }
        }
    }
}
Also used : Expression(com.cburch.logisim.analyze.model.Expression) Component(com.cburch.logisim.comp.Component) Location(com.cburch.logisim.data.Location)

Example 58 with Location

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

the class Analyze method computeExpression.

// 
// computeExpression
// 
/**
 * Computes the expression corresponding to the given circuit, or raises
 * ComputeException if difficulties arise.
 */
public static void computeExpression(AnalyzerModel model, Circuit circuit, Map<Instance, String> pinNames) throws AnalyzeException {
    ExpressionMap expressionMap = new ExpressionMap(circuit);
    ArrayList<String> inputNames = new ArrayList<String>();
    ArrayList<String> outputNames = new ArrayList<String>();
    ArrayList<Instance> outputPins = new ArrayList<Instance>();
    for (Map.Entry<Instance, String> entry : pinNames.entrySet()) {
        Instance pin = entry.getKey();
        String label = entry.getValue();
        if (Pin.FACTORY.isInputPin(pin)) {
            expressionMap.currentCause = Instance.getComponentFor(pin);
            Expression e = Expressions.variable(label);
            expressionMap.put(pin.getLocation(), e);
            inputNames.add(label);
        } else {
            outputPins.add(pin);
            outputNames.add(label);
        }
    }
    propagateComponents(expressionMap, circuit.getNonWires());
    for (int iterations = 0; !expressionMap.dirtyPoints.isEmpty(); iterations++) {
        if (iterations > MAX_ITERATIONS) {
            throw new AnalyzeException.Circular();
        }
        propagateWires(expressionMap, new HashSet<Location>(expressionMap.dirtyPoints));
        HashSet<Component> dirtyComponents = getDirtyComponents(circuit, expressionMap.dirtyPoints);
        expressionMap.dirtyPoints.clear();
        propagateComponents(expressionMap, dirtyComponents);
        Expression expr = checkForCircularExpressions(expressionMap);
        if (expr != null)
            throw new AnalyzeException.Circular();
    }
    model.setVariables(inputNames, outputNames);
    for (int i = 0; i < outputPins.size(); i++) {
        Instance pin = outputPins.get(i);
        model.getOutputExpressions().setExpression(outputNames.get(i), expressionMap.get(pin.getLocation()));
    }
}
Also used : Instance(com.cburch.logisim.instance.Instance) ArrayList(java.util.ArrayList) Expression(com.cburch.logisim.analyze.model.Expression) Component(com.cburch.logisim.comp.Component) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Map(java.util.Map) SortedMap(java.util.SortedMap) Location(com.cburch.logisim.data.Location)

Example 59 with Location

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

the class SvgReader method createPath.

private static AbstractCanvasObject createPath(Element elt) {
    Matcher patt = PATH_REGEX.matcher(elt.getAttribute("d"));
    List<String> tokens = new ArrayList<String>();
    // -1 error, 0 start, 1 curve, 2 polyline
    int type = -1;
    while (patt.find()) {
        String token = patt.group();
        tokens.add(token);
        if (Character.isLetter(token.charAt(0))) {
            switch(token.charAt(0)) {
                case 'M':
                    if (type == -1)
                        type = 0;
                    else
                        type = -1;
                    break;
                case 'Q':
                case 'q':
                    if (type == 0)
                        type = 1;
                    else
                        type = -1;
                    break;
                /*
				 * not supported case 'L': case 'l': case 'H': case 'h': case
				 * 'V': case 'v': if (type == 0 || type == 2) type = 2; else
				 * type = -1; break;
				 */
                default:
                    type = -1;
            }
            if (type == -1) {
                throw new NumberFormatException("Unrecognized path command '" + token.charAt(0) + "'");
            }
        }
    }
    if (type == 1) {
        if (tokens.size() == 8 && tokens.get(0).equals("M") && tokens.get(3).toUpperCase().equals("Q")) {
            int x0 = Integer.parseInt(tokens.get(1));
            int y0 = Integer.parseInt(tokens.get(2));
            int x1 = Integer.parseInt(tokens.get(4));
            int y1 = Integer.parseInt(tokens.get(5));
            int x2 = Integer.parseInt(tokens.get(6));
            int y2 = Integer.parseInt(tokens.get(7));
            if (tokens.get(3).equals("q")) {
                x1 += x0;
                y1 += y0;
                x2 += x0;
                y2 += y0;
            }
            Location e0 = Location.create(x0, y0);
            Location e1 = Location.create(x2, y2);
            Location ct = Location.create(x1, y1);
            return new Curve(e0, e1, ct);
        } else {
            throw new NumberFormatException("Unexpected format for curve");
        }
    } else {
        throw new NumberFormatException("Unrecognized path");
    }
}
Also used : Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) Location(com.cburch.logisim.data.Location)

Example 60 with Location

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

the class AbstractGate method computePorts.

void computePorts(Instance instance) {
    GateAttributes attrs = (GateAttributes) instance.getAttributeSet();
    int inputs = attrs.inputs;
    Port[] ports = new Port[inputs + 1];
    ports[0] = new Port(0, 0, Port.OUTPUT, StdAttr.WIDTH);
    for (int i = 0; i < inputs; i++) {
        Location offs = getInputOffset(attrs, i);
        ports[i + 1] = new Port(offs.getX(), offs.getY(), Port.INPUT, StdAttr.WIDTH);
    }
    instance.setPorts(ports);
}
Also used : Port(com.cburch.logisim.instance.Port) 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