Module: Roby::GUI::GraphvizTask

Includes:
GraphvizPlanObject
Included in:
Task, Transaction::TaskProxy
Defined in:
lib/roby/gui/plan_dot_layout.rb

Instance Method Summary collapse

Methods included from GraphvizPlanObject

#to_dot

Instance Method Details

#apply_layout(bounding_rects, positions, display) ⇒ Object



195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
# File 'lib/roby/gui/plan_dot_layout.rb', line 195

def apply_layout(bounding_rects, positions, display)
    if !(task = positions[dot_id])
        puts "No layout for #{self}"
        return
    end
    each_event do |ev|
        next if !display.displayed?(ev)
        positions[ev.dot_id] += task
    end
    # Apply the layout on the events
    each_event do |ev|
        ev.apply_layout(bounding_rects, positions, display)
    end
    # And recalculate the bounding box
    bounding_rect = Qt::RectF.new
    each_event.map do |ev|
        next if !display.displayed?(ev)
        graphics = display[ev]
        bounding_rect |= graphics.map_rect_to_scene(graphics.bounding_rect)
        bounding_rect |= graphics.text.map_rect_to_scene(graphics.text.bounding_rect)
    end
    if !graphics_item = display[self]
        raise "no graphics for #{self}" unless graphics_item = display[self]
    end
    if bounding_rect.null? # no events, we need to take the bounding box from the fake task node
        bounding_rect = Qt::RectF.new(
            task.x - DEFAULT_TASK_WIDTH / 2,
            task.y - DEFAULT_TASK_HEIGHT / 2, DEFAULT_TASK_WIDTH, DEFAULT_TASK_HEIGHT)
    else
        bounding_rect.y -= 5
    end
    graphics_item.rect = bounding_rect

    text_pos = Qt::PointF.new(
        bounding_rect.x + bounding_rect.width / 2 - graphics_item.text.bounding_rect.width / 2,
        bounding_rect.y + bounding_rect.height)
    graphics_item.text.pos = text_pos
end

#dot_label(display) ⇒ Object



184
185
186
187
188
189
190
191
192
193
# File 'lib/roby/gui/plan_dot_layout.rb', line 184

def dot_label(display)
    event_names = each_event.find_all { |ev| display.displayed?(ev) }.
        map { |ev| ev.dot_label(display) }.
        join(" ")

    own = super
    if own.size > event_names.size then own
    else event_names
    end
end

#to_dot_events(display, io) ⇒ Object



164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/roby/gui/plan_dot_layout.rb', line 164

def to_dot_events(display, io)
    return unless display.displayed?(self)
    io << "subgraph cluster_#{dot_id} {\n"
    graphics = display.graphics[self]
    text_bb = graphics.text.bounding_rect
    has_event = false
    each_event do |ev|
        if display.displayed?(ev)
            ev.to_dot(display, io)
            has_event = true
        end
    end
    task_height = if !has_event then DEFAULT_TASK_HEIGHT + text_bb.height
                  else text_bb.height
                  end

    io << "  #{dot_id}[width=#{[DEFAULT_TASK_WIDTH, text_bb.width].max},height=#{task_height},fixedsize=true];\n"
    io << "}\n"
end