OpenASIP 2.2
Loading...
Searching...
No Matches
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"
56#include "Model.hh"
57#include "MDFDocument.hh"
58#include "Machine.hh"
59
60using boost::format;
61using std::string;
62using namespace TTAMachine;
63
64BEGIN_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 */
137
138
139/**
140 * Sets texts for widgets.
141 */
142void
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);
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 */
178bool
180
181 return wxWindow::TransferDataToWindow();
182}
183
184
185/**
186 * Validates input in the controls, and updates the AddressSpace.
187 */
188void
190 EndModal(wxID_CANCEL);
191}
192
193/**
194 * Editing selected parameter
195 */
196void
198 doEdit();
199}
200
201
202/**
203 * Runs the plugin
204 */
205void
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?
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());
232 } catch (KeyNotFound& e) {
233 // no new adf created by the plugin. just exit
236 diag.ShowModal();
238 EndModal(wxID_CANCEL);
239 return;
240 } catch (Exception& e) {
241 // error in parameters
244 diag.ShowModal();
246 return;
247 }
248
250 EndModal(wxID_OK);
251}
252
253
254/**
255 * Parameter was doubleclicked
256 */
257void
259 selectedParam_ = event.GetIndex();
260 doEdit();
261}
262
263/**
264 * Parameter was selected
265 */
266void
268 selectedParam_ = event.GetIndex();
269}
270
271/**
272 * Parameter was deselected
273 */
274void
278
279
280/**
281 * A plugin was selected
282 */
283void
285
286 string pluginName =
288
289 // get current plugin
290 for (size_t i = 0; i < plugins_.size(); i++) {
291 if (plugins_.at(i)->name() == pluginName) {
293 break;
294 }
295 }
296
297 // set description field
298 pluginDescription_->Clear();
301
303}
304
305
306/**
307 * Starts parameter editor
308 */
309void
311 if (selectedParam_ == -1) {
312 return;
313 }
314
316 EditParameterDialog diag(this, &param);
317 diag.ShowModal();
318 selectedPlugin_->giveParameter(param.name(), param.value());
320}
321
322
323/**
324 * Updates parameter list
325 */
326void
328
329 parameterList_->DeleteAllItems();
330
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 */
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 */
379wxSizer*
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
END_EVENT_TABLE() using namespace IDF
int RowID
Type definition of row ID in relational databases.
Definition DBTypes.hh:37
#define ILLEGAL_ROW_ID
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
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
EVT_BUTTON(ID_EDIT_ARCH_PORT, FUImplementationDialog::onEditArchitecturePort) EVT_BUTTON(ID_ADD_EXTERNAL_PORT
#define INT(OPERAND)
Definition OSAL.hh:312
void onEdit(wxCommandEvent &)
wxSizer * createContents(wxWindow *parent, bool call_fit, bool set_sizer)
void onParamDeSelect(wxListEvent &event)
void onParamSelect(wxListEvent &event)
void onParamActivate(wxListEvent &event)
wxComboBox * pluginNames_
Plugin names combo box.
void onClose(wxCommandEvent &event)
wxTextCtrl * pluginDescription_
description text field
DesignSpaceExplorerPlugin * selectedPlugin_
std::vector< DesignSpaceExplorerPlugin * > plugins_
ExplorerPluginParameter getParam(int paramNum)
void onRun(wxCommandEvent &event)
TTAMachine::Machine & machine_
Machine that is being modified.
void onSelectPlugin(wxCommandEvent &event)
int selectedParam_
Selected parameter, or -1.
wxListCtrl * parameterList_
Parameter list;.
RowID addArchitecture(const TTAMachine::Machine &mom)
TTAMachine::Machine * architecture(RowID id) const
static DSDBManager * createNew(const std::string &file)
RowID addConfiguration(const MachineConfiguration &conf)
virtual std::string description() const
virtual bool requiresHDB() const =0
virtual bool requiresSimulationData() const =0
virtual std::string name() const
virtual bool producesArchitecture() const =0
std::map< std::string, ExplorerPluginParameter > ParameterMap
virtual std::vector< RowID > explore(const RowID &startPointConfigurationID, const unsigned int &maxIter=0)
virtual void giveParameter(const std::string &name, const std::string &value)
virtual void setDSDB(DSDBManager &dsdb)
std::string errorMessage() const
Definition Exception.cc:123
static bool removeFileOrDirectory(const std::string &path)
Definition Model.hh:50
TTAMachine::Machine * getMachine()
Definition Model.cc:88
static ProDeTextGenerator * instance()
@ TXT_COLUMN_TYPE
Label for type column in a list.
@ TXT_CALL_EXPLORER_PLUGIN_TITLE
Call Explorer plugin title.
@ TXT_COLUMN_NAME
Label for name column in a list.
@ TXT_COLUMN_VALUE
Label for value column in a list.
virtual void copyFromMachine(Machine &machine)
Definition Machine.cc:884
virtual boost::format text(int textId)
static wxString toWxString(const std::string &source)
static std::string toString(const wxString &source)