Search in sources :

Example 11 with Component

use of com.cburch.logisim.comp.Component in project logisim-evolution by reds-heig.

the class XmlWriter method fromCircuit.

Element fromCircuit(Circuit circuit) {
    Element ret = doc.createElement("circuit");
    ret.setAttribute("name", circuit.getName());
    addAttributeSetContent(ret, circuit.getStaticAttributes(), null);
    if (!circuit.getAppearance().isDefaultAppearance()) {
        Element appear = doc.createElement("appear");
        for (Object o : circuit.getAppearance().getObjectsFromBottom()) {
            if (o instanceof AbstractCanvasObject) {
                Element elt = ((AbstractCanvasObject) o).toSvgElement(doc);
                if (elt != null) {
                    appear.appendChild(elt);
                }
            }
        }
        ret.appendChild(appear);
    }
    for (Wire w : circuit.getWires()) {
        ret.appendChild(fromWire(w));
    }
    for (Component comp : circuit.getNonWires()) {
        Element elt = fromComponent(comp);
        if (elt != null)
            ret.appendChild(elt);
    }
    return ret;
}
Also used : Element(org.w3c.dom.Element) AbstractCanvasObject(com.cburch.draw.model.AbstractCanvasObject) AbstractCanvasObject(com.cburch.draw.model.AbstractCanvasObject) Wire(com.cburch.logisim.circuit.Wire) Component(com.cburch.logisim.comp.Component)

Example 12 with Component

use of com.cburch.logisim.comp.Component 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 13 with Component

use of com.cburch.logisim.comp.Component in project logisim-evolution by reds-heig.

the class AttrTableSelectionModel method getTitle.

@Override
public String getTitle() {
    ComponentFactory wireFactory = null;
    ComponentFactory factory = null;
    int factoryCount = 0;
    int totalCount = 0;
    boolean variousFound = false;
    Selection selection = frame.getCanvas().getSelection();
    for (Component comp : selection.getComponents()) {
        ComponentFactory fact = comp.getFactory();
        if (fact.equals(factory)) {
            factoryCount++;
        } else if (comp instanceof Wire) {
            wireFactory = fact;
            if (factory == null) {
                factoryCount++;
            }
        } else if (factory == null) {
            factory = fact;
            factoryCount = 1;
        } else {
            variousFound = true;
        }
        if (!(comp instanceof Wire)) {
            totalCount++;
        }
    }
    if (factory == null) {
        factory = wireFactory;
    }
    if (variousFound) {
        SetInstance(factory);
        return Strings.get("selectionVarious", "" + totalCount);
    } else if (factoryCount == 0) {
        String circName = frame.getCanvas().getCircuit().getName();
        SetInstance(frame.getCanvas().getCircuit().getSubcircuitFactory());
        return Strings.get("circuitAttrTitle", circName);
    } else if (factoryCount == 1) {
        SetInstance(factory);
        return Strings.get("selectionOne", factory.getDisplayName());
    } else {
        SetInstance(factory);
        return Strings.get("selectionMultiple", factory.getDisplayName(), "" + factoryCount);
    }
}
Also used : ComponentFactory(com.cburch.logisim.comp.ComponentFactory) Component(com.cburch.logisim.comp.Component) Wire(com.cburch.logisim.circuit.Wire)

Example 14 with Component

use of com.cburch.logisim.comp.Component in project logisim-evolution by reds-heig.

the class Canvas method getToolTipText.

@Override
public String getToolTipText(MouseEvent event) {
    boolean showTips = AppPreferences.COMPONENT_TIPS.getBoolean();
    if (showTips) {
        Canvas.snapToGrid(event);
        Location loc = Location.create(event.getX(), event.getY());
        ComponentUserEvent e = null;
        for (Component comp : getCircuit().getAllContaining(loc)) {
            Object makerObj = comp.getFeature(ToolTipMaker.class);
            if (makerObj != null && makerObj instanceof ToolTipMaker) {
                ToolTipMaker maker = (ToolTipMaker) makerObj;
                if (e == null) {
                    e = new ComponentUserEvent(this, loc.getX(), loc.getY());
                }
                String ret = maker.getToolTip(e);
                if (ret != null) {
                    unrepairMouseEvent(event);
                    return ret;
                }
            }
        }
    }
    return null;
}
Also used : ToolTipMaker(com.cburch.logisim.tools.ToolTipMaker) ComponentUserEvent(com.cburch.logisim.comp.ComponentUserEvent) Component(com.cburch.logisim.comp.Component) Location(com.cburch.logisim.data.Location)

Example 15 with Component

use of com.cburch.logisim.comp.Component 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

Component (com.cburch.logisim.comp.Component)97 Location (com.cburch.logisim.data.Location)26 ArrayList (java.util.ArrayList)20 Circuit (com.cburch.logisim.circuit.Circuit)19 AttributeSet (com.cburch.logisim.data.AttributeSet)13 Wire (com.cburch.logisim.circuit.Wire)12 Bounds (com.cburch.logisim.data.Bounds)11 HashMap (java.util.HashMap)11 HashSet (java.util.HashSet)11 SubcircuitFactory (com.cburch.logisim.circuit.SubcircuitFactory)8 ComponentFactory (com.cburch.logisim.comp.ComponentFactory)8 EndData (com.cburch.logisim.comp.EndData)8 InstanceComponent (com.cburch.logisim.instance.InstanceComponent)8 Project (com.cburch.logisim.proj.Project)7 Pin (com.cburch.logisim.std.wiring.Pin)7 Graphics (java.awt.Graphics)7 CircuitState (com.cburch.logisim.circuit.CircuitState)6 Splitter (com.cburch.logisim.circuit.Splitter)6 Selection (com.cburch.logisim.gui.main.Selection)6 InstanceState (com.cburch.logisim.instance.InstanceState)5