mirror of
https://github.com/moveit/moveit_task_constructor.git
synced 2025-11-04 14:49:57 +08:00
auto-load TaskPanel with TaskDisplay
This commit is contained in:
parent
6f95642a5a
commit
5adac3f21f
@ -37,6 +37,7 @@
|
||||
*/
|
||||
|
||||
#include "task_display.h"
|
||||
#include "task_panel.h"
|
||||
#include "task_list_model.h"
|
||||
#include "meta_task_list_model.h"
|
||||
#include <moveit/task_constructor/introspection.h>
|
||||
@ -46,6 +47,7 @@
|
||||
#include <moveit/rdf_loader/rdf_loader.h>
|
||||
#include <moveit/robot_model/robot_model.h>
|
||||
|
||||
#include <rviz/display_context.h>
|
||||
#include <rviz/properties/string_property.h>
|
||||
#include <rviz/properties/ros_topic_property.h>
|
||||
#include <rviz/properties/status_property.h>
|
||||
@ -83,11 +85,13 @@ TaskDisplay::TaskDisplay() : Display()
|
||||
|
||||
TaskDisplay::~TaskDisplay()
|
||||
{
|
||||
if (context_) TaskPanel::decUseCount();
|
||||
}
|
||||
|
||||
void TaskDisplay::onInitialize()
|
||||
{
|
||||
Display::onInitialize();
|
||||
TaskPanel::incUseCount(context_->getWindowManager());
|
||||
trajectory_visual_->onInitialize(scene_node_, context_);
|
||||
}
|
||||
|
||||
|
||||
@ -85,6 +85,16 @@ TaskPanel::TaskPanel(QWidget* parent)
|
||||
|
||||
connect(d->tasks_view->selectionModel(), SIGNAL(currentChanged(QModelIndex, QModelIndex)),
|
||||
this, SLOT(onCurrentStageChanged(QModelIndex,QModelIndex)));
|
||||
|
||||
// if still undefined, this becomes the global instance
|
||||
if (TaskPanelPrivate::global_instance_.isNull()) {
|
||||
TaskPanelPrivate::global_instance_ = this;
|
||||
// If an explicitly created instance is explicitly destroyed, we don't notice.
|
||||
// If there there were displays "using" it, global_use_count_ is still greater zero.
|
||||
if (TaskPanelPrivate::global_use_count_ > 0); // In this case, don't increment use count
|
||||
else
|
||||
++TaskPanelPrivate::global_use_count_; // otherwise increment use count for explicitly created instance
|
||||
}
|
||||
}
|
||||
|
||||
TaskPanel::~TaskPanel()
|
||||
@ -92,6 +102,28 @@ TaskPanel::~TaskPanel()
|
||||
delete d_ptr;
|
||||
}
|
||||
|
||||
QPointer<TaskPanel> TaskPanelPrivate::global_instance_;
|
||||
uint TaskPanelPrivate::global_use_count_ = 0;
|
||||
|
||||
void TaskPanel::incUseCount(rviz::WindowManagerInterface* window_manager)
|
||||
{
|
||||
++TaskPanelPrivate::global_use_count_;
|
||||
if (TaskPanelPrivate::global_instance_ || !window_manager)
|
||||
return; // already define, nothing to do
|
||||
|
||||
--TaskPanelPrivate::global_use_count_; // counteract ++ in constructor
|
||||
TaskPanelPrivate::global_instance_ = new TaskPanel(window_manager->getParentWindow());
|
||||
TaskPanelPrivate::global_instance_->d_ptr->window_manager_ = window_manager;
|
||||
window_manager->addPane("Motion Planning Tasks", TaskPanelPrivate::global_instance_);
|
||||
}
|
||||
|
||||
void TaskPanel::decUseCount()
|
||||
{
|
||||
Q_ASSERT(TaskPanelPrivate::global_use_count_ > 0);
|
||||
if (--TaskPanelPrivate::global_use_count_ == 0 && TaskPanelPrivate::global_instance_)
|
||||
TaskPanelPrivate::global_instance_->deleteLater();
|
||||
}
|
||||
|
||||
TaskPanelPrivate::TaskPanelPrivate(TaskPanel *q_ptr)
|
||||
: q_ptr(q_ptr)
|
||||
, settings(new rviz::PropertyTreeModel(new rviz::Property, q_ptr))
|
||||
@ -136,6 +168,7 @@ TaskPanelPrivate::getTaskModel(const QModelIndex &index) const
|
||||
|
||||
void TaskPanel::onInitialize()
|
||||
{
|
||||
d_ptr->window_manager_ = vis_manager_->getWindowManager();
|
||||
}
|
||||
|
||||
void TaskPanel::save(rviz::Config config) const
|
||||
@ -171,7 +204,7 @@ void TaskPanel::addTask()
|
||||
|
||||
void TaskPanel::showStageDockWidget()
|
||||
{
|
||||
rviz::PanelDockWidget *dock = getStageDockWidget(vis_manager_->getWindowManager());
|
||||
rviz::PanelDockWidget *dock = getStageDockWidget(d_ptr->window_manager_);
|
||||
if (dock) dock->show();
|
||||
}
|
||||
|
||||
|
||||
@ -42,11 +42,15 @@
|
||||
#include <moveit/macros/class_forward.h>
|
||||
#include <QModelIndex>
|
||||
|
||||
namespace rviz {
|
||||
class WindowManagerInterface;
|
||||
}
|
||||
|
||||
namespace moveit_rviz_plugin {
|
||||
|
||||
class TaskSolutionVisualization;
|
||||
MOVEIT_CLASS_FORWARD(TaskListModel)
|
||||
typedef std::weak_ptr<TaskListModel> TaskListModelWeakPtr;
|
||||
MOVEIT_CLASS_FORWARD(TaskPanel)
|
||||
|
||||
/** The TaskPanel displays information about manipulation tasks in the system.
|
||||
*
|
||||
@ -65,6 +69,14 @@ public:
|
||||
TaskPanel(QWidget* parent = 0);
|
||||
~TaskPanel();
|
||||
|
||||
/** Increment/decrement use count for global task panel instance.
|
||||
*
|
||||
* If not yet done, an instance is created. If use count drops to zero,
|
||||
* the global instance is destroyed.
|
||||
*/
|
||||
static void incUseCount(rviz::WindowManagerInterface *window_manager);
|
||||
static void decUseCount();
|
||||
|
||||
void onInitialize() override;
|
||||
void load(const rviz::Config& config) override;
|
||||
void save(rviz::Config config) const override;
|
||||
|
||||
@ -66,6 +66,10 @@ public:
|
||||
|
||||
TaskPanel* q_ptr;
|
||||
rviz::PropertyTreeModel* settings;
|
||||
rviz::WindowManagerInterface* window_manager_;
|
||||
|
||||
static QPointer<TaskPanel> global_instance_;
|
||||
static uint global_use_count_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user