Search in sources :

Example 46 with Component

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

the class Dependencies method processCircuit.

private void processCircuit(Circuit circ) {
    circ.addCircuitListener(myListener);
    for (Component comp : circ.getNonWires()) {
        if (comp.getFactory() instanceof SubcircuitFactory) {
            SubcircuitFactory factory = (SubcircuitFactory) comp.getFactory();
            depends.addEdge(circ, factory.getSubcircuit());
        }
    }
}
Also used : SubcircuitFactory(com.cburch.logisim.circuit.SubcircuitFactory) Component(com.cburch.logisim.comp.Component)

Example 47 with Component

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

the class Circuit method Annotate.

public void Annotate(boolean ClearExistingLabels, FPGAReport reporter) {
    /* If I am already completely annotated, return */
    if (Annotated) {
        reporter.AddInfo("Nothing to do !");
        return;
    }
    SortedSet<Component> comps = new TreeSet<Component>(new AnnotateComparator());
    HashMap<String, AutoLabel> lablers = new HashMap<String, AutoLabel>();
    Set<String> LabelNames = new HashSet<String>();
    Set<String> Subcircuits = new HashSet<String>();
    for (Component comp : getNonWires()) {
        if (comp.getFactory() instanceof Tunnel)
            continue;
        /* we are directly going to remove duplicated labels */
        AttributeSet attrs = comp.getAttributeSet();
        if (attrs.containsAttribute(StdAttr.LABEL)) {
            String label = attrs.getValue(StdAttr.LABEL);
            if (!label.isEmpty()) {
                if (LabelNames.contains(label.toUpperCase())) {
                    SetAttributeAction act = new SetAttributeAction(this, Strings.getter("changeComponentAttributesAction"));
                    act.set(comp, StdAttr.LABEL, "");
                    proj.doAction(act);
                    reporter.AddSevereWarning("Removed duplicated label " + this.getName() + "/" + label);
                } else {
                    LabelNames.add(label.toUpperCase());
                }
            }
        }
        /* now we only process those that require a label */
        if (comp.getFactory().RequiresNonZeroLabel()) {
            if (ClearExistingLabels) {
                /* in case of label cleaning, we clear first the old label */
                reporter.AddInfo("Cleared " + this.getName() + "/" + comp.getAttributeSet().getValue(StdAttr.LABEL));
                SetAttributeAction act = new SetAttributeAction(this, Strings.getter("changeComponentAttributesAction"));
                act.set(comp, StdAttr.LABEL, "");
                proj.doAction(act);
            }
            if (comp.getAttributeSet().getValue(StdAttr.LABEL).isEmpty()) {
                comps.add(comp);
                String ComponentName = GetAnnotationName(comp);
                if (!lablers.containsKey(ComponentName)) {
                    lablers.put(ComponentName, new AutoLabel(ComponentName + "_0", this));
                }
            }
        }
        /* if the current component is a sub-circuit, recurse into it */
        if (comp.getFactory() instanceof SubcircuitFactory) {
            SubcircuitFactory sub = (SubcircuitFactory) comp.getFactory();
            if (!Subcircuits.contains(sub.getName()))
                Subcircuits.add(sub.getName());
        }
    }
    /* Now Annotate */
    for (Component comp : comps) {
        String ComponentName = GetAnnotationName(comp);
        if (!lablers.containsKey(ComponentName) || !lablers.get(ComponentName).hasNext(this)) {
            /* This should never happen! */
            reporter.AddFatalError("Annotate internal Error: Either there exists duplicate labels or the label syntax is incorrect!\nPlease try annotation on labeled components also\n");
            return;
        } else {
            String NewLabel = lablers.get(ComponentName).GetNext(this, comp.getFactory());
            SetAttributeAction act = new SetAttributeAction(this, Strings.getter("changeComponentAttributesAction"));
            act.set(comp, StdAttr.LABEL, NewLabel);
            proj.doAction(act);
            reporter.AddInfo("Labeled " + this.getName() + "/" + NewLabel);
        }
    }
    Annotated = true;
    /* Now annotate all circuits below me */
    for (String subs : Subcircuits) {
        Circuit circ = proj.getLogisimFile().getCircuit(subs);
        circ.Annotate(ClearExistingLabels, reporter);
    }
}
Also used : HashMap(java.util.HashMap) WeakHashMap(java.util.WeakHashMap) AutoLabel(com.cburch.logisim.util.AutoLabel) SetAttributeAction(com.cburch.logisim.tools.SetAttributeAction) Tunnel(com.cburch.logisim.std.wiring.Tunnel) AttributeSet(com.cburch.logisim.data.AttributeSet) TreeSet(java.util.TreeSet) Component(com.cburch.logisim.comp.Component) HashSet(java.util.HashSet)

Example 48 with Component

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

the class Circuit method IsComponentName.

private static boolean IsComponentName(String Name, Set<Component> comps, Boolean ShowDialog) {
    if (Name.isEmpty())
        return false;
    for (Component comp : comps) {
        if (comp.getFactory().getName().toUpperCase().equals(Name.toUpperCase())) {
            if (ShowDialog) {
                String msg = com.cburch.logisim.circuit.Strings.get("ComponentLabelNameError");
                JOptionPane.showMessageDialog(null, "\"" + Name + "\" : " + msg);
            }
            return true;
        }
    }
    /* we do not have to check the wires as (1) Wire is a reserved keyword, and (2) they cannot have a label */
    return false;
}
Also used : Component(com.cburch.logisim.comp.Component)

Example 49 with Component

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

the class Circuit method getBounds.

public Bounds getBounds() {
    Bounds wireBounds = wires.getWireBounds();
    Iterator<Component> it = comps.iterator();
    if (!it.hasNext())
        return wireBounds;
    Component first = it.next();
    Bounds firstBounds = first.getBounds();
    int xMin = firstBounds.getX();
    int yMin = firstBounds.getY();
    int xMax = xMin + firstBounds.getWidth();
    int yMax = yMin + firstBounds.getHeight();
    while (it.hasNext()) {
        Component c = it.next();
        Bounds bds = c.getBounds();
        int x0 = bds.getX();
        int x1 = x0 + bds.getWidth();
        int y0 = bds.getY();
        int y1 = y0 + bds.getHeight();
        if (x0 < xMin)
            xMin = x0;
        if (x1 > xMax)
            xMax = x1;
        if (y0 < yMin)
            yMin = y0;
        if (y1 > yMax)
            yMax = y1;
    }
    Bounds compBounds = Bounds.create(xMin, yMin, xMax - xMin, yMax - yMin);
    if (wireBounds.getWidth() == 0 || wireBounds.getHeight() == 0) {
        return compBounds;
    } else {
        return compBounds.add(wireBounds);
    }
}
Also used : Bounds(com.cburch.logisim.data.Bounds) Component(com.cburch.logisim.comp.Component)

Example 50 with Component

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

the class Circuit method mutatorClear.

public void mutatorClear() {
    locker.checkForWritePermission("clear");
    Set<Component> oldComps = comps;
    comps = new HashSet<Component>();
    wires = new CircuitWires();
    clocks.clear();
    MyNetList.clear();
    Annotated = false;
    for (Component comp : oldComps) {
        if (comp.getFactory() instanceof SubcircuitFactory) {
            SubcircuitFactory sub = (SubcircuitFactory) comp.getFactory();
            sub.getSubcircuit().circuitsUsingThis.remove(comp);
        }
    }
    fireEvent(CircuitEvent.ACTION_CLEAR, oldComps);
}
Also used : 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