]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Mouse click (for rename) on Sysdyn diagram more intuitive (refs #4484).
authormiettinen <miettinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 29 Oct 2013 08:14:21 +0000 (08:14 +0000)
committermiettinen <miettinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 29 Oct 2013 08:14:21 +0000 (08:14 +0000)
Allow Valve terminals to be generic Shapes, we need something other (i.e. Polygon) shape to define a Valve than Rectangle (refs #4482).

git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@28142 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/routing/DependencyRouter.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/HoverTextNode.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/ValveFactory.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/ValveOutline.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/connections/Arcs.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/connections/DependencyNode.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/preferences/SolverPreferencePage.java

index 1b2bf60d2b78a383626edfe08da8af8200a4844e..dc2e29fecad78591e15b9c2e46cb0ce1b7f85f76 100644 (file)
@@ -1,5 +1,6 @@
 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
@@ -59,11 +60,11 @@ public class DependencyRouter implements IRouter2 {
         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
@@ -84,10 +85,10 @@ public class DependencyRouter implements IRouter2 {
 //        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
@@ -131,12 +132,12 @@ public class DependencyRouter implements IRouter2 {
                \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
index 27bf28085542f2d48fe92405af984ae151504b0d..be323011a6d9743a2d8c0c951d961f95011cdd8c 100644 (file)
@@ -15,12 +15,19 @@ import java.awt.BasicStroke;
 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
@@ -83,4 +90,72 @@ public class HoverTextNode extends TextNode implements ISelectionPainterNode {
         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
index b3c2d6fcbcc83f0f79f25c5479799521b889c816..25890ac08d3cf23518bd761dd94c7ef84f543f66 100644 (file)
@@ -31,7 +31,6 @@ import org.simantics.g2d.element.IElement;
 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
@@ -81,7 +80,7 @@ public class ValveFactory extends SysdynElementFactory {
                 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
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/ValveOutline.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/ValveOutline.java
new file mode 100644 (file)
index 0000000..8e35e69
--- /dev/null
@@ -0,0 +1,27 @@
+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
index f9768fed2e00faac41e31a64e19d3992ae3a052d..602796de95460fd14b416c679fdf2fcf42207fa1 100644 (file)
@@ -11,7 +11,7 @@
  *******************************************************************************/\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
@@ -84,11 +84,11 @@ public class Arcs {
     }   \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
@@ -96,7 +96,7 @@ public class Arcs {
                 }\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
@@ -104,7 +104,7 @@ public class Arcs {
                 }\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
@@ -113,7 +113,7 @@ public class Arcs {
                 }\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
@@ -126,7 +126,7 @@ public class Arcs {
         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
@@ -134,7 +134,7 @@ public class Arcs {
                 }\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
@@ -142,7 +142,7 @@ public class Arcs {
                 }\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
@@ -151,7 +151,7 @@ public class Arcs {
                 }\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
@@ -163,14 +163,14 @@ public class Arcs {
         }\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
@@ -219,15 +219,15 @@ public class Arcs {
         * @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
index 0eacd1b7050e3e3bd9fde3c20f603d41f420294e..c1609423a95dcc607e074abcab28d889c2b44bb5 100644 (file)
@@ -15,6 +15,7 @@ import java.awt.BasicStroke;
 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
@@ -57,8 +58,8 @@ public class DependencyNode extends TextNode implements ISelectionPainterNode {
 \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
@@ -155,11 +156,11 @@ public class DependencyNode extends TextNode implements ISelectionPainterNode {
         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
@@ -236,7 +237,7 @@ public class DependencyNode extends TextNode implements ISelectionPainterNode {
 \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
@@ -268,9 +269,9 @@ public class DependencyNode extends TextNode implements ISelectionPainterNode {
             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
index f02898296690a23a96816228b6df9ec9c5a09477..3cd3f0597eebfeee6eed3ab5e7b00717bb510e2d 100644 (file)
@@ -29,7 +29,7 @@ public class SolverPreferencePage extends FieldEditorPreferencePage implements
                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