OpenASIP 2.2
Loading...
Searching...
No Matches
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.
 
wxString name_
 Name of the port.
 
wxChoice * outputSocketChoice_
 Output socket choice control.
 

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.

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("")),
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}
virtual bool TransferDataToWindow()
wxString name_
Name of the port.
wxSizer * createContents(wxWindow *parent, bool call_fit, bool set_sizer)
wxChoice * outputSocketChoice_
Output socket choice control.
TTAMachine::Port * port_
Immediate unit port to edit with the dialog.

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

References ID_HELP, ID_LABEL_NAME, ID_LABEL_OUTPUT_SOCKET, ID_LINE, ID_NAME, and ID_OUTPUT_SOCKET.

◆ 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}
#define assert(condition)

References assert, and name_.

◆ 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 =
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}
static bool isValidComponentName(const std::string &name)
static const wxString NONE
Constant for "None".
static ProDeTextGenerator * instance()
@ MSG_ERROR_SAME_NAME
Error: Same name exists.
@ MSG_ERROR_ILLEGAL_NAME
Error: Illegal component name.
@ COMP_PORT
Name for port (w/o article).
@ COMP_IMMEDIATE_UNIT
Immediate unit (w/o article).
@ COMP_A_PORT
Name for port (w/ article).
virtual Machine * machine() const
ComponentType * item(int index) const
virtual SocketNavigator socketNavigator() const
Definition Machine.cc:368
virtual void attachSocket(Socket &socket)
Definition Port.cc:191
virtual void detachAllSockets()
Definition Port.cc:536
Unit * parentUnit() const
virtual std::string name() const
Definition Port.cc:141
virtual void setName(const std::string &name)
Definition Port.cc:155
virtual int portCount() const
Definition Unit.cc:135
virtual Port * port(const std::string &name) const
Definition Unit.cc:116
virtual boost::format text(int textId)
static wxString toWxString(const std::string &source)
static std::string toString(const wxString &source)

References TTAMachine::Port::attachSocket(), ProDeTextGenerator::COMP_A_PORT, ProDeTextGenerator::COMP_IMMEDIATE_UNIT, ProDeTextGenerator::COMP_PORT, TTAMachine::Port::detachAllSockets(), ProDeTextGenerator::instance(), MachineTester::isValidComponentName(), TTAMachine::Machine::Navigator< ComponentType >::item(), TTAMachine::Component::machine(), ProDeTextGenerator::MSG_ERROR_ILLEGAL_NAME, ProDeTextGenerator::MSG_ERROR_SAME_NAME, TTAMachine::Port::name(), name_, ProDeConstants::NONE, outputSocketChoice_, TTAMachine::Port::parentUnit(), TTAMachine::Unit::port(), port_, TTAMachine::Unit::portCount(), TTAMachine::Port::setName(), TTAMachine::Machine::socketNavigator(), Texts::TextGenerator::text(), WxConversion::toString(), and WxConversion::toWxString().

Here is the call graph for this function:

◆ setTexts()

void IUPortDialog::setTexts ( )
private

Sets texts for widgets.

Definition at line 98 of file IUPortDialog.cc.

98 {
101
102 // Dialog title
103 format fmt = prodeTexts->text(
105 SetTitle(WxConversion::toWxString(fmt.str()));
106
107 // buttons
108 WidgetTools::setLabel(generator, FindWindow(wxID_OK),
110
111 WidgetTools::setLabel(generator, FindWindow(wxID_CANCEL),
113
116
117 // widget labels
120
123}
@ 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_NAME
Label for component name widget.
@ TXT_LABEL_OUTPUT_SOCKET
Label for output socket selector.
@ TXT_IU_PORT_DIALOG_TITLE
Immediate unit port dialog title.
static void setLabel(Texts::TextGenerator *generator, wxWindow *widget, int textID)

References ID_HELP, ID_LABEL_NAME, ID_LABEL_OUTPUT_SOCKET, 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_IU_PORT_DIALOG_TITLE, ProDeTextGenerator::TXT_LABEL_NAME, and ProDeTextGenerator::TXT_LABEL_OUTPUT_SOCKET.

Here is the call graph for this function:

◆ 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}
void updateSocket()

References TTAMachine::Port::name(), name_, port_, WxConversion::toWxString(), and updateSocket().

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}
virtual TCEString name() const
virtual Socket * outputSocket() const
Definition Port.cc:281
virtual void detachSocket(Socket &socket)
Definition Port.cc:237
@ OUTPUT
Data goes from port to bus.
Definition Socket.hh:60
Direction direction() const

References TTAMachine::Port::attachSocket(), MachineTester::canConnect(), TTAMachine::Machine::Navigator< ComponentType >::count(), TTAMachine::Port::detachSocket(), TTAMachine::Socket::direction(), TTAMachine::Machine::Navigator< ComponentType >::item(), TTAMachine::Component::machine(), TTAMachine::Component::name(), ProDeConstants::NONE, TTAMachine::Socket::OUTPUT, TTAMachine::Port::outputSocket(), outputSocketChoice_, TTAMachine::Port::parentUnit(), port_, TTAMachine::Machine::socketNavigator(), and WxConversion::toWxString().

Referenced by TransferDataToWindow().

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.

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

◆ outputSocketChoice_

wxChoice* IUPortDialog::outputSocketChoice_
private

Output socket choice control.

Definition at line 64 of file IUPortDialog.hh.

Referenced by onOK(), and updateSocket().

◆ port_

TTAMachine::Port* IUPortDialog::port_
private

Immediate unit port to edit with the dialog.

Definition at line 60 of file IUPortDialog.hh.

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


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