diff --git a/source/RobotAPI/gui-plugins/SensorActorWidgetsPlugin/ArmarXPlotter/ArmarXPlotter.cpp b/source/RobotAPI/gui-plugins/SensorActorWidgetsPlugin/ArmarXPlotter/ArmarXPlotter.cpp index 4bd149f05409b740f330aaa64c62ad244e76e99e..c0021acd3478a5906ca01142a198dd8238db81a6 100644 --- a/source/RobotAPI/gui-plugins/SensorActorWidgetsPlugin/ArmarXPlotter/ArmarXPlotter.cpp +++ b/source/RobotAPI/gui-plugins/SensorActorWidgetsPlugin/ArmarXPlotter/ArmarXPlotter.cpp @@ -115,6 +115,7 @@ namespace armarx stackedLayout->addWidget(barsWidget); getWidget()->setLayout(stackedLayout); + } ArmarXPlotter::~ArmarXPlotter() @@ -122,6 +123,7 @@ namespace armarx // if(dialog && this->getState() == eManagedIceObjectInitialized) // getArmarXManager()->removeObjectNonBlocking(dialog); // delete dialog; + } @@ -160,14 +162,20 @@ namespace armarx } + usingTopic("TopicReplayerListener"); + } + void ArmarXPlotter::onExitComponent() { + unsubscribeFromTopic("TopicReplayerListener"); + if (pollingTask) { pollingTask->stop(); } + } void ArmarXPlotter::onCloseWidget(QCloseEvent* event) @@ -194,6 +202,7 @@ namespace armarx dialog->ui.spinBoxUpdateInterval->setValue(updateInterval); dialog->ui.spinBoxShownInterval->setValue(shownInterval); + dialog->ui.syncDataLogging->setChecked(syncDataLogging); dialog->ui.listWidget->clear(); dialog->ui.listWidget->addItems(selectedChannels); // if(dialog->exec()) @@ -214,6 +223,7 @@ namespace armarx pollingInterval = dialog->ui.spinBoxPollingInterval->value(); selectedChannels = dialog->getSelectedChannels(); loggingDir = dialog->ui.editLoggingDirectory->text(); + syncDataLogging = dialog->ui.syncDataLogging->isChecked(); ui.btnLogToFile->setChecked(false); ui.BTNPlotterStatus->setChecked(false); markers.clear(); @@ -230,7 +240,6 @@ namespace armarx { if (toggled) { - std::string filename = "datalog-" + IceUtil::Time::now().toDateTime() + ".csv"; boost::replace_all(filename, "/", "-"); filename = loggingDir.toStdString() + "/" + filename; @@ -527,6 +536,8 @@ namespace armarx settings->setValue("pollingInterval", pollingInterval); settings->setValue("selectedChannels", selectedChannels); settings->setValue("autoScaleActive", ui.BTNAutoScale->isChecked()); + settings->setValue("syncDataLogging", syncDataLogging); + } void ArmarXPlotter::loadSettings(QSettings* settings) @@ -537,6 +548,7 @@ namespace armarx pollingInterval = settings->value("pollingInterval", 33).toInt(); selectedChannels = settings->value("selectedChannels", QStringList()).toStringList(); ui.BTNAutoScale->setChecked(settings->value("autoScaleActive", true).toBool()); + syncDataLogging = settings->value("syncDataLogging", false).toBool(); ARMARX_VERBOSE << "Settings loaded" << flush; } diff --git a/source/RobotAPI/gui-plugins/SensorActorWidgetsPlugin/ArmarXPlotter/ArmarXPlotter.h b/source/RobotAPI/gui-plugins/SensorActorWidgetsPlugin/ArmarXPlotter/ArmarXPlotter.h index 15c0a7f89e570906ed7b6ea1a2d6442317823081..2bf57ee936be87ae041fb84f225ab512077eaf6f 100644 --- a/source/RobotAPI/gui-plugins/SensorActorWidgetsPlugin/ArmarXPlotter/ArmarXPlotter.h +++ b/source/RobotAPI/gui-plugins/SensorActorWidgetsPlugin/ArmarXPlotter/ArmarXPlotter.h @@ -41,6 +41,7 @@ #include <ArmarXCore/observers/variant/Variant.h> #include <ArmarXCore/util/json/JSONObject.h> #include <ArmarXCore/core/services/tasks/PeriodicTask.h> +#include <ArmarXCore/interface/components/TopicRecorderInterface.h> // QT #include <QWidget> #include <QDialog> @@ -78,12 +79,51 @@ namespace armarx */ class ARMARXCOMPONENT_IMPORT_EXPORT ArmarXPlotter: - public ArmarXComponentWidgetController + public ArmarXComponentWidgetController, + public TopicReplayerListenerInterface + { Q_OBJECT public: + void onStartReplay(const Ice::Current& c = Ice::Current()) + { + if (!syncDataLogging) + { + return; + } + + if (!ui.btnLogToFile->isChecked()) + { + ui.btnLogToFile->setChecked(true); + toggleLogging(true); + } + else + { + ARMARX_WARNING << "already logging to file"; + } + } + + void onStopReply(const Ice::Current& c = Ice::Current()) + { + if (!syncDataLogging) + { + return; + } + + if (ui.btnLogToFile->isChecked()) + { + ui.btnLogToFile->setChecked(false); + toggleLogging(false); + } + else + { + ARMARX_WARNING << "not logging to file."; + } + } + + std::map<std::string, QwtPlotCurve*> curves; Ui::ArmarXPlotter ui; QPointer<ArmarXPlotterDialog> dialog; @@ -156,6 +196,7 @@ namespace armarx void logToFile(const IceUtil::Time& time, const std::map<std::string, VariantPtr>& dataMaptoAppend); Mutex dataMutex; + bool syncDataLogging; PeriodicTask<ArmarXPlotter>::pointer_type pollingTask; int pollingInterval = 33; std::ofstream logstream; @@ -168,6 +209,7 @@ namespace armarx std::map<std::string, QwtThermo*> bars; void clearBarList(); + }; } diff --git a/source/RobotAPI/gui-plugins/SensorActorWidgetsPlugin/ArmarXPlotter/ArmarXPlotterDialog.ui b/source/RobotAPI/gui-plugins/SensorActorWidgetsPlugin/ArmarXPlotter/ArmarXPlotterDialog.ui index 4a739efbff645b4943a9e3b245516f36c695245d..b2dc66d441043cc3e1c1a82560140e89cbfb9903 100644 --- a/source/RobotAPI/gui-plugins/SensorActorWidgetsPlugin/ArmarXPlotter/ArmarXPlotterDialog.ui +++ b/source/RobotAPI/gui-plugins/SensorActorWidgetsPlugin/ArmarXPlotter/ArmarXPlotterDialog.ui @@ -25,33 +25,6 @@ <layout class="QVBoxLayout" name="verticalLayout"> <item> <layout class="QGridLayout" name="gridLayout"> - <item row="1" column="0"> - <widget class="QLabel" name="LblUpdateInterval"> - <property name="text"> - <string>Update interval (in ms)</string> - </property> - </widget> - </item> - <item row="0" column="0"> - <widget class="QLabel" name="LBLShownInterval"> - <property name="text"> - <string>Shown Interval (in s)</string> - </property> - </widget> - </item> - <item row="0" column="1"> - <spacer name="horizontalSpacer"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> <item row="4" column="0"> <widget class="QLabel" name="label"> <property name="text"> @@ -59,23 +32,6 @@ </property> </widget> </item> - <item row="5" column="0"> - <widget class="QLabel" name="label_2"> - <property name="text"> - <string>Logging directory</string> - </property> - </widget> - </item> - <item row="5" column="1" colspan="2"> - <widget class="QLineEdit" name="editLoggingDirectory"/> - </item> - <item row="5" column="3"> - <widget class="QToolButton" name="btnSelectLoggingDir"> - <property name="text"> - <string>...</string> - </property> - </widget> - </item> <item row="4" column="2" colspan="2"> <widget class="QSpinBox" name="spinBoxPollingInterval"> <property name="minimum"> @@ -89,6 +45,19 @@ </property> </widget> </item> + <item row="0" column="1"> + <spacer name="horizontalSpacer"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> <item row="1" column="2" colspan="2"> <widget class="QSpinBox" name="spinBoxUpdateInterval"> <property name="buttonSymbols"> @@ -108,6 +77,30 @@ </property> </widget> </item> + <item row="1" column="0"> + <widget class="QLabel" name="LblUpdateInterval"> + <property name="text"> + <string>Update interval (in ms)</string> + </property> + </widget> + </item> + <item row="6" column="1" colspan="2"> + <widget class="QLineEdit" name="editLoggingDirectory"/> + </item> + <item row="0" column="0"> + <widget class="QLabel" name="LBLShownInterval"> + <property name="text"> + <string>Shown Interval (in s)</string> + </property> + </widget> + </item> + <item row="6" column="3"> + <widget class="QToolButton" name="btnSelectLoggingDir"> + <property name="text"> + <string>...</string> + </property> + </widget> + </item> <item row="0" column="2" colspan="2"> <widget class="QSpinBox" name="spinBoxShownInterval"> <property name="minimum"> @@ -121,6 +114,20 @@ </property> </widget> </item> + <item row="6" column="0"> + <widget class="QLabel" name="label_2"> + <property name="text"> + <string>Logging directory</string> + </property> + </widget> + </item> + <item row="7" column="0"> + <widget class="QCheckBox" name="syncDataLogging"> + <property name="text"> + <string>Synchronize data logging with TopicReplayer</string> + </property> + </widget> + </item> </layout> </item> <item> diff --git a/source/RobotAPI/gui-plugins/SensorActorWidgetsPlugin/CMakeLists.txt b/source/RobotAPI/gui-plugins/SensorActorWidgetsPlugin/CMakeLists.txt index 48671d0e8edda743e028eec78bfca31ce88660df..b299fbdfbccf8916f2d6b434c0918e5577ea1fc1 100644 --- a/source/RobotAPI/gui-plugins/SensorActorWidgetsPlugin/CMakeLists.txt +++ b/source/RobotAPI/gui-plugins/SensorActorWidgetsPlugin/CMakeLists.txt @@ -64,7 +64,7 @@ set(GUI_UIS ) -set(COMPONENT_LIBS RobotAPIUnits ArmarXCoreObservers ObserverPropertiesGuiPlugin RobotAPIInterfaces ${qwt_LIBRARIES} ${Simox_LIBRARIES} ${QT_LIBRARIES}) +set(COMPONENT_LIBS RobotAPIUnits ArmarXCoreTopicRecording ArmarXCoreObservers ObserverPropertiesGuiPlugin RobotAPIInterfaces ${qwt_LIBRARIES} ${Simox_LIBRARIES} ${QT_LIBRARIES})