OpenASIP 2.2
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
SRPortDialog Class Reference

#include <SRPortDialog.hh>

Inheritance diagram for SRPortDialog:
Inheritance graph
Collaboration diagram for SRPortDialog:
Collaboration graph

Public Member Functions

 SRPortDialog (wxWindow *parent, TTAMachine::SpecialRegisterPort *port)
 
 ~SRPortDialog ()
 

Protected Member Functions

virtual bool TransferDataToWindow ()
 

Private Types

enum  {
  ID_NAME =10000 , ID_WIDTH , ID_INPUT_SOCKET , ID_OUTPUT_SOCKET ,
  ID_HELP , ID_LABEL_NAME , ID_LABEL_WIDTH , ID_LABEL_INPUT_SOCKET ,
  ID_LABEL_OUTPUT_SOCKET , ID_LINE
}
 

Private Member Functions

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

Private Attributes

TTAMachine::SpecialRegisterPortport_
 Function unit port to modify.
 
wxString name_
 Name of the port.
 
int width_
 Width of the port.
 
wxChoice * inputSocketChoice_
 Input socket choice control.
 
wxChoice * outputSocketChoice_
 Output socket choice control.
 
TTAMachine::SocketoldInput_
 Original input socket of the port.
 
TTAMachine::SocketoldOutput_
 Original output socket of the port.
 

Detailed Description

Dialog for creating and editing special register ports.

Definition at line 44 of file SRPortDialog.hh.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
private
Enumerator
ID_NAME 
ID_WIDTH 
ID_INPUT_SOCKET 
ID_OUTPUT_SOCKET 
ID_HELP 
ID_LABEL_NAME 
ID_LABEL_WIDTH 
ID_LABEL_INPUT_SOCKET 
ID_LABEL_OUTPUT_SOCKET 
ID_LINE 

Definition at line 79 of file SRPortDialog.hh.

Constructor & Destructor Documentation

◆ SRPortDialog()

SRPortDialog::SRPortDialog ( wxWindow *  parent,
TTAMachine::SpecialRegisterPort port 
)

The Constructor.

Parameters
parentParent window of the dialog.
portPort to modify.

Definition at line 78 of file SRPortDialog.cc.

80 :
81 wxDialog(parent, -1, _T(""), wxDefaultPosition),
82 port_(port),
83 name_(_T("")),
87
90
91 createContents(this, true, true);
92
94 dynamic_cast<wxChoice*>(FindWindow(ID_INPUT_SOCKET));
96 dynamic_cast<wxChoice*>(FindWindow(ID_OUTPUT_SOCKET));
97
98 FindWindow(ID_NAME)->SetValidator(wxTextValidator(wxFILTER_ASCII, &name_));
99 FindWindow(ID_WIDTH)->SetValidator(wxGenericValidator(&width_));
100
101 FindWindow(wxID_OK)->Disable();
102
103 // set texts to widgets
104 setTexts();
105
107}
static const int DEFAULT_WIDTH
Default bit width.
wxChoice * outputSocketChoice_
Output socket choice control.
int width_
Width of the port.
wxString name_
Name of the port.
wxSizer * createContents(wxWindow *parent, bool call_fit, bool set_sizer)
wxChoice * inputSocketChoice_
Input socket choice control.
TTAMachine::SpecialRegisterPort * port_
Function unit port to modify.
virtual bool TransferDataToWindow()
TTAMachine::Socket * oldOutput_
Original output socket of the port.
TTAMachine::Socket * oldInput_
Original input socket of the port.
virtual Socket * outputSocket() const
Definition Port.cc:281
virtual Socket * inputSocket() const
Definition Port.cc:261

◆ ~SRPortDialog()

SRPortDialog::~SRPortDialog ( )

The Destructor.

Definition at line 112 of file SRPortDialog.cc.

112 {
113}

Member Function Documentation

◆ createContents()

wxSizer * SRPortDialog::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 381 of file SRPortDialog.cc.

