]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Merged changes from trunks to stable branch until r24347. This covers sprints 2012...
authorlehtonen <lehtonen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 5 Mar 2012 13:20:56 +0000 (13:20 +0000)
committerlehtonen <lehtonen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 5 Mar 2012 13:20:56 +0000 (13:20 +0000)
and half of 2012-4. For issues closed in sprints 2012-2, 2012-3 and 2012-4, see
https://www.simantics.org/redmine/projects/simantics-platform/versions/162
https://www.simantics.org/redmine/projects/simantics-platform/versions/167
https://www.simantics.org/redmine/projects/simantics-platform/versions/168.

refs #3263

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

68 files changed:
stable/org.simantics.jfreechart.ontology/graph.tg
stable/org.simantics.modelica/src/org/simantics/modelica/ModelicaManager.java
stable/org.simantics.modelica/src/org/simantics/modelica/data/SimulationResult.java
stable/org.simantics.sysdyn.ontology/META-INF/MANIFEST.MF
stable/org.simantics.sysdyn.ontology/graph.tg
stable/org.simantics.sysdyn.ontology/graph/PropertyViewpoints.pgraph [new file with mode: 0644]
stable/org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph
stable/org.simantics.sysdyn.ontology/src/org/simantics/sysdyn/SysdynResource.java
stable/org.simantics.sysdyn.ui/adapters.xml
stable/org.simantics.sysdyn.ui/plugin.xml
stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SimulationResult.java
stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SimulationResultDecorator.java
stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SimulationResultImager.java
stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SimulationResultLabeler.java
stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/HistoryDataNode.java [new file with mode: 0644]
stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/SimulationResultNode.java
stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/SysdynConnectionBuilder.java
stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ShowModuleHandler.java
stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewHistoryDataHandler.java [new file with mode: 0644]
stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/listeners/SysdynPlaybackExperimentListener.java
stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/modelica/SysdynModelicaEditor.java
stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ConfigurationTab.java
stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/HistoryDataTab.java [new file with mode: 0644]
stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/InputVariableTab.java
stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java
stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/FontSelectionComposite.java [new file with mode: 0644]
stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/historyDataset/VariableChildRule.java [new file with mode: 0644]
stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/historyDataset/VariableLabelRule.java [new file with mode: 0644]
stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/structure/Dependencies.java [moved from stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/dependencies/DependencyView.java with 58% similarity]
stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/structure/DependencyGraphRequest.java [moved from stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/dependencies/CreateDependencyGraph.java with 76% similarity]
stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/structure/ModuleStructure.java [new file with mode: 0644]
stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/structure/ModuleStructureGraphRequest.java [new file with mode: 0644]
stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/structure/StructureView.java [new file with mode: 0644]
stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/element/ChartNode.java
stable/org.simantics.sysdyn/META-INF/MANIFEST.MF
stable/org.simantics.sysdyn/src/org/simantics/sysdyn/expressionParser/ExpressionParser.java
stable/org.simantics.sysdyn/src/org/simantics/sysdyn/expressionParser/ExpressionParser.jj
stable/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/HistoryDatasetResult.java [new file with mode: 0644]
stable/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/HistoryDatasetUtils.java [new file with mode: 0644]
stable/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynModel.java
stable/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynResult.java
stable/org.simantics.sysdyn/src/org/simantics/sysdyn/modelica/ModelicaWriter.java
stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Configuration.java
stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Entity.java [new file with mode: 0644]
stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Function.java [new file with mode: 0644]
stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/FunctionLibrary.java [new file with mode: 0644]
stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/IndependentVariable.java
stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Input.java
stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/LibraryDummy.java
stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Model.java
stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Module.java
stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/ModuleType.java
stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/SharedFunctionLibrary.java [new file with mode: 0644]
stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Stock.java
stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/SysdynSchema.java
stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Variability.java [new file with mode: 0644]
stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Variable.java
stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/annotations/BuiltinFunctions.java [new file with mode: 0644]
stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/annotations/BuiltinFunctionsAccessor.java [new file with mode: 0644]
stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/annotations/BuiltinFunctionsFactory.java [new file with mode: 0644]
stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/ConstantExpression.java
stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/DelayExpression.java
stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/Expression.java
stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/IExpression.java
stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/NormalExpression.java
stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/ParameterExpression.java
stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/StockExpression.java
stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/WithLookupExpression.java

