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

#include <RFPortDialog.hh>

Inheritance diagram for RFPortDialog:
Inheritance graph
Collaboration diagram for RFPortDialog:
Collaboration graph

Public Member Functions

 RFPortDialog (wxWindow *parent, TTAMachine::Port *port)
 
virtual ~RFPortDialog ()
 

Private Types

enum  { ID_NAME = 10000, ID_INPUT_SOCKET, ID_OUTPUT_SOCKET, ID_HELP }
 enumerated IDs for the port controls More...
 

Private Member Functions

wxSizer * createContents (wxWindow *parent, bool call_fit, bool set_sizer)
 
virtual bool TransferDataToWindow ()
 
void onOK (wxCommandEvent &event)
 
void onCancel (wxCommandEvent &event)
 
void onHelp (wxCommandEvent &event)
 
void onName (wxCommandEvent &event)
 
void onSocketChoice (wxCommandEvent &event)
 
void updateSockets ()
 
void setTexts ()
 

Private Attributes

TTAMachine::Portport_
 Port to modify. More...
 
wxString name_
 Name of the port. More...
 
wxChoice * inputSocketChoice_
 Input socket choice control. More...
 
wxChoice * outputSocketChoice_
 Output socket choice control. More...
 
TTAMachine::SocketoldInput_
 Original input socket of the port. More...
 
TTAMachine::SocketoldOutput_
 Original output socket of the port. More...
 

Detailed Description

Dialog for querying register file port parameters from the user.

Definition at line 44 of file RFPortDialog.hh.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
private

enumerated IDs for the port controls

Enumerator
ID_NAME 
ID_INPUT_SOCKET 
ID_OUTPUT_SOCKET 
ID_HELP 

Definition at line 74 of file RFPortDialog.hh.

74  {
75  ID_NAME = 10000,
78  ID_HELP
79  };

Constructor & Destructor Documentation

◆ RFPortDialog()

RFPortDialog::RFPortDialog ( wxWindow *  parent,
TTAMachine::Port port 
)

The Constructor.

Parameters
parentParent window of the dialog.
portPort to modify.

Definition at line 71 of file RFPortDialog.cc.

73  :
74  wxDialog(parent, -1, _T(""), wxDefaultPosition),
75  port_(port),
76  name_(_T("")),
77  inputSocketChoice_(NULL),
78  outputSocketChoice_(NULL) {
79 
82  createContents(this, true, true);
83  FindWindow(wxID_OK)->Disable();
84 
85  // set widget texts
86  setTexts();
87 
89 }

◆ ~RFPortDialog()

RFPortDialog::~RFPortDialog ( )
virtual

The Destructor.

Definition at line 94 of file RFPortDialog.cc.

94  {
95 }

Member Function Documentation

◆ createContents()

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

Creates contents of the dialog window. Initially generated with wxDesigner, the code will be cleaned up later.

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 340 of file RFPortDialog.cc.

