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;
}
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);
}
}
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;
}
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()));
}
}
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();
}
Aggregations