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

#include <RFGuardDialog.hh>

Inheritance diagram for RFGuardDialog:
Inheritance graph
Collaboration diagram for RFGuardDialog:
Collaboration graph

Public Member Functions

 RFGuardDialog (wxWindow *parent, TTAMachine::Bus *bus, TTAMachine::RegisterGuard *guard=NULL)
 
virtual ~RFGuardDialog ()
 
virtual bool TransferDataToWindow ()
 

Private Types

enum  {
  ID_LABEL_NAME = 10000, ID_RF_NAME, ID_LABEL_INDEX, ID_RF_INDEX,
  ID_INVERTED, ID_HELP, ID_LINE
}
 

Private Member Functions

wxSizer * createContents (wxWindow *parent, bool call_fit, bool set_sizer)
 
void onRFChoice (wxCommandEvent &event)
 
void onOK (wxCommandEvent &event)
 
void onCancel (wxCommandEvent &event)
 
const TTAMachine::RegisterFileselectedRF () const
 
void setTexts ()
 

Private Attributes

wxChoice * nameChoice_
 Choice widget for register file name selection. More...
 
wxChoice * indexChoice_
 Choice widget for register index selection. More...
 
wxCheckBox * invertedBox_
 Checkbox widget for the inverted flag. More...
 
bool inverted_
 Inverted flag of the guard. More...
 
bool newInverted_
 Modified inverted flag of the guard. More...
 
int index_
 Register index of the guard. More...
 
int newIndex_
 Modified register index of the guard. More...
 
const TTAMachine::RegisterFilerf_
 Guard register. More...
 
TTAMachine::Busbus_
 Parent bus of the register guard. More...
 
bool adding_
 True if a new guard is being added, false otherwise. More...
 

Detailed Description

Dialog for editing register file guard properties.

Definition at line 46 of file RFGuardDialog.hh.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
private
Enumerator
ID_LABEL_NAME 
ID_RF_NAME 
ID_LABEL_INDEX 
ID_RF_INDEX 
ID_INVERTED 
ID_HELP 
ID_LINE 

Definition at line 86 of file RFGuardDialog.hh.

86  {
87  ID_LABEL_NAME = 10000,
88  ID_RF_NAME,
92  ID_HELP,
93  ID_LINE
94  };

Constructor & Destructor Documentation

◆ RFGuardDialog()

RFGuardDialog::RFGuardDialog ( wxWindow *  parent,
TTAMachine::Bus bus,
TTAMachine::RegisterGuard guard = NULL 
)

The Constructor.

Parameters
parentParent window of the dialog.

Definition at line 62 of file RFGuardDialog.cc.

65  :
66  wxDialog(parent, -1, _T(""), wxDefaultPosition),
67  inverted_(false),
68  newInverted_(false),
69  index_(0),
70  newIndex_(0),
71  rf_(NULL),
72  bus_(bus),
73  adding_(false) {
74 
75 
76  if (guard == NULL) {
77  // adding a new guard
78  adding_ = true;
80  } else {
81  // editing an old guard
82  rf_ = guard->registerFile();
83  index_ = guard->registerIndex();
84  newIndex_ = index_;
85  inverted_ = guard->isInverted();
86 
87  // The guard is temporarily deleted to simplify legality checks.
88  delete guard;
89  guard = NULL;
90  }
92 
93  createContents(this, true, true);
94 
95  // set pointers to the dialog widgets
96  nameChoice_ = dynamic_cast<wxChoice*>(FindWindow(ID_RF_NAME));
97  indexChoice_ = dynamic_cast<wxChoice*>(FindWindow(ID_RF_INDEX));
98  invertedBox_ = dynamic_cast<wxCheckBox*>(FindWindow(ID_INVERTED));
99 
100  invertedBox_->SetValidator(wxGenericValidator(&newInverted_));
101  indexChoice_->SetValidator(wxGenericValidator(&newIndex_));
102 
103  // set widget texts.
104  setTexts();
105 }

