Search in sources :

Example 1 with ComponentFactory

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

the class Netlist method GetGatedClockComponents.

public void GetGatedClockComponents(ArrayList<Netlist> HierarchyNetlists, NetlistComponent SubCircuit, Map<String, Map<NetlistComponent, Circuit>> NotGatedSet, Map<String, Map<NetlistComponent, Circuit>> GatedSet, Set<NetlistComponent> WarnedComponents, FPGAReport Reporter) {
    /* First pass: we go down the tree */
    for (NetlistComponent SubCirc : MySubCircuits) {
        SubcircuitFactory sub = (SubcircuitFactory) SubCirc.GetComponent().getFactory();
        ArrayList<String> NewHierarchyNames = new ArrayList<String>();
        ArrayList<Netlist> NewHierarchyNetlists = new ArrayList<Netlist>();
        NewHierarchyNames.addAll(GetCurrentHierarchyLevel());
        NewHierarchyNames.add(CorrectLabel.getCorrectLabel(SubCirc.GetComponent().getAttributeSet().getValue(StdAttr.LABEL)));
        NewHierarchyNetlists.addAll(HierarchyNetlists);
        NewHierarchyNetlists.add(sub.getSubcircuit().getNetList());
        sub.getSubcircuit().getNetList().SetCurrentHierarchyLevel(NewHierarchyNames);
        sub.getSubcircuit().getNetList().GetGatedClockComponents(NewHierarchyNetlists, SubCirc, NotGatedSet, GatedSet, WarnedComponents, Reporter);
    }
    /* Second pass: we find all components with a clock input and see if they are connected to a clock */
    boolean GatedClock = false;
    List<SourceInfo> PinSources = new ArrayList<SourceInfo>();
    List<Set<Wire>> PinWires = new ArrayList<Set<Wire>>();
    List<Set<NetlistComponent>> PinGatedComponents = new ArrayList<Set<NetlistComponent>>();
    List<SourceInfo> NonPinSources = new ArrayList<SourceInfo>();
    List<Set<Wire>> NonPinWires = new ArrayList<Set<Wire>>();
    List<Set<NetlistComponent>> NonPinGatedComponents = new ArrayList<Set<NetlistComponent>>();
    for (NetlistComponent comp : MyComponents) {
        ComponentFactory fact = comp.GetComponent().getFactory();
        if (fact instanceof DFlipFlop || fact instanceof JKFlipFlop || fact instanceof SRFlipFlop || fact instanceof TFlipFlop) {
            AttributeSet attrs = comp.GetComponent().getAttributeSet();
            if (IsFlipFlop(attrs)) {
                GatedClock |= HasGatedClock(comp, comp.NrOfEnds() - 5, PinSources, PinWires, PinGatedComponents, NonPinSources, NonPinWires, NonPinGatedComponents, WarnedComponents, Reporter);
            }
        } else if (fact instanceof Counter) {
            GatedClock |= HasGatedClock(comp, Counter.CK, PinSources, PinWires, PinGatedComponents, NonPinSources, NonPinWires, NonPinGatedComponents, WarnedComponents, Reporter);
        } else if (fact instanceof Ram) {
            if (IsFlipFlop(comp.GetComponent().getAttributeSet()))
                GatedClock |= HasGatedClock(comp, Ram.CLK, PinSources, PinWires, PinGatedComponents, NonPinSources, NonPinWires, NonPinGatedComponents, WarnedComponents, Reporter);
        } else if (fact instanceof Random) {
            GatedClock |= HasGatedClock(comp, Random.CK, PinSources, PinWires, PinGatedComponents, NonPinSources, NonPinWires, NonPinGatedComponents, WarnedComponents, Reporter);
        } else if (fact instanceof Register) {
            if (IsFlipFlop(comp.GetComponent().getAttributeSet()))
                GatedClock |= HasGatedClock(comp, Register.CK, PinSources, PinWires, PinGatedComponents, NonPinSources, NonPinWires, NonPinGatedComponents, WarnedComponents, Reporter);
        } else if (fact instanceof ShiftRegister) {
            GatedClock |= HasGatedClock(comp, ShiftRegister.CK, PinSources, PinWires, PinGatedComponents, NonPinSources, NonPinWires, NonPinGatedComponents, WarnedComponents, Reporter);
        }
    }
    /* We have two situations:
		 * 1) The gated clock net is generated locally, in this case we can mark them and add the current system to the non-gated set as
		 *    each instance will be equal at higher/lower levels.
		 * 2) The gated clock nets are connected to a pin, in this case each instance of this circuit could be either gated or non-gated,
		 *    we have to do something on the level higher and we mark this in the sets to be processed later. 
		 */
    String MyName = CorrectLabel.getCorrectLabel(CircuitName);
    if (HierarchyNetlists.size() > 1) {
        if (GatedClock && PinSources.isEmpty()) {
            GatedClock = false;
            /* we have only non-pin driven gated clocks */
            WarningForGatedClock(NonPinSources, NonPinGatedComponents, NonPinWires, WarnedComponents, HierarchyNetlists, Reporter, Strings.get("NetList_GatedClock"));
        }
        if (GatedClock && !PinSources.isEmpty()) {
            for (int i = 0; i < PinSources.size(); i++) {
                Reporter.AddSevereWarning(Strings.get("NetList_GatedClock"));
                Reporter.AddWarningIncrement(Strings.get("NetList_TraceListBegin"));
                SimpleDRCContainer warn = new SimpleDRCContainer(MyCircuit, Strings.get("NetList_GatedClockSink"), SimpleDRCContainer.LEVEL_NORMAL, SimpleDRCContainer.MARK_INSTANCE | SimpleDRCContainer.MARK_WIRE, true);
                warn.AddMarkComponents(PinWires.get(i));
                for (NetlistComponent comp : PinGatedComponents.get(i)) warn.AddMarkComponent(comp.GetComponent());
                Reporter.AddWarning(warn);
                WarningTraceForGatedClock(PinSources.get(i).getSource(), PinSources.get(i).getIndex(), HierarchyNetlists, CurrentHierarchyLevel, Reporter);
                Reporter.AddWarningIncrement(Strings.get("NetList_TraceListEnd"));
            }
        }
        /* we only mark if we are not at top-level */
        if (GatedClock) {
            if (GatedSet.containsKey(MyName))
                GatedSet.get(MyName).put(SubCircuit, HierarchyNetlists.get(HierarchyNetlists.size() - 2).getCircuit());
            else {
                Map<NetlistComponent, Circuit> newList = new HashMap<NetlistComponent, Circuit>();
                newList.put(SubCircuit, HierarchyNetlists.get(HierarchyNetlists.size() - 2).getCircuit());
                GatedSet.put(MyName, newList);
            }
        } else {
            if (NotGatedSet.containsKey(MyName))
                NotGatedSet.get(MyName).put(SubCircuit, HierarchyNetlists.get(HierarchyNetlists.size() - 2).getCircuit());
            else {
                Map<NetlistComponent, Circuit> newList = new HashMap<NetlistComponent, Circuit>();
                newList.put(SubCircuit, HierarchyNetlists.get(HierarchyNetlists.size() - 2).getCircuit());
                NotGatedSet.put(MyName, newList);
            }
        }
    } else {
        /* At toplevel we warn for all possible gated clocks */
        WarningForGatedClock(NonPinSources, NonPinGatedComponents, NonPinWires, WarnedComponents, HierarchyNetlists, Reporter, Strings.get("NetList_GatedClock"));
        WarningForGatedClock(PinSources, PinGatedComponents, PinWires, WarnedComponents, HierarchyNetlists, Reporter, Strings.get("NetList_PossibleGatedClock"));
    }
}
Also used : DFlipFlop(com.cburch.logisim.std.memory.DFlipFlop) HashSet(java.util.HashSet) Set(java.util.Set) AttributeSet(com.cburch.logisim.data.AttributeSet) HashMap(java.util.HashMap) ComponentFactory(com.cburch.logisim.comp.ComponentFactory) ArrayList(java.util.ArrayList) TFlipFlop(com.cburch.logisim.std.memory.TFlipFlop) ShiftRegister(com.cburch.logisim.std.memory.ShiftRegister) Wire(com.cburch.logisim.circuit.Wire) Counter(com.cburch.logisim.std.memory.Counter) SRFlipFlop(com.cburch.logisim.std.memory.SRFlipFlop) Random(com.cburch.logisim.std.memory.Random) SubcircuitFactory(com.cburch.logisim.circuit.SubcircuitFactory) JKFlipFlop(com.cburch.logisim.std.memory.JKFlipFlop) Circuit(com.cburch.logisim.circuit.Circuit) AttributeSet(com.cburch.logisim.data.AttributeSet) ShiftRegister(com.cburch.logisim.std.memory.ShiftRegister) Register(com.cburch.logisim.std.memory.Register) Ram(com.cburch.logisim.std.memory.Ram)

