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

Last change on this file since 88 was 88, checked in by Sanahuja Guillaume, 6 years ago

m

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