cosmos 3.6.3 → 3.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -133,7 +133,7 @@ module Cosmos
133
133
  if label
134
134
  text = label.to_s
135
135
  else
136
- text = convert_x_value_to_text(value, @max_x_characters)
136
+ text = convert_x_value_to_text(value)
137
137
  end
138
138
  left_widths << ((metrics.width(text) / 2) - LEFT_X_LABEL_WIDTH_ADJUST)
139
139
 
@@ -214,7 +214,7 @@ module Cosmos
214
214
  if label
215
215
  text = label.to_s
216
216
  else
217
- text = convert_x_value_to_text(value, @max_x_characters)
217
+ text = convert_x_value_to_text(value)
218
218
  end
219
219
  metrics = Cosmos.getFontMetrics(@font)
220
220
  text_width = metrics.width(text)
@@ -244,19 +244,23 @@ module Cosmos
244
244
  end # def draw_x_label_and_grid_line
245
245
 
246
246
  # Converts a x value into text with a max number of characters
247
- def convert_x_value_to_text(value, max_characters)
248
- if !@show_popup_x_y and @unix_epoch_x_values
249
- if (value > 1 and value < 2147483647)
250
- time = Time.at(value.to_f)
247
+ def convert_x_value_to_text(value, max_characters = @max_x_characters, full_date = false)
248
+ if !@show_popup_x_y && @unix_epoch_x_values
249
+ # Determine if the value is a time stamp and should be converted
250
+ if value > 1 && value < 2147483647
251
+ time = Time.at(value)
251
252
  time = time.utc if @utc_time
252
- text = time.formatted(false) # no year
253
+ if full_date
254
+ time.formatted # full date with day, month, year
255
+ else
256
+ time.formatted(false) # just hour, minutes, seconds
257
+ end
253
258
  else
254
- text = value.to_s
259
+ truncate_to_max(value.to_s, max_characters, value)
255
260
  end
256
261
  else
257
- text = value.to_s
262
+ truncate_to_max(value.to_s, max_characters, value)
258
263
  end
259
- truncate_to_max(text, max_characters, value)
260
264
  end
261
265
 
262
266
  # Converts a y value into text with a max number of characters
@@ -349,10 +353,46 @@ module Cosmos
349
353
  end
350
354
  legend_width += (GRAPH_SPACER * 2)
351
355
  legend_width *= 2 if @lines.axes == :BOTH
352
- legend_graph_x = (self.width - legend_width) / 2
353
356
 
354
- text_x = legend_graph_x + GRAPH_SPACER
355
- text_y = self.height - metrics.height
357
+ if @legend_position == :right
358
+ legend_height = 0
359
+ if @show_legend && !@lines.empty?
360
+ text_y = (self.height/2) - 1 - (GRAPH_SPACER * 2)
361
+ text_height = metrics.height
362
+ if @lines.axes == :BOTH
363
+ left_count = 0
364
+ right_count = 0
365
+ @lines.legend.each do |text, color, axis|
366
+ if axis == :LEFT
367
+ left_count += 1
368
+ else
369
+ right_count += 1
370
+ end
371
+ end
372
+ if left_count < right_count
373
+ text_y += text_height * (right_count/2)
374
+ else
375
+ text_y += text_height * (left_count/2)
376
+ end
377
+ else
378
+ text_y += text_height * (@lines.size/2)
379
+ end
380
+ legend_height = self.height - text_y - GRAPH_SPACER
381
+ end
382
+
383
+ legend_graph_x = self.width - legend_width - GRAPH_SPACER*3
384
+
385
+ char_width = metrics.width('W')
386
+ legend_graph_x -= (char_width + GRAPH_SPACER) if @right_y_axis_title
387
+
388
+ text_x = legend_graph_x + GRAPH_SPACER
389
+
390
+ else # @legend_position == :bottom or default
391
+ legend_graph_x = (self.width - legend_width) / 2
392
+
393
+ text_x = legend_graph_x + GRAPH_SPACER
394
+ text_y = self.height - metrics.height
395
+ end # @legend_position
356
396
  return [text_x, text_y, legend_width, metrics.height]
