Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix loss of sensors #1442

Merged
merged 4 commits into from
Oct 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ public slots:
, const robotModel::DeviceInfo &sensor
, Reason reason) override;

void propagateChanges(const robotModel::PortInfo &port
, const robotModel::DeviceInfo &sensor);
void propagateChanges(const QString &robotId, const robotModel::PortInfo &port
, const robotModel::DeviceInfo &sensor, Reason reason);

void propagateChangesFromBox(QComboBox *box);

bool areConvertible(const robotModel::PortInfo &port1
, const robotModel::PortInfo &port2) const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,12 @@ void DevicesConfigurationProvider::deviceConfigurationChanged(const QString &rob
{
if (mCurrentConfiguration[robotId][port] != device) {
mCurrentConfiguration[robotId][port] = device;
// Allow provider to react on configuration change.
onDeviceConfigurationChanged(robotId, port, device, reason);

for (DevicesConfigurationProvider * const provider : mConnectedProviders) {
// Broadcast change.
provider->deviceConfigurationChanged(robotId, port, device, reason);

// Allow connected providers to react on configuration change.
provider->onDeviceConfigurationChanged(robotId, port, device, reason);
}
}
}
Expand All @@ -88,9 +87,9 @@ void DevicesConfigurationProvider::onDeviceConfigurationChanged(const QString &r
, const PortInfo &port, const DeviceInfo &sensor, Reason reason)
{
Q_UNUSED(robotId)
Q_UNUSED(port);
Q_UNUSED(sensor);
Q_UNUSED(reason);
Q_UNUSED(port)
Q_UNUSED(sensor)
Q_UNUSED(reason)
}

void DevicesConfigurationProvider::clearConfiguration(Reason reason)
Expand Down
43 changes: 22 additions & 21 deletions plugins/robots/common/kitBase/src/devicesConfigurationWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ QLayout *DevicesConfigurationWidget::initPort(const QString &robotModelName
}

if (mAutosaveMode) {
connect(comboBox, &QComboBox::currentTextChanged, this, &DevicesConfigurationWidget::save);
connect(comboBox, &QComboBox::currentTextChanged, this, [this](){
propagateChangesFromBox(qobject_cast<QComboBox *>(sender()));
});
}

QHBoxLayout * const layout = new QHBoxLayout;
Expand All @@ -128,10 +130,7 @@ QLayout *DevicesConfigurationWidget::initPort(const QString &robotModelName
void DevicesConfigurationWidget::onDeviceConfigurationChanged(const QString &robotId
, const PortInfo &port, const DeviceInfo &sensor, Reason reason)
{
Q_UNUSED(port)
Q_UNUSED(sensor)
Q_UNUSED(reason)

propagateChanges(robotId, port, sensor, reason);
// This method can be called when we did not accomplish processing all combo boxes during saving.
// So ignoring such case.
if (!mSaving && robotId == mCurrentRobotId) {
Expand All @@ -143,8 +142,8 @@ void DevicesConfigurationWidget::refresh()
{
mRefreshing = true;
for (QComboBox * const box : mConfigurers) {
const PortInfo port = box->property("port").value<PortInfo>();
const DeviceInfo device = currentConfiguration(mCurrentRobotId, port);
const PortInfo &port = box->property("port").value<PortInfo>();
const DeviceInfo &device = currentConfiguration(mCurrentRobotId, port);
if (device.isNull()) {
box->setCurrentIndex(0);
} else {
Expand All @@ -169,36 +168,38 @@ void DevicesConfigurationWidget::save()

mSaving = true;
for (QComboBox * const box : mConfigurers) {
if (!box->isVisible()) {
continue;
}

const QString robotModelName = box->property("robotModelName").toString();
const PortInfo port = box->property("port").value<PortInfo>();
const DeviceInfo device = box->itemData(box->currentIndex()).value<DeviceInfo>();
if (robotModelName == mCurrentModelType && currentConfiguration(mCurrentRobotId, port) != device) {
propagateChanges(port, device);
if (box->isVisible() && box->property("robotModelName").toString() == mCurrentModelType) {
propagateChangesFromBox(box);
}
}

mSaving = false;
}

void DevicesConfigurationWidget::propagateChanges(const PortInfo &port, const DeviceInfo &sensor)
void DevicesConfigurationWidget::propagateChangesFromBox(QComboBox *box)
{
const PortInfo &port = box->property("port").value<PortInfo>();
const DeviceInfo &device = box->itemData(box->currentIndex()).value<DeviceInfo>();
if (currentConfiguration(mCurrentRobotId, port) != device) {
propagateChanges(mCurrentRobotId, port, device, Reason::userAction);
}
}

void DevicesConfigurationWidget::propagateChanges(const QString &robotId, const PortInfo &port
, const DeviceInfo &sensor, Reason reason)
{
const auto kit = mCurrentRobotId.split(QRegExp("[A-Z]")).first();
const auto kit = robotId.split(QRegExp("[A-Z]")).first();
for (const QString &robotModelType : mRobotModels.keys()) {
const RobotModelInterface *robotModel = mRobotModels[robotModelType];
if (robotModel->robotId().contains(kit)) {
for (const PortInfo &otherPort : robotModel->configurablePorts()) {
if (areConvertible(port, otherPort)) {
if (sensor.isNull()) {
deviceConfigurationChanged(robotModel->robotId(), otherPort, DeviceInfo(), Reason::userAction);
deviceConfigurationChanged(robotModel->robotId(), otherPort, DeviceInfo(), reason);
} else {
const DeviceInfo otherDevice = convertibleDevice(robotModel, otherPort, sensor);
if (!otherDevice.isNull()) {
deviceConfigurationChanged(robotModel->robotId(), otherPort
, otherDevice, Reason::userAction);
, otherDevice, reason);
}
}
}
Expand Down