Class: Cosmos::LimitsbarWidget

Inherits:
Qt::Label
  • Object
show all
Includes:
Widget
Defined in:
lib/cosmos/tools/tlm_viewer/widgets/limitsbar_widget.rb

Direct Known Subclasses

RangebarWidget, TrendbarWidget

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 included from Widget

#context_menu, #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 = 160, height = 25) ⇒ LimitsbarWidget

Returns a new instance of LimitsbarWidget.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/cosmos/tools/tlm_viewer/widgets/limitsbar_widget.rb', line 18

def initialize(parent_layout, target_name, packet_name, item_name, value_type = :CONVERTED, width = 160, height = 25)
  super(target_name, packet_name, item_name, value_type)
  @value_type = :CONVERTED if @value_type == :WITH_UNITS
  @width = width.to_i
  @height = height.to_i
  @value = 0
  @x_pad = 6
  @y_pad = 6
  @bar_width = @width - (2 * @x_pad)
  @bar_height = @height - (2 * @y_pad)
  @painter = nil
  setFixedSize(width.to_i, height.to_i)
  parent_layout.addWidget(self) if parent_layout
end

Class Method Details

.takes_value?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/cosmos/tools/tlm_viewer/widgets/limitsbar_widget.rb', line 33

def LimitsbarWidget.takes_value?
  return true
end

Instance Method Details

#paint_implementation(dc) ⇒ Object



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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/cosmos/tools/tlm_viewer/widgets/limitsbar_widget.rb', line 57

def paint_implementation(dc)
  draw_bar = true

  limits_values = @item.limits.values
  if limits_values
    limits = limits_values[@limits_set]
    limits = limits_values[:DEFAULT] unless limits
    if limits
      red_low = limits[0]
      yellow_low = limits[1]
      yellow_high = limits[2]
      red_high = limits[3]
      green_low = limits[4]
      green_high = limits[5]
    else
      draw_bar = false
    end
  else
    draw_bar = false
  end

  if draw_bar
    # Calculate sizes of limits sections
    red_low_width  = (0.1 * @bar_width).round
    red_high_width = (0.1 * @bar_width).round

    inner_value_range = red_high - red_low

    yellow_low_width  = ((yellow_low - red_low)   / inner_value_range * 0.8 * @bar_width).round
    yellow_high_width = ((red_high - yellow_high) / inner_value_range * 0.8 * @bar_width).round

    if green_high
      green_low_width  = ((green_low - yellow_low)   / inner_value_range * 0.8 * @bar_width).round
      green_high_width = ((yellow_high - green_high) / inner_value_range * 0.8 * @bar_width).round
      blue_width = @bar_width - red_low_width - yellow_low_width - green_low_width - green_high_width - yellow_high_width - red_high_width
    else
      green_width = @bar_width - red_low_width - yellow_low_width - yellow_high_width - red_high_width
    end

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

    # Draw RED_LOW bar
    dc.addRectColorFill(x_pos, y_pos, red_low_width, @bar_height, 'red')
    dc.addRectColor(x_pos, y_pos, red_low_width, @bar_height)
    x_pos += red_low_width

    # Draw YELLOW_LOW bar
    dc.addRectColorFill(x_pos, y_pos, yellow_low_width, @bar_height, 'yellow')
    dc.addRectColor(x_pos, y_pos, yellow_low_width, @bar_height)
    x_pos += yellow_low_width

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

      # Draw BLUE bar
      dc.addRectColorFill(x_pos, y_pos, blue_width, @bar_height, 'dodgerblue')
      dc.addRectColor(x_pos, y_pos, blue_width, @bar_height)
      x_pos += blue_width

      # Draw GREEN_HIGH bar
      dc.addRectColorFill(x_pos, y_pos, green_high_width, @bar_height, 'lime')
      dc.addRectColor(x_pos, y_pos, green_high_width, @bar_height)
      x_pos += green_high_width
    else
      # Draw GREEN bar
      dc.addRectColorFill(x_pos, y_pos, green_width, @bar_height, 'lime')
      dc.addRectColor(x_pos, y_pos, green_width, @bar_height)
      x_pos += green_width
    end

    # Draw YELLOW_HIGH bar
    dc.addRectColorFill(x_pos, y_pos, yellow_high_width, @bar_height, 'yellow')
    dc.addRectColor(x_pos, y_pos, yellow_high_width, @bar_height)
    x_pos += yellow_high_width

    # Draw RED_HIGH bar
    dc.addRectColorFill(x_pos, y_pos, red_high_width, @bar_height, 'red')
    dc.addRectColor(x_pos, y_pos, red_high_width, @bar_height)
    x_pos += red_high_width

    # Draw line at current value
    @bar_scale = (red_high - red_low) / 0.8
    @low_value = red_low - 0.1 * @bar_scale
    @high_value = red_high + 0.1 * @bar_scale

    @line_pos = (@x_pad + (@value - @low_value) / @bar_scale * @bar_width).to_i
    if @line_pos < @x_pad
      @line_pos = @x_pad
    end
    if @line_pos > @x_pad + @bar_width
      @line_pos = @bar_width + @x_pad
    end

    dc.addLineColor(@line_pos, @y_pad - 3, @line_pos, @y_pad + @bar_height + 3)

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

    #Additional drawing for subclasses
    additional_drawing(dc)
  end # if draw_bar == true
end

#paintEvent(event) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/cosmos/tools/tlm_viewer/widgets/limitsbar_widget.rb', line 42

def paintEvent(event)
  begin
    return if @painter
    @painter = Qt::Painter.new(self)
    # Seems like on initialization sometimes we get some weird bad conditions so check for them
    if @painter.isActive and @painter.paintEngine
      paint_implementation(@painter)
    end
    @painter.dispose
    @painter = nil
  rescue Exception => err
    Cosmos.handle_fatal_exception(err)
  end
end

#value=(data) ⇒ Object



37
38
39
40
# File 'lib/cosmos/tools/tlm_viewer/widgets/limitsbar_widget.rb', line 37

def value= (data)
  @value = data.to_f
  update()
end