OpenASIP 2.2
Loading...
Searching...
No Matches
AddIUFromHDBDialog.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 AddIUFromHDBDialog.cc
26 *
27 * Implementation of AddIUFromHDBDialog class.
28 *
29 * @author Veli-Pekka Jääskeläinen 2006 (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#include <wx/dir.h>
37#include <wx/imaglist.h>
38
39#include "AddIUFromHDBDialog.hh"
40#include "Model.hh"
41#include "Machine.hh"
42#include "WxConversion.hh"
43#include "WidgetTools.hh"
44#include "HDBManager.hh"
45#include "HDBRegistry.hh"
46#include "RFArchitecture.hh"
47#include "WarningDialog.hh"
48#include "MapTools.hh"
49#include "Environment.hh"
50#include "FileSystem.hh"
51#include "Conversion.hh"
52#include "ProDeConstants.hh"
53
54#if !wxCHECK_VERSION(3, 0, 0)
55 typedef long int wxIntPtr;
56#endif
57
58using std::string;
59using boost::format;
60using namespace TTAMachine;
61using namespace HDB;
62
63BEGIN_EVENT_TABLE(AddIUFromHDBDialog, wxDialog)
68 EVT_LIST_COL_CLICK(ID_LIST, AddIUFromHDBDialog::onColumnClick)
70
71
72const int AddIUFromHDBDialog::DEFAULT_SIZE = 1;
73const int AddIUFromHDBDialog::DEFAULT_WIDTH = 32;
74const Machine::Extension AddIUFromHDBDialog::DEFAULT_EXTENSION_MODE =
75 Machine::ZERO;
76
77const wxString AddIUFromHDBDialog::HDB_FILE_FILTER = _T("*.hdb");
78
79int wxCALLBACK
80IUListCompareASC(wxIntPtr item1, wxIntPtr item2, wxIntPtr sortData) {
81
82 ListItemData* lid1 = (ListItemData*)item1;
83 ListItemData* lid2 = (ListItemData*)item2;
84 int sortColumn = (int)sortData;
85
86 if (sortColumn == 0) {
87 return lid1->width - lid2->width;
88 } else if (sortColumn == 1) {
89 return lid1->size - lid2->size;
90 } else if (sortColumn == 2) {
91 return lid1->readPorts - lid2->readPorts;
92 } else if (sortColumn == 3) {
93 return lid1->latency - lid2->latency;
94 } else if (sortColumn == 4) {
95 return lid1->hdbId - lid2->hdbId;
96 } else if (sortColumn == 5) {
97 return lid1->path.Cmp(lid2->path);
98 }
99
100 return 0;
101}
102
103int wxCALLBACK
105
106 ListItemData* lid1 = (ListItemData*)item1;
107 ListItemData* lid2 = (ListItemData*)item2;
108 int sortColumn = (int)sortData;
109
110 if (sortColumn == 0) {
111 return lid2->width - lid1->width;
112 } else if (sortColumn == 1) {
113 return lid2->size - lid1->size;
114 } else if (sortColumn == 2) {
115 return lid2->readPorts - lid1->readPorts;
116 } else if (sortColumn == 3) {
117 return lid2->latency - lid1->latency;
118 } else if (sortColumn == 4) {
119 return lid2->hdbId - lid1->hdbId;
120 } else if (sortColumn == 5) {
121 return lid2->path.Cmp(lid1->path);
122 }
123
124 return 0;
125}
126
127/**
128 * The Constructor.
129 *
130 * @param parent Parent window of the dialog.
131 * @param machine Parent Machine of the immediate slots.
132 */
134 wxWindow* parent,
135 Model* model) :
136 wxDialog(
137 parent, -1, _T("HDB Immediate Units"),
138 wxDefaultPosition, wxDefaultSize,
139 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER),
140 model_(model), sortColumn_(0), sortASC_(true) {
141
142 createContents(this, true, true);
143 SetSize(400, 300);
144
145 list_ = dynamic_cast<wxListCtrl*>(FindWindow(ID_LIST));
146
147 list_->InsertColumn(0, _T("Width"), wxLIST_FORMAT_LEFT, wxLIST_AUTOSIZE);
148 list_->InsertColumn(1, _T("Size"), wxLIST_FORMAT_LEFT, wxLIST_AUTOSIZE);
149 list_->InsertColumn(2, _T("Read ports"), wxLIST_FORMAT_LEFT, 100);
150 //list_->InsertColumn(5, _T("Max Reads"));
151 //list_->InsertColumn(6, _T("Max RW"));
152 list_->InsertColumn(3, _T("Latency"), wxLIST_FORMAT_LEFT, wxLIST_AUTOSIZE);
153 list_->InsertColumn(4, _T("ID"), wxLIST_FORMAT_LEFT, wxLIST_AUTOSIZE);
154 list_->InsertColumn(5, _T("HDB"), wxLIST_FORMAT_LEFT, wxLIST_AUTOSIZE);
155
156 string iconPath =
158
159 wxImageList* imageList = new wxImageList(13, 17);
160 imageList->Add(wxIcon(
162 imageList->Add(wxIcon(
164 list_->SetImageList(imageList, wxIMAGE_LIST_SMALL);
165
166 // Disable conditional buttons.
167 FindWindow(ID_ADD)->Disable();
168}
169
170
171/**
172 * The Destructor.
173 */
177
178
179/**
180 * Transfers data from the HDBs to the dialog list.
181 *
182 * @return True, if the the data transfer was succesful.
183 */
184bool
186
188 list_->DeleteAllItems();
189
190
191 const std::vector<string> hdbPaths = Environment::hdbPaths();
192 std::vector<string>::const_iterator hdbIter = hdbPaths.begin();
193
194 wxString paths;
195 bool hdbsFound = false;
196
197 // Read all hdb files found in the search directories.
198 for(; hdbIter != hdbPaths.end(); hdbIter++) {
199
200 wxString file;
201 wxString hdbPath = WxConversion::toWxString(*hdbIter);
202 paths.Append(hdbPath);
203 paths.Append(_T("\n"));
204 wxDir dir;
205
206 if (dir.Exists(hdbPath) &&
207 dir.Open(hdbPath) &&
208 dir.GetFirst(&file, HDB_FILE_FILTER)) {
209
210 do {
211 string path = *hdbIter + FileSystem::DIRECTORY_SEPARATOR +
213
214 if (loadHDB(path)) {
215 hdbsFound = true;
216 }
217 } while (dir.GetNext(&file));
218
219 }
220
221 }
222
223 if (!hdbsFound) {
224 wxString message = _T("No HDBs found in HDB search paths:\n");
225 message.Append(paths);
226 WarningDialog dialog(this, message);
227 dialog.ShowModal();
228 }
229
230 list_->SetColumnWidth(5, wxLIST_AUTOSIZE);
231 return wxDialog::TransferDataToWindow();
232}
233
234/**
235 * Loads immediate units from a HDB to the dialog list.
236 *
237 * @param path Full path to the HDB file to load.
238 * @return True, if the HDB was succesfully loaded.
239 */
240bool
241AddIUFromHDBDialog::loadHDB(const std::string& path) {
242
243 HDBManager* manager = NULL;
244
245 try {
246 manager = &HDBRegistry::instance().hdb(path);
247 } catch (Exception& e) {
248 wxString message = _T("Unable to open HDB '");
249 message.Append(WxConversion::toWxString(path));
250 message.Append(_T("':'"));
251 message.Append(WxConversion::toWxString(e.errorMessage()));
252 WarningDialog dialog(this, message);
253 dialog.ShowModal();
254 return false;
255 }
256
257 const std::set<RowID> rfArchIDs = manager->rfArchitectureIDs();
258 std::set<RowID>::iterator iter = rfArchIDs.begin();
259
260 // Read properties of all immediate units in the HDB and append
261 // data in the list widget.
262 for (; iter != rfArchIDs.end(); iter++) {
263
264 RFArchitecture* arch = manager->rfArchitectureByID(*iter);
265
266 if (arch->writePortCount() != 1 ||
267 arch->bidirPortCount() != 0) {
268
269 // Register file architecture must contain one read port and
270 // no bidirectional ports or it's not listed as an immediate
271 // unit architecture.
272 continue;
273 }
274
275 iuArchitectures_.insert(
276 std::pair<int, RFArchitecture*>(list_->GetItemCount(), arch));
277
278 ListItemData* lid = new ListItemData;
279
280 if (arch->hasParameterizedWidth()) {
281 list_->InsertItem(0, _T("param"));
282 lid->width = 0;
283 } else {
284 list_->InsertItem(0, WxConversion::toWxString(arch->width()));
285 lid->width = arch->width();
286 }
287 if (arch->hasParameterizedSize()) {
288 list_->SetItem(0, 1, _T("param"));
289 lid->size = 0;
290 } else {
291 list_->SetItem(0, 1, WxConversion::toWxString(arch->size()));
292 lid->size = arch->size();
293 }
294 list_->SetItem(0, 2, WxConversion::toWxString(arch->readPortCount()));
295 lid->readPorts = arch->readPortCount();
296 list_->SetItem(0, 3, WxConversion::toWxString(arch->latency()));
297 lid->latency = arch->latency();
298 list_->SetItem(0, 4, WxConversion::toWxString(*iter));
299 lid->hdbId = *iter;
300 list_->SetItem(0, 5, WxConversion::toWxString(path));
301 lid->path = WxConversion::toWxString(path);
302 lid->id = list_->GetItemCount() - 1;
303 list_->SetItemData(0, (long)lid);
304
305 }
306 // default sorting column is "Width"
307 list_->SortItems(IUListCompareASC, 0);
309
310 return true;
311}
312
313/**
314 * Enables and disables the delete button according to slot list selection.
315 */
316void
318 if (list_->GetSelectedItemCount() == 1) {
319 FindWindow(ID_ADD)->Enable();
320 } else {
321 FindWindow(ID_ADD)->Disable();
322 }
323}
324
325
326/**
327 * Adds a new register file to the machine when "Add" button is pressed.
328 */
329void
331
332 long item = -1;
333 item = list_->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
334 if ( item == -1 ) return;
335
336 ListItemData* lid = (ListItemData*)list_->GetItemData(item);
337 int id = lid->id;
338 const RFArchitecture* arch =
340
342
343 // Set size and width.
344 int size = DEFAULT_SIZE;
345 int width = DEFAULT_WIDTH;
346
347 if (!arch->hasParameterizedWidth()) {
348 size = arch->width();
349 }
350
351 if (!arch->hasParameterizedSize()) {
352 size = arch->size();
353 }
354
355 // Generate name for the new immediate unit.
356 string name =
357 "IU_" + Conversion::toString(size) + "x" + Conversion::toString(width);
358
359 string iuName = name;
360 int idx = 1;
361 while (machine->immediateUnitNavigator().hasItem(iuName)) {
362 iuName = name + "_" + Conversion::toString(idx);
363 idx++;
364 }
365
366 int maxReads = arch->maxReads();
367 int guardLatency = arch->guardLatency();
368
369 // Create an immediate unit object and attach it to the machine.
371 iuName, size, width, maxReads, guardLatency, DEFAULT_EXTENSION_MODE);
372
373 for (int i = 0; i < arch->readPortCount(); i++) {
374 string name = "r" + Conversion::toString(i);
375 new RFPort(name, *iu);
376 }
377
381
382}
383
384/**
385 * Closes the dialog when the close button is pressed.
386 */
387void
389 Close();
390}
391
392
393/**
394 * Creates the dialog contents.
395 *
396 * @param parent Parent dialog of the contents.
397 * @param call_fit If true, fits the contents inside the dialog.
398 * @param set_sizer If true, sets the main sizer as dialog contents.
399 * @return Top level sizer of the dialog contents.
400 */
401wxSizer*
403 wxWindow *parent, bool call_fit, bool set_sizer) {
404
405 wxFlexGridSizer *item0 = new wxFlexGridSizer( 1, 0, 0 );
406 item0->AddGrowableCol( 0 );
407 item0->AddGrowableRow( 0 );
408
409 wxListCtrl *item1 = new wxListCtrl( parent, ID_LIST, wxDefaultPosition, wxSize(160,120), wxLC_REPORT|wxSUNKEN_BORDER );
410 item0->Add( item1, 0, wxGROW|wxALL, 5 );
411
412 wxButton *item2 = new wxButton( parent, ID_ADD, wxT("&Add"), wxDefaultPosition, wxDefaultSize, 0 );
413 item0->Add( item2, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
414
415 wxStaticLine *item3 = new wxStaticLine( parent, ID_LINE, wxDefaultPosition, wxSize(20,-1), wxLI_HORIZONTAL );
416 item0->Add( item3, 0, wxGROW|wxALL, 5 );
417
418 wxButton *item4 = new wxButton( parent, ID_CLOSE, wxT("&Close"), wxDefaultPosition, wxDefaultSize, 0 );
419 item0->Add( item4, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL, 5 );
420
421 if (set_sizer) {
422 parent->SetSizer( item0 );
423 if (call_fit) {
424 item0->SetSizeHints( parent );
425 }
426 }
427
428 return item0;
429}
430
431
432/**
433 * Sorts HDB IU list according to clicked column.
434 */
435void
437
438 int clickedColumn = event.GetColumn();
439
440 if (clickedColumn == sortColumn_) {
442 } else {
443 sortASC_ = true;
444 setColumnImage(sortColumn_, -1); // removes arrow from old column
445 sortColumn_ = clickedColumn;
446 }
447
448 setColumnImage(clickedColumn, sortASC_);
449
450 if (sortASC_) {
451 list_->SortItems(IUListCompareASC, clickedColumn);
452 } else {
453 list_->SortItems(IUListCompareDESC, clickedColumn);
454 }
455}
456
457
458/**
459 * Sets sorting arrow image on selected column
460 *
461 * @param col Column index to set the image
462 * @param image Image index in wxImageList
463 */
464void
466 wxListItem item;
467 item.SetMask(wxLIST_MASK_IMAGE);
468 item.SetImage(image);
469 list_->SetColumn(col, item);
470}
long int wxIntPtr
long int wxIntPtr
int wxCALLBACK IUListCompareASC(wxIntPtr item1, wxIntPtr item2, wxIntPtr sortData)
int wxCALLBACK IUListCompareDESC(wxIntPtr item1, wxIntPtr item2, wxIntPtr sortData)
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
const int DEFAULT_WIDTH
Default window width.
#define DEFAULT_SIZE
AddIUFromHDBDialog(wxWindow *parent, Model *model)
static const wxString HDB_FILE_FILTER
File filter for HDB files.
void setColumnImage(int col, int image)
virtual bool TransferDataToWindow()
wxSizer * createContents(wxWindow *parent, bool call_fit, bool set_sizer)
void onColumnClick(wxListEvent &event)
void onClose(wxCommandEvent &event)
static const int DEFAULT_SIZE
Default size for the IU, if the size is parameterized in the HDB.
bool loadHDB(const std::string &path)
void onListSelectionChange(wxListEvent &event)
std::map< int, HDB::RFArchitecture * > iuArchitectures_
Map of iu architectures displayed in the dialog list.
static const int DEFAULT_WIDTH
Default width for the IU, if the size is parameterized in the HDB.
static const TTAMachine::Machine::Extension DEFAULT_EXTENSION_MODE
Default extension mode for the immediate unit.
void onAdd(wxCommandEvent &event)
Model * model_
Model of the current adf file.
wxListCtrl * list_
Immediate slot list widget.
static std::string toString(const T &source)
static std::vector< std::string > hdbPaths(bool libraryPathsOnly=false)
static std::string iconDirPath()
std::string errorMessage() const
Definition Exception.cc:123
static const std::string DIRECTORY_SEPARATOR
std::set< RowID > rfArchitectureIDs() const
virtual RFArchitecture * rfArchitectureByID(RowID id) const
static HDBRegistry & instance()
CachedHDBManager & hdb(const std::string fileName)
bool hasParameterizedWidth() const
bool hasParameterizedSize() const
static KeyType keyForValue(const MapType &aMap, const ValueType &aValue)
static void deleteAllValues(MapType &aMap)
Definition Model.hh:50
void pushToStack()
Definition Model.cc:167
void notifyObservers(bool modified=true)
Definition Model.cc:152
TTAMachine::Machine * getMachine()
Definition Model.cc:88
static const std::string ICON_SORT_DESC
Icon location for descending sort.
static const std::string ICON_SORT_ASC
Icon location for ascending sort.
bool hasItem(const std::string &name) const
virtual ImmediateUnitNavigator immediateUnitNavigator() const
Definition Machine.cc:416
virtual void addImmediateUnit(ImmediateUnit &unit)
Definition Machine.cc:224
static wxString toWxString(const std::string &source)
static std::string toString(const wxString &source)