OpenASIP 2.2
Loading...
Searching...
No Matches
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
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
54using boost::format;
55using std::string;
56using namespace TTAMachine;
57
58BEGIN_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,
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 */
106
107
108/**
109 * Sets texts for widgets.
110 */
111void
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
130
133
136
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));
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 */
193void
195
196 // Generate name for the new AS.
199 int i = 1;
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 */
232void
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 */
245void
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 */
266void
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 */
279void
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 */
294void
296
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 */
319void
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 */
351wxSizer*
352AddressSpacesDialog::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}
END_EVENT_TABLE() using namespace IDF
TTAMachine::Machine * machine
the architecture definition of the estimated processor
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
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
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
void onActivateAS(wxListEvent &event)
void onDelete(wxCommandEvent &event)
wxListCtrl * asList_
List control for listing the address spaces.
void onASRightClick(wxListEvent &event)
TTAMachine::Machine * machine_
Machine containing the address spaces to list.
wxSizer * createContents(wxWindow *parent, bool call_fit, bool set_sizer)
void onAdd(wxCommandEvent &event)
void onEdit(wxCommandEvent &event)
TTAMachine::AddressSpace * selectedAS()
void onASSelection(wxListEvent &event)
static std::string toString(const T &source)
@ TXT_BUTTON_EDIT_DIALOG
Label for edit button (with trailing ...).
@ TXT_BUTTON_ADD_DIALOG
Label for add button (with trailing ...).
@ TXT_BUTTON_HELP
Label for help button.
@ TXT_BUTTON_DELETE
Label for delete button.
@ TXT_BUTTON_CANCEL
Label for cancel button.
@ TXT_BUTTON_OK
Label for OK button.
static GUITextGenerator * instance()
static int requiredBits(unsigned long int number)
static const int DEFAULT_AS_MIN_ADDRESS
Default address space min address.
static const int DEFAULT_AS_MAU_WIDTH
Default address space width.
static const int DEFAULT_AS_MAX_ADDRESS
Default address space max address.
static const std::string COMP_NEW_NAME_PREFIX_AS
Prefix for new address space names.
static ProDeTextGenerator * instance()
@ TXT_LABEL_BUTTON_EDIT
Label for &Edit... button.
@ TXT_COLUMN_MAX_ADDRESS
Label for max-address column.
@ TXT_COLUMN_MIN_ADDRESS
Label for min-address column.
@ TXT_LABEL_BUTTON_DELETE
Label for &Delete button.
@ TXT_ADDRESS_SPACES_DIALOG_TITLE
Address spaces dialog title.
@ TXT_COLUMN_MAU
Label for MAU column in a list.
@ TXT_COLUMN_BIT_WIDTH
Label for bit width column in a list.
@ TXT_COLUMN_NAME
Label for name column in a list.
virtual ULongWord end() const
virtual int width() const
virtual ULongWord start() const
virtual TCEString name() const
ComponentType * item(int index) const
bool hasItem(const std::string &name) const
virtual AddressSpaceNavigator addressSpaceNavigator() const
Definition Machine.cc:392
virtual boost::format text(int textId)
static void setLabel(Texts::TextGenerator *generator, wxWindow *widget, int textID)
static wxString toWxString(const std::string &source)
static std::string toString(const wxString &source)