]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Allow shadow variables to provide values (of the original variables) to modules....
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 7 May 2013 12:13:46 +0000 (12:13 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 7 May 2013 12:13:46 +0000 (12:13 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@27317 ac1ea38d-2e2b-0410-8846-a27921b304fc

12 files changed:
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/CreateVariablesShortcutParticipant.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/SysdynComponentCopyAdvisor.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/SysdynConnectTool.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/modules/ModuleInputEditingSupport.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/modules/ReferenceRow.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/UnitFunction.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/viewUtils/SysdynDatasetSelectionListener.java
org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Module.java
org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Shadow.java [new file with mode: 0644]
org.simantics.sysdyn/src/org/simantics/sysdyn/representation/SysdynSchema.java
org.simantics.sysdyn/src/org/simantics/sysdyn/representation/visitors/ElementVisitorVoidAdapter.java
org.simantics.sysdyn/src/org/simantics/sysdyn/representation/visitors/IElementVisitorVoid.java

index e518828c79a3603e0720e880aa0c9ab7fa1d8a9d..7866f7d8c3b1e76a226642c8cd5da4bf765297ed 100644 (file)
@@ -48,6 +48,7 @@ import org.simantics.sysdyn.SysdynResource;
 import org.simantics.sysdyn.ui.elements.AuxiliaryFactory;\r
 import org.simantics.sysdyn.ui.elements.CloudFactory;\r
 import org.simantics.sysdyn.ui.elements.InputFactory;\r
+import org.simantics.sysdyn.ui.elements.ShadowFactory;\r
 import org.simantics.sysdyn.ui.elements.StockFactory;\r
 import org.simantics.sysdyn.ui.elements.ValveFactory;\r
 import org.simantics.ui.SimanticsUI;\r
@@ -153,7 +154,13 @@ public class CreateVariablesShortcutParticipant extends AbstractDiagramParticipa
                                                SysdynResource.URIs.InputSymbol,\r
                                                (ShapeNode)InputFactory.INPUT_IMAGE.init(parent)\r
                                                );\r
-                       }\r
+                       } else if (kpe.keyCode == java.awt.event.KeyEvent.VK_G) {\r
+                variableInformation = new VariableInformation(\r
+                        java.awt.event.KeyEvent.VK_G,\r
+                        SysdynResource.URIs.ShadowSymbol,\r
+                        (ShapeNode)ShadowFactory.GHOST_IMAGE.init(parent)\r
+                        );\r
+            }\r
 \r
                        if (variableInformation != null) {\r
                                updateSG();\r
index 93ff24b0cbd0cd94b7a3d02edcb60002f9efd3e2..8e6158630732a84a8ce30e1ef49d2ce30c6be4e3 100644 (file)
@@ -54,7 +54,8 @@ public class SysdynComponentCopyAdvisor extends ComponentCopyAdvisor {
                           return StatementEvaluation.INCLUDE;\r
                       else\r
                           return StatementEvaluation.INCLUDE_AND_FOLLOW;\r
-                  }\r
+                  } else if(statement.getPredicate().equals(SYSDYN.Shadow_original))\r
+                      return StatementEvaluation.INCLUDE;\r
               } catch (ServiceException e) {\r
                   e.printStackTrace();\r
               }\r
index 1b4b7a795cab520daa759a26cc1f7c5c91708c76..9182e3b1515d8e7e38a25137ae7033f89d200de7 100644 (file)
@@ -271,6 +271,7 @@ public class SysdynConnectTool extends ConnectTool2 {
                                                Resource start = soa.adapt(Resource.class);\r
                                                if(g.isInheritedFrom(start, sr.ModuleSymbol) && !end.equals(sr.InputSymbol)) return null;\r
                                                if(end.equals(sr.StockSymbol)) return null;\r
+                        if(end.equals(sr.ShadowSymbol)) return null;\r
                                        } else if (currentConnection.equals(flow)) {\r
                                                if(!(end.equals(sr.StockSymbol) || end.equals(sr.ValveSymbol) || end.equals(sr.CloudSymbol))) return null;\r
                                        } else {\r
index 0fc9588de985e037bf370401f7d2cdd9911d7799..42a751a185af9e43c56ab65ff2806882bd9c2e02 100644 (file)
@@ -74,7 +74,13 @@ public class ModuleInputEditingSupport extends EditingSupport {
                                 if(graph.getPossibleObject(dependency, sr.Dependency_refersTo) == null ||\r
                                         graph.getPossibleObject(dependency, sr.Dependency_refersTo).equals(inputVariable)) {\r
                                     Resource output = graph.getSingleObject(dependency, sr.Variable_HasTail);\r
-                                    result.put((String)graph.getRelatedValue(output, l0.HasName), dependency);\r
+                                    \r
+                                    if(graph.isInstanceOf(output, sr.Shadow)) {\r
+                                        output = graph.getPossibleObject(output, sr.Shadow_original);\r
+                                    }\r
+                                    \r
+                                    if(output != null)\r
+                                        result.put((String)graph.getRelatedValue(output, l0.HasName), dependency);\r
                                 }\r
                             }\r
                             return result;\r
index bab8583c59f8d5e9ec2279644e67dc827e3e9ac3..e6685123261d078002c52df646d93e0e75dd31af 100644 (file)
@@ -76,8 +76,13 @@ public class ReferenceRow {
                     Resource valueResource = graph.getPossibleObject(dependency, sr.Variable_HasTail);\r
                     if(!graph.isInstanceOf(valueResource, sr.Variable))\r
                         valueResource = graph.getPossibleObject(dependency, sr.Variable_HasHead);\r
-                    if(!graph.isInstanceOf(valueResource, sr.Variable))\r
+                    \r
+                    if(graph.isInstanceOf(valueResource, sr.Shadow))\r
+                        valueResource = graph.getPossibleObject(valueResource, sr.Shadow_original);\r
+                    \r
+                    if(valueResource == null || !graph.isInstanceOf(valueResource, sr.Variable))\r
                         return "";\r
+                    \r
                     return (String)graph.getRelatedValue(valueResource, l0.HasName, Bindings.STRING);\r
                 }\r
             });\r
