Search in sources :

Example 31 with Circuit

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);
}
Also used : CircuitState(com.cburch.logisim.circuit.CircuitState) Instance(com.cburch.logisim.instance.Instance) ArrayList(java.util.ArrayList) Loader(com.cburch.logisim.file.Loader) Circuit(com.cburch.logisim.circuit.Circuit) IOException(java.io.IOException) Project(com.cburch.logisim.proj.Project) LogisimFile(com.cburch.logisim.file.LogisimFile) LogisimFile(com.cburch.logisim.file.LogisimFile) File(java.io.File) Map(java.util.Map) LoadFailedException(com.cburch.logisim.file.LoadFailedException)

Example 32 with Circuit

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);
    }
}
Also used : ProjectExplorerToolNode(com.cburch.logisim.gui.generic.ProjectExplorerToolNode) ComponentFactory(com.cburch.logisim.comp.ComponentFactory) AttrTableModel(com.cburch.logisim.gui.generic.AttrTableModel) SubcircuitFactory(com.cburch.logisim.circuit.SubcircuitFactory) Circuit(com.cburch.logisim.circuit.Circuit) AddTool(com.cburch.logisim.tools.AddTool) Tool(com.cburch.logisim.tools.Tool) AddTool(com.cburch.logisim.tools.AddTool)

Example 33 with Circuit

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;
    }
}
Also used : ProjectExplorerToolNode(com.cburch.logisim.gui.generic.ProjectExplorerToolNode) ComponentFactory(com.cburch.logisim.comp.ComponentFactory) SubcircuitFactory(com.cburch.logisim.circuit.SubcircuitFactory) Circuit(com.cburch.logisim.circuit.Circuit) AddTool(com.cburch.logisim.tools.AddTool) ProjectExplorerLibraryNode(com.cburch.logisim.gui.generic.ProjectExplorerLibraryNode) Library(com.cburch.logisim.tools.Library) Tool(com.cburch.logisim.tools.Tool) AddTool(com.cburch.logisim.tools.AddTool)

Example 34 with Circuit

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

Example 35 with Circuit

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;
}
Also used : EndData(com.cburch.logisim.comp.EndData) Bounds(com.cburch.logisim.data.Bounds) Circuit(com.cburch.logisim.circuit.Circuit) Component(com.cburch.logisim.comp.Component) Wire(com.cburch.logisim.circuit.Wire) Location(com.cburch.logisim.data.Location)

Aggregations

Circuit (com.cburch.logisim.circuit.Circuit)62 Component (com.cburch.logisim.comp.Component)19 SubcircuitFactory (com.cburch.logisim.circuit.SubcircuitFactory)12 Project (com.cburch.logisim.proj.Project)11 ArrayList (java.util.ArrayList)9 Wire (com.cburch.logisim.circuit.Wire)8 ComponentFactory (com.cburch.logisim.comp.ComponentFactory)8 Location (com.cburch.logisim.data.Location)8 Bounds (com.cburch.logisim.data.Bounds)6 LogisimFile (com.cburch.logisim.file.LogisimFile)6 AddTool (com.cburch.logisim.tools.AddTool)6 Tool (com.cburch.logisim.tools.Tool)6 CircuitState (com.cburch.logisim.circuit.CircuitState)5 AttributeSet (com.cburch.logisim.data.AttributeSet)5 Selection (com.cburch.logisim.gui.main.Selection)5 Action (com.cburch.logisim.proj.Action)4 CircuitMutation (com.cburch.logisim.circuit.CircuitMutation)3 ComponentDrawContext (com.cburch.logisim.comp.ComponentDrawContext)3 Graphics (java.awt.Graphics)3 CanvasObject (com.cburch.draw.model.CanvasObject)2