31 #include <SimoxUtility/algorithm/string/string_tools.h>
38 #include <QStackedLayout>
42 #include <IceUtil/IceUtil.h>
60 plotterController->
setGraphStyle(
ui.CBgraphStyle->currentText().toStdString());
79 connect(
ui.BTNEdit, SIGNAL(clicked()),
this, SLOT(
configDialog()));
80 connect(
ui.BTNPlotterStatus, SIGNAL(toggled(
bool)), plotterController, SLOT(plottingPaused(
bool)));
82 connect(
ui.BTNAutoScale, SIGNAL(toggled(
bool)), plotterController, SLOT(autoScale(
bool)));
84 connect(
ui.btnLogToFile, SIGNAL(toggled(
bool)),
this, SLOT(
toggleLogging(
bool)));
86 connect(
ui.CBgraphStyle, SIGNAL(currentTextChanged(QString)),
this, SLOT(
onGraphStyleChanged(QString)));
88 connect(
ui.btnClearHistory, SIGNAL(clicked()), plotterController, SLOT(clearHistory()));
90 if (!QMetaObject::invokeMethod(plotterController,
"setupCurves"))
101 plotterController->deleteLater();
109 if (logstream.is_open())
128 dialog->ui.syncDataLogging->setChecked(syncDataLogging);
129 dialog->ui.listWidget->clear();
144 std::unique_lock lock(dataMutex);
150 syncDataLogging =
dialog->ui.syncDataLogging->isChecked();
151 ui.btnLogToFile->setChecked(
false);
152 ui.BTNPlotterStatus->setChecked(
false);
161 std::lock_guard<std::mutex> lock(mutex);
165 std::filesystem::path outputPath;
166 if (filename.empty())
168 outputPath =
loggingDir.toStdString() +
"/datalog.csv";
170 std::string time = IceUtil::Time::now().toDateTime();
171 time = simox::alg::replace_all(time,
"/",
"-");
172 time = simox::alg::replace_all(time,
" ",
"_");
173 time = simox::alg::replace_all(time,
":",
"-");
174 outputPath = outputPath.parent_path() / (outputPath.stem().string() +
"-" + time + outputPath.extension().string());
179 std::filesystem::path path = filename;
180 outputPath =
loggingDir.toStdString() +
"/" + path.stem().string() +
".csv";
183 ARMARX_INFO <<
"Logging to " << outputPath.string();
184 logstream.open(outputPath.string());
185 logStartTime = IceUtil::Time::now();
187 if (!logstream.is_open())
189 ARMARX_ERROR <<
"Could not open file for logging: " << outputPath.string();
190 ui.btnLogToFile->setChecked(
false);
194 std::lock_guard<std::mutex> lock(fileMutex);
198 logstream <<
"Timestamp";
199 for (
const auto&
s : csvHeader)
201 logstream <<
"," <<
s;
203 logstream << std::endl;
205 connect(plotterController, SIGNAL(newDataAvailable(
long, std::map<std::string, VariantPtr>)),
this, SLOT(
logToFile(
long, std::map<std::string, VariantPtr>)));
212 QObject::disconnect(plotterController, SIGNAL(newDataAvailable(
long, std::map<std::string, VariantPtr>)),
this, SLOT(
logToFile(
long, std::map<std::string, VariantPtr>)));
214 std::lock_guard<std::mutex> lock(fileMutex);
226 const auto st = style.toStdString();
230 if (style ==
"Bar chart")
232 ui.BTNAutoScale->setDisabled(
true);
236 ui.BTNAutoScale->setDisabled(
false);
243 std::unique_lock lock(dataMutex);
248 settings->setValue(
"autoScaleActive",
ui.BTNAutoScale->isChecked());
249 settings->setValue(
"syncDataLogging", syncDataLogging);
255 std::unique_lock lock(dataMutex);
260 ui.BTNAutoScale->setChecked(
settings->value(
"autoScaleActive",
true).toBool());
261 syncDataLogging =
settings->value(
"syncDataLogging",
false).toBool();
268 std::lock_guard<std::mutex> lock(fileMutex);
270 if (!logstream.is_open() || !dataMaptoAppend.size())
275 logstream << (IceUtil::Time::microSeconds(timestamp) - logStartTime).toMilliSecondsDouble();
277 for (
const auto& f : csvHeader)
280 if (dataMaptoAppend.count(f))
282 logstream << dataMaptoAppend.at(f)->Variant::getOutputValueOnly();
285 logstream << std::endl;