Skip to content

Commit 4b3e3e5

Browse files
authored
Merge 9be69c0 into b45f60f
2 parents b45f60f + 9be69c0 commit 4b3e3e5

File tree

9 files changed

+154
-11
lines changed

9 files changed

+154
-11
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
4747
# as protobuf could be find transitively by any dependency
4848
set(protobuf_MODULE_COMPATIBLE TRUE)
4949

50-
ign_find_package(sdformat11 REQUIRED VERSION 11.2.1)
50+
ign_find_package(sdformat11 REQUIRED VERSION 11.4.0)
5151
set(SDF_VER ${sdformat11_VERSION_MAJOR})
5252

5353
#--------------------------------------

src/Conversions.cc

+27
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,14 @@ msgs::Light ignition::gazebo::convert(const sdf::Light &_in)
568568
out.set_spot_inner_angle(_in.SpotInnerAngle().Radian());
569569
out.set_spot_outer_angle(_in.SpotOuterAngle().Radian());
570570
out.set_spot_falloff(_in.SpotFalloff());
571+
572+
// todo(ahcorde) Use the field is_light_off in light.proto from
573+
// Garden on.
574+
auto header = out.mutable_header()->add_data();
575+
header->set_key("isLightOn");
576+
std::string *value = header->add_value();
577+
*value = std::to_string(_in.LightOn());
578+
571579
if (_in.Type() == sdf::LightType::POINT)
572580
out.set_type(msgs::Light_LightType_POINT);
573581
else if (_in.Type() == sdf::LightType::SPOT)
@@ -597,6 +605,25 @@ sdf::Light ignition::gazebo::convert(const msgs::Light &_in)
597605
out.SetSpotInnerAngle(math::Angle(_in.spot_inner_angle()));
598606
out.SetSpotOuterAngle(math::Angle(_in.spot_outer_angle()));
599607
out.SetSpotFalloff(_in.spot_falloff());
608+
609+
// todo(ahcorde) Use the field is_light_off in light.proto from
610+
// Garden on.
611+
bool isLightOn = true;
612+
for (int i = 0; i < _in.header().data_size(); ++i)
613+
{
614+
for (int j = 0;
615+
j < _in.header().data(i).value_size(); ++j)
616+
{
617+
if (_in.header().data(i).key() ==
618+
"isLightOn")
619+
{
620+
isLightOn = ignition::math::parseInt(
621+
_in.header().data(i).value(0));
622+
}
623+
}
624+
}
625+
out.SetLightOn(isLightOn);
626+
600627
if (_in.type() == msgs::Light_LightType_POINT)
601628
out.SetType(sdf::LightType::POINT);
602629
else if (_in.type() == msgs::Light_LightType_SPOT)

src/gui/plugins/component_inspector/ComponentInspector.cc

+27-2
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,21 @@ void ignition::gazebo::setData(QStandardItem *_item, const msgs::Light &_data)
153153
lightType = 2;
154154
}
155155

156+
bool isLightOn = true;
157+
for (int i = 0; i < _data.header().data_size(); ++i)
158+
{
159+
for (int j = 0;
160+
j < _data.header().data(i).value_size(); ++j)
161+
{
162+
if (_data.header().data(i).key() ==
163+
"isLightOn")
164+
{
165+
isLightOn = ignition::math::parseInt(
166+
_data.header().data(i).value(0));
167+
}
168+
}
169+
}
170+
156171
_item->setData(QString("Light"),
157172
ComponentsModel::RoleNames().key("dataType"));
158173
_item->setData(QList({
@@ -176,7 +191,8 @@ void ignition::gazebo::setData(QStandardItem *_item, const msgs::Light &_data)
176191
QVariant(_data.spot_outer_angle()),
177192
QVariant(_data.spot_falloff()),
178193
QVariant(_data.intensity()),
179-
QVariant(lightType)
194+
QVariant(lightType),
195+
QVariant(isLightOn)
180196
}), ComponentsModel::RoleNames().key("data"));
181197
}
182198

