OpenASIP  2.0
ImmediateSlotDialog.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 ImmediateSlotDialog.cc
26  *
27  * Implementation of ImmediateSlotDialog class.
28  *
29  * @author Veli-Pekka Jääskeläinen 2005 (vjaaskel-no.spam-cs.tut.fi)
30  * @note rating: red
31  */
32 
33 #include <boost/format.hpp>
34 #include <wx/statline.h>
35 #include <wx/listctrl.h>
36 
37 #include "ImmediateSlotDialog.hh"
38 #include "ImmediateSlot.hh"
39 #include "Machine.hh"
40 #include "WxConversion.hh"
41 #include "WidgetTools.hh"
42 #include "ProDeTextGenerator.hh"
43 #include "GUITextGenerator.hh"
44 #include "MachineTester.hh"
45 #include "InformationDialog.hh"
46 #include "WarningDialog.hh"
47 
48 using std::string;
49 using boost::format;
50 using namespace TTAMachine;
51 
52 BEGIN_EVENT_TABLE(ImmediateSlotDialog, wxDialog)
57  EVT_TEXT(ID_NAME, ImmediateSlotDialog::onSlotName)
59 
60 
61 /**
62  * The Constructor.
63  *
64  * @param parent Parent window of the dialog.
65  * @param machine Parent Machine of the immediate slots.
66  */
68  wxWindow* parent,
69  Machine* machine) :
70  wxDialog(parent, -1, _T(""), wxDefaultPosition),
71  machine_(machine) {
72 
73  createContents(this, true, true);
74 
75  slotList_ = dynamic_cast<wxListCtrl*>(FindWindow(ID_SLOT_LIST));
76 
77  FindWindow(ID_NAME)->SetValidator(
78  wxTextValidator(wxFILTER_ASCII, &slotName_));
79 
80  // Disable conditional buttons.
81  FindWindow(ID_ADD_SLOT)->Disable();
82  FindWindow(ID_DELETE_SLOT)->Disable();
83 
84  setTexts();
85 }
86 
87 
88 /**
89  * The Destructor.
90  */
92 }
93 
94 
95 /**
96  * Sets widget texts.
97  */
98 void
102 
103  // Dialog title.
104  format fmt = prodeTexts->text(
106  SetTitle(WxConversion::toWxString(fmt.str()));
107 
108  // Buttons
109  WidgetTools::setLabel(generator, FindWindow(wxID_OK),
111  WidgetTools::setLabel(generator, FindWindow(wxID_CANCEL),
113  WidgetTools::setLabel(generator, FindWindow(ID_HELP),
115  WidgetTools::setLabel(generator, FindWindow(ID_ADD_SLOT),
117  WidgetTools::setLabel(generator, FindWindow(ID_DELETE_SLOT),
119 
120  WidgetTools::setLabel(generator, FindWindow(ID_NAME),
122 
123  format fmtCol = prodeTexts->text(ProDeTextGenerator::TXT_COLUMN_NAME);
124  slotList_->InsertColumn(0, WxConversion::toWxString(fmtCol.str()),
125  wxLIST_FORMAT_LEFT, 300);
126 
127 }
128 
129 
130 /**
131  * Transfers data from the machine model to the dialog widgets.
132  */
133 bool
135 
136  // update slot list
137  slotList_->DeleteAllItems();
138  const Machine::ImmediateSlotNavigator navigator =
139  machine_->immediateSlotNavigator();
140 
141  for (int i = 0; i < navigator.count(); i++) {
142  slotList_->InsertItem(
143  i, WxConversion::toWxString(navigator.item(i)->name()));
144  }
145 
146  return wxDialog::TransferDataToWindow();
147 }
148 
149 
150 /**
151  * Enables and disables the delete button according to slot list selection.
152  */
153 void
155  if (slotList_->GetSelectedItemCount() == 1) {
156  FindWindow(ID_DELETE_SLOT)->Enable();
157  } else {
158  FindWindow(ID_DELETE_SLOT)->Disable();
159  }
160 }
161 
162 
163 /**
164  * Deletes the selected immediate slot.
165  */
166 void
168 
169  // Check which slot is selected.
170  long item = -1;
171  item = slotList_->GetNextItem(
172  item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
173 
174  if (item < 0) {
175  return;
176  }
177 
178  ImmediateSlot* slot =
179  machine_->immediateSlotNavigator().item(item);
180 
181  delete slot;
182 
183  TransferDataToWindow();
184  wxListEvent dummy;
185  onSlotSelection(dummy);
186 }
187 
188 
189 /**
190  * Adds a new slot to the machine when "Add" button is pressed.
191  */
192 void
194 
195  if (!TransferDataFromWindow()) {
196  return;
197  }
198 
199  string trimmedName =
200  WxConversion::toString(slotName_.Trim(false).Trim(true));
201 
202  // Check name validity.
203  if (!MachineTester::isValidComponentName(trimmedName)) {
205  format message =
207  InformationDialog warning(
208  this, WxConversion::toWxString(message.str()));
209  warning.ShowModal();
210  return;
211  }
212 
213  if (machine_->immediateSlotNavigator().hasItem(trimmedName)) {
215  format message =
217  message % trimmedName;
218  message % prodeTexts->text(ProDeTextGenerator::COMP_AN_IMM_SLOT).str();
219  message % prodeTexts->text(ProDeTextGenerator::COMP_MACHINE).str();
220  message % prodeTexts->text(ProDeTextGenerator::COMP_IMM_SLOT).str();
221  WarningDialog warning(this, WxConversion::toWxString(message.str()));
222  warning.ShowModal();
223  return;
224  }
225 
226  // Buses share namespace with immediate slots. Check that a bus with the
227  // same name does not exist.
228  if (machine_->busNavigator().hasItem(trimmedName)) {
230  format message =
232  message % trimmedName;
233  message % prodeTexts->text(ProDeTextGenerator::COMP_A_BUS).str();
234  message % prodeTexts->text(ProDeTextGenerator::COMP_MACHINE).str();
235  message % prodeTexts->text(ProDeTextGenerator::COMP_IMM_SLOT).str();
236  WarningDialog warning(this, WxConversion::toWxString(message.str()));
237  warning.ShowModal();
238  return;
239  }
240 
241  new ImmediateSlot(trimmedName, *machine_);
242  slotName_ = _T("");
243  TransferDataToWindow();
244 }
245 
246 
247 /**
248  * Enables and disables the "Add" button when text is entered in the
249  * slot name widget.
250  */
251 void
253 
254  if (!TransferDataFromWindow()) {
255  return;
256  }
257 
258  wxString trimmedName = slotName_.Trim(false).Trim(true);
259  if (trimmedName == _T("")) {
260  FindWindow(ID_ADD_SLOT)->Disable();
261  } else {
262  FindWindow(ID_ADD_SLOT)->Enable();
263  }
264 }
265 
266 
267 /**
268  * Creates the dialog contents.
269  *
270  * @param parent Parent dialog of the contents.
271  * @param call_fit If true, fits the contents inside the dialog.
272  * @param set_sizer If true, sets the main sizer as dialog contents.
273  * @return Top level sizer of the dialog contents.
274  */
275 wxSizer*
277  wxWindow *parent, bool call_fit, bool set_sizer) {
278 
279 
280  wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL );
281 
282  wxListCtrl *item1 = new wxListCtrl( parent, ID_SLOT_LIST, wxDefaultPosition, wxSize(300,200), wxLC_REPORT|wxLC_SINGLE_SEL|wxSUNKEN_BORDER );
283  item0->Add( item1, 0, wxGROW|wxALL, 5 );
284 
285  wxBoxSizer *item2 = new wxBoxSizer( wxVERTICAL );
286 
287  wxBoxSizer *item3 = new wxBoxSizer( wxHORIZONTAL );
288 
289  wxBoxSizer *item4 = new wxBoxSizer( wxHORIZONTAL );
290 
291  wxStaticText *item5 = new wxStaticText( parent, ID_LABEL_NAME, wxT("Name:"), wxDefaultPosition, wxDefaultSize, 0 );
292  item4->Add( item5, 0, wxALIGN_CENTER|wxALL, 5 );
293 
294  wxTextCtrl *item6 = new wxTextCtrl( parent, ID_NAME, wxT(""), wxDefaultPosition, wxSize(120,-1), 0 );
295  item4->Add( item6, 0, wxALIGN_CENTER|wxALL, 5 );
296 
297  item3->Add( item4, 0, wxGROW|wxALL, 5 );
298 
299  wxBoxSizer *item7 = new wxBoxSizer( wxHORIZONTAL );
300 
301  wxButton *item8 = new wxButton( parent, ID_ADD_SLOT, wxT("Add"), wxDefaultPosition, wxDefaultSize, 0 );
302  item7->Add( item8, 0, wxALIGN_CENTER|wxALL, 5 );
303 
304  wxButton *item9 = new wxButton( parent, ID_DELETE_SLOT, wxT("Delete"), wxDefaultPosition, wxDefaultSize, 0 );
305  item7->Add( item9, 0, wxALIGN_CENTER|wxALL, 5 );
306 
307  item3->Add( item7, 0, wxALIGN_CENTER, 5 );
308 
309  item2->Add( item3, 0, wxALIGN_CENTER|wxALL, 5 );
310 
311  item0->Add( item2, 0, wxGROW|wxALL, 5 );
312 
313  wxStaticLine *item10 = new wxStaticLine( parent, ID_LINE, wxDefaultPosition, wxSize(20,-1), wxLI_HORIZONTAL );
314  item0->Add( item10, 0, wxGROW|wxALL, 5 );
315 
316  wxGridSizer *item11 = new wxGridSizer( 2, 0, 0 );
317 
318  wxButton *item12 = new wxButton( parent, ID_HELP, wxT("&Help"), wxDefaultPosition, wxDefaultSize, 0 );
319  item11->Add( item12, 0, wxALL, 5 );
320 
321  wxBoxSizer *item13 = new wxBoxSizer( wxHORIZONTAL );
322 
323  wxButton *item14 = new wxButton( parent, wxID_OK, wxT("&OK"), wxDefaultPosition, wxDefaultSize, 0 );
324  item13->Add( item14, 0, wxALIGN_CENTER|wxALL, 5 );
325 
326  wxButton *item15 = new wxButton( parent, wxID_CANCEL, wxT("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
327  item13->Add( item15, 0, wxALIGN_CENTER|wxALL, 5 );
328 
329  item11->Add( item13, 0, 0, 5 );
330 
331  item0->Add( item11, 0, wxGROW, 5 );
332 
333  if (set_sizer)
334  {
335  parent->SetSizer( item0 );
336  if (call_fit)
337  item0->SetSizeHints( parent );
338  }
339 
340  return item0;
341 }
WarningDialog
Definition: WarningDialog.hh:42
ImmediateSlotDialog::onDeleteSlot
void onDeleteSlot(wxCommandEvent &event)
Definition: ImmediateSlotDialog.cc:167
ImmediateSlotDialog::onSlotSelection
void onSlotSelection(wxListEvent &event)
Definition: ImmediateSlotDialog.cc:154
ProDeTextGenerator::COMP_AN_IMM_SLOT
@ COMP_AN_IMM_SLOT
Name for imm. slot (w/ article).
Definition: ProDeTextGenerator.hh:283
WxConversion::toWxString
static wxString toWxString(const std::string &source)
ImmediateSlotDialog::onSlotName
void onSlotName(wxCommandEvent &event)
Definition: ImmediateSlotDialog.cc:252
machine
TTAMachine::Machine * machine
the architecture definition of the estimated processor
Definition: EstimatorCmdLineUI.cc:59
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
GUITextGenerator
Definition: GUITextGenerator.hh:46
ImmediateSlotDialog::onAddSlot
void onAddSlot(wxCommandEvent &event)
Definition: ImmediateSlotDialog.cc:193
GUITextGenerator::TXT_BUTTON_HELP
@ TXT_BUTTON_HELP
Label for help button.
Definition: GUITextGenerator.hh:60
WidgetTools.hh
FindWindow
Definition: FindWindow.hh:49
ImmediateSlotDialog::TransferDataToWindow
virtual bool TransferDataToWindow()
Definition: ImmediateSlotDialog.cc:134
TTAMachine::Machine::Navigator::count
int count() const
Texts::TextGenerator::text
virtual boost::format text(int textId)
Definition: TextGenerator.cc:94
ProDeTextGenerator.hh
ProDeTextGenerator
Definition: ProDeTextGenerator.hh:49
ProDeTextGenerator::MSG_ERROR_ILLEGAL_NAME
@ MSG_ERROR_ILLEGAL_NAME
Error: Illegal component name.
Definition: ProDeTextGenerator.hh:223
ProDeTextGenerator::MSG_ERROR_SAME_NAME
@ MSG_ERROR_SAME_NAME
Error: Same name exists.
Definition: ProDeTextGenerator.hh:229
ImmediateSlotDialog::createContents
wxSizer * createContents(wxWindow *parent, bool call_fit, bool set_sizer)
Definition: ImmediateSlotDialog.cc:276
GUITextGenerator::TXT_BUTTON_CANCEL
@ TXT_BUTTON_CANCEL
Label for cancel button.
Definition: GUITextGenerator.hh:55
WarningDialog.hh
ImmediateSlot.hh
dummy
SimValue dummy(32)
a dummy simvalue which is given for operands that are not bound
InformationDialog.hh
GUITextGenerator::TXT_BUTTON_ADD
@ TXT_BUTTON_ADD
Label for an add button.
Definition: GUITextGenerator.hh:53
ProDeTextGenerator::TXT_LABEL_NAME
@ TXT_LABEL_NAME
Label for component name widget.
Definition: ProDeTextGenerator.hh:56
ImmediateSlotDialog.hh
Machine.hh
MachineTester::isValidComponentName
static bool isValidComponentName(const std::string &name)
Definition: MachineTester.cc:312
EVT_LIST_ITEM_SELECTED
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
GUITextGenerator::TXT_BUTTON_DELETE
@ TXT_BUTTON_DELETE
Label for delete button.
Definition: GUITextGenerator.hh:56
GUITextGenerator.hh
MachineTester.hh
ProDeTextGenerator::instance
static ProDeTextGenerator * instance()
Definition: ProDeTextGenerator.cc:382
EVT_LIST_ITEM_DESELECTED
FUImplementationDialog::onAddExternalPort FUImplementationDialog::onDeleteExternalPort FUImplementationDialog::onArchPortSelection EVT_LIST_ITEM_DESELECTED(ID_ARCH_PORT_LIST, FUImplementationDialog::onArchPortSelection) EVT_LIST_ITEM_ACTIVATED(ID_ARCH_PORT_LIST
EVT_BUTTON
EVT_BUTTON(ID_EDIT_ARCH_PORT, FUImplementationDialog::onEditArchitecturePort) EVT_BUTTON(ID_ADD_EXTERNAL_PORT
ProDeTextGenerator::COMP_A_BUS
@ COMP_A_BUS
Name for a bus component.
Definition: ProDeTextGenerator.hh:253
ProDeTextGenerator::COMP_IMM_SLOT
@ COMP_IMM_SLOT
Name for imm. slot (w/o article).
Definition: ProDeTextGenerator.hh:282
ImmediateSlotDialog
Definition: ImmediateSlotDialog.hh:47
ImmediateSlotDialog::~ImmediateSlotDialog
virtual ~ImmediateSlotDialog()
Definition: ImmediateSlotDialog.cc:91
ProDeTextGenerator::COMP_MACHINE
@ COMP_MACHINE
Text for machine description.
Definition: ProDeTextGenerator.hh:252
WxConversion.hh
TTAMachine::Machine::Navigator::item
ComponentType * item(int index) const
InformationDialog
Definition: InformationDialog.hh:42
TTAMachine
Definition: Assembler.hh:48
WxConversion::toString
static std::string toString(const wxString &source)
ProDeTextGenerator::TXT_COLUMN_NAME
@ TXT_COLUMN_NAME
Label for name column in a list.
Definition: ProDeTextGenerator.hh:105
TTAMachine::Machine::Navigator
Definition: Machine.hh:186
ImmediateSlotDialog::setTexts
void setTexts()
Definition: ImmediateSlotDialog.cc:99
ProDeTextGenerator::TXT_IMMEDIATE_SLOT_DIALOG_TITLE
@ TXT_IMMEDIATE_SLOT_DIALOG_TITLE
Immediate Slot dialog title.
Definition: ProDeTextGenerator.hh:175
TTAMachine::ImmediateSlot
Definition: ImmediateSlot.hh:44
END_EVENT_TABLE
END_EVENT_TABLE() using namespace IDF
TTAMachine::Machine
Definition: Machine.hh:73
GUITextGenerator::TXT_BUTTON_OK
@ TXT_BUTTON_OK
Label for OK button.
Definition: GUITextGenerator.hh:59