mirror of
https://github.com/moveit/moveit_task_constructor.git
synced 2025-11-04 14:49:57 +08:00
Use public API only in visualization package
This commit is contained in:
parent
0d6f79050a
commit
5037bc77e7
@ -37,7 +37,6 @@
|
|||||||
#include "local_task_model.h"
|
#include "local_task_model.h"
|
||||||
#include "factory_model.h"
|
#include "factory_model.h"
|
||||||
#include "properties/property_factory.h"
|
#include "properties/property_factory.h"
|
||||||
#include <moveit/task_constructor/task_p.h>
|
|
||||||
#include <rviz/properties/property_tree_model.h>
|
#include <rviz/properties/property_tree_model.h>
|
||||||
|
|
||||||
#include <ros/console.h>
|
#include <ros/console.h>
|
||||||
@ -63,23 +62,25 @@ QModelIndex LocalTaskModel::index(Node* n) const {
|
|||||||
if (n == root_)
|
if (n == root_)
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
|
|
||||||
const ContainerBasePrivate* parent = n->parent()->pimpl();
|
const ContainerBase* parent = n->parent();
|
||||||
|
|
||||||
// the internal pointer refers to n
|
// the internal pointer refers to n
|
||||||
int row = 0;
|
int row = 0;
|
||||||
for (const auto& child : parent->children()) {
|
auto findRow = [n, &row](const Stage& child, int /* depth */) -> bool {
|
||||||
if (child->pimpl() == n)
|
if (&child == n)
|
||||||
return createIndex(row, 0, n);
|
return false; // found, don't continue traversal
|
||||||
++row;
|
++row;
|
||||||
}
|
return true;
|
||||||
Q_ASSERT(false);
|
};
|
||||||
return QModelIndex();
|
parent->traverseChildren(findRow);
|
||||||
|
Q_ASSERT(row < parent->numChildren());
|
||||||
|
return createIndex(row, 0, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
LocalTaskModel::LocalTaskModel(ContainerBase::pointer&& container, const planning_scene::PlanningSceneConstPtr& scene,
|
LocalTaskModel::LocalTaskModel(ContainerBase::pointer&& container, const planning_scene::PlanningSceneConstPtr& scene,
|
||||||
rviz::DisplayContext* display_context, QObject* parent)
|
rviz::DisplayContext* display_context, QObject* parent)
|
||||||
: BaseTaskModel(scene, display_context, parent), Task("", std::move(container)) {
|
: BaseTaskModel(scene, display_context, parent), Task("", std::move(container)) {
|
||||||
root_ = pimpl();
|
root_ = this;
|
||||||
flags_ |= LOCAL_MODEL;
|
flags_ |= LOCAL_MODEL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,32 +88,41 @@ int LocalTaskModel::rowCount(const QModelIndex& parent) const {
|
|||||||
if (parent.column() > 0)
|
if (parent.column() > 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
ContainerBasePrivate* c = dynamic_cast<ContainerBasePrivate*>(node(parent));
|
ContainerBase* c = dynamic_cast<ContainerBase*>(node(parent));
|
||||||
if (!c)
|
if (!c)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return c->children().size();
|
return c->numChildren();
|
||||||
}
|
}
|
||||||
|
|
||||||
QModelIndex LocalTaskModel::index(int row, int column, const QModelIndex& parent) const {
|
QModelIndex LocalTaskModel::index(int row, int column, const QModelIndex& parent) const {
|
||||||
if (column < 0 || column >= columnCount())
|
if (column < 0 || column >= columnCount())
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
|
|
||||||
Q_ASSERT(dynamic_cast<ContainerBasePrivate*>(node(parent)));
|
Q_ASSERT(dynamic_cast<ContainerBase*>(node(parent)));
|
||||||
ContainerBasePrivate* p = static_cast<ContainerBasePrivate*>(node(parent));
|
ContainerBase* p = static_cast<ContainerBase*>(node(parent));
|
||||||
if (!p || row < 0 || (size_t)row >= p->children().size())
|
if (!p || row < 0 || (size_t)row >= p->numChildren())
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
|
|
||||||
auto it = p->children().begin();
|
Node* child = nullptr;
|
||||||
std::advance(it, row);
|
int idx = 0;
|
||||||
return createIndex(row, column, it->get()->pimpl());
|
p->traverseChildren([&idx, row, &child](const Stage& ch, int /* depth */) -> bool {
|
||||||
|
if (idx == row) {
|
||||||
|
child = const_cast<Node*>(&ch);
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
++idx;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return createIndex(row, column, child);
|
||||||
}
|
}
|
||||||
|
|
||||||
QModelIndex LocalTaskModel::parent(const QModelIndex& index) const {
|
QModelIndex LocalTaskModel::parent(const QModelIndex& index) const {
|
||||||
if (index.model() != this)
|
if (index.model() != this)
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
|
|
||||||
ContainerBasePrivate* parent = node(index)->parent()->pimpl();
|
ContainerBase* parent = const_cast<ContainerBase*>(node(index)->parent());
|
||||||
Q_ASSERT(parent);
|
Q_ASSERT(parent);
|
||||||
|
|
||||||
return this->index(parent);
|
return this->index(parent);
|
||||||
@ -120,7 +130,7 @@ QModelIndex LocalTaskModel::parent(const QModelIndex& index) const {
|
|||||||
|
|
||||||
Qt::ItemFlags LocalTaskModel::flags(const QModelIndex& index) const {
|
Qt::ItemFlags LocalTaskModel::flags(const QModelIndex& index) const {
|
||||||
Qt::ItemFlags flags = BaseTaskModel::flags(index);
|
Qt::ItemFlags flags = BaseTaskModel::flags(index);
|
||||||
ContainerBasePrivate* c = dynamic_cast<ContainerBasePrivate*>(node(index));
|
ContainerBase* c = dynamic_cast<ContainerBase*>(node(index));
|
||||||
// dropping into containers is enabled
|
// dropping into containers is enabled
|
||||||
if (c && stage_factory_)
|
if (c && stage_factory_)
|
||||||
flags |= Qt::ItemIsDropEnabled;
|
flags |= Qt::ItemIsDropEnabled;
|
||||||
@ -139,7 +149,7 @@ QVariant LocalTaskModel::data(const QModelIndex& index, int role) const {
|
|||||||
case 0:
|
case 0:
|
||||||
return QString::fromStdString(n->name());
|
return QString::fromStdString(n->name());
|
||||||
case 1:
|
case 1:
|
||||||
return (uint)n->me()->solutions().size();
|
return (uint)n->solutions().size();
|
||||||
case 2:
|
case 2:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -157,7 +167,7 @@ bool LocalTaskModel::setData(const QModelIndex& index, const QVariant& value, in
|
|||||||
const QString& name = value.toString();
|
const QString& name = value.toString();
|
||||||
if (name == n->name().c_str())
|
if (name == n->name().c_str())
|
||||||
return false;
|
return false;
|
||||||
n->me()->setName(name.toStdString());
|
n->setName(name.toStdString());
|
||||||
dataChanged(index, index);
|
dataChanged(index, index);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -168,10 +178,9 @@ bool LocalTaskModel::removeRows(int row, int count, const QModelIndex& parent) {
|
|||||||
if (flags_ & IS_RUNNING)
|
if (flags_ & IS_RUNNING)
|
||||||
return false; // cannot modify running task
|
return false; // cannot modify running task
|
||||||
|
|
||||||
Q_ASSERT(dynamic_cast<ContainerBase*>(node(parent)->me()));
|
Q_ASSERT(dynamic_cast<ContainerBase*>(node(parent)));
|
||||||
ContainerBasePrivate* cp = static_cast<ContainerBasePrivate*>(node(parent));
|
ContainerBase* c = static_cast<ContainerBase*>(node(parent));
|
||||||
ContainerBase* c = static_cast<ContainerBase*>(cp->me());
|
if (row < 0 || (size_t)row + count > c->numChildren())
|
||||||
if (row < 0 || (size_t)row + count > cp->children().size())
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
beginRemoveRows(parent, row, row + count - 1);
|
beginRemoveRows(parent, row, row + count - 1);
|
||||||
@ -195,7 +204,7 @@ bool LocalTaskModel::dropMimeData(const QMimeData* mime, Qt::DropAction action,
|
|||||||
if (!mime->hasFormat(mime_type))
|
if (!mime->hasFormat(mime_type))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
ContainerBasePrivate* c = dynamic_cast<ContainerBasePrivate*>(node(parent));
|
ContainerBase* c = dynamic_cast<ContainerBase*>(node(parent));
|
||||||
Q_ASSERT(c);
|
Q_ASSERT(c);
|
||||||
|
|
||||||
QString error;
|
QString error;
|
||||||
@ -204,7 +213,7 @@ bool LocalTaskModel::dropMimeData(const QMimeData* mime, Qt::DropAction action,
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
beginInsertRows(parent, row, row);
|
beginInsertRows(parent, row, row);
|
||||||
static_cast<ContainerBase*>(c->me())->insert(moveit::task_constructor::Stage::pointer(stage), row);
|
c->insert(moveit::task_constructor::Stage::pointer(stage), row);
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -231,7 +240,7 @@ rviz::PropertyTreeModel* LocalTaskModel::getPropertyModel(const QModelIndex& ind
|
|||||||
auto it_inserted = properties_.insert(std::make_pair(n, nullptr));
|
auto it_inserted = properties_.insert(std::make_pair(n, nullptr));
|
||||||
if (it_inserted.second) { // newly inserted, create new model
|
if (it_inserted.second) { // newly inserted, create new model
|
||||||
it_inserted.first->second =
|
it_inserted.first->second =
|
||||||
PropertyFactory::instance().createPropertyTreeModel(*n->me(), scene_.get(), display_context_);
|
PropertyFactory::instance().createPropertyTreeModel(*n, scene_.get(), display_context_);
|
||||||
it_inserted.first->second->setParent(this);
|
it_inserted.first->second->setParent(this);
|
||||||
}
|
}
|
||||||
return it_inserted.first->second;
|
return it_inserted.first->second;
|
||||||
|
|||||||
@ -44,7 +44,7 @@ namespace moveit_rviz_plugin {
|
|||||||
class LocalTaskModel : public BaseTaskModel, public moveit::task_constructor::Task
|
class LocalTaskModel : public BaseTaskModel, public moveit::task_constructor::Task
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
typedef moveit::task_constructor::StagePrivate Node;
|
using Node = moveit::task_constructor::Stage;
|
||||||
Node* root_;
|
Node* root_;
|
||||||
StageFactoryPtr stage_factory_;
|
StageFactoryPtr stage_factory_;
|
||||||
std::map<Node*, rviz::PropertyTreeModel*> properties_;
|
std::map<Node*, rviz::PropertyTreeModel*> properties_;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user