OpenASIP 2.2
Loading...
Searching...
No Matches
OutputOperandDialog.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 OutputOperandDialog.cc
26 *
27 * Definition of OutputOperandDialog class.
28 *
29 * @author Jussi Nykänen 2004 (nykanen-no.spam-cs.tut.fi)
30 * @author Tero Ryynänen 2008 (tero.ryynanen-no.spam-tut.fi)
31 * @note rating: red
32 */
33
34#include <string>
35#include <wx/valgen.h>
36#include <boost/format.hpp>
37
39#include "OSEdTextGenerator.hh"
40#include "GUITextGenerator.hh"
41#include "WxConversion.hh"
42#include "WidgetTools.hh"
43#include "DialogPosition.hh"
44#include "Operand.hh"
45#include "ObjectState.hh"
46#include "SimValue.hh"
47
48using std::string;
49using boost::format;
50
51BEGIN_EVENT_TABLE(OutputOperandDialog, wxDialog)
53
54 EVT_CHOICE(ID_OPERATION_OUTPUT_TYPES, OutputOperandDialog::onType)
55 EVT_SPINCTRL(ID_ELEMENT_WIDTH, OutputOperandDialog::onElementWidth)
56 EVT_CHOICE(ID_ELEMENT_COUNT, OutputOperandDialog::onElementCount)
58
59/**
60 * Constructor.
61 *
62 * @param parent Parent window.
63 * @param operand Operand to be added or modified.
64 * @param index Index of the operand.
65 */
67 wxWindow* parent,
68 Operand* operand,
69 int index) :
70 wxDialog(parent, -1, _T(""),
71 DialogPosition::getPosition(DialogPosition::DIALOG_OUTPUT_OPERAND)),
72 operand_(operand), memData_(false), index_(index) {
73
74 memData_ = operand_->isMemoryData();
75 createContents(this, true, true);
76
77 outputTypesComboBox_ =
78 dynamic_cast<wxChoice*>(FindWindow(ID_OPERATION_OUTPUT_TYPES));
79
80 elementWidthSpinCtrl_ =
81 dynamic_cast<wxSpinCtrl*>(FindWindow(ID_ELEMENT_WIDTH));
82
83 elementCountChoice_ =
84 dynamic_cast<wxChoice*>(FindWindow(ID_ELEMENT_COUNT));
85
86 FindWindow(ID_MEM_DATA)->SetValidator(wxGenericValidator(&memData_));
87
88 outputTypes_.push_back(Operand::SINT_WORD_STRING);
89 outputTypes_.push_back(Operand::UINT_WORD_STRING);
90 outputTypes_.push_back(Operand::FLOAT_WORD_STRING);
91 outputTypes_.push_back(Operand::DOUBLE_WORD_STRING);
92 outputTypes_.push_back(Operand::HALF_FLOAT_WORD_STRING);
93 outputTypes_.push_back(Operand::BOOL_STRING);
94 outputTypes_.push_back(Operand::RAW_DATA_STRING);
95 outputTypes_.push_back(Operand::SLONG_WORD_STRING);
96 outputTypes_.push_back(Operand::ULONG_WORD_STRING);
97
98 operandTypes_.insert(operandPair(0, Operand::SINT_WORD));
99 operandTypes_.insert(operandPair(1, Operand::UINT_WORD));
100 operandTypes_.insert(operandPair(2, Operand::FLOAT_WORD));
101 operandTypes_.insert(operandPair(3, Operand::DOUBLE_WORD));
102 operandTypes_.insert(operandPair(4, Operand::HALF_FLOAT_WORD));
103 operandTypes_.insert(operandPair(5, Operand::BOOL));
104 operandTypes_.insert(operandPair(6, Operand::RAW_DATA));
105 operandTypes_.insert(operandPair(7, Operand::SLONG_WORD));
106 operandTypes_.insert(operandPair(8, Operand::ULONG_WORD));
107
108 FindWindow(wxID_OK)->SetFocus();
109
110 type_ = operand_->type();
111 elemWidth_ = operand_->elementWidth();
112 elemCount_ = operand_->elementCount();
113 updateTypes();
114 updateElementWidths();
115 updateElementCounts();
116
117 setTexts();
118}
119
120/**
121 * Destructor.
122 */
124 int x, y;
125 GetPosition(&x, &y);
126 wxPoint point(x, y);
128}
129
130/**
131 * Event handler for operand type choice box.
132**/
133void
135
136 type_ = outputTypesComboBox_->GetSelection();
137
138 Operand::OperandType operType = static_cast<Operand::OperandType>(type_);
140 elemCount_ = 1;
143}
144
145/**
146 * Event handler for element width spin ctrl.
147**/
148void
150 elemWidth_ = elementWidthSpinCtrl_->GetValue();
151 // update choice box list cells
153}
154
155/**
156 * Event handler for element count choice box.
157**/
158void
160 // get the current choice box value and convert it to integer
161 int index = elementCountChoice_->GetSelection();
162 wxString number = elementCountChoice_->GetString(index);
163 long value;
164 if(!number.ToLong(&value)) {
165 elemCount_ = 1;
166 return;
167 }
168
169 // save current choice
170 elemCount_ = static_cast<int>(value);
171 // update spin ctrl range
173}
174
175/**
176 * Updates the type lists.
177 */
178void
180
181 outputTypesComboBox_->Clear();
182
183 for (unsigned int i = 0; i < outputTypes_.size(); i++) {
184 wxString oper = WxConversion::toWxString(outputTypes_.at(i));
185 outputTypesComboBox_->Append(oper);
186 }
187
188 outputTypesComboBox_->SetSelection(type_);
189
190}
191
192/**
193 * Updates the element width choice box list.
194**/
195void
197
198 Operand::OperandType operType = static_cast<Operand::OperandType>(type_);
199
200 if (operType == Operand::RAW_DATA) {
201 // element width for raw data can be arbitrary up to the max width
202 int elemWidth = 1;
203 int lastValidWidth = 1;
204 while (elemCount_*elemWidth <= SIMD_WORD_WIDTH) {
205 lastValidWidth = elemWidth;
206 elemWidth *= 2;
207 }
208
209 // degrade current element width if it is too big
210 if (elemWidth_ > lastValidWidth) {
211 elemWidth_ = lastValidWidth;
212 }
213 elementWidthSpinCtrl_->SetRange(1, lastValidWidth);
215 } else if (operType == Operand::SINT_WORD || operType == Operand::UINT_WORD) {
216 // element width for integers is 8 to 32
217 elementWidthSpinCtrl_->SetRange(8, 32);
219 } else {
220 // element width for other types is their default type width
223 }
224}
225
226/**
227 * Updates the element count choice box list.
228**/
229void
231
232 elementCountChoice_->Clear();
233
234 // update the list so that only shorter or equal than SIMD_WORD_WIDTH
235 // width*count combinations are listed
236 int elemCount = 1;
237 int elemCountIndex = 0;
238 while (elemCount*elemWidth_ <= SIMD_WORD_WIDTH) {
239 if (elemCount < elemCount_) {
240 ++elemCountIndex;
241 }
243 elemCount *= 2;
244 }
245 elementCountChoice_->SetSelection(elemCountIndex);
246}
247
248/**
249 * Set texts to widgets.
250 */
251void
253
256
257 // title
258 format fmt =
260 fmt % index_;
261 SetTitle(WxConversion::toWxString(fmt.str()));
262
263 // buttons
264 WidgetTools::setLabel(&guiText, FindWindow(wxID_OK),
266
267 WidgetTools::setLabel(&guiText, FindWindow(wxID_CANCEL),
269
270 // check boxes
273}
274
275/**
276 * Handles the event when OK button is pushed.
277 */
278void
280 TransferDataFromWindow();
281 ObjectState* root = new ObjectState("");
283
284 int selected = outputTypesComboBox_->GetSelection();
285 Operand::OperandType type = operandTypes_[selected];
286
287 switch(type)
288 {
291 break;
294 break;
297 break;
300 break;
302 root->setAttribute(
304 break;
305 case Operand::BOOL:
307 break;
310 break;
312 root->setAttribute(
314 break;
316 root->setAttribute(
318 break;
319 default:
321 break;
322 }
323
326
329
330 operand_->loadState(root);
331 delete root;
332 EndModal(wxID_OK);
333}
334
335/**
336 * Creates the contents of the dialog.
337 *
338 * NOTE! This function was generated by wxDesigner. This is why it may be
339 * ugly.
340 *
341 * @param parent Parent window.
342 * @param call_fit If true fits the contents inside the dialog.
343 * @param set_sizer If true, sets the main sizer as dialog contents.
344 * @return The created sizer.
345 */
346wxSizer*
348 wxWindow *parent,
349 bool call_fit,
350 bool set_sizer) {
351
352 wxBoxSizer *item0 = new wxBoxSizer(wxVERTICAL);
353
354 wxBoxSizer *item1 = new wxBoxSizer(wxHORIZONTAL);
355
356 wxString strs9[] =
357 {
358 wxT("id: 1")
359 };
360
361 // Choice for input operand types
362 wxChoice *itemOutputTypes = new wxChoice(parent, ID_OPERATION_OUTPUT_TYPES, wxDefaultPosition, wxSize(100,-1), 1, strs9);
363 item1->Add(itemOutputTypes, 0, wxALIGN_CENTER|wxALL, 5);
364
365 wxStaticText *itemTextWidth = new wxStaticText(parent, ID_TEXT_WIDTH, wxT("Element width:"), wxDefaultPosition, wxDefaultSize, 0);
366 item1->Add(itemTextWidth, 0, wxALIGN_CENTER|wxALL, 5);
367 wxSpinCtrl *itemElemWidth = new wxSpinCtrl(parent, ID_ELEMENT_WIDTH, wxT(""), wxDefaultPosition, wxSize(-1,-1), 1);
368 item1->Add(itemElemWidth, 0, wxALIGN_CENTER|wxALL, 5);
369 wxStaticText *itemTextCount = new wxStaticText(parent, ID_TEXT_COUNT, wxT("Element count:"), wxDefaultPosition, wxDefaultSize, 0);
370 item1->Add(itemTextCount, 0, wxALIGN_CENTER|wxALL, 5);
371 wxChoice *itemElemCount = new wxChoice(parent, ID_ELEMENT_COUNT, wxDefaultPosition, wxSize(70,-1), 1, strs9);
372 item1->Add(itemElemCount, 0, wxALIGN_CENTER|wxALL, 5);
373
374 wxBoxSizer *item1b = new wxBoxSizer(wxHORIZONTAL);
375 wxCheckBox *item3 = new wxCheckBox(parent, ID_MEM_DATA, wxT("Memory data"), wxDefaultPosition, wxDefaultSize, 0);
376 item1b->Add(item3, 0, wxALIGN_CENTER|wxALL, 5);
377
378 item0->Add(item1, 0, wxALIGN_CENTER|wxALL, 5);
379 item0->Add(item1b, 0, wxALIGN_CENTER|wxALL, 5);
380
381 wxBoxSizer *item4 = new wxBoxSizer(wxHORIZONTAL);
382
383 wxButton *item5 = new wxButton(parent, wxID_OK, wxT("&OK"), wxDefaultPosition, wxDefaultSize, 0);
384 item4->Add(item5, 0, wxALIGN_CENTER|wxALL, 5);
385
386 wxButton *item6 = new wxButton(parent, wxID_CANCEL, wxT("&Cancel"), wxDefaultPosition, wxDefaultSize, 0);
387 item4->Add(item6, 0, wxALIGN_CENTER|wxALL, 5);
388
389 item0->Add(item4, 0, wxALIGN_CENTER|wxALL, 5);
390
391 if (set_sizer)
392 {
393 parent->SetSizer(item0);
394 if (call_fit)
395 item0->SetSizeHints(parent);
396 }
397
398 return item0;
399}
END_EVENT_TABLE() using namespace IDF
EVT_BUTTON(ID_EDIT_ARCH_PORT, FUImplementationDialog::onEditArchitecturePort) EVT_BUTTON(ID_ADD_EXTERNAL_PORT
find Finds info of the inner loops in the false
std::pair< int, Operand::OperandType > operandPair
#define SIMD_WORD_WIDTH
Definition SimValue.hh:42
static void setPosition(Dialogs dialog, wxPoint point)
@ DIALOG_OUTPUT_OPERAND
Output operand dialog.
@ TXT_BUTTON_CANCEL
Label for cancel button.
@ TXT_BUTTON_OK
Label for OK button.
static GUITextGenerator * instance()
static OSEdTextGenerator & instance()
@ TXT_OUTPUT_OPERAND_DIALOG_TITLE
Output operand dialog title.
@ TXT_CHECKBOX_MEM_DATA
Memory data label.
void setAttribute(const std::string &name, const std::string &value)
static const std::string FLOAT_WORD_STRING
Definition Operand.hh:75
static const std::string OPRND_ELEM_WIDTH
Object state name for element width.
Definition Operand.hh:98
static const std::string SLONG_WORD_STRING
Definition Operand.hh:70
virtual int index() const
Definition Operand.cc:135
static const std::string OPRND_TYPE
Object state name for operand type.
Definition Operand.hh:84
static int defaultElementWidth(OperandType type)
Definition Operand.cc:557
static const std::string OPRND_MEM_ADDRESS
Object state name for memory address.
Definition Operand.hh:86
static const std::string OPRND_ELEM_COUNT
Object state name for element count.
Definition Operand.hh:100
static const std::string HALF_FLOAT_WORD_STRING
Definition Operand.hh:74
static const std::string BOOL_STRING
Definition Operand.hh:77
static const std::string DOUBLE_WORD_STRING
Definition Operand.hh:76
OperandType
Definition Operand.hh:58
@ SLONG_WORD
Definition Operand.hh:66
@ FLOAT_WORD
Definition Operand.hh:61
@ ULONG_WORD
Definition Operand.hh:67
@ RAW_DATA
Definition Operand.hh:65
@ SINT_WORD
Definition Operand.hh:59
@ DOUBLE_WORD
Definition Operand.hh:62
@ UINT_WORD
Definition Operand.hh:60
@ HALF_FLOAT_WORD
Definition Operand.hh:63
static const std::string ULONG_WORD_STRING
Definition Operand.hh:71
static const std::string OPRND_MEM_DATA
Object state name for memory data.
Definition Operand.hh:90
static const std::string OPRND_ID
Object state name for operand id.
Definition Operand.hh:82
static const std::string UINT_WORD_STRING
Definition Operand.hh:73
static const std::string RAW_DATA_STRING
Definition Operand.hh:78
static const std::string SINT_WORD_STRING
Definition Operand.hh:72
virtual void loadState(const ObjectState *state)
Definition Operand.cc:383
void onElementWidth(wxSpinEvent &event)
std::vector< std::string > outputTypes_
Output types.
int elemWidth_
Current element width in choice box.
@ ID_MEM_DATA
Memory data choice.
@ ID_OPERATION_OUTPUT_TYPES
Output Type ComboBox.
int type_
Current operand type in choice box.
void onElementCount(wxCommandEvent &event)
void onType(wxCommandEvent &event)
bool memData_
Flag indicating whether operand is memory data or not.
void onOk(wxCommandEvent &event)
wxChoice * elementCountChoice_
Choice box for operand element count.
wxChoice * outputTypesComboBox_
Choice box for operation input types.
wxSpinCtrl * elementWidthSpinCtrl_
Spin ctrl for operand element width.
wxSizer * createContents(wxWindow *window, bool call_fit, bool set_sizer)
int index_
Index of the operand.
Operand * operand_
Operand to be modified.
int elemCount_
Current element count in choice box.
virtual boost::format text(int textId)
static void setLabel(Texts::TextGenerator *generator, wxWindow *widget, int textID)
static wxString toWxString(const std::string &source)