Search in sources :

Example 1 with CircuitState

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);
        }
    }
}
Also used : CircuitState(com.cburch.logisim.circuit.CircuitState) TreePath(javax.swing.tree.TreePath) Simulator(com.cburch.logisim.circuit.Simulator)

Example 2 with CircuitState

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();
}
Also used : CircuitState(com.cburch.logisim.circuit.CircuitState) AppearancePort(com.cburch.logisim.circuit.appear.AppearancePort) PopupFactory(javax.swing.PopupFactory) Instance(com.cburch.logisim.instance.Instance) JViewport(javax.swing.JViewport) Popup(javax.swing.Popup) ArrayList(java.util.ArrayList) Point(java.awt.Point) Dimension(java.awt.Dimension) Point(java.awt.Point)

Example 3 with CircuitState

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();
}
Also used : CircuitState(com.cburch.logisim.circuit.CircuitState) LogisimFile(com.cburch.logisim.file.LogisimFile) Value(com.cburch.logisim.data.Value) Circuit(com.cburch.logisim.circuit.Circuit) LoadedLibrary(com.cburch.logisim.file.LoadedLibrary) Component(com.cburch.logisim.comp.Component)

Example 4 with CircuitState

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);
    }
}
Also used : CircuitState(com.cburch.logisim.circuit.CircuitState) Value(com.cburch.logisim.data.Value)

Example 5 with CircuitState

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);
}
Also used : CircuitState(com.cburch.logisim.circuit.CircuitState) SubcircuitFactory(com.cburch.logisim.circuit.SubcircuitFactory)

Aggregations

CircuitState (com.cburch.logisim.circuit.CircuitState)26 Component (com.cburch.logisim.comp.Component)6 Circuit (com.cburch.logisim.circuit.Circuit)5 ArrayList (java.util.ArrayList)4 ComponentDrawContext (com.cburch.logisim.comp.ComponentDrawContext)3 Location (com.cburch.logisim.data.Location)3 Instance (com.cburch.logisim.instance.Instance)3 InstanceState (com.cburch.logisim.instance.InstanceState)3 Color (java.awt.Color)3 Dimension (java.awt.Dimension)3 Simulator (com.cburch.logisim.circuit.Simulator)2 SubcircuitFactory (com.cburch.logisim.circuit.SubcircuitFactory)2 Bounds (com.cburch.logisim.data.Bounds)2 Value (com.cburch.logisim.data.Value)2 LogisimFile (com.cburch.logisim.file.LogisimFile)2 Graphics (java.awt.Graphics)2 TreePath (javax.swing.tree.TreePath)2 CircuitListener (com.cburch.logisim.circuit.CircuitListener)1 SimulatorEvent (com.cburch.logisim.circuit.SimulatorEvent)1 AppearancePort (com.cburch.logisim.circuit.appear.AppearancePort)1