Class: Syskit::GUI::ModelViews::Profile

Inherits:
MetaRuby::GUI::HTML::Collection
  • Object
show all
Defined in:
lib/syskit/gui/model_views/profile.rb

Overview

Visualization of a syskit profile

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(page) ⇒ Profile

Returns a new instance of Profile



123
124
125
126
127
128
129
# File 'lib/syskit/gui/model_views/profile.rb', line 123

def initialize(page)
    super(page)
    @instanciation_method = :compute_system_network

    register_type Syskit::InstanceRequirements, ProfileElementView.new(page),
        method: :compute_system_network, show_requirements: true
end

Instance Attribute Details

#instanciation_methodObject

Returns the value of attribute instanciation_method



121
122
123
# File 'lib/syskit/gui/model_views/profile.rb', line 121

def instanciation_method
  @instanciation_method
end

Instance Method Details



164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/syskit/gui/model_views/profile.rb', line 164

def compute_toplevel_links(model, options)
    explicit_selections = mapping_to_links(
        model.dependency_injection.explicit,
        true, options[:interactive])

    defaults = model.dependency_injection.defaults.inject(Hash.new) do |h, k|
        h[k] = k
        h
    end
    default_selections = mapping_to_links(
        defaults, false, options[:interactive])

    definitions = Hash.new
    model.definitions.keys.sort.each do |name|
        definitions[name] = model.resolved_definition(name)
    end
    definitions = mapping_to_links(
        definitions, false, options[:interactive])
    definitions.each do |obj|
        doc = first_paragraph(obj.object.doc || "")
        obj.format = "%s: #{doc}"
    end

    devices = Hash.new
    model.robot.each_device.sort_by(&:name).each do |dev|
        req = dev.to_instance_requirements
        model.inject_di_context(req)
        devices[dev.name] = req
    end
    devices = mapping_to_links(
        devices, false, options[:interactive])

    [explicit_selections, default_selections, definitions, devices].each do |collection|
        collection.each do |el|
            el.object = el.object.to_instance_requirements
            el.rendering_options[:method] = instanciation_method
        end
    end

    return explicit_selections, default_selections, definitions, devices
end

#first_paragraph(string) ⇒ Object



151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/syskit/gui/model_views/profile.rb', line 151

def first_paragraph(string)
    paragraph = String.new
    string.each_line do |line|
        line = line.chomp
        if line.empty?
            return paragraph
        else
            paragraph << " " << line
        end
    end
    paragraph
end


135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/syskit/gui/model_views/profile.rb', line 135

def mapping_to_links(mapping, with_value, interactive = true)
    mapping.keys.map do |key|
        object = mapping[key]
        id = element_link_target(object, interactive)

        if with_value
            text = ModelViews.render_mapping(page, key, object)
            key_text, value_text = text.first.split(": ")
            text[0] = "%s: #{value_text}"
            Element.new(object, "<pre>#{text.join("\n")}</pre>", id, key_text, Hash.new(buttons: []), Hash.new)
        else
            Element.new(object, "%s", id, key, Hash.new(buttons: []), Hash.new)
        end
    end
end

#render(model, interactive: true, **push_options) ⇒ Object



206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/syskit/gui/model_views/profile.rb', line 206

def render(model, interactive: true, **push_options)
    explicit_selections, default_selections, definitions, devices =
        compute_toplevel_links(model, interactive: interactive)

    ComponentNetworkBaseView.html_defined_in(page, model, with_require: true)
    render_links("Explicit Selection", explicit_selections)
    render_links("Default selections", default_selections)
    render_links("Definitions", definitions)
    render_links("Devices", devices)
    page.save

    if !interactive
        render_all_elements(explicit_selections + default_selections + definitions + devices,
            interactive: false, **push_options)
    end
end

#render_object_as_text(model) ⇒ Object



131
132
133
# File 'lib/syskit/gui/model_views/profile.rb', line 131

def render_object_as_text(model)
    render_instance_requirements(model.to_instance_requirements).join("\n")
end