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"
|
|
|
|
|
2013-05-19 17:37:30 +03:00
|
|
|
ConnectionDiagram::ConnectionDiagram(QWidget *parent, VehicleConfigurationSource *configSource) :
|
2012-08-27 07:19:46 +02:00
|
|
|
QDialog(parent), ui(new Ui::ConnectionDiagram), m_configSource(configSource), m_background(0)
|
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);
|
2013-05-19 17:37:30 +03:00
|
|
|
|
2012-08-27 07:19:46 +02:00
|
|
|
ui->connectionDiagram->fitInView(m_background, Qt::KeepAspectRatio);
|
|
|
|
}
|
|
|
|
|
2013-05-19 17:37:30 +03:00
|
|
|
void ConnectionDiagram::showEvent(QShowEvent *event)
|
2012-08-27 07:19:46 +02:00
|
|
|
{
|
|
|
|
QWidget::showEvent(event);
|
2013-05-19 17:37:30 +03:00
|
|
|
|
2012-08-27 07:19:46 +02:00
|
|
|
ui->connectionDiagram->fitInView(m_background, Qt::KeepAspectRatio);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConnectionDiagram::setupGraphicsScene()
|
|
|
|
{
|
2012-08-24 00:48:09 +02:00
|
|
|
m_renderer = new QSvgRenderer();
|
2012-08-27 07:19:46 +02:00
|
|
|
if (QFile::exists(QString(":/setupwizard/resources/connection-diagrams.svg")) &&
|
2013-05-19 17:37:30 +03:00
|
|
|
m_renderer->load(QString(":/setupwizard/resources/connection-diagrams.svg")) &&
|
|
|
|
m_renderer->isValid()) {
|
2012-09-10 22:37:39 +02:00
|
|
|
m_scene = new QGraphicsScene(this);
|
|
|
|
ui->connectionDiagram->setScene(m_scene);
|
2013-05-19 17:37:30 +03:00
|
|
|
// ui->connectionDiagram->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
|
2012-09-03 01:01:57 +02:00
|
|
|
|
2012-08-27 07:19:46 +02:00
|
|
|
m_background = new QGraphicsSvgItem();
|
|
|
|
m_background->setSharedRenderer(m_renderer);
|
|
|
|
m_background->setElementId("background");
|
2012-09-03 01:01:57 +02:00
|
|
|
m_background->setOpacity(0);
|
2013-05-19 17:37:30 +03:00
|
|
|
// m_background->setFlags(QGraphicsItem::ItemClipsToShape);
|
2012-08-30 22:13:44 +02:00
|
|
|
m_background->setZValue(-1);
|
2012-09-10 22:37:39 +02:00
|
|
|
m_scene->addItem(m_background);
|
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;
|
|
|
|
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;
|
2013-05-19 17:37:30 +03:00
|
|
|
case VehicleConfigurationSource::MULTI_ROTOR_HEXA:
|
|
|
|
elementsToShow << "hexa";
|
2012-08-27 07:19:46 +02:00
|
|
|
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:
|
|
|
|
case VehicleConfigurationSource::VEHICLE_HELI:
|
|
|
|
case VehicleConfigurationSource::VEHICLE_SURFACE:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (m_configSource->getInputType()) {
|
|
|
|
case VehicleConfigurationSource::INPUT_PWM:
|
|
|
|
elementsToShow << "pwm";
|
|
|
|
break;
|
|
|
|
case VehicleConfigurationSource::INPUT_PPM:
|
|
|
|
elementsToShow << "ppm";
|
|
|
|
break;
|
|
|
|
case VehicleConfigurationSource::INPUT_SBUS:
|
|
|
|
elementsToShow << "sbus";
|
|
|
|
break;
|
|
|
|
case VehicleConfigurationSource::INPUT_DSMX10:
|
|
|
|
case VehicleConfigurationSource::INPUT_DSMX11:
|
|
|
|
case VehicleConfigurationSource::INPUT_DSM2:
|
|
|
|
elementsToShow << "satellite";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2012-08-27 07:19:46 +02:00
|
|
|
}
|
|
|
|
|
2012-09-10 22:37:39 +02:00
|
|
|
setupGraphicsSceneItems(elementsToShow);
|
2012-08-27 07:19:46 +02:00
|
|
|
|
|
|
|
ui->connectionDiagram->setSceneRect(m_background->boundingRect());
|
|
|
|
ui->connectionDiagram->fitInView(m_background, Qt::KeepAspectRatio);
|
2012-08-24 00:48:09 +02:00
|
|
|
|
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-02-26 17:57:45 +01:00
|
|
|
//QRectF backgBounds = m_renderer->boundsOnElement("background");
|
2012-09-03 01:01:57 +02: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-03 01:01:57 +02:00
|
|
|
|
2013-05-19 17:37:30 +03:00
|
|
|
// QRectF orig = m_renderer->boundsOnElement(elementId);
|
|
|
|
// element->setPos(orig.x() - backgBounds.x(), orig.y() - backgBounds.y());
|
2012-09-03 01:01:57 +02:00
|
|
|
|
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
|
|
|
|
2012-09-10 22:37:39 +02:00
|
|
|
image.fill(0);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|