use of com.cburch.logisim.circuit.Circuit in project logisim-evolution by reds-heig.
the class TtyInterface method run.
public static void run(Startup args) {
File fileToOpen = args.getFilesToOpen().get(0);
Loader loader = new Loader(null);
LogisimFile file;
try {
file = loader.openLogisimFile(fileToOpen, args.getSubstitutions());
} catch (LoadFailedException e) {
logger.error("{}", Strings.get("ttyLoadError", fileToOpen.getName()));
System.exit(-1);
return;
}
int format = args.getTtyFormat();
if ((format & FORMAT_STATISTICS) != 0) {
format &= ~FORMAT_STATISTICS;
displayStatistics(file);
}
if (format == 0) {
// no simulation remaining to perform, so just exit
System.exit(0);
}
Project proj = new Project(file);
Circuit circuit = file.getMainCircuit();
Map<Instance, String> pinNames = Analyze.getPinLabels(circuit);
ArrayList<Instance> outputPins = new ArrayList<Instance>();
Instance haltPin = null;
for (Map.Entry<Instance, String> entry : pinNames.entrySet()) {
Instance pin = entry.getKey();
String pinName = entry.getValue();
if (!Pin.FACTORY.isInputPin(pin)) {
outputPins.add(pin);
if (pinName.equals("halt")) {
haltPin = pin;
}
}
}
CircuitState circState = new CircuitState(proj, circuit);
// we have to do our initial propagation before the simulation starts -
// it's necessary to populate the circuit with substates.
circState.getPropagator().propagate();
if (args.getLoadFile() != null) {
try {
boolean loaded = loadRam(circState, args.getLoadFile());
if (!loaded) {
logger.error("{}", Strings.get("loadNoRamError"));
System.exit(-1);
}
} catch (IOException e) {
logger.error("{}: {}", Strings.get("loadIoError"), e.toString());
System.exit(-1);
}
}
int ttyFormat = args.getTtyFormat();
int simCode = runSimulation(circState, outputPins, haltPin, ttyFormat);
System.exit(simCode);
}
use of com.cburch.logisim.circuit.Circuit in project logisim-evolution by reds-heig.
the class ToolboxManip method selectionChanged.
public void selectionChanged(ProjectExplorerEvent event) {
Object selected = event.getTarget();
if (selected instanceof ProjectExplorerToolNode) {
Tool tool = ((ProjectExplorerToolNode) selected).getValue();
if (selected instanceof AddTool) {
AddTool addTool = (AddTool) tool;
ComponentFactory source = addTool.getFactory();
if (source instanceof SubcircuitFactory) {
SubcircuitFactory circFact = (SubcircuitFactory) source;
Circuit circ = circFact.getSubcircuit();
if (proj.getCurrentCircuit() == circ) {
AttrTableModel m = new AttrTableCircuitModel(proj, circ);
proj.getFrame().setAttrTableModel(m);
return;
}
}
}
// This was causing the selection to lag behind double-clicks,
// commented-out
// lastSelected = proj.getTool();
proj.setTool(tool);
proj.getFrame().viewAttributes(tool);
}
}
use of com.cburch.logisim.circuit.Circuit in project logisim-evolution by reds-heig.
the class ToolboxManip method menuRequested.
public JPopupMenu menuRequested(ProjectExplorerEvent event) {
Object clicked = event.getTarget();
if (clicked instanceof ProjectExplorerToolNode) {
Tool baseTool = ((ProjectExplorerToolNode) clicked).getValue();
if (baseTool instanceof AddTool) {
AddTool tool = (AddTool) baseTool;
ComponentFactory source = tool.getFactory();
if (source instanceof SubcircuitFactory) {
Circuit circ = ((SubcircuitFactory) source).getSubcircuit();
return Popups.forCircuit(proj, tool, circ);
} else {
return null;
}
} else {
return null;
}
} else if (clicked instanceof ProjectExplorerLibraryNode) {
Library lib = ((ProjectExplorerLibraryNode) clicked).getValue();
if (lib == proj.getLogisimFile()) {
return Popups.forProject(proj);
} else {
boolean is_top = event.getTreePath().getPathCount() <= 2;
return Popups.forLibrary(proj, lib, is_top);
}
} else {
return null;
}
}
use of com.cburch.logisim.circuit.Circuit in project logisim-evolution by reds-heig.
the class SelectionAttributes method setValue.
@Override
public <V> void setValue(Attribute<V> attr, V value) {
Circuit circ = canvas.getCircuit();
if (selected.isEmpty() && circ != null) {
circ.getStaticAttributes().setValue(attr, value);
} else {
int i = findIndex(attr);
Object[] vs = values;
if (i >= 0 && i < vs.length) {
vs[i] = value;
for (Component comp : selected) {
comp.getAttributeSet().setValue(attr, value);
}
}
}
}
use of com.cburch.logisim.circuit.Circuit in project logisim-evolution by reds-heig.
the class SelectionBase method hasConflictTranslated.
private boolean hasConflictTranslated(Collection<Component> components, int dx, int dy, boolean selfConflicts) {
Circuit circuit = proj.getCurrentCircuit();
if (circuit == null)
return false;
for (Component comp : components) {
if (!(comp instanceof Wire)) {
for (EndData endData : comp.getEnds()) {
if (endData != null && endData.isExclusive()) {
Location endLoc = endData.getLocation().translate(dx, dy);
Component conflict = circuit.getExclusive(endLoc);
if (conflict != null) {
if (selfConflicts || !components.contains(conflict))
return true;
}
}
}
Location newLoc = comp.getLocation().translate(dx, dy);
Bounds newBounds = comp.getBounds().translate(dx, dy);
for (Component comp2 : circuit.getAllContaining(newLoc)) {
Bounds bds = comp2.getBounds();
if (bds.equals(newBounds)) {
if (selfConflicts || !components.contains(comp2))
return true;
}
}
}
}
return false;
}
Aggregations