cosmos 4.4.0 → 4.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (202) hide show
  1. checksums.yaml +5 -5
  2. data/.dockerignore +2 -0
  3. data/.gitignore +1 -0
  4. data/.travis.yml +6 -6
  5. data/Dockerfile +70 -0
  6. data/Manifest.txt +37 -2
  7. data/README.md +9 -0
  8. data/Rakefile +55 -5
  9. data/appveyor.yml +18 -8
  10. data/autohotkey/config/tools/cmd_sequence/cmd_sequence.txt +2 -0
  11. data/autohotkey/lib/cmd_sequence_exporter.rb +52 -0
  12. data/autohotkey/procedures/collect.rb +2 -2
  13. data/autohotkey/procedures/collect_util.rb +1 -1
  14. data/autohotkey/procedures/script_test.rb +1 -1
  15. data/autohotkey/tools/CmdSenderAHK2 +18 -0
  16. data/autohotkey/tools/cmd_extractor.ahk +11 -9
  17. data/autohotkey/tools/cmd_sender.ahk +35 -7
  18. data/autohotkey/tools/cmd_sender2.ahk +4 -0
  19. data/autohotkey/tools/cmd_sequence.ahk +22 -9
  20. data/autohotkey/tools/config_editor.ahk +4 -4
  21. data/autohotkey/tools/data_viewer.ahk +1 -1
  22. data/autohotkey/tools/limits_monitor.ahk +1 -1
  23. data/autohotkey/tools/packet_viewer.ahk +1 -1
  24. data/autohotkey/tools/script_runner.ahk +1 -1
  25. data/autohotkey/tools/test_runner2.ahk +1 -1
  26. data/autohotkey/tools/tlm_grapher.ahk +1 -1
  27. data/autohotkey/tools/tlm_grapher3.ahk +1 -1
  28. data/autohotkey/tools/tlm_viewer.ahk +1 -1
  29. data/autohotkey/tools/tlm_viewer2.ahk +1 -1
  30. data/autohotkey/tools/tlm_viewer5.ahk +1 -1
  31. data/bin/cstol_converter +1 -1
  32. data/bin/rubysloc +73 -28
  33. data/bin/xtce_converter +1 -1
  34. data/cosmos.gemspec +2 -2
  35. data/data/config/command_modifiers.yaml +16 -1
  36. data/data/config/interface_modifiers.yaml +3 -2
  37. data/data/config/param_item_modifiers.yaml +5 -0
  38. data/data/config/system.yaml +110 -23
  39. data/data/config/telemetry_modifiers.yaml +16 -1
  40. data/data/crc.txt +416 -411
  41. data/demo/Rakefile +4 -4
  42. data/demo/config/dart/Gemfile +1 -6
  43. data/demo/config/data/crc.txt +233 -232
  44. data/demo/config/system/system.txt +17 -6
  45. data/demo/config/system/system2.txt +17 -6
  46. data/demo/config/system/system_alt_ports.txt +17 -6
  47. data/demo/config/targets/INST/cmd_tlm/inst_cmds.txt +4 -4
  48. data/demo/config/targets/INST/cmd_tlm/inst_tlm.txt +4 -0
  49. data/demo/config/targets/INST/cmd_tlm/inst_tlm_override.txt +12 -0
  50. data/demo/config/targets/INST/lib/sim_inst.rb +2 -2
  51. data/demo/config/targets/INST/target.txt +1 -0
  52. data/demo/config/tools/handbook_creator/default_toc.xsl +59 -59
  53. data/demo/procedures/cosmos_api_test.rb +8 -8
  54. data/ext/cosmos/ext/buffered_file/buffered_file.c +2 -2
  55. data/ext/cosmos/ext/config_parser/config_parser.c +1 -2
  56. data/ext/cosmos/ext/line_graph/line_graph.c +53 -94
  57. data/ext/cosmos/ext/platform/platform.c +56 -21
  58. data/ext/cosmos/ext/polynomial_conversion/polynomial_conversion.c +4 -8
  59. data/ext/cosmos/ext/structure/structure.c +12 -0
  60. data/extensions/vscode/.gitignore +4 -0
  61. data/extensions/vscode/.vscode/launch.json +32 -0
  62. data/extensions/vscode/.vscode/settings.json +13 -0
  63. data/extensions/vscode/.vscode/tasks.json +79 -0
  64. data/extensions/vscode/License.txt +879 -0
  65. data/extensions/vscode/README.md +9 -0
  66. data/extensions/vscode/client/License.txt +879 -0
  67. data/extensions/vscode/client/README.md +39 -0
  68. data/extensions/vscode/client/cosmos.configuration.json +23 -0
  69. data/extensions/vscode/client/images/icon.png +0 -0
  70. data/extensions/vscode/client/package-lock.json +414 -0
  71. data/extensions/vscode/client/package.json +105 -0
  72. data/extensions/vscode/client/src/extension.ts +132 -0
  73. data/extensions/vscode/client/src/screen_preview.rb +25 -0
  74. data/extensions/vscode/client/syntaxes/cosmos.tmLanguage.json +219 -0
  75. data/extensions/vscode/client/tsconfig.json +17 -0
  76. data/extensions/vscode/package-lock.json +26 -0
  77. data/extensions/vscode/package.json +35 -0
  78. data/extensions/vscode/server/License.txt +879 -0
  79. data/extensions/vscode/server/package-lock.json +236 -0
  80. data/extensions/vscode/server/package.json +29 -0
  81. data/extensions/vscode/server/src/server.ts +59 -0
  82. data/extensions/vscode/server/tsconfig.json +16 -0
  83. data/install/Rakefile +4 -4
  84. data/install/config/dart/Gemfile +2 -7
  85. data/install/config/data/crc.txt +137 -137
  86. data/install/config/system/system.txt +17 -6
  87. data/install/config/tools/handbook_creator/default_toc.xsl +59 -59
  88. data/lib/cosmos/config/config_parser.rb +2 -10
  89. data/lib/cosmos/core_ext/class.rb +10 -0
  90. data/lib/cosmos/core_ext/time.rb +5 -3
  91. data/lib/cosmos/dart/config/boot.rb +1 -1
  92. data/lib/cosmos/dart/config/database.yml +2 -0
  93. data/lib/cosmos/dart/examples/dart_decom_client.rb +1 -1
  94. data/lib/cosmos/dart/lib/dart_common.rb +12 -5
  95. data/lib/cosmos/dart/lib/dart_constants.rb +15 -0
  96. data/lib/cosmos/dart/lib/dart_decom_query.rb +5 -6
  97. data/lib/cosmos/dart/lib/dart_decommutator.rb +64 -54
  98. data/lib/cosmos/dart/lib/dart_master_query.rb +71 -0
  99. data/lib/cosmos/dart/lib/dart_reducer_worker_thread.rb +165 -134
  100. data/lib/cosmos/dart/processes/dart.rb +4 -2
  101. data/lib/cosmos/dart/processes/dart_decom_server.rb +3 -3
  102. data/lib/cosmos/dart/processes/dart_ingester.rb +38 -1
  103. data/lib/cosmos/dart/processes/dart_master.rb +44 -0
  104. data/lib/cosmos/dart/processes/dart_util.rb +115 -0
  105. data/lib/cosmos/dart/spec/dart/dart_database_cleaner_spec.rb +2 -2
  106. data/lib/cosmos/gui/qt.rb +10 -10
  107. data/lib/cosmos/gui/qt_tool.rb +17 -12
  108. data/lib/cosmos/gui/text/completion_text_edit.rb +2 -0
  109. data/lib/cosmos/gui/widgets/dart_meta_frame.rb +22 -3
  110. data/lib/cosmos/interfaces/dart_status_interface.rb +1 -1
  111. data/lib/cosmos/interfaces/linc_interface.rb +3 -3
  112. data/lib/cosmos/interfaces/protocols/burst_protocol.rb +1 -1
  113. data/lib/cosmos/interfaces/protocols/crc_protocol.rb +1 -1
  114. data/lib/cosmos/interfaces/protocols/length_protocol.rb +5 -0
  115. data/lib/cosmos/interfaces/protocols/template_protocol.rb +3 -3
  116. data/lib/cosmos/interfaces/serial_interface.rb +7 -1
  117. data/lib/cosmos/interfaces/stream_interface.rb +1 -1
  118. data/lib/cosmos/interfaces/tcpip_server_interface.rb +16 -16
  119. data/lib/cosmos/io/io_multiplexer.rb +6 -2
  120. data/lib/cosmos/io/json_drb.rb +5 -5
  121. data/lib/cosmos/io/json_drb_object.rb +7 -2
  122. data/lib/cosmos/io/json_drb_rack.rb +25 -5
  123. data/lib/cosmos/io/json_rpc.rb +1 -1
  124. data/lib/cosmos/io/posix_serial_driver.rb +60 -22
  125. data/lib/cosmos/io/serial_driver.rb +11 -8
  126. data/lib/cosmos/io/win32_serial_driver.rb +31 -3
  127. data/lib/cosmos/packet_logs/packet_log_reader.rb +2 -2
  128. data/lib/cosmos/packets/packet.rb +9 -9
  129. data/lib/cosmos/packets/packet_config.rb +27 -9
  130. data/lib/cosmos/packets/parsers/xtce_converter.rb +10 -10
  131. data/lib/cosmos/packets/parsers/xtce_parser.rb +3 -0
  132. data/lib/cosmos/packets/structure.rb +35 -5
  133. data/lib/cosmos/packets/structure_item.rb +5 -1
  134. data/lib/cosmos/packets/telemetry.rb +7 -1
  135. data/lib/cosmos/script/api_shared.rb +18 -1
  136. data/lib/cosmos/script/extract.rb +1 -1
  137. data/lib/cosmos/script/script.rb +4 -11
  138. data/lib/cosmos/streams/serial_stream.rb +11 -6
  139. data/lib/cosmos/system/system.rb +155 -57
  140. data/lib/cosmos/tools/cmd_sender/cmd_param_table_item_delegate.rb +15 -0
  141. data/lib/cosmos/tools/cmd_sender/cmd_params.rb +382 -0
  142. data/lib/cosmos/tools/cmd_sender/cmd_sender.rb +29 -318
  143. data/lib/cosmos/tools/cmd_sequence/cmd_sequence.rb +14 -17
  144. data/lib/cosmos/tools/cmd_sequence/sequence_item.rb +38 -331
  145. data/lib/cosmos/tools/cmd_sequence/sequence_list.rb +16 -11
  146. data/lib/cosmos/tools/cmd_tlm_server/api.rb +10 -8
  147. data/lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server.rb +2 -2
  148. data/lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server_gui.rb +1 -0
  149. data/lib/cosmos/tools/cmd_tlm_server/gui/logging_tab.rb +1 -1
  150. data/lib/cosmos/tools/cmd_tlm_server/interface_thread.rb +29 -26
  151. data/lib/cosmos/tools/cmd_tlm_server/limits_groups_background_task.rb +1 -1
  152. data/lib/cosmos/tools/cmd_tlm_server/router_thread.rb +5 -0
  153. data/lib/cosmos/tools/config_editor/config_editor.rb +34 -3
  154. data/lib/cosmos/tools/config_editor/config_editor_frame.rb +8 -9
  155. data/lib/cosmos/tools/config_editor/system_config_dialog.rb +158 -0
  156. data/lib/cosmos/tools/handbook_creator/handbook_creator.rb +1 -1
  157. data/lib/cosmos/tools/handbook_creator/handbook_creator_config.rb +1 -1
  158. data/lib/cosmos/tools/script_runner/script_runner_frame.rb +7 -4
  159. data/lib/cosmos/tools/test_runner/test.rb +6 -3
  160. data/lib/cosmos/tools/test_runner/test_runner.rb +6 -6
  161. data/lib/cosmos/tools/tlm_extractor/tlm_extractor.rb +3 -3
  162. data/lib/cosmos/tools/tlm_extractor/tlm_extractor_config.rb +1 -4
  163. data/lib/cosmos/tools/tlm_extractor/tlm_extractor_processor.rb +20 -16
  164. data/lib/cosmos/tools/tlm_grapher/tabbed_plots_tool/tabbed_plots_dart_thread.rb +21 -17
  165. data/lib/cosmos/tools/tlm_grapher/tlm_grapher.rb +18 -11
  166. data/lib/cosmos/tools/tlm_viewer/tlm_viewer.rb +17 -6
  167. data/lib/cosmos/tools/tlm_viewer/widgets/canvasdot_widget.rb +2 -0
  168. data/lib/cosmos/top_level.rb +1 -1
  169. data/lib/cosmos/utilities/ruby_lex_utils.rb +34 -30
  170. data/lib/cosmos/utilities/simulated_target.rb +1 -1
  171. data/lib/cosmos/version.rb +5 -5
  172. data/lib/cosmos/win32/excel.rb +23 -17
  173. data/run_gui_tests.bat +1 -0
  174. data/spec/core_ext/class_spec.rb +54 -0
  175. data/spec/core_ext/socket_spec.rb +1 -1
  176. data/spec/core_ext/time_spec.rb +4 -0
  177. data/spec/install/yaml_docs_spec.rb +26 -6
  178. data/spec/interfaces/linc_interface_spec.rb +1 -1
  179. data/spec/interfaces/protocols/length_protocol_spec.rb +39 -0
  180. data/spec/interfaces/serial_interface_spec.rb +1 -5
  181. data/spec/io/json_drb_rack_spec.rb +166 -0
  182. data/spec/io/json_drb_spec.rb +14 -0
  183. data/spec/io/json_rpc_spec.rb +4 -5
  184. data/spec/io/posix_serial_driver_spec.rb +81 -0
  185. data/spec/io/win32_serial_driver_spec.rb +33 -3
  186. data/spec/packet_logs/packet_log_reader_spec.rb +36 -37
  187. data/spec/packets/structure_spec.rb +52 -2
  188. data/spec/packets/telemetry_spec.rb +29 -1
  189. data/spec/script/extract_spec.rb +4 -1
  190. data/spec/system/system_spec.rb +111 -3
  191. data/spec/tools/cmd_tlm_server/api_spec.rb +12 -12
  192. data/spec/tools/cmd_tlm_server/background_tasks_spec.rb +2 -2
  193. data/spec/tools/cmd_tlm_server/interface_thread_spec.rb +4 -3
  194. data/spec/tools/cmd_tlm_server/router_thread_spec.rb +2 -3
  195. data/spec/utilities/logger_spec.rb +3 -3
  196. data/spec/utilities/message_log_spec.rb +6 -3
  197. data/tasks/gemfile_stats.rake +22 -13
  198. data/test/performance/Rakefile +4 -4
  199. data/test/performance/config/data/crc.txt +67 -48
  200. metadata +52 -11
  201. data/demo/outputs/dart/logs/README.txt +0 -1
  202. data/lib/cosmos/dart/Gemfile +0 -69
