Search in sources :

Example 1 with AppearanceElement

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

the class AppearanceCanvas method doAction.

@Override
public void doAction(Action canvasAction) {
    Circuit circuit = circuitState.getCircuit();
    if (!proj.getLogisimFile().contains(circuit)) {
        return;
    }
    if (canvasAction instanceof ModelReorderAction) {
        int max = getMaxIndex(getModel());
        ModelReorderAction reorder = (ModelReorderAction) canvasAction;
        List<ReorderRequest> rs = reorder.getReorderRequests();
        List<ReorderRequest> mod = new ArrayList<ReorderRequest>(rs.size());
        boolean changed = false;
        boolean movedToMax = false;
        for (ReorderRequest r : rs) {
            CanvasObject o = r.getObject();
            if (o instanceof AppearanceElement) {
                changed = true;
            } else {
                if (r.getToIndex() > max) {
                    int from = r.getFromIndex();
                    changed = true;
                    movedToMax = true;
                    if (from == max && !movedToMax) {
                        // this change is ineffective - don't add it
                        ;
                    } else {
                        mod.add(new ReorderRequest(o, from, max));
                    }
                } else {
                    if (r.getToIndex() == max)
                        movedToMax = true;
                    mod.add(r);
                }
            }
        }
        if (changed) {
            if (mod.isEmpty()) {
                return;
            }
            canvasAction = new ModelReorderAction(getModel(), mod);
        }
    }
    if (canvasAction instanceof ModelAddAction) {
        ModelAddAction addAction = (ModelAddAction) canvasAction;
        int cur = addAction.getDestinationIndex();
        int max = getMaxIndex(getModel());
        if (cur > max) {
            canvasAction = new ModelAddAction(getModel(), addAction.getObjects(), max + 1);
        }
    }
    proj.doAction(new CanvasActionAdapter(circuit, canvasAction));
}
Also used : ReorderRequest(com.cburch.draw.model.ReorderRequest) CanvasObject(com.cburch.draw.model.CanvasObject) ModelReorderAction(com.cburch.draw.actions.ModelReorderAction) ModelAddAction(com.cburch.draw.actions.ModelAddAction) ArrayList(java.util.ArrayList) Circuit(com.cburch.logisim.circuit.Circuit) AppearanceElement(com.cburch.logisim.circuit.appear.AppearanceElement)

Example 2 with AppearanceElement

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

the class AppearanceEditHandler method computeEnabled.

@Override
public void computeEnabled() {
    Project proj = canvas.getProject();
    Circuit circ = canvas.getCircuit();
    Selection sel = canvas.getSelection();
    boolean selEmpty = sel.isEmpty();
    boolean canChange = proj.getLogisimFile().contains(circ);
    boolean clipExists = !Clipboard.isEmpty();
    boolean selHasRemovable = false;
    for (CanvasObject o : sel.getSelected()) {
        if (!(o instanceof AppearanceElement)) {
            selHasRemovable = true;
        }
    }
    boolean canRaise;
    boolean canLower;
    if (!selEmpty && canChange) {
        Map<CanvasObject, Integer> zs = ZOrder.getZIndex(sel.getSelected(), canvas.getModel());
        int zmin = Integer.MAX_VALUE;
        int zmax = Integer.MIN_VALUE;
        int count = 0;
        for (Map.Entry<CanvasObject, Integer> entry : zs.entrySet()) {
            if (!(entry.getKey() instanceof AppearanceElement)) {
                count++;
                int z = entry.getValue().intValue();
                if (z < zmin)
                    zmin = z;
                if (z > zmax)
                    zmax = z;
            }
        }
        int maxPoss = AppearanceCanvas.getMaxIndex(canvas.getModel());
        if (count > 0 && count <= maxPoss) {
            canRaise = zmin <= maxPoss - count;
            canLower = zmax >= count;
        } else {
            canRaise = false;
            canLower = false;
        }
    } else {
        canRaise = false;
        canLower = false;
    }
    boolean canAddCtrl = false;
    boolean canRemCtrl = false;
    Handle handle = sel.getSelectedHandle();
    if (handle != null && canChange) {
        CanvasObject o = handle.getObject();
        canAddCtrl = o.canInsertHandle(handle.getLocation()) != null;
        canRemCtrl = o.canDeleteHandle(handle.getLocation()) != null;
    }
    setEnabled(LogisimMenuBar.CUT, selHasRemovable && canChange);
    setEnabled(LogisimMenuBar.COPY, !selEmpty);
    setEnabled(LogisimMenuBar.PASTE, canChange && clipExists);
    setEnabled(LogisimMenuBar.DELETE, selHasRemovable && canChange);
    setEnabled(LogisimMenuBar.DUPLICATE, !selEmpty && canChange);
    setEnabled(LogisimMenuBar.SELECT_ALL, true);
    setEnabled(LogisimMenuBar.RAISE, canRaise);
    setEnabled(LogisimMenuBar.LOWER, canLower);
    setEnabled(LogisimMenuBar.RAISE_TOP, canRaise);
    setEnabled(LogisimMenuBar.LOWER_BOTTOM, canLower);
    setEnabled(LogisimMenuBar.ADD_CONTROL, canAddCtrl);
    setEnabled(LogisimMenuBar.REMOVE_CONTROL, canRemCtrl);
}
Also used : Project(com.cburch.logisim.proj.Project) CanvasObject(com.cburch.draw.model.CanvasObject) Selection(com.cburch.draw.canvas.Selection) Circuit(com.cburch.logisim.circuit.Circuit) AppearanceElement(com.cburch.logisim.circuit.appear.AppearanceElement) Map(java.util.Map) Handle(com.cburch.draw.model.Handle)

Aggregations

CanvasObject (com.cburch.draw.model.CanvasObject)2 Circuit (com.cburch.logisim.circuit.Circuit)2 AppearanceElement (com.cburch.logisim.circuit.appear.AppearanceElement)2 ModelAddAction (com.cburch.draw.actions.ModelAddAction)1 ModelReorderAction (com.cburch.draw.actions.ModelReorderAction)1 Selection (com.cburch.draw.canvas.Selection)1 Handle (com.cburch.draw.model.Handle)1 ReorderRequest (com.cburch.draw.model.ReorderRequest)1 Project (com.cburch.logisim.proj.Project)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1