use of com.cburch.logisim.circuit.CircuitState in project logisim-evolution by reds-heig.
the class SimulationExplorer method projectChanged.
//
// ProjectListener methods
//
public void projectChanged(ProjectEvent event) {
int action = event.getAction();
if (action == ProjectEvent.ACTION_SET_STATE) {
Simulator sim = project.getSimulator();
CircuitState root = sim.getCircuitState();
if (model.getRootState() != root) {
model = new SimulationTreeModel(root);
tree.setModel(model);
}
model.setCurrentView(project.getCircuitState());
TreePath path = model.mapToPath(project.getCircuitState());
if (path != null) {
tree.scrollPathToVisible(path);
}
}
}
use of com.cburch.logisim.circuit.CircuitState in project logisim-evolution by reds-heig.
the class LayoutPopupManager method showPopup.
private void showPopup(Set<AppearancePort> portObjects) {
dragStart = null;
CircuitState circuitState = canvas.getCircuitState();
if (circuitState == null)
return;
ArrayList<Instance> ports = new ArrayList<Instance>(portObjects.size());
for (AppearancePort portObject : portObjects) {
ports.add(portObject.getPin());
}
hideCurrentPopup();
LayoutThumbnail layout = new LayoutThumbnail();
layout.setCircuit(circuitState, ports);
JViewport owner = canvasPane.getViewport();
Point ownerLoc = owner.getLocationOnScreen();
Dimension ownerDim = owner.getSize();
Dimension layoutDim = layout.getPreferredSize();
int x = ownerLoc.x + Math.max(0, ownerDim.width - layoutDim.width - 5);
int y = ownerLoc.y + Math.max(0, ownerDim.height - layoutDim.height - 5);
PopupFactory factory = PopupFactory.getSharedInstance();
Popup popup = factory.getPopup(canvasPane.getViewport(), layout, x, y);
popup.show();
curPopup = popup;
curPopupTime = System.currentTimeMillis();
}
use of com.cburch.logisim.circuit.CircuitState in project logisim-evolution by reds-heig.
the class RegTabContent method fillArray.
/**
* This function will clear and fill the registers tab and refresh their
* value. It will start by iterate over all circuits of the current project
* to register all the "Register" components (providing their attributes are
* correctly set). It will then fill the panel with each register found,
* including their current value.
*/
private void fillArray() {
int y = 0;
MyLabel col1 = new MyLabel("Circuit", Font.ITALIC | Font.BOLD);
MyLabel col2 = new MyLabel("Reg name", Font.BOLD);
MyLabel col3 = new MyLabel("Value", Font.BOLD);
registers.clear();
panel.removeAll();
for (Circuit circ : proj.getLogisimFile().getCircuits()) {
getAllRegisters(circ);
}
if (proj.getLogisimFile().getLibrary("prodis_v1.3") instanceof LoadedLibrary) {
if (((LoadedLibrary) proj.getLogisimFile().getLibrary("prodis_v1.3")).getBase() instanceof LogisimFile) {
for (Circuit circ : ((LogisimFile) ((LoadedLibrary) proj.getLogisimFile().getLibrary("prodis_v1.3")).getBase()).getCircuits()) {
getAllRegisters(circ);
}
}
}
col1.setColor(Color.LIGHT_GRAY);
col2.setColor(Color.LIGHT_GRAY);
col3.setColor(Color.LIGHT_GRAY);
c.fill = GridBagConstraints.HORIZONTAL;
c.anchor = GridBagConstraints.FIRST_LINE_START;
c.ipady = 2;
c.weighty = 0;
c.gridy = y;
c.gridx = 0;
c.weightx = 0.3;
panel.add(col1, c);
c.gridx++;
c.weightx = 0.5;
panel.add(col2, c);
c.gridx++;
c.weightx = 0.2;
panel.add(col3, c);
y++;
if (!registers.isEmpty()) {
Object[] objArr = registers.keySet().toArray();
Arrays.sort(objArr);
for (Object name : objArr) {
c.gridy = y;
c.gridx = 0;
String circuitName = name.toString().split("/")[0];
panel.add(new MyLabel(circuitName, Font.ITALIC, true), c);
c.gridx++;
String registerName = name.toString().split("/")[1];
panel.add(new MyLabel(registerName), c);
c.gridx++;
Component selReg = registers.get(name.toString());
CircuitState mainCircState = proj.getCircuitState();
while (mainCircState.getParentState() != null) {
// Get the main
// circuit
mainCircState = mainCircState.getParentState();
}
Value val = findVal(mainCircState, circuitName, selReg.getEnd(0).getLocation());
if (val != null) {
panel.add(new MyLabel(val.toHexString()), c);
} else {
panel.add(new MyLabel("-"), c);
}
y++;
}
}
c.weighty = 1;
c.gridy++;
c.gridx = 0;
c.weightx = 1;
panel.add(new MyLabel(""), c);
panel.validate();
}
use of com.cburch.logisim.circuit.CircuitState in project logisim-evolution by reds-heig.
the class Model method propagationCompleted.
public void propagationCompleted() {
CircuitState circuitState = getCircuitState();
Value[] vals = new Value[selection.size()];
boolean changed = false;
for (int i = selection.size() - 1; i >= 0; i--) {
SelectionItem item = selection.get(i);
vals[i] = item.fetchValue(circuitState);
if (!changed) {
Value v = getValueLog(item).getLast();
changed = v == null ? vals[i] != null : !v.equals(vals[i]);
}
}
if (changed) {
for (int i = selection.size() - 1; i >= 0; i--) {
SelectionItem item = selection.get(i);
getValueLog(item).append(vals[i]);
}
fireEntryAdded(new ModelEvent(), vals);
}
}
use of com.cburch.logisim.circuit.CircuitState 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);
}
Aggregations