OpenASIP 2.2
Loading...
Searching...
No Matches
FUGuardDialog.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 FUGuardDialog.cc
26 *
27 * Implementation of FUGuardDialog class.
28 *
29 * @author Veli-Pekka Jääskeläinen 2004 (vjaaskel-no.spam-cs.tut.fi)
30 */
31
32#include <wx/wx.h>
33#include <wx/statline.h>
34#include <wx/valgen.h>
35#include <boost/format.hpp>
36
37#include "FUGuardDialog.hh"
38#include "Guard.hh"
39#include "WxConversion.hh"
40#include "Machine.hh"
41#include "FunctionUnit.hh"
42#include "FUPort.hh"
43#include "InformationDialog.hh"
44#include "WidgetTools.hh"
45#include "GUITextGenerator.hh"
46#include "ProDeTextGenerator.hh"
47#include "ProDeConstants.hh"
48
49using std::string;
50using boost::format;
51using namespace TTAMachine;
52
53BEGIN_EVENT_TABLE(FUGuardDialog, wxDialog)
54 EVT_CHOICE(ID_FU_NAME, FUGuardDialog::onFUChoice)
58
59/**
60 * The Constructor.
61 *
62 * @param parent Parent window of the dialog.
63 * @param guard Port guard to edit.
64 */
66 wxWindow* parent,
67 Bus* bus,
68 PortGuard* guard) :
69 wxDialog(parent, -1, _T(""), wxDefaultPosition),
70 inverted_(false),
71 newInverted_(false),
72 port_(NULL),
73 bus_(bus),
74 adding_(false) {
75
76
77 if (guard == NULL) {
78 // adding a new guard
79 adding_ = true;
80
82 bus_->machine()->functionUnitNavigator();
83
84 for (int i = 0; i < navigator.count(); i++) {
85 if (navigator.item(i)->operationPortCount() > 0) {
86 port_ = navigator.item(i)->operationPort(0);
87 break;
88 }
89 }
90
91 assert(port_ != NULL);
92
93 } else {
94 // editing an old guard
95 port_ = guard->port();
96 inverted_ = guard->isInverted();
97 newInverted_ = inverted_;
98 bus_ = guard->parentBus();
99
100 // The guard is temporarily deleted to simplify legality checks.
101 delete guard;
102 guard = NULL;
103 }
104
105 createContents(this, true, true);
106
107 // set pointers to the dialog widgets
108 nameChoice_ = dynamic_cast<wxChoice*>(FindWindow(ID_FU_NAME));
109 portChoice_ = dynamic_cast<wxChoice*>(FindWindow(ID_FU_PORT));
110 invertedBox_ = dynamic_cast<wxCheckBox*>(FindWindow(ID_INVERTED));
111
112 invertedBox_->SetValidator(wxGenericValidator(&newInverted_));
113
114 // set widget texts.
115 setTexts();
116}
117
118
119/**
120 * The Destructor.
121 */
124
125
126/**
127 * Sets texts for widgets.
128 */
129void
159
160
161/**
162 * Transfers data from the guard object to the dialog widgets.
163 *
164 * @return true, if the transfer was succesful, false otherwise.
165 */
166bool
168 nameChoice_->Clear();
169 portChoice_->Clear();
170
173
174 // add function units and set selection
175 for (int i = 0; i < navigator.count(); i++) {
176 wxString name = WxConversion::toWxString(navigator.item(i)->name());
177 nameChoice_->Append(name);
178 }
179 nameChoice_->SetStringSelection(
181
182 // add function unit ports and set selection
183 for (int i = 0; i < port_->parentUnit()->portCount(); i++) {
184
185 // port must be output port
186 if (port_->parentUnit()->port(i)->outputSocket() == NULL) {
187 continue;
188 }
189
190 wxString name =
192
193 portChoice_->Append(name);
194 }
195 portChoice_->SetStringSelection(WxConversion::toWxString(port_->name()));
196
197 // set inverted checkbox
198 invertedBox_->SetValue(newInverted_);
199
200 return wxDialog::TransferDataToWindow();
201}
202
203
204/**
205 * Updates the port choice when the function unit selection is changed.
206 */
207void
209
210 wxString selection = portChoice_->GetStringSelection();
211
212 portChoice_->Clear();
213
214 FunctionUnit* fu = selectedFU();
215 for (int i = 0; i < fu->portCount(); i++) {
216 wxString name = WxConversion::toWxString(fu->port(i)->name());
217 portChoice_->Append(name);
218 }
219
220 if (portChoice_->FindString(selection) >= 0) {
221 portChoice_->SetStringSelection(selection);
222 } else {
223 portChoice_->SetSelection(0);
224 }
225}
226
227
228/**
229 * Returns a pointer to the selected function unit.
230 *
231 * @return Pointer to the selected function unit.
232 */
235 string name = WxConversion::toString(nameChoice_->GetStringSelection());
238 FunctionUnit* fu = navigator.item(name);
239 return fu;
240}
241
242
243/**
244 * Returns a pointer to the selected function unit port.
245 *
246 * @return Pointer to the selected function unit port.
247 */
248FUPort*
250 string name = WxConversion::toString(portChoice_->GetStringSelection());
251
252 if (name == "") {
253 return NULL;
254 }
255
256 FUPort* port = selectedFU()->operationPort(name);
257 return port;
258}
259
260/**
261 * Updates the guard object when the OK-button is pressed.
262 *
263 * Closes the dialog.
264 */
265void
266FUGuardDialog::onOK(wxCommandEvent&) {
267 FUPort* port = selectedPort();
268 if (port == NULL) {
270 format message = prodeTexts->text(ProDeTextGenerator::MSG_ERROR);
271 InformationDialog dialog(
273 message.str() + "Select a port.\n"));
274 dialog.ShowModal();
275 return;
276 }
277
278 TransferDataFromWindow();
279
280 try {
281 new PortGuard(newInverted_, *port, *bus_);
282 } catch (ComponentAlreadyExists& e) {
284 format message =
286 InformationDialog dialog(
287 this, WxConversion::toWxString(message.str()));
288 dialog.ShowModal();
289 return;
290 }
291 EndModal(wxID_OK);
292}
293
294
295/**
296 * Cancels the dialog effects by creating the original port guard.
297 *
298 * Closes the Dialog.
299 */
300void
301FUGuardDialog::onCancel(wxCommandEvent&) {
302 if (adding_ == false) {
303 new PortGuard(inverted_, *port_, *bus_);
304 }
305 EndModal(wxID_CANCEL);
306}
307
308
309/**
310 * Creates contents of the dialog window.
311 *
312 * Code generated with wxDesigner.
313 *
314 * @param parent Parent dialog of the contents.
315 * @param call_fit If true, fits sizer in dialog window.
316 * @param set_sizer If true, sets sizer as dialog's sizer.
317 * @return Top level sizer of the contents.
318 */
319wxSizer*
321 wxWindow *parent, bool call_fit, bool set_sizer) {
322
323 wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL );
324
325 wxGridSizer *item1 = new wxGridSizer( 2, 0, 0 );
326
327 wxStaticText *item2 = new wxStaticText( parent, ID_LABEL_NAME, wxT("Function Unit Name:"), wxDefaultPosition, wxDefaultSize, 0 );
328 item1->Add( item2, 0, wxALL, 5 );
329
330 wxString *strs3 = (wxString*) NULL;
331 wxChoice *item3 = new wxChoice( parent, ID_FU_NAME, wxDefaultPosition, wxSize(100,-1), 0, strs3, 0 );
332 item1->Add( item3, 0, wxGROW|wxALL, 5 );
333
334 wxStaticText *item4 = new wxStaticText( parent, ID_LABEL_PORT, wxT("Port Name:"), wxDefaultPosition, wxDefaultSize, 0 );
335 item1->Add( item4, 0, wxALL, 5 );
336
337 wxString *strs5 = (wxString*) NULL;
338 wxChoice *item5 = new wxChoice( parent, ID_FU_PORT, wxDefaultPosition, wxSize(100,-1), 0, strs5, 0 );
339 item1->Add( item5, 0, wxGROW|wxALL, 5 );
340
341 item0->Add( item1, 0, wxALIGN_CENTER|wxALL, 5 );
342
343 wxCheckBox *item6 = new wxCheckBox( parent, ID_INVERTED, wxT("Inverted"), wxDefaultPosition, wxDefaultSize, 0 );
344 item0->Add( item6, 0, wxALL, 5 );
345
346 wxStaticLine *item7 = new wxStaticLine( parent, ID_LINE, wxDefaultPosition, wxSize(20,-1), wxLI_HORIZONTAL );
347 item0->Add( item7, 0, wxGROW|wxALL, 5 );
348
349 wxBoxSizer *item8 = new wxBoxSizer( wxHORIZONTAL );
350
351 wxButton *item9 = new wxButton( parent, ID_HELP, wxT("&Help"), wxDefaultPosition, wxDefaultSize, 0 );
352 item8->Add( item9, 0, wxALIGN_CENTER|wxALL, 5 );
353
354 wxButton *item10 = new wxButton( parent, wxID_OK, wxT("&OK"), wxDefaultPosition, wxDefaultSize, 0 );
355 item8->Add( item10, 0, wxALIGN_CENTER|wxALL, 5 );
356
357 wxButton *item11 = new wxButton( parent, wxID_CANCEL, wxT("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
358 item8->Add( item11, 0, wxALIGN_CENTER|wxALL, 5 );
359
360 item0->Add( item8, 0, wxALIGN_CENTER|wxALL, 5 );
361
362 if (set_sizer)
363 {
364 parent->SetSizer( item0 );
365 if (call_fit)
366 item0->SetSizeHints( parent );
367 }
368
369 return item0;
370}
#define assert(condition)
END_EVENT_TABLE() using namespace IDF
EVT_BUTTON(ID_EDIT_ARCH_PORT, FUImplementationDialog::onEditArchitecturePort) EVT_BUTTON(ID_ADD_EXTERNAL_PORT
find Finds info of the inner loops in the false
bool adding_
True if a new guard is being added, false otherwise.
void onCancel(wxCommandEvent &event)
virtual ~FUGuardDialog()
wxCheckBox * invertedBox_
Checkbox widget for the inverted flag.
virtual bool TransferDataToWindow()
void onOK(wxCommandEvent &event)
wxSizer * createContents(wxWindow *parent, bool call_fit, bool set_sizer)
TTAMachine::FunctionUnit * selectedFU() const
bool inverted_
Inverted flag for the guard.
wxChoice * portChoice_
Choice widget for the port selection.
wxChoice * nameChoice_
Choice widget for the function unit selection.
TTAMachine::FUPort * selectedPort() const
bool newInverted_
Modified inverted flag.
void onFUChoice(wxCommandEvent &event)
TTAMachine::Bus * bus_
Parent bus of the guard.
TTAMachine::FUPort * port_
Port of the guard.
@ TXT_BUTTON_HELP
Label for help button.
@ TXT_BUTTON_CANCEL
Label for cancel button.
@ TXT_BUTTON_OK
Label for OK button.
static GUITextGenerator * instance()
static ProDeTextGenerator * instance()
@ TXT_FU_GUARD_DIALOG_TITLE
Function unit guard dialog title.
@ MSG_ERROR_GUARD_EXISTS
Error: Equal guard exists.
@ TXT_LABEL_FU_NAME
Label for function unit name.
@ TXT_LABEL_PORT_NAME
Label for port name.
@ TXT_LABEL_INVERTED
Label for inverted checkbox.
@ MSG_ERROR
Text 'Error' and new line.
FunctionUnit * parentUnit() const
Definition BaseFUPort.cc:96
virtual Machine * machine() const
virtual TCEString name() const
virtual FUPort * operationPort(const std::string &name) const
virtual BaseFUPort * port(const std::string &name) const
ComponentType * item(int index) const
virtual FunctionUnitNavigator functionUnitNavigator() const
Definition Machine.cc:380
virtual Socket * outputSocket() const
Definition Port.cc:281
virtual std::string name() const
Definition Port.cc:141
virtual int portCount() const
Definition Unit.cc:135
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)