cosmos 3.6.3 → 3.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/Manifest.txt +10 -0
  3. data/data/crc.txt +22 -13
  4. data/demo/config/data/crc.txt +2 -1
  5. data/demo/config/targets/INST/screens/limits.txt +51 -0
  6. data/demo/config/targets/INST/screens/other.txt +0 -5
  7. data/ext/cosmos/ext/array/array.c +6 -6
  8. data/ext/cosmos/ext/buffered_file/buffered_file.c +10 -10
  9. data/ext/cosmos/ext/config_parser/config_parser.c +10 -10
  10. data/ext/cosmos/ext/cosmos_io/cosmos_io.c +3 -3
  11. data/ext/cosmos/ext/crc/crc.c +6 -6
  12. data/ext/cosmos/ext/line_graph/line_graph.c +20 -20
  13. data/ext/cosmos/ext/low_fragmentation_array/low_fragmentation_array.c +4 -4
  14. data/ext/cosmos/ext/packet/packet.c +18 -23
  15. data/ext/cosmos/ext/platform/platform.c +1 -1
  16. data/ext/cosmos/ext/polynomial_conversion/polynomial_conversion.c +1 -1
  17. data/ext/cosmos/ext/structure/structure.c +34 -29
  18. data/ext/cosmos/ext/tabbed_plots_config/tabbed_plots_config.c +1 -1
  19. data/ext/cosmos/ext/telemetry/telemetry.c +33 -33
  20. data/lib/cosmos/gui/line_graph/line_graph.rb +25 -1
  21. data/lib/cosmos/gui/line_graph/line_graph_dialog.rb +2 -2
  22. data/lib/cosmos/gui/line_graph/line_graph_drawing.rb +64 -14
  23. data/lib/cosmos/gui/line_graph/line_graph_popups.rb +2 -1
  24. data/lib/cosmos/gui/line_graph/line_graph_scaling.rb +9 -3
  25. data/lib/cosmos/gui/line_graph/line_graph_script.rb +64 -9
  26. data/lib/cosmos/gui/line_graph/lines.rb +24 -11
  27. data/lib/cosmos/interfaces/udp_interface.rb +8 -3
  28. data/lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server_config.rb +1 -1
  29. data/lib/cosmos/tools/tlm_viewer/widgets.rb +8 -1
  30. data/lib/cosmos/tools/tlm_viewer/widgets/canvasdot_widget.rb +79 -0
  31. data/lib/cosmos/tools/tlm_viewer/widgets/labelvaluelimitscolumn_widget.rb +38 -0
  32. data/lib/cosmos/tools/tlm_viewer/widgets/labelvaluerangebar_widget.rb +1 -1
  33. data/lib/cosmos/tools/tlm_viewer/widgets/labelvaluerangecolumn_widget.rb +39 -0
  34. data/lib/cosmos/tools/tlm_viewer/widgets/limits_widget.rb +103 -0
  35. data/lib/cosmos/tools/tlm_viewer/widgets/limitsbar_widget.rb +77 -147
  36. data/lib/cosmos/tools/tlm_viewer/widgets/limitscolor_widget.rb +102 -0
  37. data/lib/cosmos/tools/tlm_viewer/widgets/limitscolumn_widget.rb +108 -0
  38. data/lib/cosmos/tools/tlm_viewer/widgets/rangecolumn_widget.rb +57 -0
  39. data/lib/cosmos/tools/tlm_viewer/widgets/valuelimitscolumn_widget.rb +37 -0
  40. data/lib/cosmos/tools/tlm_viewer/widgets/valuerangecolumn_widget.rb +37 -0
  41. data/lib/cosmos/version.rb +5 -5
  42. data/spec/tools/cmd_tlm_server/cmd_tlm_server_config_spec.rb +33 -4
  43. metadata +12 -2
