Search in sources :

Example 11 with Instance

use of com.cburch.logisim.instance.Instance in project logisim-evolution by reds-heig.

the class DefaultAppearance method old_build.

private static List<CanvasObject> old_build(Collection<Instance> pins) {
    Map<Direction, List<Instance>> edge;
    edge = new HashMap<Direction, List<Instance>>();
    edge.put(Direction.NORTH, new ArrayList<Instance>());
    edge.put(Direction.SOUTH, new ArrayList<Instance>());
    edge.put(Direction.EAST, new ArrayList<Instance>());
    edge.put(Direction.WEST, new ArrayList<Instance>());
    for (Instance pin : pins) {
        Direction pinFacing = pin.getAttributeValue(StdAttr.FACING);
        Direction pinEdge = pinFacing.reverse();
        List<Instance> e = edge.get(pinEdge);
        e.add(pin);
    }
    for (Map.Entry<Direction, List<Instance>> entry : edge.entrySet()) {
        sortPinList(entry.getValue(), entry.getKey());
    }
    int numNorth = edge.get(Direction.NORTH).size();
    int numSouth = edge.get(Direction.SOUTH).size();
    int numEast = edge.get(Direction.EAST).size();
    int numWest = edge.get(Direction.WEST).size();
    int maxVert = Math.max(numNorth, numSouth);
    int maxHorz = Math.max(numEast, numWest);
    int offsNorth = computeOffset(numNorth, numSouth, maxHorz);
    int offsSouth = computeOffset(numSouth, numNorth, maxHorz);
    int offsEast = computeOffset(numEast, numWest, maxVert);
    int offsWest = computeOffset(numWest, numEast, maxVert);
    int width = computeDimension(maxVert, maxHorz);
    int height = computeDimension(maxHorz, maxVert);
    // compute position of anchor relative to top left corner of box
    int ax;
    int ay;
    if (numEast > 0) {
        // anchor is on east side
        ax = width;
        ay = offsEast;
    } else if (numNorth > 0) {
        // anchor is on north side
        ax = offsNorth;
        ay = 0;
    } else if (numWest > 0) {
        // anchor is on west side
        ax = 0;
        ay = offsWest;
    } else if (numSouth > 0) {
        // anchor is on south side
        ax = offsSouth;
        ay = height;
    } else {
        // anchor is top left corner
        ax = 0;
        ay = 0;
    }
    // place rectangle so anchor is on the grid
    int rx = OFFS + (9 - (ax + 9) % 10);
    int ry = OFFS + (9 - (ay + 9) % 10);
    Location e0 = Location.create(rx + (width - 8) / 2, ry + 1);
    Location e1 = Location.create(rx + (width + 8) / 2, ry + 1);
    Location ct = Location.create(rx + width / 2, ry + 11);
    Curve notch = new Curve(e0, e1, ct);
    notch.setValue(DrawAttr.STROKE_WIDTH, Integer.valueOf(2));
    notch.setValue(DrawAttr.STROKE_COLOR, Color.GRAY);
    Rectangle rect = new Rectangle(rx, ry, width, height);
    rect.setValue(DrawAttr.STROKE_WIDTH, Integer.valueOf(2));
    List<CanvasObject> ret = new ArrayList<CanvasObject>();
    ret.add(notch);
    ret.add(rect);
    placePins(ret, edge.get(Direction.WEST), rx, ry + offsWest, 0, 10);
    placePins(ret, edge.get(Direction.EAST), rx + width, ry + offsEast, 0, 10);
    placePins(ret, edge.get(Direction.NORTH), rx + offsNorth, ry, 10, 0);
    placePins(ret, edge.get(Direction.SOUTH), rx + offsSouth, ry + height, 10, 0);
    ret.add(new AppearanceAnchor(Location.create(rx + ax, ry + ay)));
    return ret;
}
Also used : Instance(com.cburch.logisim.instance.Instance) Curve(com.cburch.draw.shapes.Curve) Rectangle(com.cburch.draw.shapes.Rectangle) ArrayList(java.util.ArrayList) Direction(com.cburch.logisim.data.Direction) CanvasObject(com.cburch.draw.model.CanvasObject) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) Location(com.cburch.logisim.data.Location)

