OpenASIP 2.2
Loading...
Searching...
No Matches
RFPortDialog.cc
Go to the documentation of this file.
1/*
2 Copyright (c) 2002-2009 Tampere University.
3
4 This file is part of TTA-Based Codesign Environment (TCE).
5
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 and/or sell copies of the Software, and to permit persons to whom the
11 Software is furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
23 */
24/**
25 * @file RFPortDialog.cc
26 *
27 * Definition of RFPortDialog class.
28 *
29 * @author Veli-Pekka Jääskeläinen 2004 (vjaaskel-no.spam-cs.tut.fi)
30 * @note rating: red
31 */
32
33#include <wx/wx.h>
34#include <wx/statline.h>
35#include <boost/format.hpp>
36
37#include "RegisterFile.hh"
38#include "RFPortDialog.hh"
39#include "WxConversion.hh"
40#include "Conversion.hh"
41#include "ProDeConstants.hh"
42#include "Socket.hh"
43#include "Machine.hh"
44#include "MachineTester.hh"
45#include "WarningDialog.hh"
46#include "UserManualCmd.hh"
47#include "Port.hh"
48#include "WidgetTools.hh"
49#include "GUITextGenerator.hh"
50#include "ProDeTextGenerator.hh"
51#include "InformationDialog.hh"
52
53using boost::format;
54using std::string;
55using namespace TTAMachine;
56
57BEGIN_EVENT_TABLE(RFPortDialog, wxDialog)
58 EVT_TEXT(ID_NAME, RFPortDialog::onName)
61 EVT_CHOICE(ID_INPUT_SOCKET, RFPortDialog::onSocketChoice)
62 EVT_CHOICE(ID_OUTPUT_SOCKET, RFPortDialog::onSocketChoice)
64
65/**
66 * The Constructor.
67 *
68 * @param parent Parent window of the dialog.
69 * @param port Port to modify.
70 */
72 wxWindow* parent,
73 Port* port):
74 wxDialog(parent, -1, _T(""), wxDefaultPosition),
75 port_(port),
76 name_(_T("")),
77 inputSocketChoice_(NULL),
78 outputSocketChoice_(NULL) {
79
80 oldInput_ = port_->inputSocket();
81 oldOutput_ = port_->outputSocket();
82 createContents(this, true, true);
83 FindWindow(wxID_OK)->Disable();
84
85 // set widget texts
86 setTexts();
87
88 TransferDataToWindow();
89}
90
91/**
92 * The Destructor.
93 */
96
97/**
98 * Sets texts for widgets.
99 */
100void
130
131/**
132 * Validates input in the controls, and updates the port.
133 */
134void
135RFPortDialog::onOK(wxCommandEvent&) {
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}
191
192
193/**
194 * Resets the original output and input sockets for the port and closes the
195 * dialog.
196 */
197void
198RFPortDialog::onCancel(wxCommandEvent&) {
200 if (oldInput_ != NULL) {
202 }
203 if (oldOutput_ != NULL) {
205 }
206 EndModal(wxID_CANCEL);
207}
208
209/**
210 * Transfers data from the port object to the dialog widgets.
211 *
212 * @return False, if an error occured in the transfer.
213 */
214bool
218 return wxWindow::TransferDataToWindow();
219}
220
221/**
222 * Updates the port object when user changes input/output socket selection.
223 */
224void
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}
245
246/**
247 * Updates input and output socket choicers.
248 */
249void
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}
313
314/**
315 * Validates input in the controls, and updates the ComponentDescriptor.
316 */
317void
318RFPortDialog::onName(wxCommandEvent&) {
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}
329
330/**
331 * Creates contents of the dialog window. Initially generated with
332 * wxDesigner, the code will be cleaned up later.
333 *
334 * @param parent Parent dialog of the contents.
335 * @param call_fit If true, fits sizer in dialog window.
336 * @param set_sizer If true, sets sizer as dialog's sizer.
337 * @return Top level sizer of the contents.
338 */
339wxSizer*
341 wxWindow *parent, bool call_fit, bool set_sizer) {
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}
#define assert(condition)
END_EVENT_TABLE() using namespace IDF
EVT_BUTTON(ID_EDIT_ARCH_PORT, FUImplementationDialog::onEditArchitecturePort) EVT_BUTTON(ID_ADD_EXTERNAL_PORT
const string TRUE
Value used for true in attribute and element values.
const string RF
@ TXT_BUTTON_HELP
Label for help button.
@ TXT_BUTTON_CANCEL
Label for cancel button.
@ TXT_BUTTON_OK
Label for OK button.
static GUITextGenerator * instance()
virtual bool canConnect(const TTAMachine::Socket &socket, const TTAMachine::Segment &segment)
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.
@ TXT_LABEL_NAME
Label for component name widget.
@ COMP_REGISTER_FILE
Register file (w/o article).
@ 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.
@ COMP_PORT
Name for port (w/o article).
@ COMP_A_PORT
Name for port (w/ article).
void updateSockets()
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.
void onSocketChoice(wxCommandEvent &event)
void onCancel(wxCommandEvent &event)
void onOK(wxCommandEvent &event)
wxChoice * outputSocketChoice_
Output socket choice control.
virtual ~RFPortDialog()
void onName(wxCommandEvent &event)
TTAMachine::Socket * oldInput_
Original input socket of the port.
TTAMachine::Socket * oldOutput_
Original output socket of the port.
virtual Machine * machine() const
virtual TCEString name() const
ComponentType * item(int index) const
virtual SocketNavigator socketNavigator() const
Definition Machine.cc:368
virtual Socket * outputSocket() const
Definition Port.cc:281
virtual void attachSocket(Socket &socket)
Definition Port.cc:191
virtual void detachSocket(Socket &socket)
Definition Port.cc:237
virtual void detachAllSockets()
Definition Port.cc:536
Unit * parentUnit() const
virtual Socket * inputSocket() const
Definition Port.cc:261
virtual std::string name() const
Definition Port.cc:141
virtual void setName(const std::string &name)
Definition Port.cc:155
@ 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
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 void setLabel(Texts::TextGenerator *generator, wxWindow *widget, int textID)
static wxString toWxString(const std::string &source)
static std::string toString(const wxString &source)