Search in sources :

Example 6 with SubcircuitFactory

use of com.cburch.logisim.circuit.SubcircuitFactory in project logisim-evolution by reds-heig.

the class AttrTableSelectionModel method setValueRequested.

@Override
public void setValueRequested(Attribute<Object> attr, Object value) throws AttrTableSetException {
    Selection selection = frame.getCanvas().getSelection();
    Circuit circuit = frame.getCanvas().getCircuit();
    if (selection.isEmpty() && circuit != null) {
        AttrTableCircuitModel circuitModel = new AttrTableCircuitModel(project, circuit);
        circuitModel.setValueRequested(attr, value);
    } else {
        SetAttributeAction act = new SetAttributeAction(circuit, Strings.getter("selectionAttributeAction"));
        AutoLabel labler = null;
        if (attr.equals(StdAttr.LABEL)) {
            labler = new AutoLabel((String) value, circuit);
        }
        SortedSet<Component> comps = new TreeSet<Component>(new PositionComparator());
        comps.addAll(selection.getComponents());
        for (Component comp : comps) {
            if (!(comp instanceof Wire)) {
                if (comp.getFactory() instanceof SubcircuitFactory) {
                    SubcircuitFactory fac = (SubcircuitFactory) comp.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);
                            project.doAction(action);
                        } catch (CircuitException ex) {
                            JOptionPane.showMessageDialog(project.getFrame(), ex.getMessage());
                        }
                        return;
                    }
                }
                if (attr.equals(StdAttr.LABEL)) {
                    if (labler.hasNext(circuit)) {
                        if (comps.size() > 1) {
                            act.set(comp, attr, labler.GetNext(circuit, comp.getFactory()));
                        } else {
                            if (getAttributeSet().getValue(StdAttr.LABEL).equals((String) value))
                                return;
                            else
                                act.set(comp, attr, labler.GetCurrent(circuit, comp.getFactory()));
                        }
                    } else
                        act.set(comp, attr, "");
                } else
                    act.set(comp, attr, value);
            }
        }
        project.doAction(act);
    }
}
Also used : Action(com.cburch.logisim.proj.Action) SetAttributeAction(com.cburch.logisim.tools.SetAttributeAction) CircuitException(com.cburch.logisim.circuit.CircuitException) AutoLabel(com.cburch.logisim.util.AutoLabel) Circuit(com.cburch.logisim.circuit.Circuit) SetAttributeAction(com.cburch.logisim.tools.SetAttributeAction) Wire(com.cburch.logisim.circuit.Wire) TreeSet(java.util.TreeSet) SubcircuitFactory(com.cburch.logisim.circuit.SubcircuitFactory) CircuitMutation(com.cburch.logisim.circuit.CircuitMutation) Component(com.cburch.logisim.comp.Component)

Example 7 with SubcircuitFactory

use of com.cburch.logisim.circuit.SubcircuitFactory in project logisim-evolution by reds-heig.

the class SelectionItem method fetchValue.

public Value fetchValue(CircuitState root) {
    CircuitState cur = root;
    for (int i = 0; i < path.length; i++) {
        SubcircuitFactory circFact = (SubcircuitFactory) path[i].getFactory();
        cur = circFact.getSubstate(cur, path[i]);
    }
    Loggable log = (Loggable) comp.getFeature(Loggable.class);
    return log == null ? Value.NIL : log.getLogValue(cur, option);
}
Also used : CircuitState(com.cburch.logisim.circuit.CircuitState) SubcircuitFactory(com.cburch.logisim.circuit.SubcircuitFactory)

Example 8 with SubcircuitFactory

use of com.cburch.logisim.circuit.SubcircuitFactory in project logisim-evolution by reds-heig.

the class AddTool method mousePressed.

@Override
public void mousePressed(Canvas canvas, Graphics g, MouseEvent e) {
    // verify the addition would be valid
    Circuit circ = canvas.getCircuit();
    if (!canvas.getProject().getLogisimFile().contains(circ)) {
        canvas.setErrorMessage(Strings.getter("cannotModifyError"));
        return;
    }
    if (factory instanceof SubcircuitFactory) {
        SubcircuitFactory circFact = (SubcircuitFactory) factory;
        Dependencies depends = canvas.getProject().getDependencies();
        if (!depends.canAdd(circ, circFact.getSubcircuit())) {
            canvas.setErrorMessage(Strings.getter("circularError"));
            return;
        }
    }
    if (shouldSnap)
        Canvas.snapToGrid(e);
    moveTo(canvas, g, e.getX(), e.getY());
    setState(canvas, SHOW_ADD);
}
Also used : SubcircuitFactory(com.cburch.logisim.circuit.SubcircuitFactory) Circuit(com.cburch.logisim.circuit.Circuit) Dependencies(com.cburch.logisim.proj.Dependencies)

