Class: Roby::GUI::ChronicleWidget::TaskLayout

Inherits:
Object
  • Object
show all
Defined in:
lib/roby/gui/chronicle_widget.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(task, base_time, time_to_pixel, fm) ⇒ TaskLayout

Returns a new instance of TaskLayout.



645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
# File 'lib/roby/gui/chronicle_widget.rb', line 645

def initialize(task, base_time, time_to_pixel, fm)
    @task = task
    @base_time = base_time
    @time_to_pixel = time_to_pixel
    @fm = fm
    @event_height = [2 * EVENT_CIRCLE_RADIUS, fm.height].max

    @add_point = time_to_pixel * (task.addition_time - base_time)
    @start_point = nil
    @end_point   = nil
    @finalization_point = nil

    @state = :pending
    @messages = Array.new
    @events = Array.new
    @event_max_x = Array.new
    @base_height = event_height
    update
end

Instance Attribute Details

#add_pointObject (readonly)

Returns the value of attribute add_point.



631
632
633
# File 'lib/roby/gui/chronicle_widget.rb', line 631

def add_point
  @add_point
end

#base_heightObject (readonly)

Returns the value of attribute base_height.



643
644
645
# File 'lib/roby/gui/chronicle_widget.rb', line 643

def base_height
  @base_height
end

#base_timeObject (readonly)

Returns the value of attribute base_time.



624
625
626
# File 'lib/roby/gui/chronicle_widget.rb', line 624

def base_time
  @base_time
end

#end_pointObject (readonly)

Returns the value of attribute end_point.



633
634
635
# File 'lib/roby/gui/chronicle_widget.rb', line 633

def end_point
  @end_point
end

#event_heightObject (readonly)

Returns the value of attribute event_height.



636
637
638
# File 'lib/roby/gui/chronicle_widget.rb', line 636

def event_height
  @event_height
end

#event_max_xObject (readonly)

Returns the value of attribute event_max_x.



637
638
639
# File 'lib/roby/gui/chronicle_widget.rb', line 637

def event_max_x
  @event_max_x
end

#eventsObject (readonly)

Returns the value of attribute events.



638
639
640
# File 'lib/roby/gui/chronicle_widget.rb', line 638

def events
  @events
end

#finalization_pointObject (readonly)

Returns the value of attribute finalization_point.



634
635
636
# File 'lib/roby/gui/chronicle_widget.rb', line 634

def finalization_point
  @finalization_point
end

#fmObject (readonly)

Returns the value of attribute fm.



626
627
628
# File 'lib/roby/gui/chronicle_widget.rb', line 626

def fm
  @fm
end

#messagesObject

Returns the value of attribute messages.



639
640
641
# File 'lib/roby/gui/chronicle_widget.rb', line 639

def messages
  @messages
end

#start_pointObject (readonly)

Returns the value of attribute start_point.



632
633
634
# File 'lib/roby/gui/chronicle_widget.rb', line 632

def start_point
  @start_point
end

#stateObject (readonly)

Returns the value of attribute state.



629
630
631
# File 'lib/roby/gui/chronicle_widget.rb', line 629

def state
  @state
end

#taskObject (readonly)

Returns the value of attribute task.



628
629
630
# File 'lib/roby/gui/chronicle_widget.rb', line 628

def task
  @task
end

#time_to_pixelObject (readonly)

Returns the value of attribute time_to_pixel.



625
626
627
# File 'lib/roby/gui/chronicle_widget.rb', line 625

def time_to_pixel
  @time_to_pixel
end

#titleObject

Returns the value of attribute title.



641
642
643
# File 'lib/roby/gui/chronicle_widget.rb', line 641

def title
  @title
end

Instance Method Details

#append_event(event, event_height) ⇒ Object



698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
# File 'lib/roby/gui/chronicle_widget.rb', line 698

def append_event(event, event_height)
    event_x = Integer(time_to_pixel * (event.time - base_time))
    event_current_level = nil
    event_max_x.each_with_index do |x, idx|
        if x < event_x - EVENT_CIRCLE_RADIUS
            event_current_level = idx
            break
        end
    end
    event_current_level ||= event_max_x.size

    event_y = event_current_level * event_height
    event_max_x[event_current_level] = event_x + 2 * EVENT_CIRCLE_RADIUS + fm.width(event.symbol.to_s)
    events << [event.time, event_x, event_y, event.symbol.to_s]
end

#events_in_range(display_start_time, display_end_time) ⇒ Object



714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
# File 'lib/roby/gui/chronicle_widget.rb', line 714

def events_in_range(display_start_time, display_end_time)
    if !@time_first_event
        return
    elsif @time_first_event > display_end_time
        return
    elsif @time_last_event < display_start_time
        return
    else
        result = []
        events.each do |ev|
            time = ev.first
            if time > display_start_time
                if time < display_end_time
                    result << ev
                else
                    break
                end
            end
        end
        result if !result.empty?
    end
end

#height(display_start_time, display_end_time) ⇒ Object



737
738
739
740
741
742
743
# File 'lib/roby/gui/chronicle_widget.rb', line 737

def height(display_start_time, display_end_time)
    if events = events_in_range(display_start_time, display_end_time)
        max_event_y = events.max_by { |_, _, y, _| y }
        max_event_y = max_event_y[2]
    end
    (max_event_y || 0) + (messages.size + 1) * fm.height
end

#updateObject



665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
# File 'lib/roby/gui/chronicle_widget.rb', line 665

def update
    return if @finalization_point
    history_size = events.size
    return if !task.finalization_time && task.history.size == history_size

    last_event = task.last_event
    if !last_event
        @state = :pending
    else
        @state = GUI.task_state_at(task, last_event.time)
        @time_last_event = last_event.time
        if state != :running
            end_time = last_event.time
        end
    end


    if start_time = task.start_time
        @time_first_event = start_time
        @start_point = time_to_pixel * (start_time - base_time)
    end
    if end_time
        @end_point = time_to_pixel * (end_time - base_time)
    end
    if finalization_time = task.finalization_time
        @finalization_point = time_to_pixel * (finalization_time - base_time)
    end

    task.history[history_size..-1].each do |event|
        append_event(event, event_height)
    end
end