]> gerrit.simantics Code Review - simantics/sysdyn.git/blob
098521890af33e48acf7c9319a09e7220d282070
[simantics/sysdyn.git] /
1 /*******************************************************************************\r
2  * Copyright (c) 2013 Association for Decentralized Information Management in\r
3  * Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     Semantum Oy - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.sysdyn.adapter;\r
13 \r
14 import org.simantics.databoard.Bindings;\r
15 import org.simantics.db.ReadGraph;\r
16 import org.simantics.db.Resource;\r
17 import org.simantics.db.exception.DatabaseException;\r
18 import org.simantics.db.layer0.request.PossibleModel;\r
19 import org.simantics.simulation.ontology.SimulationResource;\r
20 import org.simantics.sysdyn.SysdynResource;\r
21 import org.simantics.sysdyn.adapter.distribution.IDistribution;\r
22 import org.simantics.sysdyn.manager.SysdynModel;\r
23 import org.simantics.sysdyn.manager.SysdynModelManager;\r
24 import org.simantics.sysdyn.representation.Enumeration;\r
25 import org.simantics.sysdyn.representation.Variable;\r
26 import org.simantics.sysdyn.representation.utils.IndexUtils;\r
27 import org.simantics.sysdyn.representation.utils.RepresentationUtils;\r
28 \r
29 public class SensitivityExperimentParameter {\r
30     \r
31     private String variableName;\r
32     private String[] indexes;\r
33     private String fullName;\r
34     private IDistribution distribution;\r
35     \r
36     public SensitivityExperimentParameter(ReadGraph graph, Resource parameter) {\r
37         \r
38         try {\r
39             SysdynResource SR = SysdynResource.getInstance(graph);\r
40             Resource distributionResource = graph.getPossibleObject(parameter, SR.SensitivityAnalysisExperiment_Parameter_propabilityDistribution);\r
41             distribution = graph.adapt(distributionResource, IDistribution.class);\r
42             variableName = graph.getPossibleRelatedValue(parameter, SR.SensitivityAnalysisExperiment_Parameter_variable, Bindings.STRING);\r
43             indexes = graph.getPossibleRelatedValue(parameter, SR.SensitivityAnalysisExperiment_Parameter_indexes, Bindings.STRING_ARRAY);\r
44             \r
45             Resource model = graph.syncRequest(new PossibleModel(parameter));\r
46             SysdynModelManager smm = SysdynModelManager.getInstance(graph.getSession());\r
47             SysdynModel sm = smm.getModel(graph, graph.getPossibleObject(model, SimulationResource.getInstance(graph).HasConfiguration));\r
48             \r
49             Variable variable = RepresentationUtils.getVariable(sm.getConfiguration(), variableName);\r
50             \r
51             if(indexes == null && (variable.getArrayIndexes() != null & variable.getArrayIndexes().size() > 0)) {\r
52                 indexes = new String[variable.getArrayIndexes().size()];\r
53                 \r
54                 for(int i = 0; i < variable.getArrayIndexes().size(); i++) {\r
55                     Enumeration e = variable.getArrayIndexes().get(i);\r
56                     indexes[i] = e.getEnumerationIndexes().get(0).getName();\r
57                 }\r
58             }\r
59             \r
60             if(indexes != null) {\r
61                 StringBuilder sb = new StringBuilder();\r
62                 sb.append("[");\r
63                 for(int i = 0; i < indexes.length; i++) {\r
64                     if(i > 0)\r
65                         sb.append(",");\r
66 \r
67                     String index = indexes[i];\r
68                     sb.append(index);\r
69                 }\r
70                 sb.append("]");\r
71                 String result = IndexUtils.rangeToIndexes(variable, sb.toString());\r
72                 fullName = variableName + result;\r
73             } else {\r
74                 fullName = variableName;\r
75             }\r
76         } catch (DatabaseException e) {\r
77 \r
78         }\r
79     }\r
80 \r
81     public String getVariableName() {\r
82         return variableName;\r
83     }\r
84     \r
85     \r
86 \r
87     public String[] getIndexes() {\r
88         return indexes;\r
89     }\r
90 \r
91     public String getFullName() {\r
92         return fullName;\r
93     }\r
94 \r
95     public IDistribution getDistribution() {\r
96         return distribution;\r
97     }\r
98     \r
99     \r
100 \r
101 }\r