@@ -989,7 +1005,8 @@ void ComponentInspector::OnLight(
9891005
double _attRange, double _attLinear, double _attConstant,
9901006
double _attQuadratic, bool _castShadows, double _directionX,
9911007
double _directionY, double _directionZ, double _innerAngle,
992-
double _outerAngle, double _falloff, double _intensity, int _type)
1008+
double _outerAngle, double _falloff, double _intensity, int _type,
1009+
bool _isLightOn)
9931010
{
9941011
std::function<void(const ignition::msgs::Boolean &, const bool)> cb =
9951012
[](const ignition::msgs::Boolean &/*_rep*/, const bool _result)
@@ -999,6 +1016,14 @@ void ComponentInspector::OnLight(
9991016
};
10001017

10011018
ignition::msgs::Light req;
1019+
1020+
// todo(ahcorde) Use the field is_light_off in light.proto from
1021+
// Garden on.
1022+
auto header = req.mutable_header()->add_data();
1023+
header->set_key("isLightOn");
1024+
std::string *value = header->add_value();
1025+
*value = std::to_string(_isLightOn);
1026+
10021027
req.set_name(this->dataPtr->entityName);
10031028
req.set_id(this->dataPtr->entity);
10041029
ignition::msgs::Set(req.mutable_diffuse(),

src/gui/plugins/component_inspector/ComponentInspector.hh

+2-1
Original file line numberDiff line numberDiff line change
@@ -252,14 +252,15 @@ namespace gazebo
252252
/// \param[in] _falloff Falloff of the spotlight
253253
/// \param[in] _intensity Intensity of the light
254254
/// \param[in] _type light type
255+
/// \param[in] _isLightOn is light on
255256
public: Q_INVOKABLE void OnLight(
256257
double _rSpecular, double _gSpecular, double _bSpecular,
257258
double _aSpecular, double _rDiffuse, double _gDiffuse,
258259
double _bDiffuse, double _aDiffuse, double _attRange,
259260
double _attLinear, double _attConstant, double _attQuadratic,
260261
bool _castShadows, double _directionX, double _directionY,
261262
double _directionZ, double _innerAngle, double _outerAngle,
262-
double _falloff, double _intensity, int _type);
263+
double _falloff, double _intensity, int _type, bool _isLightOn);
263264

264265
/// \brief Callback in Qt thread when physics' properties change.
265266
/// \param[in] _stepSize step size

src/gui/plugins/component_inspector/ComponentInspector.qml

+4-2
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,14 @@ Rectangle {
101101
_rDiffuse, _gDiffuse, _bDiffuse, _aDiffuse,
102102
_attRange, _attLinear, _attConstant, _attQuadratic,
103103
_castShadows, _directionX, _directionY, _directionZ,
104-
_innerAngle, _outerAngle, _falloff, _intensity, _type) {
104+
_innerAngle, _outerAngle, _falloff, _intensity, _type,
105+
_isLightOn) {
105106
ComponentInspector.OnLight(_rSpecular, _gSpecular, _bSpecular, _aSpecular,
106107
_rDiffuse, _gDiffuse, _bDiffuse, _aDiffuse,
107108
_attRange, _attLinear, _attConstant, _attQuadratic,
108109
_castShadows, _directionX, _directionY, _directionZ,
109-
_innerAngle, _outerAngle, _falloff, _intensity, _type)
110+
_innerAngle, _outerAngle, _falloff, _intensity, _type,
111+
_isLightOn)
110112
}
111113

