* Utilities for handling charts\r
* \r
* @author Teemu Lempinen\r
+ * @author Tuomas Miettinen\r
*\r
*/\r
public class ChartUtils {\r
\r
+ public static final String emptyVariableName = "<Write variable name>";\r
+\r
/**\r
* Creates a new range axis of type jfree.NumberAxis to a plot\r
* \r
// Create series\r
Resource series = GraphUtils.create2(graph, jfree.Series,\r
l0.HasName, "Series" + UUID.randomUUID().toString(),\r
- jfree.variableRVI, rvi == null ? " <Write variable name>" : rvi,\r
+ jfree.variableRVI, rvi == null ? " " + emptyVariableName : rvi,\r
l0.PartOf, dataset);\r
\r
// Add series to the dataset's series list\r
import org.simantics.db.WriteGraph;\r
import org.simantics.db.common.utils.ListUtils;\r
import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.jfreechart.chart.ChartUtils;\r
import org.simantics.layer0.Layer0;\r
import org.simantics.layer0.utils.direct.GraphUtils;\r
import org.simantics.sysdyn.SysdynResource;\r
\r
Resource parameter = GraphUtils.create2(graph, sr.SensitivityAnalysisExperiment_Parameter,\r
sr.SensitivityAnalysisExperiment_Parameter_propabilityDistribution, distribution,\r
- sr.SensitivityAnalysisExperiment_Parameter_variable, "<Write variable name>",\r
+ sr.SensitivityAnalysisExperiment_Parameter_variable, ChartUtils.emptyVariableName,\r
L0.PartOf, experiment);\r
\r
ArrayList<Resource> parameterList = new ArrayList<Resource>();\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.db.management.ISessionContext;\r
import org.simantics.db.request.Read;\r
+import org.simantics.jfreechart.chart.ChartUtils;\r
import org.simantics.jfreechart.chart.properties.RangeComposite;\r
import org.simantics.jfreechart.chart.properties.xyline.AxisAndVariablesExplorerComposite;\r
import org.simantics.layer0.Layer0;\r
\r
GridDataFactory.fillDefaults().hint(250, SWT.DEFAULT).grab(false, true).applyTo(explorer);\r
\r
+ Composite buttonComposite = new Composite(explorer, SWT.NONE);\r
+ GridDataFactory.fillDefaults().applyTo(buttonComposite);\r
+ GridLayoutFactory.fillDefaults().numColumns(3).applyTo(buttonComposite);\r
+ \r
+ Button addVariable = new Button(buttonComposite, support, SWT.NONE);\r
+ addVariable.setText("Add parameter");\r
+ addVariable.addSelectionListener(new SelectionListenerImpl<Resource>(context) {\r
+\r
+ @Override\r
+ public void apply(WriteGraph graph, Resource input) throws DatabaseException {\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ Layer0 L0 = Layer0.getInstance(graph);\r
+ \r
+ Resource distribution = GraphUtils.create2(graph, sr.UniformDistribution,\r
+ sr.UniformDistribution_minValue, 0.0,\r
+ sr.UniformDistribution_maxValue, 10.0);\r
+ \r
+ Resource parameter = GraphUtils.create2(graph, sr.SensitivityAnalysisExperiment_Parameter,\r
+ sr.SensitivityAnalysisExperiment_Parameter_propabilityDistribution, distribution,\r
+ sr.SensitivityAnalysisExperiment_Parameter_variable, ChartUtils.emptyVariableName,\r
+ L0.PartOf, input);\r
+ \r
+ Resource parameterList = graph.getPossibleObject(input, sr.SensitivityAnalysisExperiment_parameterList);\r
+ ListUtils.insertBack(graph, parameterList, Collections.singleton(parameter));\r
+ }\r
+ });\r
+\r
+ remove = new Button(buttonComposite, parameterSupport, SWT.NONE);\r
+ remove.setText("Remove");\r
+ remove.addSelectionListener(new SelectionListenerImpl<Resource>(context) {\r
+\r
+ @Override\r
+ public void apply(WriteGraph graph, Resource input) throws DatabaseException {\r
+ if(input == null)\r
+ return;\r
+ \r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ Layer0 L0 = Layer0.getInstance(graph);\r
+ \r
+ Resource experiment = graph.getPossibleObject(input, L0.PartOf);\r
+ Resource parameterList = graph.getPossibleObject(experiment, sr.SensitivityAnalysisExperiment_parameterList);\r
+ \r
+ if(ListUtils.toList(graph, parameterList).size() > 1)\r
+ ListUtils.removeElement(graph, parameterList, input);\r
+ \r
+ }\r
+ \r
+ });\r
+\r
+ propertyContainer.setContent(content);\r
+ Point tsize = content.computeSize(SWT.DEFAULT, SWT.DEFAULT);\r
+ propertyContainer.setMinSize(tsize);\r
+ \r
+ \r
Group parameterPropertyGroup = new Group(content, SWT.NONE);\r
GridDataFactory.fillDefaults().grab(true, false).applyTo(parameterPropertyGroup);\r
GridLayoutFactory.fillDefaults().applyTo(parameterPropertyGroup);\r
DistributionPropertyWidget dpw = new DistributionPropertyWidget(parameterProperties, context, parameterSupport, SWT.NONE);\r
GridDataFactory.fillDefaults().grab(true, true).applyTo(dpw);\r
\r
- \r
- Composite buttonComposite = new Composite(content, SWT.NONE);\r
- GridDataFactory.fillDefaults().applyTo(buttonComposite);\r
- GridLayoutFactory.fillDefaults().numColumns(3).applyTo(buttonComposite);\r
- \r
- \r
- Button addVariable = new Button(buttonComposite, support, SWT.NONE);\r
- addVariable.setText("Add parameter");\r
- addVariable.addSelectionListener(new SelectionListenerImpl<Resource>(context) {\r
-\r
- @Override\r
- public void apply(WriteGraph graph, Resource input) throws DatabaseException {\r
- SysdynResource sr = SysdynResource.getInstance(graph);\r
- Layer0 L0 = Layer0.getInstance(graph);\r
- \r
- Resource distribution = GraphUtils.create2(graph, sr.UniformDistribution,\r
- sr.UniformDistribution_minValue, 0.0,\r
- sr.UniformDistribution_maxValue, 10.0);\r
- \r
- Resource parameter = GraphUtils.create2(graph, sr.SensitivityAnalysisExperiment_Parameter,\r
- sr.SensitivityAnalysisExperiment_Parameter_propabilityDistribution, distribution,\r
- sr.SensitivityAnalysisExperiment_Parameter_variable, "<Write variable name>",\r
- L0.PartOf, input);\r
- \r
- Resource parameterList = graph.getPossibleObject(input, sr.SensitivityAnalysisExperiment_parameterList);\r
- ListUtils.insertBack(graph, parameterList, Collections.singleton(parameter));\r
- }\r
- });\r
-\r
- remove = new Button(buttonComposite, parameterSupport, SWT.NONE);\r
- remove.setText("Remove");\r
- remove.addSelectionListener(new SelectionListenerImpl<Resource>(context) {\r
-\r
- @Override\r
- public void apply(WriteGraph graph, Resource input) throws DatabaseException {\r
- if(input == null)\r
- return;\r
- \r
- SysdynResource sr = SysdynResource.getInstance(graph);\r
- Layer0 L0 = Layer0.getInstance(graph);\r
- \r
- Resource experiment = graph.getPossibleObject(input, L0.PartOf);\r
- Resource parameterList = graph.getPossibleObject(experiment, sr.SensitivityAnalysisExperiment_parameterList);\r
- \r
- if(ListUtils.toList(graph, parameterList).size() > 1)\r
- ListUtils.removeElement(graph, parameterList, input);\r
- \r
- }\r
- \r
- });\r
- \r
-\r
- propertyContainer.setContent(content);\r
- Point size = content.computeSize(SWT.DEFAULT, SWT.DEFAULT);\r
- propertyContainer.setMinSize(size);\r
-\r
}\r
\r
\r
@Override\r
public Composite createContent(Composite parent, ISessionContext context, WidgetSupport support) {\r
Composite composite = new Composite(parent, SWT.NONE);\r
- GridLayoutFactory.fillDefaults().numColumns(2).applyTo(composite);\r
+ GridLayoutFactory.fillDefaults().numColumns(4).applyTo(composite);\r
\r
- // minValue\r
+ // mean\r
Label label = new Label(composite, SWT.NONE);\r
+ label.setText("Mean (\u03BC)");\r
+ GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label);\r
+ \r
+ mean = new TrackedText(composite, support, SWT.BORDER);\r
+ mean.setTextFactory(new DoublePropertyFactory(SysdynResource.URIs.NormalDistribution_mean));\r
+ mean.addModifyListener(new DoublePropertyModifier(context, SysdynResource.URIs.NormalDistribution_mean));\r
+ mean.setInputValidator(new DoubleValidator(true));\r
+ mean.setColorProvider(new SysdynBasicColorProvider(new LocalResourceManager(JFaceResources.getResources(), mean.getWidget())));\r
+ GridDataFactory.fillDefaults().grab(true, false).applyTo(mean.getWidget());\r
+ \r
+ // minValue\r
+ label = new Label(composite, SWT.NONE);\r
label.setText("Min value");\r
- GridDataFactory.fillDefaults().applyTo(label);\r
+ GridDataFactory.fillDefaults().indent(15, 0).align(SWT.END, SWT.CENTER).applyTo(label);\r
\r
minValue = new TrackedText(composite, support, SWT.BORDER);\r
minValue.setTextFactory(new DoublePropertyFactory(SysdynResource.URIs.NormalDistribution_minValue));\r
minValue.setColorProvider(new SysdynBasicColorProvider(new LocalResourceManager(JFaceResources.getResources(), minValue.getWidget())));\r
GridDataFactory.fillDefaults().grab(true, false).applyTo(minValue.getWidget());\r
\r
+ // stdDeviation\r
+ label = new Label(composite, SWT.NONE);\r
+ label.setText("Standard deviation (\u03C3)");\r
+ GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label);\r
+ \r
+ stdDeviation = new TrackedText(composite, support, SWT.BORDER);\r
+ stdDeviation.setTextFactory(new DoublePropertyFactory(SysdynResource.URIs.NormalDistribution_stdDeviation));\r
+ stdDeviation.addModifyListener(new DoublePropertyModifier(context, SysdynResource.URIs.NormalDistribution_stdDeviation));\r
+ stdDeviation.setInputValidator(new DoubleValidator(true));\r
+ stdDeviation.setColorProvider(new SysdynBasicColorProvider(new LocalResourceManager(JFaceResources.getResources(), stdDeviation.getWidget())));\r
+ GridDataFactory.fillDefaults().grab(true, false).applyTo(stdDeviation.getWidget());\r
+ \r
// maxValue\r
label = new Label(composite, SWT.NONE);\r
label.setText("Max value");\r
- GridDataFactory.fillDefaults().applyTo(label);\r
+ GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(label);\r
\r
maxValue = new TrackedText(composite, support, SWT.BORDER);\r
maxValue.setTextFactory(new DoublePropertyFactory(SysdynResource.URIs.NormalDistribution_maxValue));\r
maxValue.setColorProvider(new SysdynBasicColorProvider(new LocalResourceManager(JFaceResources.getResources(), maxValue.getWidget())));\r
GridDataFactory.fillDefaults().grab(true, false).applyTo(maxValue.getWidget());\r
\r
- // mean\r
- label = new Label(composite, SWT.NONE);\r
- label.setText("Mean");\r
- GridDataFactory.fillDefaults().applyTo(label);\r
- \r
- mean = new TrackedText(composite, support, SWT.BORDER);\r
- mean.setTextFactory(new DoublePropertyFactory(SysdynResource.URIs.NormalDistribution_mean));\r
- mean.addModifyListener(new DoublePropertyModifier(context, SysdynResource.URIs.NormalDistribution_mean));\r
- mean.setInputValidator(new DoubleValidator(true));\r
- mean.setColorProvider(new SysdynBasicColorProvider(new LocalResourceManager(JFaceResources.getResources(), mean.getWidget())));\r
- GridDataFactory.fillDefaults().grab(true, false).applyTo(mean.getWidget());\r
- \r
- // stdDeviation\r
- label = new Label(composite, SWT.NONE);\r
- label.setText("Standard deviation");\r
- GridDataFactory.fillDefaults().applyTo(label);\r
- \r
- stdDeviation = new TrackedText(composite, support, SWT.BORDER);\r
- stdDeviation.setTextFactory(new DoublePropertyFactory(SysdynResource.URIs.NormalDistribution_stdDeviation));\r
- stdDeviation.addModifyListener(new DoublePropertyModifier(context, SysdynResource.URIs.NormalDistribution_stdDeviation));\r
- stdDeviation.setInputValidator(new DoubleValidator(true));\r
- stdDeviation.setColorProvider(new SysdynBasicColorProvider(new LocalResourceManager(JFaceResources.getResources(), stdDeviation.getWidget())));\r
- GridDataFactory.fillDefaults().grab(true, false).applyTo(stdDeviation.getWidget());\r
- \r
return composite;\r
}\r
\r
SysdynModel sm = smm.getModel(graph, graph.getPossibleObject(model, SimulationResource.getInstance(graph).HasConfiguration));\r
\r
Variable variable = RepresentationUtils.getVariable(sm.getConfiguration(), variableName);\r
- \r
- if(indexes == null && (variable.getArrayIndexes() != null & variable.getArrayIndexes().size() > 0)) {\r
- indexes = new String[variable.getArrayIndexes().size()];\r
- \r
- for(int i = 0; i < variable.getArrayIndexes().size(); i++) {\r
- Enumeration e = variable.getArrayIndexes().get(i);\r
- indexes[i] = e.getEnumerationIndexes().get(0).getName();\r
- }\r
- }\r
- \r
- if(indexes != null) {\r
- StringBuilder sb = new StringBuilder();\r
- sb.append("[");\r
- for(int i = 0; i < indexes.length; i++) {\r
- if(i > 0)\r
- sb.append(",");\r
-\r
- String index = indexes[i];\r
- sb.append(index);\r
- }\r
- sb.append("]");\r
- String result = IndexUtils.rangeToIndexes(variable, sb.toString());\r
- fullName = variableName + result;\r
- } else {\r
- fullName = variableName;\r
+ \r
+ if (variable != null) {\r
+ if(indexes == null && (variable.getArrayIndexes() != null & variable.getArrayIndexes().size() > 0)) {\r
+ indexes = new String[variable.getArrayIndexes().size()];\r
+ \r
+ for(int i = 0; i < variable.getArrayIndexes().size(); i++) {\r
+ Enumeration e = variable.getArrayIndexes().get(i);\r
+ indexes[i] = e.getEnumerationIndexes().get(0).getName();\r
+ }\r
+ }\r
+ \r
+ if(indexes != null) {\r
+ StringBuilder sb = new StringBuilder();\r
+ sb.append("[");\r
+ for(int i = 0; i < indexes.length; i++) {\r
+ if(i > 0)\r
+ sb.append(",");\r
+ \r
+ String index = indexes[i];\r
+ sb.append(index);\r
+ }\r
+ sb.append("]");\r
+ String result = IndexUtils.rangeToIndexes(variable, sb.toString());\r
+ fullName = variableName + result;\r
+ } else {\r
+ fullName = variableName;\r
+ }\r
}\r
} catch (DatabaseException e) {\r
\r
if(parameters != null) {\r
parameters.clear();\r
for(Resource p : parameterResources) {\r
- SensitivityExperimentParameter parameter = graph.adapt(p, SensitivityExperimentParameter.class);\r
- parameters.add(parameter);\r
+ SensitivityExperimentParameter parameter = graph.adapt(p, SensitivityExperimentParameter.class);\r
+ if (parameter.getFullName() != null)\r
+ parameters.add(parameter);\r
}\r
}\r
}\r