Search in sources :

Example 31 with Vector

use of de.neemann.digital.draw.graphics.Vector in project Digital by hneemann.

the class TestSelect method testSelect.

public void testSelect() throws Exception {
    Circuit c = new ToBreakRunner("dig/selectOuter.dig").getCircuit();
    // don't select by clicking in label size bounding box
    VisualElement el = c.getElementAt(new Vector(65, 15));
    assertNull(el);
    // select by clicking in shape size bounding box
    el = c.getElementAt(new Vector(55, 15));
    assertNotNull(el);
    assertEquals("selectInnerLongName.dig", el.getElementName());
    // select output by clicking in shape size bounding box
    el = c.getElementAt(new Vector(195, 20));
    assertNotNull(el);
    assertEquals(Out.DESCRIPTION.getName(), el.getElementName());
    // don't select output by clicking in label text
    el = c.getElementAt(new Vector(250, 20));
    assertNull(el);
    // select text by clicking in text size bounding box
    el = c.getElementAt(new Vector(20, 110));
    assertNotNull(el);
    assertEquals(DummyElement.TEXTDESCRIPTION.getName(), el.getElementName());
}
Also used : Circuit(de.neemann.digital.draw.elements.Circuit) VisualElement(de.neemann.digital.draw.elements.VisualElement) Vector(de.neemann.digital.draw.graphics.Vector)

Example 32 with Vector

use of de.neemann.digital.draw.graphics.Vector in project Digital by hneemann.

the class CircuitComponent method drawGrid.

private void drawGrid(Graphics2D gr2) {
    Vector g1 = raster(getPosVector(0, 0));
    Point2D p1 = new Point2D.Double();
    transform.transform(new Point(g1.x, g1.y), p1);
    Vector g2 = raster(getPosVector(getWidth(), getHeight()));
    Point2D p2 = new Point2D.Double();
    transform.transform(new Point(g2.x, g2.y), p2);
    int cx = (g2.x - g1.x) / SIZE;
    int cy = (g2.y - g1.y) / SIZE;
    if (cx == 0 || cy == 0)
        return;
    float screenScaling = Screen.getInstance().getScaling();
    double delta = transform.getScaleX() * 2 * screenScaling;
    double min = 2 * screenScaling;
    if (delta < min)
        delta = min;
    double max = 8 * screenScaling;
    if (delta > max)
        delta = max;
    double sub = delta / 2.0;
    gr2.setColor(GRID_COLOR);
    for (int x = 0; x <= cx; x++) {
        double xx = p1.getX() + (p2.getX() - p1.getX()) * x / cx - sub;
        for (int y = 0; y <= cy; y++) {
            double yy = p1.getY() + (p2.getY() - p1.getY()) * y / cy - sub;
            gr2.fill(new Rectangle2D.Double(xx, yy, delta, delta));
        }
    }
}
Also used : Point2D(java.awt.geom.Point2D) Rectangle2D(java.awt.geom.Rectangle2D) Vector(de.neemann.digital.draw.graphics.Vector)

Example 33 with Vector

use of de.neemann.digital.draw.graphics.Vector in project Digital by hneemann.

the class CircuitComponent method createPasteAction.

private ToolTipAction createPasteAction(ShapeFactory shapeFactory) {
    return new ToolTipAction(Lang.get("menu_paste")) {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (!isLocked()) {
                Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
                try {
                    Object data = clipboard.getData(DataFlavor.stringFlavor);
                    if (data instanceof String) {
                        Vector posVector = getPosVector(lastMousePos.x, lastMousePos.y);
                        ArrayList<Movable> elements = CircuitTransferable.createList(data, shapeFactory, posVector);
                        if (elements != null)
                            setPartsToInsert(elements, posVector);
                    }
                } catch (Exception e1) {
                    e1.printStackTrace();
                    SwingUtilities.invokeLater(new ErrorMessage(Lang.get("msg_clipboardContainsNoImportableData")).setComponent(CircuitComponent.this));
                }
            }
        }
    }.setAcceleratorCTRLplus('V').enableAcceleratorIn(this);
}
Also used : Clipboard(java.awt.datatransfer.Clipboard) Vector(de.neemann.digital.draw.graphics.Vector) NoninvertibleTransformException(java.awt.geom.NoninvertibleTransformException) ElementNotFoundException(de.neemann.digital.draw.library.ElementNotFoundException) IOException(java.io.IOException) NodeException(de.neemann.digital.core.NodeException)

