use of de.neemann.digital.draw.elements.Wire in project Digital by hneemann.
the class NetListTest method testTunnel.
public void testTunnel() throws Exception {
Circuit c = new Circuit();
c.add(new Wire(new Vector(1, 1), new Vector(2, 1)));
addTunnel(c, new Vector(2, 1), "A");
c.add(new Wire(new Vector(3, 1), new Vector(4, 1)));
addTunnel(c, new Vector(3, 1), "A");
NetList ns = new NetList(c);
assertEquals(1, ns.size());
}
use of de.neemann.digital.draw.elements.Wire in project Digital by hneemann.
the class ModifyMoveSelected method rotateElements.
/**
* Rotates the given elements
*
* @param elements the elements to rotate
* @param center the center position
*/
public static void rotateElements(ArrayList<Movable> elements, Vector center) {
Transform transform = new TransformRotate(center, 1) {
@Override
public Vector transform(Vector v) {
return super.transform(v.sub(center));
}
@Override
public VectorFloat transform(VectorFloat v) {
return super.transform(v.sub(center));
}
};
for (Movable m : elements) {
if (m instanceof VisualElement) {
VisualElement ve = (VisualElement) m;
ve.rotate();
ve.setPos(transform.transform(ve.getPos()));
} else if (m instanceof Wire) {
Wire w = (Wire) m;
w.p1 = transform.transform(w.p1);
w.p2 = transform.transform(w.p2);
} else {
Vector p = m.getPos();
Vector t = transform.transform(p);
m.move(t.sub(p));
}
}
}
use of de.neemann.digital.draw.elements.Wire in project Digital by hneemann.
the class Net method interconnect.
/**
* Do the interconnection.
* All inputs and outputs in the net are connected together.
* If there is no output an exception is thrown.
* If there is one single output, all input {@link ObservableValue}s are set to this output
* If there are more then one output a {@link DataBus} is created.
* <p>
* At the end all wires get a reference to the {@link ObservableValue} the represent
*
* @param m the model is needed to create the {@link DataBus}
* @param attachWires if true, the values are attached to the wires
* @throws PinException PinException
*/
public void interconnect(Model m, boolean attachWires) throws PinException {
ArrayList<Pin> inputs = new ArrayList<>();
ArrayList<Pin> outputs = new ArrayList<>();
for (Pin p : pins) {
if (p.getDirection() == Pin.Direction.input)
inputs.add(p);
else
outputs.add(p);
}
if (outputs.size() == 0)
throw new PinException(Lang.get("err_noOutConnectedToWire", this.toString()), this);
ObservableValue value = null;
if (outputs.size() == 1 && outputs.get(0).getPullResistor() == PinDescription.PullResistor.none) {
value = outputs.get(0).getValue();
} else {
value = new DataBus(this, m, outputs).getReadableOutput();
}
if (value == null)
throw new PinException(Lang.get("err_output_N_notDefined", outputs.get(0)), this);
for (Pin i : inputs) i.setValue(value);
for (// set also the reader for bidirectional pins
Pin o : // set also the reader for bidirectional pins
outputs) o.setReaderValue(value);
if (wires != null && attachWires)
for (Wire w : wires) w.setValue(value);
}
use of de.neemann.digital.draw.elements.Wire in project Digital by hneemann.
the class NetListTest method testTunnel3.
public void testTunnel3() throws Exception {
Circuit c = new Circuit();
c.add(new Wire(new Vector(1, 1), new Vector(2, 1)));
addTunnel(c, new Vector(2, 1), "A");
c.add(new Wire(new Vector(3, 1), new Vector(4, 1)));
addTunnel(c, new Vector(3, 1), "A");
addTunnel(c, new Vector(4, 1), "C");
c.add(new Wire(new Vector(1, 4), new Vector(2, 4)));
addTunnel(c, new Vector(2, 4), "B");
addTunnel(c, new Vector(1, 4), "C");
c.add(new Wire(new Vector(3, 4), new Vector(4, 4)));
addTunnel(c, new Vector(3, 4), "B");
NetList ns = new NetList(c);
assertEquals(1, ns.size());
}
use of de.neemann.digital.draw.elements.Wire in project Digital by hneemann.
the class NetListTest method testSimple.
public void testSimple() throws Exception {
Circuit c = new Circuit();
c.add(new Wire(new Vector(1, 1), new Vector(1, 2)));
c.add(new Wire(new Vector(2, 1), new Vector(2, 2)));
c.add(new Wire(new Vector(1, 2), new Vector(2, 2)));
c.add(new Wire(new Vector(1, 1), new Vector(2, 1)));
NetList ns = new NetList(c);
assertEquals(1, ns.size());
}
Aggregations