2 import "Simantics/Variables"
3 import "Simantics/Model"
4 import "Simantics/Entity"
5 import "Simantics/Subscription"
7 import "http://www.simantics.org/Charts-1.2" as CHART
10 type ChartGroup = Resource
11 type ChartItem = Resource
13 importJava "org.simantics.charts.ui.SCLChart" where
14 @JavaName createNewChart
16 Creates a new Chart to the default Charts folder under the given Model parameter. Returns the created Chart.
18 createChart :: Model -> <Proc> Chart
20 @JavaName createNewChart
22 Creates a new Chart under the given ChartGroup parameter. Returns the created Chart.
24 createChartInGroup :: ChartGroup -> <Proc> Chart
26 @JavaName createNewChartGroup
28 Creates a new ChartGroup under the given Model parameter. Returns the created ChartGroup.
30 createChartGroup :: Model -> <Proc> ChartGroup
32 @JavaName addChartItems
34 Creates new chartItem with the given Variable to the given Chart and returns the created ChartItem. New Subscription item is created at the same time.
36 addChartItems :: Chart -> Variable -> <WriteGraph> ChartItem
38 @JavaName linkSubToChart
40 Links the given Subscription to the given chart and returns the created ChartItem.
42 linkSubToChart :: Subscription -> Chart -> <WriteGraph> ChartItem
45 Browses the given Model for its Charts and then returns them in a list.
47 chartsOf :: Model -> <ReadGraph> [Chart]
48 chartsOf model = recurse model
52 charts = filter isChart cs
53 chartGrp = filter isChartGroup cs
54 charts + concatMap recurse chartGrp
55 isChart r = isInstanceOf r CHART.TimeSeriesChart
56 isChartGroup r = isInstanceOf r CHART.ChartGroup
58 //-----------------------------------------------------------------------------
59 // Support for exporting subscription data in CSV format
61 import "UI/Progress" as Progress
64 importJava "org.simantics.history.csv.DecimalSeparator" where
67 @JavaName fromPreference
69 Possible arguments are:
74 decimalSeparatorFromString :: String -> <Proc> DecimalSeparator
76 importJava "org.simantics.history.csv.ColumnSeparator" where
79 @JavaName fromPreference
81 Possible arguments are:
89 columnSeparatorFromString :: String -> <Proc> ColumnSeparator
91 importJava "org.simantics.history.csv.ExportInterpolation" where
92 data ExportInterpolation
94 @JavaName fromPreference
96 Possible arguments are:
98 Linear Interpolation (lerp)
99 Previous Sample (previous)
101 exportInterpolationFromString :: String -> <Proc> ExportInterpolation
103 importJava "org.simantics.charts.ui.CSVExportPlan" where
104 @FieldNames [startTime, timeStep, decimalSeparator, columnSeparator, resample, samplingMode, timeDigits, floatDigits, doubleDigits]
107 Example of construction:
109 plan = CSVExportPlan {
112 decimalSeparator = decimalSeparatorFromString ".",
113 columnSeparator = columnSeparatorFromString ",",
115 samplingMode = exportInterpolationFromString "lerp",
121 data CSVExportPlan = CSVExportPlan {
124 decimalSeparator :: DecimalSeparator,
125 columnSeparator :: ColumnSeparator,
127 samplingMode :: ExportInterpolation ,
128 timeDigits :: Integer,
129 floatDigits :: Integer,
130 doubleDigits :: Integer
135 setCSVExportPlanItems :: CSVExportPlan -> [Resource] -> <Proc> ()
138 Example of construction:
140 plan = SubscriptionCSVExportPlan {
142 filePath = "D:/folder/output.csv",
143 subscriptionNames = ["Default"],
144 exportPlan = CSVExportPlan {}
147 data SubscriptionCSVExportPlan = SubscriptionCSVExportPlan {
149 subscriptionNames :: [String],
151 exportPlan :: CSVExportPlan
155 modelNameOf SubscriptionCSVExportPlan { modelName } = modelName
157 subscriptionNamesOf SubscriptionCSVExportPlan { subscriptionNames } = subscriptionNames
159 filePathOf SubscriptionCSVExportPlan { filePath } = filePath
161 exportPlanOf SubscriptionCSVExportPlan { exportPlan } = exportPlan
163 importJava "org.simantics.charts.ui.CSVExporter" where
166 exportSubscriptionsCSVInternal :: Progress.ProgressMonitor -> File -> CSVExportPlan -> <Proc> ()
169 Exports subscription data as CSV values in a similar manner as the CSV Exporter provided by the user interface
173 exportSubscriptionsCSV SubscriptionCSVExportPlan {
175 filePath = "D:/folder/output.csv",
176 subscriptionNames = ["Default"],
177 exportPlan = CSVExportPlan {
180 decimalSeparator = decimalSeparatorFromString ".",
181 columnSeparator = columnSeparatorFromString ",",
183 samplingMode = exportInterpolationFromString "lerp",
190 exportSubscriptionsCSV :: SubscriptionCSVExportPlan -> <Proc> ()
191 exportSubscriptionsCSV subscriptionExportPlan = do
192 items = syncRead (\_ -> resolveSubscriptionItems (modelNameOf subscriptionExportPlan) (subscriptionNamesOf subscriptionExportPlan))
193 csvExportPlan = exportPlanOf subscriptionExportPlan
194 setCSVExportPlanItems csvExportPlan items
195 exportSubscriptionsCSVInternal (Progress.createNullProgressMonitor ()) (file (filePathOf subscriptionExportPlan)) csvExportPlan
198 resolveSubscriptionItems :: String -> [String] -> <Proc, ReadGraph> [Resource]
199 resolveSubscriptionItems modelName subscriptionNames = concatMap itemsOf (filter nameFilter subscriptions)
201 nameFilter sub = elem (relatedValue2 sub L0.HasLabel) subscriptionNames
202 subscriptions = (objectsWithType (model modelName) L0.ConsistsOf MOD.Subscription)
203 itemsOf subscription = objectsWithType subscription L0.ConsistsOf MOD.Subscription.Item