Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
wxMatrixPanel.cpp
1 /*
2  * wxMatrixPanel.cpp
3  *
4  * Created on: Jun 25, 2010
5  * Author: ischiller
6  */
7 
8 #include "wxMatrixPanel.hh"
9 #include <Gui/StringConv.hh>
10 #include <sstream>
11 
12 using namespace std;
13 
14 namespace BIAS {
15 
16 /*
17 ===============================================================================
18 wxMatrixPanel
19 ===============================================================================
20  */
21 
22 wxMatrixPanel::wxMatrixPanel(wxWindow* parent, wxWindowID id, bool editable)
23 : wxPanel(parent, id)
24 {
25  editable_ = editable;
26  rows_ = 0;
27  cols_ = 0;
28 }
29 
31 {
32  // need to re-create controls?
33  if ((int)matrix.GetRows() != rows_ || (int)matrix.GetCols() != cols_)
34  {
35  controls_.clear();
36  DestroyChildren();
37  wxSizer* sizer = new wxFlexGridSizer(matrix.GetCols(), matrix.GetRows(), 0, 0);
38  SetSizer(sizer);
39 
40  rows_ = matrix.GetRows();
41  cols_ = matrix.GetCols();
42 
43  for (int i = 0; i < rows_; i++)
44  {
45  for (int j = 0; j < cols_; j++)
46  {
47  wxTextCtrl* control = new wxTextCtrl(this, GetId());
48  control->SetEditable(editable_);
49  sizer->Add(control);
50  controls_.push_back(control);
51  }
52  }
53  }
54 
55  // fill controls
56  int index = 0;
57  for (int i = 0; i < rows_; i++)
58  {
59  for (int j = 0; j < cols_; j++, index++)
60  {
61  //if (index < (int)controls_.size() && FindFocus() == controls_[index])
62  //{
63  stringstream str;
64  str << matrix[i][j];
65  controls_[index]->SetValue(AsciiToWx(str.str()));
66  //}
67  }
68  }
69 }
70 
72 {
73  Matrix<double> matrix(rows_, cols_);
74  int index = 0;
75  for (int i = 0; i < rows_; i++)
76  {
77  for (int j = 0; j < cols_; j++, index++)
78  {
79  stringstream str(WxToAscii(controls_[index]->GetValue()));
80  str >> matrix[i][j];
81  }
82  }
83  return matrix;
84 }
85 
86 }
wxString AsciiToWx(const char *thestring)
Converts a C string to a wxString.
Definition: StringConv.hh:32
unsigned int GetRows() const
Definition: Matrix.hh:202
void SetMatrix(const Matrix< double > &matrix)
unsigned int GetCols() const
Definition: Matrix.hh:204
Matrix< double > GetMatrix()