◆ ~RFGuardDialog()

RFGuardDialog::~RFGuardDialog ( )
virtual

The Destructor.

Definition at line 111 of file RFGuardDialog.cc.

111  {
112 }

Member Function Documentation

◆ createContents()

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

Creates contents of the dialog window.

Code generated with wxDesigner.

Parameters
parentParent dialog of the contents.
call_fitIf true, fits sizer in dialog window.
set_sizerIf true, sets sizer as dialog's sizer.
Returns
Top level sizer of the contents.

Definition at line 347 of file RFGuardDialog.cc.

348  {
349 
350  wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL );
351 
352  wxGridSizer *item1 = new wxGridSizer( 2, 0, 0 );
353 
354  wxStaticText *item2 = new wxStaticText( parent, ID_LABEL_NAME, wxT("Register File Name:"), wxDefaultPosition, wxDefaultSize, 0 );
355  item1->Add( item2, 0, wxALL, 5 );
356 
357  wxString *strs3 = (wxString*) NULL;
358  wxChoice *item3 = new wxChoice( parent, ID_RF_NAME, wxDefaultPosition, wxSize(100,-1), 0, strs3, 0 );
359  item1->Add( item3, 0, wxGROW|wxALL, 5 );
360 
361  wxStaticText *item4 = new wxStaticText( parent, ID_LABEL_INDEX, wxT("Register Index:"), wxDefaultPosition, wxDefaultSize, 0 );
362  item1->Add( item4, 0, wxALL, 5 );
363 
364  wxString *strs5 = (wxString*) NULL;
365  wxChoice *item5 = new wxChoice( parent, ID_RF_INDEX, wxDefaultPosition, wxSize(100,-1), 0, strs5, 0 );
366  item1->Add( item5, 0, wxGROW|wxALL, 5 );
367 
368  item0->Add( item1, 0, wxGROW|wxALL, 5 );
369 
370  wxCheckBox *item6 = new wxCheckBox( parent, ID_INVERTED, wxT("Inverted"), wxDefaultPosition, wxDefaultSize, 0 );
371  item0->Add( item6, 0, wxALL, 5 );
372 
373  wxStaticLine *item7 = new wxStaticLine( parent, ID_LINE, wxDefaultPosition, wxSize(20,-1), wxLI_HORIZONTAL );
374  item0->Add( item7, 0, wxGROW|wxALL, 5 );
375 
376  wxBoxSizer *item8 = new wxBoxSizer( wxHORIZONTAL );
377 
378  wxButton *item9 = new wxButton( parent, ID_HELP, wxT("&Help"), wxDefaultPosition, wxDefaultSize, 0 );
379  item8->Add( item9, 0, wxALIGN_CENTER|wxALL, 5 );
380 
381  wxButton *item10 = new wxButton( parent, wxID_OK, wxT("&OK"), wxDefaultPosition, wxDefaultSize, 0 );
382  item8->Add( item10, 0, wxALIGN_CENTER|wxALL, 5 );
383 
384  wxButton *item11 = new wxButton( parent, wxID_CANCEL, wxT("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
385  item8->Add( item11, 0, wxALIGN_CENTER|wxALL, 5 );
386 
387  item0->Add( item8, 0, wxALIGN_CENTER|wxALL, 5 );
388 
389  if (set_sizer)
390  {
391  parent->SetSizer( item0 );
392  if (call_fit)
393  item0->SetSizeHints( parent );
394  }
395 
396  return item0;
397 }

◆ onCancel()

void RFGuardDialog::onCancel ( wxCommandEvent &  event)
private

Cancels the dialog effects by creating the original register guard.

Closes the dialog.

Definition at line 328 of file RFGuardDialog.cc.

328  {
329  if (adding_ == false) {
331  }
332  EndModal(wxID_CANCEL);
333 }

◆ onOK()

void RFGuardDialog::onOK ( wxCommandEvent &  event)
private

Updates the guard object when the OK-button is pressed.

Closes the dialog.

Definition at line 244 of file RFGuardDialog.cc.

244  {
245  TransferDataFromWindow();
246  try {
247  // get currently selected index and its string representation
248  int indexSelection = indexChoice_->GetSelection();
249  assert(indexSelection != wxNOT_FOUND);
250  wxString choiceText = indexChoice_->GetString(indexSelection);
251 
252  // get the string that resembles all indices
254  format fmtAll = prodeTexts->text(ProDeTextGenerator::TXT_ALL);
255  bool singleGuard = true;
256 
257  // check if user has selected all indices
258  if (choiceText.IsSameAs(WxConversion::toWxString(fmtAll.str()))) {
259  singleGuard = false;
260  }
261 
262  if (!adding_ || (adding_ && singleGuard)) {
263  // add / edit one guard
265  bus_);
266  } else {
267  // add new guard for every index
268 
269  string rfNameSel = WxConversion::toString(
270  nameChoice_->GetStringSelection());
271 
272  // loop all bus guards and mark old guards (if there is any)
273  // of the selected register file name to be deleted
274  std::vector<RegisterGuard*> toBeDeleted;
275  for (int i = 0; i < bus_->guardCount(); ++i) {
276  Guard* g = bus_->guard(i);
277  RegisterGuard* rfGuard =
278  dynamic_cast<RegisterGuard*>(g);
279 
280  if (rfGuard != NULL) {
281  string rfName = rfGuard->registerFile()->name();
282 
283  // if register file names match
284  if (rfName.compare(rfNameSel) == 0) {
285  // if inverted setting is same
286  if (rfGuard->isInverted() == newInverted_) {
287  toBeDeleted.push_back(rfGuard);
288  }
289  }
290  }
291  }
292 
293  // delete old guards
294  for (unsigned int i = 0; i < toBeDeleted.size(); ++i) {
295  if (toBeDeleted.at(i) != NULL) {
296  delete toBeDeleted.at(i);
297  toBeDeleted.at(i) = NULL;
298  }
299  }
300 
301  // create new guard for every file register's index
302  for (int index = 0; index < selectedRF()->numberOfRegisters();
303  ++index) {
304  new RegisterGuard(newInverted_, *selectedRF(), index,
305  bus_);
306  }
307  }
308  } catch (ComponentAlreadyExists& e) {
310  format message =
312  InformationDialog dialog(
313  this, WxConversion::toWxString(message.str()));
314  dialog.ShowModal();
315  return;
316  }
317 
318  EndModal(wxID_OK);
319 }

References assert, ProDeTextGenerator::instance(), TTAMachine::Guard::isInverted(), ProDeTextGenerator::MSG_ERROR_GUARD_EXISTS, TTAMachine::Component::name(), TTAMachine::RegisterGuard::registerFile(), Texts::TextGenerator::text(), WxConversion::toString(), WxConversion::toWxString(), and ProDeTextGenerator::TXT_ALL.

Here is the call graph for this function:

◆ onRFChoice()

void RFGuardDialog::onRFChoice ( wxCommandEvent &  event)
private

Updates the index choice when the register file selection is changed.

Definition at line 196 of file RFGuardDialog.cc.

196  {
197 
198  int selection = indexChoice_->GetSelection();
199 
200  indexChoice_->Clear();
201 
202  const RegisterFile* rf = selectedRF();
203  for (int i = 0; i < rf->numberOfRegisters(); i++) {
204  wxString index = WxConversion::toWxString(i);
205  indexChoice_->Append(index);
206  }
207 
208  // add choice to create guard for every index
209  if (adding_) {
211  format fmtAll = prodeTexts->text(ProDeTextGenerator::TXT_ALL);
212  indexChoice_->Append(WxConversion::toWxString(fmtAll.str()));
213  }
214 
215  if (static_cast<int>(indexChoice_->GetCount()) >= selection) {
216  indexChoice_->SetSelection(selection);
217  } else {
218  indexChoice_->SetSelection(0);
219  }
220 }

