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: 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 |
|
---|
35 | UavMultiplex_impl::UavMultiplex_impl(const FrameworkManager *parent,
|
---|
36 | UavMultiplex *self, std::string name) {
|
---|
37 | input = new cvmatrix(self, 7, 1, floatType);
|
---|
38 | multiplexcombobox = NULL;
|
---|
39 | this->self = self;
|
---|
40 |
|
---|
41 | // station sol
|
---|
42 | main_tab = new Tab(parent->GetTabWidget(), name);
|
---|
43 | tabwidget = new TabWidget(main_tab->NewRow(), "UavMultiplex");
|
---|
44 | setup_tab = new Tab(tabwidget, "Setup");
|
---|
45 | }
|
---|
46 |
|
---|
47 | UavMultiplex_impl::~UavMultiplex_impl(void) {
|
---|
48 | delete main_tab;
|
---|
49 | if (multiplexcombobox != NULL)
|
---|
50 | free(multiplexcombobox);
|
---|
51 | }
|
---|
52 |
|
---|
53 | void UavMultiplex_impl::SetMultiplexComboBox(string name, int index) {
|
---|
54 | // we do not know motorcount at constructor time, so allocation is done here
|
---|
55 | if (multiplexcombobox == NULL) {
|
---|
56 | multiplexcombobox =
|
---|
57 | (ComboBox **)malloc(self->MotorsCount() * sizeof(ComboBox *));
|
---|
58 | for (int i = 0; i < self->MotorsCount(); i++)
|
---|
59 | multiplexcombobox[i] = NULL;
|
---|
60 | groupbox = new GroupBox(setup_tab->NewRow(), "motor attribution");
|
---|
61 | }
|
---|
62 | if (index > self->MotorsCount()) {
|
---|
63 | self->Err("index out of bound %i/%i\n", index, self->MotorsCount());
|
---|
64 | return;
|
---|
65 | }
|
---|
66 | if (multiplexcombobox[index] != NULL) {
|
---|
67 | self->Err("index already setup\n");
|
---|
68 | return;
|
---|
69 | }
|
---|
70 |
|
---|
71 | multiplexcombobox[index] =
|
---|
72 | new ComboBox(groupbox->At(index / 4, index % 4), name);
|
---|
73 |
|
---|
74 | for (int i = 0; i < self->MotorsCount(); i++) {
|
---|
75 | ostringstream oss;
|
---|
76 | oss << i;
|
---|
77 | multiplexcombobox[index]->AddItem(oss.str());
|
---|
78 | }
|
---|
79 | }
|
---|
80 |
|
---|
81 | int UavMultiplex_impl::MultiplexValue(int index) const {
|
---|
82 | if (multiplexcombobox[index] != NULL) {
|
---|
83 | return multiplexcombobox[index]->CurrentIndex();
|
---|
84 | } else {
|
---|
85 | self->Err("multiplex not setup for motor %i\n", index);
|
---|
86 | return 0;
|
---|
87 | }
|
---|
88 | }
|
---|