OpenASIP  2.0
AddressSpacesDialog.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 AddressSpacesDialog.cc
26  *
27  * Definition of AddressSpacesDialog class.
28  *
29  * @author Veli-Pekka Jääskeläinen 2004 (vjaaskel-no.spam-cs.tut.fi)
30  * @note rating: red
31  */
32 
33 #include <string>
34 #include <wx/statline.h>
35 #include <wx/listctrl.h>
36 #include <boost/format.hpp>
37 
38 #include "AddressSpacesDialog.hh"
39 #include "AddressSpaceDialog.hh"
40 #include "WxConversion.hh"
41 #include "InformationDialog.hh"
42 #include "Machine.hh"
43 #include "AddressSpace.hh"
44 #include "ControlUnit.hh"
45 #include "ModelConstants.hh"
46 #include "Machine.hh"
47 #include "ProDeConstants.hh"
48 #include "GUITextGenerator.hh"
49 #include "ProDeTextGenerator.hh"
50 #include "WidgetTools.hh"
51 #include "MathTools.hh"
52 #include "Conversion.hh"
53 
54 using boost::format;
55 using std::string;
56 using namespace TTAMachine;
57 
58 BEGIN_EVENT_TABLE(AddressSpacesDialog, wxDialog)
62 
63  EVT_MENU(ID_EDIT, AddressSpacesDialog::onEdit)
64  EVT_MENU(ID_DELETE, AddressSpacesDialog::onDelete)
65 
66  EVT_LIST_ITEM_FOCUSED(ID_LIST, AddressSpacesDialog::onASSelection)
67  EVT_LIST_DELETE_ITEM(ID_LIST, AddressSpacesDialog::onASSelection)
71  EVT_LIST_ITEM_RIGHT_CLICK(ID_LIST, AddressSpacesDialog::onASRightClick)
73 
74 
75 /**
76  * The Constructor.
77  *
78  * @param parent Parent window of the dialog.
79  * @param machine Machine containing the address spaces.
80  */
82  wxWindow* parent,
83  Machine* machine):
84  wxDialog(parent, -1, _T(""), wxDefaultPosition, wxSize(400,300)),
85  machine_(machine) {
86 
87  createContents(this, true, true);
88 
89  asList_ = dynamic_cast<wxListCtrl*>(FindWindow(ID_LIST));
90 
91  FindWindow(ID_EDIT)->Disable();
92  FindWindow(ID_DELETE)->Disable();
93 
94  // set texts to widgets
95  setTexts();
96 
97  updateASList();
98 }
99 
100 
101 /**
102  * The Destructor.
103  */
105 }
106 
107 
108 /**
109  * Sets texts for widgets.
110  */
111 void
115 
116  // Dialog title
117  format fmt = prodeTexts->text(
119  SetTitle(WxConversion::toWxString(fmt.str()));
120 
121  // buttons
122  WidgetTools::setLabel(generator, FindWindow(wxID_OK),
124 
125  WidgetTools::setLabel(generator, FindWindow(wxID_CANCEL),
127 
128  WidgetTools::setLabel(generator, FindWindow(ID_HELP),
130 
131  WidgetTools::setLabel(generator, FindWindow(ID_ADD),
133 
134  WidgetTools::setLabel(generator, FindWindow(ID_EDIT),
136 
137  WidgetTools::setLabel(generator, FindWindow(ID_DELETE),
139 
140  // Create address space list column.
141  wxListCtrl* portList =
142  dynamic_cast<wxListCtrl*>(FindWindow(ID_LIST));
143  fmt = prodeTexts->text(ProDeTextGenerator::TXT_COLUMN_NAME);
144  portList->InsertColumn(0, WxConversion::toWxString(fmt.str()),
145  wxLIST_FORMAT_LEFT, 100);
146  fmt = prodeTexts->text(ProDeTextGenerator::TXT_COLUMN_MAU);
147  portList->InsertColumn(1, WxConversion::toWxString(fmt.str()),
148  wxLIST_FORMAT_LEFT, 40);
150  portList->InsertColumn(2, WxConversion::toWxString(fmt.str()),
151  wxLIST_FORMAT_LEFT, 90);
153  portList->InsertColumn(3, WxConversion::toWxString(fmt.str()),
154  wxLIST_FORMAT_LEFT, 90);
156  portList->InsertColumn(4, WxConversion::toWxString(fmt.str()),
157  wxLIST_FORMAT_LEFT, 80);
158 }
159 
160 /**
161  * Returns pointer to the AddressSpace, which is selected on the list.
162  *
163  * @return The selected address space, or NULL if no address space is selected.
164  */
167 
168  long item = -1;
169  item = asList_->GetNextItem(
170  item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
171 
172  if (item == -1) {
173  return NULL;
174  }
175 
176  string asName = WxConversion::toString(asList_->GetItemText(item));
178  machine_->addressSpaceNavigator();
179 
180  if (!navigator.hasItem(asName)) {
181  return NULL;
182  }
183 
184  return navigator.item(asName);
185 
186 }
187 
188 
189 /**
190  * Creates and shows an address space dialog with default values set
191  * for adding an address space.
192  */
193 void
194 AddressSpacesDialog::onAdd(wxCommandEvent&) {
195 
196  // Generate name for the new AS.
198  machine_->addressSpaceNavigator();
199  int i = 1;
200  string newName = ProDeConstants::COMP_NEW_NAME_PREFIX_AS +
202  while (navigator.hasItem(newName)) {
205  i++;
206  }
207 
208  AddressSpace* newAS =
209  new AddressSpace(newName,
213  *machine_);
214 
215  AddressSpaceDialog dialog(this, machine_, newAS);
216 
217  if (dialog.ShowModal() == wxID_OK) {
218  updateASList();
219  } else {
220  // The dialog was cancelled.
221  delete newAS;
222  }
223 }
224 
225 
226 
227 /**
228  * Handles left mouse button double click on the address space list.
229  *
230  * Opens the clicked address space in an AddressSpaceDialog.
231  */
232 void
234  wxCommandEvent dummy;
235  onEdit(dummy);
236 }
237 
238 
239 /**
240  * Handles the 'Edit' button event.
241  *
242  * Opens an AddressSpaceDialog with the selected address space's attributes
243  * set.
244  */
245 void
246 AddressSpacesDialog::onEdit(wxCommandEvent&) {
247 
248  AddressSpace* selected = selectedAS();
249  if (selected == NULL) {
250  // No address space selected.
251  return;
252  }
253 
254  AddressSpaceDialog dialog(this, machine_, selectedAS());
255 
256  dialog.ShowModal();
257  updateASList();
258 }
259 
260 
261 /**
262  * Handles the 'Delete' button event.
263  *
264  * Deletes the selected address space.
265  */
266 void
268  delete selectedAS();
269  updateASList();
270 }
271 
272 
273 /**
274  * Disables and enables Edit and Delete buttons under the address space list.
275  *
276  * If an address space is selected, buttons are enabled. If no address space
277  * is selected the buttons will be disabled.
278  */
279 void
281  if (asList_->GetSelectedItemCount() != 1) {
282  FindWindow(ID_DELETE)->Disable();
283  FindWindow(ID_EDIT)->Disable();
284  return;
285  }
286  FindWindow(ID_DELETE)->Enable();
287  FindWindow(ID_EDIT)->Enable();
288 }
289 
290 
291 /**
292  * Updates the address space list.
293  */
294 void
296 
297  Machine::AddressSpaceNavigator asNavigator =
298  machine_->addressSpaceNavigator();
299 
300  asList_->DeleteAllItems();
301 
302  for (int i = 0; i < asNavigator.count(); i++) {
303  AddressSpace* as = asNavigator.item(i);
304  int bitWidth = MathTools::requiredBits(as->end());
305  asList_->InsertItem(i, WxConversion::toWxString(as->name()));
306  asList_->SetItem(i, 1, WxConversion::toWxString(as->width()));
307  asList_->SetItem(i, 2, WxConversion::toWxString(as->start()));
308  asList_->SetItem(i, 3, WxConversion::toWxString(as->end()));
309  asList_->SetItem(i, 4, WxConversion::toWxString(bitWidth));
310  }
311 }
312 
313 
314 /**
315  * Opens a pop-up menu when right mouse button is pressed on the list.
316  *
317  * @param event Information about right mouse click event.
318  */
319 void
321 
322  asList_->SetItemState(event.GetIndex(), wxLIST_STATE_SELECTED,
323  wxLIST_STATE_SELECTED);
324 
325  wxMenu* contextMenu = new wxMenu();
326 
328  format button = prodeTexts->text(
330  contextMenu->Append(
331  ID_EDIT, WxConversion::toWxString(button.str()));
332  button = prodeTexts->text(
334  contextMenu->Append(
335  ID_DELETE, WxConversion::toWxString(button.str()));
336  asList_->PopupMenu(contextMenu, event.GetPoint());
337 }
338 
339 
340 /**
341  * Creates the dialog window contents.
342  *
343  * This method was generated with wxDesigner, thus the ugly code and
344  * too long lines.
345  *
346  * @return Main sizer of the created contents.
347  * @param parent The dialog window.
348  * @param call_fit If true, fits the contents inside the dialog.
349  * @param set_sizer If true, sets the main sizer as dialog contents.
350  */
351 wxSizer*
352 AddressSpacesDialog::createContents( wxWindow *parent, bool call_fit, bool set_sizer )
353 {
354  wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL );
355 
356  wxListCtrl *item1 = new wxListCtrl( parent, ID_LIST, wxDefaultPosition, wxSize(400,200), wxLC_REPORT|wxLC_SINGLE_SEL );
357  item0->Add( item1, 0, wxALIGN_CENTER|wxALL, 5 );
358 
359  wxGridSizer *item2 = new wxGridSizer( 3, 0, 0 );
360 
361  wxButton *item3 = new wxButton( parent, ID_ADD, wxT("&Add..."), wxDefaultPosition, wxDefaultSize, 0 );
362  item2->Add( item3, 0, wxALIGN_CENTER|wxALL, 5 );
363 
364  wxButton *item4 = new wxButton( parent, ID_EDIT, wxT("&Edit..."), wxDefaultPosition, wxDefaultSize, 0 );
365  item2->Add( item4, 0, wxALIGN_CENTER|wxALL, 5 );
366 
367  wxButton *item5 = new wxButton( parent, ID_DELETE, wxT("&Delete"), wxDefaultPosition, wxDefaultSize, 0 );
368  item2->Add( item5, 0, wxALIGN_CENTER|wxALL, 5 );
369 
370  item0->Add( item2, 0, wxGROW, 5 );
371 
372  wxStaticLine *item6 = new wxStaticLine( parent, ID_LINE, wxDefaultPosition, wxSize(20,-1), wxLI_HORIZONTAL );
373  item0->Add( item6, 0, wxGROW|wxALL, 5 );
374 
375  wxGridSizer *item7 = new wxGridSizer( 2, 0, 0 );
376 
377  wxButton *item8 = new wxButton( parent, ID_HELP, wxT("&Help"), wxDefaultPosition, wxDefaultSize, 0 );
378  item7->Add( item8, 0, wxALL, 5 );
379 
380  wxBoxSizer *item9 = new wxBoxSizer( wxHORIZONTAL );
381 
382  wxButton *item10 = new wxButton( parent, wxID_OK, wxT("&OK"), wxDefaultPosition, wxDefaultSize, 0 );
383  item9->Add( item10, 0, wxALIGN_CENTER|wxALL, 5 );
384 
385  wxButton *item11 = new wxButton( parent, wxID_CANCEL, wxT("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
386  item9->Add( item11, 0, wxALIGN_CENTER|wxALL, 5 );
387 
388  item7->Add( item9, 0, wxALL, 5 );
389 
390  item0->Add( item7, 0, wxGROW, 5 );
391 
392  if (set_sizer)
393  {
394  parent->SetSizer( item0 );
395  if (call_fit)
396  item0->SetSizeHints( parent );
397  }
398 
399  return item0;
400 }
AddressSpacesDialog::onActivateAS
void onActivateAS(wxListEvent &event)
Definition: AddressSpacesDialog.cc:233
WxConversion::toWxString
static wxString toWxString(const std::string &source)
TTAMachine::Component::name
virtual TCEString name() const
Definition: MachinePart.cc:125
EVT_LIST_ITEM_ACTIVATED
FUImplementationDialog::onAddExternalPort FUImplementationDialog::onDeleteExternalPort FUImplementationDialog::onArchPortSelection FUImplementationDialog::onArchPortActivation FUImplementationDialog::onExternalPortActivation FUImplementationDialog::onParameterSelection EVT_LIST_ITEM_ACTIVATED(ID_PARAMETER_LIST, FUImplementationDialog::onParameterActivation) EVT_LIST_ITEM_DESELECTED(ID_PARAMETER_LIST
ProDeTextGenerator::TXT_LABEL_BUTTON_DELETE
@ TXT_LABEL_BUTTON_DELETE
Label for &Delete button.
Definition: ProDeTextGenerator.hh:95
ModelConstants::DEFAULT_AS_MAU_WIDTH
static const int DEFAULT_AS_MAU_WIDTH
Default address space width.
Definition: ModelConstants.hh:66
machine
TTAMachine::Machine * machine
the architecture definition of the estimated processor
Definition: EstimatorCmdLineUI.cc:59
AddressSpacesDialog::setTexts
void setTexts()
Definition: AddressSpacesDialog.cc:112
TTAMachine::AddressSpace
Definition: AddressSpace.hh:51
AddressSpacesDialog::onASRightClick
void onASRightClick(wxListEvent &event)
Definition: AddressSpacesDialog.cc:320
WidgetTools::setLabel
static void setLabel(Texts::TextGenerator *generator, wxWindow *widget, int textID)
Definition: WidgetTools.cc:92
ProDeConstants::COMP_NEW_NAME_PREFIX_AS
static const std::string COMP_NEW_NAME_PREFIX_AS
Prefix for new address space names.
Definition: ProDeConstants.hh:379
GUITextGenerator::instance
static GUITextGenerator * instance()
Definition: GUITextGenerator.cc:67
AddressSpace.hh
GUITextGenerator
Definition: GUITextGenerator.hh:46
AddressSpacesDialog.hh
GUITextGenerator::TXT_BUTTON_HELP
@ TXT_BUTTON_HELP
Label for help button.
Definition: GUITextGenerator.hh:60
WidgetTools.hh
FindWindow
Definition: FindWindow.hh:49
ModelConstants::DEFAULT_AS_MIN_ADDRESS
static const int DEFAULT_AS_MIN_ADDRESS
Default address space min address.
Definition: ModelConstants.hh:68
TTAMachine::Machine::Navigator::count
int count() const
Texts::TextGenerator::text
virtual boost::format text(int textId)
Definition: TextGenerator.cc:94
AddressSpaceDialog
Definition: AddressSpaceDialog.hh:50
ProDeTextGenerator.hh
Conversion::toString
static std::string toString(const T &source)
ProDeTextGenerator::TXT_LABEL_BUTTON_EDIT
@ TXT_LABEL_BUTTON_EDIT
Label for &Edit... button.
Definition: ProDeTextGenerator.hh:96
ProDeTextGenerator
Definition: ProDeTextGenerator.hh:49
ProDeTextGenerator::TXT_COLUMN_MIN_ADDRESS
@ TXT_COLUMN_MIN_ADDRESS
Label for min-address column.
Definition: ProDeTextGenerator.hh:124
ModelConstants::DEFAULT_AS_MAX_ADDRESS
static const int DEFAULT_AS_MAX_ADDRESS
Default address space max address.
Definition: ModelConstants.hh:70
AddressSpacesDialog::~AddressSpacesDialog
~AddressSpacesDialog()
Definition: AddressSpacesDialog.cc:104
GUITextGenerator::TXT_BUTTON_CANCEL
@ TXT_BUTTON_CANCEL
Label for cancel button.
Definition: GUITextGenerator.hh:55
AddressSpacesDialog
Definition: AddressSpacesDialog.hh:48
ProDeTextGenerator::TXT_COLUMN_BIT_WIDTH
@ TXT_COLUMN_BIT_WIDTH
Label for bit width column in a list.
Definition: ProDeTextGenerator.hh:111
Conversion.hh
ProDeTextGenerator::TXT_ADDRESS_SPACES_DIALOG_TITLE
@ TXT_ADDRESS_SPACES_DIALOG_TITLE
Address spaces dialog title.
Definition: ProDeTextGenerator.hh:210
dummy
SimValue dummy(32)
a dummy simvalue which is given for operands that are not bound
TTAMachine::Machine::Navigator::hasItem
bool hasItem(const std::string &name) const
InformationDialog.hh
AddressSpaceDialog.hh
ProDeTextGenerator::TXT_COLUMN_MAX_ADDRESS
@ TXT_COLUMN_MAX_ADDRESS
Label for max-address column.
Definition: ProDeTextGenerator.hh:125
MathTools::requiredBits
static int requiredBits(unsigned long int number)
ModelConstants.hh
Machine.hh
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
ProDeConstants.hh
GUITextGenerator.hh
TTAMachine::AddressSpace::width
virtual int width() const
Definition: AddressSpace.cc:155
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
AddressSpacesDialog::selectedAS
TTAMachine::AddressSpace * selectedAS()
Definition: AddressSpacesDialog.cc:166
GUITextGenerator::TXT_BUTTON_ADD_DIALOG
@ TXT_BUTTON_ADD_DIALOG
Label for add button (with trailing ...).
Definition: GUITextGenerator.hh:54
GUITextGenerator::TXT_BUTTON_EDIT_DIALOG
@ TXT_BUTTON_EDIT_DIALOG
Label for edit button (with trailing ...).
Definition: GUITextGenerator.hh:58
ControlUnit.hh
ProDeTextGenerator::TXT_COLUMN_MAU
@ TXT_COLUMN_MAU
Label for MAU column in a list.
Definition: ProDeTextGenerator.hh:110
WxConversion.hh
TTAMachine::Machine::Navigator::item
ComponentType * item(int index) const
AddressSpacesDialog::onDelete
void onDelete(wxCommandEvent &event)
Definition: AddressSpacesDialog.cc:267
MathTools.hh
TTAMachine
Definition: Assembler.hh:48
WxConversion::toString
static std::string toString(const wxString &source)
AddressSpacesDialog::onAdd
void onAdd(wxCommandEvent &event)
Definition: AddressSpacesDialog.cc:194
TTAMachine::AddressSpace::start
virtual ULongWord start() const
Definition: AddressSpace.cc:166
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
TTAMachine::AddressSpace::end
virtual ULongWord end() const
Definition: AddressSpace.cc:177
AddressSpacesDialog::updateASList
void updateASList()
Definition: AddressSpacesDialog.cc:295
AddressSpacesDialog::onEdit
void onEdit(wxCommandEvent &event)
Definition: AddressSpacesDialog.cc:246
END_EVENT_TABLE
END_EVENT_TABLE() using namespace IDF
TTAMachine::Machine
Definition: Machine.hh:73
AddressSpacesDialog::createContents
wxSizer * createContents(wxWindow *parent, bool call_fit, bool set_sizer)
Definition: AddressSpacesDialog.cc:352
AddressSpacesDialog::onASSelection
void onASSelection(wxListEvent &event)
Definition: AddressSpacesDialog.cc:280
GUITextGenerator::TXT_BUTTON_OK
@ TXT_BUTTON_OK
Label for OK button.
Definition: GUITextGenerator.hh:59