Module: Syskit::GUI::PageExtension

Included in:
HTMLPage, Page
Defined in:
lib/syskit/gui/page_extension.rb

Instance Method Summary collapse

Instance Method Details

#push_plan(title, kind, plan, buttons: [], zoom: 1, id: kind, external_objects: nil, **options) ⇒ Object

Adds a plan representation on the page

Parameters:

  • title (String)

    the title that should be added to the section

  • kind (String)

    either dataflow or hierarchy

  • plan (Roby::Plan)
  • buttons (Array)

    a list of [MetaRuby::GUI::HTML::Button] to be rendered on top of the plan to interact with it

  • zoom (Float)

    the zooming factor for the rendered SVG

  • id (String)

    the fragment id

  • external_objects (String)

    if given, the rendered SVG is saved in a file whose name is generated using #% kind.svg

  • options (Hash)

    additional options to pass to Syskit::Graphviz#to_file



34
35
36
37
38
39
40
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
73
# File 'lib/syskit/gui/page_extension.rb', line 34

def push_plan(title, kind, plan, buttons: [],
              zoom: 1, id: kind, external_objects: nil,
              **options)

    svg_io = Tempfile.open(kind)
    begin
        Syskit::Graphviz.new(plan, self, typelib_resolver: GUI::ModelBrowser::TypelibResolver.new).
            to_file(kind, 'svg', svg_io, options)
        svg_io.flush
        svg_io.rewind
        svg = svg_io.read
        svg = svg.encode 'utf-8', invalid: :replace
    rescue DotCrashError, DotFailedError => e
        svg = e.message
    end

    # Fixup a mixup in dot's SVG output. The URIs that contain < and >
    # are not properly escaped to &lt; and &gt;
    svg = svg.gsub(/xlink:href="[^"]+"/) { |match| match.gsub("<", "&lt;").gsub(">", "&gt;") }

    begin
        if match = /svg width=\"(\d+)(\w+)\" height=\"(\d+)(\w+)\"/.match(svg)
            width, w_unit, height, h_unit = *match.captures
            svg = match.pre_match + "svg width=\"#{(Float(width) * zoom * 0.6)}#{w_unit}\" height=\"#{(Float(height) * zoom * 0.6)}#{h_unit}\"" + match.post_match
        end
    rescue ArgumentError
    end

    if pattern = external_objects
        file = pattern % kind + ".svg"
        File.open(file, 'w') do |io|
            io.write(svg)
        end
        push(title, "<object data=\"#{file}\" type=\"image/svg+xml\"></object>",
             id: id, buttons: buttons)
    else
        push(title, svg, id: id, buttons: buttons)
    end
    emit :updated
end

#uri_for(object) ⇒ Object

Returns the path part of the URI to an object

Overloaded from MetaRuby to handle task contexts properly in the oroGen HTML templates. In these templates, the models are OroGen::Spec::TaskContext, but the model browser only knows about Syskit::TaskContext



10
11
12
13
14
15
16
17
18
# File 'lib/syskit/gui/page_extension.rb', line 10

def uri_for(object)
    if object.kind_of?(OroGen::Spec::TaskContext)
        if syskit_model = Syskit::TaskContext.find_model_by_orogen(object)
            super(syskit_model)
        end
    else
        super
    end
end