Package com.cburch.logisim.instance

Examples of com.cburch.logisim.instance.Instance


    BitWidth dataBits = state.getAttributeValue(DATA_ATTR);

    RamState myState = (RamState) state.getData();
    if (myState == null) {
      MemContents contents = MemContents.create(addrBits.getWidth(), dataBits.getWidth());
      Instance instance = state.getInstance();
      myState = new RamState(instance, contents, new MemListener(instance));
      state.setData(myState);
    } else {
      myState.setRam(state.getInstance());
    }
View Full Code Here


   
    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()));
    }
  }
View Full Code Here

    ArrayList<Instance> inputPins = new ArrayList<Instance>();
    ArrayList<String> inputNames = new ArrayList<String>();
    ArrayList<Instance> outputPins = new ArrayList<Instance>();
    ArrayList<String> outputNames = new ArrayList<String>();
    for (Map.Entry<Instance, String> entry : pinLabels.entrySet()) {
      Instance pin = entry.getKey();
      if (Pin.FACTORY.isInputPin(pin)) {
        inputPins.add(pin);
        inputNames.add(entry.getValue());
      } else {
        outputPins.add(pin);
        outputNames.add(entry.getValue());
      }
    }
   
    int inputCount = inputPins.size();
    int rowCount = 1 << inputCount;
    Entry[][] columns = new Entry[outputPins.size()][rowCount];
   
    for (int i = 0; i < rowCount; i++) {
      CircuitState circuitState = new CircuitState(proj, circuit);
      for (int j = 0; j < inputCount; j++) {
        Instance pin = inputPins.get(j);
        InstanceState pinState = circuitState.getInstanceState(pin);
        boolean value = TruthTable.isInputSet(i, j, inputCount);
        Pin.FACTORY.setValue(pinState, value ? Value.TRUE : Value.FALSE);
      }
     
      Propagator prop = circuitState.getPropagator();
      prop.propagate();
      /* TODO for the SimulatorPrototype class
      do {
        prop.step();
      } while (prop.isPending()); */
      // TODO: Search for circuit state
     
      if (prop.isOscillating()) {
        for (int j = 0; j < columns.length; j++) {
          columns[j][i] = Entry.OSCILLATE_ERROR;
        }
      } else {
        for (int j = 0; j < columns.length; j++) {
          Instance pin = outputPins.get(j);
          InstanceState pinState = circuitState.getInstanceState(pin);
          Entry out;
          Value outValue = Pin.FACTORY.getValue(pinState).get(0);
          if (outValue == Value.TRUE) out = Entry.ONE;
          else if (outValue == Value.FALSE) out = Entry.ZERO;
View Full Code Here

      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));
    }
  }
View Full Code Here

    g.setFont(attrs.getFont());
    FontMetrics fm = g.getFontMetrics();
    Bounds bds = computeBounds(attrs, fm.stringWidth(label),
        fm.getAscent() + fm.getDescent(), g, label);
    if (attrs.setOffsetBounds(bds)) {
      Instance instance = painter.getInstance();
      if (instance != null) instance.recomputeBounds();
    }
   
    int x0 = bds.getX();
    int y0 = bds.getY();
    int x1 = x0 + bds.getWidth();
View Full Code Here

            Rectangle bdsOut = GraphicsUtil.getTextBounds(g, textTrim, 0, 0,
                    halign, valign);
            newBds = Bounds.create(bdsOut).expand(4);
        }
        if (attrs.setOffsetBounds(newBds)) {
            Instance instance = painter.getInstance();
            if (instance != null) {
                instance.recomputeBounds();
            }

        }

        g.setFont(old);
View Full Code Here

        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()));
        }
    }
View Full Code Here

        ArrayList<Instance> inputPins = new ArrayList<Instance>();
        ArrayList<String> inputNames = new ArrayList<String>();
        ArrayList<Instance> outputPins = new ArrayList<Instance>();
        ArrayList<String> outputNames = new ArrayList<String>();
        for (Map.Entry<Instance, String> entry : pinLabels.entrySet()) {
            Instance pin = entry.getKey();
            if (Pin.FACTORY.isInputPin(pin)) {
                inputPins.add(pin);
                inputNames.add(entry.getValue());
            } else {
                outputPins.add(pin);
                outputNames.add(entry.getValue());
            }
        }

        int inputCount = inputPins.size();
        int rowCount = 1 << inputCount;
        Entry[][] columns = new Entry[outputPins.size()][rowCount];

        for (int i = 0; i < rowCount; i++) {
            CircuitState circuitState = new CircuitState(proj, circuit);
            for (int j = 0; j < inputCount; j++) {
                Instance pin = inputPins.get(j);
                InstanceState pinState = circuitState.getInstanceState(pin);
                boolean value = TruthTable.isInputSet(i, j, inputCount);
                Pin.FACTORY.setValue(pinState, value ? Value.TRUE : Value.FALSE);
            }

            Propagator prop = circuitState.getPropagator();
            prop.propagate();
            /* TODO for the SimulatorPrototype class
            do {
                prop.step();
            } while (prop.isPending()); */
            // TODO: Search for circuit state

            if (prop.isOscillating()) {
                for (int j = 0; j < columns.length; j++) {
                    columns[j][i] = Entry.OSCILLATE_ERROR;
                }
            } else {
                for (int j = 0; j < columns.length; j++) {
                    Instance pin = outputPins.get(j);
                    InstanceState pinState = circuitState.getInstanceState(pin);
                    Entry out;
                    Value outValue = Pin.FACTORY.getValue(pinState).get(0);
                    if (outValue == Value.TRUE) {
                        out = Entry.ONE;
View Full Code Here

        // which instances facing the same way in layout
        Set<Location> usedLocs = new HashSet<Location>();
        List<Instance> sameWay = new ArrayList<Instance>();
        Direction facing = pin.getAttributeValue(StdAttr.FACING);
        for (Map.Entry<Instance, AppearancePort> entry : others.entrySet()) {
            Instance pin2 = entry.getKey();
            Location loc = entry.getValue().getLocation();
            usedLocs.add(loc);
            if (pin2.getAttributeValue(StdAttr.FACING) == facing) {
                sameWay.add(pin2);
            }
        }

        // if at least one faces the same way, place pin relative to that
        if (sameWay.size() > 0) {
            sameWay.add(pin);
            DefaultAppearance.sortPinList(sameWay, facing);
            boolean isFirst = false;
            // (preferably previous in map)
            Instance neighbor = null;
            for (Instance p : sameWay) {
                if (p == pin) {
                    break;
                } else {
                    neighbor = p;
View Full Code Here

        Project proj = new Project(file);
        Circuit circuit = file.getMainCircuit();
        Map<Instance, String> pinNames = Analyze.getPinLabels(circuit);
        ArrayList<Instance> outputPins = new ArrayList<Instance>();
        Instance haltPin = null;
        for (Map.Entry<Instance, String> entry : pinNames.entrySet()) {
            Instance pin = entry.getKey();
            String pinName = entry.getValue();
            if (!Pin.FACTORY.isInputPin(pin)) {
                outputPins.add(pin);
                if (pinName.equals("halt")) {
                    haltPin = pin;
View Full Code Here

TOP

Related Classes of com.cburch.logisim.instance.Instance

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.