source: flair-src/trunk/lib/FlairFilter/src/UavMultiplex_impl.cpp@ 137

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

singleton manager

File size: 2.4 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: 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
29using std::string;
30using std::ostringstream;
31using namespace flair::core;
32using namespace flair::gui;
33using namespace flair::filter;
34
35UavMultiplex_impl::UavMultiplex_impl(UavMultiplex *self, std::string name) {
36 input = new cvmatrix(self, 7, 1, floatType);
37 multiplexcombobox = NULL;
38 this->self = self;
39
40 // station sol
41 main_tab = new Tab(getFrameworkManager()->GetTabWidget(), name);
42 tabwidget = new TabWidget(main_tab->NewRow(), "UavMultiplex");
43 setup_tab = new Tab(tabwidget, "Setup");
44}
45
46UavMultiplex_impl::~UavMultiplex_impl(void) {
47 delete main_tab;
48 if (multiplexcombobox != NULL)
49 free(multiplexcombobox);
50}
51
52void 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 }
69
70 multiplexcombobox[index] =
71 new ComboBox(groupbox->At(index / 4, index % 4), name);
72
73 for (int i = 0; i < self->MotorsCount(); i++) {
74 ostringstream oss;
75 oss << i;
76 multiplexcombobox[index]->AddItem(oss.str());
77 }
78}
79
80int 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 }
87}
Note: See TracBrowser for help on using the repository browser.