357
397
  end
358
398
 
@@ -462,9 +502,19 @@ module Cosmos
462
502
 
463
503
  def truncate_to_max(text, max_characters, value)
464
504
  if text.length > max_characters
505
+ # Transform the text into either decimal floating point or scientific
506
+ # notation, which ever results in a smaller string
465
507
  text = sprintf("%0.#{max_characters}g", value.to_f)
508
+ # If the value is still too big we need a smaller decimal
466
509
  if text.length > max_characters
467
- text = sprintf("%0.#{max_characters - 5}g", value.to_f)
510
+ # Subtract 5 to get the correct number of characters
511
+ # For example: sprintf("%0.8g", 9123123123.123) => 9.1231231e+09
512
+ # We wanted an 8 character string but ended up with 13. We need to
513
+ # remove 5 of the decimal places so subtract 5.
514
+ # sprintf("%0.3g", 9123123123.123) => 9.12e+09
515
+ precision = max_characters - 5
516
+ precision = 0 if precision < 0 # Protect against negative
517
+ text = sprintf("%0.#{precision}g", value.to_f)
468
518
  end
469
519
  end
470
520
  text
@@ -43,10 +43,11 @@ module Cosmos
43
43
  graph_x = scale_value_to_graph_x(x)
44
44
  graph_y = scale_value_to_graph_y(y, axis)
45
45
 
46
- x_text = convert_x_value_to_text(x_text.to_f, @max_x_characters)
47
46
  if @left_button_pressed
47
+ x_text = convert_x_value_to_text(x, 25, true) unless x_text
48
48
  popup_text = "(#{item}) #{x_text}, #{y_text}"
49
49
  else
50
+ x_text = convert_x_value_to_text(x) unless x_text
50
51
  popup_text = "#{x_text}, #{y_text}"
51
52
  end
52
53
 
@@ -26,7 +26,12 @@ module Cosmos
26
26
  end
27
27
 
28
28
  # Determine number of pixels to the right side of graph
29
- @graph_right_x = self.width - 6 * GRAPH_SPACER
29
+ if @show_legend and !@lines.empty? and @legend_position == :right
30
+ legend_x, legend_y, legend_width, legend_height = get_legend_position()
31
+ else
32
+ legend_width = 0
33
+ end
34
+ @graph_right_x = self.width - legend_width - 8 * GRAPH_SPACER
30
35
  if @right_y_axis_title
31
36
  @graph_right_x -= (metrics.width('W') + GRAPH_SPACER)
32
37
  end
@@ -48,8 +53,9 @@ module Cosmos
48
53
  x_axis_title_height = 0
49
54
  end
50
55
  x_axis_label_height = metrics.height + GRAPH_SPACER
56
+
51
57
  legend_height = 0
52
- if @show_legend && !@lines.empty?
58
+ if @show_legend and !@lines.empty? and @legend_position == :bottom
53
59
  text_y = self.height - 1 - (GRAPH_SPACER * 2)
54
60
  text_height = metrics.height
55
61
  if @lines.axes == :BOTH
@@ -315,7 +321,7 @@ module Cosmos
315
321
  end
316
322
  end # def build_x_grid_lines
317
323
 
318
- # Calculate the x gride lines for the graph
324
+ # Calculate the x grid lines for the graph
319
325
  def calculate_x_grid_lines
320
326
  if @manual_x_grid_line_scale
321
327
  # With manual grid lines, draw them all regardless of whether it will look nice
@@ -9,18 +9,73 @@
9
9
  # attribution addendums as found in the LICENSE.txt
10
10
 
11
11
  require 'cosmos'
