Skip to content

Commit

Permalink
copy properties to the SModel already during initial SModel generation
Browse files Browse the repository at this point in the history
for client-only layout.
  • Loading branch information
NiklasRentzCAU committed Sep 28, 2024
1 parent 85cedde commit 5277008
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import org.eclipse.sprotty.SPort
import org.eclipse.sprotty.xtext.IDiagramGenerator
import org.eclipse.xtend.lib.annotations.Accessors
import org.eclipse.xtext.util.CancelIndicator
import de.cau.cs.kieler.klighd.lsp.utils.KGraphMappingUtil

/**
* A diagram generator that can create Sprotty {@link SGraph} from any {@link Object} that has a registered view
Expand Down Expand Up @@ -259,6 +260,7 @@ class KGraphDiagramGenerator implements IDiagramGenerator {
nodeElement.data = node.data.filter[KRenderingLibrary.isAssignableFrom(it.class)].toList

setProperties(nodeElement, node)
KGraphMappingUtil.mapProperties(node, nodeElement)
findSpecialRenderings(filteredData)

val renderingContextData = RenderingContextData.get(node)
Expand Down Expand Up @@ -311,6 +313,7 @@ class KGraphDiagramGenerator implements IDiagramGenerator {

val renderings = edge.data.filter[KRendering.isAssignableFrom(it.class)].toList

KGraphMappingUtil.mapProperties(edge, edgeElement)
findSpecialRenderings(renderings)
edgeElement.children.addAll(createLabels(edge.labels))
edgeElement.junctionPoints = edge.getProperty(CoreOptions.JUNCTION_POINTS)
Expand All @@ -332,6 +335,7 @@ class KGraphDiagramGenerator implements IDiagramGenerator {

val renderings = port.data.filter [ KRendering.isAssignableFrom(it.class)].toList

KGraphMappingUtil.mapProperties(port, portElement)
findSpecialRenderings(renderings)
portElement.children.addAll(createLabels(port.labels))

Expand All @@ -353,6 +357,7 @@ class KGraphDiagramGenerator implements IDiagramGenerator {

val renderings = label.data.filter[KRendering.isAssignableFrom(it.class)].toList

KGraphMappingUtil.mapProperties(label, labelElement)
findSpecialRenderings(renderings)
// activate the element by default if it does not have an active/inactive status yet.
val renderingContextData = RenderingContextData.get(label)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* http://rtsys.informatik.uni-kiel.de/kieler
*
* Copyright 2018-2022 by
* Copyright 2018-2024 by
* + Kiel University
* + Department of Computer Science
* + Real-Time and Embedded Systems Group
Expand Down Expand Up @@ -39,6 +39,7 @@ abstract interface SKElement {
def List<KGraphData> getData()
def void setData(List<KGraphData> data)
def HashMap<String, Object> getProperties()
def void setProperties(HashMap<String, Object> theProperties)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import de.cau.cs.kieler.klighd.kgraph.KLabel
import de.cau.cs.kieler.klighd.kgraph.KNode
import de.cau.cs.kieler.klighd.kgraph.KPort
import de.cau.cs.kieler.klighd.kgraph.KShapeLayout
import de.cau.cs.kieler.klighd.kgraph.util.KGraphUtil
import de.cau.cs.kieler.klighd.lsp.model.SKEdge
import de.cau.cs.kieler.klighd.lsp.model.SKElement
import de.cau.cs.kieler.klighd.lsp.model.SKLabel
Expand All @@ -39,7 +40,6 @@ import org.eclipse.sprotty.Dimension
import org.eclipse.sprotty.Point
import org.eclipse.sprotty.SModelElement
import org.eclipse.sprotty.SShapeElement
import de.cau.cs.kieler.klighd.kgraph.util.KGraphUtil

/**
* A helper class containing static methods for mapping of KGraph and SGraph bounds.
Expand Down Expand Up @@ -108,15 +108,7 @@ class KGraphMappingUtil {
skEdge.junctionPoints.addAllAsCopies(0, kEdge.getProperty(CoreOptions.JUNCTION_POINTS))
skEdge.junctionPoints.offset(new KVector(leftInset, topInset))

// map all properties excepts those that are blacklisted
// also include external whitelisted properties
var properties = kEdge.allProperties;

for (propertyKVPair : properties.entrySet()) {
if (keepProperty(propertyKVPair.key)) {
skEdge.properties.put(propertyKVPair.key.id, propertyKVPair.value)
}
}
mapProperties(kEdge, skEdge)
}

/**
Expand All @@ -138,11 +130,19 @@ class KGraphMappingUtil {
skNode.position = new Point(kNode.xpos + leftInset, kNode.ypos + topInset)
skNode.size = new Dimension(kNode.width, kNode.height)

var properties = kNode.allProperties;
mapProperties(kNode, skNode)
}

/**
* Maps the properties of the KGraphElement to the corresponding SModelElement.
* Excepts those that are blacklisted, but also include whitelisted external properties.
*/
static def mapProperties(KGraphElement kElement, SKElement sElement) {
val properties = kElement.allProperties

for (propertyKVPair : properties.entrySet()) {
if (keepProperty(propertyKVPair.key)) {
skNode.properties.put(propertyKVPair.key.id, propertyKVPair.value)
sElement.properties.put(propertyKVPair.key.id, propertyKVPair.value)
}
}
}
Expand Down

0 comments on commit 5277008

Please sign in to comment.