use of com.cburch.logisim.circuit.Circuit 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.Circuit in project logisim-evolution by reds-heig.
the class EditTool method mousePressed.
@Override
public void mousePressed(Canvas canvas, Graphics g, MouseEvent e) {
boolean wire = updateLocation(canvas, e);
Location oldWireLoc = wireLoc;
wireLoc = NULL_LOCATION;
lastX = Integer.MIN_VALUE;
if (wire) {
current = wiring;
Selection sel = canvas.getSelection();
Circuit circ = canvas.getCircuit();
Collection<Component> selected = sel.getAnchoredComponents();
ArrayList<Component> suppress = null;
for (Wire w : circ.getWires()) {
if (selected.contains(w)) {
if (w.contains(oldWireLoc)) {
if (suppress == null)
suppress = new ArrayList<Component>();
suppress.add(w);
}
}
}
sel.setSuppressHandles(suppress);
} else {
current = select;
}
pressX = e.getX();
pressY = e.getY();
current.mousePressed(canvas, g, e);
}
use of com.cburch.logisim.circuit.Circuit in project logisim-evolution by reds-heig.
the class EditTool method attemptReface.
private void attemptReface(Canvas canvas, final Direction facing, KeyEvent e) {
if (e.getModifiersEx() == 0) {
final Circuit circuit = canvas.getCircuit();
final Selection sel = canvas.getSelection();
SetAttributeAction act = new SetAttributeAction(circuit, Strings.getter("selectionRefaceAction"));
for (Component comp : sel.getComponents()) {
if (!(comp instanceof Wire)) {
Attribute<Direction> attr = getFacingAttribute(comp);
if (attr != null) {
act.set(comp, attr, facing);
}
}
}
if (!act.isEmpty()) {
canvas.getProject().doAction(act);
e.consume();
}
}
}
use of com.cburch.logisim.circuit.Circuit in project logisim-evolution by reds-heig.
the class TextTool method mousePressed.
@Override
public void mousePressed(Canvas canvas, Graphics g, MouseEvent e) {
Project proj = canvas.getProject();
Circuit circ = canvas.getCircuit();
if (!proj.getLogisimFile().contains(circ)) {
if (caret != null)
caret.cancelEditing();
canvas.setErrorMessage(Strings.getter("cannotModifyError"));
return;
}
// Maybe user is clicking within the current caret.
if (caret != null) {
if (caret.getBounds(g).contains(e.getX(), e.getY())) {
// Yes
caret.mousePressed(e);
proj.repaintCanvas();
return;
} else {
// No. End the current caret.
caret.stopEditing();
}
}
// caret will be null at this point
// Otherwise search for a new caret.
int x = e.getX();
int y = e.getY();
Location loc = Location.create(x, y);
ComponentUserEvent event = new ComponentUserEvent(canvas, x, y);
// First search in selection.
for (Component comp : proj.getSelection().getComponentsContaining(loc, g)) {
TextEditable editable = (TextEditable) comp.getFeature(TextEditable.class);
if (editable != null) {
caret = editable.getTextCaret(event);
if (caret != null) {
proj.getFrame().viewComponentAttributes(circ, comp);
caretComponent = comp;
caretCreatingText = false;
break;
}
}
}
// Then search in circuit
if (caret == null) {
for (Component comp : circ.getAllContaining(loc, g)) {
TextEditable editable = (TextEditable) comp.getFeature(TextEditable.class);
if (editable != null) {
caret = editable.getTextCaret(event);
if (caret != null) {
proj.getFrame().viewComponentAttributes(circ, comp);
caretComponent = comp;
caretCreatingText = false;
break;
}
}
}
}
// if nothing found, create a new label
if (caret == null) {
if (loc.getX() < 0 || loc.getY() < 0)
return;
AttributeSet copy = (AttributeSet) attrs.clone();
caretComponent = Text.FACTORY.createComponent(loc, copy);
caretCreatingText = true;
TextEditable editable = (TextEditable) caretComponent.getFeature(TextEditable.class);
if (editable != null) {
caret = editable.getTextCaret(event);
proj.getFrame().viewComponentAttributes(circ, caretComponent);
}
}
if (caret != null) {
caretCanvas = canvas;
caretCircuit = canvas.getCircuit();
caret.addCaretListener(listener);
caretCircuit.addCircuitListener(listener);
}
proj.repaintCanvas();
}
use of com.cburch.logisim.circuit.Circuit 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;
}
Aggregations