Class: Cosmos::CanvasdotWidget

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

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

Methods included from Widget

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

Constructor Details

#initialize(parent_layout, x, y, color = 'black', width = 3) ⇒ CanvasdotWidget

Returns a new instance of CanvasdotWidget.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/cosmos/tools/tlm_viewer/widgets/canvasdot_widget.rb', line 18

def initialize(parent_layout, x, y, color='black', width=3)
  super()
  if is_numeric?(x)
    @x = x.to_i
  else
    @x = x.to_s
  end

  if is_numeric?(y)
    @y = y.to_i
  else
    @y = y.to_s
  end

  @point = Qt::Point.new(0, 0)
  update_point

  @width = width.to_i
  @color = Cosmos::getColor(color)
  parent_layout.add_repaint(self)
end

Instance Method Details

#disposeObject



73
74
75
76
# File 'lib/cosmos/tools/tlm_viewer/widgets/canvasdot_widget.rb', line 73

def dispose
  super()
  @point.dispose
end

#eval_str(string_to_eval) ⇒ Object



65
66
67
# File 'lib/cosmos/tools/tlm_viewer/widgets/canvasdot_widget.rb', line 65

def eval_str(string_to_eval)
  @screen.instance_eval(string_to_eval)
end

#is_numeric?(obj) ⇒ Boolean

update_point

Returns:

  • (Boolean)


54
55
56
# File 'lib/cosmos/tools/tlm_viewer/widgets/canvasdot_widget.rb', line 54

def is_numeric?(obj) 
  obj.to_s.match(/\A[+-]?\d+?(\.\d+)?\Z/) == nil ? false : true
end

#paint(painter) ⇒ Object



58
59
60
61
62
63
# File 'lib/cosmos/tools/tlm_viewer/widgets/canvasdot_widget.rb', line 58

def paint(painter)
  painter.save
  painter.setBrush(@color)
  painter.drawEllipse(@point, @width, @width)
  painter.restore
end

#update_pointObject

initialize



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/cosmos/tools/tlm_viewer/widgets/canvasdot_widget.rb', line 40

def update_point
  if is_numeric?(@x)
    @point.x = @x
  else
    @point.x = eval_str(@x)
  end
  
  if is_numeric?(@y)
    @point.y = @y
  else
    @point.y = eval_str(@y)
  end
end

#update_widgetObject



69
70
71
# File 'lib/cosmos/tools/tlm_viewer/widgets/canvasdot_widget.rb', line 69

def update_widget
  update_point
end