Search in sources :

Example 76 with Component

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

the class Netlist method GenerateNetlist.

private boolean GenerateNetlist(FPGAReport Reporter, String HDLIdentifier) {
    ArrayList<SimpleDRCContainer> drc = new ArrayList<SimpleDRCContainer>();
    boolean errors = false;
    GridBagConstraints gbc = new GridBagConstraints();
    JFrame panel = new JFrame("Netlist: " + MyCircuit.getName());
    panel.setResizable(false);
    panel.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    GridBagLayout thisLayout = new GridBagLayout();
    panel.setLayout(thisLayout);
    JLabel LocText = new JLabel("Generating Netlist for Circuit: " + MyCircuit.getName());
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    panel.add(LocText, gbc);
    JProgressBar progres = new JProgressBar(0, 7);
    progres.setValue(0);
    progres.setStringPainted(true);
    gbc.gridx = 0;
    gbc.gridy = 1;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    panel.add(progres, gbc);
    panel.pack();
    panel.setLocation(Projects.getCenteredLoc(panel.getWidth(), panel.getHeight()));
    panel.setVisible(true);
    CircuitName = MyCircuit.getName();
    wires.clear();
    wires.addAll(MyCircuit.getWires());
    /*
		 * FIRST PASS: In this pass we take all wire segments and see if they
		 * are connected to other segments. If they are connected we build a
		 * net.
		 */
    while (wires.size() != 0) {
        Net NewNet = new Net();
        GetNet(null, NewNet);
        if (!NewNet.isEmpty()) {
            MyNets.add(NewNet);
        }
    }
    /*
		 * Here we start to detect direct input-output component connections,
		 * read we detect "hidden" nets
		 */
    Set<Component> components = MyCircuit.getNonWires();
    /* we Start with the creation of an outputs list */
    Set<Location> OutputsList = new HashSet<Location>();
    Set<Location> InputsList = new HashSet<Location>();
    Set<Component> TunnelList = new HashSet<Component>();
    MyComplexSplitters.clear();
    drc.clear();
    drc.add(new SimpleDRCContainer(MyCircuit, Strings.get("NetList_IOError"), SimpleDRCContainer.LEVEL_FATAL, SimpleDRCContainer.MARK_INSTANCE));
    drc.add(new SimpleDRCContainer(MyCircuit, Strings.get("NetList_BitwidthError"), SimpleDRCContainer.LEVEL_FATAL, SimpleDRCContainer.MARK_WIRE));
    for (Component com : components) {
        /*
			 * We do not process the splitter and tunnel, they are processed
			 * later on
			 */
        boolean Ignore = false;
        /* In this case, the probe should not be synthetised:
			 * We could set the Probe as non-HDL element. But If we set the Probe
			 * as non HDL element, logisim will not allow user to download the design. 
			 * 
			 * In some case we need to use Logisim Simulation before running the design on the hardware. 
			 * During simulation, probes are very helpful to see signals values. And when simulation is ok, 
			 * the user does not want to delete all probes.
			 * Thus, here we remove it form the netlist so it is transparent.
			 */
        if (com.getFactory() instanceof Probe) {
            continue;
        }
        if (com.getFactory() instanceof SplitterFactory) {
            MyComplexSplitters.add(com);
            Ignore = true;
        }
        if (com.getFactory() instanceof Tunnel) {
            TunnelList.add(com);
            Ignore = true;
        }
        List<EndData> ends = com.getEnds();
        for (EndData end : ends) {
            if (!Ignore) {
                if (end.isInput() && end.isOutput()) {
                    drc.get(0).AddMarkComponent(com);
                }
                if (end.isOutput()) {
                    OutputsList.add(end.getLocation());
                } else {
                    InputsList.add(end.getLocation());
                }
            }
            /* Here we are going to mark the bitwidths on the nets */
            int width = end.getWidth().getWidth();
            Location loc = end.getLocation();
            for (Net ThisNet : MyNets) {
                if (ThisNet.contains(loc)) {
                    if (!ThisNet.setWidth(width)) {
                        drc.get(1).AddMarkComponents(ThisNet.getWires());
                    }
                }
            }
        }
    }
    for (int i = 0; i < drc.size(); i++) {
        if (drc.get(i).DRCInfoPresent()) {
            errors = true;
            Reporter.AddError(drc.get(i));
        }
    }
    if (errors) {
        panel.dispose();
        return false;
    }
    progres.setValue(1);
    Rectangle ProgRect = progres.getBounds();
    ProgRect.x = 0;
    ProgRect.y = 0;
    progres.paintImmediately(ProgRect);
    /*
		 * Now we check if an input pin is connected to an output and in case of
		 * a Splitter if it is connected to either of them
		 */
    drc.add(new SimpleDRCContainer(MyCircuit, Strings.get("NetAdd_ComponentWidthMismatch"), SimpleDRCContainer.LEVEL_FATAL, SimpleDRCContainer.MARK_INSTANCE));
    Map<Location, Integer> Points = new HashMap<Location, Integer>();
    for (Component comp : components) {
        for (EndData end : comp.getEnds()) {
            Location loc = end.getLocation();
            if (Points.containsKey(loc)) {
                /* Found a connection already used */
                boolean newNet = true;
                for (Net net : MyNets) {
                    if (net.contains(loc))
                        newNet = false;
                }
                if (newNet) {
                    int BitWidth = Points.get(loc);
                    if (BitWidth == end.getWidth().getWidth()) {
                        MyNets.add(new Net(loc, BitWidth));
                    } else {
                        drc.get(0).AddMarkComponent(comp);
                    }
                }
            } else
                Points.put(loc, end.getWidth().getWidth());
        }
    }
    if (drc.get(0).DRCInfoPresent()) {
        Reporter.AddError(drc.get(0));
        panel.dispose();
        return false;
    }
    progres.setValue(2);
    ProgRect = progres.getBounds();
    ProgRect.x = 0;
    ProgRect.y = 0;
    progres.paintImmediately(ProgRect);
    /*
		 * Here we are going to process the tunnels and possible merging of the
		 * tunneled nets
		 */
    boolean TunnelsPresent = false;
    for (Component com : TunnelList) {
        List<EndData> ends = com.getEnds();
        for (EndData end : ends) {
            for (Net ThisNet : MyNets) {
                if (ThisNet.contains(end.getLocation())) {
                    ThisNet.addTunnel(com.getAttributeSet().getValue(StdAttr.LABEL));
                    TunnelsPresent = true;
                }
            }
        }
    }
    drc.clear();
    drc.add(new SimpleDRCContainer(MyCircuit, Strings.get("NetMerge_BitWidthError"), SimpleDRCContainer.LEVEL_FATAL, SimpleDRCContainer.MARK_WIRE));
    if (TunnelsPresent) {
        Iterator<Net> NetIterator = MyNets.listIterator();
        while (NetIterator.hasNext()) {
            Net ThisNet = NetIterator.next();
            if (ThisNet.HasTunnel() && (MyNets.indexOf(ThisNet) < (MyNets.size() - 1))) {
                boolean merged = false;
                Iterator<Net> SearchIterator = MyNets.listIterator(MyNets.indexOf(ThisNet) + 1);
                while (SearchIterator.hasNext() && !merged) {
                    Net SearchNet = SearchIterator.next();
                    for (String name : ThisNet.TunnelNames()) {
                        if (SearchNet.ContainsTunnel(name) && !merged) {
                            merged = true;
                            if (!SearchNet.merge(ThisNet)) {
                                drc.get(0).AddMarkComponents(SearchNet.getWires());
                                drc.get(0).AddMarkComponents(ThisNet.getWires());
                            }
                        }
                    }
                }
                if (merged) {
                    NetIterator.remove();
                }
            }
        }
    }
    if (drc.get(0).DRCInfoPresent()) {
        Reporter.AddError(drc.get(0));
        panel.dispose();
        return false;
    }
    progres.setValue(3);
    ProgRect = progres.getBounds();
    ProgRect.x = 0;
    ProgRect.y = 0;
    progres.paintImmediately(ProgRect);
    /* At this point all net segments are build. All tunnels have been removed. There is still the processing of
		 * the splitters and the determination of the direction of the nets.
		 */
    /* First we are going to check on duplicated splitters and remove them */
    Iterator<Component> MySplitIterator = MyComplexSplitters.listIterator();
    while (MySplitIterator.hasNext()) {
        Component ThisSplitter = MySplitIterator.next();
        if (MyComplexSplitters.indexOf(ThisSplitter) < (MyComplexSplitters.size() - 1)) {
            boolean FoundDuplicate = false;
            Iterator<Component> SearchIterator = MyComplexSplitters.listIterator(MyComplexSplitters.indexOf(ThisSplitter) + 1);
            while (SearchIterator.hasNext() && !FoundDuplicate) {
                Component SearchSplitter = SearchIterator.next();
                if (SearchSplitter.getLocation().equals(ThisSplitter.getLocation())) {
                    FoundDuplicate = true;
                    for (int i = 0; i < SearchSplitter.getEnds().size(); i++) {
                        if (!SearchSplitter.getEnd(i).getLocation().equals(ThisSplitter.getEnd(i).getLocation()))
                            FoundDuplicate = false;
                    }
                }
            }
            if (FoundDuplicate) {
                SimpleDRCContainer warn = new SimpleDRCContainer(MyCircuit, Strings.get("NetList_duplicatedSplitter"), SimpleDRCContainer.LEVEL_SEVERE, SimpleDRCContainer.MARK_INSTANCE);
                warn.AddMarkComponent(ThisSplitter);
                Reporter.AddWarning(warn);
                MySplitIterator.remove();
            }
        }
    }
    /* In this round we are going to detect the unconnected nets meaning those having a width of 0 and remove them */
    drc.clear();
    Iterator<Net> NetIterator = MyNets.listIterator();
    drc.add(new SimpleDRCContainer(MyCircuit, Strings.get("NetList_emptynets"), SimpleDRCContainer.LEVEL_NORMAL, SimpleDRCContainer.MARK_WIRE));
    while (NetIterator.hasNext()) {
        Net wire = NetIterator.next();
        if (wire.BitWidth() == 0) {
            drc.get(0).AddMarkComponents(wire.getWires());
            NetIterator.remove();
        }
    }
    if (drc.get(0).DRCInfoPresent()) {
        Reporter.AddWarning(drc.get(0));
    }
    MySplitIterator = MyComplexSplitters.iterator();
    /* We also check quickly the splitters and remove the ones where input-bus is output-bus. We mark those who are not
		 * correctly connected and remove both versions from the set.
		 */
    drc.clear();
    drc.add(new SimpleDRCContainer(MyCircuit, Strings.get("NetList_ShortCircuit"), SimpleDRCContainer.LEVEL_FATAL, SimpleDRCContainer.MARK_WIRE));
    errors = false;
    while (MySplitIterator.hasNext()) {
        Component mySplitter = MySplitIterator.next();
        int BusWidth = mySplitter.getEnd(0).getWidth().getWidth();
        List<EndData> myEnds = mySplitter.getEnds();
        int MaxFanoutWidth = 0;
        int index = -1;
        for (int i = 1; i < myEnds.size(); i++) {
            int width = mySplitter.getEnd(i).getWidth().getWidth();
            if (width > MaxFanoutWidth) {
                MaxFanoutWidth = width;
                index = i;
            }
        }
        /* stupid situation first: the splitters bus connection is a single fanout */
        if (BusWidth == MaxFanoutWidth) {
            Net busnet = null;
            Net connectedNet = null;
            Location BusLoc = mySplitter.getEnd(0).getLocation();
            Location ConnectedLoc = mySplitter.getEnd(index).getLocation();
            boolean issueWarning = false;
            /* here we search for the nets */
            for (Net CurrentNet : MyNets) {
                if (CurrentNet.contains(BusLoc)) {
                    if (busnet != null) {
                        Reporter.AddFatalError("BUG: Multiple bus nets found for a single splitter\n ==> " + this.getClass().getName().replaceAll("\\.", "/") + ":" + Thread.currentThread().getStackTrace()[2].getLineNumber() + "\n");
                        panel.dispose();
                        return false;
                    } else {
                        busnet = CurrentNet;
                    }
                }
                if (CurrentNet.contains(ConnectedLoc)) {
                    if (connectedNet != null) {
                        Reporter.AddFatalError("BUG: Multiple nets found for a single splitter split connection\n ==> " + this.getClass().getName().replaceAll("\\.", "/") + ":" + Thread.currentThread().getStackTrace()[2].getLineNumber() + "\n");
                        panel.dispose();
                        return false;
                    } else {
                        connectedNet = CurrentNet;
                    }
                }
            }
            if (connectedNet != null) {
                if (busnet != null) {
                    /* we can merge both nets */
                    if (!busnet.merge(connectedNet)) {
                        Reporter.AddFatalError("BUG: Splitter bus merge error\n ==> " + this.getClass().getName().replaceAll("\\.", "/") + ":" + Thread.currentThread().getStackTrace()[2].getLineNumber() + "\n");
                        panel.dispose();
                        return false;
                    } else {
                        MyNets.remove(MyNets.indexOf(connectedNet));
                    }
                } else {
                    issueWarning = true;
                }
            } else {
                issueWarning = true;
            }
            if (issueWarning) {
                SimpleDRCContainer warn = new SimpleDRCContainer(MyCircuit, Strings.get("NetList_NoSplitterConnection"), SimpleDRCContainer.LEVEL_SEVERE, SimpleDRCContainer.MARK_INSTANCE);
                warn.AddMarkComponent(mySplitter);
                Reporter.AddWarning(warn);
            }
            MySplitIterator.remove();
        /* Does not exist anymore */
        }
    }
    progres.setValue(4);
    ProgRect = progres.getBounds();
    ProgRect.x = 0;
    ProgRect.y = 0;
    progres.paintImmediately(ProgRect);
    /*
		 * Finally we have to process the splitters to determine the bus
		 * hierarchy (if any)
		 */
    /*
		 * In this round we only process the evident splitters and remove them
		 * from the list
		 */
    Iterator<Component> MySplitters = MyComplexSplitters.iterator();
    while (MySplitters.hasNext()) {
        Component com = MySplitters.next();
        /*
			 * Currently by definition end(0) is the combined end of the
			 * splitter
			 */
        List<EndData> ends = com.getEnds();
        EndData CombinedEnd = ends.get(0);
        int RootNet = -1;
        /* We search for the root net in the list of nets */
        for (int i = 0; i < MyNets.size() && RootNet < 0; i++) {
            if (MyNets.get(i).contains(CombinedEnd.getLocation())) {
                RootNet = i;
            }
        }
        if (RootNet < 0) {
            Reporter.AddFatalError("BUG: Splitter without a bus connection\n ==> " + this.getClass().getName().replaceAll("\\.", "/") + ":" + Thread.currentThread().getStackTrace()[2].getLineNumber() + "\n");
            this.clear();
            panel.dispose();
            return false;
        }
        /*
			 * Now we process all the other ends to find the child busses/nets
			 * of this root bus
			 */
        ArrayList<Integer> Connections = new ArrayList<Integer>();
        for (int i = 1; i < ends.size(); i++) {
            EndData ThisEnd = ends.get(i);
            /* Find the connected net */
            int ConnectedNet = -1;
            for (int j = 0; j < MyNets.size() && ConnectedNet < 1; j++) {
                if (MyNets.get(j).contains(ThisEnd.getLocation())) {
                    ConnectedNet = j;
                }
            }
            Connections.add(ConnectedNet);
        }
        boolean unconnectedEnds = false;
        for (int i = 1; i < ends.size(); i++) {
            int ConnectedNet = Connections.get(i - 1);
            if (ConnectedNet >= 0) {
                /* There is a net connected to this splitter's end point */
                if (!MyNets.get(ConnectedNet).setParent(MyNets.get(RootNet))) {
                    MyNets.get(ConnectedNet).ForceRootNet();
                }
                /* Here we have to process the inherited bits of the parent */
                byte[] BusBitConnection = ((Splitter) com).GetEndpoints();
                for (byte b = 0; b < BusBitConnection.length; b++) {
                    if (BusBitConnection[b] == i) {
                        MyNets.get(ConnectedNet).AddParrentBit(b);
                    }
                }
            } else {
                unconnectedEnds = true;
            }
        }
        if (unconnectedEnds) {
            SimpleDRCContainer warn = new SimpleDRCContainer(MyCircuit, Strings.get("NetList_NoSplitterEndConnections"), SimpleDRCContainer.LEVEL_NORMAL, SimpleDRCContainer.MARK_INSTANCE);
            warn.AddMarkComponent(com);
            Reporter.AddWarning(warn);
        }
    }
    progres.setValue(5);
    ProgRect = progres.getBounds();
    ProgRect.x = 0;
    ProgRect.y = 0;
    progres.paintImmediately(ProgRect);
    /*
		 * Now the complete netlist is created, we have to check that each
		 * net/bus entry has only 1 source and 1 or more sinks. If there exist
		 * more than 1 source we have a short circuit! We keep track of the
		 * sources and sinks at the root nets/buses
		 */
    for (Net ThisNet : MyNets) {
        if (ThisNet.IsRootNet()) {
            ThisNet.InitializeSourceSinks();
        }
    }
    for (Component comp : components) {
        if (comp.getFactory() instanceof SubcircuitFactory) {
            if (!ProcessSubcircuit(comp, Reporter)) {
                this.clear();
                panel.dispose();
                return false;
            }
        } else if ((comp.getFactory() instanceof Pin) || (comp.getFactory().getIOInformation() != null) || (comp.getFactory().getHDLGenerator(HDLIdentifier, comp.getAttributeSet()) != null)) {
            if (!ProcessNormalComponent(comp, Reporter)) {
                this.clear();
                panel.dispose();
                return false;
            }
        }
    }
    progres.setValue(6);
    ProgRect = progres.getBounds();
    ProgRect.x = 0;
    ProgRect.y = 0;
    progres.paintImmediately(ProgRect);
    /*
		 * Here we are going to process the complex splitters, note that in the
		 * previous handling of the splitters we marked all nets connected to a
		 * complex splitter with a forcerootnet annotation; we are going to
		 * cycle trough all these nets
		 */
    for (Net thisnet : MyNets) {
        if (thisnet.IsForcedRootNet()) {
            /* Cycle through all the bits of this net */
            for (int bit = 0; bit < thisnet.BitWidth(); bit++) {
                for (Component comp : MyComplexSplitters) {
                    /*
						 * Currently by definition end(0) is the combined end of
						 * the splitter
						 */
                    List<EndData> ends = comp.getEnds();
                    EndData CombinedEnd = ends.get(0);
                    int ConnectedBus = -1;
                    /* We search for the root net in the list of nets */
                    for (int i = 0; i < MyNets.size() && ConnectedBus < 0; i++) {
                        if (MyNets.get(i).contains(CombinedEnd.getLocation())) {
                            ConnectedBus = i;
                        }
                    }
                    if (ConnectedBus < 0) {
                        /*
							 * This should never happen as we already checked in
							 * the first pass
							 */
                        Reporter.AddFatalError("BUG: This is embarasing as this should never happen\n ==> " + this.getClass().getName().replaceAll("\\.", "/") + ":" + Thread.currentThread().getStackTrace()[2].getLineNumber() + "\n");
                        this.clear();
                        panel.dispose();
                        return false;
                    }
                    for (int endid = 1; endid < ends.size(); endid++) {
                        /*
							 * we iterate through all bits to see if the current
							 * net is connected to this splitter
							 */
                        if (thisnet.contains(ends.get(endid).getLocation())) {
                            /*
								 * first we have to get the bitindices of the
								 * rootbus
								 */
                            /*
								 * Here we have to process the inherited bits of
								 * the parent
								 */
                            byte[] BusBitConnection = ((Splitter) comp).GetEndpoints();
                            ArrayList<Byte> IndexBits = new ArrayList<Byte>();
                            for (byte b = 0; b < BusBitConnection.length; b++) {
                                if (BusBitConnection[b] == endid) {
                                    IndexBits.add(b);
                                }
                            }
                            byte ConnectedBusIndex = IndexBits.get(bit);
                            /* Figure out the rootbusid and rootbusindex */
                            Net Rootbus = MyNets.get(ConnectedBus);
                            while (!Rootbus.IsRootNet()) {
                                ConnectedBusIndex = Rootbus.getBit(ConnectedBusIndex);
                                Rootbus = Rootbus.getParent();
                            }
                            ConnectionPoint SolderPoint = new ConnectionPoint(comp);
                            SolderPoint.SetParrentNet(Rootbus, ConnectedBusIndex);
                            Boolean IsSink = true;
                            if (!thisnet.hasBitSource(bit)) {
                                if (HasHiddenSource(Rootbus, ConnectedBusIndex, MyComplexSplitters, comp, new HashSet<String>())) {
                                    IsSink = false;
                                }
                            }
                            if (IsSink) {
                                thisnet.addSinkNet(bit, SolderPoint);
                            } else {
                                thisnet.addSourceNet(bit, SolderPoint);
                            }
                        }
                    }
                }
            }
        }
    }
    progres.setValue(7);
    ProgRect = progres.getBounds();
    ProgRect.x = 0;
    ProgRect.y = 0;
    progres.paintImmediately(ProgRect);
    panel.dispose();
    /* So now we have all information we need! */
    return true;
}
Also used : GridBagConstraints(java.awt.GridBagConstraints) SplitterFactory(com.cburch.logisim.circuit.SplitterFactory) GridBagLayout(java.awt.GridBagLayout) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JProgressBar(javax.swing.JProgressBar) Rectangle(java.awt.Rectangle) Probe(com.cburch.logisim.std.wiring.Probe) JFrame(javax.swing.JFrame) SubcircuitFactory(com.cburch.logisim.circuit.SubcircuitFactory) InstanceComponent(com.cburch.logisim.instance.InstanceComponent) Component(com.cburch.logisim.comp.Component) HashSet(java.util.HashSet) EndData(com.cburch.logisim.comp.EndData) Splitter(com.cburch.logisim.circuit.Splitter) JLabel(javax.swing.JLabel) Tunnel(com.cburch.logisim.std.wiring.Tunnel) Pin(com.cburch.logisim.std.wiring.Pin) Location(com.cburch.logisim.data.Location)

