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 integers and floats on component inspector #1143

Merged
merged 1 commit into from
Oct 27, 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
73 changes: 73 additions & 0 deletions src/gui/plugins/component_inspector/ComponentInspector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@
#include "ignition/gazebo/components/Actor.hh"
#include "ignition/gazebo/components/AngularAcceleration.hh"
#include "ignition/gazebo/components/AngularVelocity.hh"
#include "ignition/gazebo/components/BatterySoC.hh"
#include "ignition/gazebo/components/CastShadows.hh"
#include "ignition/gazebo/components/CenterOfVolume.hh"
#include "ignition/gazebo/components/ChildLinkName.hh"
#include "ignition/gazebo/components/Collision.hh"
#include "ignition/gazebo/components/Factory.hh"
#include "ignition/gazebo/components/Gravity.hh"
#include "ignition/gazebo/components/Joint.hh"
#include "ignition/gazebo/components/LaserRetro.hh"
#include "ignition/gazebo/components/Level.hh"
#include "ignition/gazebo/components/Light.hh"
#include "ignition/gazebo/components/LinearAcceleration.hh"
Expand All @@ -53,7 +56,10 @@
#include "ignition/gazebo/components/Sensor.hh"
#include "ignition/gazebo/components/SourceFilePath.hh"
#include "ignition/gazebo/components/Static.hh"
#include "ignition/gazebo/components/ThreadPitch.hh"
#include "ignition/gazebo/components/Transparency.hh"
#include "ignition/gazebo/components/Visual.hh"
#include "ignition/gazebo/components/Volume.hh"
#include "ignition/gazebo/components/WindMode.hh"
#include "ignition/gazebo/components/World.hh"
#include "ignition/gazebo/EntityComponentManager.hh"
Expand Down Expand Up @@ -184,6 +190,13 @@ void ignition::gazebo::setData(QStandardItem *_item, const int &_data)
_item->setData(_data, ComponentsModel::RoleNames().key("data"));
}

//////////////////////////////////////////////////
template<>
void ignition::gazebo::setData(QStandardItem *_item, const Entity &_data)
{
setData(_item, static_cast<int>(_data));
}

//////////////////////////////////////////////////
template<>
void ignition::gazebo::setData(QStandardItem *_item, const double &_data)
Expand Down Expand Up @@ -462,13 +475,30 @@ void ComponentInspector::Update(const UpdateInfo &,
setUnit(item, "rad/s");
}
}
else if (typeId == components::BatterySoC::typeId)
{
auto comp = _ecm.Component<components::BatterySoC>(
this->dataPtr->entity);
if (comp)
setData(item, comp->Data());
}
else if (typeId == components::CastShadows::typeId)
{
auto comp = _ecm.Component<components::CastShadows>(
this->dataPtr->entity);
if (comp)
setData(item, comp->Data());
}
else if (typeId == components::CenterOfVolume::typeId)
{
auto comp = _ecm.Component<components::CenterOfVolume>(
this->dataPtr->entity);
if (comp)
{
setData(item, comp->Data());
setUnit(item, "m");
}
}
else if (typeId == components::ChildLinkName::typeId)
{
auto comp = _ecm.Component<components::ChildLinkName>(
Expand All @@ -485,6 +515,12 @@ void ComponentInspector::Update(const UpdateInfo &,
setUnit(item, "m/s\u00B2");
}
}
else if (typeId == components::LaserRetro::typeId)
{
auto comp = _ecm.Component<components::LaserRetro>(this->dataPtr->entity);
if (comp)
setData(item, comp->Data());
}
else if (typeId == components::LinearAcceleration::typeId)
{
auto comp = _ecm.Component<components::LinearAcceleration>(
Expand Down Expand Up @@ -584,6 +620,33 @@ void ComponentInspector::Update(const UpdateInfo &,
if (comp)
setData(item, comp->Data());
}
else if (typeId == components::ThreadPitch::typeId)
{
auto comp = _ecm.Component<components::ThreadPitch>(
this->dataPtr->entity);
if (comp)
{
setData(item, comp->Data());
setUnit(item, "m");
}
}
else if (typeId == components::Transparency::typeId)
{
auto comp = _ecm.Component<components::Transparency>(
this->dataPtr->entity);
if (comp)
setData(item, comp->Data());
}
else if (typeId == components::Volume::typeId)
{
auto comp = _ecm.Component<components::Volume>(
this->dataPtr->entity);
if (comp)
{
setData(item, comp->Data());
setUnit(item, "m\u00B3");
}
}
else if (typeId == components::WindMode::typeId)
{
auto comp = _ecm.Component<components::WindMode>(this->dataPtr->entity);
Expand All @@ -600,6 +663,16 @@ void ComponentInspector::Update(const UpdateInfo &,
setUnit(item, "rad/s\u00B2");
}
}
else if (typeId == components::WorldAngularVelocity::typeId)
{
auto comp = _ecm.Component<components::WorldAngularVelocity>(
this->dataPtr->entity);
if (comp)
{
setData(item, comp->Data());
setUnit(item, "rad/s");
}
}
else if (typeId == components::WorldLinearVelocity::typeId)
{
auto comp = _ecm.Component<components::WorldLinearVelocity>(
Expand Down
2 changes: 2 additions & 0 deletions src/gui/plugins/component_inspector/ComponentInspector.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<qresource prefix="ComponentInspector/">
<file>Boolean.qml</file>
<file>ComponentInspector.qml</file>
<file>Float.qml</file>
<file>Integer.qml</file>
<file>NoData.qml</file>
<file>Physics.qml</file>
<file>Pose3d.qml</file>
Expand Down
20 changes: 15 additions & 5 deletions src/gui/plugins/component_inspector/Float.qml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ Rectangle {
// Maximum spinbox value
property double spinMax: 1000000

// Unit
property string unit: model && model.unit != undefined ? model.unit : ''

RowLayout {
anchors.fill: parent

Expand All @@ -55,13 +58,20 @@ Rectangle {
id: typeHeader
}

IgnSpinBox {
// TODO(anyone) Support write mode
Text {
id: content
value: model.data
minimumValue: -spinMax
maximumValue: spinMax
decimals: xSpin.width < 100 ? 2 : 6
Layout.fillWidth: true
horizontalAlignment: Text.AlignRight
color: Material.theme == Material.Light ? "black" : "white"
font.pointSize: 12
text: {
var decimals = getDecimals(content.width)
var valueText = model.data.toFixed(decimals)
if (unit !== '')
valueText += ' ' + unit
return valueText
}
}

Item {
Expand Down
20 changes: 15 additions & 5 deletions src/gui/plugins/component_inspector/Integer.qml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ Rectangle {
// Maximum spinbox value
property double spinMax: 1000000

Row {
// Unit
property string unit: model && model.unit != undefined ? model.unit : ''

RowLayout {
anchors.fill: parent

Item {
Expand All @@ -55,12 +58,19 @@ Rectangle {
id: typeHeader
}

IgnSpinBox {
// TODO(anyone) Support write mode
Text {
id: content
value: model.data
minimumValue: -spinMax
maximumValue: spinMax
Layout.fillWidth: true
horizontalAlignment: Text.AlignRight
color: Material.theme == Material.Light ? "black" : "white"
font.pointSize: 12
text: {
var valueText = model.data
if (unit !== '')
valueText += ' ' + unit
return valueText
}
}

Item {
Expand Down