12
- require 'cosmos/gui/qt_tool'
13
- require 'cosmos/gui/line_graph/line_graph_dialog'
12
+ Qt.execute_in_main_thread do
13
+ require 'cosmos/gui/qt_tool'
14
+ require 'cosmos/gui/line_graph/line_graph_dialog'
15
+ end
16
+
17
+ # Create a new graph object and populate
18
+ # plot (x, y, legend, [y,legend], [y,legend], ... , [opts])
19
+ # x - default => [0...y_array.length]
20
+ # y - Y data array to plot
21
+ # legend - Line Legend to describe Y data
22
+ # args - Additional y , legend pairs to plot
23
+ # opts - Hash options at the end of the argument list
24
+ # :width => 400 - default => 800
25
+ # :height => 300 - default => 600
26
+ # :x => 100 - default => -1 # Place centered in current screen
27
+ # :y => 100 - default => -1 # Place centered in current screen
28
+ # :winTitle => "Graph 1" - default => "Graph"
29
+ def plot (x = nil, y = nil, legend = "Line 1", *args)
30
+ my_opts = {:width => 800, :height => 600, :x => -1, :y => -1, :winTitle => "Graph"}
31
+
32
+ # Get the Hash options parameters from the end of the list of arguments
33
+ arg_idx = -1
34
+ while (args[arg_idx].is_a?(Hash)) do
35
+ my_opts.merge!(args[arg_idx])
36
+ arg_idx -= 1
37
+ end
38
+
39
+ if y
40
+ raise "Legend [0] must be a string" unless legend.kind_of? String
41
+ raise "Y [0] must be an array" unless y.kind_of? Array
42
+ end
43
+
44
+ # Split out the arguments for the other y arrays & legends
45
+ y_array = args[0..arg_idx].values_at(* args[0..arg_idx].each_index.select {|i| i.even?})
46
+ legend_array = args[0..arg_idx].values_at(* args[0..arg_idx].each_index.select {|i| i.odd?})
47
+
48
+ raise "Legend Argument List and Y Argument List not the same size" unless legend_array.length == y_array.length
49
+ (0...y_array.length).each do |i|
50
+ if y_array[i]
51
+ raise "Legend [#{i+1}] must be a string" unless legend_array[i].kind_of? String
52
+ raise "Y [#{i+1}] must be an array" unless y_array[i].kind_of? Array
53
+ end
54
+ end
14
55
 
15
- def plot(x, y1, y2 = nil)
56
+ my_line_graph = ''
16
57
  Qt.execute_in_main_thread do
17
- a = Cosmos::LineGraphDialog.new('Graph')
18
- a.line_graph.add_line('Data 1', y1, x, nil, nil, nil, nil, 'red')
19
- if y2
20
- a.line_graph.add_line('Data 2', y2, x, nil, nil, nil, nil, 'blue')
58
+ a = Cosmos::LineGraphDialog.new(my_opts[:winTitle], my_opts[:width], my_opts[:height])
59
+ if y
60
+ a.line_graph.add_line(legend, y, x, nil, nil, nil, nil, 'auto')
21
61
  end
62
+
63
+ (0...y_array.length).each do |i|
64
+ if y_array[i]
65
+ a.line_graph.add_line(legend_array[i], y_array[i], x, nil, nil, nil, nil, 'auto')
66
+ end
67
+ end
68
+
22
69
  a.raise
23
- a.exec
24
- a.dispose
70
+ a.show
71
+
72
+ my_line_graph = a.line_graph
73
+
74
+ # Move the window
75
+ if my_opts[:x] >= 0 && my_opts[:y] >= 0
76
+ a.move(my_opts[:x],my_opts[:y])
77
+ end
25
78
  end
79
+ return my_line_graph
26
80
  end
81
+
@@ -41,6 +41,11 @@ module Cosmos
41
41
  @lines.empty?
42
42
  end
43
43
 
44
+ # @return [Integer] Number of lines that are present
45
+ def num_lines
46
+ return @lines.length
47
+ end
48
+
44
49
  # @return [Boolean] true if there are lines on the left y axis
45
50
  def left_y_axis?
