OpenASIP  2.0
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>
35 #include "ProDeBusOrderDialog.hh"
36 #include "Machine.hh"
37 #include "WxConversion.hh"
38 #include "Bus.hh"
39 
40 BEGIN_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  */
76 }
77 
78 
79 /**
80  * Updates the bus list order.
81  */
82 void
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  */
98 void
99 ProDeBusOrderDialog::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 
110  updateBusList();
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  */
123 void
124 ProDeBusOrderDialog::onDown(wxCommandEvent&) {
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 
136  updateBusList();
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  */
148 void
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  */
180 int
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  */
191 wxSizer*
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 }
ProDeBusOrderDialog::createContents
wxSizer * createContents(wxWindow *parent, bool call_fit, bool set_sizer)
Definition: ProDeBusOrderDialog.cc:192
WxConversion::toWxString
static wxString toWxString(const std::string &source)
TTAMachine::Machine::setBusPosition
void setBusPosition(const Bus &bus, int newPosition)
Definition: Machine.cc:651
ProDeBusOrderDialog::onBusSelectionChanged
void onBusSelectionChanged(wxListEvent &event)
Definition: ProDeBusOrderDialog.cc:149
machine
TTAMachine::Machine * machine
the architecture definition of the estimated processor
Definition: EstimatorCmdLineUI.cc:59
ProDeBusOrderDialog::list_
wxListCtrl * list_
List widget for the buses.
Definition: ProDeBusOrderDialog.hh:71
FindWindow
Definition: FindWindow.hh:49
TTAMachine::Machine::Navigator::count
int count() const
ProDeBusOrderDialog::onDown
void onDown(wxCommandEvent &event)
Definition: ProDeBusOrderDialog.cc:124
ProDeBusOrderDialog::ID_LIST
@ ID_LIST
Definition: ProDeBusOrderDialog.hh:65
ProDeBusOrderDialog::machine_
TTAMachine::Machine & machine_
Machine containing the buses to sort.
Definition: ProDeBusOrderDialog.hh:69
ProDeBusOrderDialog.hh
ProDeBusOrderDialog::ID_UP
@ ID_UP
Definition: ProDeBusOrderDialog.hh:62
ProDeBusOrderDialog::ID_DOWN
@ ID_DOWN
Definition: ProDeBusOrderDialog.hh:63
Machine.hh
ProDeBusOrderDialog::updateBusList
void updateBusList()
Definition: ProDeBusOrderDialog.cc:83
Bus.hh
EVT_LIST_ITEM_SELECTED
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
ProDeBusOrderDialog::ID_LINE
@ ID_LINE
Definition: ProDeBusOrderDialog.hh:64
ProDeBusOrderDialog::onUp
void onUp(wxCommandEvent &event)
Definition: ProDeBusOrderDialog.cc:99
ProDeBusOrderDialog
Definition: ProDeBusOrderDialog.hh:48
EVT_LIST_ITEM_DESELECTED
FUImplementationDialog::onAddExternalPort FUImplementationDialog::onDeleteExternalPort FUImplementationDialog::onArchPortSelection EVT_LIST_ITEM_DESELECTED(ID_ARCH_PORT_LIST, FUImplementationDialog::onArchPortSelection) EVT_LIST_ITEM_ACTIVATED(ID_ARCH_PORT_LIST
EVT_BUTTON
EVT_BUTTON(ID_EDIT_ARCH_PORT, FUImplementationDialog::onEditArchitecturePort) EVT_BUTTON(ID_ADD_EXTERNAL_PORT
TTAMachine::Machine::busNavigator
virtual BusNavigator busNavigator() const
Definition: Machine.cc:356
WxConversion.hh
TTAMachine::Machine::Navigator::item
ComponentType * item(int index) const
TTAMachine
Definition: Assembler.hh:48
TTAMachine::Machine::Navigator
Definition: Machine.hh:186
ProDeBusOrderDialog::selectedBus
int selectedBus() const
Definition: ProDeBusOrderDialog.cc:181
ProDeBusOrderDialog::~ProDeBusOrderDialog
virtual ~ProDeBusOrderDialog()
Definition: ProDeBusOrderDialog.cc:75
END_EVENT_TABLE
END_EVENT_TABLE() using namespace IDF