Search in sources :

Example 31 with CanvasObject

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

the class CircuitAppearance method paintSubcircuit.

public void paintSubcircuit(Graphics g, Direction facing) {
    Direction defaultFacing = getFacing();
    double rotate = 0.0;
    if (facing != defaultFacing && g instanceof Graphics2D) {
        rotate = defaultFacing.toRadians() - facing.toRadians();
        ((Graphics2D) g).rotate(rotate);
    }
    Location offset = findAnchorLocation();
    g.translate(-offset.getX(), -offset.getY());
    for (CanvasObject shape : getObjectsFromBottom()) {
        if (!(shape instanceof AppearanceElement)) {
            Graphics dup = g.create();
            shape.paint(dup, null);
            dup.dispose();
        }
    }
    g.translate(offset.getX(), offset.getY());
    if (rotate != 0.0) {
        ((Graphics2D) g).rotate(-rotate);
    }
}
Also used : Graphics(java.awt.Graphics) CanvasObject(com.cburch.draw.model.CanvasObject) Direction(com.cburch.logisim.data.Direction) Graphics2D(java.awt.Graphics2D) Location(com.cburch.logisim.data.Location)

Example 32 with CanvasObject

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

the class CircuitAppearance method contains.

/**
 * Code taken from Cornell's version of Logisim:
 * http://www.cs.cornell.edu/courses/cs3410/2015sp/
 */
public boolean contains(Location loc) {
    Location query;
    AppearanceAnchor anchor = findAnchor();
    if (anchor == null) {
        query = loc;
    } else {
        Location anchorLoc = anchor.getLocation();
        query = loc.translate(anchorLoc.getX(), anchorLoc.getY());
    }
    for (CanvasObject o : getObjectsFromBottom()) {
        if (!(o instanceof AppearanceElement) && o.contains(query, true)) {
            return true;
        }
    }
    return false;
}
Also used : CanvasObject(com.cburch.draw.model.CanvasObject) Location(com.cburch.logisim.data.Location)

Example 33 with CanvasObject

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

the class CircuitAppearance method getPortOffsets.

public SortedMap<Location, Instance> getPortOffsets(Direction facing) {
    Location anchor = null;
    Direction defaultFacing = Direction.EAST;
    List<AppearancePort> ports = new ArrayList<AppearancePort>();
    for (CanvasObject shape : getObjectsFromBottom()) {
        if (shape instanceof AppearancePort) {
            ports.add((AppearancePort) shape);
        } else if (shape instanceof AppearanceAnchor) {
            AppearanceAnchor o = (AppearanceAnchor) shape;
            anchor = o.getLocation();
            defaultFacing = o.getFacing();
        }
    }
    SortedMap<Location, Instance> ret = new TreeMap<Location, Instance>();
    for (AppearancePort port : ports) {
        Location loc = port.getLocation();
        if (anchor != null) {
            loc = loc.translate(-anchor.getX(), -anchor.getY());
        }
        if (facing != defaultFacing) {
            loc = loc.rotate(defaultFacing, facing, 0, 0);
        }
        ret.put(loc, port.getPin());
    }
    return ret;
}
Also used : CanvasObject(com.cburch.draw.model.CanvasObject) Instance(com.cburch.logisim.instance.Instance) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) Direction(com.cburch.logisim.data.Direction) Location(com.cburch.logisim.data.Location)

Example 34 with CanvasObject

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

the class AppearanceEditHandler method paste.

@Override
public void paste() {
    ClipboardContents clip = Clipboard.get();
    Collection<CanvasObject> contents = clip.getElements();
    List<CanvasObject> add = new ArrayList<CanvasObject>(contents.size());
    for (CanvasObject o : contents) {
        add.add(o.clone());
    }
    if (add.isEmpty())
        return;
    // find how far we have to translate shapes so that at least one of the
    // pasted shapes doesn't match what's already in the model
    Collection<CanvasObject> raw = canvas.getModel().getObjectsFromBottom();
    MatchingSet<CanvasObject> cur = new MatchingSet<CanvasObject>(raw);
    int dx = 0;
    while (true) {
        // if any shapes in "add" aren't in canvas, we are done
        boolean allMatch = true;
        for (CanvasObject o : add) {
            if (!cur.contains(o)) {
                allMatch = false;
                break;
            }
        }
        if (!allMatch)
            break;
        // otherwise translate everything by 10 pixels and repeat test
        for (CanvasObject o : add) {
            o.translate(10, 10);
        }
        dx += 10;
    }
    Location anchorLocation = clip.getAnchorLocation();
    if (anchorLocation != null && dx != 0) {
        anchorLocation = anchorLocation.translate(dx, dx);
    }
    canvas.getProject().doAction(new SelectionAction(canvas, Strings.getter("pasteClipboardAction"), null, add, add, anchorLocation, clip.getAnchorFacing()));
}
Also used : MatchingSet(com.cburch.draw.util.MatchingSet) CanvasObject(com.cburch.draw.model.CanvasObject) ArrayList(java.util.ArrayList) Location(com.cburch.logisim.data.Location)

Example 35 with CanvasObject

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

the class AppearanceEditHandler method delete.

@Override
public void delete() {
    Selection sel = canvas.getSelection();
    int n = sel.getSelected().size();
    List<CanvasObject> select = new ArrayList<CanvasObject>(n);
    List<CanvasObject> remove = new ArrayList<CanvasObject>(n);
    Location anchorLocation = null;
    Direction anchorFacing = null;
    for (CanvasObject o : sel.getSelected()) {
        if (o.canRemove()) {
            remove.add(o);
        } else {
            select.add(o);
            if (o instanceof AppearanceAnchor) {
                AppearanceAnchor anchor = (AppearanceAnchor) o;
                anchorLocation = anchor.getLocation();
                anchorFacing = anchor.getFacing();
            }
        }
    }
    if (!remove.isEmpty()) {
        canvas.getProject().doAction(new SelectionAction(canvas, Strings.getter("deleteSelectionAction"), remove, null, select, anchorLocation, anchorFacing));
    }
}
Also used : CanvasObject(com.cburch.draw.model.CanvasObject) Selection(com.cburch.draw.canvas.Selection) ArrayList(java.util.ArrayList) AppearanceAnchor(com.cburch.logisim.circuit.appear.AppearanceAnchor) Direction(com.cburch.logisim.data.Direction) Location(com.cburch.logisim.data.Location)

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