Class: Cosmos::LimitscolumnWidget

Inherits:
LimitsWidget show all
Defined in:
lib/cosmos/tools/tlm_viewer/widgets/limitscolumn_widget.rb

Overview

Draw a column which consists of the red low, yellow low, green with potentially a blue operational limits inside it, yellow high, and red high. Then draw a horizontal black bar with a little black triangle at the current value location.

Direct Known Subclasses

RangecolumnWidget

Instance Attribute Summary

Attributes included from Widget

#item, #item_name, #limits_set, #limits_state, #packet, #packet_name, #polling_period, #screen, #settings, #target_name, #value, #value_type

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from LimitsWidget

#calculate_widths, #get_limits, #paintEvent, #process_settings, #value=

Methods included from Widget

#context_menu, #get_image, #get_tooltip_text, included, #process_settings, #set_setting, #set_subsetting, #shutdown, #update_widget

Constructor Details

#initialize(parent_layout, target_name, packet_name, item_name, value_type = :CONVERTED, width = 30, height = 100) ⇒ LimitscolumnWidget

Returns a new instance of LimitscolumnWidget.



18
19
20
# File 'lib/cosmos/tools/tlm_viewer/widgets/limitscolumn_widget.rb', line 18

def initialize(parent_layout, target_name, packet_name, item_name, value_type = :CONVERTED, width = 30, height = 100)
  super(parent_layout, target_name, packet_name, item_name, value_type, width, height)
end

Class Method Details

.takes_value?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/cosmos/tools/tlm_viewer/widgets/limitscolumn_widget.rb', line 22

def LimitscolumnWidget.takes_value?
  return true
end

Instance Method Details

#paint_implementation(dc) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/cosmos/tools/tlm_viewer/widgets/limitscolumn_widget.rb', line 26

def paint_implementation(dc)
  limits = get_limits()
  return unless limits

  limits, widths = calculate_widths(limits, @bar_height, @min_value, @max_value)

  # Set starting points
  x_pos = @x_pad
  y_pos = @y_pad

  # Draw RED_LOW bar
  dc.addRectColorFill(x_pos, y_pos, @bar_width, widths.red_low, 'red')
  dc.addRectColor(x_pos, y_pos, @bar_width, widths.red_low)
  y_pos += widths.red_low

  # Draw YELLOW_LOW bar
  dc.addRectColorFill(x_pos, y_pos, @bar_width, widths.yellow_low, 'yellow')
  dc.addRectColor(x_pos, y_pos, @bar_width, widths.yellow_low)
  y_pos += widths.yellow_low

  if widths.green_high
    # Draw GREEN_LOW bar
    dc.addRectColorFill(x_pos, y_pos, @bar_width, widths.green_low, 'lime')
    dc.addRectColor(x_pos, y_pos, @bar_width, widths.green_low)
    y_pos += widths.green_low

    # Draw BLUE bar
    dc.addRectColorFill(x_pos, y_pos, @bar_width, widths.blue, 'dodgerblue')
    dc.addRectColor(x_pos, y_pos, @bar_width, widths.blue)
    y_pos += widths.blue

    # Draw GREEN_HIGH bar
    dc.addRectColorFill(x_pos, y_pos, @bar_width, widths.green_high, 'lime')
    dc.addRectColor(x_pos, y_pos, @bar_width, widths.green_high)
    y_pos += widths.green_high
  else
    # Draw GREEN bar
    dc.addRectColorFill(x_pos, y_pos, @bar_width, widths.green, 'lime')
    dc.addRectColor(x_pos, y_pos, @bar_width, widths.green)
    y_pos += widths.green
  end

  # Draw YELLOW_HIGH bar
  dc.addRectColorFill(x_pos, y_pos, @bar_width, widths.yellow_high, 'yellow')
  dc.addRectColor(x_pos, y_pos, @bar_width, widths.yellow_high)
  y_pos += widths.yellow_high

  # Draw RED_HIGH bar
  dc.addRectColorFill(x_pos, y_pos, @bar_width, widths.red_high, 'red')
  dc.addRectColor(x_pos, y_pos, @bar_width, widths.red_high)
  y_pos += widths.red_high

  # Draw line at current value
  red_low = limits[0]
  red_high = limits[3]
  # Start with a diviser of 0.8 assuming we'll draw red limits
  diviser = 0.8
  # If there is a min or max value equal to the min or or max red limit
  # it means we're not drawing red bar and the diviser increases
  diviser += 0.1 if @min_value && limits[0] == @min_value
  diviser += 0.1 if @max_value && limits[3] == @max_value
  @bar_scale = (red_high - red_low) / diviser
  if @min_value && @min_value >= red_low
    @low_value = @min_value
  else
    @low_value = red_low - 0.1 * @bar_scale
  end
  if @max_value && @max_value <= red_high
    @high_value = @max_value
  else
    @high_value = red_high + 0.1 * @bar_scale
  end

  if @value.is_a?(Float) && (@value.infinite? || @value.nan?)
    if @value.infinite? == 1
      @line_pos = @bar_width + @y_pad
    else
      @line_pos = @y_pad
    end
  else
    @line_pos = @height - (@y_pad + (@value - @low_value) / @bar_scale * @bar_height).to_i
    if @line_pos < @y_pad
      @line_pos = @y_pad
    end
    if @line_pos > @y_pad + @bar_height
      @line_pos = @bar_height + @y_pad
    end
  end

  dc.addLineColor(@x_pad - 3, @line_pos, @x_pad + @bar_width + 3, @line_pos)

  # Draw triangle next to current value line
  top_triangle = Qt::Polygon.new(3)
  top_triangle.setPoint(0, @x_pad + @bar_width, @line_pos)
  top_triangle.setPoint(1, @x_pad + @bar_width + 5, @line_pos + 5)
  top_triangle.setPoint(2, @x_pad + @bar_width + 5, @line_pos - 5)
  dc.setBrush(Cosmos::BLACK)
  dc.drawPolygon(top_triangle)
  top_triangle.dispose

  # Additional drawing for subclasses
  additional_drawing(dc)
end