Class: Syskit::GUI::ModelViews::Composition

Inherits:
ComponentNetworkView show all
Defined in:
lib/syskit/gui/model_views/composition.rb

Overview

Visualization of a composition model

In addition to the plain component network, it visualizes the specializations and allows to select them dynamically

Constant Summary

Constants inherited from ComponentNetworkBaseView

ComponentNetworkBaseView::Button, ComponentNetworkBaseView::DATA_SERVICE_WITHOUT_NAMES_TEMPLATE, ComponentNetworkBaseView::DATA_SERVICE_WITH_NAMES_TEMPLATE

Instance Attribute Summary collapse

Attributes inherited from ComponentNetworkView

#dataflow_options, #hierarchy_options, #plan, #task

Attributes inherited from ComponentNetworkBaseView

#current_model, #page, #plan

Instance Method Summary collapse

Methods inherited from ComponentNetworkView

#process_options, #render_plan, #view_partial_plans=, #view_partial_plans?

Methods inherited from ComponentNetworkBaseView

#buttonClicked, common_graph_buttons, #compute_system_network, find_definition_place, graph_annotation_buttons, html_defined_in, #instanciate_model, #list_services, make_annotation_buttons, #push_plan, #render_data_services, #render_require_section, #save_svg, task_annotation_buttons

Constructor Details

#initialize(page) ⇒ Composition

Returns a new instance of Composition



15
16
17
18
19
# File 'lib/syskit/gui/model_views/composition.rb', line 15

def initialize(page)
    super(page)
    @specializations = Hash.new
    @task_model_view = Roby::GUI::ModelViews::Task.new(page)
end

Instance Attribute Details

#specializationsObject (readonly)

Returns the value of attribute specializations



12
13
14
# File 'lib/syskit/gui/model_views/composition.rb', line 12

def specializations
  @specializations
end

#task_model_viewObject (readonly)

Returns the value of attribute task_model_view



13
14
15
# File 'lib/syskit/gui/model_views/composition.rb', line 13

def task_model_view
  @task_model_view
end

Instance Method Details

#clearObject



74
75
76
77
# File 'lib/syskit/gui/model_views/composition.rb', line 74

def clear
    super
    specializations.clear
end

#clickedSpecialization(task) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/syskit/gui/model_views/composition.rb', line 41

def clickedSpecialization(task)
    clicked  = task.model.applied_specializations.dup.to_set
    selected = current_model.applied_specializations.dup.to_set

    if clicked.all? { |s| selected.include?(s) }
        # This specialization is already selected, remove it
        clicked.each { |s| selected.delete(s) }
        new_selection = selected

        new_merged_selection = new_selection.inject(Syskit::Models::CompositionSpecialization.new) do |merged, s|
            merged.merge(s)
        end
    else
        # This is not already selected, add it to the set. We have to
        # take care that some of the currently selected specializations
        # might not be compatible
        new_selection = clicked
        new_merged_selection = new_selection.inject(Syskit::Models::CompositionSpecialization.new) do |merged, s|
            merged.merge(s)
        end

        selected.each do |s|
            if new_merged_selection.compatible_with?(s)
                new_selection << s
                new_merged_selection.merge(s)
            end
        end
    end

    new_model = current_model.root_model.specializations.create_specialized_model(new_merged_selection, new_selection)
    render(new_model)
end

#create_specialization_graph(root_model) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
# File 'lib/syskit/gui/model_views/composition.rb', line 79

def create_specialization_graph(root_model)
    plan = Roby::Plan.new
    specializations = Hash.new
    root_model.specializations.each_specialization.map do |spec|
        task_model = root_model.specializations.specialized_model(spec, [spec])
        plan.add(task = task_model.new)
        specializations[spec] = task
    end

    return plan, specializations
end

#disableObject



26
27
28
29
# File 'lib/syskit/gui/model_views/composition.rb', line 26

def disable
    disconnect(page, SIGNAL('linkClicked(const QUrl&)'), self, SLOT('linkClicked(const QUrl&)'))
    super
end

#enableObject



21
22
23
24
# File 'lib/syskit/gui/model_views/composition.rb', line 21

def enable
    connect(page, SIGNAL('linkClicked(const QUrl&)'), self, SLOT('linkClicked(const QUrl&)'))
    super
end

#linkClicked(url) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/syskit/gui/model_views/composition.rb', line 31

def linkClicked(url)
    if url.scheme == 'plan'
        id = Integer(url.path.gsub(/\//, ''))
        if task = specializations.values.find { |task| task.dot_id == id }
            clickedSpecialization(task)
        end
    end
end

#render(model, doc: true, **options) ⇒ Object



118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/syskit/gui/model_views/composition.rb', line 118

def render(model, doc: true, **options)
    if doc && model.doc
        page.push nil, page.main_doc(model.doc)
    end

    super(model, **options)
    task_model_view.render(model, doc: false)
    if task
        render_data_services(task)
    end
    render_specializations(model)
end

#render_specializations(model) ⇒ Object



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
# File 'lib/syskit/gui/model_views/composition.rb', line 91

def render_specializations(model)
    plan, @specializations = create_specialization_graph(model.root_model)

    current_specializations, incompatible_specializations = [], Hash.new
    if model.root_model != model
        current_specializations = model.applied_specializations.map { |s| specializations[s] }

        incompatible_specializations = specializations.dup
        incompatible_specializations.delete_if do |spec, task|
            model.applied_specializations.all? { |applied_spec| applied_spec.compatible_with?(spec) }
        end
    end

    display_options = Hash[
        accessor: :each_compatible_specialization,
        dot_edge_mark: '--',
        dot_graph_type: 'graph',
        graphviz_tool: 'fdp',
        highlights: current_specializations,
        toned_down: incompatible_specializations.values,
        annotations: [],
        id: 'specializations'
    ]
    page.push_plan('Specializations', 'relation_to_dot',
                             plan, display_options)
end