OpenASIP  2.0
MemoryValueDialog.cc
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2009 Tampere University.
3 
4  This file is part of TTA-Based Codesign Environment (TCE).
5 
6  Permission is hereby granted, free of charge, to any person obtaining a
7  copy of this software and associated documentation files (the "Software"),
8  to deal in the Software without restriction, including without limitation
9  the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  and/or sell copies of the Software, and to permit persons to whom the
11  Software is furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  DEALINGS IN THE SOFTWARE.
23  */
24 /**
25  * @file MemoryValueDialog.cc
26  *
27  * Definition of MemoryValueDialog class.
28  *
29  * @author Jussi Nykänen 2004 (nykanen-no.spam-cs.tut.fi)
30  * @note rating: red
31  */
32 
33 #include "MemoryValueDialog.hh"
34 #include "NumberControl.hh"
35 #include "InformationDialog.hh"
36 #include "Conversion.hh"
37 #include "WxConversion.hh"
38 
39 using std::string;
40 
41 BEGIN_EVENT_TABLE(MemoryValueDialog, wxDialog)
44 
45 /**
46  * Constructor.
47  *
48  * @param parent Parent window.
49  * @param pos Position of the dialog.
50  */
51 MemoryValueDialog::MemoryValueDialog(wxWindow* parent, unsigned maxBits) :
52  wxDialog(parent, -1, _T("Memory value"), wxDefaultPosition,
53  wxDefaultSize),
54  maxBits_(maxBits) {
55 
56  createContents(this, true, true);
57  value_ = dynamic_cast<NumberControl*>(FindWindow(ID_VALUE));
58 }
59 
60 /**
61  * Destructor.
62  */
64 }
65 
66 /**
67  * Returns the mode of the number control.
68  *
69  * @return The mode.
70  */
71 long
73  return value_->mode();
74 }
75 
76 /**
77  * Sets the value.
78  *
79  * @param value Value to be set.
80  */
81 void
83  value_->setValue(value);
84 }
85 
86 /**
87  * Returns the value user typed.
88  *
89  * @return User given value.
90  */
91 int
93  return value_->intValue();
94 }
95 
96 /**
97  * Returns the value user typed.
98  *
99  * @return User given value as double.
100  */
101 double
103  return value_->doubleValue();
104 }
105 
106 /**
107  * Event handler for the OK button.
108  *
109  * Checks that the value doesn't use more than maximum number of bits allowed.
110  */
111 void
112 MemoryValueDialog::onOK(wxCommandEvent&) {
113 
114  std::string binary = Conversion::toBinary(intValue());
115  if (binary.length() > maxBits_) {
116  wxString message = _T("Bit width of the value exceeds the maximum");
117  message.Append(_T(" bit width of "));
118  message.Append(WxConversion::toWxString(maxBits_));
119  message.Append(_T("."));
120  InformationDialog dialog(this, message);
121  dialog.ShowModal();
122  return;
123  }
124 
125  EndModal(wxID_OK);
126 }
127 
128 /**
129  * Creates the contents of the dialog.
130  *
131  * @param parent The parent window.
132  * @param call_fit If true fits the contents inside the dialog.
133  * @param set_sizer If true sets the main sizer as dialog contents.
134  * @return The created sizer.
135  */
136 wxSizer*
138  wxWindow* parent,
139  bool call_fit,
140  bool set_sizer) {
141 
142  wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL );
143 
144  wxWindow *item1 = new NumberControl(
145  parent, ID_VALUE, wxDefaultPosition,
146  wxSize(240, -1), NumberControl::MODE_BINARY |
149 
150  item0->Add( item1, 0, wxALIGN_CENTER|wxALL, 5 );
151 
152  wxBoxSizer *item2 = new wxBoxSizer( wxHORIZONTAL );
153 
154  wxButton *item3 = new wxButton( parent, wxID_OK, wxT("OK"), wxDefaultPosition, wxDefaultSize, 0 );
155  item2->Add( item3, 0, wxALIGN_CENTER|wxALL, 5 );
156 
157  wxButton *item4 = new wxButton( parent, wxID_CANCEL, wxT("Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
158  item2->Add( item4, 0, wxALIGN_CENTER|wxALL, 5 );
159 
160  item0->Add( item2, 0, wxALIGN_CENTER|wxALL, 5 );
161 
162  if (set_sizer)
163  {
164  parent->SetSizer( item0 );
165  if (call_fit)
166  item0->SetSizeHints( parent );
167  }
168 
169  return item0;
170 }
MemoryValueDialog::intValue
int intValue()
Definition: MemoryValueDialog.cc:92
WxConversion::toWxString
static wxString toWxString(const std::string &source)
MemoryValueDialog::maxBits_
unsigned maxBits_
Maximum number of bits used by the returned value.
Definition: MemoryValueDialog.hh:69
MemoryValueDialog::ID_VALUE
@ ID_VALUE
Definition: MemoryValueDialog.hh:63
MemoryValueDialog::value_
NumberControl * value_
NumberControl for giving new values to memory.
Definition: MemoryValueDialog.hh:67
NumberControl::setValue
void setValue(const ULongWord value)
Definition: NumberControl.cc:381
MemoryValueDialog::createContents
wxSizer * createContents(wxWindow *parent, bool call_fit, bool set_sizer)
Definition: MemoryValueDialog.cc:137
FindWindow
Definition: FindWindow.hh:49
NumberControl::mode
long mode() const
Definition: NumberControl.cc:764
Conversion::toBinary
static std::string toBinary(unsigned int source, unsigned int stringWidth=0)
Definition: Conversion.cc:155
NumberControl::intValue
int intValue() const
Definition: NumberControl.cc:417
NumberControl::doubleValue
double doubleValue() const
Definition: NumberControl.cc:450
NumberControl.hh
Conversion.hh
InformationDialog.hh
MemoryValueDialog::setValue
void setValue(int value)
Definition: MemoryValueDialog.cc:82
MemoryValueDialog.hh
MemoryValueDialog
Definition: MemoryValueDialog.hh:44
NumberControl::MODE_UNSIGNED
static const long MODE_UNSIGNED
Style flag for unsigned integer mode availability.
Definition: NumberControl.hh:98
NumberControl::MODE_HEXADECIMAL
static const long MODE_HEXADECIMAL
Style flag for hexadecimal mode availability.
Definition: NumberControl.hh:100
MemoryValueDialog::onOK
void onOK(wxCommandEvent &event)
Definition: MemoryValueDialog.cc:112
EVT_BUTTON
EVT_BUTTON(ID_EDIT_ARCH_PORT, FUImplementationDialog::onEditArchitecturePort) EVT_BUTTON(ID_ADD_EXTERNAL_PORT
MemoryValueDialog::mode
long mode()
Definition: MemoryValueDialog.cc:72
NumberControl::MODE_BINARY
static const long MODE_BINARY
Style flag for binary mode availability.
Definition: NumberControl.hh:94
NumberControl
Definition: NumberControl.hh:59
WxConversion.hh
InformationDialog
Definition: InformationDialog.hh:42
MemoryValueDialog::~MemoryValueDialog
virtual ~MemoryValueDialog()
Definition: MemoryValueDialog.cc:63
NumberControl::MODE_FLOAT
static const long MODE_FLOAT
Style flag for float mode availability.
Definition: NumberControl.hh:102
MemoryValueDialog::doubleValue
double doubleValue()
Definition: MemoryValueDialog.cc:102
END_EVENT_TABLE
END_EVENT_TABLE() using namespace IDF
Memory
Definition: Memory.hh:74