Example 77 with Component

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

the class Netlist method MarkClockSourceComponents.

public boolean MarkClockSourceComponents(ArrayList<String> HierarchyNames, ArrayList<Netlist> HierarchyNetlists, ClockSourceContainer ClockSources, FPGAReport Reporter) {
    /* First pass: we go down the hierarchy till the leaves */
    for (NetlistComponent sub : MySubCircuits) {
        ArrayList<String> NewHierarchyNames = new ArrayList<String>();
        ArrayList<Netlist> NewHierarchyNetlists = new ArrayList<Netlist>();
        SubcircuitFactory SubFact = (SubcircuitFactory) sub.GetComponent().getFactory();
        NewHierarchyNames.addAll(HierarchyNames);
        NewHierarchyNames.add(CorrectLabel.getCorrectLabel(sub.GetComponent().getAttributeSet().getValue(StdAttr.LABEL)));
        NewHierarchyNetlists.addAll(HierarchyNetlists);
        NewHierarchyNetlists.add(SubFact.getSubcircuit().getNetList());
        if (!SubFact.getSubcircuit().getNetList().MarkClockSourceComponents(NewHierarchyNames, NewHierarchyNetlists, ClockSources, Reporter)) {
            return false;
        }
    }
    /*
		 * We see if some components require the Global fast FPGA
		 * clock
		 */
    for (Component comp : MyCircuit.getNonWires()) {
        if (comp.getFactory().RequiresGlobalClock()) {
            ClockSources.SetGloblaClockRequirement();
        }
    }
    /* Second pass: We mark all clock sources */
    for (NetlistComponent ClockSource : MyClockGenerators) {
        if (ClockSource.NrOfEnds() != 1) {
            Reporter.AddFatalError("BUG: Found a clock source with more than 1 connection\n ==> " + this.getClass().getName().replaceAll("\\.", "/") + ":" + Thread.currentThread().getStackTrace()[2].getLineNumber() + "\n");
            return false;
        }
        ConnectionEnd ClockConnection = ClockSource.getEnd(0);
        if (ClockConnection.NrOfBits() != 1) {
            Reporter.AddFatalError("BUG: Found a clock source with a bus as output\n ==> " + this.getClass().getName().replaceAll("\\.", "/") + ":" + Thread.currentThread().getStackTrace()[2].getLineNumber() + "\n");
            return false;
        }
        ConnectionPoint SolderPoint = ClockConnection.GetConnection((byte) 0);
        /* Check if the clock source is connected */
        if (SolderPoint.GetParrentNet() != null) {
            /* Third pass: add this clock to the list of ClockSources */
            int clockid = ClockSources.getClockId(ClockSource.GetComponent());
            /* Forth pass: Add this source as clock source to the tree */
            MyClockInformation.AddClockSource(HierarchyNames, clockid, SolderPoint);
            /* Fifth pass: trace the clock net all the way */
            if (!TraceClockNet(SolderPoint.GetParrentNet(), SolderPoint.GetParrentNetBitIndex(), clockid, HierarchyNames, HierarchyNetlists, Reporter)) {
                return false;
            }
            /*
				 * Sixth pass: We have to account for the complex splitters;
				 * therefore we have also to trace through our own netlist to
				 * find the clock connections
				 */
            ArrayList<ConnectionPoint> HiddenSinks = GetHiddenSinkNets(SolderPoint.GetParrentNet(), SolderPoint.GetParrentNetBitIndex(), MyComplexSplitters, null, new HashSet<String>(), true);
            for (ConnectionPoint thisNet : HiddenSinks) {
                MarkClockNet(HierarchyNames, clockid, thisNet);
                if (!TraceClockNet(thisNet.GetParrentNet(), thisNet.GetParrentNetBitIndex(), clockid, HierarchyNames, HierarchyNetlists, Reporter)) {
                    return false;
                }
            }
        }
    }
    return true;
}
Also used : ArrayList(java.util.ArrayList) SubcircuitFactory(com.cburch.logisim.circuit.SubcircuitFactory) InstanceComponent(com.cburch.logisim.instance.InstanceComponent) Component(com.cburch.logisim.comp.Component)

