From 3b85f5768478debda745f576c471c7dc5770dc03 Mon Sep 17 00:00:00 2001 From: ahcorde Date: Wed, 16 Feb 2022 09:37:03 +0100 Subject: [PATCH 1/7] Allow to turn on/off lights Signed-off-by: ahcorde --- src/Conversions.cc | 27 +++++++++++ .../component_inspector/ComponentInspector.cc | 29 +++++++++++- .../component_inspector/ComponentInspector.hh | 2 +- .../ComponentInspector.qml | 6 ++- src/gui/plugins/component_inspector/Light.qml | 45 ++++++++++++++++++- src/rendering/RenderUtil.cc | 34 ++++++++++++-- src/systems/user_commands/UserCommands.cc | 21 +++++++++ 7 files changed, 154 insertions(+), 10 deletions(-) diff --git a/src/Conversions.cc b/src/Conversions.cc index a71ef0aafb..a2709d6527 100644 --- a/src/Conversions.cc +++ b/src/Conversions.cc @@ -568,6 +568,14 @@ msgs::Light ignition::gazebo::convert(const sdf::Light &_in) out.set_spot_inner_angle(_in.SpotInnerAngle().Radian()); out.set_spot_outer_angle(_in.SpotOuterAngle().Radian()); out.set_spot_falloff(_in.SpotFalloff()); + + // todo(anyone) Use the field isLightOn in light.proto from + // Garden on. + auto header = out.mutable_header()->add_data(); + header->set_key("isLightOn"); + std::string *value = header->add_value(); + *value = std::to_string(_in.LightOn()); + if (_in.Type() == sdf::LightType::POINT) out.set_type(msgs::Light_LightType_POINT); else if (_in.Type() == sdf::LightType::SPOT) @@ -597,6 +605,25 @@ sdf::Light ignition::gazebo::convert(const msgs::Light &_in) out.SetSpotInnerAngle(math::Angle(_in.spot_inner_angle())); out.SetSpotOuterAngle(math::Angle(_in.spot_outer_angle())); out.SetSpotFalloff(_in.spot_falloff()); + + // todo(anyone) Use the field isLightOn in light.proto from + // Garden on. + bool isLightOn = true; + for (int i = 0; i < _in.header().data_size(); ++i) + { + for (int j = 0; + j < _in.header().data(i).value_size(); ++j) + { + if (_in.header().data(i).key() == + "isLightOn") + { + isLightOn = ignition::math::parseInt( + _in.header().data(i).value(0)); + } + } + } + out.SetLightOn(isLightOn); + if (_in.type() == msgs::Light_LightType_POINT) out.SetType(sdf::LightType::POINT); else if (_in.type() == msgs::Light_LightType_SPOT) diff --git a/src/gui/plugins/component_inspector/ComponentInspector.cc b/src/gui/plugins/component_inspector/ComponentInspector.cc index f2c31ec06f..2ebf5f68e5 100644 --- a/src/gui/plugins/component_inspector/ComponentInspector.cc +++ b/src/gui/plugins/component_inspector/ComponentInspector.cc @@ -153,6 +153,21 @@ void ignition::gazebo::setData(QStandardItem *_item, const msgs::Light &_data) lightType = 2; } + bool isLightOn = true; + for (int i = 0; i < _data.header().data_size(); ++i) + { + for (int j = 0; + j < _data.header().data(i).value_size(); ++j) + { + if (_data.header().data(i).key() == + "isLightOn") + { + isLightOn = ignition::math::parseInt( + _data.header().data(i).value(0)); + } + } + } + _item->setData(QString("Light"), ComponentsModel::RoleNames().key("dataType")); _item->setData(QList({ @@ -176,7 +191,8 @@ void ignition::gazebo::setData(QStandardItem *_item, const msgs::Light &_data) QVariant(_data.spot_outer_angle()), QVariant(_data.spot_falloff()), QVariant(_data.intensity()), - QVariant(lightType) + QVariant(lightType), + QVariant(isLightOn) }), ComponentsModel::RoleNames().key("data")); } @@ -989,7 +1005,8 @@ void ComponentInspector::OnLight( double _attRange, double _attLinear, double _attConstant, double _attQuadratic, bool _castShadows, double _directionX, double _directionY, double _directionZ, double _innerAngle, - double _outerAngle, double _falloff, double _intensity, int _type) + double _outerAngle, double _falloff, double _intensity, int _type, + bool _isLightOn) { std::function cb = [](const ignition::msgs::Boolean &/*_rep*/, const bool _result) @@ -999,6 +1016,14 @@ void ComponentInspector::OnLight( }; ignition::msgs::Light req; + + // todo(anyone) Use the field isLightOn in light.proto from + // Garden on. + auto header = req.mutable_header()->add_data(); + header->set_key("isLightOn"); + std::string *value = header->add_value(); + *value = std::to_string(_isLightOn); + req.set_name(this->dataPtr->entityName); req.set_id(this->dataPtr->entity); ignition::msgs::Set(req.mutable_diffuse(), diff --git a/src/gui/plugins/component_inspector/ComponentInspector.hh b/src/gui/plugins/component_inspector/ComponentInspector.hh index 9229a24188..4a166b1baf 100644 --- a/src/gui/plugins/component_inspector/ComponentInspector.hh +++ b/src/gui/plugins/component_inspector/ComponentInspector.hh @@ -259,7 +259,7 @@ namespace gazebo double _attLinear, double _attConstant, double _attQuadratic, bool _castShadows, double _directionX, double _directionY, double _directionZ, double _innerAngle, double _outerAngle, - double _falloff, double _intensity, int _type); + double _falloff, double _intensity, int _type, bool _isLightOn); /// \brief Callback in Qt thread when physics' properties change. /// \param[in] _stepSize step size diff --git a/src/gui/plugins/component_inspector/ComponentInspector.qml b/src/gui/plugins/component_inspector/ComponentInspector.qml index 545e46d538..c9f68bd1e4 100644 --- a/src/gui/plugins/component_inspector/ComponentInspector.qml +++ b/src/gui/plugins/component_inspector/ComponentInspector.qml @@ -101,12 +101,14 @@ Rectangle { _rDiffuse, _gDiffuse, _bDiffuse, _aDiffuse, _attRange, _attLinear, _attConstant, _attQuadratic, _castShadows, _directionX, _directionY, _directionZ, - _innerAngle, _outerAngle, _falloff, _intensity, _type) { + _innerAngle, _outerAngle, _falloff, _intensity, _type, + _isLightOn) { ComponentInspector.OnLight(_rSpecular, _gSpecular, _bSpecular, _aSpecular, _rDiffuse, _gDiffuse, _bDiffuse, _aDiffuse, _attRange, _attLinear, _attConstant, _attQuadratic, _castShadows, _directionX, _directionY, _directionZ, - _innerAngle, _outerAngle, _falloff, _intensity, _type) + _innerAngle, _outerAngle, _falloff, _intensity, _type, + _isLightOn) } /* diff --git a/src/gui/plugins/component_inspector/Light.qml b/src/gui/plugins/component_inspector/Light.qml index 98cf143e82..9fc209ac61 100644 --- a/src/gui/plugins/component_inspector/Light.qml +++ b/src/gui/plugins/component_inspector/Light.qml @@ -99,6 +99,9 @@ Rectangle { // Loaded item for intensity property var intensityItem: {} + // Loaded item for isLightOn + property var isLightOnItem: {} + // Send new light data to C++ function sendLight() { // TODO(anyone) There's a loss of precision when these values get to C++ @@ -123,7 +126,8 @@ Rectangle { outerAngleItem.value, falloffItem.value, intensityItem.value, - model.data[20] + model.data[20], + isLightOnItem.checked ); } @@ -285,6 +289,45 @@ Rectangle { id: grid width: parent.width + RowLayout { + Rectangle { + color: "transparent" + height: 40 + Layout.preferredWidth: isOnText.width + indentation*3 + Loader { + id: isLightOn + width: iconWidth + height: iconHeight + y:10 + sourceComponent: plotIcon + } + Component.onCompleted: isLightOn.item.componentInfo = "is light on ?" + + Text { + id : isOnText + text: ' Turn on/off' + leftPadding: 5 + color: Material.theme == Material.Light ? "#444444" : "#bbbbbb" + font.pointSize: 12 + anchors.centerIn: parent + } + } + Item { + Layout.fillWidth: true + height: 40 + + Loader { + id: inOnLoader + anchors.fill: parent + property double numberValue: model.data[21] + sourceComponent: ignSwitch + onLoaded: { + isLightOnItem = inOnLoader.item + } + } + } + } + RowLayout { Rectangle { color: "transparent" diff --git a/src/rendering/RenderUtil.cc b/src/rendering/RenderUtil.cc index 35c347cd33..cef69cfbc3 100644 --- a/src/rendering/RenderUtil.cc +++ b/src/rendering/RenderUtil.cc @@ -2131,11 +2131,37 @@ void RenderUtilPrivate::UpdateLights( auto l = std::dynamic_pointer_cast(node); if (l) { - if (!ignition::math::equal( - l->Intensity(), - static_cast(light.second.intensity()))) + // todo(anyone) Use the field isLightOn in light.proto from + // Garden on. + bool isLightOn = true; + for (int i = 0; i < light.second.header().data_size(); ++i) + { + for (int j = 0; + j < light.second.header().data(i).value_size(); ++j) + { + if (light.second.header().data(i).key() == + "isLightOn") + { + isLightOn = ignition::math::parseInt( + light.second.header().data(i).value(0)); + } + } + } + + // const auto lightOnOff = _entityLightsOn.at(light.first); + + if (isLightOn) + { + if (!ignition::math::equal( + l->Intensity(), + static_cast(light.second.intensity()))) + { + l->SetIntensity(light.second.intensity()); + } + } + else { - l->SetIntensity(light.second.intensity()); + l->SetIntensity(0); } if (light.second.has_diffuse()) { diff --git a/src/systems/user_commands/UserCommands.cc b/src/systems/user_commands/UserCommands.cc index 079245773c..65e4d5f334 100644 --- a/src/systems/user_commands/UserCommands.cc +++ b/src/systems/user_commands/UserCommands.cc @@ -159,7 +159,28 @@ class LightCommand : public UserCommandBase public: std::function lightEql { [](const msgs::Light &_a, const msgs::Light &_b) { + // todo(anyone) Use the field isLightOn in light.proto from + // Garden on. + auto getIsLightOn = [](const msgs::Light &_light) -> bool + { + bool isLightOn = true; + for (int i = 0; i < _light.header().data_size(); ++i) + { + for (int j = 0; + j < _light.header().data(i).value_size(); ++j) + { + if (_light.header().data(i).key() == + "isLightOn") + { + isLightOn = ignition::math::parseInt( + _light.header().data(i).value(0)); + } + } + } + return isLightOn; + }; return + getIsLightOn(_a) == getIsLightOn(_b) && _a.type() == _b.type() && _a.name() == _b.name() && math::equal( From 56b6b55cf136852ec782ff65aeb99766bebf28eb Mon Sep 17 00:00:00 2001 From: ahcorde Date: Wed, 16 Feb 2022 18:26:11 +0100 Subject: [PATCH 2/7] feedback Signed-off-by: ahcorde --- src/gui/plugins/component_inspector/Light.qml | 7 ------- src/rendering/RenderUtil.cc | 2 -- 2 files changed, 9 deletions(-) diff --git a/src/gui/plugins/component_inspector/Light.qml b/src/gui/plugins/component_inspector/Light.qml index 9fc209ac61..6b3969dc72 100644 --- a/src/gui/plugins/component_inspector/Light.qml +++ b/src/gui/plugins/component_inspector/Light.qml @@ -294,13 +294,6 @@ Rectangle { color: "transparent" height: 40 Layout.preferredWidth: isOnText.width + indentation*3 - Loader { - id: isLightOn - width: iconWidth - height: iconHeight - y:10 - sourceComponent: plotIcon - } Component.onCompleted: isLightOn.item.componentInfo = "is light on ?" Text { diff --git a/src/rendering/RenderUtil.cc b/src/rendering/RenderUtil.cc index cef69cfbc3..d822ab4217 100644 --- a/src/rendering/RenderUtil.cc +++ b/src/rendering/RenderUtil.cc @@ -2148,8 +2148,6 @@ void RenderUtilPrivate::UpdateLights( } } - // const auto lightOnOff = _entityLightsOn.at(light.first); - if (isLightOn) { if (!ignition::math::equal( From 1ee3ec59262cecdb2bab027965cc2274a8ed3e38 Mon Sep 17 00:00:00 2001 From: ahcorde Date: Thu, 24 Feb 2022 22:20:52 +0100 Subject: [PATCH 3/7] make linters happy Signed-off-by: ahcorde --- src/Conversions.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Conversions.cc b/src/Conversions.cc index a2709d6527..fd85b46df6 100644 --- a/src/Conversions.cc +++ b/src/Conversions.cc @@ -623,7 +623,7 @@ sdf::Light ignition::gazebo::convert(const msgs::Light &_in) } } out.SetLightOn(isLightOn); - + if (_in.type() == msgs::Light_LightType_POINT) out.SetType(sdf::LightType::POINT); else if (_in.type() == msgs::Light_LightType_SPOT) From 2936623b32377ef6ed4810fbd8363c405c792914 Mon Sep 17 00:00:00 2001 From: ahcorde Date: Mon, 14 Mar 2022 11:16:07 +0100 Subject: [PATCH 4/7] Added Feedback Signed-off-by: ahcorde --- src/Conversions.cc | 4 ++-- src/gui/plugins/component_inspector/ComponentInspector.cc | 2 +- src/gui/plugins/component_inspector/ComponentInspector.hh | 1 + src/gui/plugins/component_inspector/Light.qml | 2 +- src/rendering/RenderUtil.cc | 2 +- src/systems/user_commands/UserCommands.cc | 2 +- 6 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Conversions.cc b/src/Conversions.cc index fd85b46df6..aafd9213f7 100644 --- a/src/Conversions.cc +++ b/src/Conversions.cc @@ -569,7 +569,7 @@ msgs::Light ignition::gazebo::convert(const sdf::Light &_in) out.set_spot_outer_angle(_in.SpotOuterAngle().Radian()); out.set_spot_falloff(_in.SpotFalloff()); - // todo(anyone) Use the field isLightOn in light.proto from + // todo(ahcorde) Use the field is_light_off in light.proto from // Garden on. auto header = out.mutable_header()->add_data(); header->set_key("isLightOn"); @@ -606,7 +606,7 @@ sdf::Light ignition::gazebo::convert(const msgs::Light &_in) out.SetSpotOuterAngle(math::Angle(_in.spot_outer_angle())); out.SetSpotFalloff(_in.spot_falloff()); - // todo(anyone) Use the field isLightOn in light.proto from + // todo(ahcorde) Use the field is_light_off in light.proto from // Garden on. bool isLightOn = true; for (int i = 0; i < _in.header().data_size(); ++i) diff --git a/src/gui/plugins/component_inspector/ComponentInspector.cc b/src/gui/plugins/component_inspector/ComponentInspector.cc index 2ebf5f68e5..f16712ce73 100644 --- a/src/gui/plugins/component_inspector/ComponentInspector.cc +++ b/src/gui/plugins/component_inspector/ComponentInspector.cc @@ -1017,7 +1017,7 @@ void ComponentInspector::OnLight( ignition::msgs::Light req; - // todo(anyone) Use the field isLightOn in light.proto from + // todo(ahcorde) Use the field is_light_off in light.proto from // Garden on. auto header = req.mutable_header()->add_data(); header->set_key("isLightOn"); diff --git a/src/gui/plugins/component_inspector/ComponentInspector.hh b/src/gui/plugins/component_inspector/ComponentInspector.hh index 4a166b1baf..0590aa31c7 100644 --- a/src/gui/plugins/component_inspector/ComponentInspector.hh +++ b/src/gui/plugins/component_inspector/ComponentInspector.hh @@ -252,6 +252,7 @@ namespace gazebo /// \param[in] _falloff Falloff of the spotlight /// \param[in] _intensity Intensity of the light /// \param[in] _type light type + /// \param[in] _isLightOn is light on public: Q_INVOKABLE void OnLight( double _rSpecular, double _gSpecular, double _bSpecular, double _aSpecular, double _rDiffuse, double _gDiffuse, diff --git a/src/gui/plugins/component_inspector/Light.qml b/src/gui/plugins/component_inspector/Light.qml index 6b3969dc72..b336f31d12 100644 --- a/src/gui/plugins/component_inspector/Light.qml +++ b/src/gui/plugins/component_inspector/Light.qml @@ -310,7 +310,7 @@ Rectangle { height: 40 Loader { - id: inOnLoader + id: isOnLoader anchors.fill: parent property double numberValue: model.data[21] sourceComponent: ignSwitch diff --git a/src/rendering/RenderUtil.cc b/src/rendering/RenderUtil.cc index d822ab4217..15e7bdfd43 100644 --- a/src/rendering/RenderUtil.cc +++ b/src/rendering/RenderUtil.cc @@ -2131,7 +2131,7 @@ void RenderUtilPrivate::UpdateLights( auto l = std::dynamic_pointer_cast(node); if (l) { - // todo(anyone) Use the field isLightOn in light.proto from + // todo(ahcorde) Use the field is_light_off in light.proto from // Garden on. bool isLightOn = true; for (int i = 0; i < light.second.header().data_size(); ++i) diff --git a/src/systems/user_commands/UserCommands.cc b/src/systems/user_commands/UserCommands.cc index 65e4d5f334..1bd29a7d96 100644 --- a/src/systems/user_commands/UserCommands.cc +++ b/src/systems/user_commands/UserCommands.cc @@ -159,7 +159,7 @@ class LightCommand : public UserCommandBase public: std::function lightEql { [](const msgs::Light &_a, const msgs::Light &_b) { - // todo(anyone) Use the field isLightOn in light.proto from + // todo(ahcorde) Use the field is_light_off in light.proto from // Garden on. auto getIsLightOn = [](const msgs::Light &_light) -> bool { From 58c447c696767e8a2edc49fb1c58726721cfc2b3 Mon Sep 17 00:00:00 2001 From: ahcorde Date: Mon, 14 Mar 2022 11:45:15 +0100 Subject: [PATCH 5/7] Fix qml Signed-off-by: ahcorde --- src/gui/plugins/component_inspector/Light.qml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/gui/plugins/component_inspector/Light.qml b/src/gui/plugins/component_inspector/Light.qml index b336f31d12..f051feb2b3 100644 --- a/src/gui/plugins/component_inspector/Light.qml +++ b/src/gui/plugins/component_inspector/Light.qml @@ -294,7 +294,6 @@ Rectangle { color: "transparent" height: 40 Layout.preferredWidth: isOnText.width + indentation*3 - Component.onCompleted: isLightOn.item.componentInfo = "is light on ?" Text { id : isOnText @@ -315,7 +314,7 @@ Rectangle { property double numberValue: model.data[21] sourceComponent: ignSwitch onLoaded: { - isLightOnItem = inOnLoader.item + isLightOnItem = isOnLoader.item } } } From 3b04882beb0cad46d2c3d13cd28079bf92acc88d Mon Sep 17 00:00:00 2001 From: Louise Poubel Date: Mon, 14 Mar 2022 15:12:21 -0700 Subject: [PATCH 6/7] Depend on libSDFormat 11.4.0 Signed-off-by: Louise Poubel --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 150f789e88..9631ab9fc3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,7 +47,7 @@ set(CMAKE_POLICY_DEFAULT_CMP0077 NEW) # as protobuf could be find transitively by any dependency set(protobuf_MODULE_COMPATIBLE TRUE) -ign_find_package(sdformat11 REQUIRED VERSION 11.2.1) +ign_find_package(sdformat11 REQUIRED VERSION 11.4.0) set(SDF_VER ${sdformat11_VERSION_MAJOR}) #-------------------------------------- From e44575aec86d6816a73a24e4fbbffc82a3a58c11 Mon Sep 17 00:00:00 2001 From: ahcorde Date: Tue, 15 Mar 2022 12:55:53 +0100 Subject: [PATCH 7/7] Improved coverage Signed-off-by: ahcorde --- test/integration/user_commands.cc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/integration/user_commands.cc b/test/integration/user_commands.cc index 4011cfaccf..390f4a4a2e 100644 --- a/test/integration/user_commands.cc +++ b/test/integration/user_commands.cc @@ -760,6 +760,14 @@ TEST_F(UserCommandsTest, IGN_UTILS_TEST_ENABLED_ONLY_ON_LINUX(Light)) req.set_attenuation_constant(0.6f); req.set_attenuation_quadratic(0.001f); req.set_cast_shadows(true); + + // todo(ahcorde) Use the field is_light_off in light.proto from + // Garden on. + auto header = req.mutable_header()->add_data(); + header->set_key("isLightOn"); + std::string *value = header->add_value(); + *value = std::to_string(true); + EXPECT_TRUE(node.Request(service, req, timeout, res, result)); EXPECT_TRUE(result); EXPECT_TRUE(res.data());