OpenASIP  2.0
CostFunctionPluginDialog.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 CostFunctionPluginDialog.cc
26  *
27  * Implementation of CostFunctionPluginDialog class.
28  *
29  * @author Veli-Pekka Jääskeläinen 2006 (vjaaskel-no.spam-cs.tut.fi)
30  * @note rating: red
31  */
32 
33 #include <wx/listctrl.h>
34 #include <wx/statline.h>
35 #include <wx/valgen.h>
37 #include "HDBManager.hh"
38 #include "WxConversion.hh"
39 #include "ContainerTools.hh"
41 #include "CostFunctionPlugin.hh"
42 #include "ErrorDialog.hh"
43 
44 #if wxCHECK_VERSION(3, 0, 0)
45  #define wxOPEN wxFD_OPEN
46  #define wxFILE_MUST_EXIST wxFD_FILE_MUST_EXIST
47 #endif
48 
49 using namespace HDB;
50 
51 BEGIN_EVENT_TABLE(CostFunctionPluginDialog, wxDialog)
57 
61 
62 const wxString CostFunctionPluginDialog::TYPE_COST_FU =
63  _T("FU Cost Estimator");
64 const wxString CostFunctionPluginDialog::TYPE_COST_RF =
65  _T("RF Cost Estimator");
66 const wxString CostFunctionPluginDialog::TYPE_COST_DECOMP =
67  _T("Decompressor Cost Estimator");
68 const wxString CostFunctionPluginDialog::TYPE_COST_ICDEC =
69  _T("IC & Decoder Cost Estimator");
70 
71 /**
72  * The Constructor.
73  *
74  * @param parent Parent window of the dialog.
75  * @param id Dialog window ID.
76  * @param hdb HDB containing the cost function plugin.
77  * @param pluginID Row ID of the plugin in the HDB.
78  */
80  wxWindow* parent, wxWindowID id, HDB::HDBManager& hdb, int pluginID) :
81  wxDialog(parent, id, _T("Cost Function Plugin")),
82  hdb_(hdb), id_(pluginID) {
83 
84  createContents(this, true, true);
85 
86  list_ = dynamic_cast<wxListCtrl*>(FindWindow(ID_LIST));
87  typeChoice_ = dynamic_cast<wxChoice*>(FindWindow(ID_TYPE));
88 
89  list_->InsertColumn(0, _T("Type"), wxLIST_FORMAT_LEFT, 50);
90  list_->InsertColumn(1, _T("ID"), wxLIST_FORMAT_LEFT, 50);
91  list_->InsertColumn(2, _T("Name"), wxLIST_FORMAT_LEFT, 200);
92  list_->InsertColumn(3, _T("Data"), wxLIST_FORMAT_RIGHT, 200);
93 
94  typeChoice_->Append(TYPE_COST_RF);
95  typeChoice_->Append(TYPE_COST_FU);
96  typeChoice_->Append(TYPE_COST_DECOMP);
97  typeChoice_->Append(TYPE_COST_ICDEC);
98 
99  FindWindow(ID_NAME)->SetValidator(wxGenericValidator(&name_));
100  FindWindow(ID_PATH)->SetValidator(wxGenericValidator(&path_));
101  FindWindow(
102  ID_DESCRIPTION)->SetValidator(wxGenericValidator(&description_));
103 
104  const CostFunctionPlugin* plugin = hdb_.costFunctionPluginByID(id_);
105 
106  name_ = WxConversion::toWxString(plugin->name());
107  path_ = WxConversion::toWxString(plugin->pluginFilePath());
108  description_ = WxConversion::toWxString(plugin->description());
109 
110  if (plugin->type() == CostFunctionPlugin::COST_FU) {
111  typeChoice_->SetStringSelection(TYPE_COST_FU);
112  } else if (plugin->type() == CostFunctionPlugin::COST_RF) {
113  typeChoice_->SetStringSelection(TYPE_COST_RF);
114  } else if (plugin->type() == CostFunctionPlugin::COST_DECOMP) {
115  typeChoice_->SetStringSelection(TYPE_COST_DECOMP);
116  } else if (plugin->type() == CostFunctionPlugin::COST_ICDEC) {
117  typeChoice_->SetStringSelection(TYPE_COST_ICDEC);
118  }
119  delete plugin;
120 
121  FindWindow(ID_DELETE)->Disable();
122  FindWindow(ID_MODIFY)->Disable();
123 }
124 
125 /**
126 y * The Destructor.
127  */
129 }
130 
131 /**
132  * Transfers data to the dilaog widgets.
133  */
134 bool
136 
137  list_->DeleteAllItems();
138 
139  // Plugin cost estimation data.
140  const std::set<RowID> pluginDataIDs = hdb_.costFunctionPluginDataIDs(id_);
141  std::set<RowID>::const_iterator iter = pluginDataIDs.begin();
142  for (; iter != pluginDataIDs.end(); iter++) {
143  const CostEstimationData data = hdb_.costEstimationData(*iter);
144  if (data.hasFUReference()) {
145  list_->InsertItem(0, _T("FU"));
146  list_->SetItem(0, 1, WxConversion::toWxString(data.fuReference()));
147  } else if (data.hasRFReference()) {
148  list_->InsertItem(0, _T("RF"));
149  list_->SetItem(0, 1, WxConversion::toWxString(data.rfReference()));
150  } else if (data.hasBusReference()) {
151  list_->InsertItem(0, _T("Bus"));
152  list_->SetItem(
153  0, 1, WxConversion::toWxString(data.busReference()));
154  } else if (data.hasSocketReference()) {
155  list_->InsertItem(0, _T("Socket"));
156  list_->SetItem(
158  } else {
159  list_->InsertItem(0, _T("-"));
160  list_->SetItem(0, 1, _T("-"));
161  }
162 
163  list_->SetItem(0, 2, WxConversion::toWxString(data.name()));
164  list_->SetItem(
165  0, 3, WxConversion::toWxString(data.value().stringValue()));
166  list_->SetItemData(0, *iter);
167  }
168 
169  return wxDialog::TransferDataToWindow();
170 }
171 
172 /**
173  * Returns RowID of the cost estimation data selected in the list.
174  *
175  * Returns -1 if no data is selected.
176  *
177  * @return RowID of the selected cost estiamtion data.
178  */
179 int
181  int item = list_->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
182 
183  if (item < 0) {
184  return -1;
185  }
186 
187  return list_->GetItemData(item);
188 }
189 
190 /**
191  * Event handler for the plugin data list selection changes.
192  *
193  * Updates the delete and modify button enabled/disabled states.
194  */
195 void
197  if (selectedData() == -1) {
198  FindWindow(ID_DELETE)->Disable();
199  FindWindow(ID_MODIFY)->Disable();
200  } else {
201  FindWindow(ID_DELETE)->Enable();
202  FindWindow(ID_MODIFY)->Enable();
203  }
204 }
205 
206 /**
207  * Event handler for the browse plugin file path button.
208  */
209 void
211  wxFileDialog dialog(
212  this, _T("Choose a plugin file."), _T(""), _T(""),
213  _T("Plugin files (*.so)|*.so|All Files|*.*"),
214  wxOPEN | wxFILE_MUST_EXIST);
215  if (dialog.ShowModal() == wxID_OK) {
216  dynamic_cast<wxTextCtrl*>(
217  FindWindow(ID_PATH))->SetValue(dialog.GetPath());
218  }
219 }
220 /**
221  * Event handler for the add button.
222  */
223 void
225  TransferDataFromWindow();
226  CostEstimationDataDialog dialog(this, -1, hdb_, id_, -1);
227  dialog.ShowModal();
228  TransferDataFromWindow();
229  TransferDataToWindow();
230 
231 }
232 
233 /**
234  * Event handler for the modify button.
235  */
236 void
238  TransferDataFromWindow();
239  int selected = selectedData();
240  if (selected >= 0) {
241  CostEstimationDataDialog dialog(this, -1, hdb_, id_, selected);
242  dialog.ShowModal();
243  TransferDataToWindow();
244  }
245 }
246 
247 /**
248  * Event handler for the Delete button.
249  */
250 void
252  TransferDataFromWindow();
253  int selected = selectedData();
254  if (selected >= 0) {
255  hdb_.removeCostEstimationData(selected);
256  TransferDataToWindow();
257  }
258 }
259 
260 /**
261  * Event handler for the Close button.
262  */
263 void
265 
266  TransferDataFromWindow();
267 
268  if (name_.IsEmpty()) {
269  wxString message(_T("Plugin name not set."));
270  ErrorDialog dialog(this, message);
271  dialog.ShowModal();
272  return;
273  }
274 
277 
278  if (typeChoice_->GetStringSelection() == TYPE_COST_RF) {
280  } else if (typeChoice_->GetStringSelection() == TYPE_COST_DECOMP) {
282  } else if (typeChoice_->GetStringSelection() == TYPE_COST_ICDEC) {
284  } else {
285  assert(typeChoice_->GetStringSelection() == TYPE_COST_FU);
286  }
287 
288  std::string description = WxConversion::toString(description_);
289  std::string name = WxConversion::toString(name_);
290  std::string path = WxConversion::toString(path_);
291  CostFunctionPlugin modified(-1, description, name, path, type);
292  hdb_.modifyCostFunctionPlugin(id_, modified);
293  EndModal(wxID_OK);
294 }
295 
296 /**
297  * Creates the dialog widgets.
298  *
299  * @param parent Parent window of the dialog widgets.
300  */
301 wxSizer*
303  wxWindow* parent, bool call_fit, bool set_sizer) {
304 
305  wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL );
306 
307  wxFlexGridSizer *item1 = new wxFlexGridSizer( 3, 0, 0 );
308 
309  wxStaticText *item2 = new wxStaticText( parent, ID_TEXT, wxT("Name:"), wxDefaultPosition, wxDefaultSize, 0 );
310  item1->Add( item2, 0, wxALIGN_RIGHT|wxALL, 5 );
311 
312  wxTextCtrl *item3 = new wxTextCtrl( parent, ID_NAME, wxT(""), wxDefaultPosition, wxSize(300,-1), 0 );
313  item1->Add( item3, 0, wxALIGN_CENTER|wxALL, 5 );
314 
315  item1->Add( 20, 20, 0, wxALIGN_CENTER|wxALL, 5 );
316 
317  wxStaticText *item4 = new wxStaticText( parent, ID_TEXT, wxT("Plugin file path:"), wxDefaultPosition, wxDefaultSize, 0 );
318  item1->Add( item4, 0, wxALIGN_RIGHT|wxALL, 5 );
319 
320  wxTextCtrl *item5 = new wxTextCtrl( parent, ID_PATH, wxT(""), wxDefaultPosition, wxSize(80,-1), 0 );
321  item1->Add( item5, 0, wxGROW|wxALL, 5 );
322 
323  wxButton *item6 = new wxButton( parent, ID_BROWSE, wxT("Browse..."), wxDefaultPosition, wxDefaultSize, 0 );
324  item1->Add( item6, 0, wxALIGN_CENTER|wxALL, 5 );
325 
326  wxStaticText *item7 = new wxStaticText( parent, ID_TEXT, wxT("Plugin type:"), wxDefaultPosition, wxDefaultSize, 0 );
327  item1->Add( item7, 0, wxALIGN_RIGHT|wxALL, 5 );
328 
329  wxString *strs8 = (wxString*) NULL;
330  wxChoice *item8 = new wxChoice( parent, ID_TYPE, wxDefaultPosition, wxSize(100,-1), 0, strs8, 0 );
331  item1->Add( item8, 0, wxGROW|wxALL, 5 );
332 
333  item1->Add( 20, 20, 0, wxALIGN_CENTER|wxALL, 5 );
334 
335  wxStaticText *item9 = new wxStaticText( parent, ID_TEXT, wxT("Description:"), wxDefaultPosition, wxDefaultSize, 0 );
336  item1->Add( item9, 0, wxALIGN_RIGHT|wxALL, 5 );
337 
338  wxTextCtrl *item10 = new wxTextCtrl( parent, ID_DESCRIPTION, wxT(""), wxDefaultPosition, wxSize(200,60), wxTE_MULTILINE );
339  item1->Add( item10, 0, wxGROW|wxALL, 5 );
340 
341  item0->Add( item1, 0, wxGROW|wxALL, 5 );
342 
343  wxStaticBox *item12 = new wxStaticBox( parent, -1, wxT("Plugin data:") );
344  wxStaticBoxSizer *item11 = new wxStaticBoxSizer( item12, wxVERTICAL );
345 
346  wxListCtrl *item13 = new wxListCtrl( parent, ID_LIST, wxDefaultPosition, wxSize(500,300), wxLC_REPORT|wxSUNKEN_BORDER );
347  item11->Add( item13, 0, wxGROW|wxALL, 5 );
348 
349  item0->Add( item11, 0, wxGROW|wxALL, 5 );
350 
351  wxBoxSizer *item14 = new wxBoxSizer( wxHORIZONTAL );
352 
353  wxButton *item15 = new wxButton( parent, ID_ADD, wxT("Add..."), wxDefaultPosition, wxDefaultSize, 0 );
354  item14->Add( item15, 0, wxALIGN_CENTER|wxALL, 5 );
355 
356  wxButton *item16 = new wxButton( parent, ID_MODIFY, wxT("Modify..."), wxDefaultPosition, wxDefaultSize, 0 );
357  item14->Add( item16, 0, wxALIGN_CENTER|wxALL, 5 );
358 
359  wxButton *item17 = new wxButton( parent, ID_DELETE, wxT("Delete"), wxDefaultPosition, wxDefaultSize, 0 );
360  item14->Add( item17, 0, wxALIGN_CENTER|wxALL, 5 );
361 
362  item0->Add( item14, 0, wxALIGN_CENTER, 5 );
363 
364  wxStaticLine *item18 = new wxStaticLine( parent, ID_LINE, wxDefaultPosition, wxSize(20,-1), wxLI_HORIZONTAL );
365  item0->Add( item18, 0, wxGROW|wxALL, 5 );
366 
367  wxBoxSizer *item19 = new wxBoxSizer( wxHORIZONTAL );
368 
369  wxButton *item20 = new wxButton( parent, wxID_CANCEL, wxT("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
370  item19->Add( item20, 0, wxALIGN_CENTER|wxALL, 5 );
371 
372  wxButton *item21 = new wxButton( parent, wxID_OK, wxT("&OK"), wxDefaultPosition, wxDefaultSize, 0 );
373  item19->Add( item21, 0, wxALL, 5 );
374 
375  item0->Add( item19, 0, 0, 5 );
376 
377  if (set_sizer)
378  {
379  parent->SetSizer( item0 );
380  if (call_fit)
381  item0->SetSizeHints( parent );
382  }
383 
384  return item0;
385 }
CostEstimationData::rfReference
RowID rfReference() const
Definition: CostEstimationData.cc:118
CostFunctionPluginDialog::onOK
void onOK(wxCommandEvent &event)
Definition: CostFunctionPluginDialog.cc:264
WxConversion::toWxString
static wxString toWxString(const std::string &source)
HDB::CostFunctionPlugin::CostFunctionPluginType
CostFunctionPluginType
all supported cost function plugin types
Definition: CostFunctionPlugin.hh:46
CostEstimationData::name
std::string name() const
Definition: CostEstimationData.cc:58
HDB
Definition: CostDatabase.hh:49
FU
const string FU
Definition: IDFSerializer.cc:64
HDB::CostFunctionPlugin::description
std::string description() const
Definition: CostFunctionPlugin.cc:74
DataObject::stringValue
virtual std::string stringValue() const
Definition: DataObject.cc:344
CostFunctionPluginDialog.hh
CostEstimationData::hasSocketReference
bool hasSocketReference() const
HDB::CostFunctionPlugin::COST_DECOMP
@ COST_DECOMP
decompressor cost estimator
Definition: CostFunctionPlugin.hh:49
CostFunctionPluginDialog::createContents
wxSizer * createContents(wxWindow *parent, bool call_fit, bool set_sizer)
Definition: CostFunctionPluginDialog.cc:302
CostEstimationData::hasFUReference
bool hasFUReference() const
FindWindow
Definition: FindWindow.hh:49
CostFunctionPluginDialog::selectedData
int selectedData()
Definition: CostFunctionPluginDialog.cc:180
CostEstimationDataDialog
Definition: CostEstimationDataDialog.hh:46
HDB::CostFunctionPlugin::COST_FU
@ COST_FU
function unit cost estimator
Definition: CostFunctionPlugin.hh:47
assert
#define assert(condition)
Definition: Application.hh:86
CostFunctionPluginDialog
Definition: CostFunctionPluginDialog.hh:46
HDB::CostFunctionPlugin::COST_ICDEC
@ COST_ICDEC
interconnection network & decoder cost estimator
Definition: CostFunctionPlugin.hh:50
CostEstimationData::busReference
RowID busReference() const
Definition: CostEstimationData.cc:133
ErrorDialog
Definition: ErrorDialog.hh:42
ErrorDialog.hh
CostFunctionPluginDialog::onDelete
void onDelete(wxCommandEvent &event)
Definition: CostFunctionPluginDialog.cc:251
HDB::HDBManager
Definition: HDBManager.hh:82
CostFunctionPluginDialog::onAdd
void onAdd(wxCommandEvent &event)
Definition: CostFunctionPluginDialog.cc:224
CostEstimationData::socketReference
RowID socketReference() const
Definition: CostEstimationData.cc:148
CostFunctionPluginDialog::onBrowse
void onBrowse(wxCommandEvent &event)
Definition: CostFunctionPluginDialog.cc:210
CostEstimationDataDialog.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
CostEstimationData
Definition: CostEstimationData.hh:42
CostEstimationData::value
DataObject value() const
Definition: CostEstimationData.cc:73
HDB::CostFunctionPlugin::COST_RF
@ COST_RF
register file cost estimator
Definition: CostFunctionPlugin.hh:48
CostEstimationData::hasBusReference
bool hasBusReference() const
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
CostFunctionPluginDialog::onDataSelection
void onDataSelection(wxListEvent &event)
Definition: CostFunctionPluginDialog.cc:196
CostEstimationData::fuReference
RowID fuReference() const
Definition: CostEstimationData.cc:103
HDB::CostFunctionPlugin::pluginFilePath
std::string pluginFilePath() const
Definition: CostFunctionPlugin.cc:94
CostFunctionPluginDialog::onModify
void onModify(wxCommandEvent &event)
Definition: CostFunctionPluginDialog.cc:237
CostEstimationData::hasRFReference
bool hasRFReference() const
CostFunctionPluginDialog::TransferDataToWindow
virtual bool TransferDataToWindow()
Definition: CostFunctionPluginDialog.cc:135
CostFunctionPlugin.hh
WxConversion.hh
HDB::CostFunctionPlugin::type
CostFunctionPluginType type() const
Definition: CostFunctionPlugin.cc:104
HDBManager.hh
WxConversion::toString
static std::string toString(const wxString &source)
HDB::CostFunctionPlugin::name
std::string name() const
Definition: CostFunctionPlugin.cc:84
HDB::CostFunctionPlugin
Definition: CostFunctionPlugin.hh:43
END_EVENT_TABLE
END_EVENT_TABLE() using namespace IDF
ContainerTools.hh
CostFunctionPluginDialog::~CostFunctionPluginDialog
virtual ~CostFunctionPluginDialog()
Definition: CostFunctionPluginDialog.cc:128