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

Issue#27: rebased candidate_v2, added rename and delete subproperties #114

Open
wants to merge 1 commit into
base: m1_merge_candidate_v2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions urdf_editor/include/urdf_editor/link_collision_property.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ namespace urdf_editor

QtProperty *getTopItem() { return top_item_; }

void removeSubProperties();

private slots:
void onValueChanged(QtProperty *property, const QVariant &val);
Expand Down
2 changes: 2 additions & 0 deletions urdf_editor/include/urdf_editor/link_inertial_property.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ namespace urdf_editor

QtProperty *getTopItem() { return top_item_; }

void removeSubProperties();

private slots:
void onValueChanged(QtProperty *property, const QVariant &val);
void onChildValueChanged(QtProperty *property, const QVariant &val);
Expand Down
4 changes: 3 additions & 1 deletion urdf_editor/include/urdf_editor/link_property.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ namespace urdf_editor

void loadData();

void setLinkName(QString new_name);
void removeSubProperties();

bool hasInertialProperty();
void createInertialProperty();
LinkInertialPropertySharedPtr getInertialProperty();


/*! Check if has visual property */
bool hasVisualProperty();
Expand Down
3 changes: 3 additions & 0 deletions urdf_editor/include/urdf_editor/link_visual_property.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ namespace urdf_editor

QtProperty *getTopItem() { return top_item_; }

void removeSubProperties();


private slots:
void onValueChanged(QtProperty *property, const QVariant &val);
void onChildValueChanged(QtProperty *property, const QVariant &val);
Expand Down
1 change: 1 addition & 0 deletions urdf_editor/include/urdf_editor/urdf_property.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ namespace urdf_editor

private slots:
void on_treeWidget_itemClicked(QTreeWidgetItem *item, int column);
void on_treeWidget_customContextMenuRequested(const QPoint &pos);

void on_propertyWidget_customContextMenuRequested(const QPoint &pos);
void on_propertyWidget_jointNameChanged(JointProperty *property, QString current_name, QString new_name);
Expand Down
7 changes: 7 additions & 0 deletions urdf_editor/src/link_collision_property.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,13 @@ namespace urdf_editor
loading_ = false;
}

void LinkCollisionProperty::removeSubProperties()
{
QList<QtProperty *> sub_items = top_item_->subProperties();
for (int i = 0; i < sub_items.length(); ++i)
top_item_->removeSubProperty(sub_items[i]);
}

void LinkCollisionProperty::loadFactoryForManager(QtTreePropertyBrowserSharedPtr& property_editor)
{
property_editor->setFactoryForManager(manager_, factory_);
Expand Down
7 changes: 7 additions & 0 deletions urdf_editor/src/link_inertial_property.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ namespace urdf_editor
}
}

void LinkInertialProperty::removeSubProperties()
{
QList<QtProperty *> sub_items = top_item_->subProperties();
for (int i = 0; i < sub_items.length(); ++i)
top_item_->removeSubProperty(sub_items[i]);
}

void LinkInertialProperty::loadFactoryForManager(QtTreePropertyBrowserSharedPtr& property_editor)
{
property_editor->setFactoryForManager(manager_, factory_);
Expand Down
13 changes: 13 additions & 0 deletions urdf_editor/src/link_property.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,19 @@ namespace urdf_editor
}
}

void LinkProperty::setLinkName(QString new_name)
{
name_item_->setValue(new_name);
}

void LinkProperty::removeSubProperties()
{
QList<QtProperty *> sub_items = top_item_->subProperties();
for (int i = 0; i < sub_items.length(); ++i)
if (sub_items[i]->propertyName() != "Type")
top_item_->removeSubProperty(sub_items[i]);
}

bool LinkProperty::hasInertialProperty()
{
return (inertial_property_ != NULL);
Expand Down
7 changes: 7 additions & 0 deletions urdf_editor/src/link_visual_property.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,13 @@ namespace urdf_editor
loading_ = false;
}

void LinkVisualProperty::removeSubProperties()
{
QList<QtProperty *> sub_items = top_item_->subProperties();
for (int i = 0; i < sub_items.length(); ++i)
top_item_->removeSubProperty(sub_items[i]);
}

void LinkVisualProperty::loadFactoryForManager(QtTreePropertyBrowserSharedPtr& property_editor)
{
property_editor->setFactoryForManager(manager_, factory_);
Expand Down
113 changes: 113 additions & 0 deletions urdf_editor/src/urdf_property.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,119 @@ namespace urdf_editor
return rviz_widget_->loadRobot(tree_widget_->getRobotModel());
}

void URDFProperty::on_treeWidget_customContextMenuRequested(const QPoint &pos)
{
QTreeWidgetItem *sel = tree_widget_->selectedItems()[0];
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);
if (!base_exist || !tool0_exist)
{
menu->addSeparator();
QMenu *convertMenu = menu->addMenu("Convert to");
if (!base_exist)
{
convertMenu->addAction("base");
}
if (!tool0_exist)
{
convertMenu->addAction("tool0");
}
}
}

QAction *selected_item = menu->exec(tree_widget_->mapToGlobal(pos));
if (selected_item)
{
if (selected_item->text() == "Add")
{
// we can only add to the link root item or to other links
if (sel == link_root_ || isLink(sel))
{
addModelLink(sel);
}
// or to the joint root item or to other links
else if (sel == joint_root_ || isJoint(sel))
{
addModelJoint(sel);
}
}
else if (selected_item->text() == "tool0")
{
// Change the name of current link
QString new_name = "tool0";
LinkPropertySharedPtr activeLink = ltree_to_link_property_[sel];
activeLink->setLinkName(new_name);

// if this link already has an 'inertial' element, delete it
if (activeLink->hasInertialProperty())
{
LinkInertialPropertySharedPtr inertial_property = activeLink->getInertialProperty();
inertial_property->removeSubProperties();
}
// if this link already has a 'visual element, delete it
if (activeLink->hasVisualProperty())
{
LinkVisualPropertySharedPtr visual_property = activeLink->getVisualProperty();
visual_property->removeSubProperties();
}
// if this link already has a 'collision element, delete it
if (activeLink->hasCollisionProperty())
{
LinkCollisionPropertySharedPtr collision_property = activeLink->getCollisionProperty();
collision_property->removeSubProperties();
}
}
else if (selected_item->text() == "base")
{
// Change the name of current link
QString new_name = "base";
LinkPropertySharedPtr activeLink = ltree_to_link_property_[sel];
activeLink->setLinkName(new_name);

// if this link already has an 'inertial' element, delete it
if (activeLink->hasInertialProperty())
{
LinkInertialPropertySharedPtr inertial_property = activeLink->getInertialProperty();
inertial_property->removeSubProperties();
}
// if this link already has a 'visual element, delete it
if (activeLink->hasVisualProperty())
{
LinkVisualPropertySharedPtr visual_property = activeLink->getVisualProperty();
visual_property->removeSubProperties();
}
// if this link already has a 'collision element, delete it
if (activeLink->hasCollisionProperty())
{
LinkCollisionPropertySharedPtr collision_property = activeLink->getCollisionProperty();
collision_property->removeSubProperties();
}
}
else
{
if (isLink(sel))
{
link_names_.removeOne(sel->text(0));
link_root_->removeChild(sel);
}
else if (isJoint(sel))
{
joint_names_.removeOne(sel->text(0));
sel->parent()->removeChild(sel);
}
}
}

delete menu;
}

void URDFProperty::on_treeWidget_itemClicked(QTreeWidgetItem *item, int column)
{
if (tree_widget_->isLink(item))
Expand Down