Search in sources :

Example 16 with Circuit

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

the class AddTool method mousePressed.

@Override
public void mousePressed(Canvas canvas, Graphics g, MouseEvent e) {
    // verify the addition would be valid
    Circuit circ = canvas.getCircuit();
    if (!canvas.getProject().getLogisimFile().contains(circ)) {
        canvas.setErrorMessage(Strings.getter("cannotModifyError"));
        return;
    }
    if (factory instanceof SubcircuitFactory) {
        SubcircuitFactory circFact = (SubcircuitFactory) factory;
        Dependencies depends = canvas.getProject().getDependencies();
        if (!depends.canAdd(circ, circFact.getSubcircuit())) {
            canvas.setErrorMessage(Strings.getter("circularError"));
            return;
        }
    }
    if (shouldSnap)
        Canvas.snapToGrid(e);
    moveTo(canvas, g, e.getX(), e.getY());
    setState(canvas, SHOW_ADD);
}
Also used : SubcircuitFactory(com.cburch.logisim.circuit.SubcircuitFactory) Circuit(com.cburch.logisim.circuit.Circuit) Dependencies(com.cburch.logisim.proj.Dependencies)

Example 17 with Circuit

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

the class EditTool method mousePressed.

@Override
public void mousePressed(Canvas canvas, Graphics g, MouseEvent e) {
    boolean wire = updateLocation(canvas, e);
    Location oldWireLoc = wireLoc;
    wireLoc = NULL_LOCATION;
    lastX = Integer.MIN_VALUE;
    if (wire) {
        current = wiring;
        Selection sel = canvas.getSelection();
        Circuit circ = canvas.getCircuit();
        Collection<Component> selected = sel.getAnchoredComponents();
        ArrayList<Component> suppress = null;
        for (Wire w : circ.getWires()) {
            if (selected.contains(w)) {
                if (w.contains(oldWireLoc)) {
                    if (suppress == null)
                        suppress = new ArrayList<Component>();
                    suppress.add(w);
                }
            }
        }
        sel.setSuppressHandles(suppress);
    } else {
        current = select;
    }
    pressX = e.getX();
    pressY = e.getY();
    current.mousePressed(canvas, g, e);
}
Also used : Selection(com.cburch.logisim.gui.main.Selection) ArrayList(java.util.ArrayList) Circuit(com.cburch.logisim.circuit.Circuit) Component(com.cburch.logisim.comp.Component) Wire(com.cburch.logisim.circuit.Wire) Location(com.cburch.logisim.data.Location)

Example 18 with Circuit

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

the class EditTool method attemptReface.

private void attemptReface(Canvas canvas, final Direction facing, KeyEvent e) {
    if (e.getModifiersEx() == 0) {
        final Circuit circuit = canvas.getCircuit();
        final Selection sel = canvas.getSelection();
        SetAttributeAction act = new SetAttributeAction(circuit, Strings.getter("selectionRefaceAction"));
        for (Component comp : sel.getComponents()) {
            if (!(comp instanceof Wire)) {
                Attribute<Direction> attr = getFacingAttribute(comp);
                if (attr != null) {
                    act.set(comp, attr, facing);
                }
            }
        }
        if (!act.isEmpty()) {
            canvas.getProject().doAction(act);
            e.consume();
        }
    }
}
Also used : Selection(com.cburch.logisim.gui.main.Selection) Circuit(com.cburch.logisim.circuit.Circuit) Component(com.cburch.logisim.comp.Component) Wire(com.cburch.logisim.circuit.Wire) Direction(com.cburch.logisim.data.Direction)

Example 19 with Circuit

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

the class TextTool method mousePressed.

