use of com.cburch.logisim.circuit.CircuitMutation in project logisim-evolution by reds-heig.
the class AttrTableCircuitModel method setValueRequested.
@Override
public void setValueRequested(Attribute<Object> attr, Object value) throws AttrTableSetException {
if (!proj.getLogisimFile().contains(circ)) {
String msg = Strings.get("cannotModifyCircuitError");
throw new AttrTableSetException(msg);
} else {
CircuitMutation xn = new CircuitMutation(circ);
xn.setForCircuit(attr, value);
proj.doAction(xn.toAction(Strings.getter("changeCircuitAttrAction")));
}
}
use of com.cburch.logisim.circuit.CircuitMutation in project logisim-evolution by reds-heig.
the class AttrTableToolModel method setValueRequested.
@Override
public void setValueRequested(Attribute<Object> attr, Object value) {
if (tool instanceof AddTool) {
AddTool mytool = (AddTool) tool;
if (mytool.getFactory() instanceof SubcircuitFactory) {
SubcircuitFactory fac = (SubcircuitFactory) mytool.getFactory();
if (attr.equals(CircuitAttributes.NAMED_CIRCUIT_BOX) || attr.equals(CircuitAttributes.NAME_ATTR)) {
try {
CircuitMutation mutation = new CircuitMutation(fac.getSubcircuit());
mutation.setForCircuit(attr, value);
Action action = mutation.toAction(null);
proj.doAction(action);
} catch (CircuitException ex) {
JOptionPane.showMessageDialog(proj.getFrame(), ex.getMessage());
}
return;
}
}
}
proj.doAction(ToolAttributeAction.create(tool, attr, value));
}
use of com.cburch.logisim.circuit.CircuitMutation in project logisim-evolution by reds-heig.
the class SetAttributeAction method doIt.
@Override
public void doIt(Project proj) {
CircuitMutation xn = new CircuitMutation(circuit);
int len = values.size();
oldValues.clear();
for (int i = 0; i < len; i++) {
Component comp = comps.get(i);
Attribute<Object> attr = attrs.get(i);
Object value = values.get(i);
if (circuit.contains(comp)) {
oldValues.add(null);
xn.set(comp, attr, value);
} else {
AttributeSet compAttrs = comp.getAttributeSet();
oldValues.add(compAttrs.getValue(attr));
compAttrs.setValue(attr, value);
}
}
if (!xn.isEmpty()) {
CircuitTransactionResult result = xn.execute();
xnReverse = result.getReverseTransaction();
}
}
use of com.cburch.logisim.circuit.CircuitMutation 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.circuit.CircuitMutation 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;
}
}
}
Aggregations