Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
wxVectorPanel.cpp
1 /* This file is part of the BIAS library (Basic ImageAlgorithmS).
2 
3  Copyright (C) 2003-2009 (see file CONTACT for details)
4  Multimediale Systeme der Informationsverarbeitung
5  Institut fuer Informatik
6  Christian-Albrechts-Universitaet Kiel
7 
8  BIAS is free software; you can redistribute it and/or modify
9  it under the terms of the GNU Lesser General Public License as published by
10  the Free Software Foundation; either version 2.1 of the License, or
11  (at your option) any later version.
12 
13  BIAS is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public License
19  along with BIAS; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
21 
22 /*
23  * wxVectorPanel.cpp
24  *
25  * Created on: Jun 25, 2010
26  * Author: ischiller
27  */
28 
29 #include "wxVectorPanel.hh"
30 #include <Gui/StringConv.hh>
31 #include <sstream>
32 
33 #ifdef WIN32
34 # pragma warning (disable: 4005) //M_PI redefinition
35 #endif
36 
37 using namespace std;
38 
39 namespace BIAS {
40 
41 /*
42 ===============================================================================
43 wxVectorPanel
44 ===============================================================================
45 */
46 
47 wxVectorPanel::wxVectorPanel(wxWindow* parent, wxWindowID id, bool editable)
48  : wxPanel(parent, id)
49 {
50  editable_ = editable;
51 }
52 
54 {
55  // need to re-create controls?
56  if (vector.Size() != controls_.size())
57  {
58  controls_.clear();
59  DestroyChildren();
60  wxSizer* sizer = new wxFlexGridSizer(vector.Size(), 1, 0, 0);
61  SetSizer(sizer);
62 
63  for (int i = 0; i < (int)vector.Size(); i++)
64  {
65  wxTextCtrl* control = new wxTextCtrl(this, GetId(), _T(""),
66  wxDefaultPosition, wxDefaultSize,
67  wxTE_PROCESS_ENTER);
68  control->SetEditable(editable_);
69  sizer->Add(control);
70  controls_.push_back(control);
71  }
72  }
73 
74  // fill controls
75  for (int i = 0; i < (int)vector.Size(); i++)
76  {
77  //instead of using this blocking technique when focused
78  //use TEXT_ENTER event which occures when enter is pressed
79  //within the TextCtr.
80  //if (FindFocus() == controls_[i]) continue;
81 
82  stringstream str;
83  str << vector[i];
84  controls_[i]->SetValue(AsciiToWx(str.str()));
85  }
86 }
87 
89 {
90  Vector<double> v(controls_.size());
91  for (int i = 0; i < (int)controls_.size(); i++)
92  {
93  stringstream str(WxToAscii(controls_[i]->GetValue()));
94  str >> v[i];
95  }
96  return v;
97 }
98 
99 
100 }
wxString AsciiToWx(const char *thestring)
Converts a C string to a wxString.
Definition: StringConv.hh:32
unsigned int Size() const
length of the vector
Definition: Vector.hh:143
BIAS::Vector< double > GetVector() const
void SetVector(const BIAS::Vector< double > &vector)