dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
magicwaypointgadgetwidget.cpp
Go to the documentation of this file.
1 
12 /*
13  * This program is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 3 of the License, or
16  * (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful, but
19  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  * for more details.
22  *
23  * You should have received a copy of the GNU General Public License along
24  * with this program; if not, see <http://www.gnu.org/licenses/>
25  */
27 #include "ui_magicwaypoint.h"
28 
29 #include <QDebug>
30 #include <QString>
31 #include <QStringList>
32 #include <QWidget>
33 #include <QTextEdit>
34 #include <QVBoxLayout>
35 #include <QPushButton>
36 
37 #include "uavobjects/uavobject.h"
39 #include "manualcontrolcommand.h"
42 
44  : QLabel(parent)
45 {
46  m_magicwaypoint = new Ui_MagicWaypoint();
47  m_magicwaypoint->setupUi(this);
48 
49  // Connect object updated event from UAVObject to also update check boxes
50  connect(getPathDesired(), SIGNAL(objectUpdated(UAVObject *)), this,
51  SLOT(pathDesiredChanged(UAVObject *)));
52  connect(getPositionActual(), SIGNAL(objectUpdated(UAVObject *)), this,
54 
55  // Connect updates from the position widget to this widget
56  connect(m_magicwaypoint->widgetPosition, SIGNAL(positionClicked(double, double)), this,
57  SLOT(positionSelected(double, double)));
58  connect(this, SIGNAL(positionActualObjectChanged(double, double)),
59  m_magicwaypoint->widgetPosition, SLOT(updateActualIndicator(double, double)));
60  connect(this, SIGNAL(positionDesiredObjectChanged(double, double)),
61  m_magicwaypoint->widgetPosition, SLOT(updateDesiredIndicator(double, double)));
62 
63  // Catch changes in scale for visualization
64  connect(m_magicwaypoint->horizontalSliderScale, SIGNAL(valueChanged(int)), this,
65  SLOT(scaleChanged(int)));
66 
67  // Make sure the scale is correctly visualized
68  m_magicwaypoint->horizontalSliderScale->setValue(10);
69 }
70 
72 {
73  // Do nothing
74 }
75 
80 PathDesired *MagicWaypointGadgetWidget::getPathDesired()
81 {
82  ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
83  UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
84  PathDesired *obj = PathDesired::GetInstance(objManager);
85  Q_ASSERT(obj != NULL); // Save crashes later
86  return obj;
87 }
88 
92 PositionActual *MagicWaypointGadgetWidget::getPositionActual()
93 {
94  ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
95  UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
96  PositionActual *obj = PositionActual::GetInstance(objManager);
97  Q_ASSERT(obj != NULL);
98  return obj;
99 }
100 
105 {
106  Q_UNUSED(scale);
107  pathDesiredChanged(getPathDesired());
108  positionActualChanged(getPositionActual());
109 }
110 
115 {
116  PositionActual::DataFields positionActual = getPositionActual()->getData();
117  double scale = m_magicwaypoint->horizontalSliderScale->value();
118 
119  emit positionActualObjectChanged(positionActual.North / scale, positionActual.East / scale);
120 }
121 
126 {
127  PathDesired::DataFields pathDesired = getPathDesired()->getData();
128  double scale = m_magicwaypoint->horizontalSliderScale->value();
129 
130  emit positionDesiredObjectChanged(pathDesired.End[PathDesired::END_NORTH] / scale,
131  pathDesired.End[PathDesired::END_EAST] / scale);
132 }
133 
137 void MagicWaypointGadgetWidget::positionSelected(double north, double east)
138 {
139  double scale = m_magicwaypoint->horizontalSliderScale->value();
140 
141  PathDesired::DataFields pathDesired = getPathDesired()->getData();
142  pathDesired.End[PathDesired::END_NORTH] = north * scale;
143  pathDesired.End[PathDesired::END_EAST] = east * scale;
144  pathDesired.Mode = PathDesired::MODE_ENDPOINT;
145  getPathDesired()->setData(pathDesired);
146 }
147 
MagicWaypointGadgetWidget(QWidget *parent=nullptr)
Core plugin system that manages the plugins, their life cycle and their registered objects...
Definition: pluginmanager.h:53
void positionDesiredObjectChanged(double north, double east)
void positionSelected(double north, double east)
void positionActualObjectChanged(double north, double east)