Search in sources :

Example 11 with Circuit

use of com.cburch.logisim.circuit.Circuit in project logisim-evolution by reds-heig.

the class AppearanceCanvas method setCircuit.

public void setCircuit(Project proj, CircuitState circuitState) {
    this.proj = proj;
    this.circuitState = circuitState;
    Circuit circuit = circuitState.getCircuit();
    setModel(circuit.getAppearance(), this);
}
Also used : Circuit(com.cburch.logisim.circuit.Circuit)

Example 12 with Circuit

use of com.cburch.logisim.circuit.Circuit in project logisim-evolution by reds-heig.

the class AppearanceEditHandler method computeEnabled.

@Override
public void computeEnabled() {
    Project proj = canvas.getProject();
    Circuit circ = canvas.getCircuit();
    Selection sel = canvas.getSelection();
    boolean selEmpty = sel.isEmpty();
    boolean canChange = proj.getLogisimFile().contains(circ);
    boolean clipExists = !Clipboard.isEmpty();
    boolean selHasRemovable = false;
    for (CanvasObject o : sel.getSelected()) {
        if (!(o instanceof AppearanceElement)) {
            selHasRemovable = true;
        }
    }
    boolean canRaise;
    boolean canLower;
    if (!selEmpty && canChange) {
        Map<CanvasObject, Integer> zs = ZOrder.getZIndex(sel.getSelected(), canvas.getModel());
        int zmin = Integer.MAX_VALUE;
        int zmax = Integer.MIN_VALUE;
        int count = 0;
        for (Map.Entry<CanvasObject, Integer> entry : zs.entrySet()) {
            if (!(entry.getKey() instanceof AppearanceElement)) {
                count++;
                int z = entry.getValue().intValue();
                if (z < zmin)
                    zmin = z;
                if (z > zmax)
                    zmax = z;
            }
        }
        int maxPoss = AppearanceCanvas.getMaxIndex(canvas.getModel());
        if (count > 0 && count <= maxPoss) {
            canRaise = zmin <= maxPoss - count;
            canLower = zmax >= count;
        } else {
            canRaise = false;
            canLower = false;
        }
    } else {
        canRaise = false;
        canLower = false;
    }
    boolean canAddCtrl = false;
    boolean canRemCtrl = false;
    Handle handle = sel.getSelectedHandle();
    if (handle != null && canChange) {
        CanvasObject o = handle.getObject();
        canAddCtrl = o.canInsertHandle(handle.getLocation()) != null;
        canRemCtrl = o.canDeleteHandle(handle.getLocation()) != null;
    }
    setEnabled(LogisimMenuBar.CUT, selHasRemovable && canChange);
    setEnabled(LogisimMenuBar.COPY, !selEmpty);
    setEnabled(LogisimMenuBar.PASTE, canChange && clipExists);
    setEnabled(LogisimMenuBar.DELETE, selHasRemovable && canChange);
    setEnabled(LogisimMenuBar.DUPLICATE, !selEmpty && canChange);
    setEnabled(LogisimMenuBar.SELECT_ALL, true);
    setEnabled(LogisimMenuBar.RAISE, canRaise);
    setEnabled(LogisimMenuBar.LOWER, canLower);
    setEnabled(LogisimMenuBar.RAISE_TOP, canRaise);
    setEnabled(LogisimMenuBar.LOWER_BOTTOM, canLower);
    setEnabled(LogisimMenuBar.ADD_CONTROL, canAddCtrl);
    setEnabled(LogisimMenuBar.REMOVE_CONTROL, canRemCtrl);
}
Also used : Project(com.cburch.logisim.proj.Project) CanvasObject(com.cburch.draw.model.CanvasObject) Selection(com.cburch.draw.canvas.Selection) Circuit(com.cburch.logisim.circuit.Circuit) AppearanceElement(com.cburch.logisim.circuit.appear.AppearanceElement) Map(java.util.Map) Handle(com.cburch.draw.model.Handle)

Example 13 with Circuit

use of com.cburch.logisim.circuit.Circuit in project logisim-evolution by reds-heig.

the class AttrTableSelectionModel method setValueRequested.

