Skip to content

Commit

Permalink
Fix Plotting Crash
Browse files Browse the repository at this point in the history
Signed-off-by: AmrElsersy <[email protected]>
  • Loading branch information
AmrElsersy authored and chapulina committed Sep 14, 2020
1 parent 40a4658 commit 4bdf559
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 30 deletions.
4 changes: 0 additions & 4 deletions include/ignition/gui/PlottingInterface.hh
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,6 @@ class IGNITION_GUI_VISIBLE PlottingInterface : public QObject
/// \return updating plot timeout
public: float Timeout() const;

/// \brief Get the Plotting Time
/// \return Plotting Time
public slots: double Time() const;

/// \brief slot to get triggered to plot a point and send its data to the UI
/// \param[in] _chart chart ID
/// \param[in] _fieldID field path ID
Expand Down
42 changes: 17 additions & 25 deletions src/PlottingInterface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,19 @@ class TransportPrivate
class PlottingIfacePrivate
{
/// \brief Responsible for transport messages and topics
public: Transport *transport;
public: Transport transport;

/// \brief current plotting time
public: double time;
public: double *time {new double};

/// \brief Plotting time pointer to give access to topics to read it
public: std::shared_ptr<double> plottingTimeRef {&time};
public: std::shared_ptr<double> plottingTimeRef {time};

/// \brief timeout to update the plot with the timer
public: int timeout;

/// \brief timer to update the plotting each time step
public: QTimer *timer;
public: QTimer timer;
};

}
Expand Down Expand Up @@ -497,8 +497,7 @@ void Transport::UnsubscribeOutdatedTopics()
PlottingInterface::PlottingInterface() : QObject(),
dataPtr(std::make_unique<PlottingIfacePrivate>())
{
this->dataPtr->transport = new Transport();
connect(this->dataPtr->transport,
connect(&this->dataPtr->transport,
SIGNAL(plot(int, QString, double, double)), this,
SLOT(onPlot(int, QString, double, double)));

Expand All @@ -518,21 +517,15 @@ void PlottingInterface::unsubscribe(int _chart,
QString _topic,
QString _fieldPath)
{
this->dataPtr->transport->Unsubscribe(_topic.toStdString(),
_fieldPath.toStdString(),
_chart);
this->dataPtr->transport.Unsubscribe(_topic.toStdString(),
_fieldPath.toStdString(),
_chart);
}

//////////////////////////////////////////////////////
float PlottingInterface::Timeout() const
{
return this->dataPtr->timer->interval();
}

//////////////////////////////////////////////////////
double PlottingInterface::Time() const
{
return this->dataPtr->time;
return this->dataPtr->timer.interval();
}

//////////////////////////////////////////////////////
Expand Down Expand Up @@ -571,18 +564,17 @@ void PlottingInterface::subscribe(int _chart,
QString _topic,
QString _fieldPath)
{
this->dataPtr->transport->Subscribe(_topic.toStdString(),
_fieldPath.toStdString(),
_chart, this->dataPtr->plottingTimeRef);
this->dataPtr->transport.Subscribe(_topic.toStdString(),
_fieldPath.toStdString(),
_chart, this->dataPtr->plottingTimeRef);
}

////////////////////////////////////////////
void PlottingInterface::InitTimer()
{
this->dataPtr->timer = new QTimer();
this->dataPtr->timer->setInterval(this->dataPtr->timeout);
connect(this->dataPtr->timer, SIGNAL(timeout()), this, SLOT(UpdateTime()));
this->dataPtr->timer->start();
this->dataPtr->timer.setInterval(this->dataPtr->timeout);
connect(&this->dataPtr->timer, SIGNAL(timeout()), this, SLOT(UpdateTime()));
this->dataPtr->timer.start();
}

//////////////////////////////////////////////////////
Expand All @@ -592,15 +584,15 @@ void PlottingInterface::onPlot(int _chart, QString _fieldID,
// if _x == -1, then the msg has not header time
// so update x with the default plotting time that is handled by a timer
if (static_cast<int>(_x) == DEFAULT_TIME)
_x = this->dataPtr->time;
_x = *this->dataPtr->time;

emit this->plot(_chart, _fieldID, _x, _y);
}

//////////////////////////////////////////////////////
void PlottingInterface::UpdateTime()
{
this->dataPtr->time += this->dataPtr->timeout * 0.001;
*this->dataPtr->time += this->dataPtr->timeout * 0.001;
}

//////////////////////////////////////////////////////
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/plotting/TransportPlotting.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ using namespace ignition;
using namespace gui;
using namespace plugins;

TransportPlotting::~TransportPlotting() {}
TransportPlotting::~TransportPlotting() {
}

//////////////////////////////////////////
void TransportPlotting::LoadConfig(const tinyxml2::XMLElement *)
Expand Down

0 comments on commit 4bdf559

Please sign in to comment.