@@ -0,0 +1,38 @@
1
+ # encoding: ascii-8bit
2
+
3
+ # Copyright 2014 Ball Aerospace & Technologies Corp.
4
+ # All Rights Reserved.
5
+ #
6
+ # This program is free software; you can modify and/or redistribute it
7
+ # under the terms of the GNU General Public License
8
+ # as published by the Free Software Foundation; version 3 with
9
+ # attribution addendums as found in the LICENSE.txt
10
+
11
+ require 'cosmos/tools/tlm_viewer/widgets/widget'
12
+ require 'cosmos/tools/tlm_viewer/widgets/multi_widget'
13
+ require 'cosmos/tools/tlm_viewer/widgets/labelvalue_widget'
14
+ require 'cosmos/tools/tlm_viewer/widgets/limitsbar_widget'
15
+
16
+ module Cosmos
17
+
18
+ class LabelvaluelimitscolumnWidget < Qt::Widget
19
+ include Widget
20
+ include MultiWidget
21
+
22
+ def initialize(parent_layout, target_name, packet_name, item_name, value_type = :WITH_UNITS, characters = 12)
23
+ super(target_name, packet_name, item_name, value_type)
24
+ setLayout(Qt::VBoxLayout.new())
25
+ layout.setSpacing(1)
26
+ layout.setContentsMargins(0,0,0,0)
27
+ @widgets << LabelWidget.new(layout, item_name.to_s)
28
+ @widgets << LimitscolumnWidget.new(layout, target_name, packet_name, item_name, value_type)
29
+ @widgets << ValueWidget.new(layout, target_name, packet_name, item_name, value_type, characters)
30
+ parent_layout.addWidget(self) if parent_layout
31
+ end
32
+
33
+ def self.takes_value?
34
+ return true
35
+ end
36
+ end
37
+
38
+ end # module Cosmos
@@ -19,7 +19,7 @@ module Cosmos
19
19
  include Widget
20
20
  include MultiWidget
21
21
 
22
- def initialize (parent_layout, target_name, packet_name, item_name, low_value, high_value, value_type = :WITH_UNITS, characters = 12, width = 160, height = 25)
22
+ def initialize(parent_layout, target_name, packet_name, item_name, low_value, high_value, value_type = :WITH_UNITS, characters = 12, width = 160, height = 25)
23
23
  super(target_name, packet_name, item_name, value_type)
24
24
  setLayout(Qt::HBoxLayout.new())
25
25
  layout.setSpacing(1)
