source: flair-src/trunk/tools/Controller/Mavlink/src/GuiInterface.cpp@ 413

Last change on this file since 413 was 318, checked in by Sanahuja Guillaume, 5 years ago
File size: 5.5 KB
Line 
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 <FrameworkManager.h>
21#include <Thread.h>
22
23#include <Tab.h>
24#include <TabWidget.h>
25#include <DoubleSpinBox.h>
26#include <PushButton.h>
27#include <GroupBox.h>
28#include <ListWidget.h>
29#include <Label.h>
30#include <ComboBox.h>
31
32#include <string>
33#include <sstream>
34
35using namespace flair::core;
36using namespace flair::gui;
37using namespace std;
38
39GuiInterface::GuiInterface(string name)
40 : Thread(getFrameworkManager(), name, 6),
41 mainTab(new Tab(getFrameworkManager()->GetTabWidget(), name)) {
42
43 tabWidget = new TabWidget(mainTab->NewRow(), name);
44
45 // Main tab
46 Tab* settingsTab = new Tab(tabWidget, "Settings");
47
48 // Controls group
49 controlsGroupBox = new GroupBox(settingsTab->NewRow(), "Controls");
50 btnStartMission = new PushButton(controlsGroupBox->LastRowLastCol(), "Start mission");
51 btnStopMission = new PushButton(controlsGroupBox->LastRowLastCol(), "Stop mission");
52 btnPauseMission = new PushButton(controlsGroupBox->LastRowLastCol(), "Pause mission");
53
54 // Add cmd group
55 addCmdGroupBox = new GroupBox(settingsTab->NewRow(), "Add mission command");
56 // commandLabel = new Label(addCmdGroupBox->NewRow(), "Command label");
57 // commandLabel->SetText("Command");
58 // param1Label = new Label(addCmdGroupBox->LastRowLastCol(), "Param1 label");
59 // commandLabel->SetText("Param1");
60 // param2Label = new Label(addCmdGroupBox->LastRowLastCol(), "Param2 label");
61 // commandLabel->SetText("Param2");
62 // param3Label = new Label(addCmdGroupBox->LastRowLastCol(), "Param3 label");
63 // commandLabel->SetText("Param3");
64 comboCmd = new ComboBox(addCmdGroupBox->NewRow(), "Select command");
65 // Fill the ComboBox
66 for (auto &command : commandsAvailable) {
67 comboCmd->AddItem(command);
68 }
69 // comboCmd->AddItem("WAYPOINT");
70 // comboCmd->AddItem("TAKEOFF");
71 // comboCmd->AddItem("LAND");
72 // comboCmd->AddItem("RETURN");
73 // comboCmd->AddItem("JUMP");
74 param1Field = new DoubleSpinBox(addCmdGroupBox->NewRow(), "Param1", -90, 90, 0.5, 1, 0);
75 latitudeField = new DoubleSpinBox(addCmdGroupBox->LastRowLastCol(), "Longitude", -90, 90, 0.5, 1, 1.5);
76 param2Field = new DoubleSpinBox(addCmdGroupBox->NewRow(), "Param2", -90, 90, 0.5, 1, 0);
77 longitudeField = new DoubleSpinBox(addCmdGroupBox->LastRowLastCol(), "Latitude", -90, 90, 0.5, 1, -1.5);
78 param3Field = new DoubleSpinBox(addCmdGroupBox->NewRow(), "Param3", -90, 90, 0.5, 1, 0);
79 altitudeField = new DoubleSpinBox(addCmdGroupBox->LastRowLastCol(), "Altitude", -90, 90, 0.5, 1, 2);
80 btnAddMissionCmd = new PushButton(addCmdGroupBox->NewRow(), "Add mission cmd");
81 btnDelMissionCmd = new PushButton(addCmdGroupBox->LastRowLastCol(), "Del mission cmd");
82 btnSendMission = new PushButton(addCmdGroupBox->LastRowLastCol(), "Send mission");
83
84 // Show wpt group
85 showItemsGroupBox = new GroupBox(settingsTab->NewRow(), "Show mission items");
86 listMissionItems = new ListWidget(showItemsGroupBox->NewRow(), "Mission cmd list");
87
88 // listEntranceWpt = new ListWidget(showWptGroupBox->LastRowLastCol(), "Entrance wpt");
89 // listExitWpt = new ListWidget(showWptGroupBox->LastRowLastCol(), "Exit wpt");
90 // btnRemoveMissionWpt = new PushButton(showWptGroupBox->NewRow(), "Remove mission wpt");
91 // btnRemoveEntranceWpt = new PushButton(showWptGroupBox->LastRowLastCol(), "Remove entrance wpt");
92 // btnRemoveExitWpt = new PushButton(showWptGroupBox->LastRowLastCol(), "Remove exit wpt");
93
94 // // Action wpt group
95 // actionWptGroupBox = new GroupBox(settingsTab->NewRow(), "Action");
96 // btnSendWpt = new PushButton(actionWptGroupBox->NewRow(), "Send wpt");
97 // btnClearWpt = new PushButton(actionWptGroupBox->LastRowLastCol(), "Clear wpt");
98 // btnLoop = new PushButton(actionWptGroupBox->LastRowLastCol(), "Loop");
99
100 //TODO IP & PORT from config.h file
101 // sendSocket = new Socket((Thread *)this, "send socket", "127.0.0.1:5000");
102}
103
104GuiInterface::~GuiInterface() {
105}
106
107void GuiInterface::Run() {
108 Thread::Info("Debug: enter MavPlanner acquisition loop\n");
109
110 if (getFrameworkManager()->ErrorOccured()) {
111 SafeStop();
112 Thread::Err("An error occurred, we don't launch the Run loop.\n");
113 }
114
115 while (!ToBeStopped()) {
116 // TODO : time from config.h
117 Thread::SleepMS(500);
118 // Buttons to control GUI
119 if (btnAddMissionCmd->Clicked()) {
120 listMissionItems->AddItem(MissionCmdGet());
121 }
122 if (btnDelMissionCmd->Clicked()) {
123 listMissionItems->RemoveItem();
124 }
125 // Buttons to send commands
126 if (btnStartMission->Clicked()) {
127 MissionStart();
128 }
129 if (btnStopMission->Clicked()) {
130 MissionStop();
131 }
132 if (btnPauseMission->Clicked()) {
133 MissionPause();
134 }
135 if (btnSendMission->Clicked()) {
136 MissionSend();
137 }
138 }
139}
140
141std::string GuiInterface::MissionCmdGet() {
142 std::ostringstream stringStream;
143 stringStream.precision(1);
144 stringStream << fixed;
145 stringStream << commandsAvailable[comboCmd->CurrentIndex()] << "|" << param1Field->Value() << "|" << param2Field->Value() \
146 << "|" << param3Field->Value() << "|" << latitudeField->Value() << "|" << longitudeField->Value() << "|" << altitudeField->Value();
147 return stringStream.str();
148}
Note: See TracBrowser for help on using the repository browser.