Module: Roby::GUI::GraphvizPlan

Included in:
Plan
Defined in:
lib/roby/gui/plan_dot_layout.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#depthObject (readonly)

The distance from the root plan



88
89
90
# File 'lib/roby/gui/plan_dot_layout.rb', line 88

def depth
  @depth
end

#layout_levelObject

Returns the value of attribute layout_level.



8
9
10
# File 'lib/roby/gui/plan_dot_layout.rb', line 8

def layout_level
  @layout_level
end

Instance Method Details

#all_events(display) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/roby/gui/plan_dot_layout.rb', line 9

def all_events(display)
    tasks.inject(free_events.dup) do |events, task|
        if display.displayed?(task)
            events.merge(task.events.values.to_set)
        else
            events
        end
    end
end

#apply_layout(bounding_rects, positions, display, max_depth = nil) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/roby/gui/plan_dot_layout.rb', line 102

def apply_layout(bounding_rects, positions, display, max_depth = nil)
    max_depth ||= compute_depth(0)

    if rect = bounding_rects[dot_id]
        item = display[self]
        item.z_value = PLAN_LAYER + depth - max_depth
        item.rect = rect
    else
        DRoby::Logfile.warn "no bounding rectangle for #{self} (#{dot_id})"
    end


    (tasks | finalized_tasks | free_events | finalized_events).
        each do |obj|
            next if !display.displayed?(obj)
            obj.apply_layout(bounding_rects, positions, display)
        end

    transactions.each do |trsc|
        trsc.apply_layout(bounding_rects, positions, display, max_depth)
    end
    layout_relations(positions, display, each_task_relation_graph.to_a, tasks)
end

#compute_depth(depth) ⇒ Object

Computes the plan depths and max_depth for this plan and all its children. depth is this plan depth

Returns max_depth



94
95
96
97
98
99
100
# File 'lib/roby/gui/plan_dot_layout.rb', line 94

def compute_depth(depth)
    @depth = depth
    child_depth = transactions.
        map { |trsc| trsc.compute_depth(depth + 1) }.
        max
    child_depth || depth
end

#each_displayed_relation(display, graphs, objects, &block) ⇒ Object



63
64
65
66
67
68
# File 'lib/roby/gui/plan_dot_layout.rb', line 63

def each_displayed_relation(display, graphs, objects, &block)
    graphs.each do |g|
        next unless display.relation_enabled?(g.class)
        each_edge(g, display, objects, &block)
    end
end

#each_edge(graph, display, objects) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/roby/gui/plan_dot_layout.rb', line 36

def each_edge(graph, display, objects)
    objects.each do |from|
        next unless display.displayed?(from)
        unless display[from]
            DRoby::Logfile.warn "no display item for #{from} in #each_displayed_relation"
            next
        end

        graph.each_out_neighbour(from) do |to|
            next unless display.displayed?(to)
            unless display[to]
                DRoby::Logfile.warn "no display item for child in #{from} <#{rel}> #{to} in #each_displayed_relation"
                next
            end

            yield(graph, from, to)
        end
    end
end

#each_layout_relation(display, graphs, objects, &block) ⇒ Object



56
57
58
59
60
61
# File 'lib/roby/gui/plan_dot_layout.rb', line 56

def each_layout_relation(display, graphs, objects, &block)
    graphs.each do |g|
        next unless display.layout_relation?(g.class)
        each_edge(g, display, objects, &block)
    end
end

#layout_relations(positions, display, graphs, objects) ⇒ Object



81
82
83
84
85
# File 'lib/roby/gui/plan_dot_layout.rb', line 81

def layout_relations(positions, display, graphs, objects)
    each_displayed_relation(display, graphs, objects) do |graph, from, to|
        display.task_relation(from, to, graph.class, graph.edge_info(from, to))
    end
end

#relations_to_dot(display, io, graphs, objects) ⇒ Object



70
71
72
73
74
75
76
77
78
79
# File 'lib/roby/gui/plan_dot_layout.rb', line 70

def relations_to_dot(display, io, graphs, objects)
    each_layout_relation(display, graphs, objects) do |graph, from, to|
        from_id, to_id = from.dot_id, to.dot_id
        if from_id && to_id
            io << "  #{from_id} -> #{to_id}\n"
        else
            DRoby::Logfile.warn "ignoring #{from}(#{from.object_id} #{from_id}) -> #{to}(#{to.object_id} #{to_id}) in #{graph.class} in #{caller(1).join("\n  ")}"
        end
    end
end

#to_dot(display, io, level) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/roby/gui/plan_dot_layout.rb', line 19

def to_dot(display, io, level)
    @layout_level = level
    io << "subgraph cluster_#{dot_id} {\n"
    (tasks | finalized_tasks | free_events | finalized_events).
        each do |obj|
            obj.to_dot(display, io) if display.displayed?(obj)
        end

    io << "};\n"

    transactions.each do |trsc|
        trsc.to_dot(display, io, level + 1)
    end

    relations_to_dot(display, io, each_task_relation_graph, tasks)
end