use of de.neemann.digital.draw.elements.VisualElement in project Digital by hneemann.
the class CircuitBuilder method createInputBus.
private void createInputBus(Collection<Variable> inputs, Circuit circuit) {
HashMap<String, Integer> varPos = new HashMap<>();
int dx = -inputs.size() * SIZE * 2;
pos -= SIZE;
for (Variable v : inputs) {
VisualElement visualElement;
if (sequentialVars.contains(v) || varsToNet.contains(v.getIdentifier())) {
visualElement = new VisualElement(Tunnel.DESCRIPTION.getName()).setShapeFactory(shapeFactory);
visualElement.getElementAttributes().set(Keys.ROTATE, new Rotation(1)).set(Keys.NETNAME, v.getIdentifier());
} else {
visualElement = new VisualElement(In.DESCRIPTION.getName()).setShapeFactory(shapeFactory);
visualElement.getElementAttributes().set(Keys.ROTATE, new Rotation(3)).set(Keys.LABEL, v.getIdentifier());
checkPinNumber(visualElement);
}
visualElement.setPos(new Vector(dx, -SIZE * 5));
circuit.add(visualElement);
circuit.add(new Wire(new Vector(dx, -SIZE * 5), new Vector(dx, pos)));
if (isNotNeeded(v.getIdentifier())) {
visualElement = new VisualElement(de.neemann.digital.core.basic.Not.DESCRIPTION.getName()).setShapeFactory(shapeFactory);
visualElement.getElementAttributes().set(Keys.ROTATE, new Rotation(3));
visualElement.setPos(new Vector(dx + SIZE, -SIZE * 3));
circuit.add(visualElement);
circuit.add(new Wire(new Vector(dx, -SIZE * 4), new Vector(dx + SIZE, -SIZE * 4)));
circuit.add(new Wire(new Vector(dx + SIZE, -SIZE * 3), new Vector(dx + SIZE, -SIZE * 4)));
circuit.add(new Wire(new Vector(dx + SIZE, -SIZE), new Vector(dx + SIZE, pos)));
}
varPos.put(v.getIdentifier(), dx);
dx += SIZE * 2;
}
for (FragmentVariable f : fragmentVariables) {
Vector p = f.getCircuitPos();
int in = varPos.get(f.getVariable().getIdentifier());
if (f.isInvert())
in += SIZE;
circuit.add(new Wire(p, new Vector(in, p.y)));
}
}
use of de.neemann.digital.draw.elements.VisualElement in project Digital by hneemann.
the class CircuitBuilder method checkForInputBus.
private void checkForInputBus(Collection<Variable> variables, int splitterXPos, Circuit circuit) {
StringBuilder pinString = new StringBuilder();
int y = 0;
for (Map.Entry<String, ArrayList<String>> e : mis.getInputBusMap().entrySet()) {
pinString.setLength(0);
int found = 0;
final ArrayList<String> inputs = e.getValue();
for (String n : inputs) {
if (variables.contains(new Variable(n))) {
found++;
String p = mis.getPins().get(n);
if (p != null) {
if (pinString.length() != 0)
pinString.append(",");
pinString.append(p);
}
}
}
if (found == inputs.size()) {
varsToNet.addAll(inputs);
circuit.add(new VisualElement(Splitter.DESCRIPTION.getName()).setAttribute(Keys.INPUT_SPLIT, "" + inputs.size()).setAttribute(Keys.OUTPUT_SPLIT, "1*" + inputs.size()).setPos(new Vector(splitterXPos, y)).setShapeFactory(shapeFactory));
circuit.add(new VisualElement(In.DESCRIPTION.getName()).setAttribute(Keys.LABEL, e.getKey()).setAttribute(Keys.BITS, inputs.size()).setAttribute(Keys.PINNUMBER, pinString.toString()).setPos(new Vector(splitterXPos - 2 * SIZE, y)).setShapeFactory(shapeFactory));
circuit.add(new Wire(new Vector(splitterXPos - 2 * SIZE, y), new Vector(splitterXPos, y)));
for (int i = 0; i < inputs.size(); i++) {
circuit.add(new VisualElement(Tunnel.DESCRIPTION.getName()).setAttribute(Keys.NETNAME, inputs.get(i)).setPos(new Vector(splitterXPos + 2 * SIZE, y + i * SIZE)).setShapeFactory(shapeFactory));
circuit.add(new Wire(new Vector(splitterXPos + SIZE, y + i * SIZE), new Vector(splitterXPos + 2 * SIZE, y + i * SIZE)));
}
y += (inputs.size() + 2) * SIZE;
}
}
}
use of de.neemann.digital.draw.elements.VisualElement in project Digital by hneemann.
the class ExportZipAction method addFile.
private void addFile(ZipOutputStream zip, File file, Circuit circuit) throws ElementNotFoundException, IOException {
addToZip(zip, file);
for (VisualElement ve : circuit.getElements()) {
String name = ve.getElementName();
if (!elementSet.contains(name)) {
elementSet.add(name);
ElementTypeDescription desc = lib.getElementType(name);
if (desc instanceof ElementLibrary.ElementTypeDescriptionCustom) {
ElementLibrary.ElementTypeDescriptionCustom custom = (ElementLibrary.ElementTypeDescriptionCustom) desc;
addFile(zip, custom.getFile(), custom.getCircuit());
}
}
}
}
use of de.neemann.digital.draw.elements.VisualElement in project Digital by hneemann.
the class InsertAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
if (node.isUnique()) {
VisualElement visualElement = new VisualElement(node.getName()).setPos(new Vector(10, 10)).setShapeFactory(shapeFactory);
if (getIcon() == null) {
try {
node.getDescription();
setIcon(node.getIcon(shapeFactory));
} catch (IOException ex) {
SwingUtilities.invokeLater(new ErrorMessage(Lang.get("msg_errorImportingModel_N0", node.getName())).addCause(ex));
}
}
if (visualElement.getShape() instanceof MissingShape)
return;
circuitComponent.setPartToInsert(visualElement);
insertHistory.add(this);
}
}
use of de.neemann.digital.draw.elements.VisualElement in project Digital by hneemann.
the class ModifySetBits method modify.
@Override
public void modify(Circuit circuit, ElementLibrary library) {
ArrayList<Movable> list = circuit.getElementsToMove(min, max);
for (Movable m : list) if (m instanceof VisualElement) {
VisualElement ve = (VisualElement) m;
try {
ElementTypeDescription td = library.getElementType(ve.getElementName());
if (td != null) {
if (td.getAttributeList().contains(Keys.BITS))
ve.setAttribute(Keys.BITS, bits);
}
} catch (ElementNotFoundException e) {
e.printStackTrace();
}
}
circuit.modified();
}
Aggregations