Search in sources :

Example 26 with AttributeSet

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

the class AbstractFlipFlopHDLGeneratorFactory method GetPortMap.

@Override
public SortedMap<String, String> GetPortMap(Netlist Nets, NetlistComponent ComponentInfo, FPGAReport Reporter, String HDLType) {
    SortedMap<String, String> PortMap = new TreeMap<String, String>();
    Boolean GatedClock = false;
    Boolean HasClock = true;
    Boolean ActiveLow = false;
    String OpenBracket = (HDLType.equals(VHDL)) ? "(" : "[";
    String CloseBracket = (HDLType.equals(VHDL)) ? ")" : "]";
    String ZeroBit = (HDLType.equals(VHDL)) ? "'0'" : "1'b0";
    String SetBit = (HDLType.equals(VHDL)) ? "'1'" : "1'b1";
    int nr_of_pins = ComponentInfo.NrOfEnds();
    AttributeSet attrs = ComponentInfo.GetComponent().getAttributeSet();
    if (!ComponentInfo.EndIsConnected(ComponentInfo.NrOfEnds() - 5)) {
        Reporter.AddSevereWarning("Component \"" + ComponentName() + "\" in circuit \"" + Nets.getCircuitName() + "\" has no clock connection");
        HasClock = false;
    }
    String ClockNetName = GetClockNetName(ComponentInfo, ComponentInfo.NrOfEnds() - 5, Nets);
    if (ClockNetName.isEmpty()) {
        GatedClock = true;
    }
    if (attrs.containsAttribute(StdAttr.EDGE_TRIGGER)) {
        if (attrs.getValue(StdAttr.EDGE_TRIGGER) == StdAttr.TRIG_FALLING)
            ActiveLow = true;
    } else {
        if (attrs.containsAttribute(StdAttr.TRIGGER)) {
            if (attrs.getValue(StdAttr.TRIGGER) == StdAttr.TRIG_FALLING || attrs.getValue(StdAttr.TRIGGER) == StdAttr.TRIG_LOW)
                ActiveLow = true;
        }
    }
    PortMap.putAll(GetNetMap("Reset", true, ComponentInfo, nr_of_pins - 2, Reporter, HDLType, Nets));
    PortMap.putAll(GetNetMap("Preset", true, ComponentInfo, nr_of_pins - 1, Reporter, HDLType, Nets));
    if (HasClock && !GatedClock && Netlist.IsFlipFlop(attrs)) {
        if (Nets.RequiresGlobalClockConnection()) {
            PortMap.put("Tick", ClockNetName + OpenBracket + Integer.toString(ClockHDLGeneratorFactory.GlobalClockIndex) + CloseBracket);
        } else {
            if (ActiveLow)
                PortMap.put("Tick", ClockNetName + OpenBracket + Integer.toString(ClockHDLGeneratorFactory.NegativeEdgeTickIndex) + CloseBracket);
            else
                PortMap.put("Tick", ClockNetName + OpenBracket + Integer.toString(ClockHDLGeneratorFactory.PositiveEdgeTickIndex) + CloseBracket);
        }
        PortMap.put("Clock", ClockNetName + OpenBracket + Integer.toString(ClockHDLGeneratorFactory.GlobalClockIndex) + CloseBracket);
    } else if (!HasClock) {
        PortMap.put("Tick", ZeroBit);
        PortMap.put("Clock", ZeroBit);
    } else {
        PortMap.put("Tick", SetBit);
        if (!GatedClock) {
            if (ActiveLow)
                PortMap.put("Clock", ClockNetName + OpenBracket + Integer.toString(ClockHDLGeneratorFactory.InvertedDerivedClockIndex) + CloseBracket);
            else
                PortMap.put("Clock", ClockNetName + OpenBracket + Integer.toString(ClockHDLGeneratorFactory.DerivedClockIndex) + CloseBracket);
        } else {
            PortMap.put("Clock", GetNetName(ComponentInfo, ComponentInfo.NrOfEnds() - 5, true, HDLType, Nets));
        }
    }
    PortMap.putAll(GetInputMaps(ComponentInfo, Nets, Reporter, HDLType));
    PortMap.putAll(GetNetMap("Q", true, ComponentInfo, nr_of_pins - 4, Reporter, HDLType, Nets));
    PortMap.putAll(GetNetMap("Q_bar", true, ComponentInfo, nr_of_pins - 3, Reporter, HDLType, Nets));
    return PortMap;
}
Also used : AttributeSet(com.cburch.logisim.data.AttributeSet) TreeMap(java.util.TreeMap)

