Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ de.cau.cs.kieler.sccharts.ui.synthesis.hooks.HideAnnotationHook
de.cau.cs.kieler.sccharts.ui.synthesis.hooks.LabelPlacementSideHook
de.cau.cs.kieler.sccharts.ui.synthesis.hooks.LabelShorteningHook
de.cau.cs.kieler.sccharts.ui.synthesis.hooks.SynthesisAnnotationHook
de.cau.cs.kieler.sccharts.ui.synthesis.hooks.TopdownLayoutHook
de.cau.cs.kieler.sccharts.ui.synthesis.hooks.LayoutHook
de.cau.cs.kieler.sccharts.ui.synthesis.hooks.ExpandCollapseHook
de.cau.cs.kieler.sccharts.ui.synthesis.hooks.ColorAnnotationHook
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*
* KIELER - Kiel Integrated Environment for Layout Eclipse RichClient
*
* http://rtsys.informatik.uni-kiel.de/kieler
*
* Copyright 2024 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.sccharts.ui.synthesis.hooks

import de.cau.cs.kieler.klighd.SynthesisOption
import de.cau.cs.kieler.klighd.kgraph.KNode
import de.cau.cs.kieler.klighd.krendering.ViewSynthesisShared
import de.cau.cs.kieler.sccharts.Region
import de.cau.cs.kieler.sccharts.Scope
import de.cau.cs.kieler.sccharts.State
import de.cau.cs.kieler.sccharts.ui.synthesis.GeneralSynthesisOptions
import java.util.EnumSet
import org.eclipse.elk.core.options.ContentAlignment
import org.eclipse.elk.core.options.CoreOptions
import org.eclipse.elk.core.options.SizeConstraint
import org.eclipse.elk.core.options.TopdownNodeTypes

import static extension de.cau.cs.kieler.klighd.syntheses.DiagramSyntheses.*

/**
* Hook that configures SCCharts to be laid out using top-down layout instead of bottom-up layout.
*
* @author mka
*
*/
@ViewSynthesisShared
class TopdownLayoutHook extends SynthesisHook {

/** Action ID */
public static final String ID = "de.cau.cs.kieler.sccharts.ui.synthesis.hooks.TopdownLayoutHook";

public static final SynthesisOption USE_TOPDOWN_LAYOUT =
SynthesisOption.createCheckOption(TopdownLayoutHook, "Topdown Layout", false)
.setCategory(GeneralSynthesisOptions::LAYOUT)

public static final SynthesisOption TOPDOWN_HIERARCHICAL_NODE_WIDTH =
SynthesisOption.createRangeOption("Topdown Hierarchical Node Width", 50.0f, 5000.0f, 1.0f, 150.0f)
.setCategory(GeneralSynthesisOptions::LAYOUT)

public static final SynthesisOption TOPDOWN_HIERARCHICAL_NODE_ASPECT_RATIO =
SynthesisOption.createRangeOption("Topdown Hierarchical Node Aspect Ratio", 0.2f, 5.0f, 0.01f, 1.41f)
.setCategory(GeneralSynthesisOptions::LAYOUT)

public static final SynthesisOption SCALE_CAP =
SynthesisOption.createCheckOption(TopdownLayoutHook, "Enable Scale Cap", true)
.setCategory(GeneralSynthesisOptions::LAYOUT)
Comment on lines +42 to +60
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Try to always use the create... method using the class, that causes better IDs for the options to be generated.
  2. please use the setDescription method for each new option: This creates a hover-feedback popup for all options better describing what the option does. For example, I don't really get just from the name what "Enable Scale Cap" in the layout category should do.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please order the options the same way as they are used in the displayed synthesis options, or at least alphabetical



// public static final SynthesisOption
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?


override getDisplayedSynthesisOptions() {
return #[
USE_TOPDOWN_LAYOUT, SCALE_CAP, TOPDOWN_HIERARCHICAL_NODE_WIDTH, TOPDOWN_HIERARCHICAL_NODE_ASPECT_RATIO
]
}

