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

Add Light Usercommand and include Light parameters in the componentInspector #482

Merged
merged 67 commits into from
Feb 17, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
d4fc697
Add Light Usercommand and include Light parameters in the componentIn…
ahcorde Dec 10, 2020
2b81da5
make linters happy
ahcorde Dec 10, 2020
8adc695
Included spot and directional features
ahcorde Dec 14, 2020
deea452
Fix compile warning
ahcorde Dec 14, 2020
ef53a13
make linters happy
ahcorde Dec 14, 2020
c11d628
Added feedback
ahcorde Dec 15, 2020
6609c26
make linters happy
ahcorde Dec 15, 2020
f8519ae
Added light user commands tests
ahcorde Dec 15, 2020
248af9e
make linters happy
ahcorde Dec 15, 2020
3e79da9
Merge branch 'ign-gazebo4' into ahcorde/feature/lights
ahcorde Dec 15, 2020
9823e74
Allow to plot Light values with the plotting plugin
ahcorde Dec 16, 2020
45d6faf
Merge branch 'ahcorde/feature/lights' of https://github.com/ignitionr…
ahcorde Dec 16, 2020
89f2791
Fixed plotting plugin
ahcorde Dec 16, 2020
7d80435
Merge branch 'ign-gazebo4' into ahcorde/feature/lights
ahcorde Dec 16, 2020
55e20e6
Added feedback
ahcorde Dec 16, 2020
19b3c9f
Removed LightCmd
ahcorde Dec 17, 2020
eb00612
make linters happy
ahcorde Dec 17, 2020
8877542
make linters happy
ahcorde Dec 17, 2020
0e660f9
Added UpdateECM method
ahcorde Dec 18, 2020
9ff266b
Fixed year in the License
ahcorde Dec 21, 2020
eb1d450
Fix lights inside link
ahcorde Dec 21, 2020
dc97cf2
Removed compiler warning
ahcorde Dec 21, 2020
5595db1
Merge branch 'ign-gazebo4' into ahcorde/feature/lights
ahcorde Dec 21, 2020
d175a11
make linters happy
ahcorde Dec 21, 2020
eec5a1e
Merge branch 'ahcorde/feature/lights' of https://github.com/ignitionr…
ahcorde Dec 21, 2020
2d8b9d5
simplifying the search for lights attached to links
ahcorde Dec 22, 2020
135c827
used convert method
ahcorde Dec 23, 2020
fd4edbc
Merge branch 'ign-gazebo4' into ahcorde/feature/lights
chapulina Dec 23, 2020
254a197
added some feedback
ahcorde Dec 24, 2020
d7709b4
Merge branch 'ahcorde/feature/lights' of https://github.com/ignitionr…
ahcorde Dec 28, 2020
d414397
Improved GUI
ahcorde Dec 28, 2020
cadc2ba
Fixed tests
ahcorde Dec 28, 2020
89b603a
make linters happy
ahcorde Dec 28, 2020
57e7ca3
Changed LightCmd to use msgs::Light
ahcorde Dec 30, 2020
8220d40
Merge branch 'ign-gazebo4' into ahcorde/feature/lights
ahcorde Jan 6, 2021
e68d524
Merge branch 'ign-gazebo4' into ahcorde/feature/lights
chapulina Jan 8, 2021
ab1f9b3
Merge branch 'ign-gazebo4' into ahcorde/feature/lights
chapulina Jan 8, 2021
1b0b091
Removed LightCmd from Plotting class
ahcorde Jan 12, 2021
0c78305
Fixed GUI when a color is picked through the color palette
ahcorde Jan 12, 2021
7e849ef
Merge branch 'ahcorde/feature/lights' of https://github.com/ignitionr…
ahcorde Jan 12, 2021
c49e071
Merge branch 'ign-gazebo4' into ahcorde/feature/lights
ahcorde Jan 12, 2021
69d9d66
Removed LightCmd form component inspector
ahcorde Jan 12, 2021
690b43c
Merge branch 'ign-gazebo4' into ahcorde/feature/lights
ahcorde Jan 13, 2021
642c12c
Merge branch 'ign-gazebo4' into ahcorde/feature/lights
ahcorde Jan 14, 2021
2fa8b6f
Merge branch 'ign-gazebo4' into ahcorde/feature/lights
ahcorde Jan 26, 2021
e316926
Added feedback
ahcorde Jan 26, 2021
d6f0c5f
Added feedback
ahcorde Jan 26, 2021
7a6e162
Merge branch 'ign-gazebo4' into ahcorde/feature/lights
chapulina Jan 29, 2021
7b6d922
Added feedback
ahcorde Feb 1, 2021
5bafe43
Merge branch 'ahcorde/feature/lights' of https://github.com/ignitionr…
ahcorde Feb 1, 2021
5eb2bb1
improved variable name
ahcorde Feb 1, 2021
53f045b
Added light tutorial and example (#515)
ahcorde Feb 2, 2021
4b77b66
Merge remote-tracking branch 'origin/ign-gazebo4' into ahcorde/featur…
ahcorde Feb 3, 2021
a9e2e59
Restored some files
ahcorde Feb 3, 2021
291b1d5
Fixed tests
ahcorde Feb 3, 2021
4b322b8
Fixed tests
ahcorde Feb 4, 2021
40320e7
Added feedback
ahcorde Feb 5, 2021
79779e6
Fix seg faults
ahcorde Feb 5, 2021
10a63ff
Merge branch 'ign-gazebo4' into ahcorde/feature/lights
ahcorde Feb 5, 2021
f0c104a
Merge branch 'ign-gazebo4' into ahcorde/feature/lights
ahcorde Feb 9, 2021
35c376a
Merge branch 'ign-gazebo4' into ahcorde/feature/lights
ahcorde Feb 11, 2021
0a22adc
Fixed merge
ahcorde Feb 11, 2021
88c736b
Merge branch 'ign-gazebo4' into ahcorde/feature/lights
ahcorde Feb 12, 2021
50d10e2
Merge branch 'ign-gazebo4' into ahcorde/feature/lights
ahcorde Feb 16, 2021
9004fc5
Merge branch 'ign-gazebo4' into ahcorde/feature/lights
chapulina Feb 16, 2021
b993f9d
Added feedback
ahcorde Feb 17, 2021
71623c3
Added light tutorial and example (#515)
ahcorde Feb 2, 2021
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
107 changes: 101 additions & 6 deletions src/gui/plugins/component_inspector/ComponentInspector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ namespace ignition::gazebo
/// \brief Name of the world
public: std::string worldName;

/// \brief Entity name
public: std::string entityName;

/// \brief Entity type, such as 'world' or 'model'.
public: QString type;

Expand Down Expand Up @@ -112,6 +115,46 @@ void ignition::gazebo::setData(QStandardItem *_item, const math::Pose3d &_data)
}), ComponentsModel::RoleNames().key("data"));
}

