From 0526c4eb528b249dd9121f654bf532e8afdee06f Mon Sep 17 00:00:00 2001 From: AmrElsersy Date: Thu, 30 Jul 2020 00:14:04 +0200 Subject: [PATCH 01/14] Drag & Drop Items in Component Inspector Signed-off-by: AmrElsersy --- .../component_inspector/ComponentInspector.cc | 6 +- .../ComponentInspector.qrc | 1 + .../plugins/component_inspector/Pose3d.qml | 187 +++++++++++++++--- .../plugins/component_inspector/Vector3d.qml | 107 ++++++++-- .../component_inspector/plottable_icon.svg | 76 +++++++ 5 files changed, 329 insertions(+), 48 deletions(-) create mode 100644 src/gui/plugins/component_inspector/plottable_icon.svg diff --git a/src/gui/plugins/component_inspector/ComponentInspector.cc b/src/gui/plugins/component_inspector/ComponentInspector.cc index 1857dca09e..cdc8bee1f9 100644 --- a/src/gui/plugins/component_inspector/ComponentInspector.cc +++ b/src/gui/plugins/component_inspector/ComponentInspector.cc @@ -256,7 +256,8 @@ QHash ComponentsModel::RoleNames() std::pair(102, "shortName"), std::pair(103, "dataType"), std::pair(104, "unit"), - std::pair(105, "data")}; + std::pair(105, "data"), + std::pair(106, "entity")}; } ///////////////////////////////////////////////// @@ -383,6 +384,9 @@ void ComponentInspector::Update(const UpdateInfo &, Q_ARG(ignition::gazebo::ComponentTypeId, typeId)); } + item->setData(QString::number(this->dataPtr->entity), + ComponentsModel::RoleNames().key("entity")); + if (nullptr == item) { ignerr << "Failed to get item for component type [" << typeId << "]" diff --git a/src/gui/plugins/component_inspector/ComponentInspector.qrc b/src/gui/plugins/component_inspector/ComponentInspector.qrc index 73b599baf0..43efec19d1 100644 --- a/src/gui/plugins/component_inspector/ComponentInspector.qrc +++ b/src/gui/plugins/component_inspector/ComponentInspector.qrc @@ -7,5 +7,6 @@ String.qml TypeHeader.qml Vector3d.qml + plottable_icon.svg diff --git a/src/gui/plugins/component_inspector/Pose3d.qml b/src/gui/plugins/component_inspector/Pose3d.qml index 0190a08c04..b1a3534cfe 100644 --- a/src/gui/plugins/component_inspector/Pose3d.qml +++ b/src/gui/plugins/component_inspector/Pose3d.qml @@ -44,6 +44,9 @@ Rectangle { return !(isModel) } + property int iconWidth: 20 + property int iconHeight: 20 + // Loaded item for X property var xItem: {} @@ -177,6 +180,7 @@ Rectangle { } } + GridLayout { id: grid width: parent.width @@ -185,14 +189,58 @@ Rectangle { // Left spacer Item { Layout.rowSpan: 3 - width: margin + indentation + width: margin + } + + + Component { + id: plotIcon + Image { + property string componentInfo: "" + source: "plottable_icon.svg" + anchors.top: parent.top + anchors.left: parent.left + + Drag.mimeData: { "text/plain" : (model === null) ? "" : + "Component," + model.entity + "," + model.typeId + "," + model.dataType + "," + componentInfo} + Drag.dragType: Drag.Automatic + Drag.supportedActions : Qt.CopyAction + Drag.active: dragMouse.drag.active + // a point to drag from + Drag.hotSpot.x: 0 + Drag.hotSpot.y: y + MouseArea { + id: dragMouse + anchors.fill: parent + drag.target: (model === null) ? null : parent + onPressed: parent.grabToImage(function(result) {parent.Drag.imageSource = result.url }) + onReleased: parent.Drag.drop(); + cursorShape: Qt.DragCopyCursor + } + } } - Text { - text: 'X (m)' - leftPadding: 5 - color: Material.theme == Material.Light ? "#444444" : "#bbbbbb" - font.pointSize: 12 + Rectangle { + color: "transparent" + height: 40 + Layout.preferredWidth: xText.width + indentation*3 + Loader { + id: loaderX + width: iconWidth + height: iconHeight + y:10 + sourceComponent: plotIcon + } + Component.onCompleted: loaderX.item.componentInfo = "x" + + Text { + id : xText + text: ' X (m)' + leftPadding: 5 + color: Material.theme == Material.Light ? "#444444" : "#bbbbbb" + font.pointSize: 12 + anchors.centerIn: parent + } } Item { @@ -209,11 +257,27 @@ Rectangle { } } - Text { - text: 'Roll (rad)' - leftPadding: 5 - color: Material.theme == Material.Light ? "#444444" : "#bbbbbb" - font.pointSize: 12 + Rectangle { + color: "transparent" + height: 40 + Layout.preferredWidth: rollText.width + indentation*3 + Loader { + id: loaderRoll + width: iconWidth + height: iconHeight + y:10 + sourceComponent: plotIcon + } + Component.onCompleted: loaderRoll.item.componentInfo = "roll" + + Text { + id: rollText + text: ' Roll (rad)' + leftPadding: 5 + color: Material.theme == Material.Light ? "#444444" : "#bbbbbb" + font.pointSize: 12 + anchors.centerIn: parent + } } Item { @@ -236,11 +300,27 @@ Rectangle { width: margin } - Text { - text: 'Y (m)' - leftPadding: 5 - color: Material.theme == Material.Light ? "#444444" : "#bbbbbb" - font.pointSize: 12 + + Rectangle { + color: "transparent" + height: 40 + Layout.preferredWidth: yText.width + indentation*3 + Loader { + id: loaderY + width: iconWidth + height: iconHeight + y:10 + sourceComponent: plotIcon + } + Component.onCompleted: loaderY.item.componentInfo = "y" + Text { + id: yText + text: ' Y (m)' + leftPadding: 5 + color: Material.theme == Material.Light ? "#444444" : "#bbbbbb" + font.pointSize: 12 + anchors.centerIn: parent + } } Item { @@ -257,11 +337,26 @@ Rectangle { } } - Text { - text: 'Pitch (rad)' - leftPadding: 5 - color: Material.theme == Material.Light ? "#444444" : "#bbbbbb" - font.pointSize: 12 + Rectangle { + color: "transparent" + height: 40 + Layout.preferredWidth: pitchText.width + indentation*3 + Loader { + id: loaderPitch + width: iconWidth + height: iconHeight + y:10 + sourceComponent: plotIcon + } + Component.onCompleted: loaderPitch.item.componentInfo = "pitch"; + Text { + id: pitchText + text: ' Pitch (rad)' + leftPadding: 5 + color: Material.theme == Material.Light ? "#444444" : "#bbbbbb" + font.pointSize: 12 + anchors.centerIn: parent + } } Item { @@ -278,11 +373,26 @@ Rectangle { } } - Text { - text: 'Z (m)' - leftPadding: 5 - color: Material.theme == Material.Light ? "#444444" : "#bbbbbb" - font.pointSize: 12 + Rectangle { + color: "transparent" + height: 40 + Layout.preferredWidth: zText.width + indentation*3 + Loader { + id: loaderZ + width: iconWidth + height: iconHeight + y:10 + sourceComponent: plotIcon + } + Component.onCompleted: loaderZ.item.componentInfo = "z"; + Text { + id: zText + text: ' Z (m)' + leftPadding: 5 + color: Material.theme == Material.Light ? "#444444" : "#bbbbbb" + font.pointSize: 12 + anchors.centerIn: parent + } } Item { @@ -299,11 +409,26 @@ Rectangle { } } - Text { - text: 'Yaw (rad)' - leftPadding: 5 - color: Material.theme == Material.Light ? "#444444" : "#bbbbbb" - font.pointSize: 12 + Rectangle { + color: "transparent" + height: 40 + Layout.preferredWidth: yawText.width + indentation*3 + Loader { + id: loaderYaw + width: iconWidth + height: iconHeight + y:10 + sourceComponent: plotIcon + } + Component.onCompleted: loaderYaw.item.componentInfo = "yaw"; + Text { + id: yawText + text: ' Yaw (rad)' + leftPadding: 5 + color: Material.theme == Material.Light ? "#444444" : "#bbbbbb" + font.pointSize: 12 + anchors.centerIn: parent + } } Item { diff --git a/src/gui/plugins/component_inspector/Vector3d.qml b/src/gui/plugins/component_inspector/Vector3d.qml index 669619aa0a..66088c08d2 100644 --- a/src/gui/plugins/component_inspector/Vector3d.qml +++ b/src/gui/plugins/component_inspector/Vector3d.qml @@ -32,6 +32,10 @@ Rectangle { // Left indentation property int indentation: 10 + // icon size + property int iconWidth: 20 + property int iconHeight: 20 + // Horizontal margins property int margin: 5 @@ -74,6 +78,32 @@ Rectangle { } } } + Component { + id: plotIcon + Image { + property string componentInfo: "" + source: "plottable_icon.svg" + anchors.top: parent.top + anchors.left: parent.left + + Drag.mimeData: { "text/plain" : (model === null) ? "" : + "Component," + model.entity + "," + model.typeId + "," + model.dataType + "," + componentInfo} + Drag.dragType: Drag.Automatic + Drag.supportedActions : Qt.CopyAction + Drag.active: dragMouse.drag.active + // a point to drag from + Drag.hotSpot.x: 0 + Drag.hotSpot.y: y + MouseArea { + id: dragMouse + anchors.fill: parent + drag.target: (model === null) ? null : parent + onPressed: parent.grabToImage(function(result) {parent.Drag.imageSource = result.url }) + onReleased: parent.Drag.drop(); + cursorShape: Qt.DragCopyCursor + } + } + } Column { anchors.fill: parent @@ -149,13 +179,28 @@ Rectangle { width: indentation + margin } - Text { - text: 'X (' + unit + ')' - leftPadding: 5 - color: Material.theme == Material.Light ? "#444444" : "#bbbbbb" - font.pointSize: 12 - } + Rectangle { + color: "transparent" + height: 40 + Layout.preferredWidth: xText.width + indentation*3 + Loader { + id: loaderX + width: iconWidth + height: iconHeight + y:10 + sourceComponent: plotIcon + } + Component.onCompleted: loaderX.item.componentInfo = "x" + Text { + id: xText + text: ' X (' + unit + ')' + leftPadding: 5 + color: Material.theme == Material.Light ? "#444444" : "#bbbbbb" + font.pointSize: 12 + anchors.centerIn: parent + } + } Item { Layout.fillWidth: true height: 40 @@ -172,11 +217,26 @@ Rectangle { width: margin } - Text { - text: 'Y (' + unit + ')' - leftPadding: 5 - color: Material.theme == Material.Light ? "#444444" : "#bbbbbb" - font.pointSize: 12 + Rectangle { + color: "transparent" + height: 40 + Layout.preferredWidth: xText.width + indentation*3 + Loader { + id: loaderY + width: iconWidth + height: iconHeight + y:10 + sourceComponent: plotIcon + } + Component.onCompleted: loaderY.item.componentInfo = "y" + + Text { + text: ' Y (' + unit + ')' + leftPadding: 5 + color: Material.theme == Material.Light ? "#444444" : "#bbbbbb" + font.pointSize: 12 + anchors.centerIn: parent + } } Item { @@ -189,11 +249,26 @@ Rectangle { } } - Text { - text: 'Z (' + unit + ')' - leftPadding: 5 - color: Material.theme == Material.Light ? "#444444" : "#bbbbbb" - font.pointSize: 12 + Rectangle { + color: "transparent" + height: 40 + Layout.preferredWidth: xText.width + indentation*3 + Loader { + id: loaderZ + width: iconWidth + height: iconHeight + y:10 + sourceComponent: plotIcon + } + Component.onCompleted: loaderZ.item.componentInfo = "z" + + Text { + text: 'Z (' + unit + ')' + leftPadding: 5 + color: Material.theme == Material.Light ? "#444444" : "#bbbbbb" + font.pointSize: 12 + anchors.centerIn: parent + } } Item { diff --git a/src/gui/plugins/component_inspector/plottable_icon.svg b/src/gui/plugins/component_inspector/plottable_icon.svg new file mode 100644 index 0000000000..bcac9afc2e --- /dev/null +++ b/src/gui/plugins/component_inspector/plottable_icon.svg @@ -0,0 +1,76 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + From 99f7633ebb93868b26c8191b2877d4037e54b2b9 Mon Sep 17 00:00:00 2001 From: AmrElsersy Date: Sun, 2 Aug 2020 10:12:58 +0200 Subject: [PATCH 02/14] Component Plotting Plugin Signed-off-by: AmrElsersy --- src/gui/plugins/CMakeLists.txt | 1 + src/gui/plugins/plotting/CMakeLists.txt | 4 + src/gui/plugins/plotting/Plotting.cc | 353 ++++++++++++++++++++++++ src/gui/plugins/plotting/Plotting.hh | 188 +++++++++++++ src/gui/plugins/plotting/Plotting.qml | 5 + src/gui/plugins/plotting/Plotting.qrc | 5 + 6 files changed, 556 insertions(+) create mode 100644 src/gui/plugins/plotting/CMakeLists.txt create mode 100644 src/gui/plugins/plotting/Plotting.cc create mode 100644 src/gui/plugins/plotting/Plotting.hh create mode 100644 src/gui/plugins/plotting/Plotting.qml create mode 100644 src/gui/plugins/plotting/Plotting.qrc diff --git a/src/gui/plugins/CMakeLists.txt b/src/gui/plugins/CMakeLists.txt index c2ef4a81b0..55be08c151 100644 --- a/src/gui/plugins/CMakeLists.txt +++ b/src/gui/plugins/CMakeLists.txt @@ -85,6 +85,7 @@ add_subdirectory(align_tool) add_subdirectory(component_inspector) add_subdirectory(entity_tree) add_subdirectory(grid_config) +add_subdirectory(plotting) add_subdirectory(scene3d) add_subdirectory(shapes) add_subdirectory(transform_control) diff --git a/src/gui/plugins/plotting/CMakeLists.txt b/src/gui/plugins/plotting/CMakeLists.txt new file mode 100644 index 0000000000..dc26ac4083 --- /dev/null +++ b/src/gui/plugins/plotting/CMakeLists.txt @@ -0,0 +1,4 @@ +gz_add_gui_plugin(Plotting + SOURCES Plotting.cc + QT_HEADERS Plotting.hh +) diff --git a/src/gui/plugins/plotting/Plotting.cc b/src/gui/plugins/plotting/Plotting.cc new file mode 100644 index 0000000000..119f2bfce3 --- /dev/null +++ b/src/gui/plugins/plotting/Plotting.cc @@ -0,0 +1,353 @@ +/* + * Copyright (C) 2020 Open Source Robotics Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * +*/ +#include + +#include "Plotting.hh" + +namespace ignition::gazebo +{ + class PlottingPrivate + { + /// \brief Interface to communicate with Qml + public: ignition::gui::PlottingInterface *plottingIface; + + public: std::map components; + + public: QTimer *timer; + }; +} + +using namespace ignition::gazebo; +using namespace ignition::gui; + +////////////////////////////////////////////////// +PlotComponent::PlotComponent(std::string _type, uint64_t _entity, + uint64_t _typeId) +{ + this->entity = _entity; + this->typeId = _typeId; + this->type = _type; + + if (_type == "Vector3d") + { + this->data["x"] = new Field(); + this->data["y"] = new Field(); + this->data["z"] = new Field(); + this->data["roll"] = new Field(); + this->data["pitch"] = new Field(); + this->data["yaw"] = new Field(); + } + else if (_type == "Pose3d") + { + this->data["x"] = new Field(); + this->data["y"] = new Field(); + this->data["z"] = new Field(); + } + else if (_type == "double") + this->data["value"] = new Field(); + else + ignwarn << "Invalid Plot Component Type:" << _type << std::endl; +} + +////////////////////////////////////////////////// +void PlotComponent::RegisterChart(std::string _attribute, int _chart) +{ + if (this->data.count(_attribute) == 0) + { + ignwarn << "Invalid Plot Component Attribute" << std::endl; + return; + } + this->data[_attribute]->AddChart(_chart); +} + +////////////////////////////////////////////////// +void PlotComponent::UnRegisterChart(std::string _attribute, int _chart) +{ + if (this->data.count(_attribute) == 0) + { + ignwarn << "Invalid Plot Component Attribute" << std::endl; + return; + } + this->data[_attribute]->RemoveChart(_chart); +} + +////////////////////////////////////////////////// +bool PlotComponent::HasCharts() +{ + for (auto field : data) + if (field.second->ChartCount() > 0) + return true; + return false; +} + +////////////////////////////////////////////////// +void PlotComponent::SetAttributeValue(std::string _attribute, + const double &_value) +{ + if (this->data.count(_attribute) > 0) + this->data[_attribute]->SetValue(_value); +} + +////////////////////////////////////////////////// +std::map PlotComponent::Data() const +{ + return this->data; +} + +////////////////////////////////////////////////// +uint64_t PlotComponent::Entity() +{ + return this->entity; +} + +////////////////////////////////////////////////// +uint64_t PlotComponent::TypeId() +{ + return this->typeId; +} + +// ======================= Plotting ========================= +Plotting ::Plotting () : GuiSystem() , dataPtr(new PlottingPrivate) +{ + this->dataPtr->plottingIface = new ignition::gui::PlottingInterface(); + + // Plot Timer + this->dataPtr->timer = new QTimer(); + auto timeout = this->dataPtr->plottingIface->Timeout(); + this->dataPtr->timer->setInterval(timeout); + connect(this->dataPtr->timer, SIGNAL(timeout()), this, SLOT(UpdateGui())); + this->dataPtr->timer->start(); + + // PlottingInterface connecting + connect(this->dataPtr->plottingIface, SIGNAL(ComponentSubscribe + (uint64_t, uint64_t, std::string, std::string, int)), + this, SLOT(RegisterChartToComponent + (uint64_t, uint64_t, std::string, std::string, int))); + + connect(this->dataPtr->plottingIface, SIGNAL(ComponentUnSubscribe + (uint64_t, uint64_t, std::string, int)), + this, SLOT(UnRegisterChartToComponent + (uint64_t, uint64_t, std::string, int))); +} + +////////////////////////////////////////////////// +Plotting ::~Plotting() +{ + delete this->dataPtr->plottingIface; +} + +////////////////////////////////////////////////// +void Plotting::SetData(std::string _Id, const ignition::math::Vector3d &_vector) +{ + this->dataPtr->components[_Id]->SetAttributeValue("x", _vector.X()); + this->dataPtr->components[_Id]->SetAttributeValue("y", _vector.Y()); + this->dataPtr->components[_Id]->SetAttributeValue("z", _vector.Z()); +} + +////////////////////////////////////////////////// +void Plotting::SetData(std::string _Id, const ignition::math::Pose3d &_pose) +{ + this->dataPtr->components[_Id]->SetAttributeValue("x", _pose.Pos().X()); + this->dataPtr->components[_Id]->SetAttributeValue("y", _pose.Pos().Y()); + this->dataPtr->components[_Id]->SetAttributeValue("z", _pose.Pos().Z()); + this->dataPtr->components[_Id]->SetAttributeValue("roll", _pose.Rot().Roll()); + this->dataPtr->components[_Id]->SetAttributeValue("pitch", + _pose.Rot().Pitch()); + this->dataPtr->components[_Id]->SetAttributeValue("yaw", _pose.Rot().Yaw()); +} + +////////////////////////////////////////////////// +void Plotting::SetData(std::string _Id, const double &_value) +{ + this->dataPtr->components[_Id]->SetAttributeValue("value", _value); +} + + +////////////////////////////////////////////////// +void Plotting::RegisterChartToComponent(uint64_t _entity, uint64_t _typeId, + std::string _type, + std::string _attribute, + int _chart) +{ + std::string Id = std::to_string(_entity) + "," + std::to_string(_typeId); + + if (this->dataPtr->components.count(Id) == 0) + this->dataPtr->components[Id] = new PlotComponent(_type, + _entity, + _typeId); + + this->dataPtr->components[Id]->RegisterChart(_attribute, _chart); +} + +////////////////////////////////////////////////// +void Plotting::UnRegisterChartToComponent(uint64_t _entity, uint64_t _typeId, + std::string _attribute, int _chart) +{ + std::string Id = std::to_string(_entity) + "," + std::to_string(_typeId); + std::cout << "UnRegister " << Id << std::endl; + + if (this->dataPtr->components.count(Id) == 0) + return; + + this->dataPtr->components[Id]->UnRegisterChart(_attribute, _chart); + + if (!this->dataPtr->components[Id]->HasCharts()) + this->dataPtr->components.erase(Id); +} + +////////////////////////////////////////////////// +void Plotting ::Update(const ignition::gazebo::UpdateInfo &, + ignition::gazebo::EntityComponentManager &_ecm) +{ + for (auto component : this->dataPtr->components) + { + auto entity = component.second->Entity(); + auto typeId = component.second->TypeId(); + + if (typeId == components::AngularAcceleration::typeId) + { + auto comp = _ecm.Component(entity); + if (comp) + this->SetData(component.first, comp->Data()); + } + else if (typeId == components::AngularVelocity::typeId) + { + auto comp = _ecm.Component(entity); + if (comp) + this->SetData(component.first, comp->Data()); + } + else if (typeId == components::CastShadows::typeId) + { + auto comp = _ecm.Component(entity); + if (comp) + this->SetData(component.first, comp->Data()); + } + else if (typeId == components::Gravity::typeId) + { + auto comp = _ecm.Component(entity); + if (comp) + this->SetData(component.first, comp->Data()); + } + else if (typeId == components::LinearAcceleration::typeId) + { + auto comp = _ecm.Component(entity); + if (comp) + this->SetData(component.first, comp->Data()); + } + else if (typeId == components::LinearVelocity::typeId) + { + auto comp = _ecm.Component(entity); + if (comp) + this->SetData(component.first, comp->Data()); + } + else if (typeId == components::MagneticField::typeId) + { + auto comp = _ecm.Component(entity); + if (comp) + this->SetData(component.first, comp->Data()); + } + else if (typeId == components::ParentEntity::typeId) + { + auto comp = _ecm.Component(entity); + if (comp) + this->SetData(component.first, comp->Data()); + } + else if (typeId == components::Pose::typeId) + { + auto comp = _ecm.Component(entity); + if (comp) + this->SetData(component.first, comp->Data()); + } + else if (typeId == components::Static::typeId) + { + auto comp = _ecm.Component(entity); + if (comp) + this->SetData(component.first, comp->Data()); + } + else if (typeId == components::TrajectoryPose::typeId) + { + auto comp = _ecm.Component(entity); + if (comp) + this->SetData(component.first, comp->Data()); + } + else if (typeId == components::WindMode::typeId) + { + auto comp = _ecm.Component(entity); + if (comp) + this->SetData(component.first, comp->Data()); + } + else if (typeId == components::WorldAngularAcceleration::typeId) + { + auto comp = _ecm.Component( + entity); + if (comp) + this->SetData(component.first, comp->Data()); + } + else if (typeId == components::WorldLinearVelocity::typeId) + { + auto comp = _ecm.Component( + entity); + if (comp) + this->SetData(component.first, comp->Data()); + } + else if (typeId == components::WorldLinearVelocitySeed::typeId) + { + auto comp = _ecm.Component( + entity); + if (comp) + this->SetData(component.first, comp->Data()); + } + else if (typeId == components::WorldPose::typeId) + { + auto comp = _ecm.Component(entity); + if (comp) + this->SetData(component.first, comp->Data()); + } + else if (typeId == components::WorldPoseCmd::typeId) + { + auto comp = _ecm.Component(entity); + if (comp) + this->SetData(component.first, comp->Data()); + } + } +} + +////////////////////////////////////////////////// +void Plotting ::UpdateGui() +{ + // Complexty O(registered attributes) + for (auto component : this->dataPtr->components) + { + for (auto attribute : component.second->Data()) + { + for (auto chart : attribute.second->Charts()) + { + QString attributeName = QString::fromStdString( + component.first + "," + attribute.first); + float x = this->dataPtr->plottingIface->Time(); + double y = attribute.second->Value(); + + emit this->dataPtr->plottingIface->plot(chart, attributeName, x, y); + } + } + } +} + +// Register this plugin +IGNITION_ADD_PLUGIN(ignition::gazebo::Plotting , + ignition::gazebo::GuiSystem, + ignition::gui::Plugin) diff --git a/src/gui/plugins/plotting/Plotting.hh b/src/gui/plugins/plotting/Plotting.hh new file mode 100644 index 0000000000..a0fa09df68 --- /dev/null +++ b/src/gui/plugins/plotting/Plotting.hh @@ -0,0 +1,188 @@ +/* + * Copyright (C) 2020 Open Source Robotics Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * +*/ +#ifndef IGNITION_GUI_PLUGINS_PLOTTING_HH_ +#define IGNITION_GUI_PLUGINS_PLOTTING_HH_ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "ignition/gazebo/components/Actor.hh" +#include "ignition/gazebo/components/AngularAcceleration.hh" +#include "ignition/gazebo/components/AngularVelocity.hh" +#include "ignition/gazebo/components/CastShadows.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/Level.hh" +#include "ignition/gazebo/components/Light.hh" +#include "ignition/gazebo/components/LinearAcceleration.hh" +#include "ignition/gazebo/components/LinearVelocity.hh" +#include "ignition/gazebo/components/LinearVelocitySeed.hh" +#include "ignition/gazebo/components/Link.hh" +#include "ignition/gazebo/components/MagneticField.hh" +#include "ignition/gazebo/components/Model.hh" +#include "ignition/gazebo/components/Name.hh" +#include "ignition/gazebo/components/ParentEntity.hh" +#include "ignition/gazebo/components/ParentLinkName.hh" +#include "ignition/gazebo/components/Performer.hh" +#include "ignition/gazebo/components/PerformerAffinity.hh" +#include "ignition/gazebo/components/Pose.hh" +#include "ignition/gazebo/components/PoseCmd.hh" +#include "ignition/gazebo/components/Sensor.hh" +#include "ignition/gazebo/components/Static.hh" +#include "ignition/gazebo/components/Visual.hh" +#include "ignition/gazebo/components/WindMode.hh" +#include "ignition/gazebo/components/World.hh" +#include "ignition/gazebo/EntityComponentManager.hh" + + +class PlotComponent +{ + /// \brief Constructor + /// \param[in] _type component data type (Pose3d, Vector3d, double) + /// \param [in] _entity entity id of that component + /// \param [in] _typeId type identifier unique to each component type + public: PlotComponent(std::string _type, uint64_t _entity, uint64_t _typeId); + + /// \brief Add a registered chart to the attribute + /// \param[in] _attribute component attribute to add the chart to it + /// \param[in] _chart chart ID to be added to the attribute + public: void RegisterChart(std::string _attribute, int _chart); + + /// \brief Remove a registered chart from the attribute + /// \param[in] _attribute component attribute to remove the chart from it + /// \param[in] _chart chart ID to be removed from the attribute + public: void UnRegisterChart(std::string _attribute, int _chart); + + /// \brief Check if any of the component attributes has any chart + /// \return true if any attribute has a chart + /// false if all attributes are empty from the charts + public: bool HasCharts(); + + /// \brief Set a value of specefic component attribute + /// \param[in] _attribute component attribute to set its value + /// ex : yaw attribute in Pose3d type Component + /// \param[in] _value value to be set to the attribute + public: void SetAttributeValue(std::string _attribute, const double &_value); + + /// \brief Get all attributes of the component + /// \return component attributes + public: std::map Data() const; + + /// \brief Get the Component entity ID + /// \return entity ID + public: uint64_t Entity(); + + /// \brief Get the Component type ID + /// \return component type ID + public: uint64_t TypeId(); + + /// \brief entity id in the simulation + private: uint64_t entity; + + /// \brief type identifier unique to each component type + private: uint64_t typeId; + + /// \brief component data type (Pose3d, Vector3d, double) + private: std::string type; + + /// \brief attributes of the components, + /// ex: x,y,z attributes in Vector3d type component + private: std::map data; +}; + + +namespace ignition { + +namespace gazebo { + +class PlottingPrivate; + +class Plotting : public ignition::gazebo::GuiSystem +{ + Q_OBJECT + /// \brief Constructor + public: Plotting(); + + /// \brief Destructor + public: ~Plotting(); + + /// \brief called every simulation iteration to access components + public: void Update(const ignition::gazebo::UpdateInfo &_info, + ignition::gazebo::EntityComponentManager &_ecm) override; + + /// \brief Set the Component data of giving id to the giving vector + /// \param [in] _Id Component Key of the components map + /// \param [in] _vector Vector Data to be set to the component + public: void SetData(std::string _Id, + const ignition::math::Vector3d &_vector); + + /// \brief Set the Component data of giving id to the giving pose + /// \param [in] _Id Component Key of the components map + /// \param [in] _pose Position Data to be set to the component + public: void SetData(std::string _Id, + const ignition::math::Pose3d &_pose); + + /// \brief Set the Component data of giving id to the giving number + /// \param [in] _Id Component Key of the components map + /// \param [in] _value double Data to be set to the component + /// valid for types (double, float, int, bool) + public: void SetData(std::string _Id, const double &_value); + + /// \brief Add a chart to a specefic component attribute + /// \param [in] _entity entity id in the simulation + /// \param [in] _typeId type identifier unique to each component type + /// \param [in] _attribute component attribute to add the chart to it + /// ex: x attribute in Pose3d Component + /// \param [in] _chart chart ID to be registered + public slots: void RegisterChartToComponent(uint64_t _entity, + uint64_t _typeId, + std::string _type, + std::string _attribute, + int _chart); + + /// \brief Remove a chart from a specefic component attribute + /// \param [in] _entity entity id in the simulation + /// \param [in] _typeId type identifier unique to each component type + /// \param [in] _attribute component attribute to remove the chart from it + /// ex: x attribute in Pose3d Component + /// \param [in] _chart chart ID to be unregistered + public slots: void UnRegisterChartToComponent(uint64_t _entity, + uint64_t _typeId, + std::string _attribute, + int _chart); + + /// \brief send data to Qml to plot + public slots: void UpdateGui(); + + /// \brief dataPtr holds Abstraction data of PlottingPrivate + private: std::unique_ptr dataPtr; +}; +} +} + +#endif diff --git a/src/gui/plugins/plotting/Plotting.qml b/src/gui/plugins/plotting/Plotting.qml new file mode 100644 index 0000000000..913d9f49ff --- /dev/null +++ b/src/gui/plugins/plotting/Plotting.qml @@ -0,0 +1,5 @@ +import "qrc:/qml" + +PlottingInterface { + +} diff --git a/src/gui/plugins/plotting/Plotting.qrc b/src/gui/plugins/plotting/Plotting.qrc new file mode 100644 index 0000000000..e520bf6c03 --- /dev/null +++ b/src/gui/plugins/plotting/Plotting.qrc @@ -0,0 +1,5 @@ + + + Plotting.qml + + From e72f3c2f350d7ef2fd0fef55eeea6d3368d256b2 Mon Sep 17 00:00:00 2001 From: AmrElsersy Date: Thu, 13 Aug 2020 10:58:04 +0200 Subject: [PATCH 03/14] Integration with PlottingInterface Signed-off-by: AmrElsersy --- src/gui/plugins/plotting/Plotting.cc | 22 +++++++++++----------- src/gui/plugins/plotting/Plotting.hh | 4 ++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/gui/plugins/plotting/Plotting.cc b/src/gui/plugins/plotting/Plotting.cc index 119f2bfce3..b58d3e1dc7 100644 --- a/src/gui/plugins/plotting/Plotting.cc +++ b/src/gui/plugins/plotting/Plotting.cc @@ -44,21 +44,21 @@ PlotComponent::PlotComponent(std::string _type, uint64_t _entity, if (_type == "Vector3d") { - this->data["x"] = new Field(); - this->data["y"] = new Field(); - this->data["z"] = new Field(); - this->data["roll"] = new Field(); - this->data["pitch"] = new Field(); - this->data["yaw"] = new Field(); + this->data["x"] = new PlotData(); + this->data["y"] = new PlotData(); + this->data["z"] = new PlotData(); } else if (_type == "Pose3d") { - this->data["x"] = new Field(); - this->data["y"] = new Field(); - this->data["z"] = new Field(); + this->data["x"] = new PlotData(); + this->data["y"] = new PlotData(); + this->data["z"] = new PlotData(); + this->data["roll"] = new PlotData(); + this->data["pitch"] = new PlotData(); + this->data["yaw"] = new PlotData(); } else if (_type == "double") - this->data["value"] = new Field(); + this->data["value"] = new PlotData(); else ignwarn << "Invalid Plot Component Type:" << _type << std::endl; } @@ -103,7 +103,7 @@ void PlotComponent::SetAttributeValue(std::string _attribute, } ////////////////////////////////////////////////// -std::map PlotComponent::Data() const +std::map PlotComponent::Data() const { return this->data; } diff --git a/src/gui/plugins/plotting/Plotting.hh b/src/gui/plugins/plotting/Plotting.hh index a0fa09df68..f9e262cfe7 100644 --- a/src/gui/plugins/plotting/Plotting.hh +++ b/src/gui/plugins/plotting/Plotting.hh @@ -91,7 +91,7 @@ class PlotComponent /// \brief Get all attributes of the component /// \return component attributes - public: std::map Data() const; + public: std::map Data() const; /// \brief Get the Component entity ID /// \return entity ID @@ -112,7 +112,7 @@ class PlotComponent /// \brief attributes of the components, /// ex: x,y,z attributes in Vector3d type component - private: std::map data; + private: std::map data; }; From d6dbd898d57e953f2cfca3dac3326bfda27640ff Mon Sep 17 00:00:00 2001 From: AmrElsersy Date: Thu, 13 Aug 2020 11:44:56 +0200 Subject: [PATCH 04/14] dataPtr Plot Component Signed-off-by: AmrElsersy --- src/gui/plugins/plotting/Plotting.cc | 65 ++++++++++++++++++---------- src/gui/plugins/plotting/Plotting.hh | 24 +++------- 2 files changed, 48 insertions(+), 41 deletions(-) diff --git a/src/gui/plugins/plotting/Plotting.cc b/src/gui/plugins/plotting/Plotting.cc index b58d3e1dc7..98a8c03e49 100644 --- a/src/gui/plugins/plotting/Plotting.cc +++ b/src/gui/plugins/plotting/Plotting.cc @@ -29,6 +29,22 @@ namespace ignition::gazebo public: QTimer *timer; }; + + class PlotComponentPrivate + { + /// \brief entity id in the simulation + public: uint64_t entity; + + /// \brief type identifier unique to each component type + public: uint64_t typeId; + + /// \brief component data type (Pose3d, Vector3d, double) + public: std::string type; + + /// \brief attributes of the components, + /// ex: x,y,z attributes in Vector3d type component + public: std::map data; + }; } using namespace ignition::gazebo; @@ -36,29 +52,30 @@ using namespace ignition::gui; ////////////////////////////////////////////////// PlotComponent::PlotComponent(std::string _type, uint64_t _entity, - uint64_t _typeId) + uint64_t _typeId) : + dataPtr(new PlotComponentPrivate) { - this->entity = _entity; - this->typeId = _typeId; - this->type = _type; + this->dataPtr->entity = _entity; + this->dataPtr->typeId = _typeId; + this->dataPtr->type = _type; if (_type == "Vector3d") { - this->data["x"] = new PlotData(); - this->data["y"] = new PlotData(); - this->data["z"] = new PlotData(); + this->dataPtr->data["x"] = new PlotData(); + this->dataPtr->data["y"] = new PlotData(); + this->dataPtr->data["z"] = new PlotData(); } else if (_type == "Pose3d") { - this->data["x"] = new PlotData(); - this->data["y"] = new PlotData(); - this->data["z"] = new PlotData(); - this->data["roll"] = new PlotData(); - this->data["pitch"] = new PlotData(); - this->data["yaw"] = new PlotData(); + this->dataPtr->data["x"] = new PlotData(); + this->dataPtr->data["y"] = new PlotData(); + this->dataPtr->data["z"] = new PlotData(); + this->dataPtr->data["roll"] = new PlotData(); + this->dataPtr->data["pitch"] = new PlotData(); + this->dataPtr->data["yaw"] = new PlotData(); } else if (_type == "double") - this->data["value"] = new PlotData(); + this->dataPtr->data["value"] = new PlotData(); else ignwarn << "Invalid Plot Component Type:" << _type << std::endl; } @@ -66,29 +83,29 @@ PlotComponent::PlotComponent(std::string _type, uint64_t _entity, ////////////////////////////////////////////////// void PlotComponent::RegisterChart(std::string _attribute, int _chart) { - if (this->data.count(_attribute) == 0) + if (this->dataPtr->data.count(_attribute) == 0) { ignwarn << "Invalid Plot Component Attribute" << std::endl; return; } - this->data[_attribute]->AddChart(_chart); + this->dataPtr->data[_attribute]->AddChart(_chart); } ////////////////////////////////////////////////// void PlotComponent::UnRegisterChart(std::string _attribute, int _chart) { - if (this->data.count(_attribute) == 0) + if (this->dataPtr->data.count(_attribute) == 0) { ignwarn << "Invalid Plot Component Attribute" << std::endl; return; } - this->data[_attribute]->RemoveChart(_chart); + this->dataPtr->data[_attribute]->RemoveChart(_chart); } ////////////////////////////////////////////////// bool PlotComponent::HasCharts() { - for (auto field : data) + for (auto field : this->dataPtr->data) if (field.second->ChartCount() > 0) return true; return false; @@ -98,26 +115,26 @@ bool PlotComponent::HasCharts() void PlotComponent::SetAttributeValue(std::string _attribute, const double &_value) { - if (this->data.count(_attribute) > 0) - this->data[_attribute]->SetValue(_value); + if (this->dataPtr->data.count(_attribute) > 0) + this->dataPtr->data[_attribute]->SetValue(_value); } ////////////////////////////////////////////////// std::map PlotComponent::Data() const { - return this->data; + return this->dataPtr->data; } ////////////////////////////////////////////////// uint64_t PlotComponent::Entity() { - return this->entity; + return this->dataPtr->entity; } ////////////////////////////////////////////////// uint64_t PlotComponent::TypeId() { - return this->typeId; + return this->dataPtr->typeId; } // ======================= Plotting ========================= diff --git a/src/gui/plugins/plotting/Plotting.hh b/src/gui/plugins/plotting/Plotting.hh index f9e262cfe7..cc8cec587c 100644 --- a/src/gui/plugins/plotting/Plotting.hh +++ b/src/gui/plugins/plotting/Plotting.hh @@ -59,6 +59,11 @@ #include "ignition/gazebo/components/World.hh" #include "ignition/gazebo/EntityComponentManager.hh" +namespace ignition { + +namespace gazebo { + +class PlotComponentPrivate; class PlotComponent { @@ -101,25 +106,10 @@ class PlotComponent /// \return component type ID public: uint64_t TypeId(); - /// \brief entity id in the simulation - private: uint64_t entity; - - /// \brief type identifier unique to each component type - private: uint64_t typeId; - - /// \brief component data type (Pose3d, Vector3d, double) - private: std::string type; - - /// \brief attributes of the components, - /// ex: x,y,z attributes in Vector3d type component - private: std::map data; + /// \brief dataPtr holds Abstraction data of PlottingPrivate + private: std::unique_ptr dataPtr; }; - -namespace ignition { - -namespace gazebo { - class PlottingPrivate; class Plotting : public ignition::gazebo::GuiSystem From 3201d8e54366c3d5bce2ab550551d8d2c7592e81 Mon Sep 17 00:00:00 2001 From: AmrElsersy Date: Sat, 22 Aug 2020 06:40:25 +0200 Subject: [PATCH 05/14] Plot over 60Hz in Update() function of _ecm Signed-off-by: AmrElsersy --- src/gui/plugins/plotting/Plotting.cc | 23 ++++------------------- src/gui/plugins/plotting/Plotting.hh | 3 --- 2 files changed, 4 insertions(+), 22 deletions(-) diff --git a/src/gui/plugins/plotting/Plotting.cc b/src/gui/plugins/plotting/Plotting.cc index 98a8c03e49..56afce7bae 100644 --- a/src/gui/plugins/plotting/Plotting.cc +++ b/src/gui/plugins/plotting/Plotting.cc @@ -26,8 +26,6 @@ namespace ignition::gazebo public: ignition::gui::PlottingInterface *plottingIface; public: std::map components; - - public: QTimer *timer; }; class PlotComponentPrivate @@ -142,13 +140,6 @@ Plotting ::Plotting () : GuiSystem() , dataPtr(new PlottingPrivate) { this->dataPtr->plottingIface = new ignition::gui::PlottingInterface(); - // Plot Timer - this->dataPtr->timer = new QTimer(); - auto timeout = this->dataPtr->plottingIface->Timeout(); - this->dataPtr->timer->setInterval(timeout); - connect(this->dataPtr->timer, SIGNAL(timeout()), this, SLOT(UpdateGui())); - this->dataPtr->timer->start(); - // PlottingInterface connecting connect(this->dataPtr->plottingIface, SIGNAL(ComponentSubscribe (uint64_t, uint64_t, std::string, std::string, int)), @@ -227,7 +218,7 @@ void Plotting::UnRegisterChartToComponent(uint64_t _entity, uint64_t _typeId, } ////////////////////////////////////////////////// -void Plotting ::Update(const ignition::gazebo::UpdateInfo &, +void Plotting ::Update(const ignition::gazebo::UpdateInfo &_info, ignition::gazebo::EntityComponentManager &_ecm) { for (auto component : this->dataPtr->components) @@ -340,27 +331,21 @@ void Plotting ::Update(const ignition::gazebo::UpdateInfo &, if (comp) this->SetData(component.first, comp->Data()); } - } -} -////////////////////////////////////////////////// -void Plotting ::UpdateGui() -{ - // Complexty O(registered attributes) - for (auto component : this->dataPtr->components) - { for (auto attribute : component.second->Data()) { for (auto chart : attribute.second->Charts()) { QString attributeName = QString::fromStdString( component.first + "," + attribute.first); - float x = this->dataPtr->plottingIface->Time(); double y = attribute.second->Value(); + double x = _info.simTime.count() * std::pow(10, -9); + emit this->dataPtr->plottingIface->plot(chart, attributeName, x, y); } } + } } diff --git a/src/gui/plugins/plotting/Plotting.hh b/src/gui/plugins/plotting/Plotting.hh index cc8cec587c..c5c5930e46 100644 --- a/src/gui/plugins/plotting/Plotting.hh +++ b/src/gui/plugins/plotting/Plotting.hh @@ -166,9 +166,6 @@ class Plotting : public ignition::gazebo::GuiSystem std::string _attribute, int _chart); - /// \brief send data to Qml to plot - public slots: void UpdateGui(); - /// \brief dataPtr holds Abstraction data of PlottingPrivate private: std::unique_ptr dataPtr; }; From dcc6cd07cd93934e10861a1bfe3a63f4f95808f2 Mon Sep 17 00:00:00 2001 From: AmrElsersy Date: Wed, 2 Sep 2020 14:23:52 +0200 Subject: [PATCH 06/14] Fix Style Signed-off-by: AmrElsersy --- src/gui/plugins/plotting/Plotting.cc | 79 +++++++++++++++++++-------- src/gui/plugins/plotting/Plotting.hh | 75 +++++++++---------------- src/gui/plugins/plotting/Plotting.qml | 23 +++++++- 3 files changed, 104 insertions(+), 73 deletions(-) diff --git a/src/gui/plugins/plotting/Plotting.cc b/src/gui/plugins/plotting/Plotting.cc index 56afce7bae..28ae303d66 100644 --- a/src/gui/plugins/plotting/Plotting.cc +++ b/src/gui/plugins/plotting/Plotting.cc @@ -17,6 +17,38 @@ #include #include "Plotting.hh" +#include + +#include "ignition/gazebo/components/Actor.hh" +#include "ignition/gazebo/components/AngularAcceleration.hh" +#include "ignition/gazebo/components/AngularVelocity.hh" +#include "ignition/gazebo/components/CastShadows.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/Level.hh" +#include "ignition/gazebo/components/Light.hh" +#include "ignition/gazebo/components/LinearAcceleration.hh" +#include "ignition/gazebo/components/LinearVelocity.hh" +#include "ignition/gazebo/components/LinearVelocitySeed.hh" +#include "ignition/gazebo/components/Link.hh" +#include "ignition/gazebo/components/MagneticField.hh" +#include "ignition/gazebo/components/Model.hh" +#include "ignition/gazebo/components/Name.hh" +#include "ignition/gazebo/components/ParentEntity.hh" +#include "ignition/gazebo/components/ParentLinkName.hh" +#include "ignition/gazebo/components/Performer.hh" +#include "ignition/gazebo/components/PerformerAffinity.hh" +#include "ignition/gazebo/components/Pose.hh" +#include "ignition/gazebo/components/PoseCmd.hh" +#include "ignition/gazebo/components/Sensor.hh" +#include "ignition/gazebo/components/Static.hh" +#include "ignition/gazebo/components/Visual.hh" +#include "ignition/gazebo/components/WindMode.hh" +#include "ignition/gazebo/components/World.hh" +#include "ignition/gazebo/EntityComponentManager.hh" namespace ignition::gazebo { @@ -25,16 +57,18 @@ namespace ignition::gazebo /// \brief Interface to communicate with Qml public: ignition::gui::PlottingInterface *plottingIface; + /// \brief registered components for plotting + /// map key: string contains EntityID + "," + ComponentID public: std::map components; }; class PlotComponentPrivate { /// \brief entity id in the simulation - public: uint64_t entity; + public: Entity entity; /// \brief type identifier unique to each component type - public: uint64_t typeId; + public: ComponentTypeId typeId; /// \brief component data type (Pose3d, Vector3d, double) public: std::string type; @@ -49,8 +83,9 @@ using namespace ignition::gazebo; using namespace ignition::gui; ////////////////////////////////////////////////// -PlotComponent::PlotComponent(std::string _type, uint64_t _entity, - uint64_t _typeId) : +PlotComponent::PlotComponent(std::string _type, + ignition::gazebo::Entity _entity, + ComponentTypeId _typeId) : dataPtr(new PlotComponentPrivate) { this->dataPtr->entity = _entity; @@ -124,13 +159,13 @@ std::map PlotComponent::Data() const } ////////////////////////////////////////////////// -uint64_t PlotComponent::Entity() +Entity PlotComponent::Entity() { return this->dataPtr->entity; } ////////////////////////////////////////////////// -uint64_t PlotComponent::TypeId() +ComponentTypeId PlotComponent::TypeId() { return this->dataPtr->typeId; } @@ -142,14 +177,14 @@ Plotting ::Plotting () : GuiSystem() , dataPtr(new PlottingPrivate) // PlottingInterface connecting connect(this->dataPtr->plottingIface, SIGNAL(ComponentSubscribe - (uint64_t, uint64_t, std::string, std::string, int)), + (Entity, ComponentTypeId, std::string, std::string, int)), this, SLOT(RegisterChartToComponent - (uint64_t, uint64_t, std::string, std::string, int))); + (Entity, ComponentTypeId, std::string, std::string, int))); connect(this->dataPtr->plottingIface, SIGNAL(ComponentUnSubscribe - (uint64_t, uint64_t, std::string, int)), + (Entity, ComponentTypeId, std::string, int)), this, SLOT(UnRegisterChartToComponent - (uint64_t, uint64_t, std::string, int))); + (Entity, ComponentTypeId, std::string, int))); } ////////////////////////////////////////////////// @@ -186,7 +221,7 @@ void Plotting::SetData(std::string _Id, const double &_value) ////////////////////////////////////////////////// -void Plotting::RegisterChartToComponent(uint64_t _entity, uint64_t _typeId, +void Plotting::RegisterChartToComponent(Entity _entity, ComponentTypeId _typeId, std::string _type, std::string _attribute, int _chart) @@ -194,27 +229,27 @@ void Plotting::RegisterChartToComponent(uint64_t _entity, uint64_t _typeId, std::string Id = std::to_string(_entity) + "," + std::to_string(_typeId); if (this->dataPtr->components.count(Id) == 0) - this->dataPtr->components[Id] = new PlotComponent(_type, - _entity, - _typeId); + this->dataPtr->components[Id] = new PlotComponent(_type, + _entity, + _typeId); this->dataPtr->components[Id]->RegisterChart(_attribute, _chart); } ////////////////////////////////////////////////// -void Plotting::UnRegisterChartToComponent(uint64_t _entity, uint64_t _typeId, +void Plotting::UnRegisterChartToComponent(Entity _entity, ComponentTypeId _typeId, std::string _attribute, int _chart) { - std::string Id = std::to_string(_entity) + "," + std::to_string(_typeId); - std::cout << "UnRegister " << Id << std::endl; + std::string id = std::to_string(_entity) + "," + std::to_string(_typeId); + igndbg << "UnRegister [" << id << "]" << std::endl; - if (this->dataPtr->components.count(Id) == 0) - return; + if (this->dataPtr->components.count(id) == 0) + return; - this->dataPtr->components[Id]->UnRegisterChart(_attribute, _chart); + this->dataPtr->components[id]->UnRegisterChart(_attribute, _chart); - if (!this->dataPtr->components[Id]->HasCharts()) - this->dataPtr->components.erase(Id); + if (!this->dataPtr->components[id]->HasCharts()) + this->dataPtr->components.erase(id); } ////////////////////////////////////////////////// diff --git a/src/gui/plugins/plotting/Plotting.hh b/src/gui/plugins/plotting/Plotting.hh index c5c5930e46..7fed034501 100644 --- a/src/gui/plugins/plotting/Plotting.hh +++ b/src/gui/plugins/plotting/Plotting.hh @@ -26,38 +26,6 @@ #include #include -#include - -#include "ignition/gazebo/components/Actor.hh" -#include "ignition/gazebo/components/AngularAcceleration.hh" -#include "ignition/gazebo/components/AngularVelocity.hh" -#include "ignition/gazebo/components/CastShadows.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/Level.hh" -#include "ignition/gazebo/components/Light.hh" -#include "ignition/gazebo/components/LinearAcceleration.hh" -#include "ignition/gazebo/components/LinearVelocity.hh" -#include "ignition/gazebo/components/LinearVelocitySeed.hh" -#include "ignition/gazebo/components/Link.hh" -#include "ignition/gazebo/components/MagneticField.hh" -#include "ignition/gazebo/components/Model.hh" -#include "ignition/gazebo/components/Name.hh" -#include "ignition/gazebo/components/ParentEntity.hh" -#include "ignition/gazebo/components/ParentLinkName.hh" -#include "ignition/gazebo/components/Performer.hh" -#include "ignition/gazebo/components/PerformerAffinity.hh" -#include "ignition/gazebo/components/Pose.hh" -#include "ignition/gazebo/components/PoseCmd.hh" -#include "ignition/gazebo/components/Sensor.hh" -#include "ignition/gazebo/components/Static.hh" -#include "ignition/gazebo/components/Visual.hh" -#include "ignition/gazebo/components/WindMode.hh" -#include "ignition/gazebo/components/World.hh" -#include "ignition/gazebo/EntityComponentManager.hh" namespace ignition { @@ -65,13 +33,17 @@ namespace gazebo { class PlotComponentPrivate; +/// \brief A container of the component data that keeps track of the registered +/// attributes and update their values and their registered charts class PlotComponent { /// \brief Constructor /// \param[in] _type component data type (Pose3d, Vector3d, double) /// \param [in] _entity entity id of that component /// \param [in] _typeId type identifier unique to each component type - public: PlotComponent(std::string _type, uint64_t _entity, uint64_t _typeId); + public: PlotComponent(std::string _type, + ignition::gazebo::Entity _entity, + ComponentTypeId _typeId); /// \brief Add a registered chart to the attribute /// \param[in] _attribute component attribute to add the chart to it @@ -99,12 +71,12 @@ class PlotComponent public: std::map Data() const; /// \brief Get the Component entity ID - /// \return entity ID - public: uint64_t Entity(); + /// \return Entity ID + public: ignition::gazebo::Entity Entity(); /// \brief Get the Component type ID /// \return component type ID - public: uint64_t TypeId(); + public: ComponentTypeId TypeId(); /// \brief dataPtr holds Abstraction data of PlottingPrivate private: std::unique_ptr dataPtr; @@ -112,6 +84,8 @@ class PlotComponent class PlottingPrivate; +/// \brief Physics data plotting handler that keeps track of the +/// registered components, update them and update the plot class Plotting : public ignition::gazebo::GuiSystem { Q_OBJECT @@ -121,7 +95,7 @@ class Plotting : public ignition::gazebo::GuiSystem /// \brief Destructor public: ~Plotting(); - /// \brief called every simulation iteration to access components + // Documentation inherited public: void Update(const ignition::gazebo::UpdateInfo &_info, ignition::gazebo::EntityComponentManager &_ecm) override; @@ -144,25 +118,26 @@ class Plotting : public ignition::gazebo::GuiSystem public: void SetData(std::string _Id, const double &_value); /// \brief Add a chart to a specefic component attribute - /// \param [in] _entity entity id in the simulation - /// \param [in] _typeId type identifier unique to each component type - /// \param [in] _attribute component attribute to add the chart to it - /// ex: x attribute in Pose3d Component + /// \param[in] _entity entity id in the simulation + /// \param[in] _typeId type identifier unique to each component type + /// \param[in] _type Component Datatype could be ("Pose3d","Vector3d","double") + /// \param[in] _attribute component attribute to add the chart to it + /// ex: x attribute in Pose3d Component will be "x" /// \param [in] _chart chart ID to be registered - public slots: void RegisterChartToComponent(uint64_t _entity, - uint64_t _typeId, + public slots: void RegisterChartToComponent(Entity _entity, + ComponentTypeId _typeId, std::string _type, std::string _attribute, int _chart); /// \brief Remove a chart from a specefic component attribute - /// \param [in] _entity entity id in the simulation - /// \param [in] _typeId type identifier unique to each component type - /// \param [in] _attribute component attribute to remove the chart from it - /// ex: x attribute in Pose3d Component - /// \param [in] _chart chart ID to be unregistered - public slots: void UnRegisterChartToComponent(uint64_t _entity, - uint64_t _typeId, + /// \param[in] _entity entity id in the simulation + /// \param[in] _typeId type identifier unique to each component type + /// \param[in] _attribute component attribute to remove the chart from it + /// ex: x attribute in Pose3d Component will be "x" + /// \param[in] _chart chart ID to be unregistered + public slots: void UnRegisterChartToComponent(Entity _entity, + ComponentTypeId _typeId, std::string _attribute, int _chart); diff --git a/src/gui/plugins/plotting/Plotting.qml b/src/gui/plugins/plotting/Plotting.qml index 913d9f49ff..cfafbba101 100644 --- a/src/gui/plugins/plotting/Plotting.qml +++ b/src/gui/plugins/plotting/Plotting.qml @@ -1,5 +1,26 @@ +/* + * Copyright (C) 2020 Open Source Robotics Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * +*/ +import QtQuick 2.0 +import QtQuick.Controls 1.4 +import QtQuick.Layouts 1.3 + import "qrc:/qml" PlottingInterface { - + Layout.minimumWidth: 600 + Layout.minimumHeight: 600 } From e01c00c8030119269b2e26270e2e0c001bb0adb1 Mon Sep 17 00:00:00 2001 From: AmrElsersy Date: Wed, 2 Sep 2020 15:25:07 +0200 Subject: [PATCH 07/14] using typeName instead of typeId Signed-off-by: AmrElsersy --- .../plugins/component_inspector/Pose3d.qml | 286 +++++++++--------- .../plugins/component_inspector/Vector3d.qml | 160 +++++----- 2 files changed, 225 insertions(+), 221 deletions(-) diff --git a/src/gui/plugins/component_inspector/Pose3d.qml b/src/gui/plugins/component_inspector/Pose3d.qml index b1a3534cfe..1252d9fad4 100644 --- a/src/gui/plugins/component_inspector/Pose3d.qml +++ b/src/gui/plugins/component_inspector/Pose3d.qml @@ -189,59 +189,61 @@ Rectangle { // Left spacer Item { Layout.rowSpan: 3 - width: margin + width: margin + indentation } Component { - id: plotIcon - Image { - property string componentInfo: "" - source: "plottable_icon.svg" - anchors.top: parent.top - anchors.left: parent.left - - Drag.mimeData: { "text/plain" : (model === null) ? "" : - "Component," + model.entity + "," + model.typeId + "," + model.dataType + "," + componentInfo} - Drag.dragType: Drag.Automatic - Drag.supportedActions : Qt.CopyAction - Drag.active: dragMouse.drag.active - // a point to drag from - Drag.hotSpot.x: 0 - Drag.hotSpot.y: y - MouseArea { - id: dragMouse - anchors.fill: parent - drag.target: (model === null) ? null : parent - onPressed: parent.grabToImage(function(result) {parent.Drag.imageSource = result.url }) - onReleased: parent.Drag.drop(); - cursorShape: Qt.DragCopyCursor - } + id: plotIcon + Image { + property string componentInfo: "" + source: "plottable_icon.svg" + anchors.top: parent.top + anchors.left: parent.left + + Drag.mimeData: { "text/plain" : (model === null) ? "" : + "Component," + model.entity + "," + model.typeId + "," + + model.dataType + "," + componentInfo + "," + model.shortName + } + Drag.dragType: Drag.Automatic + Drag.supportedActions : Qt.CopyAction + Drag.active: dragMouse.drag.active + // a point to drag from + Drag.hotSpot.x: 0 + Drag.hotSpot.y: y + MouseArea { + id: dragMouse + anchors.fill: parent + drag.target: (model === null) ? null : parent + onPressed: parent.grabToImage(function(result) {parent.Drag.imageSource = result.url }) + onReleased: parent.Drag.drop(); + cursorShape: Qt.DragCopyCursor } } + } Rectangle { - color: "transparent" - height: 40 - Layout.preferredWidth: xText.width + indentation*3 - Loader { - id: loaderX - width: iconWidth - height: iconHeight - y:10 - sourceComponent: plotIcon - } - Component.onCompleted: loaderX.item.componentInfo = "x" - - Text { - id : xText - text: ' X (m)' - leftPadding: 5 - color: Material.theme == Material.Light ? "#444444" : "#bbbbbb" - font.pointSize: 12 - anchors.centerIn: parent - } - } + color: "transparent" + height: 40 + Layout.preferredWidth: xText.width + indentation*3 + Loader { + id: loaderX + width: iconWidth + height: iconHeight + y:10 + sourceComponent: plotIcon + } + Component.onCompleted: loaderX.item.componentInfo = "x" + + Text { + id : xText + text: ' X (m)' + leftPadding: 5 + color: Material.theme == Material.Light ? "#444444" : "#bbbbbb" + font.pointSize: 12 + anchors.centerIn: parent + } + } Item { Layout.fillWidth: true @@ -258,26 +260,26 @@ Rectangle { } Rectangle { - color: "transparent" - height: 40 - Layout.preferredWidth: rollText.width + indentation*3 - Loader { - id: loaderRoll - width: iconWidth - height: iconHeight - y:10 - sourceComponent: plotIcon - } - Component.onCompleted: loaderRoll.item.componentInfo = "roll" - - Text { - id: rollText - text: ' Roll (rad)' - leftPadding: 5 - color: Material.theme == Material.Light ? "#444444" : "#bbbbbb" - font.pointSize: 12 - anchors.centerIn: parent - } + color: "transparent" + height: 40 + Layout.preferredWidth: rollText.width + indentation*3 + Loader { + id: loaderRoll + width: iconWidth + height: iconHeight + y:10 + sourceComponent: plotIcon + } + Component.onCompleted: loaderRoll.item.componentInfo = "roll" + + Text { + id: rollText + text: ' Roll (rad)' + leftPadding: 5 + color: Material.theme == Material.Light ? "#444444" : "#bbbbbb" + font.pointSize: 12 + anchors.centerIn: parent + } } Item { @@ -297,30 +299,30 @@ Rectangle { // Right spacer Item { Layout.rowSpan: 3 - width: margin + width: margin + indentation } Rectangle { - color: "transparent" - height: 40 - Layout.preferredWidth: yText.width + indentation*3 - Loader { - id: loaderY - width: iconWidth - height: iconHeight - y:10 - sourceComponent: plotIcon - } - Component.onCompleted: loaderY.item.componentInfo = "y" - Text { - id: yText - text: ' Y (m)' - leftPadding: 5 - color: Material.theme == Material.Light ? "#444444" : "#bbbbbb" - font.pointSize: 12 - anchors.centerIn: parent - } + color: "transparent" + height: 40 + Layout.preferredWidth: yText.width + indentation*3 + Loader { + id: loaderY + width: iconWidth + height: iconHeight + y:10 + sourceComponent: plotIcon + } + Component.onCompleted: loaderY.item.componentInfo = "y" + Text { + id: yText + text: ' Y (m)' + leftPadding: 5 + color: Material.theme == Material.Light ? "#444444" : "#bbbbbb" + font.pointSize: 12 + anchors.centerIn: parent + } } Item { @@ -338,25 +340,25 @@ Rectangle { } Rectangle { - color: "transparent" - height: 40 - Layout.preferredWidth: pitchText.width + indentation*3 - Loader { - id: loaderPitch - width: iconWidth - height: iconHeight - y:10 - sourceComponent: plotIcon - } - Component.onCompleted: loaderPitch.item.componentInfo = "pitch"; - Text { - id: pitchText - text: ' Pitch (rad)' - leftPadding: 5 - color: Material.theme == Material.Light ? "#444444" : "#bbbbbb" - font.pointSize: 12 - anchors.centerIn: parent - } + color: "transparent" + height: 40 + Layout.preferredWidth: pitchText.width + indentation*3 + Loader { + id: loaderPitch + width: iconWidth + height: iconHeight + y:10 + sourceComponent: plotIcon + } + Component.onCompleted: loaderPitch.item.componentInfo = "pitch"; + Text { + id: pitchText + text: ' Pitch (rad)' + leftPadding: 5 + color: Material.theme == Material.Light ? "#444444" : "#bbbbbb" + font.pointSize: 12 + anchors.centerIn: parent + } } Item { @@ -374,25 +376,25 @@ Rectangle { } Rectangle { - color: "transparent" - height: 40 - Layout.preferredWidth: zText.width + indentation*3 - Loader { - id: loaderZ - width: iconWidth - height: iconHeight - y:10 - sourceComponent: plotIcon - } - Component.onCompleted: loaderZ.item.componentInfo = "z"; - Text { - id: zText - text: ' Z (m)' - leftPadding: 5 - color: Material.theme == Material.Light ? "#444444" : "#bbbbbb" - font.pointSize: 12 - anchors.centerIn: parent - } + color: "transparent" + height: 40 + Layout.preferredWidth: zText.width + indentation*3 + Loader { + id: loaderZ + width: iconWidth + height: iconHeight + y:10 + sourceComponent: plotIcon + } + Component.onCompleted: loaderZ.item.componentInfo = "z"; + Text { + id: zText + text: ' Z (m)' + leftPadding: 5 + color: Material.theme == Material.Light ? "#444444" : "#bbbbbb" + font.pointSize: 12 + anchors.centerIn: parent + } } Item { @@ -410,25 +412,25 @@ Rectangle { } Rectangle { - color: "transparent" - height: 40 - Layout.preferredWidth: yawText.width + indentation*3 - Loader { - id: loaderYaw - width: iconWidth - height: iconHeight - y:10 - sourceComponent: plotIcon - } - Component.onCompleted: loaderYaw.item.componentInfo = "yaw"; - Text { - id: yawText - text: ' Yaw (rad)' - leftPadding: 5 - color: Material.theme == Material.Light ? "#444444" : "#bbbbbb" - font.pointSize: 12 - anchors.centerIn: parent - } + color: "transparent" + height: 40 + Layout.preferredWidth: yawText.width + indentation*3 + Loader { + id: loaderYaw + width: iconWidth + height: iconHeight + y:10 + sourceComponent: plotIcon + } + Component.onCompleted: loaderYaw.item.componentInfo = "yaw"; + Text { + id: yawText + text: ' Yaw (rad)' + leftPadding: 5 + color: Material.theme == Material.Light ? "#444444" : "#bbbbbb" + font.pointSize: 12 + anchors.centerIn: parent + } } Item { diff --git a/src/gui/plugins/component_inspector/Vector3d.qml b/src/gui/plugins/component_inspector/Vector3d.qml index 66088c08d2..7b72068728 100644 --- a/src/gui/plugins/component_inspector/Vector3d.qml +++ b/src/gui/plugins/component_inspector/Vector3d.qml @@ -79,30 +79,32 @@ Rectangle { } } Component { - id: plotIcon - Image { - property string componentInfo: "" - source: "plottable_icon.svg" - anchors.top: parent.top - anchors.left: parent.left + id: plotIcon + Image { + property string componentInfo: "" + source: "plottable_icon.svg" + anchors.top: parent.top + anchors.left: parent.left - Drag.mimeData: { "text/plain" : (model === null) ? "" : - "Component," + model.entity + "," + model.typeId + "," + model.dataType + "," + componentInfo} - Drag.dragType: Drag.Automatic - Drag.supportedActions : Qt.CopyAction - Drag.active: dragMouse.drag.active - // a point to drag from - Drag.hotSpot.x: 0 - Drag.hotSpot.y: y - MouseArea { - id: dragMouse - anchors.fill: parent - drag.target: (model === null) ? null : parent - onPressed: parent.grabToImage(function(result) {parent.Drag.imageSource = result.url }) - onReleased: parent.Drag.drop(); - cursorShape: Qt.DragCopyCursor - } + Drag.mimeData: { "text/plain" : (model === null) ? "" : + "Component," + model.entity + "," + model.typeId + "," + + model.dataType + "," + componentInfo + "," + model.shortName } + Drag.dragType: Drag.Automatic + Drag.supportedActions : Qt.CopyAction + Drag.active: dragMouse.drag.active + // a point to drag from + Drag.hotSpot.x: 0 + Drag.hotSpot.y: y + MouseArea { + id: dragMouse + anchors.fill: parent + drag.target: (model === null) ? null : parent + onPressed: parent.grabToImage(function(result) {parent.Drag.imageSource = result.url }) + onReleased: parent.Drag.drop(); + cursorShape: Qt.DragCopyCursor + } + } } Column { @@ -176,30 +178,30 @@ Rectangle { // Left spacer Item { Layout.rowSpan: 3 - width: indentation + margin + width: margin + indentation } Rectangle { - color: "transparent" - height: 40 - Layout.preferredWidth: xText.width + indentation*3 - Loader { - id: loaderX - width: iconWidth - height: iconHeight - y:10 - sourceComponent: plotIcon - } - Component.onCompleted: loaderX.item.componentInfo = "x" + color: "transparent" + height: 40 + Layout.preferredWidth: xText.width + indentation*3 + Loader { + id: loaderX + width: iconWidth + height: iconHeight + y:10 + sourceComponent: plotIcon + } + Component.onCompleted: loaderX.item.componentInfo = "x" - Text { - id: xText - text: ' X (' + unit + ')' - leftPadding: 5 - color: Material.theme == Material.Light ? "#444444" : "#bbbbbb" - font.pointSize: 12 - anchors.centerIn: parent - } + Text { + id: xText + text: ' X (' + unit + ')' + leftPadding: 5 + color: Material.theme == Material.Light ? "#444444" : "#bbbbbb" + font.pointSize: 12 + anchors.centerIn: parent + } } Item { Layout.fillWidth: true @@ -214,29 +216,29 @@ Rectangle { // Right spacer Item { Layout.rowSpan: 3 - width: margin + width: margin + indentation } Rectangle { - color: "transparent" - height: 40 - Layout.preferredWidth: xText.width + indentation*3 - Loader { - id: loaderY - width: iconWidth - height: iconHeight - y:10 - sourceComponent: plotIcon - } - Component.onCompleted: loaderY.item.componentInfo = "y" + color: "transparent" + height: 40 + Layout.preferredWidth: xText.width + indentation*3 + Loader { + id: loaderY + width: iconWidth + height: iconHeight + y:10 + sourceComponent: plotIcon + } + Component.onCompleted: loaderY.item.componentInfo = "y" - Text { - text: ' Y (' + unit + ')' - leftPadding: 5 - color: Material.theme == Material.Light ? "#444444" : "#bbbbbb" - font.pointSize: 12 - anchors.centerIn: parent - } + Text { + text: ' Y (' + unit + ')' + leftPadding: 5 + color: Material.theme == Material.Light ? "#444444" : "#bbbbbb" + font.pointSize: 12 + anchors.centerIn: parent + } } Item { @@ -250,25 +252,25 @@ Rectangle { } Rectangle { - color: "transparent" - height: 40 - Layout.preferredWidth: xText.width + indentation*3 - Loader { - id: loaderZ - width: iconWidth - height: iconHeight - y:10 - sourceComponent: plotIcon - } - Component.onCompleted: loaderZ.item.componentInfo = "z" + color: "transparent" + height: 40 + Layout.preferredWidth: xText.width + indentation*3 + Loader { + id: loaderZ + width: iconWidth + height: iconHeight + y:10 + sourceComponent: plotIcon + } + Component.onCompleted: loaderZ.item.componentInfo = "z" - Text { - text: 'Z (' + unit + ')' - leftPadding: 5 - color: Material.theme == Material.Light ? "#444444" : "#bbbbbb" - font.pointSize: 12 - anchors.centerIn: parent - } + Text { + text: 'Z (' + unit + ')' + leftPadding: 5 + color: Material.theme == Material.Light ? "#444444" : "#bbbbbb" + font.pointSize: 12 + anchors.centerIn: parent + } } Item { From a0833f6b4689e64fb0976c15e02e8f88bf4bfea8 Mon Sep 17 00:00:00 2001 From: AmrElsersy Date: Wed, 2 Sep 2020 18:25:32 +0200 Subject: [PATCH 08/14] Fix signals Signed-off-by: AmrElsersy --- src/gui/plugins/plotting/Plotting.cc | 14 +++++++------- src/gui/plugins/plotting/Plotting.hh | 8 ++++---- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/gui/plugins/plotting/Plotting.cc b/src/gui/plugins/plotting/Plotting.cc index 28ae303d66..5715521c7d 100644 --- a/src/gui/plugins/plotting/Plotting.cc +++ b/src/gui/plugins/plotting/Plotting.cc @@ -1,4 +1,4 @@ -/* + /* * Copyright (C) 2020 Open Source Robotics Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -177,14 +177,14 @@ Plotting ::Plotting () : GuiSystem() , dataPtr(new PlottingPrivate) // PlottingInterface connecting connect(this->dataPtr->plottingIface, SIGNAL(ComponentSubscribe - (Entity, ComponentTypeId, std::string, std::string, int)), + (uint64_t, uint64_t, std::string, std::string, int)), this, SLOT(RegisterChartToComponent - (Entity, ComponentTypeId, std::string, std::string, int))); + (uint64_t, uint64_t, std::string, std::string, int))); connect(this->dataPtr->plottingIface, SIGNAL(ComponentUnSubscribe - (Entity, ComponentTypeId, std::string, int)), + (uint64_t, uint64_t, std::string, int)), this, SLOT(UnRegisterChartToComponent - (Entity, ComponentTypeId, std::string, int))); + (uint64_t, uint64_t, std::string, int))); } ////////////////////////////////////////////////// @@ -221,7 +221,7 @@ void Plotting::SetData(std::string _Id, const double &_value) ////////////////////////////////////////////////// -void Plotting::RegisterChartToComponent(Entity _entity, ComponentTypeId _typeId, +void Plotting::RegisterChartToComponent(uint64_t _entity, uint64_t _typeId, std::string _type, std::string _attribute, int _chart) @@ -237,7 +237,7 @@ void Plotting::RegisterChartToComponent(Entity _entity, ComponentTypeId _typeId, } ////////////////////////////////////////////////// -void Plotting::UnRegisterChartToComponent(Entity _entity, ComponentTypeId _typeId, +void Plotting::UnRegisterChartToComponent(uint64_t _entity, uint64_t _typeId, std::string _attribute, int _chart) { std::string id = std::to_string(_entity) + "," + std::to_string(_typeId); diff --git a/src/gui/plugins/plotting/Plotting.hh b/src/gui/plugins/plotting/Plotting.hh index 7fed034501..323dc3f8a4 100644 --- a/src/gui/plugins/plotting/Plotting.hh +++ b/src/gui/plugins/plotting/Plotting.hh @@ -124,8 +124,8 @@ class Plotting : public ignition::gazebo::GuiSystem /// \param[in] _attribute component attribute to add the chart to it /// ex: x attribute in Pose3d Component will be "x" /// \param [in] _chart chart ID to be registered - public slots: void RegisterChartToComponent(Entity _entity, - ComponentTypeId _typeId, + public slots: void RegisterChartToComponent(uint64_t _entity, + uint64_t _typeId, std::string _type, std::string _attribute, int _chart); @@ -136,8 +136,8 @@ class Plotting : public ignition::gazebo::GuiSystem /// \param[in] _attribute component attribute to remove the chart from it /// ex: x attribute in Pose3d Component will be "x" /// \param[in] _chart chart ID to be unregistered - public slots: void UnRegisterChartToComponent(Entity _entity, - ComponentTypeId _typeId, + public slots: void UnRegisterChartToComponent(uint64_t _entity, + uint64_t _typeId, std::string _attribute, int _chart); From 6057d30d9b21cab550590c40c4780ba1ee899e5c Mon Sep 17 00:00:00 2001 From: AmrElsersy Date: Thu, 3 Sep 2020 05:32:15 +0200 Subject: [PATCH 09/14] Convert typeId to typeName for export Signed-off-by: AmrElsersy --- src/gui/plugins/plotting/Plotting.cc | 21 ++++++++++++++++++++- src/gui/plugins/plotting/Plotting.hh | 5 +++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/gui/plugins/plotting/Plotting.cc b/src/gui/plugins/plotting/Plotting.cc index 5715521c7d..f61435d226 100644 --- a/src/gui/plugins/plotting/Plotting.cc +++ b/src/gui/plugins/plotting/Plotting.cc @@ -60,6 +60,9 @@ namespace ignition::gazebo /// \brief registered components for plotting /// map key: string contains EntityID + "," + ComponentID public: std::map components; + + /// \brief Factory to convert typeIDs to names + public: components::Factory *factory; }; class PlotComponentPrivate @@ -174,6 +177,7 @@ ComponentTypeId PlotComponent::TypeId() Plotting ::Plotting () : GuiSystem() , dataPtr(new PlottingPrivate) { this->dataPtr->plottingIface = new ignition::gui::PlottingInterface(); + this->dataPtr->factory = new components::Factory; // PlottingInterface connecting connect(this->dataPtr->plottingIface, SIGNAL(ComponentSubscribe @@ -185,6 +189,9 @@ Plotting ::Plotting () : GuiSystem() , dataPtr(new PlottingPrivate) (uint64_t, uint64_t, std::string, int)), this, SLOT(UnRegisterChartToComponent (uint64_t, uint64_t, std::string, int))); + + connect(this->dataPtr->plottingIface, SIGNAL(ComponentName(uint64_t)), + this, SLOT(ComponentName(uint64_t))); } ////////////////////////////////////////////////// @@ -249,7 +256,19 @@ void Plotting::UnRegisterChartToComponent(uint64_t _entity, uint64_t _typeId, this->dataPtr->components[id]->UnRegisterChart(_attribute, _chart); if (!this->dataPtr->components[id]->HasCharts()) - this->dataPtr->components.erase(id); + this->dataPtr->components.erase(id); +} + +////////////////////////////////////////////////// +std::string Plotting::ComponentName(const uint64_t &_typeId) +{ + std::string name = this->dataPtr->factory->Name(_typeId); + + // 22 is size of "ign.gazebo.components." + if (name.size() > 22) + name.erase(0,22); + + return name; } ////////////////////////////////////////////////// diff --git a/src/gui/plugins/plotting/Plotting.hh b/src/gui/plugins/plotting/Plotting.hh index 323dc3f8a4..c1116e6a5f 100644 --- a/src/gui/plugins/plotting/Plotting.hh +++ b/src/gui/plugins/plotting/Plotting.hh @@ -141,6 +141,11 @@ class Plotting : public ignition::gazebo::GuiSystem std::string _attribute, int _chart); + /// \brief Get Component Name based on its type Id + /// \param[in] _typeId type Id of the component + /// \return Component name + public slots: std::string ComponentName(const uint64_t &_typeId); + /// \brief dataPtr holds Abstraction data of PlottingPrivate private: std::unique_ptr dataPtr; }; From 431aaf4ba8dc278982953c931ae5f2b0d7adf492 Mon Sep 17 00:00:00 2001 From: AmrElsersy Date: Fri, 4 Sep 2020 02:00:03 +0200 Subject: [PATCH 10/14] Factory singleton Signed-off-by: AmrElsersy --- src/gui/plugins/plotting/Plotting.cc | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/gui/plugins/plotting/Plotting.cc b/src/gui/plugins/plotting/Plotting.cc index f61435d226..da8fbbf909 100644 --- a/src/gui/plugins/plotting/Plotting.cc +++ b/src/gui/plugins/plotting/Plotting.cc @@ -60,9 +60,6 @@ namespace ignition::gazebo /// \brief registered components for plotting /// map key: string contains EntityID + "," + ComponentID public: std::map components; - - /// \brief Factory to convert typeIDs to names - public: components::Factory *factory; }; class PlotComponentPrivate @@ -177,7 +174,6 @@ ComponentTypeId PlotComponent::TypeId() Plotting ::Plotting () : GuiSystem() , dataPtr(new PlottingPrivate) { this->dataPtr->plottingIface = new ignition::gui::PlottingInterface(); - this->dataPtr->factory = new components::Factory; // PlottingInterface connecting connect(this->dataPtr->plottingIface, SIGNAL(ComponentSubscribe @@ -262,7 +258,7 @@ void Plotting::UnRegisterChartToComponent(uint64_t _entity, uint64_t _typeId, ////////////////////////////////////////////////// std::string Plotting::ComponentName(const uint64_t &_typeId) { - std::string name = this->dataPtr->factory->Name(_typeId); + std::string name = components::Factory::Instance()->Name(_typeId); // 22 is size of "ign.gazebo.components." if (name.size() > 22) From 580f0ceb2f9daf5c75a05bbba28faf995c4e4b4c Mon Sep 17 00:00:00 2001 From: AmrElsersy Date: Tue, 15 Sep 2020 14:07:33 +0200 Subject: [PATCH 11/14] fix deleting allocated data Signed-off-by: AmrElsersy --- .../plugins/component_inspector/Vector3d.qml | 2 +- src/gui/plugins/plotting/Plotting.cc | 37 +++++++++---------- src/gui/plugins/plotting/Plotting.hh | 11 ++++-- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/gui/plugins/component_inspector/Vector3d.qml b/src/gui/plugins/component_inspector/Vector3d.qml index 7b72068728..c9227b4de2 100644 --- a/src/gui/plugins/component_inspector/Vector3d.qml +++ b/src/gui/plugins/component_inspector/Vector3d.qml @@ -265,7 +265,7 @@ Rectangle { Component.onCompleted: loaderZ.item.componentInfo = "z" Text { - text: 'Z (' + unit + ')' + text: ' Z (' + unit + ')' leftPadding: 5 color: Material.theme == Material.Light ? "#444444" : "#bbbbbb" font.pointSize: 12 diff --git a/src/gui/plugins/plotting/Plotting.cc b/src/gui/plugins/plotting/Plotting.cc index da8fbbf909..3815dce884 100644 --- a/src/gui/plugins/plotting/Plotting.cc +++ b/src/gui/plugins/plotting/Plotting.cc @@ -19,33 +19,19 @@ #include "Plotting.hh" #include -#include "ignition/gazebo/components/Actor.hh" #include "ignition/gazebo/components/AngularAcceleration.hh" #include "ignition/gazebo/components/AngularVelocity.hh" #include "ignition/gazebo/components/CastShadows.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/Level.hh" -#include "ignition/gazebo/components/Light.hh" #include "ignition/gazebo/components/LinearAcceleration.hh" #include "ignition/gazebo/components/LinearVelocity.hh" #include "ignition/gazebo/components/LinearVelocitySeed.hh" -#include "ignition/gazebo/components/Link.hh" #include "ignition/gazebo/components/MagneticField.hh" -#include "ignition/gazebo/components/Model.hh" -#include "ignition/gazebo/components/Name.hh" #include "ignition/gazebo/components/ParentEntity.hh" -#include "ignition/gazebo/components/ParentLinkName.hh" -#include "ignition/gazebo/components/Performer.hh" -#include "ignition/gazebo/components/PerformerAffinity.hh" #include "ignition/gazebo/components/Pose.hh" #include "ignition/gazebo/components/PoseCmd.hh" -#include "ignition/gazebo/components/Sensor.hh" #include "ignition/gazebo/components/Static.hh" -#include "ignition/gazebo/components/Visual.hh" #include "ignition/gazebo/components/WindMode.hh" #include "ignition/gazebo/components/World.hh" #include "ignition/gazebo/EntityComponentManager.hh" @@ -110,7 +96,14 @@ PlotComponent::PlotComponent(std::string _type, else if (_type == "double") this->dataPtr->data["value"] = new PlotData(); else - ignwarn << "Invalid Plot Component Type:" << _type << std::endl; + ignwarn << "Invalid Plot Component Type:" << _type << std::endl; +} + +////////////////////////////////////////////////// +PlotComponent::~PlotComponent() +{ + for (auto plotData : this->dataPtr->data) + delete plotData.second; } ////////////////////////////////////////////////// @@ -170,7 +163,7 @@ ComponentTypeId PlotComponent::TypeId() return this->dataPtr->typeId; } -// ======================= Plotting ========================= +////////////////////////////////////////////////// Plotting ::Plotting () : GuiSystem() , dataPtr(new PlottingPrivate) { this->dataPtr->plottingIface = new ignition::gui::PlottingInterface(); @@ -194,6 +187,9 @@ Plotting ::Plotting () : GuiSystem() , dataPtr(new PlottingPrivate) Plotting ::~Plotting() { delete this->dataPtr->plottingIface; + + for (auto component : this->dataPtr->components) + delete component.second; } ////////////////////////////////////////////////// @@ -240,7 +236,7 @@ void Plotting::RegisterChartToComponent(uint64_t _entity, uint64_t _typeId, } ////////////////////////////////////////////////// -void Plotting::UnRegisterChartToComponent(uint64_t _entity, uint64_t _typeId, +void Plotting::UnRegisterChartFromComponent(uint64_t _entity, uint64_t _typeId, std::string _attribute, int _chart) { std::string id = std::to_string(_entity) + "," + std::to_string(_typeId); @@ -260,9 +256,10 @@ std::string Plotting::ComponentName(const uint64_t &_typeId) { std::string name = components::Factory::Instance()->Name(_typeId); - // 22 is size of "ign.gazebo.components." - if (name.size() > 22) - name.erase(0,22); + auto pos = name.find("ign.gazebo.components."); + + if (pos != std::string::npos) + name.erase(pos, 22); return name; } diff --git a/src/gui/plugins/plotting/Plotting.hh b/src/gui/plugins/plotting/Plotting.hh index c1116e6a5f..afe52b871f 100644 --- a/src/gui/plugins/plotting/Plotting.hh +++ b/src/gui/plugins/plotting/Plotting.hh @@ -45,6 +45,9 @@ class PlotComponent ignition::gazebo::Entity _entity, ComponentTypeId _typeId); + /// \brief Destructor + public: ~PlotComponent(); + /// \brief Add a registered chart to the attribute /// \param[in] _attribute component attribute to add the chart to it /// \param[in] _chart chart ID to be added to the attribute @@ -136,10 +139,10 @@ class Plotting : public ignition::gazebo::GuiSystem /// \param[in] _attribute component attribute to remove the chart from it /// ex: x attribute in Pose3d Component will be "x" /// \param[in] _chart chart ID to be unregistered - public slots: void UnRegisterChartToComponent(uint64_t _entity, - uint64_t _typeId, - std::string _attribute, - int _chart); + public slots: void UnRegisterChartFromComponent(uint64_t _entity, + uint64_t _typeId, + std::string _attribute, + int _chart); /// \brief Get Component Name based on its type Id /// \param[in] _typeId type Id of the component From 125b79b5d6bb308831a3a6b01d1a5f28a06fd634 Mon Sep 17 00:00:00 2001 From: AmrElsersy Date: Tue, 15 Sep 2020 14:24:25 +0200 Subject: [PATCH 12/14] fix style Signed-off-by: AmrElsersy --- src/gui/plugins/plotting/Plotting.cc | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/gui/plugins/plotting/Plotting.cc b/src/gui/plugins/plotting/Plotting.cc index 3815dce884..d3d3807387 100644 --- a/src/gui/plugins/plotting/Plotting.cc +++ b/src/gui/plugins/plotting/Plotting.cc @@ -94,16 +94,16 @@ PlotComponent::PlotComponent(std::string _type, this->dataPtr->data["yaw"] = new PlotData(); } else if (_type == "double") - this->dataPtr->data["value"] = new PlotData(); + this->dataPtr->data["value"] = new PlotData(); else - ignwarn << "Invalid Plot Component Type:" << _type << std::endl; + ignwarn << "Invalid Plot Component Type:" << _type << std::endl; } ////////////////////////////////////////////////// PlotComponent::~PlotComponent() { for (auto plotData : this->dataPtr->data) - delete plotData.second; + delete plotData.second; } ////////////////////////////////////////////////// @@ -133,7 +133,7 @@ bool PlotComponent::HasCharts() { for (auto field : this->dataPtr->data) if (field.second->ChartCount() > 0) - return true; + return true; return false; } @@ -189,7 +189,7 @@ Plotting ::~Plotting() delete this->dataPtr->plottingIface; for (auto component : this->dataPtr->components) - delete component.second; + delete component.second; } ////////////////////////////////////////////////// @@ -237,7 +237,7 @@ void Plotting::RegisterChartToComponent(uint64_t _entity, uint64_t _typeId, ////////////////////////////////////////////////// void Plotting::UnRegisterChartFromComponent(uint64_t _entity, uint64_t _typeId, - std::string _attribute, int _chart) + std::string _attribute, int _chart) { std::string id = std::to_string(_entity) + "," + std::to_string(_typeId); igndbg << "UnRegister [" << id << "]" << std::endl; @@ -259,7 +259,7 @@ std::string Plotting::ComponentName(const uint64_t &_typeId) auto pos = name.find("ign.gazebo.components."); if (pos != std::string::npos) - name.erase(pos, 22); + name.erase(pos, 22); return name; } From 8b10c670d428fd3442fb3bf7830547609024340c Mon Sep 17 00:00:00 2001 From: AmrElsersy Date: Thu, 17 Sep 2020 13:40:25 +0200 Subject: [PATCH 13/14] used shared_ptr for PlotComponent & PlotData Signed-off-by: AmrElsersy --- src/gui/plugins/plotting/Plotting.cc | 46 +++++++++++++--------------- src/gui/plugins/plotting/Plotting.hh | 8 +++-- 2 files changed, 26 insertions(+), 28 deletions(-) diff --git a/src/gui/plugins/plotting/Plotting.cc b/src/gui/plugins/plotting/Plotting.cc index d3d3807387..70542b5cba 100644 --- a/src/gui/plugins/plotting/Plotting.cc +++ b/src/gui/plugins/plotting/Plotting.cc @@ -14,11 +14,10 @@ * limitations under the License. * */ -#include #include "Plotting.hh" -#include +#include #include "ignition/gazebo/components/AngularAcceleration.hh" #include "ignition/gazebo/components/AngularVelocity.hh" #include "ignition/gazebo/components/CastShadows.hh" @@ -45,7 +44,8 @@ namespace ignition::gazebo /// \brief registered components for plotting /// map key: string contains EntityID + "," + ComponentID - public: std::map components; + public: std::map> components; }; class PlotComponentPrivate @@ -61,7 +61,8 @@ namespace ignition::gazebo /// \brief attributes of the components, /// ex: x,y,z attributes in Vector3d type component - public: std::map data; + public: std::map> data; }; } @@ -69,7 +70,7 @@ using namespace ignition::gazebo; using namespace ignition::gui; ////////////////////////////////////////////////// -PlotComponent::PlotComponent(std::string _type, +PlotComponent::PlotComponent(const std::string &_type, ignition::gazebo::Entity _entity, ComponentTypeId _typeId) : dataPtr(new PlotComponentPrivate) @@ -80,21 +81,21 @@ PlotComponent::PlotComponent(std::string _type, if (_type == "Vector3d") { - this->dataPtr->data["x"] = new PlotData(); - this->dataPtr->data["y"] = new PlotData(); - this->dataPtr->data["z"] = new PlotData(); + this->dataPtr->data["x"] = std::shared_ptr (new PlotData()); + this->dataPtr->data["y"] = std::shared_ptr (new PlotData()); + this->dataPtr->data["z"] = std::shared_ptr (new PlotData()); } else if (_type == "Pose3d") { - this->dataPtr->data["x"] = new PlotData(); - this->dataPtr->data["y"] = new PlotData(); - this->dataPtr->data["z"] = new PlotData(); - this->dataPtr->data["roll"] = new PlotData(); - this->dataPtr->data["pitch"] = new PlotData(); - this->dataPtr->data["yaw"] = new PlotData(); + this->dataPtr->data["x"] = std::shared_ptr (new PlotData()); + this->dataPtr->data["y"] = std::shared_ptr (new PlotData()); + this->dataPtr->data["z"] = std::shared_ptr (new PlotData()); + this->dataPtr->data["roll"] = std::shared_ptr (new PlotData()); + this->dataPtr->data["pitch"] = std::shared_ptr (new PlotData()); + this->dataPtr->data["yaw"] = std::shared_ptr (new PlotData()); } else if (_type == "double") - this->dataPtr->data["value"] = new PlotData(); + this->dataPtr->data["value"] = std::shared_ptr (new PlotData()); else ignwarn << "Invalid Plot Component Type:" << _type << std::endl; } @@ -102,8 +103,6 @@ PlotComponent::PlotComponent(std::string _type, ////////////////////////////////////////////////// PlotComponent::~PlotComponent() { - for (auto plotData : this->dataPtr->data) - delete plotData.second; } ////////////////////////////////////////////////// @@ -146,7 +145,7 @@ void PlotComponent::SetAttributeValue(std::string _attribute, } ////////////////////////////////////////////////// -std::map PlotComponent::Data() const +std::map> PlotComponent::Data() const { return this->dataPtr->data; } @@ -187,9 +186,6 @@ Plotting ::Plotting () : GuiSystem() , dataPtr(new PlottingPrivate) Plotting ::~Plotting() { delete this->dataPtr->plottingIface; - - for (auto component : this->dataPtr->components) - delete component.second; } ////////////////////////////////////////////////// @@ -228,9 +224,10 @@ void Plotting::RegisterChartToComponent(uint64_t _entity, uint64_t _typeId, std::string Id = std::to_string(_entity) + "," + std::to_string(_typeId); if (this->dataPtr->components.count(Id) == 0) - this->dataPtr->components[Id] = new PlotComponent(_type, - _entity, - _typeId); + this->dataPtr->components[Id] = std::shared_ptr + (new PlotComponent(_type, + _entity, + _typeId)); this->dataPtr->components[Id]->RegisterChart(_attribute, _chart); } @@ -392,7 +389,6 @@ void Plotting ::Update(const ignition::gazebo::UpdateInfo &_info, emit this->dataPtr->plottingIface->plot(chart, attributeName, x, y); } } - } } diff --git a/src/gui/plugins/plotting/Plotting.hh b/src/gui/plugins/plotting/Plotting.hh index afe52b871f..2cf93a9657 100644 --- a/src/gui/plugins/plotting/Plotting.hh +++ b/src/gui/plugins/plotting/Plotting.hh @@ -26,6 +26,7 @@ #include #include +#include namespace ignition { @@ -41,7 +42,7 @@ class PlotComponent /// \param[in] _type component data type (Pose3d, Vector3d, double) /// \param [in] _entity entity id of that component /// \param [in] _typeId type identifier unique to each component type - public: PlotComponent(std::string _type, + public: PlotComponent(const std::string &_type, ignition::gazebo::Entity _entity, ComponentTypeId _typeId); @@ -71,7 +72,8 @@ class PlotComponent /// \brief Get all attributes of the component /// \return component attributes - public: std::map Data() const; + public: std::map> + Data() const; /// \brief Get the Component entity ID /// \return Entity ID @@ -123,7 +125,7 @@ class Plotting : public ignition::gazebo::GuiSystem /// \brief Add a chart to a specefic component attribute /// \param[in] _entity entity id in the simulation /// \param[in] _typeId type identifier unique to each component type - /// \param[in] _type Component Datatype could be ("Pose3d","Vector3d","double") + /// \param[in] _type Component Datatype ("Pose3d","Vector3d","double") /// \param[in] _attribute component attribute to add the chart to it /// ex: x attribute in Pose3d Component will be "x" /// \param [in] _chart chart ID to be registered From 095b1fedec0dd8bc0c89769ae85b596a3f02cca1 Mon Sep 17 00:00:00 2001 From: Louise Poubel Date: Thu, 17 Sep 2020 12:23:58 -0700 Subject: [PATCH 14/14] Use smart pointers and set plugin name Signed-off-by: Louise Poubel --- src/gui/plugins/plotting/Plotting.cc | 53 ++++++++++++++++------------ src/gui/plugins/plotting/Plotting.hh | 3 ++ 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/src/gui/plugins/plotting/Plotting.cc b/src/gui/plugins/plotting/Plotting.cc index 70542b5cba..d470f2e3d3 100644 --- a/src/gui/plugins/plotting/Plotting.cc +++ b/src/gui/plugins/plotting/Plotting.cc @@ -40,7 +40,7 @@ namespace ignition::gazebo class PlottingPrivate { /// \brief Interface to communicate with Qml - public: ignition::gui::PlottingInterface *plottingIface; + public: std::unique_ptr plottingIface{nullptr}; /// \brief registered components for plotting /// map key: string contains EntityID + "," + ComponentID @@ -73,7 +73,7 @@ using namespace ignition::gui; PlotComponent::PlotComponent(const std::string &_type, ignition::gazebo::Entity _entity, ComponentTypeId _typeId) : - dataPtr(new PlotComponentPrivate) + dataPtr(std::make_unique()) { this->dataPtr->entity = _entity; this->dataPtr->typeId = _typeId; @@ -81,21 +81,21 @@ PlotComponent::PlotComponent(const std::string &_type, if (_type == "Vector3d") { - this->dataPtr->data["x"] = std::shared_ptr (new PlotData()); - this->dataPtr->data["y"] = std::shared_ptr (new PlotData()); - this->dataPtr->data["z"] = std::shared_ptr (new PlotData()); + this->dataPtr->data["x"] = std::make_shared(); + this->dataPtr->data["y"] = std::make_shared(); + this->dataPtr->data["z"] = std::make_shared(); } else if (_type == "Pose3d") { - this->dataPtr->data["x"] = std::shared_ptr (new PlotData()); - this->dataPtr->data["y"] = std::shared_ptr (new PlotData()); - this->dataPtr->data["z"] = std::shared_ptr (new PlotData()); - this->dataPtr->data["roll"] = std::shared_ptr (new PlotData()); - this->dataPtr->data["pitch"] = std::shared_ptr (new PlotData()); - this->dataPtr->data["yaw"] = std::shared_ptr (new PlotData()); + this->dataPtr->data["x"] = std::make_shared(); + this->dataPtr->data["y"] = std::make_shared(); + this->dataPtr->data["z"] = std::make_shared(); + this->dataPtr->data["roll"] = std::make_shared(); + this->dataPtr->data["pitch"] = std::make_shared(); + this->dataPtr->data["yaw"] = std::make_shared(); } else if (_type == "double") - this->dataPtr->data["value"] = std::shared_ptr (new PlotData()); + this->dataPtr->data["value"] = std::make_shared(); else ignwarn << "Invalid Plot Component Type:" << _type << std::endl; } @@ -163,29 +163,36 @@ ComponentTypeId PlotComponent::TypeId() } ////////////////////////////////////////////////// -Plotting ::Plotting () : GuiSystem() , dataPtr(new PlottingPrivate) +Plotting ::Plotting() : GuiSystem(), + dataPtr(std::make_unique()) { - this->dataPtr->plottingIface = new ignition::gui::PlottingInterface(); + this->dataPtr->plottingIface = std::make_unique(); // PlottingInterface connecting - connect(this->dataPtr->plottingIface, SIGNAL(ComponentSubscribe + this->connect(this->dataPtr->plottingIface.get(), SIGNAL(ComponentSubscribe (uint64_t, uint64_t, std::string, std::string, int)), this, SLOT(RegisterChartToComponent (uint64_t, uint64_t, std::string, std::string, int))); - connect(this->dataPtr->plottingIface, SIGNAL(ComponentUnSubscribe + this->connect(this->dataPtr->plottingIface.get(), SIGNAL(ComponentUnSubscribe (uint64_t, uint64_t, std::string, int)), this, SLOT(UnRegisterChartToComponent (uint64_t, uint64_t, std::string, int))); - connect(this->dataPtr->plottingIface, SIGNAL(ComponentName(uint64_t)), - this, SLOT(ComponentName(uint64_t))); + this->connect(this->dataPtr->plottingIface.get(), + SIGNAL(ComponentName(uint64_t)), this, SLOT(ComponentName(uint64_t))); } ////////////////////////////////////////////////// Plotting ::~Plotting() { - delete this->dataPtr->plottingIface; +} + +////////////////////////////////////////// +void Plotting::LoadConfig(const tinyxml2::XMLElement *) +{ + if (this->title.empty()) + this->title = "Plotting"; } ////////////////////////////////////////////////// @@ -224,10 +231,10 @@ void Plotting::RegisterChartToComponent(uint64_t _entity, uint64_t _typeId, std::string Id = std::to_string(_entity) + "," + std::to_string(_typeId); if (this->dataPtr->components.count(Id) == 0) - this->dataPtr->components[Id] = std::shared_ptr - (new PlotComponent(_type, - _entity, - _typeId)); + { + this->dataPtr->components[Id] = std::make_shared( + _type, _entity, _typeId); + } this->dataPtr->components[Id]->RegisterChart(_attribute, _chart); } diff --git a/src/gui/plugins/plotting/Plotting.hh b/src/gui/plugins/plotting/Plotting.hh index 2cf93a9657..bf9c54c69b 100644 --- a/src/gui/plugins/plotting/Plotting.hh +++ b/src/gui/plugins/plotting/Plotting.hh @@ -100,6 +100,9 @@ class Plotting : public ignition::gazebo::GuiSystem /// \brief Destructor public: ~Plotting(); + // Documentation inherited + public: void LoadConfig(const tinyxml2::XMLElement *) override; + // Documentation inherited public: void Update(const ignition::gazebo::UpdateInfo &_info, ignition::gazebo::EntityComponentManager &_ecm) override;