module Vizkit

Attributes

vizkit3d_transformer_broadcaster_name[RW]

When using Vizkit3D widgets, this is a [task_name, port_name] pair of a data source that should be used to gather transformation configuration. This configuration is supposed to be stored in a /transformer/ConfigurationState data structure.

A port can also be set directly in Vizkit.vizkit3d_transformer_configuration

vizkit3d_widget[RW]

Allow to set the vizkit3d widget to a custom one. If it is not set by the user Vizkit will automatically create one if accessed.

Public Class Methods

app() click to toggle source
# File lib/vizkit/vizkit.rb, line 42
def self.app
    $qApp
end
connect_all() click to toggle source
# File lib/vizkit/vizkit.rb, line 170
def self.connect_all()
    @connections.each do |connection|
        connection.connect
    end
end
connect_port_to 'corridor_planner', 'plan', widget click to toggle source
connect_port_to 'corridor_planner', 'plan' do |value|
...
end

Asks vizkit to connect the given task,port pair on either a widget, and/or through a block. The return value is the connection object which can be used to disconnect and reconncet the widget/ block.

Unlike Orocos::QtOutputPort#connect_to, this expects a task and port name, i.e. can be called even though the remote task is not started yet This is use full if tasks are replayed from a logfile

# File lib/vizkit/vizkit.rb, line 193
def self.connect_port_to(task_name, port_name, widget = nil, options = Hash.new, &block)
    if widget.kind_of?(Hash)
        widget, options = nil, widget
    end
    widget = if widget.respond_to? :to_str
                 default_loader.create_plugin(widget.to_str)
             else
                 widget
             end
    port = Orocos::Async.proxy(task_name).port(port_name)
    l = port.on_reachable do
        begin
            port.connect_to widget,options,&block
            l.stop # stop listener
        rescue Exception => e
            Vizkit.warn "error while connecting #{port.name} with widget: #{e}"
        end
    end
end
connection_manager() click to toggle source

returns an instance to a connection manager handing the connections between code blocks and orocos ports

# File lib/vizkit/vizkit.rb, line 246
def self.connection_manager
    @connection_manager ||= Vizkit::ConnectionManager.new($qApp)
end
control(value, options=Hash.new,&block) click to toggle source
# File lib/vizkit/vizkit.rb, line 96
def self.control value, options=Hash.new,&block
    options[:widget_type] = :control
    widget = widget_from_options(value,options,&block)
    if(!widget)
        Vizkit.warn "No widget found for controlling #{value}!"
        return nil
    end
    widget
end
default_loader() click to toggle source
# File lib/vizkit/vizkit.rb, line 46
def self.default_loader
    @default_loader ||= UiLoader.new
    @default_loader
end
disconnect_all() click to toggle source

disconnects all connections to widgets

# File lib/vizkit/vizkit.rb, line 177
def self.disconnect_all
end
display(value,options=Hash.new,&block) click to toggle source
# File lib/vizkit/vizkit.rb, line 115
def self.display value,options=Hash.new,&block
    value = value.to_proxy
    options[:widget_type] = :display
    widget = widget_from_options(value,options,&block)
    Vizkit.warn "No widget found for displaying #{value}!" if(!widget)
    widget
end
ensure_orocos_initialized() click to toggle source

Make sure that orocos.rb is properly initialized. This must be called in each widget that require an Orocos component “behind the scenes”

# File lib/vizkit/vizkit.rb, line 238
def self.ensure_orocos_initialized
    if !Orocos.initialized?
        Orocos.initialize
    end
end
exec(async_period: 0.01) click to toggle source
# File lib/vizkit/vizkit.rb, line 135
def self.exec(async_period: 0.01)
    #install event filter
    obj = ShortCutFilter.new
    $qApp.installEventFilter(obj)

    timer = Qt::Timer.new
    timer.connect SIGNAL("timeout()") do
        Orocos::Async.step
    end
    timer.start Integer(async_period * 1000)

    $qApp.exec
end
get(name,options=Hash.new) click to toggle source
# File lib/vizkit/vizkit.rb, line 166
def self.get(name,options=Hash.new)
    Orocos::Async.get name,options
end
load(ui_file,parent = nil) click to toggle source
# File lib/vizkit/vizkit.rb, line 158
def self.load(ui_file,parent = nil)
    default_loader.load(ui_file,parent)
end
process_events() click to toggle source
# File lib/vizkit/vizkit.rb, line 149
def self.process_events()
    $qApp.processEvents
end
proxy(name,options=Hash.new) click to toggle source
# File lib/vizkit/vizkit.rb, line 162
def self.proxy(name,options=Hash.new)
    Orocos::Async.proxy name,options