Example 12 with Instance

use of com.cburch.logisim.instance.Instance in project logisim-evolution by reds-heig.

the class AppearanceSvgReader method createShape.

public static AbstractCanvasObject createShape(Element elt, Map<Location, Instance> pins) {
    String name = elt.getTagName();
    if (name.equals("circ-anchor") || name.equals("circ-origin")) {
        Location loc = getLocation(elt);
        AbstractCanvasObject ret = new AppearanceAnchor(loc);
        if (elt.hasAttribute("facing")) {
            Direction facing = Direction.parse(elt.getAttribute("facing"));
            ret.setValue(AppearanceAnchor.FACING, facing);
        }
        return ret;
    } else if (name.equals("circ-port")) {
        Location loc = getLocation(elt);
        String[] pinStr = elt.getAttribute("pin").split(",");
        Location pinLoc = Location.create(Integer.parseInt(pinStr[0].trim()), Integer.parseInt(pinStr[1].trim()));
        Instance pin = pins.get(pinLoc);
        if (pin == null) {
            return null;
        } else {
            return new AppearancePort(loc, pin);
        }
    } else {
        return SvgReader.createShape(elt);
    }
}
Also used : Instance(com.cburch.logisim.instance.Instance) AbstractCanvasObject(com.cburch.draw.model.AbstractCanvasObject) Direction(com.cburch.logisim.data.Direction) Location(com.cburch.logisim.data.Location)

Example 13 with Instance

use of com.cburch.logisim.instance.Instance in project logisim-evolution by reds-heig.

the class Ram method getState.

@Override
MemState getState(InstanceState state) {
    RamState ret = (RamState) state.getData();
    if (ret == null) {
        MemContents contents = state.getInstance().getAttributeValue(Ram.CONTENTS_ATTR);
        Instance instance = state.getInstance();
        ret = new RamState(instance, contents.clone(), new MemListener(instance));
        state.setData(ret);
    } else {
        ret.setRam(state.getInstance());
    }
    return ret;
}
Also used : Instance(com.cburch.logisim.instance.Instance)

Example 14 with Instance

use of com.cburch.logisim.instance.Instance in project logisim-evolution by reds-heig.

the class Analyze method computeExpression.

// 
// computeExpression
// 
/**
 * Computes the expression corresponding to the given circuit, or raises
 * ComputeException if difficulties arise.
 */
public static void computeExpression(AnalyzerModel model, Circuit circuit, Map<Instance, String> pinNames) throws AnalyzeException {
    ExpressionMap expressionMap = new ExpressionMap(circuit);
    ArrayList<String> inputNames = new ArrayList<String>();
    ArrayList<String> outputNames = new ArrayList<String>();
    ArrayList<Instance> outputPins = new ArrayList<Instance>();
    for (Map.Entry<Instance, String> entry : pinNames.entrySet()) {
        Instance pin = entry.getKey();
        String label = entry.getValue();
        if (Pin.FACTORY.isInputPin(pin)) {
            expressionMap.currentCause = Instance.getComponentFor(pin);
            Expression e = Expressions.variable(label);
            expressionMap.put(pin.getLocation(), e);
            inputNames.add(label);
        } else {
            outputPins.add(pin);
            outputNames.add(label);
        }
    }
    propagateComponents(expressionMap, circuit.getNonWires());
    for (int iterations = 0; !expressionMap.dirtyPoints.isEmpty(); iterations++) {
        if (iterations > MAX_ITERATIONS) {
            throw new AnalyzeException.Circular();
        }
        propagateWires(expressionMap, new HashSet<Location>(expressionMap.dirtyPoints));
        HashSet<Component> dirtyComponents = getDirtyComponents(circuit, expressionMap.dirtyPoints);
        expressionMap.dirtyPoints.clear();
        propagateComponents(expressionMap, dirtyComponents);
        Expression expr = checkForCircularExpressions(expressionMap);
        if (expr != null)
            throw new AnalyzeException.Circular();
    }
    model.setVariables(inputNames, outputNames);
    for (int i = 0; i < outputPins.size(); i++) {
        Instance pin = outputPins.get(i);
        model.getOutputExpressions().setExpression(outputNames.get(i), expressionMap.get(pin.getLocation()));
    }
}
Also used : Instance(com.cburch.logisim.instance.Instance) ArrayList(java.util.ArrayList) Expression(com.cburch.logisim.analyze.model.Expression) Component(com.cburch.logisim.comp.Component) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Map(java.util.Map) SortedMap(java.util.SortedMap) Location(com.cburch.logisim.data.Location)