Example 78 with Component

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

the class Netlist method GetHiddenSource.

private SourceInfo GetHiddenSource(Net thisNet, Byte bitIndex, List<Component> SplitterList, Component ActiveSplitter, Set<String> HandledNets, Set<Wire> Segments, FPGAReport Reporter) {
    /*
		 * to prevent deadlock situations we check if we already looked at this
		 * net
		 */
    String NetId = Integer.toString(MyNets.indexOf(thisNet)) + "-" + Byte.toString(bitIndex);
    if (HandledNets.contains(NetId)) {
        return null;
    } else {
        HandledNets.add(NetId);
        Segments.addAll(thisNet.getWires());
    }
    if (thisNet.hasBitSource(bitIndex)) {
        List<ConnectionPoint> sources = thisNet.GetBitSources(bitIndex);
        if (sources.size() != 1) {
            Reporter.AddFatalError("BUG: Found multiple sources\n ==> " + this.getClass().getName().replaceAll("\\.", "/") + ":" + Thread.currentThread().getStackTrace()[2].getLineNumber() + "\n");
            return null;
        }
        return new SourceInfo(sources.get(0), bitIndex);
    }
    /* Check if we have a connection to another splitter */
    for (Component currentSplitter : SplitterList) {
        if (currentSplitter.equals(ActiveSplitter)) {
            continue;
        }
        List<EndData> ends = currentSplitter.getEnds();
        for (byte end = 0; end < ends.size(); end++) {
            if (thisNet.contains(ends.get(end).getLocation())) {
                /* Here we have to process the inherited bits of the parent */
                byte[] BusBitConnection = ((Splitter) currentSplitter).GetEndpoints();
                if (end == 0) {
                    /* this is a main net, find the connected end */
                    Byte SplitterEnd = BusBitConnection[bitIndex];
                    /* Find the corresponding Net index */
                    Byte Netindex = 0;
                    for (int index = 0; index < bitIndex; index++) {
                        if (BusBitConnection[index] == SplitterEnd) {
                            Netindex++;
                        }
                    }
                    /* Find the connected Net */
                    Net SlaveNet = null;
                    for (Net thisnet : MyNets) {
                        if (thisnet.contains(ends.get(SplitterEnd).getLocation())) {
                            SlaveNet = thisnet;
                        }
                    }
                    if (SlaveNet != null) {
                        if (SlaveNet.IsRootNet()) {
                            /* Trace down the slavenet */
                            SourceInfo ret = GetHiddenSource(SlaveNet, Netindex, SplitterList, currentSplitter, HandledNets, Segments, Reporter);
                            if (ret != null)
                                return ret;
                        } else {
                            SourceInfo ret = GetHiddenSource(SlaveNet.getParent(), SlaveNet.getBit(Netindex), SplitterList, currentSplitter, HandledNets, Segments, Reporter);
                            if (ret != null)
                                return ret;
                        }
                    }
                } else {
                    ArrayList<Byte> Rootindices = new ArrayList<Byte>();
                    for (byte b = 0; b < BusBitConnection.length; b++) {
                        if (BusBitConnection[b] == end) {
                            Rootindices.add(b);
                        }
                    }
                    Net RootNet = null;
                    for (Net thisnet : MyNets) {
                        if (thisnet.contains(currentSplitter.getEnd(0).getLocation())) {
                            RootNet = thisnet;
                        }
                    }
                    if (RootNet != null) {
                        if (RootNet.IsRootNet()) {
                            SourceInfo ret = GetHiddenSource(RootNet, Rootindices.get(bitIndex), SplitterList, currentSplitter, HandledNets, Segments, Reporter);
                            if (ret != null)
                                return ret;
                        } else {
                            SourceInfo ret = GetHiddenSource(RootNet.getParent(), RootNet.getBit(Rootindices.get(bitIndex)), SplitterList, currentSplitter, HandledNets, Segments, Reporter);
                            if (ret != null)
                                return ret;
                        }
                    }
                }
            }
        }
    }
    return null;
}
Also used : EndData(com.cburch.logisim.comp.EndData) Splitter(com.cburch.logisim.circuit.Splitter) ArrayList(java.util.ArrayList) InstanceComponent(com.cburch.logisim.instance.InstanceComponent) Component(com.cburch.logisim.comp.Component)