46
51
  !left().empty?
@@ -77,8 +82,8 @@ module Cosmos
77
82
  index = x_values.nearest_index(x_value, ordered_x_values)
78
83
  if (x_values[index] - x_value).abs < value_delta
79
84
  if y_values[index] >= min and y_values[index] <= max
80
- x_text = get_display_text(x_values[index], x_states, x_labels[index])
81
- y_text = get_display_text(y_values[index], y_states, y_labels[index])
85
+ x_text = get_display_text(x_values, x_states, x_labels, index)
86
+ y_text = get_display_text(y_values, y_states, y_labels, index)
82
87
  result << [x_values[index], y_values[index], x_text, y_text, item, color, axis]
83
88
  end
84
89
  end
@@ -130,16 +135,25 @@ module Cosmos
130
135
  @lines.each do |x_values, y_values, x_labels, y_labels, x_states, y_states, color|
131
136
  maximum, maximum_index = x_values.max_with_index
132
137
  line_max_values << maximum
133
- line_max_labels << x_labels[maximum_index]
134
138
  minimum, minimum_index = x_values.min_with_index
135
139
  line_min_values << minimum
136
- line_min_labels << x_labels[minimum_index]
140
+
141
+ # If there are labels then use them directly
142
+ if x_labels
143
+ line_max_labels << x_labels[maximum_index]
144
+ line_min_labels << x_labels[minimum_index]
145
+ else # Put in max and min as place holders
146
+ line_max_labels << maximum
147
+ line_min_labels << minimum
148
+ end
137
149
  end
138
150
  x_max, x_max_index = line_max_values.max_with_index
139
151
  x_min, x_min_index = line_min_values.min_with_index
140
152
  x_max_label = line_max_labels[x_max_index]
153
+ # If the label equals the max it was a placeholder so set to nil
141
154
  x_max_label = nil if x_max_label == x_max
142
155
  x_min_label = line_min_labels[x_min_index]
156
+ # If the label equals the min it was a placeholder so set to nil
143
157
  x_min_label = nil if x_min_label == x_min
144
158
 
145
159
  if x_min == x_max
@@ -155,14 +169,13 @@ module Cosmos
155
169
  return [x_min, x_max, x_min_label, x_max_label]
156
170
  end
157
171
 
158
- def get_display_text(key, states, label)
159
- text = label
172
+ def get_display_text(keys, states, labels, index)
173
+ text = nil
174
+ text = labels[index] if labels
160
175
  if states
161
- text = states.key(key)
176
+ text = states.key(keys[index])
162
177
  if text
163
- text = "#{text} (#{key})"
164
- else
165
- text = label
178
+ text = "#{text} (#{keys[index]})"
166
179
  end
167
180
  end
168
181
  return text
@@ -266,7 +279,7 @@ module Cosmos
266
279
  x = (1..(y.length)).to_a_to_f
267
280
  end
268
281
  y_labels = y unless y_labels
269
- x_labels = x unless x_labels
282
+ # x_labels are only set if the formatted time item is used
270
283
  y_states = y_states.clone if y_states
271
284
  x_states = x_states.clone if x_states
272
285
 
@@ -28,6 +28,7 @@ module Cosmos
28
28
  # routers allowed before dropping the packet.
29
29
  # @param write_timeout [Integer] Seconds to wait before aborting writes
30
30
  # @param read_timeout [Integer] Seconds to wait before aborting reads
31
+ # @param bind_address [String] Address to bind UDP ports to
31
32
  def initialize(hostname,
32
33
  write_dest_port,
33
34
  read_port,
@@ -35,7 +36,8 @@ module Cosmos
35
36
  interface_address = nil,
36
37
  ttl = 128, # default for Windows
37
38
  write_timeout = 10.0,
38
- read_timeout = nil)
39
+ read_timeout = nil,
40
+ bind_address = "0.0.0.0")
39
41
  super()
40
42
 
41
43
  @hostname = ConfigParser.handle_nil(hostname)
