Skip to content

Commit

Permalink
Merge pull request #81 from kieler/nre/tik-merge2
Browse files Browse the repository at this point in the history
Proxy Views: SCCharts-specific renderings
  • Loading branch information
a-sr authored May 7, 2024
2 parents b33a6b1 + aedc6e4 commit 47410fc
Show file tree
Hide file tree
Showing 14 changed files with 506 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ import de.cau.cs.kieler.sccharts.State
import de.cau.cs.kieler.sccharts.extensions.SCChartsScopeExtensions
import de.cau.cs.kieler.sccharts.extensions.SCChartsSerializeHRExtensions
import de.cau.cs.kieler.sccharts.ui.synthesis.actions.ReferenceExpandAction
import de.cau.cs.kieler.sccharts.ui.synthesis.filtering.SCChartsSemanticFilterTags
import de.cau.cs.kieler.sccharts.ui.synthesis.hooks.actions.MemorizingExpandCollapseAction
import de.cau.cs.kieler.sccharts.ui.synthesis.styles.ColorStore
import de.cau.cs.kieler.sccharts.ui.synthesis.styles.ControlflowRegionStyles
import de.cau.cs.kieler.sccharts.ui.synthesis.styles.ProxyStyles
import java.util.EnumSet
import org.eclipse.elk.alg.layered.options.CenterEdgeLabelPlacementStrategy
import org.eclipse.elk.alg.layered.options.FixedAlignment
Expand Down Expand Up @@ -76,12 +78,18 @@ class ControlflowRegionSynthesis extends SubSynthesis<ControlflowRegion, KNode>

override performTranformation(ControlflowRegion region) {
val node = region.createNode().associateWith(region);
node.getProperty(KlighdProperties.SEMANTIC_FILTER_TAGS).addAll(
SCChartsSemanticFilterTags.REGION,
SCChartsSemanticFilterTags.CONTROLFLOW_REGION
)
val proxy = createNode().associateWith(region)

node.configureNodeLOD(region)

// Set KIdentifier for use with incremental update
if (!region.name.nullOrEmpty) {
node.KID = region.name
proxy.KID = '''«region.name»-proxy'''
}

if (USE_KLAY.booleanValue) {
Expand Down Expand Up @@ -195,19 +203,36 @@ class ControlflowRegionSynthesis extends SubSynthesis<ControlflowRegion, KNode>
]
} else {
node.addRegionFigure => [
if (region.override) addOverrideRegionStyle
if (region.abort) addAbortRegionStyle
if (region.final) addFinalRegionStyle
addCorrespondingRegionFigure(region)
]
}

proxy.addRegionFigure => [
addCorrespondingRegionFigure(region)
val label = region.serializeHighlighted(true)
if (label.length > 0) {
val name = label.get(0)
if (name.key.length > ProxyStyles.MAX_PROXY_LABEL_LENGTH) {
label.set(0, new Pair(name.key.subSequence(0, ProxyStyles.MAX_PROXY_LABEL_LENGTH) + "...", name.value))
}
}
addRegionLabel(label)
]

val returnNodes = <KNode> newArrayList(node)

if (SHOW_COMMENTS.booleanValue) {
region.getCommentAnnotations.forEach[
node.children += it.transform
val comments = it.transform
node.children += comments
// Comments shouldn't be rendered as proxies
comments.forEach[
setProperty(KlighdProperties.PROXY_VIEW_RENDER_NODE_AS_PROXY, false)
]
]
}
}

ProxyStyles.setProxySize(node, proxy)