Example 79 with Component

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

the class CanvasPainter method drawWithUserState.

private void drawWithUserState(Graphics base, Graphics g, Project proj) {
    Circuit circ = proj.getCurrentCircuit();
    Selection sel = proj.getSelection();
    Set<Component> hidden;
    Tool dragTool = canvas.getDragTool();
    if (dragTool == null) {
        hidden = NO_COMPONENTS;
    } else {
        hidden = dragTool.getHiddenComponents(canvas);
        if (hidden == null)
            hidden = NO_COMPONENTS;
    }
    // draw halo around component whose attributes we are viewing
    boolean showHalo = AppPreferences.ATTRIBUTE_HALO.getBoolean();
    if (showHalo && haloedComponent != null && haloedCircuit == circ && !hidden.contains(haloedComponent)) {
        GraphicsUtil.switchToWidth(g, 3);
        g.setColor(Canvas.HALO_COLOR);
        Bounds bds = haloedComponent.getBounds(g).expand(5);
        int w = bds.getWidth();
        int h = bds.getHeight();
        double a = Canvas.SQRT_2 * w;
        double b = Canvas.SQRT_2 * h;
        g.drawOval((int) Math.round(bds.getX() + w / 2.0 - a / 2.0), (int) Math.round(bds.getY() + h / 2.0 - b / 2.0), (int) Math.round(a), (int) Math.round(b));
        GraphicsUtil.switchToWidth(g, 1);
        g.setColor(Color.BLACK);
    }
    // draw circuit and selection
    CircuitState circState = proj.getCircuitState();
    boolean printerView = AppPreferences.PRINTER_VIEW.getBoolean();
    ComponentDrawContext context = new ComponentDrawContext(canvas, circ, circState, base, g, printerView);
    context.setHighlightedWires(highlightedWires);
    circ.draw(context, hidden);
    sel.draw(context, hidden);
    // draw tool
    Tool tool = dragTool != null ? dragTool : proj.getTool();
    if (tool != null && !canvas.isPopupMenuUp()) {
        Graphics gCopy = g.create();
        context.setGraphics(gCopy);
        tool.draw(canvas, context);
        gCopy.dispose();
    }
}
Also used : CircuitState(com.cburch.logisim.circuit.CircuitState) Graphics(java.awt.Graphics) ComponentDrawContext(com.cburch.logisim.comp.ComponentDrawContext) Bounds(com.cburch.logisim.data.Bounds) Circuit(com.cburch.logisim.circuit.Circuit) Component(com.cburch.logisim.comp.Component) Tool(com.cburch.logisim.tools.Tool)

