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

#include <IUPortDialog.hh>

Inheritance diagram for IUPortDialog:
Inheritance graph
Collaboration diagram for IUPortDialog:
Collaboration graph

Public Member Functions

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

Private Types

enum  {
  ID_NAME = 10000, ID_OUTPUT_SOCKET, ID_HELP, ID_LABEL_NAME,
  ID_LABEL_OUTPUT_SOCKET, ID_LINE
}
 Enumerated IDs for dialog controls. More...
 

Private Member Functions

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

Private Attributes

TTAMachine::Portport_
 Immediate unit port to edit with the dialog. More...
 
wxString name_
 Name of the port. More...
 
wxChoice * outputSocketChoice_
 Output socket choice control. More...
 

Detailed Description

Dialog for editing immediate unit ports.

Definition at line 45 of file IUPortDialog.hh.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
private

Enumerated IDs for dialog controls.

Enumerator
ID_NAME 
ID_OUTPUT_SOCKET 
ID_HELP 
ID_LABEL_NAME 
ID_LABEL_OUTPUT_SOCKET 
ID_LINE 

Definition at line 67 of file IUPortDialog.hh.

67  {
68  ID_NAME= 10000,
70  ID_HELP,
73  ID_LINE
74  };

Constructor & Destructor Documentation

◆ IUPortDialog()

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

The Constructor.

Parameters
parentParent window of the dialog.
portImmediate unit port to be modified with the dialog.

Definition at line 64 of file IUPortDialog.cc.

66  :
67  wxDialog(parent, -1, _T(""), wxDefaultPosition),
68  port_(port),
69  name_(_T("")),
70  outputSocketChoice_(NULL) {
71 
72  createContents(this, true, true);
73  FindWindow(wxID_OK)->Disable();
74 
76  dynamic_cast<wxChoice*>(FindWindow(ID_OUTPUT_SOCKET));
77  FindWindow(ID_NAME)->SetValidator(
78  wxTextValidator(wxFILTER_ASCII, &name_));
79 
80  // set texts for widgets
81  setTexts();
82 
84 }

◆ ~IUPortDialog()

IUPortDialog::~IUPortDialog ( )
virtual

The Destructor.

Definition at line 90 of file IUPortDialog.cc.

90  {
91 }

Member Function Documentation

◆ createContents()

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

Creates the dialog window contents.

This method was initially generated with wxDesigner, code will be cleaned up later.

Returns
Main sizer of the created contents.
Parameters
parentThe dialog window.
call_fitIf true, fits the contents inside the dialog.
set_sizerIf true, sets the main sizer as dialog contents.

Definition at line 284 of file IUPortDialog.cc.

