Search in sources :

Example 1 with Movable

use of de.neemann.digital.draw.elements.Movable 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();
}
Also used : ElementTypeDescription(de.neemann.digital.core.element.ElementTypeDescription) Movable(de.neemann.digital.draw.elements.Movable) VisualElement(de.neemann.digital.draw.elements.VisualElement) ElementNotFoundException(de.neemann.digital.draw.library.ElementNotFoundException)

Example 2 with Movable

use of de.neemann.digital.draw.elements.Movable 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));
        }
    }
}
Also used : TransformRotate(de.neemann.digital.draw.graphics.TransformRotate) Movable(de.neemann.digital.draw.elements.Movable) VisualElement(de.neemann.digital.draw.elements.VisualElement) Transform(de.neemann.digital.draw.graphics.Transform) Wire(de.neemann.digital.draw.elements.Wire) Vector(de.neemann.digital.draw.graphics.Vector) VectorFloat(de.neemann.digital.draw.graphics.VectorFloat)

Aggregations

Movable (de.neemann.digital.draw.elements.Movable)2 VisualElement (de.neemann.digital.draw.elements.VisualElement)2 ElementTypeDescription (de.neemann.digital.core.element.ElementTypeDescription)1 Wire (de.neemann.digital.draw.elements.Wire)1 Transform (de.neemann.digital.draw.graphics.Transform)1 TransformRotate (de.neemann.digital.draw.graphics.TransformRotate)1 Vector (de.neemann.digital.draw.graphics.Vector)1 VectorFloat (de.neemann.digital.draw.graphics.VectorFloat)1 ElementNotFoundException (de.neemann.digital.draw.library.ElementNotFoundException)1