Skip to content
Snippets Groups Projects
Commit 79053547 authored by Dominik Muth's avatar Dominik Muth
Browse files

added debug layer widget as library

parent 402c2be9
No related branches found
No related tags found
No related merge requests found
add_subdirectory(drivers)
add_subdirectory(core)
add_subdirectory(widgets)
armarx_set_target("RobotAPI Library: RobotAPIWidgets")
find_package(Qt4 COMPONENTS QtCore QtGui QtDesigner)
armarx_build_if(QT_FOUND "Qt not available")
find_package(Coin3D REQUIRED)
armarx_build_if(Coin3D_FOUND "Coin3D not available")
find_package(SoQt REQUIRED)
armarx_build_if(SOQT_FOUND "SoQt not available")
find_package(jsoncpp QUIET)
armarx_build_if(jsoncpp_FOUND "jsoncpp not available")
include(${QT_USE_FILE})
include_directories(${Eigen3_INCLUDE_DIR})
include_directories(
${Coin3D_INCLUDE_DIRS}
${SoQt_INCLUDE_DIRS}
${jsoncpp_INCLUDE_DIR})
set(LIB_NAME RobotAPIWidgets)
set(LIBS ArmarXCore RobotAPICore ${QT_LIBRARIES})
set(LIB_FILES
DebugLayerControlWidget.cpp
)
set(LIB_HEADERS
DebugLayerControlWidget.h
)
set(GUI_UIS
DebugLayerControlWidget.ui
)
# and finally a resource file
#SET( QT_RESOURCES
# armarxicons.qrc
#)
#QT4_ADD_RESOURCES( QT_RC_SRCS ${QT_RESOURCES} )
qt4_wrap_cpp(LIB_FILES
DebugLayerControlWidget.h
)
qt4_wrap_ui(UI_HEADER ${GUI_UIS})
list(APPEND LIB_HEADERS ${UI_HEADER})
#list(APPEND LIB_FILES ${QT_RC_SRCS})
armarx_add_library("${LIB_NAME}" "${LIB_FILES}" "${LIB_HEADERS}" "${LIBS}")
#include "DebugLayerControlWidget.h"
#include <RobotAPI/libraries/widgets/ui_DebugLayerControlWidget.h>
#define UPDATE_INTERVAL 1.0 // update every second
DebugLayerControlWidget::DebugLayerControlWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::DebugLayerControlWidget)
{
entityDrawer = NULL;
ui->setupUi(this);
//init timer
SoSensorManager* sensor_mgr = SoDB::getSensorManager();
timerSensor = new SoTimerSensor(onTimer, this);
timerSensor->setInterval(SbTime(UPDATE_INTERVAL));
sensor_mgr->insertTimerSensor(timerSensor);
//connect signal mapper
QObject::connect(&layerSignalMapperVisible,SIGNAL(mapped(QString)),this,SLOT(layerToggleVisibility(QString)));
QObject::connect(&layerSignalMapperRemove,SIGNAL(mapped(QString)),this,SLOT(layerRemove(QString)));
}
DebugLayerControlWidget::~DebugLayerControlWidget()
{
//destroy timer
if (timerSensor)
{
SoSensorManager* sensor_mgr = SoDB::getSensorManager();
sensor_mgr->removeTimerSensor(timerSensor);
}
delete ui;
}
void DebugLayerControlWidget::setEntityDrawer(DebugDrawerComponentPtr entityDrawer)
{
this->entityDrawer = entityDrawer;
}
void DebugLayerControlWidget::updateLayers()
{
//ui.layerTable->clear();
if (entityDrawer) {
armarx::LayerInformationSequence layers = entityDrawer->layerInformation();
ui->layerTable->setRowCount(layers.size());
for (std::size_t i=0;i<layers.size();++i)
{
const auto& layer=layers.at(i);
QString name=QString::fromStdString(layer.layerName);
//store visibility
layerVisibility[layer.layerName]=layer.visible;
//add name and number of elements
ui->layerTable->setItem(i,0,new QTableWidgetItem{name});
ui->layerTable->setItem(i,1,new QTableWidgetItem{QString::number(layer.elementCount)});
//add visibility checkbox
std::unique_ptr<QCheckBox> box{new QCheckBox};
box->setChecked(layer.visible);
layerSignalMapperVisible.setMapping(box.get(),name);
QObject::connect(box.get(), SIGNAL(stateChanged(int)), &layerSignalMapperVisible, SLOT(map()));
ui->layerTable->setCellWidget(i,2,box.release());
//add remove button
std::unique_ptr<QPushButton> removeB{new QPushButton("remove")};
layerSignalMapperRemove.setMapping(removeB.get(),name);
QObject::connect(removeB.get(), SIGNAL(clicked()), &layerSignalMapperRemove, SLOT(map()));
ui->layerTable->setCellWidget(i, 3, removeB.release());
}
} else {
VR_INFO << "No Debug Drawer" << std::endl;
}
}
void DebugLayerControlWidget::layerToggleVisibility(QString layerName)
{
//VR_INFO << "should toggle: " << layerName.toStdString() << std::endl;
auto name = layerName.toStdString();
if (layerVisibility.find(name)!=layerVisibility.end())
{
if (entityDrawer)
{
entityDrawer->enableLayerVisu(name, !layerVisibility.at(name));
}
} else
VR_INFO << "name not present" << std::endl;
}
void DebugLayerControlWidget::layerRemove(QString layerName)
{
auto name = layerName.toStdString();
VR_INFO << "remove layer: " << name << std::endl;
if (entityDrawer->hasLayer(name)) {
entityDrawer->removeLayer(name);
} else
VR_INFO << "name not present" << std::endl;
}
void DebugLayerControlWidget::onTimer(void* data, SoSensor *sensor)
{
DebugLayerControlWidget* controller = static_cast<DebugLayerControlWidget*>(data);
if (controller)
controller->updateLayers();
}
/*
* This file is part of ArmarX.
*
* ArmarX is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* ArmarX is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package MemoryX::WorkingMemoryGui
* @author Dominik Muth
* @copyright 2015 KIT
* @license http://www.gnu.org/licenses/gpl-2.0.txt
* GNU General Public License
*/
#ifndef DEBUGLAYERWIDGET_H
#define DEBUGLAYERWIDGET_H
/* ArmarX headers */
#include <ArmarXCore/core/Component.h>
#include <RobotAPI/components/DebugDrawer/DebugDrawerComponent.h>
/* QT headers */
#include <QWidget>
#include <QCheckBox>
#include <QSignalMapper>
#include <QPushButton>
/* STD headers */
#include <unordered_map>
/* Inventor headers */
#include <Inventor/sensors/SoTimerSensor.h>
#include <Inventor/SoDB.h>
#include <Inventor/Qt/SoQt.h>
/* System headers */
#include <string>
using namespace armarx;
namespace Ui {
class DebugLayerControlWidget;
}
class DebugLayerControlWidget : public QWidget
{
Q_OBJECT
public:
DebugLayerControlWidget(QWidget *parent = 0);
~DebugLayerControlWidget();
void setEntityDrawer(DebugDrawerComponentPtr entityDrawer);
public slots:
void updateLayers();
void layerToggleVisibility(QString layerName);
protected:
DebugDrawerComponentPtr entityDrawer;
SoTimerSensor* timerSensor;
/**
* @brief Maps events to toggle a layer's visibility from checkboxes contained in the table to layerToggleVisibility.
*/
QSignalMapper layerSignalMapperVisible;
/**
* @brief Maps events to remove a layer.
*/
QSignalMapper layerSignalMapperRemove;
/**
* @brief Stores whether a layer is currently visible.
*/
std::unordered_map<std::string,bool> layerVisibility;
static void onTimer(void *data, SoSensor *sensor);
protected slots:
void layerRemove(QString layerName);
private:
Ui::DebugLayerControlWidget *ui;
};
#endif // DEBUGLAYERWIDGET_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DebugLayerControlWidget</class>
<widget class="QWidget" name="DebugLayerControlWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>447</width>
<height>197</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QGroupBox" name="groupBoxLayer">
<property name="title">
<string>Visualisation layer</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QTableWidget" name="layerTable">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="showDropIndicator" stdset="0">
<bool>false</bool>
</property>
<property name="dragDropOverwriteMode">
<bool>false</bool>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::NoSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<column>
<property name="text">
<string>Name</string>
</property>
</column>
<column>
<property name="text">
<string>Elements</string>
</property>
</column>
<column>
<property name="text">
<string>Visible</string>
</property>
</column>
<column>
<property name="text">
<string/>
</property>
</column>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment