Search in sources :

Example 26 with Component

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

the class CircuitWires method connectTunnels.

private void connectTunnels(BundleMap ret) {
    // determine the sets of tunnels
    HashMap<String, ArrayList<Location>> tunnelSets = new HashMap<String, ArrayList<Location>>();
    for (Component comp : tunnels) {
        String label = comp.getAttributeSet().getValue(StdAttr.LABEL);
        label = label.trim();
        if (!label.equals("")) {
            ArrayList<Location> tunnelSet = tunnelSets.get(label);
            if (tunnelSet == null) {
                tunnelSet = new ArrayList<Location>(3);
                tunnelSets.put(label, tunnelSet);
            }
            tunnelSet.add(comp.getLocation());
        }
    }
    // now connect the bundles that are tunnelled together
    for (ArrayList<Location> tunnelSet : tunnelSets.values()) {
        WireBundle foundBundle = null;
        Location foundLocation = null;
        for (Location loc : tunnelSet) {
            WireBundle b = ret.getBundleAt(loc);
            if (b != null) {
                foundBundle = b;
                foundLocation = loc;
                break;
            }
        }
        if (foundBundle == null) {
            foundLocation = tunnelSet.get(0);
            foundBundle = ret.createBundleAt(foundLocation);
        }
        for (Location loc : tunnelSet) {
            if (loc != foundLocation) {
                WireBundle b = ret.getBundleAt(loc);
                if (b == null) {
                    foundBundle.points.add(loc);
                    ret.setBundleAt(loc, foundBundle);
                } else {
                    b.unite(foundBundle);
                }
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Component(com.cburch.logisim.comp.Component) Location(com.cburch.logisim.data.Location)

Example 27 with Component

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

the class CircuitWires method connectPullResistors.

private void connectPullResistors(BundleMap ret) {
    for (Component comp : pulls) {
        Location loc = comp.getEnd(0).getLocation();
        WireBundle b = ret.getBundleAt(loc);
        if (b == null) {
            b = ret.createBundleAt(loc);
            b.points.add(loc);
            ret.setBundleAt(loc, b);
        }
        Instance instance = Instance.getInstanceFor(comp);
        b.addPullValue(PullResistor.getPullValue(instance));
    }
}
Also used : Instance(com.cburch.logisim.instance.Instance) Component(com.cburch.logisim.comp.Component) Location(com.cburch.logisim.data.Location)

Example 28 with Component

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

the class CircuitWires method draw.

void draw(ComponentDrawContext context, Collection<Component> hidden) {
    boolean showState = context.getShowState();
    CircuitState state = context.getCircuitState();
    Graphics g = context.getGraphics();
    g.setColor(Color.BLACK);
    GraphicsUtil.switchToWidth(g, Wire.WIDTH);
    WireSet highlighted = context.getHighlightedWires();
    BundleMap bmap = getBundleMap();
    boolean isValid = bmap.isValid();
    if (hidden == null || hidden.size() == 0) {
        for (Wire w : wires) {
            Location s = w.e0;
            Location t = w.e1;
            WireBundle wb = bmap.getBundleAt(s);
            int width = 5;
            if (!wb.isValid()) {
                g.setColor(Value.WIDTH_ERROR_COLOR);
            } else if (showState) {
                if (!isValid)
                    g.setColor(Value.NIL_COLOR);
                else
                    g.setColor(state.getValue(s).getColor());
            } else {
                g.setColor(Color.BLACK);
            }
            if (highlighted.containsWire(w)) {
                if (wb.isBus())
                    width = Wire.HIGHLIGHTED_WIDTH_BUS;
                else
                    width = Wire.HIGHLIGHTED_WIDTH;
                GraphicsUtil.switchToWidth(g, width);
                g.drawLine(s.getX(), s.getY(), t.getX(), t.getY());
            } else {
                if (wb.isBus())
                    width = Wire.WIDTH_BUS;
                else
                    width = Wire.WIDTH;
                GraphicsUtil.switchToWidth(g, width);
                g.drawLine(s.getX(), s.getY(), t.getX(), t.getY());
            }
            if (w.IsSetAsMarked()) {
                width += 2;
                g.setColor(w.GetMarkColor());
                GraphicsUtil.switchToWidth(g, 2);
                if (w.isVertical()) {
                    g.drawLine(s.getX() - width, s.getY(), t.getX() - width, t.getY());
                    g.drawLine(s.getX() + width, s.getY(), t.getX() + width, t.getY());
                } else {
                    g.drawLine(s.getX(), s.getY() - width, t.getX(), t.getY() - width);
                    g.drawLine(s.getX(), s.getY() + width, t.getX(), t.getY() + width);
                }
            }
        }
        for (Location loc : points.getSplitLocations()) {
            if (points.getComponentCount(loc) > 2) {
                WireBundle wb = bmap.getBundleAt(loc);
                if (wb != null) {
                    if (!wb.isValid()) {
                        g.setColor(Value.WIDTH_ERROR_COLOR);
                    } else if (showState) {
                        if (!isValid)
                            g.setColor(Value.NIL_COLOR);
                        else
                            g.setColor(state.getValue(loc).getColor());
                    } else {
                        g.setColor(Color.BLACK);
                    }
                    int radius;
                    if (highlighted.containsLocation(loc)) {
                        radius = wb.isBus() ? (int) (Wire.HIGHLIGHTED_WIDTH_BUS * Wire.DOT_MULTIPLY_FACTOR) : (int) (Wire.HIGHLIGHTED_WIDTH * Wire.DOT_MULTIPLY_FACTOR);
                    } else {
                        radius = wb.isBus() ? (int) (Wire.WIDTH_BUS * Wire.DOT_MULTIPLY_FACTOR) : (int) (Wire.WIDTH * Wire.DOT_MULTIPLY_FACTOR);
                    }
                    g.fillOval(loc.getX() - radius, loc.getY() - radius, radius * 2, radius * 2);
                }
            }
        }
    } else {
        for (Wire w : wires) {
            if (!hidden.contains(w)) {
                Location s = w.e0;
                Location t = w.e1;
                WireBundle wb = bmap.getBundleAt(s);
                if (!wb.isValid()) {
                    g.setColor(Value.WIDTH_ERROR_COLOR);
                } else if (showState) {
                    if (!isValid)
                        g.setColor(Value.NIL_COLOR);
                    else
                        g.setColor(state.getValue(s).getColor());
                } else {
                    g.setColor(Color.BLACK);
                }
                if (highlighted.containsWire(w)) {
                    GraphicsUtil.switchToWidth(g, Wire.WIDTH + 2);
                    g.drawLine(s.getX(), s.getY(), t.getX(), t.getY());
                    GraphicsUtil.switchToWidth(g, Wire.WIDTH);
                } else {
                    if (wb.isBus())
                        GraphicsUtil.switchToWidth(g, Wire.WIDTH_BUS);
                    else
                        GraphicsUtil.switchToWidth(g, Wire.WIDTH);
                    g.drawLine(s.getX(), s.getY(), t.getX(), t.getY());
                }
            }
        }
        // while at a time anway.
        for (Location loc : points.getSplitLocations()) {
            if (points.getComponentCount(loc) > 2) {
                int icount = 0;
                for (Component comp : points.getComponents(loc)) {
                    if (!hidden.contains(comp))
                        ++icount;
                }
                if (icount > 2) {
                    WireBundle wb = bmap.getBundleAt(loc);
                    if (wb != null) {
                        if (!wb.isValid()) {
                            g.setColor(Value.WIDTH_ERROR_COLOR);
                        } else if (showState) {
                            if (!isValid)
                                g.setColor(Value.NIL_COLOR);
                            else
                                g.setColor(state.getValue(loc).getColor());
                        } else {
                            g.setColor(Color.BLACK);
                        }
                        int radius;
                        if (highlighted.containsLocation(loc)) {
                            radius = wb.isBus() ? Wire.HIGHLIGHTED_WIDTH_BUS : Wire.HIGHLIGHTED_WIDTH;
                        } else {
                            radius = wb.isBus() ? Wire.WIDTH_BUS : Wire.WIDTH;
                        }
                        g.fillOval(loc.getX() - radius, loc.getY() - radius, radius * 2, radius * 2);
                    }
                }
            }
        }
    }
}
Also used : Graphics(java.awt.Graphics) Component(com.cburch.logisim.comp.Component) Location(com.cburch.logisim.data.Location)

Example 29 with Component

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

the class PropagationPoints method draw.

void draw(ComponentDrawContext context) {
    if (data.isEmpty())
        return;
    CircuitState state = context.getCircuitState();
    HashMap<CircuitState, CircuitState> stateMap = new HashMap<CircuitState, CircuitState>();
    for (CircuitState s : state.getSubstates()) {
        addSubstates(stateMap, s, s);
    }
    Graphics g = context.getGraphics();
    GraphicsUtil.switchToWidth(g, 2);
    for (Entry e : data) {
        if (e.state == state) {
            Location p = e.loc;
            g.drawOval(p.getX() - 4, p.getY() - 4, 8, 8);
        } else if (stateMap.containsKey(e.state)) {
            CircuitState substate = stateMap.get(e.state);
            Component subcirc = substate.getSubcircuit();
            Bounds b = subcirc.getBounds();
            g.drawRect(b.getX(), b.getY(), b.getWidth(), b.getHeight());
        }
    }
    GraphicsUtil.switchToWidth(g, 1);
}
Also used : Graphics(java.awt.Graphics) HashMap(java.util.HashMap) Bounds(com.cburch.logisim.data.Bounds) Component(com.cburch.logisim.comp.Component) Location(com.cburch.logisim.data.Location)

Example 30 with Component

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

the class LoadedLibrary method replaceAll.

private static void replaceAll(Circuit circuit, Map<ComponentFactory, ComponentFactory> compMap) {
    ArrayList<Component> toReplace = null;
    for (Component comp : circuit.getNonWires()) {
        if (compMap.containsKey(comp.getFactory())) {
            if (toReplace == null)
                toReplace = new ArrayList<Component>();
            toReplace.add(comp);
        }
    }
    if (toReplace != null) {
        CircuitMutation xn = new CircuitMutation(circuit);
        for (Component comp : toReplace) {
            xn.remove(comp);
            ComponentFactory factory = compMap.get(comp.getFactory());
            if (factory != null) {
                AttributeSet newAttrs = createAttributes(factory, comp.getAttributeSet());
                xn.add(factory.createComponent(comp.getLocation(), newAttrs));
            }
        }
        xn.execute();
    }
}
Also used : AttributeSet(com.cburch.logisim.data.AttributeSet) ComponentFactory(com.cburch.logisim.comp.ComponentFactory) ArrayList(java.util.ArrayList) CircuitMutation(com.cburch.logisim.circuit.CircuitMutation) 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