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

Last change on this file since 15 was 15, checked in by Bayard Gildas, 5 years ago

sources reformatted with flair-format-dir script

File size: 2.5 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(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
47UavMultiplex_impl::~UavMultiplex_impl(void) {
48  delete main_tab;
49  if (multiplexcombobox != NULL)
50    free(multiplexcombobox);
51}
52
53void 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
81int 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}
Note: See TracBrowser for help on using the repository browser.