Example 15 with Instance

use of com.cburch.logisim.instance.Instance in project logisim-evolution by reds-heig.

the class ProjectCircuitActions method doAnalyze.

public static void doAnalyze(Project proj, Circuit circuit) {
    Map<Instance, String> pinNames = Analyze.getPinLabels(circuit);
    ArrayList<String> inputNames = new ArrayList<String>();
    ArrayList<String> outputNames = new ArrayList<String>();
    for (Map.Entry<Instance, String> entry : pinNames.entrySet()) {
        Instance pin = entry.getKey();
        boolean isInput = Pin.FACTORY.isInputPin(pin);
        if (isInput) {
            inputNames.add(entry.getValue());
        } else {
            outputNames.add(entry.getValue());
        }
        if (pin.getAttributeValue(StdAttr.WIDTH).getWidth() > 1) {
            if (isInput) {
                analyzeError(proj, Strings.get("analyzeMultibitInputError"));
            } else {
                analyzeError(proj, Strings.get("analyzeMultibitOutputError"));
            }
            return;
        }
    }
    if (inputNames.size() > AnalyzerModel.MAX_INPUTS) {
        analyzeError(proj, StringUtil.format(Strings.get("analyzeTooManyInputsError"), "" + AnalyzerModel.MAX_INPUTS));
        return;
    }
    if (outputNames.size() > AnalyzerModel.MAX_OUTPUTS) {
        analyzeError(proj, StringUtil.format(Strings.get("analyzeTooManyOutputsError"), "" + AnalyzerModel.MAX_OUTPUTS));
        return;
    }
    Analyzer analyzer = AnalyzerManager.getAnalyzer();
    analyzer.getModel().setCurrentCircuit(proj, circuit);
    configureAnalyzer(proj, circuit, analyzer, pinNames, inputNames, outputNames);
    analyzer.setVisible(true);
    analyzer.toFront();
}
Also used : Instance(com.cburch.logisim.instance.Instance) ArrayList(java.util.ArrayList) Analyzer(com.cburch.logisim.analyze.gui.Analyzer) Map(java.util.Map)

Aggregations

Instance (com.cburch.logisim.instance.Instance)28 ArrayList (java.util.ArrayList)14 Map (java.util.Map)10 Direction (com.cburch.logisim.data.Direction)9 Location (com.cburch.logisim.data.Location)9 HashMap (java.util.HashMap)9 Graphics (java.awt.Graphics)5 CanvasObject (com.cburch.draw.model.CanvasObject)4 Component (com.cburch.logisim.comp.Component)4 Bounds (com.cburch.logisim.data.Bounds)4 InstanceState (com.cburch.logisim.instance.InstanceState)4 List (java.util.List)4 TreeMap (java.util.TreeMap)4 Rectangle (com.cburch.draw.shapes.Rectangle)3 Text (com.cburch.draw.shapes.Text)3 CircuitState (com.cburch.logisim.circuit.CircuitState)3 Value (com.cburch.logisim.data.Value)3 Font (java.awt.Font)3 FontMetrics (java.awt.FontMetrics)3 Graphics2D (java.awt.Graphics2D)3