index b48384c3c9643f06abc96f041414f02f93920b2f..decb0ada466460226f855b07239dc2a5c4befa43 100644 (file)
Binary files a/stable/org.simantics.jfreechart.ontology/graph.tg and b/stable/org.simantics.jfreechart.ontology/graph.tg differ
index d77b43799fa6270ae274679424110f2eb3122bc3..835f7338048b796f3d7649d5b350aaa17bf610b6 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************\r
- * Copyright (c) 2010 Association for Decentralized Information Management in\r
+ * Copyright (c) 2010, 2012 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
@@ -242,6 +242,9 @@ public class ModelicaManager {
             if(inits.containsKey("numberOfIntervals")) {\r
                 s.print(",numberOfIntervals="+inits.get("numberOfIntervals"));\r
             }\r
+            if(inits.containsKey("variableFilter")) {\r
+                s.print(",variableFilter=\""+inits.get("variableFilter")+"\"");\r
+            }\r
             s.print(");\n");\r
             s.println("getErrorString();");\r
             s.close();\r
index 766d4c2c452aa3797049e74323332ccbbf287298..725d7e71befd5a111ed8dac7901f7aa8a2c8b871 100644 (file)
@@ -48,14 +48,14 @@ import org.xml.sax.SAXException;
  */\r
 public class SimulationResult {    \r
 \r
-    List<DataSet> variables = new ArrayList<DataSet>();\r
-    List<DataSet> initials = new ArrayList<DataSet>();\r
+    protected List<DataSet> variables = new ArrayList<DataSet>();\r
+    protected List<DataSet> initials = new ArrayList<DataSet>();\r
     protected int numberOfTimeSteps = 0;\r
     \r
     /**\r
      * Private class used in displaying errors\r
      */\r
-    class TimeValuePair {\r
+    protected class TimeValuePair {\r
         public String time;\r
         public String value;\r
 \r
@@ -65,7 +65,7 @@ public class SimulationResult {
         }\r
     }\r
 \r
-    HashMap<String, ArrayList<TimeValuePair>> errors = new HashMap<String, ArrayList<TimeValuePair>>();\r
+    protected HashMap<String, ArrayList<TimeValuePair>> errors = new HashMap<String, ArrayList<TimeValuePair>>();\r
 \r
     /**\r
      * Get the next line in the plt-file\r
index 86466a568f8a405cf30aa260a3543d27acabeb16..f4ca250c91862d1910de091a8e3fcffd60d8d866 100644 (file)
@@ -17,7 +17,8 @@ Require-Bundle: org.simantics.layer0,
  org.simantics.image2.ontology;bundle-version="1.1.0",
  org.simantics.color.ontology;bundle-version="1.0.0",
  org.simantics.simulation.ontology;bundle-version="1.0.0",
- org.simantics.silk.ontology;bundle-version="1.0.0"
+ org.simantics.silk.ontology;bundle-version="1.0.0",
+ org.simantics.spreadsheet.ontology;bundle-version="1.1.0"
 Bundle-RequiredExecutionEnvironment: JavaSE-1.6
 Export-Package: org.simantics.sysdyn
 Bundle-Vendor: VTT Technical Reserarch Centre of Finland
index 00e94b3e08537ccf8f26e55854882020759cd994..d1dcc33a4b740c5a8113585809344d74e411f1d5 100644 (file)
Binary files a/stable/org.simantics.sysdyn.ontology/graph.tg and b/stable/org.simantics.sysdyn.ontology/graph.tg differ
diff --git a/stable/org.simantics.sysdyn.ontology/graph/PropertyViewpoints.pgraph b/stable/org.simantics.sysdyn.ontology/graph/PropertyViewpoints.pgraph
new file mode 100644 (file)
index 0000000..3d93928
--- /dev/null
@@ -0,0 +1,24 @@
+L0 = <http://www.simantics.org/Layer0-1.0>\r
+VP = <http://www.simantics.org/Viewpoint-1.1>\r
+SYSDYN = <http://www.simantics.org/Sysdyn-1.1>\r
+\r
+HDBC = SYSDYN.HistoryDataset.HistoryDatasetVariablesBrowseContext : VP.BrowseContext\r
+\r
+HDBC.StringNodeType <T VP.NodeType\r
+    @L0.assert VP.HasContentType "java.lang.String"\r
+\r
+HDBC.VariableChildRule : VP.ChildRule\r
+HDBC.VariableLabelRule : VP.LabelRule\r
+\r
+HDBC\r
+    @VP.customChildRule SYSDYN.HistoryDataset HDBC.VariableChildRule\r
+        SYSDYN.HistoryDataset.FoundVariableNameNode : HDBC.StringNodeType\r
+\r
+HDBC        \r
+    @VP.customLabelRule SYSDYN.HistoryDataset.FoundVariableNameNode HDBC.VariableLabelRule\r
+    \r
+HDBC    \r
+    VP.BrowseContext.HasVisualsContribution _ : VP.VisualsContribution\r
+        VP.VisualsContribution.HasNodeType SYSDYN.HistoryDataset\r
+        VP.VisualsContribution.HasRule VP.PassThruSorterRule\r
+    \r
index 803aea0515d36b7d9a40722c546020235ccd243f..0e46d521d847a1669406942a2518435341efe65d 100644 (file)
@@ -7,6 +7,7 @@ SIMU = <http://www.simantics.org/Simulation-1.0>
 MOD = <http://www.simantics.org/Modeling-1.1>
 PROJ = <http://www.simantics.org/Project-1.1>
 JFREE = <http://www.simantics.org/JFreeChart-1.0>
+SHEET = <http://www.simantics.org/Spreadsheet-1.1>
  
 //#####################################################################
 // Defines ontology and attaches it to SimanticsDomain
@@ -35,6 +36,7 @@ SYSDYN.SysdynModel <T MOD.StructuralModel
     >-- SYSDYN.SysdynModel.outputInterval --> L0.Double <R L0.HasProperty : L0.FunctionalRelation
     >-- SYSDYN.SysdynModel.tolerance --> L0.Double <R L0.HasProperty : L0.FunctionalRelation
     >-- SYSDYN.SysdynModel.solver --> L0.String <R L0.HasProperty : L0.FunctionalRelation
+    >-- SYSDYN.SysdynModel.variableFilter --> L0.String <R L0.HasProperty : L0.FunctionalRelation
     @L0.assert SYSDYN.SysdynModel.startTime 0.0
     @L0.assert SYSDYN.SysdynModel.stopTime 10.0
     @L0.assert SYSDYN.SysdynModel.solver "euler"
@@ -79,6 +81,7 @@ SYSDYN.Variable <T STR.Component
     >-- SYSDYN.Variable.expressions --> SYSDYN.Expressions <R L0.DependsOn : L0.FunctionalRelation
     >-- SYSDYN.Variable.arrayIndexes --> SYSDYN.ArrayIndexes <R L0.DependsOn : L0.FunctionalRelation
     >-- SYSDYN.Variable.unit --> L0.String <R L0.HasProperty : L0.FunctionalRelation
+    >-- SYSDYN.Variable.variability --> L0.String <R L0.HasProperty : L0.FunctionalRelation
     >-- SYSDYN.Variable.isTailOf --> STR.Connection <R STR.IsConnectedTo
         L0.InverseOf SYSDYN.HasTail 
         STR.AllowsConnectionType SYSDYN.SysdynConnectionType
@@ -265,7 +268,7 @@ SYSDYN.SimulateOnChangeExperiment <T SYSDYN.Experiment
 SYSDYN.PlaybackExperiment <T SYSDYN.Experiment
 
 //#####################################################################
-// Results
+// Results and history datasets
 //#####################################################################
 
 SYSDYN.Result <T L0.Entity
@@ -274,6 +277,16 @@ SYSDYN.Result <T L0.Entity
     >-- SYSDYN.Result.resultFile --> L0.String <R L0.HasProperty
     >-- SYSDYN.Result.showResult --> SYSDYN.Result <R L0.IsRelatedTo : L0.Tag
         @L0.symmetric
+        
+SYSDYN.HistoryDataset <T SYSDYN.Result
+    @L0.singleProperty L0.HasName
+    @L0.singleProperty L0.HasLabel
+    >-- SYSDYN.HistoryDataset.start --> L0.String <R L0.HasProperty     // Start of the history data table (e.g. B3)
+    >-- SYSDYN.HistoryDataset.end --> L0.String <R L0.HasProperty       // End of the history data table (e.g. D56)
+    >-- SYSDYN.HistoryDataset.timeName --> L0.String <R L0.HasProperty  // Name of the time variable. Will be saved as "time"
+    >-- SYSDYN.HistoryDataset.columns --> L0.Boolean <R L0.HasProperty  // Is the data in columns. If false, data is in rows
+    >-- SYSDYN.HistoryDataset.sheet --> SHEET.Spreadsheet <R L0.IsRelatedTo : L0.FunctionalRelation
+    
 
 //#####################################################################
 //#####################################################################
index ea85ab298707a01cf32d9507508c5bb5a0dbf98b..7a12eda3d8c79b7d397688f335f02abb2d0495f4 100644 (file)
@@ -135,6 +135,21 @@ public class SysdynResource {
     public final Resource HasTailTerminal;\r
     public final Resource HasUnit;\r
     public final Resource HasUnit_Inverse;\r
+    public final Resource HistoryDataset;\r
+    public final Resource HistoryDataset_FoundVariableNameNode;\r
+    public final Resource HistoryDataset_HistoryDatasetVariablesBrowseContext;\r
+    public final Resource HistoryDataset_HistoryDatasetVariablesBrowseContext_StringNodeType;\r
+    public final Resource HistoryDataset_HistoryDatasetVariablesBrowseContext_VariableChildRule;\r
+    public final Resource HistoryDataset_HistoryDatasetVariablesBrowseContext_VariableLabelRule;\r
+    public final Resource HistoryDataset_columns;\r
+    public final Resource HistoryDataset_columns_Inverse;\r
+    public final Resource HistoryDataset_end;\r
+    public final Resource HistoryDataset_end_Inverse;\r
+    public final Resource HistoryDataset_sheet;\r
+    public final Resource HistoryDataset_start;\r
+    public final Resource HistoryDataset_start_Inverse;\r
+    public final Resource HistoryDataset_timeName;\r
+    public final Resource HistoryDataset_timeName_Inverse;\r
     public final Resource HistoryRealization;\r
     public final Resource Horizontal;\r
     public final Resource ImportModuleTree;\r
@@ -241,6 +256,8 @@ public class SysdynResource {
     public final Resource SysdynModel_stopTime_Inverse;\r
     public final Resource SysdynModel_tolerance;\r
     public final Resource SysdynModel_tolerance_Inverse;\r
+    public final Resource SysdynModel_variableFilter;\r
+    public final Resource SysdynModel_variableFilter_Inverse;\r
     public final Resource SysdynModelicaFunction;\r
     public final Resource SysdynModelicaFunctionLibrary;\r
     public final Resource SysdynModelicaFunction_modelicaFunctionCode;\r
@@ -294,6 +311,8 @@ public class SysdynResource {
     public final Resource Variable_type_Inverse;\r
     public final Resource Variable_unit;\r
     public final Resource Variable_unit_Inverse;\r
+    public final Resource Variable_variability;\r
+    public final Resource Variable_variability_Inverse;\r
     public final Resource Vertical;\r
     public final Resource WithLookupExpression;\r
     public final Resource WithLookupExpression_expression;\r
@@ -432,6 +451,21 @@ public class SysdynResource {
         public static final String HasTailTerminal = "http://www.simantics.org/Sysdyn-1.1/HasTailTerminal";\r
         public static final String HasUnit = "http://www.simantics.org/Sysdyn-1.1/HasUnit";\r
         public static final String HasUnit_Inverse = "http://www.simantics.org/Sysdyn-1.1/HasUnit/Inverse";\r
+        public static final String HistoryDataset = "http://www.simantics.org/Sysdyn-1.1/HistoryDataset";\r
+        public static final String HistoryDataset_FoundVariableNameNode = "http://www.simantics.org/Sysdyn-1.1/HistoryDataset/FoundVariableNameNode";\r
+        public static final String HistoryDataset_HistoryDatasetVariablesBrowseContext = "http://www.simantics.org/Sysdyn-1.1/HistoryDataset/HistoryDatasetVariablesBrowseContext";\r
+        public static final String HistoryDataset_HistoryDatasetVariablesBrowseContext_StringNodeType = "http://www.simantics.org/Sysdyn-1.1/HistoryDataset/HistoryDatasetVariablesBrowseContext/StringNodeType";\r
+        public static final String HistoryDataset_HistoryDatasetVariablesBrowseContext_VariableChildRule = "http://www.simantics.org/Sysdyn-1.1/HistoryDataset/HistoryDatasetVariablesBrowseContext/VariableChildRule";\r
+        public static final String HistoryDataset_HistoryDatasetVariablesBrowseContext_VariableLabelRule = "http://www.simantics.org/Sysdyn-1.1/HistoryDataset/HistoryDatasetVariablesBrowseContext/VariableLabelRule";\r
+        public static final String HistoryDataset_columns = "http://www.simantics.org/Sysdyn-1.1/HistoryDataset/columns";\r
+        public static final String HistoryDataset_columns_Inverse = "http://www.simantics.org/Sysdyn-1.1/HistoryDataset/columns/Inverse";\r
+        public static final String HistoryDataset_end = "http://www.simantics.org/Sysdyn-1.1/HistoryDataset/end";\r
+        public static final String HistoryDataset_end_Inverse = "http://www.simantics.org/Sysdyn-1.1/HistoryDataset/end/Inverse";\r
+        public static final String HistoryDataset_sheet = "http://www.simantics.org/Sysdyn-1.1/HistoryDataset/sheet";\r
+        public static final String HistoryDataset_start = "http://www.simantics.org/Sysdyn-1.1/HistoryDataset/start";\r
+        public static final String HistoryDataset_start_Inverse = "http://www.simantics.org/Sysdyn-1.1/HistoryDataset/start/Inverse";\r
+        public static final String HistoryDataset_timeName = "http://www.simantics.org/Sysdyn-1.1/HistoryDataset/timeName";\r
+        public static final String HistoryDataset_timeName_Inverse = "http://www.simantics.org/Sysdyn-1.1/HistoryDataset/timeName/Inverse";\r
         public static final String HistoryRealization = "http://www.simantics.org/Sysdyn-1.1/HistoryRealization";\r
         public static final String Horizontal = "http://www.simantics.org/Sysdyn-1.1/Horizontal";\r
         public static final String ImportModuleTree = "http://www.simantics.org/Sysdyn-1.1/ImportModuleTree";\r
@@ -538,6 +572,8 @@ public class SysdynResource {
         public static final String SysdynModel_stopTime_Inverse = "http://www.simantics.org/Sysdyn-1.1/SysdynModel/stopTime/Inverse";\r
         public static final String SysdynModel_tolerance = "http://www.simantics.org/Sysdyn-1.1/SysdynModel/tolerance";\r
         public static final String SysdynModel_tolerance_Inverse = "http://www.simantics.org/Sysdyn-1.1/SysdynModel/tolerance/Inverse";\r
+        public static final String SysdynModel_variableFilter = "http://www.simantics.org/Sysdyn-1.1/SysdynModel/variableFilter";\r
+        public static final String SysdynModel_variableFilter_Inverse = "http://www.simantics.org/Sysdyn-1.1/SysdynModel/variableFilter/Inverse";\r
         public static final String SysdynModelicaFunction = "http://www.simantics.org/Sysdyn-1.1/SysdynModelicaFunction";\r
         public static final String SysdynModelicaFunctionLibrary = "http://www.simantics.org/Sysdyn-1.1/SysdynModelicaFunctionLibrary";\r
         public static final String SysdynModelicaFunction_modelicaFunctionCode = "http://www.simantics.org/Sysdyn-1.1/SysdynModelicaFunction/modelicaFunctionCode";\r
@@ -591,6 +627,8 @@ public class SysdynResource {
         public static final String Variable_type_Inverse = "http://www.simantics.org/Sysdyn-1.1/Variable/type/Inverse";\r
         public static final String Variable_unit = "http://www.simantics.org/Sysdyn-1.1/Variable/unit";\r
         public static final String Variable_unit_Inverse = "http://www.simantics.org/Sysdyn-1.1/Variable/unit/Inverse";\r
+        public static final String Variable_variability = "http://www.simantics.org/Sysdyn-1.1/Variable/variability";\r
+        public static final String Variable_variability_Inverse = "http://www.simantics.org/Sysdyn-1.1/Variable/variability/Inverse";\r
         public static final String Vertical = "http://www.simantics.org/Sysdyn-1.1/Vertical";\r
         public static final String WithLookupExpression = "http://www.simantics.org/Sysdyn-1.1/WithLookupExpression";\r
         public static final String WithLookupExpression_expression = "http://www.simantics.org/Sysdyn-1.1/WithLookupExpression/expression";\r
@@ -739,6 +777,21 @@ public class SysdynResource {
         HasTailTerminal = getResourceOrNull(graph, URIs.HasTailTerminal);\r
         HasUnit = getResourceOrNull(graph, URIs.HasUnit);\r
         HasUnit_Inverse = getResourceOrNull(graph, URIs.HasUnit_Inverse);\r
+        HistoryDataset = getResourceOrNull(graph, URIs.HistoryDataset);\r
+        HistoryDataset_FoundVariableNameNode = getResourceOrNull(graph, URIs.HistoryDataset_FoundVariableNameNode);\r
+        HistoryDataset_HistoryDatasetVariablesBrowseContext = getResourceOrNull(graph, URIs.HistoryDataset_HistoryDatasetVariablesBrowseContext);\r
+        HistoryDataset_HistoryDatasetVariablesBrowseContext_StringNodeType = getResourceOrNull(graph, URIs.HistoryDataset_HistoryDatasetVariablesBrowseContext_StringNodeType);\r
+        HistoryDataset_HistoryDatasetVariablesBrowseContext_VariableChildRule = getResourceOrNull(graph, URIs.HistoryDataset_HistoryDatasetVariablesBrowseContext_VariableChildRule);\r
+        HistoryDataset_HistoryDatasetVariablesBrowseContext_VariableLabelRule = getResourceOrNull(graph, URIs.HistoryDataset_HistoryDatasetVariablesBrowseContext_VariableLabelRule);\r
+        HistoryDataset_columns = getResourceOrNull(graph, URIs.HistoryDataset_columns);\r
+        HistoryDataset_columns_Inverse = getResourceOrNull(graph, URIs.HistoryDataset_columns_Inverse);\r
+        HistoryDataset_end = getResourceOrNull(graph, URIs.HistoryDataset_end);\r
+        HistoryDataset_end_Inverse = getResourceOrNull(graph, URIs.HistoryDataset_end_Inverse);\r
+        HistoryDataset_sheet = getResourceOrNull(graph, URIs.HistoryDataset_sheet);\r
+        HistoryDataset_start = getResourceOrNull(graph, URIs.HistoryDataset_start);\r
+        HistoryDataset_start_Inverse = getResourceOrNull(graph, URIs.HistoryDataset_start_Inverse);\r
+        HistoryDataset_timeName = getResourceOrNull(graph, URIs.HistoryDataset_timeName);\r
+        HistoryDataset_timeName_Inverse = getResourceOrNull(graph, URIs.HistoryDataset_timeName_Inverse);\r
         HistoryRealization = getResourceOrNull(graph, URIs.HistoryRealization);\r
         Horizontal = getResourceOrNull(graph, URIs.Horizontal);\r
         ImportModuleTree = getResourceOrNull(graph, URIs.ImportModuleTree);\r
@@ -845,6 +898,8 @@ public class SysdynResource {
         SysdynModel_stopTime_Inverse = getResourceOrNull(graph, URIs.SysdynModel_stopTime_Inverse);\r
         SysdynModel_tolerance = getResourceOrNull(graph, URIs.SysdynModel_tolerance);\r
         SysdynModel_tolerance_Inverse = getResourceOrNull(graph, URIs.SysdynModel_tolerance_Inverse);\r
+        SysdynModel_variableFilter = getResourceOrNull(graph, URIs.SysdynModel_variableFilter);\r
+        SysdynModel_variableFilter_Inverse = getResourceOrNull(graph, URIs.SysdynModel_variableFilter_Inverse);\r
         SysdynModelicaFunction = getResourceOrNull(graph, URIs.SysdynModelicaFunction);\r
         SysdynModelicaFunctionLibrary = getResourceOrNull(graph, URIs.SysdynModelicaFunctionLibrary);\r
         SysdynModelicaFunction_modelicaFunctionCode = getResourceOrNull(graph, URIs.SysdynModelicaFunction_modelicaFunctionCode);\r
@@ -898,6 +953,8 @@ public class SysdynResource {
         Variable_type_Inverse = getResourceOrNull(graph, URIs.Variable_type_Inverse);\r
         Variable_unit = getResourceOrNull(graph, URIs.Variable_unit);\r
         Variable_unit_Inverse = getResourceOrNull(graph, URIs.Variable_unit_Inverse);\r
+        Variable_variability = getResourceOrNull(graph, URIs.Variable_variability);\r
+        Variable_variability_Inverse = getResourceOrNull(graph, URIs.Variable_variability_Inverse);\r
         Vertical = getResourceOrNull(graph, URIs.Vertical);\r
         WithLookupExpression = getResourceOrNull(graph, URIs.WithLookupExpression);\r
         WithLookupExpression_expression = getResourceOrNull(graph, URIs.WithLookupExpression_expression);\r
index ac87af2b877466788022a575b488502b11a15265..6c3dcbee8620e51aa853ba8b5dadd67a8b9baaac 100644 (file)
@@ -10,5 +10,5 @@
         VTT Technical Research Centre of Finland - initial API and implementation\r
  -->\r
 
-<adapters>\r\r   <target interface="org.simantics.db.layer0.adapter.Realization">\r               <type uri="http://www.simantics.org/Sysdyn-0.0/Module"\r                 class="org.simantics.structural2.realization.StructuralRealization">\r                   <this />\r               </type>\r        </target>\r\r     <target interface="org.simantics.layer0.utils.triggers.ITrigger">\r      <type uri = "http://www.simantics.org/Sysdyn-0.0/DiagramToCompositeMapping"\r          class = "org.simantics.sysdyn.ui.editor.DiagramToCompositeMapping3">\r         <graph/>\r           <this />\r       </type>\r        </target>\r      \r       <target interface="org.simantics.structural.ui.modelBrowser.nodes.AbstractNode">\r               <type uri="http://www.simantics.org/Sysdyn-0.0/SysdynModel"\r                    class="org.simantics.structural.ui.modelBrowser.nodes.ModelNode">\r                      <this />\r               </type>\r        </target>               \r               \r\r      <target\r                interface="org.simantics.browsing.ui.common.node.AbstractNode">\r                <type\r                  uri="http://www.simantics.org/Sysdyn-0.0/SysdynModel"\r                  class="org.simantics.sysdyn.ui.browser.nodes.ModelNode">\r                       <this />\r               </type>\r\r               <resource\r                      uri="http://www.simantics.org/Sysdyn-0.0/ModuleSymbol"\r                 class="org.simantics.sysdyn.ui.browser.nodes.SymbolNode">\r                      <this />\r               </resource>\r\r           <type\r                  uri="http://www.simantics.org/Simulation-1.0/Experiment"\r                       class="org.simantics.sysdyn.ui.browser.nodes.ExperimentNode">\r                  <this />\r               </type>\r                \r               <type\r                  uri="http://www.simantics.org/Sysdyn-0.0/Result"\r                       class="org.simantics.sysdyn.ui.browser.nodes.SimulationResultNode">\r                    <this />\r               </type>\r                \r       </target>\r\r     <!-- Inject default connection routing algorithm for sysdyn diagrams -->\r       <target interface="org.simantics.g2d.diagram.DiagramClass">\r            <adapter uri="http://www.simantics.org/Sysdyn-0.0/ConfigurationDiagram"\r                        adapterClass="org.simantics.sysdyn.ui.elements2.ConfigurationDiagramClassAdapter" />\r   </target>\r\r     <!-- Sysdyn symbols -->\r        <target interface="org.simantics.diagram.adapter.ElementFactory">\r              <resource uri="http://www.simantics.org/Sysdyn-0.0/StockSymbol"\r                        class="org.simantics.sysdyn.ui.elements2.StockFactory" />\r              <resource uri="http://www.simantics.org/Sysdyn-0.0/ModuleSymbol"\r                       class="org.simantics.sysdyn.ui.elements2.ModuleFactory" />\r             <resource uri="http://www.simantics.org/Sysdyn-0.0/ValveSymbol"\r                        class="org.simantics.sysdyn.ui.elements2.ValveFactory" />\r              <resource uri="http://www.simantics.org/Sysdyn-0.0/AuxiliarySymbol"\r                    class="org.simantics.sysdyn.ui.elements2.AuxiliaryFactory" />\r          <resource uri="http://www.simantics.org/Sysdyn-0.0/CloudSymbol"\r                        class="org.simantics.sysdyn.ui.elements2.CloudFactory" />\r              <resource uri="http://www.simantics.org/Sysdyn-0.0/InputSymbol"\r                        class="org.simantics.sysdyn.ui.elements2.InputFactory" />\r\r             <type uri="http://www.simantics.org/Sysdyn-0.0/StockSymbol"\r                    class="org.simantics.sysdyn.ui.elements2.StockFactory" />\r              <type uri="http://www.simantics.org/Sysdyn-0.0/ModuleSymbol"\r                   class="org.simantics.sysdyn.ui.elements2.ModuleFactory" />\r             <type uri="http://www.simantics.org/Sysdyn-0.0/ValveSymbol"\r                    class="org.simantics.sysdyn.ui.elements2.ValveFactory" />\r              <type uri="http://www.simantics.org/Sysdyn-0.0/AuxiliarySymbol"\r                        class="org.simantics.sysdyn.ui.elements2.AuxiliaryFactory" />\r          <type uri="http://www.simantics.org/Sysdyn-0.0/CloudSymbol"\r                    class="org.simantics.sysdyn.ui.elements2.CloudFactory" />\r              <type uri="http://www.simantics.org/Sysdyn-0.0/InputSymbol"\r                    class="org.simantics.sysdyn.ui.elements2.InputFactory" />                       \r       </target>\r      \r       <!-- Sysdyn connections -->\r    <target interface="org.simantics.diagram.adapter.ElementFactory">\r              <!-- Edges -->       \r        <resource uri="http://www.simantics.org/Sysdyn-0.0/FlowConnection"\r            class="org.simantics.sysdyn.ui.elements2.connections.RouteFlowEdgeFactory" />\r        <type uri="http://www.simantics.org/Sysdyn-0.0/FlowConnection"\r            class="org.simantics.sysdyn.ui.elements2.connections.RouteFlowEdgeFactory" />            \r        <type uri="http://www.simantics.org/Sysdyn-0.0/FlowConnection"\r            class="org.simantics.sysdyn.ui.elements2.connections.RouteFlowConnectionFactory">\r            <graph/>\r        </type>                       \r                       \r               <resource uri="http://www.simantics.org/Sysdyn-0.0/DependencyConnection"\r                       class="org.simantics.sysdyn.ui.elements2.connections.DependencyEdgeFactory" />\r         <type uri="http://www.simantics.org/Sysdyn-0.0/DependencyConnection"\r                   class="org.simantics.sysdyn.ui.elements2.connections.DependencyEdgeFactory" />\r         <type uri="http://www.simantics.org/Sysdyn-0.0/DependencyConnection"\r                   class="org.simantics.sysdyn.ui.elements2.connections.DependencyConnectionFactory" />\r   </target>\r      \r       <target interface="org.simantics.g2d.connection.EdgeVisualsConfigurer">\r          <baseType uri="http://www.simantics.org/Diagram-0.0/HasConnector" />\r   <resource uri="http://www.simantics.org/Diagram-0.0/HasPlainConnector"\r          class="org.simantics.diagram.content.ArrowConfigurer">\r         <string>none 0</string>\r       </resource>\r    <resource uri="http://www.simantics.org/Diagram-0.0/HasArrowConnector"\r          class="org.simantics.diagram.content.ArrowConfigurer">\r         <string>fill 1</string>\r       </resource>\r  </target>\r      \r       <!-- ModelBrowser2 -->\r \r       <target interface="org.simantics.browsing.ui.model.children.ChildRule">\r        <resource uri="http://www.simantics.org/Sysdyn-0.0/ProjectBrowseContext/ModuleTypeChildRule"\r            class="org.simantics.sysdyn.ui.browser.childrules.ModuleTypeChildRule"/>\r        <resource uri="http://www.simantics.org/Sysdyn-0.0/ProjectBrowseContext/ModuleContentChildRule"\r            class="org.simantics.sysdyn.ui.browser.childrules.ModuleContentChildRule"/>     \r        <resource uri="http://www.simantics.org/Sysdyn-0.0/ChartAxisAndVariablesBrowseContext/AxisChildRule"\r            class="org.simantics.sysdyn.ui.trend.chart.graphexplorer.AxisChildRule"/>     \r        <resource uri="http://www.simantics.org/Sysdyn-0.0/ChartAxisAndVariablesBrowseContext/VariableChildRule"\r            class="org.simantics.sysdyn.ui.trend.chart.graphexplorer.VariableChildRule"/>  \r        <resource uri="http://www.simantics.org/Sysdyn-0.0/BarSeriesBrowseContext/SeriesChildRule"\r            class="org.simantics.sysdyn.ui.trend.chart.graphexplorer.SeriesChildRule"/>           \r        <resource uri="http://www.simantics.org/Sysdyn-0.0/PieSeriesBrowseContext/SeriesChildRule"\r            class="org.simantics.sysdyn.ui.trend.chart.graphexplorer.SeriesChildRule"/>                          \r    </target>\r    \r    <target interface="org.simantics.browsing.ui.model.visuals.VisualsRule">\r        <resource uri="http://www.simantics.org/Sysdyn-0.0/ProjectBrowseContext/ModuleTypeLabelRule"\r            class="org.simantics.sysdyn.ui.browser.labelrules.ModuleTypeLabelRule"/>\r        <resource uri="http://www.simantics.org/Sysdyn-0.0/ChartAxisAndVariablesBrowseContext/SeriesLabelRule"\r            class="org.simantics.sysdyn.ui.trend.chart.graphexplorer.SeriesLabelRule"/>         \r        <resource uri="http://www.simantics.org/Sysdyn-0.0/ChartAxisAndVariablesBrowseContext/AxisLabelRule"\r            class="org.simantics.sysdyn.ui.trend.chart.graphexplorer.AxisLabelRule"/> \r        <resource uri="http://www.simantics.org/Sysdyn-0.0/BarSeriesBrowseContext/SeriesLabelRule"\r            class="org.simantics.sysdyn.ui.trend.chart.graphexplorer.SeriesLabelRule"/>         \r        <resource uri="http://www.simantics.org/Sysdyn-0.0/PieSeriesBrowseContext/SeriesLabelRule"\r            class="org.simantics.sysdyn.ui.trend.chart.graphexplorer.SeriesLabelRule"/>       \r                     \r        <resource uri="http://www.simantics.org/Sysdyn-0.0/ChartAxisAndVariablesBrowseContext/SeriesLabelDecorationRule"\r            class="org.simantics.sysdyn.ui.trend.chart.graphexplorer.SeriesLabelDecorationRule"/>   \r        <resource uri="http://www.simantics.org/Sysdyn-0.0/BarSeriesBrowseContext/SeriesLabelDecorationRule"\r            class="org.simantics.sysdyn.ui.trend.chart.graphexplorer.SeriesLabelDecorationRule"/>         \r        <resource uri="http://www.simantics.org/Sysdyn-0.0/PieSeriesBrowseContext/SeriesLabelDecorationRule"\r            class="org.simantics.sysdyn.ui.trend.chart.graphexplorer.SeriesLabelDecorationRule"/>       \r                                               \r    </target>    \r    \r    <target interface="org.simantics.db.layer0.adapter.ActionFactory">\r        <resource uri="http://www.simantics.org/Sysdyn-0.0/ProjectActionContext/Actions/NewModuleType"\r            class="org.simantics.sysdyn.ui.browser.actions.NewModuleTypeAction" />\r        <resource uri="http://www.simantics.org/Sysdyn-0.0/ProjectActionContext/Actions/NewEnumeration"\r            class="org.simantics.sysdyn.ui.browser.actions.NewEnumerationAction" />\r        <resource uri="http://www.simantics.org/Sysdyn-0.0/ProjectActionContext/Actions/OpenWorkbook"\r            class="org.simantics.sysdyn.ui.browser.actions.OpenWorkbookAction" />\r        <resource uri="http://www.simantics.org/Sysdyn-0.0/ProjectActionContext/Actions/NewFunction"\r            class="org.simantics.sysdyn.ui.browser.actions.NewFunctionAction" />\r        <resource uri="http://www.simantics.org/Sysdyn-0.0/ProjectActionContext/Actions/NewFunctionLibrary"\r            class="org.simantics.sysdyn.ui.browser.actions.NewFunctionLibraryAction" />\r        <resource uri="http://www.simantics.org/Sysdyn-0.0/ProjectActionContext/Actions/NewSharedFunctionLibrary"\r            class="org.simantics.sysdyn.ui.browser.actions.NewSharedFunctionLibraryAction" />            \r    </target>         \r    \r   <target interface="org.simantics.db.layer0.adapter.DropActionFactory">\r        <resource\r            uri="http://www.simantics.org/Sysdyn-0.0/ChartAxisAndVariablesActionContext/Actions/SeriesDropAction"\r            class="org.simantics.sysdyn.ui.trend.chart.graphexplorer.SeriesDropAction" />\r        <resource\r            uri="http://www.simantics.org/Sysdyn-0.0/ChartAxisAndVariablesActionContext/Actions/AxisDropAction"\r            class="org.simantics.sysdyn.ui.trend.chart.graphexplorer.AxisDropAction" />            \r            \r        <resource\r            uri="http://www.simantics.org/Sysdyn-0.0/BarSeriesActionContext/Actions/SeriesDropAction"\r            class="org.simantics.sysdyn.ui.trend.chart.graphexplorer.SeriesDropAction" />\r        <resource\r            uri="http://www.simantics.org/Sysdyn-0.0/PieSeriesActionContext/Actions/SeriesDropAction"\r            class="org.simantics.sysdyn.ui.trend.chart.graphexplorer.SeriesDropAction" />                        \r    </target>     \r  \r  <!-- PROFILES -->\r    <target interface="org.simantics.scenegraph.profile.Style">\r        <resource uri="http://www.simantics.org/Sysdyn-0.0/SimulationPlaybackStyle"\r            class="org.simantics.sysdyn.ui.elements2.profiles.SimulationPlaybackStyle">\r        </resource>\r                <resource uri="http://www.simantics.org/Sysdyn-0.0/IssueStyle"\r            class="org.simantics.sysdyn.ui.elements2.profiles.IssueDecorationStyle">\r        </resource>\r    </target>\r    \r  <!-- Charts -->\r    <target interface="org.simantics.diagram.adapter.ElementFactory">\r        <resource uri="http://www.simantics.org/JFreeChart-1.0/ChartElement"\r            class="org.simantics.sysdyn.ui.trend.chart.element.ChartElementFactory" />\r            \r        <type uri="http://www.simantics.org/JFreeChart-1.0/ChartElement"\r            class="org.simantics.sysdyn.ui.trend.chart.element.ChartElementFactory" />\r    </target>\r                \r    <target interface="org.simantics.diagram.synchronization.graph.ElementWriter">\r        <resource uri="http://www.simantics.org/JFreeChart-1.0/ChartElement"\r            class="org.simantics.sysdyn.ui.trend.chart.element.ChartElementWriter" />\r    </target>\r                    \r    <target interface="org.simantics.sysdyn.ui.trend.chart.IJFreeChart">\r        <type uri="http://www.simantics.org/JFreeChart-1.0/Chart"\r            class="org.simantics.sysdyn.ui.trend.chart.JFreeChart">\r            <graph />\r            <this />\r        </type>\r    </target>  \r    \r    <target interface="org.simantics.sysdyn.ui.trend.chart.IDataset">\r        <type uri="http://www.simantics.org/JFreeChart-1.0/XYDataset"\r            class="org.simantics.sysdyn.ui.trend.chart.XYDataset">\r            <graph />\r            <this />\r        </type>\r        <type uri="http://www.simantics.org/JFreeChart-1.0/CategoryDataset"\r            class="org.simantics.sysdyn.ui.trend.chart.CategoryDataset">\r            <graph />\r            <this />\r        </type>        \r        <type uri="http://www.simantics.org/JFreeChart-1.0/PieDataset"\r            class="org.simantics.sysdyn.ui.trend.chart.PieDataset">\r            <graph />\r            <this />\r        </type>          \r    </target>\r    \r     <target interface="org.simantics.sysdyn.ui.trend.chart.ITitle">\r        <type uri="http://www.simantics.org/JFreeChart-1.0/TextTitle"\r            class="org.simantics.sysdyn.ui.trend.chart.TextTitle">\r            <graph />\r            <this />\r        </type>\r    </target>\r    \r    <target interface="org.simantics.sysdyn.ui.trend.chart.IAxis">\r        <type uri="http://www.simantics.org/JFreeChart-1.0/NumberAxis"\r            class="org.simantics.sysdyn.ui.trend.chart.NumberAxis">\r            <graph />\r            <this />\r        </type>\r        <type uri="http://www.simantics.org/JFreeChart-1.0/CategoryAxis"\r            class="org.simantics.sysdyn.ui.trend.chart.CategoryAxis">\r            <graph />\r            <this />\r        </type>        \r    </target>\r       \r    <target interface="org.simantics.sysdyn.ui.trend.chart.IPlot">\r        <type uri="http://www.simantics.org/JFreeChart-1.0/XYPlot"\r            class="org.simantics.sysdyn.ui.trend.chart.XYPlot">\r            <graph />\r            <this />\r        </type>\r        <type uri="http://www.simantics.org/JFreeChart-1.0/CategoryPlot"\r            class="org.simantics.sysdyn.ui.trend.chart.CategoryPlot">\r            <graph />\r            <this />\r        </type>      \r        <type uri="http://www.simantics.org/JFreeChart-1.0/PiePlot"\r            class="org.simantics.sysdyn.ui.trend.chart.PiePlot">\r            <graph />\r            <this />\r        </type>               \r    </target>\r    \r     <target interface="org.simantics.sysdyn.ui.trend.chart.IRenderer">\r     \r        <type uri="http://www.simantics.org/JFreeChart-1.0/XYLineRenderer"\r            class="org.simantics.sysdyn.ui.trend.chart.XYLineRenderer">\r            <graph />\r            <this />\r        </type>  \r        <type uri="http://www.simantics.org/JFreeChart-1.0/XYAreaRenderer"\r            class="org.simantics.sysdyn.ui.trend.chart.XYAreaRenderer">\r            <graph />\r            <this />\r        </type>        \r                \r        <type uri="http://www.simantics.org/JFreeChart-1.0/BarRenderer"\r            class="org.simantics.sysdyn.ui.trend.chart.BarRenderer">\r            <graph />\r            <this />\r        </type>\r        <type uri="http://www.simantics.org/JFreeChart-1.0/StackedBarRenderer"\r            class="org.simantics.sysdyn.ui.trend.chart.StackedBarRenderer">\r            <graph />\r            <this />\r        </type>        \r    </target>    \r       \r
+<adapters>\r\r   <target interface="org.simantics.db.layer0.adapter.Realization">\r               <type uri="http://www.simantics.org/Sysdyn-0.0/Module"\r                 class="org.simantics.structural2.realization.StructuralRealization">\r                   <this />\r               </type>\r        </target>\r\r     <target interface="org.simantics.layer0.utils.triggers.ITrigger">\r      <type uri = "http://www.simantics.org/Sysdyn-0.0/DiagramToCompositeMapping"\r          class = "org.simantics.sysdyn.ui.editor.DiagramToCompositeMapping3">\r         <graph/>\r           <this />\r       </type>\r        </target>\r      \r       <target interface="org.simantics.structural.ui.modelBrowser.nodes.AbstractNode">\r               <type uri="http://www.simantics.org/Sysdyn-0.0/SysdynModel"\r                    class="org.simantics.structural.ui.modelBrowser.nodes.ModelNode">\r                      <this />\r               </type>\r        </target>               \r               \r\r      <target\r                interface="org.simantics.browsing.ui.common.node.AbstractNode">\r                <type\r                  uri="http://www.simantics.org/Sysdyn-0.0/SysdynModel"\r                  class="org.simantics.sysdyn.ui.browser.nodes.ModelNode">\r                       <this />\r               </type>\r\r               <resource\r                      uri="http://www.simantics.org/Sysdyn-0.0/ModuleSymbol"\r                 class="org.simantics.sysdyn.ui.browser.nodes.SymbolNode">\r                      <this />\r               </resource>\r\r           <type\r                  uri="http://www.simantics.org/Simulation-1.0/Experiment"\r                       class="org.simantics.sysdyn.ui.browser.nodes.ExperimentNode">\r                  <this />\r               </type>\r                \r               <type\r                  uri="http://www.simantics.org/Sysdyn-0.0/Result"\r                       class="org.simantics.sysdyn.ui.browser.nodes.SimulationResultNode">\r                    <this />\r               </type>\r                \r       </target>\r\r     <!-- Inject default connection routing algorithm for sysdyn diagrams -->\r       <target interface="org.simantics.g2d.diagram.DiagramClass">\r            <adapter uri="http://www.simantics.org/Sysdyn-0.0/ConfigurationDiagram"\r                        adapterClass="org.simantics.sysdyn.ui.elements2.ConfigurationDiagramClassAdapter" />\r   </target>\r\r     <!-- Sysdyn symbols -->\r        <target interface="org.simantics.diagram.adapter.ElementFactory">\r              <resource uri="http://www.simantics.org/Sysdyn-0.0/StockSymbol"\r                        class="org.simantics.sysdyn.ui.elements2.StockFactory" />\r              <resource uri="http://www.simantics.org/Sysdyn-0.0/ModuleSymbol"\r                       class="org.simantics.sysdyn.ui.elements2.ModuleFactory" />\r             <resource uri="http://www.simantics.org/Sysdyn-0.0/ValveSymbol"\r                        class="org.simantics.sysdyn.ui.elements2.ValveFactory" />\r              <resource uri="http://www.simantics.org/Sysdyn-0.0/AuxiliarySymbol"\r                    class="org.simantics.sysdyn.ui.elements2.AuxiliaryFactory" />\r          <resource uri="http://www.simantics.org/Sysdyn-0.0/CloudSymbol"\r                        class="org.simantics.sysdyn.ui.elements2.CloudFactory" />\r              <resource uri="http://www.simantics.org/Sysdyn-0.0/InputSymbol"\r                        class="org.simantics.sysdyn.ui.elements2.InputFactory" />\r\r             <type uri="http://www.simantics.org/Sysdyn-0.0/StockSymbol"\r                    class="org.simantics.sysdyn.ui.elements2.StockFactory" />\r              <type uri="http://www.simantics.org/Sysdyn-0.0/ModuleSymbol"\r                   class="org.simantics.sysdyn.ui.elements2.ModuleFactory" />\r             <type uri="http://www.simantics.org/Sysdyn-0.0/ValveSymbol"\r                    class="org.simantics.sysdyn.ui.elements2.ValveFactory" />\r              <type uri="http://www.simantics.org/Sysdyn-0.0/AuxiliarySymbol"\r                        class="org.simantics.sysdyn.ui.elements2.AuxiliaryFactory" />\r          <type uri="http://www.simantics.org/Sysdyn-0.0/CloudSymbol"\r                    class="org.simantics.sysdyn.ui.elements2.CloudFactory" />\r              <type uri="http://www.simantics.org/Sysdyn-0.0/InputSymbol"\r                    class="org.simantics.sysdyn.ui.elements2.InputFactory" />                       \r       </target>\r      \r       <!-- Sysdyn connections -->\r    <target interface="org.simantics.diagram.adapter.ElementFactory">\r              <!-- Edges -->       \r        <resource uri="http://www.simantics.org/Sysdyn-0.0/FlowConnection"\r            class="org.simantics.sysdyn.ui.elements2.connections.RouteFlowEdgeFactory" />\r        <type uri="http://www.simantics.org/Sysdyn-0.0/FlowConnection"\r            class="org.simantics.sysdyn.ui.elements2.connections.RouteFlowEdgeFactory" />            \r        <type uri="http://www.simantics.org/Sysdyn-0.0/FlowConnection"\r            class="org.simantics.sysdyn.ui.elements2.connections.RouteFlowConnectionFactory">\r            <graph/>\r        </type>                       \r                       \r               <resource uri="http://www.simantics.org/Sysdyn-0.0/DependencyConnection"\r                       class="org.simantics.sysdyn.ui.elements2.connections.DependencyEdgeFactory" />\r         <type uri="http://www.simantics.org/Sysdyn-0.0/DependencyConnection"\r                   class="org.simantics.sysdyn.ui.elements2.connections.DependencyEdgeFactory" />\r         <type uri="http://www.simantics.org/Sysdyn-0.0/DependencyConnection"\r                   class="org.simantics.sysdyn.ui.elements2.connections.DependencyConnectionFactory" />\r   </target>\r      \r       <target interface="org.simantics.g2d.connection.EdgeVisualsConfigurer">\r          <baseType uri="http://www.simantics.org/Diagram-0.0/HasConnector" />\r   <resource uri="http://www.simantics.org/Diagram-0.0/HasPlainConnector"\r          class="org.simantics.diagram.content.ArrowConfigurer">\r         <string>none 0</string>\r       </resource>\r    <resource uri="http://www.simantics.org/Diagram-0.0/HasArrowConnector"\r          class="org.simantics.diagram.content.ArrowConfigurer">\r         <string>fill 1</string>\r       </resource>\r  </target>\r      \r       <!-- ModelBrowser2 -->\r \r       <target interface="org.simantics.browsing.ui.model.children.ChildRule">\r        <resource uri="http://www.simantics.org/Sysdyn-0.0/ProjectBrowseContext/ModuleTypeChildRule"\r            class="org.simantics.sysdyn.ui.browser.childrules.ModuleTypeChildRule"/>\r        <resource uri="http://www.simantics.org/Sysdyn-0.0/ProjectBrowseContext/ModuleContentChildRule"\r            class="org.simantics.sysdyn.ui.browser.childrules.ModuleContentChildRule"/>     \r        <resource uri="http://www.simantics.org/Sysdyn-0.0/ChartAxisAndVariablesBrowseContext/AxisChildRule"\r            class="org.simantics.sysdyn.ui.trend.chart.graphexplorer.AxisChildRule"/>     \r        <resource uri="http://www.simantics.org/Sysdyn-0.0/ChartAxisAndVariablesBrowseContext/VariableChildRule"\r            class="org.simantics.sysdyn.ui.trend.chart.graphexplorer.VariableChildRule"/>  \r        <resource uri="http://www.simantics.org/Sysdyn-0.0/BarSeriesBrowseContext/SeriesChildRule"\r            class="org.simantics.sysdyn.ui.trend.chart.graphexplorer.SeriesChildRule"/>           \r        <resource uri="http://www.simantics.org/Sysdyn-0.0/PieSeriesBrowseContext/SeriesChildRule"\r            class="org.simantics.sysdyn.ui.trend.chart.graphexplorer.SeriesChildRule"/>    \r        <resource uri="http://www.simantics.org/Sysdyn-0.0/HistoryDataset/HistoryDatasetVariablesBrowseContext/VariableChildRule"\r            class="org.simantics.sysdyn.ui.properties.widgets.historyDataset.VariableChildRule"/>                \r    </target>\r    \r    <target interface="org.simantics.browsing.ui.model.visuals.VisualsRule">\r        <resource uri="http://www.simantics.org/Sysdyn-0.0/ProjectBrowseContext/ModuleTypeLabelRule"\r            class="org.simantics.sysdyn.ui.browser.labelrules.ModuleTypeLabelRule"/>\r        <resource uri="http://www.simantics.org/Sysdyn-0.0/ChartAxisAndVariablesBrowseContext/SeriesLabelRule"\r            class="org.simantics.sysdyn.ui.trend.chart.graphexplorer.SeriesLabelRule"/>         \r        <resource uri="http://www.simantics.org/Sysdyn-0.0/ChartAxisAndVariablesBrowseContext/AxisLabelRule"\r            class="org.simantics.sysdyn.ui.trend.chart.graphexplorer.AxisLabelRule"/> \r        <resource uri="http://www.simantics.org/Sysdyn-0.0/BarSeriesBrowseContext/SeriesLabelRule"\r            class="org.simantics.sysdyn.ui.trend.chart.graphexplorer.SeriesLabelRule"/>         \r        <resource uri="http://www.simantics.org/Sysdyn-0.0/PieSeriesBrowseContext/SeriesLabelRule"\r            class="org.simantics.sysdyn.ui.trend.chart.graphexplorer.SeriesLabelRule"/>   \r        <resource uri="http://www.simantics.org/Sysdyn-0.0/HistoryDataset/HistoryDatasetVariablesBrowseContext/VariableLabelRule"\r            class="org.simantics.sysdyn.ui.properties.widgets.historyDataset.VariableLabelRule"/>                \r                \r                     \r        <resource uri="http://www.simantics.org/Sysdyn-0.0/ChartAxisAndVariablesBrowseContext/SeriesLabelDecorationRule"\r            class="org.simantics.sysdyn.ui.trend.chart.graphexplorer.SeriesLabelDecorationRule"/>   \r        <resource uri="http://www.simantics.org/Sysdyn-0.0/BarSeriesBrowseContext/SeriesLabelDecorationRule"\r            class="org.simantics.sysdyn.ui.trend.chart.graphexplorer.SeriesLabelDecorationRule"/>         \r        <resource uri="http://www.simantics.org/Sysdyn-0.0/PieSeriesBrowseContext/SeriesLabelDecorationRule"\r            class="org.simantics.sysdyn.ui.trend.chart.graphexplorer.SeriesLabelDecorationRule"/>     \r    </target>    \r    \r    <target interface="org.simantics.db.layer0.adapter.ActionFactory">\r        <resource uri="http://www.simantics.org/Sysdyn-0.0/ProjectActionContext/Actions/NewModuleType"\r            class="org.simantics.sysdyn.ui.browser.actions.NewModuleTypeAction" />\r        <resource uri="http://www.simantics.org/Sysdyn-0.0/ProjectActionContext/Actions/NewEnumeration"\r            class="org.simantics.sysdyn.ui.browser.actions.NewEnumerationAction" />\r        <resource uri="http://www.simantics.org/Sysdyn-0.0/ProjectActionContext/Actions/OpenWorkbook"\r            class="org.simantics.sysdyn.ui.browser.actions.OpenWorkbookAction" />\r        <resource uri="http://www.simantics.org/Sysdyn-0.0/ProjectActionContext/Actions/NewFunction"\r            class="org.simantics.sysdyn.ui.browser.actions.NewFunctionAction" />\r        <resource uri="http://www.simantics.org/Sysdyn-0.0/ProjectActionContext/Actions/NewFunctionLibrary"\r            class="org.simantics.sysdyn.ui.browser.actions.NewFunctionLibraryAction" />\r        <resource uri="http://www.simantics.org/Sysdyn-0.0/ProjectActionContext/Actions/NewSharedFunctionLibrary"\r            class="org.simantics.sysdyn.ui.browser.actions.NewSharedFunctionLibraryAction" />            \r    </target>         \r    \r   <target interface="org.simantics.db.layer0.adapter.DropActionFactory">\r        <resource\r            uri="http://www.simantics.org/Sysdyn-0.0/ChartAxisAndVariablesActionContext/Actions/SeriesDropAction"\r            class="org.simantics.sysdyn.ui.trend.chart.graphexplorer.SeriesDropAction" />\r        <resource\r            uri="http://www.simantics.org/Sysdyn-0.0/ChartAxisAndVariablesActionContext/Actions/AxisDropAction"\r            class="org.simantics.sysdyn.ui.trend.chart.graphexplorer.AxisDropAction" />            \r            \r        <resource\r            uri="http://www.simantics.org/Sysdyn-0.0/BarSeriesActionContext/Actions/SeriesDropAction"\r            class="org.simantics.sysdyn.ui.trend.chart.graphexplorer.SeriesDropAction" />\r        <resource\r            uri="http://www.simantics.org/Sysdyn-0.0/PieSeriesActionContext/Actions/SeriesDropAction"\r            class="org.simantics.sysdyn.ui.trend.chart.graphexplorer.SeriesDropAction" />                        \r    </target>     \r  \r  <!-- PROFILES -->\r    <target interface="org.simantics.scenegraph.profile.Style">\r        <resource uri="http://www.simantics.org/Sysdyn-0.0/SimulationPlaybackStyle"\r            class="org.simantics.sysdyn.ui.elements2.profiles.SimulationPlaybackStyle">\r        </resource>\r                <resource uri="http://www.simantics.org/Sysdyn-0.0/IssueStyle"\r            class="org.simantics.sysdyn.ui.elements2.profiles.IssueDecorationStyle">\r        </resource>\r    </target>\r    \r  <!-- Charts -->\r    <target interface="org.simantics.diagram.adapter.ElementFactory">\r        <resource uri="http://www.simantics.org/JFreeChart-1.0/ChartElement"\r            class="org.simantics.sysdyn.ui.trend.chart.element.ChartElementFactory" />\r            \r        <type uri="http://www.simantics.org/JFreeChart-1.0/ChartElement"\r            class="org.simantics.sysdyn.ui.trend.chart.element.ChartElementFactory" />\r    </target>\r                \r    <target interface="org.simantics.diagram.synchronization.graph.ElementWriter">\r        <resource uri="http://www.simantics.org/JFreeChart-1.0/ChartElement"\r            class="org.simantics.sysdyn.ui.trend.chart.element.ChartElementWriter" />\r    </target>\r                    \r    <target interface="org.simantics.sysdyn.ui.trend.chart.IJFreeChart">\r        <type uri="http://www.simantics.org/JFreeChart-1.0/Chart"\r            class="org.simantics.sysdyn.ui.trend.chart.JFreeChart">\r            <graph />\r            <this />\r        </type>\r    </target>  \r    \r    <target interface="org.simantics.sysdyn.ui.trend.chart.IDataset">\r        <type uri="http://www.simantics.org/JFreeChart-1.0/XYDataset"\r            class="org.simantics.sysdyn.ui.trend.chart.XYDataset">\r            <graph />\r            <this />\r        </type>\r        <type uri="http://www.simantics.org/JFreeChart-1.0/CategoryDataset"\r            class="org.simantics.sysdyn.ui.trend.chart.CategoryDataset">\r            <graph />\r            <this />\r        </type>        \r        <type uri="http://www.simantics.org/JFreeChart-1.0/PieDataset"\r            class="org.simantics.sysdyn.ui.trend.chart.PieDataset">\r            <graph />\r            <this />\r        </type>          \r    </target>\r    \r     <target interface="org.simantics.sysdyn.ui.trend.chart.ITitle">\r        <type uri="http://www.simantics.org/JFreeChart-1.0/TextTitle"\r            class="org.simantics.sysdyn.ui.trend.chart.TextTitle">\r            <graph />\r            <this />\r        </type>\r    </target>\r    \r    <target interface="org.simantics.sysdyn.ui.trend.chart.IAxis">\r        <type uri="http://www.simantics.org/JFreeChart-1.0/NumberAxis"\r            class="org.simantics.sysdyn.ui.trend.chart.NumberAxis">\r            <graph />\r            <this />\r        </type>\r        <type uri="http://www.simantics.org/JFreeChart-1.0/CategoryAxis"\r            class="org.simantics.sysdyn.ui.trend.chart.CategoryAxis">\r            <graph />\r            <this />\r        </type>        \r    </target>\r       \r    <target interface="org.simantics.sysdyn.ui.trend.chart.IPlot">\r        <type uri="http://www.simantics.org/JFreeChart-1.0/XYPlot"\r            class="org.simantics.sysdyn.ui.trend.chart.XYPlot">\r            <graph />\r            <this />\r        </type>\r        <type uri="http://www.simantics.org/JFreeChart-1.0/CategoryPlot"\r            class="org.simantics.sysdyn.ui.trend.chart.CategoryPlot">\r            <graph />\r            <this />\r        </type>      \r        <type uri="http://www.simantics.org/JFreeChart-1.0/PiePlot"\r            class="org.simantics.sysdyn.ui.trend.chart.PiePlot">\r            <graph />\r            <this />\r        </type>               \r    </target>\r    \r     <target interface="org.simantics.sysdyn.ui.trend.chart.IRenderer">\r     \r        <type uri="http://www.simantics.org/JFreeChart-1.0/XYLineRenderer"\r            class="org.simantics.sysdyn.ui.trend.chart.XYLineRenderer">\r            <graph />\r            <this />\r        </type>  \r        <type uri="http://www.simantics.org/JFreeChart-1.0/XYAreaRenderer"\r            class="org.simantics.sysdyn.ui.trend.chart.XYAreaRenderer">\r            <graph />\r            <this />\r        </type>        \r                \r        <type uri="http://www.simantics.org/JFreeChart-1.0/BarRenderer"\r            class="org.simantics.sysdyn.ui.trend.chart.BarRenderer">\r            <graph />\r            <this />\r        </type>\r        <type uri="http://www.simantics.org/JFreeChart-1.0/StackedBarRenderer"\r            class="org.simantics.sysdyn.ui.trend.chart.StackedBarRenderer">\r            <graph />\r            <this />\r        </type>        \r    </target>    \r       \r
 </adapters>
\ No newline at end of file
index 7b2f5227d54219ed0e0cc00685573f1b46ec64ca..949c5febffa64767f915200e589241af1fa38437 100644 (file)
    <extension\r
          point="org.eclipse.ui.editors">\r
       <editor\r
-            class="org.simantics.sysdyn.ui.editor.DiagramViewer"\r
+            class="org.simantics.modeling.ui.diagramEditor.DiagramEditor:viewer=org.simantics.sysdyn.ui.editor.DiagramViewer"\r
             default="false"\r
             icon="platform:/plugin/com.famfamfam.silk/icons/plugin.png"\r
             id="org.simantics.sysdyn.ui.diagramViewer"\r
+            matchingStrategy="org.simantics.ui.workbench.editor.input.ResourceEditorInputMatchingStrategy"\r
             name="System dynamic diagram viewer">\r
       </editor>\r
       <editor\r
       <view\r
             allowMultiple="false"\r
             category="org.simantics.sysdyn.ui.category"\r
-            class="org.simantics.sysdyn.ui.dependencies.DependencyView"\r
+            class="org.simantics.sysdyn.ui.structure.StructureView"\r
             icon="platform:/plugin/com.famfamfam.silk/icons/arrow_switch.png"\r
-            id="org.simantics.sysdyn.ui.dependencies.view"\r
-            name="Dependencies"\r
+            id="org.simantics.sysdyn.ui.structure.view"\r
+            name="Structure"\r
             restorable="true">\r
       </view>\r
       <view\r
                relative="org.simantics.browsing.ui.graph.propertyView">\r
          </view>\r
          <view\r
-               id="org.simantics.sysdyn.ui.dependencies.view"\r
+               id="org.simantics.sysdyn.ui.structure.view"\r
                minimized="false"\r
                relationship="stack"\r
                relative="org.simantics.sysdyn.ui.trend.view">\r
                   </with>\r
                </visibleWhen>\r
             </command>\r
+            <command\r
+                  commandId="org.simantics.sysdyn.ui.newHistoryData"\r
+                  icon="platform:/plugin/com.famfamfam.silk/icons/table.png"\r
+                  id="org.simantics.sysdyn.ui.browser.newHistoryData"\r
+                  label="History Data"\r
+                  style="push">\r
+               <visibleWhen\r
+                     checkEnabled="true">\r
+                  <with\r
+                        variable="selection">\r
+                     <test\r
+                           args="org.simantics.sysdyn.ui.browser.nodes.ExperimentNode"\r
+                           property="org.simantics.sysdyn.ui.nodeClass">\r
+                     </test>\r
+                  </with>\r
+               </visibleWhen>\r
+            </command>\r
          </menu>\r
          <dynamic\r
                class="org.simantics.ui.contribution.OpenWithMenuContribution"\r
             id="org.simantics.sysdyn.ui.newPieChart"\r
             name="New Pie Chart">\r
       </command>\r
+      <command\r
+            defaultHandler="org.simantics.sysdyn.ui.handlers.newComponents.NewHistoryDataHandler"\r
+            id="org.simantics.sysdyn.ui.newHistoryData"\r
+            name="New History Data">\r
+      </command>\r
    </extension>\r
    <extension\r
          point="org.eclipse.ui.handlers">\r
index 40bcbe6efc8e41732d534c511ff40f93c7d2b13f..8c9a821b55cef2573a6b3abc5a0eb4820b14dc6d 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************\r
- * Copyright (c) 2010 Association for Decentralized Information Management in\r
+ * Copyright (c) 2010, 2012 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
@@ -26,34 +26,35 @@ import org.simantics.db.exception.DatabaseException;
 import org.simantics.layer0.Layer0;\r
 import org.simantics.sysdyn.SysdynResource;\r
 import org.simantics.sysdyn.ui.browser.nodes.ExperimentNode;\r
+import org.simantics.sysdyn.ui.browser.nodes.HistoryDataNode;\r
 \r
 public class SimulationResult  extends ViewpointContributor<ExperimentNode> {\r
 \r
     @SuppressWarnings("unchecked")\r
-       @Override\r
+    @Override\r
     public Collection<?> getContribution(ReadGraph graph, ExperimentNode experiment) throws DatabaseException {\r
         ArrayList<AbstractNode<Resource>> result = new ArrayList<AbstractNode<Resource>>();\r
         SysdynResource sr = SysdynResource.getInstance(graph);\r
         for(final Resource r : graph.syncRequest(new ObjectsWithType(experiment.data, sr.Experiment_result, sr.Result))) {\r
-            String resultPath = (String)graph.getPossibleRelatedValue(r, sr.Result_resultFile);\r
-            File file = new File(resultPath);\r
-            if(file.exists()) {\r
-                try {\r
-                    result.add(graph.adapt(r, AbstractNode.class));\r
-                } catch(DatabaseException e) {\r
-                    e.printStackTrace();\r
-                }\r
+            if(graph.isInstanceOf(r, sr.HistoryDataset)) {\r
+                result.add(graph.adapt(r, AbstractNode.class));\r
             } else {\r
-                graph.asyncRequest(new WriteRequest() {\r
-                    \r
-                    @Override\r
-                    public void perform(WriteGraph graph) throws DatabaseException {\r
-                       Layer0 l0 = Layer0.getInstance(graph);\r
-                        graph.deny(r, l0.PartOf);\r
-                        graph.deny(r, graph.getInverse(SysdynResource.getInstance(graph).Experiment_result));\r
-                        \r
-                    }\r
-                });\r
+                String resultPath = (String)graph.getPossibleRelatedValue(r, sr.Result_resultFile);\r
+                File file = new File(resultPath);\r
+                if(file.exists()) {\r
+                    result.add(new HistoryDataNode(r));\r
+                } else {\r
+                    graph.asyncRequest(new WriteRequest() {\r
+\r
+                        @Override\r
+                        public void perform(WriteGraph graph) throws DatabaseException {\r
+                            Layer0 l0 = Layer0.getInstance(graph);\r
+                            graph.deny(r, l0.PartOf);\r
+                            graph.deny(r, graph.getInverse(SysdynResource.getInstance(graph).Experiment_result));\r
+\r
+                        }\r
+                    });\r
+                }\r
             }\r
         }\r
         return result;\r
index f3abbfa761ddcf303fb2e685d28bd347e351eb24..442e91a02dbdbaaeb346c9b8bb8af9abc726a45a 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************\r
- * Copyright (c) 2010 Association for Decentralized Information Management in\r
+ * Copyright (c) 2010, 2012 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
@@ -16,14 +16,15 @@ import org.eclipse.swt.SWT;
 import org.simantics.browsing.ui.content.LabelDecorator;\r
 import org.simantics.browsing.ui.graph.contributor.labeler.LabelDecoratorContributor;\r
 import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.sysdyn.SysdynResource;\r
 import org.simantics.sysdyn.ui.browser.nodes.SimulationResultNode;\r
 \r
-public class SimulationResultDecorator extends LabelDecoratorContributor<SimulationResultNode>{\r
+public class SimulationResultDecorator extends LabelDecoratorContributor<SimulationResultNode<Resource>>{\r
 \r
     @Override\r
-    public LabelDecorator getDecorator(ReadGraph graph, SimulationResultNode result) throws DatabaseException {\r
+    public LabelDecorator getDecorator(ReadGraph graph, SimulationResultNode<Resource> result) throws DatabaseException {\r
         if (graph.hasStatement(result.data, SysdynResource.getInstance(graph).Result_showResult)) {\r
             return new LabelDecorator.Stub() {\r
 \r
index 3c2de6cf8b602a60ad38506f5157023cc349e202..3dc688d5d9a6eec53b003742fdb946b462341d47 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************\r
- * Copyright (c) 2010 Association for Decentralized Information Management in\r
+ * Copyright (c) 2010, 2012 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
@@ -14,16 +14,20 @@ package org.simantics.sysdyn.ui.browser.contributions;
 import org.eclipse.jface.resource.ImageDescriptor;\r
 import org.simantics.browsing.ui.swt.ImagerContributor;\r
 import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.sysdyn.SysdynResource;\r
 import org.simantics.sysdyn.ui.Activator;\r
 import org.simantics.sysdyn.ui.browser.nodes.SimulationResultNode;\r
 \r
-public class SimulationResultImager extends ImagerContributor<SimulationResultNode>{\r
+public class SimulationResultImager extends ImagerContributor<SimulationResultNode<Resource>>{\r
 \r
     @Override\r
-    public ImageDescriptor getDescriptor(ReadGraph graph, SimulationResultNode result) throws DatabaseException {\r
-        if(graph.hasStatement(result.data, SysdynResource.getInstance(graph).Result_showResult))\r
+    public ImageDescriptor getDescriptor(ReadGraph graph, SimulationResultNode<Resource> result) throws DatabaseException {\r
+        SysdynResource sr = SysdynResource.getInstance(graph);\r
+        if(graph.isInstanceOf(result.data, sr.HistoryDataset))\r
+            return ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/table.png"));\r
+        if(graph.hasStatement(result.data, sr.Result_showResult))\r
             return ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/chart_bar.png"));\r
         else\r
             return ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/chart_bar_blackAndWhite.png"));\r
index 917adb9c54f3b49792b512aca78f50a0dbcb87ce..f0e968edfc2f970f42ac018cb77f25f71f27bc44 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************\r
- * Copyright (c) 2010 Association for Decentralized Information Management in\r
+ * Copyright (c) 2010, 2012 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
@@ -13,14 +13,15 @@ package org.simantics.sysdyn.ui.browser.contributions;
 \r
 import org.simantics.browsing.ui.graph.contributor.labeler.LabelerContributor;\r
 import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.layer0.Layer0;\r
 import org.simantics.sysdyn.ui.browser.nodes.SimulationResultNode;\r
 \r
-public class SimulationResultLabeler extends LabelerContributor<SimulationResultNode>{\r
+public class SimulationResultLabeler extends LabelerContributor<SimulationResultNode<Resource>>{\r
 \r
     @Override\r
-    public String getLabel(ReadGraph graph, SimulationResultNode result) throws DatabaseException {\r
+    public String getLabel(ReadGraph graph, SimulationResultNode<Resource> result) throws DatabaseException {\r
         String name = graph.getPossibleRelatedValue(result.data, Layer0.getInstance(graph).HasLabel);\r
         return name == null ? "Experiment (no name)" : name;\r
     }\r
diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/HistoryDataNode.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/nodes/HistoryDataNode.java
new file mode 100644 (file)
index 0000000..196a52e
--- /dev/null
@@ -0,0 +1,44 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2012 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.browser.nodes;\r
+\r
+import org.simantics.browsing.ui.common.node.DeleteException;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.exception.CancelTransactionException;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.util.RemoverUtil;\r
+import org.simantics.ui.SimanticsUI;\r
+import org.simantics.utils.ui.ExceptionUtils;\r
+\r
+public class HistoryDataNode extends SimulationResultNode<Resource> {\r
+\r
+    public HistoryDataNode(Resource resource) {\r
+        super(resource);\r
+    }\r
+\r
+    @Override\r
+    public void delete() throws DeleteException {\r
+        try {\r
+            SimanticsUI.getSession().syncRequest(new WriteRequest() {\r
+                @Override\r
+                public void perform(WriteGraph graph) throws DatabaseException, CancelTransactionException {\r
+                    RemoverUtil.remove(graph, data);\r
+                }\r
+            });\r
+        } catch (DatabaseException e) {\r
+            ExceptionUtils.logAndShowError(e);\r
+        }\r
+        \r
+    }\r
+}\r
index 768b591e03b47d763fdd8d67aa4cfa9483573b60..bc9c4a3f467bbaa3cb3f3d8dd2047993e1335793 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************\r
- * Copyright (c) 2010 Association for Decentralized Information Management in\r
+ * Copyright (c) 2010, 2012 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
@@ -31,7 +31,7 @@ import org.simantics.sysdyn.ui.handlers.ToggleResultActivation;
 import org.simantics.ui.SimanticsUI;\r
 import org.simantics.utils.ui.ExceptionUtils;\r
 \r
-public class SimulationResultNode  extends AbstractNode<Resource> implements IDoubleClickableNode, IDeletableNode, IModifiableNode {\r
+public class SimulationResultNode<T>  extends AbstractNode<Resource> implements IDoubleClickableNode, IDeletableNode, IModifiableNode {\r
 \r
     public SimulationResultNode(Resource resource) {\r
         super(resource);\r
index 5d48050f700346664fb6f49f4499a020249730e5..da8581db6cbc749e640d9bff72c4de0605eb7195 100644 (file)
@@ -1,3 +1,14 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2012 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.editor.participant;\r
 \r
 import java.awt.geom.AffineTransform;\r
@@ -176,6 +187,7 @@ public class SysdynConnectionBuilder extends ConnectionBuilder{
 \r
         Resource valve = graph.newResource();\r
         graph.claim(valve, L0.InstanceOf, null, valveClassResource);\r
+        graph.claim(valve, L0.PartOf, diagramResource);\r
         valveElement.setHint(ElementHints.KEY_OBJECT, valve);\r
 \r
         OrderedSetUtils.add(graph, diagramResource, valve);\r
index 5a35e5385de562564c281dbc46a40296cbadee32..b2478e0c2e6bf95111d0d8a80b949bbf4d829803 100644 (file)
@@ -15,6 +15,7 @@ import org.eclipse.core.commands.AbstractHandler;
 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.IEditorPart;\r
 import org.eclipse.ui.PartInitException;\r
 import org.eclipse.ui.PlatformUI;\r
 import org.eclipse.ui.handlers.HandlerUtil;\r
@@ -29,6 +30,7 @@ import org.simantics.db.layer0.variable.Variables;
 import org.simantics.diagram.stubs.DiagramResource;\r
 import org.simantics.modeling.ComponentUtils;\r
 import org.simantics.modeling.ModelingResources;\r
+import org.simantics.modeling.ui.diagramEditor.DiagramEditor;\r
 import org.simantics.structural.stubs.StructuralResource2;\r
 import org.simantics.sysdyn.SysdynResource;\r
 import org.simantics.sysdyn.ui.editor.DiagramViewer;\r
@@ -47,7 +49,12 @@ public class ShowModuleHandler extends AbstractHandler {
                \r
                ISelection s = HandlerUtil.getCurrentSelectionChecked(event);\r
                final Resource resources[] = ResourceAdaptionUtils.toResources(s);\r
-               final DiagramViewer viewer = (DiagramViewer)HandlerUtil.getActiveEditor(event);\r
+               IEditorPart editor = (IEditorPart)HandlerUtil.getActiveEditor(event);\r
+               if (!(editor instanceof DiagramEditor))\r
+                       return null;\r
+               final DiagramViewer viewer = (DiagramViewer) ((DiagramEditor) editor).getViewer();\r
+               if (viewer == null)\r
+                       return null;\r
                \r
                SimanticsUI.getSession().asyncRequest(new ReadRequest() {\r
                        \r
diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewHistoryDataHandler.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewHistoryDataHandler.java
new file mode 100644 (file)
index 0000000..09d7beb
--- /dev/null
@@ -0,0 +1,69 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2012 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.newComponents;\r
+\r
+import java.util.UUID;\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
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.common.utils.NameUtils;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.layer0.utils.direct.GraphUtils;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.ui.SimanticsUI;\r
+import org.simantics.ui.utils.AdaptionUtils;\r
+\r
+/**\r
+ * Handler for creating new history dataset\r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
+public class NewHistoryDataHandler extends AbstractHandler {\r
+\r
+    @Override\r
+    public Object execute(ExecutionEvent event) throws ExecutionException {\r
+\r
+        ISelection sel = HandlerUtil.getCurrentSelection(event);\r
+\r
+        final Resource experiment = AdaptionUtils.adaptToSingle(sel, Resource.class);\r
+\r
+        SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
+\r
+            @Override\r
+            public void perform(WriteGraph g) throws DatabaseException {\r
+                SysdynResource sr = SysdynResource.getInstance(g);\r
+                Layer0 l0 = Layer0.getInstance(g);\r
+                if(!g.isInstanceOf(experiment, sr.Experiment))\r
+                    return; // Not called from an experiment\r
+\r
+                Resource model = g.getPossibleObject(experiment, l0.PartOf);\r
+                // Create the history dataset\r
+                GraphUtils.create2(g, \r
+                        sr.HistoryDataset,\r
+                        l0.HasName, "HistoryDataset" + UUID.randomUUID().toString(),\r
+                        l0.HasLabel, NameUtils.findFreshLabel(g, "History Dataset", experiment),\r
+                        sr.Experiment_result_Inverse, experiment, \r
+                        sr.HistoryDataset_columns, Boolean.TRUE,\r
+                        l0.PartOf, model);\r
+            }\r
+        });\r
+        return null;\r
+    }\r
+\r
+}
\ No newline at end of file
index 8c678caca80bf870328d8c02e05c51596c69427d..a0c89f82dd2818e15859b727cf76a505bce46efa 100644 (file)
@@ -29,6 +29,7 @@ import org.simantics.db.service.VirtualGraphSupport;
 import org.simantics.diagram.profile.Profiles;\r
 import org.simantics.diagram.stubs.DiagramResource;\r
 import org.simantics.layer0.Layer0;\r
+import org.simantics.modeling.ui.diagramEditor.DiagramEditor;\r
 import org.simantics.project.IProject;\r
 import org.simantics.simulation.experiment.ExperimentState;\r
 import org.simantics.simulation.experiment.IExperiment;\r
@@ -148,13 +149,16 @@ public class SysdynPlaybackExperimentListener implements IExperimentListener {
         for(IWorkbenchPage page : pages) {\r
             for(IEditorReference reference : page.getEditorReferences()) {\r
                 IEditorPart iep = reference.getEditor(false);\r
-                if(iep instanceof DiagramViewer) {\r
-                    DiagramViewer viewer = (DiagramViewer) iep;\r
-                    Resource runtime = viewer.getRuntime();\r
-                    String modelUri = viewer.getResourceInput2().getModelURI();\r
-                    DiagramInfo info = new DiagramInfo();\r
-                    info.modelURI = modelUri;\r
-                    runtimeDiagramsAndModelUris.put(runtime, info);\r
+                if(iep instanceof DiagramEditor) {\r
+                    DiagramEditor editor = (DiagramEditor) iep;\r
+                    if (editor.getViewer() instanceof DiagramViewer) {\r
+                        DiagramViewer viewer = (DiagramViewer) editor.getViewer();\r
+                        Resource runtime = viewer.getRuntime();\r
+                        String modelUri = viewer.getResourceInput2().getModelURI();\r
+                        DiagramInfo info = new DiagramInfo();\r
+                        info.modelURI = modelUri;\r
+                        runtimeDiagramsAndModelUris.put(runtime, info);\r
+                    }\r
                 }\r
             }\r
         }\r
index c5a2ed3449d8e432d4b2ba6101c13ea573f4d48f..b6fcb97bb19e140f7a70f39c9bca381eede16865 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************\r
- * Copyright (c) 2010 Association for Decentralized Information Management in\r
+ * Copyright (c) 2010, 2012 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
@@ -44,7 +44,12 @@ import org.simantics.sysdyn.representation.ModuleType;
 import org.simantics.ui.SimanticsUI;\r
 import org.simantics.ui.workbench.ResourceEditorInput;\r
 \r
-\r
+/**\r
+ * Text editor for displaying Modelica code\r
+ * \r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
 public class SysdynModelicaEditor extends TextEditor {\r
 \r
     AnnotationModel annotationModel = new AnnotationModel();\r
@@ -80,16 +85,12 @@ public class SysdynModelicaEditor extends TextEditor {
                 try {\r
                     Configuration configuration =\r
                         LoadRepresentation.loadConfiguration(SimanticsUI.getSession(), ((ResourceEditorInput)element).getResource());\r
-                    ModelicaWriter writer = new ModelicaWriter();\r
                     \r
                     HashSet<Configuration> configurations = new HashSet<Configuration>();\r
                     configurations.add(configuration);\r
                     getConfigurations(configuration, configurations);\r
-                    \r
-                    for(Configuration c : configurations)\r
-                       writer.write(c);\r
-                    \r
-                    return new Document(writer.toString());\r
+\r
+                    return new Document(ModelicaWriter.write(configurations));\r
                 } catch (DatabaseException e) {\r
                     e.printStackTrace();\r
                     throw new CoreException(STATUS_ERROR);\r
index a67546b18b746514ea8caf774770be9ff9fde155..f0d9b324fefcda81909066796022850065cd1a05 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************\r
- * Copyright (c) 2010 Association for Decentralized Information Management in\r
+ * Copyright (c) 2010, 2012 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,10 +18,12 @@ import org.eclipse.jface.dialogs.IInputValidator;
 import org.eclipse.jface.layout.GridDataFactory;\r
 import org.eclipse.jface.layout.GridLayoutFactory;\r
 import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.custom.ScrolledComposite;\r
 import org.eclipse.swt.widgets.Composite;\r
 import org.eclipse.swt.widgets.Label;\r
 import org.eclipse.ui.IWorkbenchSite;\r
 import org.simantics.browsing.ui.swt.widgets.StringPropertyFactory;\r
+import org.simantics.browsing.ui.swt.widgets.StringPropertyModifier;\r
 import org.simantics.browsing.ui.swt.widgets.TrackedCombo;\r
 import org.simantics.browsing.ui.swt.widgets.TrackedText;\r
 import org.simantics.browsing.ui.swt.widgets.impl.ReadFactoryImpl;\r
@@ -40,8 +42,19 @@ import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyFactor
 import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyModifier;\r
 import org.simantics.sysdyn.ui.utils.VariableNameUtils;\r
 \r
+/**\r
+ * Tab displaying configuration properties. Displayed for model and configuration.\r
+ * \r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
 public class ConfigurationTab extends LabelPropertyTabContributor {\r
 \r
+    /**\r
+     * Modifier for modifying model labels\r
+     * @author Teemu Lempinen\r
+     *\r
+     */\r
        private class ModelLabelModifier extends TextModifyListenerImpl<Resource> {\r
 \r
                public ModelLabelModifier(ISessionContext context, String propertyURI) {\r
@@ -60,7 +73,11 @@ public class ConfigurationTab extends LabelPropertyTabContributor {
     \r
     @Override\r
     public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) {\r
-        Composite composite = new Composite(body, SWT.NONE);\r
+        ScrolledComposite sc = new ScrolledComposite(body,  SWT.H_SCROLL | SWT.V_SCROLL);\r
+        GridDataFactory.fillDefaults().grab(true, true).applyTo(sc);\r
+        GridLayoutFactory.fillDefaults().applyTo(sc);\r
+        \r
+        Composite composite = new Composite(sc, SWT.NONE);\r
         GridDataFactory.fillDefaults().grab(true, true).applyTo(composite);\r
         GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(composite);\r
 \r
@@ -155,8 +172,30 @@ public class ConfigurationTab extends LabelPropertyTabContributor {
         tolerance.addModifyListener(new DoublePropertyModifier(context, SysdynResource.URIs.SysdynModel_tolerance));\r
         tolerance.setInputValidator(new DoubleValidator());\r
         GridDataFactory.fillDefaults().hint(200, SWT.DEFAULT).applyTo(tolerance.getWidget());\r
-\r
         \r
+        label = new Label(composite, SWT.NONE);\r
+        label.setText("Variable filter");\r
+        label.setToolTipText("Variable filter as regular expression.\n" +\r
+                       "To include variables Auxiliary1, Auxiliary2 and Auxiliary3: \n" +\r
+                       "Auxiliary[1-3]\n" +\r
+                       "or\n" +\r
+                       "Auxiliary1|Auxiliary2|Auxiliary3");\r
+\r
+        TrackedText variableFilter = new TrackedText(composite, support, SWT.BORDER);\r
+        variableFilter.setTextFactory(new StringPropertyFactory(SysdynResource.URIs.SysdynModel_variableFilter, ""));\r
+        variableFilter.addModifyListener(new StringPropertyModifier(context, SysdynResource.URIs.SysdynModel_variableFilter));\r
+        GridDataFactory.fillDefaults().hint(200, SWT.DEFAULT).applyTo(variableFilter.getWidget());\r
+        variableFilter.getWidget().setToolTipText("Variable filter as regular expression.\n" +\r
+                "To include variables Auxiliary1, Auxiliary2 and Auxiliary3: \n" +\r
+                "Auxiliary[1-3]\n" +\r
+                "or\n" +\r
+                "Auxiliary1|Auxiliary2|Auxiliary3");\r
+        \r
+        // Scrolled composite settings\r
+        sc.setContent(composite);\r
+        sc.setMinSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT));\r
+        sc.setExpandHorizontal(true);\r
+        sc.setExpandVertical(true);\r
     }\r
 \r
     private class DoubleValidator implements IInputValidator {\r
diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/HistoryDataTab.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/HistoryDataTab.java
new file mode 100644 (file)
index 0000000..fe3694d
--- /dev/null
@@ -0,0 +1,286 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2012 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.Collection;\r
+import java.util.LinkedHashMap;\r
+import java.util.Map;\r
+\r
+import org.eclipse.jface.layout.GridDataFactory;\r
+import org.eclipse.jface.layout.GridLayoutFactory;\r
+import org.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.custom.ScrolledComposite;\r
+import org.eclipse.swt.widgets.Combo;\r
+import org.eclipse.swt.widgets.Composite;\r
+import org.eclipse.swt.widgets.Group;\r
+import org.eclipse.swt.widgets.Label;\r
+import org.eclipse.ui.IWorkbenchSite;\r
+import org.simantics.browsing.ui.swt.SingleSelectionInputSource;\r
+import org.simantics.browsing.ui.swt.widgets.Button;\r
+import org.simantics.browsing.ui.swt.widgets.GraphExplorerComposite;\r
+import org.simantics.browsing.ui.swt.widgets.StringPropertyFactory;\r
+import org.simantics.browsing.ui.swt.widgets.StringPropertyModifier;\r
+import org.simantics.browsing.ui.swt.widgets.TrackedCombo;\r
+import org.simantics.browsing.ui.swt.widgets.TrackedText;\r
+import org.simantics.browsing.ui.swt.widgets.impl.ReadFactoryImpl;\r
+import org.simantics.browsing.ui.swt.widgets.impl.SelectionListenerImpl;\r
+import org.simantics.browsing.ui.swt.widgets.impl.TextModifyListener;\r
+import org.simantics.browsing.ui.swt.widgets.impl.TrackedModifyEvent;\r
+import org.simantics.browsing.ui.swt.widgets.impl.Widget;\r
+import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
+import org.simantics.databoard.Bindings;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.request.ObjectsWithType;\r
+import org.simantics.db.common.request.PossibleObjectWithType;\r
+import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.common.utils.NameUtils;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.management.ISessionContext;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.simulation.ontology.SimulationResource;\r
+import org.simantics.spreadsheet.resource.SpreadsheetResource;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.utils.datastructures.ArrayMap;\r
+import org.simantics.utils.ui.ISelectionUtils;\r
+\r
+/**\r
+ * Tab for displaying and modifying history data settings in SysDyn.\r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
+public class HistoryDataTab  extends LabelPropertyTabContributor {\r
+\r
+    @Override\r
+    public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport support) {\r
+        \r
+        // Scrolled composite for scrollable tab\r
+        ScrolledComposite sc = new ScrolledComposite(body, SWT.H_SCROLL | SWT.V_SCROLL);\r
+        GridDataFactory.fillDefaults().grab(true, true).applyTo(sc);\r
+        GridLayoutFactory.fillDefaults().margins(3, 3).applyTo(sc);\r
+\r
+        // Container for all components\r
+        Composite composite = new Composite(sc, SWT.NONE);\r
+        GridDataFactory.fillDefaults().grab(true, true).applyTo(composite);\r
+        GridLayoutFactory.fillDefaults().numColumns(3).margins(3, 3).applyTo(composite);\r
+\r
+        // Name\r
+        Label label = new Label(composite, SWT.NONE);\r
+        GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(label);\r
+        label.setText("Name: ");\r
+        \r
+        TrackedText nameText = new TrackedText(composite, support, SWT.BORDER);\r
+        nameText.setTextFactory(new StringPropertyFactory(Layer0.URIs.HasLabel));\r
+        nameText.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasLabel));\r
+        GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(nameText.getWidget());\r
+\r
+        // Sheet selection \r
+        label = new Label(composite, SWT.NONE);\r
+        GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(label);\r
+        label.setText("Sheet: ");\r
+        \r
+        TrackedCombo sheet = new TrackedCombo(composite, support, SWT.DROP_DOWN | SWT.BORDER | SWT.READ_ONLY);\r
+        sheet.setItemFactory(new SheetItemFactory());\r
+        sheet.setSelectionFactory(new SheetSelectionFactory());\r
+        sheet.addModifyListener(new SheetModifyListener());\r
+        GridDataFactory.fillDefaults().span(2, 1).applyTo(sheet.getWidget());\r
+\r
+        // Orientation (columns or rows)\r
+        label = new Label(composite, SWT.NONE);\r
+        GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(label);\r
+        label.setText("Orientation: ");\r
+        \r
+        Composite orientation = new Composite(composite, SWT.NONE);\r
+        GridDataFactory.fillDefaults().applyTo(orientation);\r
+        GridLayoutFactory.fillDefaults().numColumns(2).applyTo(orientation);\r
+        \r
+        // Radio buttons for orientation\r
+        Button columns = new Button(orientation, support, SWT.RADIO);\r
+        GridDataFactory.fillDefaults().applyTo(columns.getWidget());\r
+        columns.setText("Columns");\r
+        columns.addSelectionListener(new SelectionListenerImpl<Resource>(context) {\r
+            @Override\r
+            public void apply(WriteGraph graph, Resource input) throws DatabaseException {\r
+                graph.claimLiteral(input, SysdynResource.getInstance(graph).HistoryDataset_columns, Boolean.TRUE, Bindings.BOOLEAN);\r
+            }\r
+        });\r
+        columns.setSelectionFactory(new ReadFactoryImpl<Resource, Boolean>() {\r
+\r
+            @Override\r
+            public Boolean perform(ReadGraph graph, Resource input) throws DatabaseException {\r
+                return graph.getPossibleRelatedValue(input, SysdynResource.getInstance(graph).HistoryDataset_columns);\r
+            }\r
+        });\r
+        \r
+        Button rows = new Button(orientation, support, SWT.RADIO);\r
+        rows.setText("Rows");\r
+        rows.addSelectionListener(new SelectionListenerImpl<Resource>(context) {\r
+            @Override\r
+            public void apply(WriteGraph graph, Resource input) throws DatabaseException {\r
+                graph.claimLiteral(input, SysdynResource.getInstance(graph).HistoryDataset_columns, Boolean.FALSE, Bindings.BOOLEAN);\r
+            }\r
+        });\r
+        rows.setSelectionFactory(new ReadFactoryImpl<Resource, Boolean>() {\r
+\r
+            @Override\r
+            public Boolean perform(ReadGraph graph, Resource input) throws DatabaseException {\r
+                return Boolean.FALSE.equals(graph.getPossibleRelatedValue(input, SysdynResource.getInstance(graph).HistoryDataset_columns));\r
+            }\r
+        });\r
+        \r
+        \r
+        // Group container displaying all variables found in the defined range\r
+        Group c = new Group(composite, SWT.NONE);\r
+        c.setText("Variables in range");\r
+        GridDataFactory.fillDefaults().span(1, 4).applyTo(c);\r
+        GridLayoutFactory.fillDefaults().margins(3, 1).spacing(0, 0).applyTo(c);\r
+        \r
+        GraphExplorerComposite explorer = new GraphExplorerComposite(ArrayMap.keys(\r
+                "displaySelectors", "displayFilter").values(false, false), site, c, support, SWT.FULL_SELECTION | SWT.BORDER);\r
+        explorer.setBrowseContexts(SysdynResource.URIs.HistoryDataset_HistoryDatasetVariablesBrowseContext);\r
+        explorer.setInputSource(new SingleSelectionInputSource(Resource.class));\r
+        explorer.finish();\r
+        GridDataFactory.fillDefaults().hint(SWT.DEFAULT,100).grab(true, false).applyTo(explorer);\r
+        \r
+        // Range start \r
+        label = new Label(composite, SWT.NONE);\r
+        GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(label);\r
+        label.setText("Range Start: ");\r
+        \r
+        TrackedText start = new TrackedText(composite, support, SWT.BORDER);\r
+        start.setTextFactory(new StringPropertyFactory(SysdynResource.URIs.HistoryDataset_start));\r
+        start.addModifyListener(new StringPropertyModifier(context, SysdynResource.URIs.HistoryDataset_start));\r
+        GridDataFactory.fillDefaults().applyTo(start.getWidget());\r
+        \r
+        // Range end\r
+        label = new Label(composite, SWT.NONE);\r
+        GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(label);\r
+        label.setText("Range End: ");\r
+        \r
+        TrackedText end = new TrackedText(composite, support, SWT.BORDER);\r
+        end.setTextFactory(new StringPropertyFactory(SysdynResource.URIs.HistoryDataset_end));\r
+        end.addModifyListener(new StringPropertyModifier(context, SysdynResource.URIs.HistoryDataset_end));\r
+        GridDataFactory.fillDefaults().applyTo(end.getWidget());\r
+        \r
+        // Time variable. This variable is used as time values in the history dataset\r
+        label = new Label(composite, SWT.NONE);\r
+        GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(label);\r
+        label.setText("Time variable: ");\r
+        \r
+        TrackedText time = new TrackedText(composite, support, SWT.BORDER);\r
+        time.setTextFactory(new StringPropertyFactory(SysdynResource.URIs.HistoryDataset_timeName));\r
+        time.addModifyListener(new StringPropertyModifier(context, SysdynResource.URIs.HistoryDataset_timeName));\r
+        GridDataFactory.fillDefaults().applyTo(time.getWidget());\r
+        \r
+        \r
+        // Scrolled composite settings\r
+        sc.setContent(composite);\r
+        sc.setMinSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT));\r
+        sc.setExpandHorizontal(true);\r
+        sc.setExpandVertical(true);\r
+\r
+\r
+    }\r
+\r
+    /**\r
+     * Item factory for finding spreadsheets from a model\r
+     * @author Teemu Lempinen\r
+     *\r
+     */\r
+    private class SheetItemFactory extends ReadFactoryImpl<Resource, Map<String,Object>> {\r
+\r
+        @Override\r
+        public Map<String, Object> perform(ReadGraph graph, Resource historyData) throws DatabaseException {\r
+            Layer0 l0 = Layer0.getInstance(graph);\r
+            SimulationResource simu = SimulationResource.getInstance(graph);\r
+            SpreadsheetResource spreadSheet = SpreadsheetResource.getInstance(graph);\r
+\r
+            Resource model = graph.getPossibleObject(historyData, l0.PartOf);\r
+            Resource config = graph.getPossibleObject(model, simu.HasConfiguration);\r
+            Resource book = graph.syncRequest(new PossibleObjectWithType(config, l0.ConsistsOf, spreadSheet.Book));\r
+            Collection<Resource> sheets = graph.syncRequest(new ObjectsWithType(book, l0.ConsistsOf, spreadSheet.Spreadsheet));\r
+\r
+            Map<String, Object> map = new LinkedHashMap<String, Object>();\r
+\r
+            for(Resource sheet : sheets) {\r
+                map.put(NameUtils.getSafeName(graph, sheet), sheet);\r
+            }\r
+            return map;\r
+        }\r
+    };\r
+    \r
+    /**\r
+     * Selection factory for finding the defined sheet name for a history dataset\r
+     * @author Teemu Lempinen\r
+     *\r
+     */\r
+    private class SheetSelectionFactory extends ReadFactoryImpl<Resource, String> {\r
+\r
+        @Override\r
+        public String perform(ReadGraph graph, Resource historyData) throws DatabaseException {\r
+            Resource selectedSheet = graph.getPossibleObject(historyData, SysdynResource.getInstance(graph).HistoryDataset_sheet);\r
+            if(selectedSheet != null) {\r
+                String name = NameUtils.getSafeName(graph, selectedSheet);\r
+                return name;// Return the selected sheet, if it exits\r
+            } else {\r
+                return null;\r
+            }\r
+        }\r
+    };\r
+\r
+    /**\r
+     * Listener for listening sheet selections in sheet combo\r
+     * @author Teemu Lempinen\r
+     *\r
+     */\r
+    private class SheetModifyListener implements TextModifyListener, Widget {\r
+\r
+        private ISessionContext context;\r
+        private Object lastInput = null;\r
+\r
+        @Override\r
+        public void modifyText(TrackedModifyEvent e) {\r
+\r
+            Combo combo = (Combo)e.getWidget();\r
+            String textValue = combo.getText();\r
+            Map<?,?> data = (Map<?, ?>) combo.getData();\r
+            if(data == null) return;\r
+            final Resource value = (Resource) data.get(textValue);\r
+            if(value == null) return;\r
+            final Object input = lastInput;\r
+\r
+            try {\r
+                context.getSession().syncRequest(new WriteRequest() {\r
+                    @Override\r
+                    public void perform(WriteGraph graph) throws DatabaseException {\r
+\r
+                        Resource resource = (Resource) ISelectionUtils.filterSingleSelection((ISelection)input, Resource.class);\r
+                        SysdynResource sr = SysdynResource.getInstance(graph);\r
+                        graph.deny(resource, sr.HistoryDataset_sheet);\r
+                        graph.claim(resource, SysdynResource.getInstance(graph).HistoryDataset_sheet, value);\r
+                    }\r
+\r
+                });\r
+            } catch (DatabaseException e1) {\r
+                e1.printStackTrace();\r
+            }\r
+        }\r
+\r
+        @Override\r
+        public void setInput(ISessionContext context, Object parameter) {\r
+            this.context = context;\r
+            lastInput = parameter;\r
+        }\r
+    }\r
+}\r
index a3d6b1875c27337642ab754318c7bfa063bdf0c7..e55f2acd95416348dc516a476217d5642a6b70ce 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************\r
- * Copyright (c) 2010, 2011 Association for Decentralized Information Management in\r
+ * Copyright (c) 2010, 2012 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
@@ -12,6 +12,9 @@
 package org.simantics.sysdyn.ui.properties;\r
 \r
 \r
+import java.util.HashMap;\r
+import java.util.Map;\r
+\r
 import org.eclipse.jface.layout.GridDataFactory;\r
 import org.eclipse.jface.layout.GridLayoutFactory;\r
 import org.eclipse.swt.SWT;\r
@@ -19,8 +22,15 @@ import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Label;\r
 import org.eclipse.ui.IWorkbenchSite;\r
 import org.simantics.browsing.ui.swt.widgets.StringPropertyFactory;\r
+import org.simantics.browsing.ui.swt.widgets.TrackedCombo;\r
 import org.simantics.browsing.ui.swt.widgets.TrackedText;\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.db.management.ISessionContext;\r
 import org.simantics.layer0.Layer0;\r
 import org.simantics.sysdyn.SysdynResource;\r
@@ -29,6 +39,7 @@ import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyFactor
 import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyModifier;\r
 import org.simantics.sysdyn.ui.properties.widgets.factories.VariableNamePropertyModifier;\r
 import org.simantics.sysdyn.ui.properties.widgets.factories.VariableNameValidator;\r
+import org.simantics.utils.datastructures.Pair;\r
 import org.simantics.utils.ui.validators.DoubleValidator;\r
 \r
 /**\r
@@ -53,7 +64,7 @@ public class InputVariableTab  extends LabelPropertyTabContributor {
         GridDataFactory.fillDefaults().grab(true, false).applyTo(nameText.getWidget());\r
 \r
         Composite defaultValueComposite = new Composite(composite, SWT.NONE);\r
-        GridDataFactory.fillDefaults().grab(false, true).applyTo(defaultValueComposite);\r
+        GridDataFactory.fillDefaults().grab(false, false).applyTo(defaultValueComposite);\r
         GridLayoutFactory.fillDefaults().numColumns(2).applyTo(defaultValueComposite);\r
         \r
         Label label = new Label(defaultValueComposite, SWT.NULL);\r
@@ -65,6 +76,68 @@ public class InputVariableTab  extends LabelPropertyTabContributor {
         defaultValue.setInputValidator(new DoubleValidator());\r
         GridDataFactory.fillDefaults().grab(true, false).applyTo(defaultValue.getWidget());\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
+        \r
+        label = new Label(variabilityComposite, SWT.NULL);\r
+        label.setText("Variability:");\r
+        \r
+        TrackedCombo variability = new TrackedCombo(variabilityComposite, support, SWT.DROP_DOWN | SWT.BORDER | SWT.READ_ONLY);\r
+        GridDataFactory.fillDefaults().grab(true, false).applyTo(variability.getWidget());\r
+        setVariabilityFactories(variability);\r
+        \r
         new IsOutputWidget(composite, support, SWT.NULL);\r
     }\r
+    \r
+    /**\r
+     * set item, selection and modify properties for variability combo\r
+     * @param variability\r
+     */\r
+    private void setVariabilityFactories(TrackedCombo variability) {\r
+        variability.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
+                map.put("continuous", "continuous");\r
+                map.put("parameter", "parameter");\r
+                map.put("constant", "constant");\r
+                return map;\r
+            }\r
+        });\r
+        \r
+        variability.setSelectionFactory(new ReadFactoryImpl<Resource, String>() {\r
+            \r
+            public Object getIdentity(Object inputContents) {\r
+                return new Pair<Object, Class<?>>(inputContents, getClass());\r
+            }\r
+\r
+            @Override\r
+            public String perform(ReadGraph graph, final Resource input) throws DatabaseException {\r
+                SysdynResource sr = SysdynResource.getInstance(graph);\r
+                String variability = graph.getPossibleRelatedValue(input, sr.Variable_variability);\r
+                if(variability == null || variability.isEmpty())\r
+                    return "continuous";\r
+                else \r
+                    return variability;\r
+            }\r
+        });\r
+        \r
+        variability.addModifyListener(new ComboModifyListenerImpl<Resource>() {\r
+\r
+            @Override\r
+            public void applyText(WriteGraph graph, Resource input, String text) throws DatabaseException {\r
+                SysdynResource sr = SysdynResource.getInstance(graph);\r
+                String variability = text;\r
+                if(text.equals("continuous"))\r
+                    variability = "";\r
+                \r
+                if(variability != null) {\r
+                    graph.claimLiteral(input, sr.Variable_variability, variability);\r
+                }\r
+            }\r
+            \r
+        });\r
+    }\r
 }\r
