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

#include <FUGuardDialog.hh>

Inheritance diagram for FUGuardDialog:
Inheritance graph
Collaboration diagram for FUGuardDialog:
Collaboration graph

Public Member Functions

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

Private Types

enum  {
  ID_LABEL_NAME = 10000, ID_LABEL_PORT, ID_FU_NAME, ID_FU_PORT,
  ID_INVERTED, ID_HELP, ID_LINE
}
 

Private Member Functions

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

Private Attributes

wxChoice * nameChoice_
 Choice widget for the function unit selection. More...
 
wxChoice * portChoice_
 Choice widget for the port selection. More...
 
wxCheckBox * invertedBox_
 Checkbox widget for the inverted flag. More...
 
bool inverted_
 Inverted flag for the guard. More...
 
bool newInverted_
 Modified inverted flag. More...
 
TTAMachine::FUPortport_
 Port of the guard. More...
 
TTAMachine::Busbus_
 Parent bus of the guard. More...
 
bool adding_
 True if a new guard is being added, false otherwise. More...
 

Detailed Description

Dialog for editing function unit port guard properties.

Definition at line 47 of file FUGuardDialog.hh.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
private
Enumerator
ID_LABEL_NAME 
ID_LABEL_PORT 
ID_FU_NAME 
ID_FU_PORT 
ID_INVERTED 
ID_HELP 
ID_LINE 

Definition at line 84 of file FUGuardDialog.hh.

84  {
85  ID_LABEL_NAME = 10000,
87  ID_FU_NAME,
88  ID_FU_PORT,
90  ID_HELP,
91  ID_LINE
92  };

Constructor & Destructor Documentation

◆ FUGuardDialog()

FUGuardDialog::FUGuardDialog ( wxWindow *  parent,
TTAMachine::Bus bus,
TTAMachine::PortGuard guard = NULL 
)

The Constructor.

Parameters
parentParent window of the dialog.
guardPort guard to edit.

Definition at line 65 of file FUGuardDialog.cc.

68  :
69  wxDialog(parent, -1, _T(""), wxDefaultPosition),
70  inverted_(false),
71  newInverted_(false),
72  port_(NULL),
73  bus_(bus),
74  adding_(false) {
75 
76 
77  if (guard == NULL) {
78  // adding a new guard
79  adding_ = true;
80 
83 
84  for (int i = 0; i < navigator.count(); i++) {
85  if (navigator.item(i)->operationPortCount() > 0) {
86  port_ = navigator.item(i)->operationPort(0);
87  break;
88  }
89  }
90 
91  assert(port_ != NULL);
92 
93  } else {
94  // editing an old guard
95  port_ = guard->port();
96  inverted_ = guard->isInverted();
98  bus_ = guard->parentBus();
99 
100  // The guard is temporarily deleted to simplify legality checks.
101  delete guard;
102  guard = NULL;
103  }
104 
105  createContents(this, true, true);
106 
107  // set pointers to the dialog widgets
108  nameChoice_ = dynamic_cast<wxChoice*>(FindWindow(ID_FU_NAME));
109  portChoice_ = dynamic_cast<wxChoice*>(FindWindow(ID_FU_PORT));
110  invertedBox_ = dynamic_cast<wxCheckBox*>(FindWindow(ID_INVERTED));
111 
112  invertedBox_->SetValidator(wxGenericValidator(&newInverted_));
113 
114  // set widget texts.
115  setTexts();
116 }

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

Here is the call graph for this function:

◆ ~FUGuardDialog()

FUGuardDialog::~FUGuardDialog ( )
virtual

The Destructor.

Definition at line 122 of file FUGuardDialog.cc.

122  {
123 }

Member Function Documentation

◆ createContents()

wxSizer * FUGuardDialog::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 320 of file FUGuardDialog.cc.

