OpenASIP 2.2
Loading...
Searching...
No Matches
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
39using std::string;
40
41BEGIN_EVENT_TABLE(MemoryValueDialog, wxDialog)
44
45/**
46 * Constructor.
47 *
48 * @param parent Parent window.
49 * @param pos Position of the dialog.
50 */
51MemoryValueDialog::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 */
65
66/**
67 * Returns the mode of the number control.
68 *
69 * @return The mode.
70 */
71long
73 return value_->mode();
74}
75
76/**
77 * Sets the value.
78 *
79 * @param value Value to be set.
80 */
81void
83 value_->setValue(value);
84}
85
86/**
87 * Returns the value user typed.
88 *
89 * @return User given value.
90 */
91int
95
96/**
97 * Returns the value user typed.
98 *
99 * @return User given value as double.
100 */
101double
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 */
111void
112MemoryValueDialog::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 */
136wxSizer*
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}
END_EVENT_TABLE() using namespace IDF
EVT_BUTTON(ID_EDIT_ARCH_PORT, FUImplementationDialog::onEditArchitecturePort) EVT_BUTTON(ID_ADD_EXTERNAL_PORT
static std::string toBinary(unsigned int source, unsigned int stringWidth=0)
wxSizer * createContents(wxWindow *parent, bool call_fit, bool set_sizer)
unsigned maxBits_
Maximum number of bits used by the returned value.
void onOK(wxCommandEvent &event)
NumberControl * value_
NumberControl for giving new values to memory.
void setValue(int value)
int intValue() const
static const long MODE_UNSIGNED
Style flag for unsigned integer mode availability.
static const long MODE_FLOAT
Style flag for float mode availability.
double doubleValue() const
void setValue(const ULongWord value)
static const long MODE_BINARY
Style flag for binary mode availability.
long mode() const
static const long MODE_HEXADECIMAL
Style flag for hexadecimal mode availability.
static wxString toWxString(const std::string &source)