@@ -57,6 +59,8 @@ module Cosmos
57
59
  @write_timeout = @write_timeout.to_f if @write_timeout
58
60
  @read_timeout = ConfigParser.handle_nil(read_timeout)
59
61
  @read_timeout = @read_timeout.to_f if @read_timeout
62
+ @bind_address = ConfigParser.handle_nil(interface_address)
63
+ @bind_address = '127.0.0.1' if @bind_address and @bind_address.upcase == 'LOCALHOST'
60
64
  @write_socket = nil
61
65
  @read_socket = nil
62
66
  @read_allowed = false unless @read_port
@@ -72,8 +76,9 @@ module Cosmos
72
76
  @write_dest_port,
73
77
  @write_src_port,
74
78
  @interface_address,
75
- @ttl) if @write_dest_port
76
- @read_socket = UdpReadSocket.new(@read_port,@hostname,@interface_address) if @read_port
79
+ @ttl,
80
+ @bind_address) if @write_dest_port
81
+ @read_socket = UdpReadSocket.new(@read_port, @hostname, @interface_address, @bind_address) if @read_port
77
82
  end
78
83
 
79
84
  # @return [Boolean] Whether the active ports (read and/or write) have
@@ -240,7 +240,7 @@ module Cosmos
240
240
  parser.verify_num_parameters(1, nil, usage)
241
241
  background_task = Cosmos.require_class(params[0])
242
242
  if params[1]
243
- @background_tasks << background_task.new(params[1..-1])
243
+ @background_tasks << background_task.new(*params[1..-1])
244
244
  else
245
245
  @background_tasks << background_task.new
246
246
  end
@@ -1,8 +1,8 @@
1
1
  # encoding: ascii-8bit
2
-
3
2
  require 'cosmos/tools/tlm_viewer/widgets/array_widget.rb'
4
3
  require 'cosmos/tools/tlm_viewer/widgets/block_widget.rb'
5
4
  require 'cosmos/tools/tlm_viewer/widgets/button_widget.rb'
5
+ require 'cosmos/tools/tlm_viewer/widgets/canvasdot_widget.rb'
6
6
  require 'cosmos/tools/tlm_viewer/widgets/canvasimagevalue_widget.rb'
7
7
  require 'cosmos/tools/tlm_viewer/widgets/canvasimage_widget.rb'
8
8
  require 'cosmos/tools/tlm_viewer/widgets/canvaslabelvalue_widget.rb'
@@ -23,17 +23,22 @@ require 'cosmos/tools/tlm_viewer/widgets/labelprogressbar_widget.rb'
23
23
  require 'cosmos/tools/tlm_viewer/widgets/labeltrendlimitsbar_widget.rb'
24
24
  require 'cosmos/tools/tlm_viewer/widgets/labelvaluedesc_widget.rb'
25
25
  require 'cosmos/tools/tlm_viewer/widgets/labelvaluelimitsbar_widget.rb'
26
+ require 'cosmos/tools/tlm_viewer/widgets/labelvaluelimitscolumn_widget.rb'
26
27
  require 'cosmos/tools/tlm_viewer/widgets/labelvaluerangebar_widget.rb'
28
+ require 'cosmos/tools/tlm_viewer/widgets/labelvaluerangecolumn_widget.rb'
27
29
  require 'cosmos/tools/tlm_viewer/widgets/labelvalue_widget.rb'
28
30
  require 'cosmos/tools/tlm_viewer/widgets/label_widget.rb'
29
31
  require 'cosmos/tools/tlm_viewer/widgets/layout_widget.rb'
30
32
  require 'cosmos/tools/tlm_viewer/widgets/limitsbar_widget.rb'
33
+ require 'cosmos/tools/tlm_viewer/widgets/limitscolumn_widget.rb'
34
+ require 'cosmos/tools/tlm_viewer/widgets/limitscolor_widget.rb'
31
35
  require 'cosmos/tools/tlm_viewer/widgets/linegraph_widget.rb'