321  {
322 
323  wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL );
324 
325  wxGridSizer *item1 = new wxGridSizer( 2, 0, 0 );
326 
327  wxStaticText *item2 = new wxStaticText( parent, ID_LABEL_NAME, wxT("Function Unit Name:"), wxDefaultPosition, wxDefaultSize, 0 );
328  item1->Add( item2, 0, wxALL, 5 );
329 
330  wxString *strs3 = (wxString*) NULL;
331  wxChoice *item3 = new wxChoice( parent, ID_FU_NAME, wxDefaultPosition, wxSize(100,-1), 0, strs3, 0 );
332  item1->Add( item3, 0, wxGROW|wxALL, 5 );
333 
334  wxStaticText *item4 = new wxStaticText( parent, ID_LABEL_PORT, wxT("Port Name:"), wxDefaultPosition, wxDefaultSize, 0 );
335  item1->Add( item4, 0, wxALL, 5 );
336 
337  wxString *strs5 = (wxString*) NULL;
338  wxChoice *item5 = new wxChoice( parent, ID_FU_PORT, wxDefaultPosition, wxSize(100,-1), 0, strs5, 0 );
339  item1->Add( item5, 0, wxGROW|wxALL, 5 );
340 
341  item0->Add( item1, 0, wxALIGN_CENTER|wxALL, 5 );
342 
343  wxCheckBox *item6 = new wxCheckBox( parent, ID_INVERTED, wxT("Inverted"), wxDefaultPosition, wxDefaultSize, 0 );
344  item0->Add( item6, 0, wxALL, 5 );
345 
346  wxStaticLine *item7 = new wxStaticLine( parent, ID_LINE, wxDefaultPosition, wxSize(20,-1), wxLI_HORIZONTAL );
347  item0->Add( item7, 0, wxGROW|wxALL, 5 );
348 
349  wxBoxSizer *item8 = new wxBoxSizer( wxHORIZONTAL );
350 
351  wxButton *item9 = new wxButton( parent, ID_HELP, wxT("&Help"), wxDefaultPosition, wxDefaultSize, 0 );
352  item8->Add( item9, 0, wxALIGN_CENTER|wxALL, 5 );
353 
354  wxButton *item10 = new wxButton( parent, wxID_OK, wxT("&OK"), wxDefaultPosition, wxDefaultSize, 0 );
355  item8->Add( item10, 0, wxALIGN_CENTER|wxALL, 5 );
356 
357  wxButton *item11 = new wxButton( parent, wxID_CANCEL, wxT("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
358  item8->Add( item11, 0, wxALIGN_CENTER|wxALL, 5 );
359 
360  item0->Add( item8, 0, wxALIGN_CENTER|wxALL, 5 );
361 
362  if (set_sizer)
363  {
364  parent->SetSizer( item0 );
365  if (call_fit)
366  item0->SetSizeHints( parent );
367  }
368 
369  return item0;
370 }

◆ onCancel()

void FUGuardDialog::onCancel ( wxCommandEvent &  event)
private

Cancels the dialog effects by creating the original port guard.

Closes the Dialog.

Definition at line 301 of file FUGuardDialog.cc.

301  {
302  if (adding_ == false) {
303  new PortGuard(inverted_, *port_, *bus_);
304  }
305  EndModal(wxID_CANCEL);
306 }

◆ onFUChoice()

void FUGuardDialog::onFUChoice ( wxCommandEvent &  event)
private

Updates the port choice when the function unit selection is changed.

Definition at line 208 of file FUGuardDialog.cc.

208  {
209 
210  wxString selection = portChoice_->GetStringSelection();
211 
212  portChoice_->Clear();
213 
214  FunctionUnit* fu = selectedFU();
215  for (int i = 0; i < fu->portCount(); i++) {
216  wxString name = WxConversion::toWxString(fu->port(i)->name());
217  portChoice_->Append(name);
218  }
219 
220  if (portChoice_->FindString(selection) >= 0) {
221  portChoice_->SetStringSelection(selection);
222  } else {
223  portChoice_->SetSelection(0);
224  }
225 }

References TTAMachine::Port::name(), TTAMachine::FunctionUnit::port(), TTAMachine::Unit::portCount(), and WxConversion::toWxString().

Here is the call graph for this function:

◆ onOK()

void FUGuardDialog::onOK ( wxCommandEvent &  event)
private

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

Closes the dialog.

Definition at line 266 of file FUGuardDialog.cc.

266  {
267  FUPort* port = selectedPort();
268  if (port == NULL) {
270  format message = prodeTexts->text(ProDeTextGenerator::MSG_ERROR);
271  InformationDialog dialog(
273  message.str() + "Select a port.\n"));
274  dialog.ShowModal();
275  return;
276  }
277 
278  TransferDataFromWindow();
279 
280  try {
281  new PortGuard(newInverted_, *port, *bus_);
282  } catch (ComponentAlreadyExists& e) {
284  format message =
286  InformationDialog dialog(
287  this, WxConversion::toWxString(message.str()));
288  dialog.ShowModal();
289  return;
290  }
291  EndModal(wxID_OK);
292 }

