use of com.cburch.logisim.comp.Component in project logisim-evolution by reds-heig.
the class AddTool method mouseReleased.
@Override
public void mouseReleased(Canvas canvas, Graphics g, MouseEvent e) {
Component added = null;
if (state == SHOW_ADD) {
Circuit circ = canvas.getCircuit();
if (!canvas.getProject().getLogisimFile().contains(circ))
return;
if (shouldSnap)
Canvas.snapToGrid(e);
moveTo(canvas, g, e.getX(), e.getY());
Location loc = Location.create(e.getX(), e.getY());
ComponentFactory source = getFactory();
AttributeSet attrsCopy = (AttributeSet) attrs.clone();
if (attrsCopy.containsAttribute(StdAttr.LABEL)) {
attrsCopy.setValue(StdAttr.LABEL, AutoLabler.GetCurrent(canvas.getCircuit(), source));
if (AutoLabler.IsActive(canvas.getCircuit())) {
if (AutoLabler.hasNext(canvas.getCircuit()))
AutoLabler.GetNext(canvas.getCircuit(), source);
else
AutoLabler.Stop(canvas.getCircuit());
} else
AutoLabler.SetLabel("", canvas.getCircuit(), source);
}
if (source == null)
return;
Component c = source.createComponent(loc, attrsCopy);
if (circ.hasConflict(c)) {
canvas.setErrorMessage(Strings.getter("exclusiveError"));
return;
}
Bounds bds = c.getBounds(g);
if (bds.getX() < 0 || bds.getY() < 0) {
canvas.setErrorMessage(Strings.getter("negativeCoordError"));
return;
}
try {
CircuitMutation mutation = new CircuitMutation(circ);
mutation.add(c);
Action action = mutation.toAction(Strings.getter("addComponentAction", factory.getDisplayGetter()));
canvas.getProject().doAction(action);
lastAddition = action;
added = c;
canvas.repaint();
} catch (CircuitException ex) {
JOptionPane.showMessageDialog(canvas.getProject().getFrame(), ex.getMessage());
}
setState(canvas, SHOW_GHOST);
} else if (state == SHOW_ADD_NO) {
setState(canvas, SHOW_NONE);
}
Project proj = canvas.getProject();
Tool next = determineNext(proj);
if (next != null) {
proj.setTool(next);
Action act = SelectionActions.dropAll(canvas.getSelection());
if (act != null) {
proj.doAction(act);
}
if (added != null)
canvas.getSelection().add(added);
}
}
use of com.cburch.logisim.comp.Component in project logisim-evolution by reds-heig.
the class EditTool method isWiringPoint.
private boolean isWiringPoint(Canvas canvas, Location loc, int modsEx) {
boolean wiring = (modsEx & MouseEvent.ALT_DOWN_MASK) == 0;
boolean select = !wiring;
if (canvas != null && canvas.getSelection() != null) {
Collection<Component> sel = canvas.getSelection().getComponents();
if (sel != null) {
for (Component c : sel) {
if (c instanceof Wire) {
Wire w = (Wire) c;
if (w.contains(loc) && !w.endsAt(loc))
return select;
}
}
}
}
Circuit circ = canvas.getCircuit();
Collection<? extends Component> at = circ.getComponents(loc);
if (at != null && at.size() > 0)
return wiring;
for (Wire w : circ.getWires()) {
if (w.contains(loc)) {
return wiring;
}
}
return select;
}
use of com.cburch.logisim.comp.Component in project logisim-evolution by reds-heig.
the class WiringTool method checkForRepairs.
private Wire checkForRepairs(Canvas canvas, Wire w, Location end) {
if (w.getLength() <= 10)
// don't repair a short wire to nothing
return w;
if (!canvas.getCircuit().getNonWires(end).isEmpty())
return w;
int delta = (end.equals(w.getEnd0()) ? 10 : -10);
Location cand;
if (w.isVertical()) {
cand = Location.create(end.getX(), end.getY() + delta);
} else {
cand = Location.create(end.getX() + delta, end.getY());
}
for (Component comp : canvas.getCircuit().getNonWires(cand)) {
if (comp.getBounds().contains(end, 2)) {
WireRepair repair = (WireRepair) comp.getFeature(WireRepair.class);
if (repair != null && repair.shouldRepairWire(new WireRepairData(w, cand))) {
w = Wire.create(w.getOtherEnd(end), cand);
canvas.repaint(end.getX() - 13, end.getY() - 13, 26, 26);
return w;
}
}
}
return w;
}
use of com.cburch.logisim.comp.Component in project logisim-evolution by reds-heig.
the class MoveGesture method computeConnections.
private static Set<ConnectionData> computeConnections(Circuit circuit, Set<Component> selected) {
if (selected == null || selected.isEmpty())
return Collections.emptySet();
// first identify locations that might be connected
Set<Location> locs = new HashSet<Location>();
for (Component comp : selected) {
for (EndData end : comp.getEnds()) {
locs.add(end.getLocation());
}
}
// now see which of them require connection
Set<ConnectionData> conns = new HashSet<ConnectionData>();
for (Location loc : locs) {
boolean found = false;
for (Component comp : circuit.getComponents(loc)) {
if (!selected.contains(comp)) {
found = true;
break;
}
}
if (found) {
List<Wire> wirePath;
Location wirePathStart;
Wire lastOnPath = findWire(circuit, loc, selected, null);
if (lastOnPath == null) {
wirePath = Collections.emptyList();
wirePathStart = loc;
} else {
wirePath = new ArrayList<Wire>();
Location cur = loc;
for (Wire w = lastOnPath; w != null; w = findWire(circuit, cur, selected, w)) {
wirePath.add(w);
cur = w.getOtherEnd(cur);
}
Collections.reverse(wirePath);
wirePathStart = cur;
}
Direction dir = null;
if (lastOnPath != null) {
Location other = lastOnPath.getOtherEnd(loc);
int dx = loc.getX() - other.getX();
int dy = loc.getY() - other.getY();
if (Math.abs(dx) > Math.abs(dy)) {
dir = dx > 0 ? Direction.EAST : Direction.WEST;
} else {
dir = dy > 0 ? Direction.SOUTH : Direction.NORTH;
}
}
conns.add(new ConnectionData(loc, dir, wirePath, wirePathStart));
}
}
return conns;
}
use of com.cburch.logisim.comp.Component in project logisim-evolution by reds-heig.
the class MoveResult method print.
public void print(PrintStream out) {
boolean printed = false;
for (Component w : replacements.getAdditions()) {
printed = true;
out.println("add " + w);
}
for (Component w : replacements.getRemovals()) {
printed = true;
out.println("del " + w);
}
for (Component w : replacements.getReplacedComponents()) {
printed = true;
out.print("repl " + w + " by");
for (Component w2 : replacements.getComponentsReplacing(w)) {
out.print(" " + w2);
}
out.println();
}
if (!printed) {
out.println("no replacements");
}
}
Aggregations