override processState(State state, KNode node) {

node.setProperty(CoreOptions::TOPDOWN_LAYOUT, USE_TOPDOWN_LAYOUT.booleanValue)
if (USE_TOPDOWN_LAYOUT.booleanValue) {
node.setLayoutOption(CoreOptions::NODE_SIZE_CONSTRAINTS, EnumSet.noneOf(SizeConstraint))
node.setLayoutOption(CoreOptions::NODE_SIZE_FIXED_GRAPH_SIZE, true)
node.setLayoutOption(CoreOptions::TOPDOWN_NODE_TYPE, TopdownNodeTypes.HIERARCHICAL_NODE)
node.setLayoutOption(CoreOptions::TOPDOWN_HIERARCHICAL_NODE_WIDTH, TOPDOWN_HIERARCHICAL_NODE_WIDTH.floatValue as double)
node.setLayoutOption(CoreOptions::TOPDOWN_HIERARCHICAL_NODE_ASPECT_RATIO, TOPDOWN_HIERARCHICAL_NODE_ASPECT_RATIO.floatValue as double)
node.setLayoutOption(CoreOptions::CONTENT_ALIGNMENT, EnumSet.of(ContentAlignment.V_CENTER, ContentAlignment.H_CENTER))

if (SCALE_CAP.booleanValue) {
node.setLayoutOption(CoreOptions::TOPDOWN_SCALE_CAP, 1.0)
} else {
node.setLayoutOption(CoreOptions::TOPDOWN_SCALE_CAP, Double.MAX_VALUE)
}
}
}

override processRegion(Region region, KNode node) {
node.setProperty(CoreOptions::TOPDOWN_LAYOUT, USE_TOPDOWN_LAYOUT.booleanValue)

if (USE_TOPDOWN_LAYOUT.booleanValue) {
node.setLayoutOption(CoreOptions::NODE_SIZE_FIXED_GRAPH_SIZE, true)
node.setLayoutOption(CoreOptions::TOPDOWN_NODE_TYPE, TopdownNodeTypes.HIERARCHICAL_NODE)
node.setLayoutOption(CoreOptions::TOPDOWN_HIERARCHICAL_NODE_WIDTH, TOPDOWN_HIERARCHICAL_NODE_WIDTH.floatValue as double)
node.setLayoutOption(CoreOptions::TOPDOWN_HIERARCHICAL_NODE_ASPECT_RATIO, TOPDOWN_HIERARCHICAL_NODE_ASPECT_RATIO.floatValue as double)
node.setLayoutOption(CoreOptions::CONTENT_ALIGNMENT, EnumSet.of(ContentAlignment.V_CENTER, ContentAlignment.H_CENTER))
if (SCALE_CAP.booleanValue) {
node.setLayoutOption(CoreOptions::TOPDOWN_SCALE_CAP, 1.0)
} else {
node.setLayoutOption(CoreOptions::TOPDOWN_SCALE_CAP, Double.MAX_VALUE)
}
}
}

override start(Scope scope, KNode node) {
node.setProperty(CoreOptions::TOPDOWN_LAYOUT, USE_TOPDOWN_LAYOUT.booleanValue)
if (USE_TOPDOWN_LAYOUT.booleanValue) {
node.setLayoutOption(CoreOptions::NODE_SIZE_FIXED_GRAPH_SIZE, true)
node.setLayoutOption(CoreOptions::TOPDOWN_NODE_TYPE, TopdownNodeTypes.ROOT_NODE)
node.setLayoutOption(CoreOptions::TOPDOWN_HIERARCHICAL_NODE_WIDTH, TOPDOWN_HIERARCHICAL_NODE_WIDTH.floatValue as double)
node.setLayoutOption(CoreOptions::TOPDOWN_HIERARCHICAL_NODE_ASPECT_RATIO, TOPDOWN_HIERARCHICAL_NODE_ASPECT_RATIO.floatValue as double)
if (SCALE_CAP.booleanValue) {
node.setLayoutOption(CoreOptions::TOPDOWN_SCALE_CAP, 1.0)
} else {
node.setLayoutOption(CoreOptions::TOPDOWN_SCALE_CAP, Double.MAX_VALUE)
}
}
}
}