From 76e83df885a8329631c48fb3f95a42788c0d86de Mon Sep 17 00:00:00 2001
From: Peter Kaiser <peter.kaiser@kit.edu>
Date: Mon, 4 Jun 2018 19:22:25 +0200
Subject: [PATCH] Added MessageDisplayPlugin

---
 data/ArmarXGui/VariantInfo-ArmarXGui.xml      |   8 ++
 source/ArmarXGui/gui-plugins/CMakeLists.txt   |   2 +
 .../MessageDisplayPlugin/CMakeLists.txt       |  41 ++++++
 .../MessageDisplayPluginGuiPlugin.cpp         |  36 +++++
 .../MessageDisplayPluginGuiPlugin.h           |  52 ++++++++
 .../MessageDisplayPluginWidget.ui             |  65 +++++++++
 .../MessageDisplayPluginWidgetController.cpp  | 110 ++++++++++++++++
 .../MessageDisplayPluginWidgetController.h    | 124 ++++++++++++++++++
 source/ArmarXGui/interface/CMakeLists.txt     |   1 +
 .../interface/MessageDisplayInterface.ice     |  32 +++++
 10 files changed, 471 insertions(+)
 create mode 100644 source/ArmarXGui/gui-plugins/MessageDisplayPlugin/CMakeLists.txt
 create mode 100644 source/ArmarXGui/gui-plugins/MessageDisplayPlugin/MessageDisplayPluginGuiPlugin.cpp
 create mode 100644 source/ArmarXGui/gui-plugins/MessageDisplayPlugin/MessageDisplayPluginGuiPlugin.h
 create mode 100644 source/ArmarXGui/gui-plugins/MessageDisplayPlugin/MessageDisplayPluginWidget.ui
 create mode 100644 source/ArmarXGui/gui-plugins/MessageDisplayPlugin/MessageDisplayPluginWidgetController.cpp
 create mode 100644 source/ArmarXGui/gui-plugins/MessageDisplayPlugin/MessageDisplayPluginWidgetController.h
 create mode 100644 source/ArmarXGui/interface/MessageDisplayInterface.ice

diff --git a/data/ArmarXGui/VariantInfo-ArmarXGui.xml b/data/ArmarXGui/VariantInfo-ArmarXGui.xml
index 865993f9..eebe860b 100644
--- a/data/ArmarXGui/VariantInfo-ArmarXGui.xml
+++ b/data/ArmarXGui/VariantInfo-ArmarXGui.xml
@@ -11,5 +11,13 @@
             propertyName="StaticPlotterName"
             propertyIsOptional="true"
             propertyDefaultValue="StaticPlotter" />
+        <Topic include="ArmarXGui/interface/MessageDisplayInterface.h"
+            humanName="Message Display Topic"
+            typeName="MessageDisplayInterfacePrx"
+            memberName="messageDisplay"
+            getterName="getMessageDisplayTopic"
+            propertyName="MessageDisplayName"
+            propertyIsOptional="true"
+            propertyDefaultValue="MessageDisplayTopic" />
     </Lib>
 </VariantInfo>
diff --git a/source/ArmarXGui/gui-plugins/CMakeLists.txt b/source/ArmarXGui/gui-plugins/CMakeLists.txt
index 5155abfe..55121f1a 100644
--- a/source/ArmarXGui/gui-plugins/CMakeLists.txt
+++ b/source/ArmarXGui/gui-plugins/CMakeLists.txt
@@ -16,3 +16,5 @@ add_subdirectory(TopicReplayerPlugin)
 add_subdirectory(IceProxy)
 
 add_subdirectory(PlotterPlugin)
