Commit 56333314 authored by jsimomaa's avatar jsimomaa
Browse files

refs #6626

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
parent a1970c42
bin.includes = feature.xml
root=rootfiles/
\ No newline at end of file
......@@ -6,7 +6,7 @@
provider-name="Association for Decentralized Information Management in Industry THTH ry">
<description>
SCL tooling for Simantics to enable the use of R statistical computing environment with Simantics through RServe.
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.
</description>
......@@ -132,4 +132,11 @@ This Agreement is governed by the laws of the State of New York and the intellec
version="0.0.0"
unpack="false"/>
<plugin
id="org.simantics.r.fileimport"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>
</feature>
......@@ -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
......@@ -2,6 +2,7 @@ L0 = <http://www.simantics.org/Layer0-1.1>
SIMU = <http://www.simantics.org/Simulation-1.1>
SEL = <http://www.simantics.org/SelectionView-1.2>
SEL_UI = <http://www.simantics.org/SelectionViewUI-1.1>
MOD = <http://www.simantics.org/Modeling-1.2>
R = <http://www.simantics.org/R-1.0> : L0.Ontology
@L0.new
......@@ -24,10 +25,12 @@ R.TabContribution : SEL.TypedVariableTabContribution
SEL.VariableTabContribution.HasView SEL_UI.StandardProperties
SEL.VariableTabContribution.HasPriority 1
L0.HasLabel "Variables"
R.RProperty <T SEL.GenericParameterType
R.Session <T SIMU.Run
>-- L0.PartOf --> R.SessionConfiguration
>-- R.Session.hasValue --> L0.Value <R L0.HasProperty : SEL.GenericParameterType
>-- R.Session.hasValue --> L0.Value <R L0.HasProperty : R.RProperty
//SEL.HasDisplayValue R.Session.hasValueDisplayValue : L0.Function
@L0.assert L0.HasLabel "R session"
......@@ -39,4 +42,6 @@ R.Session <T SIMU.Run
R.Script <T L0.Entity
>-- R.Script.text --> L0.String <R L0.HasProperty : L0.TotalFunction
@L0.assert R.Script.text ""
\ No newline at end of file
@L0.assert R.Script.text ""
R.Model <T MOD.StructuralModel
......@@ -10,6 +10,8 @@ import org.simantics.db.service.QueryControl;
public class RResource {
public final Resource Model;
public final Resource RProperty;
public final Resource Script;
public final Resource Script_text;
public final Resource Script_text_Inverse;
......@@ -29,6 +31,8 @@ public class RResource {
public final Resource TabContribution;
public static class URIs {
public static final String Model = "http://www.simantics.org/R-1.0/Model";
public static final String RProperty = "http://www.simantics.org/R-1.0/RProperty";
public static final String Script = "http://www.simantics.org/R-1.0/Script";
public static final String Script_text = "http://www.simantics.org/R-1.0/Script/text";
public static final String Script_text_Inverse = "http://www.simantics.org/R-1.0/Script/text/Inverse";
......@@ -58,6 +62,8 @@ public class RResource {
}
public RResource(ReadGraph graph) {
Model = getResourceOrNull(graph, URIs.Model);
RProperty = getResourceOrNull(graph, URIs.RProperty);
Script = getResourceOrNull(graph, URIs.Script);
Script_text = getResourceOrNull(graph, URIs.Script_text);
Script_text_Inverse = getResourceOrNull(graph, URIs.Script_text_Inverse);
......
......@@ -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
......@@ -11,7 +11,8 @@ createSessionConfiguration parent (R.SessionConfiguration host port username pas
r = newResource ()
claim r L0.InstanceOf ROntology.SessionConfiguration
claim r L0.PartOf parent
claimRelatedValue r L0.HasName host
sessionName = host + "-" + show port
claimRelatedValue r L0.HasName sessionName
claimRelatedValue r ROntology.SessionConfiguration.host host
claimRelatedValue r ROntology.SessionConfiguration.port port
claimRelatedValue r ROntology.SessionConfiguration.username username
......
package org.simantics.r;
import java.io.BufferedReader;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Optional;
import org.simantics.Simantics;
import org.simantics.db.Resource;
import org.simantics.db.WriteGraph;
import org.simantics.db.common.request.WriteResultRequest;
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.layer0.request.Configuration;
import org.simantics.modeling.ModelingUtils;
public class RModelUtils {
private static Resource createModel(WriteGraph graph, Resource type, Resource target, String name, String sclMainContents) throws DatabaseException {
Resource model = ModelingUtils.createModel(graph, type, target, name);
Resource conf = graph.syncRequest(new Configuration(model));
ModelingUtils.addSCLMainToModel(graph, model, "SCLMain", sclMainContents);
ModelingUtils.createLocalLibrary(graph, model, "Library");
return model;
}
public static Resource createRModel(final Resource target, final Path file) {
StringBuilder sb = new StringBuilder();
try (BufferedReader reader = Files.newBufferedReader(file)) {
String newLine = null;
while ((newLine = reader.readLine()) != null) {
sb.append(newLine).append("\n");
}
} catch (IOException e) {
e.printStackTrace();
}
final String sclMainContents = sb.toString();
if (!sclMainContents.isEmpty()) {
try {
return Simantics.sync(new WriteResultRequest<Resource>() {
@Override
public Resource perform(WriteGraph graph) throws DatabaseException {
RResource R = RResource.getInstance(graph);
String fileName = file.getFileName().toString();
String[] parts = fileName.split("/");
String modelName = parts[parts.length - 1];
Resource model = createModel(graph, R.Model, target, modelName, sclMainContents);
return model;
}
});
} catch (DatabaseException e) {
e.printStackTrace();
}
}
return null;
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment