OpenASIP 2.2
Loading...
Searching...
No Matches
ProDeBusOrderDialog.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 ProDeBusOrderDialog.cc
26 *
27 * Implementation of ProDeBusOrderDialog class.
28 *
29 * @author Veli-Pekka Jääskeläinen 2005 (vjaaskel-no.spam-cs.tut.fi)
30 * @note rating: red
31 */
32
33#include <wx/statline.h>
34#include <wx/listctrl.h>
36#include "Machine.hh"
37#include "WxConversion.hh"
38#include "Bus.hh"
39
40BEGIN_EVENT_TABLE(ProDeBusOrderDialog, wxDialog)
46
47/**
48 * The Constructor.
49 *
50 * @param parent Parent window of the dialog.
51 * @param machine Machine containing the buses to order.
52 */
54 wxWindow* parent, TTAMachine::Machine& machine) :
55 wxDialog(parent, -1, _T("Transport Bus Order"), wxDefaultPosition),
56 machine_(machine) {
57
58 createContents(this, true, true);
59
60 list_ = dynamic_cast<wxListCtrl*>(FindWindow(ID_LIST));
61 list_->InsertColumn(0, _T("index"), wxLIST_FORMAT_LEFT, 50);
62 list_->InsertColumn(1, _T("bus"), wxLIST_FORMAT_LEFT, 180);
63
64 // Disable conditional buttons.
65 FindWindow(ID_UP)->Disable();
66 FindWindow(ID_DOWN)->Disable();
67
68 updateBusList();
69
70}
71
72/**
73 * The Destructor.
74 */
77
78
79/**
80 * Updates the bus list order.
81 */
82void
84 list_->DeleteAllItems();
85 const TTAMachine::Machine::BusNavigator& navigator =
87
88 for (int i = 0; i < navigator.count(); i++) {
89 std::string busName = navigator.item(i)->name();
90 list_->InsertItem(i, WxConversion::toWxString(i));
91 list_->SetItem(i, 1, WxConversion::toWxString(busName));
92 }
93}
94
95/**
96 * Moves the selected bus one position up (decreases the index by one).
97 */
98void
99ProDeBusOrderDialog::onUp(wxCommandEvent&) {
100
101 const TTAMachine::Machine::BusNavigator& navigator =
103
104 int position = selectedBus();
105 if (position <= 0) {
106 return;
107 }
108 machine_.setBusPosition(*navigator.item(position), position - 1);
109
111
112 // Reselect the moved bus.
113 list_->SetItemState(
114 position - 1, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
115
116 list_->EnsureVisible(position - 1);
117}
118
119
120/**
121 * Moves the selected bus one position down (increases the index by one).
122 */
123void
125
126 const TTAMachine::Machine::BusNavigator& navigator =
128
129 int position = selectedBus();
130 if (position >= (navigator.count() - 1)) {
131 return;
132 }
133
134 machine_.setBusPosition(*navigator.item(position), position + 1);
135
137
138 // Reselect the moved bus.
139 list_->SetItemState(
140 position + 1, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
141
142 list_->EnsureVisible(position + 1);
143}
144
145/**
146 * Enables and disables Up/Down buttons according to bus selection.
147 */
148void
150
151 const TTAMachine::Machine::BusNavigator& navigator =
153
154 int selection = selectedBus();
155
156 if (selection < 0) {
157 FindWindow(ID_UP)->Disable();
158 FindWindow(ID_DOWN)->Disable();
159 return;
160 }
161
162 if (selection > 0) {
163 FindWindow(ID_UP)->Enable();
164 } else {
165 FindWindow(ID_UP)->Disable();
166 }
167
168 if (selection < (navigator.count() - 1)) {
169 FindWindow(ID_DOWN)->Enable();
170 } else {
171 FindWindow(ID_DOWN)->Disable();
172 }
173}
174
175/**
176 * Returns index of the selected bus, or -1 if no bs is selected.
177 *
178 * @return Index of bus selected in the bus list.
179 */
180int
182 int item = -1;
183 item = list_->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
184 return item;
185}
186
187
188/**
189 * Creates the dialog widgets.
190 */
191wxSizer*
193 wxWindow* parent, bool call_fit, bool set_sizer) {
194
195 wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL );
196
197 wxBoxSizer *item1 = new wxBoxSizer( wxHORIZONTAL );
198
199 wxListCtrl *item2 = new wxListCtrl( parent, ID_LIST, wxDefaultPosition, wxSize(250,300), wxLC_REPORT|wxLC_SINGLE_SEL|wxSUNKEN_BORDER );
200 item1->Add( item2, 0, wxALIGN_CENTER|wxALL, 5 );
201
202 wxBoxSizer *item3 = new wxBoxSizer( wxVERTICAL );
203
204 wxButton *item4 = new wxButton( parent, ID_UP, wxT("&Up"), wxDefaultPosition, wxDefaultSize, 0 );
205 item3->Add( item4, 0, wxALIGN_CENTER|wxALL, 5 );
206
207 wxButton *item5 = new wxButton( parent, ID_DOWN, wxT("&Down"), wxDefaultPosition, wxDefaultSize, 0 );
208 item3->Add( item5, 0, wxALIGN_CENTER|wxALL, 5 );
209
210 item1->Add( item3, 0, wxALL, 5 );
211
212 item0->Add( item1, 0, wxALIGN_CENTER|wxALL, 5 );
213
214 wxStaticLine *item6 = new wxStaticLine( parent, ID_LINE, wxDefaultPosition, wxSize(20,-1), wxLI_HORIZONTAL );
215 item0->Add( item6, 0, wxGROW|wxALL, 5 );
216
217 wxBoxSizer *item7 = new wxBoxSizer( wxHORIZONTAL );
218
219 wxButton *item8 = new wxButton( parent, wxID_CANCEL, wxT("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
220 item7->Add( item8, 0, wxALIGN_CENTER|wxALL, 5 );
221
222 wxButton *item9 = new wxButton( parent, wxID_OK, wxT("&OK"), wxDefaultPosition, wxDefaultSize, 0 );
223 item7->Add( item9, 0, wxALIGN_CENTER|wxALL, 5 );
224
225 item0->Add( item7, 0, wxALL, 5 );
226
227 if (set_sizer)
228 {
229 parent->SetSizer( item0 );
230 if (call_fit)
231 item0->SetSizeHints( parent );
232 }
233
234 return item0;
235}
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
void onBusSelectionChanged(wxListEvent &event)
wxSizer * createContents(wxWindow *parent, bool call_fit, bool set_sizer)
TTAMachine::Machine & machine_
Machine containing the buses to sort.
wxListCtrl * list_
List widget for the buses.
void onUp(wxCommandEvent &event)
void onDown(wxCommandEvent &event)
ComponentType * item(int index) const
virtual BusNavigator busNavigator() const
Definition Machine.cc:356
void setBusPosition(const Bus &bus, int newPosition)
Definition Machine.cc:651
static wxString toWxString(const std::string &source)