OpenASIP 2.2
Loading...
Searching...
No Matches
ImmediateSlotDialog.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 ImmediateSlotDialog.cc
26 *
27 * Implementation of ImmediateSlotDialog class.
28 *
29 * @author Veli-Pekka Jääskeläinen 2005 (vjaaskel-no.spam-cs.tut.fi)
30 * @note rating: red
31 */
32
33#include <boost/format.hpp>
34#include <wx/statline.h>
35#include <wx/listctrl.h>
36
38#include "ImmediateSlot.hh"
39#include "Machine.hh"
40#include "WxConversion.hh"
41#include "WidgetTools.hh"
42#include "ProDeTextGenerator.hh"
43#include "GUITextGenerator.hh"
44#include "MachineTester.hh"
45#include "InformationDialog.hh"
46#include "WarningDialog.hh"
47
48using std::string;
49using boost::format;
50using namespace TTAMachine;
51
52BEGIN_EVENT_TABLE(ImmediateSlotDialog, wxDialog)
57 EVT_TEXT(ID_NAME, ImmediateSlotDialog::onSlotName)
59
60
61/**
62 * The Constructor.
63 *
64 * @param parent Parent window of the dialog.
65 * @param machine Parent Machine of the immediate slots.
66 */
68 wxWindow* parent,
70 wxDialog(parent, -1, _T(""), wxDefaultPosition),
71 machine_(machine) {
72
73 createContents(this, true, true);
74
75 slotList_ = dynamic_cast<wxListCtrl*>(FindWindow(ID_SLOT_LIST));
76
77 FindWindow(ID_NAME)->SetValidator(
78 wxTextValidator(wxFILTER_ASCII, &slotName_));
79
80 // Disable conditional buttons.
81 FindWindow(ID_ADD_SLOT)->Disable();
82 FindWindow(ID_DELETE_SLOT)->Disable();
83
84 setTexts();
85}
86
87
88/**
89 * The Destructor.
90 */
93
94
95/**
96 * Sets widget texts.
97 */
98void
128
129
130/**
131 * Transfers data from the machine model to the dialog widgets.
132 */
133bool
135
136 // update slot list
137 slotList_->DeleteAllItems();
138 const Machine::ImmediateSlotNavigator navigator =
140
141 for (int i = 0; i < navigator.count(); i++) {
142 slotList_->InsertItem(
143 i, WxConversion::toWxString(navigator.item(i)->name()));
144 }
145
146 return wxDialog::TransferDataToWindow();
147}
148
149
150/**
151 * Enables and disables the delete button according to slot list selection.
152 */
153void
155 if (slotList_->GetSelectedItemCount() == 1) {
156 FindWindow(ID_DELETE_SLOT)->Enable();
157 } else {
158 FindWindow(ID_DELETE_SLOT)->Disable();
159 }
160}
161
162
163/**
164 * Deletes the selected immediate slot.
165 */
166void
168
169 // Check which slot is selected.
170 long item = -1;
171 item = slotList_->GetNextItem(
172 item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
173
174 if (item < 0) {
175 return;
176 }
177
178 ImmediateSlot* slot =
180
181 delete slot;
182
184 wxListEvent dummy;
186}
187
188
189/**
190 * Adds a new slot to the machine when "Add" button is pressed.
191 */
192void
194
195 if (!TransferDataFromWindow()) {
196 return;
197 }
198
199 string trimmedName =
200 WxConversion::toString(slotName_.Trim(false).Trim(true));
201
202 // Check name validity.
203 if (!MachineTester::isValidComponentName(trimmedName)) {
205 format message =
207 InformationDialog warning(
208 this, WxConversion::toWxString(message.str()));
209 warning.ShowModal();
210 return;
211 }
212
213 if (machine_->immediateSlotNavigator().hasItem(trimmedName)) {
215 format message =
217 message % trimmedName;
218 message % prodeTexts->text(ProDeTextGenerator::COMP_AN_IMM_SLOT).str();
219 message % prodeTexts->text(ProDeTextGenerator::COMP_MACHINE).str();
220 message % prodeTexts->text(ProDeTextGenerator::COMP_IMM_SLOT).str();
221 WarningDialog warning(this, WxConversion::toWxString(message.str()));
222 warning.ShowModal();
223 return;
224 }
225
226 // Buses share namespace with immediate slots. Check that a bus with the
227 // same name does not exist.
228 if (machine_->busNavigator().hasItem(trimmedName)) {
230 format message =
232 message % trimmedName;
233 message % prodeTexts->text(ProDeTextGenerator::COMP_A_BUS).str();
234 message % prodeTexts->text(ProDeTextGenerator::COMP_MACHINE).str();
235 message % prodeTexts->text(ProDeTextGenerator::COMP_IMM_SLOT).str();
236 WarningDialog warning(this, WxConversion::toWxString(message.str()));
237 warning.ShowModal();
238 return;
239 }
240
241 new ImmediateSlot(trimmedName, *machine_);
242 slotName_ = _T("");
244}
245
246
247/**
248 * Enables and disables the "Add" button when text is entered in the
249 * slot name widget.
250 */
251void
253
254 if (!TransferDataFromWindow()) {
255 return;
256 }
257
258 wxString trimmedName = slotName_.Trim(false).Trim(true);
259 if (trimmedName == _T("")) {
260 FindWindow(ID_ADD_SLOT)->Disable();
261 } else {
262 FindWindow(ID_ADD_SLOT)->Enable();
263 }
264}
265
266
267/**
268 * Creates the dialog contents.
269 *
270 * @param parent Parent dialog of the contents.
271 * @param call_fit If true, fits the contents inside the dialog.
272 * @param set_sizer If true, sets the main sizer as dialog contents.
273 * @return Top level sizer of the dialog contents.
274 */
275wxSizer*
277 wxWindow *parent, bool call_fit, bool set_sizer) {
278
279
280 wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL );
281
282 wxListCtrl *item1 = new wxListCtrl( parent, ID_SLOT_LIST, wxDefaultPosition, wxSize(300,200), wxLC_REPORT|wxLC_SINGLE_SEL|wxSUNKEN_BORDER );
283 item0->Add( item1, 0, wxGROW|wxALL, 5 );
284
285 wxBoxSizer *item2 = new wxBoxSizer( wxVERTICAL );
286
287 wxBoxSizer *item3 = new wxBoxSizer( wxHORIZONTAL );
288
289 wxBoxSizer *item4 = new wxBoxSizer( wxHORIZONTAL );
290
291 wxStaticText *item5 = new wxStaticText( parent, ID_LABEL_NAME, wxT("Name:"), wxDefaultPosition, wxDefaultSize, 0 );
292 item4->Add( item5, 0, wxALIGN_CENTER|wxALL, 5 );
293
294 wxTextCtrl *item6 = new wxTextCtrl( parent, ID_NAME, wxT(""), wxDefaultPosition, wxSize(120,-1), 0 );
295 item4->Add( item6, 0, wxALIGN_CENTER|wxALL, 5 );
296
297 item3->Add( item4, 0, wxGROW|wxALL, 5 );
298
299 wxBoxSizer *item7 = new wxBoxSizer( wxHORIZONTAL );
300
301 wxButton *item8 = new wxButton( parent, ID_ADD_SLOT, wxT("Add"), wxDefaultPosition, wxDefaultSize, 0 );
302 item7->Add( item8, 0, wxALIGN_CENTER|wxALL, 5 );
303
304 wxButton *item9 = new wxButton( parent, ID_DELETE_SLOT, wxT("Delete"), wxDefaultPosition, wxDefaultSize, 0 );
305 item7->Add( item9, 0, wxALIGN_CENTER|wxALL, 5 );
306
307 item3->Add( item7, 0, wxALIGN_CENTER, 5 );
308
309 item2->Add( item3, 0, wxALIGN_CENTER|wxALL, 5 );
310
311 item0->Add( item2, 0, wxGROW|wxALL, 5 );
312
313 wxStaticLine *item10 = new wxStaticLine( parent, ID_LINE, wxDefaultPosition, wxSize(20,-1), wxLI_HORIZONTAL );
314 item0->Add( item10, 0, wxGROW|wxALL, 5 );
315
316 wxGridSizer *item11 = new wxGridSizer( 2, 0, 0 );
317
318 wxButton *item12 = new wxButton( parent, ID_HELP, wxT("&Help"), wxDefaultPosition, wxDefaultSize, 0 );
319 item11->Add( item12, 0, wxALL, 5 );
320
321 wxBoxSizer *item13 = new wxBoxSizer( wxHORIZONTAL );
322
323 wxButton *item14 = new wxButton( parent, wxID_OK, wxT("&OK"), wxDefaultPosition, wxDefaultSize, 0 );
324 item13->Add( item14, 0, wxALIGN_CENTER|wxALL, 5 );
325
326 wxButton *item15 = new wxButton( parent, wxID_CANCEL, wxT("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
327 item13->Add( item15, 0, wxALIGN_CENTER|wxALL, 5 );
328
329 item11->Add( item13, 0, 0, 5 );
330
331 item0->Add( item11, 0, wxGROW, 5 );
332
333 if (set_sizer)
334 {
335 parent->SetSizer( item0 );
336 if (call_fit)
337 item0->SetSizeHints( parent );
338 }
339
340 return item0;
341}
END_EVENT_TABLE() using namespace IDF
TTAMachine::Machine * machine
the architecture definition of the estimated processor
FUImplementationDialog::onAddExternalPort FUImplementationDialog::onDeleteExternalPort FUImplementationDialog::onArchPortSelection EVT_LIST_ITEM_DESELECTED(ID_ARCH_PORT_LIST, FUImplementationDialog::onArchPortSelection) EVT_LIST_ITEM_ACTIVATED(ID_ARCH_PORT_LIST
FUImplementationDialog::onAddExternalPort FUImplementationDialog::onDeleteExternalPort FUImplementationDialog::onArchPortSelection FUImplementationDialog::onArchPortActivation EVT_LIST_ITEM_SELECTED(ID_EXTERNAL_PORT_LIST, FUImplementationDialog::onExternalPortSelection) EVT_LIST_ITEM_ACTIVATED(ID_EXTERNAL_PORT_LIST
EVT_BUTTON(ID_EDIT_ARCH_PORT, FUImplementationDialog::onEditArchitecturePort) EVT_BUTTON(ID_ADD_EXTERNAL_PORT
SimValue dummy(32)
a dummy simvalue which is given for operands that are not bound
@ TXT_BUTTON_HELP
Label for help button.
@ TXT_BUTTON_DELETE
Label for delete button.
@ TXT_BUTTON_CANCEL
Label for cancel button.
@ TXT_BUTTON_OK
Label for OK button.
@ TXT_BUTTON_ADD
Label for an add button.
static GUITextGenerator * instance()
wxSizer * createContents(wxWindow *parent, bool call_fit, bool set_sizer)
void onDeleteSlot(wxCommandEvent &event)
wxListCtrl * slotList_
Immediate slot list widget.
virtual bool TransferDataToWindow()
void onSlotSelection(wxListEvent &event)
void onSlotName(wxCommandEvent &event)
wxString slotName_
Text in the slot name widget.
void onAddSlot(wxCommandEvent &event)
TTAMachine::Machine * machine_
Parent machine of the immediate slots.
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.
@ TXT_LABEL_NAME
Label for component name widget.
@ COMP_MACHINE
Text for machine description.
@ COMP_AN_IMM_SLOT
Name for imm. slot (w/ article).
@ COMP_A_BUS
Name for a bus component.
@ TXT_IMMEDIATE_SLOT_DIALOG_TITLE
Immediate Slot dialog title.
@ TXT_COLUMN_NAME
Label for name column in a list.
@ COMP_IMM_SLOT
Name for imm. slot (w/o article).
ComponentType * item(int index) const
bool hasItem(const std::string &name) const
virtual ImmediateSlotNavigator immediateSlotNavigator() const
Definition Machine.cc:462
virtual BusNavigator busNavigator() const
Definition Machine.cc:356
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)