Example 9 with SubcircuitFactory

use of com.cburch.logisim.circuit.SubcircuitFactory in project logisim-evolution by reds-heig.

the class FileStatistics method doRecursiveCount.

private static Map<ComponentFactory, Count> doRecursiveCount(Circuit circuit, Set<Circuit> include, Map<Circuit, Map<ComponentFactory, Count>> countMap) {
    if (countMap.containsKey(circuit)) {
        return countMap.get(circuit);
    }
    Map<ComponentFactory, Count> counts = doSimpleCount(circuit);
    countMap.put(circuit, counts);
    for (Count count : counts.values()) {
        count.uniqueCount = count.simpleCount;
        count.recursiveCount = count.simpleCount;
    }
    for (Circuit sub : include) {
        SubcircuitFactory subFactory = sub.getSubcircuitFactory();
        if (counts.containsKey(subFactory)) {
            int multiplier = counts.get(subFactory).simpleCount;
            Map<ComponentFactory, Count> subCount;
            subCount = doRecursiveCount(sub, include, countMap);
            for (Count subcount : subCount.values()) {
                ComponentFactory subfactory = subcount.factory;
                Count supercount = counts.get(subfactory);
                if (supercount == null) {
                    supercount = new Count(subfactory);
                    counts.put(subfactory, supercount);
                }
                supercount.recursiveCount += multiplier * subcount.recursiveCount;
            }
        }
    }
    return counts;
}
Also used : ComponentFactory(com.cburch.logisim.comp.ComponentFactory) SubcircuitFactory(com.cburch.logisim.circuit.SubcircuitFactory) Circuit(com.cburch.logisim.circuit.Circuit)

Example 10 with SubcircuitFactory

use of com.cburch.logisim.circuit.SubcircuitFactory in project logisim-evolution by reds-heig.

the class LogisimFile method getCircuits.

public List<Circuit> getCircuits() {
    List<Circuit> ret = new ArrayList<Circuit>(tools.size());
    for (AddTool tool : tools) {
        SubcircuitFactory factory = (SubcircuitFactory) tool.getFactory();
        ret.add(factory.getSubcircuit());
    }
    return ret;
}
Also used : ArrayList(java.util.ArrayList) SubcircuitFactory(com.cburch.logisim.circuit.SubcircuitFactory) Circuit(com.cburch.logisim.circuit.Circuit) AddTool(com.cburch.logisim.tools.AddTool)

Aggregations

SubcircuitFactory (com.cburch.logisim.circuit.SubcircuitFactory)32 ArrayList (java.util.ArrayList)13 Circuit (com.cburch.logisim.circuit.Circuit)12 Component (com.cburch.logisim.comp.Component)8 ComponentFactory (com.cburch.logisim.comp.ComponentFactory)8 AddTool (com.cburch.logisim.tools.AddTool)8 Tool (com.cburch.logisim.tools.Tool)6 InstanceComponent (com.cburch.logisim.instance.InstanceComponent)5 ProjectExplorerToolNode (com.cburch.logisim.gui.generic.ProjectExplorerToolNode)4 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 Wire (com.cburch.logisim.circuit.Wire)3 Pin (com.cburch.logisim.std.wiring.Pin)3 Library (com.cburch.logisim.tools.Library)3 NetlistComponent (com.bfh.logisim.designrulecheck.NetlistComponent)2 CircuitException (com.cburch.logisim.circuit.CircuitException)2 CircuitMutation (com.cburch.logisim.circuit.CircuitMutation)2 CircuitState (com.cburch.logisim.circuit.CircuitState)2 EndData (com.cburch.logisim.comp.EndData)2 ProjectExplorerLibraryNode (com.cburch.logisim.gui.generic.ProjectExplorerLibraryNode)2