Example 2 with ComponentFactory

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

the class SelectionActions method getReplacementMap.

private static HashMap<Component, Component> getReplacementMap(Project proj) {
    HashMap<Component, Component> replMap;
    replMap = new HashMap<Component, Component>();
    LogisimFile file = proj.getLogisimFile();
    ArrayList<Library> libs = new ArrayList<Library>();
    libs.add(file);
    libs.addAll(file.getLibraries());
    ArrayList<String> dropped = null;
    Clipboard clip = Clipboard.get();
    Collection<Component> comps = clip.getComponents();
    HashMap<ComponentFactory, ComponentFactory> factoryReplacements;
    factoryReplacements = new HashMap<ComponentFactory, ComponentFactory>();
    for (Component comp : comps) {
        if (comp instanceof Wire)
            continue;
        ComponentFactory compFactory = comp.getFactory();
        ComponentFactory copyFactory = findComponentFactory(compFactory, libs, false);
        if (factoryReplacements.containsKey(compFactory)) {
            copyFactory = factoryReplacements.get(compFactory);
        } else if (copyFactory == null) {
            ComponentFactory candidate = findComponentFactory(compFactory, libs, true);
            if (candidate == null) {
                if (dropped == null) {
                    dropped = new ArrayList<String>();
                }
                dropped.add(compFactory.getDisplayName());
            } else {
                String msg = Strings.get("pasteCloneQuery", compFactory.getName());
                Object[] opts = { Strings.get("pasteCloneReplace"), Strings.get("pasteCloneIgnore"), Strings.get("pasteCloneCancel") };
                int select = JOptionPane.showOptionDialog(proj.getFrame(), msg, Strings.get("pasteCloneTitle"), 0, JOptionPane.QUESTION_MESSAGE, null, opts, opts[0]);
                if (select == 0) {
                    copyFactory = candidate;
                } else if (select == 1) {
                    copyFactory = null;
                } else {
                    return null;
                }
                factoryReplacements.put(compFactory, copyFactory);
            }
        }
        if (copyFactory == null) {
            replMap.put(comp, null);
        } else if (copyFactory != compFactory) {
            Location copyLoc = comp.getLocation();
            AttributeSet copyAttrs = (AttributeSet) comp.getAttributeSet().clone();
            Component copy = copyFactory.createComponent(copyLoc, copyAttrs);
            replMap.put(comp, copy);
        }
    }
    if (dropped != null) {
        Collections.sort(dropped);
        StringBuilder droppedStr = new StringBuilder();
        droppedStr.append(Strings.get("pasteDropMessage"));
        String curName = dropped.get(0);
        int curCount = 1;
        int lines = 1;
        for (int i = 1; i <= dropped.size(); i++) {
            String nextName = i == dropped.size() ? "" : dropped.get(i);
            if (nextName.equals(curName)) {
                curCount++;
            } else {
                lines++;
                droppedStr.append("\n  ");
                droppedStr.append(curName);
                if (curCount > 1) {
                    droppedStr.append(" \u00d7 " + curCount);
                }
                curName = nextName;
                curCount = 1;
            }
        }
        lines = Math.max(3, Math.min(7, lines));
        JTextArea area = new JTextArea(lines, 60);
        area.setEditable(false);
        area.setText(droppedStr.toString());
        area.setCaretPosition(0);
        JScrollPane areaPane = new JScrollPane(area);
        JOptionPane.showMessageDialog(proj.getFrame(), areaPane, Strings.get("pasteDropTitle"), JOptionPane.WARNING_MESSAGE);
    }
    return replMap;
}
Also used : JScrollPane(javax.swing.JScrollPane) JTextArea(javax.swing.JTextArea) ComponentFactory(com.cburch.logisim.comp.ComponentFactory) ArrayList(java.util.ArrayList) Wire(com.cburch.logisim.circuit.Wire) LogisimFile(com.cburch.logisim.file.LogisimFile) AttributeSet(com.cburch.logisim.data.AttributeSet) Library(com.cburch.logisim.tools.Library) Component(com.cburch.logisim.comp.Component) Location(com.cburch.logisim.data.Location)

