Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue27 configure link #84

Open
wants to merge 5 commits into
base: indigo-devel
Choose a base branch
from
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 62 additions & 1 deletion urdf_editor/src/urdf_property.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,32 @@ namespace urdf_editor
QMenu *menu = new QMenu(tree_widget_);
menu->addAction("Add");
menu->addAction("Remove");

// Add menu for converting the link to base/tool0 if there are no base/tool0 before
if (sel->parent() == link_root_)
{
bool base_exist = link_names_.contains("base", Qt::CaseSensitive);
bool tool0_exist = link_names_.contains("tool0", Qt::CaseSensitive);
bool TCP_exist = link_names_.contains("TCP", Qt::CaseSensitive);
if (!base_exist || !tool0_exist || !TCP_exist)
{
menu->addSeparator();
QMenu *convertMenu = menu->addMenu("Convert to");
if (!base_exist)
{
convertMenu->addAction("base");
}
if (!tool0_exist)
{
convertMenu->addAction("tool0");
}
if (!TCP_exist)
{
convertMenu->addAction("TCP");
}
}
}

QAction *selected_item = menu->exec(tree_widget_->mapToGlobal(pos));
if (selected_item)
{
Expand All @@ -254,6 +280,41 @@ namespace urdf_editor
addJoint(sel);
}
}
else if (selected_item->text() == "tool0")
{
// Firstly remove the link, then add new link named "tool0"
// on_propertyWidget_linkNameChanged(ltree_to_link_property_[sel].get(), "tool0");
link_names_.removeOne(sel->text(0));
link_root_->removeChild(sel);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this leak the QTreeItemWidget?

boost::shared_ptr<urdf::Link> new_link(new urdf::Link());
new_link->name = "tool0";
model_->links_.insert(std::make_pair("tool0", new_link));
addLinkProperty(new_link);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does create a new LinkProperty, but if I understand this correctly, after this the model will now have a dangling link (ie: one which is not connected to the rest of the model), as you don't also create a joint or update the joint that connected the link this converts to now have new_link as its child.

}
else if (selected_item->text() == "base")
{
link_names_.removeOne(sel->text(0));
link_root_->removeChild(sel);
boost::shared_ptr<urdf::Link> new_link(new urdf::Link());
new_link->name = "base";
model_->links_.insert(std::make_pair("base", new_link));
addLinkProperty(new_link);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See earlier comment about dangling link.

}
else if (selected_item->text() == "TCP")
{
// Add TCP link
link_names_.removeOne(sel->text(0));
link_root_->removeChild(sel);
boost::shared_ptr<urdf::Link> new_link(new urdf::Link());
new_link->name = "TCP";
model_->links_.insert(std::make_pair("TCP", new_link));
addLinkProperty(new_link);
// Add Joint which has TCP as a child and has origin property
addJoint(joint_root_);
JointPropertyPtr targetJoint = ctree_to_joint_property_[joint_root_->child(0)];
targetJoint->createOriginProperty();
targetJoint->loadProperty(property_editor_);
}
else
{
if (sel->parent() == link_root_)
Expand Down Expand Up @@ -302,7 +363,7 @@ namespace urdf_editor
if (ctree_to_joint_property_.contains(selt))
{
qDebug() << QString("The member ctree_to_joint_property_ contains the link %1").arg(selt->text(0));

JointPropertyPtr activeJoint = ctree_to_joint_property_[selt];
QMenu menu(property_editor_.get());

Expand Down