Skip to content

Commit

Permalink
Merge pull request ros-visualization#627 from acornacorn/groovy-devel
Browse files Browse the repository at this point in the history
add selectable property to RobotLink and visible_ flag to Robot class.
  • Loading branch information
hershwg committed Apr 10, 2013
2 parents c4a926b + 91765cf commit b996223
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 11 deletions.
8 changes: 8 additions & 0 deletions src/rviz/robot/robot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ namespace rviz

Robot::Robot( Ogre::SceneNode* root_node, DisplayContext* context, const std::string& name, Property* parent_property )
: scene_manager_( context->getSceneManager() )
, visible_( true )
, visual_visible_( true )
, collision_visible_( false )
, context_( context )
Expand Down Expand Up @@ -81,6 +82,7 @@ Robot::~Robot()

void Robot::setVisible( bool visible )
{
visible_ = visible;
if ( visible )
{
root_visual_node_->setVisible( visual_visible_ );
Expand All @@ -91,6 +93,7 @@ void Robot::setVisible( bool visible )
{
root_visual_node_->setVisible( false );
root_collision_node_->setVisible( false );
updateLinkVisibilities();
}
}

Expand All @@ -117,6 +120,11 @@ void Robot::updateLinkVisibilities()
}
}

bool Robot::isVisible()
{
return visible_;
}

bool Robot::isVisualVisible()
{
return visual_visible_;
Expand Down
7 changes: 7 additions & 0 deletions src/rviz/robot/robot.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,18 @@ class Robot
*/
void setCollisionVisible( bool visible );

/**
* \brief Returns whether anything is visible
*/
bool isVisible();
/**
* \brief Returns whether or not the visual representation is set to be visible
* To be visible this and isVisible() must both be true.
*/
bool isVisualVisible();
/**
* \brief Returns whether or not the collision representation is set to be visible
* To be visible this and isVisible() must both be true.
*/
bool isCollisionVisible();

Expand Down Expand Up @@ -162,6 +168,7 @@ class Robot
Ogre::SceneNode* root_collision_node_; ///< Node all our collision nodes are children of
Ogre::SceneNode* root_other_node_;

bool visible_; ///< Should we show anything at all? (affects visual, collision, axes, and trails)
bool visual_visible_; ///< Should we show the visual representation?
bool collision_visible_; ///< Should we show the collision representation?

Expand Down
62 changes: 58 additions & 4 deletions src/rviz/robot/robot_link.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#include "rviz/ogre_helpers/object.h"
#include "rviz/ogre_helpers/shape.h"
#include "rviz/properties/float_property.h"
#include "rviz/properties/bool_property.h"
#include "rviz/properties/property.h"
#include "rviz/properties/quaternion_property.h"
#include "rviz/properties/vector_property.h"
Expand All @@ -73,6 +74,9 @@ class RobotLinkSelectionHandler : public SelectionHandler
virtual void createProperties( const Picked& obj, Property* parent_property );
virtual void updateProperties();

virtual void preRenderPass(uint32_t pass);
virtual void postRenderPass(uint32_t pass);

private:
RobotLink* link_;
VectorProperty* position_property_;
Expand Down Expand Up @@ -109,6 +113,40 @@ void RobotLinkSelectionHandler::updateProperties()
orientation_property_->setQuaternion( link_->getOrientation() );
}


void RobotLinkSelectionHandler::preRenderPass(uint32_t pass)
{
if (!link_->getSelectable())
{
if( link_->visual_node_ )
{
link_->visual_node_->setVisible( false );
}
if( link_->collision_node_ )
{
link_->collision_node_->setVisible( false );
}
if( link_->trail_ )
{
link_->trail_->setVisible( false );
}
if( link_->axes_ )
{
link_->axes_->getSceneNode()->setVisible( false );
}
}
}

void RobotLinkSelectionHandler::postRenderPass(uint32_t pass)
{
if (!link_->getSelectable())
{
link_->updateVisibility();
}
}



RobotLink::RobotLink( Robot* parent, DisplayContext* context, Property* parent_property )
: parent_( parent )
, scene_manager_( context->getSceneManager() )
Expand Down Expand Up @@ -138,6 +176,10 @@ RobotLink::RobotLink( Robot* parent, DisplayContext* context, Property* parent_p
"Enable/disable showing the axes of this link.",
link_property_, SLOT( updateAxes() ), this );

selectable_property_ = new BoolProperty( "Selectable", true,
"Whether the link can be selected (clicked). If unchecked objects behind or inside the link can be manipulated.",
link_property_);

position_property_ = new VectorProperty( "Position", Ogre::Vector3::ZERO,
"Position of this link, in the current Fixed Frame. (Not editable)",
link_property_ );
Expand Down Expand Up @@ -288,19 +330,19 @@ void RobotLink::updateVisibility()
bool enabled = getEnabled();
if( visual_node_ )
{
visual_node_->setVisible( enabled && parent_->isVisualVisible() );
visual_node_->setVisible( enabled && parent_->isVisible() && parent_->isVisualVisible() );
}
if( collision_node_ )
{
collision_node_->setVisible( enabled && parent_->isCollisionVisible() );
collision_node_->setVisible( enabled && parent_->isVisible() && parent_->isCollisionVisible() );
}
if( trail_ )
{
trail_->setVisible( enabled );
trail_->setVisible( enabled && parent_->isVisible() );
}
if( axes_ )
{
axes_->getSceneNode()->setVisible( enabled );
axes_->getSceneNode()->setVisible( enabled && parent_->isVisible() );
}
}

Expand Down Expand Up @@ -679,6 +721,18 @@ void RobotLink::unsetColor()
setToNormalMaterial();
}

bool RobotLink::setSelectable( bool selectable )
{
bool old = selectable_property_->getBool();
selectable_property_->setValue( selectable );
return old;
}

bool RobotLink::getSelectable()
{
return selectable_property_->getBool();
}

Ogre::Vector3 RobotLink::getPosition()
{
return position_property_->getVector();
Expand Down
15 changes: 8 additions & 7 deletions src/rviz/robot/robot_link.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,6 @@ class Any;
class RibbonTrail;
}

namespace rviz
{
class Shape;
class Axes;
}

namespace urdf
{
class ModelInterface;
Expand All @@ -73,10 +67,12 @@ class Pose;

namespace rviz
{

class Shape;
class Axes;
class DisplayContext;
class FloatProperty;
class Property;
class BoolProperty;
class QuaternionProperty;
class Robot;
class RobotLinkSelectionHandler;
Expand Down Expand Up @@ -109,6 +105,10 @@ Q_OBJECT
void setColor( float red, float green, float blue );
void unsetColor();

/// set whether the link is selectable. If false objects behind/inside the link can be selected/manipulated. Returns old value.
bool setSelectable( bool selectable );
bool getSelectable();

Ogre::Vector3 getPosition();
Ogre::Quaternion getOrientation();

Expand Down Expand Up @@ -189,6 +189,7 @@ private Q_SLOTS:
Property* trail_property_;
Property* axes_property_;
FloatProperty* alpha_property_;
BoolProperty* selectable_property_;

friend class RobotLinkSelectionHandler;
};
Expand Down

0 comments on commit b996223

Please sign in to comment.