Example 80 with Component

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

the class XmlCircuitReader method buildCircuit.

private void buildCircuit(XmlReader.CircuitData circData, CircuitMutator mutator) {
    Element elt = circData.circuitElement;
    Circuit dest = circData.circuit;
    Map<Element, Component> knownComponents = circData.knownComponents;
    if (knownComponents == null)
        knownComponents = Collections.emptyMap();
    try {
        /* Here we check the attribute circuitnamedbox for backwards compatibility */
        boolean HasNamedBox = false;
        for (Element attrElt : XmlIterator.forChildElements(circData.circuitElement, "a")) {
            if (attrElt.hasAttribute("name")) {
                String Name = attrElt.getAttribute("name");
                if (Name.equals("circuitnamedbox")) {
                    HasNamedBox = true;
                }
            }
        }
        reader.initAttributeSet(circData.circuitElement, dest.getStaticAttributes(), null);
        if ((!HasNamedBox) && circData.circuitElement.hasChildNodes()) {
            dest.getStaticAttributes().setValue(CircuitAttributes.NAMED_CIRCUIT_BOX, false);
        }
    } catch (XmlReaderException e) {
        reader.addErrors(e, circData.circuit.getName() + ".static");
    }
    for (Element sub_elt : XmlIterator.forChildElements(elt)) {
        String sub_elt_name = sub_elt.getTagName();
        if (sub_elt_name.equals("comp")) {
            try {
                Component comp = knownComponents.get(sub_elt);
                if (comp == null) {
                    comp = getComponent(sub_elt, reader);
                }
                if (comp != null) {
                    mutator.add(dest, comp);
                }
            } catch (XmlReaderException e) {
                reader.addErrors(e, circData.circuit.getName() + "." + toComponentString(sub_elt));
            }
        } else if (sub_elt_name.equals("wire")) {
            try {
                addWire(dest, mutator, sub_elt);
            } catch (XmlReaderException e) {
                reader.addErrors(e, circData.circuit.getName() + "." + toWireString(sub_elt));
            }
        }
    }
    List<AbstractCanvasObject> appearance = circData.appearance;
    if (appearance != null && !appearance.isEmpty()) {
        dest.getAppearance().setObjectsForce(appearance);
        dest.getAppearance().setDefaultAppearance(false);
    }
}
Also used : Element(org.w3c.dom.Element) AbstractCanvasObject(com.cburch.draw.model.AbstractCanvasObject) Circuit(com.cburch.logisim.circuit.Circuit) 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