// %flair:license{ // This file is part of the Flair framework distributed under the // CECILL-C License, Version 1.0. // %flair:license} // created: 2016/09/02 // filename: GuiInterface.cpp // // authors: Thomas Fuhrmann // Copyright Heudiasyc UMR UTC/CNRS 7253 // // version: $Id: $ // // purpose: Create the GUI and give an abstract interface to it // // /*********************************************************************/ #include "GuiInterface.h" #include #include #include #include #include #include #include #include #include #include #include #include using namespace flair::core; using namespace flair::gui; using namespace std; GuiInterface::GuiInterface(const FrameworkManager *parent, string name) : Thread(parent, name, 6), mainTab(new Tab(parent->GetTabWidget(), name)) { tabWidget = new TabWidget(mainTab->NewRow(), name); // Main tab Tab* settingsTab = new Tab(tabWidget, "Settings"); // Controls group controlsGroupBox = new GroupBox(settingsTab->NewRow(), "Controls"); btnInitialize = new PushButton(controlsGroupBox->LastRowLastCol(), "Initialize"); btnStartMission = new PushButton(controlsGroupBox->LastRowLastCol(), "Start mission"); btnStopMission = new PushButton(controlsGroupBox->LastRowLastCol(), "Stop mission"); btnKill = new PushButton(controlsGroupBox->LastRowLastCol(), "Kill"); // Add wpt group addWptGroupBox = new GroupBox(settingsTab->NewRow(), "Add waypoint"); latField = new DoubleSpinBox(addWptGroupBox->NewRow(), "Latitude", -90, 90, 0.001, 3, 3); lonField = new DoubleSpinBox(addWptGroupBox->LastRowLastCol(), "Longitude", -180, 180, 0.001, 3, 3); btnAddMissionWpt = new PushButton(addWptGroupBox->NewRow(), "Add mission wpt"); btnAddEntranceWpt = new PushButton(addWptGroupBox->LastRowLastCol(), "Add entrance wpt"); btnAddExitWpt = new PushButton(addWptGroupBox->LastRowLastCol(), "Add exit wpt"); // Show wpt group showWptGroupBox = new GroupBox(settingsTab->NewRow(), "Show waypoints"); listMissionWpt = new ListWidget(showWptGroupBox->NewRow(), "Mission wpt"); listEntranceWpt = new ListWidget(showWptGroupBox->LastRowLastCol(), "Entrance wpt"); listExitWpt = new ListWidget(showWptGroupBox->LastRowLastCol(), "Exit wpt"); btnRemoveMissionWpt = new PushButton(showWptGroupBox->NewRow(), "Remove mission wpt"); btnRemoveEntranceWpt = new PushButton(showWptGroupBox->LastRowLastCol(), "Remove entrance wpt"); btnRemoveExitWpt = new PushButton(showWptGroupBox->LastRowLastCol(), "Remove exit wpt"); // Action wpt group actionWptGroupBox = new GroupBox(settingsTab->NewRow(), "Action"); btnSendWpt = new PushButton(actionWptGroupBox->NewRow(), "Send wpt"); btnClearWpt = new PushButton(actionWptGroupBox->LastRowLastCol(), "Clear wpt"); btnLoop = new PushButton(actionWptGroupBox->LastRowLastCol(), "Loop"); //TODO IP & PORT from config.h file sendSocket = new Socket((Thread *)this, "send socket", "127.0.0.1:5000"); } GuiInterface::~GuiInterface() { } void GuiInterface::Run() { Thread::Info("Debug: enter MavPlanner acquisition loop\n"); if (getFrameworkManager()->ErrorOccured()) { SafeStop(); Thread::Err("An error occurred, we don't launch the Run loop.\n"); } while (!ToBeStopped()) { // TODO : time from config.h Thread::SleepMS(500); // Buttons to control GUI if (btnAddMissionWpt->Clicked()) { listMissionWpt->AddItem(GetWptLatLon()); } if (btnAddEntranceWpt->Clicked()) { listEntranceWpt->AddItem(GetWptLatLon()); } if (btnAddExitWpt->Clicked()) { listExitWpt->AddItem(GetWptLatLon()); } if (btnRemoveMissionWpt->Clicked()) { listMissionWpt->RemoveItem(); } if (btnRemoveEntranceWpt->Clicked()) { listEntranceWpt->RemoveItem(); } if (btnRemoveExitWpt->Clicked()) { listExitWpt->RemoveItem(); } // Buttons to send commands if (btnInitialize->Clicked()) { MissionInitialize(); } if (btnStartMission->Clicked()) { MissionStart(); } if (btnStopMission->Clicked()) { MissionStop(); } if (btnKill->Clicked()) { MissionKill(); } if (btnSendWpt->Clicked()) { WptSend(); } if (btnClearWpt->Clicked()) { WptClear(); } if (btnLoop->Clicked()) { WptLoopSend(); } } } std::string GuiInterface::GetWptLatLon() { std::ostringstream stringStream; stringStream.precision(3); stringStream << fixed; stringStream << latField->Value() << " - " << lonField->Value(); return stringStream.str(); }