dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
pathplannergadgetwidget.cpp
Go to the documentation of this file.
1 
11 /*
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful, but
18  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20  * for more details.
21  *
22  * You should have received a copy of the GNU General Public License along
23  * with this program; if not, see <http://www.gnu.org/licenses/>
24  */
26 #include "waypointdialog.h"
27 #include "waypointdelegate.h"
28 #include "ui_pathplanner.h"
29 #include <QFileDialog>
30 #include <QString>
31 #include <QStringList>
32 #include <QWidget>
33 #include <QTextEdit>
34 #include <QVBoxLayout>
35 #include <QPushButton>
36 
37 #include "algorithms/pathfillet.h"
39 
41  : QLabel(parent)
42  , prevModel(NULL)
43 {
44  ui = new Ui_PathPlanner();
45  ui->setupUi(this);
46  ui->statusTL->setVisible(false);
47  ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
48  FlightDataModel *model = pm->getObject<FlightDataModel>();
49  Q_ASSERT(model);
50 
51  QItemSelectionModel *selection = pm->getObject<QItemSelectionModel>();
52  Q_ASSERT(selection);
53  setModel(model, selection);
54 }
55 
57 {
58  // Do nothing
59 }
60 
61 void PathPlannerGadgetWidget::setModel(FlightDataModel *model, QItemSelectionModel *selection)
62 {
63  proxy = new ModelUavoProxy(this, model);
64 
65  this->model = model;
66  this->selection = selection;
67 
68  ui->tableView->setModel(model);
69  ui->tableView->setSelectionModel(selection);
70  ui->tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
71 
72  ui->tableView->setItemDelegate(new WaypointDelegate(this));
73  ui->tableView->resizeColumnsToContents();
74 
75  ui->tableView->resizeColumnsToContents();
76 
77  connect(proxy, &ModelUavoProxy::sendPathPlanToUavProgress, this,
78  &PathPlannerGadgetWidget::on_waypointSendProgress);
79 }
80 
81 void PathPlannerGadgetWidget::on_tbAdd_clicked()
82 {
83  ui->tableView->model()->insertRow(ui->tableView->model()->rowCount());
84 }
85 
86 void PathPlannerGadgetWidget::on_tbDelete_clicked()
87 {
88  // XXX: TODO: Should delete all selected rows
89  ui->tableView->model()->removeRow(ui->tableView->selectionModel()->currentIndex().row());
90 }
91 
92 void PathPlannerGadgetWidget::on_tbInsert_clicked()
93 {
94  ui->tableView->model()->insertRow(ui->tableView->selectionModel()->currentIndex().row());
95 }
96 
97 void PathPlannerGadgetWidget::on_tbReadFromFile_clicked()
98 {
99  if (!model)
100  return;
101  QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"));
102  model->readFromFile(fileName);
103 }
104 
105 void PathPlannerGadgetWidget::on_tbSaveToFile_clicked()
106 {
107  if (!model)
108  return;
109  QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"));
110  model->writeToFile(fileName);
111 }
112 
118 void PathPlannerGadgetWidget::on_tbDetails_clicked()
119 {
120  ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
121  Q_ASSERT(pm);
122  if (pm == NULL)
123  return;
124 
125  WaypointDialog *dialog = pm->getObject<WaypointDialog>();
126  Q_ASSERT(dialog);
127  dialog->show();
128 }
129 
134 void PathPlannerGadgetWidget::on_tbSendToUAV_clicked()
135 {
136  enableButtons(false);
137  ui->statusTL->setVisible(false);
138  ui->statusPB->setValue(0);
139  bool result;
140  result = proxy->modelToObjects();
141  if (result)
142  ui->statusTL->setText("All waypoints were sent successfully");
143  else
144  ui->statusTL->setText("WARNING: Not all waypoints were sent successfully");
145  ui->statusTL->setVisible(true);
146  enableButtons(true);
147 }
148 
153 void PathPlannerGadgetWidget::on_tbFetchFromUAV_clicked()
154 {
155  proxy->objectsToModel();
156  ui->tableView->resizeColumnsToContents();
157 }
158 
162 void PathPlannerGadgetWidget::on_tbFilletPath_clicked()
163 {
164  // Create a copy of the model before filleting
165  if (!prevModel)
166  prevModel = new FlightDataModel(this);
167  Q_ASSERT(prevModel);
168  if (prevModel)
169  prevModel->replaceData(model);
170 
171  IPathAlgorithm *algo = new PathFillet(this);
172  // Only process is successfully configured and the verification of the model succeeds
173  QString err;
174  if (algo->configure(this) && algo->verifyPath(model, err)) {
175  // If unsuccessful delete the cached model
176  if (!algo->processPath(model)) {
177  delete prevModel;
178  prevModel = NULL;
179  }
180  }
181 }
182 
186 void PathPlannerGadgetWidget::on_tbUnfilletPath_clicked()
187 {
188  if (prevModel)
189  model->replaceData(prevModel);
190 }
191 
192 void PathPlannerGadgetWidget::on_waypointSendProgress(int value)
193 {
194  ui->statusPB->setValue(value);
195 }
196 
197 void PathPlannerGadgetWidget::enableButtons(bool enable)
198 {
199  QList<QToolButton *> blist = this->findChildren<QToolButton *>();
200  foreach (QToolButton *button, blist) {
201  button->setEnabled(enable);
202  }
203 }
204 
virtual bool configure(QWidget *callingUi=nullptr)=0
Core plugin system that manages the plugins, their life cycle and their registered objects...
Definition: pluginmanager.h:53
void sendPathPlanToUavProgress(int percent)
bool writeToFile(QString filename)
FlightDataModel::writeToFile Write the waypoints to an xml file.
virtual bool processPath(FlightDataModel *model)=0
The WaypointDialog class creates a dialog for editing the properties of a single waypoint.
bool modelToObjects()
Cast from the internal representation to the UAVOs.
void readFromFile(QString fileName)
FlightDataModel::readFromFile Read into the model from a flight plan xml file.
The WaypointDelegate class is used to handle updating the values in the mode combo box to the data mo...
bool replaceData(FlightDataModel *newModel)
Replace a model data with another model.
void setModel(FlightDataModel *model, QItemSelectionModel *selection)
PathPlannerGadgetWidget(QWidget *parent=nullptr)
Definition: icore.h:39
virtual bool verifyPath(FlightDataModel *model, QString &err)=0
void objectsToModel()
Cast from the UAVOs to the internal representation.
Algorithm to add filtets to path.