@Override
public void mousePressed(Canvas canvas, Graphics g, MouseEvent e) {
    Project proj = canvas.getProject();
    Circuit circ = canvas.getCircuit();
    if (!proj.getLogisimFile().contains(circ)) {
        if (caret != null)
            caret.cancelEditing();
        canvas.setErrorMessage(Strings.getter("cannotModifyError"));
        return;
    }
    // Maybe user is clicking within the current caret.
    if (caret != null) {
        if (caret.getBounds(g).contains(e.getX(), e.getY())) {
            // Yes
            caret.mousePressed(e);
            proj.repaintCanvas();
            return;
        } else {
            // No. End the current caret.
            caret.stopEditing();
        }
    }
    // caret will be null at this point
    // Otherwise search for a new caret.
    int x = e.getX();
    int y = e.getY();
    Location loc = Location.create(x, y);
    ComponentUserEvent event = new ComponentUserEvent(canvas, x, y);
    // First search in selection.
    for (Component comp : proj.getSelection().getComponentsContaining(loc, g)) {
        TextEditable editable = (TextEditable) comp.getFeature(TextEditable.class);
        if (editable != null) {
            caret = editable.getTextCaret(event);
            if (caret != null) {
                proj.getFrame().viewComponentAttributes(circ, comp);
                caretComponent = comp;
                caretCreatingText = false;
                break;
            }
        }
    }
    // Then search in circuit
    if (caret == null) {
        for (Component comp : circ.getAllContaining(loc, g)) {
            TextEditable editable = (TextEditable) comp.getFeature(TextEditable.class);
            if (editable != null) {
                caret = editable.getTextCaret(event);
                if (caret != null) {
                    proj.getFrame().viewComponentAttributes(circ, comp);
                    caretComponent = comp;
                    caretCreatingText = false;
                    break;
                }
            }
        }
    }
    // if nothing found, create a new label
    if (caret == null) {
        if (loc.getX() < 0 || loc.getY() < 0)
            return;
        AttributeSet copy = (AttributeSet) attrs.clone();
        caretComponent = Text.FACTORY.createComponent(loc, copy);
        caretCreatingText = true;
        TextEditable editable = (TextEditable) caretComponent.getFeature(TextEditable.class);
        if (editable != null) {
            caret = editable.getTextCaret(event);
            proj.getFrame().viewComponentAttributes(circ, caretComponent);
        }
    }
    if (caret != null) {
        caretCanvas = canvas;
        caretCircuit = canvas.getCircuit();
        caret.addCaretListener(listener);
        caretCircuit.addCircuitListener(listener);
    }
    proj.repaintCanvas();
}
Also used : Project(com.cburch.logisim.proj.Project) AttributeSet(com.cburch.logisim.data.AttributeSet) ComponentUserEvent(com.cburch.logisim.comp.ComponentUserEvent) Circuit(com.cburch.logisim.circuit.Circuit) Component(com.cburch.logisim.comp.Component) Location(com.cburch.logisim.data.Location)

Example 20 with Circuit

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

the class FileStatistics method doRecursiveCount.

private static Map<ComponentFactory, Count> doRecursiveCount(Circuit circuit, Set<Circuit> include, Map<Circuit, Map<ComponentFactory, Count>> countMap) {
    if (countMap.containsKey(circuit)) {
        return countMap.get(circuit);
    }
    Map<ComponentFactory, Count> counts = doSimpleCount(circuit);
    countMap.put(circuit, counts);
    for (Count count : counts.values()) {
        count.uniqueCount = count.simpleCount;
        count.recursiveCount = count.simpleCount;
    }
    for (Circuit sub : include) {
        SubcircuitFactory subFactory = sub.getSubcircuitFactory();
        if (counts.containsKey(subFactory)) {
            int multiplier = counts.get(subFactory).simpleCount;
            Map<ComponentFactory, Count> subCount;
            subCount = doRecursiveCount(sub, include, countMap);
            for (Count subcount : subCount.values()) {
                ComponentFactory subfactory = subcount.factory;
                Count supercount = counts.get(subfactory);
                if (supercount == null) {
                    supercount = new Count(subfactory);
                    counts.put(subfactory, supercount);
                }
                supercount.recursiveCount += multiplier * subcount.recursiveCount;
            }
        }
    }
    return counts;
}
Also used : ComponentFactory(com.cburch.logisim.comp.ComponentFactory) SubcircuitFactory(com.cburch.logisim.circuit.SubcircuitFactory) Circuit(com.cburch.logisim.circuit.Circuit)

Aggregations

Circuit (com.cburch.logisim.circuit.Circuit)62 Component (com.cburch.logisim.comp.Component)19 SubcircuitFactory (com.cburch.logisim.circuit.SubcircuitFactory)12 Project (com.cburch.logisim.proj.Project)11 ArrayList (java.util.ArrayList)9 Wire (com.cburch.logisim.circuit.Wire)8 ComponentFactory (com.cburch.logisim.comp.ComponentFactory)8 Location (com.cburch.logisim.data.Location)8 Bounds (com.cburch.logisim.data.Bounds)6 LogisimFile (com.cburch.logisim.file.LogisimFile)6 AddTool (com.cburch.logisim.tools.AddTool)6 Tool (com.cburch.logisim.tools.Tool)6 CircuitState (com.cburch.logisim.circuit.CircuitState)5 AttributeSet (com.cburch.logisim.data.AttributeSet)5 Selection (com.cburch.logisim.gui.main.Selection)5 Action (com.cburch.logisim.proj.Action)4 CircuitMutation (com.cburch.logisim.circuit.CircuitMutation)3 ComponentDrawContext (com.cburch.logisim.comp.ComponentDrawContext)3 Graphics (java.awt.Graphics)3 CanvasObject (com.cburch.draw.model.CanvasObject)2