diff --git a/plugins/de.cau.cs.kieler.klighd.lsp/src/de/cau/cs/kieler/klighd/lsp/interactive/InteractiveUtil.xtend b/plugins/de.cau.cs.kieler.klighd.lsp/src/de/cau/cs/kieler/klighd/lsp/interactive/InteractiveUtil.xtend index 91a3c5786..16b30a04f 100644 --- a/plugins/de.cau.cs.kieler.klighd.lsp/src/de/cau/cs/kieler/klighd/lsp/interactive/InteractiveUtil.xtend +++ b/plugins/de.cau.cs.kieler.klighd.lsp/src/de/cau/cs/kieler/klighd/lsp/interactive/InteractiveUtil.xtend @@ -18,6 +18,7 @@ package de.cau.cs.kieler.klighd.lsp.interactive import de.cau.cs.kieler.klighd.KlighdDataManager import de.cau.cs.kieler.klighd.internal.util.KlighdInternalProperties +import de.cau.cs.kieler.klighd.kgraph.KIdentifier import de.cau.cs.kieler.klighd.kgraph.KNode import de.cau.cs.kieler.klighd.lsp.KGraphLanguageClient import de.cau.cs.kieler.klighd.lsp.KGraphLanguageServerExtension @@ -115,8 +116,8 @@ class InteractiveUtil { // from node to the start for (var i = pos - 1; i >= 0; i--) { - if (layerNodes.get(i).getProperty(LayeredOptions.CROSSING_MINIMIZATION_IN_LAYER_PRED_OF) !== null - || layerNodes.get(i + 1).getProperty(LayeredOptions.CROSSING_MINIMIZATION_IN_LAYER_SUCC_OF) !== null) { + if (layerNodes.get(i).getProperty(LayeredOptions.CROSSING_MINIMIZATION_IN_LAYER_PRED_OF) == getIdOfNode(layerNodes.get(i + 1)) + || layerNodes.get(i + 1).getProperty(LayeredOptions.CROSSING_MINIMIZATION_IN_LAYER_SUCC_OF) == getIdOfNode(layerNodes.get(i))) { chainNodes.add(0, layerNodes.get(i)) } else { i = -1 @@ -125,8 +126,8 @@ class InteractiveUtil { // count from node to the end for (var i = pos + 1; i < layerNodes.size; i++) { - if (layerNodes.get(i).getProperty(LayeredOptions.CROSSING_MINIMIZATION_IN_LAYER_SUCC_OF) !== null - || layerNodes.get(i - 1).getProperty(LayeredOptions.CROSSING_MINIMIZATION_IN_LAYER_PRED_OF) !== null) { + if (layerNodes.get(i).getProperty(LayeredOptions.CROSSING_MINIMIZATION_IN_LAYER_SUCC_OF) == getIdOfNode(layerNodes.get(i - 1)) + || layerNodes.get(i - 1).getProperty(LayeredOptions.CROSSING_MINIMIZATION_IN_LAYER_PRED_OF) == getIdOfNode(layerNodes.get(i))) { chainNodes.add(layerNodes.get(i)) } else { i = layerNodes.size @@ -195,4 +196,19 @@ class InteractiveUtil { return } + /** + * Returns id of a node. + * + * @param node The node. + * @returns The id string of the node. + */ + static def String getIdOfNode(KNode node) { + var nameStringOfReferenceNode = node.toString + val id = node.getData(KIdentifier) + if (id !== null) { + nameStringOfReferenceNode = id.id + } + return nameStringOfReferenceNode + } + } \ No newline at end of file diff --git a/plugins/de.cau.cs.kieler.klighd.lsp/src/de/cau/cs/kieler/klighd/lsp/interactive/layered/LayeredConstraintReevaluation.xtend b/plugins/de.cau.cs.kieler.klighd.lsp/src/de/cau/cs/kieler/klighd/lsp/interactive/layered/LayeredConstraintReevaluation.xtend index 20873ad00..32a7ad6e0 100644 --- a/plugins/de.cau.cs.kieler.klighd.lsp/src/de/cau/cs/kieler/klighd/lsp/interactive/layered/LayeredConstraintReevaluation.xtend +++ b/plugins/de.cau.cs.kieler.klighd.lsp/src/de/cau/cs/kieler/klighd/lsp/interactive/layered/LayeredConstraintReevaluation.xtend @@ -116,6 +116,7 @@ class LayeredConstraintReevaluation { val layerConstraintTarget = ConstraintsUtils.getLayerConstraint(target) val layerId = target.getProperty(LayeredOptions.LAYERING_LAYER_ID) var originalLayerIndex = 0 + // Calculate previous desired layer of target. if (layerConstraintTarget === null || layerConstraintTarget <= layerId) { originalLayerIndex = layerId } else { @@ -123,7 +124,7 @@ class LayeredConstraintReevaluation { } val originalLayer = InteractiveUtil.getNodesOfLayer(originalLayerIndex, nodes) - if (originalLayer.length == 1) { + if (originalLayer.length == InteractiveUtil.getChain(target, originalLayer).size()) { // If a layer is emptied and disappears from the drawing // then all layer constraint with a value higher or equal than // the disappeared layer need to be decremented. diff --git a/plugins/de.cau.cs.kieler.klighd.lsp/src/de/cau/cs/kieler/klighd/lsp/interactive/layered/LayeredInteractiveLanguageServerExtension.xtend b/plugins/de.cau.cs.kieler.klighd.lsp/src/de/cau/cs/kieler/klighd/lsp/interactive/layered/LayeredInteractiveLanguageServerExtension.xtend index 36c11357f..56f874a0d 100644 --- a/plugins/de.cau.cs.kieler.klighd.lsp/src/de/cau/cs/kieler/klighd/lsp/interactive/layered/LayeredInteractiveLanguageServerExtension.xtend +++ b/plugins/de.cau.cs.kieler.klighd.lsp/src/de/cau/cs/kieler/klighd/lsp/interactive/layered/LayeredInteractiveLanguageServerExtension.xtend @@ -217,6 +217,15 @@ class LayeredInteractiveLanguageServerExtension implements ILanguageServerExtens val changedNodes = absoluteConstraintReevaluation.changedNodes changedNodes.addAll(relativeConstraintReevaluation.changedNodes) changedNodes.add(new ConstraintProperty(targetNode, property, nameStringOfReferenceNode)) + if (layerSwap) { + // Already apply changes to be able to correctly identify if a chain is split because of the new + // relative constraint. + changedNodes.forEach[constraint| + val KNode kNode = constraint.KNode + kNode.setProperty(constraint.property, constraint.value) + ] + absoluteConstraintReevaluation.reevaluateAfterEmptyingALayer(targetNode, referenceLayer, parentOfNode.children) + } refreshModelInEditor(changedNodes, KGraphUtil.getRootNodeOf(targetNode), uri) } } @@ -458,8 +467,12 @@ class LayeredInteractiveLanguageServerExtension implements ILanguageServerExtens absoluteConstraintReevalution.reevaluatePositionConstraintsAfterPositionChangeInLayer(layerNodes, kNode, newValueId) absoluteConstraintReevalution.reevaluatePositionConstraintInChain(kNode, newValueConstraint, chain) } - case LayeredOptions.LAYERING_LAYER_CHOICE_CONSTRAINT: + case LayeredOptions.LAYERING_LAYER_CHOICE_CONSTRAINT: { absoluteConstraintReevalution.reevaluateLayerConstraintsInChain(layerId, chain) + if (absoluteConstraintReevalution.reevaluateAfterEmptyingALayer(kNode, newValueConstraint, parentOfNode.children)) { + newValueConstraint-- + } + } } changedNodes.addAll(absoluteConstraintReevalution.changedNodes)