use of com.cburch.logisim.circuit.ReplacementMap in project logisim-evolution by reds-heig.
the class SelectTool method mouseReleased.
@Override
public void mouseReleased(Canvas canvas, Graphics g, MouseEvent e) {
Project proj = canvas.getProject();
if (state == MOVING) {
setState(proj, IDLE);
computeDxDy(proj, e, g);
int dx = curDx;
int dy = curDy;
if (dx != 0 || dy != 0) {
if (!proj.getLogisimFile().contains(canvas.getCircuit())) {
canvas.setErrorMessage(Strings.getter("cannotModifyError"));
} else if (proj.getSelection().hasConflictWhenMoved(dx, dy)) {
canvas.setErrorMessage(Strings.getter("exclusiveError"));
} else {
boolean connect = shouldConnect(canvas, e.getModifiersEx());
drawConnections = false;
ReplacementMap repl;
if (connect) {
MoveGesture gesture = moveGesture;
if (gesture == null) {
gesture = new MoveGesture(new MoveRequestHandler(canvas), canvas.getCircuit(), canvas.getSelection().getAnchoredComponents());
}
canvas.setErrorMessage(new ComputingMessage(dx, dy), COLOR_COMPUTING);
MoveResult result = gesture.forceRequest(dx, dy);
clearCanvasMessage(canvas, dx, dy);
repl = result.getReplacementMap();
} else {
repl = null;
}
Selection sel = proj.getSelection();
proj.doAction(SelectionActions.translate(sel, dx, dy, repl));
}
}
moveGesture = null;
proj.repaintCanvas();
} else if (state == RECT_SELECT) {
Bounds bds = Bounds.create(start).add(start.getX() + curDx, start.getY() + curDy);
Circuit circuit = canvas.getCircuit();
Selection sel = proj.getSelection();
Collection<Component> in_sel = sel.getComponentsWithin(bds, g);
for (Component comp : circuit.getAllWithin(bds, g)) {
if (!in_sel.contains(comp))
sel.add(comp);
}
Action act = SelectionActions.drop(sel, in_sel);
if (act != null) {
proj.doAction(act);
}
setState(proj, IDLE);
proj.repaintCanvas();
}
if (e.getClickCount() >= 2) {
Set<Component> comps = canvas.getProject().getSelection().getComponents();
if (comps.size() == 1) {
for (Component comp : comps) {
if (comp.getAttributeSet().containsAttribute(StdAttr.LABEL)) {
String OldLabel = comp.getAttributeSet().getValue(StdAttr.LABEL);
SetAttributeAction act = new SetAttributeAction(canvas.getCircuit(), Strings.getter("changeComponentAttributesAction"));
AutoLabler.AskAndSetLabel(comp.getFactory().getDisplayName(), OldLabel, canvas.getCircuit(), comp, comp.getFactory(), comp.getAttributeSet(), act, true);
if (!act.isEmpty())
canvas.getProject().doAction(act);
}
}
}
}
}
use of com.cburch.logisim.circuit.ReplacementMap in project logisim-evolution by reds-heig.
the class Connector method tryList.
private static MoveResult tryList(MoveRequest req, MoveGesture gesture, ArrayList<ConnectionData> connects, int dx, int dy, HashMap<ConnectionData, Set<Location>> pathLocs, HashMap<ConnectionData, List<SearchNode>> initNodes, long stopTime) {
AvoidanceMap avoid = gesture.getFixedAvoidanceMap().cloneMap();
avoid.markAll(gesture.getSelected(), dx, dy);
ReplacementMap replacements = new ReplacementMap();
ArrayList<ConnectionData> unconnected = new ArrayList<ConnectionData>();
int totalDistance = 0;
for (ConnectionData conn : connects) {
if (ConnectorThread.isOverrideRequested()) {
return null;
}
if (System.currentTimeMillis() - stopTime > 0) {
unconnected.add(conn);
continue;
}
List<SearchNode> connNodes = initNodes.get(conn);
Set<Location> connPathLocs = pathLocs.get(conn);
SearchNode n = findShortestPath(connNodes, connPathLocs, avoid);
if (n != null) {
// normal case - a path was found
totalDistance += n.getDistance();
ArrayList<Location> path = convertToPath(n);
processPath(path, conn, avoid, replacements, connPathLocs);
} else if (ConnectorThread.isOverrideRequested()) {
// search was aborted: return null to indicate this
return null;
} else {
unconnected.add(conn);
}
}
return new MoveResult(req, replacements, unconnected, totalDistance);
}
Aggregations