package org.simantics.sysdyn.ui.editor.routing;\r
\r
+import java.awt.Shape;\r
import java.awt.geom.Arc2D;\r
import java.awt.geom.Path2D;\r
import java.awt.geom.Point2D;\r
return shape;\r
}\r
\r
- public static Arc2D createArc(Arc2D arc, Rectangle2D tail, Rectangle2D head, double angle) {\r
- double x0 = tail.getCenterX();\r
- double y0 = tail.getCenterY();\r
- double x1 = head.getCenterX();\r
- double y1 = head.getCenterY();\r
+ public static Arc2D createArc(Arc2D arc, Shape beginBounds, Shape endBounds, double angle) {\r
+ double x0 = beginBounds.getBounds2D().getCenterX();\r
+ double y0 = beginBounds.getBounds2D().getCenterY();\r
+ double x1 = endBounds.getBounds2D().getCenterX();\r
+ double y1 = endBounds.getBounds2D().getCenterY();\r
\r
// System.out.println("createArrowShape " + x0 + " " + y0 + " " + x1 + " " + y1);\r
\r
// Rectangle2D bounds = new Rectangle2D.Double();\r
// tail.getBounds(bounds);\r
double angle0 = Arcs.nextIntersectingAngle(cx, cy, r, \r
- Math.atan2(-dy0, dx0), tail, angle < 0.0);\r
+ Math.atan2(-dy0, dx0), beginBounds, angle < 0.0);\r
// head.getBounds(bounds);\r
double angle1 = Arcs.nextIntersectingAngle(cx, cy, r, \r
- Math.atan2(-dy1, dx1), head, angle > 0.0);\r
+ Math.atan2(-dy1, dx1), endBounds, angle > 0.0);\r
double extent = angle1-angle0;\r
//double arcAngle = angle0;\r
if(angle < 0.0) {\r
\r
}\r
\r
- public static Pair<Arc2D, Path2D> createArrowShape(Pair<Arc2D, Path2D> shapes, Rectangle2D tail, Rectangle2D head, double angle) {\r
+ public static Pair<Arc2D, Path2D> createArrowShape(Pair<Arc2D, Path2D> shapes, Shape beginBounds, Shape endBounds, double angle) {\r
if(shapes == null || shapes.first == null || shapes.second == null) {\r
shapes = new Pair<Arc2D, Path2D>(new Arc2D.Double(), new Path2D.Double());\r
}\r
\r
- createArc(shapes.first, tail, head, angle);\r
+ createArc(shapes.first, beginBounds, endBounds, angle);\r
\r
double angle0 = Math.toRadians(shapes.first.getAngleStart());\r
double angle1 = Math.toRadians(shapes.first.getAngleStart() + shapes.first.getAngleExtent());\r
import java.awt.Color;\r
import java.awt.Graphics2D;\r
import java.awt.geom.AffineTransform;\r
+import java.awt.geom.Point2D;\r
import java.awt.geom.Rectangle2D;\r
\r
+import org.simantics.diagram.elements.DiagramNodeUtil;\r
import org.simantics.diagram.elements.TextNode;\r
+import org.simantics.g2d.canvas.ICanvasContext;\r
+import org.simantics.g2d.element.IElement;\r
import org.simantics.scenegraph.ISelectionPainterNode;\r
import org.simantics.scenegraph.g2d.events.EventTypes;\r
import org.simantics.scenegraph.g2d.events.FocusEvent;\r
+import org.simantics.scenegraph.g2d.events.MouseEvent.MouseButtonPressedEvent;\r
+import org.simantics.scenegraph.g2d.events.MouseEvent.MouseClickEvent;\r
+import org.simantics.scenegraph.g2d.events.MouseEvent.MouseDoubleClickedEvent;\r
import org.simantics.scenegraph.utils.NodeUtil;\r
\r
public class HoverTextNode extends TextNode implements ISelectionPainterNode {\r
return false;\r
}\r
\r
+ @Override\r
+ protected boolean mouseClicked(MouseClickEvent event) {\r
+ if (event.button != MouseClickEvent.LEFT_BUTTON)\r
+ return false;\r
+ \r
+ if (hitTest(event, 0)) {\r
+ hoverClick++;\r
+ if (hoverClick < 2)\r
+ return false;\r
+ ICanvasContext ctx = DiagramNodeUtil.getCanvasContext(this);\r
+ // FIXME: needed only because eventdelegator registrations are done before adding node to scene graph.\r
+ if (ctx == null)\r
+ return false;\r
+ IElement e = DiagramNodeUtil.getElement(ctx, this);\r
+ if (!isEditMode()) {\r
+ if (Boolean.TRUE.equals(setEditMode(true))) {\r
+ editActivation = activateEdit(0, e, ctx);\r
+ repaint();\r
+ }\r
+ } \r
+ } else {\r
+ hoverClick = 0;\r
+ if (isEditMode()) {\r
+ fireTextEditingEnded();\r
+ }\r
+ }\r
+ return false;\r
+ }\r
+ \r
+ @Override\r
+ protected boolean mouseDoubleClicked(MouseDoubleClickedEvent event) {\r
+ if (event.button != MouseClickEvent.LEFT_BUTTON)\r
+ return false;\r
+ \r
+ if (hitTest(event, 0)) {\r
+ ICanvasContext ctx = DiagramNodeUtil.getCanvasContext(this);\r
+ // FIXME: needed only because eventdelegator registrations are done before adding node to scene graph.\r
+ if (ctx == null)\r
+ return false;\r
+ \r
+ if (text != null) {\r
+ // Select the whole text.\r
+ setCaret(0, false);\r
+ setCaret(text.length(), true);\r
+ repaint();\r
+ }\r
+ }\r
+ return false;\r
+ }\r
+\r
+ @Override\r
+ protected boolean mouseButtonPressed(MouseButtonPressedEvent event) {\r
+ if (!isShiftDown(event)) {\r
+ return super.mouseButtonPressed(event);\r
+ }\r
+ \r
+ // Select text if shift is down.\r
+ if (!isEditMode())\r
+ return false;\r
+ \r
+ Point2D local = controlToLocal( event.controlPosition );\r
+ // FIXME: once the event coordinate systems are cleared up, remove this workaround\r
+ local = parentToLocal(local);\r
+ if (hover && this.containsLocal(local)) {\r
+ setCaret(local, true);\r
+ }\r
+ return false;\r
+ }\r
}\r
import org.simantics.g2d.element.SceneGraphNodeKey;\r
import org.simantics.g2d.element.handler.HandleMouseEvent;\r
import org.simantics.g2d.element.handler.InternalSize;\r
-import org.simantics.g2d.element.handler.impl.BoundsOutline;\r
import org.simantics.g2d.element.handler.impl.DefaultTransform;\r
import org.simantics.g2d.element.handler.impl.HoverImpl;\r
import org.simantics.g2d.element.handler.impl.ObjectTerminal;\r
StaticSymbolImageInitializer.INSTANCE,\r
HoverImpl.INSTANCE,\r
ValveSceneGraph.INSTANCE,\r
- BoundsOutline.INSTANCE,\r
+ ValveOutline.INSTANCE,\r
Orientation.INSTANCE,\r
ValveTextLocation.INSTANCE,\r
new WholeElementTerminals(terminals)\r
--- /dev/null
+package org.simantics.sysdyn.ui.elements;\r
+\r
+import java.awt.Polygon;\r
+import java.awt.Shape;\r
+\r
+import org.simantics.g2d.element.IElement;\r
+import org.simantics.g2d.element.handler.impl.BoundsOutline;\r
+\r
+public class ValveOutline extends BoundsOutline {\r
+\r
+ public static final BoundsOutline INSTANCE = new ValveOutline();\r
+\r
+ private static final long serialVersionUID = 5544256245734478634L;\r
+\r
+ public ValveOutline() {\r
+ super();\r
+ }\r
+\r
+ @Override\r
+ public Shape getElementShape(IElement e) {\r
+ return super.getElementShape(e);\r
+ /*int[] xs = {-5,5,5,20,20,-20,-20,-5};\r
+ int[] ys = {-5,-5,5,5,15,15,5,5};\r
+ Polygon poly = new Polygon(xs, ys, 8);\r
+ return poly;*/\r
+ }\r
+}\r
*******************************************************************************/\r
package org.simantics.sysdyn.ui.elements.connections;\r
\r
-import java.awt.geom.Rectangle2D;\r
+import java.awt.Shape;\r
\r
public class Arcs {\r
\r
} \r
\r
public static double nextIntersectingAngle(double cx, double cy, double r,\r
- double curAngle, Rectangle2D rect, boolean dir) {\r
+ double curAngle, Shape endBounds, boolean dir) {\r
if(!dir) {\r
double bestAngle = curAngle + PI2;\r
{\r
- double dx = rect.getMinX() - cx;\r
+ double dx = endBounds.getBounds2D().getMinX() - cx;\r
if(Math.abs(dx) < r) {\r
double angle = normalizeAngle(Math.acos(dx / r));\r
bestAngle = updateBestNextAngle(curAngle, bestAngle, angle);\r
}\r
}\r
{\r
- double dx = rect.getMaxX() - cx;\r
+ double dx = endBounds.getBounds2D().getMaxX() - cx;\r
if(Math.abs(dx) < r) {\r
double angle = normalizeAngle(Math.acos(dx / r));\r
bestAngle = updateBestNextAngle(curAngle, bestAngle, angle);\r
}\r
}\r
{\r
- double dy = cy - rect.getMinY();\r
+ double dy = cy - endBounds.getBounds2D().getMinY();\r
if(Math.abs(dy) < r) {\r
double angle = Math.asin(dy / r);\r
bestAngle = updateBestNextAngle(curAngle, bestAngle, angle);\r
}\r
}\r
{\r
- double dy = cy - rect.getMaxY();\r
+ double dy = cy - endBounds.getBounds2D().getMaxY();\r
if(Math.abs(dy) < r) {\r
double angle = Math.asin(dy / r);\r
bestAngle = updateBestNextAngle(curAngle, bestAngle, angle);\r
else {\r
double bestAngle = curAngle - PI2;\r
{\r
- double dx = rect.getMinX() - cx;\r
+ double dx = endBounds.getBounds2D().getMinX() - cx;\r
if(Math.abs(dx) < r) {\r
double angle = normalizeAngle(Math.acos(dx / r));\r
bestAngle = updateBestPrevAngle(curAngle, bestAngle, angle);\r
}\r
}\r
{\r
- double dx = rect.getMaxX() - cx;\r
+ double dx = endBounds.getBounds2D().getMaxX() - cx;\r
if(Math.abs(dx) < r) {\r
double angle = normalizeAngle(Math.acos(dx / r));\r
bestAngle = updateBestPrevAngle(curAngle, bestAngle, angle);\r
}\r
}\r
{\r
- double dy = cy - rect.getMinY();\r
+ double dy = cy - endBounds.getBounds2D().getMinY();\r
if(Math.abs(dy) < r) {\r
double angle = Math.asin(dy / r);\r
bestAngle = updateBestPrevAngle(curAngle, bestAngle, angle);\r
}\r
}\r
{\r
- double dy = cy - rect.getMaxY();\r
+ double dy = cy - endBounds.getBounds2D().getMaxY();\r
if(Math.abs(dy) < r) {\r
double angle = Math.asin(dy / r);\r
bestAngle = updateBestPrevAngle(curAngle, bestAngle, angle);\r
}\r
}\r
\r
- public static boolean hitTest(Rectangle2D beginBounds, Rectangle2D endBounds, double angle, double x, double y, double tolerance) {\r
+ public static boolean hitTest(Shape beginBounds, Shape endBounds, double angle, double x, double y, double tolerance) {\r
\r
boolean clockWise = angle > 0;\r
\r
- double x0 = beginBounds.getCenterX();\r
- double y0 = beginBounds.getCenterY();\r
- double x1 = endBounds.getCenterX();\r
- double y1 = endBounds.getCenterY();\r
+ double x0 = beginBounds.getBounds2D().getCenterX();\r
+ double y0 = beginBounds.getBounds2D().getCenterY();\r
+ double x1 = endBounds.getBounds2D().getCenterX();\r
+ double y1 = endBounds.getBounds2D().getCenterY();\r
\r
double offset = \r
Math.abs(angle) < 1.0e-6\r
* @return The radial distance between the the arc and (x,y); Double.NaN if the\r
* distance is not real.\r
*/\r
- public static double getRadialDistance(Rectangle2D beginBounds,\r
- Rectangle2D endBounds, double angle, double x, double y) {\r
+ public static double getRadialDistance(Shape beginBounds,\r
+ Shape endBounds, double angle, double x, double y) {\r
\r
boolean clockWise = angle > 0;\r
\r
- double x0 = beginBounds.getCenterX();\r
- double y0 = beginBounds.getCenterY();\r
- double x1 = endBounds.getCenterX();\r
- double y1 = endBounds.getCenterY();\r
+ double x0 = beginBounds.getBounds2D().getCenterX();\r
+ double y0 = beginBounds.getBounds2D().getCenterY();\r
+ double x1 = endBounds.getBounds2D().getCenterX();\r
+ double y1 = endBounds.getBounds2D().getCenterY();\r
\r
double offset = \r
Math.abs(angle) < 1.0e-6\r
import java.awt.Color;\r
import java.awt.Font;\r
import java.awt.Graphics2D;\r
+import java.awt.Shape;\r
import java.awt.Stroke;\r
import java.awt.geom.Arc2D;\r
import java.awt.geom.Path2D;\r
\r
private Color color;\r
private Stroke stroke;\r
- private Rectangle2D beginBounds;\r
- private Rectangle2D endBounds;\r
+ private Shape beginBounds;\r
+ private Shape endBounds;\r
private double angle = 0.1;\r
private String side;\r
private transient Pair<Arc2D, Path2D> shapes = new Pair<Arc2D, Path2D>(new Arc2D.Double(), new Path2D.Double());\r
return stroke;\r
}\r
\r
- public Rectangle2D getBeginBounds() {\r
+ public Shape getBeginBounds() {\r
return beginBounds;\r
}\r
\r
- public Rectangle2D getEndBounds() {\r
+ public Shape getEndBounds() {\r
return endBounds;\r
}\r
\r
\r
boolean pressHit = false;\r
\r
- private boolean hitTest(org.simantics.scenegraph.g2d.events.MouseEvent event, double tolerance) {\r
+ protected boolean hitTest(org.simantics.scenegraph.g2d.events.MouseEvent event, double tolerance) {\r
if(beginBounds == null || endBounds == null) return false;\r
Point2D localPos = NodeUtil.worldToLocal(this, event.controlPosition, new Point2D.Double());\r
return Arcs.hitTest(beginBounds, endBounds, angle, localPos.getX(), localPos.getY(), tolerance);\r
Point2D localPos = NodeUtil.worldToLocal(this, event.controlPosition, new Point2D.Double());\r
\r
setAngle(Arcs.angleOfArc(\r
- beginBounds.getCenterX(), beginBounds.getCenterY(),\r
+ beginBounds.getBounds2D().getCenterX(), beginBounds.getBounds2D().getCenterY(),\r
localPos.getX(), localPos.getY(),\r
- endBounds.getCenterX(), endBounds.getCenterY()));\r
+ endBounds.getBounds2D().getCenterX(), endBounds.getBounds2D().getCenterY()));\r
repaint();\r
}\r
\r
solverEditor = new RadioGroupFieldEditor(SolverSettings.SOLVER_TYPE, "Solver type", 1,\r
new String[][] { \r
{ "Internal", SolverSettings.SOLVER_TYPE_INTERNAL },\r
- { "Open Modelica", SolverSettings.SOLVER_TYPE_OPENMODELICA }\r
+ { "OpenModelica", SolverSettings.SOLVER_TYPE_OPENMODELICA }\r
}, getFieldEditorParent());\r
addField(solverEditor);\r
}\r