@@ -0,0 +1,382 @@
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'
12
+ Cosmos.catch_fatal_exception do
13
+ require 'cosmos/tools/cmd_sender/cmd_param_table_item_delegate'
14
+ require 'cosmos/gui/dialogs/cmd_details_dialog'
15
+ end
16
+
17
+ module Cosmos
18
+ # Builds a command parameter widget for use in Command Sender and Command Sequence.
19
+ # The main method is update_cmd_params which builds all the widgets. It can take
20
+ # existing values for use in populating the command parameter widgets.
21
+ class CmdParams < Qt::Widget
22
+ # Class instance variables which apply to all command parameters
23
+ @states_in_hex = false
24
+ @show_ignored = false
25
+ class << self
26
+ attr_accessor :states_in_hex, :show_ignored
27
+ end
28
+ MANUALLY = CmdParamTableItemDelegate::MANUALLY
29
+ # Emit the modified signal to allow changes to propagate upwards
30
+ signals 'modified()'
31
+
32
+ def initialize
33
+ super()
34
+ @param_widgets = []
35
+ @table = nil
36
+ @packet = nil
37
+ @file_dir = System.paths['LOGS']
38
+ end
39
+
40
+ # Changes the display of items with states to hex if checked is true.
41
+ # Otherwise state values are displayed as decimal.
42
+ # @param checked [Boolean] Whether to display state values in hex
43
+ def states_in_hex(checked)
44
+ CmdParams.states_in_hex = checked
45
+ @param_widgets.each do |_, _, state_value_item|
46
+ next unless state_value_item
47
+ text = state_value_item.text
48
+ quotes_removed = text.remove_quotes
49
+ if text == quotes_removed
50
+ if checked
51
+ if text.is_int?
52
+ @table.blockSignals(true)
53
+ state_value_item.text = sprintf("0x%X", text.to_i)
54
+ @table.blockSignals(false)
55
+ end
56
+ else
57
+ if text.is_hex?
58
+ @table.blockSignals(true)
59
+ state_value_item.text = Integer(text).to_s
60
+ @table.blockSignals(false)
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
66
+
67
+ # @return [Hash] Hash keyed by parameter name with String formatted value
68
+ def params_text(raw = false)
69
+ params = {}
70
+ Qt.execute_in_main_thread do
71
+ @param_widgets.each do |packet_item, value_item, state_value_item|
72
+ text = value_item.text
73
+ text = state_value_item.text if state_value_item && (text == MANUALLY or raw)
74
+ quotes_removed = text.remove_quotes
75
+ if text == quotes_removed
76
+ if (packet_item.data_type == :STRING or packet_item.data_type == :BLOCK) and text.upcase.start_with?("0X")
77
+ params[packet_item.name] = text.hex_to_byte_string
78
+ else
79
+ params[packet_item.name] = text.convert_to_value
80
+ end
81
+ else
82
+ params[packet_item.name] = quotes_removed
83
+ end
84
+ Kernel.raise "#{packet_item.name} is required." if quotes_removed == '' && packet_item.required
85
+ end
86
+ end
87
+ params
88
+ end
89
+
90
+ # Primary method which builds the command parameter table. The passed in command packet
91
+ # is used to get all the command parameters to build. Existing parameters can be passed
92
+ # in to set the initial values for all command parameters. You can also specify whether
93
+ # to display the ignored parameters when building the command parameter table. Note that
94
+ # each time this method is called the TableWidget is disposed and rebuilt.
95
+ #
96
+ # @param packet [Packet] The command packet to build a parameter list for
97
+ # @param existing [Hash] Hash keyed by parameter name with text values.
98
+ # These values will be used as the defaults for all command parameters.
99
+ # @param show_ignored [Boolean] Whether to display the ignored
100
+ # parameters. Pass nil (the default) to keep the existing setting.
101
+ def update_cmd_params(packet, existing: nil, show_ignored: nil)
102
+ @packet = packet
103
+ old_params = {}
104
+ old_params = get_params(show_ignored) if !show_ignored.nil?
105
+ old_params = set_existing(packet, existing) if existing
106
+
107
+ # Determine which items to display
108
+ target = System.targets[packet.target_name]
109
+ packet_items = packet.sorted_items
110
+ shown_packet_items = []
111
+ packet_items.each do |packet_item|
112
+ next if target && target.ignored_parameters.include?(packet_item.name) && !CmdParams.show_ignored
113
+ shown_packet_items << packet_item
114
+ end
115
+
116
+ # Destroy the old table widget and parameters
117
+ @table.dispose if @table
118
+ @table = nil
119
+ @param_widgets = []
120
+ row = 0
121
+ shown_packet_items.each do |packet_item|
122
+ value_item = nil
123
+ state_value_item = nil
124
+ @table = create_table(shown_packet_items.length) unless @table
125
+
126
+ # Parameter Name
127
+ item = Qt::TableWidgetItem.new("#{packet_item.name}:")
128
+ item.setTextAlignment(Qt::AlignRight | Qt::AlignVCenter)
129
+ item.setFlags(Qt::NoItemFlags | Qt::ItemIsSelectable | Qt::ItemIsEnabled)
130
+ @table.setItem(row, 0, item)
131
+
132
+ # Parameter Value
133
+ if packet_item.states
134
+ value_item, state_value_item = create_state_item(packet_item, old_params, row)
135
+ else
136
+ value_item = create_item(packet_item, old_params, row)
137
+ end
138
+
139
+ # Units
140
+ item = Qt::TableWidgetItem.new(packet_item.units.to_s)
141
+ item.setTextAlignment(Qt::AlignRight | Qt::AlignVCenter)
142
+ item.setFlags(Qt::NoItemFlags | Qt::ItemIsSelectable | Qt::ItemIsEnabled)
143
+ @table.setItem(row, 3, item)
144
+
145
+ # Description
146
+ item = Qt::TableWidgetItem.new(packet_item.description.to_s)
147
+ item.setTextAlignment(Qt::AlignLeft | Qt::AlignVCenter)
148
+ item.setFlags(Qt::NoItemFlags | Qt::ItemIsSelectable | Qt::ItemIsEnabled)
149
+ @table.setItem(row, 4, item)
150
+
151
+ @param_widgets << [packet_item, value_item, state_value_item]
152
+ row += 1
153
+ end
154
+
155
+ connect_table_item_changed() if @table
156
+ @table
157
+ end
158
+
159
+ # If the user right clicks over a table item, this method displays a context
160
+ # menu with various options.
161
+ # @param point [Qt::Point] Point to display the context menu
162
+ def context_menu(point)
163
+ item = @table.itemAt(point)
164
+ if item
165
+ target_name = @packet.target_name
166
+ packet_name = @packet.packet_name
167
+ item_name = @table.item(item.row, 0).text[0..-2] # Remove :
168
+ if target_name.length > 0 && packet_name.length > 0 && item_name.length > 0
169
+ menu = Qt::Menu.new()
170
+
171
+ details_action = Qt::Action.new("Details #{target_name} #{packet_name} #{item_name}", self)
172
+ details_action.statusTip = "Popup details about #{target_name} #{packet_name} #{item_name}"
173
+ details_action.connect(SIGNAL('triggered()')) do
174
+ CmdDetailsDialog.new(nil, target_name, packet_name, item_name)
175
+ end
176
+ menu.addAction(details_action)
177
+
178
+ file_chooser_action = Qt::Action.new("Insert Filename", self)
179
+ file_chooser_action.statusTip = "Select a file and place its name into this parameter"
180
+ file_chooser_action.connect(SIGNAL('triggered()')) do
181
+ filename = Qt::FileDialog::getOpenFileName(self, "Insert Filename:", @file_dir, "All Files (*)")
182
+ if filename && !filename.empty?
183
+ @file_dir = File.dirname(filename)
184
+ _, value_item, state_value_item = @param_widgets[item.row]
185
+ if state_value_item
186
+ state_value_item.setText(filename)
187
+ elsif value_item
188
+ value_item.setText(filename)
189
+ end
190
+ end
191
+ end
192
+ menu.addAction(file_chooser_action)
193
+
194
+ menu.exec(@table.mapToGlobal(point))
195
+ menu.dispose
196
+ end
197
+ end
198
+ end
199
+
200
+ private
201
+
202
+ def get_params(show_ignored)
203
+ params = {}
204
+ CmdParams.show_ignored = show_ignored
205
+ # Save parameter values
206
+ @param_widgets.each do |packet_item, value_item, state_value_item|
207
+ text = value_item.text
208
+ if state_value_item
209
+ params[packet_item.name] = [text, state_value_item.text]
210
+ else
211
+ params[packet_item.name] = text
212
+ end
213
+ end
214
+ params
215
+ end
216
+
217
+ def set_existing(packet, existing)
218
+ params = {}
219
+ existing.each do |param_name, param_value|
220
+ packet_item = packet.items[param_name]
221
+ if packet_item.states
222
+ state_value = packet_item.states[param_value]
223
+ unless state_value # If we couldn't lookup the value by the name it's manual
224
+ state_value = param_value
225
+ param_value = MANUALLY
226
+ end
227
+ params[param_name] = [param_value.to_s, state_value.to_s]
228
+ else
229
+ params[param_name] = param_value.to_s
230
+ end
231
+ end
232
+ params
233
+ end
234
+
235
+ def create_table(length)
236
+ table = Qt::TableWidget.new()
237
+ table.setSizePolicy(Qt::SizePolicy::Expanding, Qt::SizePolicy::Expanding)
238
+ table.setWordWrap(true)
239
+ table.setRowCount(length)
240
+ table.setColumnCount(5)
241
+ table.setHorizontalHeaderLabels(['Name', ' Value or State ', ' ', 'Units', 'Description'])
242
+ table.horizontalHeader.setStretchLastSection(true)
243
+ table.verticalHeader.setVisible(false)
244
+ table.setItemDelegate(CmdParamTableItemDelegate.new(table, @param_widgets, @production))
245
+ table.setContextMenuPolicy(Qt::CustomContextMenu)
246
+ table.verticalHeader.setResizeMode(Qt::HeaderView::ResizeToContents)
247
+ table.setEditTriggers(Qt::AbstractItemView::DoubleClicked | Qt::AbstractItemView::SelectedClicked | Qt::AbstractItemView::AnyKeyPressed)
248
+ table.setSelectionMode(Qt::AbstractItemView::NoSelection)
249
+ table.connect(SIGNAL('customContextMenuRequested(const QPoint&)')) {|point| context_menu(point) }
250
+ table.connect(SIGNAL('itemClicked(QTableWidgetItem*)')) do |item|
251
+ table.editItem(item) if (item.flags & Qt::ItemIsEditable) != 0
252
+ end
253
+ return table
254
+ end
255
+
256
+ def create_state_item(packet_item, old_params, row)
257
+ default_state = packet_item.states.key(packet_item.default)
258
+ if old_params[packet_item.name]
259
+ value_item = Qt::TableWidgetItem.new(old_params[packet_item.name][0])
260
+ else
261
+ if default_state
262
+ value_item = Qt::TableWidgetItem.new(default_state.to_s)
263
+ elsif @production
264
+ value_item = Qt::TableWidgetItem.new(packet_item.states.keys[0])
265
+ else
266
+ value_item = Qt::TableWidgetItem.new(MANUALLY)
267
+ end
268
+ end
269
+ value_item.setTextAlignment(Qt::AlignRight | Qt::AlignVCenter)
270
+ value_item.setFlags(Qt::NoItemFlags | Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable)
271
+ @table.setItem(row, 1, value_item)
272
+
273
+ state_value = packet_item.default.to_s
274
+ if old_params[packet_item.name]
275
+ state_value = old_params[packet_item.name][1]
276
+ end
277
+ is_integer = Integer(state_value) rescue false
278
+ if CmdParams.states_in_hex && is_integer
279
+ state_value_item = Qt::TableWidgetItem.new(sprintf("0x%X", state_value))
280
+ else
281
+ if state_value.is_printable?
282
+ state_value_item = Qt::TableWidgetItem.new(state_value)
283
+ else
284
+ state_value_item = Qt::TableWidgetItem.new("0x" + state_value.simple_formatted)
285
+ end
286
+ end
287
+ state_value_item.setTextAlignment(Qt::AlignRight | Qt::AlignVCenter)
288
+ if @production
289
+ state_value_item.setFlags(Qt::NoItemFlags)
290
+ else
291
+ state_value_item.setFlags(Qt::NoItemFlags | Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable)
292
+ end
293
+ @table.setItem(row, 2, state_value_item)
294
+
295
+ # If the parameter is required clear the combobox and
296
+ # clear the value field so they have to choose something
297
+ if packet_item.required && !old_params[packet_item.name]
298
+ value_item.setText('')
299
+ state_value_item.setText('')
300
+ end
301
+ return [value_item, state_value_item]
302
+ end
303
+
304
+ def create_item(packet_item, old_params, row)
305
+ if old_params[packet_item.name]
306
+ value_text = old_params[packet_item.name]
307
+ elsif packet_item.required
308
+ value_text = ''
309
+ else
310
+ if packet_item.format_string
311
+ begin
312
+ value_text = sprintf(packet_item.format_string, packet_item.default)
313
+ rescue
314
+ # Oh well - Don't use the format string
315
+ value_text = packet_item.default.to_s
316
+ end
317
+ else
318
+ value_text = packet_item.default.to_s
319
+ end
320
+ end
321
+ if !value_text.is_printable?
322
+ value_text = "0x" + value_text.simple_formatted
323
+ # Add quotes around STRING or BLOCK defaults so they are interpreted correctly
324
+ elsif (packet_item.data_type == :STRING or packet_item.data_type == :BLOCK)
325
+ value_text = "'#{value_text}'"
326
+ end
327
+ value_item = Qt::TableWidgetItem.new(value_text)
328
+ value_item.setTextAlignment(Qt::AlignRight | Qt::AlignVCenter)
329
+ value_item.setFlags(Qt::NoItemFlags | Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable)
330
+ @table.setItem(row, 1, value_item)
331
+ @table.setSpan(row, 1, 1, 2)
332
+ return value_item
333
+ end
334
+
335
+ def connect_table_item_changed
336
+ @table.connect(SIGNAL('itemChanged(QTableWidgetItem*)')) do |item|
337
+ packet_item, value_item, state_value_item = @param_widgets[item.row]
338
+ if item.column == 1
339
+ if packet_item.states
340
+ value = packet_item.states[value_item.text]
341
+ if packet_item.hazardous && packet_item.hazardous.key?(value_item.text)
342
+ desc = packet_item.hazardous[value]
343
+ # Hazardous states aren't required to have a description so use the item description
344
+ desc = packet_item.description unless desc
345
+ @table.item(item.row, 4).setText("(Hazardous) #{desc}")
346
+ else
347
+ @table.item(item.row, 4).setText(packet_item.description)
348
+ end
349
+ @table.blockSignals(true)
350
+ if CmdParams.states_in_hex && value.kind_of?(Integer)
351
+ state_value_item.setText(sprintf("0x%X", value))
352
+ else
353
+ state_value_item.setText(value.to_s)
354
+ end
355
+ @table.blockSignals(false)
356
+ end
357
+ elsif item.column == 2
358
+ @table.blockSignals(true)
359
+ @table.item(item.row, 1).setText(MANUALLY)
360
+ @table.blockSignals(false)
361
+ end
362
+ calculate_height()
363
+ emit modified()
364
+ end
365
+ calculate_height()
366
+ end
367
+
368
+ def calculate_height
369
+ @table.resizeColumnsToContents()
370
+ @table.resizeRowsToContents()
371
+ height = @table.horizontalHeader.height + 2 # 2 = Header frame?
372
+ @table.rowCount.times do |i|
373
+ # TODO: rowHeight does not reflect word wrapping ... it's always 37
374
+ height += @table.rowHeight(i)
375
+ # NOTE: Checking the fontMetrics boundingRect also does not refect word wrapping
376
+ # e.g. Cosmos.getFontMetrics(@table.font).boundingRect(@table.item(x,y).text).height
377
+ end
378
+ @table.setMaximumHeight(height)
379
+ @table.setMinimumHeight(height)
380
+ end
381
+ end
382
+ end