source: flair-src/branches/mavlink/tools/Controller/Mavlink/src/GuiInterface.cpp@ 76

Last change on this file since 76 was 71, checked in by Thomas Fuhrmann, 5 years ago

Add class for MavlinkPlanner

File size: 4.7 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
32#include <string>
33#include <sstream>
34
35using namespace flair::core;
36using namespace flair::gui;
37using namespace std;
38
39GuiInterface::GuiInterface(const FrameworkManager *parent, string name)
40 : Thread(parent, name, 6),
41 mainTab(new Tab(parent->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 btnInitialize = new PushButton(controlsGroupBox->LastRowLastCol(), "Initialize");
51 btnStartMission = new PushButton(controlsGroupBox->LastRowLastCol(), "Start mission");
52 btnStopMission = new PushButton(controlsGroupBox->LastRowLastCol(), "Stop mission");
53 btnKill = new PushButton(controlsGroupBox->LastRowLastCol(), "Kill");
54
55 // Add wpt group
56 addWptGroupBox = new GroupBox(settingsTab->NewRow(), "Add waypoint");
57 latField = new DoubleSpinBox(addWptGroupBox->NewRow(), "Latitude",
58 -90, 90, 0.001, 3, 3);
59 lonField = new DoubleSpinBox(addWptGroupBox->LastRowLastCol(), "Longitude",
60 -180, 180, 0.001, 3, 3);
61 btnAddMissionWpt = new PushButton(addWptGroupBox->NewRow(), "Add mission wpt");
62 btnAddEntranceWpt = new PushButton(addWptGroupBox->LastRowLastCol(), "Add entrance wpt");
63 btnAddExitWpt = new PushButton(addWptGroupBox->LastRowLastCol(), "Add exit wpt");
64
65 // Show wpt group
66 showWptGroupBox = new GroupBox(settingsTab->NewRow(), "Show waypoints");
67 listMissionWpt = new ListWidget(showWptGroupBox->NewRow(), "Mission wpt");
68 listEntranceWpt = new ListWidget(showWptGroupBox->LastRowLastCol(), "Entrance wpt");
69 listExitWpt = new ListWidget(showWptGroupBox->LastRowLastCol(), "Exit wpt");
70 btnRemoveMissionWpt = new PushButton(showWptGroupBox->NewRow(), "Remove mission wpt");
71 btnRemoveEntranceWpt = new PushButton(showWptGroupBox->LastRowLastCol(), "Remove entrance wpt");
72 btnRemoveExitWpt = new PushButton(showWptGroupBox->LastRowLastCol(), "Remove exit wpt");
73
74 // Action wpt group
75 actionWptGroupBox = new GroupBox(settingsTab->NewRow(), "Action");
76 btnSendWpt = new PushButton(actionWptGroupBox->NewRow(), "Send wpt");
77 btnClearWpt = new PushButton(actionWptGroupBox->LastRowLastCol(), "Clear wpt");
78 btnLoop = new PushButton(actionWptGroupBox->LastRowLastCol(), "Loop");
79
80 //TODO IP & PORT from config.h file
81 sendSocket = new Socket((Thread *)this, "send socket", "127.0.0.1:5000");
82}
83
84GuiInterface::~GuiInterface() {
85}
86
87void GuiInterface::Run() {
88 Thread::Info("Debug: enter MavPlanner acquisition loop\n");
89
90 if (getFrameworkManager()->ErrorOccured()) {
91 SafeStop();
92 Thread::Err("An error occurred, we don't launch the Run loop.\n");
93 }
94
95 while (!ToBeStopped()) {
96 // TODO : time from config.h
97 Thread::SleepMS(500);
98 // Buttons to control GUI
99 if (btnAddMissionWpt->Clicked()) {
100 listMissionWpt->AddItem(GetWptLatLon());
101 }
102 if (btnAddEntranceWpt->Clicked()) {
103 listEntranceWpt->AddItem(GetWptLatLon());
104 }
105 if (btnAddExitWpt->Clicked()) {
106 listExitWpt->AddItem(GetWptLatLon());
107 }
108 if (btnRemoveMissionWpt->Clicked()) {
109 listMissionWpt->RemoveItem();
110 }
111 if (btnRemoveEntranceWpt->Clicked()) {
112 listEntranceWpt->RemoveItem();
113 }
114 if (btnRemoveExitWpt->Clicked()) {
115 listExitWpt->RemoveItem();
116 }
117 // Buttons to send commands
118 if (btnInitialize->Clicked()) {
119 MissionInitialize();
120 }
121 if (btnStartMission->Clicked()) {
122 MissionStart();
123 }
124 if (btnStopMission->Clicked()) {
125 MissionStop();
126 }
127 if (btnKill->Clicked()) {
128 MissionKill();
129 }
130 if (btnSendWpt->Clicked()) {
131 WptSend();
132 }
133 if (btnClearWpt->Clicked()) {
134 WptClear();
135 }
136 if (btnLoop->Clicked()) {
137 WptLoopSend();
138 }
139 }
140}
141
142std::string GuiInterface::GetWptLatLon() {
143 std::ostringstream stringStream;
144 stringStream.precision(3);
145 stringStream << fixed;
146 stringStream << latField->Value() << " - " << lonField->Value();
147 return stringStream.str();
148}
149
Note: See TracBrowser for help on using the repository browser.