Search in sources :

Example 1 with WireRepair

use of com.cburch.logisim.tools.WireRepair in project logisim-evolution by reds-heig.

the class AbstractGate method getInstanceFeature.

@Override
protected Object getInstanceFeature(final Instance instance, Object key) {
    if (key == WireRepair.class) {
        return new WireRepair() {

            public boolean shouldRepairWire(WireRepairData data) {
                return AbstractGate.this.shouldRepairWire(instance, data);
            }
        };
    }
    if (key == ExpressionComputer.class) {
        return new ExpressionComputer() {

            public void computeExpression(Map<Location, Expression> expressionMap) {
                GateAttributes attrs = (GateAttributes) instance.getAttributeSet();
                int inputCount = attrs.inputs;
                int negated = attrs.negated;
                Expression[] inputs = new Expression[inputCount];
                int numInputs = 0;
                for (int i = 1; i <= inputCount; i++) {
                    Expression e = expressionMap.get(instance.getPortLocation(i));
                    if (e != null) {
                        int negatedBit = (negated >> (i - 1)) & 1;
                        if (negatedBit == 1) {
                            e = Expressions.not(e);
                        }
                        inputs[numInputs] = e;
                        ++numInputs;
                    }
                }
                if (numInputs > 0) {
                    Expression out = AbstractGate.this.computeExpression(inputs, numInputs);
                    expressionMap.put(instance.getPortLocation(0), out);
                }
            }
        };
    }
    return super.getInstanceFeature(instance, key);
}
Also used : ExpressionComputer(com.cburch.logisim.circuit.ExpressionComputer) WireRepair(com.cburch.logisim.tools.WireRepair) WireRepairData(com.cburch.logisim.tools.WireRepairData) Expression(com.cburch.logisim.analyze.model.Expression) Map(java.util.Map)

Aggregations

Expression (com.cburch.logisim.analyze.model.Expression)1 ExpressionComputer (com.cburch.logisim.circuit.ExpressionComputer)1 WireRepair (com.cburch.logisim.tools.WireRepair)1 WireRepairData (com.cburch.logisim.tools.WireRepairData)1 Map (java.util.Map)1