Search in sources :

Example 1 with Selection

use of com.cburch.logisim.gui.main.Selection 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 2 with Selection

use of com.cburch.logisim.gui.main.Selection 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 3 with Selection

use of com.cburch.logisim.gui.main.Selection in project logisim-evolution by reds-heig.

the class SelectTool method computeDxDy.

private void computeDxDy(Project proj, MouseEvent e, Graphics g) {
    Bounds bds = proj.getSelection().getBounds(g);
    int dx;
    int dy;
    if (bds == Bounds.EMPTY_BOUNDS) {
        dx = e.getX() - start.getX();
        dy = e.getY() - start.getY();
    } else {
        dx = Math.max(e.getX() - start.getX(), -bds.getX());
        dy = Math.max(e.getY() - start.getY(), -bds.getY());
    }
    Selection sel = proj.getSelection();
    if (sel.shouldSnap()) {
        dx = Canvas.snapXToGrid(dx);
        dy = Canvas.snapYToGrid(dy);
    }
    curDx = dx;
    curDy = dy;
}
Also used : Selection(com.cburch.logisim.gui.main.Selection) Bounds(com.cburch.logisim.data.Bounds)

Example 4 with Selection

use of com.cburch.logisim.gui.main.Selection in project logisim-evolution by reds-heig.

the class Project method setCircuitState.

public void setCircuitState(CircuitState value) {
    if (value == null || circuitState == value)
        return;
    CircuitState old = circuitState;
    Circuit oldCircuit = old == null ? null : old.getCircuit();
    Circuit newCircuit = value.getCircuit();
    boolean circuitChanged = old == null || oldCircuit != newCircuit;
    if (circuitChanged) {
        Canvas canvas = frame == null ? null : frame.getCanvas();
        if (canvas != null) {
            if (tool != null)
                tool.deselect(canvas);
            Selection selection = canvas.getSelection();
            if (selection != null) {
                Action act = SelectionActions.dropAll(selection);
                if (act != null) {
                    doAction(act);
                }
            }
            if (tool != null)
                tool.select(canvas);
        }
        if (oldCircuit != null) {
            for (CircuitListener l : circuitListeners) {
                oldCircuit.removeCircuitListener(l);
            }
        }
    }
    circuitState = value;
    stateMap.put(circuitState.getCircuit(), circuitState);
    simulator.setCircuitState(circuitState);
    if (circuitChanged) {
        fireEvent(ProjectEvent.ACTION_SET_CURRENT, oldCircuit, newCircuit);
        if (newCircuit != null) {
            for (CircuitListener l : circuitListeners) {
                newCircuit.addCircuitListener(l);
            }
        }
    }
    fireEvent(ProjectEvent.ACTION_SET_STATE, old, circuitState);
}
Also used : CircuitState(com.cburch.logisim.circuit.CircuitState) CircuitListener(com.cburch.logisim.circuit.CircuitListener) Selection(com.cburch.logisim.gui.main.Selection) Canvas(com.cburch.logisim.gui.main.Canvas) Circuit(com.cburch.logisim.circuit.Circuit)

Example 5 with Selection

use of com.cburch.logisim.gui.main.Selection in project logisim-evolution by reds-heig.

the class Project method setTool.

public void setTool(Tool value) {
    if (tool == value)
        return;
    Tool old = tool;
    Canvas canvas = frame.getCanvas();
    if (old != null)
        old.deselect(canvas);
    Selection selection = canvas.getSelection();
    if (selection != null && !selection.isEmpty()) {
        if (value == null || !getOptions().getMouseMappings().containsSelectTool()) {
            Action act = SelectionActions.anchorAll(selection);
            /*
				 * Circuit circuit = canvas.getCircuit(); CircuitMutation xn =
				 * new CircuitMutation(circuit); if (value == null) { Action act
				 * = SelectionActions.dropAll(selection); if (act != null) {
				 * doAction(act); } } else if
				 * (!getOptions().getMouseMappings().containsSelectTool()) {
				 * Action act = SelectionActions.dropAll(selection);
				 */
            if (act != null) {
                doAction(act);
            }
        }
    /*
			 * if (!xn.isEmpty()) doAction(xn.toAction(null));
			 */
    }
    startupScreen = false;
    tool = value;
    if (tool != null)
        tool.select(frame.getCanvas());
    fireEvent(ProjectEvent.ACTION_SET_TOOL, old, tool);
}
Also used : Selection(com.cburch.logisim.gui.main.Selection) Canvas(com.cburch.logisim.gui.main.Canvas) Tool(com.cburch.logisim.tools.Tool) AddTool(com.cburch.logisim.tools.AddTool)

Aggregations

Selection (com.cburch.logisim.gui.main.Selection)9 Component (com.cburch.logisim.comp.Component)6 Circuit (com.cburch.logisim.circuit.Circuit)5 Project (com.cburch.logisim.proj.Project)3 ReplacementMap (com.cburch.logisim.circuit.ReplacementMap)2 Wire (com.cburch.logisim.circuit.Wire)2 Bounds (com.cburch.logisim.data.Bounds)2 Location (com.cburch.logisim.data.Location)2 Canvas (com.cburch.logisim.gui.main.Canvas)2 Action (com.cburch.logisim.proj.Action)2 CircuitListener (com.cburch.logisim.circuit.CircuitListener)1 CircuitState (com.cburch.logisim.circuit.CircuitState)1 ComponentFactory (com.cburch.logisim.comp.ComponentFactory)1 Attribute (com.cburch.logisim.data.Attribute)1 AttributeSet (com.cburch.logisim.data.AttributeSet)1 Direction (com.cburch.logisim.data.Direction)1 AddTool (com.cburch.logisim.tools.AddTool)1 Tool (com.cburch.logisim.tools.Tool)1 KeyConfigurationEvent (com.cburch.logisim.tools.key.KeyConfigurationEvent)1 KeyConfigurationResult (com.cburch.logisim.tools.key.KeyConfigurationResult)1