+
+add_subdirectory(MessageDisplayPlugin)
\ No newline at end of file
diff --git a/source/ArmarXGui/gui-plugins/MessageDisplayPlugin/CMakeLists.txt b/source/ArmarXGui/gui-plugins/MessageDisplayPlugin/CMakeLists.txt
new file mode 100644
index 00000000..1f397331
--- /dev/null
+++ b/source/ArmarXGui/gui-plugins/MessageDisplayPlugin/CMakeLists.txt
@@ -0,0 +1,41 @@
+
+armarx_set_target("MessageDisplayPluginGuiPlugin")
+
+# most qt components will be linked against in the call armarx_gui_library
+#armarx_find_qt(QtCore QtGui QtDesigner)
+
+# ArmarXGui gets included through depends_on_armarx_package(ArmarXGui "OPTIONAL")
+# in the toplevel CMakeLists.txt
+armarx_build_if(ArmarXGui_FOUND "ArmarXGui not available")
+
+
+# all include_directories must be guarded by if(Xyz_FOUND)
+# for multiple libraries write: if(X_FOUND AND Y_FOUND)....
+#if(Xyz_FOUND)
+#    include(${Xyz_INCLUDE_DIRECTORIES})
+#endif()
+
+set(SOURCES
+./MessageDisplayPluginGuiPlugin.cpp ./MessageDisplayPluginWidgetController.cpp
+#@TEMPLATE_LINE@@COMPONENT_PATH@/@COMPONENT_NAME@GuiPlugin.cpp @COMPONENT_PATH@/@COMPONENT_NAME@WidgetController.cpp
+)
+
+# do not rename this variable, it is used in armarx_gui_library()...
+set(HEADERS
+./MessageDisplayPluginGuiPlugin.h ./MessageDisplayPluginWidgetController.h
+#@TEMPLATE_LINE@@COMPONENT_PATH@/@COMPONENT_NAME@GuiPlugin.h @COMPONENT_PATH@/@COMPONENT_NAME@WidgetController.h
+)
+
+set(GUI_MOC_HDRS ${HEADERS})
+
+set(GUI_UIS
+./MessageDisplayPluginWidget.ui
+#@TEMPLATE_LINE@@COMPONENT_PATH@/@COMPONENT_NAME@Widget.ui
+)
+
+# Add more libraries you depend on here, e.g. ${QT_LIBRARIES}.
+set(COMPONENT_LIBS ArmarXGuiInterfaces)
+
+if(ArmarXGui_FOUND)
+	armarx_gui_library(MessageDisplayPluginGuiPlugin "${SOURCES}" "${GUI_MOC_HDRS}" "${GUI_UIS}" "" "${COMPONENT_LIBS}")
+endif()
diff --git a/source/ArmarXGui/gui-plugins/MessageDisplayPlugin/MessageDisplayPluginGuiPlugin.cpp b/source/ArmarXGui/gui-plugins/MessageDisplayPlugin/MessageDisplayPluginGuiPlugin.cpp
new file mode 100644
index 00000000..f9da1abd
--- /dev/null
+++ b/source/ArmarXGui/gui-plugins/MessageDisplayPlugin/MessageDisplayPluginGuiPlugin.cpp
@@ -0,0 +1,36 @@
+/*
+ * 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    ArmarXGui::gui-plugins::MessageDisplayPluginGuiPlugin
+ * \author     Peter Kaiser ( peter dot kaiser at kit dot edu )
+ * \date       2018
+ * \copyright  http://www.gnu.org/licenses/gpl-2.0.txt
+ *             GNU General Public License
+ */
+
+#include "MessageDisplayPluginGuiPlugin.h"
+
+#include "MessageDisplayPluginWidgetController.h"
+
+using namespace armarx;
+
+MessageDisplayPluginGuiPlugin::MessageDisplayPluginGuiPlugin()
+{
+    addWidget < MessageDisplayPluginWidgetController > ();
+}
+
+#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
+Q_EXPORT_PLUGIN2(armarx_gui_MessageDisplayPluginGuiPlugin, MessageDisplayPluginGuiPlugin)
+#endif
diff --git a/source/ArmarXGui/gui-plugins/MessageDisplayPlugin/MessageDisplayPluginGuiPlugin.h b/source/ArmarXGui/gui-plugins/MessageDisplayPlugin/MessageDisplayPluginGuiPlugin.h
new file mode 100644
index 00000000..572d9b95
--- /dev/null
+++ b/source/ArmarXGui/gui-plugins/MessageDisplayPlugin/MessageDisplayPluginGuiPlugin.h
@@ -0,0 +1,52 @@
+/*
+ * 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    ArmarXGui::gui-plugins::MessageDisplayPlugin
+ * \author     Peter Kaiser ( peter dot kaiser at kit dot edu )
+ * \date       2018
+ * \copyright  http://www.gnu.org/licenses/gpl-2.0.txt
+ *             GNU General Public License
+ */
+#pragma once
+
+#include <ArmarXCore/core/system/ImportExportComponent.h>
+#include <ArmarXGui/libraries/ArmarXGuiBase/ArmarXGuiPlugin.h>
+#include <ArmarXGui/libraries/ArmarXGuiBase/ArmarXComponentWidgetController.h>
+
+namespace armarx
+{
+    /**
+     * \class MessageDisplayPluginGuiPlugin
+     * \ingroup ArmarXGuiPlugins
+     * \brief MessageDisplayPluginGuiPlugin brief description
+     *
+     * Detailed description
+     */
+    class ARMARXCOMPONENT_IMPORT_EXPORT MessageDisplayPluginGuiPlugin:
+        public armarx::ArmarXGuiPlugin
+    {
+        Q_OBJECT
+#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
+        Q_INTERFACES(ArmarXGuiInterface)
+        Q_PLUGIN_METADATA(IID "ArmarXGuiInterface/1.00")
+#endif
+    public:
+        /**
+         * All widgets exposed by this plugin are added in the constructor
+         * via calls to addWidget()
+         */
+        MessageDisplayPluginGuiPlugin();
+    };
+}
diff --git a/source/ArmarXGui/gui-plugins/MessageDisplayPlugin/MessageDisplayPluginWidget.ui b/source/ArmarXGui/gui-plugins/MessageDisplayPlugin/MessageDisplayPluginWidget.ui
new file mode 100644
index 00000000..b57944e8
--- /dev/null
+++ b/source/ArmarXGui/gui-plugins/MessageDisplayPlugin/MessageDisplayPluginWidget.ui
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>MessageDisplayPluginWidget</class>
+ <widget class="QWidget" name="MessageDisplayPluginWidget">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>1122</width>
+    <height>169</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>MessageDisplayPluginWidget</string>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout_2">
+   <item>
+    <widget class="QLabel" name="labelCaption">
+     <property name="font">
+      <font>
+       <pointsize>48</pointsize>
+       <weight>75</weight>
+       <bold>true</bold>
+      </font>
+     </property>
+     <property name="autoFillBackground">
+      <bool>false</bool>
+     </property>
+     <property name="text">
+      <string/>
+     </property>
+     <property name="textFormat">
+      <enum>Qt::AutoText</enum>
+     </property>
+     <property name="scaledContents">
+      <bool>true</bool>
+     </property>
+     <property name="alignment">
+      <set>Qt::AlignCenter</set>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <widget class="QLabel" name="labelSubcaption">
+     <property name="font">
+      <font>
+       <pointsize>30</pointsize>
+      </font>
+     </property>
+     <property name="text">
+      <string/>
+     </property>
+     <property name="scaledContents">
+      <bool>true</bool>
+     </property>
+     <property name="alignment">
+      <set>Qt::AlignCenter</set>
+     </property>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/source/ArmarXGui/gui-plugins/MessageDisplayPlugin/MessageDisplayPluginWidgetController.cpp b/source/ArmarXGui/gui-plugins/MessageDisplayPlugin/MessageDisplayPluginWidgetController.cpp
new file mode 100644
index 00000000..7bee7d70
--- /dev/null
+++ b/source/ArmarXGui/gui-plugins/MessageDisplayPlugin/MessageDisplayPluginWidgetController.cpp
@@ -0,0 +1,110 @@
+/*
+ * 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    ArmarXGui::gui-plugins::MessageDisplayPluginWidgetController
+ * \author     Peter Kaiser ( peter dot kaiser at kit dot edu )
+ * \date       2018
+ * \copyright  http://www.gnu.org/licenses/gpl-2.0.txt
+ *             GNU General Public License
+ */
+
+#include "MessageDisplayPluginWidgetController.h"
+
+#include <string>
+#include <sstream>
+
+using namespace armarx;
+
+#define FADE_TIMER_MSEC 100
+#define FADE_DURATION 2000
+
+MessageDisplayPluginWidgetController::MessageDisplayPluginWidgetController()
+{
+    widget.setupUi(getWidget());
+}
+
+
+MessageDisplayPluginWidgetController::~MessageDisplayPluginWidgetController()
+{
+
+}
+
+
+void MessageDisplayPluginWidgetController::loadSettings(QSettings* settings)
+{
+
+}
+
+void MessageDisplayPluginWidgetController::saveSettings(QSettings* settings)
+{
+
+}
+
+
+void MessageDisplayPluginWidgetController::onInitComponent()
+{
+    usingTopic("MessageDisplayTopic");
+
+    // Don't display anything on startup
+    widget.labelCaption->setText("");
+    widget.labelSubcaption->setText("");
+
+    connect(&fadeTimer, SIGNAL(timeout()), this, SLOT(timerEvent()));
+    connect(this, SIGNAL(setMessageContent(QString,QString)), this, SLOT(setMessageContentImpl(QString,QString)));
+}
+
+
+void MessageDisplayPluginWidgetController::onConnectComponent()
+{
+
+}
+
+void MessageDisplayPluginWidgetController::setMessage(const std::string &caption, const std::string &subCaption, const Ice::Current &)
+{
+    ARMARX_INFO << "New message: " << caption << " (" << subCaption << ")";
+    emit setMessageContent(QString::fromStdString(caption), QString::fromStdString(subCaption));
+}
+
+void MessageDisplayPluginWidgetController::timerEvent()
+{
+    fadeDuration -= FADE_TIMER_MSEC;
+    if (fadeDuration <= 0)
+    {
+        fadeTimer.stop();
+    }
+
+    std::stringstream ss;
+    ss << "#" << std::hex << (int)(255 * (((float)fadeDuration) / FADE_DURATION)) << "0000";
+
+    ARMARX_INFO << ("<font color='" + QString::fromStdString(ss.str()) + "'>" + currentCaption + "</font>").toStdString();
+    widget.labelCaption->setText("<font color='" + QString::fromStdString(ss.str()) + "'>" + currentCaption + "</font>");
+    widget.labelSubcaption->setText("<font color='" + QString::fromStdString(ss.str()) + "'>" + currentSubCaption + "</font>");
+}
+
+void MessageDisplayPluginWidgetController::setMessageContentImpl(const QString &caption, const QString &subcaption)
+{
+    ARMARX_INFO << "PPP";
+
+    fadeTimer.stop();
+
+    currentCaption = caption;
+    currentSubCaption = subcaption;
+
+    widget.labelCaption->setText("<font color='#FF0000'>" + currentCaption + "</font>");
+    widget.labelSubcaption->setText("<font color='#FF0000'>" + currentSubCaption + "</font>");
+
+    fadeDuration = FADE_DURATION;
+    fadeTimer.start(FADE_TIMER_MSEC);
+}
diff --git a/source/ArmarXGui/gui-plugins/MessageDisplayPlugin/MessageDisplayPluginWidgetController.h b/source/ArmarXGui/gui-plugins/MessageDisplayPlugin/MessageDisplayPluginWidgetController.h
new file mode 100644
index 00000000..4ff19e2c
--- /dev/null
+++ b/source/ArmarXGui/gui-plugins/MessageDisplayPlugin/MessageDisplayPluginWidgetController.h
@@ -0,0 +1,124 @@
+/*
+ * 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    ArmarXGui::gui-plugins::MessageDisplayPluginWidgetController
+ * @author     Peter Kaiser ( peter dot kaiser at kit dot edu )
+ * @date       2018
+ * @copyright  http://www.gnu.org/licenses/gpl-2.0.txt
+ *             GNU General Public License
+ */
+#pragma once
+
+#include "ui_MessageDisplayPluginWidget.h"
+
+#include <ArmarXGui/libraries/ArmarXGuiBase/ArmarXGuiPlugin.h>
+#include <ArmarXGui/libraries/ArmarXGuiBase/ArmarXComponentWidgetController.h>
+#include <ArmarXGui/interface/MessageDisplayInterface.h>
+
+#include <ArmarXCore/core/system/ImportExportComponent.h>
+
+#include <QTimer>
+
+namespace armarx
+{
+    /**
+    \page ArmarXGui-GuiPlugins-MessageDisplayPlugin MessageDisplayPlugin
+    \brief The MessageDisplayPlugin allows visualizing ...
+
+    \image html MessageDisplayPlugin.png
+    The user can
+
+    API Documentation \ref MessageDisplayPluginWidgetController
+
+    \see MessageDisplayPluginGuiPlugin
+    */
+
+    /**
+     * \class MessageDisplayPluginWidgetController
+     * \brief MessageDisplayPluginWidgetController brief one line description
+     *
+     * Detailed description
+     */
+    class ARMARXCOMPONENT_IMPORT_EXPORT
+        MessageDisplayPluginWidgetController:
+        public armarx::ArmarXComponentWidgetControllerTemplate < MessageDisplayPluginWidgetController >,
+        public armarx::MessageDisplayInterface
+    {
+        Q_OBJECT
+
+    public:
+        /**
+         * Controller Constructor
+         */
+        explicit MessageDisplayPluginWidgetController();
+
+        /**
+         * Controller destructor
+         */
+        virtual ~MessageDisplayPluginWidgetController();
+
+        /**
+         * @see ArmarXWidgetController::loadSettings()
+         */
+        void loadSettings(QSettings* settings) override;
+
+        /**
+         * @see ArmarXWidgetController::saveSettings()
+         */
+        void saveSettings(QSettings* settings) override;
+
+        /**
+         * Returns the Widget name displayed in the ArmarXGui to create an
+         * instance of this class.
+         */
+        static QString GetWidgetName()
+        {
+            return "Util.MessageDisplayPlugin";
+        }
+
+        /**
+         * \see armarx::Component::onInitComponent()
+         */
+        void onInitComponent() override;
+
+        /**
+         * \see armarx::Component::onConnectComponent()
+         */
+        void onConnectComponent() override;
+
+        void setMessage(const std::string& caption, const std::string& subCaption, const Ice::Current&) override;
+
+    public slots:
+        void timerEvent();
+        void setMessageContentImpl(const QString& caption, const QString& subcaption);
+
+    signals:
+        void setMessageContent(const QString& caption, const QString& subcaption);
+
+    private:
+        /**
+         * Widget Form
+         */
+        Ui::MessageDisplayPluginWidget widget;
+
+        QTimer fadeTimer;
+        int fadeDuration;
+
+        QString currentCaption;
+        QString currentSubCaption;
+    };
+}
+
+
diff --git a/source/ArmarXGui/interface/CMakeLists.txt b/source/ArmarXGui/interface/CMakeLists.txt
index c4c30f52..7d0e5ace 100644
--- a/source/ArmarXGui/interface/CMakeLists.txt
+++ b/source/ArmarXGui/interface/CMakeLists.txt
@@ -7,6 +7,7 @@ set(ARMARXGUI_INTERFACE_DEPEND ArmarXCore)
 set(SLICE_FILES
     WidgetDescription.ice
     StaticPlotterInterface.ice
+    MessageDisplayInterface.ice
 )
 
 # generate the interface library
diff --git a/source/ArmarXGui/interface/MessageDisplayInterface.ice b/source/ArmarXGui/interface/MessageDisplayInterface.ice
new file mode 100644
index 00000000..eaff9b44
--- /dev/null
+++ b/source/ArmarXGui/interface/MessageDisplayInterface.ice
@@ -0,0 +1,32 @@
+/*
+ * 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::ArmarXGui
+ * @author     Peter Kaiser (peter dot kaiser at kit dot edu)
+ * @date       2018
+ * @copyright  http://www.gnu.org/licenses/gpl-2.0.txt
+ *             GNU General Public License
+ */
+#pragma once
+
+module armarx
+{
+    interface MessageDisplayInterface
+    {
+        void setMessage(string caption, string subCaption);
+    };
+
+};
+
-- 
GitLab