/*******************************************************************************\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
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
*/\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
}\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
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
--- /dev/null
+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
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
>-- 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"
>-- 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
SYSDYN.PlaybackExperiment <T SYSDYN.Experiment
//#####################################################################
-// Results
+// Results and history datasets
//#####################################################################
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
+
//#####################################################################
//#####################################################################
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
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
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
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
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
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
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
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
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
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
<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
/*******************************************************************************\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
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
/*******************************************************************************\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
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
/*******************************************************************************\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
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
/*******************************************************************************\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
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
--- /dev/null
+/*******************************************************************************\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
/*******************************************************************************\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
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
+/*******************************************************************************\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
\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
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
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
\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
--- /dev/null
+/*******************************************************************************\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
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
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
/*******************************************************************************\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
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
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
/*******************************************************************************\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
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
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
\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
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
--- /dev/null
+/*******************************************************************************\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
/*******************************************************************************\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
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
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
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
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
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
/*******************************************************************************\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
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
--- /dev/null
+/*******************************************************************************\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
--- /dev/null
+/*******************************************************************************\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
--- /dev/null
+/*******************************************************************************\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
/*******************************************************************************\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
* 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
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
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
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
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
\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
}\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
/*******************************************************************************\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
* 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
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
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
}\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
}\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
\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
--- /dev/null
+/*******************************************************************************\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
--- /dev/null
+/*******************************************************************************\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
--- /dev/null
+/*******************************************************************************\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
/*******************************************************************************\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
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
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
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
;\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
\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
--- /dev/null
+/*******************************************************************************\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
--- /dev/null
+/*******************************************************************************\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
/*******************************************************************************\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
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
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
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
\r
return activeResults;\r
}\r
- \r
+\r
}, new Listener<ArrayList<SysdynResult>> () {\r
\r
@Override\r
public boolean isDisposed() {\r
return false;\r
}\r
- \r
+\r
});\r
}\r
\r
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
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
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
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
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
/*******************************************************************************\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
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
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
/*******************************************************************************\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
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
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
// 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
}\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
\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
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
/*******************************************************************************\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
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
@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
return model;\r
}\r
\r
- \r
}\r
--- /dev/null
+/*******************************************************************************\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
--- /dev/null
+/*******************************************************************************\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
--- /dev/null
+/*******************************************************************************\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
/*******************************************************************************\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
/*******************************************************************************\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
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
@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
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
}\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
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
+/*******************************************************************************\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
/*******************************************************************************\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
/*******************************************************************************\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
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
\r
@RelatedElement(Layer0.URIs.InstanceOf)\r
private ModuleType type;\r
- \r
+\r
@RelatedElements(SysdynResource.URIs.Module_redeclaration)\r
private List<Redeclaration> redeclarations;\r
\r
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
/*******************************************************************************\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
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
\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
@Override\r
public void accept(IElementVisitorVoid v) {\r
}\r
+ \r
+ public Object getParent() {\r
+ return parent;\r
+ }\r
\r
}\r
--- /dev/null
+/*******************************************************************************\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
/*******************************************************************************\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
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
/*******************************************************************************\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
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
--- /dev/null
+/*******************************************************************************\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
/*******************************************************************************\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
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
@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
}\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
--- /dev/null
+/*******************************************************************************\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
--- /dev/null
+/*******************************************************************************\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
--- /dev/null
+/*******************************************************************************\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
/*******************************************************************************\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
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
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
/*******************************************************************************\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
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
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
}\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
\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
/*******************************************************************************\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
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
/*******************************************************************************\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
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
/*******************************************************************************\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
/*******************************************************************************\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
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
/*******************************************************************************\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
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
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
* @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
/*******************************************************************************\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
@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
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