Search in sources :

Example 31 with AttributeSet

use of com.cburch.logisim.data.AttributeSet in project logisim-evolution by reds-heig.

the class InstanceFactory method getDefaultAttributeValue.

@Override
public Object getDefaultAttributeValue(Attribute<?> attr, LogisimVersion ver) {
    Attribute<?>[] as = attrs;
    if (as != null) {
        for (int i = 0; i < as.length; i++) {
            if (as[i] == attr) {
                return defaults[i];
            }
        }
        return null;
    } else {
        AttributeSet dfltSet = defaultSet;
        if (dfltSet == null) {
            dfltSet = createAttributeSet();
            defaultSet = dfltSet;
        }
        return ((AttributeSet) dfltSet.clone()).getValue(attr);
    }
}
Also used : Attribute(com.cburch.logisim.data.Attribute) AttributeSet(com.cburch.logisim.data.AttributeSet)

Example 32 with AttributeSet

use of com.cburch.logisim.data.AttributeSet in project logisim-evolution by reds-heig.

the class InstancePainter method getAttributeValue.

public <E> E getAttributeValue(Attribute<E> attr) {
    InstanceComponent c = comp;
    AttributeSet as = c == null ? attrs : c.getAttributeSet();
    return as.getValue(attr);
}
Also used : AttributeSet(com.cburch.logisim.data.AttributeSet)

Example 33 with AttributeSet

use of com.cburch.logisim.data.AttributeSet 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 34 with AttributeSet

use of com.cburch.logisim.data.AttributeSet in project logisim-evolution by reds-heig.

the class ToolAttributeAction method create.

public static Action create(Tool tool, Attribute<?> attr, Object value) {
    AttributeSet attrs = tool.getAttributeSet();
    KeyConfigurationEvent e = new KeyConfigurationEvent(0, attrs, null, null);
    KeyConfigurationResult r = new KeyConfigurationResult(e, attr, value);
    return new ToolAttributeAction(r);
}
Also used : KeyConfigurationResult(com.cburch.logisim.tools.key.KeyConfigurationResult) AttributeSet(com.cburch.logisim.data.AttributeSet) KeyConfigurationEvent(com.cburch.logisim.tools.key.KeyConfigurationEvent)

Example 35 with AttributeSet

use of com.cburch.logisim.data.AttributeSet in project logisim-evolution by reds-heig.

the class Selection method drawGhostsShifted.

public void drawGhostsShifted(ComponentDrawContext context, int dx, int dy) {
    if (shouldSnap()) {
        dx = Canvas.snapXToGrid(dx);
        dy = Canvas.snapYToGrid(dy);
    }
    Graphics g = context.getGraphics();
    for (Component comp : unionSet) {
        AttributeSet attrs = comp.getAttributeSet();
        Location loc = comp.getLocation();
        int x = loc.getX() + dx;
        int y = loc.getY() + dy;
        context.setGraphics(g.create());
        comp.getFactory().drawGhost(context, Color.gray, x, y, attrs);
        context.getGraphics().dispose();
    }
    context.setGraphics(g);
}
Also used : Graphics(java.awt.Graphics) AttributeSet(com.cburch.logisim.data.AttributeSet) Component(com.cburch.logisim.comp.Component) Location(com.cburch.logisim.data.Location)

Aggregations

AttributeSet (com.cburch.logisim.data.AttributeSet)65 ComponentFactory (com.cburch.logisim.comp.ComponentFactory)16 Component (com.cburch.logisim.comp.Component)13 TreeMap (java.util.TreeMap)13 Attribute (com.cburch.logisim.data.Attribute)12 Location (com.cburch.logisim.data.Location)9 HashMap (java.util.HashMap)7 Value (com.cburch.logisim.data.Value)6 Circuit (com.cburch.logisim.circuit.Circuit)5 Direction (com.cburch.logisim.data.Direction)4 Graphics (java.awt.Graphics)4 Map (java.util.Map)4 CircuitMutation (com.cburch.logisim.circuit.CircuitMutation)3 Wire (com.cburch.logisim.circuit.Wire)3 AbstractAttributeSet (com.cburch.logisim.data.AbstractAttributeSet)3 BitWidth (com.cburch.logisim.data.BitWidth)3 Bounds (com.cburch.logisim.data.Bounds)3 ToolAttributeAction (com.cburch.logisim.gui.main.ToolAttributeAction)3 Action (com.cburch.logisim.proj.Action)3 Project (com.cburch.logisim.proj.Project)3