From c208db116abb1f2f56859f3b0fee2e28d8fdb569 Mon Sep 17 00:00:00 2001 From: jsimomaa Date: Thu, 26 Sep 2019 12:57:00 +0300 Subject: [PATCH] Make defaults to work & remove apply button in dynamic visualisations gitlab #59 Change-Id: I47a836eb0d45616f475240511031fc1361d186e6 (cherry picked from commit ae5159794b57b980f6f2d5e509e6a47843be8ca0) --- .../DynamicVisualisationsUI.java | 105 ++++++++++++++---- .../district/network/DistrictNetworkUtil.java | 48 ++++---- .../ActiveDynamicVisualisationsRequest.java | 14 ++- .../network/profile/DNElementColorStyle.java | 25 ++++- .../network/profile/DNElementSizeStyle.java | 28 ++++- .../model/DynamicVisualisation.java | 16 ++- 6 files changed, 189 insertions(+), 47 deletions(-) diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/visualisations/DynamicVisualisationsUI.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/visualisations/DynamicVisualisationsUI.java index 14a8f00f..c5be0451 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/visualisations/DynamicVisualisationsUI.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/visualisations/DynamicVisualisationsUI.java @@ -18,6 +18,12 @@ import org.eclipse.jface.dialogs.InputDialog; import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.GridLayoutFactory; import org.eclipse.swt.SWT; +import org.eclipse.swt.events.FocusAdapter; +import org.eclipse.swt.events.FocusEvent; +import org.eclipse.swt.events.KeyAdapter; +import org.eclipse.swt.events.KeyEvent; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.widgets.Button; @@ -28,6 +34,7 @@ import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; +import org.eclipse.swt.widgets.Widget; import org.simantics.Simantics; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; @@ -85,8 +92,6 @@ public class DynamicVisualisationsUI extends Composite { private Button removeVisualisationTemplateButton; - private Button applyButton; - public DynamicVisualisationsUI(Composite parent, int style) { super(parent, style); // ScrolledComposite scrolledComposite = new ScrolledComposite(this, SWT.V_SCROLL); @@ -174,22 +179,6 @@ public class DynamicVisualisationsUI extends Composite { } }); - applyButton = new Button(buttonBarsComposite, SWT.NONE); - applyButton.setText("Apply"); - applyButton.setEnabled(visualisation != null); - applyButton.addSelectionListener(new SelectionAdapter() { - - @Override - public void widgetSelected(SelectionEvent e) { - try { - persistVisualisationTemplate(visualisation.getName(), Optional.of(visualisation.getVisualisationResource())); - } catch (Exception e1) { - LOGGER.error("Could not persist visualisation template", e1); - ShowError.showError("Could not persist visualisation template", e1.getMessage(), e1); - } - } - }); - removeVisualisationTemplateButton = new Button(buttonBarsComposite, SWT.NONE); removeVisualisationTemplateButton.setText("Remove"); removeVisualisationTemplateButton.setEnabled(visualisation != null && visualisation.getVisualisationResource() != null); @@ -474,17 +463,21 @@ public class DynamicVisualisationsUI extends Composite { Button usedButton = new Button(parent, SWT.CHECK); GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(usedButton); + addSelectionListener(usedButton); Combo variableCombo = new Combo(parent, SWT.READ_ONLY); variableCombo.setItems(colorContributions.keySet().toArray(new String[colorContributions.size()])); + addSelectionListener(variableCombo); GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(variableCombo); Text minText = new Text(parent, SWT.BORDER); GridDataFactory.fillDefaults().grab(true, false).hint(150, SWT.DEFAULT).align(SWT.CENTER, SWT.CENTER).applyTo(minText); + addSelectionListener(minText); Text maxText = new Text(parent, SWT.BORDER); GridDataFactory.fillDefaults().grab(true, false).hint(150, SWT.DEFAULT).align(SWT.CENTER, SWT.CENTER).applyTo(maxText); + addSelectionListener(maxText); Text unit = new Text(parent, SWT.READ_ONLY); GridDataFactory.fillDefaults().grab(true, false).align(SWT.CENTER, SWT.CENTER).applyTo(unit); @@ -492,9 +485,11 @@ public class DynamicVisualisationsUI extends Composite { Combo colorMapCombo = new Combo(parent, SWT.READ_ONLY); GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(colorMapCombo); colorMapCombo.setItems(colorMaps.keySet().toArray(new String[colorMaps.keySet().size()])); + addSelectionListener(colorMapCombo); Button defaultButton = new Button(parent, SWT.CHECK); GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(defaultButton); + addSelectionListener(defaultButton); defaultButton.addSelectionListener(new SelectionAdapter() { @Override @@ -637,17 +632,21 @@ public class DynamicVisualisationsUI extends Composite { Button usedButton = new Button(parent, SWT.CHECK); GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(usedButton); + addSelectionListener(usedButton); Combo variableCombo = new Combo(parent, SWT.READ_ONLY); variableCombo.setItems(sizeContributions.keySet().toArray(new String[sizeContributions.size()])); + addSelectionListener(variableCombo); GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(variableCombo); Text minText = new Text(parent, SWT.BORDER); GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(minText); + addSelectionListener(minText); Text maxText = new Text(parent, SWT.BORDER); GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(maxText); + addSelectionListener(maxText); Label unit = new Label(parent, SWT.NONE); GridDataFactory.fillDefaults().grab(true, false).align(SWT.CENTER, SWT.CENTER).applyTo(unit); @@ -655,9 +654,11 @@ public class DynamicVisualisationsUI extends Composite { Combo sizeMapCombo = new Combo(parent, SWT.READ_ONLY); GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(sizeMapCombo); sizeMapCombo.setItems(sizeMaps.keySet().toArray(new String[sizeMaps.keySet().size()])); + addSelectionListener(sizeMapCombo); Button defaultButton = new Button(parent, SWT.CHECK); GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(defaultButton); + addSelectionListener(defaultButton); defaultButton.addSelectionListener(new SelectionAdapter() { @Override @@ -766,12 +767,15 @@ public class DynamicVisualisationsUI extends Composite { showColorButton = new Button(parent, SWT.CHECK); showColorButton.setText("Show"); + addSelectionListener(showColorButton); colorTicksButton = new Button(parent, SWT.CHECK); colorTicksButton.setText("Ticks"); + addSelectionListener(colorTicksButton); colorGradientButton = new Button(parent, SWT.CHECK); colorGradientButton.setText("Gradients"); + addSelectionListener(colorGradientButton); Label label = new Label(parent, SWT.NONE); label.setText("Location"); @@ -781,6 +785,7 @@ public class DynamicVisualisationsUI extends Composite { if (colorLocationItems.length > 0) { colorLocationCombo.select(0); } + addSelectionListener(colorLocationCombo); label = new Label(parent, SWT.NONE); label.setText("Size"); @@ -790,6 +795,7 @@ public class DynamicVisualisationsUI extends Composite { if (colorSizeItems.length > 0) { colorSizeCombo.select(0); } + addSelectionListener(colorSizeCombo); } private void initializeObjectSizes(Composite parent) { @@ -837,12 +843,15 @@ public class DynamicVisualisationsUI extends Composite { private void createSizeBars(Composite parent) { showSizeButton = new Button(parent, SWT.CHECK); showSizeButton.setText("Show"); + addSelectionListener(showSizeButton); sizeTicksButton = new Button(parent, SWT.CHECK); sizeTicksButton.setText("Ticks"); + addSelectionListener(sizeTicksButton); sizeGradientButton = new Button(parent, SWT.CHECK); sizeGradientButton.setText("Gradient"); + addSelectionListener(sizeGradientButton); Label label = new Label(parent, SWT.NONE); label.setText("Location"); @@ -852,6 +861,7 @@ public class DynamicVisualisationsUI extends Composite { if (sizeLocationItems.length > 0) { sizeLocationCombo.select(0); } + addSelectionListener(sizeLocationCombo); label = new Label(parent, SWT.NONE); label.setText("Size"); @@ -861,6 +871,64 @@ public class DynamicVisualisationsUI extends Composite { if (sizeSizeItems.length > 0) { sizeSizeCombo.select(0); } + addSelectionListener(sizeSizeCombo); + } + + private void addSelectionListener(Widget widget) { + if (widget instanceof Button) { + ((Button) widget).addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent e) { + try { + persistVisualisationTemplate(visualisation.getName(), Optional.of(visualisation.getVisualisationResource())); + } catch (Exception e1) { + LOGGER.error("Could not persist visualisation template", e1); + ShowError.showError("Could not persist visualisation template", e1.getMessage(), e1); + } + } + }); + } else if (widget instanceof Combo) { + ((Combo) widget).addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent e) { + try { + persistVisualisationTemplate(visualisation.getName(), Optional.of(visualisation.getVisualisationResource())); + } catch (Exception e1) { + LOGGER.error("Could not persist visualisation template", e1); + ShowError.showError("Could not persist visualisation template", e1.getMessage(), e1); + } + } + }); + } else if (widget instanceof Text) { + ((Text) widget).addFocusListener(new FocusAdapter() { + + @Override + public void focusLost(FocusEvent e) { + try { + persistVisualisationTemplate(visualisation.getName(), Optional.of(visualisation.getVisualisationResource())); + } catch (Exception e1) { + LOGGER.error("Could not persist visualisation template", e1); + ShowError.showError("Could not persist visualisation template", e1.getMessage(), e1); + } + } + }); + ((Text) widget).addKeyListener(new KeyAdapter() { + + @Override + public void keyReleased(KeyEvent e) { + if(e.keyCode == SWT.CR || e.keyCode == SWT.LF) { + try { + persistVisualisationTemplate(visualisation.getName(), Optional.of(visualisation.getVisualisationResource())); + } catch (Exception e1) { + LOGGER.error("Could not persist visualisation template", e1); + ShowError.showError("Could not persist visualisation template", e1.getMessage(), e1); + } + } + } + }); + } } public void setParentResource(Resource parentResource) { @@ -950,7 +1018,6 @@ public class DynamicVisualisationsUI extends Composite { if (getParent().isDisposed()) return; - applyButton.setEnabled(visualisation != null && visualisation.getVisualisationResource() != null); removeVisualisationTemplateButton.setEnabled(visualisation != null && visualisation.getVisualisationResource() != null); if (visualisation != null) { diff --git a/org.simantics.district.network/src/org/simantics/district/network/DistrictNetworkUtil.java b/org.simantics.district.network/src/org/simantics/district/network/DistrictNetworkUtil.java index 54d3a595..e3fbac6d 100644 --- a/org.simantics.district.network/src/org/simantics/district/network/DistrictNetworkUtil.java +++ b/org.simantics.district.network/src/org/simantics/district/network/DistrictNetworkUtil.java @@ -535,18 +535,18 @@ public class DistrictNetworkUtil { graph.claimLiteral(colorContribution, L0.HasName, coll.first); DynamicColorContribution contr = coll.second; - graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_colorContributionContributorName, coll.first); - graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_colorContributionLabel, contr.getLabel()); - graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_colorContributionModuleName, contr.getModuleName()); - graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_colorContributionModuleAttribute, contr.getAttributeName()); - graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_colorContributionUnit, contr.getUnit()); - graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_colorContributionVariableGain, contr.getVariableGain()); - graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_colorContributionVariableBias, contr.getVariableBias()); - graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_colorContributionDefaultColorMap, contr.getDefaultColorMap().getLabel()); - graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_colorContributionDefaultMin, contr.getDefaultMin()); - graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_colorContributionDefaultMax, contr.getDefaultMax()); - graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_colorContributionUsed, contr.isUsed()); - graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_colorContributionUseDefault, contr.isUseDefault()); + graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_colorContributionContributorName, coll.first, Bindings.STRING); + graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_colorContributionLabel, contr.getLabel(), Bindings.STRING); + graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_colorContributionModuleName, contr.getModuleName(), Bindings.STRING); + graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_colorContributionModuleAttribute, contr.getAttributeName(), Bindings.STRING); + graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_colorContributionUnit, contr.getUnit(), Bindings.STRING); + graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_colorContributionVariableGain, contr.getVariableGain(), Bindings.DOUBLE); + graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_colorContributionVariableBias, contr.getVariableBias(), Bindings.DOUBLE); + graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_colorContributionDefaultColorMap, contr.getDefaultColorMap().getLabel(), Bindings.STRING); + graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_colorContributionDefaultMin, contr.getDefaultMin(), Bindings.DOUBLE); + graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_colorContributionDefaultMax, contr.getDefaultMax(), Bindings.DOUBLE); + graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_colorContributionUsed, contr.isUsed(), Bindings.BOOLEAN); + graph.claimLiteral(colorContribution, DN.Diagram_Visualisations_colorContributionUseDefault, contr.isUseDefault(), Bindings.BOOLEAN); graph.claim(visualisation, DN.Diagram_Visualisations_colorContributions, colorContribution); } @@ -594,18 +594,18 @@ public class DistrictNetworkUtil { graph.claimLiteral(sizeContribution, L0.HasName, coll.first); DynamicSizeContribution contr = coll.second; - graph.claimLiteral(sizeContribution, DN.Diagram_Visualisations_sizeContributionContributorName, coll.first); - graph.claimLiteral(sizeContribution, DN.Diagram_Visualisations_sizeContributionLabel, contr.getLabel()); - graph.claimLiteral(sizeContribution, DN.Diagram_Visualisations_sizeContributionModuleName, contr.getModuleName()); - graph.claimLiteral(sizeContribution, DN.Diagram_Visualisations_sizeContributionModuleAttribute, contr.getAttributeName()); - graph.claimLiteral(sizeContribution, DN.Diagram_Visualisations_sizeContributionUnit, contr.getUnit()); - graph.claimLiteral(sizeContribution, DN.Diagram_Visualisations_sizeContributionVariableGain, contr.getVariableGain()); - graph.claimLiteral(sizeContribution, DN.Diagram_Visualisations_sizeContributionVariableBias, contr.getVariableBias()); - graph.claimLiteral(sizeContribution, DN.Diagram_Visualisations_sizeContributionDefaultSizeMap, contr.getDefaultSizeMap().getLabel()); - graph.claimLiteral(sizeContribution, DN.Diagram_Visualisations_sizeContributionDefaultMin, contr.getDefaultMin()); - graph.claimLiteral(sizeContribution, DN.Diagram_Visualisations_sizeContributionDefaultMax, contr.getDefaultMax()); - graph.claimLiteral(sizeContribution, DN.Diagram_Visualisations_sizeContributionUsed, contr.isUsed()); - graph.claimLiteral(sizeContribution, DN.Diagram_Visualisations_sizeContributionUseDefault, contr.isUseDefault()); + graph.claimLiteral(sizeContribution, DN.Diagram_Visualisations_sizeContributionContributorName, coll.first, Bindings.STRING); + graph.claimLiteral(sizeContribution, DN.Diagram_Visualisations_sizeContributionLabel, contr.getLabel(), Bindings.STRING); + graph.claimLiteral(sizeContribution, DN.Diagram_Visualisations_sizeContributionModuleName, contr.getModuleName(), Bindings.STRING); + graph.claimLiteral(sizeContribution, DN.Diagram_Visualisations_sizeContributionModuleAttribute, contr.getAttributeName(), Bindings.STRING); + graph.claimLiteral(sizeContribution, DN.Diagram_Visualisations_sizeContributionUnit, contr.getUnit(), Bindings.STRING); + graph.claimLiteral(sizeContribution, DN.Diagram_Visualisations_sizeContributionVariableGain, contr.getVariableGain(), Bindings.DOUBLE); + graph.claimLiteral(sizeContribution, DN.Diagram_Visualisations_sizeContributionVariableBias, contr.getVariableBias(), Bindings.DOUBLE); + graph.claimLiteral(sizeContribution, DN.Diagram_Visualisations_sizeContributionDefaultSizeMap, contr.getDefaultSizeMap().getLabel(), Bindings.STRING); + graph.claimLiteral(sizeContribution, DN.Diagram_Visualisations_sizeContributionDefaultMin, contr.getDefaultMin(), Bindings.DOUBLE); + graph.claimLiteral(sizeContribution, DN.Diagram_Visualisations_sizeContributionDefaultMax, contr.getDefaultMax(), Bindings.DOUBLE); + graph.claimLiteral(sizeContribution, DN.Diagram_Visualisations_sizeContributionUsed, contr.isUsed(), Bindings.BOOLEAN); + graph.claimLiteral(sizeContribution, DN.Diagram_Visualisations_sizeContributionUseDefault, contr.isUseDefault(), Bindings.BOOLEAN); graph.claim(visualisation, DN.Diagram_Visualisations_sizeContributions, sizeContribution); } diff --git a/org.simantics.district.network/src/org/simantics/district/network/profile/ActiveDynamicVisualisationsRequest.java b/org.simantics.district.network/src/org/simantics/district/network/profile/ActiveDynamicVisualisationsRequest.java index 58499db0..f8f4b9aa 100644 --- a/org.simantics.district.network/src/org/simantics/district/network/profile/ActiveDynamicVisualisationsRequest.java +++ b/org.simantics.district.network/src/org/simantics/district/network/profile/ActiveDynamicVisualisationsRequest.java @@ -1,6 +1,8 @@ package org.simantics.district.network.profile; +import java.util.Collection; import java.util.Map; +import java.util.stream.Collectors; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; @@ -8,6 +10,9 @@ import org.simantics.db.common.request.ResourceRead; import org.simantics.db.exception.DatabaseException; import org.simantics.district.network.DistrictNetworkUtil; import org.simantics.district.network.ontology.DistrictNetworkResource; +import org.simantics.district.network.visualisations.DynamicVisualisationsContributions; +import org.simantics.district.network.visualisations.DynamicVisualisationsContributions.DynamicColoringObject; +import org.simantics.district.network.visualisations.DynamicVisualisationsContributions.DynamicSizingObject; import org.simantics.district.network.visualisations.model.ColorBarOptions; import org.simantics.district.network.visualisations.model.DynamicColorContribution; import org.simantics.district.network.visualisations.model.DynamicSizeContribution; @@ -32,11 +37,18 @@ public class ActiveDynamicVisualisationsRequest extends ResourceRead dynamicColoringObjects = DynamicVisualisationsContributions.dynamicColoringObjects(graph); + Map defaultColoringObjects = dynamicColoringObjects.stream().collect(Collectors.toMap(dcc -> dcc.getColoringObject().getName(), dcc -> dcc)); + + Collection dynamicSizingObjects = DynamicVisualisationsContributions.dynamicSizingObjects(graph); + Map defaultSizingObjects = dynamicSizingObjects.stream().collect(Collectors.toMap(dcc -> dcc.getSizingObject().getName(), dcc -> dcc)); + Map colorContributions = DistrictNetworkUtil.colorContributions(graph, visualisationResource); ColorBarOptions colorBarOptions = DistrictNetworkUtil.colorBarOptions(graph, visualisationResource); Map sizeContributions = DistrictNetworkUtil.sizeContributions(graph, visualisationResource); SizeBarOptions sizeBarOptions = DistrictNetworkUtil.sizeBarOptions(graph, visualisationResource); - DynamicVisualisation visualisation = new DynamicVisualisation(name, visualisationResource, colorContributions, colorBarOptions, sizeContributions, sizeBarOptions); + DynamicVisualisation visualisation = new DynamicVisualisation(name, visualisationResource, colorContributions, defaultColoringObjects, colorBarOptions, sizeContributions, defaultSizingObjects, sizeBarOptions); return visualisation; } } diff --git a/org.simantics.district.network/src/org/simantics/district/network/profile/DNElementColorStyle.java b/org.simantics.district.network/src/org/simantics/district/network/profile/DNElementColorStyle.java index 9bcae2e5..1e50a92e 100644 --- a/org.simantics.district.network/src/org/simantics/district/network/profile/DNElementColorStyle.java +++ b/org.simantics.district.network/src/org/simantics/district/network/profile/DNElementColorStyle.java @@ -11,6 +11,7 @@ import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.variable.Variable; import org.simantics.db.layer0.variable.Variables; import org.simantics.district.network.ontology.DistrictNetworkResource; +import org.simantics.district.network.visualisations.DynamicVisualisationsContributions.DynamicColoringObject; import org.simantics.district.network.visualisations.model.DynamicColorContribution; import org.simantics.district.network.visualisations.model.DynamicColorMap; import org.simantics.district.network.visualisations.model.DynamicVisualisation; @@ -20,6 +21,7 @@ import org.simantics.scenegraph.INode; import org.simantics.scenegraph.g2d.nodes.SingleElementNode; import org.simantics.scenegraph.profile.EvaluationContext; import org.simantics.scenegraph.profile.common.ProfileVariables; +import org.simantics.scl.runtime.SCLContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -67,10 +69,31 @@ public class DNElementColorStyle extends ThrottledStyleBase { if (attribute != null) { Double possibleValue = attribute.getPossibleValue(graph, Bindings.DOUBLE); if (possibleValue != null) { + + double minValue; + double maxValue; + if (dcc.isUseDefault()) { + DynamicColoringObject dynamicColoringObject = dv.getDefaultColorContributions().get(mappingName); + + // This is required if ontology module needs to be compiled + Object currentGraph = SCLContext.getCurrent().get("graph"); + try { + SCLContext.getCurrent().put("graph", graph); + + DynamicColorContribution ddcc = dynamicColoringObject.getColorContributions().get(dcc.getLabel()); + minValue = ddcc.getDefaultMin(); + maxValue = ddcc.getDefaultMax(); + } finally { + SCLContext.getCurrent().put("graph", currentGraph); + } + } else { + minValue = dcc.getDefaultMin(); + maxValue = dcc.getDefaultMax(); + } // here we do the adjusting according to spec in #15038 double adjustedValue = possibleValue.doubleValue() * dcc.getVariableGain() + dcc.getVariableBias(); DynamicColorMap defaultColorMap = dcc.getDefaultColorMap(); - Color color = defaultColorMap.getColor(adjustedValue, dv.getColorBarOptions().isUseGradients(), dcc.getDefaultMin(), dcc.getDefaultMax()); + Color color = defaultColorMap.getColor(adjustedValue, dv.getColorBarOptions().isUseGradients(), minValue, maxValue); return color; } else { LOGGER.warn("No value for {}", attribute.getURI(graph)); diff --git a/org.simantics.district.network/src/org/simantics/district/network/profile/DNElementSizeStyle.java b/org.simantics.district.network/src/org/simantics/district/network/profile/DNElementSizeStyle.java index 0a454eef..870f7457 100644 --- a/org.simantics.district.network/src/org/simantics/district/network/profile/DNElementSizeStyle.java +++ b/org.simantics.district.network/src/org/simantics/district/network/profile/DNElementSizeStyle.java @@ -10,6 +10,9 @@ import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.variable.Variable; import org.simantics.db.layer0.variable.Variables; import org.simantics.district.network.ontology.DistrictNetworkResource; +import org.simantics.district.network.visualisations.DynamicVisualisationsContributions.DynamicColoringObject; +import org.simantics.district.network.visualisations.DynamicVisualisationsContributions.DynamicSizingObject; +import org.simantics.district.network.visualisations.model.DynamicColorContribution; import org.simantics.district.network.visualisations.model.DynamicSizeContribution; import org.simantics.district.network.visualisations.model.DynamicSizeMap; import org.simantics.district.network.visualisations.model.DynamicVisualisation; @@ -20,6 +23,7 @@ import org.simantics.scenegraph.g2d.G2DSceneGraph; import org.simantics.scenegraph.g2d.nodes.SingleElementNode; import org.simantics.scenegraph.profile.EvaluationContext; import org.simantics.scenegraph.profile.common.ProfileVariables; +import org.simantics.scl.runtime.SCLContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -68,10 +72,32 @@ public class DNElementSizeStyle extends ThrottledStyleBase { if (attribute != null) { Double possibleValue = attribute.getPossibleValue(graph, Bindings.DOUBLE); if (possibleValue != null) { + + + double minValue; + double maxValue; + if (dsc.isUseDefault()) { + DynamicSizingObject dynamicSizingObject = dv.getDefaultSizeContributions().get(mappingName); + + // This is required if ontology module needs to be compiled + Object currentGraph = SCLContext.getCurrent().get("graph"); + try { + SCLContext.getCurrent().put("graph", graph); + + DynamicSizeContribution ddcc = dynamicSizingObject.getSizeContributions().get(dsc.getLabel()); + minValue = ddcc.getDefaultMin(); + maxValue = ddcc.getDefaultMax(); + } finally { + SCLContext.getCurrent().put("graph", currentGraph); + } + } else { + minValue = dsc.getDefaultMin(); + maxValue = dsc.getDefaultMax(); + } // here we do the adjusting according to spec in #15038 double adjustedValue = possibleValue.doubleValue() * dsc.getVariableGain() + dsc.getVariableBias(); DynamicSizeMap defaultSizeMap = dsc.getDefaultSizeMap(); - double size = defaultSizeMap.getSize(adjustedValue, dv.getSizeBarOptions().isUseGradients(), dsc.getDefaultMin(), dsc.getDefaultMax()); + double size = defaultSizeMap.getSize(adjustedValue, dv.getSizeBarOptions().isUseGradients(), minValue, maxValue); return size; } else { LOGGER.warn("No value for {}", attribute.getURI(graph)); diff --git a/org.simantics.district.network/src/org/simantics/district/network/visualisations/model/DynamicVisualisation.java b/org.simantics.district.network/src/org/simantics/district/network/visualisations/model/DynamicVisualisation.java index 24cf9bed..fa329b86 100644 --- a/org.simantics.district.network/src/org/simantics/district/network/visualisations/model/DynamicVisualisation.java +++ b/org.simantics.district.network/src/org/simantics/district/network/visualisations/model/DynamicVisualisation.java @@ -3,6 +3,8 @@ package org.simantics.district.network.visualisations.model; import java.util.Map; import org.simantics.db.Resource; +import org.simantics.district.network.visualisations.DynamicVisualisationsContributions.DynamicColoringObject; +import org.simantics.district.network.visualisations.DynamicVisualisationsContributions.DynamicSizingObject; public class DynamicVisualisation { @@ -10,16 +12,20 @@ public class DynamicVisualisation { private Resource visualisationResource; private Map colorContributions; + private Map defaultColorContributions; private ColorBarOptions colorBarOptions; private Map sizeContributions; + private Map defaultSizeContributions; private SizeBarOptions sizeBarOptions; - public DynamicVisualisation(String name, Resource visualisationResource, Map colorContributions, ColorBarOptions colorBarOptions, Map sizeContributions, SizeBarOptions sizeBarOptions) { + public DynamicVisualisation(String name, Resource visualisationResource, Map colorContributions, Map defaultColoringObjects, ColorBarOptions colorBarOptions, Map sizeContributions, Map defaultSizingObjects, SizeBarOptions sizeBarOptions) { this.name = name; this.visualisationResource = visualisationResource; this.colorContributions = colorContributions; + this.defaultColorContributions = defaultColoringObjects; this.colorBarOptions = colorBarOptions; this.sizeContributions = sizeContributions; + this.defaultSizeContributions = defaultSizingObjects; this.sizeBarOptions = sizeBarOptions; } @@ -34,6 +40,10 @@ public class DynamicVisualisation { public Map getColorContributions() { return colorContributions; } + + public Map getDefaultColorContributions() { + return defaultColorContributions; + } public ColorBarOptions getColorBarOptions() { return colorBarOptions; @@ -42,6 +52,10 @@ public class DynamicVisualisation { public Map getSizeContributions() { return sizeContributions; } + + public Map getDefaultSizeContributions() { + return defaultSizeContributions; + } public SizeBarOptions getSizeBarOptions() { return sizeBarOptions; -- 2.47.1