Search in sources :

Example 16 with Tool

use of com.cburch.logisim.tools.Tool in project logisim-evolution by reds-heig.

the class LogisimFile method removeCircuit.

public void removeCircuit(Circuit circuit) {
    if (tools.size() <= 1) {
        throw new RuntimeException("Cannot remove last circuit");
    }
    int index = getCircuits().indexOf(circuit);
    if (index >= 0) {
        Tool circuitTool = tools.remove(index);
        if (main == circuit) {
            AddTool dflt_tool = tools.get(0);
            SubcircuitFactory factory = (SubcircuitFactory) dflt_tool.getFactory();
            setMainCircuit(factory.getSubcircuit());
        }
        fireEvent(LibraryEvent.REMOVE_TOOL, circuitTool);
    }
}
Also used : SubcircuitFactory(com.cburch.logisim.circuit.SubcircuitFactory) AddTool(com.cburch.logisim.tools.AddTool) Tool(com.cburch.logisim.tools.Tool) AddTool(com.cburch.logisim.tools.AddTool)

Example 17 with Tool

use of com.cburch.logisim.tools.Tool in project logisim-evolution by reds-heig.

the class Project method setTool.

public void setTool(Tool value) {
    if (tool == value)
        return;
    Tool old = tool;
    Canvas canvas = frame.getCanvas();
    if (old != null)
        old.deselect(canvas);
    Selection selection = canvas.getSelection();
    if (selection != null && !selection.isEmpty()) {
        if (value == null || !getOptions().getMouseMappings().containsSelectTool()) {
            Action act = SelectionActions.anchorAll(selection);
            /*
				 * Circuit circuit = canvas.getCircuit(); CircuitMutation xn =
				 * new CircuitMutation(circuit); if (value == null) { Action act
				 * = SelectionActions.dropAll(selection); if (act != null) {
				 * doAction(act); } } else if
				 * (!getOptions().getMouseMappings().containsSelectTool()) {
				 * Action act = SelectionActions.dropAll(selection);
				 */
            if (act != null) {
                doAction(act);
            }
        }
    /*
			 * if (!xn.isEmpty()) doAction(xn.toAction(null));
			 */
    }
    startupScreen = false;
    tool = value;
    if (tool != null)
        tool.select(frame.getCanvas());
    fireEvent(ProjectEvent.ACTION_SET_TOOL, old, tool);
}
Also used : Selection(com.cburch.logisim.gui.main.Selection) Canvas(com.cburch.logisim.gui.main.Canvas) Tool(com.cburch.logisim.tools.Tool) AddTool(com.cburch.logisim.tools.AddTool)

Example 18 with Tool

use of com.cburch.logisim.tools.Tool in project logisim-evolution by reds-heig.

the class ProjectActions method doSave.

private static boolean doSave(Project proj, File f) {
    Loader loader = proj.getLogisimFile().getLoader();
    Tool oldTool = proj.getTool();
    proj.setTool(null);
    boolean ret = loader.save(proj.getLogisimFile(), f);
    if (ret) {
        AppPreferences.updateRecentFile(f);
        proj.setFileAsClean();
    }
    proj.setTool(oldTool);
    return ret;
}
Also used : Loader(com.cburch.logisim.file.Loader) Tool(com.cburch.logisim.tools.Tool)

Example 19 with Tool

use of com.cburch.logisim.tools.Tool in project logisim-evolution by reds-heig.

the class CanvasPainter method drawWithUserState.

private void drawWithUserState(Graphics base, Graphics g, Project proj) {
    Circuit circ = proj.getCurrentCircuit();
    Selection sel = proj.getSelection();
    Set<Component> hidden;
    Tool dragTool = canvas.getDragTool();
    if (dragTool == null) {
        hidden = NO_COMPONENTS;
    } else {
        hidden = dragTool.getHiddenComponents(canvas);
        if (hidden == null)
            hidden = NO_COMPONENTS;
    }
    // draw halo around component whose attributes we are viewing
    boolean showHalo = AppPreferences.ATTRIBUTE_HALO.getBoolean();
    if (showHalo && haloedComponent != null && haloedCircuit == circ && !hidden.contains(haloedComponent)) {
        GraphicsUtil.switchToWidth(g, 3);
        g.setColor(Canvas.HALO_COLOR);
        Bounds bds = haloedComponent.getBounds(g).expand(5);
        int w = bds.getWidth();
        int h = bds.getHeight();
        double a = Canvas.SQRT_2 * w;
        double b = Canvas.SQRT_2 * h;
        g.drawOval((int) Math.round(bds.getX() + w / 2.0 - a / 2.0), (int) Math.round(bds.getY() + h / 2.0 - b / 2.0), (int) Math.round(a), (int) Math.round(b));
        GraphicsUtil.switchToWidth(g, 1);
        g.setColor(Color.BLACK);
    }
    // draw circuit and selection
    CircuitState circState = proj.getCircuitState();
    boolean printerView = AppPreferences.PRINTER_VIEW.getBoolean();
    ComponentDrawContext context = new ComponentDrawContext(canvas, circ, circState, base, g, printerView);
    context.setHighlightedWires(highlightedWires);
    circ.draw(context, hidden);
    sel.draw(context, hidden);
    // draw tool
    Tool tool = dragTool != null ? dragTool : proj.getTool();
    if (tool != null && !canvas.isPopupMenuUp()) {
        Graphics gCopy = g.create();
        context.setGraphics(gCopy);
        tool.draw(canvas, context);
        gCopy.dispose();
    }
}
Also used : CircuitState(com.cburch.logisim.circuit.CircuitState) Graphics(java.awt.Graphics) ComponentDrawContext(com.cburch.logisim.comp.ComponentDrawContext) Bounds(com.cburch.logisim.data.Bounds) Circuit(com.cburch.logisim.circuit.Circuit) Component(com.cburch.logisim.comp.Component) Tool(com.cburch.logisim.tools.Tool)

Example 20 with Tool

use of com.cburch.logisim.tools.Tool in project logisim-evolution by reds-heig.

the class LayoutToolbarModel method itemSelected.

@Override
public void itemSelected(ToolbarItem item) {
    if (item instanceof ToolItem) {
        Tool tool = ((ToolItem) item).tool;
        proj.setTool(tool);
    }
}
Also used : Tool(com.cburch.logisim.tools.Tool)

Aggregations

Tool (com.cburch.logisim.tools.Tool)28 AddTool (com.cburch.logisim.tools.AddTool)16 ComponentFactory (com.cburch.logisim.comp.ComponentFactory)9 Library (com.cburch.logisim.tools.Library)7 Circuit (com.cburch.logisim.circuit.Circuit)6 SubcircuitFactory (com.cburch.logisim.circuit.SubcircuitFactory)6 ProjectExplorerToolNode (com.cburch.logisim.gui.generic.ProjectExplorerToolNode)4 SelectTool (com.cburch.logisim.tools.SelectTool)4 Component (com.cburch.logisim.comp.Component)3 ArrayList (java.util.ArrayList)3 Element (org.w3c.dom.Element)3 AttributeSet (com.cburch.logisim.data.AttributeSet)2 ProjectExplorerLibraryNode (com.cburch.logisim.gui.generic.ProjectExplorerLibraryNode)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 ToolbarItem (com.cburch.draw.toolbar.ToolbarItem)1 ToolbarSeparator (com.cburch.draw.toolbar.ToolbarSeparator)1 CircuitState (com.cburch.logisim.circuit.CircuitState)1 ComponentDrawContext (com.cburch.logisim.comp.ComponentDrawContext)1