382 {
383
384 wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL );
385
386 wxFlexGridSizer *item1 = new wxFlexGridSizer( 2, 0, 0 );
387
388 wxStaticText *item2 = new wxStaticText( parent, ID_LABEL_NAME, wxT("Name:"), wxDefaultPosition, wxDefaultSize, 0 );
389 item1->Add( item2, 0, wxALIGN_RIGHT|wxALL, 5 );
390
391 wxTextCtrl *item3 = new wxTextCtrl( parent, ID_NAME, wxT(""), wxDefaultPosition, wxSize(200,-1), 0 );
392 item1->Add( item3, 0, wxALIGN_CENTER|wxALL, 5 );
393
394 wxStaticText *item4 = new wxStaticText( parent, ID_LABEL_WIDTH, wxT("Width:"), wxDefaultPosition, wxDefaultSize, 0 );
395 item1->Add( item4, 0, wxALIGN_RIGHT|wxALL, 5 );
396
397 wxSpinCtrl *item5 = new wxSpinCtrl( parent, ID_WIDTH, wxT("1"), wxDefaultPosition, wxSize(-1,-1), 0, 1, 10000, 1 );
398 item1->Add( item5, 0, wxALIGN_CENTER|wxALL, 5 );
399
400 wxStaticText *item6 = new wxStaticText( parent, ID_LABEL_INPUT_SOCKET, wxT("Input Socket:"), wxDefaultPosition, wxDefaultSize, 0 );
401 item1->Add( item6, 0, wxALIGN_RIGHT|wxALL, 5 );
402
403 wxString strs7[] =
404 {
405 wxT("NONE")
406 };
407 wxChoice *item7 = new wxChoice( parent, ID_INPUT_SOCKET, wxDefaultPosition, wxSize(200,-1), 1, strs7, 0 );
408 item1->Add( item7, 0, wxALIGN_CENTER|wxALL, 5 );
409
410 wxStaticText *item8 = new wxStaticText( parent, ID_LABEL_OUTPUT_SOCKET, wxT("Output Socket:"), wxDefaultPosition, wxDefaultSize, 0 );
411 item1->Add( item8, 0, wxALIGN_RIGHT|wxALL, 5 );
412
413 wxString strs9[] =
414 {
415 wxT("NONE")
416 };
417 wxChoice *item9 = new wxChoice( parent, ID_OUTPUT_SOCKET, wxDefaultPosition, wxSize(200,-1), 1, strs9, 0 );
418 item1->Add( item9, 0, wxALIGN_CENTER|wxALL, 5 );
419
420 item0->Add( item1, 0, wxALIGN_CENTER|wxALL, 5 );
421
422 wxStaticLine *item10 = new wxStaticLine( parent, ID_LINE, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
423 item0->Add( item10, 0, wxGROW|wxALL, 5 );
424
425 wxBoxSizer *item11 = new wxBoxSizer( wxHORIZONTAL );
426
427 wxButton *item12 = new wxButton( parent, ID_HELP, wxT("&Help"), wxDefaultPosition, wxDefaultSize, 0 );
428 item11->Add( item12, 0, wxALIGN_CENTER|wxALL, 5 );
429
430 wxButton *item13 = new wxButton( parent, wxID_OK, wxT("&OK"), wxDefaultPosition, wxDefaultSize, 0 );
431 item11->Add( item13, 0, wxALIGN_CENTER|wxALL, 5 );
432
433 wxButton *item14 = new wxButton( parent, wxID_CANCEL, wxT("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
434 item11->Add( item14, 0, wxALIGN_CENTER|wxALL, 5 );
435
436 item0->Add( item11, 0, wxALIGN_CENTER|wxALL, 5 );
437
438 if (set_sizer)
439 {
440 parent->SetSizer( item0 );
441 if (call_fit)
442 item0->SetSizeHints( parent );
443 }
444
445 return item0;
446}

References ID_HELP, ID_INPUT_SOCKET, ID_LABEL_INPUT_SOCKET, ID_LABEL_NAME, ID_LABEL_OUTPUT_SOCKET, ID_LABEL_WIDTH, ID_LINE, ID_NAME, ID_OUTPUT_SOCKET, and ID_WIDTH.

◆ onCancel()

void SRPortDialog::onCancel ( wxCommandEvent &  event)
private

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

Definition at line 249 of file SRPortDialog.cc.

249 {
251 if (oldInput_ != NULL) {
253 }
254 if (oldOutput_ != NULL) {
256 }
257 EndModal(wxID_CANCEL);
258}
virtual void attachSocket(Socket &socket)
Definition Port.cc:191
virtual void detachAllSockets()
Definition Port.cc:536

References TTAMachine::Port::attachSocket(), TTAMachine::Port::detachAllSockets(), oldInput_, oldOutput_, and port_.

Here is the call graph for this function:

◆ onHelp()

void SRPortDialog::onHelp ( wxCommandEvent &  event)
private

◆ onName()

void SRPortDialog::onName ( wxCommandEvent &  event)
private

Disables OK-button if the name field is empty.

Definition at line 358 of file SRPortDialog.cc.

358 {
359 if (!TransferDataFromWindow()) {
360 assert(false);
361 }
362 wxString trimmedName = name_.Trim(false).Trim(true);
363 if (trimmedName == _T("")) {
364 FindWindow(wxID_OK)->Disable();
365 } else {
366 FindWindow(wxID_OK)->Enable();
367 }
368}
#define assert(condition)

References assert, and name_.

◆ onOK()

void SRPortDialog::onOK ( wxCommandEvent &  event)
private

Validates input in the controls, and updates the port object.

Definition at line 265 of file SRPortDialog.cc.

265 {
266
267 if (!Validate()) {
268 return;
269 }
270
271 if (!TransferDataFromWindow()) {
272 return;
273 }
274
275 // check whether FU already has a port of tht name.
276
277 string trimmedName =
278 WxConversion::toString(name_.Trim(false).Trim(true));
279
280 // Check the name validity.
281 if (!MachineTester::isValidComponentName(trimmedName)) {
283 format message =
285 InformationDialog warning(
286 this, WxConversion::toWxString(message.str()));
287 warning.ShowModal();
288 return;
289 }
290
291 if (port_->name() != trimmedName) {
292
293 // TODO: Remove dyanmic_cast and assert when MOM return type is
294 // fixed.
295 ControlUnit* gcu = dynamic_cast<ControlUnit*>(port_->parentUnit());
296 assert(gcu != NULL);
297
298 for (int i = 0; i < gcu->portCount(); i++) {
299 string name = gcu->port(i)->name();
300 if (name == WxConversion::toString(name_)) {
301 ProDeTextGenerator* prodeTexts =
303 format message =
305 format a_port =
307 format machine =
309 format port =
311 message % trimmedName % a_port.str() % machine.str() %
312 port.str();
313 WarningDialog warning(
314 this, WxConversion::toWxString(message.str()));
315 warning.ShowModal();
316 return;
317 }
318 }
319 }
320
321 // update attributes
322 port_->setName(trimmedName);
324
325 EndModal(wxID_OK);
326}
TTAMachine::Machine * machine
the architecture definition of the estimated processor
static bool isValidComponentName(const std::string &name)
static ProDeTextGenerator * instance()
@ MSG_ERROR_SAME_NAME
Error: Same name exists.
@ MSG_ERROR_ILLEGAL_NAME
Error: Illegal component name.
@ COMP_FUNCTION_UNIT
Name for FU (w/o article).
@ COMP_PORT
Name for port (w/o article).
@ COMP_A_PORT
Name for port (w/ article).
FunctionUnit * parentUnit() const
Definition BaseFUPort.cc:96
void setWidth(int width)
virtual BaseFUPort * port(const std::string &name) 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 boost::format text(int textId)
static wxString toWxString(const std::string &source)
static std::string toString(const wxString &source)

References assert, ProDeTextGenerator::COMP_A_PORT, ProDeTextGenerator::COMP_FUNCTION_UNIT, ProDeTextGenerator::COMP_PORT, ProDeTextGenerator::instance(), MachineTester::isValidComponentName(), machine, ProDeTextGenerator::MSG_ERROR_ILLEGAL_NAME, ProDeTextGenerator::MSG_ERROR_SAME_NAME, TTAMachine::Port::name(), name_, TTAMachine::BaseFUPort::parentUnit(), TTAMachine::FunctionUnit::port(), port_, TTAMachine::Unit::portCount(), TTAMachine::Port::setName(), TTAMachine::BaseFUPort::setWidth(), Texts::TextGenerator::text(), WxConversion::toString(), WxConversion::toWxString(), and width_.

Here is the call graph for this function:

◆ onSocketChoice()

void SRPortDialog::onSocketChoice ( wxCommandEvent &  event)
private

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

Definition at line 332 of file SRPortDialog.cc.

332 {
334 Machine::SocketNavigator navigator =
336
337 // set input socket
338 string inputSocketName =
339 WxConversion::toString(inputSocketChoice_->GetStringSelection());
340 if (inputSocketName != WxConversion::toString(ProDeConstants::NONE)) {
341 port_->attachSocket(*(navigator.item(inputSocketName)));
342 }
343
344 // set output socket
345 string outputSocketName =
346 WxConversion::toString(outputSocketChoice_->GetStringSelection());
347 if (outputSocketName != WxConversion::toString(ProDeConstants::NONE)) {
348 port_->attachSocket(*(navigator.item(outputSocketName)));
349 }
351}
static const wxString NONE
Constant for "None".
void updateSockets()
virtual Machine * machine() const
ComponentType * item(int index) const
virtual SocketNavigator socketNavigator() const
Definition Machine.cc:368

References TTAMachine::Port::attachSocket(), TTAMachine::Port::detachAllSockets(), inputSocketChoice_, TTAMachine::Machine::Navigator< ComponentType >::item(), TTAMachine::Component::machine(), ProDeConstants::NONE, outputSocketChoice_, TTAMachine::BaseFUPort::parentUnit(), port_, TTAMachine::Machine::socketNavigator(), WxConversion::toString(), and updateSockets().

Here is the call graph for this function:

◆ setTexts()

void SRPortDialog::setTexts ( )
private

Sets texts for widgets.

Definition at line 120 of file SRPortDialog.cc.

120 {
123
124 // Dialog title
125 format fmt = prodeTexts->text(
127 SetTitle(WxConversion::toWxString(fmt.str()));
128
129 // buttons
130 WidgetTools::setLabel(generator, FindWindow(wxID_OK),
132
133 WidgetTools::setLabel(generator, FindWindow(wxID_CANCEL),
135
138
139 // widget labels
142
145
148
151
152}
@ 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_SR_PORT_DIALOG_TITLE
Special reg. port dialog title.
@ TXT_LABEL_NAME
Label for component name widget.
@ TXT_LABEL_INPUT_SOCKET
Label for input socket selector.
@ TXT_LABEL_WIDTH
Label for bit width widget.
@ TXT_LABEL_OUTPUT_SOCKET
Label for output socket selector.
static void setLabel(Texts::TextGenerator *generator, wxWindow *widget, int textID)

References ID_HELP, ID_LABEL_INPUT_SOCKET, ID_LABEL_NAME, ID_LABEL_OUTPUT_SOCKET, ID_LABEL_WIDTH, 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, ProDeTextGenerator::TXT_LABEL_WIDTH, and ProDeTextGenerator::TXT_SR_PORT_DIALOG_TITLE.

Here is the call graph for this function:

◆ TransferDataToWindow()

bool SRPortDialog::TransferDataToWindow ( )
protectedvirtual

Transfers data from the port object to the dialog widgets.

Returns
False, if an error occured in the transfer.

Definition at line 161 of file SRPortDialog.cc.

161 {
162
164 width_ = port_->width();
166
167 // wxWidgets GTK1 version seems to bug with spincontrol and
168 // checkbox validators. The widget value has to be set manually.
169 dynamic_cast<wxSpinCtrl*>(FindWindow(ID_WIDTH))->SetValue(width_);
170
171 return wxWindow::TransferDataToWindow();
172}
virtual int width() const

References ID_WIDTH, TTAMachine::Port::name(), name_, port_, WxConversion::toWxString(), updateSockets(), TTAMachine::BaseFUPort::width(), and width_.

Here is the call graph for this function:

◆ updateSockets()

void SRPortDialog::updateSockets ( )
private

Updates input and output socket choicers.

Definition at line 179 of file SRPortDialog.cc.

179 {
180
181 inputSocketChoice_->Clear();
183 outputSocketChoice_->Clear();
185
186 MachineTester tester(*(port_->parentUnit()->machine()));
187
188 // Add ports to the choicers
189 Machine::SocketNavigator navigator =
191
192 for (int i = 0; i < navigator.count(); i++) {
193 Socket* socket = navigator.item(i);
194 wxString socketName = WxConversion::toWxString(socket->name());
195
196 // Add available input sockets.
197 Socket* input = port_->inputSocket();
198 if (input != NULL) {
199 port_->detachSocket(*input);
200 }
201 bool legal = tester.canConnect(*socket, *port_);
202 if (legal && socket->direction() == Socket::INPUT) {
203 inputSocketChoice_->Append(socketName);
204 }
205 if (input != NULL) {
206 port_->attachSocket(*input);
207 }
208
209 // Add available output sockets.
210 Socket* output = port_->outputSocket();
211 if (output != NULL) {
212 port_->detachSocket(*output);
213 }
214 legal = tester.canConnect(*socket, *port_);
215 if (legal && socket->direction() == Socket::OUTPUT) {
216 outputSocketChoice_->Append(socketName);
217 }
218 if (output != NULL) {
219 port_->attachSocket(*output);
220 }
221 // ignore sockets with unknown direction
222 }
223
224 // set input socket choice
225 if (port_->inputSocket() == NULL) {
226 inputSocketChoice_->SetStringSelection(ProDeConstants::NONE);
227 } else {
228 wxString socketName =
230 inputSocketChoice_->SetStringSelection(socketName);
231 }
232
233 // set output socket choice
234 if (port_->outputSocket() == NULL) {
235 outputSocketChoice_->SetStringSelection(ProDeConstants::NONE);
236 } else {
237 wxString socketName =
239 outputSocketChoice_->SetStringSelection(socketName);
240 }
241}
virtual TCEString name() const
virtual void detachSocket(Socket &socket)
Definition Port.cc:237
@ OUTPUT
Data goes from port to bus.
Definition Socket.hh:60
@ INPUT
Data goes from bus to port.
Definition Socket.hh:59
Direction direction() const

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

Referenced by onSocketChoice(), and TransferDataToWindow().

Here is the call graph for this function:

Member Data Documentation

◆ inputSocketChoice_

wxChoice* SRPortDialog::inputSocketChoice_
private

Input socket choice control.

Definition at line 70 of file SRPortDialog.hh.

Referenced by onSocketChoice(), and updateSockets().

◆ name_

wxString SRPortDialog::name_
private

Name of the port.

Definition at line 66 of file SRPortDialog.hh.

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

◆ oldInput_

TTAMachine::Socket* SRPortDialog::oldInput_
private

Original input socket of the port.

Definition at line 75 of file SRPortDialog.hh.

Referenced by onCancel().

◆ oldOutput_

TTAMachine::Socket* SRPortDialog::oldOutput_
private

Original output socket of the port.

Definition at line 77 of file SRPortDialog.hh.

Referenced by onCancel().

◆ outputSocketChoice_

wxChoice* SRPortDialog::outputSocketChoice_
private

Output socket choice control.

Definition at line 72 of file SRPortDialog.hh.

Referenced by onSocketChoice(), and updateSockets().

◆ port_

TTAMachine::SpecialRegisterPort* SRPortDialog::port_
private

Function unit port to modify.

Definition at line 64 of file SRPortDialog.hh.

Referenced by onCancel(), onOK(), onSocketChoice(), TransferDataToWindow(), and updateSockets().

◆ width_

int SRPortDialog::width_
private

Width of the port.

Definition at line 68 of file SRPortDialog.hh.

Referenced by onOK(), and TransferDataToWindow().


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