341  {
342 
343  wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL );
344  wxFlexGridSizer *item1 = new wxFlexGridSizer( 2, 0, 0 );
345 
346  // name element
347  wxStaticText *item2 =
348  new wxStaticText( parent, -1, wxT("Name:"),
349  wxDefaultPosition, wxDefaultSize, 0 );
350  item1->Add( item2, 0, wxALIGN_RIGHT|wxALL, 5 );
351  wxTextCtrl *item3 =
352  new wxTextCtrl(parent, ID_NAME, wxT(""), wxDefaultPosition,
353  wxSize(160,-1), 0,
354  wxTextValidator(wxFILTER_ASCII, &name_) );
355  item1->Add( item3, 0, wxALIGN_CENTER|wxALL, 5 );
356 
357  // input socket element
358  wxStaticText *item4 =
359  new wxStaticText(parent, -1, wxT("Input Socket:"),
360  wxDefaultPosition, wxDefaultSize, 0);
361  item1->Add( item4, 0, wxALIGN_RIGHT|wxALL, 5 );
362  wxString *strs5 = (wxString*) NULL;
364  new wxChoice(parent, ID_INPUT_SOCKET, wxDefaultPosition,
365  wxSize(100,-1), 0, strs5, 0);
366  item1->Add( inputSocketChoice_, 0,
367  wxGROW|wxALL, 5 );
368 
369  // output socket element
370  wxStaticText *item6 =
371  new wxStaticText(parent, -1, wxT("Output Socket:"),
372  wxDefaultPosition, wxDefaultSize, 0);
373  item1->Add( item6, 0, wxALIGN_RIGHT|wxALL, 5 );
374  wxString *strs7 = (wxString*) NULL;
376  new wxChoice(parent, ID_OUTPUT_SOCKET, wxDefaultPosition,
377  wxSize(100,-1), 0, strs7, 0);
378  item1->Add( outputSocketChoice_, 0,
379  wxGROW|wxALL, 5 );
380  item0->Add( item1, 0, wxGROW|wxALL, 5 );
381  wxStaticLine *item8 =
382  new wxStaticLine(parent, -1, wxDefaultPosition, wxSize(20,-1),
383  wxLI_HORIZONTAL);
384  item0->Add( item8, 0, wxGROW|wxALL, 5 );
385  wxBoxSizer *item9 = new wxBoxSizer( wxHORIZONTAL );
386 
387  // buttons
388  wxButton *item10 =
389  new wxButton(parent, ID_HELP, wxT("&Help"), wxDefaultPosition,
390  wxDefaultSize, 0);
391  item9->Add( item10, 0, wxALIGN_CENTER|wxALL, 5 );
392 
393  wxButton *item11 =
394  new wxButton(parent, wxID_OK, wxT("&OK"), wxDefaultPosition,
395  wxDefaultSize, 0);
396  item9->Add( item11, 0, wxALIGN_CENTER|wxALL, 5 );
397  wxButton *item12 =
398  new wxButton(parent, wxID_CANCEL, wxT("&Cancel"), wxDefaultPosition,
399  wxDefaultSize, 0);
400  item9->Add( item12, 0, wxALIGN_CENTER|wxALL, 5 );
401  item0->Add( item9, 0, wxALIGN_CENTER|wxALL, 5 );
402 
403  if (set_sizer) {
404  parent->SetAutoLayout( TRUE );
405  parent->SetSizer( item0 );
406  if (call_fit)
407  {
408  item0->Fit( parent );
409  item0->SetSizeHints( parent );
410  }
411  }
412  return item0;
413 }

References TRUE.

◆ onCancel()

void RFPortDialog::onCancel ( wxCommandEvent &  event)
private

Resets the original output and input sockets for the port and closes the dialog.

Definition at line 198 of file RFPortDialog.cc.

198  {
200  if (oldInput_ != NULL) {
202  }
203  if (oldOutput_ != NULL) {
205  }
206  EndModal(wxID_CANCEL);
207 }

◆ onHelp()

void RFPortDialog::onHelp ( wxCommandEvent &  event)
private

◆ onName()

void RFPortDialog::onName ( wxCommandEvent &  event)
private

Validates input in the controls, and updates the ComponentDescriptor.

Definition at line 318 of file RFPortDialog.cc.

318  {
319  if (!TransferDataFromWindow()) {
320  assert(false);
321  }
322  wxString trimmedName = name_.Trim(false).Trim(true);
323  if (trimmedName == _T("")) {
324  FindWindow(wxID_OK)->Disable();
325  } else {
326  FindWindow(wxID_OK)->Enable();
327  }
328 }

References assert.

◆ onOK()

void RFPortDialog::onOK ( wxCommandEvent &  event)
private

Validates input in the controls, and updates the port.

Definition at line 135 of file RFPortDialog.cc.

135  {
136 
137  if (!Validate()) {
138  return;
139  }
140 
141  if (!TransferDataFromWindow()) {
142  return;
143  }
144 
145  string trimmedName =
146  WxConversion::toString(name_.Trim(false).Trim(true));
147 
148  // Check the name validity.
149  if (!MachineTester::isValidComponentName(trimmedName)) {
151  format message =
153  InformationDialog warning(
154  this, WxConversion::toWxString(message.str()));
155  warning.ShowModal();
156  return;
157  }
158 
159  // check whether RF already has a port of tht name.
160  if (port_->name() != trimmedName) {
161  Unit* rf = port_->parentUnit();
162  for (int i = 0; i < rf->portCount(); i++) {
163  string name = rf->port(i)->name();
164  if (name == WxConversion::toString(name_)) {
165  ProDeTextGenerator* prodeTexts =
167  format message =
169  format a_port =
171  format rf =
173  format port =
174  prodeTexts->text(ProDeTextGenerator::COMP_PORT);
175  message % trimmedName % a_port.str() % rf.str() % port.str();
176  WarningDialog warning(
177  this, WxConversion::toWxString(message.str()));
178  warning.ShowModal();
179  return;
180  }
181  }
182  }
183 
184  port_->setName(trimmedName);
185  // update parent RFs max write and read parameters
186  RegisterFile* RF = dynamic_cast<RegisterFile*>(port_->parentUnit());
187  assert (RF != NULL);
188  //RF->updateMaxReadsAndWrites();
189  EndModal(wxID_OK);
190 }

