Search in sources :

Example 1 with ReplacementMap

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

the class SelectTool method mouseReleased.

@Override
public void mouseReleased(Canvas canvas, Graphics g, MouseEvent e) {
    Project proj = canvas.getProject();
    if (state == MOVING) {
        setState(proj, IDLE);
        computeDxDy(proj, e, g);
        int dx = curDx;
        int dy = curDy;
        if (dx != 0 || dy != 0) {
            if (!proj.getLogisimFile().contains(canvas.getCircuit())) {
                canvas.setErrorMessage(Strings.getter("cannotModifyError"));
            } else if (proj.getSelection().hasConflictWhenMoved(dx, dy)) {
                canvas.setErrorMessage(Strings.getter("exclusiveError"));
            } else {
                boolean connect = shouldConnect(canvas, e.getModifiersEx());
                drawConnections = false;
                ReplacementMap repl;
                if (connect) {
                    MoveGesture gesture = moveGesture;
                    if (gesture == null) {
                        gesture = new MoveGesture(new MoveRequestHandler(canvas), canvas.getCircuit(), canvas.getSelection().getAnchoredComponents());
                    }
                    canvas.setErrorMessage(new ComputingMessage(dx, dy), COLOR_COMPUTING);
                    MoveResult result = gesture.forceRequest(dx, dy);
                    clearCanvasMessage(canvas, dx, dy);
                    repl = result.getReplacementMap();
                } else {
                    repl = null;
                }
                Selection sel = proj.getSelection();
                proj.doAction(SelectionActions.translate(sel, dx, dy, repl));
            }
        }
        moveGesture = null;
        proj.repaintCanvas();
    } else if (state == RECT_SELECT) {
        Bounds bds = Bounds.create(start).add(start.getX() + curDx, start.getY() + curDy);
        Circuit circuit = canvas.getCircuit();
        Selection sel = proj.getSelection();
        Collection<Component> in_sel = sel.getComponentsWithin(bds, g);
        for (Component comp : circuit.getAllWithin(bds, g)) {
            if (!in_sel.contains(comp))
                sel.add(comp);
        }
        Action act = SelectionActions.drop(sel, in_sel);
        if (act != null) {
            proj.doAction(act);
        }
        setState(proj, IDLE);
        proj.repaintCanvas();
    }
    if (e.getClickCount() >= 2) {
        Set<Component> comps = canvas.getProject().getSelection().getComponents();
        if (comps.size() == 1) {
            for (Component comp : comps) {
                if (comp.getAttributeSet().containsAttribute(StdAttr.LABEL)) {
                    String OldLabel = comp.getAttributeSet().getValue(StdAttr.LABEL);
                    SetAttributeAction act = new SetAttributeAction(canvas.getCircuit(), Strings.getter("changeComponentAttributesAction"));
                    AutoLabler.AskAndSetLabel(comp.getFactory().getDisplayName(), OldLabel, canvas.getCircuit(), comp, comp.getFactory(), comp.getAttributeSet(), act, true);
                    if (!act.isEmpty())
                        canvas.getProject().doAction(act);
                }
            }
        }
    }
}
Also used : Action(com.cburch.logisim.proj.Action) Selection(com.cburch.logisim.gui.main.Selection) Bounds(com.cburch.logisim.data.Bounds) Circuit(com.cburch.logisim.circuit.Circuit) Project(com.cburch.logisim.proj.Project) Collection(java.util.Collection) MoveGesture(com.cburch.logisim.tools.move.MoveGesture) MoveResult(com.cburch.logisim.tools.move.MoveResult) ReplacementMap(com.cburch.logisim.circuit.ReplacementMap) Component(com.cburch.logisim.comp.Component)

Example 2 with ReplacementMap

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

the class Connector method tryList.

private static MoveResult tryList(MoveRequest req, MoveGesture gesture, ArrayList<ConnectionData> connects, int dx, int dy, HashMap<ConnectionData, Set<Location>> pathLocs, HashMap<ConnectionData, List<SearchNode>> initNodes, long stopTime) {
    AvoidanceMap avoid = gesture.getFixedAvoidanceMap().cloneMap();
    avoid.markAll(gesture.getSelected(), dx, dy);
    ReplacementMap replacements = new ReplacementMap();
    ArrayList<ConnectionData> unconnected = new ArrayList<ConnectionData>();
    int totalDistance = 0;
    for (ConnectionData conn : connects) {
        if (ConnectorThread.isOverrideRequested()) {
            return null;
        }
        if (System.currentTimeMillis() - stopTime > 0) {
            unconnected.add(conn);
            continue;
        }
        List<SearchNode> connNodes = initNodes.get(conn);
        Set<Location> connPathLocs = pathLocs.get(conn);
        SearchNode n = findShortestPath(connNodes, connPathLocs, avoid);
        if (n != null) {
            // normal case - a path was found
            totalDistance += n.getDistance();
            ArrayList<Location> path = convertToPath(n);
            processPath(path, conn, avoid, replacements, connPathLocs);
        } else if (ConnectorThread.isOverrideRequested()) {
            // search was aborted: return null to indicate this
            return null;
        } else {
            unconnected.add(conn);
        }
    }
    return new MoveResult(req, replacements, unconnected, totalDistance);
}
Also used : ArrayList(java.util.ArrayList) ReplacementMap(com.cburch.logisim.circuit.ReplacementMap) Location(com.cburch.logisim.data.Location)

Aggregations

ReplacementMap (com.cburch.logisim.circuit.ReplacementMap)2 Circuit (com.cburch.logisim.circuit.Circuit)1 Component (com.cburch.logisim.comp.Component)1 Bounds (com.cburch.logisim.data.Bounds)1 Location (com.cburch.logisim.data.Location)1 Selection (com.cburch.logisim.gui.main.Selection)1 Action (com.cburch.logisim.proj.Action)1 Project (com.cburch.logisim.proj.Project)1 MoveGesture (com.cburch.logisim.tools.move.MoveGesture)1 MoveResult (com.cburch.logisim.tools.move.MoveResult)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1