References ProDeTextGenerator::instance(), ProDeTextGenerator::MSG_ERROR, ProDeTextGenerator::MSG_ERROR_GUARD_EXISTS, Texts::TextGenerator::text(), and WxConversion::toWxString().

Here is the call graph for this function:

◆ selectedFU()

FunctionUnit * FUGuardDialog::selectedFU ( ) const
private

Returns a pointer to the selected function unit.

Returns
Pointer to the selected function unit.

Definition at line 234 of file FUGuardDialog.cc.

234  {
235  string name = WxConversion::toString(nameChoice_->GetStringSelection());
238  FunctionUnit* fu = navigator.item(name);
239  return fu;
240 }

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

Here is the call graph for this function:

◆ selectedPort()

FUPort * FUGuardDialog::selectedPort ( ) const
private

Returns a pointer to the selected function unit port.

Returns
Pointer to the selected function unit port.

Definition at line 249 of file FUGuardDialog.cc.

249  {
250  string name = WxConversion::toString(portChoice_->GetStringSelection());
251 
252  if (name == "") {
253  return NULL;
254  }
255 
256  FUPort* port = selectedFU()->operationPort(name);
257  return port;
258 }

References WxConversion::toString().

Here is the call graph for this function:

◆ setTexts()

void FUGuardDialog::setTexts ( )
private

Sets texts for widgets.

Definition at line 130 of file FUGuardDialog.cc.