References assert, ProDeTextGenerator::COMP_A_PORT, ProDeTextGenerator::COMP_PORT, ProDeTextGenerator::COMP_REGISTER_FILE, ProDeTextGenerator::instance(), MachineTester::isValidComponentName(), ProDeTextGenerator::MSG_ERROR_ILLEGAL_NAME, ProDeTextGenerator::MSG_ERROR_SAME_NAME, TTAMachine::Port::name(), TTAMachine::Unit::port(), TTAMachine::Unit::portCount(), RF, Texts::TextGenerator::text(), WxConversion::toString(), and WxConversion::toWxString().

Here is the call graph for this function:

◆ onSocketChoice()

void RFPortDialog::onSocketChoice ( wxCommandEvent &  event)
private

Updates the port object when user changes input/output socket selection.

Definition at line 225 of file RFPortDialog.cc.

225  {
227  Machine::SocketNavigator navigator =
229 
230  // set input socket
231  string inputSocketName =
232  WxConversion::toString(inputSocketChoice_->GetStringSelection());
233  if (inputSocketName != WxConversion::toString(ProDeConstants::NONE)) {
234  port_->attachSocket(*(navigator.item(inputSocketName)));
235  }
236 
237  // set output socket
238  string outputSocketName =
239  WxConversion::toString(outputSocketChoice_->GetStringSelection());
240  if (outputSocketName != WxConversion::toString(ProDeConstants::NONE)) {
241  port_->attachSocket(*(navigator.item(outputSocketName)));
242  }
243  updateSockets();
244 }

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

Here is the call graph for this function:

◆ setTexts()

void RFPortDialog::setTexts ( )
private

Sets texts for widgets.

Definition at line 101 of file RFPortDialog.cc.

