OpenASIP  2.0
Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
ImmediateSlotDialog Class Reference

#include <ImmediateSlotDialog.hh>

Inheritance diagram for ImmediateSlotDialog:
Inheritance graph
Collaboration diagram for ImmediateSlotDialog:
Collaboration graph

Public Member Functions

 ImmediateSlotDialog (wxWindow *parent, TTAMachine::Machine *machine)
 
virtual ~ImmediateSlotDialog ()
 

Private Types

enum  {
  ID_SLOT_LIST = 10000, ID_NAME, ID_LABEL_NAME, ID_LABE_NAME,
  ID_ADD_SLOT, ID_DELETE_SLOT, ID_LINE, ID_HELP
}
 

Private Member Functions

virtual bool TransferDataToWindow ()
 
wxSizer * createContents (wxWindow *parent, bool call_fit, bool set_sizer)
 
void updateSlotList ()
 
void onAddSlot (wxCommandEvent &event)
 
void onDeleteSlot (wxCommandEvent &event)
 
void onSlotName (wxCommandEvent &event)
 
void onSlotSelection (wxListEvent &event)
 
void setTexts ()
 

Private Attributes

TTAMachine::Machinemachine_
 Parent machine of the immediate slots. More...
 
wxListCtrl * slotList_
 Immediate slot list widget. More...
 
wxString slotName_
 Text in the slot name widget. More...
 

Detailed Description

Dialog for modifying immediate slots in a machine.

Definition at line 47 of file ImmediateSlotDialog.hh.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
private
Enumerator
ID_SLOT_LIST 
ID_NAME 
ID_LABEL_NAME 
ID_LABE_NAME 
ID_ADD_SLOT 
ID_DELETE_SLOT 
ID_LINE 
ID_HELP 

Definition at line 69 of file ImmediateSlotDialog.hh.

69  {
70  ID_SLOT_LIST = 10000,
71  ID_NAME,
76  ID_LINE,
77  ID_HELP
78  };

Constructor & Destructor Documentation

◆ ImmediateSlotDialog()

ImmediateSlotDialog::ImmediateSlotDialog ( wxWindow *  parent,
TTAMachine::Machine machine 
)

The Constructor.

Parameters
parentParent window of the dialog.
machineParent Machine of the immediate slots.

Definition at line 67 of file ImmediateSlotDialog.cc.

69  :
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 }

◆ ~ImmediateSlotDialog()

ImmediateSlotDialog::~ImmediateSlotDialog ( )
virtual

The Destructor.

Definition at line 91 of file ImmediateSlotDialog.cc.

91  {
92 }

Member Function Documentation

◆ createContents()

wxSizer * ImmediateSlotDialog::createContents ( wxWindow *  parent,
bool  call_fit,
bool  set_sizer 
)
private

Creates the dialog contents.

Parameters
parentParent dialog of the contents.
call_fitIf true, fits the contents inside the dialog.
set_sizerIf true, sets the main sizer as dialog contents.
Returns
Top level sizer of the dialog contents.

Definition at line 276 of file ImmediateSlotDialog.cc.

277  {
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 }

◆ onAddSlot()

void ImmediateSlotDialog::onAddSlot ( wxCommandEvent &  event)
private

Adds a new slot to the machine when "Add" button is pressed.

Definition at line 193 of file ImmediateSlotDialog.cc.

193  {
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("");
244 }

References ProDeTextGenerator::COMP_A_BUS, ProDeTextGenerator::COMP_AN_IMM_SLOT, ProDeTextGenerator::COMP_IMM_SLOT, ProDeTextGenerator::COMP_MACHINE, ProDeTextGenerator::instance(), MachineTester::isValidComponentName(), ProDeTextGenerator::MSG_ERROR_ILLEGAL_NAME, ProDeTextGenerator::MSG_ERROR_SAME_NAME, Texts::TextGenerator::text(), WxConversion::toString(), and WxConversion::toWxString().

Here is the call graph for this function:

◆ onDeleteSlot()

void ImmediateSlotDialog::onDeleteSlot ( wxCommandEvent &  event)
private

Deletes the selected immediate slot.

Definition at line 167 of file ImmediateSlotDialog.cc.

167  {
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 =
180 
181  delete slot;
182 
184  wxListEvent dummy;
186 }

References dummy.

◆ onSlotName()

void ImmediateSlotDialog::onSlotName ( wxCommandEvent &  event)
private

Enables and disables the "Add" button when text is entered in the slot name widget.

Definition at line 252 of file ImmediateSlotDialog.cc.

252  {
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 }

◆ onSlotSelection()

void ImmediateSlotDialog::onSlotSelection ( wxListEvent &  event)
private

Enables and disables the delete button according to slot list selection.

Definition at line 154 of file ImmediateSlotDialog.cc.

154  {
155  if (slotList_->GetSelectedItemCount() == 1) {
156  FindWindow(ID_DELETE_SLOT)->Enable();
157  } else {
158  FindWindow(ID_DELETE_SLOT)->Disable();
159  }
160 }

◆ setTexts()

void ImmediateSlotDialog::setTexts ( )
private

Sets widget texts.

Definition at line 99 of file ImmediateSlotDialog.cc.

99  {
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),
119 
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 }

