OpenASIP 2.2
Loading...
Searching...
No Matches
IUPortDialog.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 IUPortDialog.cc
26 *
27 * Definition of IUPortDialog class.
28 *
29 * @author Veli-Pekka Jääskeläinen 2004 (vjaaskel-no.spam-cs.tut.fi)
30 */
31
32#include <boost/format.hpp>
33
34#include "IUPortDialog.hh"
35#include "WxConversion.hh"
36#include "Conversion.hh"
37#include "ProDeConstants.hh"
38#include "Socket.hh"
39#include "Port.hh"
40#include "Machine.hh"
41#include "MachineTester.hh"
42#include "WarningDialog.hh"
43#include "UserManualCmd.hh"
44#include "InformationDialog.hh"
45#include "WidgetTools.hh"
46#include "GUITextGenerator.hh"
47#include "ProDeTextGenerator.hh"
48
49using boost::format;
50using std::string;
51using namespace TTAMachine;
52
53BEGIN_EVENT_TABLE(IUPortDialog, wxDialog)
54 EVT_TEXT(ID_NAME, IUPortDialog::onName)
57
58/**
59 * The Constructor.
60 *
61 * @param parent Parent window of the dialog.
62 * @param port Immediate unit port to be modified with the dialog.
63 */
65 wxWindow* parent,
66 Port* port):
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
75 outputSocketChoice_ =
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
83 TransferDataToWindow();
84}
85
86
87/**
88 * The Destructor.
89 */
92
93
94/**
95 * Sets texts for widgets.
96 */
97void
124
125
126/**
127 * Transfers data from the Port object to the dialog widgets.
128 *
129 * @return false, if an error occured in the transfer.
130 */
131bool
134
135 updateSocket();
136
137 return wxWindow::TransferDataToWindow();
138}
139
140
141/**
142 * Updates output socket choicer.
143 */
144void
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}
184
185
186
187/**
188 * Validates input in the controls, and updates the port.
189 */
190void
191IUPortDialog::onOK(wxCommandEvent&) {
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}
253
254
255/**
256 * Validates input in the controls, and updates the port.
257 */
258void
259IUPortDialog::onName(wxCommandEvent&) {
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}
270
271
272/**
273 * Creates the dialog window contents.
274 *
275 * This method was initially generated with wxDesigner, code will be
276 * cleaned up later.
277 *
278 * @return Main sizer of the created contents.
279 * @param parent The dialog window.
280 * @param call_fit If true, fits the contents inside the dialog.
281 * @param set_sizer If true, sets the main sizer as dialog contents.
282 */
283wxSizer*
285 wxWindow *parent, bool call_fit, bool set_sizer) {
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}
#define assert(condition)
END_EVENT_TABLE() using namespace IDF
EVT_BUTTON(ID_EDIT_ARCH_PORT, FUImplementationDialog::onEditArchitecturePort) EVT_BUTTON(ID_ADD_EXTERNAL_PORT
@ 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 TransferDataToWindow()
void onOK(wxCommandEvent &event)
wxString name_
Name of the port.
wxSizer * createContents(wxWindow *parent, bool call_fit, bool set_sizer)
wxChoice * outputSocketChoice_
Output socket choice control.
virtual ~IUPortDialog()
void updateSocket()
TTAMachine::Port * port_
Immediate unit port to edit with the dialog.
void onName(wxCommandEvent &event)
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.
@ TXT_LABEL_OUTPUT_SOCKET
Label for output socket selector.
@ COMP_PORT
Name for port (w/o article).
@ COMP_IMMEDIATE_UNIT
Immediate unit (w/o article).
@ COMP_A_PORT
Name for port (w/ article).
@ TXT_IU_PORT_DIALOG_TITLE
Immediate unit port dialog title.
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 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
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)