mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-20 10:54:14 +01:00
Merge remote-tracking branch 'origin/MikeL_ConfigVehicle' into next
This commit is contained in:
commit
621c78e5cb
@ -554,7 +554,7 @@ void ConfigCcpmWidget::updateThrottleCurveValue(QList<double> curveValues0,doubl
|
||||
|
||||
for (i=0; i<internalCurveValues.length(); i++)
|
||||
{
|
||||
CurrentValue=m_ccpm->CurveSettings->item(i, 1 )->text().toDouble();
|
||||
CurrentValue=m_ccpm->CurveSettings->item(i, 0 )->text().toDouble();
|
||||
if (CurrentValue!=internalCurveValues[i])
|
||||
{
|
||||
m_ccpm->CurveSettings->item(i, 0)->setText(QString().sprintf("%.3f",internalCurveValues.at(i)));
|
||||
@ -1224,11 +1224,10 @@ void ConfigCcpmWidget::setMixer()
|
||||
}
|
||||
|
||||
//get the user data for the curve into the mixer settings
|
||||
for (i=0;i<5;i++)
|
||||
for (i=0;i<5;i++) {
|
||||
mixerSettingsData.ThrottleCurve1[i] = m_ccpm->CurveSettings->item(i, 0)->text().toDouble();
|
||||
|
||||
for (i=0;i<5;i++)
|
||||
mixerSettingsData.ThrottleCurve2[i] = m_ccpm->CurveSettings->item(i, 1)->text().toDouble();
|
||||
}
|
||||
|
||||
//mapping of collective input to curve 2...
|
||||
//MixerSettings.Curve2Source = Throttle,Roll,Pitch,Yaw,Accessory0,Accessory1,Accessory2,Accessory3,Accessory4,Accessory5
|
||||
|
@ -46,7 +46,7 @@
|
||||
#define STICK_MIN_MOVE -8
|
||||
#define STICK_MAX_MOVE 8
|
||||
|
||||
ConfigInputWidget::ConfigInputWidget(QWidget *parent) : ConfigTaskWidget(parent),wizardStep(wizardNone),loop(NULL),skipflag(false),transmitterType(heli)
|
||||
ConfigInputWidget::ConfigInputWidget(QWidget *parent) : ConfigTaskWidget(parent),wizardStep(wizardNone),transmitterType(heli),loop(NULL),skipflag(false)
|
||||
{
|
||||
manualCommandObj = ManualControlCommand::GetInstance(getObjectManager());
|
||||
manualSettingsObj = ManualControlSettings::GetInstance(getObjectManager());
|
||||
|
@ -84,7 +84,7 @@ public:
|
||||
};
|
||||
|
||||
ConfigTaskWidget(QWidget *parent = 0);
|
||||
~ConfigTaskWidget();
|
||||
virtual ~ConfigTaskWidget();
|
||||
|
||||
void disableMouseWheelEvents();
|
||||
bool eventFilter( QObject * obj, QEvent * evt );
|
||||
|
@ -43,6 +43,7 @@ Node::Node(MixerCurveWidget *graphWidget)
|
||||
setCacheMode(DeviceCoordinateCache);
|
||||
setZValue(-1);
|
||||
vertical = false;
|
||||
value = 0;
|
||||
}
|
||||
|
||||
void Node::addEdge(Edge *edge)
|
||||
@ -98,6 +99,15 @@ void Node::verticalMove(bool flag){
|
||||
vertical = flag;
|
||||
}
|
||||
|
||||
double Node::getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
void Node::setValue(double val) {
|
||||
value = val;
|
||||
}
|
||||
|
||||
|
||||
QVariant Node::itemChange(GraphicsItemChange change, const QVariant &value)
|
||||
{
|
||||
|
||||
@ -117,11 +127,19 @@ QVariant Node::itemChange(GraphicsItemChange change, const QVariant &value)
|
||||
newPos.setY(h);
|
||||
return newPos;
|
||||
}
|
||||
case ItemPositionHasChanged:
|
||||
case ItemPositionHasChanged: {
|
||||
foreach (Edge *edge, edgeList)
|
||||
edge->adjust();
|
||||
graph->itemMoved((h-newPos.y())/h);
|
||||
|
||||
double min = graph->getMin();
|
||||
double range = graph->getMax() - min;
|
||||
double ratio = (h - newPos.y()) / h;
|
||||
double val = (range * ratio ) + min;
|
||||
setValue(val);
|
||||
|
||||
graph->itemMoved(val);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
};
|
||||
|
@ -48,12 +48,16 @@ public:
|
||||
enum { Type = UserType + 1 };
|
||||
int type() const { return Type; }
|
||||
|
||||
|
||||
void verticalMove(bool flag);
|
||||
|
||||
QRectF boundingRect() const;
|
||||
QPainterPath shape() const;
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
||||
|
||||
void setValue(double val);
|
||||
double getValue();
|
||||
|
||||
protected:
|
||||
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
|
||||
|
||||
@ -61,6 +65,8 @@ protected:
|
||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
||||
|
||||
private:
|
||||
|
||||
double value;
|
||||
QList<Edge *> edgeList;
|
||||
QPointF newPos;
|
||||
MixerCurveWidget *graph;
|
||||
|
@ -32,8 +32,6 @@
|
||||
#include <QtGui>
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Initialize the widget
|
||||
*/
|
||||
@ -74,11 +72,48 @@ MixerCurveWidget::MixerCurveWidget(QWidget *parent) : QGraphicsView(parent)
|
||||
scene->setSceneRect(plot->boundingRect());
|
||||
setScene(scene);
|
||||
|
||||
initNodes(MixerCurveWidget::NODE_NUMELEM);
|
||||
}
|
||||
|
||||
MixerCurveWidget::~MixerCurveWidget()
|
||||
{
|
||||
for (int i=0; i<nodePool.count(); i++)
|
||||
delete nodePool.at(i);
|
||||
|
||||
for (int i=0; i<edgePool.count(); i++)
|
||||
delete edgePool.at(i);
|
||||
}
|
||||
|
||||
Node* MixerCurveWidget::getNode(int index)
|
||||
{
|
||||
Node* node;
|
||||
|
||||
if (index >= 0 && index < nodePool.count())
|
||||
{
|
||||
node = nodePool.at(index);
|
||||
}
|
||||
else {
|
||||
node = new Node(this);
|
||||
nodePool.append(node);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
Edge* MixerCurveWidget::getEdge(int index, Node* sourceNode, Node* destNode)
|
||||
{
|
||||
Edge* edge;
|
||||
|
||||
if (index >= 0 && index < edgePool.count())
|
||||
{
|
||||
edge = edgePool.at(index);
|
||||
edge->setSourceNode(sourceNode);
|
||||
edge->setDestNode(destNode);
|
||||
}
|
||||
else {
|
||||
edge = new Edge(sourceNode,destNode);
|
||||
edgePool.append(edge);
|
||||
}
|
||||
return edge;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -89,60 +124,62 @@ MixerCurveWidget::~MixerCurveWidget()
|
||||
*/
|
||||
void MixerCurveWidget::initCurve(QList<double> points)
|
||||
{
|
||||
|
||||
if (points.length() < 2)
|
||||
return; // We need at least 2 points on a curve!
|
||||
|
||||
// First of all, reset the list
|
||||
// TODO: one edge might not get deleted properly, small mem leak maybe...
|
||||
if (nodeList.count() != points.count())
|
||||
initNodes(points.count());
|
||||
|
||||
// finally, set node positions
|
||||
setCurve(points);
|
||||
}
|
||||
|
||||
void MixerCurveWidget::initNodes(int numPoints)
|
||||
{
|
||||
// First of all, clear any existing list
|
||||
if (nodeList.count()) {
|
||||
foreach (Node *node, nodeList ) {
|
||||
QList<Edge*> edges = node->edges();
|
||||
foreach(Edge *edge, edges) {
|
||||
if (scene()->items().contains(edge))
|
||||
scene()->removeItem(edge);
|
||||
else
|
||||
if (edge->destNode() == node) {
|
||||
delete edge;
|
||||
}
|
||||
else {
|
||||
scene()->removeItem(edge);
|
||||
}
|
||||
}
|
||||
scene()->removeItem(node);
|
||||
delete node;
|
||||
}
|
||||
nodeList.clear();
|
||||
scene()->removeItem(node);
|
||||
}
|
||||
|
||||
nodeList.clear();
|
||||
}
|
||||
|
||||
// Create the nodes and edges
|
||||
Node* prevNode = 0;
|
||||
for (int i=0; i<numPoints; i++) {
|
||||
|
||||
Node *node = getNode(i);
|
||||
|
||||
// Create the nodes
|
||||
qreal w = plot->boundingRect().width()/(points.length()-1);
|
||||
qreal h = plot->boundingRect().height();
|
||||
for (int i=0; i<points.length(); i++) {
|
||||
Node *node = new Node(this);
|
||||
scene()->addItem(node);
|
||||
nodeList.append(node);
|
||||
double val = points.at(i);
|
||||
if (val>curveMax)
|
||||
val=curveMax;
|
||||
if (val<curveMin)
|
||||
val=curveMin;
|
||||
val+=curveMin;
|
||||
val/=(curveMax-curveMin);
|
||||
node->setPos(w*i,h-val*h);
|
||||
node->verticalMove(true);
|
||||
}
|
||||
scene()->addItem(node);
|
||||
|
||||
// ... and link them together:
|
||||
for (int i=0; i<(points.length()-1); i++) {
|
||||
scene()->addItem(new Edge(nodeList.at(i),nodeList.at(i+1)));
|
||||
}
|
||||
if (prevNode) {
|
||||
scene()->addItem(getEdge(i, prevNode, node));
|
||||
}
|
||||
|
||||
prevNode = node;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Returns the current curve settings
|
||||
*/
|
||||
QList<double> MixerCurveWidget::getCurve() {
|
||||
|
||||
QList<double> list;
|
||||
|
||||
qreal h = plot->boundingRect().height();
|
||||
foreach(Node *node, nodeList) {
|
||||
list.append(((curveMax-curveMin)*(h-node->pos().y())/h)+curveMin);
|
||||
list.append(node->getValue());
|
||||
}
|
||||
|
||||
return list;
|
||||
@ -150,11 +187,15 @@ QList<double> MixerCurveWidget::getCurve() {
|
||||
/**
|
||||
Sets a linear graph
|
||||
*/
|
||||
void MixerCurveWidget::initLinearCurve(quint32 numPoints, double maxValue)
|
||||
void MixerCurveWidget::initLinearCurve(quint32 numPoints, double maxValue, double minValue)
|
||||
{
|
||||
Q_UNUSED(maxValue);
|
||||
Q_UNUSED(minValue);
|
||||
|
||||
QList<double> points;
|
||||
for (double i=0; i<numPoints;i++) {
|
||||
points.append(maxValue*(i/(numPoints-1)));
|
||||
double val = ((curveMax - curveMin) * (i/(numPoints-1))) + curveMin;
|
||||
points.append(val);
|
||||
}
|
||||
initCurve(points);
|
||||
}
|
||||
@ -163,25 +204,35 @@ void MixerCurveWidget::initLinearCurve(quint32 numPoints, double maxValue)
|
||||
*/
|
||||
void MixerCurveWidget::setCurve(QList<double> points)
|
||||
{
|
||||
if (nodeList.length()<1)
|
||||
{
|
||||
initCurve(points);
|
||||
}
|
||||
else
|
||||
{
|
||||
qreal w = plot->boundingRect().width()/(points.length()-1);
|
||||
qreal h = plot->boundingRect().height();
|
||||
for (int i=0; i<points.length(); i++) {
|
||||
double val = points.at(i);
|
||||
if (val>curveMax)
|
||||
val=curveMax;
|
||||
if (val<curveMin)
|
||||
val=curveMin;
|
||||
val-=curveMin;
|
||||
val/=(curveMax-curveMin);
|
||||
nodeList.at(i)->setPos(w*i,h-val*h);
|
||||
}
|
||||
curveUpdating = true;
|
||||
|
||||
if (nodeList.count() != points.count())
|
||||
initNodes(points.count());
|
||||
|
||||
double min = curveMin + 10;
|
||||
double max = curveMax + 10;
|
||||
|
||||
qreal w = plot->boundingRect().width()/(points.count()-1);
|
||||
qreal h = plot->boundingRect().height();
|
||||
for (int i=0; i<points.count(); i++) {
|
||||
|
||||
double val = points.at(i);
|
||||
if (val < curveMin)
|
||||
val = curveMin;
|
||||
if (val > curveMax)
|
||||
val = curveMax;
|
||||
|
||||
val += 10;
|
||||
val -= min;
|
||||
val /= (max - min);
|
||||
|
||||
nodeList.at(i)->setPos(w*i, h - (val*h));
|
||||
nodeList.at(i)->verticalMove(true);
|
||||
}
|
||||
|
||||
curveUpdating = false;
|
||||
|
||||
emit curveUpdated(points, (double)0);
|
||||
}
|
||||
|
||||
|
||||
@ -205,8 +256,10 @@ void MixerCurveWidget::resizeEvent(QResizeEvent* event)
|
||||
|
||||
void MixerCurveWidget::itemMoved(double itemValue)
|
||||
{
|
||||
QList<double> list = getCurve();
|
||||
emit curveUpdated(list, itemValue);
|
||||
if (!curveUpdating) {
|
||||
QList<double> list = getCurve();
|
||||
emit curveUpdated(list, itemValue);
|
||||
}
|
||||
}
|
||||
|
||||
void MixerCurveWidget::setMin(double value)
|
||||
@ -217,6 +270,14 @@ void MixerCurveWidget::setMax(double value)
|
||||
{
|
||||
curveMax = value;
|
||||
}
|
||||
double MixerCurveWidget::getMin()
|
||||
{
|
||||
return curveMin;
|
||||
}
|
||||
double MixerCurveWidget::getMax()
|
||||
{
|
||||
return curveMax;
|
||||
}
|
||||
void MixerCurveWidget::setRange(double min, double max)
|
||||
{
|
||||
curveMin = min;
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include <QGraphicsView>
|
||||
#include <QtSvg/QSvgRenderer>
|
||||
#include <QtSvg/QGraphicsSvgItem>
|
||||
#include <QtCore/QPointer>
|
||||
#include "mixercurvepoint.h"
|
||||
#include "mixercurveline.h"
|
||||
#include "uavobjectwidgetutils_global.h"
|
||||
@ -45,12 +46,16 @@ public:
|
||||
void itemMoved(double itemValue); // Callback when a point is moved, to be updated
|
||||
void initCurve (QList<double> points);
|
||||
QList<double> getCurve();
|
||||
void initLinearCurve(quint32 numPoints, double maxValue);
|
||||
void initLinearCurve(quint32 numPoints, double maxValue = 1, double minValue = 0);
|
||||
void setCurve(QList<double>);
|
||||
void setMin(double value);
|
||||
double getMin();
|
||||
void setMax(double value);
|
||||
double getMax();
|
||||
void setRange(double min, double max);
|
||||
|
||||
static const int NODE_NUMELEM = 5;
|
||||
|
||||
signals:
|
||||
void curveUpdated(QList<double>, double );
|
||||
|
||||
@ -58,9 +63,19 @@ private slots:
|
||||
|
||||
private:
|
||||
QGraphicsSvgItem *plot;
|
||||
|
||||
QList<Node*> nodePool;
|
||||
QList<Edge*> edgePool;
|
||||
QList<Node*> nodeList;
|
||||
QList<double> points;
|
||||
|
||||
double curveMin;
|
||||
double curveMax;
|
||||
bool curveUpdating;
|
||||
|
||||
void initNodes(int numPoints);
|
||||
Node* getNode(int index);
|
||||
Edge* getEdge(int index, Node* sourceNode, Node* destNode);
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent *event);
|
||||
|
Loading…
x
Reference in New Issue
Block a user