+
+ private void showSaveVisualisationTemplateDialog(Shell shell) {
+
+ InputDialog dialog = new InputDialog(shell, "Save visualisation template", "Give template a name", "", new IInputValidator() {
+
+ @Override
+ public String isValid(String newText) {
+ if (newText == null || newText.isEmpty())
+ return "Name cannot be empty";
+ return null;
+ }
+ });
+
+ if (dialog.open() == Dialog.OK) {
+ String name = dialog.getValue();
+ try {
+ persistVisualisationTemplate(name, Optional.empty());
+ } catch (Exception e) {
+ LOGGER.error("Could not persist visualisation template", e);
+ ShowError.showError("Could not persist visualisation template", e.getMessage(), e);
+ }
+ }
+ }
+
+ private void persistCurrentVisualisationTemplateIfAvailable() {
+ if (visualisation != null) {
+ 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 {
+ LOGGER.info("No current visualisation template selected for saving");
+ }
+ }
+
+ private void persistVisualisationTemplate(String templateName, Optional<Resource> existing) throws Exception {
+
+ List<Pair<String, DynamicColorContribution>> colorCollect = colorSuppliers.stream().filter(Objects::nonNull).map(s -> s.get()).filter(Objects::nonNull).collect(Collectors.toList());
+
+ String colorLocation = colorLocationCombo.getItem(colorLocationCombo.getSelectionIndex());
+ String colorSize = colorSizeCombo.getItem(colorSizeCombo.getSelectionIndex());
+
+ ColorBarOptions colorBarOptions = new ColorBarOptions()
+ .showColorBars(showColorButton.getSelection())
+ .showColorBarsTicks(colorTicksButton.getSelection())
+ .useGradients(colorGradientButton.getSelection())
+ .withLocation(ColorBarsLocation.valueOf(colorLocation))
+ .withSize(ColorBarsSize.valueOf(colorSize));
+
+ List<Pair<String, DynamicSizeContribution>> sizeCollect = sizeSuppliers.stream().filter(Objects::nonNull).map(s -> s.get()).filter(Objects::nonNull).collect(Collectors.toList());
+
+ String sizeLocation = sizeLocationCombo.getItem(sizeLocationCombo.getSelectionIndex());
+ String sizeSize = sizeSizeCombo.getItem(sizeSizeCombo.getSelectionIndex());
+
+ final SizeBarOptions sizeBarOptions = new SizeBarOptions()
+ .showSizeBars(showSizeButton.getSelection())
+ .showSizeBarsTicks(sizeTicksButton.getSelection())
+ .useGradients(sizeGradientButton.getSelection())
+ .withLocation(SizeBarsLocation.valueOf(sizeLocation))
+ .withSize(SizeBarsSize.valueOf(sizeSize));
+
+ List<Pair<String, DynamicArrowContribution>> edgeArrowCollect = edgeArrowSuppliers.stream().filter(Objects::nonNull).map(s -> s.get()).filter(Objects::nonNull).collect(Collectors.toList());
+
+ boolean hideEdges = hideEdgesButton.getSelection();
+ boolean hidePoints = hidePointsButton.getSelection();
+ boolean hideConsumers = hideConsumersButton.getSelection();
+ boolean hideProducers = hideProducersButton.getSelection();
+ boolean hideValves = hideValvesButton.getSelection();
+ boolean hidePumpingStations = hidePumpingStationsButton.getSelection();
+
+ boolean networkBranchesStaticProperties = networkBranchesStaticPropertiesButton.getSelection();
+ boolean pointsStaticProperties = pointsStaticPropertiesButton.getSelection();
+ boolean consumersStaticProperties = consumersStaticPropertiesButton.getSelection();
+
+ boolean dynamicSymbolsEdges = dynamicSymbolsEdgesButton.getSelection();
+ boolean dynamicSymbolsProducers = dynamicSymbolsProducersButton.getSelection();
+ boolean dynamicSymbolsValves = dynamicSymbolsValvesButton.getSelection();
+ boolean dynamicSymbolsPumpingStations = dynamicSymbolsPumpingStationsButton.getSelection();
+
+ boolean disabled = disableUpdatesButton.getSelection();
+ boolean resetVisualisation = resetVisualisationButton.getSelection();
+ Long interval;
+ try {
+ // inteval is in milliseconds but shown as seconds
+
+ interval = (long)(Double.parseDouble(intervalText.getText()) * 1000);
+ } catch (NumberFormatException e) {
+ // ignore
+ interval = 2000L;
+ }
+ final long finalInterval = interval;
+
+ boolean hoverVertex = hoveringVertexEnabledButton.getSelection();
+ boolean hoverEdges = hoveringEdgesEnabledButton.getSelection();
+
+ boolean elevationServerBoundingBox = elevationServerEnabledButton.getSelection();
+ boolean notInSimulation = notInSimulationButton.getSelection();
+ boolean showConnectedComponents = showConnectedComponentsButton.getSelection();
+
+ Simantics.getSession().asyncRequest(new WriteRequest() {
+
+ @Override
+ public void perform(WriteGraph graph) throws DatabaseException {
+ Resource exist;
+ if (existing.isPresent()) {
+ exist = existing.get();
+ } else {
+ exist = DynamicVisualisations.createVisualisation(graph, parentResource, templateName);
+ }
+ DynamicVisualisations.setIntervalAndDisabled(graph, exist, finalInterval, disabled, resetVisualisation);
+ DynamicVisualisations.setColorContributions(graph, exist, colorCollect);
+ DynamicVisualisations.setColorBarOptions(graph, exist, colorBarOptions);
+ DynamicVisualisations.setSizeContributions(graph, exist, sizeCollect);
+ DynamicVisualisations.setSizeBarOptions(graph, exist, sizeBarOptions);
+ DynamicVisualisations.setEdgeArrowContributions(graph, exist, edgeArrowCollect);
+ DynamicVisualisations.setHideElements(graph, exist,
+ hideEdges,
+ hidePoints,
+ hideConsumers,
+ hideProducers,
+ hideValves,
+ hidePumpingStations
+ );
+
+ DynamicVisualisations.setStaticProperties(graph, exist,
+ networkBranchesStaticProperties,
+ pointsStaticProperties,
+ consumersStaticProperties
+ );
+
+ DynamicVisualisations.setDynamicSymbols(graph, exist,
+ dynamicSymbolsEdges,
+ dynamicSymbolsProducers,
+ dynamicSymbolsValves,
+ dynamicSymbolsPumpingStations
+ );
+ DynamicVisualisations.setKeyVariablesHover(graph, exist, hoverVertex, hoverEdges);
+
+ DynamicVisualisations.setElevationServerBoundingBox(graph, exist, elevationServerBoundingBox);
+ DynamicVisualisations.setNotInSimulation(graph, exist, notInSimulation);
+ DynamicVisualisations.setShowConnectedComponents(graph, exist, showConnectedComponents);
+ }
+ });
+ }
+
+ private void initializeColoringObjects(Composite parent) {
+ Group group = new Group(parent, SWT.NONE);
+ group.setText("Coloring Objects");
+ GridDataFactory.fillDefaults().grab(true, false).applyTo(group);
+ GridLayoutFactory.fillDefaults().numColumns(8).margins(5, 5).applyTo(group);
+
+ {
+ createColoringObjectHeaderRow(group);
+ }
+ colorSuppliers = new ArrayList<>();
+ {
+ try {
+ Pair<Collection<DynamicColoringObject>, Map<String, DynamicColorMap>> result = Simantics.getSession().syncRequest(new UniqueRead<Pair<Collection<DynamicColoringObject>, Map<String, DynamicColorMap>>>() {
+
+ @Override
+ 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.first) {
+ colorSuppliers.add(createColoringObjectRow(group, object, result.second));
+ }
+
+ } catch (DatabaseException e) {
+ LOGGER.error("Could not create coloring objecst", e);
+ }
+ }
+ }