31 #include "systemalarms.h"
40 : QGraphicsView(parent)
42 setMinimumSize(128, 64);
43 setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
44 setScene(
new QGraphicsScene(
this));
46 m_renderer =
new QSvgRenderer();
47 background =
new QGraphicsSvgItem();
48 foreground =
new QGraphicsSvgItem();
49 nolink =
new QGraphicsSvgItem();
57 SystemAlarms *obj = SystemAlarms::GetInstance(objManager);
63 &SystemHealthGadgetWidget::onAutopilotConnect);
65 &SystemHealthGadgetWidget::onAutopilotDisconnect);
67 setToolTip(tr(
"Displays flight system errors. Click on an alarm for more information."));
73 void SystemHealthGadgetWidget::onAutopilotConnect()
77 SystemAlarms *obj = SystemAlarms::GetInstance(objManager);
79 if (obj->getIsPresentOnHardware()) {
80 nolink->setVisible(
false);
82 nolink->setVisible(
true);
89 void SystemHealthGadgetWidget::onAutopilotDisconnect()
91 nolink->setVisible(
true);
94 void SystemHealthGadgetWidget::updateAlarms(
UAVObject *systemAlarm)
101 QGraphicsScene *m_scene = scene();
102 foreach (QGraphicsItem *item, background->childItems()) {
103 m_scene->removeItem(item);
114 QString value = field->
getValue(
i).toString();
115 if (m_renderer->elementExists(element)) {
116 QMatrix blockMatrix = m_renderer->matrixForElement(element);
117 qreal startX = blockMatrix.mapRect(m_renderer->boundsOnElement(element)).
x();
118 qreal startY = blockMatrix.mapRect(m_renderer->boundsOnElement(element)).
y();
119 QString element2 = element +
"-" + value;
120 if (m_renderer->elementExists(element2)) {
121 QGraphicsSvgItem *ind =
new QGraphicsSvgItem();
122 ind->setSharedRenderer(m_renderer);
123 ind->setElementId(element2);
124 ind->setParentItem(background);
126 matrix.translate(startX, startY);
127 ind->setTransform(matrix,
false);
129 if ((value.compare(
"Uninitialised") != 0) && !warningClean.contains(element2)) {
130 qDebug() <<
"[SystemHealth] Warning: The SystemHealth SVG does not contain a "
131 "graphical element for the "
132 << element2 <<
" alarm.";
133 warningClean.append(element2);
136 }
else if (!warningClean.contains(element)) {
137 qDebug() <<
"[SystemHealth] Warning: The SystemHealth SVG does not contain a graphical "
139 << element <<
" alarm.";
140 warningClean.append(element);
152 if (QFile::exists(dfn)) {
153 m_renderer->load(dfn);
154 if (m_renderer->isValid()) {
156 background->setSharedRenderer(m_renderer);
157 background->setElementId(
"background");
159 if (m_renderer->elementExists(
"foreground")) {
160 foreground->setSharedRenderer(m_renderer);
161 foreground->setElementId(
"foreground");
162 foreground->setZValue(99);
165 if (m_renderer->elementExists(
"nolink")) {
166 nolink->setSharedRenderer(m_renderer);
167 nolink->setElementId(
"nolink");
168 nolink->setZValue(100);
171 QGraphicsScene *l_scene = scene();
172 l_scene->setSceneRect(background->boundingRect());
173 fitInView(background, Qt::KeepAspectRatio);
179 if (telMngr->isConnected()) {
180 onAutopilotConnect();
181 SystemAlarms *obj = SystemAlarms::GetInstance(objManager);
186 qDebug() <<
"SystemHealthGadget: no file";
192 QGraphicsScene *l_scene = scene();
194 l_scene->addItem(background);
195 l_scene->addItem(foreground);
196 l_scene->addItem(nolink);
203 if (!m_renderer->isValid()) {
204 qDebug() <<
"SystemHealthGadget: System file not loaded, not rendering";
207 QGraphicsView::paintEvent(event);
216 fitInView(background, Qt::KeepAspectRatio);
221 QGraphicsScene *graphicsScene = scene();
223 QPoint point =
event->pos();
224 bool haveAlarmItem =
false;
225 foreach (QGraphicsItem *sceneItem, items(point)) {
226 QGraphicsSvgItem *clickedItem =
dynamic_cast<QGraphicsSvgItem *
>(sceneItem);
229 if ((clickedItem != foreground) && (clickedItem != background)) {
234 haveAlarmItem =
true;
235 QString itemId = clickedItem->elementId();
236 if (itemId.contains(
"OK")) {
238 showAlarmDescriptionForItemId(
"AlarmOK", event->globalPos());
241 showAlarmDescriptionForItemId(itemId, event->globalPos());
246 if (!haveAlarmItem) {
248 showAllAlarmDescriptions(event->globalPos());
253 void SystemHealthGadgetWidget::showAlarmDescriptionForItemId(
const QString itemId,
254 const QPoint &location)
256 QFile alarmDescription(getAlarmDescriptionFileName(itemId));
257 if (alarmDescription.open(QIODevice::ReadOnly | QIODevice::Text)) {
258 QTextStream textStream(&alarmDescription);
259 QWhatsThis::showText(location, textStream.readAll());
263 void SystemHealthGadgetWidget::showAllAlarmDescriptions(
const QPoint &location)
265 QGraphicsScene *graphicsScene = scene();
269 foreach (QGraphicsItem *curItem, graphicsScene->items()) {
270 QGraphicsSvgItem *curSvgItem =
dynamic_cast<QGraphicsSvgItem *
>(curItem);
271 if (curSvgItem && (curSvgItem != foreground) && (curSvgItem != background)) {
272 QString elementId = curSvgItem->elementId();
273 if (!elementId.contains(
"OK")) {
276 QFile alarmDescription(getAlarmDescriptionFileName(elementId));
277 if (alarmDescription.open(QIODevice::ReadOnly | QIODevice::Text)) {
278 QTextStream textStream(&alarmDescription);
279 alarmsText.append(textStream.readAll());
280 alarmDescription.close();
286 if (alarmsText.length() > 0) {
287 QWhatsThis::showText(location, alarmsText);
292 QString SystemHealthGadgetWidget::getAlarmDescriptionFileName(
const QString itemId)
294 QString alarmDescriptionFileName;
297 SystemAlarms::DataFields systemAlarmsData = SystemAlarms::GetInstance(objManager)->getData();
298 if (itemId.contains(
"SystemConfiguration-")) {
299 switch (systemAlarmsData.ConfigError) {
300 case SystemAlarms::CONFIGERROR_STABILIZATION:
301 alarmDescriptionFileName =
302 QString(
":/systemhealth/html/SystemConfiguration-Error-Stabilization.html");
304 case SystemAlarms::CONFIGERROR_NAVFILTER:
305 alarmDescriptionFileName =
306 QString(
":/systemhealth/html/SystemConfiguration-Error-NavFilter.html");
308 case SystemAlarms::CONFIGERROR_MULTIROTOR:
309 alarmDescriptionFileName =
310 QString(
":/systemhealth/html/SystemConfiguration-Error-Multirotor.html");
312 case SystemAlarms::CONFIGERROR_AUTOTUNE:
313 alarmDescriptionFileName =
314 QString(
":/systemhealth/html/SystemConfiguration-Error-AutoTune.html");
316 case SystemAlarms::CONFIGERROR_ALTITUDEHOLD:
317 alarmDescriptionFileName =
318 QString(
":/systemhealth/html/SystemConfiguration-Error-AltitudeHold.html");
320 case SystemAlarms::CONFIGERROR_POSITIONHOLD:
321 alarmDescriptionFileName =
322 QString(
":/systemhealth/html/SystemConfiguration-Error-PositionHold.html");
324 case SystemAlarms::CONFIGERROR_DUPLICATEPORTCFG:
325 alarmDescriptionFileName =
326 QString(
":/systemhealth/html/SystemConfiguration-Error-DuplicatePortCfg.html");
328 case SystemAlarms::CONFIGERROR_PATHPLANNER:
329 alarmDescriptionFileName =
330 QString(
":/systemhealth/html/SystemConfiguration-Error-PathPlanner.html");
332 case SystemAlarms::CONFIGERROR_UNSAFETOARM:
333 alarmDescriptionFileName =
334 QString(
":/systemhealth/html/SystemConfiguration-Error-UnsafeToArm.html");
336 case SystemAlarms::CONFIGERROR_LQG:
337 alarmDescriptionFileName =
338 QString(
":/systemhealth/html/SystemConfiguration-Error-LQG.html");
340 case SystemAlarms::CONFIGERROR_UNDEFINED:
341 alarmDescriptionFileName =
342 QString(
":/systemhealth/html/SystemConfiguration-Undefined.html");
345 alarmDescriptionFileName = QString(
":/systemhealth/html/SystemConfiguration-None.html");
348 }
else if (itemId.contains(
"ManualControl-")) {
349 switch (systemAlarmsData.ManualControl) {
350 case SystemAlarms::MANUALCONTROL_SETTINGS:
351 alarmDescriptionFileName =
352 QString(
":/systemhealth/html/ManualControl-Critical-Settings.html");
354 case SystemAlarms::MANUALCONTROL_NORX:
355 alarmDescriptionFileName =
356 QString(
":/systemhealth/html/ManualControl-Warning-NoRx.html");
358 case SystemAlarms::MANUALCONTROL_ACCESSORY:
359 alarmDescriptionFileName =
360 QString(
":/systemhealth/html/ManualControl-Warning-Accessory.html");
362 case SystemAlarms::MANUALCONTROL_ALTITUDEHOLD:
363 alarmDescriptionFileName =
364 QString(
":/systemhealth/html/ManualControl-Error-AltitudeHold.html");
366 case SystemAlarms::MANUALCONTROL_PATHFOLLOWER:
367 alarmDescriptionFileName =
368 QString(
":/systemhealth/html/ManualControl-Critical-PathFollower.html");
370 case SystemAlarms::MANUALCONTROL_CHANNELCONFIGURATION:
371 alarmDescriptionFileName =
372 QString(
":/systemhealth/html/ManualControl-Warning-ChannelConfiguration.html");
374 case SystemAlarms::MANUALCONTROL_UNDEFINED:
375 alarmDescriptionFileName = QString(
":/systemhealth/html/ManualControl-Undefined.html");
378 alarmDescriptionFileName = QString(
":/systemhealth/html/ManualControl-None.html");
381 }
else if (itemId.contains(
"StateEstimation-") || itemId.contains(
"Attitude-")) {
382 switch (systemAlarmsData.StateEstimation) {
383 case SystemAlarms::STATEESTIMATION_GYROQUEUENOTUPDATING:
384 alarmDescriptionFileName =
385 QString(
":/systemhealth/html/StateEstimation-Gyro-Queue-Not-Updating.html");
387 case SystemAlarms::STATEESTIMATION_ACCELEROMETERQUEUENOTUPDATING:
388 alarmDescriptionFileName = QString(
389 ":/systemhealth/html/StateEstimation-Accelerometer-Queue-Not-Updating.html");
391 case SystemAlarms::STATEESTIMATION_NOGPS:
392 alarmDescriptionFileName = QString(
":/systemhealth/html/StateEstimation-No-GPS.html");
394 case SystemAlarms::STATEESTIMATION_NOMAGNETOMETER:
395 alarmDescriptionFileName =
396 QString(
":/systemhealth/html/StateEstimation-No-Magnetometer.html");
398 case SystemAlarms::STATEESTIMATION_NOBAROMETER:
399 alarmDescriptionFileName =
400 QString(
":/systemhealth/html/StateEstimation-No-Barometer.html");
402 case SystemAlarms::STATEESTIMATION_TOOFEWSATELLITES:
403 alarmDescriptionFileName =
404 QString(
":/systemhealth/html/StateEstimation-Too-Few-Satellites.html");
406 case SystemAlarms::STATEESTIMATION_PDOPTOOHIGH:
407 alarmDescriptionFileName =
408 QString(
":/systemhealth/html/StateEstimation-PDOP-Too-High.html");
410 case SystemAlarms::STATEESTIMATION_UNDEFINED:
411 alarmDescriptionFileName =
412 QString(
":/systemhealth/html/StateEstimation-Undefined.html");
414 case SystemAlarms::STATEESTIMATION_NOHOME:
415 alarmDescriptionFileName = QString(
":/systemhealth/html/StateEstimation-NoHome.html");
418 alarmDescriptionFileName = QString(
":/systemhealth/html/StateEstimation-None.html");
422 alarmDescriptionFileName = QString(
":/systemhealth/html/" + itemId +
".html");
424 return alarmDescriptionFileName;
void paintEvent(QPaintEvent *event)
void resizeEvent(QResizeEvent *event)
void setSystemFile(QString dfn)
Core plugin system that manages the plugins, their life cycle and their registered objects...
QVariant getValue(int index=0) const
int getNumElements() const
void objectUpdated(UAVObject *obj)
Signal sent whenever any field of the object is updated.
~SystemHealthGadgetWidget()
UAVObjectField * getField(const QString &name)
QStringList getElementNames() const
SystemHealthGadgetWidget(QWidget *parent=nullptr)
void mousePressEvent(QMouseEvent *event)