OpenASIP 2.2
Loading...
Searching...
No Matches
Public Member Functions | Private Types | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
AddIUFromHDBDialog Class Reference

#include <AddIUFromHDBDialog.hh>

Inheritance diagram for AddIUFromHDBDialog:
Inheritance graph
Collaboration diagram for AddIUFromHDBDialog:
Collaboration graph

Public Member Functions

 AddIUFromHDBDialog (wxWindow *parent, Model *model)
 
virtual ~AddIUFromHDBDialog ()
 

Private Types

enum  { ID_LIST = 10000 , ID_ADD , ID_CLOSE , ID_LINE }
 

Private Member Functions

virtual bool TransferDataToWindow ()
 
wxSizer * createContents (wxWindow *parent, bool call_fit, bool set_sizer)
 
void onListSelectionChange (wxListEvent &event)
 
void onAdd (wxCommandEvent &event)
 
void onClose (wxCommandEvent &event)
 
bool loadHDB (const std::string &path)
 
void onColumnClick (wxListEvent &event)
 
void setColumnImage (int col, int image)
 

Private Attributes

Modelmodel_
 Model of the current adf file.
 
wxListCtrl * list_
 Immediate slot list widget.
 
std::map< int, HDB::RFArchitecture * > iuArchitectures_
 Map of iu architectures displayed in the dialog list.
 
int sortColumn_
 
bool sortASC_
 

Static Private Attributes

static const int DEFAULT_SIZE = 1
 Default size for the IU, if the size is parameterized in the HDB.
 
static const int DEFAULT_WIDTH = 32
 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.
 
static const wxString HDB_FILE_FILTER = _T("*.hdb")
 File filter for HDB files.
 

Detailed Description

Dialog for adding immediate unit architectures directly from HDB to the current machine.

Definition at line 61 of file AddIUFromHDBDialog.hh.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
private
Enumerator
ID_LIST 
ID_ADD 
ID_CLOSE 
ID_LINE 

Definition at line 86 of file AddIUFromHDBDialog.hh.

Constructor & Destructor Documentation

◆ AddIUFromHDBDialog()

AddIUFromHDBDialog::AddIUFromHDBDialog ( wxWindow *  parent,
Model model 
)

The Constructor.

Parameters
parentParent window of the dialog.
machineParent Machine of the immediate slots.

Definition at line 133 of file AddIUFromHDBDialog.cc.

135 :
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}
wxSizer * createContents(wxWindow *parent, bool call_fit, bool set_sizer)
Model * model_
Model of the current adf file.
wxListCtrl * list_
Immediate slot list widget.
static std::string iconDirPath()
static const std::string DIRECTORY_SEPARATOR
static const std::string ICON_SORT_DESC
Icon location for descending sort.
static const std::string ICON_SORT_ASC
Icon location for ascending sort.
static wxString toWxString(const std::string &source)

References createContents(), FileSystem::DIRECTORY_SEPARATOR, ProDeConstants::ICON_SORT_ASC, ProDeConstants::ICON_SORT_DESC, Environment::iconDirPath(), ID_ADD, ID_LIST, list_, and WxConversion::toWxString().

Here is the call graph for this function:

◆ ~AddIUFromHDBDialog()

AddIUFromHDBDialog::~AddIUFromHDBDialog ( )
virtual

The Destructor.

Definition at line 174 of file AddIUFromHDBDialog.cc.

174 {
176}
std::map< int, HDB::RFArchitecture * > iuArchitectures_
Map of iu architectures displayed in the dialog list.
static void deleteAllValues(MapType &aMap)

References MapTools::deleteAllValues(), and iuArchitectures_.

Here is the call graph for this function:

Member Function Documentation

◆ createContents()

wxSizer * AddIUFromHDBDialog::createContents ( wxWindow *  parent,
bool  call_fit,
bool  set_sizer 
)
private

Creates the dialog contents.

Parameters
parentParent dialog of the contents.
call_fitIf true, fits the contents inside the dialog.
set_sizerIf true, sets the main sizer as dialog contents.
Returns
Top level sizer of the dialog contents.

Definition at line 402 of file AddIUFromHDBDialog.cc.

403 {
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}

References ID_ADD, ID_CLOSE, ID_LINE, and ID_LIST.

Referenced by AddIUFromHDBDialog().

