Class: Cosmos::LimitsWidget
- Includes:
- Widget
- Defined in:
- lib/cosmos/tools/tlm_viewer/widgets/limits_widget.rb
Overview
This class is a common base class for LimitsbarWidget and LimitscolumnWidget and should not be instantiated
Direct Known Subclasses
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
Instance Method Summary collapse
- #calculate_widths(limits, length) ⇒ Object
- #get_limits ⇒ Object
-
#initialize(parent_layout, target_name, packet_name, item_name, value_type, width, height) ⇒ LimitsWidget
constructor
A new instance of LimitsWidget.
- #paintEvent(event) ⇒ Object
- #value=(data) ⇒ Object
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, width, height) ⇒ LimitsWidget
Returns a new instance of LimitsWidget.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/cosmos/tools/tlm_viewer/widgets/limits_widget.rb', line 21 def initialize(parent_layout, target_name, packet_name, item_name, value_type, width, height) 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 |
Instance Method Details
#calculate_widths(limits, length) ⇒ Object
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 |
# File 'lib/cosmos/tools/tlm_viewer/widgets/limits_widget.rb', line 66 def calculate_widths(limits, length) red_low = limits[0] yellow_low = limits[1] yellow_high = limits[2] red_high = limits[3] green_low = limits[4] green_high = limits[5] widths = OpenStruct.new # Calculate sizes of limits sections widths.red_low = (0.1 * length).round widths.red_high = (0.1 * length).round inner_value_range = red_high - red_low widths.yellow_low = ((yellow_low - red_low) / inner_value_range * 0.8 * length).round widths.yellow_high = ((red_high - yellow_high) / inner_value_range * 0.8 * length).round if green_high widths.green_low = ((green_low - yellow_low) / inner_value_range * 0.8 * length).round widths.green_high = ((yellow_high - green_high) / inner_value_range * 0.8 * length).round widths.blue = length - widths.red_low - widths.yellow_low - widths.green_low - widths.green_high - widths.yellow_high - widths.red_high else widths.green = length - widths.red_low - widths.yellow_low - widths.yellow_high - widths.red_high end widths end |
#get_limits ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/cosmos/tools/tlm_viewer/widgets/limits_widget.rb', line 56 def get_limits limits = nil limits_values = @item.limits.values if limits_values limits = limits_values[@limits_set] limits = limits_values[:DEFAULT] unless limits end limits end |
#paintEvent(event) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/cosmos/tools/tlm_viewer/widgets/limits_widget.rb', line 41 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
36 37 38 39 |
# File 'lib/cosmos/tools/tlm_viewer/widgets/limits_widget.rb', line 36 def value=(data) @value = data.to_f update() end |