Fix session load issue for dsl file

This commit is contained in:
DreamSourceLab 2020-01-21 11:39:07 +08:00
parent 9af32655db
commit 9dfea2e314
2 changed files with 88 additions and 48 deletions

View File

@ -99,6 +99,7 @@ void StoreProgress::export_run()
void StoreProgress::show_error() void StoreProgress::show_error()
{ {
_done = true;
if (!_store_session.error().isEmpty()) { if (!_store_session.error().isEmpty()) {
dialogs::DSMessageBox msg(parentWidget()); dialogs::DSMessageBox msg(parentWidget());
msg.mBox()->setText(tr("Failed to save data.")); msg.mBox()->setText(tr("Failed to save data."));
@ -125,12 +126,9 @@ void StoreProgress::on_progress_updated()
const QString err = _store_session.error(); const QString err = _store_session.error();
if (!err.isEmpty()) { if (!err.isEmpty()) {
show_error(); show_error();
//close();
_done = true;
} }
if (p.first == p.second) { if (p.first == p.second) {
//close();
_done = true; _done = true;
} }
} }

View File

@ -988,63 +988,105 @@ bool MainWindow::load_session_json(QJsonDocument json, bool file_dev)
} }
// load channel settings // load channel settings
for (const GSList *l = _session.get_device()->dev_inst()->channels; l; l = l->next) { if (file_dev && (sdi->mode == DSO)) {
sr_channel *const probe = (sr_channel*)l->data; for (const GSList *l = _session.get_device()->dev_inst()->channels; l; l = l->next) {
assert(probe); sr_channel *const probe = (sr_channel*)l->data;
bool isEnabled = false; assert(probe);
foreach (const QJsonValue &value, sessionObj["channel"].toArray()) { foreach (const QJsonValue &value, sessionObj["channel"].toArray()) {
QJsonObject obj = value.toObject(); QJsonObject obj = value.toObject();
if ((probe->index == obj["index"].toDouble()) && if ((strcmp(probe->name, g_strdup(obj["name"].toString().toStdString().c_str())) == 0) &&
(probe->type == obj["type"].toDouble())) { (probe->type == obj["type"].toDouble())) {
isEnabled = true; probe->vdiv = obj["vdiv"].toDouble();
probe->enabled = obj["enabled"].toBool(); probe->coupling = obj["coupling"].toDouble();
probe->name = g_strdup(obj["name"].toString().toStdString().c_str()); probe->vfactor = obj["vfactor"].toDouble();
probe->vdiv = obj["vdiv"].toDouble(); probe->trig_value = obj["trigValue"].toDouble();
probe->coupling = obj["coupling"].toDouble(); probe->map_unit = g_strdup(obj["mapUnit"].toString().toStdString().c_str());
probe->vfactor = obj["vfactor"].toDouble(); probe->map_min = obj["mapMin"].toDouble();
probe->trig_value = obj["trigValue"].toDouble(); probe->map_max = obj["mapMax"].toDouble();
probe->map_unit = g_strdup(obj["mapUnit"].toString().toStdString().c_str()); break;
probe->map_min = obj["mapMin"].toDouble(); }
probe->map_max = obj["mapMax"].toDouble();
break;
} }
} }
if (!isEnabled) } else {
probe->enabled = false; for (const GSList *l = _session.get_device()->dev_inst()->channels; l; l = l->next) {
sr_channel *const probe = (sr_channel*)l->data;
assert(probe);
bool isEnabled = false;
foreach (const QJsonValue &value, sessionObj["channel"].toArray()) {
QJsonObject obj = value.toObject();
if ((probe->index == obj["index"].toDouble()) &&
(probe->type == obj["type"].toDouble())) {
isEnabled = true;
probe->enabled = obj["enabled"].toBool();
probe->name = g_strdup(obj["name"].toString().toStdString().c_str());
probe->vdiv = obj["vdiv"].toDouble();
probe->coupling = obj["coupling"].toDouble();
probe->vfactor = obj["vfactor"].toDouble();
probe->trig_value = obj["trigValue"].toDouble();
probe->map_unit = g_strdup(obj["mapUnit"].toString().toStdString().c_str());
probe->map_min = obj["mapMin"].toDouble();
probe->map_max = obj["mapMax"].toDouble();
break;
}
}
if (!isEnabled)
probe->enabled = false;
}
} }
//_session.init_signals(); //_session.init_signals();
_session.reload(); _session.reload();
// load signal setting // load signal setting
BOOST_FOREACH(const boost::shared_ptr<view::Signal> s, _session.get_signals()) { if (file_dev && (sdi->mode == DSO)) {
foreach (const QJsonValue &value, sessionObj["channel"].toArray()) { BOOST_FOREACH(const boost::shared_ptr<view::Signal> s, _session.get_signals()) {
QJsonObject obj = value.toObject(); foreach (const QJsonValue &value, sessionObj["channel"].toArray()) {
if ((s->get_index() == obj["index"].toDouble()) && QJsonObject obj = value.toObject();
(s->get_type() == obj["type"].toDouble())) { if ((strcmp(s->get_name().toStdString().c_str(), g_strdup(obj["name"].toString().toStdString().c_str())) == 0) &&
s->set_colour(QColor(obj["colour"].toString())); (s->get_type() == obj["type"].toDouble())) {
s->set_name(g_strdup(obj["name"].toString().toStdString().c_str())); s->set_colour(QColor(obj["colour"].toString()));
boost::shared_ptr<view::LogicSignal> logicSig; boost::shared_ptr<view::DsoSignal> dsoSig;
if ((logicSig = dynamic_pointer_cast<view::LogicSignal>(s))) { if ((dsoSig = dynamic_pointer_cast<view::DsoSignal>(s))) {
logicSig->set_trig(obj["strigger"].toDouble()); dsoSig->load_settings();
dsoSig->set_zero_ratio(obj["zeroPos"].toDouble());
dsoSig->set_trig_ratio(obj["trigValue"].toDouble());
dsoSig->commit_settings();
}
break;
} }
}
}
} else {
BOOST_FOREACH(const boost::shared_ptr<view::Signal> s, _session.get_signals()) {
foreach (const QJsonValue &value, sessionObj["channel"].toArray()) {
QJsonObject obj = value.toObject();
if ((s->get_index() == obj["index"].toDouble()) &&
(s->get_type() == obj["type"].toDouble())) {
s->set_colour(QColor(obj["colour"].toString()));
s->set_name(g_strdup(obj["name"].toString().toStdString().c_str()));
boost::shared_ptr<view::DsoSignal> dsoSig; boost::shared_ptr<view::LogicSignal> logicSig;
if ((dsoSig = dynamic_pointer_cast<view::DsoSignal>(s))) { if ((logicSig = dynamic_pointer_cast<view::LogicSignal>(s))) {
dsoSig->load_settings(); logicSig->set_trig(obj["strigger"].toDouble());
dsoSig->set_zero_ratio(obj["zeroPos"].toDouble()); }
dsoSig->set_trig_ratio(obj["trigValue"].toDouble());
dsoSig->commit_settings(); boost::shared_ptr<view::DsoSignal> dsoSig;
if ((dsoSig = dynamic_pointer_cast<view::DsoSignal>(s))) {
dsoSig->load_settings();
dsoSig->set_zero_ratio(obj["zeroPos"].toDouble());
dsoSig->set_trig_ratio(obj["trigValue"].toDouble());
dsoSig->commit_settings();
}
boost::shared_ptr<view::AnalogSignal> analogSig;
if ((analogSig = dynamic_pointer_cast<view::AnalogSignal>(s))) {
analogSig->set_zero_ratio(obj["zeroPos"].toDouble());
analogSig->commit_settings();
}
break;
} }
boost::shared_ptr<view::AnalogSignal> analogSig;
if ((analogSig = dynamic_pointer_cast<view::AnalogSignal>(s))) {
analogSig->set_zero_ratio(obj["zeroPos"].toDouble());
analogSig->commit_settings();
}
break;
} }
} }
} }