OpenASIP 2.2
Loading...
Searching...
No Matches
TemplateListDialog.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 TemplateListDialog.cc
26 *
27 * Implementation of TemplateListDialog class.
28 *
29 * @author Veli-Pekka Jääskeläinen 2004 (vjaaskel-no.spam-cs.tut.fi)
30 * @note rating: red
31 */
32
33#include <boost/format.hpp>
34#include <wx/wx.h>
35#include <wx/sizer.h>
36#include <wx/statline.h>
37#include <wx/listctrl.h>
38
39#include "TemplateListDialog.hh"
40#include "Machine.hh"
41#include "MachineTester.hh"
43#include "Bus.hh"
44#include "WxConversion.hh"
45#include "TemplateSlotDialog.hh"
46#include "WidgetTools.hh"
47#include "InformationDialog.hh"
48#include "WarningDialog.hh"
49#include "GUITextGenerator.hh"
50#include "ProDeTextGenerator.hh"
51
52using std::string;
53using boost::format;
54using namespace TTAMachine;
55
56// too long lines to keep doxygen quiet
57BEGIN_EVENT_TABLE(TemplateListDialog, wxDialog)
67 EVT_TEXT(ID_NAME, TemplateListDialog::onTemplateName)
69
70
71/**
72 * The Constructor.
73 *
74 * @param parent Parent window of the dialog.
75 * @param machine Parent machine of the instruction templates.
76 */
78 wxWindow* parent,
80 wxDialog(parent, -1, _T(""), wxDefaultPosition),
81 machine_(machine),
82 templateName_(_T("")) {
83
84 createContents(this, true, true);
85
86 templateList_ = dynamic_cast<wxListCtrl*>(FindWindow(ID_TEMPLATE_LIST));
87 slotList_ = dynamic_cast<wxListCtrl*>(FindWindow(ID_SLOT_LIST));
88
89 FindWindow(ID_NAME)->SetValidator(
90 wxTextValidator(wxFILTER_ASCII, &templateName_));
91 FindWindow(ID_ADD_TEMPLATE)->Disable();
92 FindWindow(ID_DELETE_TEMPLATE)->Disable();
93 FindWindow(ID_EDIT_SLOT)->Disable();
94
95 // set widget texts
96 setTexts();
97}
98
99
100/**
101 * The Destructor.
102 */
105
106
107/**
108 * Sets texts for widgets.
109 */
110void
114
115 // Dialog title
116 format fmt = prodeTexts->text(
118 SetTitle(WxConversion::toWxString(fmt.str()));
119
120 // buttons
121 WidgetTools::setLabel(generator, FindWindow(wxID_OK),
123
124 WidgetTools::setLabel(generator, FindWindow(wxID_CANCEL),
126
129
132
135
138
141
144
145 // widget labels
148
149 // box sizer label
152
155
156 // Create instruction template list columns.
157 wxListCtrl* templateList =
158 dynamic_cast<wxListCtrl*>(FindWindow(ID_TEMPLATE_LIST));
159 fmt = prodeTexts->text(ProDeTextGenerator::TXT_COLUMN_NAME);
160 templateList->InsertColumn(0, WxConversion::toWxString(fmt.str()),
161 wxLIST_FORMAT_LEFT, 160);
162
163 // Create template slot list columns.
164 wxListCtrl* slotList =
165 dynamic_cast<wxListCtrl*>(FindWindow(ID_SLOT_LIST));
166 fmt = prodeTexts->text(ProDeTextGenerator::TXT_COLUMN_SLOT);
167 slotList->InsertColumn(0, WxConversion::toWxString(fmt.str()),
168 wxLIST_FORMAT_LEFT, 100);
170 slotList->InsertColumn(1, WxConversion::toWxString(fmt.str()),
171 wxLIST_FORMAT_LEFT, 100);
173 slotList->InsertColumn(2, WxConversion::toWxString(fmt.str()),
174 wxLIST_FORMAT_LEFT, 50);
175
176}
177
178
179/**
180 * Transfers data from the machine to the dialog widgets.
181 */
182bool
184
185 // update template list
186 templateList_->DeleteAllItems();
189 for (int i = 0; i < navigator.count(); i++) {
190 templateList_->InsertItem(
191 i, WxConversion::toWxString(navigator.item(i)->name()));
192 }
194 return wxDialog::TransferDataToWindow();
195}
196
197
198/**
199 * Updates the template slot list.
200 */
201void
203
204
205 slotList_->DeleteAllItems();
206 slotList_->Enable();
207
209
210 if (templ == NULL) {
211 FindWindow(ID_ADD_SLOT)->Disable();
212 return;
213 }
214
215 FindWindow(ID_ADD_SLOT)->Enable();
216
217 // Add bus slots.
219 for (int i = 0; i < busNavigator.count(); i++) {
220 if (templ->usesSlot(busNavigator.item(i)->name())) {
221
222 Bus* slot = busNavigator.item(i);
223 // Add slot name.
224 slotList_->InsertItem(
225 0, WxConversion::toWxString(slot->name()));
226
227 // Add slot Destination.
228
229 // Set slot destination.
230 wxString name = WxConversion::toWxString(
231 templ->destinationOfSlot(slot->name())->name());
232 slotList_->SetItem(0, 1, name);
233
234 // Set slot width.
235 wxString width = WxConversion::toWxString(
236 templ->supportedWidth(slot->name()));
237 slotList_->SetItem(0, 2, width);
238 }
239 }
240
241 // Add immediate slots.
242 Machine::ImmediateSlotNavigator immsNavigator =
244 for (int i = 0; i < immsNavigator.count(); i++) {
245 if (templ->usesSlot(immsNavigator.item(i)->name())) {
246
247 ImmediateSlot* slot = immsNavigator.item(i);
248
249 // Add slot name.
250 slotList_->InsertItem(
251 0, WxConversion::toWxString(slot->name()));
252
253 // Set slot destination.
254 wxString name = WxConversion::toWxString(
255 templ->destinationOfSlot(slot->name())->name());
256 slotList_->SetItem(0, 1, name);
257
258 // Set slot width.
259 wxString width = WxConversion::toWxString(
260 templ->supportedWidth(slot->name()));
261 slotList_->SetItem(0, 2, width);
262 }
263 }
264 wxListEvent dummy;
266}
267
268
269/**
270 * Updates the slot list when the template selection changes.
271 */
272void
274 if (templateList_->GetSelectedItemCount() == 0) {
275 FindWindow(ID_DELETE_TEMPLATE)->Disable();
276 } else {
278 }
280}
281
282
283/**
284 * Updates the edit/delete slot buttons when the slot selection changes.
285 */
286void
288 if (slotList_->GetSelectedItemCount() == 1) {
289 FindWindow(ID_DELETE_SLOT)->Enable();
290 FindWindow(ID_EDIT_SLOT)->Enable();
291 } else {
292 FindWindow(ID_DELETE_SLOT)->Disable();
293 FindWindow(ID_EDIT_SLOT)->Disable();
294 }
295}
296
297
298/**
299 * Deletes the selected template.
300 */
301void
303 delete selectedTemplate();
305 wxListEvent dummy;
307}
308
309
310/**
311 * Returns pointer to the selected InstructionTemplate.
312 *
313 * @return Pointer to the selected InstructionTemplate.
314 */
317 long item = -1;
318 item = templateList_->GetNextItem(
319 item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
320
321 if (item < 0) {
322 return NULL;
323 }
324
325 InstructionTemplate* temp =
327 return temp;
328}
329
330
331/**
332 * Returns name of the selected slot.
333 *
334 * @return Name of the selected slot.
335 */
336string
339 return name;
340}
341
342
343/**
344 * Handles the Add tempalte button event.
345 *
346 * Adds a new template to the machine.
347 */
348void
350 if (!TransferDataFromWindow()) {
351 assert(false);
352 }
353 string trimmedName =
354 WxConversion::toString(templateName_.Trim(false).Trim(true));
355
356 // Check the name validity.
357 if (!MachineTester::isValidComponentName(trimmedName)) {
359 format message =
361 InformationDialog warning(
362 this, WxConversion::toWxString(message.str()));
363 warning.ShowModal();
364 return;
365 }
366
369
370 if (navigator.hasItem(trimmedName)) {
371 ProDeTextGenerator* prodeTexts =
373 format message =
375 format a_tmplate =
377 format machine =
379 format tmplate =
381 message % trimmedName % a_tmplate.str() % machine.str() %
382 tmplate.str();
383 WarningDialog warning(this, WxConversion::toWxString(message.str()));
384 warning.ShowModal();
385 return;
386 }
387 new InstructionTemplate(trimmedName, *machine_);
388 templateName_ = _T("");
390}
391
392
393/**
394 * Enables and disables the Add template button when text is entered in the
395 * template name widget.
396 */
397void
399 if (!TransferDataFromWindow()) {
400 assert(false);
401 }
402 wxString trimmedName = templateName_.Trim(false).Trim(true);
403 if (trimmedName == _T("")) {
404 FindWindow(ID_ADD_TEMPLATE)->Disable();
405 } else {
406 FindWindow(ID_ADD_TEMPLATE)->Enable();
407 }
408}
409
410
411/**
412 * Handles the add slot button event.
413 */
414void
416
417 if (selectedTemplate() == NULL) {
418 assert(false);
419 }
420
421 // Check that there is at least one immediate unit in the machine.
422 const Machine::ImmediateUnitNavigator iuNavigator =
424
425 if (iuNavigator.count() == 0) {
427 wxString message = WxConversion::toWxString(generator->text(
429
430 InformationDialog dialog(this, message);
431 dialog.ShowModal();
432 return;
433 }
434
435 // check that the template doesn't have all possible slots already
436 bool available = false;
437
438 // check buses
439 const Machine::BusNavigator busNavigator = machine_->busNavigator();
440 for (int i = 0; i < busNavigator.count(); i++) {
441 if (!selectedTemplate()->usesSlot(busNavigator.item(i)->name())) {
442 available = true;
443 break;
444 }
445 }
446
447 // check immediate slots
448 const Machine::ImmediateSlotNavigator immsNavigator =
450 for (int i = 0; i < immsNavigator.count(); i++) {
451 if (!selectedTemplate()->usesSlot(immsNavigator.item(i)->name())) {
452 available = true;
453 break;
454 }
455 }
456
457 if (available == false) {
459 wxString message = WxConversion::toWxString(generator->text(
461 InformationDialog dialog(this, message);
462 dialog.ShowModal();
463 return;
464 }
465
466 TemplateSlotDialog dialog(this, selectedTemplate());
467 dialog.ShowModal();
469}
470
471
472/**
473 * Handles the delete slot button event.
474 */
475void
480
481
482/**
483 * Handles the edit slot button event.
484 */
485void
488 selectedTemplate()->templateSlot(selectedSlot()) );
489 dialog.ShowModal();
491}
492
493
494/**
495 * Creates the dialog window contents.
496 *
497 * This method was generated with wxDesigner.
498 *
499 * @return Main sizer of the created contents.
500 * @param parent The dialog window.
501 * @param call_fit If true, fits the contents inside the dialog.
502 * @param set_sizer If true, sets the main sizer as dialog contents.
503 */
504wxSizer*
506 wxWindow *parent, bool call_fit, bool set_sizer) {
507
508 wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL );
509
510 wxBoxSizer *item1 = new wxBoxSizer( wxHORIZONTAL );
511
512 wxStaticBox *item3 = new wxStaticBox( parent, -1, wxT("Instruction Templates:") );
513 wxStaticBoxSizer *item2 = new wxStaticBoxSizer( item3, wxVERTICAL );
514 templateSizer_ = item2;
515
516 wxListCtrl *item4 = new wxListCtrl( parent, ID_TEMPLATE_LIST, wxDefaultPosition, wxSize(160,200), wxLC_REPORT|wxLC_SINGLE_SEL|wxSUNKEN_BORDER );
517 item2->Add( item4, 0, wxGROW|wxALL, 5 );
518
519 wxBoxSizer *item5 = new wxBoxSizer( wxHORIZONTAL );
520
521 wxStaticText *item6 = new wxStaticText( parent, ID_LABEL_NAME, wxT("Name:"), wxDefaultPosition, wxDefaultSize, 0 );
522 item5->Add( item6, 0, wxALIGN_CENTER|wxALL, 5 );
523
524 wxTextCtrl *item7 = new wxTextCtrl( parent, ID_NAME, wxT(""), wxDefaultPosition, wxSize(120,-1), 0 );
525 item5->Add( item7, 0, wxALIGN_CENTER|wxALL, 5 );
526
527 item2->Add( item5, 0, wxGROW|wxALL, 5 );
528
529 wxBoxSizer *item8 = new wxBoxSizer( wxHORIZONTAL );
530
531 wxButton *item9 = new wxButton( parent, ID_ADD_TEMPLATE, wxT("Add"), wxDefaultPosition, wxDefaultSize, 0 );
532 item8->Add( item9, 0, wxALIGN_CENTER|wxALL, 5 );
533
534 wxButton *item10 = new wxButton( parent, ID_DELETE_TEMPLATE, wxT("Delete"), wxDefaultPosition, wxDefaultSize, 0 );
535 item8->Add( item10, 0, wxALIGN_CENTER|wxALL, 5 );
536
537 item2->Add( item8, 0, wxALIGN_CENTER|wxALL, 5 );
538
539 item1->Add( item2, 0, wxGROW|wxALL, 5 );
540
541 wxStaticBox *item12 = new wxStaticBox( parent, -1, wxT("Template Slots:") );
542 wxStaticBoxSizer *item11 = new wxStaticBoxSizer( item12, wxVERTICAL );
543 slotSizer_ = item11;
544
545 wxListCtrl *item13 = new wxListCtrl( parent, ID_SLOT_LIST, wxDefaultPosition, wxSize(250,245), wxLC_REPORT|wxLC_SINGLE_SEL|wxSUNKEN_BORDER );
546 item11->Add( item13, 0, wxGROW|wxALL, 5 );
547
548 wxBoxSizer *item14 = new wxBoxSizer( wxHORIZONTAL );
549
550 wxButton *item15 = new wxButton( parent, ID_ADD_SLOT, wxT("Add..."), wxDefaultPosition, wxDefaultSize, 0 );
551 item14->Add( item15, 0, wxALIGN_CENTER|wxALL, 5 );
552
553 wxButton *item16 = new wxButton( parent, ID_EDIT_SLOT, wxT("Edit..."), wxDefaultPosition, wxDefaultSize, 0 );
554 item14->Add( item16, 0, wxALIGN_CENTER|wxALL, 5 );
555
556 wxButton *item17 = new wxButton( parent, ID_DELETE_SLOT, wxT("Delete"), wxDefaultPosition, wxDefaultSize, 0 );
557 item14->Add( item17, 0, wxALIGN_CENTER|wxALL, 5 );
558
559 item11->Add( item14, 0, wxALIGN_CENTER|wxALL, 5 );
560
561 item1->Add( item11, 0, wxGROW|wxALL, 5 );
562
563 item0->Add( item1, 0, wxALIGN_CENTER|wxALL, 5 );
564
565 wxStaticLine *item18 = new wxStaticLine( parent, ID_LINE, wxDefaultPosition, wxSize(20,-1), wxLI_HORIZONTAL );
566 item0->Add( item18, 0, wxGROW|wxALL, 5 );
567
568 wxGridSizer *item19 = new wxGridSizer( 2, 0, 0 );
569
570 wxButton *item20 = new wxButton( parent, ID_HELP, wxT("&Help"), wxDefaultPosition, wxDefaultSize, 0 );
571 item19->Add( item20, 0, wxALL, 5 );
572
573 wxBoxSizer *item21 = new wxBoxSizer( wxHORIZONTAL );
574
575 wxButton *item22 = new wxButton( parent, wxID_OK, wxT("&OK"), wxDefaultPosition, wxDefaultSize, 0 );
576 item21->Add( item22, 0, wxALIGN_CENTER|wxALL, 5 );
577
578 wxButton *item23 = new wxButton( parent, wxID_CANCEL, wxT("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
579 item21->Add( item23, 0, wxALIGN_CENTER|wxALL, 5 );
580
581 item19->Add( item21, 0, wxALL, 5 );
582
583 item0->Add( item19, 0, wxGROW, 5 );
584
585 if (set_sizer)
586 {
587 parent->SetSizer( item0 );
588 if (call_fit)
589 item0->SetSizeHints( parent );
590 }
591
592 return item0;
593}
#define assert(condition)
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
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
@ 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.
@ TXT_BUTTON_ADD
Label for an add button.
static GUITextGenerator * instance()
static bool isValidComponentName(const std::string &name)
static ProDeTextGenerator * instance()
@ MSG_ERROR_SAME_NAME
Error: Same name exists.
@ MSG_ERROR_ILLEGAL_NAME
Error: Illegal component name.
@ TXT_TEMPLATES_TEMPLATES_BOX
Instruction Templates bos title.
@ TXT_LABEL_NAME
Label for component name widget.
@ MSG_ERROR_NO_IMMEDIATE_UNITS
Error: No IUs for a template slot.
@ COMP_TEMPLATE
Name for template (w/o article).
@ TXT_COLUMN_WIDTH
Label for width column in a list.
@ COMP_MACHINE
Text for machine description.
@ COMP_A_TEMPLATE
Name for template (w/ article).
@ TXT_COLUMN_SLOT
Label for slot column in a list.
@ MSG_ERROR_NO_SLOTS_AVAILABLE
Error: No slots available for IT.
@ TXT_COLUMN_DESTINATION
Label for destination column.
@ TXT_TEMPLATES_DIALOG_TITLE
Templates dialog title.
@ TXT_TEMPLATES_SLOTS_BOX
Template Slots box title.
@ TXT_COLUMN_NAME
Label for name column in a list.
virtual TCEString name() const
virtual bool usesSlot(const std::string &slotName) const
virtual ImmediateUnit * destinationOfSlot(const std::string &slotName) const
virtual void removeSlot(const std::string &slotName)
ComponentType * item(int index) const
bool hasItem(const std::string &name) const
virtual ImmediateSlotNavigator immediateSlotNavigator() const
Definition Machine.cc:462
virtual InstructionTemplateNavigator instructionTemplateNavigator() const
Definition Machine.cc:428
virtual ImmediateUnitNavigator immediateUnitNavigator() const
Definition Machine.cc:416
virtual BusNavigator busNavigator() const
Definition Machine.cc:356
wxString templateName_
Name of the new template.
TTAMachine::InstructionTemplate * selectedTemplate()
wxStaticBoxSizer * slotSizer_
Box sizer around the slot list.
void onTemplateName(wxCommandEvent &event)
wxStaticBoxSizer * templateSizer_
Box sizer around the template list.
wxListCtrl * templateList_
Widget for list of templates.
wxSizer * createContents(wxWindow *parent, bool call_fit, bool set_sizer)
wxListCtrl * slotList_
Widget for list of slots in the selected template.
void onAddSlot(wxCommandEvent &event)
void onAddTemplate(wxCommandEvent &event)
void onTemplateSelection(wxListEvent &event)
TTAMachine::Machine * machine_
Parent machine of the instruction templates.
void onSlotSelection(wxListEvent &event)
virtual bool TransferDataToWindow()
void onEditSlot(wxCommandEvent &event)
void onDeleteTemplate(wxCommandEvent &event)
void onDeleteSlot(wxCommandEvent &event)
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 std::string lcStringSelection(wxListCtrl *list, int column)
static wxString toWxString(const std::string &source)
static std::string toString(const wxString &source)