From 0cac646f5a9fcd268c6e17014931b9f78d45c46b Mon Sep 17 00:00:00 2001 From: lempinen Date: Wed, 10 Jul 2013 12:50:48 +0000 Subject: [PATCH] Documentation utils (refs #3511) git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@27703 ac1ea38d-2e2b-0410-8846-a27921b304fc --- org.simantics.sysdyn/scl/Sysdyn.scl | 6 ++ .../sysdyn/manager/SysdynGameExperiment.java | 3 +- .../sysdyn/utils/DocumentationUtils.java | 82 ++++++++++++++++++- 3 files changed, 89 insertions(+), 2 deletions(-) diff --git a/org.simantics.sysdyn/scl/Sysdyn.scl b/org.simantics.sysdyn/scl/Sysdyn.scl index f1d5fb35..72217d49 100644 --- a/org.simantics.sysdyn/scl/Sysdyn.scl +++ b/org.simantics.sysdyn/scl/Sysdyn.scl @@ -5,6 +5,12 @@ importJava "org.simantics.sysdyn.utils.DocumentationUtils" where @JavaName getModules getModules :: Variable -> [Resource] + + @JavaName getExperimentVariables + getExperimentVariables :: Variable -> [Variable] + + @JavaName getRoleVariables + getRoleVariables :: Variable -> [Variable] @JavaName getConfiguration getConfiguration :: Resource -> Resource diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynGameExperiment.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynGameExperiment.java index 7343a4df..d4b865f4 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynGameExperiment.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynGameExperiment.java @@ -512,7 +512,8 @@ public class SysdynGameExperiment extends SysdynExperiment { @Override public void updateSubscriptions() { try { - currentValues = control.getSubscribedResults(currentValues); + if(control.isInitialized()) + currentValues = control.getSubscribedResults(currentValues); } catch (FMUJNIException e) { e.printStackTrace(); } diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/DocumentationUtils.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/DocumentationUtils.java index b044d2aa..5d468db0 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/DocumentationUtils.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/DocumentationUtils.java @@ -9,7 +9,9 @@ import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.common.request.ObjectsWithSupertype; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.Variables; import org.simantics.layer0.Layer0; +import org.simantics.modeling.ModelingResources; import org.simantics.simulation.ontology.SimulationResource; import org.simantics.structural.stubs.StructuralResource2; import org.simantics.sysdyn.SysdynResource; @@ -28,6 +30,9 @@ import org.simantics.sysdyn.representation.Variable; public class DocumentationUtils { public static List getModules(ReadGraph graph, org.simantics.db.layer0.variable.Variable model) throws DatabaseException { + if(model == null) + return Collections.emptyList(); + SysdynResource SR = SysdynResource.getInstance(graph); Resource modelResource = model.getRepresents(graph); @@ -41,7 +46,65 @@ public class DocumentationUtils { return result; } + public static List getExperimentVariables(ReadGraph graph, org.simantics.db.layer0.variable.Variable model) throws DatabaseException { + if(model == null) + return Collections.emptyList(); + + ModelingResources MR = ModelingResources.getInstance(graph); + if (model == null || !graph.isInstanceOf(model.getRepresents(graph), MR.StructuralModel)) { + return Collections.emptyList(); + } + + Layer0 L0 = Layer0.getInstance(graph); + SimulationResource SIMU = SimulationResource.getInstance(graph); + ArrayList result = new ArrayList(); + for (Resource config : graph.getObjects(model.getRepresents(graph), L0.ConsistsOf)) { + if (graph.isInstanceOf(config, SIMU.Experiment)) { + for (Resource run : graph.getObjects(config, L0.ConsistsOf)) { + if (graph.isInstanceOf(run, SIMU.Run)) { + if (graph.hasStatement(run, SIMU.IsActive)) { + org.simantics.db.layer0.variable.Variable runVar = Variables.getPossibleVariable(graph, run); + if(runVar != null) + result.add(runVar); + } + } + } + } + } + + return result; + } + + public static List getRoleVariables(ReadGraph graph, org.simantics.db.layer0.variable.Variable experiment) throws DatabaseException { + if(experiment == null) + return Collections.emptyList(); + + SimulationResource SIMU = SimulationResource.getInstance(graph); + + if(graph.isInstanceOf(experiment.getRepresents(graph), SIMU.Run)) + experiment = experiment.getParent(graph); + + if(!graph.isInstanceOf(experiment.getRepresents(graph), SIMU.Experiment)) + return Collections.emptyList(); + + Resource roleType = graph.getPossibleResource("http://www.simantics.org/Documentation-1.1/Role"); + if(roleType == null) + return Collections.emptyList(); + + ArrayList result = new ArrayList(); + for(org.simantics.db.layer0.variable.Variable part : experiment.getChildren(graph)) { + if(graph.isInstanceOf(part.getRepresents(graph), roleType)) { + result.add(part); + } + } + + return result; + } + public static Resource getConfiguration(ReadGraph graph, Resource module) throws DatabaseException { + if(module == null) + return null; + SysdynResource SR = SysdynResource.getInstance(graph); if(graph.isInstanceOf(module, SR.SysdynModel)) { @@ -54,6 +117,8 @@ public class DocumentationUtils { } public static List getConfigurationVariables(ReadGraph graph, Resource configuration) throws DatabaseException { + if(configuration == null) + return Collections.emptyList(); SysdynModelManager smm = SysdynModelManager.getInstance(graph.getSession()); SysdynModel sm = smm.getModel(graph, configuration); @@ -107,6 +172,8 @@ public class DocumentationUtils { } public static String getName(ReadGraph graph, Resource variable) throws DatabaseException { + if(variable == null) + return null; SysdynModelManager smm = SysdynModelManager.getInstance(graph.getSession()); Resource configuration = graph.syncRequest(new GetConfigurationRequest(variable)); @@ -146,6 +213,8 @@ public class DocumentationUtils { } public static String getType(ReadGraph graph, Resource variable) throws DatabaseException { + if(variable == null) + return null; SysdynModelManager smm = SysdynModelManager.getInstance(graph.getSession()); Resource configuration = graph.syncRequest(new GetConfigurationRequest(variable)); @@ -170,6 +239,8 @@ public class DocumentationUtils { } public static String getUnit(ReadGraph graph, Resource variable) throws DatabaseException { + if(variable == null) + return null; SysdynModelManager smm = SysdynModelManager.getInstance(graph.getSession()); Resource configuration = graph.syncRequest(new GetConfigurationRequest(variable)); @@ -190,6 +261,8 @@ public class DocumentationUtils { public static String getVariability(ReadGraph graph, Resource variable) throws DatabaseException { + if(variable == null) + return null; SysdynModelManager smm = SysdynModelManager.getInstance(graph.getSession()); Resource configuration = graph.syncRequest(new GetConfigurationRequest(variable)); @@ -219,6 +292,8 @@ public class DocumentationUtils { } public static String getDescription(ReadGraph graph, Resource variable) throws DatabaseException { + if(variable == null) + return null; SysdynModelManager smm = SysdynModelManager.getInstance(graph.getSession()); Resource configuration = graph.syncRequest(new GetConfigurationRequest(variable)); @@ -239,7 +314,9 @@ public class DocumentationUtils { public static String getDocumentationDefinition(ReadGraph graph, Resource variable) throws DatabaseException { - + if(variable == null) + return null; + SysdynModelManager smm = SysdynModelManager.getInstance(graph.getSession()); Resource configuration = graph.syncRequest(new GetConfigurationRequest(variable)); SysdynModel sm = smm.getModel(graph,configuration); @@ -303,6 +380,9 @@ public class DocumentationUtils { } public static int numberOfModuleTypes(ReadGraph graph, org.simantics.db.layer0.variable.Variable model) throws DatabaseException { + if(model == null) + return 0; + Resource modelResource = model.getRepresents(graph); return graph.syncRequest(new ObjectsWithSupertype( modelResource, -- 2.47.1