@@ -0,0 +1,39 @@
1
+ # encoding: ascii-8bit
2
+
3
+ # Copyright 2014 Ball Aerospace & Technologies Corp.
4
+ # All Rights Reserved.
5
+ #
6
+ # This program is free software; you can modify and/or redistribute it
7
+ # under the terms of the GNU General Public License
8
+ # as published by the Free Software Foundation; version 3 with
9
+ # attribution addendums as found in the LICENSE.txt
10
+
11
+ require 'cosmos/tools/tlm_viewer/widgets/widget'
12
+ require 'cosmos/tools/tlm_viewer/widgets/multi_widget'
13
+ require 'cosmos/tools/tlm_viewer/widgets/label_widget'
14
+ require 'cosmos/tools/tlm_viewer/widgets/value_widget'
15
+ require 'cosmos/tools/tlm_viewer/widgets/rangecolumn_widget'
16
+
17
+ module Cosmos
18
+
19
+ class LabelvaluerangecolumnWidget < Qt::Widget
20
+ include Widget
21
+ include MultiWidget
22
+
23
+ def initialize(parent_layout, target_name, packet_name, item_name, low_value, high_value, value_type = :WITH_UNITS, characters = 8, width = 30, height = 100)
24
+ super(target_name, packet_name, item_name, value_type)
25
+ setLayout(Qt::VBoxLayout.new())
26
+ layout.setSpacing(1)
27
+ layout.setContentsMargins(0,0,0,0)
28
+ @widgets << LabelWidget.new(layout, item_name)
29
+ @widgets << RangecolumnWidget.new(layout, target_name, packet_name, item_name, low_value, high_value, value_type, width, height)
30
+ @widgets << ValueWidget.new(layout, target_name, packet_name, item_name, value_type, characters)
31
+ parent_layout.addWidget(self) if parent_layout
32
+ end
33
+
34
+ def self.takes_value?
35
+ return true
36
+ end
37
+ end
38
+
39
+ end # module Cosmos
@@ -0,0 +1,103 @@
1
+ # encoding: ascii-8bit
2
+
3
+ # Copyright 2014 Ball Aerospace & Technologies Corp.
4
+ # All Rights Reserved.
5
+ #
6
+ # This program is free software; you can modify and/or redistribute it
7
+ # under the terms of the GNU General Public License
8
+ # as published by the Free Software Foundation; version 3 with
9
+ # attribution addendums as found in the LICENSE.txt
10
+
11
+ require 'ostruct'
12
+ require 'cosmos/tools/tlm_viewer/widgets/widget'
13
+
14
+ module Cosmos
15
+
16
+ # This class is a common base class for LimitsbarWidget and
17
+ # LimitscolumnWidget and should not be instantiated
18
+ class LimitsWidget < Qt::Label
19
+ include Widget
20
+
21
+ def initialize(parent_layout, target_name, packet_name, item_name, value_type, width, height)
22
+ super(target_name, packet_name, item_name, value_type)
23
+ @value_type = :CONVERTED if @value_type == :WITH_UNITS
24
+ @width = width.to_i
25
+ @height = height.to_i
26
+ @value = 0
27
+ @x_pad = 6
28
+ @y_pad = 6
29
+ @bar_width = @width - (2 * @x_pad)
30
+ @bar_height = @height - (2 * @y_pad)
31
+ @painter = nil
32
+ setFixedSize(width.to_i, height.to_i)
33
+ parent_layout.addWidget(self) if parent_layout
34
+ end
35
+
36
+ def value=(data)
37
+ @value = data.to_f
38
+ update()
39
+ end
40
+
41
+ def paintEvent(event)
42
+ begin
43
+ return if @painter
44
+ @painter = Qt::Painter.new(self)
45
+ # Seems like on initialization sometimes we get some weird bad conditions so check for them
46
+ if @painter.isActive and @painter.paintEngine
47
+ paint_implementation(@painter)
48
+ end
49
+ @painter.dispose
50
+ @painter = nil
51
+ rescue Exception => err
52
+ Cosmos.handle_fatal_exception(err)
53
+ end
54
+ end
55
+
56
+ def get_limits
57
+ limits = nil
58
+ limits_values = @item.limits.values
59
+ if limits_values
60
+ limits = limits_values[@limits_set]
61
+ limits = limits_values[:DEFAULT] unless limits
62
+ end
63
+ limits
64
+ end
65
+
66
+ def calculate_widths(limits, length)
67
+ red_low = limits[0]
68
+ yellow_low = limits[1]
69
+ yellow_high = limits[2]
70
+ red_high = limits[3]
71
+ green_low = limits[4]
72
+ green_high = limits[5]
73
+
74
+ widths = OpenStruct.new
75
+ # Calculate sizes of limits sections
76
+ widths.red_low = (0.1 * length).round
77
+ widths.red_high = (0.1 * length).round
78
+
79
+ inner_value_range = red_high - red_low
80
+
81
+ widths.yellow_low = ((yellow_low - red_low) / inner_value_range * 0.8 * length).round
82
+ widths.yellow_high = ((red_high - yellow_high) / inner_value_range * 0.8 * length).round
83
+
84
+ if green_high
85
+ widths.green_low = ((green_low - yellow_low) / inner_value_range * 0.8 * length).round
86
+ widths.green_high = ((yellow_high - green_high) / inner_value_range * 0.8 * length).round
87
+ widths.blue = length - widths.red_low - widths.yellow_low - widths.green_low -
88
+ widths.green_high - widths.yellow_high - widths.red_high
89
+ else
90
+ widths.green = length - widths.red_low - widths.yellow_low -
91
+ widths.yellow_high - widths.red_high
92
+ end
93
+ widths
94
+ end
95
+
96
+ protected
97
+
98
+ def additional_drawing(dc)
99
+ # Do nothing
100
+ end
101
+ end
102
+
103
+ end # module Cosmos
@@ -8,170 +8,100 @@
8
8
  # as published by the Free Software Foundation; version 3 with
