Search in sources :

Example 1 with DotDirection

use of edu.mit.csail.sdg.alloy4graph.DotDirection in project org.alloytools.alloy by AlloyTools.

the class StaticGraphMaker method createEdge.

/**
 * Create an edge for a given tuple from a relation (if neither start nor end
 * node is explicitly invisible)
 */
private boolean createEdge(final boolean hidePrivate, final boolean hideMeta, AlloyRelation rel, AlloyTuple tuple, boolean bidirectional, Color magicColor) {
    // An edge will be drawn from A to D, with the label "R [B, C]"
    if ((hidePrivate && tuple.getStart().getType().isPrivate) || (hideMeta && tuple.getStart().getType().isMeta) || !view.nodeVisible(tuple.getStart(), instance))
        return false;
    if ((hidePrivate && tuple.getEnd().getType().isPrivate) || (hideMeta && tuple.getEnd().getType().isMeta) || !view.nodeVisible(tuple.getEnd(), instance))
        return false;
    GraphNode start = createNode(hidePrivate, hideMeta, tuple.getStart());
    GraphNode end = createNode(hidePrivate, hideMeta, tuple.getEnd());
    if (start == null || end == null)
        return false;
    boolean layoutBack = view.layoutBack.resolve(rel);
    String label = view.label.get(rel);
    if (tuple.getArity() > 2) {
        StringBuilder moreLabel = new StringBuilder();
        List<AlloyAtom> atoms = tuple.getAtoms();
        for (int i = 1; i < atoms.size() - 1; i++) {
            if (i > 1)
                moreLabel.append(", ");
            moreLabel.append(atomname(atoms.get(i), false));
        }
        if (label.length() == 0) {
        /* label=moreLabel.toString(); */
        } else {
            label = label + (" [" + moreLabel + "]");
        }
    }
    DotDirection dir = bidirectional ? DotDirection.BOTH : (layoutBack ? DotDirection.BACK : DotDirection.FORWARD);
    DotStyle style = view.edgeStyle.resolve(rel);
    DotColor color = view.edgeColor.resolve(rel);
    int weight = view.weight.get(rel);
    GraphEdge e = new GraphEdge((layoutBack ? end : start), (layoutBack ? start : end), tuple, label, rel);
    if (color == DotColor.MAGIC && magicColor != null)
        e.set(magicColor);
    else
        e.set(color.getColor(view.getEdgePalette()));
    e.set(style);
    e.set(dir != DotDirection.FORWARD, dir != DotDirection.BACK);
    e.set(weight < 1 ? 1 : (weight > 100 ? 10000 : 100 * weight));
    edges.put(e, tuple);
    return true;
}
Also used : DotColor(edu.mit.csail.sdg.alloy4graph.DotColor) DotDirection(edu.mit.csail.sdg.alloy4graph.DotDirection) DotStyle(edu.mit.csail.sdg.alloy4graph.DotStyle) GraphNode(edu.mit.csail.sdg.alloy4graph.GraphNode) GraphEdge(edu.mit.csail.sdg.alloy4graph.GraphEdge)

Aggregations

DotColor (edu.mit.csail.sdg.alloy4graph.DotColor)1 DotDirection (edu.mit.csail.sdg.alloy4graph.DotDirection)1 DotStyle (edu.mit.csail.sdg.alloy4graph.DotStyle)1 GraphEdge (edu.mit.csail.sdg.alloy4graph.GraphEdge)1 GraphNode (edu.mit.csail.sdg.alloy4graph.GraphNode)1