Skip to content
Snippets Groups Projects
Commit 08264e66 authored by Rainer Kartmann's avatar Rainer Kartmann
Browse files

Add ImageView, show

parent 90fdc841
No related branches found
No related tags found
2 merge requests!120armem/dev,!111Resolve "Show images in ArMemMemoryViewer"
......@@ -17,6 +17,7 @@ set(SOURCES
instance/InstanceTreeDataVisitorBase.cpp
instance/InstanceTreeDataVisitor.cpp
instance/InstanceTreeTypedDataVisitor.cpp
instance/ImageView.cpp
query_widgets/QueryWidget.cpp
query_widgets/SnapshotForm.cpp
......@@ -31,6 +32,7 @@ set(HEADERS
instance/InstanceTreeDataVisitorBase.h
instance/InstanceTreeDataVisitor.h
instance/InstanceTreeTypedDataVisitor.h
instance/ImageView.h
query_widgets/QueryWidget.h
query_widgets/SnapshotForm.h
......
#include "InstanceWidget.h"
#include <QAction>
#include <QGroupBox>
#include <QHBoxLayout>
#include <QHeaderView>
#include <QImage>
#include <QLabel>
#include <QLayout>
#include <QMenu>
#include <QSplitter>
#include <QVBoxLayout>
#include <SimoxUtility/algorithm/string.h>
......@@ -16,6 +19,7 @@
#include <RobotAPI/libraries/armem_gui/gui_utils.h>
#include <RobotAPI/libraries/armem_gui/instance/InstanceTreeDataVisitor.h>
#include <RobotAPI/libraries/armem_gui/instance/InstanceTreeTypedDataVisitor.h>
#include <RobotAPI/libraries/armem_gui/instance/ImageView.h>
namespace armarx::armem::gui
......@@ -25,9 +29,14 @@ namespace armarx::armem::gui
{
QLayout* layout = new QVBoxLayout();
this->setLayout(layout);
int margin = 3;
layout->setContentsMargins(margin, margin, margin, margin);
splitter = new QSplitter(Qt::Orientation::Vertical);
layout->addWidget(splitter);
tree = new QTreeWidget(this);
layout->addWidget(tree);
splitter->addWidget(tree);
QStringList columns;
columns.insert(int(Columns::KEY), "Key");
......@@ -195,14 +204,16 @@ namespace armarx::armem::gui
{
case aron::AronTypeDescriptor::eAronIVTCByteImageType:
{
QAction* viewAction = new QAction("Toggle image view");
QStringList pathAndDel = item->data(int(Columns::KEY), Qt::UserRole).toStringList();
ARMARX_CHECK_EQUAL(pathAndDel.size(), 2);
aron::AronPath path(pathAndDel.at(0).toStdString(), pathAndDel.at(1).toStdString());
QAction* viewAction = new QAction("Show image");
menu.addAction(viewAction);
/*
connect(viewAction, &QAction::triggered, [ = ]()
{
this->detachObjectFromRobotNode(providerName, objectID);
});
*/
connect(viewAction, &QAction::triggered, [this, path]()
{
this->showImageView(path);
});
}
break;
default:
......@@ -212,4 +223,55 @@ namespace armarx::armem::gui
menu.exec(tree->mapToGlobal(pos));
}
void InstanceWidget::showImageView(const aron::AronPath& elementPath)
{
ARMARX_IMPORTANT << "Toggle image view: " << elementPath.toString();
if (!currentInstance)
{
return;
}
armarx::aron::datanavigator::AronDictDataNavigatorPtr data = currentInstance->data();
#if 0
armarx::aron::datanavigator::AronNDArrayDataNavigatorPtr imageData;
std::vector<int> shape = imageData->getDimensions();
ARMARX_CHECK_EQUAL(shape.size(), 3);
QImage::Format format = QImage::Format::Format_Invalid;
switch (shape.at(2))
{
case 1:
format = QImage::Format::Format_Grayscale8;
break;
case 3:
format = QImage::Format::Format_RGB888;
break;
default:
break;
}
currentImage = QImage(imageData->getData(), shape.at(0), shape.at(1), format);
#else
currentImage = QImage(640, 480, QImage::Format::Format_RGB888);
currentImage->fill(QColor(255, 128, 0));
#endif
if (!imageGroup)
{
ARMARX_CHECK_NULL(imageView);
imageGroup = new QGroupBox(this);
splitter->addWidget(imageGroup);
imageGroup->setLayout(new QHBoxLayout());
int margin = 2;
imageGroup->layout()->setContentsMargins(margin, margin, margin, margin);
imageView = new instance::ImageView(this);
imageGroup->layout()->addWidget(imageView);
}
imageGroup->setTitle(QString::fromStdString(elementPath.toString()));
imageView->setImage(*currentImage);
}
}
......@@ -2,18 +2,27 @@
#include <optional>
#include <QTreeWidget>
#include <QWidget>
#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronObjectTypeNavigator.h>
#include <RobotAPI/libraries/armem/core/Memory.h>
class QGroupBox;
class QLabel;
class QSplitter;
class QTreeWidget;
class QTreeWidgetItem;
namespace armarx::armem::gui
{
namespace instance
{
class ImageView;
}
class InstanceWidget : public QWidget
{
......@@ -42,6 +51,7 @@ namespace armarx::armem::gui
private slots:
void prepareTreeContextMenu(const QPoint& pos);
void showImageView(const aron::AronPath& elementPath);
private:
......@@ -60,17 +70,23 @@ namespace armarx::armem::gui
TYPE = 2,
};
std::optional<EntityInstance> currentInstance;
aron::typenavigator::AronObjectTypeNavigatorPtr currentAronType = nullptr;
QSplitter* splitter;
QTreeWidget* tree;
QTreeWidgetItem* treeItemInstanceID;
QTreeWidgetItem* treeItemMetadata;
QTreeWidgetItem* treeItemData;
std::optional<QImage> currentImage;
QGroupBox* imageGroup = nullptr;
instance::ImageView* imageView = nullptr;
QLabel* statusLabel = nullptr;
bool useTypeInfo = true;
std::optional<EntityInstance> currentInstance;
aron::typenavigator::AronObjectTypeNavigatorPtr currentAronType = nullptr;
};
}
/*
* 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 ArmarX::
* @author Rainer Kartmann ( rainer dot kartmann at kit dot edu)
* @date 2021
* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
* GNU General Public License
*/
#include "ImageView.h"
#include <QImage>
#include <QPainter>
#include <ArmarXCore/core/exceptions/local/ExpressionException.h>
namespace armarx::armem::gui::instance
{
ImageView::ImageView(QWidget* parent) : QWidget(parent)
{
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
connect(this, &This::sourceImageChanged, this, &This::updateImage);
}
void ImageView::setImage(const QImage& image)
{
sourceImage = image.copy();
emit sourceImageChanged();
}
void ImageView::paintEvent(QPaintEvent* event)
{
(void) event;
QPainter painter(this);
//scaledImage = image.scaled (width(), height(), Qt::KeepAspectRatio, Qt::FastTransformation);
scaledImage = sourceImage.scaled(width(), height(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
painter.drawImage(0, 0, scaledImage);
}
void ImageView::updateImage()
{
update(0, 0, width(), height());
}
}
/*
* 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 ArmarX::
* @author Rainer Kartmann ( rainer dot kartmann at kit dot edu)
* @date 2021
* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
* GNU General Public License
*/
#pragma once
#include <QWidget>
#include <QImage>
namespace armarx::armem::gui::instance
{
class ImageView : public QWidget
{
Q_OBJECT
using This = ImageView;
public:
ImageView(QWidget* parent = nullptr);
void setImage(const QImage& image);
public slots:
signals:
protected slots:
void updateImage();
signals:
void sourceImageChanged();
protected:
void paintEvent(QPaintEvent* pPaintEvent) override;
private:
QImage sourceImage;
QImage scaledImage;
};
}
......@@ -105,13 +105,19 @@ namespace armarx::armem::gui
protected:
template <class DataNavigator>
bool addValueRow(const std::string& key, DataNavigator& dataNavigator, const TypeNavigator& type)
template <class DataNavigatorT>
bool addValueRow(const std::string& key, DataNavigatorT& dataNavigator, const TypeNavigator& type)
{
aron::AronPath path = dataNavigator.getPath();
if (items.size() > 0)
{
QTreeWidgetItem* item = new QTreeWidgetItem(this->makeValueRowStrings(key, dataNavigator, type.getName()));
items.top()->addChild(item);
item->setData(columnKey, Qt::UserRole, QStringList
{
QString::fromStdString(path.toString()),
QString::fromStdString(path.getDelimeter())
});
item->setData(columnType, Qt::UserRole, int(type.getDescriptor()));
}
return true;
......
......@@ -21,7 +21,7 @@ namespace armarx::armem::gui
setLayout(layout);
_dataCheckBox = new QCheckBox("Get Data");
_dataCheckBox->setChecked(false);
_dataCheckBox->setChecked(true);
_tabWidget = new QTabWidget();
......
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