◆ loadHDB()

bool AddIUFromHDBDialog::loadHDB ( const std::string &  path)
private

Loads immediate units from a HDB to the dialog list.

Parameters
pathFull path to the HDB file to load.
Returns
True, if the HDB was succesfully loaded.

Definition at line 241 of file AddIUFromHDBDialog.cc.

241 {
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}
int wxCALLBACK IUListCompareASC(wxIntPtr item1, wxIntPtr item2, wxIntPtr sortData)
void setColumnImage(int col, int image)
std::string errorMessage() const
Definition Exception.cc:123
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

References HDB::RFArchitecture::bidirPortCount(), Exception::errorMessage(), HDB::RFArchitecture::hasParameterizedSize(), HDB::RFArchitecture::hasParameterizedWidth(), HDB::HDBRegistry::hdb(), ListItemData::hdbId, ListItemData::id, HDB::HDBRegistry::instance(), iuArchitectures_, IUListCompareASC(), HDB::RFArchitecture::latency(), ListItemData::latency, list_, ListItemData::path, HDB::RFArchitecture::readPortCount(), ListItemData::readPorts, HDB::HDBManager::rfArchitectureByID(), HDB::HDBManager::rfArchitectureIDs(), setColumnImage(), HDB::RFArchitecture::size(), ListItemData::size, sortASC_, WxConversion::toWxString(), HDB::RFArchitecture::width(), ListItemData::width, and HDB::RFArchitecture::writePortCount().

Referenced by TransferDataToWindow().

Here is the call graph for this function:

◆ onAdd()

void AddIUFromHDBDialog::onAdd ( wxCommandEvent &  event)
private

Adds a new register file to the machine when "Add" button is pressed.

Definition at line 330 of file AddIUFromHDBDialog.cc.

330 {
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}
TTAMachine::Machine * machine
the architecture definition of the estimated processor
static const int DEFAULT_SIZE
Default size for the IU, if the size is parameterized in the HDB.
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.
static std::string toString(const T &source)
static KeyType keyForValue(const MapType &aMap, const ValueType &aValue)
void pushToStack()
Definition Model.cc:167
void notifyObservers(bool modified=true)
Definition Model.cc:152
TTAMachine::Machine * getMachine()
Definition Model.cc:88
bool hasItem(const std::string &name) const
virtual ImmediateUnitNavigator immediateUnitNavigator() const
Definition Machine.cc:416
virtual void addImmediateUnit(ImmediateUnit &unit)
Definition Machine.cc:224

References TTAMachine::Machine::addImmediateUnit(), DEFAULT_EXTENSION_MODE, DEFAULT_SIZE, DEFAULT_WIDTH, Model::getMachine(), HDB::RFArchitecture::guardLatency(), TTAMachine::Machine::Navigator< ComponentType >::hasItem(), HDB::RFArchitecture::hasParameterizedSize(), HDB::RFArchitecture::hasParameterizedWidth(), ListItemData::id, TTAMachine::Machine::immediateUnitNavigator(), iuArchitectures_, MapTools::keyForValue(), list_, machine, HDB::RFArchitecture::maxReads(), model_, Model::notifyObservers(), Model::pushToStack(), HDB::RFArchitecture::readPortCount(), HDB::RFArchitecture::size(), Conversion::toString(), and HDB::RFArchitecture::width().

Here is the call graph for this function:

◆ onClose()

void AddIUFromHDBDialog::onClose ( wxCommandEvent &  event)
private

Closes the dialog when the close button is pressed.

Definition at line 388 of file AddIUFromHDBDialog.cc.

388 {
389 Close();
390}

◆ onColumnClick()

void AddIUFromHDBDialog::onColumnClick ( wxListEvent &  event)
private

Sorts HDB IU list according to clicked column.

Definition at line 436 of file AddIUFromHDBDialog.cc.

436 {
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}
int wxCALLBACK IUListCompareDESC(wxIntPtr item1, wxIntPtr item2, wxIntPtr sortData)

References IUListCompareASC(), IUListCompareDESC(), list_, setColumnImage(), sortASC_, and sortColumn_.

Here is the call graph for this function:

◆ onListSelectionChange()

void AddIUFromHDBDialog::onListSelectionChange ( wxListEvent &  event)
private

