|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectdiva.graph.layout.AbstractGlobalLayout
ptolemy.vergil.basic.layout.kieler.KielerLayout
public class KielerLayout
Ptolemy Layouter that uses the KIELER layout algorithm from an external library to layout a given ptolemy model.
See http://www.informatik.uni-kiel.de/rtsys/kieler/ for more information about KIELER.
KIELER - Kiel Integrated Environment for Layout for the Eclipse RichClientPlatform
The KIELER project tries to enhance graphical modeling pragmatics. Next to higher level solutions (meta layout, structure based editing...) developed for Eclipse models, it also implements custom layout algorithms.
This class interfaces a standalone KIELER layout algorithm for actor oriented port based graphical diagrams with a Ptolemy diagram.
While KIELER is mainly developed for an Eclipse environment, most algorithms are also available standalone and can be used in a non Eclipse environment. This class is a try to leverage this to apply KIELER algorithms with Ptolemy. No Eclipse is required with that. Only one standalone external library.
Calling the layout() method will create a new Kieler graph datastructure, run Kieler layout algorithms on it and augment it with resulting layout information (locations and sizes of nodes, bendoints of connections). Then this layout gets applied to the Ptolemy model. Moving of nodes in Ptolemy is done via adding or changing location attributes.
Setting bendpoints is not yet supported in Ptolemy. Ptolemy's built-in connection routing does not consider obstacle avoidance, hence overlappings with other nodes and connections might appear. This class tries to gap that hole by the option to add new relations with vertices into the Ptolemy model. The vertices are placed at the bend point positions such that a certain routing is forced.
In order to avoid cluttering of the diagram with new clumsy vertices, there are methods available to remove or just hide unnecessary relation vertices. That are those vertices, just put in for routing and that have no semantic relevance.
It uses location attributes of actors and attributes to place items and corresponding for relation vertices.
Red (cxh) |
Red (cxh) |
Field Summary | |
---|---|
private CompositeActor |
_compositeActor
The top level Ptolemy composite actor that contains the diagram that is to be laid out. |
private boolean |
_debug
Debug flag that will trigger output of additional information during layout run. |
private java.util.Map<java.lang.Object,java.lang.Object> |
_divaEdgeSource
Storage of actual sources of diva edges corresponding to data flow. |
private java.util.Map<java.lang.Object,java.lang.Object> |
_divaEdgeTarget
Storage of actual targets of diva edges corresponding to data flow. |
private boolean |
_doApplyEdgeLayout
Flag to indicate whether edge routing shall be applied by insertion of new relation vertices or not. |
private boolean |
_doBoxLayout
Flag to indicate whether all nodes should be placed including unconnected nodes such as attributes (e.g. director, text annotations,...). |
private java.util.Map<de.cau.cs.kieler.core.kgraph.KEdge,java.lang.Object> |
_kieler2PtolemyDivaEdges
Map Kieler KEdges to Ptolemy Diva Edges. |
private java.util.Map<de.cau.cs.kieler.core.kgraph.KNode,java.lang.Object> |
_kieler2ptolemyDivaNodes
Map Kieler nodes to Diva Nodes. |
private java.util.Map<de.cau.cs.kieler.core.kgraph.KNode,NamedObj> |
_kieler2ptolemyEntityNodes
Map Kieler Nodes to Ptolemy Nodes. |
private java.util.Map<de.cau.cs.kieler.core.kgraph.KPort,Port> |
_kieler2PtolemyPorts
Map Kieler ports to Ptolemy ports. |
private java.util.Map<java.lang.Object,de.cau.cs.kieler.core.kgraph.KNode> |
_ptolemy2KielerNodes
Map Diva nodes to Kieler Nodes. |
private java.util.Map<Port,java.util.List<de.cau.cs.kieler.core.kgraph.KPort>> |
_ptolemy2KielerPorts
Map Ptolemy ports to Kieler ports. |
private java.util.Map<java.lang.Object,de.cau.cs.kieler.core.kgraph.KEdge> |
_ptolemyDiva2KielerEdges
Map Ptolemy links (= Edges in Diva) to Edges in Kieler |
private PtolemyModelUtil |
_ptolemyModelUtil
Helper class to manipulate Ptolemy models. |
private long |
_time
Variable to store time for statistics. |
private Top |
_top
Pointer to Top in order to report the current status. |
private static float |
DEFAULT_PORT_SIZE
Default size of a port that will be used in Kieler layout if no explicit size (e.g. copied from Ptolemy port) is given. |
private static float |
INNER_PORT_HEIGHT_OFFSET
The offset height used by Kieler for inner ports to correct connection anchor. |
private static float |
MIN_SPACING
Minimal distance between nodes. |
private static float |
MULTIPORT_BOTTOM
Offset between bottom of Multiport to the first Kieler KPort |
private static float |
MULTIPORT_OFFSET
Offset between Kieler KPorts corresponding to a Ptolemy multiport. |
private static int |
NO_RANK
Identify that no rank is given to a port. |
Constructor Summary | |
---|---|
KielerLayout(LayoutTarget target)
Construct an instance taking a LayoutTarget for specifying some methods for layout handling as given by the standard Ptolemy AbstractGlobalLayout. |
|
KielerLayout(LayoutTarget target,
CompositeActor ptolemyContainer)
Construct an instance setting the LayoutTarget as requested by the AbstractGlobalLayout and the containing Ptolemy model. |
Method Summary | |
---|---|
private Relation |
_applyEdgeLayout(de.cau.cs.kieler.core.kgraph.KEdge kEdge)
Apply precomputed routing of edges to the Ptolemy model by insertion of new relation vertices. |
private void |
_applyLayout(de.cau.cs.kieler.core.kgraph.KNode kgraph)
Traverse a composite KNode containing corresponding Kieler nodes, ports and edges for the Ptolemy model and apply all layout information contained by it back to the Ptolemy model. |
private void |
_createGraph(java.lang.Object composite,
de.cau.cs.kieler.core.kgraph.KNode hierarchicalLayoutNode,
de.cau.cs.kieler.core.kgraph.KNode boxLayoutNode)
Creates a graph for the KIELER API from a ptolemy model. |
private void |
_createKEdge(java.lang.Object divaEdge)
Create a Kieler KEdge for a Ptolemy Diva edge object. |
private de.cau.cs.kieler.core.kgraph.KNode |
_createKNode(java.lang.Object node,
java.lang.Object semanticNode)
Create a new Kieler KNode corresponding to a Ptolemy diva node and its Ptolemy semantic object (e.g. an Actor). |
private de.cau.cs.kieler.core.kgraph.KNode |
_createKNodeForPort(java.lang.Object divaLocation,
Port port)
Create a Kieler KNode for a Ptolemy inner port. |
private de.cau.cs.kieler.core.kgraph.KNode |
_createKNodeForVertex(Vertex vertex)
Create a Kieler KNode for a Ptolemy Vertex. |
private void |
_createKPort(de.cau.cs.kieler.core.kgraph.KNode knode,
de.cau.cs.kieler.core.kgraph.KPortType portType,
Port port,
int rank,
int index,
int maxIndex,
float size)
Create a Kieler KPort corresponding to a Ptolemy Port. |
private void |
_createKPorts(de.cau.cs.kieler.core.kgraph.KNode knode,
java.util.List<Port> ports,
de.cau.cs.kieler.core.kgraph.KPortType portType)
Create Kieler ports (KPort) for a Kieler node (KNode) given a list of Ptolemy Port objects and a port type (incoming, outgoing). |
private de.cau.cs.kieler.core.kgraph.KPort |
_getPort(java.lang.Object ptolemyObject,
de.cau.cs.kieler.core.kgraph.KPortType type,
Relation rel)
Get a Kieler KPort for a corresponding Ptolemy object, i.e. a Port or a relation Vertex. |
private void |
_kNode2Ptolemy(de.cau.cs.kieler.kiml.layout.klayoutdata.KShapeLayout kshapeLayout,
de.cau.cs.kieler.core.kgraph.KNode referenceNode)
Transform a location from a Kieler node from Kieler coordinate system to ptolemy coordinate system. |
private NamedObj |
_replaceRelation(de.cau.cs.kieler.core.kgraph.KPort kPort,
de.cau.cs.kieler.core.kgraph.KNode kNode,
java.lang.String newRelationName,
Relation oldRelation)
Replace a relation connected to a port of a node with a new relation by unlinking the old one and linking the new one. |
private void |
_report(java.lang.String message)
Report a message to the top window status handler if it is available. |
private void |
_storeEndpoints()
Determine the direction of dataflow of all edges and store it in the local maps. |
void |
layout(java.lang.Object composite)
Layout the given composite. |
void |
setApplyEdgeLayout(boolean flag)
Configure whether the layout should only place nodes or additionally route edges. |
void |
setBoxLayout(boolean flag)
Configure whether all unconnected nodes should also be placed by the layouter with a simple box layout heuristic. |
void |
setModel(CompositeActor model)
Set the Ptolemy Model that contains the graph that is to be layouted. |
void |
setTop(Top top)
Set the Top window to enable status reports on the status bar. |
Methods inherited from class diva.graph.layout.AbstractGlobalLayout |
---|
getLayoutTarget, setLayoutTarget |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final float DEFAULT_PORT_SIZE
private static final float INNER_PORT_HEIGHT_OFFSET
private static final float MIN_SPACING
private static final float MULTIPORT_OFFSET
private static final float MULTIPORT_BOTTOM
private static final int NO_RANK
private CompositeActor _compositeActor
private boolean _debug
private java.util.Map<java.lang.Object,java.lang.Object> _divaEdgeSource
private java.util.Map<java.lang.Object,java.lang.Object> _divaEdgeTarget
private boolean _doApplyEdgeLayout
private boolean _doBoxLayout
private java.util.Map<de.cau.cs.kieler.core.kgraph.KEdge,java.lang.Object> _kieler2PtolemyDivaEdges
private java.util.Map<de.cau.cs.kieler.core.kgraph.KNode,java.lang.Object> _kieler2ptolemyDivaNodes
private java.util.Map<de.cau.cs.kieler.core.kgraph.KNode,NamedObj> _kieler2ptolemyEntityNodes
private java.util.Map<de.cau.cs.kieler.core.kgraph.KPort,Port> _kieler2PtolemyPorts
private java.util.Map<java.lang.Object,de.cau.cs.kieler.core.kgraph.KNode> _ptolemy2KielerNodes
private java.util.Map<Port,java.util.List<de.cau.cs.kieler.core.kgraph.KPort>> _ptolemy2KielerPorts
private java.util.Map<java.lang.Object,de.cau.cs.kieler.core.kgraph.KEdge> _ptolemyDiva2KielerEdges
private PtolemyModelUtil _ptolemyModelUtil
private long _time
private Top _top
Constructor Detail |
---|
public KielerLayout(LayoutTarget target)
target
- The LayoutTarget on which layout will be performedpublic KielerLayout(LayoutTarget target, CompositeActor ptolemyContainer)
target
- The LayoutTarget on which layout will be performedptolemyContainer
- The composite actor that contains all elements to be layoutedMethod Detail |
---|
public void layout(java.lang.Object composite)
layout
in interface GlobalLayout
layout
in class AbstractGlobalLayout
composite
- the container of the diagram in terms of an GraphModel.public void setApplyEdgeLayout(boolean flag)
flag
- True iff edge routing shall be applied by insertion of
relation vertices.public void setBoxLayout(boolean flag)
flag
- If true, apply layout to all nodes, including unconnected
ones. Otherwise, apply layout only to connected nodes.public void setModel(CompositeActor model)
model
- The parent composite actor which internal diagram shall be
layouted.public void setTop(Top top)
top
- The Top windowprivate Relation _applyEdgeLayout(de.cau.cs.kieler.core.kgraph.KEdge kEdge) throws IllegalActionException
kEdge
- The Kieler KEdge that hold the precomupted layout information,
i.e. bend point positions
IllegalActionException
- Exception will be thrown if replacing of original relation
is not possible, i.e. if unlink() or link() methods fail.private void _applyLayout(de.cau.cs.kieler.core.kgraph.KNode kgraph) throws IllegalActionException
Optionally route edges explicitly by inserting new relation vertices for each bend point.
kgraph
- The Kieler graph object containing all layout information to
apply to the Ptolemy model
IllegalActionException
- Exception can be thrown if routing of edges fails due to
not allowed unlinking or linking of new relations.setApplyEdgeLayout(boolean)
private void _createGraph(java.lang.Object composite, de.cau.cs.kieler.core.kgraph.KNode hierarchicalLayoutNode, de.cau.cs.kieler.core.kgraph.KNode boxLayoutNode)
composite
- The GraphModel composite object to retrieve the model
information fromboxLayoutNode
- Kieler subgraph to receive all unconnected model elementshierarchicalLayoutNode
- Kieler subgraph to receive all connected model elementsprivate void _createKEdge(java.lang.Object divaEdge)
_applyLayout(KNode)
method will be able to reapply the
layout.
divaEdge
- The Ptolemy diva edge object for which to create a new KEdge.private de.cau.cs.kieler.core.kgraph.KNode _createKNode(java.lang.Object node, java.lang.Object semanticNode)
_applyLayout(KNode)
method will be able to reapply the layout.
node
- The Diva node object.semanticNode
- The corresponding Ptolemy semantic object, e.g. an Actor or
TextAttribute
private de.cau.cs.kieler.core.kgraph.KNode _createKNodeForPort(java.lang.Object divaLocation, Port port)
divaLocation
- Diva Representation of an inner portport
- The Ptolemy inner port.
private de.cau.cs.kieler.core.kgraph.KNode _createKNodeForVertex(Vertex vertex)
vertex
- The Ptolemy vertex for which to create a KNode
private void _createKPort(de.cau.cs.kieler.core.kgraph.KNode knode, de.cau.cs.kieler.core.kgraph.KPortType portType, Port port, int rank, int index, int maxIndex, float size)
_applyLayout(KNode)
method will be able to reapply the layout.
knode
- The parent KNode of the new portportType
- The port Type, either input or outputport
- The corresponding Ptolemy port (might be a multiport)rank
- The rank of the new port which is an ordering index. If this
is not set, Kieler will try to infer the ranks automatically
from the port's position.index
- Index of the KPort corresponding to a multiportmaxIndex
- Width of the multiport, i.e. the number of connected edges to
that port.size
- Custom size (same for width and height) for a port that will
be used instead of the real Ptolemy port size. If this value
is negative, the original Ptolemy sizes are used.private void _createKPorts(de.cau.cs.kieler.core.kgraph.KNode knode, java.util.List<Port> ports, de.cau.cs.kieler.core.kgraph.KPortType portType)
knode
- The KNode to create Kieler ports for.ports
- The Ptolemy ports counterparts for which to create Kieler
ports.portType
- Type of port, input or output. This is relevant for some
Kieler layout algorithms.private de.cau.cs.kieler.core.kgraph.KPort _getPort(java.lang.Object ptolemyObject, de.cau.cs.kieler.core.kgraph.KPortType type, Relation rel)
ptolemyObject
- The corresponding Ptolemy object, either a Vertex or a Porttype
- The type of the port, incoming or outgoingrel
- The relation that is connected to the Ptolemy multiport
private void _kNode2Ptolemy(de.cau.cs.kieler.kiml.layout.klayoutdata.KShapeLayout kshapeLayout, de.cau.cs.kieler.core.kgraph.KNode referenceNode)
kshapeLayout
- Layout of KNode kieler graphical node that contains bounds
with location and size. This object will be altered to fit the
new location.referenceNode
- The parent reference node giving the bounds to calculate with.private NamedObj _replaceRelation(de.cau.cs.kieler.core.kgraph.KPort kPort, de.cau.cs.kieler.core.kgraph.KNode kNode, java.lang.String newRelationName, Relation oldRelation) throws IllegalActionException
kPort
- Kieler KPort the relation is connected to. Might be null or
invalid if the port is an inner port within the composite
actor.kNode
- Kieler KNode the port belongs to or---if it is an inner
port--- the inner port itself.newRelationName
- The new relation that should be connected.oldRelation
- The old relation that should be replaced. It does not get
deleted at this point.
IllegalActionException
- Exception may be thrown if unlinking or linking of a
relation fails.private void _report(java.lang.String message)
message
- The message to be reported.private void _storeEndpoints()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |