use of com.ait.lienzo.client.core.types.Point2DArray in project lienzo-core by ahome-it.
the class WiresConnectorControlImpl method destroyControlPoint.
@Override
public void destroyControlPoint(final IPrimitive<?> control) {
if (m_connector.getPointHandles().size() <= 2) {
m_wiresManager.deregister(m_connector);
return;
}
IControlHandle selected = null;
for (final IControlHandle handle : m_connector.getPointHandles()) {
if (handle.getControl() == control) {
selected = handle;
break;
}
}
if (null == selected) {
return;
}
final Point2DArray oldPoints = m_connector.getLine().getPoint2DArray();
final Point2DArray newPoints = new Point2DArray();
final Point2D selectedPoint2D = selected.getControl().getLocation();
for (int i = 0; i < oldPoints.size(); i++) {
final Point2D current = oldPoints.get(i);
if (!current.equals(selectedPoint2D)) {
newPoints.push(current);
}
}
m_connector.getLine().setPoint2DArray(newPoints);
destroyPointHandles();
showPointHandles();
}
use of com.ait.lienzo.client.core.types.Point2DArray in project lienzo-core by ahome-it.
the class WiresConnectorControlImpl method addControlPoint.
@Override
public void addControlPoint(final double x, final double y) {
hideControlPoints();
final Point2DArray oldPoints = m_connector.getLine().getPoint2DArray();
final int pointIndex = getIndexForSelectedSegment(m_connector, (int) x, (int) y, oldPoints);
if (pointIndex > 0) {
final Point2D point = new Point2D(x, y);
final Point2DArray newPoints = new Point2DArray();
newPoints.push(oldPoints.get(0));
for (int i = 1; i < pointIndex; i++) {
newPoints.push(oldPoints.get(i));
}
newPoints.push(point);
for (int i = pointIndex; i < oldPoints.size(); i++) {
newPoints.push(oldPoints.get(i));
}
m_connector.getLine().setPoint2DArray(newPoints);
}
showPointHandles();
m_connector.getLine().getLayer().batch();
}
use of com.ait.lienzo.client.core.types.Point2DArray in project lienzo-core by ahome-it.
the class WiresConnectorControlImpl method reset.
/*
***************** CONTROL POINTS **********************************
*/
@Override
public void reset() {
if (null != m_startPoints) {
final IControlHandleList handles = m_connector.getPointHandles();
final Point2DArray points = m_connector.getLine().getPoint2DArray();
for (int i = 0, j = 0; i < handles.size(); i++, j += 2) {
final double px = m_startPoints.get(j);
final double py = m_startPoints.get(j + 1);
final IControlHandle h = handles.getHandle(i);
final IPrimitive<?> prim = h.getControl();
prim.setX(px);
prim.setY(py);
final Point2D point = points.get(i);
point.setX(px);
point.setY(py);
}
}
m_connector.getLine().refresh();
m_wiresManager.getLayer().getLayer().batch();
}
use of com.ait.lienzo.client.core.types.Point2DArray in project lienzo-core by ahome-it.
the class WiresConnectorControlImpl method move.
/**
* See class javadocs to explain why we have these booleans
*/
@Override
public void move(final double dx, final double dy, final boolean midPointsOnly, final boolean moveLinePoints) {
final IControlHandleList handles = m_connector.getPointHandles();
int start = 0;
int end = handles.size();
if (midPointsOnly) {
if (m_connector.getHeadConnection().getMagnet() != null) {
start++;
}
if (m_connector.getTailConnection().getMagnet() != null) {
end--;
}
}
final Point2DArray points = m_connector.getLine().getPoint2DArray();
for (int i = start, j = (start == 0) ? start : 2; i < end; i++, j += 2) {
if (moveLinePoints) {
final Point2D p = points.get(i);
p.setX(m_startPoints.get(j) + dx);
p.setY(m_startPoints.get(j + 1) + dy);
}
final IControlHandle h = handles.getHandle(i);
final IPrimitive<?> prim = h.getControl();
prim.setX(m_startPoints.get(j) + dx);
prim.setY(m_startPoints.get(j + 1) + dy);
}
if (moveLinePoints) {
m_connector.getLine().refresh();
}
m_wiresManager.getLayer().getLayer().batch();
}
use of com.ait.lienzo.client.core.types.Point2DArray in project lienzo-core by ahome-it.
the class MagnetManager method createMagnets.
/**
* Right now it only works with provided FOUR or EIGHT cardinals, anything else will break WiresConnector autoconnection
*
* @param wiresShape
* @param requestedCardinals
* @return
*/
public Magnets createMagnets(final WiresShape wiresShape, final Direction[] requestedCardinals) {
final IPrimitive<?> primTarget = wiresShape.getGroup();
final Point2DArray points = getWiresIntersectionPoints(wiresShape, requestedCardinals);
final ControlHandleList list = new ControlHandleList(primTarget);
final BoundingBox box = wiresShape.getPath().getBoundingBox();
final Point2D primLoc = primTarget.getComputedLocation();
final Magnets magnets = new Magnets(this, list, wiresShape);
int i = 0;
for (final Point2D p : points) {
final double mx = primLoc.getX() + p.getX();
final double my = primLoc.getY() + p.getY();
final WiresMagnet m = new WiresMagnet(magnets, null, i++, p.getX(), p.getY(), getControlPrimitive(mx, my), true);
final Direction d = getDirection(p, box);
m.setDirection(d);
list.add(m);
}
final String uuid = primTarget.uuid();
m_magnetRegistry.put(uuid, magnets);
wiresShape.setMagnets(magnets);
return magnets;
}
Aggregations