Example 3 with ComponentFactory

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

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

the class AddTool method paintIcon.

@Override
public void paintIcon(ComponentDrawContext c, int x, int y) {
    FactoryDescription desc = description;
    if (desc != null && !desc.isFactoryLoaded()) {
        Icon icon = desc.getIcon();
        if (icon != null) {
            icon.paintIcon(c.getDestination(), c.getGraphics(), x + 2, y + 2);
            return;
        }
    }
    ComponentFactory source = getFactory();
    if (source != null) {
        AttributeSet base = getBaseAttributes();
        source.paintIcon(c, x, y, base);
    }
}
Also used : AttributeSet(com.cburch.logisim.data.AttributeSet) ComponentFactory(com.cburch.logisim.comp.ComponentFactory) Icon(javax.swing.Icon)

Example 5 with ComponentFactory

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

the class AddTool method setFacing.

private void setFacing(Canvas canvas, Direction facing) {
    ComponentFactory source = getFactory();
    if (source == null)
        return;
    AttributeSet base = getBaseAttributes();
    Object feature = source.getFeature(ComponentFactory.FACING_ATTRIBUTE_KEY, base);
    @SuppressWarnings("unchecked") Attribute<Direction> attr = (Attribute<Direction>) feature;
    if (attr != null) {
        Action act = ToolAttributeAction.create(this, attr, facing);
        canvas.getProject().doAction(act);
    }
}
Also used : Action(com.cburch.logisim.proj.Action) ToolAttributeAction(com.cburch.logisim.gui.main.ToolAttributeAction) AttributeSet(com.cburch.logisim.data.AttributeSet) Attribute(com.cburch.logisim.data.Attribute) ComponentFactory(com.cburch.logisim.comp.ComponentFactory) Direction(com.cburch.logisim.data.Direction)

