OpenASIP 2.2
Loading...
Searching...
No Matches
OTAFormatListDialog.cc
Go to the documentation of this file.
1/*
2 Copyright (C) 2022 Tampere University.
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18/**
19 * @file OTAFormatListDialog.cc
20 *
21 * Implementation of OTAFormatListDialog class.
22 *
23 * @author Kari Hepola 2022
24 * @note rating: red
25 */
26
27#include <boost/format.hpp>
28#include <wx/wx.h>
29#include <wx/sizer.h>
30#include <wx/statline.h>
31#include <wx/listctrl.h>
32
34#include "Machine.hh"
35#include "MachineTester.hh"
37#include "Bus.hh"
38#include "WxConversion.hh"
39#include "OTAOperationDialog.hh"
40#include "WidgetTools.hh"
41#include "InformationDialog.hh"
42#include "WarningDialog.hh"
43#include "GUITextGenerator.hh"
44#include "ProDeTextGenerator.hh"
45
46#include "RISCVFields.hh"
47
48using std::string;
49using boost::format;
50using namespace TTAMachine;
51
52// too long lines to keep doxygen quiet
53BEGIN_EVENT_TABLE(OTAFormatListDialog, wxDialog)
64
65
66/**
67 * The Constructor.
68 *
69 * @param parent Parent window of the dialog.
70 * @param machine Parent machine of the instruction OTAFormats.
71 */
73 wxWindow* parent,
75 wxDialog(parent, -1, _T(""), wxDefaultPosition),
76 machine_(machine),
77 OTAFormatName_(_T("")) {
78
79 createContents(this, true, true);
80
81 OTAFormatList_ = dynamic_cast<wxListCtrl*>(FindWindow(ID_OTA_FORMAT_LIST));
82 operationList_ = dynamic_cast<wxListCtrl*>(FindWindow(ID_OPERATION_LIST));
83
84 FindWindow(ID_NAME)->SetValidator(
85 wxTextValidator(wxFILTER_ASCII, &OTAFormatName_));
86 FindWindow(ID_ADD_OTA_FORMAT)->Disable();
87 FindWindow(ID_DELETE_OTA_FORMAT)->Disable();
88 // set widget texts
89 setTexts();
90}
91
92
93/**
94 * The Destructor.
95 */
98
99
100/**
101 * Sets texts for widgets.
102 */
103void
107
108 // Dialog title
109 format fmt = prodeTexts->text(
111 SetTitle(WxConversion::toWxString(fmt.str()));
112
113 // buttons
114 WidgetTools::setLabel(generator, FindWindow(wxID_OK),
116
117 WidgetTools::setLabel(generator, FindWindow(wxID_CANCEL),
119
122
125
128
131
134
135 // widget labels
138
139 // box sizer label
142
145
146 // Create instruction OTAFormat list columns.
147 wxListCtrl* OTAFormatList =
148 dynamic_cast<wxListCtrl*>(FindWindow(ID_OTA_FORMAT_LIST));
149 fmt = prodeTexts->text(ProDeTextGenerator::TXT_COLUMN_NAME);
150 OTAFormatList->InsertColumn(0, WxConversion::toWxString(fmt.str()),
151 wxLIST_FORMAT_LEFT, 160);
152
153 // Create OTAFormat Operation list columns.
154 wxListCtrl* OperationList =
155 dynamic_cast<wxListCtrl*>(FindWindow(ID_OPERATION_LIST));
157 OperationList->InsertColumn(0, WxConversion::toWxString(fmt.str()),
158 wxLIST_FORMAT_LEFT, 100);
159}
160
161
162/**
163 * Transfers data from the machine to the dialog widgets.
164 */
165bool
167
168 // update OTAFormat list
169 OTAFormatList_->DeleteAllItems();
172 for (int i = 0; i < navigator.count(); i++) {
173 OTAFormatList_->InsertItem(
174 i, WxConversion::toWxString(navigator.item(i)->name()));
175 }
177 return wxDialog::TransferDataToWindow();
178}
179
180
181/**
182 * Updates the OTAFormat Operation list.
183 */
184void
186
187
188 operationList_->DeleteAllItems();
189 operationList_->Enable();
190
192
193 if (f == NULL) {
194 FindWindow(ID_ADD_OPERATION)->Disable();
195 return;
196 }
197
198 for (int i = 0; i < f->operationCount(); i++) {
199 operationList_->InsertItem(
201 }
202
203 FindWindow(ID_ADD_OPERATION)->Enable();
204
205 wxListEvent dummy;
207}
208
209
210/**
211 * Updates the Operation list when the OTAFormat selection changes.
212 */
213void
215 if (OTAFormatList_->GetSelectedItemCount() == 0) {
217 } else {
219 }
221}
222
223
224/**
225 * Updates the edit/delete Operation buttons when the Operation selection changes.
226 */
227void
229 if (operationList_->GetSelectedItemCount() == 1) {
231 } else {
233 }
234}
235
236
237/**
238 * Deletes the selected OTAFormat.
239 */
240void
242 delete selectedOTAFormat();
244 wxListEvent dummy;
246}
247
248
249/**
250 * Returns pointer to the selected OperationTriggeredFormat.
251 *
252 * @return Pointer to the selected OperationTriggeredFormat.
253 */
256 long item = -1;
257 item = OTAFormatList_->GetNextItem(
258 item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
259
260 if (item < 0) {
261 return NULL;
262 }
263
266 return f;
267}
268
269
270/**
271 * Returns name of the selected Operation.
272 *
273 * @return Name of the selected Operation.
274 */
275string
280
281bool
296
297
298/**
299 * Handles the Add tempalte button event.
300 *
301 * Adds a new OTAFormat to the machine.
302 */
303void
305 if (!TransferDataFromWindow()) {
306 assert(false);
307 }
308 string trimmedName =
309 WxConversion::toString(OTAFormatName_.Trim(false).Trim(true));
310
311 // Check the name validity.
312 if (!validFormatName()) {
313 std::string message = "Format name is illegal. Legal names are:\n" + \
323 InformationDialog warning(
324 this, WxConversion::toWxString(message));
325 warning.ShowModal();
326 return;
327 }
328
331
332 if (navigator.hasItem(trimmedName)) {
333 ProDeTextGenerator* prodeTexts =
335 format message =
337 format a_tmplate =
339 format machine =
341 format tmplate =
343 message % trimmedName % a_tmplate.str() % machine.str() %
344 tmplate.str();
345 WarningDialog warning(this, WxConversion::toWxString(message.str()));
346 warning.ShowModal();
347 return;
348 }
349 new OperationTriggeredFormat(trimmedName, *machine_);
350 OTAFormatName_ = _T("");
352}
353
354
355/**
356 * Enables and disables the Add OTAFormat button when text is entered in the
357 * OTAFormat name widget.
358 */
359void
361 if (!TransferDataFromWindow()) {
362 assert(false);
363 }
364 wxString trimmedName = OTAFormatName_.Trim(false).Trim(true);
367 if (trimmedName == _T("")) {
368 FindWindow(ID_ADD_OTA_FORMAT)->Disable();
369 //Only 6 formats in RISC-V + 3 custom formats
370 } else if (nav.count() > 8) {
371 FindWindow(ID_ADD_OTA_FORMAT)->Disable();
372 } else {
373 FindWindow(ID_ADD_OTA_FORMAT)->Enable();
374 }
375}
376
377
378/**
379 * Handles the add Operation button event.
380 */
381void
383
384 if (selectedOTAFormat() == NULL) {
385 assert(false);
386 }
388 dialog.ShowModal();
390}
391
392
393/**
394 * Handles the delete Operation button event.
395 */
396void
404
405
406/**
407 * Creates the dialog window contents.
408 *
409 * This method was generated with wxDesigner.
410 *
411 * @return Main sizer of the created contents.
412 * @param parent The dialog window.
413 * @param call_fit If true, fits the contents inside the dialog.
414 * @param set_sizer If true, sets the main sizer as dialog contents.
415 */
416wxSizer*
418 wxWindow *parent, bool call_fit, bool set_sizer) {
419
420 wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL );
421
422 wxBoxSizer *item1 = new wxBoxSizer( wxHORIZONTAL );
423
424 wxStaticBox *item3 = new wxStaticBox( parent, -1, wxT("Instruction OTAFormats:") );
425 wxStaticBoxSizer *item2 = new wxStaticBoxSizer( item3, wxVERTICAL );
426 OTAFormatSizer_ = item2;
427
428 wxListCtrl *item4 = new wxListCtrl( parent, ID_OTA_FORMAT_LIST, wxDefaultPosition, wxSize(160,200), wxLC_REPORT|wxLC_SINGLE_SEL|wxSUNKEN_BORDER );
429 item2->Add( item4, 0, wxGROW|wxALL, 5 );
430
431 wxBoxSizer *item5 = new wxBoxSizer( wxHORIZONTAL );
432
433 wxStaticText *item6 = new wxStaticText( parent, ID_LABEL_NAME, wxT("Name:"), wxDefaultPosition, wxDefaultSize, 0 );
434 item5->Add( item6, 0, wxALIGN_CENTER|wxALL, 5 );
435
436 wxTextCtrl *item7 = new wxTextCtrl( parent, ID_NAME, wxT(""), wxDefaultPosition, wxSize(120,-1), 0 );
437 item5->Add( item7, 0, wxALIGN_CENTER|wxALL, 5 );
438
439 item2->Add( item5, 0, wxGROW|wxALL, 5 );
440
441 wxBoxSizer *item8 = new wxBoxSizer( wxHORIZONTAL );
442
443 wxButton *item9 = new wxButton( parent, ID_ADD_OTA_FORMAT, wxT("Add"), wxDefaultPosition, wxDefaultSize, 0 );
444 item8->Add( item9, 0, wxALIGN_CENTER|wxALL, 5 );
445
446 wxButton *item10 = new wxButton( parent, ID_DELETE_OTA_FORMAT, wxT("Delete"), wxDefaultPosition, wxDefaultSize, 0 );
447 item8->Add( item10, 0, wxALIGN_CENTER|wxALL, 5 );
448
449 item2->Add( item8, 0, wxALIGN_CENTER|wxALL, 5 );
450
451 item1->Add( item2, 0, wxGROW|wxALL, 5 );
452
453 wxStaticBox *item12 = new wxStaticBox( parent, -1, wxT("OTAFormat Operations:") );
454 wxStaticBoxSizer *item11 = new wxStaticBoxSizer( item12, wxVERTICAL );
455 operationSizer_ = item11;
456
457 wxListCtrl *item13 = new wxListCtrl( parent, ID_OPERATION_LIST, wxDefaultPosition, wxSize(250,245), wxLC_REPORT|wxLC_SINGLE_SEL|wxSUNKEN_BORDER );
458 item11->Add( item13, 0, wxGROW|wxALL, 5 );
459
460 wxBoxSizer *item14 = new wxBoxSizer( wxHORIZONTAL );
461
462 wxButton *item15 = new wxButton( parent, ID_ADD_OPERATION, wxT("Add..."), wxDefaultPosition, wxDefaultSize, 0 );
463 item14->Add( item15, 0, wxALIGN_CENTER|wxALL, 5 );
464
465 wxButton *item17 = new wxButton( parent, ID_DELETE_OPERATION, wxT("Delete"), wxDefaultPosition, wxDefaultSize, 0 );
466 item14->Add( item17, 0, wxALIGN_CENTER|wxALL, 5 );
467
468 item11->Add( item14, 0, wxALIGN_CENTER|wxALL, 5 );
469
470 item1->Add( item11, 0, wxGROW|wxALL, 5 );
471
472 item0->Add( item1, 0, wxALIGN_CENTER|wxALL, 5 );
473
474 wxStaticLine *item18 = new wxStaticLine( parent, ID_LINE, wxDefaultPosition, wxSize(20,-1), wxLI_HORIZONTAL );
475 item0->Add( item18, 0, wxGROW|wxALL, 5 );
476
477 wxGridSizer *item19 = new wxGridSizer( 2, 0, 0 );
478
479 wxButton *item20 = new wxButton( parent, ID_HELP, wxT("&Help"), wxDefaultPosition, wxDefaultSize, 0 );
480 item19->Add( item20, 0, wxALL, 5 );
481
482 wxBoxSizer *item21 = new wxBoxSizer( wxHORIZONTAL );
483
484 wxButton *item22 = new wxButton( parent, wxID_OK, wxT("&OK"), wxDefaultPosition, wxDefaultSize, 0 );
485 item21->Add( item22, 0, wxALIGN_CENTER|wxALL, 5 );
486
487 wxButton *item23 = new wxButton( parent, wxID_CANCEL, wxT("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
488 item21->Add( item23, 0, wxALIGN_CENTER|wxALL, 5 );
489
490 item19->Add( item21, 0, wxALL, 5 );
491
492 item0->Add( item19, 0, wxGROW, 5 );
493
494 if (set_sizer)
495 {
496 parent->SetSizer( item0 );
497 if (call_fit)
498 item0->SetSizeHints( parent );
499 }
500
501 return item0;
502}
#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_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()
wxStaticBoxSizer * operationSizer_
Box sizer around the operation list.
void onOperationSelection(wxListEvent &event)
void onDeleteOperation(wxCommandEvent &event)
void onOTAFormatName(wxCommandEvent &event)
void onAddOperation(wxCommandEvent &event)
wxListCtrl * operationList_
Widget for list of operations in the selected OTAFormat.
wxStaticBoxSizer * OTAFormatSizer_
Box sizer around the OTAFormat list.
wxListCtrl * OTAFormatList_
Widget for list of OTAFormats.
void onDeleteOTAFormat(wxCommandEvent &event)
wxString OTAFormatName_
Name of the new OTAFormat.
void onOTAFormatSelection(wxListEvent &event)
TTAMachine::Machine * machine_
Parent machine of the instruction OTAFormats.
TTAMachine::OperationTriggeredFormat * selectedOTAFormat()
virtual bool TransferDataToWindow()
wxSizer * createContents(wxWindow *parent, bool call_fit, bool set_sizer)
void onAddOTAFormat(wxCommandEvent &event)
static ProDeTextGenerator * instance()
@ MSG_ERROR_SAME_NAME
Error: Same name exists.
@ TXT_OTA_FORMATS_DIALOG_TITLE
OTA Formats dialog title.
@ TXT_LABEL_NAME
Label for component name widget.
@ COMP_AN_OTA_FORMAT
Name for OTA Format (w/ article).
@ COMP_OTA_FORMAT
Name for OTA Format (w/o article).
@ TXT_OTA_FORMATS_BOX
OTA Formats box title.
@ COMP_MACHINE
Text for machine description.
@ TXT_COLUMN_OTA_OPERATION
Label for OTA operation column in a list.
@ TXT_COLUMN_NAME
Label for name column in a list.
@ TXT_OTA_FORMATS_OPERATIONS_BOX
OTA Formats operations dialog title.
ComponentType * item(int index) const
bool hasItem(const std::string &name) const
virtual OperationTriggeredFormatNavigator operationTriggeredFormatNavigator() const
Definition Machine.cc:439
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)
const std::string RISCV_S_TYPE_NAME
const std::string RISCV_R1R_TYPE_NAME
const std::string RISCV_R3R_TYPE_NAME
const std::string RISCV_B_TYPE_NAME
const std::string RISCV_J_TYPE_NAME
const std::string RISCV_R_TYPE_NAME
const std::string RISCV_R1_TYPE_NAME
const std::string RISCV_I_TYPE_NAME
const std::string RISCV_U_TYPE_NAME