112114
/*

src/gui/plugins/component_inspector/Light.qml

+36-1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ Rectangle {
9999
// Loaded item for intensity
100100
property var intensityItem: {}
101101

102+
// Loaded item for isLightOn
103+
property var isLightOnItem: {}
104+
102105
// Send new light data to C++
103106
function sendLight() {
104107
// TODO(anyone) There's a loss of precision when these values get to C++
@@ -123,7 +126,8 @@ Rectangle {
123126
outerAngleItem.value,
124127
falloffItem.value,
125128
intensityItem.value,
126-
model.data[20]
129+
model.data[20],
130+
isLightOnItem.checked
127131
);
128132
}
129133

@@ -285,6 +289,37 @@ Rectangle {
285289
id: grid
286290
width: parent.width
287291

292+
RowLayout {
293+
Rectangle {
294+
color: "transparent"
295+
height: 40
296+
Layout.preferredWidth: isOnText.width + indentation*3
297+
298+
Text {
299+
id : isOnText
300+
text: ' Turn on/off'
301+
leftPadding: 5
302+
color: Material.theme == Material.Light ? "#444444" : "#bbbbbb"
303+
font.pointSize: 12
304+
anchors.centerIn: parent
305+
}
306+
}
307+
Item {
308+
Layout.fillWidth: true
309+
height: 40
310+
311+
Loader {
312+
id: isOnLoader
313+
anchors.fill: parent
314+
property double numberValue: model.data[21]
315+
sourceComponent: ignSwitch
316+
onLoaded: {
317+
isLightOnItem = isOnLoader.item
318+
}
319+
}
320+
}
321+
}
322+
288323
RowLayout {
289324
Rectangle {
290325
color: "transparent"

src/rendering/RenderUtil.cc

+28-4
Original file line numberDiff line numberDiff line change
@@ -2131,11 +2131,35 @@ void RenderUtilPrivate::UpdateLights(
21312131
auto l = std::dynamic_pointer_cast<rendering::Light>(node);
21322132
if (l)
21332133
{
2134-
if (!ignition::math::equal(
2135-
l->Intensity(),
2136-
static_cast<double>(light.second.intensity())))
2134+
// todo(ahcorde) Use the field is_light_off in light.proto from
2135+
// Garden on.
2136+
bool isLightOn = true;
2137+
for (int i = 0; i < light.second.header().data_size(); ++i)
2138+
{
2139+
for (int j = 0;
2140+
j < light.second.header().data(i).value_size(); ++j)
2141+
{
2142+
if (light.second.header().data(i).key() ==
2143+
"isLightOn")
2144+
{
2145+
isLightOn = ignition::math::parseInt(
2146+
light.second.header().data(i).value(0));
2147+
}
2148+
}
2149+
}
2150+
2151+
if (isLightOn)
2152+
{
2153+
if (!ignition::math::equal(
2154+
l->Intensity(),
2155+
static_cast<double>(light.second.intensity())))
2156+
{
2157+
l->SetIntensity(light.second.intensity());
2158+
}
2159+
}
2160+
else
21372161
{
2138-
l->SetIntensity(light.second.intensity());
2162+
l->SetIntensity(0);
21392163
}
21402164
if (light.second.has_diffuse())
21412165
{

src/systems/user_commands/UserCommands.cc

+21
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,28 @@ class LightCommand : public UserCommandBase
159159
public: std::function<bool(const msgs::Light &, const msgs::Light &)>
160160
lightEql { [](const msgs::Light &_a, const msgs::Light &_b)
161161
{
162+
// todo(ahcorde) Use the field is_light_off in light.proto from
163+
// Garden on.
164+
auto getIsLightOn = [](const msgs::Light &_light) -> bool
165+
{
166+
bool isLightOn = true;
167+
for (int i = 0; i < _light.header().data_size(); ++i)
168+
{
169+
for (int j = 0;
170+
j < _light.header().data(i).value_size(); ++j)
171+
{
172+
if (_light.header().data(i).key() ==
173+
"isLightOn")
174+
{
175+
isLightOn = ignition::math::parseInt(
176+
_light.header().data(i).value(0));
177+
}
178+
}
179+
}
180+
return isLightOn;
181+
};
162182
return
183+
getIsLightOn(_a) == getIsLightOn(_b) &&
163184
_a.type() == _b.type() &&
164185
_a.name() == _b.name() &&
165186
math::equal(

test/integration/user_commands.cc

+8
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,14 @@ TEST_F(UserCommandsTest, IGN_UTILS_TEST_ENABLED_ONLY_ON_LINUX(Light))
760760
req.set_attenuation_constant(0.6f);
761761
req.set_attenuation_quadratic(0.001f);
762762
req.set_cast_shadows(true);
763+
764+
// todo(ahcorde) Use the field is_light_off in light.proto from
765+
// Garden on.
766+
auto header = req.mutable_header()->add_data();
767+
header->set_key("isLightOn");
768+
std::string *value = header->add_value();
769+
*value = std::to_string(true);
770+
763771
EXPECT_TRUE(node.Request(service, req, timeout, res, result));
764772
EXPECT_TRUE(result);
765773
EXPECT_TRUE(res.data());

0 commit comments

Comments
 (0)