32
36
  require 'cosmos/tools/tlm_viewer/widgets/matrixbycolumns_widget.rb'
33
37
  require 'cosmos/tools/tlm_viewer/widgets/multi_widget.rb'
34
38
  require 'cosmos/tools/tlm_viewer/widgets/progressbar_widget.rb'
35
39
  require 'cosmos/tools/tlm_viewer/widgets/radiobutton_widget.rb'
36
40
  require 'cosmos/tools/tlm_viewer/widgets/rangebar_widget.rb'
41
+ require 'cosmos/tools/tlm_viewer/widgets/rangecolumn_widget.rb'
37
42
  require 'cosmos/tools/tlm_viewer/widgets/screenshotbutton_widget.rb'
38
43
  require 'cosmos/tools/tlm_viewer/widgets/scrollwindow_widget.rb'
39
44
  require 'cosmos/tools/tlm_viewer/widgets/sectionheader_widget.rb'
@@ -47,7 +52,9 @@ require 'cosmos/tools/tlm_viewer/widgets/trendbar_widget.rb'
47
52
  require 'cosmos/tools/tlm_viewer/widgets/trendlimitsbar_widget.rb'
48
53
  require 'cosmos/tools/tlm_viewer/widgets/value_widget.rb'
49
54
  require 'cosmos/tools/tlm_viewer/widgets/valuelimitsbar_widget.rb'
55
+ require 'cosmos/tools/tlm_viewer/widgets/valuelimitscolumn_widget.rb'
50
56
  require 'cosmos/tools/tlm_viewer/widgets/valuerangebar_widget.rb'
57
+ require 'cosmos/tools/tlm_viewer/widgets/valuerangecolumn_widget.rb'
51
58
  require 'cosmos/tools/tlm_viewer/widgets/verticalbox_widget.rb'
52
59
  require 'cosmos/tools/tlm_viewer/widgets/vertical_widget.rb'
53
60
  require 'cosmos/tools/tlm_viewer/widgets/widget.rb'
@@ -0,0 +1,79 @@
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
+
13
+ module Cosmos
14
+
15
+ class CanvasdotWidget
16
+ include Widget
17
+
18
+ def initialize(parent_layout, x, y, color='black', width=3)
19
+ super()
20
+ if is_numeric?(x)
21
+ @x = x.to_i
22
+ else
23
+ @x = x.to_s
24
+ end
25
+
26
+ if is_numeric?(y)
27
+ @y = y.to_i
28
+ else
29
+ @y = y.to_s
30
+ end
31
+
32
+ @point = Qt::Point.new(0, 0)
33
+ update_point
34
+
35
+ @width = width.to_i
36
+ @color = Cosmos::getColor(color)
37
+ parent_layout.add_repaint(self)
38
+ end # initialize
39
+
40
+ def update_point
41
+ if is_numeric?(@x)
42
+ @point.x = @x
43
+ else
44
+ @point.x = eval_str(@x)
45
+ end
46
+
47
+ if is_numeric?(@y)
48
+ @point.y = @y
49
+ else
50
+ @point.y = eval_str(@y)
51
+ end
52
+ end # update_point
53
+
54
+ def is_numeric?(obj)
55
+ obj.to_s.match(/\A[+-]?\d+?(\.\d+)?\Z/) == nil ? false : true
56
+ end
57
+
58
+ def paint(painter)
59
+ painter.save
60
+ painter.setBrush(@color)
61
+ painter.drawEllipse(@point, @width, @width)
62
+ painter.restore
63
+ end
64
+
65
+ def eval_str(string_to_eval)
66
+ @screen.instance_eval(string_to_eval)
67
+ end
68
+
69
+ def update_widget
70
+ update_point
71
+ end
72
+
73
+ def dispose
74
+ super()
75
+ @point.dispose
76
+ end
77
+ end # CanvasdotWidget
78
+
79
+ end # module Cosmos