index d26e366817b21fdf1960ef101ed46b5bc3863cbf..35f0299ff9004320b2a9121184e6e17e2a0da593 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************\r
- * Copyright (c) 2010, 2011 Association for Decentralized Information Management in\r
+ * Copyright (c) 2010, 2012 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
@@ -246,6 +246,15 @@ public class ResourceSelectionProcessor implements SelectionProcessor<Object, Re
                                 r,\r
                                 "Experiment Properties"));\r
 \r
+            // History data\r
+            if (backend.isInstanceOf(r, sr.HistoryDataset))\r
+                return Collections.singleton(\r
+                        new ComparableTabContributor(\r
+                                new HistoryDataTab(),\r
+                                0,\r
+                                r,\r
+                                "History Data Properties"));\r
+            \r
             // Saved simulation result\r
             if (backend.isInstanceOf(r, sr.Result))\r
                 return Collections.singleton(\r
diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/FontSelectionComposite.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/FontSelectionComposite.java
new file mode 100644 (file)
index 0000000..fd3b4a3
--- /dev/null
@@ -0,0 +1,668 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2012 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.widgets;\r
+\r
+import java.awt.Font;\r
+import java.awt.GraphicsEnvironment;\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+import java.util.Locale;\r
+import java.util.TreeMap;\r
+\r
+import org.eclipse.core.runtime.ListenerList;\r
+import org.eclipse.jface.layout.GridDataFactory;\r
+import org.eclipse.jface.layout.GridLayoutFactory;\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.events.KeyEvent;\r
+import org.eclipse.swt.events.KeyListener;\r
+import org.eclipse.swt.events.ModifyEvent;\r
+import org.eclipse.swt.events.ModifyListener;\r
+import org.eclipse.swt.events.SelectionEvent;\r
+import org.eclipse.swt.events.SelectionListener;\r
+import org.eclipse.swt.graphics.FontData;\r
+import org.eclipse.swt.graphics.Point;\r
+import org.eclipse.swt.graphics.Rectangle;\r
+import org.eclipse.swt.widgets.Composite;\r
+import org.eclipse.swt.widgets.Event;\r
+import org.eclipse.swt.widgets.Listener;\r
+import org.eclipse.swt.widgets.ScrollBar;\r
+import org.eclipse.swt.widgets.Table;\r
+import org.eclipse.swt.widgets.TableColumn;\r
+import org.eclipse.swt.widgets.TableItem;\r
+import org.eclipse.swt.widgets.Text;\r
+import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
+import org.simantics.db.management.ISessionContext;\r
+\r
+/**\r
+ * Composite for displaying font selection tools. By default, the composite contains\r
+ * font family, font style and font size.\r
+ * \r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
+public class FontSelectionComposite extends Composite {\r
+\r
+\r
+    protected Text fontName, fontStyle, fontSize;\r
+    protected ArrayList<String> familyIndex = new ArrayList<String>();\r
+    protected TreeMap<String, ArrayList<Font>> fonts = getFonts(familyIndex);\r
+    protected Table fontFamilyTable, fontStyleTable, fontSizeTable;\r
+    protected String[] sizes = new String[] {"8", "9", "10", "11", "12", "14", "16", "18", "20", "24", "26", "28", "36", "48", "72"};\r
+\r
+    private ListenerList modifyListeners;\r
+\r
+\r
+    /**\r
+     * Gets all available fonts\r
+     * @param familyIndex Optional list for indexing font families\r
+     * @return Tree where key is font family name and object a list of fonts belonging to that family\r
+     */\r
+    private static TreeMap<String, ArrayList<Font>> getFonts(ArrayList<String> familyIndex) {\r
+        TreeMap<String, ArrayList<Font>> fonts = new TreeMap<String, ArrayList<Font>>();\r
+\r
+        GraphicsEnvironment gEnv = GraphicsEnvironment\r
+                .getLocalGraphicsEnvironment();\r
+        Font allFonts[] = gEnv.getAllFonts();\r
+\r
+        for(Font font : allFonts) {\r
+            String family = font.getFamily(Locale.ROOT);\r
+            if(!fonts.containsKey(family)) {\r
+                if(familyIndex != null)\r
+                    familyIndex.add(family);\r
+                fonts.put(family, new ArrayList<Font>());\r
+            }\r
+\r
+            boolean add = true;\r
+            for(Font f : fonts.get(family)) {\r
+                if(f.getFontName().equals(font.getFontName())) {\r
+                    add = false;\r
+                    break;\r
+                }\r
+            }\r
+\r
+            if(add)\r
+                fonts.get(family).add(font);\r
+        }\r
+        return fonts;\r
+    }\r
+\r
+    /**\r
+     * Composite containing components for selecting a font\r
+     * \r
+     * @param parent Parent composite\r
+     * @param context {@link ISessionContext}\r
+     * @param support {@link WidgetSupport}\r
+     * @param style SWT style\r
+     */\r
+    public FontSelectionComposite(Composite parent, ISessionContext context, WidgetSupport support, int style) {\r
+        super(parent, style);\r
+\r
+        modifyListeners = new ListenerList();\r
+\r
+        GridLayoutFactory.fillDefaults().numColumns(3).applyTo(this);\r
+\r
+        /*\r
+         * Two-row layout. First row consists of editable text boxes,\r
+         * second row consists of tables containing possible options\r
+         */\r
+\r
+        // First row\r
+        fontName = new Text(this, SWT.BORDER);\r
+        GridDataFactory.fillDefaults().applyTo(fontName);\r
+\r
+        fontStyle = new Text(this, SWT.BORDER);\r
+        GridDataFactory.fillDefaults().applyTo(fontStyle);\r
+\r
+        fontSize = new Text(this, SWT.BORDER);\r
+        GridDataFactory.fillDefaults().applyTo(fontSize);\r
+\r
+        // Second row\r
+        fontFamilyTable = new Table (this, SWT.VIRTUAL | SWT.BORDER | SWT.FULL_SELECTION);\r
+        fontFamilyTable.setLinesVisible (false);\r
+        fontFamilyTable.setHeaderVisible (false);\r
+        GridDataFactory.fillDefaults().hint(SWT.DEFAULT, 100).applyTo(fontFamilyTable);\r
+        fontFamilyTable.setItemCount(familyIndex.size());\r
+        TableColumn column = new TableColumn (fontFamilyTable, SWT.NONE);\r
+        column.setWidth(200);\r
+\r
+\r
+        fontStyleTable = new Table (this, SWT.BORDER | SWT.FULL_SELECTION);\r
+        fontStyleTable.setLinesVisible (false);\r
+        fontStyleTable.setHeaderVisible (false);\r
+        GridDataFactory.fillDefaults().hint(100, 100).applyTo(fontStyleTable);\r
+        column = new TableColumn (fontStyleTable, SWT.NONE);\r
+        setFontStyleTableWidth();\r
+\r
+\r
+\r
+        fontSizeTable = new Table (this, SWT.VIRTUAL | SWT.BORDER | SWT.FULL_SELECTION);\r
+        fontSizeTable.setLinesVisible (false);\r
+        fontSizeTable.setHeaderVisible (false);\r
+        GridDataFactory.fillDefaults().hint(SWT.DEFAULT, 100).applyTo(fontSizeTable);\r
+        column = new TableColumn (fontSizeTable, SWT.NONE);\r
+        column.setWidth(70);\r
+        for(String size : sizes) {\r
+            TableItem item = new TableItem(fontSizeTable, SWT.NONE);\r
+            item.setText(0, size);\r
+        }\r
+\r
+        // Listeners for components\r
+        addFontFamilyListeners();\r
+        addFontStyleListeners();\r
+        addFontSizeListeners();\r
+    }\r
+\r
+\r
+    /**\r
+     * Set controls to display given font\r
+     */\r
+    public void setFont(Font font, boolean notify) {\r
+        Object[] listeners = new Object[0];\r
+        if(!notify) {\r
+            listeners = modifyListeners.getListeners();\r
+            for(Object listener : listeners)\r
+                modifyListeners.remove(listener);\r
+        }\r
+\r
+        String fontFamily = font.getFamily(Locale.ROOT);\r
+        String fontName = font.getFontName(Locale.ROOT);\r
+        this.fontName.setText(fontFamily);\r
+        this.fontFamilyTable.setTopIndex(this.fontFamilyTable.getSelectionIndex());\r
+\r
+        String style = "Regular";\r
+        if(fontName.length() > fontFamily.length())\r
+            style = fontName.substring(fontFamily.length() + 1);\r
+        this.fontStyle.setText(style);\r
+\r
+        int size = font.getSize();\r
+        fontSize.setText("" + size);\r
+        \r
+        if(!notify) {\r
+            for(Object listener : listeners)\r
+                modifyListeners.add(listener);\r
+        }\r
+    }\r
+\r
+    /**\r
+     * Get the AWT font defined in this composite\r
+     * @return AWT font\r
+     */\r
+    public Font getAWTFont() {\r
+        String family = fontName.getText();\r
+        String style = fontStyle.getText();\r
+        if(style.equals("Regular"))\r
+            style = null;\r
+\r
+        String name = family + (style != null ? " " + style : "");\r
+\r
+        int size = 10;\r
+        try {\r
+            size = Integer.parseInt(fontSize.getText());\r
+        } catch (NumberFormatException e) {\r
+        }\r
+\r
+        if(name != null && name.length() > 0)\r
+            return new Font(name, 0, size);\r
+        else\r
+            return null;\r
+    }\r
+\r
+\r
+    /**\r
+     * Adds listeners for font family name text and table\r
+     */\r
+    protected void addFontFamilyListeners() {\r
+\r
+        // Font name modify listener\r
+        fontName.addModifyListener(new ModifyListener() {\r
+\r
+            @Override\r
+            public void modifyText(ModifyEvent e) {\r
+                Text text = (Text) e.widget;\r
+                String name = text.getText();\r
+                fontFamilyTextModified(name, false);\r
+            }\r
+        });\r
+\r
+        // Font name key listener for auto-completion\r
+        fontName.addKeyListener(new KeyListener() {\r
+\r
+            @Override\r
+            public void keyReleased(KeyEvent e) {\r
+            }\r
+\r
+            @Override\r
+            public void keyPressed(KeyEvent e) {\r
+                if ((e.character == ' ') && ((e.stateMask & SWT.CTRL) != 0) ) {\r
+                    fontFamilyTextModified(fontName.getText(), true);\r
+                    e.doit = false;\r
+                } else if(e.keyCode == SWT.CR || e.keyCode == SWT.LF || e.keyCode == SWT.KEYPAD_CR) {\r
+                    fontChanged();\r
+                }\r
+            }\r
+        });\r
+        \r
+        // Call listener when editing has ended\r
+        fontName.addListener(SWT.FocusOut, new Listener() {\r
+            public void handleEvent(Event e) {\r
+                fontChanged();\r
+            }\r
+        });\r
+\r
+        // Font family data listener for lazy initialization of the table\r
+        fontFamilyTable.addListener (SWT.SetData, new Listener () {\r
+            public void handleEvent (Event event) {\r
+                TableItem item = (TableItem) event.item;\r
+                int index = fontFamilyTable.indexOf (item);\r
+\r
+                String family = familyIndex.get(index);\r
+                item.setText (family);\r
+\r
+                Font font = fonts.get(family).get(0);\r
+                if(font.canDisplay('a')) {\r
+                    FontData fontData =  toSwtFontData(font, 10);\r
+                    org.eclipse.swt.graphics.Font swtFont = new org.eclipse.swt.graphics.Font(item.getDisplay(), fontData);\r
+                    item.setFont(swtFont);\r
+                }\r
+            }\r
+        });\r
+\r
+\r
+        // Updates selected font to font name text\r
+        fontFamilyTable.addSelectionListener(new SelectionListener() {\r
+\r
+            @Override\r
+            public void widgetSelected(SelectionEvent e) {\r
+                TableItem[] selection = fontFamilyTable.getSelection();\r
+\r
+                if(selection.length > 0) {\r
+                    String family = selection[0].getText();\r
+                    fontName.setText(family);\r
+                    fontChanged();\r
+                }\r
+            }\r
+\r
+            @Override\r
+            public void widgetDefaultSelected(SelectionEvent e) {\r
+            }\r
+        });\r
+\r
+        /*\r
+         *  Forces focus to font name texts and starts editing it, \r
+         *  if user presses a letter when focus is in font family table\r
+         */\r
+        fontFamilyTable.addKeyListener(new KeyListener() {\r
+            @Override\r
+            public void keyReleased(KeyEvent e) {\r
+            }\r
+\r
+            @Override\r
+            public void keyPressed(KeyEvent e) {\r
+                if(Character.isLetter(e.character)) {\r
+                    fontName.forceFocus();\r
+                    fontName.setTextChars(new char[] {e.character});\r
+                    fontName.setSelection(1, 1);\r
+                }\r
+            }\r
+        });\r
+    }\r
+\r
+    /**\r
+     * Implements interactions between font name text and font family table, when \r
+     * the text in font name text has been changed.\r
+     * @param name New name\r
+     * @param autoComplete Has autocomplete been called\r
+     */\r
+    protected void fontFamilyTextModified(String name, boolean autoComplete) {\r
+        if(name.isEmpty())\r
+            return;\r
+        for(int i = 0; i < familyIndex.size(); i++) {\r
+            String family = familyIndex.get(i);\r
+            if(family.equals(name)) {\r
+                //complete match\r
+                fontFamilyTable.select(i);\r
+                selectFontFamily(name);\r
+                break;\r
+            } else if(family.toLowerCase().equals(name.toLowerCase())) {\r
+                // Wrong case but correct name\r
+                fontName.setText(family);\r
+                fontName.setSelection(family.length(), family.length());\r
+                fontFamilyTable.setTopIndex(i);\r
+                fontChanged();\r
+                break;\r
+            } else if(family.toLowerCase().startsWith(name.toLowerCase())) {\r
+                if(autoComplete) {\r
+                    // Fill in the rest of the name\r
+                    fontName.setText(family);\r
+                    fontName.setSelection(family.length());\r
+                    fontChanged();\r
+                    // The beginning is correct, help user by displaying the nearest name\r
+                } else { \r
+                    fontFamilyTable.setTopIndex(i);\r
+                }\r
+                break;\r
+            }\r
+        }\r
+    }\r
+\r
+\r
+    /**\r
+     * Adds listeners for font style text and table\r
+     */\r
+    protected void addFontStyleListeners() {\r
+\r
+        // Font style modify listener\r
+        fontStyle.addModifyListener(new ModifyListener() {\r
+\r
+            @Override\r
+            public void modifyText(ModifyEvent e) {\r
+                Text text = (Text) e.widget;\r
+                String name = text.getText();\r
+                fontStyleTextModified(name, false);\r
+            }\r
+        });\r
+\r
+        // Font style key listener for auto-complete\r
+        fontStyle.addKeyListener(new KeyListener() {\r
+\r
+            @Override\r
+            public void keyReleased(KeyEvent e) {\r
+            }\r
+\r
+            @Override\r
+            public void keyPressed(KeyEvent e) {\r
+                if ((e.character == ' ') && ((e.stateMask & SWT.CTRL) != 0) ) {\r
+                    fontStyleTextModified(fontStyle.getText(), true);\r
+                    e.doit = false;\r
+                } else if(e.keyCode == SWT.CR || e.keyCode == SWT.LF || e.keyCode == SWT.KEYPAD_CR) {\r
+                    fontChanged();\r
+                }\r
+            }\r
+        });\r
+\r
+        // Update selected style to font style text\r
+        fontStyleTable.addSelectionListener(new SelectionListener() {\r
+\r
+            @Override\r
+            public void widgetSelected(SelectionEvent e) {\r
+                TableItem[] selection = fontStyleTable.getSelection();\r
+\r
+                if(selection.length > 0) {\r
+                    String family = selection[0].getText();\r
+                    fontStyle.setText(family);\r
+                    fontChanged();\r
+                }\r
+            }\r
+\r
+            @Override\r
+            public void widgetDefaultSelected(SelectionEvent e) {\r
+            }\r
+        });\r
+\r
+        /*\r
+         *  Forces focus to font style text and starts editing it, \r
+         *  if user presses a letter when focus is in font style table\r
+         */\r
+        fontStyleTable.addKeyListener(new KeyListener() {\r
+            @Override\r
+            public void keyReleased(KeyEvent e) {\r
+            }\r
+\r
+            @Override\r
+            public void keyPressed(KeyEvent e) {\r
+                if(Character.isLetter(e.character)) {\r
+                    fontStyle.forceFocus();\r
+                    fontStyle.setTextChars(new char[] {e.character});\r
+                    fontStyle.setSelection(1, 1);\r
+                    e.doit = false;\r
+                } else if(e.keyCode == SWT.CR || e.keyCode == SWT.LF || e.keyCode == SWT.KEYPAD_CR) {\r
+                    fontChanged();\r
+                }\r
+            }\r
+        });\r
+    }\r
+\r
+    /**\r
+     * Handles interactions between font style text and font style table, when\r
+     * font style text has been changed\r
+     * \r
+     * @param name New text for font style \r
+     * @param autoComplete is auto-completion used\r
+     */\r
+    protected void fontStyleTextModified(String name, boolean autoComplete) {\r
+        if(name.isEmpty())\r
+            return;\r
+\r
+        for(int i = 0; i < fontStyleTable.getItemCount(); i++) {\r
+            TableItem item = fontStyleTable.getItem(i);\r
+            String style = item.getText();\r
+\r
+            if(style.equals(name)) {\r
+                //complete match\r
+                fontStyleTable.select(i);\r
+                break;\r
+            } else if(style.toLowerCase().equals(name.toLowerCase())) {\r
+                // Wrong case, correct style. -> fix the case\r
+                fontStyle.setText(style);\r
+                fontStyle.setSelection(style.length());\r
+                fontStyleTable.setTopIndex(i);\r
+                fontChanged();\r
+                break;\r
+            } else if(style.toLowerCase().startsWith(name.toLowerCase())) {\r
+                // The beginning of the word is correct\r
+                fontStyleTable.setTopIndex(i);\r
+                if(autoComplete) {\r
+                    // Fill in the rest of the name\r
+                    fontStyle.setText(style);\r
+                    fontStyle.setSelection(style.length());\r
+                    fontChanged();\r
+                    // The beginning is correct, help user by displaying the nearest name\r
+                } else { \r
+                    fontStyleTable.setTopIndex(i);\r
+                }\r
+                break;\r
+            }\r
+        }\r
+    }\r
+\r
+\r
+    /**\r
+     * Listeners for font size text and font size table\r
+     */\r
+    protected void addFontSizeListeners() {\r
+\r
+        // Select an item from size table, if there is a matching item \r
+        fontSize.addKeyListener(new KeyListener() {\r
+\r
+            @Override\r
+            public void keyReleased(KeyEvent e) {\r
+                Text text = (Text) e.widget;\r
+                String size = text.getText();\r
+\r
+                for(int i = 0; i < sizes.length; i++) {\r
+                    if(sizes[i].equals(size)) {\r
+                        fontSizeTable.select(i);\r
+                        fontSizeTable.setTopIndex(i);\r
+                        fontChanged();\r
+                        break;\r
+                    }\r
+                }  \r
+            }\r
+\r
+            @Override\r
+            public void keyPressed(KeyEvent e) {\r
+            }\r
+        });\r
+\r
+        // Change the text in size text according to the selection in size table\r
+        fontSizeTable.addSelectionListener(new SelectionListener() {\r
+\r
+            @Override\r
+            public void widgetSelected(SelectionEvent e) {\r
+                fontSize.setText(fontSizeTable.getSelection()[0].getText());\r
+                fontChanged();\r
+            }\r
+\r
+            @Override\r
+            public void widgetDefaultSelected(SelectionEvent e) {\r
+            }\r
+        });\r
+\r
+        // Change focus from table to text, if user starts to write a number \r
+        fontSizeTable.addKeyListener(new KeyListener() {\r
+\r
+            @Override\r
+            public void keyReleased(KeyEvent e) { }\r
+\r
+            @Override\r
+            public void keyPressed(KeyEvent e) {\r
+                if(Character.isDigit(e.character)) {\r
+                    fontSize.setTextChars(new char[]{e.character});\r
+                    fontSize.setSelection(1);\r
+                    fontSize.forceFocus();\r
+                    e.doit = false;\r
+                }\r
+            }\r
+        });\r
+\r
+    }\r
+\r
+    /**\r
+     * Creates the contents of fontStyleTable according to the selected font family \r
+     * @param family Selected font family\r
+     */\r
+    protected void selectFontFamily(String family) {\r
+        String old = fontStyle.getText();\r
+        String selection = null, optionalSelection = null;\r
+\r
+        // Clear the table\r
+        fontStyleTable.removeAll();\r
+\r
+        if(familyIndex.indexOf(family) > -1) {\r
+            for(int i = 0; i < fonts.get(family).size(); i++) {\r
+                Font font = fonts.get(family).get(i);\r
+\r
+                String name = font.getFontName(Locale.ROOT);\r
+\r
+                // Style is "Regular", unless otherwise defined\r
+                String style = "Regular";\r
+                if(name.length() > family.length())\r
+                    style = name.substring(family.length() + 1);\r
+\r
+                // If previous font was bold, try to conserve the style\r
+                if(old.equals(style))\r
+                    selection  = style;\r
+                else if((!old.isEmpty() && style.contains(old)) || optionalSelection == null)\r
+                    optionalSelection = style;\r
+\r
+                TableItem item = new TableItem (fontStyleTable, SWT.NONE);\r
+                item.setText (0, style);\r
+                item.setData(font);\r
+\r
+                // If the font is not symbolic, use the font in the created item\r
+                if(font.canDisplay('a')) {\r
+                    FontData fontData = toSwtFontData(font, 10);\r
+                    org.eclipse.swt.graphics.Font swtFont = new org.eclipse.swt.graphics.Font(item.getDisplay(), fontData);\r
+                    item.setFont(swtFont);\r
+                }\r
+            }\r
+            fontStyleTable.setItemCount(fonts.get(family).size());\r
+\r
+            if(selection == null)\r
+                selection = optionalSelection;\r
+\r
+            fontStyle.setText(selection);\r
+            fontStyle.setSelection(selection.length(), selection.length());\r
+\r
+            setFontStyleTableWidth();\r
+        }\r
+    }\r
+\r
+    /**\r
+     * Set width for style table column. Width can change, if scroll bar appears \r
+     */\r
+    protected void setFontStyleTableWidth() {\r
+        Rectangle area = fontStyleTable.getClientArea();\r
+        Point size = fontStyleTable.computeSize(SWT.DEFAULT, SWT.DEFAULT);\r
+        ScrollBar vBar = fontStyleTable.getVerticalBar();\r
+        int width = 100;\r
+        if (area.height == 0 || size.y <= area.height) {\r
+            Point vBarSize = vBar.getSize();\r
+            width += vBarSize.x;\r
+        }\r
+        fontStyleTable.getColumn(0).setWidth(width);\r
+    }\r
+\r
+\r
+    /**\r
+     * Builds SWT FontData from AWT font. Simple conversion.\r
+     * \r
+     * @param font AWT font\r
+     * @param height Height for the created data (or -1 if inherited directly from awt font, size matching not guaranteed)\r
+     * @return\r
+     */\r
+    protected static FontData toSwtFontData(Font font, int height) {\r
+        FontData fontData = new FontData();\r
+        fontData.setName(font.getFontName());\r
+        fontData.setStyle(font.getStyle());\r
+        fontData.setHeight(height > 0 ? height : font.getSize());\r
+        return fontData;\r
+    }\r
+\r
+\r
+    public void addFontModifiedListener(FontChangeListener listener) {\r
+        modifyListeners.add(listener);\r
+    }\r
+\r
+    public void removeFontModifiedListener(FontChangeListener listener) {\r
+        modifyListeners.remove(listener);\r
+    }\r
+\r
+    public List<FontChangeListener> getFontModifiedListener() {\r
+        ArrayList<FontChangeListener> listeners = new ArrayList<FontChangeListener>(modifyListeners.size());\r
+        for(Object l : modifyListeners.getListeners())\r
+            listeners.add((FontChangeListener)l);\r
+        return listeners;\r
+    }\r
+\r
+    /**\r
+     * Called when some property of the font definiton has changed.\r
+     * Calls font change listeners.\r
+     */\r
+    protected void fontChanged() {\r
+        Font font = getAWTFont();\r
+        if(font != null) {\r
+            \r
+            int style = 0;\r
+            style |= (font.getFontName(Locale.ROOT).contains("Bold") ? SWT.BOLD : 0);\r
+            style |= (font.getFontName(Locale.ROOT).contains("Italic") ? SWT.ITALIC : 0);\r
+            FontData data = new FontData(font.getFamily(Locale.ROOT), font.getSize(), style);\r
+            org.eclipse.swt.graphics.Font swt = new org.eclipse.swt.graphics.Font(this.getDisplay(), data);\r
+            \r
+            Object[] listenersArray = modifyListeners.getListeners();\r
+            for (int i = 0; i < listenersArray.length; i++) {\r
+                ((FontChangeListener)listenersArray[i]).awtFontChanged(font);\r
+                ((FontChangeListener)listenersArray[i]).swtFontChanged(swt);\r
+            }\r
+        }\r
+    }\r
+\r
+    \r
+\r
+    /**\r
+     * Font change listening interface\r
+     */\r
+    public interface FontChangeListener {\r
+        public void awtFontChanged(Font font);\r
+        public void swtFontChanged(org.eclipse.swt.graphics.Font font);\r
+    }\r
+}\r
diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/historyDataset/VariableChildRule.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/historyDataset/VariableChildRule.java
new file mode 100644 (file)
index 0000000..45b2924
--- /dev/null
@@ -0,0 +1,51 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2012 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.widgets.historyDataset;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+\r
+import org.simantics.browsing.ui.model.children.ChildRule;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.sysdyn.manager.HistoryDatasetUtils;\r
+import org.simantics.sysdyn.ui.properties.HistoryDataTab;\r
+\r
+/**\r
+ * Variable child rule for GE in {@link HistoryDataTab}\r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
+public class VariableChildRule implements ChildRule {\r
+\r
+    @Override\r
+    public boolean isCompatible(Class<?> contentType) {\r
+        return contentType.equals(Resource.class);\r
+    }\r
+\r
+    @Override\r
+    public Collection<?> getChildren(ReadGraph graph, Object parent) throws DatabaseException {\r
+        ArrayList<String> result = new ArrayList<String>();\r
+        if(!(parent instanceof Resource))\r
+            return result;\r
+        result.addAll(HistoryDatasetUtils.getVariableNamesInRange(graph, (Resource)parent));\r
+        return result;\r
+\r
+\r
+    }\r
+\r
+    @Override\r
+    public Collection<?> getParents(ReadGraph graph, Object child) throws DatabaseException {\r
+        return new ArrayList<Resource>();\r
+    }\r
+}\r
diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/historyDataset/VariableLabelRule.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/historyDataset/VariableLabelRule.java
new file mode 100644 (file)
index 0000000..0cb9459
--- /dev/null
@@ -0,0 +1,40 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2012 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.widgets.historyDataset;\r
+\r
+import java.util.Collections;\r
+import java.util.Map;\r
+\r
+import org.simantics.browsing.ui.common.ColumnKeys;\r
+import org.simantics.browsing.ui.model.labels.LabelRule;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.sysdyn.ui.properties.HistoryDataTab;\r
+\r
+/**\r
+ * Variable label rule for GE in {@link HistoryDataTab}\r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
+public class VariableLabelRule implements LabelRule {\r
+\r
+    @Override\r
+    public boolean isCompatible(Class<?> contentType) {\r
+        return contentType.equals(String.class);\r
+    }\r
+\r
+    @Override\r
+    public Map<String, String> getLabel(ReadGraph graph, Object content) throws DatabaseException {\r
+        return Collections.singletonMap(ColumnKeys.SINGLE, (content instanceof String ? (String)content : "No content"));\r
+    }\r
+\r
+}\r
similarity index 58%
rename from stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/dependencies/DependencyView.java
rename to stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/structure/Dependencies.java
index d783c03caa82ecd3270a7f224fc61846fdc8c136..348d098e28b6f5ebe434dfc572d4a5da6eb198bd 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************\r
- * Copyright (c) 2010 Association for Decentralized Information Management in\r
+ * Copyright (c) 2010, 2012 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
@@ -9,7 +9,7 @@
  * Contributors:\r
  *     VTT Technical Research Centre of Finland - initial API and implementation\r
  *******************************************************************************/\r