Enables and disables the delete button according to slot list selection.

Definition at line 317 of file AddIUFromHDBDialog.cc.

317 {
318 if (list_->GetSelectedItemCount() == 1) {
319 FindWindow(ID_ADD)->Enable();
320 } else {
321 FindWindow(ID_ADD)->Disable();
322 }
323}

References ID_ADD, and list_.

◆ setColumnImage()

void AddIUFromHDBDialog::setColumnImage ( int  col,
int  image 
)
private

Sets sorting arrow image on selected column

Parameters
colColumn index to set the image
imageImage index in wxImageList

Definition at line 465 of file AddIUFromHDBDialog.cc.

465 {
466 wxListItem item;
467 item.SetMask(wxLIST_MASK_IMAGE);
468 item.SetImage(image);
469 list_->SetColumn(col, item);
470}

References list_.

Referenced by loadHDB(), and onColumnClick().

◆ TransferDataToWindow()

bool AddIUFromHDBDialog::TransferDataToWindow ( )
privatevirtual

Transfers data from the HDBs to the dialog list.

Returns
True, if the the data transfer was succesful.

Definition at line 185 of file AddIUFromHDBDialog.cc.

185 {
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}
static const wxString HDB_FILE_FILTER
File filter for HDB files.
bool loadHDB(const std::string &path)
static std::vector< std::string > hdbPaths(bool libraryPathsOnly=false)
static std::string toString(const wxString &source)

References MapTools::deleteAllValues(), FileSystem::DIRECTORY_SEPARATOR, HDB_FILE_FILTER, Environment::hdbPaths(), iuArchitectures_, list_, loadHDB(), WxConversion::toString(), and WxConversion::toWxString().

Here is the call graph for this function:

Member Data Documentation

◆ DEFAULT_EXTENSION_MODE

const Machine::Extension AddIUFromHDBDialog::DEFAULT_EXTENSION_MODE
staticprivate
Initial value:
=
Machine::ZERO

Default extension mode for the immediate unit.

Definition at line 98 of file AddIUFromHDBDialog.hh.

Referenced by onAdd().

◆ DEFAULT_SIZE

const int AddIUFromHDBDialog::DEFAULT_SIZE = 1
staticprivate

Default size for the IU, if the size is parameterized in the HDB.

Definition at line 94 of file AddIUFromHDBDialog.hh.

Referenced by onAdd().

◆ DEFAULT_WIDTH

const int AddIUFromHDBDialog::DEFAULT_WIDTH = 32
staticprivate

Default width for the IU, if the size is parameterized in the HDB.

Definition at line 96 of file AddIUFromHDBDialog.hh.

Referenced by onAdd().

◆ HDB_FILE_FILTER

const wxString AddIUFromHDBDialog::HDB_FILE_FILTER = _T("*.hdb")
staticprivate

File filter for HDB files.

Definition at line 100 of file AddIUFromHDBDialog.hh.

Referenced by TransferDataToWindow().

◆ iuArchitectures_

std::map<int, HDB::RFArchitecture*> AddIUFromHDBDialog::iuArchitectures_
private

Map of iu architectures displayed in the dialog list.

Definition at line 81 of file AddIUFromHDBDialog.hh.

Referenced by loadHDB(), onAdd(), TransferDataToWindow(), and ~AddIUFromHDBDialog().

◆ list_

wxListCtrl* AddIUFromHDBDialog::list_
private

Immediate slot list widget.

Definition at line 79 of file AddIUFromHDBDialog.hh.

Referenced by AddIUFromHDBDialog(), loadHDB(), onAdd(), onColumnClick(), onListSelectionChange(), setColumnImage(), and TransferDataToWindow().

◆ model_

Model* AddIUFromHDBDialog::model_
private

Model of the current adf file.

Definition at line 77 of file AddIUFromHDBDialog.hh.

Referenced by onAdd().

◆ sortASC_

bool AddIUFromHDBDialog::sortASC_
private

Definition at line 84 of file AddIUFromHDBDialog.hh.

Referenced by loadHDB(), and onColumnClick().

◆ sortColumn_

int AddIUFromHDBDialog::sortColumn_
private

Definition at line 83 of file AddIUFromHDBDialog.hh.

Referenced by onColumnClick().


The documentation for this class was generated from the following files: