OpenASIP 2.2
Loading...
Searching...
No Matches
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.
 
wxChoice * indexChoice_
 Choice widget for register index selection.
 
wxCheckBox * invertedBox_
 Checkbox widget for the inverted flag.
 
bool inverted_
 Inverted flag of the guard.
 
bool newInverted_
 Modified inverted flag of the guard.
 
int index_
 Register index of the guard.
 
int newIndex_
 Modified register index of the guard.
 
const TTAMachine::RegisterFilerf_
 Guard register.
 
TTAMachine::Busbus_
 Parent bus of the register guard.
 
bool adding_
 True if a new guard is being added, false otherwise.
 

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.

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();
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}
const TTAMachine::RegisterFile * rf_
Guard register.
bool adding_
True if a new guard is being added, false otherwise.
int index_
Register index of the guard.
bool newInverted_
Modified inverted flag of the guard.
wxSizer * createContents(wxWindow *parent, bool call_fit, bool set_sizer)
int newIndex_
Modified register index of the guard.
wxChoice * nameChoice_
Choice widget for register file name selection.
TTAMachine::Bus * bus_
Parent bus of the register guard.
bool inverted_
Inverted flag of the guard.
wxChoice * indexChoice_
Choice widget for register index selection.
wxCheckBox * invertedBox_
Checkbox widget for the inverted flag.
virtual Machine * machine() const
virtual bool isInverted() const
ComponentType * item(int index) const
virtual RegisterFileNavigator registerFileNavigator() const
Definition Machine.cc:450
const RegisterFile * registerFile() const

◆ ~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}

References ID_HELP, ID_INVERTED, ID_LABEL_INDEX, ID_LABEL_NAME, ID_LINE, ID_RF_INDEX, and ID_RF_NAME.

◆ 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}

References adding_, bus_, index_, inverted_, and rf_.

◆ 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}
#define assert(condition)
static ProDeTextGenerator * instance()
@ MSG_ERROR_GUARD_EXISTS
Error: Equal guard exists.
@ TXT_ALL
Text 'all' in lower case.
const TTAMachine::RegisterFile * selectedRF() const
virtual int numberOfRegisters() const
Guard * guard(int index) const
Definition Bus.cc:456
int guardCount() const
Definition Bus.cc:441
virtual TCEString name() const
virtual boost::format text(int textId)
static wxString toWxString(const std::string &source)
static std::string toString(const wxString &source)

References adding_, assert, bus_, TTAMachine::Bus::guard(), TTAMachine::Bus::guardCount(), indexChoice_, ProDeTextGenerator::instance(), TTAMachine::Guard::isInverted(), ProDeTextGenerator::MSG_ERROR_GUARD_EXISTS, TTAMachine::Component::name(), nameChoice_, newIndex_, newInverted_, TTAMachine::BaseRegisterFile::numberOfRegisters(), TTAMachine::RegisterGuard::registerFile(), selectedRF(), 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 adding_, indexChoice_, ProDeTextGenerator::instance(), TTAMachine::BaseRegisterFile::numberOfRegisters(), selectedRF(), 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 bus_, TTAMachine::Machine::Navigator< ComponentType >::item(), TTAMachine::Component::machine(), nameChoice_, TTAMachine::Machine::registerFileNavigator(), and WxConversion::toString().

Referenced by onOK(), onRFChoice(), and TransferDataToWindow().

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}
@ TXT_BUTTON_HELP
Label for help button.
@ TXT_BUTTON_CANCEL
Label for cancel button.
@ TXT_BUTTON_OK
Label for OK button.
static GUITextGenerator * instance()
@ TXT_LABEL_REGISTER_INDEX
Label for register index widget.
@ TXT_RF_GUARD_DIALOG_TITLE
Register file guard dialog title.
@ TXT_LABEL_RF_NAME
Label for register file name.
@ TXT_LABEL_INVERTED
Label for inverted checkbox.
static void setLabel(Texts::TextGenerator *generator, wxWindow *widget, int textID)

References ID_HELP, ID_INVERTED, ID_LABEL_INDEX, ID_LABEL_NAME, 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 adding_, bus_, TTAMachine::Machine::Navigator< ComponentType >::count(), indexChoice_, ProDeTextGenerator::instance(), invertedBox_, TTAMachine::Machine::Navigator< ComponentType >::item(), TTAMachine::Component::machine(), TTAMachine::Component::name(), nameChoice_, newIndex_, newInverted_, TTAMachine::BaseRegisterFile::numberOfRegisters(), TTAMachine::Machine::registerFileNavigator(), rf_, selectedRF(), 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.

Referenced by onCancel(), onOK(), onRFChoice(), and TransferDataToWindow().

◆ bus_

TTAMachine::Bus* RFGuardDialog::bus_
private

Parent bus of the register guard.

Definition at line 81 of file RFGuardDialog.hh.

Referenced by onCancel(), onOK(), selectedRF(), and TransferDataToWindow().

◆ index_

int RFGuardDialog::index_
private

Register index of the guard.

Definition at line 75 of file RFGuardDialog.hh.

Referenced by onCancel().

◆ indexChoice_

wxChoice* RFGuardDialog::indexChoice_
private

Choice widget for register index selection.

Definition at line 66 of file RFGuardDialog.hh.

Referenced by onOK(), onRFChoice(), and TransferDataToWindow().

◆ inverted_

bool RFGuardDialog::inverted_
private

Inverted flag of the guard.

Definition at line 71 of file RFGuardDialog.hh.

Referenced by onCancel().

◆ invertedBox_

wxCheckBox* RFGuardDialog::invertedBox_
private

Checkbox widget for the inverted flag.

Definition at line 68 of file RFGuardDialog.hh.

Referenced by TransferDataToWindow().

◆ nameChoice_

wxChoice* RFGuardDialog::nameChoice_
private

Choice widget for register file name selection.

Definition at line 64 of file RFGuardDialog.hh.

Referenced by onOK(), selectedRF(), and TransferDataToWindow().

◆ newIndex_

int RFGuardDialog::newIndex_
private

Modified register index of the guard.

Definition at line 77 of file RFGuardDialog.hh.

Referenced by onOK(), and TransferDataToWindow().

◆ newInverted_

bool RFGuardDialog::newInverted_
private

Modified inverted flag of the guard.

Definition at line 73 of file RFGuardDialog.hh.

Referenced by onOK(), and TransferDataToWindow().

◆ rf_

const TTAMachine::RegisterFile* RFGuardDialog::rf_
private

Guard register.

Definition at line 79 of file RFGuardDialog.hh.

Referenced by onCancel(), and TransferDataToWindow().


The documentation for this class was generated from the following files: