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);
}
}
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;
}
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;
}
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()));
}
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));
}
}
Aggregations