Module: Syskit::GUI::PageExtension
Instance Method Summary collapse
-
#push_plan(title, kind, plan, buttons: [], zoom: 1, id: kind, external_objects: nil, **options) ⇒ Object
Adds a plan representation on the page.
-
#uri_for(object) ⇒ Object
Returns the path part of the URI to an object.
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
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, **) svg_io = Tempfile.open(kind) begin Syskit::Graphviz.new(plan, self, typelib_resolver: GUI::ModelBrowser::TypelibResolver.new). to_file(kind, 'svg', svg_io, ) svg_io.flush svg_io.rewind svg = svg_io.read svg = svg.encode 'utf-8', invalid: :replace rescue DotCrashError, DotFailedError => e svg = e. end # Fixup a mixup in dot's SVG output. The URIs that contain < and > # are not properly escaped to < and > svg = svg.gsub(/xlink:href="[^"]+"/) { |match| match.gsub("<", "<").gsub(">", ">") } 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: ) else push(title, svg, id: id, 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 |