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);
}
}
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);
}
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);
}
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;
}
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;
}
Aggregations