]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
New decoration for modules & Enumeration copy+paste (not working properly, core consu...
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Wed, 11 May 2011 12:00:33 +0000 (12:00 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Wed, 11 May 2011 12:00:33 +0000 (12:00 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@20863 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/plugin.xml
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/HoverTextElementNoBounds.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/HoverTextNode.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/ModuleFactory.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/ModuleNode.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/EnumerationPasteHandler.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/EnumerationTab.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/ExpressionUtils.java

index 49de4a6929dd255ffca1539e984d2bb07b0e2bd9..563a7dd34d3791b8b2b249e615ea1b52ee42be81 100644 (file)
             </with>\r
          </activeWhen>\r
       </handler>\r
+      <handler\r
+            class="org.simantics.modeling.ui.modelBrowser.handlers.StandardCopyHandler"\r
+            commandId="org.eclipse.ui.edit.copy">\r
+         <enabledWhen>\r
+            <not>\r
+               <count\r
+                     value="0">\r
+               </count>\r
+            </not>\r
+         </enabledWhen>\r
+         <activeWhen>\r
+            <with\r
+                  variable="selection">\r
+               <test\r
+                     args="org.simantics.sysdyn.ui.browser.nodes.EnumerationNode"\r
+                     property="org.simantics.sysdyn.ui.nodeClass">\r
+               </test>\r
+            </with>\r
+         </activeWhen>\r
+      </handler>\r
+      <handler\r
+            class="org.simantics.modeling.ui.modelBrowser.handlers.StandardPasteHandler"\r
+            commandId="org.eclipse.ui.edit.paste">\r
+         <enabledWhen>\r
+            <not>\r
+               <count\r
+                     value="0">\r
+               </count>\r
+            </not>\r
+         </enabledWhen>\r
+         <activeWhen>\r
+            <with\r
+                  variable="selection">\r
+               <and>\r
+                  <test\r
+                        args="org.simantics.sysdyn.ui.browser.nodes.ConfigurationNode"\r
+                        property="org.simantics.sysdyn.ui.nodeClass">\r
+                  </test>\r
+                  <not>\r
+                     <test\r
+                           args="org.simantics.sysdyn.ui.browser.nodes.ModuleNode"\r
+                           property="org.simantics.sysdyn.ui.nodeClass">\r
+                     </test>\r
+                  </not>\r
+               </and>\r
+            </with>\r
+         </activeWhen>\r
+      </handler>\r
    </extension>\r
    <extension\r
          point="org.simantics.browsing.ui.common.viewpointContributionBinding">\r
index 2b583a4a7bcf4d584756871ff0fce1202d67e2c3..1495974b9de261108381f7a543369c0b3fa747f3 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************\r
- * Copyright (c) 2010 Association for Decentralized Information Management in\r
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
  * Industry THTH ry.\r
  * All rights reserved. This program and the accompanying materials\r
  * are made available under the terms of the Eclipse Public License v1.0\r
@@ -33,9 +33,9 @@ import org.simantics.scenegraph.g2d.G2DParentNode;
 import org.simantics.sysdyn.ui.utils.VariableNameUtils;\r
 import org.simantics.ui.SimanticsUI;\r
 import org.simantics.utils.datastructures.Callback;\r
+import org.simantics.utils.datastructures.hints.IHintContext.Key;\r
 import org.simantics.utils.datastructures.hints.IHintListener;\r
 import org.simantics.utils.datastructures.hints.IHintObservable;\r
-import org.simantics.utils.datastructures.hints.IHintContext.Key;\r
 \r
 /**\r
  * ElementHandler for text elements\r
@@ -67,11 +67,14 @@ public class HoverTextElementNoBounds extends TextElementNoBounds {
                super(originX, originY, horizontalAlignment, borderWidth, paddingX, paddingY, editable);\r
        }\r
 \r
-       @Override\r
-       public void init(final IElement e, G2DParentNode parent) {\r
-               HoverTextNode node = ElementUtils.getOrCreateNode(e, parent, SG_NODE, "text", HoverTextNode.class, new Callback<HoverTextNode>() {\r
+       protected HoverTextNode getTextNode(IElement e, G2DParentNode parent) {\r
+               return ElementUtils.getOrCreateNode(e, parent, SG_NODE, "text", HoverTextNode.class, getCallback(e, parent, HoverTextNode.class));\r
+       }\r
+               \r
+       protected <T extends HoverTextNode> Callback<T> getCallback(final IElement e, G2DParentNode parent, Class<T> nodeClass) {\r
+               return new Callback<T>() {\r
                        @Override\r
-                       public void run(HoverTextNode node) {\r
+                       public void run(T node) {\r
                                node.setTextListener(new ITextListener() {\r
 \r
                                        String textBeforeEdit;\r
@@ -149,7 +152,12 @@ public class HoverTextElementNoBounds extends TextElementNoBounds {
                                        }\r
                                });\r
                        }\r
-               });\r
+               };\r
+       }\r
+\r
+       @Override\r
+       public void init(final IElement e, G2DParentNode parent) {\r
+               HoverTextNode node = getTextNode(e, parent);\r
 \r
                //Font font = new Font("Tahoma", 0, 12);\r
                Font font = ElementUtils.getTextFont(e);\r
index f3d3e0d775e0128a0ffed86b1a77b5f7b7bf3ee7..7b4f246383077a1044016b973c314dfc4bb0acee 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************\r
- * Copyright (c) 2010 Association for Decentralized Information Management in\r
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
  * Industry THTH ry.\r
  * All rights reserved. This program and the accompanying materials\r
  * are made available under the terms of the Eclipse Public License v1.0\r
@@ -18,7 +18,6 @@ import java.awt.geom.AffineTransform;
 import java.awt.geom.Rectangle2D;\r
 \r
 import org.simantics.diagram.elements.TextNode;\r
-import org.simantics.g2d.utils.Alignment;\r
 import org.simantics.scenegraph.ISelectionPainterNode;\r
 import org.simantics.scenegraph.utils.NodeUtil;\r
 \r
@@ -26,7 +25,7 @@ public class HoverTextNode extends TextNode implements ISelectionPainterNode {
 \r
     private static final long serialVersionUID = 3539499125943249895L;\r
 
-    private static transient ThreadLocal<Rectangle2D> tempBounds = new ThreadLocal<Rectangle2D>() {\r
+    protected static transient ThreadLocal<Rectangle2D> tempBounds = new ThreadLocal<Rectangle2D>() {\r
         @Override\r
         protected Rectangle2D initialValue() {\r
             return new Rectangle2D.Double();\r
index e7321734aa58abcd044509dcbc989f79cbade0ef..678f63e82fda17588a9790a1ccac9b41c2932c4e 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************\r
- * Copyright (c) 2010 Association for Decentralized Information Management in\r
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
  * Industry THTH ry.\r
  * All rights reserved. This program and the accompanying materials\r
  * are made available under the terms of the Eclipse Public License v1.0\r
@@ -18,6 +18,9 @@ import java.util.Collection;
 \r
 import org.simantics.db.Resource;\r
 import org.simantics.g2d.element.ElementClass;\r
+import org.simantics.g2d.element.ElementUtils;\r
+import org.simantics.g2d.element.IElement;\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.ObjectTerminal;\r
@@ -32,10 +35,11 @@ import org.simantics.g2d.element.handler.impl.TextImpl;
 import org.simantics.g2d.image.Image;\r
 import org.simantics.g2d.image.impl.ShapeImage;\r
 import org.simantics.g2d.utils.Alignment;\r
+import org.simantics.scenegraph.g2d.G2DParentNode;\r
 \r
 public class ModuleFactory extends SysdynElementFactory {\r
 \r
-    private static final BasicStroke    STROKE           = new BasicStroke(1f);\r
+    private static final BasicStroke    STROKE           = new BasicStroke(2.0f);\r
     private static final Image DEFAULT_IMAGE = new ShapeImage(new Rectangle2D.Double(-5, -2.5, 10, 5), null, STROKE, true);\r
 \r
     @Override\r
@@ -50,10 +54,25 @@ public class ModuleFactory extends SysdynElementFactory {
                 new StaticObjectAdapter(elementType),\r
                 new StaticSymbolImpl(DEFAULT_IMAGE),\r
                 StaticSymbolImageInitializer.INSTANCE,\r
-                new HoverTextElementHandler(0, 0, Alignment.LEADING, 1f , 7, 7, true),\r
+                new ModuleSceneGraph(0, 0, Alignment.LEADING, 1f , 4, 4, true),\r
                 BoundsOutline.INSTANCE,\r
                 new WholeElementTerminals(terminals)\r
         ).setId(ModuleFactory.class.getSimpleName());\r
     }\r
+    \r
+    \r
+    public static class ModuleSceneGraph extends HoverTextElementHandler implements InternalSize {\r
 \r
+               private static final long       serialVersionUID = 2367230056477661273L;\r
+        \r
+               public ModuleSceneGraph(double originX, double originY, Alignment horizontalAlignment, double borderWidth,\r
+                   double paddingX, double paddingY, boolean editable) {\r
+               super(originX, originY, horizontalAlignment, borderWidth, paddingX, paddingY, editable);\r
+        }\r
+               \r
+               protected HoverTextNode getTextNode(IElement e, G2DParentNode parent) {\r
+                       return ElementUtils.getOrCreateNode(e, parent, SG_NODE, "text", ModuleNode.class, getCallback(e, parent, ModuleNode.class));\r
+               }\r
+\r
+    }\r
 }\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/ModuleNode.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/ModuleNode.java
new file mode 100644 (file)
index 0000000..6695543
--- /dev/null
@@ -0,0 +1,100 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.ui.elements2;\r
+\r
+import java.awt.AlphaComposite;\r
+import java.awt.BasicStroke;\r
+import java.awt.Color;\r
+import java.awt.Composite;\r
+import java.awt.Graphics2D;\r
+import java.awt.geom.AffineTransform;\r
+import java.awt.geom.Path2D;\r
+import java.awt.geom.Rectangle2D;\r
+\r
+import org.simantics.scenegraph.utils.GeometryUtils;\r
+import org.simantics.scenegraph.utils.NodeUtil;\r
+\r
+public class ModuleNode extends HoverTextNode {\r
+\r
+       private static final long serialVersionUID = 8535695797227320496L;\r
+    private static double              CORNER_LENGTH    = 2.0; \r
+    private static double              CORNER_PADDING   = 0.8; \r
+    \r
+    \r
+    @Override\r
+    public void render(Graphics2D g) {\r
+       super.render(g);\r
+       \r
+        AffineTransform ot = g.getTransform();\r
+        BasicStroke oldStroke = (BasicStroke)g.getStroke();\r
+        Color oldColor = g.getColor();\r
+\r
+        \r
+        g.transform(transform);\r
+       \r
+        Rectangle2D bounds = expandBounds( alignBounds( getTightUnalignedBoundsInLocal( tempBounds.get() ) ) );\r
+\r
+        Path2D path = new Path2D.Double();\r
+        // LEFT TOP\r
+        path.moveTo(bounds.getMinX() + CORNER_LENGTH, bounds.getMinY() - CORNER_PADDING);\r
+        path.lineTo(bounds.getMinX() - CORNER_PADDING, bounds.getMinY() - CORNER_PADDING);\r
+        path.lineTo(bounds.getMinX() - CORNER_PADDING, bounds.getMinY() + CORNER_LENGTH);\r
+        \r
+        // LEFT BOTTOM\r
+        path.moveTo(bounds.getMinX() + CORNER_LENGTH, bounds.getMaxY() + CORNER_PADDING);\r
+        path.lineTo(bounds.getMinX() - CORNER_PADDING, bounds.getMaxY() + CORNER_PADDING);\r
+        path.lineTo(bounds.getMinX() - CORNER_PADDING, bounds.getMaxY() - CORNER_LENGTH);\r
+        \r
+        // RIGHT TOP\r
+        path.moveTo(bounds.getMaxX() - CORNER_LENGTH, bounds.getMinY() - CORNER_PADDING);\r
+        path.lineTo(bounds.getMaxX() + CORNER_PADDING, bounds.getMinY() - CORNER_PADDING);\r
+        path.lineTo(bounds.getMaxX() + CORNER_PADDING, bounds.getMinY() + CORNER_LENGTH);\r
+        \r
+        // RIGHT BOTTOM\r
+        path.moveTo(bounds.getMaxX() - CORNER_LENGTH, bounds.getMaxY() + CORNER_PADDING);\r
+        path.lineTo(bounds.getMaxX() + CORNER_PADDING, bounds.getMaxY() + CORNER_PADDING);\r
+        path.lineTo(bounds.getMaxX() + CORNER_PADDING, bounds.getMaxY() - CORNER_LENGTH);\r
+        \r
+        g.translate(x, y);\r
+        g.setStroke(new BasicStroke((float) (scale*borderWidth)));       \r
+        g.setColor(Color.GRAY);\r
+        g.draw(path);   \r
+        \r
+        \r
+        boolean selected = NodeUtil.isSelected(this, 1);\r
+        if (selected && showSelection()) {\r
+            Composite oc = g.getComposite();\r
+            g.setComposite(AlphaComposite.SrcAtop.derive(0.5f));\r
+\r
+            g.setColor(Color.RED);\r
+            float bw = borderWidth;\r
+            double s = GeometryUtils.getScale(g.getTransform());\r
+            if (bw <= 0f) {\r
+                bw = (float) (1f / s);\r
+            } else {\r
+                bw *= 3f * scale;\r
+            }\r
+            g.setStroke(new BasicStroke(bw));\r
+            g.draw(path);\r
+            //g.draw(GeometryUtils.expandRectangle(r, 1.0));\r
+\r
+            g.setComposite(oc);\r
+        }\r
+        \r
+        g.setColor(oldColor);\r
+        g.setStroke(oldStroke);\r
+        g.translate(-x, -y);\r
+        \r
+        g.setTransform(ot);\r
+    }\r
+\r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/EnumerationPasteHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/EnumerationPasteHandler.java
new file mode 100644 (file)
index 0000000..a37cb37
--- /dev/null
@@ -0,0 +1,29 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.ui.handlers;\r
+\r
+import org.eclipse.core.commands.AbstractHandler;\r
+import org.eclipse.core.commands.ExecutionEvent;\r
+import org.eclipse.core.commands.ExecutionException;\r
+import org.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.ui.handlers.HandlerUtil;\r
+\r
+public class EnumerationPasteHandler extends AbstractHandler {\r
+\r
+       @Override\r
+       public Object execute(ExecutionEvent event) throws ExecutionException {\r
+        ISelection sel = HandlerUtil.getCurrentSelection(event);\r
+               System.out.println("PASTE " + sel);\r
+               return null;\r
+       }\r
+\r
+}\r
index 3d88d8496f0b34d3b498528e3a0cda90a3a41c40..589f0c361a3119a0a77e8a18eecc0e3cbbe65049 100644 (file)
@@ -1,5 +1,17 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
 package org.simantics.sysdyn.ui.properties;\r
 \r
+import java.util.HashSet;\r
 import java.util.List;\r
 \r
 import org.eclipse.jface.layout.GridDataFactory;\r
@@ -31,6 +43,7 @@ import org.simantics.db.Resource;
 import org.simantics.db.WriteGraph;\r
 import org.simantics.db.common.request.ReadRequest;\r
 import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.common.utils.NameUtils;\r
 import org.simantics.db.common.utils.OrderedSetUtils;\r
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.db.layer0.variable.Variable;\r
@@ -164,11 +177,15 @@ public class EnumerationTab extends LabelPropertyTabContributor implements Widge
                                        public void perform(WriteGraph graph) throws DatabaseException {\r
                                                SysdynResource sr = SysdynResource.getInstance(graph);\r
                                                Layer0 l0 = Layer0.getInstance(graph);\r
-\r
-\r
+                                               \r
+                                               HashSet<String> names = new HashSet<String>();\r
+                                               for(Resource r : OrderedSetUtils.toList(graph, enumerationIndexes)) {\r
+                                                       names.add(NameUtils.getSafeName(graph, r));\r
+                                               }\r
+                                               \r
                                                Resource ei = GraphUtils.create2(graph, \r
                                                                sr.EnumerationIndex,\r
-                                                               l0.HasName, "index");\r
+                                                               l0.HasName, NameUtils.findFreshName(graph, "index", names, ""));\r
                                                OrderedSetUtils.add(graph, enumerationIndexes, ei);\r
                                        }\r
                                });\r
index 5297a2f5a5479dc28a9f6c2cddd52034011f35a7..904378ba1b19de0b9497cc6f59a0762216eb0f5e 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************\r
- * Copyright (c) 2010 Association for Decentralized Information Management in\r
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
  * Industry THTH ry.\r
  * All rights reserved. This program and the accompanying materials\r
  * are made available under the terms of the Eclipse Public License v1.0\r
@@ -164,6 +164,9 @@ public class ExpressionUtils {
                        }\r
 \r
                        // VARIABLE NAMES\r
+                       \r
+                       if(variables.contains("time"))\r
+                               variables.remove("time");\r
 \r
                        for(String v : variables) {\r
                                if(!modelVariables.keySet().contains(v)) {\r