130  {
133 
134  // Dialog title
135  format fmt = prodeTexts->text(
137  SetTitle(WxConversion::toWxString(fmt.str()));
138 
139  // buttons
140  WidgetTools::setLabel(generator, FindWindow(wxID_OK),
142 
143  WidgetTools::setLabel(generator, FindWindow(wxID_CANCEL),
145 
148 
149  // widget labels
152 
155 
158 }

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_FU_GUARD_DIALOG_TITLE, ProDeTextGenerator::TXT_LABEL_FU_NAME, ProDeTextGenerator::TXT_LABEL_INVERTED, and ProDeTextGenerator::TXT_LABEL_PORT_NAME.

Here is the call graph for this function:

◆ TransferDataToWindow()

bool FUGuardDialog::TransferDataToWindow ( )
virtual

Transfers data from the guard object to the dialog widgets.

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

Definition at line 167 of file FUGuardDialog.cc.

167  {
168  nameChoice_->Clear();
169  portChoice_->Clear();
170 
173 
174  // add function units and set selection
175  for (int i = 0; i < navigator.count(); i++) {
176  wxString name = WxConversion::toWxString(navigator.item(i)->name());
177  nameChoice_->Append(name);
178  }
179  nameChoice_->SetStringSelection(
181 
182  // add function unit ports and set selection
183  for (int i = 0; i < port_->parentUnit()->portCount(); i++) {
184 
185  // port must be output port
186  if (port_->parentUnit()->port(i)->outputSocket() == NULL) {
187  continue;
188  }
189 
190  wxString name =
192 
193  portChoice_->Append(name);
194  }
195  portChoice_->SetStringSelection(WxConversion::toWxString(port_->name()));
196 
197  // set inverted checkbox
198  invertedBox_->SetValue(newInverted_);
199 
200  return wxDialog::TransferDataToWindow();
201 }

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

Here is the call graph for this function:

Member Data Documentation

◆ adding_

bool FUGuardDialog::adding_
private

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

Definition at line 81 of file FUGuardDialog.hh.

◆ bus_

TTAMachine::Bus* FUGuardDialog::bus_
private

Parent bus of the guard.

Definition at line 79 of file FUGuardDialog.hh.

◆ inverted_

bool FUGuardDialog::inverted_
private

Inverted flag for the guard.

Definition at line 73 of file FUGuardDialog.hh.

◆ invertedBox_

wxCheckBox* FUGuardDialog::invertedBox_
private

Checkbox widget for the inverted flag.

Definition at line 70 of file FUGuardDialog.hh.

◆ nameChoice_

wxChoice* FUGuardDialog::nameChoice_
private

Choice widget for the function unit selection.

Definition at line 66 of file FUGuardDialog.hh.

◆ newInverted_

bool FUGuardDialog::newInverted_
private

Modified inverted flag.

Definition at line 75 of file FUGuardDialog.hh.

◆ port_

TTAMachine::FUPort* FUGuardDialog::port_
private

Port of the guard.

Definition at line 77 of file FUGuardDialog.hh.

◆ portChoice_

wxChoice* FUGuardDialog::portChoice_
private

Choice widget for the port selection.

Definition at line 68 of file FUGuardDialog.hh.


The documentation for this class was generated from the following files:
FUGuardDialog::createContents
wxSizer * createContents(wxWindow *parent, bool call_fit, bool set_sizer)
Definition: FUGuardDialog.cc:320
FUGuardDialog::ID_LABEL_NAME
@ ID_LABEL_NAME
Definition: FUGuardDialog.hh:85
WxConversion::toWxString
static wxString toWxString(const std::string &source)
FUGuardDialog::invertedBox_
wxCheckBox * invertedBox_
Checkbox widget for the inverted flag.
Definition: FUGuardDialog.hh:70
TTAMachine::Component::name
virtual TCEString name() const
Definition: MachinePart.cc:125
TTAMachine::PortGuard::port
FUPort * port() const
FUGuardDialog::ID_FU_PORT
@ ID_FU_PORT
Definition: FUGuardDialog.hh:88
FUGuardDialog::selectedFU
TTAMachine::FunctionUnit * selectedFU() const
Definition: FUGuardDialog.cc:234
FUGuardDialog::ID_FU_NAME
@ ID_FU_NAME
Definition: FUGuardDialog.hh:87
TTAMachine::BaseFUPort::parentUnit
FunctionUnit * parentUnit() const
Definition: BaseFUPort.cc:96
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
FUGuardDialog::nameChoice_
wxChoice * nameChoice_
Choice widget for the function unit selection.
Definition: FUGuardDialog.hh:66
GUITextGenerator
Definition: GUITextGenerator.hh:46
GUITextGenerator::TXT_BUTTON_HELP
@ TXT_BUTTON_HELP
Label for help button.
Definition: GUITextGenerator.hh:60
TTAMachine::FunctionUnit::port
virtual BaseFUPort * port(const std::string &name) const
Definition: FunctionUnit.cc:145
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
ProDeTextGenerator::MSG_ERROR_GUARD_EXISTS
@ MSG_ERROR_GUARD_EXISTS
Error: Equal guard exists.
Definition: ProDeTextGenerator.hh:242
FUGuardDialog::portChoice_
wxChoice * portChoice_
Choice widget for the port selection.
Definition: FUGuardDialog.hh:68
assert
#define assert(condition)
Definition: Application.hh:86
TTAMachine::FunctionUnit
Definition: FunctionUnit.hh:55
TTAMachine::FUPort
Definition: FUPort.hh:46
FUGuardDialog::ID_LABEL_PORT
@ ID_LABEL_PORT
Definition: FUGuardDialog.hh:86
GUITextGenerator::TXT_BUTTON_CANCEL
@ TXT_BUTTON_CANCEL
Label for cancel button.
Definition: GUITextGenerator.hh:55
FUGuardDialog::bus_
TTAMachine::Bus * bus_
Parent bus of the guard.
Definition: FUGuardDialog.hh:79
FUGuardDialog::newInverted_
bool newInverted_
Modified inverted flag.
Definition: FUGuardDialog.hh:75
TTAMachine::Machine::functionUnitNavigator
virtual FunctionUnitNavigator functionUnitNavigator() const
Definition: Machine.cc:380
ProDeTextGenerator::TXT_FU_GUARD_DIALOG_TITLE
@ TXT_FU_GUARD_DIALOG_TITLE
Function unit guard dialog title.
Definition: ProDeTextGenerator.hh:197
TTAMachine::Unit::portCount
virtual int portCount() const
Definition: Unit.cc:135
FUGuardDialog::setTexts
void setTexts()
Definition: FUGuardDialog.cc:130
ProDeTextGenerator::instance
static ProDeTextGenerator * instance()
Definition: ProDeTextGenerator.cc:382
TTAMachine::Guard::parentBus
virtual Bus * parentBus() const
FUGuardDialog::inverted_
bool inverted_
Inverted flag for the guard.
Definition: FUGuardDialog.hh:73
ProDeTextGenerator::MSG_ERROR
@ MSG_ERROR
Text 'Error' and new line.
Definition: ProDeTextGenerator.hh:222
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
TTAMachine::Port::name
virtual std::string name() const
Definition: Port.cc:141
FUGuardDialog::ID_INVERTED
@ ID_INVERTED
Definition: FUGuardDialog.hh:89
TTAMachine::Port::outputSocket
virtual Socket * outputSocket() const
Definition: Port.cc:281
ComponentAlreadyExists
Definition: Exception.hh:510
FUGuardDialog::selectedPort
TTAMachine::FUPort * selectedPort() const
Definition: FUGuardDialog.cc:249
TTAMachine::Machine::Navigator::item
ComponentType * item(int index) const
TTAMachine::PortGuard
Definition: Guard.hh:99
InformationDialog
Definition: InformationDialog.hh:42
TTAMachine::FunctionUnit::operationPort
virtual FUPort * operationPort(const std::string &name) const
Definition: FunctionUnit.cc:224
FUGuardDialog::ID_HELP
@ ID_HELP
Definition: FUGuardDialog.hh:90
ProDeTextGenerator::TXT_LABEL_PORT_NAME
@ TXT_LABEL_PORT_NAME
Label for port name.
Definition: ProDeTextGenerator.hh:84
ProDeTextGenerator::TXT_LABEL_FU_NAME
@ TXT_LABEL_FU_NAME
Label for function unit name.
Definition: ProDeTextGenerator.hh:83
WxConversion::toString
static std::string toString(const wxString &source)
FUGuardDialog::adding_
bool adding_
True if a new guard is being added, false otherwise.
Definition: FUGuardDialog.hh:81
TTAMachine::Machine::Navigator
Definition: Machine.hh:186
FUGuardDialog::ID_LINE
@ ID_LINE
Definition: FUGuardDialog.hh:91
FUGuardDialog::port_
TTAMachine::FUPort * port_
Port of the guard.
Definition: FUGuardDialog.hh:77
GUITextGenerator::TXT_BUTTON_OK
@ TXT_BUTTON_OK
Label for OK button.
Definition: GUITextGenerator.hh:59