use of com.cburch.logisim.circuit.Wire in project logisim-evolution by reds-heig.
the class WiringTool method mouseReleased.
@Override
public void mouseReleased(Canvas canvas, Graphics g, MouseEvent e) {
if (!exists)
return;
Canvas.snapToGrid(e);
int curX = e.getX();
int curY = e.getY();
if (computeMove(curX, curY)) {
cur = Location.create(curX, curY);
}
if (hasDragged) {
exists = false;
super.mouseReleased(canvas, g, e);
ArrayList<Wire> ws = new ArrayList<Wire>(2);
if (cur.getY() == start.getY() || cur.getX() == start.getX()) {
Wire w = Wire.create(cur, start);
w = checkForRepairs(canvas, w, w.getEnd0());
w = checkForRepairs(canvas, w, w.getEnd1());
if (performShortening(canvas, start, cur)) {
return;
}
if (w.getLength() > 0)
ws.add(w);
} else {
Location m;
if (direction == HORIZONTAL) {
m = Location.create(cur.getX(), start.getY());
} else {
m = Location.create(start.getX(), cur.getY());
}
Wire w0 = Wire.create(start, m);
Wire w1 = Wire.create(m, cur);
w0 = checkForRepairs(canvas, w0, start);
w1 = checkForRepairs(canvas, w1, cur);
if (w0.getLength() > 0)
ws.add(w0);
if (w1.getLength() > 0)
ws.add(w1);
}
if (ws.size() > 0) {
CircuitMutation mutation = new CircuitMutation(canvas.getCircuit());
mutation.addAll(ws);
StringGetter desc;
if (ws.size() == 1)
desc = Strings.getter("addWireAction");
else
desc = Strings.getter("addWiresAction");
Action act = mutation.toAction(desc);
canvas.getProject().doAction(act);
lastAction = act;
}
}
}
use of com.cburch.logisim.circuit.Wire in project logisim-evolution by reds-heig.
the class WiringTool method draw.
@Override
public void draw(Canvas canvas, ComponentDrawContext context) {
Graphics g = context.getGraphics();
if (exists) {
Location e0 = start;
Location e1 = cur;
Wire shortenBefore = willShorten(start, cur);
if (shortenBefore != null) {
Wire shorten = getShortenResult(shortenBefore, start, cur);
if (shorten == null) {
return;
} else {
e0 = shorten.getEnd0();
e1 = shorten.getEnd1();
}
}
int x0 = e0.getX();
int y0 = e0.getY();
int x1 = e1.getX();
int y1 = e1.getY();
g.setColor(Color.BLACK);
GraphicsUtil.switchToWidth(g, 3);
if (direction == HORIZONTAL) {
if (x0 != x1)
g.drawLine(x0, y0, x1, y0);
if (y0 != y1)
g.drawLine(x1, y0, x1, y1);
} else if (direction == VERTICAL) {
if (y0 != y1)
g.drawLine(x0, y0, x0, y1);
if (x0 != x1)
g.drawLine(x0, y1, x1, y1);
}
} else if (AppPreferences.ADD_SHOW_GHOSTS.getBoolean() && inCanvas) {
g.setColor(Color.GRAY);
g.fillOval(cur.getX() - 2, cur.getY() - 2, 5, 5);
}
}
use of com.cburch.logisim.circuit.Wire 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.circuit.Wire in project logisim-evolution by reds-heig.
the class SimpleDRCContainer method ClearMarks.
public void ClearMarks() {
if (!DRCInfoPresent())
return;
for (Object obj : DRCComponents) {
if (obj instanceof Wire) {
Wire wire = (Wire) obj;
if ((MarkType & MARK_WIRE) != 0) {
wire.SetMarked(false);
}
} else if (obj instanceof Splitter) {
Splitter split = (Splitter) obj;
if ((MarkType & MARK_INSTANCE) != 0) {
split.SetMarked(false);
}
} else if (obj instanceof InstanceComponent) {
InstanceComponent comp = (InstanceComponent) obj;
comp.clearMarks();
}
}
}
Aggregations