Skip to content

Commit

Permalink
Merge pull request #120 from BallAerospace/handbook_creator_ignore
Browse files Browse the repository at this point in the history
Add Hide ignored option to HandbookCreator re#23
  • Loading branch information
jmthomas committed Apr 24, 2015
2 parents a55f2bd + 325bde3 commit 9a5a2f7
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 23 deletions.
9 changes: 9 additions & 0 deletions autohotkey/tools/handbook_creator.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,14 @@ Click 55 165 ; Open in browser HC-4
Sleep 2000
WinActivate Handbook Creator
Sleep 500
Send ^h ; Hide ignored parameters / items
Sleep 500
Click 55 75 ; Create HTML HC-1
WinWaitActive Done
Send {Enter}
WinWaitActive Handbook Creator
Click 55 165 ; Open in browser HC-4
Sleep 2000
WinActivate Handbook Creator
Send ^q

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<h2><%= "#{packet.target_name} #{packet.packet_name}" %></h2>
<div><span style="font-size:18px;background:#555555;color:white;"><%= packet.hazardous ? 'Hazardous' : '' %></span></div>
<div><%= packet.description %></div>
<% items = packet.sorted_items.reject{|item| ignored[packet.target_name].include? item.name} %>
<% next if items.empty? %>
<table class="table table-striped">
<thead>
<tr>
Expand All @@ -19,7 +21,7 @@
</tr>
<thead>
<tbody>
<% packet.sorted_items.each do |item| %>
<% items.each do |item| %>
<tr>
<td>
<%= item.name %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<div id="tlm_<%= "#{packet.target_name}_#{packet.packet_name}" %>">
<h2><%= "#{packet.target_name} #{packet.packet_name}" %></h2>
<div><%= packet.description %></div>
<% items = packet.sorted_items.reject{|item| ignored[packet.target_name].include? item.name} %>
<% next if items.empty? %>
<table class="table table-striped">
<thead>
<tr>
Expand All @@ -16,7 +18,7 @@
</tr>
<thead>
<tbody>
<% packet.sorted_items.each do |item| %>
<% items.each do |item| %>
<tr>
<td><%= item.name %></td>
<td>
Expand Down
23 changes: 15 additions & 8 deletions lib/cosmos/tools/handbook_creator/handbook_creator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

module Cosmos

# Creates command and telemetry handbooks from the COSMOS definitions in both
# HTML and PDF format.
# Creates command and telemetry handbooks from the COSMOS definitions in
# both HTML and PDF format.
class HandbookCreator < QtTool

def initialize (options)
Expand All @@ -42,23 +42,30 @@ def initialize (options)

def initialize_actions
super()
@hide_ignored_action = Qt::Action.new(tr('&Hide Ignored Items'), self)
@hide_ignored_keyseq = Qt::KeySequence.new(tr('Ctrl+H'))
@hide_ignored_action.shortcut = @hide_ignored_keyseq
@hide_ignored_action.statusTip = tr('Do not include ignored items in command and telemetry handbooks')
@hide_ignored_action.setCheckable(true)
@hide_ignored_action.setChecked(false)
end

def initialize_menus
# File Menu
@file_menu = menuBar.addMenu(tr('&File'))
@file_menu.addAction(@hide_ignored_action)
@file_menu.addAction(@exit_action)

# Help Menu
@about_string = "Handbook Creator creates Command and Telemetry Handbooks"
initialize_help_menu()
end

def create_pdfs(both = false)
def create_pdfs(both, hide_ignored)
success = false
ProgressDialog.execute(self, 'PDF Creation Progress', 700, 600, true, false, true, true, false) do |progress_dialog|
begin
success = @config.create_pdf(progress_dialog)
success = @config.create_pdf(hide_ignored, progress_dialog)
if success
msg = "\n\n"
msg << "HTML and " if both
Expand Down Expand Up @@ -88,7 +95,7 @@ def initialize_central_widget
@html_button.setStyleSheet("text-align:left")
@html_button.connect(SIGNAL('clicked()')) do
begin
@config.create_html
@config.create_html(@hide_ignored_action.isChecked)
Qt::MessageBox.information(self, 'Done', 'HTML Handbooks created successfully')
rescue Exception => err
Cosmos.handle_critical_exception(err)
Expand All @@ -99,16 +106,16 @@ def initialize_central_widget
@pdf_button = Qt::PushButton.new(Cosmos.get_icon('pdf-32.png'), 'Create PDF Handbooks')
@pdf_button.setStyleSheet("text-align:left")
@pdf_button.connect(SIGNAL('clicked()')) do
create_pdfs()
create_pdfs(false, @hide_ignored_action.isChecked)
end
@top_layout.addWidget(@pdf_button)