-package org.simantics.sysdyn.ui.dependencies;\r
+package org.simantics.sysdyn.ui.structure;\r
 \r
 import java.util.Set;\r
 \r
@@ -22,6 +22,8 @@ import org.eclipse.jface.layout.GridLayoutFactory;
 import org.eclipse.jface.viewers.ISelection;\r
 import org.eclipse.jface.viewers.IStructuredSelection;\r
 import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.custom.CTabFolder;\r
+import org.eclipse.swt.custom.CTabItem;\r
 import org.eclipse.swt.events.ModifyEvent;\r
 import org.eclipse.swt.events.ModifyListener;\r
 import org.eclipse.swt.events.SelectionAdapter;\r
@@ -31,9 +33,6 @@ import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;\r
 import org.eclipse.swt.widgets.Label;\r
 import org.eclipse.swt.widgets.Spinner;\r
-import org.eclipse.ui.ISelectionListener;\r
-import org.eclipse.ui.IWorkbenchPart;\r
-import org.eclipse.ui.part.ViewPart;\r
 import org.simantics.db.Resource;\r
 import org.simantics.db.procedure.Listener;\r
 import org.simantics.graphviz.Graph;\r
@@ -41,37 +40,37 @@ import org.simantics.graphviz.ui.GraphvizComponent;
 import org.simantics.ui.SimanticsUI;\r
 import org.simantics.utils.ui.ISelectionUtils;\r
 \r
