Skip to content

Commit

Permalink
Merge pull request #73 from kieler/sdo/interactiveMrTree
Browse files Browse the repository at this point in the history
Add MrTree LS extension and configuration.
  • Loading branch information
a-sr authored May 7, 2024
2 parents 03c832a + 98d54fe commit b33a6b1
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
de.cau.cs.kieler.language.server.sccharts.SCTXConstraintSerializer
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package de.cau.cs.kieler.language.server
import de.cau.cs.kieler.core.services.KielerServiceLoader
import de.cau.cs.kieler.klighd.lsp.KGraphLanguageClient
import de.cau.cs.kieler.klighd.lsp.interactive.layered.LayeredInteractiveLanguageServerExtension
import de.cau.cs.kieler.klighd.lsp.interactive.mrtree.MrTreeInteractiveLanguageServerExtension
import de.cau.cs.kieler.klighd.lsp.interactive.rectpacking.RectpackingInteractiveLanguageServerExtension
import de.cau.cs.kieler.klighd.lsp.launch.AbstractLsCreator
import java.util.List
Expand All @@ -32,14 +33,17 @@ class LSCreator extends AbstractLsCreator {

RectpackingInteractiveLanguageServerExtension rectPack

MrTreeInteractiveLanguageServerExtension mrTree

List<ILSDiagramHighlighter> diagramHighlighters

List<ILanguageServerExtension> iLanguageServerExtensions

override getLanguageServerExtensions() {
constraints = injector.getInstance(LayeredInteractiveLanguageServerExtension)
rectPack = injector.getInstance(RectpackingInteractiveLanguageServerExtension)
iLanguageServerExtensions = newArrayList(constraints, rectPack)
mrTree = injector.getInstance(MrTreeInteractiveLanguageServerExtension)
iLanguageServerExtensions = newArrayList(constraints, rectPack, mrTree)
for (lse : KielerServiceLoader.load(ILanguageServerContribution)) {
iLanguageServerExtensions.add(lse.getLanguageServerExtension(injector))
}
Expand All @@ -60,6 +64,7 @@ class LSCreator extends AbstractLsCreator {
}
constraints.client = languageClient as KGraphLanguageClient
rectPack.client = languageClient as KGraphLanguageClient
mrTree.client = languageClient as KGraphLanguageClient
diagramHighlighters = newArrayList
for (iLSdhc : KielerServiceLoader.load(ILSDiagramHighlighterContribution)) {
var highlighter = iLSdhc.getHighlighter(injector)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* KIELER - Kiel Integrated Environment for Layout Eclipse RichClient
*
* http://rtsys.informatik.uni-kiel.de/kieler
*
* Copyright 2022 by
* + Kiel University
* + Department of Computer Science
* + Real-Time and Embedded Systems Group
*
* This code is provided under the terms of the Eclipse Public License (EPL).
*/
package de.cau.cs.kieler.language.server.sccharts

import de.cau.cs.kieler.annotations.Annotatable
import de.cau.cs.kieler.annotations.AnnotationsFactory
import de.cau.cs.kieler.annotations.TypedStringAnnotation
import de.cau.cs.kieler.klighd.internal.util.KlighdInternalProperties
import de.cau.cs.kieler.klighd.kgraph.KNode
import de.cau.cs.kieler.klighd.lsp.interactive.ConstraintProperty
import de.cau.cs.kieler.klighd.lsp.interactive.IConstraintSerializer
import de.cau.cs.kieler.klighd.lsp.interactive.InteractiveUtil
import de.cau.cs.kieler.sccharts.impl.StateImpl
import java.util.List
import org.eclipse.elk.graph.properties.IProperty
import org.eclipse.emf.ecore.resource.Resource

/**
* Serialize a constraint for an SCChart node (region or state) as a layout annotation.
*
* @author sdo
*
*/
class SCTXConstraintSerializer implements IConstraintSerializer {

override canHandle(Object graph) {
return graph instanceof StateImpl
}

override serializeConstraints(List<ConstraintProperty<Object>> changedNodes, Object graph, Resource resource) {
// Get previous file content as String

val codeBefore = InteractiveUtil.serializeResource(resource)
changedNodes.forEach[c|
val Annotatable anno = c.KNode.getProperty(KlighdInternalProperties.MODEL_ELEMENT) as Annotatable
copyConstraintAnnotations(anno, c.KNode, c.property.id, c.property)
]
// Get changed file as String
val String codeAfter = InteractiveUtil.serializeResource(resource)

return InteractiveUtil.calculateTextEdit(codeBefore, codeAfter)
}

/**
* Copies an arbitrary IProperty of a KNode to a State if the value on the KNode
* is different to the value on the State.
* If the new value on the KNode was the default value of the property
* then the property is set to null on the State.
*
* @param state The target state.
* @param kNode The source KNode of the property.
* @param annotation The annotation that should be set.
* @param property Determines which IProperty should be copied.
*/
static def <T> copyConstraintAnnotations(Annotatable state, KNode kNode, String annotation, IProperty<T> property) {
val String value = "" + kNode.getProperty(property)

val annotations = state.getAnnotations().filter(TypedStringAnnotation)

// Remove old annotation if it exists.
var TypedStringAnnotation annotationToRemove = null
for (a : annotations) {
if (a.type.equals(annotation)) {
annotationToRemove = a
}
}
if (annotationToRemove !== null) {
state.annotations.remove(annotationToRemove)
}

// Add annotation with new value if the value is not the default one.
if (kNode.getProperty(property) !== null && !kNode.getProperty(property).equals(property.^default)) {
var newA = AnnotationsFactory::eINSTANCE.createTypedStringAnnotation => [
it.name = "layout"
it.type = annotation
it.values += value
]
state.annotations.add(newA)
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -351,13 +351,23 @@ class SCChartsSynthesis extends AbstractDiagramSynthesis<SCCharts> {
override List<? extends IGraphElementVisitor> getAdditionalLayoutConfigs(KNode viewModel) {
val List<IGraphElementVisitor> additionalLayoutRuns = newArrayList
// Add interactive Layout run.
if ((!viewModel.getChildren().isEmpty() && viewModel.getChildren().get(0)
.getProperty(CoreOptions.INTERACTIVE_LAYOUT))) {
if (!viewModel.getChildren().isEmpty() && (viewModel.getChildren().get(0)
.getProperty(CoreOptions.INTERACTIVE_LAYOUT) || isChildInteractive(viewModel))) {
additionalLayoutRuns.add(new CompoundGraphElementVisitor(
new InteractiveRectPackingGraphVisitor(),
new InteractiveLayeredGraphVisitor()));
}
return additionalLayoutRuns;
}

private def isChildInteractive(KNode node) {
val children = node.getChildren.get(0).getChildren()
for (n : children) {
if (n.getProperty(CoreOptions.INTERACTIVE_LAYOUT)) {
return true
}
}
return false
}

}
3 changes: 2 additions & 1 deletion plugins/de.cau.cs.kieler.scg.klighd/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ Require-Bundle: org.eclipse.elk.core;bundle-version="0.7.1",
de.cau.cs.kieler.kicool.ui,
de.cau.cs.kieler.simulation.ide,
de.cau.cs.kieler.simulation.ui,
de.cau.cs.kieler.annotations.ide
de.cau.cs.kieler.annotations.ide,
org.eclipse.elk.alg.mrtree
Bundle-RequiredExecutionEnvironment: JavaSE-11
Export-Package: de.cau.cs.kieler.scg.klighd
Bundle-ActivationPolicy: lazy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package de.cau.cs.kieler.scg.klighd.ssa.domtree
import com.google.inject.Inject
import de.cau.cs.kieler.annotations.extensions.AnnotationsExtensions
import de.cau.cs.kieler.klighd.LightDiagramServices
import de.cau.cs.kieler.klighd.SynthesisOption
import de.cau.cs.kieler.klighd.internal.util.SourceModelTrackingAdapter
import de.cau.cs.kieler.klighd.kgraph.KNode
import de.cau.cs.kieler.klighd.krendering.SimpleUpdateStrategy
Expand All @@ -33,13 +34,15 @@ import de.cau.cs.kieler.scg.SchedulingBlock
import de.cau.cs.kieler.scg.extensions.SCGControlFlowExtensions
import de.cau.cs.kieler.scg.extensions.SCGCoreExtensions
import de.cau.cs.kieler.scg.processors.ssa.DominatorTree
import java.util.List
import java.util.Map
import org.eclipse.elk.alg.mrtree.options.EdgeRoutingMode
import org.eclipse.elk.alg.mrtree.options.MrTreeOptions
import org.eclipse.elk.alg.mrtree.options.OrderWeighting
import org.eclipse.elk.core.options.CoreOptions
import org.eclipse.elk.core.options.Direction

import static extension de.cau.cs.kieler.klighd.syntheses.DiagramSyntheses.*
import de.cau.cs.kieler.klighd.SynthesisOption
import java.util.List

class DominatorTreeSynthesis extends AbstractDiagramSynthesis<SCGraphs> {

Expand Down Expand Up @@ -133,8 +136,11 @@ class DominatorTreeSynthesis extends AbstractDiagramSynthesis<SCGraphs> {
nodes.entrySet.forEach[nodes.createDTEdge(value, key, dt)]

val dtDiagram = createNode
dtDiagram.addLayoutParam(CoreOptions::ALGORITHM, "org.eclipse.elk.mrtree")
dtDiagram.addLayoutParam(CoreOptions::ALGORITHM, MrTreeOptions.ALGORITHM_ID)
dtDiagram.addLayoutParam(CoreOptions::DIRECTION, Direction.DOWN)
dtDiagram.addLayoutParam(MrTreeOptions::EDGE_ROUTING_MODE, EdgeRoutingMode.AVOID_OVERLAP)
dtDiagram.addLayoutParam(MrTreeOptions::WEIGHTING, OrderWeighting.MODEL_ORDER)
dtDiagram.addLayoutParam(MrTreeOptions::COMPACTION, false)
dtDiagram.children += nodes.values

return dtDiagram
Expand Down

0 comments on commit b33a6b1

Please sign in to comment.