]> gerrit.simantics Code Review - simantics/r.git/commitdiff
refs #6626
authorjsimomaa <jsimomaa@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 4 Aug 2016 07:17:21 +0000 (07:17 +0000)
committerjsimomaa <jsimomaa@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 4 Aug 2016 07:17:21 +0000 (07:17 +0000)
Some minor improvements to Simantics R Environment
RUI and RDB shared libraries for generic R user interface

git-svn-id: https://www.simantics.org/svn/simantics/r/trunk@33067 ac1ea38d-2e2b-0410-8846-a27921b304fc

12 files changed:
org.simantics.r.feature/build.properties
org.simantics.r.feature/feature.xml
org.simantics.r.feature/rootfiles/sharedlibraries/RDB.sharedLibrary [new file with mode: 0644]
org.simantics.r.feature/rootfiles/sharedlibraries/RStandardLibrary-1.2.sharedLibrary [new file with mode: 0644]
org.simantics.r.feature/rootfiles/sharedlibraries/RUI.sharedLibrary [new file with mode: 0644]
org.simantics.r.ontology/META-INF/MANIFEST.MF
org.simantics.r.ontology/graph.tg
org.simantics.r.ontology/graph/R.pgraph
org.simantics.r.ontology/src/org/simantics/r/RResource.java
org.simantics.r/META-INF/MANIFEST.MF
org.simantics.r/scl/R/RConfiguration.scl
org.simantics.r/src/org/simantics/r/RModelUtils.java [new file with mode: 0644]

index 82ab19c62d182db3688b1af6e6f465a74265ac92..6d715015ccf6e1472d269c48df1a35eb50190f93 100644 (file)
@@ -1 +1,2 @@
 bin.includes = feature.xml\r
+root=rootfiles/
\ No newline at end of file
index 73f39973f27baf93b8787f5a81f5c348dfd40072..729149d4938e0e474ba19ff097a032327ff2b58f 100644 (file)
@@ -6,7 +6,7 @@
       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
@@ -132,4 +132,11 @@ This Agreement is governed by the laws of the State of New York and the intellec
          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
diff --git a/org.simantics.r.feature/rootfiles/sharedlibraries/RDB.sharedLibrary b/org.simantics.r.feature/rootfiles/sharedlibraries/RDB.sharedLibrary
new file mode 100644 (file)
index 0000000..2bb8854
Binary files /dev/null and b/org.simantics.r.feature/rootfiles/sharedlibraries/RDB.sharedLibrary differ
diff --git a/org.simantics.r.feature/rootfiles/sharedlibraries/RStandardLibrary-1.2.sharedLibrary b/org.simantics.r.feature/rootfiles/sharedlibraries/RStandardLibrary-1.2.sharedLibrary
new file mode 100644 (file)
index 0000000..27842d3
Binary files /dev/null and b/org.simantics.r.feature/rootfiles/sharedlibraries/RStandardLibrary-1.2.sharedLibrary differ
diff --git a/org.simantics.r.feature/rootfiles/sharedlibraries/RUI.sharedLibrary b/org.simantics.r.feature/rootfiles/sharedlibraries/RUI.sharedLibrary
new file mode 100644 (file)
index 0000000..7c87041
Binary files /dev/null and b/org.simantics.r.feature/rootfiles/sharedlibraries/RUI.sharedLibrary differ
index 9db08a6ac9a1762d0ffb913572b9b0d13596d4f3..db09dafdc7bfebf858f7d317fc24c7dc8513c70e 100644 (file)
@@ -7,6 +7,7 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.8
 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
index 132a3d2fe42fdc1dee4bd134e1bcbeeb67e7c1ca..3ad1a743ad9f52e8da2ccf35a1f2f5aa7bdc40f1 100644 (file)
Binary files a/org.simantics.r.ontology/graph.tg and b/org.simantics.r.ontology/graph.tg differ
index cd441bc0258a07d64d38f935587cb66bf2ffa7c4..2aa6093d72347dae81df8fb1ded2b7cc1202e5a3 100644 (file)
@@ -2,6 +2,7 @@ L0 = <http://www.simantics.org/Layer0-1.1>
 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
@@ -24,10 +25,12 @@ R.TabContribution : SEL.TypedVariableTabContribution
     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
@@ -39,4 +42,6 @@ R.Session <T SIMU.Run
 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
index 441cd105e77554182c7d4e2cb38bddc056a002a4..64015408895afc1df0fd2a96dd06e9e3c4ca840b 100644 (file)
@@ -10,6 +10,8 @@ import org.simantics.db.service.QueryControl;
 \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
@@ -29,6 +31,8 @@ public class RResource {
     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
@@ -58,6 +62,8 @@ public class RResource {
     }\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
index 4a8a87e368d26a73bdb48fa136b9204e38445e64..9d0c09105554fde247982c9b9fbad035c560a247 100644 (file)
@@ -8,5 +8,8 @@ Require-Bundle: org.simantics.r.ontology;bundle-version="1.0.0",
  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
index 05217d7902e0c0cf8406ee3995045901f8a210dc..7ad0196779d8da3a5094986eb7de99037eba6710 100644 (file)
@@ -11,7 +11,8 @@ createSessionConfiguration parent (R.SessionConfiguration host port username pas
     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
diff --git a/org.simantics.r/src/org/simantics/r/RModelUtils.java b/org.simantics.r/src/org/simantics/r/RModelUtils.java
new file mode 100644 (file)
index 0000000..0bf6ccf
--- /dev/null
@@ -0,0 +1,61 @@
+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