//////////////////////////////////////////////////
template<>
void ignition::gazebo::setData(QStandardItem *_item, const sdf::Light &_data)
{
int lightType = 0;
if (_data.Type() == sdf::LightType::SPOT)
{
lightType = 1;
}
else if (_data.Type() == sdf::LightType::DIRECTIONAL)
{
lightType = 2;
}
ahcorde marked this conversation as resolved.
Show resolved Hide resolved

_item->setData(QString("Light"),
ComponentsModel::RoleNames().key("dataType"));
_item->setData(QList({
QVariant(_data.Specular().R()),
QVariant(_data.Specular().G()),
QVariant(_data.Specular().B()),
QVariant(_data.Specular().A()),
QVariant(_data.Diffuse().R()),
QVariant(_data.Diffuse().G()),
QVariant(_data.Diffuse().B()),
QVariant(_data.Diffuse().A()),
QVariant(_data.AttenuationRange()),
QVariant(_data.LinearAttenuationFactor()),
QVariant(_data.ConstantAttenuationFactor()),
QVariant(_data.QuadraticAttenuationFactor()),
QVariant(_data.CastShadows()),
QVariant(lightType),
QVariant(_data.Direction().X()),
QVariant(_data.Direction().Y()),
QVariant(_data.Direction().Z()),
QVariant(_data.SpotInnerAngle().Radian()),
QVariant(_data.SpotOuterAngle().Radian()),
QVariant(_data.SpotFalloff())
}), ComponentsModel::RoleNames().key("data"));
}

