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