OpenASIP 2.2
Loading...
Searching...
No Matches
RFGuardDialog.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 RFGuardDialog.cc
26 *
27 * Implementation of RFGuardDialog 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 "RFGuardDialog.hh"
38#include "Guard.hh"
39#include "WxConversion.hh"
40#include "Machine.hh"
41#include "RegisterFile.hh"
42#include "InformationDialog.hh"
43#include "WidgetTools.hh"
44#include "GUITextGenerator.hh"
45#include "ProDeTextGenerator.hh"
46
47using boost::format;
48using std::string;
49using namespace TTAMachine;
50
51BEGIN_EVENT_TABLE(RFGuardDialog, wxDialog)
52 EVT_CHOICE(ID_RF_NAME, RFGuardDialog::onRFChoice)
56
57/**
58 * The Constructor.
59 *
60 * @param parent Parent window of the dialog.
61 */
63 wxWindow* parent,
64 Bus* bus,
65 RegisterGuard* guard):
66 wxDialog(parent, -1, _T(""), wxDefaultPosition),
67 inverted_(false),
68 newInverted_(false),
69 index_(0),
70 newIndex_(0),
71 rf_(NULL),
72 bus_(bus),
73 adding_(false) {
74
75
76 if (guard == NULL) {
77 // adding a new guard
78 adding_ = true;
79 rf_ = bus_->machine()->registerFileNavigator().item(0);
80 } else {
81 // editing an old guard
82 rf_ = guard->registerFile();
83 index_ = guard->registerIndex();
84 newIndex_ = index_;
85 inverted_ = guard->isInverted();
86
87 // The guard is temporarily deleted to simplify legality checks.
88 delete guard;
89 guard = NULL;
90 }
91 newInverted_ = inverted_;
92
93 createContents(this, true, true);
94
95 // set pointers to the dialog widgets
96 nameChoice_ = dynamic_cast<wxChoice*>(FindWindow(ID_RF_NAME));
97 indexChoice_ = dynamic_cast<wxChoice*>(FindWindow(ID_RF_INDEX));
98 invertedBox_ = dynamic_cast<wxCheckBox*>(FindWindow(ID_INVERTED));
99
100 invertedBox_->SetValidator(wxGenericValidator(&newInverted_));
101 indexChoice_->SetValidator(wxGenericValidator(&newIndex_));
102
103 // set widget texts.
104 setTexts();
105}
106
107
108/**
109 * The Destructor.
110 */
113
114
115/**
116 * Sets texts for widgets.
117 */
118void
148
149
150/**
151 * Transfers data from the Guard object to the dialog widgets.
152 *
153 * @return true, if the transfer was succesful, false otherwise.
154 */
155bool
157 nameChoice_->Clear();
158 indexChoice_->Clear();
159
162
163 // set register file name
164 for (int i = 0; i < navigator.count(); i++) {
165 wxString name = WxConversion::toWxString(navigator.item(i)->name());
166 nameChoice_->Append(name);
167 }
168 nameChoice_->SetStringSelection(WxConversion::toWxString(rf_->name()));
169
170 // set register index
171 for (int i = 0; i < selectedRF()->numberOfRegisters(); i++) {
172 wxString index = WxConversion::toWxString(i);
173 indexChoice_->Append(index);
174 }
175
176 // add choice to create guard for every index
177 if (adding_) {
179 format fmtAll = prodeTexts->text(ProDeTextGenerator::TXT_ALL);
180 indexChoice_->Append(WxConversion::toWxString(fmtAll.str()));
181 }
182
183 indexChoice_->SetSelection(newIndex_);
184
185 // set inverted flag
186 invertedBox_->SetValue(newInverted_);
187
188 return wxDialog::TransferDataToWindow();
189}
190
191
192/**
193 * Updates the index choice when the register file selection is changed.
194 */
195void
197
198 int selection = indexChoice_->GetSelection();
199
200 indexChoice_->Clear();
201
202 const RegisterFile* rf = selectedRF();
203 for (int i = 0; i < rf->numberOfRegisters(); i++) {
204 wxString index = WxConversion::toWxString(i);
205 indexChoice_->Append(index);
206 }
207
208 // add choice to create guard for every index
209 if (adding_) {
211 format fmtAll = prodeTexts->text(ProDeTextGenerator::TXT_ALL);
212 indexChoice_->Append(WxConversion::toWxString(fmtAll.str()));
213 }
214
215 if (static_cast<int>(indexChoice_->GetCount()) >= selection) {
216 indexChoice_->SetSelection(selection);
217 } else {
218 indexChoice_->SetSelection(0);
219 }
220}
221
222
223/**
224 * Returns a pointer to the selected register file.
225 *
226 * @return Pointer to the selected refister file.
227 */
228const RegisterFile*
230 string name = WxConversion::toString(nameChoice_->GetStringSelection());
233 RegisterFile* rf = navigator.item(name);
234 return rf;
235}
236
237
238/**
239 * Updates the guard object when the OK-button is pressed.
240 *
241 * Closes the dialog.
242 */
243void
244RFGuardDialog::onOK(wxCommandEvent&) {
245 TransferDataFromWindow();
246 try {
247 // get currently selected index and its string representation
248 int indexSelection = indexChoice_->GetSelection();
249 assert(indexSelection != wxNOT_FOUND);
250 wxString choiceText = indexChoice_->GetString(indexSelection);
251
252 // get the string that resembles all indices
254 format fmtAll = prodeTexts->text(ProDeTextGenerator::TXT_ALL);
255 bool singleGuard = true;
256
257 // check if user has selected all indices
258 if (choiceText.IsSameAs(WxConversion::toWxString(fmtAll.str()))) {
259 singleGuard = false;
260 }
261
262 if (!adding_ || (adding_ && singleGuard)) {
263 // add / edit one guard
265 bus_);
266 } else {
267 // add new guard for every index
268
269 string rfNameSel = WxConversion::toString(
270 nameChoice_->GetStringSelection());
271
272 // loop all bus guards and mark old guards (if there is any)
273 // of the selected register file name to be deleted
274 std::vector<RegisterGuard*> toBeDeleted;
275 for (int i = 0; i < bus_->guardCount(); ++i) {
276 Guard* g = bus_->guard(i);
277 RegisterGuard* rfGuard =
278 dynamic_cast<RegisterGuard*>(g);
279
280 if (rfGuard != NULL) {
281 string rfName = rfGuard->registerFile()->name();
282
283 // if register file names match
284 if (rfName.compare(rfNameSel) == 0) {
285 // if inverted setting is same
286 if (rfGuard->isInverted() == newInverted_) {
287 toBeDeleted.push_back(rfGuard);
288 }
289 }
290 }
291 }
292
293 // delete old guards
294 for (unsigned int i = 0; i < toBeDeleted.size(); ++i) {
295 if (toBeDeleted.at(i) != NULL) {
296 delete toBeDeleted.at(i);
297 toBeDeleted.at(i) = NULL;
298 }
299 }
300
301 // create new guard for every file register's index
302 for (int index = 0; index < selectedRF()->numberOfRegisters();
303 ++index) {
304 new RegisterGuard(newInverted_, *selectedRF(), index,
305 bus_);
306 }
307 }
308 } catch (ComponentAlreadyExists& e) {
310 format message =
312 InformationDialog dialog(
313 this, WxConversion::toWxString(message.str()));
314 dialog.ShowModal();
315 return;
316 }
317
318 EndModal(wxID_OK);
319}
320
321
322/**
323 * Cancels the dialog effects by creating the original register guard.
324 *
325 * Closes the dialog.
326 */
327void
328RFGuardDialog::onCancel(wxCommandEvent&) {
329 if (adding_ == false) {
331 }
332 EndModal(wxID_CANCEL);
333}
334
335
336/**
337 * Creates contents of the dialog window.
338 *
339 * Code generated with wxDesigner.
340 *
341 * @param parent Parent dialog of the contents.
342 * @param call_fit If true, fits sizer in dialog window.
343 * @param set_sizer If true, sets sizer as dialog's sizer.
344 * @return Top level sizer of the contents.
345 */
346wxSizer*
348 wxWindow *parent, bool call_fit, bool set_sizer) {
349
350 wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL );
351
352 wxGridSizer *item1 = new wxGridSizer( 2, 0, 0 );
353
354 wxStaticText *item2 = new wxStaticText( parent, ID_LABEL_NAME, wxT("Register File Name:"), wxDefaultPosition, wxDefaultSize, 0 );
355 item1->Add( item2, 0, wxALL, 5 );
356
357 wxString *strs3 = (wxString*) NULL;
358 wxChoice *item3 = new wxChoice( parent, ID_RF_NAME, wxDefaultPosition, wxSize(100,-1), 0, strs3, 0 );
359 item1->Add( item3, 0, wxGROW|wxALL, 5 );
360
361 wxStaticText *item4 = new wxStaticText( parent, ID_LABEL_INDEX, wxT("Register Index:"), wxDefaultPosition, wxDefaultSize, 0 );
362 item1->Add( item4, 0, wxALL, 5 );
363
364 wxString *strs5 = (wxString*) NULL;
365 wxChoice *item5 = new wxChoice( parent, ID_RF_INDEX, wxDefaultPosition, wxSize(100,-1), 0, strs5, 0 );
366 item1->Add( item5, 0, wxGROW|wxALL, 5 );
367
368 item0->Add( item1, 0, wxGROW|wxALL, 5 );
369
370 wxCheckBox *item6 = new wxCheckBox( parent, ID_INVERTED, wxT("Inverted"), wxDefaultPosition, wxDefaultSize, 0 );
371 item0->Add( item6, 0, wxALL, 5 );
372
373 wxStaticLine *item7 = new wxStaticLine( parent, ID_LINE, wxDefaultPosition, wxSize(20,-1), wxLI_HORIZONTAL );
374 item0->Add( item7, 0, wxGROW|wxALL, 5 );
375
376 wxBoxSizer *item8 = new wxBoxSizer( wxHORIZONTAL );
377
378 wxButton *item9 = new wxButton( parent, ID_HELP, wxT("&Help"), wxDefaultPosition, wxDefaultSize, 0 );
379 item8->Add( item9, 0, wxALIGN_CENTER|wxALL, 5 );
380
381 wxButton *item10 = new wxButton( parent, wxID_OK, wxT("&OK"), wxDefaultPosition, wxDefaultSize, 0 );
382 item8->Add( item10, 0, wxALIGN_CENTER|wxALL, 5 );
383
384 wxButton *item11 = new wxButton( parent, wxID_CANCEL, wxT("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
385 item8->Add( item11, 0, wxALIGN_CENTER|wxALL, 5 );
386
387 item0->Add( item8, 0, wxALIGN_CENTER|wxALL, 5 );
388
389 if (set_sizer)
390 {
391 parent->SetSizer( item0 );
392 if (call_fit)
393 item0->SetSizeHints( parent );
394 }
395
396 return item0;
397}
#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
@ 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()
@ MSG_ERROR_GUARD_EXISTS
Error: Equal guard exists.
@ TXT_LABEL_REGISTER_INDEX
Label for register index widget.
@ TXT_RF_GUARD_DIALOG_TITLE
Register file guard dialog title.
@ TXT_LABEL_RF_NAME
Label for register file name.
@ TXT_LABEL_INVERTED
Label for inverted checkbox.
@ TXT_ALL
Text 'all' in lower case.
const TTAMachine::RegisterFile * selectedRF() const
const TTAMachine::RegisterFile * rf_
Guard register.
bool adding_
True if a new guard is being added, false otherwise.
virtual ~RFGuardDialog()
int index_
Register index of the guard.
bool newInverted_
Modified inverted flag of the guard.
wxSizer * createContents(wxWindow *parent, bool call_fit, bool set_sizer)
int newIndex_
Modified register index of the guard.
void onOK(wxCommandEvent &event)
void onCancel(wxCommandEvent &event)
wxChoice * nameChoice_
Choice widget for register file name selection.
TTAMachine::Bus * bus_
Parent bus of the register guard.
virtual bool TransferDataToWindow()
bool inverted_
Inverted flag of the guard.
wxChoice * indexChoice_
Choice widget for register index selection.
void onRFChoice(wxCommandEvent &event)
wxCheckBox * invertedBox_
Checkbox widget for the inverted flag.
virtual int numberOfRegisters() const
Guard * guard(int index) const
Definition Bus.cc:456
int guardCount() const
Definition Bus.cc:441
virtual Machine * machine() const
virtual TCEString name() const
virtual bool isInverted() const
ComponentType * item(int index) const
virtual RegisterFileNavigator registerFileNavigator() const
Definition Machine.cc:450
const RegisterFile * registerFile() const
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)