Class: Ui::RelationsView

Inherits:
Ui_RelationsView show all
Defined in:
lib/roby/log/gui/relations_view.rb,
lib/roby/log/gui/relations_view_ui.rb

Constant Summary collapse

ZOOM_STEP =
0.25

Instance Attribute Summary collapse

Attributes inherited from Ui_RelationsView

#actionBookmarksAdd, #actionFit, #actionHideFinalized, #actionKeepSignals, #actionOwnership, #actionPrefixAdd, #actionPrint, #actionRedraw, #actionSVGExport, #actionShowAll, #actionUnzoom, #actionZoom, #centralwidget, #graphics, #menuRemovedPrefixes, #menuTask_labels, #menuView, #menubar, #vboxLayout

Instance Method Summary collapse

Methods inherited from Ui_RelationsView

#retranslateUi, #retranslate_ui, #setup_ui

Instance Attribute Details

#displayObject (readonly)

Returns the value of attribute display.



5
6
7
# File 'lib/roby/log/gui/relations_view.rb', line 5

def display
  @display
end

#prefixActionsObject (readonly)

Returns the value of attribute prefixActions.



6
7
8
# File 'lib/roby/log/gui/relations_view.rb', line 6

def prefixActions
  @prefixActions
end

Instance Method Details

#config_pathObject



8
9
10
# File 'lib/roby/log/gui/relations_view.rb', line 8

def config_path
  "#{display.decoder.name}-events.yml"
end

#load_configObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/roby/log/gui/relations_view.rb', line 12

def load_config
  if File.readable?(config_path)
 STDERR.puts "Loading config from #{config_path}"
 config_data = File.open(config_path) do |io|
    YAML.load(io)
 end

 display.removed_prefixes.clear
 if removed_prefixes_config = config_data['prefixes']
    removed_prefixes_config.each do |name, enabled|
  display.removed_prefixes[name] = enabled
    end
 end
  else
 STDERR.puts "No such config file #{config_path}"
  end
end

#save_configObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/roby/log/gui/relations_view.rb', line 29

def save_config
  STDERR.puts "Saving config into #{display.decoder.name}-events.yml"
  config = { 'prefixes' => Hash.new }
  display.removed_prefixes.each do |name, enabled|
 config['prefixes'][name] = enabled
  end
  config['show_ownership'] = display.show_ownership
  config['show_arguments'] = display.show_arguments
  config['hide_finalized'] = display.hide_finalized

  File.open(config_path, 'w') do |io|
 YAML.dump(config, io)
  end
end

#sceneObject



4
# File 'lib/roby/log/gui/relations_view.rb', line 4

def scene; graphics.scene end

#setupUi(relations_display) ⇒ Object



65
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/roby/log/gui/relations_view.rb', line 65

def setupUi(relations_display)
  @display   = relations_display
  super(relations_display.main)

  actionOwnership.connect(SIGNAL(:triggered)) do
 display.show_ownership = actionOwnership.checked?
 display.update
  end

  actionHideFinalized.connect(SIGNAL(:triggered)) do
 display.hide_finalized = actionHideFinalized.checked?
 display.update
  end

  #############################################################
  # Build the removed_prefixes menu
  actionPrefixAdd.connect(SIGNAL(:triggered)) do
 new_prefix = Qt::InputDialog.get_text display.main, "New prefix", "New prefix to remove"
 if !new_prefix.nil?
    display.removed_prefixes[new_prefix] = true
    save_config
    update_prefix_menu
    display.update
 end
  end
  update_prefix_menu
  
  #############################################################
  # Handle the other toolbar's buttons
  graphics.singleton_class.class_eval do
 define_method(:contextMenuEvent) do |event|
    item = itemAt(event.pos)
    if item
  unless obj = relations_display.object_of(item)
      return super(event)
  end
    end

    return unless obj.kind_of?(Roby::LoggedTask)

    menu = Qt::Menu.new
    hide_this     = menu.add_action("Hide")
    hide_children = menu.add_action("Hide children")
    show_children = menu.add_action("Show children")
    return unless action = menu.exec(event.globalPos)

    case action.text
    when "Hide"
  relations_display.set_visibility(obj, false)
    when "Hide children"
  for child in Roby::TaskStructure.children_of(obj, relations_display.enabled_relations)
      relations_display.set_visibility(child, false)
  end
    when "Show children"
  for child in Roby::TaskStructure.children_of(obj, relations_display.enabled_relations)
      relations_display.set_visibility(child, true)
  end
    end

    relations_display.update
 end
  end

  actionShowAll.connect(SIGNAL(:triggered)) do
 display.graphics.keys.each do |obj|
    display.set_visibility(obj, true) if obj.kind_of?(Roby::Task::DRoby) || (obj.kind_of?(Roby::EventGenerator::DRoby) && !obj.respond_to?(:task))
 end
 display.update
  end
  actionRedraw.connect(SIGNAL(:triggered)) do
 display.update
  end

  actionZoom.connect(SIGNAL(:triggered)) do 
 scale = graphics.matrix.m11
 if scale + ZOOM_STEP > 1
    scale = 1 - ZOOM_STEP
 end
 graphics.resetMatrix
 graphics.scale scale + ZOOM_STEP, scale + ZOOM_STEP
  end
  actionUnzoom.connect(SIGNAL(:triggered)) do
 scale = graphics.matrix.m11
 graphics.resetMatrix
 graphics.scale scale - ZOOM_STEP, scale - ZOOM_STEP
  end
  actionFit.connect(SIGNAL(:triggered)) do
 graphics.fitInView(graphics.scene.items_bounding_rect, Qt::KeepAspectRatio)
  end

  actionKeepSignals.connect(SIGNAL(:triggered)) do 
 display.keep_signals = actionKeepSignals.checked?
  end

  actionPrint.connect(SIGNAL(:triggered)) do
 return unless scene
 printer = Qt::Printer.new;
 if Qt::PrintDialog.new(printer).exec() == Qt::Dialog::Accepted
    painter = Qt::Painter.new(printer);
    painter.setRenderHint(Qt::Painter::Antialiasing);
    scene.render(painter);
 end
  end

  actionSVGExport.connect(SIGNAL(:triggered)) do
 return unless scene

 if path = Qt::FileDialog.get_save_file_name(nil, "SVG Export")
    svg = Qt::SvgGenerator.new
    svg.file_name = path
    svg.size = Qt::Size.new(Integer(scene.width * 0.8), Integer(scene.height * 0.8))
    painter = Qt::Painter.new
    painter.begin(svg)
    scene.render(painter)
    painter.end
 end
  end
  actionSVGExport.enabled = defined?(Qt::SvgGenerator)
end

#update_prefix_menuObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/roby/log/gui/relations_view.rb', line 44

def update_prefix_menu
  @prefixActions ||= []
  prefixActions.each do |action|
 menuRemovedPrefixes.remove_action(action)
  end

  prefixActions.clear
  display.removed_prefixes.each do |prefix, bool|
 action = Qt::Action.new prefix, menuRemovedPrefixes
 prefixActions << action
 action.checkable = true
 action.checked = bool
 action.connect(SIGNAL(:triggered)) do 
    display.removed_prefixes[prefix] = action.checked?
    display.update
 end
 menuRemovedPrefixes.add_action action
  end
end