9
9
  # attribution addendums as found in the LICENSE.txt
10
10
 
11
- require 'cosmos/tools/tlm_viewer/widgets/widget'
11
+ require 'cosmos/tools/tlm_viewer/widgets/limits_widget'
12
12
 
13
13
  module Cosmos
14
14
 
15
- class LimitsbarWidget < Qt::Label
16
- include Widget
15
+ class LimitsbarWidget < LimitsWidget
17
16
 
18
17
  def initialize(parent_layout, target_name, packet_name, item_name, value_type = :CONVERTED, width = 160, height = 25)
19
- super(target_name, packet_name, item_name, value_type)
20
- @value_type = :CONVERTED if @value_type == :WITH_UNITS
21
- @width = width.to_i
22
- @height = height.to_i
23
- @value = 0
24
- @x_pad = 6
25
- @y_pad = 6
26
- @bar_width = @width - (2 * @x_pad)
27
- @bar_height = @height - (2 * @y_pad)
28
- @painter = nil
29
- setFixedSize(width.to_i, height.to_i)
30
- parent_layout.addWidget(self) if parent_layout
18
+ super(parent_layout, target_name, packet_name, item_name, value_type, width, height)
31
19
  end
32
20
 
33
21
  def LimitsbarWidget.takes_value?
34
22
  return true
35
23
  end
36
24
 
37
- def value= (data)
38
- @value = data.to_f
39
- update()
40
- end
41
-
42
- def paintEvent(event)
43
- begin
44
- return if @painter
45
- @painter = Qt::Painter.new(self)
46
- # Seems like on initialization sometimes we get some weird bad conditions so check for them
47
- if @painter.isActive and @painter.paintEngine
48
- paint_implementation(@painter)
49
- end
50
- @painter.dispose
51
- @painter = nil
52
- rescue Exception => err
53
- Cosmos.handle_fatal_exception(err)
54
- end
55
- end
56
-
57
25
  def paint_implementation(dc)
58
- draw_bar = true
59
-
60
- limits_values = @item.limits.values
61
- if limits_values
62
- limits = limits_values[@limits_set]
63
- limits = limits_values[:DEFAULT] unless limits
64
- if limits
65
- red_low = limits[0]
66
- yellow_low = limits[1]
67
- yellow_high = limits[2]
68
- red_high = limits[3]
69
- green_low = limits[4]
70
- green_high = limits[5]
71
- else
72
- draw_bar = false
73
- end
26
+ limits = get_limits()
27
+ return unless limits
28
+
29
+ widths = calculate_widths(limits, @bar_width)
30
+
31
+ # Set starting points
32
+ x_pos = @x_pad
33
+ y_pos = @y_pad
34
+
35
+ # Draw RED_LOW bar
36
+ dc.addRectColorFill(x_pos, y_pos, widths.red_low, @bar_height, 'red')
37
+ dc.addRectColor(x_pos, y_pos, widths.red_low, @bar_height)
38
+ x_pos += widths.red_low
39
+
40
+ # Draw YELLOW_LOW bar
41
+ dc.addRectColorFill(x_pos, y_pos, widths.yellow_low, @bar_height, 'yellow')
42
+ dc.addRectColor(x_pos, y_pos, widths.yellow_low, @bar_height)
43
+ x_pos += widths.yellow_low
44
+
45
+ if widths.green_high
46
+ # Draw GREEN_LOW bar
47
+ dc.addRectColorFill(x_pos, y_pos, widths.green_low, @bar_height, 'lime')
48
+ dc.addRectColor(x_pos, y_pos, widths.green_low, @bar_height)
49
+ x_pos += widths.green_low
50
+
51
+ # Draw BLUE bar
52
+ dc.addRectColorFill(x_pos, y_pos, widths.blue, @bar_height, 'dodgerblue')
53
+ dc.addRectColor(x_pos, y_pos, widths.blue, @bar_height)
54
+ x_pos += widths.blue
55
+
56
+ # Draw GREEN_HIGH bar
57
+ dc.addRectColorFill(x_pos, y_pos, widths.green_high, @bar_height, 'lime')
58
+ dc.addRectColor(x_pos, y_pos, widths.green_high, @bar_height)
59
+ x_pos += widths.green_high
74
60
  else