101  {
104 
105  // Dialog title
106  format fmt = prodeTexts->text(
108  SetTitle(WxConversion::toWxString(fmt.str()));
109 
110  // buttons
111  WidgetTools::setLabel(generator, FindWindow(wxID_OK),
113 
114  WidgetTools::setLabel(generator, FindWindow(wxID_CANCEL),
116 
119 
120  // widget labels
123 
126 
129 }

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_INPUT_SOCKET, ProDeTextGenerator::TXT_LABEL_NAME, ProDeTextGenerator::TXT_LABEL_OUTPUT_SOCKET, and ProDeTextGenerator::TXT_RF_PORT_DIALOG_TITLE.

Here is the call graph for this function:

◆ TransferDataToWindow()

bool RFPortDialog::TransferDataToWindow ( )
privatevirtual

Transfers data from the port object to the dialog widgets.

Returns
False, if an error occured in the transfer.

Definition at line 215 of file RFPortDialog.cc.

215  {
217  updateSockets();
218  return wxWindow::TransferDataToWindow();
219 }

References WxConversion::toWxString().

Here is the call graph for this function:

◆ updateSockets()

void RFPortDialog::updateSockets ( )
private

Updates input and output socket choicers.

Definition at line 250 of file RFPortDialog.cc.

250  {
251 
252  inputSocketChoice_->Clear();
254  outputSocketChoice_->Clear();
256 
257  MachineTester tester(*(port_->parentUnit()->machine()));
258 
259  // Add ports to the choicers
260  Machine::SocketNavigator navigator =
262 
263  for (int i = 0; i < navigator.count(); i++) {
264  Socket* socket = navigator.item(i);
265  wxString socketName = WxConversion::toWxString(socket->name());
266 
267  // Add available input sockets.
268  Socket* input = port_->inputSocket();
269  if (input != NULL) {
270  port_->detachSocket(*input);
271  }
272  bool legal = tester.canConnect(*socket, *port_);
273  if (legal && socket->direction() == Socket::INPUT) {
274  inputSocketChoice_->Append(socketName);
275  }
276  if (input != NULL) {
277  port_->attachSocket(*input);
278  }
279 
280  // Add available output sockets.
281  Socket* output = port_->outputSocket();
282  if (output != NULL) {
283  port_->detachSocket(*output);
284  }
285  legal = tester.canConnect(*socket, *port_);
286  if (legal && socket->direction() == Socket::OUTPUT) {
287  outputSocketChoice_->Append(socketName);
288  }
289  if (output != NULL) {
290  port_->attachSocket(*output);
291  }
292  // ignore sockets with unknown direction
293  }
294 
295  // set input socket choice
296  if (port_->inputSocket() == NULL) {
297  inputSocketChoice_->SetStringSelection(ProDeConstants::NONE);
298  } else {
299  wxString socketName =
301  inputSocketChoice_->SetStringSelection(socketName);
302  }
303 
304  // set output socket choice
305  if (port_->outputSocket() == NULL) {
306  outputSocketChoice_->SetStringSelection(ProDeConstants::NONE);
307  } else {
308  wxString socketName =
310  outputSocketChoice_->SetStringSelection(socketName);
311  }
312 }

References MachineTester::canConnect(), TTAMachine::Machine::Navigator< ComponentType >::count(), TTAMachine::Socket::direction(), TTAMachine::Socket::INPUT, TTAMachine::Machine::Navigator< ComponentType >::item(), TTAMachine::Component::name(), ProDeConstants::NONE, TTAMachine::Socket::OUTPUT, and WxConversion::toWxString().

Here is the call graph for this function:

Member Data Documentation

◆ inputSocketChoice_

wxChoice* RFPortDialog::inputSocketChoice_
private

Input socket choice control.

Definition at line 65 of file RFPortDialog.hh.

◆ name_

wxString RFPortDialog::name_
private

Name of the port.

Definition at line 63 of file RFPortDialog.hh.

◆ oldInput_

TTAMachine::Socket* RFPortDialog::oldInput_
private

Original input socket of the port.

Definition at line 69 of file RFPortDialog.hh.

◆ oldOutput_

TTAMachine::Socket* RFPortDialog::oldOutput_
private

Original output socket of the port.

Definition at line 71 of file RFPortDialog.hh.

◆ outputSocketChoice_

wxChoice* RFPortDialog::outputSocketChoice_
private

Output socket choice control.

Definition at line 67 of file RFPortDialog.hh.

◆ port_

TTAMachine::Port* RFPortDialog::port_
private

Port to modify.

Definition at line 61 of file RFPortDialog.hh.


The documentation for this class was generated from the following files:
WarningDialog
Definition: WarningDialog.hh:42
TTAMachine::Port::inputSocket
virtual Socket * inputSocket() const
Definition: Port.cc:261
WxConversion::toWxString
static wxString toWxString(const std::string &source)
TTAMachine::Component::name
virtual TCEString name() const
Definition: MachinePart.cc:125
RFPortDialog::name_
wxString name_
Name of the port.
Definition: RFPortDialog.hh:63
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
ProDeTextGenerator::TXT_LABEL_INPUT_SOCKET
@ TXT_LABEL_INPUT_SOCKET
Label for input socket selector.
Definition: ProDeTextGenerator.hh:61
GUITextGenerator
Definition: GUITextGenerator.hh:46
GUITextGenerator::TXT_BUTTON_HELP
@ TXT_BUTTON_HELP
Label for help button.
Definition: GUITextGenerator.hh:60
RFPortDialog::ID_HELP
@ ID_HELP
Definition: RFPortDialog.hh:78
FindWindow
Definition: FindWindow.hh:49
RFPortDialog::createContents
wxSizer * createContents(wxWindow *parent, bool call_fit, bool set_sizer)
Definition: RFPortDialog.cc:340
TTAMachine::Machine::Navigator::count
int count() const
Texts::TextGenerator::text
virtual boost::format text(int textId)
Definition: TextGenerator.cc:94
TTAMachine::Socket::direction
Direction direction() const
RFPortDialog::ID_NAME
@ ID_NAME
Definition: RFPortDialog.hh:75
RFPortDialog::setTexts
void setTexts()
Definition: RFPortDialog.cc:101
ProDeTextGenerator
Definition: ProDeTextGenerator.hh:49
ProDeTextGenerator::MSG_ERROR_ILLEGAL_NAME
@ MSG_ERROR_ILLEGAL_NAME
Error: Illegal component name.
Definition: ProDeTextGenerator.hh:223
ProDeTextGenerator::MSG_ERROR_SAME_NAME
@ MSG_ERROR_SAME_NAME
Error: Same name exists.
Definition: ProDeTextGenerator.hh:229
TTAMachine::Port::setName
virtual void setName(const std::string &name)
Definition: Port.cc:155
assert
#define assert(condition)
Definition: Application.hh:86
ProDeTextGenerator::TXT_RF_PORT_DIALOG_TITLE
@ TXT_RF_PORT_DIALOG_TITLE
Register file port Dialog title.
Definition: ProDeTextGenerator.hh:161
TTAMachine::Port::attachSocket
virtual void attachSocket(Socket &socket)
Definition: Port.cc:191
GUITextGenerator::TXT_BUTTON_CANCEL
@ TXT_BUTTON_CANCEL
Label for cancel button.
Definition: GUITextGenerator.hh:55
TTAMachine::Unit
Definition: Unit.hh:51
ProDeTextGenerator::COMP_A_PORT
@ COMP_A_PORT
Name for port (w/ article).
Definition: ProDeTextGenerator.hh:270
TTAMachine::Unit::port
virtual Port * port(const std::string &name) const
Definition: Unit.cc:116
TTAMachine::Socket
Definition: Socket.hh:53
ProDeTextGenerator::COMP_REGISTER_FILE
@ COMP_REGISTER_FILE
Register file (w/o article).
Definition: ProDeTextGenerator.hh:269
TTAMachine::Port::detachSocket
virtual void detachSocket(Socket &socket)
Definition: Port.cc:237
ProDeTextGenerator::TXT_LABEL_NAME
@ TXT_LABEL_NAME
Label for component name widget.
Definition: ProDeTextGenerator.hh:56
RFPortDialog::ID_INPUT_SOCKET
@ ID_INPUT_SOCKET
Definition: RFPortDialog.hh:76
MachineTester::isValidComponentName
static bool isValidComponentName(const std::string &name)
Definition: MachineTester.cc:312
TRUE
const string TRUE
Value used for true in attribute and element values.
Definition: GUIOptionsSerializer.cc:65
TTAMachine::Machine::socketNavigator
virtual SocketNavigator socketNavigator() const
Definition: Machine.cc:368
RFPortDialog::updateSockets
void updateSockets()
Definition: RFPortDialog.cc:250
TTAMachine::Unit::portCount
virtual int portCount() const
Definition: Unit.cc:135
RFPortDialog::oldOutput_
TTAMachine::Socket * oldOutput_
Original output socket of the port.
Definition: RFPortDialog.hh:71
ProDeTextGenerator::instance
static ProDeTextGenerator * instance()
Definition: ProDeTextGenerator.cc:382
RFPortDialog::ID_OUTPUT_SOCKET
@ ID_OUTPUT_SOCKET
Definition: RFPortDialog.hh:77
TTAMachine::Component::machine
virtual Machine * machine() const
TTAMachine::Port::name
virtual std::string name() const
Definition: Port.cc:141
RFPortDialog::port_
TTAMachine::Port * port_
Port to modify.
Definition: RFPortDialog.hh:61
TTAMachine::Port::outputSocket
virtual Socket * outputSocket() const
Definition: Port.cc:281
ProDeTextGenerator::TXT_LABEL_OUTPUT_SOCKET
@ TXT_LABEL_OUTPUT_SOCKET
Label for output socket selector.
Definition: ProDeTextGenerator.hh:62
TTAMachine::Machine::Navigator::item
ComponentType * item(int index) const
TTAMachine::RegisterFile
Definition: RegisterFile.hh:47
InformationDialog
Definition: InformationDialog.hh:42
ProDeTextGenerator::COMP_PORT
@ COMP_PORT
Name for port (w/o article).
Definition: ProDeTextGenerator.hh:271
ProDeConstants::NONE
static const wxString NONE
Constant for "None".
Definition: ProDeConstants.hh:56
MachineTester
Definition: MachineTester.hh:46
WxConversion::toString
static std::string toString(const wxString &source)
TTAMachine::Port::detachAllSockets
virtual void detachAllSockets()
Definition: Port.cc:536
RFPortDialog::outputSocketChoice_
wxChoice * outputSocketChoice_
Output socket choice control.
Definition: RFPortDialog.hh:67
TTAMachine::Machine::Navigator
Definition: Machine.hh:186
RFPortDialog::inputSocketChoice_
wxChoice * inputSocketChoice_
Input socket choice control.
Definition: RFPortDialog.hh:65
RF
const string RF
Definition: IDFSerializer.cc:68
RFPortDialog::TransferDataToWindow
virtual bool TransferDataToWindow()
Definition: RFPortDialog.cc:215
GUITextGenerator::TXT_BUTTON_OK
@ TXT_BUTTON_OK
Label for OK button.
Definition: GUITextGenerator.hh:59
TTAMachine::Port::parentUnit
Unit * parentUnit() const
RFPortDialog::oldInput_
TTAMachine::Socket * oldInput_
Original input socket of the port.
Definition: RFPortDialog.hh:69