[88] | 1 | // %flair:license{
|
---|
| 2 | // This file is part of the Flair framework distributed under the
|
---|
| 3 | // CECILL-C License, Version 1.0.
|
---|
| 4 | // %flair:license}
|
---|
| 5 | // created: 2016/09/02
|
---|
| 6 | // filename: GuiInterface.cpp
|
---|
| 7 | //
|
---|
| 8 | // authors: Thomas Fuhrmann
|
---|
| 9 | // Copyright Heudiasyc UMR UTC/CNRS 7253
|
---|
| 10 | //
|
---|
| 11 | // version: $Id: $
|
---|
| 12 | //
|
---|
| 13 | // purpose: Create the GUI and give an abstract interface to it
|
---|
| 14 | //
|
---|
| 15 | //
|
---|
| 16 | /*********************************************************************/
|
---|
| 17 |
|
---|
| 18 | #include "GuiInterface.h"
|
---|
| 19 |
|
---|
| 20 | #include <cvmatrix.h>
|
---|
| 21 | #include <FrameworkManager.h>
|
---|
| 22 | #include <Thread.h>
|
---|
| 23 |
|
---|
| 24 | #include <Tab.h>
|
---|
| 25 | #include <TabWidget.h>
|
---|
| 26 | #include <DoubleSpinBox.h>
|
---|
| 27 | #include <PushButton.h>
|
---|
| 28 | #include <GroupBox.h>
|
---|
| 29 | #include <ListWidget.h>
|
---|
| 30 | #include <Label.h>
|
---|
| 31 | #include <ComboBox.h>
|
---|
| 32 |
|
---|
| 33 | #include <string>
|
---|
| 34 | #include <sstream>
|
---|
| 35 |
|
---|
| 36 | using namespace flair::core;
|
---|
| 37 | using namespace flair::gui;
|
---|
| 38 | using namespace std;
|
---|
| 39 |
|
---|
[137] | 40 | GuiInterface::GuiInterface(string name)
|
---|
| 41 | : Thread(getFrameworkManager(), name, 6),
|
---|
| 42 | mainTab(new Tab(getFrameworkManager()->GetTabWidget(), name)) {
|
---|
[88] | 43 |
|
---|
| 44 | tabWidget = new TabWidget(mainTab->NewRow(), name);
|
---|
| 45 |
|
---|
| 46 | // Main tab
|
---|
| 47 | Tab* settingsTab = new Tab(tabWidget, "Settings");
|
---|
| 48 |
|
---|
| 49 | // Controls group
|
---|
| 50 | controlsGroupBox = new GroupBox(settingsTab->NewRow(), "Controls");
|
---|
| 51 | btnStartMission = new PushButton(controlsGroupBox->LastRowLastCol(), "Start mission");
|
---|
| 52 | btnStopMission = new PushButton(controlsGroupBox->LastRowLastCol(), "Stop mission");
|
---|
| 53 | btnPauseMission = new PushButton(controlsGroupBox->LastRowLastCol(), "Pause mission");
|
---|
| 54 |
|
---|
| 55 | // Add cmd group
|
---|
| 56 | addCmdGroupBox = new GroupBox(settingsTab->NewRow(), "Add mission command");
|
---|
| 57 | // commandLabel = new Label(addCmdGroupBox->NewRow(), "Command label");
|
---|
| 58 | // commandLabel->SetText("Command");
|
---|
| 59 | // param1Label = new Label(addCmdGroupBox->LastRowLastCol(), "Param1 label");
|
---|
| 60 | // commandLabel->SetText("Param1");
|
---|
| 61 | // param2Label = new Label(addCmdGroupBox->LastRowLastCol(), "Param2 label");
|
---|
| 62 | // commandLabel->SetText("Param2");
|
---|
| 63 | // param3Label = new Label(addCmdGroupBox->LastRowLastCol(), "Param3 label");
|
---|
| 64 | // commandLabel->SetText("Param3");
|
---|
| 65 | comboCmd = new ComboBox(addCmdGroupBox->NewRow(), "Select command");
|
---|
| 66 | // Fill the ComboBox
|
---|
| 67 | for (auto &command : commandsAvailable) {
|
---|
| 68 | comboCmd->AddItem(command);
|
---|
| 69 | }
|
---|
| 70 | // comboCmd->AddItem("WAYPOINT");
|
---|
| 71 | // comboCmd->AddItem("TAKEOFF");
|
---|
| 72 | // comboCmd->AddItem("LAND");
|
---|
| 73 | // comboCmd->AddItem("RETURN");
|
---|
| 74 | // comboCmd->AddItem("JUMP");
|
---|
| 75 | param1Field = new DoubleSpinBox(addCmdGroupBox->NewRow(), "Param1", -90, 90, 0.5, 1, 0);
|
---|
| 76 | latitudeField = new DoubleSpinBox(addCmdGroupBox->LastRowLastCol(), "Longitude", -90, 90, 0.5, 1, 1.5);
|
---|
| 77 | param2Field = new DoubleSpinBox(addCmdGroupBox->NewRow(), "Param2", -90, 90, 0.5, 1, 0);
|
---|
| 78 | longitudeField = new DoubleSpinBox(addCmdGroupBox->LastRowLastCol(), "Latitude", -90, 90, 0.5, 1, -1.5);
|
---|
| 79 | param3Field = new DoubleSpinBox(addCmdGroupBox->NewRow(), "Param3", -90, 90, 0.5, 1, 0);
|
---|
| 80 | altitudeField = new DoubleSpinBox(addCmdGroupBox->LastRowLastCol(), "Altitude", -90, 90, 0.5, 1, 2);
|
---|
| 81 | btnAddMissionCmd = new PushButton(addCmdGroupBox->NewRow(), "Add mission cmd");
|
---|
| 82 | btnDelMissionCmd = new PushButton(addCmdGroupBox->LastRowLastCol(), "Del mission cmd");
|
---|
| 83 | btnSendMission = new PushButton(addCmdGroupBox->LastRowLastCol(), "Send mission");
|
---|
| 84 |
|
---|
| 85 | // Show wpt group
|
---|
| 86 | showItemsGroupBox = new GroupBox(settingsTab->NewRow(), "Show mission items");
|
---|
| 87 | listMissionItems = new ListWidget(showItemsGroupBox->NewRow(), "Mission cmd list");
|
---|
| 88 |
|
---|
| 89 | // listEntranceWpt = new ListWidget(showWptGroupBox->LastRowLastCol(), "Entrance wpt");
|
---|
| 90 | // listExitWpt = new ListWidget(showWptGroupBox->LastRowLastCol(), "Exit wpt");
|
---|
| 91 | // btnRemoveMissionWpt = new PushButton(showWptGroupBox->NewRow(), "Remove mission wpt");
|
---|
| 92 | // btnRemoveEntranceWpt = new PushButton(showWptGroupBox->LastRowLastCol(), "Remove entrance wpt");
|
---|
| 93 | // btnRemoveExitWpt = new PushButton(showWptGroupBox->LastRowLastCol(), "Remove exit wpt");
|
---|
| 94 |
|
---|
| 95 | // // Action wpt group
|
---|
| 96 | // actionWptGroupBox = new GroupBox(settingsTab->NewRow(), "Action");
|
---|
| 97 | // btnSendWpt = new PushButton(actionWptGroupBox->NewRow(), "Send wpt");
|
---|
| 98 | // btnClearWpt = new PushButton(actionWptGroupBox->LastRowLastCol(), "Clear wpt");
|
---|
| 99 | // btnLoop = new PushButton(actionWptGroupBox->LastRowLastCol(), "Loop");
|
---|
| 100 |
|
---|
| 101 | //TODO IP & PORT from config.h file
|
---|
| 102 | // sendSocket = new Socket((Thread *)this, "send socket", "127.0.0.1:5000");
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | GuiInterface::~GuiInterface() {
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | void GuiInterface::Run() {
|
---|
| 109 | Thread::Info("Debug: enter MavPlanner acquisition loop\n");
|
---|
| 110 |
|
---|
| 111 | if (getFrameworkManager()->ErrorOccured()) {
|
---|
| 112 | SafeStop();
|
---|
| 113 | Thread::Err("An error occurred, we don't launch the Run loop.\n");
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | while (!ToBeStopped()) {
|
---|
| 117 | // TODO : time from config.h
|
---|
| 118 | Thread::SleepMS(500);
|
---|
| 119 | // Buttons to control GUI
|
---|
| 120 | if (btnAddMissionCmd->Clicked()) {
|
---|
| 121 | listMissionItems->AddItem(MissionCmdGet());
|
---|
| 122 | }
|
---|
| 123 | if (btnDelMissionCmd->Clicked()) {
|
---|
| 124 | listMissionItems->RemoveItem();
|
---|
| 125 | }
|
---|
| 126 | // Buttons to send commands
|
---|
| 127 | if (btnStartMission->Clicked()) {
|
---|
| 128 | MissionStart();
|
---|
| 129 | }
|
---|
| 130 | if (btnStopMission->Clicked()) {
|
---|
| 131 | MissionStop();
|
---|
| 132 | }
|
---|
| 133 | if (btnPauseMission->Clicked()) {
|
---|
| 134 | MissionPause();
|
---|
| 135 | }
|
---|
| 136 | if (btnSendMission->Clicked()) {
|
---|
| 137 | MissionSend();
|
---|
| 138 | }
|
---|
| 139 | }
|
---|
| 140 | }
|
---|
| 141 |
|
---|
| 142 | std::string GuiInterface::MissionCmdGet() {
|
---|
| 143 | std::ostringstream stringStream;
|
---|
| 144 | stringStream.precision(1);
|
---|
| 145 | stringStream << fixed;
|
---|
| 146 | stringStream << commandsAvailable[comboCmd->CurrentIndex()] << "|" << param1Field->Value() << "|" << param2Field->Value() \
|
---|
| 147 | << "|" << param3Field->Value() << "|" << latitudeField->Value() << "|" << longitudeField->Value() << "|" << altitudeField->Value();
|
---|
| 148 | return stringStream.str();
|
---|
| 149 | }
|
---|