@Override
public void setValueRequested(Attribute<Object> attr, Object value) throws AttrTableSetException {
    Selection selection = frame.getCanvas().getSelection();
    Circuit circuit = frame.getCanvas().getCircuit();
    if (selection.isEmpty() && circuit != null) {
        AttrTableCircuitModel circuitModel = new AttrTableCircuitModel(project, circuit);
        circuitModel.setValueRequested(attr, value);
    } else {
        SetAttributeAction act = new SetAttributeAction(circuit, Strings.getter("selectionAttributeAction"));
        AutoLabel labler = null;
        if (attr.equals(StdAttr.LABEL)) {
            labler = new AutoLabel((String) value, circuit);
        }
        SortedSet<Component> comps = new TreeSet<Component>(new PositionComparator());
        comps.addAll(selection.getComponents());
        for (Component comp : comps) {
            if (!(comp instanceof Wire)) {
                if (comp.getFactory() instanceof SubcircuitFactory) {
                    SubcircuitFactory fac = (SubcircuitFactory) comp.getFactory();
                    if (attr.equals(CircuitAttributes.NAMED_CIRCUIT_BOX) || attr.equals(CircuitAttributes.NAME_ATTR)) {
                        try {
                            CircuitMutation mutation = new CircuitMutation(fac.getSubcircuit());
                            mutation.setForCircuit(attr, value);
                            Action action = mutation.toAction(null);
                            project.doAction(action);
                        } catch (CircuitException ex) {
                            JOptionPane.showMessageDialog(project.getFrame(), ex.getMessage());
                        }
                        return;
                    }
                }
                if (attr.equals(StdAttr.LABEL)) {
                    if (labler.hasNext(circuit)) {
                        if (comps.size() > 1) {
                            act.set(comp, attr, labler.GetNext(circuit, comp.getFactory()));
                        } else {
                            if (getAttributeSet().getValue(StdAttr.LABEL).equals((String) value))
                                return;
                            else
                                act.set(comp, attr, labler.GetCurrent(circuit, comp.getFactory()));
                        }
                    } else
                        act.set(comp, attr, "");
                } else
                    act.set(comp, attr, value);
            }
        }
        project.doAction(act);
    }
}
Also used : Action(com.cburch.logisim.proj.Action) SetAttributeAction(com.cburch.logisim.tools.SetAttributeAction) CircuitException(com.cburch.logisim.circuit.CircuitException) AutoLabel(com.cburch.logisim.util.AutoLabel) Circuit(com.cburch.logisim.circuit.Circuit) SetAttributeAction(com.cburch.logisim.tools.SetAttributeAction) Wire(com.cburch.logisim.circuit.Wire) TreeSet(java.util.TreeSet) SubcircuitFactory(com.cburch.logisim.circuit.SubcircuitFactory) CircuitMutation(com.cburch.logisim.circuit.CircuitMutation) Component(com.cburch.logisim.comp.Component)

Example 14 with Circuit

use of com.cburch.logisim.circuit.Circuit in project logisim-evolution by reds-heig.

the class LayoutThumbnail method paintComponent.

@Override
protected void paintComponent(Graphics g) {
    if (circuitState != null) {
        Circuit circuit = circuitState.getCircuit();
        Bounds bds = circuit.getBounds(g);
        Dimension size = getSize();
        double scaleX = (double) (size.width - 2 * BORDER) / bds.getWidth();
        double scaleY = (double) (size.height - 2 * BORDER) / bds.getHeight();
        double scale = Math.min(1.0, Math.min(scaleX, scaleY));
        Graphics gCopy = g.create();
        int borderX = (int) ((size.width - bds.getWidth() * scale) / 2);
        int borderY = (int) ((size.height - bds.getHeight() * scale) / 2);
        gCopy.translate(borderX, borderY);
        if (scale != 1.0 && g instanceof Graphics2D) {
            ((Graphics2D) gCopy).scale(scale, scale);
        }
        gCopy.translate(-bds.getX(), -bds.getY());
        ComponentDrawContext context = new ComponentDrawContext(this, circuit, circuitState, g, gCopy);
        context.setShowState(false);
        context.setShowColor(false);
        circuit.draw(context, Collections.<Component>emptySet());
        if (ports != null) {
            gCopy.setColor(AppearancePort.COLOR);
            int width = Math.max(4, (int) ((2 / scale) + 0.5));
            GraphicsUtil.switchToWidth(gCopy, width);
            for (Instance port : ports) {
                Bounds b = port.getBounds();
                int x = b.getX();
                int y = b.getY();
                int w = b.getWidth();
                int h = b.getHeight();
                if (Pin.FACTORY.isInputPin(port)) {
                    gCopy.drawRect(x, y, w, h);
                } else {
                    if (b.getWidth() > 25) {
                        gCopy.drawRoundRect(x, y, w, h, 4, 4);
                    } else {
                        gCopy.drawOval(x, y, w, h);
                    }
                }
            }
        }
        gCopy.dispose();
        g.setColor(Color.BLACK);
        GraphicsUtil.switchToWidth(g, 2);
        g.drawRect(0, 0, size.width - 2, size.height - 2);
    }
}
Also used : Graphics(java.awt.Graphics) ComponentDrawContext(com.cburch.logisim.comp.ComponentDrawContext) Instance(com.cburch.logisim.instance.Instance) Bounds(com.cburch.logisim.data.Bounds) Circuit(com.cburch.logisim.circuit.Circuit) Dimension(java.awt.Dimension) Graphics2D(java.awt.Graphics2D)

Example 15 with Circuit

use of com.cburch.logisim.circuit.Circuit 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)

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