bin.includes = feature.xml\r
+root=rootfiles/
\ No newline at end of file
provider-name="Association for Decentralized Information Management in Industry THTH ry">\r
\r
<description>\r
- SCL tooling for Simantics to enable the use of R statistical computing environment with Simantics through RServe.\r
+ SCL tooling for Simantics to enable the use of R statistical computing environment with Simantics through RServe.
Allows R code evaluation and reading the R data model through the Simantics Variable interface.\r
</description>\r
\r
version="0.0.0"\r
unpack="false"/>\r
\r
+ <plugin\r
+ id="org.simantics.r.fileimport"\r
+ download-size="0"\r
+ install-size="0"\r
+ version="0.0.0"\r
+ unpack="false"/>\r
+\r
</feature>\r
Require-Bundle: org.simantics.layer0;bundle-version="1.1.0",
org.simantics.simulation.ontology;bundle-version="1.1.0",
org.simantics.selectionview.ontology;bundle-version="1.2.0",
- org.simantics.selectionview.ui.ontology;bundle-version="1.1.0"
+ org.simantics.selectionview.ui.ontology;bundle-version="1.1.0",
+ org.simantics.modeling.ontology;bundle-version="1.2.0"
Export-Package: org.simantics.r
Bundle-Vendor: Association for Decentralized Information Management in Industry THTH ry
SIMU = <http://www.simantics.org/Simulation-1.1>\r
SEL = <http://www.simantics.org/SelectionView-1.2>\r
SEL_UI = <http://www.simantics.org/SelectionViewUI-1.1>\r
+MOD = <http://www.simantics.org/Modeling-1.2>\r
\r
R = <http://www.simantics.org/R-1.0> : L0.Ontology\r
@L0.new\r
SEL.VariableTabContribution.HasView SEL_UI.StandardProperties\r
SEL.VariableTabContribution.HasPriority 1\r
L0.HasLabel "Variables"\r
- \r
+\r
+R.RProperty <T SEL.GenericParameterType\r
+\r
R.Session <T SIMU.Run\r
>-- L0.PartOf --> R.SessionConfiguration\r
- >-- R.Session.hasValue --> L0.Value <R L0.HasProperty : SEL.GenericParameterType\r
+ >-- R.Session.hasValue --> L0.Value <R L0.HasProperty : R.RProperty\r
//SEL.HasDisplayValue R.Session.hasValueDisplayValue : L0.Function\r
\r
@L0.assert L0.HasLabel "R session"\r
R.Script <T L0.Entity\r
>-- R.Script.text --> L0.String <R L0.HasProperty : L0.TotalFunction\r
\r
- @L0.assert R.Script.text ""
\ No newline at end of file
+ @L0.assert R.Script.text ""\r
+ \r
+R.Model <T MOD.StructuralModel\r
\r
public class RResource {\r
\r
+ public final Resource Model;\r
+ public final Resource RProperty;\r
public final Resource Script;\r
public final Resource Script_text;\r
public final Resource Script_text_Inverse;\r
public final Resource TabContribution;\r
\r
public static class URIs {\r
+ public static final String Model = "http://www.simantics.org/R-1.0/Model";\r
+ public static final String RProperty = "http://www.simantics.org/R-1.0/RProperty";\r
public static final String Script = "http://www.simantics.org/R-1.0/Script";\r
public static final String Script_text = "http://www.simantics.org/R-1.0/Script/text";\r
public static final String Script_text_Inverse = "http://www.simantics.org/R-1.0/Script/text/Inverse";\r
}\r
\r
public RResource(ReadGraph graph) {\r
+ Model = getResourceOrNull(graph, URIs.Model);\r
+ RProperty = getResourceOrNull(graph, URIs.RProperty);\r
Script = getResourceOrNull(graph, URIs.Script);\r
Script_text = getResourceOrNull(graph, URIs.Script_text);\r
Script_text_Inverse = getResourceOrNull(graph, URIs.Script_text_Inverse);\r
org.simantics.r.scl;bundle-version="0.0.1",
org.simantics.scl.runtime;bundle-version="0.4.0",
org.simantics.db.layer0;bundle-version="1.1.0",
- org.simantics.simulator.variable;bundle-version="1.0.0"
+ org.simantics.simulator.variable;bundle-version="1.0.0",
+ org.simantics.modeling;bundle-version="1.1.1",
+ org.simantics
Bundle-Vendor: Association for Decentralized Information Management in Industry THTH ry
+Export-Package: org.simantics.r
r = newResource ()\r
claim r L0.InstanceOf ROntology.SessionConfiguration\r
claim r L0.PartOf parent\r
- claimRelatedValue r L0.HasName host\r
+ sessionName = host + "-" + show port\r
+ claimRelatedValue r L0.HasName sessionName\r
claimRelatedValue r ROntology.SessionConfiguration.host host\r
claimRelatedValue r ROntology.SessionConfiguration.port port\r
claimRelatedValue r ROntology.SessionConfiguration.username username\r
--- /dev/null
+package org.simantics.r;\r
+\r
+import java.io.BufferedReader;\r
+import java.io.IOException;\r
+import java.nio.file.Files;\r
+import java.nio.file.Path;\r
+import java.util.Optional;\r
+\r
+import org.simantics.Simantics;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.request.WriteResultRequest;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.request.Configuration;\r
+import org.simantics.modeling.ModelingUtils;\r
+\r
+public class RModelUtils {\r
+\r
+ private static Resource createModel(WriteGraph graph, Resource type, Resource target, String name, String sclMainContents) throws DatabaseException {\r
+ Resource model = ModelingUtils.createModel(graph, type, target, name);\r
+ Resource conf = graph.syncRequest(new Configuration(model));\r
+\r
+ ModelingUtils.addSCLMainToModel(graph, model, "SCLMain", sclMainContents);\r
+ ModelingUtils.createLocalLibrary(graph, model, "Library");\r
+ \r
+ return model;\r
+ }\r
+\r
+ public static Resource createRModel(final Resource target, final Path file) {\r
+ StringBuilder sb = new StringBuilder();\r
+ try (BufferedReader reader = Files.newBufferedReader(file)) {\r
+ String newLine = null;\r
+ while ((newLine = reader.readLine()) != null) {\r
+ sb.append(newLine).append("\n");\r
+ }\r
+ } catch (IOException e) {\r
+ e.printStackTrace();\r
+ }\r
+ final String sclMainContents = sb.toString();\r
+ if (!sclMainContents.isEmpty()) {\r
+ try {\r
+ return Simantics.sync(new WriteResultRequest<Resource>() {\r
+ \r
+ @Override\r
+ public Resource perform(WriteGraph graph) throws DatabaseException {\r
+ RResource R = RResource.getInstance(graph);\r
+ String fileName = file.getFileName().toString();\r
+ String[] parts = fileName.split("/");\r
+ String modelName = parts[parts.length - 1]; \r
+ \r
+ Resource model = createModel(graph, R.Model, target, modelName, sclMainContents);\r
+ return model;\r
+ }\r
+ });\r
+ } catch (DatabaseException e) {\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+ return null;\r
+ }\r
+}\r