References ProDeTextGenerator::instance(), TTAMachine::BaseRegisterFile::numberOfRegisters(), Texts::TextGenerator::text(), WxConversion::toWxString(), and ProDeTextGenerator::TXT_ALL.

Here is the call graph for this function:

◆ selectedRF()

const RegisterFile * RFGuardDialog::selectedRF ( ) const
private

Returns a pointer to the selected register file.

Returns
Pointer to the selected refister file.

Definition at line 229 of file RFGuardDialog.cc.

229  {
230  string name = WxConversion::toString(nameChoice_->GetStringSelection());
233  RegisterFile* rf = navigator.item(name);
234  return rf;
235 }

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

Here is the call graph for this function:

◆ setTexts()

void RFGuardDialog::setTexts ( )
private

Sets texts for widgets.

Definition at line 119 of file RFGuardDialog.cc.

119  {
122 
123  // Dialog title
124  format fmt = prodeTexts->text(
126  SetTitle(WxConversion::toWxString(fmt.str()));
127 
128  // buttons
129  WidgetTools::setLabel(generator, FindWindow(wxID_OK),
131 
132  WidgetTools::setLabel(generator, FindWindow(wxID_CANCEL),
134 
137 
138  // widget labels
141 
144 
147 }

References GUITextGenerator::instance(), ProDeTextGenerator::instance(), WidgetTools::setLabel(), Texts::TextGenerator::text(), WxConversion::toWxString(), GUITextGenerator::TXT_BUTTON_CANCEL, GUITextGenerator::TXT_BUTTON_HELP, GUITextGenerator::TXT_BUTTON_OK, ProDeTextGenerator::TXT_LABEL_INVERTED, ProDeTextGenerator::TXT_LABEL_REGISTER_INDEX, ProDeTextGenerator::TXT_LABEL_RF_NAME, and ProDeTextGenerator::TXT_RF_GUARD_DIALOG_TITLE.

Here is the call graph for this function:

◆ TransferDataToWindow()

bool RFGuardDialog::TransferDataToWindow ( )
virtual

Transfers data from the Guard object to the dialog widgets.

Returns
true, if the transfer was succesful, false otherwise.

Definition at line 156 of file RFGuardDialog.cc.

156  {
157  nameChoice_->Clear();
158  indexChoice_->Clear();
159 
162 
163  // set register file name
164  for (int i = 0; i < navigator.count(); i++) {
165  wxString name = WxConversion::toWxString(navigator.item(i)->name());
166  nameChoice_->Append(name);
167  }
168  nameChoice_->SetStringSelection(WxConversion::toWxString(rf_->name()));
169 
170  // set register index
171  for (int i = 0; i < selectedRF()->numberOfRegisters(); i++) {
172  wxString index = WxConversion::toWxString(i);
173  indexChoice_->Append(index);
174  }
175 
176  // add choice to create guard for every index
177  if (adding_) {
179  format fmtAll = prodeTexts->text(ProDeTextGenerator::TXT_ALL);
180  indexChoice_->Append(WxConversion::toWxString(fmtAll.str()));
181  }
182 
183  indexChoice_->SetSelection(newIndex_);
184 
185  // set inverted flag
186  invertedBox_->SetValue(newInverted_);
187 
188  return wxDialog::TransferDataToWindow();
189 }

References TTAMachine::Machine::Navigator< ComponentType >::count(), ProDeTextGenerator::instance(), TTAMachine::Machine::Navigator< ComponentType >::item(), Texts::TextGenerator::text(), WxConversion::toWxString(), and ProDeTextGenerator::TXT_ALL.

Here is the call graph for this function:

Member Data Documentation

◆ adding_

bool RFGuardDialog::adding_
private

True if a new guard is being added, false otherwise.

Definition at line 83 of file RFGuardDialog.hh.

◆ bus_

TTAMachine::Bus* RFGuardDialog::bus_
private

Parent bus of the register guard.

Definition at line 81 of file RFGuardDialog.hh.

◆ index_

int RFGuardDialog::index_
private

Register index of the guard.

Definition at line 75 of file RFGuardDialog.hh.

◆ indexChoice_

wxChoice* RFGuardDialog::indexChoice_
private

Choice widget for register index selection.

Definition at line 66 of file RFGuardDialog.hh.

◆ inverted_

bool RFGuardDialog::inverted_
private

Inverted flag of the guard.

Definition at line 71 of file RFGuardDialog.hh.

◆ invertedBox_

wxCheckBox* RFGuardDialog::invertedBox_
private

Checkbox widget for the inverted flag.

Definition at line 68 of file RFGuardDialog.hh.

◆ nameChoice_

wxChoice* RFGuardDialog::nameChoice_
private

Choice widget for register file name selection.

Definition at line 64 of file RFGuardDialog.hh.

◆ newIndex_

int RFGuardDialog::newIndex_
private

Modified register index of the guard.

Definition at line 77 of file RFGuardDialog.hh.

◆ newInverted_

bool RFGuardDialog::newInverted_
private

Modified inverted flag of the guard.

Definition at line 73 of file RFGuardDialog.hh.

◆ rf_

const TTAMachine::RegisterFile* RFGuardDialog::rf_
private

Guard register.

Definition at line 79 of file RFGuardDialog.hh.


The documentation for this class was generated from the following files:
TTAMachine::Guard
Definition: Guard.hh:55
RFGuardDialog::adding_
bool adding_
True if a new guard is being added, false otherwise.
Definition: RFGuardDialog.hh:83
ProDeTextGenerator::TXT_LABEL_RF_NAME
@ TXT_LABEL_RF_NAME
Label for register file name.
Definition: ProDeTextGenerator.hh:86
RFGuardDialog::newIndex_
int newIndex_
Modified register index of the guard.
Definition: RFGuardDialog.hh:77
WxConversion::toWxString
static wxString toWxString(const std::string &source)
RFGuardDialog::indexChoice_
wxChoice * indexChoice_
Choice widget for register index selection.
Definition: RFGuardDialog.hh:66
TTAMachine::Component::name
virtual TCEString name() const
Definition: MachinePart.cc:125
TTAMachine::RegisterGuard::registerIndex
int registerIndex() const
RFGuardDialog::index_
int index_
Register index of the guard.
Definition: RFGuardDialog.hh:75
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
RFGuardDialog::invertedBox_
wxCheckBox * invertedBox_
Checkbox widget for the inverted flag.
Definition: RFGuardDialog.hh:68
GUITextGenerator
Definition: GUITextGenerator.hh:46
RFGuardDialog::ID_LINE
@ ID_LINE
Definition: RFGuardDialog.hh:93
GUITextGenerator::TXT_BUTTON_HELP
@ TXT_BUTTON_HELP
Label for help button.
Definition: GUITextGenerator.hh:60
RFGuardDialog::ID_INVERTED
@ ID_INVERTED
Definition: RFGuardDialog.hh:91
FindWindow
Definition: FindWindow.hh:49
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
RFGuardDialog::newInverted_
bool newInverted_
Modified inverted flag of the guard.
Definition: RFGuardDialog.hh:73
ProDeTextGenerator::MSG_ERROR_GUARD_EXISTS
@ MSG_ERROR_GUARD_EXISTS
Error: Equal guard exists.
Definition: ProDeTextGenerator.hh:242
TTAMachine::BaseRegisterFile::numberOfRegisters
virtual int numberOfRegisters() const
assert
#define assert(condition)
Definition: Application.hh:86
RFGuardDialog::ID_RF_INDEX
@ ID_RF_INDEX
Definition: RFGuardDialog.hh:90
RFGuardDialog::setTexts
void setTexts()
Definition: RFGuardDialog.cc:119
ProDeTextGenerator::TXT_ALL
@ TXT_ALL
Text 'all' in lower case.
Definition: ProDeTextGenerator.hh:132
GUITextGenerator::TXT_BUTTON_CANCEL
@ TXT_BUTTON_CANCEL
Label for cancel button.
Definition: GUITextGenerator.hh:55
ProDeTextGenerator::TXT_RF_GUARD_DIALOG_TITLE
@ TXT_RF_GUARD_DIALOG_TITLE
Register file guard dialog title.
Definition: ProDeTextGenerator.hh:199
TTAMachine::RegisterGuard
Definition: Guard.hh:137
RFGuardDialog::ID_RF_NAME
@ ID_RF_NAME
Definition: RFGuardDialog.hh:88
RFGuardDialog::ID_LABEL_INDEX
@ ID_LABEL_INDEX
Definition: RFGuardDialog.hh:89
RFGuardDialog::bus_
TTAMachine::Bus * bus_
Parent bus of the register guard.
Definition: RFGuardDialog.hh:81
RFGuardDialog::createContents
wxSizer * createContents(wxWindow *parent, bool call_fit, bool set_sizer)
Definition: RFGuardDialog.cc:347
RFGuardDialog::nameChoice_
wxChoice * nameChoice_
Choice widget for register file name selection.
Definition: RFGuardDialog.hh:64
TTAMachine::Bus::guardCount
int guardCount() const
Definition: Bus.cc:441
TTAMachine::Bus::guard
Guard * guard(int index) const
Definition: Bus.cc:456
RFGuardDialog::selectedRF
const TTAMachine::RegisterFile * selectedRF() const
Definition: RFGuardDialog.cc:229
RFGuardDialog::ID_LABEL_NAME
@ ID_LABEL_NAME
Definition: RFGuardDialog.hh:87
ProDeTextGenerator::instance
static ProDeTextGenerator * instance()
Definition: ProDeTextGenerator.cc:382
TTAMachine::Machine::registerFileNavigator
virtual RegisterFileNavigator registerFileNavigator() const
Definition: Machine.cc:450
ProDeTextGenerator::TXT_LABEL_INVERTED
@ TXT_LABEL_INVERTED
Label for inverted checkbox.
Definition: ProDeTextGenerator.hh:85
TTAMachine::Guard::isInverted
virtual bool isInverted() const
TTAMachine::Component::machine
virtual Machine * machine() const
ComponentAlreadyExists
Definition: Exception.hh:510
ProDeTextGenerator::TXT_LABEL_REGISTER_INDEX
@ TXT_LABEL_REGISTER_INDEX
Label for register index widget.
Definition: ProDeTextGenerator.hh:87
TTAMachine::Machine::Navigator::item
ComponentType * item(int index) const
TTAMachine::RegisterFile
Definition: RegisterFile.hh:47
InformationDialog
Definition: InformationDialog.hh:42
WxConversion::toString
static std::string toString(const wxString &source)
TTAMachine::RegisterGuard::registerFile
const RegisterFile * registerFile() const
TTAMachine::Machine::Navigator
Definition: Machine.hh:186
RFGuardDialog::rf_
const TTAMachine::RegisterFile * rf_
Guard register.
Definition: RFGuardDialog.hh:79
RFGuardDialog::ID_HELP
@ ID_HELP
Definition: RFGuardDialog.hh:92
RFGuardDialog::inverted_
bool inverted_
Inverted flag of the guard.
Definition: RFGuardDialog.hh:71
GUITextGenerator::TXT_BUTTON_OK
@ TXT_BUTTON_OK
Label for OK button.
Definition: GUITextGenerator.hh:59