-public class DependencyView extends ViewPart {\r
-\r
+public class Dependencies extends CTabItem {\r
+    \r
     private GraphvizComponent component;\r
-    private boolean disposed, isInverted = false;\r
+    private boolean isInverted = false;\r
     private Button bButton, fButton;\r
     private Resource currentSelection;\r
     private int levels = 3;\r
-    private ISelectionListener selectionListener;\r
-    private Composite baseComposite;\r
+    private GraphListener graphListener;\r
 \r
     static int MAXLEVELS = 4;\r
     static int MINLEVELS = 1;\r
 \r
-    @Override\r
-    public void createPartControl(Composite parent) {\r
-        disposed = false;\r
-        GridLayoutFactory.fillDefaults().margins(3, 3).applyTo(parent);\r
-        baseComposite = new Composite(parent, \r
-                SWT.NO_BACKGROUND | SWT.EMBEDDED);\r
-        GridLayoutFactory.fillDefaults().applyTo(baseComposite);\r
-        GridDataFactory.fillDefaults().grab(true, true).applyTo(baseComposite);\r
+    public Dependencies(CTabFolder parent, ISelection selection, int style) {\r
+        super(parent, style);\r
+        \r
+        Composite dependencies = new Composite(parent, SWT.NONE);\r
+        GridDataFactory.fillDefaults().grab(true, true).applyTo(dependencies);\r
+        GridLayoutFactory.fillDefaults().spacing(0,0).applyTo(dependencies);\r
 \r
-        component = new GraphvizComponent(baseComposite, SWT.BORDER);\r
+        component = new GraphvizComponent(dependencies, SWT.NONE);\r
         GridDataFactory.fillDefaults().grab(true, true).applyTo(component);\r
-\r
-        Composite composite = new Composite(parent, SWT.NULL);\r
+        \r
+        Label line = new Label(dependencies, SWT.SEPARATOR | SWT.SHADOW_OUT | SWT.HORIZONTAL);\r
+        GridDataFactory.fillDefaults().grab(true, false).applyTo(line);\r
+        \r
+        Composite composite = new Composite(dependencies, SWT.NONE);\r
         RowLayout layout = new RowLayout();\r
         layout.center = true;\r
         composite.setLayout(layout);\r
 \r
-        Label label = new Label(composite, SWT.NULL);\r
+        Label label = new Label(composite, SWT.NONE);\r
         label.setText("Direction: ");\r
 \r
         bButton = new Button(composite, SWT.RADIO);\r
@@ -92,7 +91,7 @@ public class DependencyView extends ViewPart {
         fButton = new Button(composite, SWT.RADIO);\r
         fButton.setText("Forward");\r
 \r
-        label = new Label(composite, SWT.NULL);\r
+        label = new Label(composite, SWT.NONE);\r
         label.setText("Steps: ");\r
 \r
         Spinner spinner = new Spinner(composite, SWT.BORDER);\r
@@ -118,20 +117,15 @@ public class DependencyView extends ViewPart {
 \r
             }\r
         });\r
-\r
-        drawSelection(getSite().getWorkbenchWindow().getSelectionService().getSelection());\r
-\r
-        selectionListener = new ISelectionListener() {\r
-\r
-            @Override\r
-            public void selectionChanged(IWorkbenchPart part, ISelection selection) {\r
-                drawSelection(selection);\r
-            }\r
-        };    \r
-        getSite().getWorkbenchWindow().getSelectionService().addPostSelectionListener(selectionListener);\r
+        \r
+        drawSelection(selection);\r
+        \r
+        this.setText("Dependencies");\r
+        this.setControl(dependencies);\r
     }\r
 \r
-    private void drawSelection(ISelection selection) {\r
+\r
+    public void drawSelection(ISelection selection) {\r
         if(selection == null || selection.isEmpty())\r
             return;\r
         if(selection instanceof IStructuredSelection) {                    \r
@@ -149,54 +143,46 @@ public class DependencyView extends ViewPart {
     }\r
 \r
     private void readGraph(Resource resource) {\r
-        SimanticsUI.getSession().asyncRequest(new CreateDependencyGraph(\r
-                resource, levels, isInverted),\r
-                new Listener<Graph>() {\r
-\r
-            @Override\r
-            public void exception(Throwable e) {\r
-                e.printStackTrace();\r
-            }\r
-\r
-            @Override\r
-            public void execute(final Graph graph) {\r
-                Job job = new Job("Layout composite graph") {\r
-\r
-                    @Override\r
-                    protected IStatus run(IProgressMonitor monitor) {\r
-                        if(!isDisposed()) {\r
-                            component.setGraph(graph, "dot");\r
-                            component.fit();                            \r
-                        }\r
-                        return Status.OK_STATUS;\r
-                    }\r
-                };\r
-                job.schedule();\r
-            }\r
-\r
-            @Override\r
-            public boolean isDisposed() {\r
-                return disposed;\r
-            }\r
-        });\r
+        if(graphListener != null)\r
+            graphListener.dispose();\r
+        \r
+        graphListener = new GraphListener();\r
+        SimanticsUI.getSession().asyncRequest(new DependencyGraphRequest(\r
+                resource, levels, isInverted), graphListener);\r
     }\r
 \r
-\r
-    @Override\r
-    public void setFocus() {\r
-        if(baseComposite != null && !baseComposite.isDisposed()) {\r
-            baseComposite.setFocus();\r
-            component.setFocus();\r
+    private class GraphListener implements Listener<Graph> {\r
+        \r
+        private boolean disposed = false;\r
+        \r
+        public void dispose() {\r
+            disposed = true;\r
+        }\r
+        \r
+        @Override\r
+        public void exception(Throwable e) {\r
+            e.printStackTrace();\r
         }\r
-    }\r
-\r
 \r
+        @Override\r
+        public void execute(final Graph graph) {\r
+            Job job = new Job("Loading dependencies graph") {\r
 \r
+                @Override\r
+                protected IStatus run(IProgressMonitor monitor) {\r
+                    if(!isDisposed()) {\r
+                        component.setGraph(graph, "dot");\r
+                        component.fit();                            \r
+                    }\r
+                    return Status.OK_STATUS;\r
+                }\r
+            };\r
+            job.schedule();\r
+        }\r
 \r
-    @Override\r
-    public void dispose() {\r
-        super.dispose();\r
-        getSite().getWorkbenchWindow().getSelectionService().removePostSelectionListener(selectionListener);\r
-        disposed = true;\r
+        @Override\r
+        public boolean isDisposed() {\r
+            return disposed;\r
+        }\r
     }\r
 }\r
similarity index 76%
rename from stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/dependencies/CreateDependencyGraph.java
rename to stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/structure/DependencyGraphRequest.java
index 586117b08303d519131e0e558be305d06fa0ce53..5864b912afb6b007730e1012cea40d8ccbda8041 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************\r
- * Copyright (c) 2010 Association for Decentralized Information Management in\r
+ * Copyright (c) 2010, 2012 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
@@ -9,7 +9,7 @@
  * Contributors:\r
  *     VTT Technical Research Centre of Finland - initial API and implementation\r
  *******************************************************************************/\r
-package org.simantics.sysdyn.ui.dependencies;\r
+package org.simantics.sysdyn.ui.structure;\r
 \r
 import java.util.ArrayList;\r
 import java.util.Collection;\r
@@ -29,14 +29,28 @@ import org.simantics.layer0.Layer0;
 import org.simantics.modeling.ModelingResources;\r
 import org.simantics.sysdyn.SysdynResource;\r
 \r
-public class CreateDependencyGraph implements Read<Graph> {\r
+/**\r
+ * Builds a graph of the dependencies of a selected variable\r
+ * \r
+ * \r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
+public class DependencyGraphRequest implements Read<Graph> {\r
 \r
        Resource root;\r
        HashMap<Resource, Node> nodes;\r
        boolean isInverted;\r
        int levels;\r
 \r
-       public CreateDependencyGraph(Resource root, int levels, boolean isInverted) {\r
+       /**\r
+        * Builds a graph of the dependencies of a selected variable\r
+        * \r
+        * @param root Variable from which to find dependencies\r
+        * @param levels How many steps of dependencies are calculated from the variable\r
+        * @param isInverted true => variables that affect root; false => variables that are affected by root \r
+        */\r
+       public DependencyGraphRequest(Resource root, int levels, boolean isInverted) {\r
                this.root = root;\r
                this.isInverted = isInverted;    \r
                this.levels = levels;\r
@@ -69,6 +83,13 @@ public class CreateDependencyGraph implements Read<Graph> {
                return graph;\r
        }\r
 \r
+       /**\r
+        * Create a root node and set appearance settings for it\r
+        * @param g ReadGraph\r
+        * @param graph Graphviz graph\r
+        * @param root Root resource\r
+        * @throws DatabaseException\r
+        */\r
        private void setRoot(ReadGraph g, IGraph graph, Resource root) throws DatabaseException {\r
                Node n;\r
                n = new Node(graph, getName(g, root));\r
@@ -79,6 +100,17 @@ public class CreateDependencyGraph implements Read<Graph> {
        }\r
 \r
 \r
+       /**\r
+        * Call for calculating  \r
+        * @param g\r
+        * @param graph\r
+        * @param r\r
+        * @param toDependency\r
+        * @param fromDependency\r
+        * @param connectionType\r
+        * @return\r
+        * @throws DatabaseException\r
+        */\r
        private Collection<Resource> getDependants(ReadGraph g, IGraph graph, Resource r, Resource toDependency, Resource fromDependency, Resource connectionType) throws DatabaseException {\r
                SysdynResource sr = SysdynResource.getInstance(g);\r
 \r
@@ -108,6 +140,7 @@ public class CreateDependencyGraph implements Read<Graph> {
                }\r
                return dependants;\r
        }\r
+       \r
        private Collection<Resource> setDependencies(ReadGraph g, IGraph graph, Resource r) throws DatabaseException{\r
                SysdynResource sr = SysdynResource.getInstance(g);\r
 \r
@@ -128,7 +161,14 @@ public class CreateDependencyGraph implements Read<Graph> {
 \r
                return dependants;\r
        }\r
-\r
+       \r
+       /**\r
+        * Set shape for a node. Rectangle for stocks, ellipse for auxiliaries and rounded rectangle for modules. \r
+        * @param g ReadGraph\r
+        * @param r Resource\r
+        * @param n Node\r
+        * @throws DatabaseException\r
+        */\r
        private void setShape(ReadGraph g, Resource r, Node n) throws DatabaseException {\r
                SysdynResource sr = SysdynResource.getInstance(g);\r
                if(g.isInstanceOf(r, sr.Stock))\r
diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/structure/ModuleStructure.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/structure/ModuleStructure.java
new file mode 100644 (file)
index 0000000..3354f7f
--- /dev/null
@@ -0,0 +1,134 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2012 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.structure;\r
+\r
+import java.util.Set;\r
+\r
+import org.eclipse.core.runtime.IProgressMonitor;\r
+import org.eclipse.core.runtime.IStatus;\r
+import org.eclipse.core.runtime.Status;\r
+import org.eclipse.core.runtime.jobs.Job;\r
+import org.eclipse.jface.layout.GridDataFactory;\r
+import org.eclipse.jface.layout.GridLayoutFactory;\r
+import org.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.jface.viewers.IStructuredSelection;\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.custom.CTabFolder;\r
+import org.eclipse.swt.custom.CTabItem;\r
+import org.eclipse.swt.widgets.Composite;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.procedure.Listener;\r
+import org.simantics.graphviz.Graph;\r
+import org.simantics.graphviz.ui.GraphvizComponent;\r
+import org.simantics.ui.SimanticsUI;\r
+import org.simantics.utils.RunnableWithObject;\r
+import org.simantics.utils.ui.ISelectionUtils;\r
+\r
+/**\r
+ * Tab for displaying hierarchical model structure\r
+ * \r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
+public class ModuleStructure extends CTabItem {\r
+\r
+    private GraphvizComponent component;\r
+    private GraphListener graphListener;\r
+\r
+    \r
+    public ModuleStructure(CTabFolder parent, int style) {\r
+        super(parent, style);\r
+        \r
+        Composite moduleStructure = new Composite(parent, SWT.NONE);\r
+        GridDataFactory.fillDefaults().grab(true, true).applyTo(moduleStructure);\r
+        GridLayoutFactory.fillDefaults().applyTo(moduleStructure);\r
+\r
+        component = new GraphvizComponent(moduleStructure, SWT.NONE);\r
+        GridDataFactory.fillDefaults().grab(true, true).applyTo(component);\r
+        \r
+        this.setText("Model Hierarchy");\r
+        this.setControl(moduleStructure);\r
+\r
+    }\r
+\r
+    /**\r
+     * Draw a graph about the model of the selected resource\r
+     * @param selection\r
+     */\r
+    public void drawSelection(ISelection selection) {\r
+        if(selection == null || selection.isEmpty())\r
+            return;\r
+\r
+        if(selection instanceof IStructuredSelection) {                    \r
+            Object[] els = ((IStructuredSelection) selection).toArray();\r
+            if(els.length == 1) {\r
+                Set<Resource> ress = ISelectionUtils.filterSetSelection(selection, Resource.class);\r
+                if(ress.isEmpty()) return;\r
+                Resource r = (ress.toArray(Resource.NONE))[0];\r
+                if(r != null) {\r
+                    // Read graph for the resource\r
+                    if(graphListener != null)\r
+                        graphListener.dispose(); // Dispose possible previous listener\r
+                    \r
+                    graphListener = new GraphListener();\r
+                    SimanticsUI.getSession().asyncRequest(new ModuleStructureGraphRequest(r), graphListener);\r
+                }\r
+            }\r
+        }           \r
+    }\r
+    \r
+    /**\r
+     * Listener for updating hierarchical model graph\r
+     * @author Teemu Lempinen\r
+     *\r
+     */\r
+    private class GraphListener implements Listener<Graph> {\r
+        private boolean disposed = false;\r
+        \r
+        public void dispose() {\r
+            disposed = true;\r
+        }\r
+        \r
+        @Override\r
+        public void exception(Throwable e) {\r
+            e.printStackTrace();\r
+        }\r
+\r
+        @Override\r
+        public void execute(final Graph graph) {\r
+            Job job = new Job("Loading model structure graph") {\r
+\r
+                @Override\r
+                protected IStatus run(IProgressMonitor monitor) {\r
+                    if(!isDisposed()) {\r
+                        component.getDisplay().asyncExec(new RunnableWithObject(graph) {\r
+                            \r
+                            @Override\r
+                            public void run() {\r
+                                component.setGraph((Graph)getObject(), "dot");\r
+                                component.fit();    \r
+                            }\r
+                        });\r
+                     \r
+                    }\r
+                    return Status.OK_STATUS;\r
+                }\r
+            };\r
+            job.schedule();\r
+        }\r
+\r
+        @Override\r
+        public boolean isDisposed() {\r
+            return disposed;\r
+        }\r
+    }\r
+}\r
diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/structure/ModuleStructureGraphRequest.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/structure/ModuleStructureGraphRequest.java
new file mode 100644 (file)
index 0000000..4724a0d
--- /dev/null
@@ -0,0 +1,131 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2012 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.structure;\r
+\r
+import java.util.HashMap;\r
+import java.util.HashSet;\r
+\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.request.PossibleObjectWithType;\r
+import org.simantics.db.common.utils.NameUtils;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.request.Read;\r
+import org.simantics.graphviz.Edge;\r
+import org.simantics.graphviz.Graph;\r
+import org.simantics.graphviz.Node;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.sysdyn.SysdynResource;\r
+\r
+/**\r
+ * Builds a graph about the modular structure of the model where a selected object is located.\r
+ * \r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
+public class ModuleStructureGraphRequest implements Read<Graph> {\r
+\r
+    private Resource resource;\r
+\r
+    /**\r
+     * Request a hierarchical graph about the model of resource\r
+     * @param resource\r
+     */\r
+    public ModuleStructureGraphRequest(Resource resource) {\r
+        this.resource = resource;\r
+    }\r
+\r
+    @Override\r
+    public Graph perform(ReadGraph graph) throws DatabaseException {\r
+        SysdynResource sr = SysdynResource.getInstance(graph);\r
+        Layer0 l0 = Layer0.getInstance(graph);\r
+\r
+        Graph g = new Graph();\r
+        g.setRankdir("TB");\r
+\r
+        // Find model resource, the root of this\r
+        Resource model = resource;\r
+        while(model != null && !graph.isInstanceOf(model, sr.SysdynModel)) {\r
+            model = graph.getPossibleObject(model, l0.PartOf);\r
+        }\r
+\r
+        // Model root was not found, return empty graph\r
+        if(model == null)\r
+            return g;\r
+\r
+        // Set root node\r
+        Node rootNode = new Node(g, NameUtils.getSafeLabel(graph, model));\r
+        rootNode.setShape("rectangle");\r
+        HashSet<Resource> visited = new HashSet<Resource>();\r
+        visited.add(model);\r
+        findChildModules(g, rootNode, graph, model, visited);\r
+\r
+\r
+        return g;\r
+    }\r
+\r
+    /**\r
+     * Recursive call for finding child modules \r
+     * @param g GraphViz graph\r
+     * @param parent Parent module or model\r
+     * @param graph ReadGraph\r
+     * @param resource Module type or model\r
+     * @param visited All visited modules. Needed to check for loops in the structure. Loops are not allowed.\r
+     * @throws DatabaseException\r
+     */\r
+    private void findChildModules(Graph g, Node parent, ReadGraph graph, Resource resource, HashSet<Resource> visited) throws DatabaseException {\r
+        SysdynResource sr = SysdynResource.getInstance(graph);\r
+        Layer0 l0 = Layer0.getInstance(graph);\r
+\r
+        HashMap<Resource, Integer> modules = new HashMap<Resource, Integer>();\r
+\r
+        // Find all module children\r
+        Resource configuration = graph.syncRequest(new PossibleObjectWithType(resource, l0.ConsistsOf, sr.Configuration));\r
+        for(Resource m : graph.getObjects(configuration, l0.ConsistsOf)) {\r
+            Resource type = graph.getPossibleObject(m, l0.InstanceOf);\r
+            if(graph.isInheritedFrom(type, sr.Module)) {\r
+                if(!modules.containsKey(type))\r
+                    modules.put(type, 0);\r
+                modules.put(type, modules.get(type) + 1);\r
+            }\r
+        }\r
+\r
+        // Display module children in graph\r
+        for(Resource type : modules.keySet()) {\r
+\r
+            Node node = new Node(g, NameUtils.getSafeName(graph, type));\r
+            node.setShape("rectangle");\r
+            Edge edge = new Edge(g, parent, node);\r
+            edge.set("labeldistance", "1.5");\r
+            edge.set("labelfontsize", "7");\r
+            edge.setFontColor("#4f4f4f");\r
+            if(modules.get(type) > 1)\r
+                edge.setHeadLabel(modules.get(type).toString());\r
+            \r
+            if(visited.contains(type)) {\r
+                // Found a loop. Stop recursive call and display error.\r
+                edge.setFontColor("#FF0000");\r
+                edge.setColor("#FF000");\r
+                edge.setLabel("Error: loop");\r
+                node.setColor("#FF0000");\r
+                node.setFontColor("#FF0000");\r
+                continue;\r
+            } else {\r
+                visited.add(type);\r
+                findChildModules(g, node, graph, type, visited);\r
+            }\r
+            \r
+        }\r
+\r
+    }\r
+\r
+}\r
diff --git a/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/structure/StructureView.java b/stable/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/structure/StructureView.java
new file mode 100644 (file)
index 0000000..ab3983b
--- /dev/null
@@ -0,0 +1,110 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2012 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.structure;\r
+\r
+import org.eclipse.jface.layout.GridDataFactory;\r
+import org.eclipse.jface.layout.GridLayoutFactory;\r
+import org.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.custom.CTabFolder;\r
+import org.eclipse.swt.events.SelectionEvent;\r
+import org.eclipse.swt.events.SelectionListener;\r
+import org.eclipse.swt.widgets.Composite;\r
+import org.eclipse.ui.ISelectionListener;\r
+import org.eclipse.ui.IWorkbenchPart;\r
+import org.eclipse.ui.part.ViewPart;\r
+\r
+/**\r
+ * View for displaying different types of structural visualizations\r
+ * \r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
+public class StructureView extends ViewPart {\r
+\r
+    private CTabFolder tabFolder;\r
+    private ISelectionListener selectionListener;\r
+    private Dependencies dependencies;\r
+    private ModuleStructure moduleStructure;\r
+    \r
+    \r
+    @Override\r
+    public void createPartControl(Composite parent) {\r
+        tabFolder = new CTabFolder(parent, SWT.BORDER);\r
+        GridDataFactory.fillDefaults().grab(true, true).applyTo(tabFolder);\r
+        GridLayoutFactory.fillDefaults().applyTo(tabFolder);\r
+\r
+        final ISelection currentSeletion = getSite().getWorkbenchWindow().getSelectionService().getSelection();\r
+        \r
+        // Dependencies\r
+        dependencies = new Dependencies(tabFolder, currentSeletion, SWT.NONE);\r
+\r
+        \r
+        // Hierarchical model structure\r
+        moduleStructure = new ModuleStructure(tabFolder, SWT.NONE);\r
+\r
+\r
+        selectionListener = new ISelectionListener() {\r
+\r
+            @Override\r
+            public void selectionChanged(IWorkbenchPart part, ISelection selection) {\r
+                drawSelection(selection);\r
+            }\r
+        };    \r
+        getSite().getWorkbenchWindow().getSelectionService().addPostSelectionListener(selectionListener);\r
+        \r
+        \r
+        // Listener for refreshing module structure visualization on first loading\r
+        tabFolder.addSelectionListener(new SelectionListener() {\r
+            \r
+            private boolean openedOnce = false;\r
+            \r
+            @Override\r
+            public void widgetSelected(SelectionEvent e) {\r
+                if(!openedOnce && e.item.equals(moduleStructure)) {\r
+                    openedOnce = true;\r
+                    moduleStructure.drawSelection(currentSeletion);\r
+                }\r
+            }\r
+            \r
+            @Override\r
+            public void widgetDefaultSelected(SelectionEvent e) {\r
+            }\r
+        });\r
+    }\r
+    \r
+    /**\r
+     * Draw structural visualizations for selected object(s)\r
+     * \r
+     * @param selection Current selection\r
+     */\r
+    private void drawSelection(ISelection selection) {\r
+        dependencies.drawSelection(selection);\r
+        moduleStructure.drawSelection(selection);\r
+    }\r
+    \r
+\r
+    @Override\r
+    public void setFocus() {\r
+        if(tabFolder != null && !tabFolder.isDisposed()) {\r
+            tabFolder.setFocus();\r
+        }\r
+    }\r
+\r
+\r
+    @Override\r
+    public void dispose() {\r
+        super.dispose();\r
+        getSite().getWorkbenchWindow().getSelectionService().removePostSelectionListener(selectionListener);\r
+    }\r
+\r
+}\r
index f0460938c913cba757d6990c18dd414dc544465d..c1c0d43779b0043aaa600ad0bbe208f33300b97b 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************\r
- * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
+ * Copyright (c) 2007, 2012 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
@@ -28,6 +28,7 @@ import org.simantics.scenegraph.ISelectionPainterNode;
 import org.simantics.scenegraph.g2d.events.EventTypes;\r
 import org.simantics.scenegraph.g2d.events.MouseEvent.MouseButtonPressedEvent;\r
 import org.simantics.scenegraph.g2d.events.MouseEvent.MouseButtonReleasedEvent;\r
+import org.simantics.scenegraph.g2d.events.MouseEvent.MouseDragBegin;\r
 import org.simantics.scenegraph.g2d.events.MouseEvent.MouseMovedEvent;\r
 import org.simantics.scenegraph.swing.ComponentNode;\r
 import org.simantics.scenegraph.utils.GeometryUtils;\r
@@ -256,6 +257,15 @@ public class ChartNode extends ComponentNode<JPanel> implements ISelectionPainte
         setBounds(bounds);\r
     }\r
 \r
+    @Override\r
+    protected boolean mouseDragged(MouseDragBegin e) {\r
+        if(dragging) {\r
+            return true; // Eat event for faster resize\r
+        } else {\r
+            return false;\r
+        }\r
+    }\r
+    \r
     @Override\r
     protected boolean mouseButtonReleased(MouseButtonReleasedEvent e) {\r
         if(dragging) {\r
index c83f7bdb8a7beb0726dc2794e6cc694e231b7cfe..a7e2ceea8950eda1e3aaea54cd23f33628388dc7 100644 (file)
@@ -34,6 +34,8 @@ Export-Package: org.simantics.sysdyn,
  org.simantics.sysdyn.modelParser,
  org.simantics.sysdyn.modelica,
  org.simantics.sysdyn.representation,
+ org.simantics.sysdyn.representation.expressions,
+ org.simantics.sysdyn.representation.utils,
  org.simantics.sysdyn.representation.visitors,
  org.simantics.sysdyn.simulation,
  org.simantics.sysdyn.tableParser
index fc72235a2cfc047a9e1f0cb91940f702b3e3e6ac..2178b0050024b02947ef11c479445ddf5274e99e 100644 (file)
@@ -571,6 +571,10 @@ public class ExpressionParser implements ExpressionParserConstants {
       ;\r
     }\r
     jj_consume_token(63);\r
+        if(functionCall != null) {\r
+          if(!functionCallReferences.containsKey(functionCall))\r
+              functionCallReferences.put(functionCall, new ArrayList<Token>());\r
+            }\r
   }\r
 \r
   final public void function_arguments() throws ParseException {\r
index df82b2c8ff1e1a382cda115ff9833824a010ab3f..bc00a1885b46caeb997dd99533409da58aba52be 100644 (file)
@@ -263,7 +263,11 @@ void component_reference(String prevToken) : {
 \r
 void function_call_args() : {\r
 } {\r
-       "(" ( function_arguments() )? ")"\r
+       "(" ( function_arguments() )? ")"\r      {\r        if(functionCall != null) {\r
+          if(!functionCallReferences.containsKey(functionCall))\r
+              functionCallReferences.put(functionCall, new ArrayList<Token>());\r
+            }\r
+       }\r
 }\r
 \r
 void function_arguments() : {\r
diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/HistoryDatasetResult.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/HistoryDatasetResult.java
new file mode 100644 (file)
index 0000000..21ed8b0
--- /dev/null
@@ -0,0 +1,309 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2012 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.manager;\r
+\r
+import java.io.File;\r
+import java.io.InputStream;\r
+import java.util.ArrayList;\r
+import java.util.HashMap;\r
+import java.util.List;\r
+\r
+import org.simantics.Simantics;\r
+import org.simantics.databoard.Bindings;\r
+import org.simantics.databoard.binding.mutable.Variant;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\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.db.procedure.Listener;\r
+import org.simantics.db.request.Read;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.modelica.data.DataSet;\r
+import org.simantics.modelica.data.SimulationResult;\r
+import org.simantics.simulation.ontology.SimulationResource;\r
+import org.simantics.spreadsheet.SheetVariables;\r
+import org.simantics.spreadsheet.common.matrix.VariantMatrix;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.representation.Configuration;\r
+import org.simantics.sysdyn.representation.IElement;\r
+import org.simantics.sysdyn.representation.Module;\r
+import org.simantics.sysdyn.representation.utils.IndexUtils;\r
+import org.simantics.utils.datastructures.Pair;\r
+\r
+/**\r
+ * A result built from a spreadsheet table. Imitates a normal simulation result for \r
+ * easy display on charts and tables.\r
+ * \r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
+public class HistoryDatasetResult extends SimulationResult {\r
+    @Override\r
+    public void read(File file) {} // Do nothing\r
+    @Override\r
+    public void read(InputStream stream) {} // Do nothing\r
+\r
+    private boolean disposed;\r
+\r
+    /**\r
+     * Dispose listeners of this result. It is important to dispose all listeners \r
+     * when they are not needed anymore.\r
+     */\r
+    public void disposeListeners() {\r
+        this.disposed = true;\r
+    }\r
+\r
+    /**\r
+     * Reads history data to this result. Location of the data is described in historyData resource.\r
+     * \r
+     * @param sysdynResult SysdynResult to which this simulation result is read\r
+     * @param historyData Resource describing the history data to be read from a spreadsheet\r
+     */\r
+    public void read(final SysdynResult sysdynResult, final Resource historyData) {\r
+\r
+        Simantics.getSession().asyncRequest(new Read<Pair<SysdynModel, List<DataSet>>>() {\r
+\r
+            @Override\r
+            public Pair<SysdynModel, List<DataSet>> perform(ReadGraph graph) throws DatabaseException {\r
+                ArrayList<DataSet> variables = new ArrayList<DataSet>();\r
+\r
+                SysdynResource sr = SysdynResource.getInstance(graph);\r
+                Layer0 l0 = Layer0.getInstance(graph);\r
+                SimulationResource simu = SimulationResource.getInstance(graph);\r
+\r
+                String datasetName = "History Dataset";\r
+                VariantMatrix vm = null;\r
+                SysdynModel sdmodel = null;\r
+                String timeVariable = "time";\r
+                boolean columns = true;\r
+                try {\r
+                    Pair<SysdynModel, List<DataSet>> emptyResult = new Pair<SysdynModel, List<DataSet>>(sdmodel, variables);\r
+\r
+                    \r
+                    // Find the SysdynModel of this historyData\r
+                    Resource model = graph.getPossibleObject(historyData, l0.PartOf);\r
+                    Resource config = graph.getPossibleObject(model, simu.HasConfiguration);\r
+                    sdmodel = SysdynModelManager.getInstance(graph.getSession()).getModel(graph, config);\r
+                    sdmodel.update(graph);\r
+                    \r
+                    // Find properties of the result: name, sheet, range, time variable, orientation\r
+                    datasetName = NameUtils.getSafeLabel(graph, historyData);\r
+                    \r
+\r
+                    Resource sheet = graph.getPossibleObject(historyData, sr.HistoryDataset_sheet);\r
+                    if(sheet == null)\r
+                        return emptyResult;\r
+                    \r
+                    String start = graph.getPossibleRelatedValue(historyData, sr.HistoryDataset_start);\r
+                    String end = graph.getPossibleRelatedValue(historyData, sr.HistoryDataset_end);\r
+                    if(start == null || start.isEmpty() || end == null || end.isEmpty())\r
+                        return emptyResult;\r
+                    String r = start + ":" + end;\r
+                    \r
+                    String time = graph.getPossibleRelatedValue(historyData, sr.HistoryDataset_timeName);\r
+                    if(time != null && !time.isEmpty())\r
+                        timeVariable = time;\r
+                    \r
+                    if(graph.hasStatement(historyData, sr.HistoryDataset_columns))\r
+                        columns = graph.getRelatedValue(historyData, sr.HistoryDataset_columns, Bindings.BOOLEAN);\r
+                        \r
+                    // Find the sheet variable\r
+                    Variable v = graph.adapt(sheet, Variable.class);\r
+                    Variable range = v.getChild(graph, r);\r
+                    if(range == null)\r
+                        return emptyResult;\r
+                    \r
+                    // Find the content of the range\r
+                    Variant content = range.getPropertyValue(graph, SheetVariables.CONTENT, Bindings.VARIANT);\r
+                    Object matrixValue = content.getValue();\r
+                    if(matrixValue instanceof VariantMatrix) {\r
+                        vm = (VariantMatrix)matrixValue;\r
+                    }\r
+\r
+                } catch(DatabaseException e) {\r
+                    return new Pair<SysdynModel, List<DataSet>>(sdmodel, variables);\r
+                } catch(NegativeArraySizeException e) {\r
+                    // Negative array size may be result of mofifying start and end variables\r
+                    return new Pair<SysdynModel, List<DataSet>>(sdmodel, variables);\r
+                }\r
+\r
+                \r
+                // Orientation\r
+                int x = columns ? vm.getColumnCount() : vm.getRowCount();\r
+                int y = columns ? vm.getRowCount() : vm.getColumnCount();\r
+                \r
+                /*\r
+                 * The table needs at least:\r
+                 * \r
+                 * headers for variables + one value\r
+                 * two variables (of which one is time-variable)\r
+                 * \r
+                 * => minimum of 2x2 matrix\r
+                 */\r
+                if(vm == null || x < 2 || y < 2)\r
+                    return new Pair<SysdynModel, List<DataSet>>(sdmodel, variables);\r
+\r
+                String[] names = new String[x];\r
+                HashMap<String, ArrayList<Pair<Double, Double>>> values = new HashMap<String, ArrayList<Pair<Double,Double>>>();\r
+                Integer timeIndex = null;\r
+                \r
+                // Find variable names\r
+                for(int i = 0; i < x ; i++) {\r
+                    Variant cell = columns ? vm.get(0, i) : vm.get(i, 0);\r
+                    if(cell != null && cell.getValue() != null) {\r
+                        String name = cell.getValue().toString();\r
+                        if(!values.containsKey(name)) {\r
+                            names[i] = name;\r
+                            values.put(names[i], new ArrayList<Pair<Double,Double>>());\r
+\r
+                            // Time column index\r
+                            if(names[i].equals(timeVariable))\r
+                                timeIndex = i;\r
+                        }\r
+                    } else {\r
+                        names[i] = null;\r
+                    }\r
+                }\r
+\r
+                // If times were not found, return empty\r
+                if(timeIndex == null || names[timeIndex] == null)\r
+                    return new Pair<SysdynModel, List<DataSet>>(sdmodel, variables);\r
+\r
+                // Get time column ready first\r
+                for(int i = 1; i < y; i++) {\r
+                    Variant cell = columns ? vm.get(i, timeIndex) : vm.get(timeIndex, i);\r
+                    Double value = null;\r
+                    if(cell != null)\r
+                        value = getDoubleValue(cell);\r
+                    values.get(names[timeIndex]).add(new Pair<Double, Double>(value, value)); // add also null-values\r
+                }\r
+\r
+                // Get variable values column by column (or row by row\r
+                for(int i = 0; i < x; i++) {\r
+                    if(i == timeIndex || names[i] == null) \r
+                        continue;\r
+\r
+                    for(int j = 1; j < y; j++) {\r
+                        Variant cell = columns ? vm.get(j, i) : vm.get(i, j);\r
+                        if(cell != null && cell.getValue() != null) {\r
+                            Double value = getDoubleValue(cell);\r
+                            if(value != null) {\r
+                                Pair<Double, Double> time = values.get(names[timeIndex]).get(j - 1);\r
+                                if(time != null && time.first != null) {\r
+                                    values.get(names[i]).add(\r
+                                            new Pair<Double, Double>(\r
+                                                    time.first, \r
+                                                    value)\r
+                                            );\r
+                                }\r
+                            }\r
+                        }\r
+                    }\r
+\r
+                    ArrayList<Pair<Double, Double>> doubles = values.get(names[i]);\r
+                    \r
+                    String name = names[i];\r
+                    // If the variable has array indexes, they need to be converted to numbers\r
+                    if(name.contains("[")) {\r
+                        org.simantics.sysdyn.representation.Variable variable = getVariable(name, sdmodel.getConfiguration());\r
+                        if(variable != null)\r
+                            name = IndexUtils.equationRangesToIndexes(variable, name);\r
+                    }\r
+\r
+                    // Read values to SysdynDataSet\r
+                    SysdynDataSet ds = new SysdynDataSet(name, datasetName, new double[doubles.size()], new double[doubles.size()]);\r
+                    variables.add(ds);\r
+                    for(int d = 0; d < doubles.size(); d++) {\r
+                        Pair<Double, Double> pair = doubles.get(d);\r
+                        ds.times[d] = pair.first;\r
+                        ds.values[d] = pair.second;\r
+                    }\r
+                }\r
+                return new Pair<SysdynModel, List<DataSet>>(sdmodel, variables);\r
+            }\r
+\r
+        }, new Listener<Pair<SysdynModel, List<DataSet>>>() {\r
+\r
+            @Override\r
+            public void execute(Pair<SysdynModel, List<DataSet>> result) {\r
+                // Update result set and send message to model that results have been changed\r
+                HistoryDatasetResult.this.variables = result.second;\r
+                sysdynResult.setResult(HistoryDatasetResult.this);\r
+                result.first.resultChanged();\r
+            }\r
+\r
+            @Override\r
+            public void exception(Throwable t) {\r
+                t.printStackTrace();\r
+            }\r
+\r
+            @Override\r
+            public boolean isDisposed() {\r
+                return disposed;\r
+            }\r
+        });\r
+\r
+\r
+    }\r
+    \r
+    /**\r
+     * Finds a variable defined by path starting from configuration \r
+     * @param path Path of the variable\r
+     * @param configuration Configuration where to look for the variable\r
+     * @return Variable\r
+     */\r
+    private org.simantics.sysdyn.representation.Variable getVariable(String path, Configuration configuration) {\r
+        String next = path;\r
+        int index = next.indexOf(".");\r
+\r
+        // If path has commas, we are looking for a module\r
+        if(index > 0) {\r
+            path = path.substring(index + 1);\r
+            next = next.substring(0, index);\r
+        } else {\r
+            // No commas, we are looking for a variable\r
+            if(next.contains("["))\r
+                // Variable has array indexes, remove the array indexes\r
+                next = next.substring(0, next.indexOf("["));\r
+        }\r
+\r
+        for(IElement e : configuration.getElements()) {\r
+            if(e instanceof org.simantics.sysdyn.representation.Variable) {\r
+                org.simantics.sysdyn.representation.Variable v = (org.simantics.sysdyn.representation.Variable) e;\r
+                if(v.getName().equals(next)) {\r
+                    return v; // found the variable\r
+                }\r
+            } else if(e instanceof Module && ((Module)e).getName().equals(next)) {\r
+                return getVariable(path, ((Module)e).getType().getConfiguration()); // Recursive call with a shorter path\r
+            }\r
+        }\r
+        return null;\r
+    }\r
+\r
+    /**\r
+     * Finds the double value from a spreadsheet cell. \r
+     * @param cell Cell where to look for\r
+     * @return Double value of the cell or null if not double or if empty\r
+     */\r
+    private Double getDoubleValue(Variant cell) {\r
+        if(cell.getValue() == null)\r
+            return null;\r
+\r
+        Double value = null;\r
+        try {\r
+            value = Double.parseDouble(cell.getValue().toString());\r
+        } catch (NumberFormatException e) {\r
+        }\r
+        return value;\r
+    }\r
+}\r
diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/HistoryDatasetUtils.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/HistoryDatasetUtils.java
new file mode 100644 (file)
index 0000000..e164c81
--- /dev/null
@@ -0,0 +1,92 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2012 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.manager;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import org.simantics.databoard.Bindings;\r
+import org.simantics.databoard.binding.mutable.Variant;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.variable.Variable;\r
+import org.simantics.spreadsheet.SheetVariables;\r
+import org.simantics.spreadsheet.common.matrix.VariantMatrix;\r
+import org.simantics.sysdyn.SysdynResource;\r
+\r
+public class HistoryDatasetUtils {\r
+    \r
+    public static List<String> getVariableNamesInRange(ReadGraph graph, Resource historyData) throws DatabaseException {\r
+        SysdynResource sr = SysdynResource.getInstance(graph);\r
+        \r
+        ArrayList<String> values = new ArrayList<String>();\r
+\r
+\r
+        Resource sheet = graph.getPossibleObject(historyData, sr.HistoryDataset_sheet);\r
+        if(sheet == null)\r
+            return values;\r
+        \r
+        String start = graph.getPossibleRelatedValue(historyData, sr.HistoryDataset_start);\r
+        String end = graph.getPossibleRelatedValue(historyData, sr.HistoryDataset_end);\r
+        if(start == null || start.isEmpty() || end == null || end.isEmpty())\r
+            return values;\r
+        String r = start + ":" + end;\r
+        \r
+        if(!graph.hasStatement(historyData, sr.HistoryDataset_columns))\r
+            return values;\r
+            \r
+        boolean columns = graph.getRelatedValue(historyData, sr.HistoryDataset_columns, Bindings.BOOLEAN);\r
+            \r
+        Variable v = graph.adapt(sheet, Variable.class);\r
+        Variable range = v.getChild(graph, r);\r
+        if(range == null)\r
+            return values;\r
+        \r
+        Variant content = range.getPropertyValue(graph, SheetVariables.CONTENT, Bindings.VARIANT);\r
+        Object matrixValue = content.getValue();\r
+        if(!(matrixValue instanceof VariantMatrix))\r
+            return values;\r
+        \r
+        VariantMatrix vm = (VariantMatrix)matrixValue;\r
+        \r
+        /*\r
+         * The table needs at least:\r
+         * \r
+         * headers for variables + one value\r
+         * two variables (of which one is time-variable)\r
+         * \r
+         * => minimum of 2x2 matrix\r
+         */\r
+        \r
+        int x = columns ? vm.getColumnCount() : vm.getRowCount();\r
+        int y = columns ? vm.getRowCount() : vm.getColumnCount();\r
+        \r
+        if(vm == null || x < 2 || y < 2)\r
+            return values;\r
+\r
+        \r
+        // Names\r
+        for(int i = 0; i < x ; i++) {\r
+            Variant cell = columns ? vm.get(0, i) : vm.get(i, 0);\r
+            if(cell != null && cell.getValue() != null) {\r
+                String name = cell.getValue().toString();\r
+                if(!values.contains(name)) {\r
+                    values.add(name);\r
+                }\r
+            }\r
+        }\r
+        \r
+        return values;\r
+    }\r
+\r
+}\r
index 2bb5a165a7a4602b84cd82ece20be041149023f3..057885a67336f9e3af2235f985723b448d7b0a23 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************\r
- * Copyright (c) 2010 Association for Decentralized Information Management in\r
+ * Copyright (c) 2010, 2012 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,6 +33,7 @@ import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;\r
 import org.simantics.db.Session;\r
 import org.simantics.db.common.request.ObjectsWithType;\r
+import org.simantics.db.common.utils.NameUtils;\r
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.db.exception.ManyObjectsForFunctionalRelationException;\r
 import org.simantics.db.exception.ServiceException;\r
@@ -93,6 +94,7 @@ public class SysdynModel implements IMappingListener, IModel {
     private SimulationResult result;\r
     private SysdynResult sysdynResult;\r
     private ArrayList<SysdynResult> activeResults;\r
+    private ArrayList<HistoryDatasetResult> listeningHistories = new ArrayList<HistoryDatasetResult>();\r
 \r
     private CopyOnWriteArrayList<Runnable> modificationListeners =\r
             new CopyOnWriteArrayList<Runnable>();\r
@@ -187,27 +189,44 @@ public class SysdynModel implements IMappingListener, IModel {
         sysdynResult.setResult(new SimulationResult());\r
 \r
         previousModelStructure = "";\r
-        \r
+\r
         g.asyncRequest(new Read<ArrayList<SysdynResult>> () {\r
             @Override\r
             public ArrayList<SysdynResult> perform(ReadGraph graph) throws DatabaseException {\r
                 ArrayList<SysdynResult> activeResults = new ArrayList<SysdynResult>();\r
                 // TODO: this can be done automatically with a listener\r
+                \r
+                for(HistoryDatasetResult hs : listeningHistories)\r
+                    hs.disposeListeners(); // dispose old histories listening to spreadsheets\r
+                \r
                 try {\r
                     // Find all active saved results\r
                     Layer0 l0 = Layer0.getInstance(graph);\r
                     SysdynResource sr = SysdynResource.getInstance(graph);\r
                     SimulationResource SIMU = SimulationResource.getInstance(graph);\r
-                    Resource model = graph.getSingleObject(getConfigurationResource(), SIMU.IsConfigurationOf);\r
+                    Resource model = graph.getPossibleObject(getConfigurationResource(), SIMU.IsConfigurationOf);\r
+                    if(model == null)\r
+                        return null;\r
                     Collection<Resource> experiments = graph.syncRequest(new ObjectsWithType(model, l0.ConsistsOf, sr.Experiment));\r
                     for(Resource experiment : experiments) {\r
                         Collection<Resource> experimentResults = graph.getObjects(experiment, sr.Experiment_result);\r
                         for(Resource result : experimentResults) {\r
                             if(graph.hasStatement(result, sr.Result_showResult)) {\r
-                                SysdynResult sysdynResult = new SysdynResult(\r
-                                        (String) graph.getPossibleRelatedValue(result, l0.HasLabel),\r
-                                        (String) graph.getPossibleRelatedValue(result, sr.Result_resultFile));\r
-                                activeResults.add(sysdynResult);\r
+                                SysdynResult sysdynResult = null;\r
+                                if(graph.isInstanceOf(result, sr.HistoryDataset)) {\r
+                                    HistoryDatasetResult r = new HistoryDatasetResult();\r
+                                    listeningHistories.add(r);\r
+                                    sysdynResult = new SysdynResult(r, NameUtils.getSafeLabel(graph, result));\r
+                                    r.read(sysdynResult, result);\r
+                                } else {\r
+                                    sysdynResult = new SysdynResult(\r
+                                            (String) graph.getPossibleRelatedValue(result, l0.HasLabel),\r
+                                            (String) graph.getPossibleRelatedValue(result, sr.Result_resultFile));\r
+                                }\r
+                                \r
+                                if(sysdynResult != null)\r
+                                    activeResults.add(sysdynResult);\r
+\r
                             }\r
                         }\r
                     }\r
@@ -221,7 +240,7 @@ public class SysdynModel implements IMappingListener, IModel {
 \r
                 return activeResults;\r
             }\r
-            \r
+\r
         }, new Listener<ArrayList<SysdynResult>> () {\r
 \r
             @Override\r
@@ -239,7 +258,7 @@ public class SysdynModel implements IMappingListener, IModel {
             public boolean isDisposed() {\r
                 return false;\r
             }\r
-            \r
+\r
         });\r
     }\r
 \r
@@ -263,12 +282,10 @@ public class SysdynModel implements IMappingListener, IModel {
         progressMonitor.subTask("Write modelica classes");\r
 \r
         // Write Modelica files\r
-        ModelicaWriter writer = new ModelicaWriter();\r
+        String modelText = null;\r
         try {\r
             // Write all configurations once\r
-            for(Configuration c : modules) {\r
-                writer.write(c);\r
-            }\r
+            modelText = ModelicaWriter.write(modules);\r
         } catch (Exception e) {\r
             // Stop experiment and show console\r
             setExperimentStopped(experiment);\r
@@ -276,7 +293,6 @@ public class SysdynModel implements IMappingListener, IModel {
             monitor.message("Error when writing Modelica code.");\r
             return;\r
         }\r
-        String modelText = writer.toString();\r
         progressMonitor.worked(1);\r
 \r
         // Write initial files and add init-parameters\r
@@ -300,6 +316,9 @@ public class SysdynModel implements IMappingListener, IModel {
         inits.put("method", method);\r
         if(model.getTolerance() != null)\r
             inits.put("tolerance", model.getTolerance().toString());\r
+        String variableFilter = model.getVariableFilter();\r
+        if(variableFilter != null && !variableFilter.isEmpty())\r
+            inits.put("variableFilter", variableFilter);\r
 \r
         // add loadFile script to load all related functions and function libraries \r
         StringBuilder functionscript = new StringBuilder();\r
@@ -335,6 +354,7 @@ public class SysdynModel implements IMappingListener, IModel {
                 previousImportantInits.put("stop value", stopTime.toString());\r
                 previousImportantInits.put("method", method);\r
                 previousImportantInits.put("outputFormat", outputFormat);\r
+                previousImportantInits.put("variableFilter", variableFilter);\r
             } catch (ModelicaException e) {\r
                 if(e.getMessage() != null)\r
                     monitor.message(e.getMessage());\r
@@ -443,7 +463,9 @@ public class SysdynModel implements IMappingListener, IModel {
             while (c != null && p != null) {\r
                 // if the lines are the same, no need for further examination\r
                 if(!c.equals(p)) {\r
-                    if(c.contains("parameter") && p.contains("parameter")) {\r
+                    if(\r
+                            c.contains("parameter") && c.contains("/* Actual value read from init file */") &&\r
+                            p.contains("parameter") && p.contains("/* Actual value read from init file */")) {\r
                         /*\r
                          *  The line is a parameter definition.\r
                          *  In this case only what is before '=' matters\r
index d0771f50cfee1bd3602845663c8374d0c7c356cc..1bfe6621eac24a1678fa9cc337dbe0c89047397d 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************\r
- * Copyright (c) 2010 Association for Decentralized Information Management in\r
+ * Copyright (c) 2010, 2012 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
@@ -50,8 +50,8 @@ import org.simantics.modelica.data.SimulationResult;
  */\r
 public class SysdynResult {\r
 \r
-    RecordAccessor accessor;\r
-    String resultName;\r
+    protected RecordAccessor accessor;\r
+    protected String resultName;\r
 \r
     /**\r
      * Create an empty result\r
@@ -68,6 +68,17 @@ public class SysdynResult {
         if(result != null)\r
             setResult(result);\r
     }\r
+    \r
+    /**\r
+     * Create a sysdynresult accessor using a {@link SimulationResult}\r
+     * @param result\r
+     * @param resultName Name of the result (seen in visualization)\r
+     */\r
+    public SysdynResult(SimulationResult result, String resultName) {\r
+        this.resultName = resultName;\r
+        if(result != null)\r
+            setResult(result);\r
+    }\r
 \r
     /**\r
      * Open result from a file\r
index c9cecaf02ea077199015ffedd9a4995ccb345cdf..53ac48bd521e7705710a4ca6efbeeba325ffa6ac 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************\r
- * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
+ * Copyright (c) 2007, 2012 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
@@ -12,6 +12,7 @@
 package org.simantics.sysdyn.modelica;\r
 \r
 import java.util.ArrayList;\r
+import java.util.Collection;\r
 import java.util.HashMap;\r
 \r
 import org.simantics.sysdyn.representation.Book;\r
@@ -26,27 +27,45 @@ import org.simantics.sysdyn.representation.ModuleType;
 import org.simantics.sysdyn.representation.Stock;\r
 import org.simantics.sysdyn.representation.Variable;\r
 \r
+/**\r
+ * ModelicaWriter writes Sysdyn model representations (objmap) into Modelica code.\r
+ * \r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
 public class ModelicaWriter {\r
 \r
-    StringBuilder b = new StringBuilder();\r
-    String app;\r
-    boolean enumerationsWritten = false;\r
-\r
-    public void write(Configuration conf) {\r
-\r
-       if(!enumerationsWritten) {\r
-               b.append("partial class Enumeration_class\n");\r
-               b.append("    parameter Integer size;\n");\r
-               b.append("    parameter Integer elements[:];\n");\r
-               b.append("end Enumeration_class;\n\n");\r
-               enumerationsWritten = true;\r
-       }\r
-       \r
-        writeConfiguration(conf);\r
+    /**\r
+     * Write a collection of configurations into a single Modelica code\r
+     * \r
+     * @param Configurations Configurations, one main configuration and possible modules\r
+     * @return Complete Modelica code of a model\r
+     */\r
+    public static String write(Collection<Configuration> configurations) {\r
+        StringBuilder b = new StringBuilder();\r
+\r
+        // Super class for enumerations\r
+        b.append("partial class Enumeration_class\n");\r
+        b.append("    parameter Integer size;\n");\r
+        b.append("    parameter Integer elements[:];\n");\r
+        b.append("end Enumeration_class;\n\n");\r
+\r
+        for(Configuration conf : configurations)\r
+            writeConfiguration(conf, b);\r
+\r
+        return b.toString();\r
     }\r
 \r
-    private void writeConfiguration(Configuration configuration) {\r
+    /**\r
+     * Write a single configuration to a given string builder\r
+     * \r
+     * @param configuration Model or module configuration\r
+     * @param b String builder\r
+     */\r
+    private static void writeConfiguration(Configuration configuration, StringBuilder b) {\r
+        String app;\r
 \r
+        // Lists for storing different configuration elements\r
         ArrayList<IndependentVariable> variables = new ArrayList<IndependentVariable>();\r
         ArrayList<Input> inputs = new ArrayList<Input>();\r
         ArrayList<Module> modules = new ArrayList<Module>();\r
@@ -60,41 +79,56 @@ public class ModelicaWriter {
         // Initialize lists\r
         for(IElement element : configuration.getElements()) {\r
             if(element instanceof IndependentVariable) {\r
+                // Normal variable\r
                 variables.add((IndependentVariable)element);\r
                 if(element instanceof Stock)\r
+                    // Stock\r
                     stocks.add((Stock)element);\r
             } else if (element instanceof Module) {\r
+                // Module\r
                 Module m = (Module)element; \r
                 modules.add(m);\r
                 moduleInputs.put(m.getName(), new ArrayList<Input>());\r
                 for(IElement e : m.getType().getConfiguration().getElements())\r
+                    // Inputs inside the module\r
                     if(e instanceof Input && !((Input)e).isHeadOfDependency()) {\r
                         moduleInputs.get(m.getName()).add((Input)e);\r
                     }\r
             } else if (element instanceof Input) {\r
+                // Input variables\r
                 inputs.add((Input)element);\r
             } else if (element instanceof Enumeration) {\r
+                // Enumerations\r
                 enumerations.add((Enumeration)element);\r
             } else if (element instanceof Dependency) {\r
                 Dependency dependency = (Dependency)element;\r
                 if(dependency.getHead() instanceof Module) {\r
+                    // References given to child modules\r
                     outputDependencies.add(dependency);\r
                 } else if(dependency.getTail() instanceof Module){\r
+                    // References from child modules\r
                     inputDependencies.add(dependency);\r
                 }\r
             } else if (element instanceof Book) {\r
+                // Spreadsheet book\r
                 book = (Book)element;\r
             }\r
         }\r
+        \r
+        // Setup input references. (Input, String reference to another variable)\r
+        HashMap<Input, String> inputReferences = new HashMap<Input, String>();\r
+        setupInputReferences(inputReferences, inputDependencies);\r
+        \r
 \r
+        // If the configuration is model configuration, use model name. Otherwise, use configuration name.\r
         ModuleType mt = configuration.getModuleType();\r
         String className = mt != null ? (mt.getName().replace(" ", "")) : (configuration.getName().replace(" ", ""));\r
         b.append("class ").append(className).append('\n');\r
 \r
         b.append("// Variable definitions\n");\r
         for(IndependentVariable variable : variables) {\r
-               app = variable.getDeclaration();\r
-               if (app != null) b.append(app);\r
+            app = variable.getDeclaration();\r
+            if (app != null) b.append(app);\r
         }\r
 \r
         if(!modules.isEmpty()) {\r
@@ -104,20 +138,17 @@ public class ModelicaWriter {
             }\r
         }\r
 \r
-        if(!inputs.isEmpty()) {\r
-            b.append("// Input definitions\n");\r
-            for(Input i : inputs) {\r
-                b.append(i.getDeclaration());\r
-            }\r
-        }\r
-        \r
+\r
+        // Input definitions\r
+        inputDefinitions(b, configuration, inputs, inputReferences);\r
+\r
         if(!enumerations.isEmpty()) {\r
             b.append("// Enumeration definitions\n");\r
             for(Enumeration e : enumerations) {\r
                 b.append(e.getDeclaration());\r
             }\r
         }\r
-        \r
+\r
         if(book != null) {\r
             b.append("// Spreadsheet definition\n");\r
             b.append(book.markBook());\r
@@ -125,64 +156,44 @@ public class ModelicaWriter {
 \r
         boolean initialEquations = false;\r
         for(Stock stock : stocks) {\r
-               app = stock.getInitialEquation();\r
-               if (app != null) {\r
-                       if(initialEquations == false) {\r
-                               initialEquations = true;\r
-                               b.append("// Initial Equations\n");\r
-                               b.append("initial equation\n");\r
-                       }\r
-                       b.append(app);\r
-               }\r
+            app = stock.getInitialEquation();\r
+            if (app != null) {\r
+                if(initialEquations == false) {\r
+                    initialEquations = true;\r
+                    b.append("// Initial Equations\n");\r
+                    b.append("initial equation\n");\r
+                }\r
+                b.append(app);\r
+            }\r
         }\r
 \r
         b.append("equation\n");\r
 \r
         b.append("// Equations\n");\r
         for(IndependentVariable variable : variables) {\r
-               app = variable.getEquation();\r
-               if (app != null) b.append(app);\r
-        }\r
-\r
-\r
-        b.append("// Inputs\n");\r
-        for(Dependency dependency : inputDependencies) {\r
-            Input variable = (Input)dependency.getHead();\r
-            Module module = (Module)dependency.getTail();\r
-            Variable reference = (Variable)dependency.refersTo();\r
-            if(reference != null && reference.getName() != null)\r
-               b.append("    " + variable.getName() + " = " + module.getName() + "." + reference.getName() + ";\n");\r
-            else\r
-               b.append("    " + variable.getName() + " = " + variable.getDefaultInputValue() + ";\n");\r
-            \r
-            if(configuration.getModel() != null) {\r
-                // Root configuration\r
-                inputs.remove(variable);\r
-            }\r
+            app = variable.getEquation();\r
+            if (app != null) b.append(app);\r
         }\r
         \r
-        // Set root configuration input defaults\r
-        if(configuration.getModel() != null) {\r
-            for(Input i : inputs) {\r
-                b.append("    " + i.getName() + " = " + i.getDefaultInputValue() + ";\n");\r
-            }\r
-        }\r
-\r
+        // Continous input references\r
+        continuousInputReferences(b, inputReferences);\r
+        \r
         b.append("// Outputs\n");\r
         for(Dependency dependency : outputDependencies) {\r
             Variable variable = (Variable)dependency.getTail();\r
             Module module = (Module)dependency.getHead();\r
             Input reference = (Input)dependency.refersTo();\r
-            if(reference != null) {\r
-               b.append("    " + module.getName() + "." + reference.getName() + " = " + variable.getName() + ";\n");\r
-               moduleInputs.get(module.getName()).remove(reference);\r
+            if(reference != null && (reference.getVariability() == null || reference.getVariability().isEmpty())) {\r
+                b.append("    " + module.getName() + "." + reference.getName() + " = " + variable.getName() + ";\n");\r
+                moduleInputs.get(module.getName()).remove(reference);\r
             }\r
         }\r
 \r
         b.append("// Default values for inputs in modules\n");\r
         for(String moduleLabel : moduleInputs.keySet()) {\r
             for(Input input : moduleInputs.get(moduleLabel)) {\r
-                b.append("    " + moduleLabel + "." + input.getName() + " = " + input.getDefaultInputValue(moduleLabel) + ";\n");\r
+                if(input.getVariability() == null || input.getVariability().isEmpty())\r
+                    b.append("    " + moduleLabel + "." + input.getName() + " = " + input.getDefaultInputValue(moduleLabel) + ";\n");\r
             }\r
         }\r
 \r
@@ -195,14 +206,86 @@ public class ModelicaWriter {
             b.replace(s, s + book.markBook().length(), book.getBook());\r
         }\r
     }\r
+    \r
+    /**\r
+     * Define continuous input references\r
+     * @param b String builder\r
+     * @param inputReferences Input references\r
+     */\r
+    private static void continuousInputReferences(StringBuilder b, HashMap<Input, String> inputReferences) {\r
+        b.append("// Inputs\n");\r
+        for(Input i : inputReferences.keySet()) {\r
+            if(i.getVariability() == null || i.getVariability().isEmpty()) {\r
+                // Define only continuous variables here\r
+                b.append("    " + i.getName() + " = " + inputReferences.get(i));\r
+            }\r
+        }\r
+    }\r
 \r
-    public String escape(String name) {\r
-        return name.replace(' ', '_');\r
+    /**\r
+     * Setup input references for all inputs that are defined in child modules\r
+     * \r
+     * @param inputReferences Map containing the references\r
+     * @param inputDependencies List of input dependencies\r
+     */\r
+    private static void setupInputReferences(HashMap<Input, String> inputReferences, ArrayList<Dependency> inputDependencies) {\r
+        for(Dependency dependency : inputDependencies) {\r
+            Input input = (Input)dependency.getHead();\r
+            Module module = (Module)dependency.getTail();\r
+            Variable reference = (Variable)dependency.refersTo();\r
+            String expression;\r
+            // If reference exists, use reference name. Otherwise, use default value.\r
+            if(reference != null && reference.getName() != null)\r
+                expression = module.getName() + "." + reference.getName() + ";\n";\r
+\r
+            else\r
+                expression = input.getDefaultInputValue() + ";\n";\r
+            \r
+            inputReferences.put(input, expression);\r
+        }\r
     }\r
 \r
-    @Override\r
-    public String toString() {\r
-        return b.toString();\r
+    /**\r
+     *  Build input definitions\r
+     * \r
+     * @param b String builder\r
+     * @param configuration Module configuration\r
+     * @param inputs All inputs of this module\r
+     * @param inputReferences \r
+     */\r
+    private static void inputDefinitions(StringBuilder b, Configuration configuration, ArrayList<Input> inputs, HashMap<Input, String> inputReferences) {\r
+        if(inputs.isEmpty())\r
+            return;\r
+        \r
+        b.append("// Input definitions\n");\r
+        for(Input i : inputs) {\r
+            if(i.getVariability() != null && !i.getVariability().isEmpty()) {\r
+                // Input is NOT continuous\r
+                if(inputReferences.containsKey(i)) {\r
+                    // Input is defined in a child module\r
+                    String declaration = i.getDeclaration();\r
+                    declaration = declaration.substring(0, declaration.length() - 2); // remove ";\n" from the end\r
+                    b.append(declaration + " = " + inputReferences.get(i));\r
+                } else {\r
+                    // Input is not defined in a child module, use default value\r
+                    b.append(i.getDeclarationWithValue());\r
+                }\r
+            } else if(configuration.getModel() != null && !i.isHeadOfDependency()) {\r
+                /*\r
+                 *  Input is in the top of the hierarchy, \r
+                 *  and it does not get value from anywhere else.\r
+                 *  => Declare it wit its default value \r
+                 */\r
+                b.append(i.getDeclarationWithValue());\r
+            } else {\r
+                // Continuous => Parent module takes care of declaring a value for the input\r
+                b.append(i.getDeclaration());\r
+            }\r
+        }\r
+    }\r
+\r
+    public String escape(String name) {\r
+        return name.replace(' ', '_');\r
     }\r
 \r
 }\r
index 02279551b912f5f016338c662190563c5412bc81..f13b4044d162d906ac156e693663293ca75a0347 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************\r
- * Copyright (c) 2010 Association for Decentralized Information Management in\r
+ * Copyright (c) 2010, 2012 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
@@ -22,7 +22,12 @@ import org.simantics.simulation.ontology.SimulationResource;
 import org.simantics.structural.stubs.StructuralResource2;\r
 import org.simantics.sysdyn.SysdynResource;\r
 \r
-\r
+/**\r
+ * Representation of a model or module configuration \r
+ * \r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
 @GraphType(SysdynResource.URIs.Configuration)\r
 public class Configuration {\r
     \r
@@ -32,18 +37,28 @@ public class Configuration {
     @RelatedValue(Layer0.URIs.HasLabel)\r
     private String label;\r
     \r
+    /**\r
+     * Not null if configuration of a module\r
+     */\r
     @RelatedElement(StructuralResource2.URIs.Defines)\r
     private ModuleType moduleType;\r
 \r
+    /**\r
+     * Not null if is configuration of a model\r
+     */\r
     @RelatedElement(SimulationResource.URIs.IsConfigurationOf)\r
     private Model model;\r
-\r
+    \r
     @RelatedElements(\r
             value = Layer0.URIs.ConsistsOf,\r
             composition = true)\r
             private ArrayList<IElement> elements = new ArrayList<IElement>();\r
 \r
 \r
+    /**\r
+     * Get all elements of this configuration. Also all sheets from books are included.\r
+     * @return\r
+     */\r
     public ArrayList<IElement> getElements() {\r
         ArrayList<IElement> elements = new ArrayList<IElement>();\r
         elements.addAll(this.elements);\r
@@ -71,5 +86,4 @@ public class Configuration {
         return model;\r
     }\r
     \r
-    \r
 }\r
diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Entity.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Entity.java
new file mode 100644 (file)
index 0000000..433848f
--- /dev/null
@@ -0,0 +1,25 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2012 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.representation;\r
+\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.objmap.annotations.GraphType;\r
+\r
+/**\r
+ * Dummy class representing any entity.\r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
+@GraphType(Layer0.URIs.Entity)\r
+public class Entity {\r
+\r
+}\r
diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Function.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Function.java
new file mode 100644 (file)
index 0000000..5924383
--- /dev/null
@@ -0,0 +1,78 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2012 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.representation;\r
+\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.objmap.annotations.GraphType;\r
+import org.simantics.objmap.annotations.RelatedValue;\r
+import org.simantics.objmap.annotations.UpdateMethod;\r
+import org.simantics.sysdyn.SysdynResource;\r
+\r
+/**\r
+ * Representation of a function\r
+ * \r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
+@GraphType(SysdynResource.URIs.SysdynModelicaFunction)\r
+public class Function {\r
+\r
+    @RelatedValue(Layer0.URIs.HasName)\r
+    private String name;\r
+\r
+    @RelatedValue(SysdynResource.URIs.SysdynModelicaFunction_modelicaFunctionCode)\r
+    private String code;\r
+\r
+    private boolean hasTimeReference = false;\r
+\r
+    public String getCode() {\r
+        return \r
+                "function " + name + "\n" +\r
+                code +\r
+                "end " + name + ";\n";\r
+    }\r
+\r
+    public String getName() {\r
+        return name;\r
+    }\r
+\r
+    /**\r
+     * Keep track if the function contains references to time. If there is a reference to time, \r
+     * the variables calling this function cannot be parameters or constants.\r
+     * \r
+     * @param g ReadGraph\r
+     * @param r Function resource\r
+     * @return\r
+     * @throws DatabaseException\r
+     */\r
+    @UpdateMethod\r
+    public boolean update(ReadGraph g, Resource r) throws DatabaseException {\r
+        String code = g.getPossibleRelatedValue(r, SysdynResource.getInstance(g).SysdynModelicaFunction_modelicaFunctionCode);\r
+        String[] elements = code.split("[\\+\\-\\*\\/\\(\\)\\[\\]\\{\\}=;\\s]");\r
+        hasTimeReference = false;\r
+        for(String element : elements) {\r
+            if("time".equals(element)) {\r
+                hasTimeReference = true;\r
+                break;\r
+            }\r
+        }\r
+        return true;\r
+    }\r
+\r
+    public boolean hasTimeReference() {\r
+        return hasTimeReference;\r
+    }\r
+\r
+}\r
diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/FunctionLibrary.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/FunctionLibrary.java
new file mode 100644 (file)
index 0000000..5300a34
--- /dev/null
@@ -0,0 +1,78 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2012 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.representation;\r
+\r
+import java.util.ArrayList;\r
+\r
+\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.objmap.annotations.GraphType;\r
+import org.simantics.objmap.annotations.RelatedElements;\r
+import org.simantics.objmap.annotations.RelatedValue;\r
+import org.simantics.sysdyn.SysdynResource;\r
+/**\r
+ * Representation of a function library\r
+ * \r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
+@GraphType(SysdynResource.URIs.SysdynModelicaFunctionLibrary)\r
+public class FunctionLibrary {\r
+    \r
+    @RelatedValue(Layer0.URIs.HasName)\r
+    private String name;\r
+\r
+    @RelatedElements(\r
+            value = Layer0.URIs.ConsistsOf,\r
+            composition = true)\r
+    private ArrayList<Object> elements = new ArrayList<Object>();\r
+\r
+    /**\r
+     * Get all functions inside this library. (sub-libraries excluded)\r
+     * @return\r
+     */\r
+    public ArrayList<Function> getFunctions() {\r
+        ArrayList<Function> functions = new ArrayList<Function>();\r
+        if(elements != null) {\r
+            for(Object element : elements) {\r
+                if(element instanceof Function)\r
+                    functions.add((Function)element);\r
+            }\r
+        }\r
+        return functions;\r
+    }\r
+    \r
+    /**\r
+     * Get all function libraries included in this library\r
+     * @return All function libraries included in this library\r
+     */\r
+    public ArrayList<FunctionLibrary> getLibraries() {\r
+        ArrayList<FunctionLibrary> libraries = new ArrayList<FunctionLibrary>();\r
+        if(elements != null) {\r
+            for(Object element : elements) {\r
+                if(element instanceof FunctionLibrary)\r
+                    libraries.add((FunctionLibrary)element);\r
+            }\r
+        }\r
+        return libraries;\r
+    }\r
+    \r
+    /**\r
+     * Get the name of this library\r
+     * @return The name of this library\r
+     */\r
+    public String getName() {\r
+        return name;\r
+    }\r
+\r
+\r
+}\r
index fa6b9f59afffbee309804f544432ba8fb53ebf7b..4ae415bfb4b72ede74bbac16eb86473ec4feb8cd 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************\r
- * Copyright (c) 2010 Association for Decentralized Information Management in\r
+ * Copyright (c) 2010, 2012 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
 package org.simantics.sysdyn.representation;\r
 \r
 import java.util.ArrayList;\r
+import java.util.Iterator;\r
 \r
 import org.simantics.sysdyn.representation.expressions.IExpression;\r
-import org.simantics.sysdyn.representation.expressions.ParameterExpression;\r
+import org.simantics.sysdyn.representation.utils.FormatUtils;\r
 \r
+/**\r
+ * Representation of an independent variable\r
+ * \r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
 public abstract class IndependentVariable extends Variable {\r
-    \r
+\r
+    /**\r
+     * Get the declaration of this variable\r
+     * @return Declaration of this variable\r
+     */\r
     public String getDeclaration() {\r
-       ArrayList<IExpression> expressions = this.expressions.getExpressions();\r
-       return expressions.get(0).getDeclaration(this);\r
-       \r
-       /*\r
-       ArrayList<IExpression> expressions = this.expressions.getExpressions();\r
-       ArrayIndexes ai = this.getArrayIndexes();\r
-       ArrayList<Enumeration> enumerations = null;\r
-       if(ai != null) \r
-               enumerations = ai.getEnumerations();\r
-       if(enumerations == null || enumerations.size() < 1) {\r
-               // NOT an array variable, get declaration from the only expression.\r
-               if(expressions.get(0) == null)\r
-                       return null;\r
-               else\r
-                       return expressions.get(0).getDeclaration(this);\r
-       } else {\r
-               // ARRAY variable. Create declaration according to the type, name and indexes\r
-               //TODO: check if all of them are parameters -> form a parameter\r
-               StringBuilder sb = new StringBuilder();\r
-               sb.append("    ");\r
-               sb.append(this.getType());\r
-               sb.append(" ");\r
-               sb.append(this.getName());\r
-               sb.append("[");\r
-               Iterator<Enumeration> iterator = enumerations.iterator();\r
-               while(iterator.hasNext()) {\r
-                       sb.append(iterator.next().getName());\r
-                       if(iterator.hasNext()) {\r
-                               sb.append(", ");\r
-                       }\r
-               }\r
-               sb.append("];\n");\r
-               return sb.toString();\r
-       }\r
-       */\r
+        Variability variability = Variability.getVariability(this);\r
+        \r
+        // [variability] type name[range]\r
+        StringBuilder sb = new StringBuilder();\r
+        sb.append("    ");\r
+        sb.append(variability.getText().isEmpty() ? "" : variability.getText() + " ");\r
+        sb.append(getType() + " ");\r
+        sb.append(getName());\r
+        sb.append(getRange());\r
+\r
+        // [= expression]\r
+        if(variability == Variability.PARAMETER || variability == Variability.CONSTANT) {\r
+            // parameters and constants are guaranteed to have only one expression\r
+            String equation = FormatUtils.formatExpressionForModelica(this, getExpressions().getExpressions().get(0).getExpression(this));\r
+            sb.append(" = " + equation);\r
+        }\r
+\r
+        // ;\n\r
+        sb.append(";\n");\r
+\r
+        // Possible additions to expressions. e.g. helper classes and variables\r
+        String addition;\r
+        for(IExpression e : getExpressions().getExpressions()) {\r
+            addition = e.getDeclarationAddition(this);\r
+            if(addition != null)\r
+                sb.append(addition);\r
+        }\r
+\r
+        return sb.toString();\r
+    }\r
+\r
+    /**\r
+     * Get the range of this variable, if it is an array variable. \r
+     * <p>\r
+     * Format: [EnumerationName.size (, Enumeration2Name.size)*] \r
+     * @return Range of this variable, if it is an array variable. Empty string otherwise.\r
+     */\r
+    public String getRange() {\r
+        ArrayIndexes ai = getArrayIndexes();\r
+        ArrayList<Enumeration> enumerations = null;\r
+        if(ai != null) \r
+            enumerations = ai.getEnumerations();\r
+\r
+        String range = "";\r
+        if(enumerations != null && enumerations.size() > 0) {\r
+            StringBuilder sb = new StringBuilder();\r
+            sb.append("[");\r
+            Iterator<Enumeration> iterator = enumerations.iterator();\r
+            while(iterator.hasNext()) {\r
+                sb.append(iterator.next().getName() + ".size");\r
+                if(iterator.hasNext()) {\r
+                    sb.append(", ");\r
+                }\r
+            }\r
+            sb.append("]");\r
+            range = sb.toString();\r
+        }\r
+        return range;\r
     }\r
-    \r
+\r
+    /**\r
+     * Get all initial equations or null, if there are no initial equations.\r
+     * @return Initial equations as string or null.\r
+     */\r
     public String getInitialEquation() {\r
-               StringBuilder sb = new StringBuilder();                 \r
+        StringBuilder sb = new StringBuilder();                \r
 \r
-               for(IExpression expression : expressions.getExpressions()) {\r
-                       String initialEquation = expression.getInitialEquation(this);\r
-                       if(initialEquation != null)\r
-                               sb.append(initialEquation);\r
-               }\r
-               String result = sb.toString();\r
-       return result.length() > 0 ? result : null;\r
+        for(IExpression expression : expressions.getExpressions()) {\r
+            String initialEquation = expression.getInitialEquation(this);\r
+            if(initialEquation != null)\r
+                sb.append(initialEquation);\r
+        }\r
+        String result = sb.toString();\r
+        return result.length() > 0 ? result : null;\r
     }\r
-    \r
+\r
+    /**\r
+     * Get the equation of this variable for equation block. Null is returned if this variable is not continuous.\r
+     * @return Equation or null\r
+     */\r
     public String getEquation() {\r
-       ArrayList<IExpression> expressions = this.expressions.getExpressions();\r
-       ArrayIndexes ai = this.getArrayIndexes();\r
-       ArrayList<Enumeration> enumerations = null;\r
-       if(ai != null) \r
-               enumerations = ai.getEnumerations();\r
-               IExpression firstExpression = expressions.get(0);\r
-       if(enumerations == null || enumerations.size() < 1) {\r
-               // NOT an array variable, get equation from the only expression.\r
-               if(firstExpression == null || firstExpression instanceof ParameterExpression)\r
-                       return null;\r
-               else\r
-                       return firstExpression.getEquation(this);\r
-       } else {\r
-               // ARRAY variable. Create all equations for the variable\r
-               //TODO: check that it has not been a parameter\r
-               StringBuilder sb = new StringBuilder();                 \r
-               for(IExpression expression : expressions) {\r
-                       sb.append(expression.getEquation(this));\r
-               }\r
-               return sb.toString();\r
-       }\r
-       \r
+        Variability variability =  Variability.getVariability(this);\r
+        if(variability == Variability.CONTINUOUS) {\r
+            return getVariableEquation();\r
+        } else {\r
+            return null;\r
+        }\r
+\r
+    }\r
+\r
+    /**\r
+     * Combines all possible equations for this variable. Array variables can have multiple equations.\r
+     * @return equations or null\r
+     */\r
+    protected String getVariableEquation() {\r
+        ArrayList<IExpression> expressions = this.expressions.getExpressions();\r
+        ArrayIndexes ai = this.getArrayIndexes();\r
+        ArrayList<Enumeration> enumerations = null;\r
+        if(ai != null) \r
+            enumerations = ai.getEnumerations();\r
+        IExpression firstExpression = expressions.get(0);\r
+        if(enumerations == null || enumerations.size() < 1) {\r
+            if(firstExpression == null)\r
+                return null;\r
+            else\r
+                return firstExpression.getEquation(this);\r
+        } else {\r
+            // ARRAY variable. Create all equations for the variable\r
+            StringBuilder sb = new StringBuilder();         \r
+            for(IExpression expression : expressions) {\r
+                sb.append(expression.getEquation(this));\r
+            }\r
+            return sb.toString();\r
+        }\r
     }\r
 }\r
index 96f3a5c4be102e0ab59655c8393c049bc83df8e3..f3e10ac98e785f6d33f18b95a92ea79f44c84548 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************\r
- * Copyright (c) 2010 Association for Decentralized Information Management in\r
+ * Copyright (c) 2010, 2012 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
@@ -21,6 +21,12 @@ import org.simantics.objmap.annotations.RelatedValue;
 import org.simantics.sysdyn.SysdynResource;\r
 import org.simantics.sysdyn.representation.visitors.IElementVisitorVoid;\r
 \r
+/**\r
+ * Representation of an input variable \r
+ * \r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
 @GraphType(SysdynResource.URIs.Input)\r
 public class Input extends Variable {\r
 \r
@@ -29,13 +35,20 @@ public class Input extends Variable {
     @RelatedElements(SysdynResource.URIs.Variable_isHeadOf)\r
     private List<IElement> isHeadOf;\r
     \r
-    \r
-    \r
     @Override\r
     public void accept(IElementVisitorVoid v) {\r
         v.visit(this);\r
     }\r
 \r
+    /**\r
+     * Get the default value for this input. Default values may be set in either \r
+     * inside input's own module or in its parent module. If the value is set in a \r
+     * parent module, give input module's instance name as inModule.\r
+     * \r
+     * @param inModule The name of the instance in which this variable is. \r
+     * Can be null, if default value is set inside the variable's own module.\r
+     * @return Default input value.\r
+     */\r
     public String getDefaultInputValue(String inModule) {\r
         if( getArrayIndexes() == null || getArrayIndexes().getEnumerations().isEmpty()) {\r
             return defaultInputValue.toString();\r
@@ -47,7 +60,7 @@ public class Input extends Variable {
             Iterator<Enumeration> i = getArrayIndexes().getEnumerations().iterator();\r
             while(i.hasNext()) {\r
                 Enumeration e = i.next();\r
-                sb.append((!inModule.isEmpty() && inModule != null ? inModule + "." : "") + e.getName() + ".size");\r
+                sb.append((inModule != null && !inModule.isEmpty() ? inModule + "." : "") + e.getName() + ".size");\r
                 if(i.hasNext())\r
                     sb.append(", ");\r
             }\r
@@ -56,14 +69,37 @@ public class Input extends Variable {
         }\r
     }\r
     \r
+    /**\r
+     * Get the default value for this input inside it's own module.\r
+     * @return Default value\r
+     */\r
     public String getDefaultInputValue() {\r
         return getDefaultInputValue(null);\r
     }\r
 \r
+    /**\r
+     * Is there a connection to this input variable from a module. (i.e. does this input variable possibly get its value from a child module)\r
+     * @return\r
+     */\r
     public boolean isHeadOfDependency() {\r
         return !isHeadOf.isEmpty();\r
     }\r
     \r
+    /**\r
+     * Get the declaration of this input variable with its default value\r
+     * @return declaration of this input variable with its default value\r
+     */\r
+    public String getDeclarationWithValue() {\r
+        String declaration = getDeclaration();\r
+        declaration = declaration.substring(0, declaration.length() - 2); // remove ";\n"\r
+        declaration += " = " + getDefaultInputValue() + ";\n";\r
+        return declaration;\r
+    }\r
+    \r
+    /**\r
+     * Get the declaration of this input variable without a default value\r
+     * @return declaration of this input variable without a default value\r
+     */\r
     public String getDeclaration() {\r
        ArrayIndexes ai = getArrayIndexes();\r
        ArrayList<Enumeration> enumerations = null;\r
@@ -85,6 +121,7 @@ public class Input extends Variable {
                range = sb.toString();\r
        }\r
        \r
-        return "    " + getType() + " " + getName() + range + ";\n";\r
+       boolean continuous = variability == null || variability.isEmpty();\r
+        return "    " + (continuous ? "" : variability + " ") + getType() + " " + getName() + range + ";\n";\r
     }\r
 }\r
index 9e0c59b1dc38d16c058924ae9924f48c4472f0c5..6abe502c08f6c5d6a0f87bad028e1f15bdc14fae 100644 (file)
@@ -1,16 +1,43 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2012 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.representation;\r
 \r
 import org.simantics.layer0.Layer0;\r
 import org.simantics.objmap.annotations.GraphType;\r
+import org.simantics.objmap.annotations.RelatedValue;\r
 import org.simantics.sysdyn.representation.visitors.IElementVisitorVoid;\r
 \r
-\r
+/**\r
+ * A dummy variable representing any possible library\r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
 @GraphType(Layer0.URIs.Library)\r
 public class LibraryDummy implements IElement {\r
+    \r
+    @RelatedValue(Layer0.URIs.HasName)\r
+    private String name;\r
        \r
     @Override\r
     public void accept(IElementVisitorVoid v) {\r
         v.visit(this);        \r
     }\r
+    \r
+    /**\r
+     * Name of the library\r
+     * @return Name of the library\r
+     */\r
+    public String getName() {\r
+        return name;\r
+    }\r
 \r
 }\r
index d2d5da2daa549caa880a8520eb5093b1f210e1f2..dbda4ea31a56f047dd72efb939c55f1e61cf4817 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************\r
- * Copyright (c) 2010 Association for Decentralized Information Management in\r
+ * Copyright (c) 2010, 2012 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
  *******************************************************************************/\r
 package org.simantics.sysdyn.representation;\r
 \r
+import java.util.ArrayList;\r
+import java.util.HashMap;\r
+\r
+import org.simantics.layer0.Layer0;\r
 import org.simantics.objmap.annotations.GraphType;\r
+import org.simantics.objmap.annotations.RelatedElements;\r
 import org.simantics.objmap.annotations.RelatedValue;\r
 import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.representation.annotations.BuiltinFunctions;\r
 \r
+/**\r
+ * Representation of a system dynamics model\r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
 @GraphType(SysdynResource.URIs.SysdynModel)\r
 public class Model {\r
 \r
     @RelatedValue(SysdynResource.URIs.SysdynModel_startTime)\r
     private Double startTime = 0.0;\r
-    \r
+\r
     @RelatedValue(SysdynResource.URIs.SysdynModel_stopTime)\r
     private Double stopTime = 10.0;\r
-    \r
+\r
     @RelatedValue(SysdynResource.URIs.SysdynModel_outputInterval)\r
     private Double outputInterval;\r
-    \r
+\r
     @RelatedValue(SysdynResource.URIs.SysdynModel_tolerance)\r
     private Double tolerance;\r
-    \r
+\r
     @RelatedValue(SysdynResource.URIs.SysdynModel_solver)\r
     private String solver;\r
+    \r
+    @RelatedValue(SysdynResource.URIs.SysdynModel_variableFilter)\r
+    private String variableFilter;\r
+\r
+    @RelatedElements(\r
+            value = Layer0.URIs.ConsistsOf,\r
+            composition = true)\r
+    private ArrayList<Object> consistsOf = new ArrayList<Object>();\r
+    \r
+    @RelatedElements(\r
+            value = Layer0.URIs.IsLinkedTo,\r
+            composition = true)\r
+    private ArrayList<Object> linkedTo = new ArrayList<Object>();\r
+    \r
+    \r
+    @BuiltinFunctions\r
+    private FunctionLibrary builtins;\r
 \r
+    /**\r
+     * \r
+     * @return Simulation start time\r
+     */\r
     public Double getStartTime() {\r
         return startTime;\r
     }\r
 \r
+    /**\r
+     * \r
+     * @return Simulation end time\r
+     */\r
     public Double getStopTime() {\r
         return stopTime;\r
     }\r
-    \r
+\r
+    /**\r
+     * Result output interval\r
+     * @return\r
+     */\r
     public Double getOutputInterval() {\r
-       return outputInterval;\r
+        return outputInterval;\r
     }\r
 \r
+    /**\r
+     * \r
+     * @return Tolerance for simulation engine\r
+     */\r
     public Double getTolerance() {\r
         return tolerance;\r
     }\r
 \r
+    /**\r
+     * \r
+     * @return Solver name\r
+     */\r
     public String getSolver() {\r
         return solver;\r
     }\r
     \r
+    /**\r
+     * \r
+     * @return variableFilter or ".*" if null\r
+     */\r
+    public String getVariableFilter() {\r
+        if(variableFilter == null || variableFilter.isEmpty())\r
+            return ".*";\r
+        else\r
+            return variableFilter;\r
+    }\r
+\r
+    /**\r
+     * Get all functions that are linked to this model: built-in functions, model's own functions and shared function libraries\r
+     * @return all functions liked to this model\r
+     */\r
+    public HashMap<String, Function> getFunctions() {\r
+        HashMap<String, Function> functions = new HashMap<String, Function>();\r
+        if(consistsOf != null ) {\r
+            for(Object o : consistsOf) {\r
+                if(o instanceof Function) {\r
+                    Function f = (Function) o;\r
+                    functions.put(f.getName(), f);\r
+                } else if (o instanceof FunctionLibrary) {\r
+                    addFunctions("", (FunctionLibrary)o, functions);\r
+                }\r
+            }\r
+        }\r
+        \r
+        if(linkedTo != null) {\r
+            for(Object o : linkedTo) {\r
+                if(o instanceof SharedFunctionLibrary) {\r
+                    SharedFunctionLibrary fl = (SharedFunctionLibrary)o;\r
+                    addFunctions(fl.getName(), fl, functions);\r
+                }\r
+            }\r
+        }\r
+        \r
+        if(builtins != null)\r
+            addBuiltinFunctions(builtins, functions);\r
+        \r
+        return functions;\r
+    }\r
+    \r
+    /**\r
+     * Add built-in functions to functions map. Built-in functions do not have any library path.\r
+     * @param library Built-in function library\r
+     * @param functions Function map containing all functions\r
+     */\r
+    private void addBuiltinFunctions(FunctionLibrary library, HashMap<String, Function> functions) {\r
+        for(Function f : library.getFunctions())\r
+            functions.put(f.getName(), f);\r
+        for(FunctionLibrary fl : library.getLibraries())\r
+            addBuiltinFunctions(fl, functions);\r
+    }\r
+    \r
+    /**\r
+     * Add functions from a library to a library map\r
+     * @param path Path to the library\r
+     * @param library Function library\r
+     * @param functions Function map containing all functions\r
+     */\r
+    private void addFunctions(String path, FunctionLibrary library, HashMap<String, Function> functions) {\r
+        for(Function f : library.getFunctions())\r
+            functions.put(path + (path.isEmpty() ? "" : ".") + f.getName(), f);\r
+        for(FunctionLibrary fl : library.getLibraries())\r
+            addFunctions((path.isEmpty() ? "" : path + ".") + fl.getName(), fl, functions);\r
+    }\r
+    \r
+    /**\r
+     * \r
+     * @return Built-in functions library\r
+     */\r
+    public FunctionLibrary getBuiltins() {\r
+        return builtins;\r
+    }\r
 }\r
index c5ece68c5759a043ed687912e42a5707a163fc7b..415fdc05d309a0dcf6613060eece6eadac26aa98 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************\r
- * Copyright (c) 2010 Association for Decentralized Information Management in\r
+ * Copyright (c) 2010, 2012 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
@@ -22,7 +22,13 @@ import org.simantics.objmap.annotations.RelatedElements;
 import org.simantics.objmap.annotations.RelatedValue;\r
 import org.simantics.sysdyn.SysdynResource;\r
 import org.simantics.sysdyn.representation.visitors.IElementVisitorVoid;\r
+import org.simantics.utils.datastructures.Pair;\r
 \r
+/**\r
+ * Representation of a module instance\r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
 @GraphType(SysdynResource.URIs.Module)\r
 public class Module implements IElement {\r
 \r
@@ -34,7 +40,7 @@ public class Module implements IElement {
 \r
     @RelatedElement(Layer0.URIs.InstanceOf)\r
     private ModuleType type;\r
-    \r
+\r
     @RelatedElements(SysdynResource.URIs.Module_redeclaration)\r
     private List<Redeclaration> redeclarations;\r
     \r
@@ -46,63 +52,155 @@ public class Module implements IElement {
     public String getName() {\r
         return name;\r
     }\r
-    \r
+\r
     public ModuleType getType() {\r
-       return type;\r
+        return type;\r
     }\r
-    \r
+\r
     /**\r
-     * Returns the declaration of a module with possible redeclared enumerations\r
-     *     \r
-     * parameter Integer Enum__size = Enum.size;\r
-     * parameter Integer Enum__elements[:] = Enum.elements;\r
-     * ModuleType ModuleType1(Enum.size = Enum__size, Enum.elements = Enum__elements);\r
+     * Returns the declaration of a module with possible redeclared enumerations and parameter assignments\r
+     *\r
+     * <p>\r
+     * Enumeration redeclaration:\r
+     * parameter Integer Enum__size = Enum.size; <br>\r
+     * parameter Integer Enum__elements[:] = Enum.elements; <br>\r
+     * ModuleType ModuleType1(Enum.size = Enum__size, Enum.elements = Enum__elements); <br>\r
      * \r
+     * <p>\r
      * Temporary parameter variables are needed to avoid name conflicts when redeclaring an \r
      * enumeration with the same name.\r
      * \r
      * @return Declaration of a module instance\r
      */\r
     public String getDeclaration() {\r
-       \r
-       StringBuilder redeclarations = new StringBuilder();\r
-       if(!getRedeclarations().isEmpty()) {\r
-               redeclarations.append("(");\r
-               Iterator<Redeclaration> i = getRedeclarations().iterator();\r
-               while(i.hasNext()) {\r
-                       Redeclaration rd = i.next();\r
-                       redeclarations.append(rd.getRedeclaration());\r
-                       if(i.hasNext())\r
-                               redeclarations.append(",");\r
-               }\r
-               redeclarations.append(")");\r
-       }\r
-       \r
-       \r
-       StringBuilder sb = new StringBuilder();\r
-       sb.append("    ");\r
-       sb.append(getType().getName());\r
-       sb.append(" ");\r
-       sb.append(getName());\r
-       sb.append(redeclarations.toString());\r
-       sb.append(";\n");\r
-       return sb.toString();\r
+\r
+\r
+        String enumerationRedeclarations = getEnumerationRedeclarations();\r
+        Pair<String, String> inputRedeclarations = getInputRedeclarations();\r
+\r
+        StringBuilder redeclarations = new StringBuilder();\r
+\r
+        if(!enumerationRedeclarations.isEmpty() || !inputRedeclarations.first.isEmpty()) {\r
+            redeclarations.append("(");\r
+            redeclarations.append(enumerationRedeclarations);\r
+\r
+            String ir = inputRedeclarations.first;\r
+            if(enumerationRedeclarations.isEmpty() && !inputRedeclarations.first.isEmpty())\r
+                // remove first ", " if no enumeration redeclarations\r
+                ir = inputRedeclarations.first.substring(2); \r
+            redeclarations.append(ir);\r
+\r
+            redeclarations.append(")");\r
+        }\r
+\r
+        StringBuilder sb = new StringBuilder();\r
+\r
+        // Possible reference variables\r
+        if(inputRedeclarations.second != null && !inputRedeclarations.second.isEmpty()) {\r
+            sb.append(inputRedeclarations.second);\r
+        }\r
+\r
+        sb.append("    ");\r
+        sb.append(getType().getName());\r
+        sb.append(" ");\r
+        sb.append(getName());\r
+        sb.append(redeclarations.toString()); // possible redeclarations\r
+        sb.append(";\n");\r
+        return sb.toString();\r
+    }\r
+\r
+    /**\r
+     * Get possible enumeration redeclarations.\r
+     * @return enumeration redeclarations or empty string\r
+     */\r
+    private String getEnumerationRedeclarations() {\r
+        StringBuilder redeclarations = new StringBuilder();\r
+        if(!getRedeclarations().isEmpty()) {\r
+\r
+            Iterator<Redeclaration> i = getRedeclarations().iterator();\r
+            while(i.hasNext()) {\r
+                Redeclaration rd = i.next();\r
+                redeclarations.append(rd.getRedeclaration());\r
+                if(i.hasNext())\r
+                    redeclarations.append(",");\r
+            }\r
+        }\r
+        return redeclarations.toString();\r
+    }\r
+\r
+    /**\r
+     * Get possible input redeclarations\r
+     * @return input redeclarations or empty string\r
+     */\r
+    private Pair<String, String> getInputRedeclarations() {\r
+        StringBuilder declarations = new StringBuilder();\r
+        StringBuilder references = new StringBuilder();\r
+\r
+        for(IElement element : parentConfiguration.getElements()) {\r
+            if (element instanceof Dependency) {\r
+                Dependency dependency = (Dependency)element;\r
+                if(dependency.getHead().equals(this)){\r
+                    Input reference = (Input)dependency.refersTo();\r
+                    Variable outputVariable = (Variable)dependency.getTail();\r
+                    String name = outputVariable.getName();\r
+\r
+                    Module module = (Module)dependency.getHead();\r
+\r
+                    if(reference != null && reference.getName() != null) {\r
+                        if(reference.getVariability() == null || reference.getVariability().isEmpty())\r
+                            continue; // Only parameters and constants are redeclared\r
+\r
+                        for(IElement e : module.getType().getConfiguration().getElements()) {\r
+                            if(e instanceof Variable) {\r
+                                Variable v = (Variable)e;\r
+\r
+                                if(v.getName() != null && outputVariable.getName().equals(v.getName())) {\r
+                                    /*\r
+                                     *  The target module contains a variable with the same name. Need to\r
+                                     *  avoid Module(variable = variable) situations \r
+                                     */\r
+                                    String declaration;\r
+                                    if(outputVariable instanceof Input)\r
+                                        declaration = ((Input)outputVariable).getDeclaration();\r
+                                    else\r
+                                        declaration = ((IndependentVariable)outputVariable).getDeclaration();\r
+\r
+                                    if(declaration.contains("="))\r
+                                        declaration = declaration.substring(0, declaration.indexOf("=") - 1); // Break to "="\r
+                                    else\r
+                                        declaration = declaration.substring(0, declaration.length() - 2); // Remove ending ";\n" \r
+\r
+                                    name = outputVariable.getName() + "_reference";\r
+                                    declaration = declaration.replace(outputVariable.getName(), name);\r
+                                    declaration += " = " + outputVariable.getName() + " /* Reference value to avoid name conflicts in module instantiation */ ;\n";\r
+                                    references.append(declaration);\r
+                                    break;\r
+                                }\r
+                            }\r
+                        }\r
+\r
+                        declarations.append(", " + reference.getName() + " = " + name);\r
+                    }\r
+                }\r
+            }\r
+        }\r
+        return new Pair<String, String>(declarations.toString(), references.toString());\r
     }\r
 \r
     public Configuration getParentConfiguration() {\r
         return this.parentConfiguration;\r
     }\r
-    \r
+\r
     /**\r
      * Return the list of the defined redeclarations for this module instance.\r
      * \r
      * @return List of the defined redeclarations or an empty list if redeclarations have not been set \r
      */\r
     public List<Redeclaration> getRedeclarations() {\r
-       if(redeclarations == null) {\r
-               redeclarations = new ArrayList<Redeclaration>();\r
-       }\r
-       return redeclarations;\r
+        if(redeclarations == null) {\r
+            redeclarations = new ArrayList<Redeclaration>();\r
+        }\r
+        return redeclarations;\r
     }\r
 \r
 }\r
index 148018c7d255827d2fe69274ef0f24c186bed9ae..5b57d2b443ae4e5b40a7e4a68ef1b8f098c07adf 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************\r
- * Copyright (c) 2010 Association for Decentralized Information Management in\r
+ * Copyright (c) 2010, 2012 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,12 @@ import org.simantics.objmap.annotations.RelatedValue;
 import org.simantics.structural.stubs.StructuralResource2;\r
 import org.simantics.sysdyn.representation.visitors.IElementVisitorVoid;\r
 \r
+/**\r
+ * Representation of a module type\r
+ * \r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
 @GraphType(StructuralResource2.URIs.ComponentType)\r
 public class ModuleType implements IElement {\r
 \r
@@ -26,6 +32,9 @@ public class ModuleType implements IElement {
     \r
     @RelatedElement(StructuralResource2.URIs.IsDefinedBy)\r
     private Configuration configuration;\r
+    \r
+    @RelatedElement(Layer0.URIs.PartOf)\r
+    protected Object parent;\r
 \r
     public String getName() {\r
        return name;\r
@@ -38,5 +47,9 @@ public class ModuleType implements IElement {
        @Override\r
        public void accept(IElementVisitorVoid v) {\r
        }\r
+       \r
+       public Object getParent() {\r
+           return parent;\r
+       }\r
 \r
 }\r
diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/SharedFunctionLibrary.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/SharedFunctionLibrary.java
new file mode 100644 (file)
index 0000000..357f9d0
--- /dev/null
@@ -0,0 +1,26 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2012 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.representation;\r
+\r
+import org.simantics.objmap.annotations.GraphType;\r
+import org.simantics.sysdyn.SysdynResource;\r
+\r
+/**\r
+ * Representation of a shared function library. See {@link FunctionLibrary} \r
+ * \r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
+@GraphType(SysdynResource.URIs.SharedFunctionOntology)\r
+public class SharedFunctionLibrary extends FunctionLibrary {\r
+\r
+}\r
index ec92d29852a2d9c0871aaea545c45c8152b3615b..9dde7e4fb5117ea9c45892d185e5ad9d81a84eef 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************\r
- * Copyright (c) 2010 Association for Decentralized Information Management in\r
+ * Copyright (c) 2010, 2012 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
@@ -16,50 +16,106 @@ import java.util.ArrayList;
 import org.simantics.objmap.annotations.GraphType;\r
 import org.simantics.objmap.annotations.RelatedElements;\r
 import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.representation.expressions.StockExpression;\r
 import org.simantics.sysdyn.representation.visitors.IElementVisitorVoid;\r
 \r
+/**\r
+ * Representation of a Stock variable\r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
 @GraphType(SysdynResource.URIs.Stock)\r
 public class Stock extends IndependentVariable {\r
 \r
     @RelatedElements(\r
             value = SysdynResource.URIs.Variable_isHeadOf,\r
             composition = true)\r
-            private ArrayList<IElement> incomingConnections = new ArrayList<IElement>();\r
-    \r
+    private ArrayList<IElement> incomingConnections = new ArrayList<IElement>();\r
+\r
 \r
     @RelatedElements(\r
             value = SysdynResource.URIs.Variable_isTailOf,\r
             composition = true)\r
-            private ArrayList<IElement> outgoingConnections = new ArrayList<IElement>();\r
-    \r
+    private ArrayList<IElement> outgoingConnections = new ArrayList<IElement>();\r
+\r
     @Override\r
     public void accept(IElementVisitorVoid v) {\r
         v.visit(this);        \r
     }\r
 \r
-       public ArrayList<Valve> getIncomingValves() {\r
-               ArrayList<Valve> valves = new ArrayList<Valve>();\r
-               for(IElement element : incomingConnections) {\r
-                       if(element instanceof Flow) {\r
-                               Flow flow = (Flow)element;\r
-                               valves.add((Valve)flow.getTail());\r
-                       }\r
-               }\r
-               return valves;\r
-       }\r
-\r
-       public ArrayList<Valve> getOutgoingValves() {\r
-               ArrayList<Valve> valves = new ArrayList<Valve>();\r
-               for(IElement element : outgoingConnections) {\r
-                       if(element instanceof Flow) {\r
-                               Flow flow = (Flow)element;\r
-                               valves.add((Valve)flow.getHead());\r
-                       }\r
-               }\r
-               return valves;\r
-       }\r
-    \r
+    @Override\r
+    public String getInitialEquation() {\r
+        if (Variability.getVariability(this) == Variability.CONTINUOUS) {\r
+            return super.getInitialEquation();\r
+        } else {\r
+            return null;\r
+        }\r
+    }\r
     \r
+    @Override\r
+    public String getDeclaration() {\r
+\r
+        ArrayIndexes ai = getArrayIndexes();\r
+\r
+        String each = "";\r
+        // each is required when a single value is used for all dimensions e.g. Stock[30](each start = 0)  \r
+        if (Variability.getVariability(this) == Variability.CONTINUOUS) {\r
+            // start parameter is not used, everything needs to be fixed=false\r
+            if(ai != null && !ai.getEnumerations().isEmpty())\r
+                each = "each";\r
+            return "    " + getType() + " " + getName() + getRange() + "(" + each + " fixed=false);\n";\r
+        } else {\r
+            // Start parameter is used. Parameter guarantees that there is only one expression.\r
+            StockExpression e = (StockExpression)getExpressions().getExpressions().get(0);\r
+            String initialEquation = e.getExpression(this);\r
+\r
+            if(ai != null && !ai.getEnumerations().isEmpty())\r
+                each = "each";\r
+\r
+\r
+            return "    " + \r
+            getType() + \r
+            " " + \r
+            getName() + \r
+            getRange() + \r
+            "(" + \r
+            (e.getStartValue(this) != null ? each : "") + \r
+            " start=" + \r
+            initialEquation + \r
+            ", " + \r
+            each + \r
+            " fixed=true);\n";\r
+        }\r
+    }\r
+\r
+    public String getEquation() {\r
+        return getVariableEquation();\r
+    }\r
+\r
+\r
+    public ArrayList<Valve> getIncomingValves() {\r
+        ArrayList<Valve> valves = new ArrayList<Valve>();\r
+        for(IElement element : incomingConnections) {\r
+            if(element instanceof Flow) {\r
+                Flow flow = (Flow)element;\r
+                valves.add((Valve)flow.getTail());\r
+            }\r
+        }\r
+        return valves;\r
+    }\r
+\r
+    public ArrayList<Valve> getOutgoingValves() {\r
+        ArrayList<Valve> valves = new ArrayList<Valve>();\r
+        for(IElement element : outgoingConnections) {\r
+            if(element instanceof Flow) {\r
+                Flow flow = (Flow)element;\r
+                valves.add((Valve)flow.getHead());\r
+            }\r
+        }\r
+        return valves;\r
+    }\r
+\r
+\r
 }\r
 \r
 \r
index aadf2a0fc1bbf80853c21bdf842b4a158324cc81..0621f8304a3c51a2ada2de0c5661583e07eddd4b 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************\r
- * Copyright (c) 2010, 2011 Association for Decentralized Information Management in\r
+ * Copyright (c) 2010, 2012 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
@@ -56,6 +56,10 @@ public class SysdynSchema extends SimpleSchema {
             addLinkType(MappingSchemas.fromAnnotations(g, Sheet.class));\r
             addLinkType(MappingSchemas.fromAnnotations(g, DiagramContainerDummy.class));\r
             addLinkType(MappingSchemas.fromAnnotations(g, DelayExpression.class));\r
+            addLinkType(MappingSchemas.fromAnnotations(g, FunctionLibrary.class));\r
+            addLinkType(MappingSchemas.fromAnnotations(g, SharedFunctionLibrary.class));\r
+            addLinkType(MappingSchemas.fromAnnotations(g, Function.class));\r
+            addLinkType(MappingSchemas.fromAnnotations(g, Entity.class));\r
         } catch (DatabaseException e) {\r
             e.printStackTrace();\r
         } catch (InstantiationException e) {\r
diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Variability.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Variability.java
new file mode 100644 (file)
index 0000000..db9d4ab
--- /dev/null
@@ -0,0 +1,180 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2012 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.representation;\r
+\r
+import java.io.StringReader;\r
+import java.util.ArrayList;\r
+import java.util.HashMap;\r
+import java.util.Set;\r
+\r
+import org.simantics.sysdyn.expressionParser.ExpressionParser;\r
+import org.simantics.sysdyn.expressionParser.ParseException;\r
+import org.simantics.sysdyn.representation.utils.FormatUtils;\r
+\r
+/**\r
+ * Variability of a variable in system dynamics models. \r
+ * \r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
+public enum Variability {\r
+    \r
+    PARAMETER("parameter"),\r
+    CONSTANT("constant"),\r
+    CONTINUOUS("");\r
+\r
+    private String text;\r
+\r
+    Variability(String text) {\r
+      this.text = text;\r
+    }\r
+\r
+    public String getText() {\r
+      return this.text;\r
+    }\r
+\r
+    /**\r
+     * Convert a textual representation to a Variability object. \r
+     * \r
+     * @param text Variability as text (parameter / constant / continuous)\r
+     * @return Variability or null\r
+     */\r
+    public static Variability fromString(String text) {\r
+      if (text != null) {\r
+        for (Variability v : Variability.values()) {\r
+          if (text.equalsIgnoreCase(v.text)) {\r
+            return v;\r
+          }\r
+        }\r
+      }\r
+      return null;\r
+    }\r
+    \r
+    /**\r
+     * Check if reference in a configuration is a parameter.\r
+     * @param configuration Configuration\r
+     * @param reference String reference to a variable\r
+     * @return is the reference a parameter\r
+     */\r
+    private static boolean isParameter(Configuration configuration, String reference) {\r
+        // Check if references are references to sheets. \r
+        // Sheet references are allowed, since sheets contain only constants\r
+\r
+        // We only need the first element to know that it is a Sheet (SheetName.CellOrRange)\r
+        String r = reference.split("\\.")[0]; \r
+        for(IElement element : configuration.getElements()) {\r
+            if(element instanceof Module) {\r
+                Module m = (Module)element;\r
+                if(r.equals(m.getName())) {\r
+                    if(!reference.contains(".")) {\r
+                        // The reference contains only modules, implementation feature for the expression parser\r
+                        return true;\r
+                    }\r
+                    Configuration moduleConfiguration = m.getType().getConfiguration();\r
+                    return isParameter(moduleConfiguration, reference.substring(reference.indexOf(".") + 1));\r
+                }\r
+            } else if(element instanceof Book) {\r
+                for(Sheet sheet : ((Book)element).getSheets()) {\r
+                    if(r.equals(sheet.getName())) {\r
+                        return true;\r
+                    }\r
+                }\r
+            } else if(element instanceof IndependentVariable && !(element instanceof Stock)) {\r
+                IndependentVariable v = (IndependentVariable)element;\r
+                if(r.equals(v.getName())) {\r
+                    return getVariability(v) != Variability.CONTINUOUS;\r
+                }\r
+            } else if(element instanceof Input) {\r
+                Input i = (Input)element;\r
+                if(r.equals(i.getName())) {\r
+                    return i.getVariability() != null && !i.getVariability().equals(Variability.CONTINUOUS.getText());\r
+                }\r
+                \r
+                \r
+            }\r
+        }\r
+        // If there was no sheet for this reference name, return false\r
+        return false;\r
+    }\r
+    \r
+    static public Variability getVariability(IndependentVariable variable) {\r
+        ArrayList<org.simantics.sysdyn.representation.expressions.IExpression> expressions = variable.getExpressions().getExpressions();\r
+\r
+        if(expressions.size() != 1)\r
+            return Variability.CONTINUOUS; // Cannot handle multiple expressions as parameters\r
+\r
+        org.simantics.sysdyn.representation.expressions.IExpression ie  = expressions.get(0);\r
+        \r
+        String expression = ie.getExpression(variable);\r
+        \r
+        return getVariability(variable, expression);\r
+    }\r
+    \r
+    /**\r
+     * Get the variability of an expression in a variable. Variables may have multiple expressions.\r
+     * \r
+     * @param variable Variable\r
+     * @param expression Expression\r
+     * @return Variability of the expression\r
+     */\r
+    static public Variability getVariability(IndependentVariable variable, String expression) {\r
+\r
+        // If no variables are used in the equation, start value is used\r
+        \r
+        HashMap<String, Function> functions = new HashMap<String, Function>();\r
+        if(variable.getParentConfiguration() != null) {\r
+            Configuration conf = variable.getParentConfiguration();\r
+            Model model = null;\r
+            if(conf.getModuleType() != null) {\r
+                ModuleType moduleType = conf.getModuleType();\r
+                if (moduleType.getParent() instanceof Model) {\r
+                    model = (Model) moduleType.getParent();\r
+                }\r
+            } else {\r
+                model = conf.getModel();\r
+            }\r
+            \r
+            if(model != null)\r
+                functions = model.getFunctions();\r
+        }\r
+        \r
+        // First the equation is formatted and parsed\r
+        String equation = FormatUtils.formatExpressionForModelica(variable, expression);\r
+        ExpressionParser parser = new ExpressionParser(new StringReader(equation));\r
+        try {\r
+            parser.expr();\r
+            if(parser.getReferences().isEmpty() && parser.getFunctionCallReferences().isEmpty()) {\r
+                // if equation did not contain any references, start value is used\r
+                return Variability.PARAMETER;\r
+            } else {\r
+                Set<String> references = parser.getReferences().keySet();\r
+                // Go through each reference\r
+                for(String reference : references) {\r
+                    if(!isParameter(variable.getParentConfiguration(), reference)) {\r
+                        return Variability.CONTINUOUS;\r
+                    }\r
+                }\r
+                \r
+                for(String function : parser.getFunctionCallReferences().keySet()) {\r
+                    if(functions.containsKey(function) && functions.get(function).hasTimeReference())\r
+                        return Variability.CONTINUOUS;\r
+                }\r
+                \r
+                // All found variables were sheets or non-continuous\r
+                return Variability.PARAMETER;\r
+            }\r
+        } catch (ParseException e) {\r
+        }\r
+        \r
+        return Variability.CONTINUOUS;\r
+    }\r
+  }\r
index f8d5a943f713f091c6a8e369edc827652adb07f9..1f1e1fc52a46ef158421b2f3633def0db487440a 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************\r
- * Copyright (c) 2010 Association for Decentralized Information Management in\r
+ * Copyright (c) 2010, 2012 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
@@ -17,6 +17,11 @@ import org.simantics.objmap.annotations.RelatedValue;
 import org.simantics.sysdyn.SysdynResource;\r
 import org.simantics.sysdyn.representation.expressions.Expressions;\r
 \r
+/**\r
+ * Abstract class for representing a variable in system dynamics models \r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
 public abstract class Variable implements IElement {\r
     \r
     @RelatedValue(SysdynResource.URIs.Variable_type)\r
@@ -34,11 +39,29 @@ public abstract class Variable implements IElement {
     @RelatedElement(SysdynResource.URIs.Variable_expressions)\r
     protected Expressions expressions;\r
     \r
-\r
+    @RelatedValue(SysdynResource.URIs.Variable_variability)\r
+    protected String variability;\r
+    \r
+    /**\r
+     * Return the variability of this variable (Used in practice only with Input variables)\r
+     * @return Variability\r
+     */\r
+    public String getVariability() {\r
+        return variability;\r
+    }\r
+    \r
+    /**\r
+     * \r
+     * @return The name of this variable\r
+     */\r
     public String getName() {\r
         return this.name;\r
     }\r
     \r
+    /**\r
+     *\r
+     * @return Parent configuration of this variable (or null if something is wrong)\r
+     */\r
     public Configuration getParentConfiguration() {\r
         if(parent instanceof Configuration) {\r
             return (Configuration)parent;\r
@@ -49,15 +72,28 @@ public abstract class Variable implements IElement {
         }\r
     }\r
 \r
+    /**\r
+     * \r
+     * @return The type of this variable (<u>Real</u> / Boolean / ...) \r
+     */\r
     public String getType() {\r
         return this.type;\r
     }\r
     \r
+    /**\r
+     * \r
+     * @return Array indexes for this variable\r
+     */\r
     public ArrayIndexes getArrayIndexes() {\r
        return this.arrayIndexes;\r
     }\r
     \r
+    /**\r
+     * \r
+     * @return Expressions of this variable\r
+     */\r
     public Expressions getExpressions() {\r
         return this.expressions;\r
     }\r
+    \r
 }\r
diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/annotations/BuiltinFunctions.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/annotations/BuiltinFunctions.java
new file mode 100644 (file)
index 0000000..173db2c
--- /dev/null
@@ -0,0 +1,31 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2012 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.representation.annotations;\r
+\r
+import java.lang.annotation.ElementType;\r
+import java.lang.annotation.Retention;\r
+import java.lang.annotation.RetentionPolicy;\r
+import java.lang.annotation.Target;\r
+\r
+import org.simantics.objmap.annotations.meta.HasFieldRuleFactory;\r
+\r
+/**\r
+ * BuiltinFunctions -annotation returns the built-in functions function library \r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
+@Retention(RetentionPolicy.RUNTIME)\r
+@Target(ElementType.FIELD)\r
+@HasFieldRuleFactory(BuiltinFunctionsFactory.class)\r
+public @interface BuiltinFunctions {\r
+}\r
+\r
diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/annotations/BuiltinFunctionsAccessor.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/annotations/BuiltinFunctionsAccessor.java
new file mode 100644 (file)
index 0000000..c010706
--- /dev/null
@@ -0,0 +1,57 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2012 Association for Decentralized Information Management\r
+ * in 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
+\r
+package org.simantics.sysdyn.representation.annotations;\r
+\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.request.PossibleObjectWithType;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.objmap.MappingException;\r
+import org.simantics.objmap.rules.domain.IDomainAccessor;\r
+import org.simantics.sysdyn.SysdynResource;\r
+\r
+/**\r
+ * Accesses the built-in functions in Sysdyn ontology\r
+ * \r
+ * @author Teemu Lempinen\r
+ */\r
+public class BuiltinFunctionsAccessor implements IDomainAccessor<Resource> {\r
+\r
+    \r
+    public BuiltinFunctionsAccessor() {\r
+    }\r
+\r
+    @Override\r
+    public Resource get(ReadGraph graph, Resource element) throws MappingException {\r
+        SysdynResource sr = SysdynResource.getInstance(graph);\r
+        Layer0 l0 = Layer0.getInstance(graph);\r
+        Resource builtinFunctions = null;\r
+        try {\r
+            Resource sysdyn = graph.getResource("http://www.simantics.org/Sysdyn-1.1");\r
+            builtinFunctions = graph.syncRequest(new PossibleObjectWithType(sysdyn, l0.ConsistsOf, sr.SysdynModelicaFunctionLibrary));\r
+        } catch (DatabaseException e) {\r
+            throw new MappingException(e);\r
+        }\r
+        return builtinFunctions;\r
+    }\r
+    \r
+    @Override\r
+    public boolean set(WriteGraph g, Resource element, Resource value)\r
+            throws MappingException {\r
+        // Built-in functions should not be set programmatically\r
+        return true;        \r
+    }\r
+\r
+}\r
diff --git a/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/annotations/BuiltinFunctionsFactory.java b/stable/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/annotations/BuiltinFunctionsFactory.java
new file mode 100644 (file)
index 0000000..f6800db
--- /dev/null
@@ -0,0 +1,36 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2012 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.representation.annotations;\r
+\r
+import java.lang.annotation.Annotation;\r
+import java.lang.reflect.Field;\r
+\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.exception.ResourceNotFoundException;\r
+import org.simantics.db.exception.ServiceException;\r
+import org.simantics.db.exception.ValidationException;\r
+import org.simantics.objmap.IMappingRule;\r
+import org.simantics.objmap.rules.MappedElementRule;\r
+import org.simantics.objmap.rules.factory.IFieldRuleFactory;\r
+import org.simantics.objmap.rules.range.FieldAccessor;\r
+\r
+public class BuiltinFunctionsFactory implements IFieldRuleFactory {\r
+\r
+    @Override\r
+    public IMappingRule create(ReadGraph g, Annotation _annotation, Field field) throws ResourceNotFoundException, ValidationException, ServiceException {\r
+        return new MappedElementRule(\r
+                new BuiltinFunctionsAccessor(),\r
+                new FieldAccessor<Object>(field)\r
+                );\r
+    }\r
+\r
+}\r
index c134bd6c9494877bdc6ddee1f3856ccdc48fb04f..5490f308ab0672d801a2d98e778ad10271717714 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************\r
- * Copyright (c) 2010 Association for Decentralized Information Management in\r
+ * Copyright (c) 2010, 2012 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
@@ -16,6 +16,12 @@ import org.simantics.objmap.annotations.RelatedValue;
 import org.simantics.sysdyn.SysdynResource;\r
 import org.simantics.sysdyn.representation.IndependentVariable;\r
 \r
+/**\r
+ * Represents a constant expression\r
+ * \r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
 @GraphType(SysdynResource.URIs.ConstantExpression)\r
 public class ConstantExpression extends Expression {\r
 \r
@@ -23,10 +29,7 @@ public class ConstantExpression extends Expression {
     private String equation;\r
 \r
     @Override\r
-    public String getDeclaration(IndependentVariable variable) {\r
-        StringBuilder b = new StringBuilder();\r
-        b.append("    constant " + variable.getType() + " " + variable.getName());\r
-        b.append(" = " + equation + ";\n");\r
-        return  b.toString();    }\r
-\r
+    public String getExpression(IndependentVariable variable) {\r
+        return equation;\r
+    }\r
 }\r
index b8c969b298a1c54dd6534dfd9dfbab5d73884729..1c63ec0d99b6bf8086100f7275fa26bbcee31549 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************\r
- * Copyright (c) 2010 Association for Decentralized Information Management in\r
+ * Copyright (c) 2010, 2012 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
  *******************************************************************************/\r
 package org.simantics.sysdyn.representation.expressions;\r
 \r
-import java.util.ArrayList;\r
-import java.util.Iterator;\r
-\r
 import org.simantics.objmap.annotations.GraphType;\r
 import org.simantics.objmap.annotations.RelatedValue;\r
 import org.simantics.sysdyn.SysdynResource;\r
-import org.simantics.sysdyn.representation.ArrayIndexes;\r
-import org.simantics.sysdyn.representation.Enumeration;\r
 import org.simantics.sysdyn.representation.IndependentVariable;\r
+import org.simantics.sysdyn.representation.Variability;\r
 import org.simantics.sysdyn.representation.Variable;\r
 import org.simantics.sysdyn.representation.utils.FormatUtils;\r
 import org.simantics.sysdyn.representation.utils.IndexUtils;\r
@@ -65,50 +61,64 @@ public class DelayExpression extends Expression {
     private String equation;\r
 \r
     @Override\r
-    public String getDeclaration(IndependentVariable variable) {\r
-\r
-        // Calculate range for the variable\r
-        ArrayIndexes ai = variable.getArrayIndexes();\r
-        ArrayList<Enumeration> enumerations = null;\r
-        if(ai != null) \r
-            enumerations = ai.getEnumerations();\r
-\r
-        String range = "";\r
-        if(enumerations != null && enumerations.size() > 0) {\r
-            StringBuilder sb = new StringBuilder();\r
-            sb.append("[");\r
-            Iterator<Enumeration> iterator = enumerations.iterator();\r
-            while(iterator.hasNext()) {\r
-                sb.append(iterator.next().getName() + ".size");\r
-                if(iterator.hasNext()) {\r
-                    sb.append(", ");\r
-                }\r
-            }\r
-            sb.append("]");\r
-            range = sb.toString();\r
+    public String getDeclarationAddition(IndependentVariable variable) {\r
+\r
+        String delayTime = FormatUtils.formatExpressionForModelica(variable, this.delayTime);\r
+        String initialValue = FormatUtils.formatExpressionForModelica(variable, this.initialValue);\r
+        Variability delayTimeVariability = Variability.getVariability((IndependentVariable)variable, delayTime);\r
+        Variability initialVariability = Variability.CONTINUOUS;\r
+        if(initialValue != null && initialValue.length() > 0) {\r
+            /*\r
+             *  By default, initial value variability is continuous.\r
+             *  If initial value has been set, it can be some other. \r
+             */\r
+            initialVariability = Variability.getVariability(variable, initialValue);\r
         }\r
-        \r
-        /* Build the declaration */\r
+\r
+\r
         StringBuilder declaration = new StringBuilder();\r
-        // Variable declaration\r
-        declaration.append("    " + variable.getType() + " " + variable.getName() + range + ";\n");\r
+\r
+        String range = variable.getRange();\r
+\r
         // Delay declaration\r
         declaration.append("    " + variable.getName() + "_delayClass " + variable.getName() + "_delayClass_instance");\r
+\r
         // Change enumeration sizes from the delay class. Supports overridden enumerations in modules.\r
-        if(range.length() > 0) {\r
+        if(range.length() > 0 || !initialVariability.equals(Variability.CONTINUOUS) || !delayTimeVariability.equals(Variability.CONTINUOUS)) {\r
             declaration.append("(");\r
-            String[] ranges = range.substring(1, range.length() - 1).split(",");\r
-            for(int i = 0; i < ranges.length; i++ ) {\r
-                String r = ranges[i];\r
-                declaration.append(r.replace(".size", "size") + " = " + r);\r
-                if(i < ranges.length - 1) {\r
-                    declaration.append(", ");\r
+\r
+            boolean started = false;\r
+            if(range.length() > 0) {\r
+                started = true;\r
+                String[] ranges = range.substring(1, range.length() - 1).split(",");\r
+                for(int i = 0; i < ranges.length; i++ ) {\r
+                    String r = ranges[i];\r
+                    declaration.append(r.replace(".size", "size") + " = " + r);\r
+                    if(i < ranges.length - 1) {\r
+                        declaration.append(", ");\r
+                    }\r
                 }\r
             }\r
+\r
+            // If initial value is not continuous, it is set in the module declaration\r
+            if(!initialVariability.equals(Variability.CONTINUOUS)) {\r
+                if(started)\r
+                    declaration.append(", ");\r
+                started = true;\r
+                declaration.append("initialValue = " + initialValue);\r
+            }\r
+\r
+            // If delay time is not continuous, it is set in the module declaration \r
+            if(!delayTimeVariability.equals(Variability.CONTINUOUS)) {\r
+                if(started)\r
+                    declaration.append(", ");\r
+                declaration.append("delayTime = " + delayTime);\r
+            }\r
+\r
             declaration.append(")");\r
         }\r
         declaration.append(";\n");\r
-        \r
+\r
         // Write the delay class\r
         declaration.append(getDelayClass(variable, range, order));\r
         return declaration.toString();\r
@@ -128,11 +138,6 @@ public class DelayExpression extends Expression {
         StringBuilder sb = new StringBuilder();\r
 \r
         sb.append("class " + variable.getName() + "_delayClass\n");\r
-        \r
-        // Auxiliary variable\r
-        sb.append("\tReal DL;\n");\r
-        // Delay time\r
-        sb.append("\tReal delayTime;\n");\r
 \r
         // Enumeration sizes as parameters. Sizes correspond the enumeration sizes of variable\r
         if(range.length() > 0) {\r
@@ -142,38 +147,66 @@ public class DelayExpression extends Expression {
             }\r
         }\r
 \r
-        if(initialValue == null || initialValue.length() == 0)\r
-            // Use "random" number as initial value, if initial value is not set\r
-            sb.append("\tReal" + range + " initialValue = " + (range.length() > 0 ? "fill(-137543," + range.substring(1, range.length() - 1) + ")" : -137543) + ";\n");\r
-        else\r
-            // Initial value\r
-            sb.append("\tReal" + range + " initialValue = " + FormatUtils.formatExpressionForModelica(variable, this.initialValue) + ";\n");\r
-        \r
+        String dt = FormatUtils.formatExpressionForModelica(variable,delayTime);\r
+        Variability delayTimeVariability = Variability.getVariability((IndependentVariable)variable, dt);\r
+        if(!delayTimeVariability.equals(Variability.CONTINUOUS)) {\r
+            // Auxiliary variable\r
+            sb.append("\t" + delayTimeVariability.getText() + " Real" + range + " DL = delayTime/" + n + ";\n");\r
+            // Delay time\r
+            sb.append("\t" + delayTimeVariability.getText() + " Real" + range + " delayTime;\n");\r
+        } else {\r
+            // Continuous auxiliary variable\r
+            sb.append("\tReal" + range + " DL;\n");\r
+            // Continuous delay time\r
+            sb.append("\tReal" + range + " delayTime;\n");\r
+        }\r
+\r
+\r
+        // Get initial value variability\r
+        Variability initialValueVariability = Variability.CONTINUOUS;\r
+        String initEquation = FormatUtils.formatExpressionForModelica(variable, this.initialValue);\r
+        if(initialValue != null && initialValue.length() > 0) {\r
+            initialValueVariability = Variability.getVariability((IndependentVariable)variable, initEquation);\r
+        }\r
+\r
+        // Declare initial value (continuous or other)\r
+        String ivv = !initialValueVariability.equals(Variability.CONTINUOUS) ? initialValueVariability.getText() + " " : "";\r
+        sb.append("\t" + ivv + "Real" + range + " initialValue;\n");\r
+\r
         // First valve\r
         sb.append("\tReal" + range + " delay0;\n");\r
 \r
         // Stocks and valves. Valves are the delayed values of the variable\r
         for(int i = 1; i <= n; i++) {\r
-            sb.append("\tReal" + range + " LV" + i + "(" + (range.length() > 0 ? "each " : "") + "fixed=false);\n");\r
+            if(initialValueVariability.equals(Variability.CONTINUOUS) || delayTimeVariability.equals(Variability.CONTINUOUS))\r
+                // Continuous initial value or delay time\r
+                sb.append("\tReal" + range + " LV" + i + "(" + (range.length() > 0 ? "each " : "") + "fixed=false);\n");\r
+            else\r
+                // initial value and delay time are not continuous\r
+                sb.append("\tReal" + range + " LV" + i + \r
+                        "(" + (range.length() > 0 ? "each " : "") + "fixed=true, start=initialValue " + (range.isEmpty() ? "*" : ".*") + " DL);\n");\r
             sb.append("\tReal" + range + " delay" + i + ";\n");\r
         }\r
 \r
-        sb.append("initial equation\n");\r
-        \r
-        // "Generic" structure selection. If the "random" number is not used in initial value, use delay0 as initial value\r
-        // Each stock gets the same initial value\r
-        for(int i = 1; i <= n; i++)\r
-            sb.append("\tLV" + i +" = DL * " + \r
-                    (range.length() > 0 ? "(if max(initialValue) < -137543 or max(initialValue) > -137543 then initialValue else delay0)" :\r
-                            "(if initialValue < -137543 or initialValue > -137543 then initialValue else delay0)") + ";\n");\r
+        // If initial value or delay time are continuous, use initial equation block\r
+        if(initialValueVariability.equals(Variability.CONTINUOUS) || delayTimeVariability.equals(Variability.CONTINUOUS)) {\r
+            sb.append("initial equation\n");\r
+\r
+            // Each stock gets the same initial value\r
+            for(int i = 1; i <= n; i++)\r
+                sb.append("\tLV" + i +" = DL " + (range.isEmpty() ? "*" : ".*") + " initialValue;\n");\r
+        }\r
 \r
+        // Equation block\r
         sb.append("equation\n");\r
-        sb.append("\tDL = delayTime/" + n + ";\n");\r
+\r
+        if(delayTimeVariability.equals(Variability.CONTINUOUS))\r
+            sb.append("\tDL = delayTime/" + n + ";\n");\r
 \r
         // Valves and stocks\r
         for(int i = 1; i <= n; i++) {\r
             sb.append("\tder(LV" + i + ") = - delay" + i + " + delay" + (i - 1) + ";\n");\r
-            sb.append("\tdelay" + i + " = LV" + i + "/DL;\n");\r
+            sb.append("\tdelay" + i + " = LV" + i + " " + (range.isEmpty() ? "/" : "./") + "DL;\n");\r
         }\r
 \r
         sb.append("end " + variable.getName() + "_delayClass;\n");\r
@@ -182,19 +215,43 @@ public class DelayExpression extends Expression {
 \r
     @Override\r
     public String getEquation(IndependentVariable variable) {\r
+        StringBuilder sb = new StringBuilder();\r
+\r
         String equation = FormatUtils.formatExpressionForModelica(variable, this.equation);\r
         String delayTime = FormatUtils.formatExpressionForModelica(variable, this.delayTime);\r
+        String initialValue = FormatUtils.formatExpressionForModelica(variable, this.initialValue);\r
 \r
-        // Set delay properties\r
-        StringBuilder sb = new StringBuilder();\r
-        sb.append("    " + variable.getName() + "_delayClass_instance.delayTime = " + delayTime + ";\n");\r
+        // First "valve" in the delay\r
         sb.append("    " + variable.getName() + "_delayClass_instance.delay0 = " + equation + ";\n");\r
 \r
-        // Use the delay in the value of variable\r
+        // Delay time (if continuous)\r
+        Variability delayTimeVariability = Variability.getVariability((IndependentVariable)variable, delayTime);\r
+        if(delayTimeVariability.equals(Variability.CONTINUOUS)) {\r
+            sb.append("    " + variable.getName() + "_delayClass_instance.delayTime = " + delayTime + ";\n");\r
+        }\r
+\r
+        // Initial value\r
+        if(initialValue == null || initialValue.length() == 0) {\r
+            // No initial value set, use delay0 (the first "valve")\r
+            sb.append("    " + variable.getName() + "_delayClass_instance.initialValue = " + variable.getName() + "_delayClass_instance.delay0;\n");\r
+        } else {\r
+            // Continuous initial value\r
+            Variability initialVariability = Variability.getVariability(variable, initialValue);\r
+            if(initialVariability.equals(Variability.CONTINUOUS)) {\r
+                sb.append("    " + variable.getName() + "_delayClass_instance.initialValue = " + initialValue + ";\n");\r
+            }\r
+        }\r
+\r
+        // The value of the actual variable\r
         String range = IndexUtils.rangeToIndexes(variable, this.getArrayRange());\r
         sb.append("    " + variable.getName() + (range.equals("[:]") ? "" : range) + " = " + variable.getName() + "_delayClass_instance.delay" + order + ";\n");\r
         return sb.toString();\r
     }\r
 \r
+    @Override\r
+    public String getExpression(IndependentVariable variable) {\r
+        return "This + is + not + a + parameter + at + any + time";\r
+    }\r
+\r
 \r
 }\r
index e500115fb26adf7de60a58fc8be08ab1eeb2ef76..1d9d77fa5a6d10bcd5faa42470d6e2d82cab4efb 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************\r
- * Copyright (c) 2010 Association for Decentralized Information Management in\r
+ * Copyright (c) 2010, 2012 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
@@ -15,23 +15,34 @@ import org.simantics.objmap.annotations.RelatedValue;
 import org.simantics.sysdyn.SysdynResource;\r
 import org.simantics.sysdyn.representation.IndependentVariable;\r
 \r
+/**\r
+ * Abstract class for any expression\r
+ * \r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
 public abstract class Expression implements IExpression {\r
         \r
     @RelatedValue(SysdynResource.URIs.Expression_arrayRange)\r
     private String range;\r
-    \r
+\r
     @Override\r
-    public String getDeclaration(IndependentVariable variable) {\r
+    public String getEquation(IndependentVariable variable) {\r
         return null;\r
     }\r
 \r
     @Override\r
-    public String getEquation(IndependentVariable variable) {\r
+    public String getInitialEquation(IndependentVariable variable) {\r
+        return null;\r
+    }\r
+    \r
+    @Override\r
+    public String getDeclarationAddition(IndependentVariable variable) {\r
         return null;\r
     }\r
 \r
     @Override\r
-    public String getInitialEquation(IndependentVariable variable) {\r
+    public String getExpression(IndependentVariable variable) {\r
         return null;\r
     }\r
     \r
index 544313479b7c8c647d587279b4fd715f7ca5edcc..c3f7ae77b2ce8bf57abb9db9dd1b9eedcf797056 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************\r
- * Copyright (c) 2010 Association for Decentralized Information Management in\r
+ * Copyright (c) 2010, 2012 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
@@ -13,11 +13,47 @@ package org.simantics.sysdyn.representation.expressions;
 \r
 import org.simantics.sysdyn.representation.IndependentVariable;\r
 \r
+/**\r
+ * Interface for all expressions in System Dynamics models\r
+ * \r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
 public interface IExpression {\r
 \r
-    String getDeclaration(IndependentVariable variable);\r
+    /**\r
+     * Get any possible additions to variable declaration.\r
+     * \r
+     * @param variable Declared independent variable\r
+     * @return additions or null\r
+     */\r
+    String getDeclarationAddition(IndependentVariable variable);\r
+    \r
+    /**\r
+     * Initial value for this variable and expression\r
+     * @param variable IndependentVariable\r
+     * @return initial value or null\r
+     */\r
     String getInitialEquation(IndependentVariable variable);\r
+    \r
+    /**\r
+     * Get the actual equation of this expression\r
+     * @param variable IndependentVariable\r
+     * @return equation or null\r
+     */\r
     String getEquation(IndependentVariable variable);\r
+    \r
+    /**\r
+     * Get the range of this expression\r
+     * @return Range or null if not multidimensional\r
+     */\r
     String getArrayRange();\r
+    \r
+    /**\r
+     * Get the plain (possibly unformatted) expression from this expression. (type variable = EXPRESSION ;\n)\r
+     * @param variable\r
+     * @return\r
+     */\r
+    String getExpression(IndependentVariable variable);\r
 \r
 }\r
index 360ad57740c66c51b5295d40024d3d3f2065496f..a0501b4796161d7417144a39fb2e2979a16a119e 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************\r
- * Copyright (c) 2010 Association for Decentralized Information Management in\r
+ * Copyright (c) 2010, 2012 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
  *******************************************************************************/\r
 package org.simantics.sysdyn.representation.expressions;\r
 \r
-import java.util.ArrayList;\r
-import java.util.Iterator;\r
-\r
 import org.simantics.objmap.annotations.GraphType;\r
 import org.simantics.objmap.annotations.RelatedValue;\r
 import org.simantics.sysdyn.SysdynResource;\r
-import org.simantics.sysdyn.representation.ArrayIndexes;\r
-import org.simantics.sysdyn.representation.Enumeration;\r
 import org.simantics.sysdyn.representation.IndependentVariable;\r
 import org.simantics.sysdyn.representation.utils.FormatUtils;\r
 import org.simantics.sysdyn.representation.utils.IndexUtils;\r
 \r
+/**\r
+ * Representation of a normal (auxiliary) expression\r
+ * \r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
 @GraphType(SysdynResource.URIs.NormalExpression)\r
 public class NormalExpression extends Expression {\r
 \r
     @RelatedValue(SysdynResource.URIs.Expression_equation)\r
     private String equation;\r
-\r
+    \r
     @Override\r
-    public String getDeclaration(IndependentVariable variable) {\r
-       \r
-       ArrayIndexes ai = variable.getArrayIndexes();\r
-       ArrayList<Enumeration> enumerations = null;\r
-       if(ai != null) \r
-               enumerations = ai.getEnumerations();\r
-       \r
-       String range = "";\r
-       if(enumerations != null && enumerations.size() > 0) {\r
-               StringBuilder sb = new StringBuilder();\r
-               sb.append("[");\r
-               Iterator<Enumeration> iterator = enumerations.iterator();\r
-               while(iterator.hasNext()) {\r
-                       sb.append(iterator.next().getName() + ".size");\r
-                       if(iterator.hasNext()) {\r
-                               sb.append(", ");\r
-                       }\r
-               }\r
-               sb.append("]");\r
-               range = sb.toString();\r
-       }\r
-       \r
-        return "    " + variable.getType() + " " + variable.getName() + range + ";\n";\r
+    public String getExpression(IndependentVariable variable) {\r
+        return equation;\r
     }\r
 \r
     @Override\r
index 90ca0c5b309ea292d2a8811cd4c5dfd5154083fb..874de79a68746c0f9eb9549bf009849964c523d1 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************\r
- * Copyright (c) 2010 Association for Decentralized Information Management in\r
+ * Copyright (c) 2010, 2012 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
  *******************************************************************************/\r
 package org.simantics.sysdyn.representation.expressions;\r
 \r
-import java.util.ArrayList;\r
-import java.util.Iterator;\r
-\r
 import org.simantics.objmap.annotations.GraphType;\r
 import org.simantics.objmap.annotations.RelatedValue;\r
 import org.simantics.sysdyn.SysdynResource;\r
-import org.simantics.sysdyn.representation.ArrayIndexes;\r
-import org.simantics.sysdyn.representation.Enumeration;\r
 import org.simantics.sysdyn.representation.IndependentVariable;\r
 import org.simantics.sysdyn.representation.utils.IndexUtils;\r
 \r
+/**\r
+ * Representation of a parameter expression\r
+ * \r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
 @GraphType(SysdynResource.URIs.ParameterExpression)\r
 public class ParameterExpression extends Expression {\r
     \r
@@ -29,38 +30,15 @@ public class ParameterExpression extends Expression {
     private String equation;\r
     \r
     @Override\r
-    public String getDeclaration(IndependentVariable variable) {\r
-       // FIXME: Still needs to manually confirm that really is parameter\r
-       ArrayIndexes ai = variable.getArrayIndexes();\r
-       ArrayList<Enumeration> enumerations = null;\r
-       if(ai != null) \r
-               enumerations = ai.getEnumerations();\r
-       \r
-       boolean parameter = true;\r
-       String range = "";\r
-       if(enumerations != null && enumerations.size() > 0) {\r
-               parameter = false;\r
-               StringBuilder sb = new StringBuilder();\r
-               sb.append("[");\r
-               Iterator<Enumeration> iterator = enumerations.iterator();\r
-               while(iterator.hasNext()) {\r
-                       sb.append(iterator.next().getName() + ".size");\r
-                       if(iterator.hasNext()) {\r
-                               sb.append(", ");\r
-                       }\r
-               }\r
-               sb.append("]");\r
-               range = sb.toString();\r
-       }\r
-       \r
-       StringBuilder sb = new StringBuilder();\r
-       sb.append("    " + (parameter ? "parameter " : "") + variable.getType() + " " + variable.getName() + range);\r
-       if(parameter)\r
-               sb.append(" = " + getValue() + " /* Actual value read from init file */");\r
-       sb.append(";\n");\r
-        return  sb.toString();\r
+    public String getExpression(IndependentVariable variable) {\r
+        return equation + " /* Actual value read from init file */";\r
     }\r
     \r
+    @Override\r
+    public String getDeclarationAddition(IndependentVariable variable) {\r
+        return ""; \r
+    }\r
+\r
     \r
     /**\r
      * Used when the expression is a part of an array variable. Then it is like a normal auxiliary.\r
index 6c30e6bab7bbe546f355a519986196d329889bd3..085754f4a86b6b60647c2d9a6d9d829c1bf3896d 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************\r
- * Copyright (c) 2010 Association for Decentralized Information Management in\r
+ * Copyright (c) 2010, 2012 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
@@ -13,7 +13,6 @@ package org.simantics.sysdyn.representation.expressions;
 \r
 import java.io.StringReader;\r
 import java.util.ArrayList;\r
-import java.util.Iterator;\r
 import java.util.Set;\r
 \r
 import org.simantics.objmap.annotations.GraphType;\r
@@ -45,58 +44,10 @@ public class StockExpression extends Expression {
     private String initialEquation;\r
 \r
     @Override\r
-    public String getDeclaration(IndependentVariable variable) {\r
-        \r
-        // See if the start parameter is used Stock(start = x, fixed = y) \r
-        String value = null;\r
-        if(useStartValue(variable))\r
-            value = FormatUtils.formatExpressionForModelica(variable, initialEquation);\r
-        \r
-        \r
-        // Build the enumeration indexes, if there are enumerations. Stock[enumIndexes, enum2Indexes, ...]\r
-       ArrayIndexes ai = variable.getArrayIndexes();\r
-       ArrayList<Enumeration> enumerations = null;\r
-       if(ai != null) \r
-               enumerations = ai.getEnumerations();\r
-       \r
-       String range = "";\r
-       if(enumerations != null && enumerations.size() > 0) {\r
-               StringBuilder sb = new StringBuilder();\r
-               sb.append("[");\r
-               Iterator<Enumeration> iterator = enumerations.iterator();\r
-               while(iterator.hasNext()) {\r
-                       sb.append(iterator.next().getName() + ".size");\r
-                       if(iterator.hasNext()) {\r
-                               sb.append(", ");\r
-                       }\r
-               }\r
-               sb.append("]");\r
-               range = sb.toString();\r
-       }\r
-        \r
-        String each = "";\r
-       // each is required when a single value is used for all dimensions e.g. Stock[30](each start = 0)  \r
-        if (value == null) {\r
-            // start parameter is not used, everything needs to be fixed=false\r
-            if(ai != null && !ai.getEnumerations().isEmpty())\r
-                each = "each";\r
-            return "    " + variable.getType() + " " + variable.getName() + range + "(" + each + " fixed=false);\n";\r
-        } else {\r
-            // start parameter is used\r
-            \r
-            if(getStartValue(variable) != null) {\r
-                // a single number is used as the initial equation -> (each start, each fixed) if there are dimensions\r
-                if(ai != null && !ai.getEnumerations().isEmpty())\r
-                    each = "each";\r
-                return "    " + variable.getType() + " " + variable.getName() + range + "(" + each+ " start=" + value + ", " + each + " fixed=true);\n";\r
-            } else {\r
-                // a function or array constructor {.., .., ..} is used as the initial equation -> (start, each fixed) if there are dimensions\r
-                if(ai != null && !ai.getEnumerations().isEmpty())\r
-                    each = "each";\r
-                return "    " + variable.getType() + " " + variable.getName() + range + "(start=" + value + ", " + each + " fixed=true);\n";\r
-            }\r
-        }\r
+    public String getExpression(IndependentVariable variable) {\r
+        return initialEquation;\r
     }\r
+    \r
 \r
     @Override\r
     public String getEquation(IndependentVariable variable) {\r
@@ -212,7 +163,7 @@ public class StockExpression extends Expression {
      * @param variable\r
      * @return Double representing the initial equation or null if initial equation is not a double\r
      */\r
-    private Double getStartValue(IndependentVariable variable) {\r
+    public Double getStartValue(IndependentVariable variable) {\r
        Double value = null;\r
        ArrayList<IExpression> expressions = variable.getExpressions().getExpressions();\r
        if(expressions.size() == 1) {\r
index ed99a2361408526275d07dcbf205abf4f0701f0e..15e3476653d363e5d41925d17e349d6a54bcf23c 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************\r
- * Copyright (c) 2010 Association for Decentralized Information Management in\r
+ * Copyright (c) 2010, 2012 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
  *******************************************************************************/\r
 package org.simantics.sysdyn.representation.expressions;\r
 \r
-import java.util.ArrayList;\r
-import java.util.Iterator;\r
-\r
 import org.simantics.objmap.annotations.GraphType;\r
 import org.simantics.objmap.annotations.RelatedValue;\r
 import org.simantics.sysdyn.SysdynResource;\r
-import org.simantics.sysdyn.representation.ArrayIndexes;\r
-import org.simantics.sysdyn.representation.Enumeration;\r
 import org.simantics.sysdyn.representation.IndependentVariable;\r
 import org.simantics.sysdyn.representation.utils.FormatUtils;\r
 import org.simantics.sysdyn.representation.utils.IndexUtils;\r
 \r
-\r
+/**\r
+ * Representation of a withlookup expression\r
+ * \r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
 @GraphType(SysdynResource.URIs.WithLookupExpression)\r
 public class WithLookupExpression extends Expression {\r
 \r
@@ -32,32 +32,6 @@ public class WithLookupExpression extends Expression {
     @RelatedValue(SysdynResource.URIs.WithLookupExpression_expression)\r
     private String equation;\r
 \r
-    @Override\r
-    public String getDeclaration(IndependentVariable variable) {\r
-       ArrayIndexes ai = variable.getArrayIndexes();\r
-       ArrayList<Enumeration> enumerations = null;\r
-       if(ai != null) \r
-               enumerations = ai.getEnumerations();\r
-       \r
-       String range = "";\r
-       if(enumerations != null && enumerations.size() > 0) {\r
-               StringBuilder sb = new StringBuilder();\r
-               sb.append("[");\r
-               Iterator<Enumeration> iterator = enumerations.iterator();\r
-               while(iterator.hasNext()) {\r
-                       sb.append(iterator.next().getName() + ".size");\r
-                       if(iterator.hasNext()) {\r
-                               sb.append(", ");\r
-                       }\r
-               }\r
-               sb.append("]");\r
-               range = sb.toString();\r
-       }\r
-       \r
-        return "    " + variable.getType() + " " + variable.getName() + range + ";\n";\r
-\r
-    }\r
-\r
     @Override\r
     public String getEquation(IndependentVariable variable) {\r
         String equation = FormatUtils.formatExpressionForModelica(variable, this.equation);\r
@@ -66,5 +40,10 @@ public class WithLookupExpression extends Expression {
         return \r
         "    " + variable.getName() + (range.equals("[:]") ? "" : range) + " = interpolate(" + equation + ", " + lookupTable + ");\n";\r
     }\r
+    \r
+    @Override\r
+    public String getExpression(IndependentVariable variable) {\r
+        return "interpolate(" + equation + ", " + lookupTable + ")";\r
+    }\r
 \r
 }\r