Aggregations

ComponentFactory (com.cburch.logisim.comp.ComponentFactory)37 AttributeSet (com.cburch.logisim.data.AttributeSet)16 AddTool (com.cburch.logisim.tools.AddTool)9 Tool (com.cburch.logisim.tools.Tool)9 Circuit (com.cburch.logisim.circuit.Circuit)8 SubcircuitFactory (com.cburch.logisim.circuit.SubcircuitFactory)8 Component (com.cburch.logisim.comp.Component)8 Library (com.cburch.logisim.tools.Library)8 ArrayList (java.util.ArrayList)6 Wire (com.cburch.logisim.circuit.Wire)4 Location (com.cburch.logisim.data.Location)4 ProjectExplorerToolNode (com.cburch.logisim.gui.generic.ProjectExplorerToolNode)4 HashSet (java.util.HashSet)4 Attribute (com.cburch.logisim.data.Attribute)3 Bounds (com.cburch.logisim.data.Bounds)3 ToolAttributeAction (com.cburch.logisim.gui.main.ToolAttributeAction)3 Action (com.cburch.logisim.proj.Action)3 HashMap (java.util.HashMap)3 CircuitMutation (com.cburch.logisim.circuit.CircuitMutation)2 Direction (com.cburch.logisim.data.Direction)2