1 /*******************************************************************************
\r
2 * Copyright (c) 2013 Association for Decentralized Information Management in
\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
10 * Semantum Oy - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.sysdyn.adapter;
\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
29 public class SensitivityExperimentParameter {
\r
31 private String variableName;
\r
32 private String[] indexes;
\r
33 private String fullName;
\r
34 private IDistribution distribution;
\r
36 public SensitivityExperimentParameter(ReadGraph graph, Resource parameter) {
\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
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
49 Variable variable = RepresentationUtils.getVariable(sm.getConfiguration(), variableName);
\r
51 if(indexes == null && (variable.getArrayIndexes() != null & variable.getArrayIndexes().size() > 0)) {
\r
52 indexes = new String[variable.getArrayIndexes().size()];
\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
60 if(indexes != null) {
\r
61 StringBuilder sb = new StringBuilder();
\r
63 for(int i = 0; i < indexes.length; i++) {
\r
67 String index = indexes[i];
\r
71 String result = IndexUtils.rangeToIndexes(variable, sb.toString());
\r
72 fullName = variableName + result;
\r
74 fullName = variableName;
\r
76 } catch (DatabaseException e) {
\r
81 public String getVariableName() {
\r
82 return variableName;
\r
87 public String[] getIndexes() {
\r
91 public String getFullName() {
\r
95 public IDistribution getDistribution() {
\r
96 return distribution;
\r