end
setup_tree_view(tree_view) click to toggle source
# File lib/vizkit/tree_view.rb, line 4
def self.setup_tree_view(tree_view)
    delegator = ItemDelegate.new(tree_view,nil)
    tree_view.setItemDelegate(delegator)
    tree_view.setSortingEnabled true
    tree_view.sortByColumn(0, Qt::AscendingOrder)
    tree_view.setAlternatingRowColors(true)
    tree_view.setContextMenuPolicy(Qt::CustomContextMenu)
    tree_view.setDragEnabled(true)
    tree_view.connect(SIGNAL('customContextMenuRequested(const QPoint&)')) do |pos|
        index = tree_view.index_at(pos)
        next unless index.isValid
        item = tree_view.item_from_index(index)
        item.context_menu(pos,tree_view)
    end

    def tree_view.real_model
        if model.is_a?(Qt::AbstractProxyModel)
            return model.sourceModel
        else
            return model
        end
    end

    def tree_view.item_from_index(index)
        if index.model.is_a?(Qt::AbstractProxyModel)
            return index.model.sourceModel.itemFromIndex(index.model.mapToSource(index))
        else
            return index.model.itemFromIndex(index)
        end
    end

    def tree_view.setModel(model)
        raise ArgumentError,"wrong model type" unless model.is_a? Qt::AbstractItemModel
        super
        connect SIGNAL("collapsed(QModelIndex)") do |index|
            item_from_index(index).collapse
            item = item_from_index(index.sibling(index.row,1))
            item.collapse if item.is_a? VizkitItem
        end
        connect SIGNAL("expanded(QModelIndex)") do |index|
            item_from_index(index).expand
            item = item_from_index(index.sibling(index.row,1))
            item.expand if item.is_a? VizkitItem
        end
    end

    def tree_view.disconnected_items
        @disconnected_items ||= []
    end

    # stops all listeners
    # this should be called if the tree view is no longer visible
    #
    # warning: if the tree view is still visible it will reconnect
    # if a item gets expanded
    def tree_view.disconnect
        0.upto(real_model.rowCount-1) do |i|
            index = real_model.index(i,0)
            next unless isExpanded(model.is_a?(Qt::AbstractProxyModel) ? model.mapFromSource(index) : index)
            real_model.item(i,0).collapse
            real_model.item(i,1).collapse
            disconnected_items << i
        end
    end

    # restores the state before disconnect was called
    def tree_view.reconnect
        disconnected_items.each do |i|
            real_model.item(i,0).expand
            real_model.item(i,1).expand
        end
        disconnected_items.clear
    end
end
setup_widget(widget,value=nil,options = Hash.new,type = :display,&block) click to toggle source
# File lib/vizkit/vizkit.rb, line 51
def self.setup_widget(widget,value=nil,options = Hash.new,type = :display,&block)
    return nil if !widget
    if type == :control || !value.respond_to?(:connect_to)
        widget.config(value,options,&block) if widget.respond_to?(:config)
        if widget.respond_to?(:plugin_spec)
            block = if block || !value.respond_to?(:writer)
                        block
                    else
                        writer = value.writer
                        Proc.new {|val|writer.write(val)}
                    end
            callback_fct = widget.plugin_spec.find_callback!(:argument => value,:callback_type => type)
            if callback_fct && (!callback_fct.respond_to?(:to_sym) || callback_fct.to_sym != :config)
                callback_fct = callback_fct.bind(widget) 
                callback_fct.call(value, options, &block)  
            end
        end
    else
        value.connect_to widget,options ,&block
    end
    widget.show if widget.is_a? Qt::Widget #respond_to is not working because qt is using method_missing
    widget
end
step() click to toggle source
# File lib/vizkit/vizkit.rb, line 153
def self.step
    $qApp.processEvents
    Orocos::Async.step
end
task_inspector() click to toggle source
# File lib/vizkit/vizkit.rb, line 106
def self.task_inspector
    @task_inspector ||= begin
                            task = default_loader.TaskInspector
                            raise "Cannot find plugin TaskInspector" unless task
                            task.add_name_service Orocos::Async.name_service
                            task
                        end
end
widget_from_options(value,options=Hash.new,&block) click to toggle source
# File lib/vizkit/vizkit.rb, line 75
def self.widget_from_options(value,options=Hash.new,&block)
    if value.is_a? Array
        result = Array.new
        value.each do |val|
            result << widget_from_options(val, options, &block)
        end
        return result
    end
    opts,options = Kernel::filter_options(options,@vizkit_local_options)
    widget = if opts[:widget].respond_to? :to_str 
                 default_loader.create_plugin(opts[:widget],opts[:parent],opts[:reuse])
             else
                 if opts[:widget]
                     opts[:widget]
                 else
                     default_loader.create_plugin_for(value,opts[:widget_type],opts[:parent],opts[:reuse])
                 end
             end
    setup_widget(widget,value,options,opts[:widget_type],&block)
end