@html_pdf_button = Qt::PushButton.new('Create HTML and PDF Handbooks')
@html_pdf_button.setStyleSheet("text-align:left")
@html_pdf_button.connect(SIGNAL('clicked()')) do
begin
@config.create_html
create_pdfs(true)
@config.create_html(@hide_ignored_action.isChecked)
create_pdfs(true, @hide_ignored_action.isChecked)
rescue Exception => err
Cosmos.handle_critical_exception(err)
end
Expand Down
54 changes: 41 additions & 13 deletions lib/cosmos/tools/handbook_creator/handbook_creator_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ def add_section(section)
@sections << section
end

def create_html
def create_html(hide_ignored)
@hide_ignored = hide_ignored
Cosmos.set_working_dir do
if @type == :TARGETS
target_names = @target_names
Expand All @@ -77,7 +78,8 @@ def create_html
end
end

def create_pdf(progress_dialog = nil)
def create_pdf(hide_ignored, progress_dialog = nil)
@hide_ignored = hide_ignored
if @pdf
if progress_dialog
Qt.execute_in_main_thread(true) do
Expand Down Expand Up @@ -169,19 +171,45 @@ def create_file_internal(file, target_names, target_pages, output)
if section.output != :ALL
next unless section.output == output
end
packets = []
packets = build_packets(System.commands, target_names) if section.type == :CMD
packets = build_packets(System.telemetry, target_names) if section.type == :TLM
packets = build_packets(section.type, target_names)
ignored = build_ignored(section.type, target_names)
if target_pages
section.create(file, target_names[0] + ' ' + section.title.to_s, packets)
section.create(file, target_names[0] + ' ' + section.title.to_s, packets, ignored)
else
section.create(file, section.title.to_s, packets)
section.create(file, section.title.to_s, packets, ignored)
end
end
end

def build_packets(packet_accessor, target_names)
def build_ignored(type, target_names)
ignored = {}
target_names = System.targets.keys if target_names.empty?
target_names.each do |name|
if @hide_ignored
if type == :CMD
ignored[name] = System.targets[name].ignored_parameters
elsif type == :TLM
ignored[name] = System.targets[name].ignored_items
end
else
# If we're not ignoring items the hash contains an empty array
ignored[name] = []
end
end
ignored
end

def build_packets(type, target_names)
packets = []
case type
when :CMD
packet_accessor = System.commands
when :TLM
packet_accessor = System.telemetry
else
# Return the empty array because there are no packets
return packets
end
if target_names.empty?
packet_accessor.all.sort.each do |target_name, target_packets|
target_packets.sort.each do |packet_name, packet|
Expand Down Expand Up @@ -221,7 +249,7 @@ def initialize(output, filename, title, type = :NONE)
@type = type
end

def create(file, title, packets = [])
def create(file, title, packets = [], ignored = {})
file.puts ERB.new(File.read(@filename)).result(binding)
end

Expand All @@ -235,15 +263,15 @@ def initialize(filename)
process_file(filename)
end

def create_html
@pages.each {|page| page.create_html}
def create_html(hide_ignored)
@pages.each {|page| page.create_html(hide_ignored)}
end

def create_pdf(progress_dialog = nil)
def create_pdf(hide_ignored, progress_dialog = nil)
begin
@pages.each_with_index do |page, index|
progress_dialog.set_overall_progress(index.to_f / @pages.length.to_f) if progress_dialog
page.create_pdf(progress_dialog)
page.create_pdf(hide_ignored, progress_dialog)
end
progress_dialog.set_overall_progress(1.0) if progress_dialog
rescue Exception => err
Expand Down

0 comments on commit 9a5a2f7

Please sign in to comment.