OpenASIP 2.2
Loading...
Searching...
No Matches
InputOperandDialog.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 InputOperandDialog.cc
26 *
27 * Definition of InputOperandDialog class.
28 *
29 * @author Jussi Nykänen 2004 (nykanen-no.spam-cs.tut.fi)
30 * @note rating: red.
31 */
32
33#include <wx/valgen.h>
34#include <string>
35#include <boost/format.hpp>
36#include <vector>
37
38#include "InputOperandDialog.hh"
39#include "WxConversion.hh"
40#include "Conversion.hh"
41#include "WidgetTools.hh"
42#include "ObjectState.hh"
43#include "OSEdConstants.hh"
44#include "GUITextGenerator.hh"
45#include "OSEdTextGenerator.hh"
46#include "DialogPosition.hh"
47#include "Operand.hh"
48#include "SimValue.hh"
49
50using std::set;
51using std::string;
52using boost::format;
53using std::vector;
54
55BEGIN_EVENT_TABLE(InputOperandDialog, wxDialog)
58
59 EVT_CHOICE(ID_OPERATION_INPUT_TYPES, InputOperandDialog::onType)
60 EVT_SPINCTRL(ID_ELEMENT_WIDTH, InputOperandDialog::onElementWidth)
61 EVT_CHOICE(ID_ELEMENT_COUNT, InputOperandDialog::onElementCount)
62
66
68
69/**
70 * Constructor.
71 *
72 * @param parent The parent window.
73 * @param operand Operand to be added or modified.
74 * @param numberOfOperands The number of input operands.
75 */
77 wxWindow* parent,
78 Operand* operand,
79 int numberOfOperands,
80 int operandIndex) :
81 wxDialog(parent, -1, _T(""),
82 DialogPosition::getPosition(DialogPosition::DIALOG_INPUT_OPERAND)),
83 operand_(operand), numberOfOperands_(numberOfOperands),
84 index_(operandIndex) {
85
86 memAddress_ = operand_->isAddress();
87 memData_ = operand_->isMemoryData();
88 createContents(this, true, true);
89
90 swapList_ = dynamic_cast<wxListCtrl*>(FindWindow(ID_SWAP_LIST));
91 swapChoice_ = dynamic_cast<wxChoice*>(FindWindow(ID_OPERAND_CHOICE));
92
93 inputTypesComboBox_ =
94 dynamic_cast<wxChoice*>(FindWindow(ID_OPERATION_INPUT_TYPES));
95
96 elementWidthSpinCtrl_ =
97 dynamic_cast<wxSpinCtrl*>(FindWindow(ID_ELEMENT_WIDTH));
98
99 elementCountChoice_ =
100 dynamic_cast<wxChoice*>(FindWindow(ID_ELEMENT_COUNT));
101
102 FindWindow(ID_MEM_ADDRESS)->SetValidator(wxGenericValidator(&memAddress_));
103 FindWindow(ID_MEM_DATA)->SetValidator(wxGenericValidator(&memData_));
104
105 FindWindow(wxID_OK)->SetFocus();
106
107 canSwap_ = operand_->swap();
108
109 inputTypes_.push_back(Operand::SINT_WORD_STRING);
110 inputTypes_.push_back(Operand::UINT_WORD_STRING);
111 inputTypes_.push_back(Operand::FLOAT_WORD_STRING);
112 inputTypes_.push_back(Operand::DOUBLE_WORD_STRING);
113 inputTypes_.push_back(Operand::HALF_FLOAT_WORD_STRING);
114 inputTypes_.push_back(Operand::BOOL_STRING);
115 inputTypes_.push_back(Operand::RAW_DATA_STRING);
116 inputTypes_.push_back(Operand::SLONG_WORD_STRING);
117 inputTypes_.push_back(Operand::ULONG_WORD_STRING);
118
119 operandTypes_[0] = Operand::SINT_WORD;
120 operandTypes_[1] = Operand::UINT_WORD;
121 operandTypes_[2] = Operand::FLOAT_WORD;
122 operandTypes_[3] = Operand::DOUBLE_WORD;
123 operandTypes_[4] = Operand::HALF_FLOAT_WORD;
124 operandTypes_[5] = Operand::BOOL;
125 operandTypes_[6] = Operand::RAW_DATA;
126 operandTypes_[7] = Operand::SLONG_WORD;
127 operandTypes_[8] = Operand::ULONG_WORD;
128
129 type_ = operand_->type();
130 elemWidth_ = operand_->elementWidth();
131 elemCount_ = operand_->elementCount();
132 updateTypes();
133 updateElementWidths();
134 updateElementCounts();
135
136 setTexts();
137 }
138
139/**
140 * Destructor.
141 */
143 int x, y;
144 GetPosition(&x, &y);
145 wxPoint point(x, y);
147}
148
149/**
150 * Set texts to widgets.
151 */
152void
194
195/**
196 * Event handler for operand type choice box.
197**/
198void
200
201 type_ = inputTypesComboBox_->GetSelection();
202
203 Operand::OperandType operType = static_cast<Operand::OperandType>(type_);
205 elemCount_ = 1;
208}
209
210/**
211 * Event handler for element width spin ctrl.
212**/
213void
215 elemWidth_ = elementWidthSpinCtrl_->GetValue();
216 // update choice box list cells
218}
219
220/**
221 * Event handler for element count choice box.
222**/
223void
225 // get the current choice box value and convert it to integer
226 int index = elementCountChoice_->GetSelection();
227 wxString number = elementCountChoice_->GetString(index);
228 long value;
229 if(!number.ToLong(&value)) {
230 elemCount_ = 1;
231 return;
232 }
233
234 // save current choice
235 elemCount_ = static_cast<int>(value);
236 // update spin ctrl range
238}
239
240/**
241 * Updates the type lists.
242**/
243void
245
246 inputTypesComboBox_->Clear();
247
248 for (unsigned int i = 0; i < inputTypes_.size(); i++) {
249 wxString oper = WxConversion::toWxString(inputTypes_.at(i));
250 inputTypesComboBox_->Append(oper);
251 }
252
253 inputTypesComboBox_->SetSelection(type_);
254}
255
256/**
257 * Updates the element width choice box list.
258**/
259void
261
262 Operand::OperandType operType = static_cast<Operand::OperandType>(type_);
263
264 if (operType == Operand::RAW_DATA) {
265 // element width for raw data can be arbitrary up to the max width
266 int elemWidth = 1;
267 int lastValidWidth = 1;
268 while (elemCount_*elemWidth <= SIMD_WORD_WIDTH) {
269 lastValidWidth = elemWidth;
270 elemWidth *= 2;
271 }
272
273 // degrade current element width if it is too big
274 if (elemWidth_ > lastValidWidth) {
275 elemWidth_ = lastValidWidth;
276 }
277 elementWidthSpinCtrl_->SetRange(1, lastValidWidth);
279 } else if (operType == Operand::SINT_WORD || operType == Operand::UINT_WORD) {
280 // element width for integers is 8 to 32
281 elementWidthSpinCtrl_->SetRange(8, 32);
283 } else {
284 // element width for other types is their default type width
287 }
288}
289
290/**
291 * Updates the element count choice box list.
292**/
293void
295
296 elementCountChoice_->Clear();
297
298 // update the list so that only shorter or equal than SIMD_WORD_WIDTH
299 // width*count combinations are listed
300 int elemCount = 1;
301 int elemCountIndex = 0;
302 while (elemCount*elemWidth_ <= SIMD_WORD_WIDTH) {
303 if (elemCount < elemCount_) {
304 ++elemCountIndex;
305 }
307 elemCount *= 2;
308 }
309 elementCountChoice_->SetSelection(elemCountIndex);
310}
311
312/**
313 * Transfers data to window.
314 *
315 * @return True if transfer is successful.
316 */
317bool
319 updateList();
320 return wxWindow::TransferDataToWindow();
321}
322
323/**
324 * Updates the list of can swap operands.
325 */
326void
328
329 swapList_->DeleteAllItems();
330 swapChoice_->Clear();
331
332 set<int>::iterator it = canSwap_.begin();
333 int i = 0;
334 while (it != canSwap_.end()) {
335 wxString id = WxConversion::toWxString(*it);
336 swapList_->InsertItem(i, id);
337 i++;
338 it++;
339 }
340
341 for (int i = 1; i <= numberOfOperands_; i++) {
342 if (i != index_ &&
343 swapList_->FindItem(-1, WxConversion::toWxString(i)) == -1) {
344
346 }
347 }
348 swapChoice_->SetSelection(0);
349 if (swapChoice_->GetCount() == 0) {
350 FindWindow(ID_ADD_BUTTON)->Disable();
351 } else {
352 FindWindow(ID_ADD_BUTTON)->Enable();
353 }
354 wxListEvent dummy;
356}
357
358/**
359 * Handles the event when id is added to can swap list.
360 */
361void
363 wxString wxId = swapChoice_->GetStringSelection();
364 string id = WxConversion::toString(wxId);
365 canSwap_.insert(Conversion::toInt(id));
366 updateList();
367}
368
369/**
370 * Handles the event when id is deleted from can swap list.
371 *
372 * It is also possible to delete multible ids from the list.
373 */
374void
376
377 vector<string> toBeDeleted;
378 long item = -1;
379 for (;;) {
380 item = swapList_->GetNextItem(
381 item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
382
383 if (item == -1) {
384 break;
385 }
386
387 wxListItem info;
388 info.SetId(item);
389 info.SetColumn(0);
390 swapList_->GetItem(info);
391 toBeDeleted.push_back(WxConversion::toString(info.GetText()));
392 }
393
394 for (size_t i = 0; i < toBeDeleted.size(); i++) {
395 int id = Conversion::toInt(toBeDeleted[i]);
396 set<int>::iterator it = canSwap_.begin();
397 while (it != canSwap_.end()) {
398 if (*it == id) {
399 canSwap_.erase(it);
400 break;
401 }
402 it++;
403 }
404 }
405
406 updateList();
407}
408
409/**
410 * Handles the event when OK button is pushed.
411 */
412void
413InputOperandDialog::onOk(wxCommandEvent&) {
414 TransferDataFromWindow();
416 EndModal(wxID_OK);
417}
418
419/**
420 * Loads the properties to the modified/created operand.
421 */
422void
424 ObjectState* root = new ObjectState("");
426
427 int selected = inputTypesComboBox_->GetSelection();
428 Operand::OperandType type = operandTypes_[selected];
429
430
431 switch(type) {
434 break;
437 break;
440 break;
443 break;
445 root->setAttribute(
447 break;
448 case Operand::BOOL:
450 break;
452 root->setAttribute(
454 break;
456 root->setAttribute(
458 break;
460 root->setAttribute(
462 break;
463 default:
465 break;
466 }
467
470
473
474 if (canSwap_.size() > 0) {
476 set<int>::iterator it = canSwap_.begin();
477 while (it != canSwap_.end()) {
478 ObjectState* swapChild = new ObjectState(Operand::OPRND_IN);
479 swapChild->setAttribute(Operand::OPRND_ID, *it);
480 swap->addChild(swapChild);
481 it++;
482 }
483 root->addChild(swap);
484 }
485
486 operand_->loadState(root);
487 delete root;
488}
489
490/**
491 *
492 */
493void
495 if (swapList_->GetSelectedItemCount() == 0) {
496 FindWindow(ID_DELETE_BUTTON)->Disable();
497 } else {
498 FindWindow(ID_DELETE_BUTTON)->Enable();
499 }
500}
501
502/**
503 * Creates the contents of dialog.
504 *
505 * NOTE! This function is generated by wxDesigner, that is why it is ugly.
506 *
507 * @param parent The parent window.
508 * @param call_fir If true, fits the contents of the dialog inside dialog.
509 * @param set_sizer If true, sets the main sizer as the contents of the dialog.
510 * @return The created sizer.
511 */
512wxSizer*
513InputOperandDialog::createContents(wxWindow *parent, bool call_fit, bool set_sizer)
514{
515 wxBoxSizer *item0 = new wxBoxSizer(wxVERTICAL);
516
517 wxBoxSizer *item1 = new wxBoxSizer(wxHORIZONTAL);
518
519 wxString strs9[] = {
520 wxT("id: 1")
521 };
522
523
524 // ComboBox for input operand types
525 wxChoice *itemInputTypes = new wxChoice(parent, ID_OPERATION_INPUT_TYPES, wxDefaultPosition, wxSize(100,-1), 1, strs9);
526 item1->Add(itemInputTypes, 0, wxALIGN_CENTER|wxALL, 5);
527
528 wxStaticText *itemTextWidth = new wxStaticText(parent, ID_TEXT_WIDTH, wxT("Element width:"), wxDefaultPosition, wxDefaultSize, 0);
529 item1->Add(itemTextWidth, 0, wxALIGN_CENTER|wxALL, 5);
530 wxSpinCtrl *itemElemWidth = new wxSpinCtrl(parent, ID_ELEMENT_WIDTH, wxT(""), wxDefaultPosition, wxSize(-1,-1), 1);
531 item1->Add(itemElemWidth, 0, wxALIGN_CENTER|wxALL, 5);
532 wxStaticText *itemTextCount = new wxStaticText(parent, ID_TEXT_COUNT, wxT("Element count:"), wxDefaultPosition, wxDefaultSize, 0);
533 item1->Add(itemTextCount, 0, wxALIGN_CENTER|wxALL, 5);
534 wxChoice *itemElemCount = new wxChoice(parent, ID_ELEMENT_COUNT, wxDefaultPosition, wxSize(70,-1), 1, strs9);
535 item1->Add(itemElemCount, 0, wxALIGN_CENTER|wxALL, 5);
536
537 wxBoxSizer *item1b = new wxBoxSizer(wxHORIZONTAL);
538
539 wxCheckBox *item2 = new wxCheckBox(parent, ID_MEM_ADDRESS, wxT("Memory address"), wxDefaultPosition, wxDefaultSize, 0);
540 item1b->Add(item2, 0, wxALIGN_CENTER|wxALL, 5);
541
542 wxCheckBox *item3 = new wxCheckBox(parent, ID_MEM_DATA, wxT("Memory data"), wxDefaultPosition, wxDefaultSize, 0);
543 item1b->Add(item3, 0, wxALIGN_CENTER|wxALL, 5);
544
545 item0->Add(item1, 0, wxALIGN_CENTER|wxALL, 5);
546 item0->Add(item1b, 0, wxALIGN_CENTER|wxALL, 5);
547
548 wxStaticBox *item5 = new wxStaticBox(parent, -1, wxT("Can swap"));
549 wxStaticBoxSizer *item4 = new wxStaticBoxSizer(item5, wxVERTICAL);
550 swapSizer_ = item4;
551
552 wxListCtrl *item6 = new wxListCtrl(parent, ID_SWAP_LIST, wxDefaultPosition, wxSize(160,120), wxLC_REPORT|wxSUNKEN_BORDER);
553 item4->Add(item6, 0, wxGROW|wxALL, 5);
554
555 wxBoxSizer *item7 = new wxBoxSizer(wxHORIZONTAL);
556
557 wxChoice *item8 = new wxChoice(parent, ID_OPERAND_CHOICE, wxDefaultPosition, wxSize(100,-1), 1, strs9, 0);
558 item7->Add(item8, 0, wxALIGN_CENTER|wxALL, 5);
559
560 wxButton *item9 = new wxButton(parent, ID_ADD_BUTTON, wxT("Add"), wxDefaultPosition, wxDefaultSize, 0);
561 item7->Add(item9, 0, wxALIGN_CENTER|wxALL, 5);
562
563 wxButton *item10 = new wxButton(parent, ID_DELETE_BUTTON, wxT("Delete"), wxDefaultPosition, wxDefaultSize, 0);
564 item7->Add(item10, 0, wxALIGN_CENTER|wxALL, 5);
565
566 item4->Add(item7, 0, wxALIGN_CENTER|wxALL, 5);
567
568 item0->Add(item4, 0, wxALIGN_CENTER|wxALL, 5);
569
570 wxGridSizer *item11 = new wxGridSizer(2, 0, 0);
571
572 item11->Add(20, 20, 0, wxALIGN_CENTER|wxALL, 5);
573
574 wxBoxSizer *item12 = new wxBoxSizer(wxHORIZONTAL);
575
576 wxButton *item13 = new wxButton(parent, wxID_OK, wxT("&OK"), wxDefaultPosition, wxDefaultSize, 0);
577 item12->Add(item13, 0, wxALIGN_CENTER|wxALL, 5);
578
579 wxButton *item14 = new wxButton(parent, wxID_CANCEL, wxT("&Cancel"), wxDefaultPosition, wxDefaultSize, 0);
580 item12->Add(item14, 0, wxALIGN_CENTER|wxALL, 5);
581
582 item11->Add(item12, 0, wxGROW|wxALL, 5);
583
584 item0->Add(item11, 0, wxALIGN_CENTER|wxALL, 5);
585
586 if (set_sizer) {
587 parent->SetSizer(item0);
588 if (call_fit)
589 item0->SetSizeHints(parent);
590 }
591
592 return item0;
593}
END_EVENT_TABLE() using namespace IDF
FUImplementationDialog::onAddExternalPort FUImplementationDialog::onDeleteExternalPort FUImplementationDialog::onArchPortSelection EVT_LIST_ITEM_DESELECTED(ID_ARCH_PORT_LIST, FUImplementationDialog::onArchPortSelection) EVT_LIST_ITEM_ACTIVATED(ID_ARCH_PORT_LIST
FUImplementationDialog::onAddExternalPort FUImplementationDialog::onDeleteExternalPort FUImplementationDialog::onArchPortSelection FUImplementationDialog::onArchPortActivation EVT_LIST_ITEM_SELECTED(ID_EXTERNAL_PORT_LIST, FUImplementationDialog::onExternalPortSelection) EVT_LIST_ITEM_ACTIVATED(ID_EXTERNAL_PORT_LIST
EVT_BUTTON(ID_EDIT_ARCH_PORT, FUImplementationDialog::onEditArchitecturePort) EVT_BUTTON(ID_ADD_EXTERNAL_PORT
SimValue dummy(32)
a dummy simvalue which is given for operands that are not bound
#define SIMD_WORD_WIDTH
Definition SimValue.hh:42
static int toInt(const T &source)
static void setPosition(Dialogs dialog, wxPoint point)
@ DIALOG_INPUT_OPERAND
Input operand dialog.
@ TXT_BUTTON_DELETE
Label for delete button.
@ TXT_BUTTON_CANCEL
Label for cancel button.
@ TXT_BUTTON_OK
Label for OK button.
@ TXT_BUTTON_ADD
Label for an add button.
static GUITextGenerator * instance()
wxSpinCtrl * elementWidthSpinCtrl_
Spin ctrl for operand element width.
wxListCtrl * swapList_
List of can swap operands.
int type_
Current operand type in choice box.
wxSizer * createContents(wxWindow *parent, bool call_fit, bool set_sizer)
void onOk(wxCommandEvent &event)
int index_
Index of the input operand currently modified.
wxChoice * elementCountChoice_
Choice box for operand element count.
Operand * operand_
Operand to be created or modified.
wxChoice * inputTypesComboBox_
Choice box for operation input types.
wxChoice * swapChoice_
Choice list for can swap operands.
void onSelection(wxListEvent &event)
std::vector< std::string > inputTypes_
Input types.
std::set< int > canSwap_
Operands that can be swapped with this operand.
int elemWidth_
Current element width in choice box.
int elemCount_
Current element count in choice box.
int numberOfOperands_
Numberof input operands.
Operand::OperandType operandTypes_[9]
void onDeleteSwap(wxCommandEvent &event)
void onType(wxCommandEvent &event)
bool memAddress_
Flag indicating if operand is memory address.
void onAddSwap(wxCommandEvent &event)
void onElementWidth(wxSpinEvent &event)
virtual bool TransferDataToWindow()
wxStaticBoxSizer * swapSizer_
Pointer to can swap sizer.
void onElementCount(wxCommandEvent &event)
bool memData_
Flag indicating if operand is memory data.
static const int DEFAULT_COLUMN_WIDTH
Default column width.
static OSEdTextGenerator & instance()
@ TXT_BOX_CAN_SWAP
Can swap sizer label.
@ TXT_COLUMN_OPERAND
Operand column header.
@ TXT_INPUT_OPERAND_DIALOG_TITLE
Input operand dialog title.
@ TXT_CHECKBOX_MEM_ADDRESS
Memory address label.
@ TXT_CHECKBOX_MEM_DATA
Memory data label.
void setAttribute(const std::string &name, const std::string &value)
void addChild(ObjectState *child)
static const std::string OPRND_IN
Object state name for input operand.
Definition Operand.hh:94
static const std::string FLOAT_WORD_STRING
Definition Operand.hh:75
static const std::string OPRND_CAN_SWAP
Object state name for can swap.
Definition Operand.hh:92
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
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
virtual boost::format text(int textId)
static void setWidgetLabel(wxWindow *widget, std::string text)
static void setLabel(Texts::TextGenerator *generator, wxWindow *widget, int textID)
static wxString toWxString(const std::string &source)
static std::string toString(const wxString &source)