OpenASIP  2.0
CallExplorerPlugin.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 CallExplorerPluginWindow.cc
26  *
27  * Definition of CallExplorerPluginWindow class.
28  *
29  * @author Viljami Korhonen 2008 (viljami.korhonen-no.spam-.tut.fi)
30  * @note rating: red
31  */
32 
33 #include <string>
34 #include <wx/statline.h>
35 #include <wx/valgen.h>
36 #include <wx/spinctrl.h>
37 #include <boost/format.hpp>
38 #include <wx/wx.h>
39 #include <wx/docview.h>
40 
41 #include "CallExplorerPlugin.hh"
42 #include "Conversion.hh"
43 #include "WxConversion.hh"
44 #include "WarningDialog.hh"
45 #include "AddressSpace.hh"
46 #include "ModelConstants.hh"
47 #include "NumberControl.hh"
48 #include "InformationDialog.hh"
49 #include "MachineTester.hh"
50 #include "GUITextGenerator.hh"
51 #include "WidgetTools.hh"
52 #include "ProDeTextGenerator.hh"
53 #include "DesignSpaceExplorer.hh"
55 #include "EditParameterDialog.hh"
56 #include "Model.hh"
57 #include "MDFDocument.hh"
58 #include "Machine.hh"
59 
60 using boost::format;
61 using std::string;
62 using namespace TTAMachine;
63 
64 BEGIN_EVENT_TABLE(CallExplorerPluginWindow, wxDialog)
69  EVT_COMBOBOX(ID_PLUGIN_CHOOSER, CallExplorerPluginWindow::onSelectPlugin)
73 
74 
75 /**
76  * The Constructor.
77  *
78  * @param parent Parent window of the dialog.
79  * @param addressSpace The address space to be modified with the dialog.
80  */
82  wxWindow* parent,
84  Model& model):
85  wxDialog(parent, -1, _T(""), wxDefaultPosition), machine_(machine),
86  model_(model),
87  selectedParam_(-1),
88  selectedPlugin_(0) {
89 
90  createContents(this, true, true);
91 
92  pluginNames_ =
93  dynamic_cast<wxComboBox*>(FindWindow(ID_PLUGIN_CHOOSER));
94 
95  pluginDescription_ =
96  dynamic_cast<wxTextCtrl*>(FindWindow(ID_DESCRIPTION_FIELD));
97 
98  parameterList_ =
99  dynamic_cast<wxListCtrl*>(FindWindow(ID_PARAM_LIST));
100 
101  editButton =
102  dynamic_cast<wxButton*>(FindWindow(ID_EDIT));
103 
104  runButton =
105  dynamic_cast<wxButton*>(FindWindow(ID_RUN));
106 
107  // Get explorer plugin names.
108  std::vector<DesignSpaceExplorerPlugin*> plugins = explorer_.getPlugins();
109  std::set<string> addedPlugins;
110 
111  for (std::size_t i = 0; i < plugins.size(); i++) {
112  DesignSpaceExplorerPlugin *plugin = plugins[i];
113 
114  if (plugin->producesArchitecture() &&
115  !plugin->requiresHDB() &&
116  !plugin->requiresSimulationData() &&
117  addedPlugins.find(plugin->name()) == addedPlugins.end()) {
118 
119  plugins_.push_back(plugin);
120  addedPlugins.insert(plugin->name());
121  }
122 
123  }
124 
125  // set widget texts
126  setTexts();
127 
128  TransferDataToWindow();
129 }
130 
131 
132 /**
133  * The Destructor.
134  */
136 }
137 
138 
139 /**
140  * Sets texts for widgets.
141  */
142 void
145 
146  // Dialog title
147  format fmt = prodeTexts->text(
149  SetTitle(WxConversion::toWxString(fmt.str()));
150 
151  // Get explorer plugin names into combo box
152  for (size_t i = 0; i < plugins_.size(); ++i) {
153  wxString pluginName = WxConversion::toWxString(plugins_.at(i)->name());
154  pluginNames_->Append(pluginName);
155  }
156 
157  // Set parameter list column titles
158  fmt = prodeTexts->text(ProDeTextGenerator::TXT_COLUMN_NAME);
159  parameterList_->InsertColumn(0, WxConversion::toWxString(fmt.str()),
160  wxLIST_FORMAT_CENTER, 160);
161  //fmt = prodeTexts->text(ProDeTextGenerator::TXT_COLUMN_COMPULSORY);
162  //parameterList_->InsertColumn(1, WxConversion::toWxString(fmt.str()),
163  // wxLIST_FORMAT_LEFT, 100);
164  fmt = prodeTexts->text(ProDeTextGenerator::TXT_COLUMN_TYPE);
165  parameterList_->InsertColumn(2, WxConversion::toWxString(fmt.str()),
166  wxLIST_FORMAT_LEFT, 100);
167  fmt = prodeTexts->text(ProDeTextGenerator::TXT_COLUMN_VALUE);
168  parameterList_->InsertColumn(3, WxConversion::toWxString(fmt.str()),
169  wxLIST_FORMAT_LEFT, 160);
170 }
171 
172 
173 /**
174  * Transfers data from the AddressSpace object to the dialog widgets.
175  *
176  * @return false, if an error occured in the transfer, true otherwise.
177  */
178 bool
180 
181  return wxWindow::TransferDataToWindow();
182 }
183 
184 
185 /**
186  * Validates input in the controls, and updates the AddressSpace.
187  */
188 void
190  EndModal(wxID_CANCEL);
191 }
192 
193 /**
194  * Editing selected parameter
195  */
196 void
198  doEdit();
199 }
200 
201 
202 /**
203  * Runs the plugin
204  */
205 void
207 
208  // no plugin selected?
209  if (selectedPlugin_ == 0) {
210  return;
211  }
212 
213  // open up a temporary dsdb
214  const string dsdbFile = "tmp.dsdb";
216  DSDBManager* dsdb = DSDBManager::createNew(dsdbFile);
217  RowID archID = dsdb->addArchitecture(machine_);
218 
219  // no implementation?
220  DSDBManager::MachineConfiguration confIn(archID, false, ILLEGAL_ROW_ID);
221  RowID confID = dsdb->addConfiguration(confIn);
222 
223  // run the plugin
224  try {
225  selectedPlugin_->setDSDB(*dsdb);
226  std::vector<RowID> result = selectedPlugin_->explore(confID, 0);
227 
228  // store the new machine
230  *dsdb->architecture(confID+result.size());
231  model_.getMachine()->copyFromMachine(machine);
232  } catch (KeyNotFound& e) {
233  // no new adf created by the plugin. just exit
234  InformationDialog diag(
236  diag.ShowModal();
238  EndModal(wxID_CANCEL);
239  return;
240  } catch (Exception& e) {
241  // error in parameters
242  InformationDialog diag(
244  diag.ShowModal();
246  return;
247  }
248 
250  EndModal(wxID_OK);
251 }
252 
253 
254 /**
255  * Parameter was doubleclicked
256  */
257 void
259  selectedParam_ = event.GetIndex();
260  doEdit();
261 }
262 
263 /**
264  * Parameter was selected
265  */
266 void
268  selectedParam_ = event.GetIndex();
269 }
270 
271 /**
272  * Parameter was deselected
273  */
274 void
276  selectedParam_ = -1;
277 }
278 
279 
280 /**
281  * A plugin was selected
282  */
283 void
285 
286  string pluginName =
287  WxConversion::toString(pluginNames_->GetValue());
288 
289  // get current plugin
290  for (size_t i = 0; i < plugins_.size(); i++) {
291  if (plugins_.at(i)->name() == pluginName) {
292  selectedPlugin_ = plugins_.at(i);
293  break;
294  }
295  }
296 
297  // set description field
298  pluginDescription_->Clear();
299  pluginDescription_->AppendText(WxConversion::toWxString(
300  selectedPlugin_->description()));
301 
302  updateParameterList();
303 }
304 
305 
306 /**
307  * Starts parameter editor
308  */
309 void
311  if (selectedParam_ == -1) {
312  return;
313  }
314 
315  ExplorerPluginParameter param = getParam(selectedParam_);
316  EditParameterDialog diag(this, &param);
317  diag.ShowModal();
318  selectedPlugin_->giveParameter(param.name(), param.value());
319  updateParameterList();
320 }
321 
322 
323 /**
324  * Updates parameter list
325  */
326 void
328 
329  parameterList_->DeleteAllItems();
330 
331  DesignSpaceExplorerPlugin::ParameterMap params = selectedPlugin_->parameters();
332  DesignSpaceExplorerPlugin::ParameterMap::iterator it = params.begin();
333 
334  for (int i =0; it != params.end(); ++it, ++i) {
335  ExplorerPluginParameter parameter = it->second;
336 
337  string name = parameter.name();
338  string type = parameter.typeAsString();
339  string value = parameter.value();
340  //string compulsory = parameter.isCompulsory() ? "x" : "";
341 
342  parameterList_->InsertItem(i, WxConversion::toWxString(name), 0);
343  //parameterList_->SetItem(i, 1, WxConversion::toWxString(compulsory));
344  parameterList_->SetItem(i, 1, WxConversion::toWxString(type));
345  parameterList_->SetItem(i, 2, WxConversion::toWxString(value));
346  }
347 }
348 
349 
350 /**
351  * Gets param from param index
352  */
355  DesignSpaceExplorerPlugin::ParameterMap params = selectedPlugin_->parameters();
356  DesignSpaceExplorerPlugin::ParameterMap::iterator it = params.begin();
357 
358  for (int i =0; it != params.end(); ++it, ++i) {
359  if (i == paramNum) {
360  return it->second;
361  }
362  }
363 
364  return ExplorerPluginParameter("", INT, false, "");
365 }
366 
367 
368 /**
369  * Creates the dialog window contents.
370  *
371  * This method was generated with wxDesigner, thus the ugly code and
372  * too long lines.
373  *
374  * @return Main sizer of the created contents.
375  * @param parent The dialog window.
376  * @param call_fit If true, fits the contents inside the dialog.
377  * @param set_sizer If true, sets the main sizer as dialog contents.
378  */
379 wxSizer*
381  wxWindow* parent,
382  bool call_fit,
383  bool set_sizer) {
384 
385  wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL );
386 
387  wxFlexGridSizer *item1 = new wxFlexGridSizer( 2, 0, 0 );
388  item1->AddGrowableCol( 1 );
389 
390  wxStaticText *item2 = new wxStaticText( parent, ID_TEXT, wxT("Explorer Plugin:"), wxDefaultPosition, wxDefaultSize, 0 );
391  item1->Add( item2, 0, wxFIXED_MINSIZE|wxALL, 5 );
392 
393  wxString *strs3 = (wxString*) NULL;
394  wxComboBox *item3 = new wxComboBox( parent, ID_PLUGIN_CHOOSER, wxT(""), wxDefaultPosition, wxDefaultSize, 0, strs3, wxCB_DROPDOWN );
395  item1->Add( item3, 0, wxGROW|wxALL, 5 );
396 
397  wxStaticText *item4 = new wxStaticText( parent, ID_TEXT, wxT("Plugin Description:"), wxDefaultPosition, wxDefaultSize, 0 );
398  item1->Add( item4, 0, wxFIXED_MINSIZE|wxALL, 5 );
399 
400  wxTextCtrl *item5 = new wxTextCtrl( parent, ID_DESCRIPTION_FIELD, wxT(""), wxDefaultPosition, wxSize(240,150), wxTE_MULTILINE|wxTE_READONLY );
401  item1->Add( item5, 0, wxGROW|wxALL, 5 );
402 
403  item0->Add( item1, 0, wxGROW|wxALL, 5 );
404 
405  wxStaticText *item6 = new wxStaticText( parent, ID_TEXT, wxT("Plugin Parameters:"), wxDefaultPosition, wxDefaultSize, 0 );
406  item0->Add( item6, 0, wxALL, 5 );
407 
408  wxListCtrl *item7 = new wxListCtrl( parent, ID_PARAM_LIST, wxDefaultPosition, wxSize(400,200), wxLC_REPORT|wxSUNKEN_BORDER );
409  item0->Add( item7, 0, wxALIGN_CENTER|wxALL, 5 );
410 
411  wxGridSizer *item8 = new wxGridSizer( 3, 0, 0 );
412 
413  item0->Add( item8, 0, wxGROW, 5 );
414 
415  wxGridSizer *item9 = new wxGridSizer( 3, 0, 0 );
416 
417  wxButton *item10 = new wxButton( parent, ID_EDIT, wxT("&Edit Parameter..."), wxDefaultPosition, wxDefaultSize, 0 );
418  item9->Add( item10, 0, wxALL, 5 );
419 
420  wxButton *item11 = new wxButton( parent, ID_RUN, wxT("&Run Plugin"), wxDefaultPosition, wxDefaultSize, 0 );
421  item9->Add( item11, 0, wxALIGN_RIGHT|wxALL, 5 );
422 
423  wxBoxSizer *item12 = new wxBoxSizer( wxHORIZONTAL );
424 
425  wxButton *item13 = new wxButton( parent, wxID_CLOSE, wxT("&Close"), wxDefaultPosition, wxDefaultSize, 0 );
426  item12->Add( item13, 0, wxALIGN_CENTER|wxALL, 5 );
427 
428  item9->Add( item12, 0, wxALL, 5 );
429 
430  item0->Add( item9, 0, wxGROW, 5 );
431 
432  if (set_sizer)
433  {
434  parent->SetSizer( item0 );
435  if (call_fit)
436  item0->SetSizeHints( parent );
437  }
438 
439  return item0;
440 }
441 
442 
ILLEGAL_ROW_ID
#define ILLEGAL_ROW_ID
Definition: DSDBManager.hh:58
CallExplorerPluginWindow::createContents
wxSizer * createContents(wxWindow *parent, bool call_fit, bool set_sizer)
Definition: CallExplorerPlugin.cc:380
EditParameterDialog.hh
WxConversion::toWxString
static wxString toWxString(const std::string &source)
FileSystem::removeFileOrDirectory
static bool removeFileOrDirectory(const std::string &path)
Definition: FileSystem.cc:493
EVT_LIST_ITEM_ACTIVATED
FUImplementationDialog::onAddExternalPort FUImplementationDialog::onDeleteExternalPort FUImplementationDialog::onArchPortSelection FUImplementationDialog::onArchPortActivation FUImplementationDialog::onExternalPortActivation FUImplementationDialog::onParameterSelection EVT_LIST_ITEM_ACTIVATED(ID_PARAMETER_LIST, FUImplementationDialog::onParameterActivation) EVT_LIST_ITEM_DESELECTED(ID_PARAMETER_LIST
MDFDocument.hh
machine
TTAMachine::Machine * machine
the architecture definition of the estimated processor
Definition: EstimatorCmdLineUI.cc:59
CallExplorerPluginWindow::onRun
void onRun(wxCommandEvent &event)
Definition: CallExplorerPlugin.cc:206
DSDBManager::architecture
TTAMachine::Machine * architecture(RowID id) const
Definition: DSDBManager.cc:807
CallExplorerPluginWindow::onParamSelect
void onParamSelect(wxListEvent &event)
Definition: CallExplorerPlugin.cc:267
AddressSpace.hh
DesignSpaceExplorerPlugin
Definition: DesignSpaceExplorerPlugin.hh:55
RowID
int RowID
Type definition of row ID in relational databases.
Definition: DBTypes.hh:37
ExplorerPluginParameter::typeAsString
TCEString typeAsString() const
Definition: ExplorerPluginParameter.cc:108
CallExplorerPluginWindow::onClose
void onClose(wxCommandEvent &event)
Definition: CallExplorerPlugin.cc:189
WidgetTools.hh
FindWindow
Definition: FindWindow.hh:49
CallExplorerPluginWindow::getParam
ExplorerPluginParameter getParam(int paramNum)
Definition: CallExplorerPlugin.cc:354
ExplorerPluginParameter::name
TCEString name() const
Definition: ExplorerPluginParameter.cc:86
CallExplorerPluginWindow::TransferDataToWindow
virtual bool TransferDataToWindow()
Definition: CallExplorerPlugin.cc:179
Texts::TextGenerator::text
virtual boost::format text(int textId)
Definition: TextGenerator.cc:94
CallExplorerPlugin.hh
ProDeTextGenerator.hh
DesignSpaceExplorerPlugin.hh
ProDeTextGenerator
Definition: ProDeTextGenerator.hh:49
ExplorerPluginParameter::value
TCEString value() const
Definition: ExplorerPluginParameter.cc:63
ProDeTextGenerator::TXT_CALL_EXPLORER_PLUGIN_TITLE
@ TXT_CALL_EXPLORER_PLUGIN_TITLE
Call Explorer plugin title.
Definition: ProDeTextGenerator.hh:212
ProDeTextGenerator::TXT_COLUMN_TYPE
@ TXT_COLUMN_TYPE
Label for type column in a list.
Definition: ProDeTextGenerator.hh:108
DSDBManager::MachineConfiguration
Definition: DSDBManager.hh:78
WarningDialog.hh
NumberControl.hh
ExplorerPluginParameter
Definition: ExplorerPluginParameter.hh:46
Conversion.hh
InformationDialog.hh
CallExplorerPluginWindow::updateParameterList
void updateParameterList()
Definition: CallExplorerPlugin.cc:327
Model.hh
CallExplorerPluginWindow
Definition: CallExplorerPlugin.hh:52
CallExplorerPluginWindow::onParamActivate
void onParamActivate(wxListEvent &event)
Definition: CallExplorerPlugin.cc:258
DesignSpaceExplorerPlugin::requiresHDB
virtual bool requiresHDB() const =0
ModelConstants.hh
CallExplorerPluginWindow::setTexts
void setTexts()
Definition: CallExplorerPlugin.cc:143
Machine.hh
Exception
Definition: Exception.hh:54
DSDBManager
Definition: DSDBManager.hh:76
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
EditParameterDialog
Definition: EditParameterDialog.hh:49
Exception::errorMessage
std::string errorMessage() const
Definition: Exception.cc:123
INT
@ INT
Definition: ExplorerPluginParameter.hh:40
GUITextGenerator.hh
DSDBManager::addConfiguration
RowID addConfiguration(const MachineConfiguration &conf)
Definition: DSDBManager.cc:299
CallExplorerPluginWindow::doEdit
void doEdit()
Definition: CallExplorerPlugin.cc:310
MachineTester.hh
DSDBManager::addArchitecture
RowID addArchitecture(const TTAMachine::Machine &mom)
Definition: DSDBManager.cc:191
ProDeTextGenerator::instance
static ProDeTextGenerator * instance()
Definition: ProDeTextGenerator.cc:382
DSDBManager::createNew
static DSDBManager * createNew(const std::string &file)
Definition: DSDBManager.cc:141
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
Model
Definition: Model.hh:50
DesignSpaceExplorer.hh
DesignSpaceExplorerPlugin::producesArchitecture
virtual bool producesArchitecture() const =0
CallExplorerPluginWindow::onParamDeSelect
void onParamDeSelect(wxListEvent &event)
Definition: CallExplorerPlugin.cc:275
CallExplorerPluginWindow::onEdit
void onEdit(wxCommandEvent &)
Definition: CallExplorerPlugin.cc:197
TTAMachine::Machine::copyFromMachine
virtual void copyFromMachine(Machine &machine)
Definition: Machine.cc:890
DesignSpaceExplorerPlugin::name
virtual std::string name() const
Definition: DesignSpaceExplorerPlugin.cc:77
DesignSpaceExplorerPlugin::ParameterMap
std::map< std::string, ExplorerPluginParameter > ParameterMap
Definition: DesignSpaceExplorerPlugin.hh:69
WxConversion.hh
KeyNotFound
Definition: Exception.hh:285
InformationDialog
Definition: InformationDialog.hh:42
TTAMachine
Definition: Assembler.hh:48
WxConversion::toString
static std::string toString(const wxString &source)
ProDeTextGenerator::TXT_COLUMN_NAME
@ TXT_COLUMN_NAME
Label for name column in a list.
Definition: ProDeTextGenerator.hh:105
CallExplorerPluginWindow::~CallExplorerPluginWindow
virtual ~CallExplorerPluginWindow()
Definition: CallExplorerPlugin.cc:135
DesignSpaceExplorerPlugin::requiresSimulationData
virtual bool requiresSimulationData() const =0
END_EVENT_TABLE
END_EVENT_TABLE() using namespace IDF
TTAMachine::Machine
Definition: Machine.hh:73
ProDeTextGenerator::TXT_COLUMN_VALUE
@ TXT_COLUMN_VALUE
Label for value column in a list.
Definition: ProDeTextGenerator.hh:107
CallExplorerPluginWindow::onSelectPlugin
void onSelectPlugin(wxCommandEvent &event)
Definition: CallExplorerPlugin.cc:284