index c01fbadf34be782b437041f9bcc4bda30fde9714..3e7d30fb753f965a6466e064437159642aad224e 100644 (file)
@@ -119,6 +119,8 @@ public class UnitFunction {
             Resource reference = graph.getPossibleObject(outputRelation, SR.Dependency_refersTo);\r
             if(reference != null) {\r
                 Resource output = graph.getPossibleObject(outputRelation, SR.Variable_HasHead);\r
+                if(output == null)\r
+                    continue;\r
                 String left = graph.getPossibleRelatedValue(output, SR.Variable_unit);\r
                 String right = graph.getPossibleRelatedValue(reference, SR.Variable_unit);\r
                 result = UnitUtils.matchUnits(left, right);\r
@@ -130,6 +132,8 @@ public class UnitFunction {
             Resource reference = graph.getPossibleObject(inputRelation, SR.Dependency_refersTo);\r
             if(reference != null) {\r
                 Resource variable = graph.getPossibleObject(inputRelation, SR.Variable_HasTail);\r
+                if(variable == null)\r
+                    continue;\r
                 String left = graph.getPossibleRelatedValue(variable, SR.Variable_unit);\r
                 String right = graph.getPossibleRelatedValue(reference, SR.Variable_unit);\r
                 result = UnitUtils.matchUnits(left, right);\r
index 62b678ac0a6d59649a43c5042c64f5405b3b4bca..688ba1f7b47ccc99fe859a07a5b59af6601e7a11 100644 (file)
@@ -210,6 +210,7 @@ public abstract class SysdynDatasetSelectionListener implements ISelectionListen
         DiagramResource dr = DiagramResource.getInstance(g);\r
         if(runtime == null) return null;\r
         Resource resource = ModelingUtils.getPossibleElementCorrespondendence(g, element);\r
+        if(resource != null && g.isInstanceOf(resource, sr.Shadow)) resource = g.getPossibleObject(resource, sr.Shadow_original);\r
         if(resource == null || !g.isInstanceOf(resource, sr.Variable)) return null;\r
         String variableURI = g.getPossibleRelatedValue(runtime, dr.RuntimeDiagram_HasVariable);\r
         if(variableURI != null) {\r
index 15a8b729ad4402f992802e7b41aaa56e21f9ba2e..9d55df020b766710e266880ebd25a293fc9feda2 100644 (file)
@@ -161,6 +161,9 @@ public class Module implements IElement {
                                if(dependency.getHead().equals(this)){\r
                                        Input reference = (Input)dependency.refersTo();\r
                                        Variable outputVariable = (Variable)dependency.getTail();\r
+                                       if(outputVariable instanceof Shadow)\r
+                                           outputVariable = ((Shadow) outputVariable).getOriginal();\r
+                                       \r
                                        String name = outputVariable.getName();\r
 \r
                                        Module module = (Module)dependency.getHead();\r
diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Shadow.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Shadow.java
new file mode 100644 (file)
index 0000000..b652f80
--- /dev/null
@@ -0,0 +1,87 @@
+/*******************************************************************************\r
+ * Copyright (c) 2013 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
+ *     Semantum Oy - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.representation;\r
+\r
+import java.util.ArrayList;\r
+\r
+import org.simantics.objmap.annotations.GraphType;\r
+import org.simantics.objmap.annotations.RelatedElement;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.representation.expressions.IExpression;\r
+import org.simantics.sysdyn.representation.visitors.IElementVisitorVoid;\r
+\r
+@GraphType(SysdynResource.URIs.Shadow)\r
+public class Shadow extends Variable {\r
+\r
+    @RelatedElement(SysdynResource.URIs.Shadow_original)\r
+    private Variable original;\r
+\r
+    @Override\r
+    public void accept(IElementVisitorVoid v) {\r
+        if(getOriginal() != null)\r
+            original.accept(v);\r
+    }\r
+\r
+    public Variable getOriginal() {\r
+        return original;\r
+    }\r
+\r
+    @Override\r
+    public String getName() {\r
+        if(getOriginal() != null)\r
+            return getOriginal().getName();\r
+        else\r
+            return super.getName();\r
+    }\r
+\r
+    @Override\r
+    public ArrayList<Enumeration> getArrayIndexes() {\r
+        if(getOriginal() != null)\r
+            return getOriginal().getArrayIndexes();\r
+        else\r
+            return super.getArrayIndexes();\r
+    }\r
+\r
+    @Override\r
+    public ArrayList<IExpression> getExpressions() {\r
+        if(getOriginal() != null)\r
+            return getOriginal().getExpressions();\r
+        else\r
+            return super.getExpressions();\r
+    }\r
+\r
+    @Override\r
+    public String getVariability() {\r
+        if(getOriginal() != null)\r
+            return getOriginal().getVariability();\r
+        else\r
+            return super.getVariability();\r
+    }\r
+\r
+    @Override\r
+    public String getType() {\r
+        if(getOriginal() != null)\r
+            return getOriginal().getType();\r
+        else\r
+            return super.getType();\r
+    }\r
+\r
+    @Override\r
+    public String getUnit() {\r
+        if(getOriginal() != null)\r
+            return getOriginal().getUnit();\r
+        else\r
+            return super.getUnit();\r
+    }\r
+\r
+}\r
+\r
index 9d4eab2691715597682207656edba680c265a409..4d47a8c5616a12420632758549b8b5d06c89c144 100644 (file)
@@ -57,6 +57,7 @@ public class SysdynSchema extends SimpleSchema {
             addLinkType(MappingSchemas.fromAnnotations(g, Function.class));\r
             addLinkType(MappingSchemas.fromAnnotations(g, Entity.class));\r
             addLinkType(MappingSchemas.fromAnnotations(g, ParameterOverride.class));\r
+            addLinkType(MappingSchemas.fromAnnotations(g, Shadow.class));\r
         } catch (DatabaseException e) {\r
             e.printStackTrace();\r
         } catch (InstantiationException e) {\r
index 64c7d287ff8aef1ffb358f633dde541fdad9f7b7..b48955c4cef882820b0a2989ea8191b5b22d2c12 100644 (file)
@@ -12,6 +12,7 @@
 package org.simantics.sysdyn.representation.visitors;\r
 \r
 import org.simantics.sysdyn.representation.Auxiliary;\r
+import org.simantics.sysdyn.representation.Book;\r
 import org.simantics.sysdyn.representation.Cloud;\r
 import org.simantics.sysdyn.representation.Configuration;\r
 import org.simantics.sysdyn.representation.Dependency;\r
@@ -21,9 +22,9 @@ import org.simantics.sysdyn.representation.Flow;
 import org.simantics.sysdyn.representation.Input;\r
 import org.simantics.sysdyn.representation.LibraryDummy;\r
 import org.simantics.sysdyn.representation.Module;\r
-import org.simantics.sysdyn.representation.Book;\r
 import org.simantics.sysdyn.representation.Stock;\r
 import org.simantics.sysdyn.representation.Valve;\r
+import org.simantics.sysdyn.representation.Variable;\r
 \r
 public class ElementVisitorVoidAdapter implements IElementVisitorVoid {\r
 \r
@@ -78,4 +79,8 @@ public class ElementVisitorVoidAdapter implements IElementVisitorVoid {
     @Override\r
     public void visit(DiagramContainerDummy container) {\r
     }\r
+    \r
+    @Override\r
+    public void visit(Variable variable) {\r
+    }\r
 }\r
index 3c78343bf13eb9f10363296dedbbe6096adf7093..a15028dc64f992b51a7a636ae045541a8cb2c8a3 100644 (file)
@@ -12,6 +12,7 @@
 package org.simantics.sysdyn.representation.visitors;\r
 \r
 import org.simantics.sysdyn.representation.Auxiliary;\r
+import org.simantics.sysdyn.representation.Book;\r
 import org.simantics.sysdyn.representation.Cloud;\r
 import org.simantics.sysdyn.representation.Configuration;\r
 import org.simantics.sysdyn.representation.Dependency;\r
@@ -21,9 +22,9 @@ import org.simantics.sysdyn.representation.Flow;
 import org.simantics.sysdyn.representation.Input;\r
 import org.simantics.sysdyn.representation.LibraryDummy;\r
 import org.simantics.sysdyn.representation.Module;\r
-import org.simantics.sysdyn.representation.Book;\r
 import org.simantics.sysdyn.representation.Stock;\r
 import org.simantics.sysdyn.representation.Valve;\r
+import org.simantics.sysdyn.representation.Variable;\r
 \r
 public interface IElementVisitorVoid {\r
 \r
@@ -40,4 +41,5 @@ public interface IElementVisitorVoid {
     void visit(LibraryDummy libraryDummy);\r
     void visit(Book sheet);\r
     void visit(DiagramContainerDummy container);\r
+    void visit(Variable variable);\r
 }\r