75
- draw_bar = false
61
+ # Draw GREEN bar
62
+ dc.addRectColorFill(x_pos, y_pos, widths.green, @bar_height, 'lime')
63
+ dc.addRectColor(x_pos, y_pos, widths.green, @bar_height)
64
+ x_pos += widths.green
76
65
  end
77
66
 
78
- if draw_bar
79
- # Calculate sizes of limits sections
80
- red_low_width = (0.1 * @bar_width).round
81
- red_high_width = (0.1 * @bar_width).round
82
-
83
- inner_value_range = red_high - red_low
84
-
85
- yellow_low_width = ((yellow_low - red_low) / inner_value_range * 0.8 * @bar_width).round
86
- yellow_high_width = ((red_high - yellow_high) / inner_value_range * 0.8 * @bar_width).round
87
-
88
- if green_high
89
- green_low_width = ((green_low - yellow_low) / inner_value_range * 0.8 * @bar_width).round
90
- green_high_width = ((yellow_high - green_high) / inner_value_range * 0.8 * @bar_width).round
91
- blue_width = @bar_width - red_low_width - yellow_low_width - green_low_width - green_high_width - yellow_high_width - red_high_width
92
- else
93
- green_width = @bar_width - red_low_width - yellow_low_width - yellow_high_width - red_high_width
94
- end
95
-
96
- # Set starting points
97
- x_pos = @x_pad
98
- y_pos = @y_pad
99
-
100
- # Draw RED_LOW bar
101
- dc.addRectColorFill(x_pos, y_pos, red_low_width, @bar_height, 'red')
102
- dc.addRectColor(x_pos, y_pos, red_low_width, @bar_height)
103
- x_pos += red_low_width
104
-
105
- # Draw YELLOW_LOW bar
106
- dc.addRectColorFill(x_pos, y_pos, yellow_low_width, @bar_height, 'yellow')
107
- dc.addRectColor(x_pos, y_pos, yellow_low_width, @bar_height)
108
- x_pos += yellow_low_width
109
-
110
- if green_high
111
- # Draw GREEN_LOW bar
112
- dc.addRectColorFill(x_pos, y_pos, green_low_width, @bar_height, 'lime')
113
- dc.addRectColor(x_pos, y_pos, green_low_width, @bar_height)
114
- x_pos += green_low_width
115
-
116
- # Draw BLUE bar
117
- dc.addRectColorFill(x_pos, y_pos, blue_width, @bar_height, 'dodgerblue')
118
- dc.addRectColor(x_pos, y_pos, blue_width, @bar_height)
119
- x_pos += blue_width
120
-
121
- # Draw GREEN_HIGH bar
122
- dc.addRectColorFill(x_pos, y_pos, green_high_width, @bar_height, 'lime')
123
- dc.addRectColor(x_pos, y_pos, green_high_width, @bar_height)
124
- x_pos += green_high_width
125
- else
126
- # Draw GREEN bar
127
- dc.addRectColorFill(x_pos, y_pos, green_width, @bar_height, 'lime')
128
- dc.addRectColor(x_pos, y_pos, green_width, @bar_height)
129
- x_pos += green_width
130
- end
131
-
132
- # Draw YELLOW_HIGH bar
133
- dc.addRectColorFill(x_pos, y_pos, yellow_high_width, @bar_height, 'yellow')
134
- dc.addRectColor(x_pos, y_pos, yellow_high_width, @bar_height)
135
- x_pos += yellow_high_width
136
-
137
- # Draw RED_HIGH bar
138
- dc.addRectColorFill(x_pos, y_pos, red_high_width, @bar_height, 'red')
139
- dc.addRectColor(x_pos, y_pos, red_high_width, @bar_height)
140
- x_pos += red_high_width
141
-
142
- # Draw line at current value
143
- @bar_scale = (red_high - red_low) / 0.8
144
- @low_value = red_low - 0.1 * @bar_scale
145
- @high_value = red_high + 0.1 * @bar_scale
146
-
147
- @line_pos = (@x_pad + (@value - @low_value) / @bar_scale * @bar_width).to_i
148
- if @line_pos < @x_pad
149
- @line_pos = @x_pad
150
- end
151
- if @line_pos > @x_pad + @bar_width
152
- @line_pos = @bar_width + @x_pad
153
- end
154
-
155
- dc.addLineColor(@line_pos, @y_pad - 3, @line_pos, @y_pad + @bar_height + 3)
156
-
157
- # Draw triangle above current value line
158
- top_triangle = Qt::Polygon.new(3)
159
- top_triangle.setPoint(0, @line_pos, @y_pad - 1)
160
- top_triangle.setPoint(1, @line_pos-5, @y_pad - 6)
161
- top_triangle.setPoint(2, @line_pos+5, @y_pad - 6)
162
- dc.setBrush(Cosmos::BLACK)
163
- dc.drawPolygon(top_triangle)
164
- top_triangle.dispose
165
-
166
- #Additional drawing for subclasses
167
- additional_drawing(dc)
168
- end # if draw_bar == true
169
- end
67
+ # Draw YELLOW_HIGH bar
68
+ dc.addRectColorFill(x_pos, y_pos, widths.yellow_high, @bar_height, 'yellow')
69
+ dc.addRectColor(x_pos, y_pos, widths.yellow_high, @bar_height)
70
+ x_pos += widths.yellow_high
71
+
72
+ # Draw RED_HIGH bar
73
+ dc.addRectColorFill(x_pos, y_pos, widths.red_high, @bar_height, 'red')
74
+ dc.addRectColor(x_pos, y_pos, widths.red_high, @bar_height)
75
+ x_pos += widths.red_high
76
+
77
+ # Draw line at current value
78
+ red_low = limits[0]
79
+ red_high = limits[3]
80
+ @bar_scale = (red_high - red_low) / 0.8
81
+ @low_value = red_low - 0.1 * @bar_scale
82
+ @high_value = red_high + 0.1 * @bar_scale
83
+
84
+ @line_pos = (@x_pad + (@value - @low_value) / @bar_scale * @bar_width).to_i
85
+ if @line_pos < @x_pad
86
+ @line_pos = @x_pad
87
+ end
88
+ if @line_pos > @x_pad + @bar_width
89
+ @line_pos = @bar_width + @x_pad
90
+ end
91
+
92
+ dc.addLineColor(@line_pos, @y_pad - 3, @line_pos, @y_pad + @bar_height + 3)
170
93
 
