L0.HasRange L0.Boolean
L0.HasLabel "Split To Multiple Diagrams"
+// Dynamic Visualisations
+DN.VisualisationsFolder <T L0.Entity
DN.Diagram.Visualisations <T L0.Entity
>-- DN.Diagram.Visualisations.ShowColorBars
@defProperty "Show Color Bars" L0.Boolean
>-- DN.Diagram.Visualisations.ShowColorBarTicks
@defProperty "Show Color Bar Ticks" L0.Boolean
+ >-- DN.Diagram.Visualisations.UseColorBarGradients
+ @defProperty "Use Color Bar Gradients" L0.Boolean
>-- DN.Diagram.Visualisations.ColorBarLocation
@defProperty "Color Bar Location" L0.String
>-- DN.Diagram.Visualisations.ColorBarSize
@defProperty "Show Size Bars" L0.Boolean
>-- DN.Diagram.Visualisations.ShowSizeBarTicks
@defProperty "Show Size Bar Ticks" L0.Boolean
+ >-- DN.Diagram.Visualisations.UseSizeBarGradients
+ @defProperty "Use Size Bar Gradients" L0.Boolean
>-- DN.Diagram.Visualisations.SizeBarLocation
@defProperty "Size Bar Location" L0.String
>-- DN.Diagram.Visualisations.SizeBarSize
DN.Diagram.Visualisations.sizeContributionUseDefault <R L0.HasProperty
+// End of dynamic visualisations
+
DN.AddLayerToDNDiagramTemplate <T L0.Template
DN.EPSG_4326 : DN.SpatialRefSystem
DN.DistrictNodeGroup <T DIA.TypeGroup
>-- DN.DistrictNodeGroup.hasComponentTypeName ==> "String" <R L0.HasProperty
+DN.Groups.ElementGroup : DIA.TypeGroup
+ DIA.TypeGroup.HasType DN.Element
DN.Groups.VertexGroup : DIA.TypeGroup
DIA.TypeGroup.HasType DN.Vertex
DN.Groups.EdgeGroup : DIA.TypeGroup
DN.ElementColoringStyle : DIA.Style
DN.ElementSizingStyle : DIA.Style
-// These are deprecated in favor of new dynamic visualisations
-//DN.VertexSizeStyle : DIA.Style
-//DN.EdgeThicknessStyle : DIA.Style
+
DN.ArrowLengthStyle : DIA.Style
DN.HideStyle : DIA.Style
DN.VertexSymbolStyle : DIA.Style
public final Resource Diagram_Visualisations_SizeBarSize;
public final Resource Diagram_Visualisations_SizeBarSize_Inverse;
public final Resource Diagram_Visualisations_SizeContribution;
+ public final Resource Diagram_Visualisations_UseColorBarGradients;
+ public final Resource Diagram_Visualisations_UseColorBarGradients_Inverse;
+ public final Resource Diagram_Visualisations_UseSizeBarGradients;
+ public final Resource Diagram_Visualisations_UseSizeBarGradients_Inverse;
public final Resource Diagram_Visualisations_colorContributionContributorName;
public final Resource Diagram_Visualisations_colorContributionContributorName_Inverse;
public final Resource Diagram_Visualisations_colorContributionDefaultColorMap;
public final Resource Functions_mappingModifier;
public final Resource Groups;
public final Resource Groups_EdgeGroup;
+ public final Resource Groups_ElementGroup;
public final Resource Groups_VertexGroup;
public final Resource HasEndVertex;
public final Resource HasEndVertex_Inverse;
public final Resource Vertex_HasVelocity_Inverse;
public final Resource Vertex_HasVolFlow;
public final Resource Vertex_HasVolFlow_Inverse;
+ public final Resource VisualisationsFolder;
public static class URIs {
public static final String ActionContext = "http://www.simantics.org/DistrictNetwork-1.0/ActionContext";
public static final String Diagram_Visualisations_SizeBarSize = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/SizeBarSize";
public static final String Diagram_Visualisations_SizeBarSize_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/SizeBarSize/Inverse";
public static final String Diagram_Visualisations_SizeContribution = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/SizeContribution";
+ public static final String Diagram_Visualisations_UseColorBarGradients = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/UseColorBarGradients";
+ public static final String Diagram_Visualisations_UseColorBarGradients_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/UseColorBarGradients/Inverse";
+ public static final String Diagram_Visualisations_UseSizeBarGradients = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/UseSizeBarGradients";
+ public static final String Diagram_Visualisations_UseSizeBarGradients_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/UseSizeBarGradients/Inverse";
public static final String Diagram_Visualisations_colorContributionContributorName = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/colorContributionContributorName";
public static final String Diagram_Visualisations_colorContributionContributorName_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/colorContributionContributorName/Inverse";
public static final String Diagram_Visualisations_colorContributionDefaultColorMap = "http://www.simantics.org/DistrictNetwork-1.0/Diagram/Visualisations/colorContributionDefaultColorMap";
public static final String Functions_mappingModifier = "http://www.simantics.org/DistrictNetwork-1.0/Functions/mappingModifier";
public static final String Groups = "http://www.simantics.org/DistrictNetwork-1.0/Groups";
public static final String Groups_EdgeGroup = "http://www.simantics.org/DistrictNetwork-1.0/Groups/EdgeGroup";
+ public static final String Groups_ElementGroup = "http://www.simantics.org/DistrictNetwork-1.0/Groups/ElementGroup";
public static final String Groups_VertexGroup = "http://www.simantics.org/DistrictNetwork-1.0/Groups/VertexGroup";
public static final String HasEndVertex = "http://www.simantics.org/DistrictNetwork-1.0/HasEndVertex";
public static final String HasEndVertex_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/HasEndVertex_Inverse";
public static final String Vertex_HasVelocity_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Vertex/HasVelocity/Inverse";
public static final String Vertex_HasVolFlow = "http://www.simantics.org/DistrictNetwork-1.0/Vertex/HasVolFlow";
public static final String Vertex_HasVolFlow_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Vertex/HasVolFlow/Inverse";
+ public static final String VisualisationsFolder = "http://www.simantics.org/DistrictNetwork-1.0/VisualisationsFolder";
}
public static Resource getResourceOrNull(ReadGraph graph, String uri) {
Diagram_Visualisations_SizeBarSize = getResourceOrNull(graph, URIs.Diagram_Visualisations_SizeBarSize);
Diagram_Visualisations_SizeBarSize_Inverse = getResourceOrNull(graph, URIs.Diagram_Visualisations_SizeBarSize_Inverse);
Diagram_Visualisations_SizeContribution = getResourceOrNull(graph, URIs.Diagram_Visualisations_SizeContribution);
+ Diagram_Visualisations_UseColorBarGradients = getResourceOrNull(graph, URIs.Diagram_Visualisations_UseColorBarGradients);
+ Diagram_Visualisations_UseColorBarGradients_Inverse = getResourceOrNull(graph, URIs.Diagram_Visualisations_UseColorBarGradients_Inverse);
+ Diagram_Visualisations_UseSizeBarGradients = getResourceOrNull(graph, URIs.Diagram_Visualisations_UseSizeBarGradients);
+ Diagram_Visualisations_UseSizeBarGradients_Inverse = getResourceOrNull(graph, URIs.Diagram_Visualisations_UseSizeBarGradients_Inverse);
Diagram_Visualisations_colorContributionContributorName = getResourceOrNull(graph, URIs.Diagram_Visualisations_colorContributionContributorName);
Diagram_Visualisations_colorContributionContributorName_Inverse = getResourceOrNull(graph, URIs.Diagram_Visualisations_colorContributionContributorName_Inverse);
Diagram_Visualisations_colorContributionDefaultColorMap = getResourceOrNull(graph, URIs.Diagram_Visualisations_colorContributionDefaultColorMap);
Functions_mappingModifier = getResourceOrNull(graph, URIs.Functions_mappingModifier);
Groups = getResourceOrNull(graph, URIs.Groups);
Groups_EdgeGroup = getResourceOrNull(graph, URIs.Groups_EdgeGroup);
+ Groups_ElementGroup = getResourceOrNull(graph, URIs.Groups_ElementGroup);
Groups_VertexGroup = getResourceOrNull(graph, URIs.Groups_VertexGroup);
HasEndVertex = getResourceOrNull(graph, URIs.HasEndVertex);
HasEndVertex_Inverse = getResourceOrNull(graph, URIs.HasEndVertex_Inverse);
Vertex_HasVelocity_Inverse = getResourceOrNull(graph, URIs.Vertex_HasVelocity_Inverse);
Vertex_HasVolFlow = getResourceOrNull(graph, URIs.Vertex_HasVolFlow);
Vertex_HasVolFlow_Inverse = getResourceOrNull(graph, URIs.Vertex_HasVolFlow_Inverse);
+ VisualisationsFolder = getResourceOrNull(graph, URIs.VisualisationsFolder);
}
public static DistrictNetworkResource getInstance(ReadGraph graph) {
import org.simantics.datatypes.literal.RGB;
import org.simantics.db.ReadGraph;
import org.simantics.db.Resource;
+import org.simantics.db.common.request.IndexRoot;
import org.simantics.db.common.request.UnaryRead;
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.procedure.Listener;
@Override
public ColorBarOptions perform(ReadGraph graph) throws DatabaseException {
DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
- Resource activeVisualisation = graph.getPossibleObject(parameter, DN.Diagram_hasActiveVisualisation);
+ Resource model = graph.syncRequest(new IndexRoot(parameter));
+ Resource vf = DistrictNetworkUtil.getVisualisationFolder(graph, model);
+ Resource activeVisualisation = graph.getPossibleObject(vf, DN.Diagram_hasActiveVisualisation);
if (activeVisualisation != null) {
return DistrictNetworkUtil.colorBarOptions(graph, activeVisualisation);
}
@Override
public Map<String, DynamicColorContribution> perform(ReadGraph graph) throws DatabaseException {
DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
- Resource activeVisualisation = graph.getPossibleObject(parameter, DN.Diagram_hasActiveVisualisation);
+ Resource model = graph.syncRequest(new IndexRoot(parameter));
+ Resource vf = DistrictNetworkUtil.getVisualisationFolder(graph, model);
+ Resource activeVisualisation = graph.getPossibleObject(vf, DN.Diagram_hasActiveVisualisation);
if (activeVisualisation != null) {
return DistrictNetworkUtil.colorContributions(graph, activeVisualisation);
}
@Override
public SizeBarOptions perform(ReadGraph graph) throws DatabaseException {
DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
- Resource activeVisualisation = graph.getPossibleObject(parameter, DN.Diagram_hasActiveVisualisation);
+ Resource model = graph.syncRequest(new IndexRoot(parameter));
+ Resource vf = DistrictNetworkUtil.getVisualisationFolder(graph, model);
+ Resource activeVisualisation = graph.getPossibleObject(vf, DN.Diagram_hasActiveVisualisation);
if (activeVisualisation != null) {
return DistrictNetworkUtil.sizeBarOptions(graph, activeVisualisation);
}
@Override
public Map<String, DynamicSizeContribution> perform(ReadGraph graph) throws DatabaseException {
DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
- Resource activeVisualisation = graph.getPossibleObject(parameter, DN.Diagram_hasActiveVisualisation);
+ Resource model = graph.syncRequest(new IndexRoot(parameter));
+ Resource vf = DistrictNetworkUtil.getVisualisationFolder(graph, model);
+ Resource activeVisualisation = graph.getPossibleObject(vf, DN.Diagram_hasActiveVisualisation);
if (activeVisualisation != null) {
return DistrictNetworkUtil.sizeContributions(graph, activeVisualisation);
}
RGBIntensity intensity = intensities.get(j);
- g2d.setColor(new Color((float)intensity.getRed(), (float)intensity.getGreen(), (float)intensity.getBlue(), 1f));
- Rectangle2D colorVertical = new Rectangle2D.Double(colorVerticalLeft, colorVerticalTop, colorVerticalWidth, colorVerticalHeigth);
- g2d.fill(colorVertical);
+ if (colorBarsOptions.isUseGradients()) {
+
+ RGBIntensity upperLimitIntensity;
+ if (j + 1 != intensities.size())
+ upperLimitIntensity = intensities.get(j + 1);
+ else
+ upperLimitIntensity = intensity;
+
+ double minRed = intensity.getRed();
+ double minGreen = intensity.getGreen();
+ double minBlue = intensity.getBlue();
+
+ double maxRed = upperLimitIntensity.getRed();
+ double maxGreen = upperLimitIntensity.getGreen();
+ double maxBlue = upperLimitIntensity.getBlue();
+
+ double redDelta = (maxRed - minRed) / colorVerticalWidth;
+ double greenDelta = (maxGreen - minGreen) / colorVerticalWidth;
+ double blueDelta = (maxBlue - minBlue) / colorVerticalWidth;
+
+ for (int k = 0; k < colorVerticalWidth; k++) {
+
+
+ g2d.setColor(new Color((float)(minRed + (k * redDelta)), (float)(minGreen + (k * greenDelta)), (float)(minBlue + (k * blueDelta)), 1f));
+ Rectangle2D colorVertical = new Rectangle2D.Double(colorVerticalLeft + k, colorVerticalTop, 1, colorVerticalHeigth);
+ g2d.fill(colorVertical);
+ }
+
+ } else {
+ g2d.setColor(new Color((float)intensity.getRed(), (float)intensity.getGreen(), (float)intensity.getBlue(), 1f));
+ Rectangle2D colorVertical = new Rectangle2D.Double(colorVerticalLeft, colorVerticalTop, colorVerticalWidth, colorVerticalHeigth);
+ g2d.fill(colorVertical);
+ }
+
+
double value = min + j * interval;
String str = Double.toString(value);
import org.simantics.db.layer0.util.RemoverUtil;
import org.simantics.db.procedure.Listener;
import org.simantics.district.network.DistrictNetworkUtil;
-import org.simantics.district.network.ontology.DistrictNetworkResource;
import org.simantics.district.network.profile.ActiveDynamicVisualisationsRequest;
import org.simantics.district.network.profile.DynamicVisualisationsRequest;
import org.simantics.district.network.visualisations.DynamicVisualisationsContributions;
private static final Logger LOGGER = LoggerFactory.getLogger(DynamicVisualisationsUI.class);
- private Resource diagramResource;
+ private Resource parentResource;
private VisualisationListener listener;
private DynamicVisualisation visualisation;
@Override
public void perform(WriteGraph graph) throws DatabaseException {
- DistrictNetworkUtil.setActiveVisualisation(graph, diagramResource, template.getResource());
+ Resource vf = DistrictNetworkUtil.getVisualisationFolder(graph, parentResource);
+ DistrictNetworkUtil.setActiveVisualisation(graph, vf, template.getResource());
}
});
break;
@Override
public void perform(WriteGraph graph) throws DatabaseException {
- DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
Resource exist;
if (existing.isPresent()) {
exist = existing.get();
} else {
- exist = DistrictNetworkUtil.createVisualisation(graph, diagramResource, templateName);
+ exist = DistrictNetworkUtil.createVisualisation(graph, parentResource, templateName);
}
DistrictNetworkUtil.setColorContributions(graph, exist, colorCollect);
colorSuppliers = new ArrayList<>();
{
try {
- Collection<DynamicColoringObject> result = Simantics.getSession().syncRequest(new UniqueRead<Collection<DynamicColoringObject>>() {
+ Pair<Collection<DynamicColoringObject>, Map<String, DynamicColorMap>> result = Simantics.getSession().syncRequest(new UniqueRead<Pair<Collection<DynamicColoringObject>, Map<String, DynamicColorMap>>>() {
@Override
- public Collection<DynamicColoringObject> perform(ReadGraph graph) throws DatabaseException {
- return DynamicVisualisationsContributions.dynamicColoringObjects(graph);
+ public Pair<Collection<DynamicColoringObject>, Map<String, DynamicColorMap>> perform(ReadGraph graph) throws DatabaseException {
+ Map<String, DynamicColorMap> dynamicColorMaps = DynamicVisualisationsContributions.dynamicColorMaps(graph);
+ return Pair.make(DynamicVisualisationsContributions.dynamicColoringObjects(graph), dynamicColorMaps);
}
});
- for (DynamicColoringObject object : result) {
- colorSuppliers.add(createColoringObjectRow(group, object));
+ for (DynamicColoringObject object : result.first) {
+ colorSuppliers.add(createColoringObjectRow(group, object, result.second));
}
} catch (DatabaseException e) {
private final Combo variableCombo;
private final Text minText;
private final Text maxText;
- private final Label unit;
+ private final Text unit;
private final Combo colorMapCombo;
private final Button defaultButton;
- public ColoringObjectRow(Label label, Button usedButton, Combo variableCombo, Text minText, Text maxText, Label unit,
+ public ColoringObjectRow(Label label, Button usedButton, Combo variableCombo, Text minText, Text maxText, Text unit,
Combo colorMapCombo, Button defaultButton) {
super();
this.label = label;
maxText.setText(Double.toString(colorContribution.getDefaultMax()));
unit.setText(colorContribution.getUnit());
- // color map only supports single for now
- colorMapCombo.setItems(colorContribution.getDefaultColorMap().getLabel());
- colorMapCombo.select(0);
-// String[] colorItems = colorMapCombo.getItems();
-// for (int i = 0; i < colorItems.length; i++) {
-//
-// if (colorContribution.getDefaultColorMap().getLabel().equals(colorItems[i])) {
-// colorMapCombo.select(i);
-// break;
-// }
-// }
+ String[] colorItems = colorMapCombo.getItems();
+ for (int i = 0; i < colorItems.length; i++) {
+
+ if (colorContribution.getDefaultColorMap().getLabel().equals(colorItems[i])) {
+ colorMapCombo.select(i);
+ break;
+ }
+ }
usedButton.setSelection(colorContribution.isUsed());
defaultButton.setSelection(colorContribution.isUseDefault());
maxText.setText(Double.toString(sizeContribution.getDefaultMax()));
unit.setText(sizeContribution.getUnit());
- // color map only supports single for now
- sizeMapCombo.setItems(sizeContribution.getDefaultSizeMap().getLabel());
- sizeMapCombo.select(0);
-// String[] colorItems = colorMapCombo.getItems();
-// for (int i = 0; i < colorItems.length; i++) {
-//
-// if (colorContribution.getDefaultColorMap().getLabel().equals(colorItems[i])) {
-// colorMapCombo.select(i);
-// break;
-// }
-// }
+ String[] sizeItems = sizeMapCombo.getItems();
+ for (int i = 0; i < sizeItems.length; i++) {
+ if (sizeContribution.getDefaultSizeMap().getLabel().equals(sizeItems[i])) {
+ sizeMapCombo.select(i);
+ break;
+ }
+ }
usedButton.setSelection(sizeContribution.isUsed());
defaultButton.setSelection(sizeContribution.isUseDefault());
}
}
- private Supplier<Pair<String, DynamicColorContribution>> createColoringObjectRow(Composite parent, DynamicColoringObject object) {
+ private Supplier<Pair<String, DynamicColorContribution>> createColoringObjectRow(Composite parent, DynamicColoringObject object, Map<String, DynamicColorMap> colorMaps) {
Label label = new Label(parent, SWT.NONE);
label.setText(object.getColoringObject().getName());
GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(label);
Text maxText = new Text(parent, SWT.BORDER);
GridDataFactory.fillDefaults().grab(true, false).hint(150, SWT.DEFAULT).align(SWT.CENTER, SWT.CENTER).applyTo(maxText);
- Label unit = new Label(parent, SWT.NONE);
- unit.setText("");
- GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(unit);
+ Text unit = new Text(parent, SWT.READ_ONLY);
+ GridDataFactory.fillDefaults().grab(true, false).align(SWT.CENTER, SWT.CENTER).applyTo(unit);
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()]));
Button defaultButton = new Button(parent, SWT.CHECK);
GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(defaultButton);
maxText.setEnabled(!defaultButton.getSelection());
unit.setText(cont.getUnit());
- colorMapCombo.setItems(cont.getDefaultColorMap().getLabel());
- colorMapCombo.select(0);
+ String[] items = colorMapCombo.getItems();
+ for (int i = 0; i < items.length; i++) {
+ String item = items[i];
+ if (item.equals(cont.getDefaultColorMap().getLabel())) {
+ colorMapCombo.select(i);
+ break;
+ }
+ }
colorMapCombo.setEnabled(!defaultButton.getSelection());
}
}
}
unit.setText(cont.getUnit());
- colorMapCombo.setItems(cont.getDefaultColorMap().getLabel());
- colorMapCombo.select(0);
+ String[] items = colorMapCombo.getItems();
+ for (int i = 0; i < items.length; i++) {
+ String item = items[i];
+ if (item.equals(cont.getDefaultColorMap().getLabel())) {
+ colorMapCombo.select(i);
+ break;
+ }
+ }
defaultButton.setSelection(true);
}
GridDataFactory.fillDefaults().grab(true, false).align(SWT.CENTER, SWT.CENTER).applyTo(label);
}
- private Supplier<Pair<String, DynamicSizeContribution>> createSizingObjectRow(Composite parent, DynamicSizingObject object) {
+ private Supplier<Pair<String, DynamicSizeContribution>> createSizingObjectRow(Composite parent, DynamicSizingObject object, Map<String, DynamicSizeMap> sizeMaps) {
Label label = new Label(parent, SWT.NONE);
label.setText(object.getSizingObject().getName());
GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(label);
GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(maxText);
Label unit = new Label(parent, SWT.NONE);
- unit.setText("");
- GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(unit);
+ GridDataFactory.fillDefaults().grab(true, false).align(SWT.CENTER, SWT.CENTER).applyTo(unit);
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()]));
Button defaultButton = new Button(parent, SWT.CHECK);
GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(defaultButton);
+ defaultButton.addSelectionListener(new SelectionAdapter() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ int index = variableCombo.getSelectionIndex();
+ if (index >= 0) {
+ String key = variableCombo.getItem(index);
+ DynamicSizeContribution cont = sizeContributions.get(key);
+
+ minText.setText(Double.toString(cont.getDefaultMin()));
+ minText.setEnabled(!defaultButton.getSelection());
+ maxText.setText(Double.toString(cont.getDefaultMax()));
+ maxText.setEnabled(!defaultButton.getSelection());
+ unit.setText(cont.getUnit());
+
+ String[] items = sizeMapCombo.getItems();
+ for (int i = 0; i < items.length; i++) {
+ String item = items[i];
+ if (item.equals(cont.getDefaultSizeMap().getLabel())) {
+ sizeMapCombo.select(i);
+ break;
+ }
+ }
+ sizeMapCombo.setEnabled(!defaultButton.getSelection());
+ }
+ }
+ });
variableCombo.addSelectionListener(new SelectionAdapter() {
}
unit.setText(cont.getUnit());
- sizeMapCombo.setItems(cont.getDefaultSizeMap().getLabel());
- sizeMapCombo.select(0);
+ String[] items = sizeMapCombo.getItems();
+ for (int i = 0; i < items.length; i++) {
+ String item = items[i];
+ if (item.equals(cont.getDefaultSizeMap().getLabel())) {
+ sizeMapCombo.select(i);
+ break;
+ }
+ }
defaultButton.setSelection(true);
}
sizeSuppliers = new ArrayList<>();
try {
- Collection<DynamicSizingObject> resultSizing = Simantics.getSession().syncRequest(new UniqueRead<Collection<DynamicSizingObject>>() {
+ Pair<Collection<DynamicSizingObject>, Map<String, DynamicSizeMap>> resultSizing = Simantics.getSession().syncRequest(new UniqueRead<Pair<Collection<DynamicSizingObject>, Map<String, DynamicSizeMap>>>() {
@Override
- public Collection<DynamicSizingObject> perform(ReadGraph graph) throws DatabaseException {
- return DynamicVisualisationsContributions.dynamicSizingObjects(graph);
+ public Pair<Collection<DynamicSizingObject>, Map<String, DynamicSizeMap>> perform(ReadGraph graph) throws DatabaseException {
+ Map<String, DynamicSizeMap> dynamicSizeMaps = DynamicVisualisationsContributions.dynamicSizeMaps(graph);
+ return Pair.make(DynamicVisualisationsContributions.dynamicSizingObjects(graph), dynamicSizeMaps);
}
});
- for (DynamicSizingObject object : resultSizing) {
- sizeSuppliers.add(createSizingObjectRow(parent, object));
+ for (DynamicSizingObject object : resultSizing.first) {
+ sizeSuppliers.add(createSizingObjectRow(parent, object, resultSizing.second));
}
} catch (DatabaseException e) {
LOGGER.error("Could not create object sizes", e);
}
}
- public void setDiagramResource(Resource diagramResource) {
- if (this.diagramResource != diagramResource) {
- this.diagramResource = diagramResource;
+ public void setParentResource(Resource parentResource) {
+ if (this.parentResource != parentResource) {
+ this.parentResource = parentResource;
updateListening();
}
}
if (visualisationsListener != null)
visualisationsListener.dispose();
visualisationsListener = new VisualisationsListener(this);
- Simantics.getSession().asyncRequest(new DynamicVisualisationsRequest(diagramResource), visualisationsListener);
+ Simantics.getSession().asyncRequest(new DynamicVisualisationsRequest(parentResource), visualisationsListener);
if (listener != null)
listener.dispose();
listener = new VisualisationListener(this);
- Simantics.getSession().asyncRequest(new ActiveDynamicVisualisationsRequest(diagramResource), listener);
+ Simantics.getSession().asyncRequest(new ActiveDynamicVisualisationsRequest(parentResource), listener);
}
private static class VisualisationsListener implements Listener<Collection<NamedResource>> {
ColorBarOptions colorOptions = visualisation.getColorBarOptions();
showColorButton.setSelection(colorOptions.isShowColorBars());
colorTicksButton.setSelection(colorOptions.isShowColorBarsTicks());
+ colorGradientButton.setSelection(colorOptions.isUseGradients());
for (int i = 0; i < colorLocationCombo.getItems().length; i++) {
String item = colorLocationCombo.getItem(i);
if (item.equals(colorOptions.getLocation().toString())) {
SizeBarOptions sizeOptions = visualisation.getSizeBarOptions();
showSizeButton.setSelection(sizeOptions.isShowSizeBars());
sizeTicksButton.setSelection(sizeOptions.isShowSizeBarsTicks());
+ sizeGradientButton.setSelection(sizeOptions.isUseGradients());
for (int i = 0; i < sizeLocationCombo.getItems().length; i++) {
String item = sizeLocationCombo.getItem(i);
if (item.equals(sizeOptions.getLocation().toString())) {
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
-import javax.inject.Inject;
-import org.eclipse.e4.ui.model.application.ui.basic.MPart;
-import org.eclipse.e4.ui.workbench.modeling.EPartService;
-import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
-import org.eclipse.e4.ui.workbench.modeling.IPartListener;
import org.eclipse.swt.widgets.Composite;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.internal.e4.compatibility.CompatibilityEditor;
-import org.simantics.district.network.ui.DistrictDiagramEditor;
-import org.simantics.ui.workbench.IResourceEditorInput;
-import org.simantics.utils.ui.workbench.WorkbenchUtils;
+import org.simantics.Simantics;
+import org.simantics.db.AsyncReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.common.procedure.adapter.AsyncListenerAdapter;
+import org.simantics.db.layer0.request.PossibleActiveModel;
public class DynamicVisualisationsView {
- @Inject
- ESelectionService selectionService;
-
- @Inject
- EPartService partService;
-
private DynamicVisualisationsUI ui;
@PostConstruct
public void postConstruct(Composite parent) {
ui = new DynamicVisualisationsUI(parent, 0);
- IEditorPart editor = WorkbenchUtils.getActiveEditor();
- if (editor instanceof DistrictDiagramEditor)
- setDiagramResource(editor.getEditorInput());
-
- partService.addPartListener(partListener);
+ Simantics.getSession().asyncRequest(new PossibleActiveModel(Simantics.getProjectResource()), new AsyncListenerAdapter<Resource>() {
+
+ @Override
+ public void execute(AsyncReadGraph graph, Resource result) {
+ if (ui != null && !ui.isDisposed()) {
+ ui.getDisplay().asyncExec(() -> {
+ ui.setParentResource(result);
+ });
+ }
+ }
+
+ @Override
+ public boolean isDisposed() {
+ return ui != null ? ui.isDisposed() : true;
+ }
+ });
}
@PreDestroy
public void dispose() {
- partService.removePartListener(partListener);
ui.dispose();
ui = null;
}
- private void setDiagramResourceFromCompatibilityEditor(MPart part) {
- if (part.getObject() instanceof CompatibilityEditor) {
- CompatibilityEditor editor = (CompatibilityEditor) part.getObject();
- IEditorPart editorPart = editor.getEditor();
- setDiagramResource(editorPart.getEditorInput());
- }
- }
-
- private void setDiagramResource(IEditorInput input) {
- if (input instanceof IResourceEditorInput) {
- ui.setDiagramResource(((IResourceEditorInput) input).getResource());
- }
- }
-
- private IPartListener partListener = new IPartListener() {
-
- @Override
- public void partVisible(MPart part) {
- setDiagramResourceFromCompatibilityEditor(part);
- }
-
- @Override
- public void partHidden(MPart part) {
- }
-
- @Override
- public void partDeactivated(MPart part) {
- }
-
- @Override
- public void partBroughtToTop(MPart part) {
- setDiagramResourceFromCompatibilityEditor(part);
- }
-
- @Override
- public void partActivated(MPart part) {
- setDiagramResourceFromCompatibilityEditor(part);
- }
- };
}
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.UUID;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.simantics.db.exception.ManyObjectsForFunctionalRelationException;
import org.simantics.db.exception.ServiceException;
import org.simantics.db.indexing.IndexUtils;
+import org.simantics.db.layer0.QueryIndexUtils;
import org.simantics.db.layer0.request.PossibleVariable;
import org.simantics.db.layer0.variable.Variable;
import org.simantics.diagram.stubs.DiagramResource;
String colorBarSize = graph.getPossibleRelatedValue(visualisation, DN.Diagram_Visualisations_ColorBarSize, Bindings.STRING);
Boolean show = graph.getPossibleRelatedValue(visualisation, DN.Diagram_Visualisations_ShowColorBars, Bindings.BOOLEAN);
Boolean showTicks = graph.getPossibleRelatedValue(visualisation, DN.Diagram_Visualisations_ShowColorBarTicks, Bindings.BOOLEAN);
+ Boolean useGradients = graph.getPossibleRelatedValue(visualisation, DN.Diagram_Visualisations_UseColorBarGradients, Bindings.BOOLEAN);
if (colorBarLocation != null) {
return new ColorBarOptions()
.showColorBars(show != null ? show : false)
.showColorBarsTicks(showTicks != null ? showTicks : false)
+ .useGradients(useGradients != null ? useGradients : false)
.withLocation(ColorBarsLocation.valueOf(colorBarLocation))
.withSize(ColorBarsSize.valueOf(colorBarSize));
}
graph.claimLiteral(visualisation, DN.Diagram_Visualisations_ColorBarSize, options.getSize().toString(), Bindings.STRING);
graph.claimLiteral(visualisation, DN.Diagram_Visualisations_ShowColorBars, options.isShowColorBars(), Bindings.BOOLEAN);
graph.claimLiteral(visualisation, DN.Diagram_Visualisations_ShowColorBarTicks, options.isShowColorBarsTicks(), Bindings.BOOLEAN);
+ graph.claimLiteral(visualisation, DN.Diagram_Visualisations_UseColorBarGradients, options.isUseGradients(), Bindings.BOOLEAN);
}
- public static Resource createVisualisation(WriteGraph graph, Resource diagram, String visualisationName) throws DatabaseException {
+ public static Resource createVisualisation(WriteGraph graph, Resource parent, String visualisationName) throws DatabaseException {
+ Resource vf = getOrCreateVisualisationsFolder(graph, parent);
Layer0 L0 = Layer0.getInstance(graph);
DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
Resource visualisation = graph.newResource();
graph.claim(visualisation, L0.InstanceOf, DN.Diagram_Visualisations);
graph.claimLiteral(visualisation, L0.HasName, visualisationName);
- graph.claim(diagram, DN.Diagram_hasVisualisation, visualisation);
+ graph.claim(vf, DN.Diagram_hasVisualisation, visualisation);
return visualisation;
}
+ public static Resource getOrCreateVisualisationsFolder(WriteGraph graph, Resource model) throws DatabaseException {
+ Resource rf = getVisualisationFolder(graph, model);
+ if (rf == null) {
+ Layer0 L0 = Layer0.getInstance(graph);
+ DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
+ rf = graph.newResource();
+ graph.claim(rf, L0.InstanceOf, null, DN.VisualisationsFolder);
+ graph.claimLiteral(rf, L0.HasName, L0.NameOf, L0.String, UUID.randomUUID().toString(), Bindings.STRING);
+ graph.claim(model, L0.ConsistsOf, L0.PartOf, rf);
+ }
+ return rf;
+ }
+
+ public static Resource getVisualisationFolder(ReadGraph graph, Resource model) throws DatabaseException {
+ List<Resource> visualisationsFolders = QueryIndexUtils.searchByType(graph, model, DistrictNetworkResource.getInstance(graph).VisualisationsFolder);
+ if (visualisationsFolders.size() > 0)
+ return visualisationsFolders.get(0);
+ return null;
+ }
+
public static SizeBarOptions sizeBarOptions(ReadGraph graph, Resource visualisation) throws DatabaseException {
DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
if (visualisation != null) {
String sizeBarSize = graph.getPossibleRelatedValue(visualisation, DN.Diagram_Visualisations_SizeBarSize, Bindings.STRING);
Boolean show = graph.getPossibleRelatedValue(visualisation, DN.Diagram_Visualisations_ShowSizeBars, Bindings.BOOLEAN);
Boolean showTicks = graph.getPossibleRelatedValue(visualisation, DN.Diagram_Visualisations_ShowSizeBarTicks, Bindings.BOOLEAN);
+ Boolean useGradients = graph.getPossibleRelatedValue(visualisation, DN.Diagram_Visualisations_UseSizeBarGradients, Bindings.BOOLEAN);
if (sizeBarLocation != null) {
return new SizeBarOptions()
.showSizeBars(show != null ? show : false)
.showSizeBarsTicks(showTicks != null ? showTicks : false)
+ .useGradients(useGradients != null ? useGradients : false)
.withLocation(SizeBarsLocation.valueOf(sizeBarLocation))
.withSize(SizeBarsSize.valueOf(sizeBarSize));
}
graph.claimLiteral(visualisation, DN.Diagram_Visualisations_SizeBarSize, options.getSize().toString(), Bindings.STRING);
graph.claimLiteral(visualisation, DN.Diagram_Visualisations_ShowSizeBars, options.isShowSizeBars(), Bindings.BOOLEAN);
graph.claimLiteral(visualisation, DN.Diagram_Visualisations_ShowSizeBarTicks, options.isShowSizeBarsTicks(), Bindings.BOOLEAN);
+ graph.claimLiteral(visualisation, DN.Diagram_Visualisations_UseSizeBarGradients, options.isUseGradients(), Bindings.BOOLEAN);
}
public static Map<String, DynamicColorContribution> colorContributions(ReadGraph graph, Resource visualisation) throws DatabaseException {
*/
public class ActiveDynamicVisualisationsRequest extends ResourceRead<DynamicVisualisation> {
- public ActiveDynamicVisualisationsRequest(Resource diagram) {
- super(diagram);
+ public ActiveDynamicVisualisationsRequest(Resource parent) {
+ super(parent);
}
@Override
public DynamicVisualisation perform(ReadGraph graph) throws DatabaseException {
DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
- Resource visualisationResource = graph.getPossibleObject(resource, DN.Diagram_hasActiveVisualisation);
- if (visualisationResource != null) {
- String name = graph.getRelatedValue(visualisationResource, Layer0.getInstance(graph).HasName);
- Map<String, DynamicColorContribution> colorContributions = DistrictNetworkUtil.colorContributions(graph, visualisationResource);
- ColorBarOptions colorBarOptions = DistrictNetworkUtil.colorBarOptions(graph, visualisationResource);
- Map<String, DynamicSizeContribution> sizeContributions = DistrictNetworkUtil.sizeContributions(graph, visualisationResource);
- SizeBarOptions sizeBarOptions = DistrictNetworkUtil.sizeBarOptions(graph, visualisationResource);
- DynamicVisualisation visualisation = new DynamicVisualisation(name, visualisationResource, colorContributions, colorBarOptions, sizeContributions, sizeBarOptions);
- return visualisation;
+ Resource visualisationFolder = DistrictNetworkUtil.getVisualisationFolder(graph, resource);
+ if (visualisationFolder != null) {
+ Resource visualisationResource = graph.getPossibleObject(visualisationFolder, DN.Diagram_hasActiveVisualisation);
+ if (visualisationResource != null) {
+ String name = graph.getRelatedValue(visualisationResource, Layer0.getInstance(graph).HasName);
+ Map<String, DynamicColorContribution> colorContributions = DistrictNetworkUtil.colorContributions(graph, visualisationResource);
+ ColorBarOptions colorBarOptions = DistrictNetworkUtil.colorBarOptions(graph, visualisationResource);
+ Map<String, DynamicSizeContribution> sizeContributions = DistrictNetworkUtil.sizeContributions(graph, visualisationResource);
+ SizeBarOptions sizeBarOptions = DistrictNetworkUtil.sizeBarOptions(graph, visualisationResource);
+ DynamicVisualisation visualisation = new DynamicVisualisation(name, visualisationResource, colorContributions, colorBarOptions, sizeContributions, sizeBarOptions);
+ return visualisation;
+ }
}
return null;
}
// 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, dcc.getDefaultMin(), dcc.getDefaultMax());
+ Color color = defaultColorMap.getColor(adjustedValue, dv.getColorBarOptions().isUseGradients(), dcc.getDefaultMin(), dcc.getDefaultMax());
return color;
} else {
LOGGER.warn("No value for {}", attribute.getURI(graph));
// 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, dsc.getDefaultMin(), dsc.getDefaultMax());
+ double size = defaultSizeMap.getSize(adjustedValue, dv.getSizeBarOptions().isUseGradients(), dsc.getDefaultMin(), dsc.getDefaultMax());
return size;
} else {
LOGGER.warn("No value for {}", attribute.getURI(graph));
import org.simantics.db.common.NamedResource;
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.layer0.Layer0;
*/
public class DynamicVisualisationsRequest extends ResourceRead<Collection<NamedResource>> {
- public DynamicVisualisationsRequest(Resource diagram) {
- super(diagram);
+ public DynamicVisualisationsRequest(Resource parent) {
+ super(parent);
}
@Override
public Collection<NamedResource> perform(ReadGraph graph) throws DatabaseException {
DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
- Collection<Resource> visualisationResources = graph.getObjects(resource, DN.Diagram_hasVisualisation);
List<NamedResource> results = new ArrayList<>();
- if (visualisationResources != null && !visualisationResources.isEmpty()) {
- for (Resource visualisationResource : visualisationResources) {
- String name = graph.getRelatedValue(visualisationResource, Layer0.getInstance(graph).HasName);
- results.add(new NamedResource(name, visualisationResource));
+ Resource visualisationFolder = DistrictNetworkUtil.getVisualisationFolder(graph, resource);
+ if (visualisationFolder != null) {
+ Collection<Resource> visualisationResources = graph.getObjects(visualisationFolder, DN.Diagram_hasVisualisation);
+ if (visualisationResources != null && !visualisationResources.isEmpty()) {
+ for (Resource visualisationResource : visualisationResources) {
+ String name = graph.getRelatedValue(visualisationResource, Layer0.getInstance(graph).HasName);
+ results.add(new NamedResource(name, visualisationResource));
+ }
}
}
return results;
import org.simantics.db.ReadGraph;
import org.simantics.db.Resource;
import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener;
+import org.simantics.db.common.request.IndexRoot;
import org.simantics.db.common.request.ResourceRead;
import org.simantics.db.exception.DatabaseException;
import org.simantics.diagram.stubs.DiagramResource;
DiagramResource DIA = DiagramResource.getInstance(graph);
Resource diagram = graph.getPossibleObject(resource, DIA.RuntimeDiagram_HasConfiguration);
if (diagram != null) {
- return graph.syncRequest(new ActiveDynamicVisualisationsRequest(diagram), TransientCacheAsyncListener.instance());
+ Resource model = graph.syncRequest(new IndexRoot(diagram));
+ return graph.syncRequest(new ActiveDynamicVisualisationsRequest(model), TransientCacheAsyncListener.instance());
}
return null;
}
@Override
public final void applyStyleForNode(EvaluationContext evaluationContext, INode node, Optional<Result> result) {
- if (!Optional.empty().equals(result)) {
+ if (!Optional.empty().equals(result) && result != null) {
applyThrottledStyleForNode(evaluationContext, node, result.get());
} else {
LOGGER.debug("Do not apply as results are unchanged for {} {} {}", evaluationContext, node, result);
package org.simantics.district.network.visualisations.model;
import java.awt.Color;
-import java.util.Arrays;
import java.util.List;
public class DynamicColorMap {
- static List<RGBIntensity> blues = Arrays.asList(new RGBIntensity(0, 0, 0.1), new RGBIntensity(0, 0, 0.5), new RGBIntensity(0, 0, 0.9));
-
- public static final DynamicColorMap DEFAULT = new DynamicColorMap("default", blues);
-
private String label;
private List<RGBIntensity> intensities;
}
}
- public Color getColor(double value, double defaultMin, double defaultMax) {
+ public Color getColor(double value, boolean useGradient, double defaultMin, double defaultMax) {
+ List<RGBIntensity> intensities = getIntensities();
double gap = defaultMax - defaultMin;
- double singleGap = gap / getIntensities().size();
+ double singleGap = gap / intensities.size();
+ double threshold = defaultMin;
int i = 0;
- while (i < getIntensities().size() - 1) {
- if (value <= defaultMin + (i * singleGap)) {
+ while (i < intensities.size() - 1) {
+ threshold = threshold + singleGap;
+ if (value <= threshold) {
break;
}
i++;
}
- RGBIntensity intensity = getIntensities().get(i);
- return new Color((float)intensity.getRed(), (float)intensity.getGreen(), (float)intensity.getBlue());
+ RGBIntensity intensity = intensities.get(i);
+ if (useGradient) {
+
+ RGBIntensity upperLimitIntensity;
+ if (i + 1 != intensities.size())
+ upperLimitIntensity = intensities.get(i + 1);
+ else
+ upperLimitIntensity = intensity;
+
+ double minRed = intensity.getRed();
+ double minGreen = intensity.getGreen();
+ double minBlue = intensity.getBlue();
+
+ double maxRed = upperLimitIntensity.getRed();
+ double maxGreen = upperLimitIntensity.getGreen();
+ double maxBlue = upperLimitIntensity.getBlue();
+
+ double delta = Math.max(value - (defaultMin + singleGap * i), 0);
+
+ double d = delta / singleGap;
+
+ double redDelta = (maxRed - minRed) * d;
+ double greenDelta = (maxGreen - minGreen) * d;
+ double blueDelta = (maxBlue - minBlue) * d;
+ return new Color((float)(minRed + redDelta), (float)(minGreen + greenDelta), (float)(minBlue + blueDelta));
+ } else {
+ return new Color((float)intensity.getRed(), (float)intensity.getGreen(), (float)intensity.getBlue());
+ }
}
}
return sizes;
}
- public double getSize(double value, double defaultMin, double defaultMax) {
+ public double getSize(double value, boolean useGradient, double defaultMin, double defaultMax) {
+ List<Double> sizes = getSizes();
double gap = defaultMax - defaultMin;
- double singleGap = gap / getSizes().size();
+ double singleGap = gap / sizes.size();
+ double threshold = defaultMin;
int i = 0;
- while (i < getSizes().size() - 1) {
- if (value <= defaultMin + (i * singleGap)) {
+ while (i < sizes.size() - 1) {
+ threshold = threshold + singleGap;
+ if (value <= threshold) {
break;
}
i++;
}
- return getSizes().get(i);
+ Double size = sizes.get(i);
+ if (useGradient) {
+
+ Double upperSize;
+ if (i + 1 != sizes.size()) {
+ upperSize = sizes.get(i + 1);
+ } else {
+ upperSize = size;
+ }
+
+ double delta = Math.max(value - (defaultMin + singleGap * i), 0);
+ double d = delta / singleGap;
+ double sizeDelta = (upperSize - size) * d;
+
+ return size + sizeDelta;
+ }
+
+ return size;
}
}