//////////////////////////////////////////////////
template<>
void ignition::gazebo::setData(QStandardItem *_item,
Expand Down Expand Up @@ -370,12 +413,6 @@ void ComponentInspector::Update(const UpdateInfo &,
continue;
}

if (typeId == components::Light::typeId)
{
this->SetType("light");
ahcorde marked this conversation as resolved.
Show resolved Hide resolved
continue;
}

if (typeId == components::Actor::typeId)
{
this->SetType("actor");
Expand Down Expand Up @@ -499,6 +536,8 @@ void ComponentInspector::Update(const UpdateInfo &,

if (this->dataPtr->entity == this->dataPtr->worldEntity)
this->dataPtr->worldName = comp->Data();
else
this->dataPtr->entityName = comp->Data();
ahcorde marked this conversation as resolved.
Show resolved Hide resolved
}
else if (typeId == components::ParentEntity::typeId)
{
Expand All @@ -521,6 +560,12 @@ void ComponentInspector::Update(const UpdateInfo &,
if (comp)
setData(item, comp->Data());
}
else if (typeId == components::Light::typeId)
{
auto comp = _ecm.Component<components::Light>(this->dataPtr->entity);
if (comp)
setData(item, comp->Data());
}
else if (typeId == components::Pose::typeId)
{
auto comp = _ecm.Component<components::Pose>(this->dataPtr->entity);
Expand Down Expand Up @@ -728,6 +773,56 @@ void ComponentInspector::OnPose(double _x, double _y, double _z, double _roll,
this->dataPtr->node.Request(poseCmdService, req, cb);
}

/////////////////////////////////////////////////
void ComponentInspector::OnLight(
double _rSpecular, double _gSpecular, double _bSpecular, double _aSpecular,
double _rDiffuse, double _gDiffuse, double _bDiffuse, double _aDiffuse,
double _attRange, double _attLinear, double _attConstant,
double _attQuadratic, bool _castShadows, double _directionX,
double _directionY, double _directionZ, double _innerAngle,
double _outerAngle, double _falloff, int _type)
{
std::function<void(const ignition::msgs::Boolean &, const bool)> cb =
[](const ignition::msgs::Boolean &/*_rep*/, const bool _result)
{
if (!_result)
ignerr << "Error setting light configuration" << std::endl;
};

ignition::msgs::Light req;
req.set_name(this->dataPtr->entityName);
ahcorde marked this conversation as resolved.
Show resolved Hide resolved
ignition::msgs::Set(req.mutable_diffuse(),
ignition::math::Color(_rDiffuse, _gDiffuse, _bDiffuse, _aDiffuse));
ignition::msgs::Set(req.mutable_specular(),
ignition::math::Color(_rSpecular, _gSpecular, _bSpecular, _aSpecular));
req.set_range(_attRange);
req.set_attenuation_linear(_attLinear);
req.set_attenuation_constant(_attConstant);
req.set_attenuation_quadratic(_attQuadratic);
req.set_cast_shadows(_castShadows);
if (_type == 0)
req.set_type(ignition::msgs::Light::POINT);
else if (_type == 1)
req.set_type(ignition::msgs::Light::SPOT);
else
req.set_type(ignition::msgs::Light::DIRECTIONAL);

if (_type == 1) { // sdf::LightType::SPOT
ahcorde marked this conversation as resolved.
Show resolved Hide resolved
req.set_spot_inner_angle(_innerAngle);
req.set_spot_outer_angle(_outerAngle);
req.set_spot_falloff(_falloff);
}

// if sdf::LightType::SPOT || sdf::LightType::DIRECTIONAL
if (_type == 1 || _type == 2) {
ahcorde marked this conversation as resolved.
Show resolved Hide resolved
ignition::msgs::Set(req.mutable_direction(),
ignition::math::Vector3d(_directionX, _directionY, _directionZ));
}

auto lightConfigService = "/world/lights/config";
ahcorde marked this conversation as resolved.
Show resolved Hide resolved
this->dataPtr->node.Request(lightConfigService, req, cb);
}

/////////////////////////////////////////////////
bool ComponentInspector::NestedModel() const
{
Expand Down
31 changes: 31 additions & 0 deletions src/gui/plugins/component_inspector/ComponentInspector.hh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include <ignition/gazebo/gui/GuiSystem.hh>
#include <ignition/gazebo/Types.hh>

#include <sdf/Light.hh>

Q_DECLARE_METATYPE(ignition::gazebo::ComponentTypeId)

namespace ignition
Expand Down Expand Up @@ -69,6 +71,12 @@ namespace gazebo
template<>
void setData(QStandardItem *_item, const math::Pose3d &_data);

/// \brief Specialized to set ligth data.
ahcorde marked this conversation as resolved.
Show resolved Hide resolved
/// \param[in] _item Item whose data will be set.
/// \param[in] _data Data to set.
template<>
void setData(QStandardItem *_item, const sdf::Light &_data);

/// \brief Specialized to set vector data.
/// \param[in] _item Item whose data will be set.
/// \param[in] _data Data to set.
Expand Down Expand Up @@ -207,6 +215,29 @@ namespace gazebo
public: Q_INVOKABLE void OnPose(double _x, double _y, double _z,
double _roll, double _pitch, double _yaw);

/// \brief Callback in Qt thread when specular changes.
/// \param[in] _rSpecular specular red
/// \param[in] _gSpecular specular green
/// \param[in] _bSpecular specular blue
/// \param[in] _aSpecular specular alpha
/// \param[in] _rDiffuse Diffuse red
/// \param[in] _gDiffuse Diffuse green
/// \param[in] _bDiffuse Diffuse blue
/// \param[in] _aDiffuse Diffuse alpha
/// \param[in] _attRange Range attenuation
/// \param[in] _attLinear Linear attenuation
/// \param[in] _attConstant Constant attenuation
/// \param[in] _attQuadratic Quadratic attenuation
/// \param[in] _castShadows Cast Shadows attenuation
ahcorde marked this conversation as resolved.
Show resolved Hide resolved
public: Q_INVOKABLE void OnLight(
double _rSpecular, double _gSpecular, double _bSpecular,
double _aSpecular, double _rDiffuse, double _gDiffuse,
double _bDiffuse, double _aDiffuse, double _attRange,
double _attLinear, double _attConstant, double _attQuadratic,
bool _castShadows, double _directionX, double _directionY,
double _directionZ, double _innerAngle, double _outerAngle,
double _falloff, int _type);

/// \brief Get whether the entity is a nested model or not
/// \return True if the entity is a nested model, false otherwise
public: Q_INVOKABLE bool NestedModel() const;
Expand Down
15 changes: 15 additions & 0 deletions src/gui/plugins/component_inspector/ComponentInspector.qml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,21 @@ Rectangle {
ComponentInspector.OnPose(_x, _y, _z, _roll, _pitch, _yaw)
}

/**
* Forward light changes to C++
*/
function onLight(_rSpecular, _gSpecular, _bSpecular, _aSpecular,
_rDiffuse, _gDiffuse, _bDiffuse, _aDiffuse,
_attRange, _attLinear, _attConstant, _attQuadratic,
_castShadows, _directionX, _directionY, _directionZ,
_innerAngle, _outerAngle, _falloff, _type) {
ComponentInspector.OnLight(_rSpecular, _gSpecular, _bSpecular, _aSpecular,
_rDiffuse, _gDiffuse, _bDiffuse, _aDiffuse,
_attRange, _attLinear, _attConstant, _attQuadratic,
_castShadows, _directionX, _directionY, _directionZ,
_innerAngle, _outerAngle, _falloff, _type)
}

Rectangle {
id: header
height: lockButton.height
Expand Down
1 change: 1 addition & 0 deletions src/gui/plugins/component_inspector/ComponentInspector.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<qresource prefix="ComponentInspector/">
<file>Boolean.qml</file>
<file>ComponentInspector.qml</file>
<file>Light.qml</file>
<file>NoData.qml</file>
<file>Pose3d.qml</file>
<file>String.qml</file>
Expand Down
Loading