false
to rotate 90 degrees counter-clockwise
*/
public static void rotate(final Resource resources[], final boolean clockwise) {
- SimanticsUI.getSession().asyncRequest(new WriteRequest() {
+ Simantics.getSession().asyncRequest(new WriteRequest() {
@Override
public void perform(WriteGraph graph) throws DatabaseException {
graph.markUndoPoint();
@@ -496,7 +511,7 @@ public final class ElementTransforms {
* for y-axis
*/
public static void flip(final Resource resources[], final boolean xAxis) {
- SimanticsUI.getSession().asyncRequest(new WriteRequest() {
+ Simantics.getSession().asyncRequest(new WriteRequest() {
@Override
public void perform(WriteGraph graph) throws DatabaseException {
graph.markUndoPoint();
@@ -621,6 +636,7 @@ public final class ElementTransforms {
return GeometryUtils.transformShape(bounds, at).getBounds2D();
}
+ @SuppressWarnings("unused")
public double getDeterminant() {
return transform[0] * transform[3] - transform[1] * transform[2];
}
@@ -712,4 +728,177 @@ public final class ElementTransforms {
}
}
+ // ------------------------------------------------------------------------
+
+ private interface TerminalFunction {
+ /**
+ * @param terminal
+ * @param rotationTheta in radians
+ * @return
+ */
+ AffineTransform transform(Resource connectionPoint, double rotationTheta);
+ default Point2D position(Resource connectionPoint, double rotationTheta) {
+ AffineTransform tr = transform(connectionPoint, rotationTheta);
+ return new Point2D.Double(tr.getTranslateX(), tr.getTranslateY());
+ }
+ Resource toConnectionPoint(Resource terminal);
+ Resource toTerminal(Resource connectionPoint);
+ Set
+ * Note that this requires that the element is connected to exactly two other
+ * elements.
+ *
+ * @param graph
+ * @param element
+ * @return the chosen rotation in degrees
+ * @throws DatabaseException
+ */
+ public static double rotateToNeighborSlope(WriteGraph graph, Resource element) throws DatabaseException {
+
+ if (LOGGER.isDebugEnabled())
+ LOGGER.debug("rotateAccordingToNeighborPositions( {} )", graph.getPossibleURI(element));
+
+ TerminalFunction elementTerminals = terminalPositionFunction(graph, true, element);
+ Set