return returnNodes
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@ import de.cau.cs.kieler.klighd.kgraph.KNode
import de.cau.cs.kieler.klighd.krendering.ViewSynthesisShared
import de.cau.cs.kieler.klighd.krendering.extensions.KNodeExtensions
import de.cau.cs.kieler.klighd.krendering.extensions.KRenderingExtensions
import de.cau.cs.kieler.klighd.microlayout.PlacementUtil
import de.cau.cs.kieler.klighd.util.KlighdProperties
import de.cau.cs.kieler.sccharts.DataflowRegion
import de.cau.cs.kieler.sccharts.extensions.SCChartsSerializeHRExtensions
import de.cau.cs.kieler.sccharts.extensions.TextFormat
import de.cau.cs.kieler.sccharts.ui.synthesis.actions.ReferenceExpandAction
import de.cau.cs.kieler.sccharts.ui.synthesis.filtering.SCChartsSemanticFilterTags
import de.cau.cs.kieler.sccharts.ui.synthesis.hooks.actions.MemorizingExpandCollapseAction
import de.cau.cs.kieler.sccharts.ui.synthesis.styles.DataflowRegionStyles
import de.cau.cs.kieler.sccharts.ui.synthesis.styles.ProxyStyles
import de.cau.cs.kieler.sccharts.ui.synthesis.styles.StateStyles
import org.eclipse.elk.alg.layered.options.GreedySwitchType
import org.eclipse.elk.alg.layered.options.LayeredOptions
import org.eclipse.elk.alg.layered.options.NodePlacementStrategy
Expand Down Expand Up @@ -80,6 +84,11 @@ class DataflowRegionSynthesis extends SubSynthesis<DataflowRegion, KNode> {

override performTranformation(DataflowRegion region) {
val node = region.createNode().associateWith(region)
node.getProperty(KlighdProperties.SEMANTIC_FILTER_TAGS).addAll(
SCChartsSemanticFilterTags.REGION,
SCChartsSemanticFilterTags.DATAFLOW_REGION
)
val proxy = createNode().associateWith(region)

node.addLayoutParam(CoreOptions::ALGORITHM, LayeredOptions.ALGORITHM_ID)
//node.setLayoutOption(LayeredOptions.CONSIDER_MODEL_ORDER, OrderingStrategy.PREFER_EDGES)
Expand Down Expand Up @@ -173,11 +182,31 @@ class DataflowRegionSynthesis extends SubSynthesis<DataflowRegion, KNode> {
]
]

proxy.addRegionFigure => [
if (sLabel.length > 0) it.setUserScheduleStyle
if (region.override) addOverrideRegionStyle
if (!CIRCUIT.booleanValue) {
if (label.length > 0) {
val name = label.get(0)
if (name.key.length > ProxyStyles.MAX_PROXY_LABEL_LENGTH) {
label.set(0, new Pair(name.key.subSequence(0, ProxyStyles.MAX_PROXY_LABEL_LENGTH) + "...", name.value))
}
}
addRegionLabel(label)
}
]

node.setSelectionStyle
proxy.setSelectionStyle

if (SHOW_COMMENTS.booleanValue) {
region.getCommentAnnotations.forEach[
node.children += it.transform
val comments = it.transform
node.children += comments
// Comments shouldn't be rendered as proxies
comments.forEach[
setProperty(KlighdProperties.PROXY_VIEW_RENDER_NODE_AS_PROXY, false)
]
]
}

Expand All @@ -187,6 +216,8 @@ class DataflowRegionSynthesis extends SubSynthesis<DataflowRegion, KNode> {
if (!CIRCUIT.booleanValue) {
node.setLayoutOption(CoreOptions::PADDING, new ElkPadding(18d, 7d, 7d, 7d));
}

ProxyStyles.setProxySize(node, proxy)

return <KNode> newArrayList(node)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ import org.eclipse.elk.graph.properties.IProperty
import org.eclipse.elk.graph.properties.Property

import static de.cau.cs.kieler.sccharts.ui.synthesis.GeneralSynthesisOptions.*
import de.cau.cs.kieler.klighd.filtering.SemanticFilterRule
import de.cau.cs.kieler.klighd.filtering.SemanticFilterTag
import de.cau.cs.kieler.klighd.KlighdOptions
import de.cau.cs.kieler.sccharts.ui.synthesis.filtering.SCChartsSemanticFilterRules

/**
* Main diagram synthesis for SCCharts.
Expand Down Expand Up @@ -167,6 +171,9 @@ class SCChartsSynthesis extends AbstractDiagramSynthesis<SCCharts> {
} else sccharts

val rootNode = createNode

// Set semantic filter rules
rootNode.setProperty(KlighdProperties.SEMANTIC_FILTER_RULES, SCChartsSemanticFilterRules.allFilters)

// If dot is used draw edges first to prevent overlapping with states when layout is bad
usedContext.setProperty(KlighdProperties.EDGES_FIRST, !USE_KLAY.booleanValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ import de.cau.cs.kieler.klighd.krendering.extensions.KEdgeExtensions
import de.cau.cs.kieler.klighd.krendering.extensions.KNodeExtensions
import de.cau.cs.kieler.klighd.krendering.extensions.KPolylineExtensions
import de.cau.cs.kieler.klighd.krendering.extensions.KRenderingExtensions
import de.cau.cs.kieler.klighd.microlayout.PlacementUtil
import de.cau.cs.kieler.klighd.util.KlighdProperties
import de.cau.cs.kieler.sccharts.Action
import de.cau.cs.kieler.sccharts.ControlflowRegion
import de.cau.cs.kieler.sccharts.DataflowRegion
Expand All @@ -66,7 +68,9 @@ import de.cau.cs.kieler.sccharts.processors.dataflow.ControlDependencies
import de.cau.cs.kieler.sccharts.processors.dataflow.RegionDependencies
import de.cau.cs.kieler.sccharts.processors.dataflow.RegionLCAFMap
import de.cau.cs.kieler.sccharts.processors.dataflow.StateDependencies
import de.cau.cs.kieler.sccharts.ui.synthesis.filtering.SCChartsSemanticFilterTags
import de.cau.cs.kieler.sccharts.ui.synthesis.hooks.actions.ToggleDependencyAction
import de.cau.cs.kieler.sccharts.ui.synthesis.styles.ProxyStyles
import de.cau.cs.kieler.sccharts.ui.synthesis.styles.StateStyles
import de.cau.cs.kieler.scl.MethodImplementationDeclaration
import java.util.ArrayList
Expand All @@ -88,6 +92,7 @@ import static de.cau.cs.kieler.sccharts.ui.synthesis.GeneralSynthesisOptions.*

import static extension de.cau.cs.kieler.annotations.ide.klighd.CommonSynthesisUtil.*
import static extension de.cau.cs.kieler.klighd.syntheses.DiagramSyntheses.*
import de.cau.cs.kieler.kexpressions.VariableDeclaration

/**
* Transforms {@link State} into {@link KNode} diagram elements.
Expand Down Expand Up @@ -140,10 +145,13 @@ class StateSynthesis extends SubSynthesis<State, KNode> {

override List<KNode> performTranformation(State state) {
val node = state.createNode().associateWith(state)
node.getProperty(KlighdProperties.SEMANTIC_FILTER_TAGS).add(SCChartsSemanticFilterTags.STATE)
val proxy = createNode().associateWith(state)

// Set KIdentifier for use with incremental update
if (!state.name.nullOrEmpty) {
node.KID = state.name
proxy.KID = '''«state.name»-proxy'''
}

// configure region dependency layout config if an appropriate result is present.
Expand All @@ -164,38 +172,56 @@ class StateSynthesis extends SubSynthesis<State, KNode> {

// Basic state style
switch state {
case isConnector:
case isConnector: {
node.addConnectorFigure
case state.isMacroState:
node.getProperty(KlighdProperties.SEMANTIC_FILTER_TAGS).add(SCChartsSemanticFilterTags.CONNECTOR_STATE)
proxy.addConnectorFigure
}
case state.isMacroState: {
node.addMacroFigure
default:
node.getProperty(KlighdProperties.SEMANTIC_FILTER_TAGS).add(SCChartsSemanticFilterTags.HIERARCHICAL_STATE)
proxy.addMacroFigure
}
default: {
node.addDefaultFigure
node.getProperty(KlighdProperties.SEMANTIC_FILTER_TAGS).add(SCChartsSemanticFilterTags.SIMPLE_STATE)
// Proxy should be more square-like
proxy.addMacroFigure
}
}

// Styles from modifiers
if (state.isReferencing) {
node.setReferencedStyle
proxy.setReferencedStyle
}
if (state.isInitial) {
node.setInitialStyle
node.getProperty(KlighdProperties.SEMANTIC_FILTER_TAGS).add(SCChartsSemanticFilterTags.INITIAL)
proxy.setInitialStyle
if (USE_KLAY.booleanValue && state.parentRegion.states.head == state) {
node.setLayoutOption(LayeredOptions::LAYERING_LAYER_CONSTRAINT, LayerConstraint::FIRST);
}
}
if (state.isFinal) {
node.setFinalStyle
node.getProperty(KlighdProperties.SEMANTIC_FILTER_TAGS).add(SCChartsSemanticFilterTags.FINAL)
proxy.setFinalStyle
}
if (state.isViolation) {
val isHaltState = state.outgoingTransitions.size == 0
|| !state.outgoingTransitions.exists[ targetState != state ]
node.setViolationStyle(isHaltState)
proxy.setViolationStyle(isHaltState)
}

node.setSelectionStyle
proxy.setSelectionStyle

// Shadow
if (!isConnector) {
node.setShadowStyle
proxy.setShadowStyle
}

// Add content
Expand Down Expand Up @@ -241,10 +267,22 @@ class StateSynthesis extends SubSynthesis<State, KNode> {
}
}
node.addMacroStateLabel(label)
if (label.length > 0) {
val name = label.get(0)
if (name.key.length > ProxyStyles.MAX_PROXY_LABEL_LENGTH) {
label.set(0, new Pair(name.key.subSequence(0, ProxyStyles.MAX_PROXY_LABEL_LENGTH) + "...", name.value))
}
}
proxy.addMacroStateLabel(label)
} else {
node.addSimpleStateLabel(state.serializeHR.toString)
val label = state.serializeHR.toString
node.addSimpleStateLabel(label)
if (label.length > ProxyStyles.MAX_PROXY_LABEL_LENGTH) {
proxy.addSimpleStateLabel(label.substring(0, ProxyStyles.MAX_PROXY_LABEL_LENGTH) + "...")
} else {
proxy.addSimpleStateLabel(label)
}
}) => [
setProperty(TracingVisualizationProperties.TRACING_NODE, true)
associateWith(state)
if (it instanceof KText) configureTextLOD(state)
eAllContents.filter(KRendering).toList.forEach[
Expand All @@ -254,12 +292,14 @@ class StateSynthesis extends SubSynthesis<State, KNode> {
]
} else {
node.addEmptyStateLabel
proxy.addEmptyStateLabel
}

// Add declarations
val declarations = new ArrayList<Declaration>(state.declarations)
if (SHOW_INHERITANCE.booleanValue) declarations.addAll(0, state.allVisibleInheritedDeclarations.toList)
for (declaration : declarations.filter[!(it instanceof MethodImplementationDeclaration) || !SHOW_METHOD_BODY.booleanValue]) {
val filteredDeclarations = declarations.filter[!(it instanceof MethodImplementationDeclaration) || !SHOW_METHOD_BODY.booleanValue]
for (declaration : filteredDeclarations) {
if (declaration instanceof ClassDeclaration) {
node.addStructDeclarations(declaration, 0)
} else {
Expand All @@ -272,7 +312,46 @@ class StateSynthesis extends SubSynthesis<State, KNode> {
]
]
}
}
}
node.getProperty(KlighdProperties.SEMANTIC_FILTER_TAGS).add(
SCChartsSemanticFilterTags.DECLARATIONS(
filteredDeclarations
.size as double
)
)

// Set declaration tags
var numInput = 0
var numOutput = 0
var numStatic = 0
var numSignal = 0
var numConst = 0
var numExtern = 0
var numVolatile = 0
var numGlobal = 0
for (declaration : filteredDeclarations) {
if (declaration instanceof VariableDeclaration) {
// Note that a declaration may have an arbitrary combination of these
if (declaration.input) numInput++
if (declaration.output) numOutput++
if (declaration.static) numStatic++
if (declaration.signal) numSignal++
if (declaration.const) numConst++
if (declaration.extern) numExtern++
if (declaration.volatile) numVolatile++
if (declaration.global) numGlobal++
}
}
node.getProperty(KlighdProperties.SEMANTIC_FILTER_TAGS).addAll(
SCChartsSemanticFilterTags.INPUT_DECLARATIONS(numInput as double),
SCChartsSemanticFilterTags.OUTPUT_DECLARATIONS(numOutput as double),
SCChartsSemanticFilterTags.STATIC_DECLARATIONS(numStatic as double),
SCChartsSemanticFilterTags.SIGNAL_DECLARATIONS(numSignal as double),
SCChartsSemanticFilterTags.CONST_DECLARATIONS(numConst as double),
SCChartsSemanticFilterTags.EXTERN_DECLARATIONS(numExtern as double),
SCChartsSemanticFilterTags.VOLATILE_DECLARATIONS(numVolatile as double),
SCChartsSemanticFilterTags.GLOBAL_DECLARATIONS(numGlobal as double)
)

// Add actions
val actions = new ArrayList<Action>(state.actions)
Expand Down Expand Up @@ -353,9 +432,17 @@ class StateSynthesis extends SubSynthesis<State, KNode> {

if (SHOW_COMMENTS.booleanValue) {
state.getCommentAnnotations.forEach[
returnNodes += it.transform
]
}
val comments = it.transform
returnNodes += comments
// Comments shouldn't be rendered as proxies
comments.forEach[
setProperty(KlighdProperties.PROXY_VIEW_RENDER_NODE_AS_PROXY, false)
]
]
}

node.setProperty(KlighdProperties.PROXY_VIEW_RENDER_NODE_AS_PROXY, true)
node.setProperty(KlighdProperties.PROXY_VIEW_PROXY_RENDERING, proxy.data)

return returnNodes
}
Expand Down
Loading

0 comments on commit 47410fc

Please sign in to comment.