Example 27 with AttributeSet

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

the class SelectionAttributes method setValue.

@Override
public <V> void setValue(Attribute<V> attr, V value) {
    Attribute<?>[] attrs = this.selAttrs;
    Object[] values = this.selValues;
    for (int i = 0; i < attrs.length; i++) {
        if (attrs[i] == attr) {
            boolean same = value == null ? values[i] == null : value.equals(values[i]);
            if (!same) {
                values[i] = value;
                for (AttributeSet objAttrs : selected.keySet()) {
                    objAttrs.setValue(attr, value);
                }
            }
            break;
        }
    }
}
Also used : Attribute(com.cburch.logisim.data.Attribute) AbstractAttributeSet(com.cburch.logisim.data.AbstractAttributeSet) AttributeSet(com.cburch.logisim.data.AttributeSet) CanvasObject(com.cburch.draw.model.CanvasObject)

Example 28 with AttributeSet

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

the class InstanceTextField method update.

void update(Attribute<String> labelAttr, Attribute<Font> fontAttr, int x, int y, int halign, int valign) {
    boolean wasReg = shouldRegister();
    this.labelAttr = labelAttr;
    this.fontAttr = fontAttr;
    this.fieldX = x;
    this.fieldY = y;
    this.halign = halign;
    this.valign = valign;
    boolean shouldReg = shouldRegister();
    AttributeSet attrs = comp.getAttributeSet();
    if (attrs.containsAttribute(StdAttr.LABEL_VISIBILITY))
        LabelIsVisable = attrs.getValue(StdAttr.LABEL_VISIBILITY);
    if (!wasReg && shouldReg)
        attrs.addAttributeListener(this);
    if (wasReg && !shouldReg)
        attrs.removeAttributeListener(this);
    updateField(attrs);
}
Also used : AttributeSet(com.cburch.logisim.data.AttributeSet)

Example 29 with AttributeSet

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

the class ToolAttributeAction method doIt.

@Override
public void doIt(Project proj) {
    AttributeSet attrs = config.getEvent().getAttributeSet();
    Map<Attribute<?>, Object> newValues = config.getAttributeValues();
    Map<Attribute<?>, Object> oldValues = new HashMap<Attribute<?>, Object>(newValues.size());
    for (Map.Entry<Attribute<?>, Object> entry : newValues.entrySet()) {
        @SuppressWarnings("unchecked") Attribute<Object> attr = (Attribute<Object>) entry.getKey();
        oldValues.put(attr, attrs.getValue(attr));
        attrs.setValue(attr, entry.getValue());
    }
    this.oldValues = oldValues;
}
Also used : AttributeSet(com.cburch.logisim.data.AttributeSet) Attribute(com.cburch.logisim.data.Attribute) HashMap(java.util.HashMap) Map(java.util.Map) HashMap(java.util.HashMap)

Example 30 with AttributeSet

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

the class ToolAttributeAction method undo.

@Override
public void undo(Project proj) {
    AttributeSet attrs = config.getEvent().getAttributeSet();
    Map<Attribute<?>, Object> oldValues = this.oldValues;
    for (Map.Entry<Attribute<?>, Object> entry : oldValues.entrySet()) {
        @SuppressWarnings("unchecked") Attribute<Object> attr = (Attribute<Object>) entry.getKey();
        attrs.setValue(attr, entry.getValue());
    }
}
Also used : AttributeSet(com.cburch.logisim.data.AttributeSet) Attribute(com.cburch.logisim.data.Attribute) Map(java.util.Map) HashMap(java.util.HashMap)

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