diff --git a/source/RobotAPI/libraries/armem_gui/CMakeLists.txt b/source/RobotAPI/libraries/armem_gui/CMakeLists.txt index b92bcbfbce86f7bc65bee7a9f186c73d14d0c9b5..92d6c7efdd3afbe72cc54f2bbbb529431ce76653 100644 --- a/source/RobotAPI/libraries/armem_gui/CMakeLists.txt +++ b/source/RobotAPI/libraries/armem_gui/CMakeLists.txt @@ -54,6 +54,9 @@ set(SOURCES query_widgets/SnapshotForm.cpp query_widgets/SnapshotSelectorWidget.cpp + prediction_widget/PredictionWidget.cpp + prediction_widget/TimestampInput.cpp + commit_widget/CommitWidget.cpp ) set(HEADERS @@ -98,6 +101,9 @@ set(HEADERS query_widgets/SnapshotForm.h query_widgets/SnapshotSelectorWidget.h + prediction_widget/PredictionWidget.h + prediction_widget/TimestampInput.h + commit_widget/CommitWidget.h ) diff --git a/source/RobotAPI/libraries/armem_gui/gui_utils.cpp b/source/RobotAPI/libraries/armem_gui/gui_utils.cpp index 29be82baa3cd7501350353fb7b567e2fac456d35..337ebc87d7506f9b4688e3ae3eabed5f4c63d389 100644 --- a/source/RobotAPI/libraries/armem_gui/gui_utils.cpp +++ b/source/RobotAPI/libraries/armem_gui/gui_utils.cpp @@ -86,3 +86,14 @@ QSplitter* armarx::gui::useSplitter(QLayout* layout) return splitter; } + +armarx::gui::LeadingZeroSpinBox::LeadingZeroSpinBox(int numDigits, int base) : + numDigits(numDigits), base(base) +{ +} + +QString +armarx::gui::LeadingZeroSpinBox::textFromValue(int value) const +{ + return QString("%1").arg(value, numDigits, base, QChar('0')); +} diff --git a/source/RobotAPI/libraries/armem_gui/gui_utils.h b/source/RobotAPI/libraries/armem_gui/gui_utils.h index 7979a2f2e8af127023c6c9dee3da719b23546310..1b7b810ad31455a5a1957dce3fb0a56eba21bfe5 100644 --- a/source/RobotAPI/libraries/armem_gui/gui_utils.h +++ b/source/RobotAPI/libraries/armem_gui/gui_utils.h @@ -2,6 +2,7 @@ #include <QLayout> #include <QLayoutItem> +#include <QSpinBox> #include <QWidget> class QLayout; @@ -56,4 +57,18 @@ namespace armarx::gui */ QSplitter* useSplitter(QLayout* layout); + // Source: https://stackoverflow.com/a/26538572 + class LeadingZeroSpinBox : public QSpinBox + { + using QSpinBox::QSpinBox; + + public: + LeadingZeroSpinBox(int numDigits, int base); + + QString textFromValue(int value) const override; + + private: + int numDigits; + int base; + }; } diff --git a/source/RobotAPI/libraries/armem_gui/memory/GroupBox.cpp b/source/RobotAPI/libraries/armem_gui/memory/GroupBox.cpp index 8796557cdcfa2d8f337166cb6181bab6f92111c5..416a988e9848ee8c09a4715050510834f9c099aa 100644 --- a/source/RobotAPI/libraries/armem_gui/memory/GroupBox.cpp +++ b/source/RobotAPI/libraries/armem_gui/memory/GroupBox.cpp @@ -47,6 +47,12 @@ namespace armarx::armem::gui::memory _memoryTabWidget->addTab(_snapshotSelectorWidget, QString("Snapshot Selection")); } + { + _predictionWidget = new armem::gui::PredictionWidget(); + _predictionWidget->setSizePolicy(QSizePolicy::Policy::Expanding, QSizePolicy::Policy::Maximum); + + _memoryTabWidget->addTab(_predictionWidget, QString("Prediction")); + } { _commitWidget = new armem::gui::CommitWidget(); _commitWidget->setSizePolicy(QSizePolicy::Policy::Expanding, QSizePolicy::Policy::Maximum); diff --git a/source/RobotAPI/libraries/armem_gui/memory/GroupBox.h b/source/RobotAPI/libraries/armem_gui/memory/GroupBox.h index 10cf3d5972cc607cfb89fb9b2b0e1962027c9a75..f5233af9c4e2c92c7bcf4bdb45e0496c1bafb4a4 100644 --- a/source/RobotAPI/libraries/armem_gui/memory/GroupBox.h +++ b/source/RobotAPI/libraries/armem_gui/memory/GroupBox.h @@ -4,6 +4,7 @@ #include <RobotAPI/libraries/armem_gui/memory/TreeWidget.h> #include <RobotAPI/libraries/armem_gui/commit_widget/CommitWidget.h> +#include <RobotAPI/libraries/armem_gui/prediction_widget/PredictionWidget.h> #include <RobotAPI/libraries/armem_gui/query_widgets/QueryWidget.h> @@ -49,6 +50,7 @@ namespace armarx::armem::gui::memory QGroupBox* _memoryTabGroup; QueryWidget* _queryWidget; SnapshotSelectorWidget* _snapshotSelectorWidget; + PredictionWidget* _predictionWidget; CommitWidget* _commitWidget; }; diff --git a/source/RobotAPI/libraries/armem_gui/prediction_widget/PredictionWidget.cpp b/source/RobotAPI/libraries/armem_gui/prediction_widget/PredictionWidget.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fe8df6467e7ca277389449bca1a6459035863cfe --- /dev/null +++ b/source/RobotAPI/libraries/armem_gui/prediction_widget/PredictionWidget.cpp @@ -0,0 +1,90 @@ +/* + * 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 RobotAPI::armem::gui + * @author phesch ( ulila at student dot kit dot edu ) + * @date 2022 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#include "PredictionWidget.h" + +#include <QComboBox> +#include <QHBoxLayout> +#include <QLabel> +#include <QLineEdit> +#include <QPushButton> +#include <QSpinBox> +#include <QVBoxLayout> + +namespace armarx::armem::gui +{ + PredictionWidget::PredictionWidget() : + memoryEntity(new QLineEdit()), + timestampInputSelector(new QComboBox()), + timestampLayout(new QHBoxLayout()), + instanceSpinner(new QSpinBox()), + predictionEngineSelector(new QComboBox()), + predictButton(new QPushButton("Copy prediction to clipboard")) + { + auto* vlayout = new QVBoxLayout(); + // memoryEntity->editingFinished() + auto* hlayout = new QHBoxLayout(); + hlayout->addWidget(memoryEntity); + hlayout->addWidget(new QLabel("Entity ID")); + vlayout->addLayout(hlayout); + + timestampInputSelector->addItems({"Absolute", "Relative to latest", "Relative to now"}); + timestampLayout->addWidget(timestampInputSelector); + vlayout->addLayout(timestampLayout); + + //hlayout = new QHBoxLayout(); + //instanceSpinner->setRange(0, std::numeric_limits<int>::max()); + //hlayout->addWidget(instanceSpinner); + //hlayout->addWidget(new QLabel("Instance")); + //vlayout->addLayout(hlayout); + + hlayout = new QHBoxLayout(); + hlayout->addWidget(predictionEngineSelector); + hlayout->addWidget(new QLabel("Prediction engine")); + vlayout->addLayout(hlayout); + + vlayout->addWidget(predictButton); + + addTimestampInputMethod("Absolute", new AbsoluteTimestampInput()); + addTimestampInputMethod("Relative to latest", new RelativeToLatestTimestampInput()); + addTimestampInputMethod("Relative to now", new RelativeToNowTimestampInput()); + + setLayout(vlayout); + + showTimestampInputMethod("Absolute"); + } + + void + PredictionWidget::addTimestampInputMethod(const QString& key, TimestampInput* input) + { + timestampInputs.emplace(key, input); + timestampLayout->addWidget(input); + } + + void PredictionWidget::showTimestampInputMethod(const QString& key) // NOLINT + { + for (const auto& [inputKey, input] : timestampInputs) + { + input->setVisible(key == inputKey); + } + } +} // namespace armarx::armem::gui diff --git a/source/RobotAPI/libraries/armem_gui/prediction_widget/PredictionWidget.h b/source/RobotAPI/libraries/armem_gui/prediction_widget/PredictionWidget.h new file mode 100644 index 0000000000000000000000000000000000000000..5f2cdbd1c53d11e59c280d72a05652d1cc370e08 --- /dev/null +++ b/source/RobotAPI/libraries/armem_gui/prediction_widget/PredictionWidget.h @@ -0,0 +1,63 @@ +/* + * 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 RobotAPI::armem::gui + * @author phesch ( ulila at student dot kit dot edu ) + * @date 2022 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +#include <map> + +#include <QWidget> + +#include "TimestampInput.h" + +class QComboBox; +class QHBoxLayout; +class QLineEdit; +class QPushButton; +class QSpinBox; + +namespace armarx::armem::gui +{ + class PredictionWidget : public QWidget + { + Q_OBJECT // NOLINT + + public: + PredictionWidget(); + + private: + QLineEdit* memoryEntity; + + QComboBox* timestampInputSelector; + QHBoxLayout* timestampLayout; + QSpinBox* instanceSpinner; + QComboBox* predictionEngineSelector; + QPushButton* predictButton; + + std::map<QString, TimestampInput*> timestampInputs; + + void addTimestampInputMethod(const QString& key, TimestampInput* input); + + private slots: // NOLINT + void showTimestampInputMethod(const QString& key); + + }; +} // namespace armarx::armem::gui diff --git a/source/RobotAPI/libraries/armem_gui/prediction_widget/TimestampInput.cpp b/source/RobotAPI/libraries/armem_gui/prediction_widget/TimestampInput.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c87f909af04ea0e44d0d7c51c7c85739695a429f --- /dev/null +++ b/source/RobotAPI/libraries/armem_gui/prediction_widget/TimestampInput.cpp @@ -0,0 +1,58 @@ +/* + * 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 RobotAPI::armem::gui + * @author phesch ( ulila at student dot kit dot edu ) + * @date 2022 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#include "TimestampInput.h" + +#include <QDateTimeEdit> +#include <QHBoxLayout> + +#include <RobotAPI/libraries/armem_gui/gui_utils.h> + +namespace armarx::armem::gui +{ + AbsoluteTimestampInput::AbsoluteTimestampInput() : + dateTime(new QDateTimeEdit(QDateTime::currentDateTime())), + microseconds(new armarx::gui::LeadingZeroSpinBox(6, 10)) + { + dateTime->setDisplayFormat("yyyy-MM-dd HH:mm:ss"); + microseconds->setRange(0, 1000 * 1000 - 1); + microseconds->setSingleStep(1); + // This cast is safe because 999 * 1000 < MAX_INT. + microseconds->setValue( + static_cast<int>((QDateTime::currentMSecsSinceEpoch() % 1000) * 1000)); + + auto* hlayout = new QHBoxLayout(); + hlayout->addWidget(dateTime); + hlayout->addWidget(microseconds); + setLayout(hlayout); + } + + RelativeTimestampInput::RelativeTimestampInput() : + seconds(new QDoubleSpinBox()) + { + auto* hlayout = new QHBoxLayout(); + seconds->setSingleStep(0.1); + seconds->setDecimals(6); + seconds->setValue(0); + setLayout(hlayout); + } +} // namespace armarx::armem::gui diff --git a/source/RobotAPI/libraries/armem_gui/prediction_widget/TimestampInput.h b/source/RobotAPI/libraries/armem_gui/prediction_widget/TimestampInput.h new file mode 100644 index 0000000000000000000000000000000000000000..3f094bdb2de5ffd6557f077a481db650ee1f00b6 --- /dev/null +++ b/source/RobotAPI/libraries/armem_gui/prediction_widget/TimestampInput.h @@ -0,0 +1,71 @@ +/* + * 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 RobotAPI::armem::gui + * @author phesch ( ulila at student dot kit dot edu ) + * @date 2022 + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +#pragma once + +#include <QWidget> + +class QDateTimeEdit; +class QDoubleSpinBox; +namespace armarx::gui +{ + class LeadingZeroSpinBox; +} + +namespace armarx::armem::gui +{ + class TimestampInput : public QWidget + { + Q_OBJECT // NOLINT + }; + + class AbsoluteTimestampInput : public TimestampInput + { + Q_OBJECT // NOLINT + + public : AbsoluteTimestampInput(); + + private: + QDateTimeEdit* dateTime; + armarx::gui::LeadingZeroSpinBox* microseconds; + }; + + class RelativeTimestampInput : public TimestampInput + { + Q_OBJECT // NOLINT + + public : RelativeTimestampInput(); + + private: + QDoubleSpinBox* seconds; + }; + + class RelativeToLatestTimestampInput : public RelativeTimestampInput + { + Q_OBJECT // NOLINT + }; + + class RelativeToNowTimestampInput : public RelativeTimestampInput + { + Q_OBJECT // NOLINT + }; +} // namespace armarx::armem::gui diff --git a/source/RobotAPI/libraries/armem_gui/query_widgets/SnapshotForm.cpp b/source/RobotAPI/libraries/armem_gui/query_widgets/SnapshotForm.cpp index e6ed6aaaf3d6860c2960dbb83215b5791b8b53de..8a9ff01c6b00a1863305e893bab631288d047b0f 100644 --- a/source/RobotAPI/libraries/armem_gui/query_widgets/SnapshotForm.cpp +++ b/source/RobotAPI/libraries/armem_gui/query_widgets/SnapshotForm.cpp @@ -15,6 +15,7 @@ #include <RobotAPI/libraries/armem/core/Time.h> #include <RobotAPI/libraries/armem/core/ice_conversions.h> #include <RobotAPI/libraries/armem/client/query/Builder.h> +#include <RobotAPI/libraries/armem_gui/gui_utils.h> namespace armarx::armem::gui @@ -42,21 +43,6 @@ namespace armarx::armem::gui } - // Source: https://stackoverflow.com/a/26538572 - class LeadingZeroSpinBox : public QSpinBox - { - using QSpinBox::QSpinBox; - - int numDigits = 6; - int base = 10; - - virtual QString textFromValue(int value) const; - }; - QString LeadingZeroSpinBox::textFromValue(int value) const - { - return QString("%1").arg(value, numDigits, base, QChar('0')); - } - SnapshotFormSingle::SnapshotFormSingle() { @@ -68,7 +54,7 @@ namespace armarx::armem::gui dateTime->setDisabled(true); setDateTimeDisplayFormat(dateTime); - microseconds = new LeadingZeroSpinBox(); + microseconds = new armarx::gui::LeadingZeroSpinBox(6, 10); microseconds->setDisabled(true); microseconds->setMinimum(0); microseconds->setMaximum(1000 * 1000 - 1);