25 #include <SimoxUtility/algorithm/string/string_tools.h>
40 #include <QStackedLayout>
45 #include <IceUtil/IceUtil.h>
58 plotterController->
setGraphStyle(
ui.CBgraphStyle->currentText().toStdString());
81 connect(
ui.BTNEdit, SIGNAL(clicked()),
this, SLOT(
configDialog()));
82 connect(
ui.BTNPlotterStatus,
83 SIGNAL(toggled(
bool)),
85 SLOT(plottingPaused(
bool)));
87 connect(
ui.BTNAutoScale, SIGNAL(toggled(
bool)), plotterController, SLOT(autoScale(
bool)));
89 connect(
ui.btnLogToFile, SIGNAL(toggled(
bool)),
this, SLOT(
toggleLogging(
bool)));
91 connect(
ui.CBgraphStyle,
92 SIGNAL(currentTextChanged(QString)),
96 connect(
ui.btnClearHistory, SIGNAL(clicked()), plotterController, SLOT(clearHistory()));
98 if (!QMetaObject::invokeMethod(plotterController,
"setupCurves"))
110 plotterController->deleteLater();
119 if (logstream.is_open())
140 dialog->ui.syncDataLogging->setChecked(syncDataLogging);
141 dialog->ui.listWidget->clear();
157 std::unique_lock lock(dataMutex);
163 syncDataLogging =
dialog->ui.syncDataLogging->isChecked();
164 ui.btnLogToFile->setChecked(
false);
165 ui.BTNPlotterStatus->setChecked(
false);
175 std::lock_guard<std::mutex> lock(mutex);
179 std::filesystem::path outputPath;
180 if (filename.empty())
182 outputPath =
loggingDir.toStdString() +
"/datalog.csv";
184 std::string time = IceUtil::Time::now().toDateTime();
185 time = simox::alg::replace_all(time,
"/",
"-");
186 time = simox::alg::replace_all(time,
" ",
"_");
187 time = simox::alg::replace_all(time,
":",
"-");
188 outputPath = outputPath.parent_path() / (outputPath.stem().string() +
"-" + time +
189 outputPath.extension().string());
193 std::filesystem::path path = filename;
194 outputPath =
loggingDir.toStdString() +
"/" + path.stem().string() +
".csv";
197 ARMARX_INFO <<
"Logging to " << outputPath.string();
198 logstream.open(outputPath.string());
199 logStartTime = IceUtil::Time::now();
201 if (!logstream.is_open())
203 ARMARX_ERROR <<
"Could not open file for logging: " << outputPath.string();
204 ui.btnLogToFile->setChecked(
false);
208 std::lock_guard<std::mutex> lock(fileMutex);
212 logstream <<
"Timestamp";
213 for (
const auto&
s : csvHeader)
215 logstream <<
"," <<
s;
217 logstream << std::endl;
219 connect(plotterController,
220 SIGNAL(newDataAvailable(
long, std::map<std::string, VariantPtr>)),
222 SLOT(
logToFile(
long, std::map<std::string, VariantPtr>)));
228 QObject::disconnect(plotterController,
229 SIGNAL(newDataAvailable(
long, std::map<std::string, VariantPtr>)),
231 SLOT(
logToFile(
long, std::map<std::string, VariantPtr>)));
233 std::lock_guard<std::mutex> lock(fileMutex);
246 const auto st = style.toStdString();
250 if (style ==
"Bar chart")
252 ui.BTNAutoScale->setDisabled(
true);
256 ui.BTNAutoScale->setDisabled(
false);
264 std::unique_lock lock(dataMutex);
269 settings->setValue(
"autoScaleActive",
ui.BTNAutoScale->isChecked());
270 settings->setValue(
"syncDataLogging", syncDataLogging);
276 std::unique_lock lock(dataMutex);
281 settings->value(
"selectedChannels", QStringList()).toStringList());
282 ui.BTNAutoScale->setChecked(
settings->value(
"autoScaleActive",
true).toBool());
283 syncDataLogging =
settings->value(
"syncDataLogging",
false).toBool();
290 const std::map<std::string, VariantPtr>& dataMaptoAppend)
292 std::lock_guard<std::mutex> lock(fileMutex);
294 if (!logstream.is_open() || !dataMaptoAppend.size())
299 logstream << (IceUtil::Time::microSeconds(timestamp) - logStartTime).toMilliSecondsDouble();
301 for (
const auto& f : csvHeader)
304 if (dataMaptoAppend.count(f))
306 logstream << dataMaptoAppend.at(f)->Variant::getOutputValueOnly();
309 logstream << std::endl;