2012-08-23 18:37:55 +02:00
|
|
|
/**
|
|
|
|
******************************************************************************
|
|
|
|
*
|
|
|
|
* @file connectiondiagram.cpp
|
|
|
|
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
|
|
|
|
* @addtogroup
|
|
|
|
* @{
|
|
|
|
* @addtogroup ConnectionDiagram
|
|
|
|
* @{
|
|
|
|
* @brief
|
|
|
|
*****************************************************************************/
|
|
|
|
/*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
2012-08-24 00:48:09 +02:00
|
|
|
#include <QDebug>
|
|
|
|
#include <QFile>
|
2012-09-10 22:37:39 +02:00
|
|
|
#include <QFileDialog>
|
2012-08-23 18:37:55 +02:00
|
|
|
#include "connectiondiagram.h"
|
|
|
|
#include "ui_connectiondiagram.h"
|
|
|
|
|
2014-09-05 17:30:20 +02:00
|
|
|
const char* ConnectionDiagram::FILE_NAME = ":/setupwizard/resources/connection-diagrams.svg";
|
2014-09-07 13:50:41 +02:00
|
|
|
const int ConnectionDiagram::IMAGE_PADDING = 10;
|
2014-09-05 17:30:20 +02:00
|
|
|
|
2013-05-19 17:37:30 +03:00
|
|
|
ConnectionDiagram::ConnectionDiagram(QWidget *parent, VehicleConfigurationSource *configSource) :
|
2014-09-05 17:30:20 +02:00
|
|
|
QDialog(parent), ui(new Ui::ConnectionDiagram), m_configSource(configSource)
|
2012-08-23 18:37:55 +02:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2012-08-27 07:19:46 +02:00
|
|
|
setWindowTitle(tr("Connection Diagram"));
|
|
|
|
setupGraphicsScene();
|
|
|
|
}
|
|
|
|
|
|
|
|
ConnectionDiagram::~ConnectionDiagram()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
2012-08-24 00:48:09 +02:00
|
|
|
|
2012-08-27 07:19:46 +02:00
|
|
|
void ConnectionDiagram::resizeEvent(QResizeEvent *event)
|
|
|
|
{
|
|
|
|
QWidget::resizeEvent(event);
|
2014-09-07 13:50:41 +02:00
|
|
|
fitInView();
|
2012-08-27 07:19:46 +02:00
|
|
|
}
|
|
|
|
|
2013-05-19 17:37:30 +03:00
|
|
|
void ConnectionDiagram::showEvent(QShowEvent *event)
|
2012-08-27 07:19:46 +02:00
|
|
|
{
|
|
|
|
QWidget::showEvent(event);
|
2014-09-07 13:50:41 +02:00
|
|
|
fitInView();
|
|
|
|
}
|
2013-05-19 17:37:30 +03:00
|
|
|
|
2014-09-07 13:50:41 +02:00
|
|
|
void ConnectionDiagram::fitInView()
|
|
|
|
{
|
|
|
|
ui->connectionDiagram->setSceneRect(m_scene->itemsBoundingRect());
|
|
|
|
ui->connectionDiagram->fitInView(
|
|
|
|
m_scene->itemsBoundingRect().adjusted(-IMAGE_PADDING,-IMAGE_PADDING, IMAGE_PADDING, IMAGE_PADDING),
|
|
|
|
Qt::KeepAspectRatio);
|
2012-08-27 07:19:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ConnectionDiagram::setupGraphicsScene()
|
|
|
|
{
|
2012-08-24 00:48:09 +02:00
|
|
|
m_renderer = new QSvgRenderer();
|
2014-09-05 17:30:20 +02:00
|
|
|
if (QFile::exists(QString(FILE_NAME)) &&
|
|
|
|
m_renderer->load(QString(FILE_NAME)) &&
|
2013-05-19 17:37:30 +03:00
|
|
|
m_renderer->isValid()) {
|
2012-09-10 22:37:39 +02:00
|
|
|
m_scene = new QGraphicsScene(this);
|
|
|
|
ui->connectionDiagram->setScene(m_scene);
|
2012-08-27 07:19:46 +02:00
|
|
|
|
|
|
|
QList<QString> elementsToShow;
|
|
|
|
|
2013-05-19 17:37:30 +03:00
|
|
|
switch (m_configSource->getControllerType()) {
|
|
|
|
case VehicleConfigurationSource::CONTROLLER_CC:
|
|
|
|
case VehicleConfigurationSource::CONTROLLER_CC3D:
|
|
|
|
elementsToShow << "controller-cc";
|
|
|
|
break;
|
|
|
|
case VehicleConfigurationSource::CONTROLLER_REVO:
|
|
|
|
elementsToShow << "controller-revo";
|
|
|
|
break;
|
2014-08-29 16:04:28 +02:00
|
|
|
case VehicleConfigurationSource::CONTROLLER_NANO:
|
|
|
|
elementsToShow << "controller-nano";
|
|
|
|
break;
|
2013-05-19 17:37:30 +03:00
|
|
|
case VehicleConfigurationSource::CONTROLLER_OPLINK:
|
|
|
|
default:
|
|
|
|
elementsToShow << "controller-cc";
|
|
|
|
break;
|
2012-08-27 07:19:46 +02:00
|
|
|
}
|
|
|
|
|
2013-05-19 17:37:30 +03:00
|
|
|
switch (m_configSource->getVehicleType()) {
|
|
|
|
case VehicleConfigurationSource::VEHICLE_MULTI:
|
|
|
|
switch (m_configSource->getVehicleSubType()) {
|
|
|
|
case VehicleConfigurationSource::MULTI_ROTOR_TRI_Y:
|
|
|
|
elementsToShow << "tri";
|
2012-08-27 07:19:46 +02:00
|
|
|
break;
|
2013-05-19 17:37:30 +03:00
|
|
|
case VehicleConfigurationSource::MULTI_ROTOR_QUAD_X:
|
|
|
|
elementsToShow << "quad-x";
|
2012-08-27 07:19:46 +02:00
|
|
|
break;
|
2013-05-19 17:37:30 +03:00
|
|
|
case VehicleConfigurationSource::MULTI_ROTOR_QUAD_PLUS:
|
|
|
|
elementsToShow << "quad-p";
|
2012-08-27 07:19:46 +02:00
|
|
|
break;
|
2014-09-16 00:48:45 +02:00
|
|
|
case VehicleConfigurationSource::MULTI_ROTOR_QUAD_H:
|
|
|
|
elementsToShow << "quad-h";
|
|
|
|
break;
|
2013-05-19 17:37:30 +03:00
|
|
|
case VehicleConfigurationSource::MULTI_ROTOR_HEXA:
|
|
|
|
elementsToShow << "hexa";
|
2012-08-27 07:19:46 +02:00
|
|
|
break;
|
2014-07-10 06:01:28 +02:00
|
|
|
case VehicleConfigurationSource::MULTI_ROTOR_HEXA_X:
|
|
|
|
elementsToShow << "hexa-x";
|
|
|
|
break;
|
2013-05-19 17:37:30 +03:00
|
|
|
case VehicleConfigurationSource::MULTI_ROTOR_HEXA_COAX_Y:
|
|
|
|
elementsToShow << "hexa-y";
|
2012-08-27 07:19:46 +02:00
|
|
|
break;
|
2013-05-19 17:37:30 +03:00
|
|
|
case VehicleConfigurationSource::MULTI_ROTOR_HEXA_H:
|
|
|
|
elementsToShow << "hexa-h";
|
2012-08-27 07:19:46 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2013-05-19 17:37:30 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case VehicleConfigurationSource::VEHICLE_FIXEDWING:
|
2013-11-24 17:29:38 -05:00
|
|
|
switch (m_configSource->getVehicleSubType()) {
|
2014-08-23 01:01:01 +10:00
|
|
|
case VehicleConfigurationSource::FIXED_WING_DUAL_AILERON:
|
2013-11-24 17:29:38 -05:00
|
|
|
elementsToShow << "aileron";
|
|
|
|
break;
|
2014-08-23 01:01:01 +10:00
|
|
|
case VehicleConfigurationSource::FIXED_WING_AILERON:
|
2014-08-23 02:00:11 +10:00
|
|
|
elementsToShow << "aileron-single";
|
2014-08-23 01:01:01 +10:00
|
|
|
break;
|
2014-06-07 23:04:12 -04:00
|
|
|
case VehicleConfigurationSource::FIXED_WING_ELEVON:
|
|
|
|
elementsToShow << "elevon";
|
2013-11-24 17:29:38 -05:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2013-05-19 17:37:30 +03:00
|
|
|
case VehicleConfigurationSource::VEHICLE_HELI:
|
|
|
|
case VehicleConfigurationSource::VEHICLE_SURFACE:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (m_configSource->getInputType()) {
|
|
|
|
case VehicleConfigurationSource::INPUT_PWM:
|
2014-08-29 16:04:28 +02:00
|
|
|
if (m_configSource->getControllerType() == VehicleConfigurationSource::CONTROLLER_NANO) {
|
|
|
|
elementsToShow << "pwm-nano";
|
|
|
|
} else {
|
|
|
|
elementsToShow << "pwm";
|
|
|
|
}
|
2013-05-19 17:37:30 +03:00
|
|
|
break;
|
|
|
|
case VehicleConfigurationSource::INPUT_PPM:
|
2014-08-29 16:04:28 +02:00
|
|
|
if (m_configSource->getControllerType() == VehicleConfigurationSource::CONTROLLER_NANO) {
|
|
|
|
elementsToShow << "ppm-nano";
|
|
|
|
} else {
|
|
|
|
elementsToShow << "ppm";
|
|
|
|
}
|
2013-05-19 17:37:30 +03:00
|
|
|
break;
|
|
|
|
case VehicleConfigurationSource::INPUT_SBUS:
|
2014-08-29 16:04:28 +02:00
|
|
|
if (m_configSource->getControllerType() == VehicleConfigurationSource::CONTROLLER_NANO) {
|
|
|
|
elementsToShow << "sbus-nano";
|
|
|
|
} else {
|
|
|
|
elementsToShow << "sbus";
|
|
|
|
}
|
2013-05-19 17:37:30 +03:00
|
|
|
break;
|
|
|
|
case VehicleConfigurationSource::INPUT_DSMX10:
|
|
|
|
case VehicleConfigurationSource::INPUT_DSMX11:
|
|
|
|
case VehicleConfigurationSource::INPUT_DSM2:
|
2014-08-29 16:04:28 +02:00
|
|
|
if (m_configSource->getControllerType() == VehicleConfigurationSource::CONTROLLER_NANO) {
|
|
|
|
elementsToShow << "satellite-nano";
|
|
|
|
} else {
|
|
|
|
elementsToShow << "satellite";
|
|
|
|
}
|
2013-05-19 17:37:30 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2012-08-27 07:19:46 +02:00
|
|
|
}
|
|
|
|
|
2014-09-05 17:30:20 +02:00
|
|
|
switch (m_configSource->getGpsType()) {
|
|
|
|
case VehicleConfigurationSource::GPS_DISABLED:
|
|
|
|
break;
|
|
|
|
case VehicleConfigurationSource::GPS_NMEA:
|
|
|
|
if (m_configSource->getControllerType() == VehicleConfigurationSource::CONTROLLER_NANO) {
|
|
|
|
elementsToShow << "nano-generic-nmea";
|
|
|
|
} else if (m_configSource->getControllerType() == VehicleConfigurationSource::CONTROLLER_REVO) {
|
|
|
|
elementsToShow << "generic-nmea";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case VehicleConfigurationSource::GPS_PLATINUM:
|
|
|
|
if (m_configSource->getControllerType() == VehicleConfigurationSource::CONTROLLER_NANO) {
|
|
|
|
elementsToShow << "nano-OPGPS-v9";
|
|
|
|
} else if (m_configSource->getControllerType() == VehicleConfigurationSource::CONTROLLER_REVO) {
|
|
|
|
elementsToShow << "OPGPS-v9";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case VehicleConfigurationSource::GPS_UBX:
|
|
|
|
if (m_configSource->getControllerType() == VehicleConfigurationSource::CONTROLLER_NANO) {
|
|
|
|
elementsToShow << "nano-OPGPS-v8-ublox";
|
|
|
|
} else if (m_configSource->getControllerType() == VehicleConfigurationSource::CONTROLLER_REVO) {
|
|
|
|
elementsToShow << "OPGPS-v8-ublox";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_configSource->getVehicleType() == VehicleConfigurationSource::VEHICLE_FIXEDWING &&
|
|
|
|
m_configSource->getAirspeedType() != VehicleConfigurationSource::AIRSPEED_ESTIMATE) {
|
|
|
|
switch (m_configSource->getAirspeedType()) {
|
|
|
|
case VehicleConfigurationSource::AIRSPEED_EAGLETREE:
|
|
|
|
if (m_configSource->getControllerType() == VehicleConfigurationSource::CONTROLLER_NANO) {
|
|
|
|
elementsToShow << "nano-eagletree-speed-sensor";
|
|
|
|
} else if (m_configSource->getControllerType() == VehicleConfigurationSource::CONTROLLER_REVO) {
|
|
|
|
elementsToShow << "eagletree-speed-sensor";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case VehicleConfigurationSource::AIRSPEED_MS4525:
|
|
|
|
if (m_configSource->getControllerType() == VehicleConfigurationSource::CONTROLLER_NANO) {
|
|
|
|
elementsToShow << "nano-ms4525-speed-sensor";
|
|
|
|
} else if (m_configSource->getControllerType() == VehicleConfigurationSource::CONTROLLER_REVO) {
|
|
|
|
elementsToShow << "ms4525-speed-sensor";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-10 22:37:39 +02:00
|
|
|
setupGraphicsSceneItems(elementsToShow);
|
2014-09-07 13:50:41 +02:00
|
|
|
fitInView();
|
2012-08-27 07:19:46 +02:00
|
|
|
qDebug() << "Scene complete";
|
2012-08-24 00:48:09 +02:00
|
|
|
}
|
2012-08-23 18:37:55 +02:00
|
|
|
}
|
|
|
|
|
2012-09-10 22:37:39 +02:00
|
|
|
void ConnectionDiagram::setupGraphicsSceneItems(QList<QString> elementsToShow)
|
2012-08-23 18:37:55 +02:00
|
|
|
{
|
2012-08-30 22:13:44 +02:00
|
|
|
qreal z = 0;
|
2014-03-04 23:45:01 +01:00
|
|
|
|
2012-08-27 07:19:46 +02:00
|
|
|
foreach(QString elementId, elementsToShow) {
|
2013-05-19 17:37:30 +03:00
|
|
|
if (m_renderer->elementExists(elementId)) {
|
|
|
|
QGraphicsSvgItem *element = new QGraphicsSvgItem();
|
2012-08-27 07:19:46 +02:00
|
|
|
element->setSharedRenderer(m_renderer);
|
|
|
|
element->setElementId(elementId);
|
2012-08-30 22:13:44 +02:00
|
|
|
element->setZValue(z++);
|
2012-09-03 01:01:57 +02:00
|
|
|
element->setOpacity(1.0);
|
2012-08-27 07:19:46 +02:00
|
|
|
|
|
|
|
QMatrix matrix = m_renderer->matrixForElement(elementId);
|
2013-05-19 17:37:30 +03:00
|
|
|
QRectF orig = matrix.mapRect(m_renderer->boundsOnElement(elementId));
|
|
|
|
element->setPos(orig.x(), orig.y());
|
2012-09-10 22:37:39 +02:00
|
|
|
m_scene->addItem(element);
|
2012-08-27 07:19:46 +02:00
|
|
|
qDebug() << "Adding " << elementId << " to scene at " << element->pos();
|
2013-05-19 17:37:30 +03:00
|
|
|
} else {
|
2012-09-03 01:01:57 +02:00
|
|
|
qDebug() << "Element with id: " << elementId << " not found.";
|
2012-08-27 07:19:46 +02:00
|
|
|
}
|
|
|
|
}
|
2012-08-23 18:37:55 +02:00
|
|
|
}
|
2012-08-27 07:19:46 +02:00
|
|
|
|
2012-09-10 22:37:39 +02:00
|
|
|
void ConnectionDiagram::on_saveButton_clicked()
|
|
|
|
{
|
|
|
|
QImage image(2200, 1100, QImage::Format_ARGB32);
|
2013-05-19 17:37:30 +03:00
|
|
|
|
2014-09-07 13:50:41 +02:00
|
|
|
image.fill(Qt::white);
|
2012-09-10 22:37:39 +02:00
|
|
|
QPainter painter(&image);
|
|
|
|
m_scene->render(&painter);
|
|
|
|
QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"), "", tr("Images (*.png *.xpm *.jpg)"));
|
2013-05-19 17:37:30 +03:00
|
|
|
if (!fileName.isEmpty()) {
|
2012-09-10 22:37:39 +02:00
|
|
|
image.save(fileName);
|
|
|
|
}
|
|
|
|
}
|