]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Unit validation for module interfaces (refs #4268)
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 6 May 2013 10:24:16 +0000 (10:24 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 6 May 2013 10:24:16 +0000 (10:24 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@27310 ac1ea38d-2e2b-0410-8846-a27921b304fc

14 files changed:
org.simantics.sysdyn.ontology/graph.tg
org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph
org.simantics.sysdyn.ontology/graph/Validation.pgraph
org.simantics.sysdyn.ontology/src/org/simantics/sysdyn/SysdynResource.java
org.simantics.sysdyn.ui/META-INF/MANIFEST.MF
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/profiles/IssueDecorationStyle.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynProject.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ConfigurationTab.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/InputVariableTab.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/UnitComboWidget.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/ModelUtils.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/ModuleStandardIssue.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/UnitFunction.java
org.simantics.sysdyn/src/org/simantics/sysdyn/representation/utils/UnitUtils.java

index da045bf5c53e1de49b6f71151085794afeb91645..87734e2663aa803cc9f3f1f9c9b7222b11d033bc 100644 (file)
Binary files a/org.simantics.sysdyn.ontology/graph.tg and b/org.simantics.sysdyn.ontology/graph.tg differ
index 9f646f051574353315b480c85d017d0b626f8a0e..54d927db8db5397eb432b770428127a17570ff34 100644 (file)
@@ -88,8 +88,8 @@ SYSDYN.DefaultRealization <T L0X.Realization
 //#####################################################################
 // Variables
 //#####################################################################
-
-SYSDYN.Variable <T STR.Component    
+SYSDYN.Component <T STR.Component
+SYSDYN.Variable <T SYSDYN.Component  
     >-- SYSDYN.Variable.type --> L0.String <R L0.HasProperty : L0.FunctionalRelation
     >-- SYSDYN.Variable.expressions --> SYSDYN.Expressions <R L0.IsComposedOf : L0.FunctionalRelation
     >-- SYSDYN.Variable.expressionList --> L0.List <R L0.IsComposedOf : L0.FunctionalRelation
@@ -186,7 +186,7 @@ SYSDYN.Shadow <T SYSDYN.Variable
 // Modules
 //#####################################################################
 
-SYSDYN.Module <T STR.Component
+SYSDYN.Module <T SYSDYN.Component
     >-- SYSDYN.Module.redeclaration --> SYSDYN.Redeclaration  <R L0.IsComposedOf
     >-- SYSDYN.Module.parameterOverride --> SYSDYN.Module.ParameterOverride <R L0.IsComposedOf
 
@@ -400,7 +400,7 @@ SYSDYN.SysdynTerminal <T DIA.Terminal
     @L0.assert DIA.Terminal.AllowedDirections 0
 
 //#####################################################################
-SYSDYN.Valve <T STR.Component
+SYSDYN.Valve
     @MOD.connection SYSDYN.Variable.isTailOf
     @MOD.connection SYSDYN.Variable.isHeadOf
     
@@ -429,7 +429,7 @@ SYSDYN.ValveSymbol <T DIA.FontProvider <T DIA.ColorProvider
                 @MOD.terminal SYSDYN.ValveSymbol SYSDYN.IsTailOfTerminal
 
 //#####################################################################
-SYSDYN.Auxiliary <T STR.Component
+SYSDYN.Auxiliary
     @MOD.connection SYSDYN.Variable.isTailOf
     @MOD.connection SYSDYN.Variable.isHeadOf
 
@@ -444,7 +444,7 @@ SYSDYN.AuxiliarySymbol <T DIA.FontProvider <T DIA.ColorProvider
                 @MOD.terminal SYSDYN.AuxiliarySymbol SYSDYN.IsTailOfTerminal
 
 //#####################################################################
-SYSDYN.Cloud <T STR.Component
+SYSDYN.Cloud
     @MOD.connection SYSDYN.Variable.isTailOf
     @MOD.connection SYSDYN.Variable.isHeadOf
 
@@ -459,7 +459,7 @@ SYSDYN.CloudSymbol <T DIA.FontProvider <T DIA.ColorProvider
                 @MOD.terminal SYSDYN.CloudSymbol SYSDYN.IsTailOfTerminal
 
 //#####################################################################
-SYSDYN.Input <T STR.Component
+SYSDYN.Input
     @MOD.connection SYSDYN.Variable.isTailOf
     @MOD.connection SYSDYN.Variable.isHeadOf
 
@@ -489,7 +489,7 @@ SYSDYN.StockSymbol <T DIA.FontProvider <T DIA.ColorProvider
                 @MOD.terminal SYSDYN.StockSymbol SYSDYN.IsTailOfTerminal    
 
 //#####################################################################
-SYSDYN.Shadow <T STR.Component
+SYSDYN.Shadow
     @MOD.connection SYSDYN.Variable.isTailOf
     @MOD.connection SYSDYN.Variable.isHeadOf
 
index 3cf2d18d781de582f9a889d0fa729699a8aa99c2..6d4fb228c232eb0e960154b9513fb5197cca9581 100644 (file)
@@ -2,6 +2,7 @@ L0 = <http://www.simantics.org/Layer0-1.1>
 L0X = <http://www.simantics.org/Layer0X-1.1>\r
 ISSUE = <http://www.simantics.org/Issue-1.2>\r
 SYSDYN = <http://www.simantics.org/Sysdyn-1.1>\r
+STR = <http://www.simantics.org/Structural-1.2>\r
 \r
 VALIDATIONS = SYSDYN.Validations : L0.Library\r
 \r
@@ -27,9 +28,12 @@ VALIDATIONS.Expressions.expressionValidator : L0.Function
 VALIDATIONS.Enumerations : L0.Library\r
 VALIDATIONS.Enumerations.enumerationIndexValidator : L0.Function\r
 \r
-// ENUMERATIONS\r
+// UNITS\r
 VALIDATIONS.Units : L0.Library\r
 VALIDATIONS.Units.unitValidator : L0.Function\r
+VALIDATIONS.Units.moduleInterfaceExtension : L0.Function\r
+\r
+\r
 \r
 SYSDYN.Variable\r
     @VALIDATIONS.constraint\r
@@ -62,15 +66,18 @@ SYSDYN.Variable
             @L0.assert L0.HasName "MissingDependencyConnectionsIssueSource"\r
         VALIDATIONS.Dependencies.missingDependencyValidator  \r
         VALIDATIONS.Functions.baseRealizationFunction \r
-        \r
-SYSDYN.IndependentVariable\r
+\r
+SYSDYN.Component\r
     @VALIDATIONS.listeningConstraint\r
         VALIDATIONS.UnitConstraint\r
         VALIDATIONS.Units.UnitIssueSource\r
             @L0.assert L0.HasName "UnitIssueSource"\r
+            L0.Asserts _ : L0.Assertion\r
+                L0.HasPredicate ISSUE.Sources.DependencyTracker.HasExtension\r
+                L0.HasObject VALIDATIONS.Units.moduleInterfaceExtension\r
         VALIDATIONS.Units.unitValidator  \r
         VALIDATIONS.Functions.baseRealizationFunction\r
-        \r
+\r
 VALIDATIONS.ExpressionIssue\r
     @VALIDATIONS.issue\r
         ISSUE.Severity.Error\r
@@ -134,6 +141,19 @@ VALIDATIONS.UnitWarning
             L0.HasValueType "String"\r
         VALIDATIONS.Functions.path        \r
 \r
+VALIDATIONS.ModuleInputUnitWarning\r
+    @VALIDATIONS.issue\r
+        ISSUE.Severity.Warning\r
+        VALIDATIONS.Units.moduleInputUnitWarningDescription : L0.Function\r
+            L0.HasValueType "String"\r
+        VALIDATIONS.Functions.path   \r
+        \r
+VALIDATIONS.ModuleOutputUnitWarning\r
+    @VALIDATIONS.issue\r
+        ISSUE.Severity.Warning\r
+        VALIDATIONS.Units.moduleOutputUnitWarningDescription : L0.Function\r
+            L0.HasValueType "String"\r
+        VALIDATIONS.Functions.path   \r
         \r
 // IssueSource template\r
 VALIDATIONS.constraint : L0.Template\r
@@ -151,7 +171,6 @@ VALIDATIONS.constraint : L0.Template
             L0.Asserts _ : L0.Assertion\r
                 L0.HasPredicate ISSUE.Sources.DependencyTracker.HasBaseFunction\r
                 L0.HasObject %baseFunction                          \r
-            \r
 \r
 VALIDATIONS.listeningConstraint : L0.Template\r
     @template %type %constraint %source %validator %baseFunction\r
index 2109bb0b386449e1dca1a844202b0e34d69c4afb..e972eab9e7cca3be662c1d65937f56b87c9f6553 100644 (file)
@@ -321,6 +321,7 @@ public class SysdynResource {
     public final Resource Charts_SensitivityPlot;\r
     public final Resource Cloud;\r
     public final Resource CloudSymbol;\r
+    public final Resource Component;\r
     public final Resource Configuration;\r
     public final Resource ConfigurationDiagram;\r
     public final Resource ConfigurationDiagramTemplate;\r
@@ -643,6 +644,8 @@ public class SysdynResource {
     public final Resource Validations_Issue_stringContexts_Inverse;\r
     public final Resource Validations_MissingDependencyConstraint;\r
     public final Resource Validations_MissingLinkIssue;\r
+    public final Resource Validations_ModuleInputUnitWarning;\r
+    public final Resource Validations_ModuleOutputUnitWarning;\r
     public final Resource Validations_NoSuchVariableIssue;\r
     public final Resource Validations_RangeIssue;\r
     public final Resource Validations_RangeWarning;\r
@@ -650,6 +653,9 @@ public class SysdynResource {
     public final Resource Validations_UnitWarning;\r
     public final Resource Validations_Units;\r
     public final Resource Validations_Units_UnitIssueSource;\r
+    public final Resource Validations_Units_moduleInputUnitWarningDescription;\r
+    public final Resource Validations_Units_moduleInterfaceExtension;\r
+    public final Resource Validations_Units_moduleOutputUnitWarningDescription;\r
     public final Resource Validations_Units_unitValidator;\r
     public final Resource Validations_Units_unitWarningDescription;\r
     public final Resource Validations_UnusedDependencyIssue;\r
@@ -1015,6 +1021,7 @@ public class SysdynResource {
         public static final String Charts_SensitivityPlot = "http://www.simantics.org/Sysdyn-1.1/Charts/SensitivityPlot";\r
         public static final String Cloud = "http://www.simantics.org/Sysdyn-1.1/Cloud";\r
         public static final String CloudSymbol = "http://www.simantics.org/Sysdyn-1.1/CloudSymbol";\r
+        public static final String Component = "http://www.simantics.org/Sysdyn-1.1/Component";\r
         public static final String Configuration = "http://www.simantics.org/Sysdyn-1.1/Configuration";\r
         public static final String ConfigurationDiagram = "http://www.simantics.org/Sysdyn-1.1/ConfigurationDiagram";\r
         public static final String ConfigurationDiagramTemplate = "http://www.simantics.org/Sysdyn-1.1/ConfigurationDiagramTemplate";\r
@@ -1337,6 +1344,8 @@ public class SysdynResource {
         public static final String Validations_Issue_stringContexts_Inverse = "http://www.simantics.org/Sysdyn-1.1/Validations/Issue/stringContexts/Inverse";\r
         public static final String Validations_MissingDependencyConstraint = "http://www.simantics.org/Sysdyn-1.1/Validations/MissingDependencyConstraint";\r
         public static final String Validations_MissingLinkIssue = "http://www.simantics.org/Sysdyn-1.1/Validations/MissingLinkIssue";\r
+        public static final String Validations_ModuleInputUnitWarning = "http://www.simantics.org/Sysdyn-1.1/Validations/ModuleInputUnitWarning";\r
+        public static final String Validations_ModuleOutputUnitWarning = "http://www.simantics.org/Sysdyn-1.1/Validations/ModuleOutputUnitWarning";\r
         public static final String Validations_NoSuchVariableIssue = "http://www.simantics.org/Sysdyn-1.1/Validations/NoSuchVariableIssue";\r
         public static final String Validations_RangeIssue = "http://www.simantics.org/Sysdyn-1.1/Validations/RangeIssue";\r
         public static final String Validations_RangeWarning = "http://www.simantics.org/Sysdyn-1.1/Validations/RangeWarning";\r
@@ -1344,6 +1353,9 @@ public class SysdynResource {
         public static final String Validations_UnitWarning = "http://www.simantics.org/Sysdyn-1.1/Validations/UnitWarning";\r
         public static final String Validations_Units = "http://www.simantics.org/Sysdyn-1.1/Validations/Units";\r
         public static final String Validations_Units_UnitIssueSource = "http://www.simantics.org/Sysdyn-1.1/Validations/Units/UnitIssueSource";\r
+        public static final String Validations_Units_moduleInputUnitWarningDescription = "http://www.simantics.org/Sysdyn-1.1/Validations/Units/moduleInputUnitWarningDescription";\r
+        public static final String Validations_Units_moduleInterfaceExtension = "http://www.simantics.org/Sysdyn-1.1/Validations/Units/moduleInterfaceExtension";\r
+        public static final String Validations_Units_moduleOutputUnitWarningDescription = "http://www.simantics.org/Sysdyn-1.1/Validations/Units/moduleOutputUnitWarningDescription";\r
         public static final String Validations_Units_unitValidator = "http://www.simantics.org/Sysdyn-1.1/Validations/Units/unitValidator";\r
         public static final String Validations_Units_unitWarningDescription = "http://www.simantics.org/Sysdyn-1.1/Validations/Units/unitWarningDescription";\r
         public static final String Validations_UnusedDependencyIssue = "http://www.simantics.org/Sysdyn-1.1/Validations/UnusedDependencyIssue";\r
@@ -1719,6 +1731,7 @@ public class SysdynResource {
         Charts_SensitivityPlot = getResourceOrNull(graph, URIs.Charts_SensitivityPlot);\r
         Cloud = getResourceOrNull(graph, URIs.Cloud);\r
         CloudSymbol = getResourceOrNull(graph, URIs.CloudSymbol);\r
+        Component = getResourceOrNull(graph, URIs.Component);\r
         Configuration = getResourceOrNull(graph, URIs.Configuration);\r
         ConfigurationDiagram = getResourceOrNull(graph, URIs.ConfigurationDiagram);\r
         ConfigurationDiagramTemplate = getResourceOrNull(graph, URIs.ConfigurationDiagramTemplate);\r
@@ -2041,6 +2054,8 @@ public class SysdynResource {
         Validations_Issue_stringContexts_Inverse = getResourceOrNull(graph, URIs.Validations_Issue_stringContexts_Inverse);\r
         Validations_MissingDependencyConstraint = getResourceOrNull(graph, URIs.Validations_MissingDependencyConstraint);\r
         Validations_MissingLinkIssue = getResourceOrNull(graph, URIs.Validations_MissingLinkIssue);\r
+        Validations_ModuleInputUnitWarning = getResourceOrNull(graph, URIs.Validations_ModuleInputUnitWarning);\r
+        Validations_ModuleOutputUnitWarning = getResourceOrNull(graph, URIs.Validations_ModuleOutputUnitWarning);\r
         Validations_NoSuchVariableIssue = getResourceOrNull(graph, URIs.Validations_NoSuchVariableIssue);\r
         Validations_RangeIssue = getResourceOrNull(graph, URIs.Validations_RangeIssue);\r
         Validations_RangeWarning = getResourceOrNull(graph, URIs.Validations_RangeWarning);\r
@@ -2048,6 +2063,9 @@ public class SysdynResource {
         Validations_UnitWarning = getResourceOrNull(graph, URIs.Validations_UnitWarning);\r
         Validations_Units = getResourceOrNull(graph, URIs.Validations_Units);\r
         Validations_Units_UnitIssueSource = getResourceOrNull(graph, URIs.Validations_Units_UnitIssueSource);\r
+        Validations_Units_moduleInputUnitWarningDescription = getResourceOrNull(graph, URIs.Validations_Units_moduleInputUnitWarningDescription);\r
+        Validations_Units_moduleInterfaceExtension = getResourceOrNull(graph, URIs.Validations_Units_moduleInterfaceExtension);\r
+        Validations_Units_moduleOutputUnitWarningDescription = getResourceOrNull(graph, URIs.Validations_Units_moduleOutputUnitWarningDescription);\r
         Validations_Units_unitValidator = getResourceOrNull(graph, URIs.Validations_Units_unitValidator);\r
         Validations_Units_unitWarningDescription = getResourceOrNull(graph, URIs.Validations_Units_unitWarningDescription);\r
         Validations_UnusedDependencyIssue = getResourceOrNull(graph, URIs.Validations_UnusedDependencyIssue);\r
index 37de08ac9e1e8b6503aacc39af579eecec46a54d..e4d2ebbcf97985d77160993bf0550c31b3897474 100644 (file)
@@ -55,7 +55,8 @@ Require-Bundle: org.simantics.layer0.utils;bundle-version="0.6.2",
  org.simantics.scenegraph.swing;bundle-version="1.0.0",
  org.eclipse.nebula.widgets.tablecombo;bundle-version="1.0.0",
  org.simantics.fmu;bundle-version="1.0.0",
- org.simantics.jfreechart;bundle-version="1.0.0"
+ org.simantics.jfreechart;bundle-version="1.0.0",
+ org.simantics.db.indexing;bundle-version="1.1.0"
 Bundle-Activator: org.simantics.sysdyn.ui.Activator
 Bundle-ActivationPolicy: lazy
 Export-Package: org.simantics.sysdyn.ui.browser.nodes
index a0289d2dedcae28197517b6a526202136f4866d5..e3db689fc116c0680d59bf32ceb7d51da786e038 100644 (file)
@@ -127,7 +127,7 @@ public class IssueDecorationStyle extends StyleBase<IssueResult> {
             list = graph.getPossibleObject(issueResource, ISSUE.Issue_HasContexts);\r
             List<Resource> contexts = ListUtils.toList(graph, list);\r
             if(!contexts.isEmpty()) {\r
-                if(ListUtils.toList(graph, list).get(0).equals(component)) {\r
+                if(ListUtils.toList(graph, list).subList(0, 1).contains(component)) {\r
                     return new IssueResult(severity, transform);\r
                 }\r
             }\r
index 8d5befedcb15e3db8ebda1b506212a66f14a5084..2664e9751a0316a74d0a7fe9dd459328f923addb 100644 (file)
@@ -21,21 +21,19 @@ import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;\r
 import org.simantics.db.Session;\r
 import org.simantics.db.WriteGraph;\r
-import org.simantics.db.common.changeset.GenericChangeListener;\r
 import org.simantics.db.common.request.ReadRequest;\r
 import org.simantics.db.common.request.WriteRequest;\r
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.db.layer0.adapter.RuntimeValuations;\r
 import org.simantics.db.layer0.adapter.TrendVariable;\r
-import org.simantics.db.layer0.genericrelation.DependenciesRelation.DependencyChangesRequest;\r
-import org.simantics.db.layer0.genericrelation.DependencyChanges;\r
 import org.simantics.db.layer0.service.ActivationManager;\r
 import org.simantics.db.request.Read;\r
 import org.simantics.db.service.GraphChangeListenerSupport;\r
 import org.simantics.db.service.VirtualGraphSupport;\r
+import org.simantics.fmu.FMUControlJNI;\r
 import org.simantics.issues.common.IssueUtils;\r
 import org.simantics.layer0.Layer0;\r
-import org.simantics.fmu.FMUControlJNI;\r
+import org.simantics.modeling.ModelingUtils;\r
 import org.simantics.modeling.services.CaseInsensitiveComponentNamingStrategy2;\r
 import org.simantics.modeling.services.ComponentNamingStrategy;\r
 import org.simantics.project.IProject;\r
@@ -248,20 +246,23 @@ public class SysdynProject extends AbstractProjectFeature {
 \r
        public void onActivated(final ReadGraph graph, final IProject project) throws DatabaseException {\r
 \r
-               GraphChangeListenerSupport changeSupport = graph.getService(GraphChangeListenerSupport.class);\r
-               changeSupport.addMetadataListener(new GenericChangeListener<DependencyChangesRequest, DependencyChanges>() {\r
-\r
-                       @Override\r
-                       public void onEvent(ReadGraph graph, DependencyChanges event) throws DatabaseException {\r
-\r
-                               WriteGraph w = (WriteGraph)graph;\r
-                               w.addMetadata(event);\r
-\r
-                       }\r
-\r
-               });\r
+//             GraphChangeListenerSupport changeSupport = graph.getService(GraphChangeListenerSupport.class);\r
+//             changeSupport.addMetadataListener(new GenericChangeListener<DependencyChangesRequest, DependencyChanges>() {\r
+//\r
+//                     @Override\r
+//                     public void onEvent(ReadGraph graph, DependencyChanges event) throws DatabaseException {\r
+//\r
+//                             WriteGraph w = (WriteGraph)graph;\r
+//                             w.addMetadata(event);\r
+//\r
+//                     }\r
+//\r
+//             });\r
 \r
                IssueUtils.listenActiveProjectIssueSources(graph, project.get());\r
+               \r
+        ModelingUtils.trackDependencies(graph);\r
+\r
 \r
        }\r
 \r
index 4758261b1a1978b524a2c1136257cd7c141e3741..477c60863f93e56cd138b463b34f25797398d350 100644 (file)
@@ -210,6 +210,9 @@ public class ConfigurationTab extends LabelPropertyTabContributor {
                         new PossibleObjectWithType(model, \r
                                 Layer0X.getInstance(graph).Activates, \r
                                 SysdynResource.getInstance(graph).Validations_Units_UnitIssueSource));\r
+                if(unitIssueSource == null)\r
+                    return false;\r
+                \r
                 Boolean result = graph.getPossibleRelatedValue(unitIssueSource, IssueResource.getInstance(graph).IssueSource_active, Bindings.BOOLEAN);\r
                 return Boolean.TRUE.equals(result);\r
             }\r
index 9578e18b9886a9aba89cd23ce4c836a83bcae098..5cccc1915afa338db88be54dd6a4c4d3c9765add 100644 (file)
@@ -35,6 +35,7 @@ import org.simantics.db.management.ISessionContext;
 import org.simantics.layer0.Layer0;\r
 import org.simantics.sysdyn.SysdynResource;\r
 import org.simantics.sysdyn.ui.properties.widgets.IsOutputWidget;\r
+import org.simantics.sysdyn.ui.properties.widgets.UnitComboWidget;\r
 import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyFactory;\r
 import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyModifier;\r
 import org.simantics.sysdyn.ui.properties.widgets.factories.VariableNamePropertyModifier;\r
@@ -76,6 +77,19 @@ public class InputVariableTab  extends LabelPropertyTabContributor {
         defaultValue.setInputValidator(new DoubleValidator());\r
         GridDataFactory.fillDefaults().grab(true, false).applyTo(defaultValue.getWidget());\r
 \r
+\r
+        Composite unitComposite = new Composite(composite, SWT.NONE);\r
+        GridDataFactory.fillDefaults().applyTo(unitComposite);\r
+        GridLayoutFactory.fillDefaults().numColumns(2).applyTo(unitComposite);\r
+        \r
+        label = new Label(unitComposite, SWT.NULL );\r
+        label.setText("Unit:");\r
+        GridDataFactory.fillDefaults().applyTo(label);\r
+\r
+        TrackedCombo unitCombo = new UnitComboWidget(unitComposite, support, SWT.DROP_DOWN | SWT.BORDER);\r
+        GridDataFactory.fillDefaults().grab(true, false).applyTo(unitCombo.getWidget());\r
+        \r
+        \r
         Composite variabilityComposite = new Composite(composite, SWT.NONE);\r
         GridDataFactory.fillDefaults().grab(false, true).applyTo(variabilityComposite);\r
         GridLayoutFactory.fillDefaults().numColumns(2).applyTo(variabilityComposite);\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/UnitComboWidget.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/UnitComboWidget.java
new file mode 100644 (file)
index 0000000..d2a770f
--- /dev/null
@@ -0,0 +1,95 @@
+/*******************************************************************************\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.ui.properties.widgets;\r
+\r
+import java.util.Collection;\r
+import java.util.HashMap;\r
+import java.util.Map;\r
+\r
+import org.eclipse.swt.widgets.Composite;\r
+import org.simantics.browsing.ui.swt.widgets.TrackedCombo;\r
+import org.simantics.browsing.ui.swt.widgets.impl.ComboModifyListenerImpl;\r
+import org.simantics.browsing.ui.swt.widgets.impl.ReadFactoryImpl;\r
+import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.manager.SysdynModel;\r
+import org.simantics.sysdyn.manager.SysdynModelManager;\r
+\r
+public class UnitComboWidget extends TrackedCombo {\r
+\r
+    public UnitComboWidget(Composite parent, WidgetSupport support, int style) {\r
+        super(parent, support, style);\r
+        \r
+        \r
+        // Add all units used in the model to the unit combo\r
+        setItemFactory(new ReadFactoryImpl<Resource, Map<String,Object>>() {\r
+\r
+            @Override\r
+            public Map<String, Object> perform(ReadGraph graph, final Resource input) throws DatabaseException {\r
+                Map<String, Object> map = new HashMap<String, Object>();\r
+\r
+                SysdynResource sr = SysdynResource.getInstance(graph);\r
+                Layer0 l0 = Layer0.getInstance(graph);\r
+                Resource model = graph.getPossibleObject(input, l0.PartOf);\r
+                if (model != null) {\r
+                    Collection<Resource> variables = graph.getObjects(model, l0.ConsistsOf);\r
+                    for(Resource v : variables) {\r
+                        Object unit = graph.getPossibleRelatedValue(v, sr.Variable_unit);\r
+                        if (unit != null && !map.keySet().contains(unit)) {\r
+                            map.put((String)unit, (String)unit);\r
+\r
+                        }\r
+                    }\r
+                }\r
+                return map;\r
+            }\r
+        });\r
+        \r
+        // Set initial selection of unit combo\r
+        setSelectionFactory(new ReadFactoryImpl<Resource, String>() {\r
+\r
+            @Override\r
+            public String perform(ReadGraph graph, final Resource input) throws DatabaseException {\r
+                String unit = graph.getPossibleRelatedValue(input, SysdynResource.getInstance(graph).Variable_unit);\r
+                if(unit == null)\r
+                    return "";\r
+                else \r
+                    return unit;\r
+            }\r
+        });\r
+\r
+        // Modify unit\r
+        addModifyListener(new ComboModifyListenerImpl<Resource>() {\r
+\r
+            @Override\r
+            public void applyText(WriteGraph graph, Resource input, String text) throws DatabaseException {\r
+                graph.denyValue(input, SysdynResource.getInstance(graph).Variable_unit);\r
+                graph.claimLiteral(input, SysdynResource.getInstance(graph).Variable_unit, text);\r
+                \r
+                Resource conf = graph.getPossibleObject(input, Layer0.getInstance(graph).PartOf);\r
+                SysdynModelManager smm = SysdynModelManager.getInstance(graph.getSession());\r
+                SysdynModel sm = smm.getModel(graph, conf);\r
+                sm.getMapping().domainModified(input);\r
+                sm.update(graph);\r
+            }\r
+        });\r
+\r
+    }\r
+    \r
+    \r
+\r
+}\r
index 8e4833b3b8cd6ff16662216341d322bbf46d4772..f9e47fefcb3e5f02e3c9587654ce4ac6a787e51c 100644 (file)
@@ -103,8 +103,8 @@ public class ModelUtils {
                     L0X.IsActivatedBy, model,\r
                     l0.PartOf, model,\r
                     IssueResource.getInstance(g).IssueSource_active, false\r
-                    );               \r
-\r
+                    );        \r
+            \r
             Resource conf = GraphUtils.create2(g,\r
                     sr.Configuration,\r
                     l0.PartOf, model,\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/ModuleStandardIssue.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/validation/ModuleStandardIssue.java
new file mode 100644 (file)
index 0000000..4cbdf73
--- /dev/null
@@ -0,0 +1,37 @@
+/*******************************************************************************\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.ui.validation;\r
+\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.issue.StandardIssue;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.issues.ontology.IssueResource;\r
+\r
+public class ModuleStandardIssue extends StandardIssue {\r
+\r
+    public ModuleStandardIssue(Resource type, Resource ... contexts) {\r
+        super(type, contexts);\r
+    }\r
+    \r
+    @Override\r
+    public void writeAdditionalContext(WriteGraph graph, Resource issue) throws DatabaseException {\r
+        super.writeAdditionalContext(graph, issue);\r
+\r
+        if(contexts.length >= 2) {\r
+            IssueResource IR = IssueResource.getInstance(graph);\r
+            // Input / output context\r
+            graph.claim(issue, IR.Issue_HasContext, IR.Issue_HasContext_Inverse, contexts[1]);\r
+        }\r
+    }\r
+\r
+}\r
index f8e5839bea2de369ea52d05e5ee71f7755f4d996..c01fbadf34be782b437041f9bcc4bda30fde9714 100644 (file)
 package org.simantics.sysdyn.ui.validation;\r
 \r
 import java.util.ArrayList;\r
+import java.util.Collection;\r
 import java.util.Collections;\r
+import java.util.HashSet;\r
 import java.util.List;\r
 \r
+import org.simantics.Simantics;\r
 import org.simantics.db.Issue;\r
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
 import org.simantics.db.common.issue.StandardIssue;\r
+import org.simantics.db.common.request.ObjectsWithType;\r
 import org.simantics.db.common.utils.ListUtils;\r
+import org.simantics.db.common.utils.NameUtils;\r
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.db.layer0.variable.Variable;\r
 import org.simantics.issues.common.IssueUtils;\r
@@ -30,40 +35,49 @@ import org.simantics.sysdyn.manager.SysdynModel;
 import org.simantics.sysdyn.manager.SysdynModelManager;\r
 import org.simantics.sysdyn.representation.IndependentVariable;\r
 import org.simantics.sysdyn.representation.expressions.IExpression;\r
+import org.simantics.sysdyn.representation.utils.UnitUtils;\r
 \r
 public class UnitFunction {\r
-    \r
+\r
     @SCLValue(type = "ReadGraph -> Resource -> [Issue]")\r
-    public static List<Issue> unitValidator(ReadGraph graph, Resource independentVariable) throws DatabaseException {\r
-        Layer0 L0 = Layer0.getInstance(graph);\r
+    public static List<Issue> unitValidator(ReadGraph graph, Resource component) throws DatabaseException {\r
         SysdynResource SR = SysdynResource.getInstance(graph);\r
-\r
-        \r
-        if(independentVariable == null)\r
+        if(graph.isInstanceOf(component, SR.Variable))\r
+            return variableValidator(graph, component);\r
+        else if(graph.isInstanceOf(component, SR.Module))\r
+            return moduleValidator(graph, component);\r
+        else\r
             return Collections.emptyList();\r
-        \r
-        Resource configuration = graph.getPossibleObject(independentVariable, L0.PartOf);\r
+    }\r
+    \r
+    private static List<Issue> variableValidator(ReadGraph graph, Resource variable) throws DatabaseException {\r
+        Layer0 L0 = Layer0.getInstance(graph); \r
+        SysdynResource SR = SysdynResource.getInstance(graph);\r
+\r
+        Resource configuration = graph.getPossibleObject(variable, L0.PartOf);\r
         if(configuration == null)\r
             return Collections.emptyList();\r
-        \r
+\r
         // Make sure unit updates are listened to\r
-        Resource unitResource = graph.getPossibleObject(independentVariable, SR.Variable_unit);\r
-        String unit = graph.getPossibleRelatedValue(independentVariable, SR.Variable_unit);\r
+        String unit = graph.getPossibleRelatedValue(variable, SR.Variable_unit);\r
         if(unit == null || unit.trim().length() == 0)\r
-            return Collections.<Issue>singletonList(new StandardIssue(SR.Validations_UnitWarning, independentVariable));\r
-        \r
-        Resource expressionList = graph.getPossibleObject(independentVariable, SR.Variable_expressionList);\r
+            return Collections.<Issue>singletonList(new StandardIssue(SR.Validations_UnitWarning, variable));\r
+\r
+        if(!graph.isInstanceOf(variable, SR.IndependentVariable))\r
+            return Collections.emptyList();\r
         \r
+        Resource expressionList = graph.getPossibleObject(variable, SR.Variable_expressionList);\r
+\r
         if(expressionList == null)\r
             return Collections.emptyList();\r
 \r
-        \r
+\r
         SysdynModelManager smm = SysdynModelManager.getInstance(graph.getSession());\r
         SysdynModel sm = smm.getModel(graph, configuration);\r
-        sm.getMapping().domainModified(independentVariable);\r
+        sm.getMapping().domainModified(variable);\r
 \r
         sm.update(graph);\r
-        Object var = sm.getMapping().get(independentVariable);\r
+        Object var = sm.getMapping().get(variable);\r
 \r
         ArrayList<Issue> issues = new ArrayList<Issue>();\r
 \r
@@ -71,54 +85,196 @@ public class UnitFunction {
             for(Resource r : graph.getObjects(expression, SR.Expression_equation)) {\r
                 graph.getValue(r);\r
             }\r
-            \r
+\r
             sm.getMapping().domainModified(expression);\r
             sm.update(graph);\r
-            \r
+\r
             Object expr = sm.getMapping().get(expression);\r
 \r
             if(expr != null && var != null && expr instanceof IExpression && var instanceof IndependentVariable) {\r
                 String result = ((IExpression)expr).validateUnits(graph, sm);\r
                 if(result != null) {\r
-                    Issue issue = new StandardIssue(SR.Validations_UnitWarning, independentVariable, expression, unitResource);\r
+                    Issue issue = new StandardIssue(SR.Validations_UnitWarning, variable, expression, graph.getPossibleObject(variable, SR.Variable_unit));\r
                     issues.add(issue);\r
                 }\r
             }\r
         }\r
+        return issues;\r
+    }\r
+    \r
+    private static List<Issue> moduleValidator(ReadGraph graph, Resource module) throws DatabaseException {\r
+        Layer0 L0 = Layer0.getInstance(graph);\r
+        SysdynResource SR = SysdynResource.getInstance(graph);\r
+\r
+        if(module == null)\r
+            return Collections.emptyList();\r
+\r
+        Resource configuration = graph.getPossibleObject(module, L0.PartOf);\r
+        if(configuration == null)\r
+            return Collections.emptyList();\r
 \r
+        String result = null;\r
+        ArrayList<Issue> issues = new ArrayList<Issue>();\r
+        for(Resource outputRelation : graph.getObjects(module, SR.Variable_isTailOf)) {\r
+            Resource reference = graph.getPossibleObject(outputRelation, SR.Dependency_refersTo);\r
+            if(reference != null) {\r
+                Resource output = graph.getPossibleObject(outputRelation, SR.Variable_HasHead);\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
+                if(result != null)\r
+                    issues.add(new ModuleStandardIssue(SR.Validations_ModuleOutputUnitWarning, module, output, reference));\r
+            }\r
+        }\r
+        for(Resource inputRelation : graph.getObjects(module, SR.Variable_isHeadOf)) {\r
+            Resource reference = graph.getPossibleObject(inputRelation, SR.Dependency_refersTo);\r
+            if(reference != null) {\r
+                Resource variable = graph.getPossibleObject(inputRelation, SR.Variable_HasTail);\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
+                if(result != null)\r
+                    issues.add(new ModuleStandardIssue(SR.Validations_ModuleInputUnitWarning, module, variable, reference));\r
+            }\r
+        }\r
         return issues;\r
     }\r
 \r
+\r
     @SCLValue(type = "ReadGraph -> Resource -> Variable -> String")\r
     public static String unitWarningDescription(ReadGraph graph, Resource converter, Variable property) throws DatabaseException {\r
         List<Resource> contexts = IssueUtils.getContextsForProperty(graph, property);\r
-        \r
+\r
         if(contexts.size() == 0)\r
             return "Error, No contexts";\r
-        \r
+\r
         Resource variable = contexts.get(0);\r
         String unit = graph.getPossibleRelatedValue(variable, SysdynResource.getInstance(graph).Variable_unit);\r
 \r
         if(unit == null || unit.length() == 0)\r
             return "No unit defined";\r
         \r
+        if(contexts.size() < 2)\r
+            return "Error, not enough contexts";\r
+\r
         Layer0 L0 = Layer0.getInstance(graph);\r
         Resource configuration = graph.getPossibleObject(variable, L0.PartOf);\r
         if(configuration == null)\r
             return "Error, No Confiugration";\r
-        \r
+\r
 \r
         SysdynModelManager smm = SysdynModelManager.getInstance(graph.getSession());\r
         SysdynModel sm = smm.getModel(graph, configuration);\r
-        \r
+\r
         SysdynResource SR = SysdynResource.getInstance(graph);\r
         for(Resource r : graph.getObjects(contexts.get(1), SR.Expression_equation)) {\r
             graph.getValue(r);\r
         }\r
-        \r
+\r
         Object expr = sm.getMapping().get(contexts.get(1));\r
         String result = ((IExpression)expr).validateUnits(graph, sm);\r
+        \r
         return result;\r
     }\r
 \r
+    @SCLValue(type = "ReadGraph -> Resource -> Variable -> String")\r
+    public static String moduleOutputUnitWarningDescription(ReadGraph graph, Resource converter, Variable property) throws DatabaseException {\r
+        List<Resource> contexts = IssueUtils.getContextsForProperty(graph, property);\r
+\r
+        if(contexts.size() < 3)\r
+            return "Error, No contexts";\r
+\r
+        Resource output = contexts.get(1);\r
+        Resource reference = contexts.get(2);\r
+\r
+        return moduleInterfaceDescription(graph, output, reference, "Module output has different unit. (", ")");\r
+\r
+    }\r
+    \r
+    @SCLValue(type = "ReadGraph -> Resource -> Variable -> String")\r
+    public static String moduleInputUnitWarningDescription(ReadGraph graph, Resource converter, Variable property) throws DatabaseException {\r
+        List<Resource> contexts = IssueUtils.getContextsForProperty(graph, property);\r
+\r
+        if(contexts.size() < 3)\r
+            return "Error, No contexts";\r
+\r
+        Resource output = contexts.get(1);\r
+        Resource reference = contexts.get(2);\r
+\r
+        return moduleInterfaceDescription(graph, output, reference, "Module input has different unit. (", ")");\r
+\r
+    }\r
+    \r
+    private static String moduleInterfaceDescription(ReadGraph graph, Resource leftResource, Resource rightResource, String prefix, String suffix) throws DatabaseException {\r
+        if(leftResource == null)\r
+            return "Erroneus error: left == null";\r
+        \r
+        if(rightResource == null)\r
+            return "Erroneus error: right == null";\r
+        \r
+        SysdynResource SR = SysdynResource.getInstance(graph);\r
+        \r
+        String left = graph.getPossibleRelatedValue(leftResource, SR.Variable_unit);\r
+        if(left == null || left.isEmpty())\r
+            return "No unit defined for " + NameUtils.getSafeName(graph, leftResource);\r
+        \r
+        String right = graph.getPossibleRelatedValue(rightResource, SR.Variable_unit);\r
+        if(right == null || right.isEmpty())\r
+            return "No unit defined for " + NameUtils.getSafeName(graph, rightResource);\r
+        \r
+        String result = UnitUtils.matchUnits(left, right);\r
+        \r
+        if(result != null)\r
+            result = prefix + result + suffix;\r
+        \r
+        return result;\r
+    }\r
+    \r
+    \r
+    \r
+    \r
+    @SCLValue(type = "ReadGraph -> [Resource] -> [Resource]")\r
+    public static List<Resource> moduleInterfaceExtension(ReadGraph graph, List<Resource> rs) throws DatabaseException {\r
+        SysdynResource SR = SysdynResource.getInstance(graph);\r
+        \r
+        HashSet<Resource> components = new HashSet<Resource>();\r
+        HashSet<Resource> searchedModuleTypes = new HashSet<Resource>();\r
+        for(Resource r : rs) {\r
+            if(!graph.isInstanceOf(r, SR.Variable))\r
+                continue;\r
+            \r
+            if(graph.isInstanceOf(r, SR.Input)) {\r
+                Resource connection = graph.getPossibleObject(r, SR.Variable_isHeadOf);\r
+                if(connection != null)\r
+                    components.add(graph.getPossibleObject(connection, SR.Variable_HasTail));\r
+            }\r
+            \r
+            for(Resource connection :  graph.getObjects(r, SR.Variable_isTailOf)) {\r
+                Resource head = graph.getPossibleObject(connection, SR.Variable_HasHead);\r
+                if(graph.isInstanceOf(head, SR.Module)) {\r
+                    components.add(head);\r
+                }\r
+            }\r
+            \r
+            Layer0 L0 = Layer0.getInstance(graph);\r
+            Resource configuration = graph.getPossibleObject(r, L0.PartOf);\r
+            Resource possibleModule = graph.getPossibleObject(configuration, L0.PartOf);\r
+            if(graph.isInheritedFrom(possibleModule, SR.Module) && !searchedModuleTypes.contains(possibleModule)) {\r
+                searchedModuleTypes.add(possibleModule);\r
+                for(Resource model : graph.syncRequest(new ObjectsWithType(Simantics.getProject().get(), L0.ConsistsOf, SR.SysdynModel))) {\r
+                    Collection<Resource> found = org.simantics.db.indexing.IndexUtils.findByType(graph, model, possibleModule);\r
+                    components.addAll(found);\r
+                }\r
+            }\r
+\r
+        }\r
+        \r
+        if(!components.isEmpty()) {\r
+            rs.addAll(components);\r
+        }\r
+        \r
+        return rs;\r
+        \r
+    }\r
+\r
 }
\ No newline at end of file
index 668c83fe54dfba93546ccf75b4205d33b7fc9bf0..732509d9631a26e99907b3e1c3ae5184702f33b3 100644 (file)
@@ -18,6 +18,7 @@ import java.util.Set;
 \r
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
+import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.db.exception.ManyObjectsForFunctionalRelationException;\r
 import org.simantics.db.exception.ServiceException;\r
 import org.simantics.simulation.ontology.SimulationResource;\r
@@ -175,5 +176,38 @@ public class UnitUtils {
             }\r
         }\r
     }\r
+    \r
+    \r
+    public static String matchUnits(String left, String right) throws DatabaseException {\r
+        if(left == null || right == null || left.isEmpty() || right.isEmpty())\r
+            return "No unit defined";\r
+        \r
+        try {\r
+\r
+            StringReader leftReader = new StringReader(left);\r
+            UnitParser leftParser = new UnitParser(leftReader);\r
+            UnitCheckingNode leftNode = (UnitCheckingNode) leftParser.expr();\r
+            leftReader.close();\r
+\r
+            StringReader rightReader = new StringReader(right);\r
+            UnitParser rightParser = new UnitParser(rightReader);\r
+            UnitCheckingNode rightNode = (UnitCheckingNode) rightParser.expr();\r
+            rightReader.close();\r
+\r
+            try {\r
+                UnitResult leftUnits = leftNode.getUnits(null);\r
+                UnitResult rightUnits = rightNode.getUnits(null);\r
+\r
+                if(!rightUnits.equals(leftUnits))\r
+                    return leftUnits.getCleanFullUnit() + " != " + rightUnits.getCleanFullUnit();\r
+            } catch (UnitCheckingException e) {\r
+                return e.getMessage();\r
+            }\r
+\r
+        } catch (ParseException e) {\r
+            e.printStackTrace();\r
+        }\r
+        return null;\r
+    }\r
 \r
 }\r