[10] | 1 | // %flair:license{
|
---|
[15] | 2 | // This file is part of the Flair framework distributed under the
|
---|
| 3 | // CECILL-C License, Version 1.0.
|
---|
[10] | 4 | // %flair:license}
|
---|
[7] | 5 | // created: 2014/04/11
|
---|
| 6 | // filename: UavMultiplex_impl.cpp
|
---|
| 7 | //
|
---|
| 8 | // author: Guillaume Sanahuja
|
---|
| 9 | // Copyright Heudiasyc UMR UTC/CNRS 7253
|
---|
| 10 | //
|
---|
| 11 | // version: $Id: $
|
---|
| 12 | //
|
---|
| 13 | // purpose: Class defining uav multiplexing
|
---|
| 14 | //
|
---|
| 15 | //
|
---|
| 16 | /*********************************************************************/
|
---|
| 17 |
|
---|
| 18 | #include "UavMultiplex_impl.h"
|
---|
| 19 | #include "UavMultiplex.h"
|
---|
| 20 | #include <cvmatrix.h>
|
---|
| 21 | #include <FrameworkManager.h>
|
---|
| 22 | #include <TabWidget.h>
|
---|
| 23 | #include <Tab.h>
|
---|
| 24 | #include <GridLayout.h>
|
---|
| 25 | #include <ComboBox.h>
|
---|
| 26 | #include <GroupBox.h>
|
---|
| 27 | #include <sstream>
|
---|
| 28 |
|
---|
| 29 | using std::string;
|
---|
| 30 | using std::ostringstream;
|
---|
| 31 | using namespace flair::core;
|
---|
| 32 | using namespace flair::gui;
|
---|
| 33 | using namespace flair::filter;
|
---|
| 34 |
|
---|
[137] | 35 | UavMultiplex_impl::UavMultiplex_impl(UavMultiplex *self, std::string name) {
|
---|
[15] | 36 | input = new cvmatrix(self, 7, 1, floatType);
|
---|
| 37 | multiplexcombobox = NULL;
|
---|
| 38 | this->self = self;
|
---|
[7] | 39 |
|
---|
[15] | 40 | // station sol
|
---|
[137] | 41 | main_tab = new Tab(getFrameworkManager()->GetTabWidget(), name);
|
---|
[15] | 42 | tabwidget = new TabWidget(main_tab->NewRow(), "UavMultiplex");
|
---|
| 43 | setup_tab = new Tab(tabwidget, "Setup");
|
---|
[7] | 44 | }
|
---|
| 45 |
|
---|
[15] | 46 | UavMultiplex_impl::~UavMultiplex_impl(void) {
|
---|
| 47 | delete main_tab;
|
---|
| 48 | if (multiplexcombobox != NULL)
|
---|
| 49 | free(multiplexcombobox);
|
---|
[7] | 50 | }
|
---|
| 51 |
|
---|
[15] | 52 | void UavMultiplex_impl::SetMultiplexComboBox(string name, int index) {
|
---|
| 53 | // we do not know motorcount at constructor time, so allocation is done here
|
---|
| 54 | if (multiplexcombobox == NULL) {
|
---|
| 55 | multiplexcombobox =
|
---|
| 56 | (ComboBox **)malloc(self->MotorsCount() * sizeof(ComboBox *));
|
---|
| 57 | for (int i = 0; i < self->MotorsCount(); i++)
|
---|
| 58 | multiplexcombobox[i] = NULL;
|
---|
| 59 | groupbox = new GroupBox(setup_tab->NewRow(), "motor attribution");
|
---|
| 60 | }
|
---|
| 61 | if (index > self->MotorsCount()) {
|
---|
| 62 | self->Err("index out of bound %i/%i\n", index, self->MotorsCount());
|
---|
| 63 | return;
|
---|
| 64 | }
|
---|
| 65 | if (multiplexcombobox[index] != NULL) {
|
---|
| 66 | self->Err("index already setup\n");
|
---|
| 67 | return;
|
---|
| 68 | }
|
---|
[7] | 69 |
|
---|
[15] | 70 | multiplexcombobox[index] =
|
---|
| 71 | new ComboBox(groupbox->At(index / 4, index % 4), name);
|
---|
[7] | 72 |
|
---|
[15] | 73 | for (int i = 0; i < self->MotorsCount(); i++) {
|
---|
| 74 | ostringstream oss;
|
---|
| 75 | oss << i;
|
---|
| 76 | multiplexcombobox[index]->AddItem(oss.str());
|
---|
| 77 | }
|
---|
[7] | 78 | }
|
---|
| 79 |
|
---|
[15] | 80 | int UavMultiplex_impl::MultiplexValue(int index) const {
|
---|
| 81 | if (multiplexcombobox[index] != NULL) {
|
---|
| 82 | return multiplexcombobox[index]->CurrentIndex();
|
---|
| 83 | } else {
|
---|
| 84 | self->Err("multiplex not setup for motor %i\n", index);
|
---|
| 85 | return 0;
|
---|
| 86 | }
|
---|
[7] | 87 | }
|
---|