PointTool::PointTool() : Tool() { topic_property_ = new StringProperty( "Topic", "/clicked_point", "The topic on which to publish points.", getPropertyContainer(), SLOT( updateTopic() ), this ); auto_deactivate_property_ = new BoolProperty( "Single click", true, "Switch away from this tool after one click.", getPropertyContainer(), SLOT( updateAutoDeactivate() ), this ); updateTopic(); }
// In a tool's load() function, we don't need to read its class // because that has already been read and used to instantiate the // object before this can have been called. void FlagTool3D::load( const rviz::Config& config ) { // Here we get the "Flags" sub-config from the tool config and loop over its entries: rviz::Config flags_config = config.mapGetChild( "Flags" ); int num_flags = flags_config.listLength(); for( int i = 0; i < num_flags; i++ ) { rviz::Config flag_config = flags_config.listChildAt( i ); // At this point each ``flag_config`` represents a single flag. // // Here we provide a default name in case the name is not in the config file for some reason: QString name = "Flag " + QString::number( i + 1 ); // Then we use the convenience function mapGetString() to read the // name from ``flag_config`` if it is there. (If no "Name" entry // were present it would return false, but we don't care about // that because we have already set a default.) flag_config.mapGetString( "Name", &name ); // Given the name we can create an rviz::VectorProperty to display the position: rviz::VectorProperty* prop = new rviz::VectorProperty( name ); // Then we just tell the property to read its contents from the config, and we've read all the data. prop->load( flag_config ); // We finish each flag by marking it read-only (as discussed // above), adding it to the property container, and finally making // an actual visible flag object in the 3D scene at the correct // position. prop->setReadOnly( true ); getPropertyContainer()->addChild( prop ); makeFlag( prop->getVector() ); } }
// Loading and saving the flags // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ // // Tools with a fixed set of Property objects representing adjustable // parameters are typically just created in the tool's constructor and // added to the Property container (getPropertyContainer()). In that // case, the Tool subclass does not need to override load() and save() // because the default behavior is to read all the Properties in the // container from the Config object. // // Here however, we have a list of named flag positions of unknown // length, so we need to implement save() and load() ourselves. // // We first save the class ID to the config object so the // rviz::ToolManager will know what to instantiate when the config // file is read back in. void FlagTool3D::save( rviz::Config config ) const { config.mapSetValue( "Class", getClassId() ); // The top level of this tool's Config is a map, but our flags // should go in a list, since they may or may not have unique keys. // Therefore we make a child of the map (``flags_config``) to store // the list. rviz::Config flags_config = config.mapMakeChild( "Flags" ); // To read the positions and names of the flags, we loop over the // the children of our Property container: rviz::Property* container = getPropertyContainer(); int num_children = container->numChildren(); for( int i = 0; i < num_children; i++ ) { rviz::Property* position_prop = container->childAt( i ); // For each Property, we create a new Config object representing a // single flag and append it to the Config list. rviz::Config flag_config = flags_config.listAppendNew(); // Into the flag's config we store its name: flag_config.mapSetValue( "Name", position_prop->getName() ); // ... and its position. position_prop->save( flag_config ); } }
InteractionTool::InteractionTool() { shortcut_key_ = 'i'; hide_inactive_property_ = new BoolProperty("Hide Inactive Objects", true, "While holding down a mouse button, hide all other Interactive Objects.", getPropertyContainer(), SLOT( hideInactivePropertyChanged() ), this ); }
GoalTool::GoalTool() { shortcut_key_ = 'g'; topic_property_ = new StringProperty( "Topic", "goal", "The topic on which to publish navigation goals.", getPropertyContainer(), SLOT( updateTopic() ), this ); }
// Activation and deactivation // ^^^^^^^^^^^^^^^^^^^^^^^^^^^ // // activate() is called when the tool is started by the user, either // by clicking on its button in the toolbar or by pressing its hotkey. // // First we set the moving flag node to be visible, then we create an // rviz::VectorProperty to show the user the position of the flag. // Unlike rviz::Display, rviz::Tool is not a subclass of // rviz::Property, so when we want to add a tool property we need to // get the parent container with getPropertyContainer() and add it to // that. // // We wouldn't have to set current_flag_property_ to be read-only, but // if it were writable the flag should really change position when the // user edits the property. This is a fine idea, and is possible, but // is left as an exercise for the reader. void PottingTool::activate() { if( moving_flag_node_ ) { moving_flag_node_->setVisible( true ); current_flag_property_ = new rviz::VectorProperty( "Flag " + QString::number( flag_nodes_.size() )); // current_flag_property_->setReadOnly( true ); getPropertyContainer()->addChild( current_flag_property_ ); } }