References GUITextGenerator::instance(), ProDeTextGenerator::instance(), WidgetTools::setLabel(), Texts::TextGenerator::text(), WxConversion::toWxString(), GUITextGenerator::TXT_BUTTON_ADD, GUITextGenerator::TXT_BUTTON_CANCEL, GUITextGenerator::TXT_BUTTON_DELETE, GUITextGenerator::TXT_BUTTON_HELP, GUITextGenerator::TXT_BUTTON_OK, ProDeTextGenerator::TXT_COLUMN_NAME, ProDeTextGenerator::TXT_IMMEDIATE_SLOT_DIALOG_TITLE, and ProDeTextGenerator::TXT_LABEL_NAME.

Here is the call graph for this function:

◆ TransferDataToWindow()

bool ImmediateSlotDialog::TransferDataToWindow ( )
privatevirtual

Transfers data from the machine model to the dialog widgets.

Definition at line 134 of file ImmediateSlotDialog.cc.

134  {
135 
136  // update slot list
137  slotList_->DeleteAllItems();
138  const Machine::ImmediateSlotNavigator navigator =
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 }

References TTAMachine::Machine::Navigator< ComponentType >::count(), TTAMachine::Machine::Navigator< ComponentType >::item(), and WxConversion::toWxString().

Here is the call graph for this function:

◆ updateSlotList()

void ImmediateSlotDialog::updateSlotList ( )
private

Member Data Documentation

◆ machine_

TTAMachine::Machine* ImmediateSlotDialog::machine_
private

Parent machine of the immediate slots.

Definition at line 63 of file ImmediateSlotDialog.hh.

◆ slotList_

wxListCtrl* ImmediateSlotDialog::slotList_
private

Immediate slot list widget.

Definition at line 65 of file ImmediateSlotDialog.hh.

◆ slotName_

wxString ImmediateSlotDialog::slotName_
private

Text in the slot name widget.

Definition at line 67 of file ImmediateSlotDialog.hh.


The documentation for this class was generated from the following files:
WarningDialog
Definition: WarningDialog.hh:42
ImmediateSlotDialog::ID_DELETE_SLOT
@ ID_DELETE_SLOT
Definition: ImmediateSlotDialog.hh:75
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::ID_NAME
@ ID_NAME
Definition: ImmediateSlotDialog.hh:71
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
ImmediateSlotDialog::ID_SLOT_LIST
@ ID_SLOT_LIST
Definition: ImmediateSlotDialog.hh:70
GUITextGenerator
Definition: GUITextGenerator.hh:46
GUITextGenerator::TXT_BUTTON_HELP
@ TXT_BUTTON_HELP
Label for help button.
Definition: GUITextGenerator.hh:60
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
Definition: ProDeTextGenerator.hh:49
ProDeTextGenerator::MSG_ERROR_ILLEGAL_NAME
@ MSG_ERROR_ILLEGAL_NAME
Error: Illegal component name.
Definition: ProDeTextGenerator.hh:223
ImmediateSlotDialog::slotList_
wxListCtrl * slotList_
Immediate slot list widget.
Definition: ImmediateSlotDialog.hh:65
ProDeTextGenerator::MSG_ERROR_SAME_NAME
@ MSG_ERROR_SAME_NAME
Error: Same name exists.
Definition: ProDeTextGenerator.hh:229
ImmediateSlotDialog::slotName_
wxString slotName_
Text in the slot name widget.
Definition: ImmediateSlotDialog.hh:67
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
ImmediateSlotDialog::ID_LINE
@ ID_LINE
Definition: ImmediateSlotDialog.hh:76
ImmediateSlotDialog::ID_LABEL_NAME
@ ID_LABEL_NAME
Definition: ImmediateSlotDialog.hh:72
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
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
MachineTester::isValidComponentName
static bool isValidComponentName(const std::string &name)
Definition: MachineTester.cc:312
TTAMachine::Machine::immediateSlotNavigator
virtual ImmediateSlotNavigator immediateSlotNavigator() const
Definition: Machine.cc:462
GUITextGenerator::TXT_BUTTON_DELETE
@ TXT_BUTTON_DELETE
Label for delete button.
Definition: GUITextGenerator.hh:56
ProDeTextGenerator::instance
static ProDeTextGenerator * instance()
Definition: ProDeTextGenerator.cc:382
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
TTAMachine::Machine::busNavigator
virtual BusNavigator busNavigator() const
Definition: Machine.cc:356
ImmediateSlotDialog::ID_HELP
@ ID_HELP
Definition: ImmediateSlotDialog.hh:77
ImmediateSlotDialog::ID_LABE_NAME
@ ID_LABE_NAME
Definition: ImmediateSlotDialog.hh:73
ProDeTextGenerator::COMP_MACHINE
@ COMP_MACHINE
Text for machine description.
Definition: ProDeTextGenerator.hh:252
TTAMachine::Machine::Navigator::item
ComponentType * item(int index) const
ImmediateSlotDialog::machine_
TTAMachine::Machine * machine_
Parent machine of the immediate slots.
Definition: ImmediateSlotDialog.hh:63
InformationDialog
Definition: InformationDialog.hh:42
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
ImmediateSlotDialog::ID_ADD_SLOT
@ ID_ADD_SLOT
Definition: ImmediateSlotDialog.hh:74
GUITextGenerator::TXT_BUTTON_OK
@ TXT_BUTTON_OK
Label for OK button.
Definition: GUITextGenerator.hh:59