Search in sources :

Example 6 with CircuitMutation

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")));
    }
}
Also used : CircuitMutation(com.cburch.logisim.circuit.CircuitMutation) AttrTableSetException(com.cburch.logisim.gui.generic.AttrTableSetException)

Example 7 with CircuitMutation

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));
}
Also used : Action(com.cburch.logisim.proj.Action) CircuitException(com.cburch.logisim.circuit.CircuitException) SubcircuitFactory(com.cburch.logisim.circuit.SubcircuitFactory) CircuitMutation(com.cburch.logisim.circuit.CircuitMutation) AddTool(com.cburch.logisim.tools.AddTool)

Example 8 with CircuitMutation

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();
    }
}
Also used : CircuitTransactionResult(com.cburch.logisim.circuit.CircuitTransactionResult) AttributeSet(com.cburch.logisim.data.AttributeSet) CircuitMutation(com.cburch.logisim.circuit.CircuitMutation) Component(com.cburch.logisim.comp.Component)

Example 9 with CircuitMutation

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);
    }
}
Also used : Project(com.cburch.logisim.proj.Project) Action(com.cburch.logisim.proj.Action) ToolAttributeAction(com.cburch.logisim.gui.main.ToolAttributeAction) CircuitException(com.cburch.logisim.circuit.CircuitException) AttributeSet(com.cburch.logisim.data.AttributeSet) ComponentFactory(com.cburch.logisim.comp.ComponentFactory) Bounds(com.cburch.logisim.data.Bounds) CircuitMutation(com.cburch.logisim.circuit.CircuitMutation) Circuit(com.cburch.logisim.circuit.Circuit) Component(com.cburch.logisim.comp.Component) Location(com.cburch.logisim.data.Location)

Example 10 with CircuitMutation

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;
        }
    }
}
Also used : Action(com.cburch.logisim.proj.Action) ArrayList(java.util.ArrayList) CircuitMutation(com.cburch.logisim.circuit.CircuitMutation) Wire(com.cburch.logisim.circuit.Wire) StringGetter(com.cburch.logisim.util.StringGetter) Location(com.cburch.logisim.data.Location)

Aggregations

CircuitMutation (com.cburch.logisim.circuit.CircuitMutation)10 Component (com.cburch.logisim.comp.Component)4 Action (com.cburch.logisim.proj.Action)4 Circuit (com.cburch.logisim.circuit.Circuit)3 CircuitException (com.cburch.logisim.circuit.CircuitException)3 Wire (com.cburch.logisim.circuit.Wire)3 AttributeSet (com.cburch.logisim.data.AttributeSet)3 Location (com.cburch.logisim.data.Location)3 SubcircuitFactory (com.cburch.logisim.circuit.SubcircuitFactory)2 ComponentFactory (com.cburch.logisim.comp.ComponentFactory)2 StringGetter (com.cburch.logisim.util.StringGetter)2 ArrayList (java.util.ArrayList)2 Expression (com.cburch.logisim.analyze.model.Expression)1 CircuitTransactionResult (com.cburch.logisim.circuit.CircuitTransactionResult)1 Bounds (com.cburch.logisim.data.Bounds)1 AttrTableSetException (com.cburch.logisim.gui.generic.AttrTableSetException)1 ToolAttributeAction (com.cburch.logisim.gui.main.ToolAttributeAction)1 Project (com.cburch.logisim.proj.Project)1 AddTool (com.cburch.logisim.tools.AddTool)1 SetAttributeAction (com.cburch.logisim.tools.SetAttributeAction)1