OpenASIP 2.2
Loading...
Searching...
No Matches
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.
 
wxString name_
 Name 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 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.

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("")),
79
82 createContents(this, true, true);
83 FindWindow(wxID_OK)->Disable();
84
85 // set widget texts
86 setTexts();
87
89}
wxString name_
Name of the port.
wxChoice * inputSocketChoice_
Input socket choice control.
virtual bool TransferDataToWindow()
wxSizer * createContents(wxWindow *parent, bool call_fit, bool set_sizer)
TTAMachine::Port * port_
Port to modify.
wxChoice * outputSocketChoice_
Output socket choice control.
TTAMachine::Socket * oldInput_
Original input socket of the port.
TTAMachine::Socket * oldOutput_
Original output socket of the port.
virtual Socket * outputSocket() const
Definition Port.cc:281
virtual Socket * inputSocket() const
Definition Port.cc:261

◆ ~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}
const string TRUE
Value used for true in attribute and element values.

References ID_HELP, ID_INPUT_SOCKET, ID_NAME, ID_OUTPUT_SOCKET, inputSocketChoice_, name_, outputSocketChoice_, and 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}
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 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}
#define assert(condition)

References assert, and name_.

◆ 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 =
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}
const string RF
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_REGISTER_FILE
Register file (w/o article).
@ COMP_PORT
Name for port (w/o article).
@ COMP_A_PORT
Name for port (w/ article).
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 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(), name_, TTAMachine::Port::parentUnit(), TTAMachine::Unit::port(), port_, TTAMachine::Unit::portCount(), RF, TTAMachine::Port::setName(), 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 }
244}
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::Port::parentUnit(), port_, TTAMachine::Machine::socketNavigator(), WxConversion::toString(), and updateSockets().

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}
@ 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_INPUT_SOCKET
Label for input socket selector.
@ TXT_RF_PORT_DIALOG_TITLE
Register file port Dialog title.
@ TXT_LABEL_OUTPUT_SOCKET
Label for output socket selector.
static void setLabel(Texts::TextGenerator *generator, wxWindow *widget, int textID)

References ID_HELP, ID_INPUT_SOCKET, ID_NAME, ID_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_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 {
218 return wxWindow::TransferDataToWindow();
219}

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

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}
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::Port::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* RFPortDialog::inputSocketChoice_
private

Input socket choice control.

Definition at line 65 of file RFPortDialog.hh.

Referenced by createContents(), onSocketChoice(), and updateSockets().

◆ name_

wxString RFPortDialog::name_
private

Name of the port.

Definition at line 63 of file RFPortDialog.hh.

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

◆ oldInput_

TTAMachine::Socket* RFPortDialog::oldInput_
private

Original input socket of the port.

Definition at line 69 of file RFPortDialog.hh.

Referenced by onCancel().

◆ oldOutput_

TTAMachine::Socket* RFPortDialog::oldOutput_
private

Original output socket of the port.

Definition at line 71 of file RFPortDialog.hh.

Referenced by onCancel().

◆ outputSocketChoice_

wxChoice* RFPortDialog::outputSocketChoice_
private

Output socket choice control.

Definition at line 67 of file RFPortDialog.hh.

Referenced by createContents(), onSocketChoice(), and updateSockets().

◆ port_

TTAMachine::Port* RFPortDialog::port_
private

Port to modify.

Definition at line 61 of file RFPortDialog.hh.

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


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