171
- protected
94
+ # Draw triangle above current value line
95
+ top_triangle = Qt::Polygon.new(3)
96
+ top_triangle.setPoint(0, @line_pos, @y_pad - 1)
97
+ top_triangle.setPoint(1, @line_pos-5, @y_pad - 6)
98
+ top_triangle.setPoint(2, @line_pos+5, @y_pad - 6)
99
+ dc.setBrush(Cosmos::BLACK)
100
+ dc.drawPolygon(top_triangle)
101
+ top_triangle.dispose
172
102
 
173
- def additional_drawing (dc)
174
- # Do nothing
103
+ # Additional drawing for subclasses
104
+ additional_drawing(dc)
175
105
  end
176
106
  end
177
107
 
@@ -0,0 +1,102 @@
1
+ # encoding: ascii-8bit
2
+
3
+ # Copyright 2015 Ball Aerospace & Technologies Corp.
4
+ # All Rights Reserved.
5
+ #
6
+ # This program is free software; you can modify and/or redistribute it
7
+ # under the terms of the GNU General Public License
8
+ # as published by the Free Software Foundation; version 3 with
9
+ # attribution addendums as found in the LICENSE.txt
10
+
11
+ require 'cosmos/tools/tlm_viewer/widgets/widget'
12
+
13
+ module Cosmos
14
+
15
+ class LimitscolorWidget < Qt::Label
16
+ include Widget
17
+
18
+ def initialize(parent_layout, target_name, packet_name, item_name, value_type = :CONVERTED, radius = 10, use_full_item_name = false)
19
+ super(target_name, packet_name, item_name, value_type)
20
+ @value_type = :CONVERTED if @value_type == :WITH_UNITS
21
+ use_full_item_name = ConfigParser::handle_true_false(use_full_item_name)
22
+ @painter = nil
23
+ @foreground = Cosmos::BLACK
24
+ parent_layout.addWidget(self) if parent_layout
25
+ @font = font()
26
+ metrics = Cosmos.getFontMetrics(@font)
27
+ if use_full_item_name
28
+ @item_text = "#{@target_name} #{@packet_name} #{@item_name}"
29
+ else
30
+ @item_text = @item_name
31
+ end
32
+ text_width = metrics.width(@item_text)
33
+ @radius = radius.to_i
34
+ @diameter = @radius * 2
35
+ @text_height = @font.pointSize
36
+ @left_offset = @diameter + 5
37
+ if @text_height > @diameter
38
+ @text_baseline = @text_height
39
+ setFixedSize(text_width + @left_offset, @text_height + 2)
40
+ else
41
+ @text_baseline = @text_height + ((@diameter - @text_height) / 2)
42
+ setFixedSize(text_width + @left_offset, @diameter + 2)
43
+ end
44
+ end
45
+
46
+ def self.takes_value?
47
+ return true
48
+ end
49
+
50
+ def value=(data)
51
+ super(data)
52
+ case @limits_state
53
+ when :RED, :RED_HIGH, :RED_LOW
54
+ @foreground = 'red'
55
+ when :YELLOW, :YELLOW_HIGH, :YELLOW_LOW
56
+ @foreground = 'yellow'
57
+ when :GREEN, :GREEN_HIGH, :GREEN_LOW
58
+ @foreground = 'lime'
59
+ when :BLUE
60
+ @foreground = 'dodgerblue'
61
+ when :STALE
62
+ @foreground = Cosmos::PURPLE
63
+ else
64
+ @foreground = Cosmos::BLACK
65
+ end
66
+ update()
67
+ end
68
+
69
+ def paintEvent(event)
70
+ begin
71
+ super(event)
72
+ return if @painter
73
+ @painter = Qt::Painter.new(self)
74
+ # Seems like on initialization sometimes we get some weird bad conditions so check for them
75
+ if @painter.isActive and @painter.paintEngine
76
+ paint_implementation(@painter)
77
+ end
78
+ @painter.dispose
79
+ @painter = nil
80
+ rescue Exception => err
81
+ Cosmos.handle_fatal_exception(err)
82
+ end
83
+ end
84
+
85
+ def paint_implementation(dc)
86
+ dc.setBrush(Cosmos.getBrush(@foreground))
87
+ dc.drawEllipse(0, 0, @diameter, @diameter)
88
+ dc.setBrush(Cosmos.getBrush(Cosmos::BLACK))
89
+ dc.drawText(@left_offset, @text_baseline, @item_text)
90
+
91
+ #Additional drawing for subclasses
92
+ additional_drawing(dc)
93
+ end
94
+
95
+ protected
96
+
97
+ def additional_drawing (dc)
98
+ # Do nothing
99
+ end
100
+ end
101
+
102
+ end # module Cosmos