285  {
286 
287  wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL );
288 
289  wxFlexGridSizer *item1 = new wxFlexGridSizer( 2, 0, 0 );
290 
291  wxStaticText *item2 = new wxStaticText( parent, ID_LABEL_NAME, wxT("Name:"), wxDefaultPosition, wxDefaultSize, 0 );
292  item1->Add( item2, 0, wxALIGN_RIGHT|wxALL, 5 );
293 
294  wxTextCtrl *item3 = new wxTextCtrl( parent, ID_NAME, wxT(""), wxDefaultPosition, wxSize(140,-1), 0 );
295  item1->Add( item3, 0, wxGROW|wxALL, 5 );
296 
297  wxStaticText *item4 = new wxStaticText( parent, ID_LABEL_OUTPUT_SOCKET, wxT("Output Socket"), wxDefaultPosition, wxDefaultSize, 0 );
298  item1->Add( item4, 0, wxALIGN_RIGHT|wxALL, 5 );
299 
300  wxString *strs5 = (wxString*) NULL;
301  wxChoice *item5 = new wxChoice( parent, ID_OUTPUT_SOCKET, wxDefaultPosition, wxSize(100,-1), 0, strs5, 0 );
302  item1->Add( item5, 0, wxGROW|wxALL, 5 );
303 
304  item0->Add( item1, 0, wxGROW|wxALL, 5 );
305 
306  wxStaticLine *item6 = new wxStaticLine( parent, ID_LINE, wxDefaultPosition, wxSize(20,-1), wxLI_HORIZONTAL );
307  item0->Add( item6, 0, wxGROW|wxALL, 5 );
308 
309  wxBoxSizer *item7 = new wxBoxSizer( wxHORIZONTAL );
310 
311  wxButton *item8 = new wxButton( parent, ID_HELP, wxT("&Help"), wxDefaultPosition, wxDefaultSize, 0 );
312  item7->Add( item8, 0, wxALIGN_CENTER|wxALL, 5 );
313 
314  wxButton *item9 = new wxButton( parent, wxID_OK, wxT("&OK"), wxDefaultPosition, wxDefaultSize, 0 );
315  item7->Add( item9, 0, wxALIGN_CENTER|wxALL, 5 );
316 
317  wxButton *item10 = new wxButton( parent, wxID_CANCEL, wxT("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
318  item7->Add( item10, 0, wxALIGN_CENTER|wxALL, 5 );
319 
320  item0->Add( item7, 0, wxALIGN_CENTER|wxALL, 5 );
321 
322  if (set_sizer)
323  {
324  parent->SetSizer( item0 );
325  if (call_fit)
326  item0->SetSizeHints( parent );
327  }
328 
329  return item0;
330 }

◆ onHelp()

void IUPortDialog::onHelp ( wxCommandEvent &  event)
private

◆ onName()

void IUPortDialog::onName ( wxCommandEvent &  event)
private

Validates input in the controls, and updates the port.

Definition at line 259 of file IUPortDialog.cc.

259  {
260  if (!TransferDataFromWindow()) {
261  assert(false);
262  }
263  wxString trimmedName = name_.Trim(false).Trim(true);
264  if (trimmedName == _T("")) {
265  FindWindow(wxID_OK)->Disable();
266  } else {
267  FindWindow(wxID_OK)->Enable();
268  }
269 }

References assert.

◆ onOK()

void IUPortDialog::onOK ( wxCommandEvent &  event)
private

Validates input in the controls, and updates the port.

Definition at line 191 of file IUPortDialog.cc.

191  {
192 
193  if (!Validate()) {
194  return;
195  }
196 
197  if (!TransferDataFromWindow()) {
198  return;
199  }
200 
201  string trimmedName =
202  WxConversion::toString(name_.Trim(false).Trim(true));
203 
204  // Check the name validity.
205  if (!MachineTester::isValidComponentName(trimmedName)) {
207  format message =
209  InformationDialog warning(
210  this, WxConversion::toWxString(message.str()));
211  warning.ShowModal();
212  return;
213  }
214 
215  if (port_->name() != trimmedName) {
216  Unit* iu = port_->parentUnit();
217  for (int i = 0; i < iu->portCount(); i++) {
218  string name = iu->port(i)->name();
219  if (name == WxConversion::toString(name_)) {
220  ProDeTextGenerator* prodeTexts =
222  format message =
224  format a_port =
226  format iu =
228  format port =
229  prodeTexts->text(ProDeTextGenerator::COMP_PORT);
230  message % trimmedName % a_port.str() % iu.str() % port.str();
231  WarningDialog warning(
232  this, WxConversion::toWxString(message.str()));
233  warning.ShowModal();
234  return;
235  }
236  }
237  }
238 
239  port_->setName(trimmedName);
241  Machine::SocketNavigator navigator =
243 
244  // set output socket
245  string outputSocketName =
246  WxConversion::toString(outputSocketChoice_->GetStringSelection());
247  if (outputSocketName != WxConversion::toString(ProDeConstants::NONE)) {
248  port_->attachSocket(*(navigator.item(outputSocketName)));
249  }
250 
251  EndModal(wxID_OK);
252 }

References ProDeTextGenerator::COMP_A_PORT, ProDeTextGenerator::COMP_IMMEDIATE_UNIT, ProDeTextGenerator::COMP_PORT, ProDeTextGenerator::instance(), MachineTester::isValidComponentName(), TTAMachine::Machine::Navigator< ComponentType >::item(), ProDeTextGenerator::MSG_ERROR_ILLEGAL_NAME, ProDeTextGenerator::MSG_ERROR_SAME_NAME, TTAMachine::Port::name(), ProDeConstants::NONE, TTAMachine::Unit::port(), TTAMachine::Unit::portCount(), Texts::TextGenerator::text(), WxConversion::toString(), and WxConversion::toWxString().

Here is the call graph for this function:

◆ setTexts()

void IUPortDialog::setTexts ( )
private

◆ TransferDataToWindow()

bool IUPortDialog::TransferDataToWindow ( )
privatevirtual

Transfers data from the Port object to the dialog widgets.

Returns
false, if an error occured in the transfer.

Definition at line 132 of file IUPortDialog.cc.

132  {
134 
135  updateSocket();
136 
137  return wxWindow::TransferDataToWindow();
138 }

References WxConversion::toWxString().

Here is the call graph for this function:

◆ updateSocket()

void IUPortDialog::updateSocket ( )
private

Updates output socket choicer.

Definition at line 145 of file IUPortDialog.cc.

145  {
146 
147  outputSocketChoice_->Clear();
149 
150  MachineTester tester(*(port_->parentUnit()->machine()));
151 
152  // Add ports to the choicer
153  Machine::SocketNavigator navigator =
155 
156  for (int i = 0; i < navigator.count(); i++) {
157  Socket* socket = navigator.item(i);
158  wxString socketName = WxConversion::toWxString(socket->name());
159 
160  // Add available output sockets.
161  Socket* output = port_->outputSocket();
162  if (output != NULL) {
163  port_->detachSocket(*output);
164  }
165  bool legal = tester.canConnect(*socket, *port_);
166  if (legal && socket->direction() == Socket::OUTPUT) {
167  outputSocketChoice_->Append(socketName);
168  }
169  if (output != NULL) {
170  port_->attachSocket(*output);
171  }
172  // ignore sockets with unknown direction
173  }
174 
175  // set output socket choice
176  if (port_->outputSocket() == NULL) {
177  outputSocketChoice_->SetStringSelection(ProDeConstants::NONE);
178  } else {
179  wxString socketName =
181  outputSocketChoice_->SetStringSelection(socketName);
182  }
183 }

References MachineTester::canConnect(), TTAMachine::Machine::Navigator< ComponentType >::count(), TTAMachine::Socket::direction(), 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

◆ name_

wxString IUPortDialog::name_
private

Name of the port.

Definition at line 62 of file IUPortDialog.hh.

◆ outputSocketChoice_

wxChoice* IUPortDialog::outputSocketChoice_
private

Output socket choice control.

Definition at line 64 of file IUPortDialog.hh.

◆ port_

TTAMachine::Port* IUPortDialog::port_
private

Immediate unit port to edit with the dialog.

Definition at line 60 of file IUPortDialog.hh.


The documentation for this class was generated from the following files:
IUPortDialog::ID_HELP
@ ID_HELP
Definition: IUPortDialog.hh:70
IUPortDialog::name_
wxString name_
Name of the port.
Definition: IUPortDialog.hh:62
WarningDialog
Definition: WarningDialog.hh:42
WxConversion::toWxString
static wxString toWxString(const std::string &source)
TTAMachine::Component::name
virtual TCEString name() const
Definition: MachinePart.cc:125
IUPortDialog::outputSocketChoice_
wxChoice * outputSocketChoice_
Output socket choice control.
Definition: IUPortDialog.hh:64
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
IUPortDialog::createContents
wxSizer * createContents(wxWindow *parent, bool call_fit, bool set_sizer)
Definition: IUPortDialog.cc:284
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
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
IUPortDialog::port_
TTAMachine::Port * port_
Immediate unit port to edit with the dialog.
Definition: IUPortDialog.hh:60
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
IUPortDialog::ID_LABEL_OUTPUT_SOCKET
@ ID_LABEL_OUTPUT_SOCKET
Definition: IUPortDialog.hh:72
TTAMachine::Port::attachSocket
virtual void attachSocket(Socket &socket)
Definition: Port.cc:191
IUPortDialog::setTexts
void setTexts()
Definition: IUPortDialog.cc:98
IUPortDialog::TransferDataToWindow
virtual bool TransferDataToWindow()
Definition: IUPortDialog.cc:132
GUITextGenerator::TXT_BUTTON_CANCEL
@ TXT_BUTTON_CANCEL
Label for cancel button.
Definition: GUITextGenerator.hh:55
IUPortDialog::ID_LINE
@ ID_LINE
Definition: IUPortDialog.hh:73
IUPortDialog::ID_LABEL_NAME
@ ID_LABEL_NAME
Definition: IUPortDialog.hh:71
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
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
MachineTester::isValidComponentName
static bool isValidComponentName(const std::string &name)
Definition: MachineTester.cc:312
TTAMachine::Machine::socketNavigator
virtual SocketNavigator socketNavigator() const
Definition: Machine.cc:368
TTAMachine::Unit::portCount
virtual int portCount() const
Definition: Unit.cc:135
ProDeTextGenerator::instance
static ProDeTextGenerator * instance()
Definition: ProDeTextGenerator.cc:382
TTAMachine::Component::machine
virtual Machine * machine() const
TTAMachine::Port::name
virtual std::string name() const
Definition: Port.cc:141
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
IUPortDialog::updateSocket
void updateSocket()
Definition: IUPortDialog.cc:145
ProDeTextGenerator::COMP_IMMEDIATE_UNIT
@ COMP_IMMEDIATE_UNIT
Immediate unit (w/o article).
Definition: ProDeTextGenerator.hh:267
TTAMachine::Machine::Navigator::item
ComponentType * item(int index) const
InformationDialog
Definition: InformationDialog.hh:42
ProDeTextGenerator::COMP_PORT
@ COMP_PORT
Name for port (w/o article).
Definition: ProDeTextGenerator.hh:271
IUPortDialog::ID_OUTPUT_SOCKET
@ ID_OUTPUT_SOCKET
Definition: IUPortDialog.hh:69
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
TTAMachine::Machine::Navigator
Definition: Machine.hh:186
ProDeTextGenerator::TXT_IU_PORT_DIALOG_TITLE
@ TXT_IU_PORT_DIALOG_TITLE
Immediate unit port dialog title.
Definition: ProDeTextGenerator.hh:181
IUPortDialog::ID_NAME
@ ID_NAME
Definition: IUPortDialog.hh:68
GUITextGenerator::TXT_BUTTON_OK
@ TXT_BUTTON_OK
Label for OK button.
Definition: GUITextGenerator.hh:59
TTAMachine::Port::parentUnit
Unit * parentUnit() const