OpenASIP  2.0
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 
38 #include "OutputOperandDialog.hh"
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 
48 using std::string;
49 using boost::format;
50 
51 BEGIN_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 **/
133 void
134 OutputOperandDialog::onType(wxCommandEvent&) {
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 **/
148 void
150  elemWidth_ = elementWidthSpinCtrl_->GetValue();
151  // update choice box list cells
153 }
154 
155 /**
156  * Event handler for element count choice box.
157 **/
158 void
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  */
178 void
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 **/
195 void
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 **/
229 void
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  }
242  elementCountChoice_->Append(WxConversion::toWxString(elemCount));
243  elemCount *= 2;
244  }
245  elementCountChoice_->SetSelection(elemCountIndex);
246 }
247 
248 /**
249  * Set texts to widgets.
250  */
251 void
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  */
278 void
279 OutputOperandDialog::onOk(wxCommandEvent&) {
280  TransferDataFromWindow();
281  ObjectState* root = new ObjectState("");
283 
284  int selected = outputTypesComboBox_->GetSelection();
285  Operand::OperandType type = operandTypes_[selected];
286 
287  switch(type)
288  {
289  case Operand::SINT_WORD:
291  break;
292  case Operand::UINT_WORD:
294  break;
295  case Operand::FLOAT_WORD:
297  break;
300  break;
302  root->setAttribute(
304  break;
305  case Operand::BOOL:
307  break;
308  case Operand::RAW_DATA:
310  break;
311  case Operand::SLONG_WORD:
312  root->setAttribute(
314  break;
315  case Operand::ULONG_WORD:
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  */
346 wxSizer*
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 }
Operand
Definition: Operand.hh:52
OutputOperandDialog::memData_
bool memData_
Flag indicating whether operand is memory data or not.
Definition: OutputOperandDialog.hh:86
Operand::OPRND_ELEM_COUNT
static const std::string OPRND_ELEM_COUNT
Object state name for element count.
Definition: Operand.hh:100
Operand::OPRND_MEM_DATA
static const std::string OPRND_MEM_DATA
Object state name for memory data.
Definition: Operand.hh:90
WxConversion::toWxString
static wxString toWxString(const std::string &source)
Operand::BOOL
@ BOOL
Definition: Operand.hh:64
Operand::SINT_WORD_STRING
static const std::string SINT_WORD_STRING
Definition: Operand.hh:72
Operand::SLONG_WORD_STRING
static const std::string SLONG_WORD_STRING
Definition: Operand.hh:70
Operand::OPRND_MEM_ADDRESS
static const std::string OPRND_MEM_ADDRESS
Object state name for memory address.
Definition: Operand.hh:86
Operand::OperandType
OperandType
Definition: Operand.hh:58
Operand::HALF_FLOAT_WORD
@ HALF_FLOAT_WORD
Definition: Operand.hh:63
OutputOperandDialog::createContents
wxSizer * createContents(wxWindow *window, bool call_fit, bool set_sizer)
Definition: OutputOperandDialog.cc:347
OutputOperandDialog::elementWidthSpinCtrl_
wxSpinCtrl * elementWidthSpinCtrl_
Spin ctrl for operand element width.
Definition: OutputOperandDialog.hh:92
OutputOperandDialog::ID_TEXT_WIDTH
@ ID_TEXT_WIDTH
Definition: OutputOperandDialog.hh:79
WidgetTools::setLabel
static void setLabel(Texts::TextGenerator *generator, wxWindow *widget, int textID)
Definition: WidgetTools.cc:92
GUITextGenerator::instance
static GUITextGenerator * instance()
Definition: GUITextGenerator.cc:67
Operand::UINT_WORD
@ UINT_WORD
Definition: Operand.hh:60
OutputOperandDialog::outputTypesComboBox_
wxChoice * outputTypesComboBox_
Choice box for operation input types.
Definition: OutputOperandDialog.hh:90
OutputOperandDialog
Definition: OutputOperandDialog.hh:49
OutputOperandDialog::onElementCount
void onElementCount(wxCommandEvent &event)
Definition: OutputOperandDialog.cc:159
GUITextGenerator
Definition: GUITextGenerator.hh:46
ObjectState
Definition: ObjectState.hh:59
OutputOperandDialog::ID_OPERATION_OUTPUT_TYPES
@ ID_OPERATION_OUTPUT_TYPES
Output Type ComboBox.
Definition: OutputOperandDialog.hh:76
WidgetTools.hh
FindWindow
Definition: FindWindow.hh:49
OutputOperandDialog::ID_ELEMENT_WIDTH
@ ID_ELEMENT_WIDTH
Definition: OutputOperandDialog.hh:77
OutputOperandDialog::outputTypes_
std::vector< std::string > outputTypes_
Output types.
Definition: OutputOperandDialog.hh:103
Texts::TextGenerator::text
virtual boost::format text(int textId)
Definition: TextGenerator.cc:94
DialogPosition::setPosition
static void setPosition(Dialogs dialog, wxPoint point)
Definition: DialogPosition.cc:63
Operand::RAW_DATA_STRING
static const std::string RAW_DATA_STRING
Definition: Operand.hh:78
Operand::HALF_FLOAT_WORD_STRING
static const std::string HALF_FLOAT_WORD_STRING
Definition: Operand.hh:74
operandPair
std::pair< int, Operand::OperandType > operandPair
Definition: OutputOperandDialog.hh:44
DialogPosition::DIALOG_OUTPUT_OPERAND
@ DIALOG_OUTPUT_OPERAND
Output operand dialog.
Definition: DialogPosition.hh:51
Operand::FLOAT_WORD_STRING
static const std::string FLOAT_WORD_STRING
Definition: Operand.hh:75
OutputOperandDialog::ID_ELEMENT_COUNT
@ ID_ELEMENT_COUNT
Definition: OutputOperandDialog.hh:78
GUITextGenerator::TXT_BUTTON_CANCEL
@ TXT_BUTTON_CANCEL
Label for cancel button.
Definition: GUITextGenerator.hh:55
Operand::OPRND_ID
static const std::string OPRND_ID
Object state name for operand id.
Definition: Operand.hh:82
OutputOperandDialog::elemCount_
int elemCount_
Current element count in choice box.
Definition: OutputOperandDialog.hh:100
Operand::SLONG_WORD
@ SLONG_WORD
Definition: Operand.hh:66
Operand::DOUBLE_WORD_STRING
static const std::string DOUBLE_WORD_STRING
Definition: Operand.hh:76
OutputOperandDialog::setTexts
void setTexts()
Definition: OutputOperandDialog.cc:252
OutputOperandDialog::onOk
void onOk(wxCommandEvent &event)
Definition: OutputOperandDialog.cc:279
ObjectState.hh
Operand::FLOAT_WORD
@ FLOAT_WORD
Definition: Operand.hh:61
Operand::UINT_WORD_STRING
static const std::string UINT_WORD_STRING
Definition: Operand.hh:73
Operand::index
virtual int index() const
Definition: Operand.cc:135
DialogPosition
Definition: DialogPosition.hh:42
OutputOperandDialog::updateElementWidths
void updateElementWidths()
Definition: OutputOperandDialog.cc:196
OutputOperandDialog::updateTypes
void updateTypes()
Definition: OutputOperandDialog.cc:179
Operand::SINT_WORD
@ SINT_WORD
Definition: Operand.hh:59
Operand::ULONG_WORD
@ ULONG_WORD
Definition: Operand.hh:67
Operand::RAW_DATA
@ RAW_DATA
Definition: Operand.hh:65
OutputOperandDialog::operandTypes_
operandList operandTypes_
Definition: OutputOperandDialog.hh:104
OutputOperandDialog::elemWidth_
int elemWidth_
Current element width in choice box.
Definition: OutputOperandDialog.hh:98
OutputOperandDialog::ID_MEM_DATA
@ ID_MEM_DATA
Memory data choice.
Definition: OutputOperandDialog.hh:75
GUITextGenerator.hh
Operand.hh
Operand::OPRND_TYPE
static const std::string OPRND_TYPE
Object state name for operand type.
Definition: Operand.hh:84
OutputOperandDialog::onType
void onType(wxCommandEvent &event)
Definition: OutputOperandDialog.cc:134
OutputOperandDialog::type_
int type_
Current operand type in choice box.
Definition: OutputOperandDialog.hh:96
Operand::DOUBLE_WORD
@ DOUBLE_WORD
Definition: Operand.hh:62
Operand::OPRND_ELEM_WIDTH
static const std::string OPRND_ELEM_WIDTH
Object state name for element width.
Definition: Operand.hh:98
EVT_BUTTON
EVT_BUTTON(ID_EDIT_ARCH_PORT, FUImplementationDialog::onEditArchitecturePort) EVT_BUTTON(ID_ADD_EXTERNAL_PORT
OSEdTextGenerator::TXT_OUTPUT_OPERAND_DIALOG_TITLE
@ TXT_OUTPUT_OPERAND_DIALOG_TITLE
Output operand dialog title.
Definition: OSEdTextGenerator.hh:111
OutputOperandDialog::ID_TEXT_COUNT
@ ID_TEXT_COUNT
Definition: OutputOperandDialog.hh:80
OutputOperandDialog::elementCountChoice_
wxChoice * elementCountChoice_
Choice box for operand element count.
Definition: OutputOperandDialog.hh:94
false
find Finds info of the inner loops in the false
Definition: InnerLoopFinder.cc:81
SimValue.hh
OutputOperandDialog::~OutputOperandDialog
virtual ~OutputOperandDialog()
Definition: OutputOperandDialog.cc:123
OSEdTextGenerator::instance
static OSEdTextGenerator & instance()
Definition: OSEdTextGenerator.cc:214
Operand::BOOL_STRING
static const std::string BOOL_STRING
Definition: Operand.hh:77
OSEdTextGenerator
Definition: OSEdTextGenerator.hh:42
WxConversion.hh
OutputOperandDialog::onElementWidth
void onElementWidth(wxSpinEvent &event)
Definition: OutputOperandDialog.cc:149
OutputOperandDialog::operand_
Operand * operand_
Operand to be modified.
Definition: OutputOperandDialog.hh:84
OSEdTextGenerator.hh
SIMD_WORD_WIDTH
#define SIMD_WORD_WIDTH
Definition: SimValue.hh:42
OutputOperandDialog::index_
int index_
Index of the operand.
Definition: OutputOperandDialog.hh:88
Operand::ULONG_WORD_STRING
static const std::string ULONG_WORD_STRING
Definition: Operand.hh:71
Operand::defaultElementWidth
static int defaultElementWidth(OperandType type)
Definition: Operand.cc:557
END_EVENT_TABLE
END_EVENT_TABLE() using namespace IDF
ObjectState::setAttribute
void setAttribute(const std::string &name, const std::string &value)
Definition: ObjectState.cc:100
OutputOperandDialog::updateElementCounts
void updateElementCounts()
Definition: OutputOperandDialog.cc:230
Operand::loadState
virtual void loadState(const ObjectState *state)
Definition: Operand.cc:383
OutputOperandDialog.hh
GUITextGenerator::TXT_BUTTON_OK
@ TXT_BUTTON_OK
Label for OK button.
Definition: GUITextGenerator.hh:59
DialogPosition.hh
OSEdTextGenerator::TXT_CHECKBOX_MEM_DATA
@ TXT_CHECKBOX_MEM_DATA
Memory data label.
Definition: OSEdTextGenerator.hh:92