Example 34 with Vector

use of de.neemann.digital.draw.graphics.Vector in project Digital by hneemann.

the class CircuitComponent method fitCircuit.

/**
 * maximizes the circuit shown
 */
public void fitCircuit() {
    GraphicMinMax gr = new GraphicMinMax();
    circuit.drawTo(gr);
    AffineTransform newTrans = new AffineTransform();
    if (gr.getMin() != null && getWidth() != 0 && getHeight() != 0) {
        Vector delta = gr.getMax().sub(gr.getMin());
        double sx = ((double) getWidth()) / (delta.x + Style.NORMAL.getThickness() * 2);
        double sy = ((double) getHeight()) / (delta.y + Style.NORMAL.getThickness() * 2);
        double s = Math.min(sx, sy);
        // set Scaling
        newTrans.setToScale(s, s);
        Vector center = gr.getMin().add(gr.getMax()).div(2);
        // move drawing center to (0,0)
        newTrans.translate(-center.x, -center.y);
        Vector dif = new Vector(getWidth(), getHeight()).div(2);
        // move drawing center to frame center
        newTrans.translate(dif.x / s, dif.y / s);
        isManualScale = false;
    } else {
        isManualScale = true;
    }
    if (!newTrans.equals(transform)) {
        transform = newTrans;
        repaintNeeded();
    }
}
Also used : AffineTransform(java.awt.geom.AffineTransform) Vector(de.neemann.digital.draw.graphics.Vector)

Example 35 with Vector

use of de.neemann.digital.draw.graphics.Vector in project Digital by hneemann.

the class CircuitComponent method scaleCircuit.

/**
 * scales the circuit
 *
 * @param f factor to scale
 */
public void scaleCircuit(double f) {
    Vector dif = getPosVector(getWidth() / 2, getHeight() / 2);
    transform.translate(dif.x, dif.y);
    transform.scale(f, f);
    transform.translate(-dif.x, -dif.y);
    isManualScale = true;
    repaintNeeded();
}
Also used : Vector(de.neemann.digital.draw.graphics.Vector)

Aggregations

Vector (de.neemann.digital.draw.graphics.Vector)63 Wire (de.neemann.digital.draw.elements.Wire)13 Polygon (de.neemann.digital.draw.graphics.Polygon)12 VisualElement (de.neemann.digital.draw.elements.VisualElement)9 Style (de.neemann.digital.draw.graphics.Style)8 Circuit (de.neemann.digital.draw.elements.Circuit)6 Pin (de.neemann.digital.draw.elements.Pin)3 Pins (de.neemann.digital.draw.elements.Pins)3 ArrayList (java.util.ArrayList)3 Rotation (de.neemann.digital.core.element.Rotation)2 ElementLibrary (de.neemann.digital.draw.library.ElementLibrary)2 ElementNotFoundException (de.neemann.digital.draw.library.ElementNotFoundException)2 ShapeFactory (de.neemann.digital.draw.shapes.ShapeFactory)2 IOException (java.io.IOException)2 NodeException (de.neemann.digital.core.NodeException)1 ObservableValue (de.neemann.digital.core.ObservableValue)1 Movable (de.neemann.digital.draw.elements.Movable)1 GraphicMinMax (de.neemann.digital.draw.graphics.GraphicMinMax)1 Orientation (de.neemann.digital.draw.graphics.Orientation)1 Transform (de.neemann.digital.draw.graphics.Transform)1