Search in sources :

Example 6 with CanvasObject

use of com.cburch.draw.model.CanvasObject in project logisim-evolution by reds-heig.

the class PolyTool method commit.

private CanvasObject commit(Canvas canvas) {
    if (!active)
        return null;
    CanvasObject add = null;
    active = false;
    final var locs = locations;
    for (var i = locs.size() - 2; i >= 0; i--) {
        if (locs.get(i).equals(locs.get(i + 1)))
            locs.remove(i);
    }
    if (locs.size() > 1) {
        final var model = canvas.getModel();
        add = new Poly(closed, locs);
        canvas.doAction(new ModelAddAction(model, add));
        repaintArea(canvas);
    }
    locs.clear();
    return add;
}
Also used : CanvasObject(com.cburch.draw.model.CanvasObject) ModelAddAction(com.cburch.draw.actions.ModelAddAction) Poly(com.cburch.draw.shapes.Poly)

Example 7 with CanvasObject

use of com.cburch.draw.model.CanvasObject in project logisim-evolution by reds-heig.

the class RectangularTool method mouseReleased.

@Override
public void mouseReleased(Canvas canvas, MouseEvent e) {
    if (active) {
        final var oldBounds = currentBounds;
        final var bds = computeBounds(canvas, e.getX(), e.getY(), e.getModifiersEx());
        currentBounds = Bounds.EMPTY_BOUNDS;
        active = false;
        CanvasObject add = null;
        if (bds.getWidth() != 0 && bds.getHeight() != 0) {
            final var model = canvas.getModel();
            add = createShape(bds.getX(), bds.getY(), bds.getWidth(), bds.getHeight());
            canvas.doAction(new ModelAddAction(model, add));
            repaintArea(canvas, oldBounds.add(bds));
        }
        canvas.toolGestureComplete(this, add);
    }
}
Also used : CanvasObject(com.cburch.draw.model.CanvasObject) ModelAddAction(com.cburch.draw.actions.ModelAddAction)

Example 8 with CanvasObject

use of com.cburch.draw.model.CanvasObject in project logisim-evolution by reds-heig.

the class DrawingAttributeSet method applyTo.

public <E extends CanvasObject> E applyTo(E drawable) {
    AbstractCanvasObject d = (AbstractCanvasObject) drawable;
    // use a for(i...) loop since the attribute list may change as we go on
    for (var i = 0; i < d.getAttributes().size(); i++) {
        Attribute<?> attr = d.getAttributes().get(i);
        @SuppressWarnings("unchecked") Attribute<Object> a = (Attribute<Object>) attr;
        if (attr == DrawAttr.FILL_COLOR && this.containsAttribute(DrawAttr.TEXT_DEFAULT_FILL)) {
            d.setValue(a, this.getValue(DrawAttr.TEXT_DEFAULT_FILL));
        } else if (this.containsAttribute(a)) {
            d.setValue(a, this.getValue(a));
        }
    }
    return drawable;
}
Also used : Attribute(com.cburch.logisim.data.Attribute) AbstractCanvasObject(com.cburch.draw.model.AbstractCanvasObject) AbstractCanvasObject(com.cburch.draw.model.AbstractCanvasObject) CanvasObject(com.cburch.draw.model.CanvasObject)

Example 9 with CanvasObject

use of com.cburch.draw.model.CanvasObject 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 10 with CanvasObject

use of com.cburch.draw.model.CanvasObject in project logisim-evolution by reds-heig.

the class AppearanceEditHandler method duplicate.

@Override
public void duplicate() {
    Selection sel = canvas.getSelection();
    int n = sel.getSelected().size();
    List<CanvasObject> select = new ArrayList<CanvasObject>(n);
    List<CanvasObject> clones = new ArrayList<CanvasObject>(n);
    for (CanvasObject o : sel.getSelected()) {
        if (o.canRemove()) {
            CanvasObject copy = o.clone();
            copy.translate(10, 10);
            clones.add(copy);
            select.add(copy);
        } else {
            select.add(o);
        }
    }
    if (!clones.isEmpty()) {
        canvas.getProject().doAction(new SelectionAction(canvas, Strings.getter("duplicateSelectionAction"), null, clones, select, null, null));
    }
}
Also used : CanvasObject(com.cburch.draw.model.CanvasObject) Selection(com.cburch.draw.canvas.Selection) ArrayList(java.util.ArrayList)

Aggregations

CanvasObject (com.cburch.draw.model.CanvasObject)45 Location (com.cburch.logisim.data.Location)15 ArrayList (java.util.ArrayList)13 Handle (com.cburch.draw.model.Handle)9 Selection (com.cburch.draw.canvas.Selection)8 ModelAddAction (com.cburch.draw.actions.ModelAddAction)7 Direction (com.cburch.logisim.data.Direction)5 HandleGesture (com.cburch.draw.model.HandleGesture)4 Poly (com.cburch.draw.shapes.Poly)4 Instance (com.cburch.logisim.instance.Instance)4 Map (java.util.Map)4 Rectangle (com.cburch.draw.shapes.Rectangle)3 HashMap (java.util.HashMap)3 AbstractCanvasObject (com.cburch.draw.model.AbstractCanvasObject)2 CanvasModel (com.cburch.draw.model.CanvasModel)2 Circuit (com.cburch.logisim.circuit.Circuit)2 AppearanceElement (com.cburch.logisim.circuit.appear.AppearanceElement)2 AppearancePort (com.cburch.logisim.circuit.appear.AppearancePort)2 Attribute (com.cburch.logisim.data.Attribute)2 Bounds (com.cburch.logisim.data.Bounds)2