OpenASIP  2.0
OperationImplementationDialog.cc
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2017 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 OperationImplementationDialog.cc
26 *
27 *Implementation of OperationImplementationDialog.
28 *
29 *@author Lasse Lehtonen 2017 (lasse.lehtonen-no.spam-tut.fi)
30 */
31 
34 #include "HDBBrowserWindow.hh"
35 #include "HDBEditor.hh"
36 #include "HDBManager.hh"
38 #include "VariableDialog.hh"
39 
40 wxDEFINE_EVENT(BUTTON_MODEL_VHDL, wxFileDirPickerEvent);
41 wxDEFINE_EVENT(BUTTON_MODEL_VERILOG, wxFileDirPickerEvent);
42 wxDEFINE_EVENT(BUTTON_POSTMODEL_VHDL, wxFileDirPickerEvent);
43 wxDEFINE_EVENT(BUTTON_POSTMODEL_VERILOG, wxFileDirPickerEvent);
44 wxDEFINE_EVENT(BUTTON_INITIAL_VHDL, wxFileDirPickerEvent);
45 wxDEFINE_EVENT(BUTTON_INITIAL_VERILOG, wxFileDirPickerEvent);
46 wxDEFINE_EVENT(BUTTON_IPXACT_ABSDEF, wxFileDirPickerEvent);
47 wxDEFINE_EVENT(BUTTON_ADD_VHDL_VAR, wxCommandEvent);
48 wxDEFINE_EVENT(BUTTON_ADD_VERILOG_VAR, wxCommandEvent);
49 
50 BEGIN_EVENT_TABLE(OperationImplementationDialog, wxDialog)
60 EVT_BUTTON(BUTTON_ADD_VERILOG_VAR,
63 
64 /// Constructor
66  : wxDialog(NULL, -1, "Add Operation Implementation", wxDefaultPosition,
67  wxSize(700, 900), wxRESIZE_BORDER) {
68  wxBoxSizer* vbox = new wxBoxSizer(wxVERTICAL);
69  wxBoxSizer* hbox1 = new wxBoxSizer(wxHORIZONTAL);
70 
71  wxButton* okButton = new wxButton(
72  this, wxID_OK, wxT("Ok"), wxDefaultPosition, wxSize(70, 30));
73  wxButton* closeButton = new wxButton(
74  this, wxID_CANCEL, wxT("Cancel"), wxDefaultPosition, wxSize(70, 30));
75 
76  wxButton* addVHDLVariableButton =
77  new wxButton(this, BUTTON_ADD_VHDL_VAR, wxT("Add"));
78  wxButton* addVerilogVariableButton =
79  new wxButton(this, BUTTON_ADD_VERILOG_VAR, wxT("Add"));
80 
81  wxButton* addButton = new wxButton(this, wxID_ADD, wxT(""));
82  wxButton* delButton = new wxButton(this, wxID_DELETE, wxT(""));
83 
84  hbox1->Add(okButton, 1);
85  hbox1->Add(closeButton, 1, wxLEFT, 5);
86 
87  wxFlexGridSizer* flex1 = new wxFlexGridSizer(13, 2, 9, 25);
88 
89  wxStaticText* title1 = new wxStaticText(this, -1, wxT("Name"));
90  wxStaticText* title2 =
91  new wxStaticText(this, -1, wxT("VHDL Op Implementation file"));
92  wxStaticText* title3 =
93  new wxStaticText(this, -1, wxT("Verilog Op Implementation file"));
94  wxStaticText* title21 =
95  new wxStaticText(this, -1, wxT("VHDL Post-Op Implementation file"));
96  wxStaticText* title31 =
97  new wxStaticText(this, -1, wxT("Verilog Post-Op Implementation file"));
98  wxStaticText* title_vhdl_init =
99  new wxStaticText(this, -1, wxT("VHDL Initial Implementation file"));
100  wxStaticText* title_vlog_init =
101  new wxStaticText(this, -1, wxT("Verilog Initial Implementation file"));
102  wxStaticText* title41 =
103  new wxStaticText(this, -1, wxT("Optional IPXACT bus definition file"));
104  wxStaticText* title4 =
105  new wxStaticText(this, -1, wxT("Selected resources"));
106  wxStaticText* title5 =
107  new wxStaticText(this, -1, wxT("Selected resources"));
108  wxStaticText* title6 =
109  new wxStaticText(this, -1, wxT("Add VHDL Variable"));
110  wxStaticText* title7 =
111  new wxStaticText(this, -1, wxT("Add Verilog Variable"));
112  wxStaticText* title_latency = new wxStaticText(this, -1, wxT("Latency"));
113 
114  nameCtrl_ = new wxTextCtrl(this, -1);
115 
116  pick1_ = new wxFilePickerCtrl(this, BUTTON_MODEL_VHDL, "",
117  "Select VHDL Op Implementation File", "*.vhd;*.vhdl", wxDefaultPosition,
118  wxDefaultSize, wxFLP_OPEN | wxFLP_FILE_MUST_EXIST | wxFLP_SMALL);
119  pick2_ = new wxFilePickerCtrl(this, BUTTON_MODEL_VERILOG, "",
120  "Select Verilog Op Implementation File", "*.vh;*.v", wxDefaultPosition,
121  wxDefaultSize, wxFLP_OPEN | wxFLP_FILE_MUST_EXIST | wxFLP_SMALL);
122  pick11_ = new wxFilePickerCtrl(this, BUTTON_POSTMODEL_VHDL, "",
123  "Select VHDL Post-Op Implementation File", "*.vhd;*.vhdl", wxDefaultPosition,
124  wxDefaultSize, wxFLP_OPEN | wxFLP_FILE_MUST_EXIST | wxFLP_SMALL);
125  pick21_ = new wxFilePickerCtrl(this, BUTTON_POSTMODEL_VERILOG, "",
126  "Select Verilog Post-Op Implementation File", "*.vh;*.v", wxDefaultPosition,
127  wxDefaultSize, wxFLP_OPEN | wxFLP_FILE_MUST_EXIST | wxFLP_SMALL);
128  pick_vhdl_init_ = new wxFilePickerCtrl(this, BUTTON_INITIAL_VHDL, "",
129  "Select VHDL Initial Implementation File", "*.vhd;*.vhdl", wxDefaultPosition,
130  wxDefaultSize, wxFLP_OPEN | wxFLP_FILE_MUST_EXIST | wxFLP_SMALL);
131  pick_vlog_init_ = new wxFilePickerCtrl(this, BUTTON_INITIAL_VERILOG, "",
132  "Select Verilog Initial Implementation File", "*.vh;*.v", wxDefaultPosition,
133  wxDefaultSize, wxFLP_OPEN | wxFLP_FILE_MUST_EXIST | wxFLP_SMALL);
134  pick31_ = new wxFilePickerCtrl(this, BUTTON_IPXACT_ABSDEF, "",
135  "Select IPXACT Bus Abstraction Definition File", "*.xml", wxDefaultPosition,
136  wxDefaultSize, wxFLP_OPEN | wxFLP_FILE_MUST_EXIST | wxFLP_SMALL);
137  latencyWheel_ = new wxSpinCtrl(this);
138 
139  flex1->Add(title1);
140  flex1->Add(nameCtrl_, 1, wxEXPAND);
141  flex1->Add(title2);
142  flex1->Add(pick1_, 1, wxEXPAND);
143  flex1->Add(title3);
144  flex1->Add(pick2_, 1, wxEXPAND);
145  flex1->Add(title21);
146  flex1->Add(pick11_, 1, wxEXPAND);
147  flex1->Add(title31);
148  flex1->Add(pick21_, 1, wxEXPAND);
149  flex1->Add(title_vhdl_init);
150  flex1->Add(pick_vhdl_init_, 1, wxEXPAND);
151  flex1->Add(title_vlog_init);
152  flex1->Add(pick_vlog_init_, 1, wxEXPAND);
153  flex1->Add(title41);
154  flex1->Add(pick31_, 1, wxEXPAND);
155  flex1->Add(title6);
156  flex1->Add(addVHDLVariableButton, 1, wxEXPAND);
157  flex1->Add(title7);
158  flex1->Add(addVerilogVariableButton, 1, wxEXPAND);
159  flex1->Add(title4);
160  flex1->Add(addButton, 1, wxEXPAND);
161  flex1->Add(title5);
162  flex1->Add(delButton, 1, wxEXPAND);
163  flex1->Add(title_latency);
164  flex1->Add(latencyWheel_, 1, wxEXPAND);
165 
166  addedResourceList_ = new wxListCtrl(
167  this, -1, wxDefaultPosition, wxDefaultSize, wxLC_REPORT);
168  addedResourceList_->AppendColumn(
169  "Added Resource", wxLIST_FORMAT_LEFT, 400);
170  addedResourceList_->AppendColumn("id", wxLIST_FORMAT_LEFT, 30);
171  addedResourceList_->AppendColumn("Count", wxLIST_FORMAT_LEFT, 120);
172 
173  addedVariableList_ = new wxListCtrl(
174  this, -1, wxDefaultPosition, wxDefaultSize, wxLC_REPORT);
175  addedVariableList_->AppendColumn(
176  "Added Variable", wxLIST_FORMAT_LEFT, 200);
177  addedVariableList_->AppendColumn("width", wxLIST_FORMAT_LEFT, 120);
178  addedVariableList_->AppendColumn("type", wxLIST_FORMAT_LEFT, 120);
179  addedVariableList_->AppendColumn("language", wxLIST_FORMAT_LEFT, 120);
180 
181  availableResourceList_ = new wxListCtrl(
182  this, -1, wxDefaultPosition, wxDefaultSize, wxLC_REPORT);
183  availableResourceList_->AppendColumn(
184  "Available Resource", wxLIST_FORMAT_LEFT, 170);
185  availableResourceList_->AppendColumn("id", wxLIST_FORMAT_LEFT, 30);
186 
187  wxBoxSizer* hbox2 = new wxBoxSizer(wxHORIZONTAL);
188  hbox2->Add(flex1, 1, wxALL | wxEXPAND, 15);
189  hbox2->Add(availableResourceList_, 1, wxALL | wxEXPAND, 15);
190  addAvailableResourcesToList();
191 
192  vbox->Add(hbox2, 1, wxALL | wxEXPAND, 15);
193  vbox->Add(addedResourceList_, 1, wxALL | wxEXPAND, 15);
194  vbox->Add(addedVariableList_, 1, wxALL | wxEXPAND, 15);
195  vbox->Add(hbox1, 0, wxALIGN_CENTER | wxTOP | wxBOTTOM, 10);
196 
197  SetSizer(vbox);
198  Centre();
199  ShowModal();
200  Destroy();
201 }
202 
203 void
205  HDB::HDBManager* manager = wxGetApp().mainFrame().hdbManager();
206  std::set<RowID> resource_ids =
208  for (const auto id : resource_ids) {
211  int idx = availableResourceList_->GetItemCount();
212  availableResourceList_->InsertItem(idx, resource.name);
213  availableResourceList_->SetItem(idx, 1, std::to_string(resource.id));
214  }
215 }
216 
217 std::string
219  HDB::HDBManager* manager = wxGetApp().mainFrame().hdbManager();
220  std::string es(path);
221  std::string s(manager->fileName());
222  size_t i = s.rfind('/', s.length());
223  if (i != std::string::npos) {
224  s = s.substr(0, i + 1);
225  if (es.find(s) == 0) {
226  return es.substr(s.length());
227  }
228  }
229  return es;
230 }
231 
232 void
235  HDB::HDBManager* manager = wxGetApp().mainFrame().hdbManager();
236 
237  operation.name = nameCtrl_->GetLineText(0);
238  if (operation.name.length() < 1) {
239  wxMessageBox(
240  wxT("Give the operation some name."), wxT("Error"), wxICON_ERROR);
241  return;
242  }
243 
244  operation.implFileVhdl = sanitize(pick1_->GetPath());
245  if (operation.implFileVhdl.length() < 1) {
246  wxMessageBox(wxT("Give the operation VHDL implementation file."),
247  wxT("Error"), wxICON_ERROR);
248  return;
249  }
250 
251  operation.implFileVerilog = sanitize(pick2_->GetPath());
252 
253  operation.postOpImplFileVhdl = sanitize(pick11_->GetPath());
254  operation.postOpImplFileVerilog = sanitize(pick21_->GetPath());
255  operation.initialImplFileVhdl = sanitize(pick_vhdl_init_->GetPath());
256  operation.initialImplFileVerilog = sanitize(pick_vlog_init_->GetPath());
257  operation.absBusDefFile = sanitize(pick31_->GetPath());
258  operation.latency = latencyWheel_->GetValue();
259 
260  long items = addedResourceList_->GetItemCount();
261  for (long i = 0; i < items; ++i) {
263  std::istringstream iss(
264  addedResourceList_->GetItemText(i, 1).ToStdString());
265  iss >> resource.id;
266  std::istringstream iss2(
267  addedResourceList_->GetItemText(i, 2).ToStdString());
268  iss2 >> resource.count;
269  operation.resources.emplace_back(resource);
270  }
271 
272  items = addedVariableList_->GetItemCount();
273  for (long i = 0; i < items; ++i) {
274  std::string name =
275  addedVariableList_->GetItemText(i, 0).ToStdString();
276  std::string width =
277  addedVariableList_->GetItemText(i, 1).ToStdString();
278  std::string type =
279  addedVariableList_->GetItemText(i, 2).ToStdString();
280  std::string lang =
281  addedVariableList_->GetItemText(i, 3).ToStdString();
282  if (lang == "VHDL") {
283  operation.vhdlVariables.emplace_back(
284  HDB::Variable{name, width, type, true});
285  } else if (lang == "Verilog") {
286  operation.verilogVariables.emplace_back(
287  HDB::Variable{name, width, type, true});
288  } else {
289  throw std::runtime_error("Unknown language");
290  }
291  }
292 
293  manager->addOperationImplementation(operation);
294  wxGetApp().mainFrame().browser()->update();
295  EndModal(wxID_OK);
296 }
297 
298 void
300 
301 void
303 
304 void
306  VariableDialog dialog(addedVariableList_, "VHDL");
307 }
308 
309 void
311  VariableDialog dialog(addedVariableList_, "Verilog");
312 }
313 
314 void
316  long item = -1;
317 
318  for (;;) {
319  item = addedResourceList_->GetNextItem(
320  item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
321  if (item == -1)
322  break;
323  addedResourceList_->DeleteItem(item);
324  if (addedResourceList_->GetItemCount() == 0 ||
325  item == addedResourceList_->GetItemCount())
326  break;
327  }
328 }
329 
330 void
332  long item = -1;
333 
334  for (;;) {
335  item = availableResourceList_->GetNextItem(
336  item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
337  if (item == -1)
338  break;
339  std::string name =
340  availableResourceList_->GetItemText(item, 0).ToStdString();
341  std::string id =
342  availableResourceList_->GetItemText(item, 1).ToStdString();
343 
344  bool found = false;
345  int idx = addedResourceList_->GetItemCount();
346  for (int i = 0; i < idx; ++i) {
347  if (addedResourceList_->GetItemText(i, 0).ToStdString() == name) {
348  std::istringstream iss(
349  addedResourceList_->GetItemText(i, 2).ToStdString());
350  int int_id;
351  iss >> int_id;
352  addedResourceList_->SetItem(i, 2, std::to_string(++int_id));
353  found = true;
354  break;
355  }
356  }
357  if (!found) {
358  addedResourceList_->InsertItem(idx, name);
359  addedResourceList_->SetItem(idx, 1, id);
360  addedResourceList_->SetItem(idx, 2, "1");
361  }
362  }
363 }
OperationImplementationDialog::onAddVerilogVariable
void onAddVerilogVariable(wxCommandEvent &)
Definition: OperationImplementationDialog.cc:310
OperationImplementationDialog::addedResourceList_
wxListCtrl * addedResourceList_
Definition: OperationImplementationDialog.hh:58
HDB::OperationImplementation::initialImplFileVerilog
std::string initialImplFileVerilog
Definition: OperationImplementation.hh:55
HDB::OperationImplementation::latency
int latency
Definition: OperationImplementation.hh:49
HDB::OperationImplementationResource::id
int id
Definition: OperationImplementationResource.hh:39
OperationImplementationDialog.hh
wxDEFINE_EVENT
wxDEFINE_EVENT(BUTTON_MODEL_VHDL, wxFileDirPickerEvent)
HDBBrowserWindow.hh
HDBEditor.hh
OperationImplementationDialog::onAddVerilogImplFile
void onAddVerilogImplFile(wxFileDirPickerEvent &)
Definition: OperationImplementationDialog.cc:302
OperationImplementationDialog::pick11_
wxFilePickerCtrl * pick11_
Definition: OperationImplementationDialog.hh:63
EVT_BUTTON
OperationImplementationDialog::onAddVerilogImplFile EVT_BUTTON(BUTTON_ADD_VHDL_VAR, OperationImplementationDialog::onAddVHDLVariable) EVT_BUTTON(BUTTON_ADD_VERILOG_VAR
OperationImplementationDialog::pick2_
wxFilePickerCtrl * pick2_
Definition: OperationImplementationDialog.hh:62
HDB::OperationImplementation::initialImplFileVhdl
std::string initialImplFileVhdl
Definition: OperationImplementation.hh:56
HDB::OperationImplementationResource::count
int count
Definition: OperationImplementationResource.hh:40
HDB::OperationImplementation::postOpImplFileVerilog
std::string postOpImplFileVerilog
Definition: OperationImplementation.hh:54
OperationImplementationDialog::pick1_
wxFilePickerCtrl * pick1_
Definition: OperationImplementationDialog.hh:61
HDB::Variable
Definition: OperationImplementation.hh:40
OperationImplementationDialog::availableResourceList_
wxListCtrl * availableResourceList_
Definition: OperationImplementationDialog.hh:57
HDB::HDBManager::addOperationImplementation
void addOperationImplementation(const OperationImplementation &operation)
Definition: HDBManager.cc:2541
OperationImplementationDialog::pick31_
wxFilePickerCtrl * pick31_
Definition: OperationImplementationDialog.hh:67
OperationImplementationDialog::addAvailableResourcesToList
void addAvailableResourcesToList()
Definition: OperationImplementationDialog.cc:204
HDB::HDBManager::OperationImplementationResourceByID
OperationImplementationResource OperationImplementationResourceByID(RowID id) const
Definition: HDBManager.cc:2410
OperationImplementationDialog::onDeleteListItem
void onDeleteListItem(wxCommandEvent &)
Definition: OperationImplementationDialog.cc:315
HDB::OperationImplementation::postOpImplFileVhdl
std::string postOpImplFileVhdl
Definition: OperationImplementation.hh:53
OperationImplementationDialog::nameCtrl_
wxTextCtrl * nameCtrl_
Definition: OperationImplementationDialog.hh:60
HDB::OperationImplementation::verilogVariables
std::vector< Variable > verilogVariables
Definition: OperationImplementation.hh:60
OperationImplementationDialog::pick_vhdl_init_
wxFilePickerCtrl * pick_vhdl_init_
Definition: OperationImplementationDialog.hh:65
HDB::HDBManager::OperationImplementationResourceIDs
std::set< RowID > OperationImplementationResourceIDs() const
Definition: HDBManager.cc:2221
HDB::OperationImplementation::implFileVerilog
std::string implFileVerilog
Definition: OperationImplementation.hh:52
VariableDialog.hh
VariableDialog
Definition: VariableDialog.hh:34
HDB::HDBManager
Definition: HDBManager.hh:82
HDB::OperationImplementation::name
std::string name
Definition: OperationImplementation.hh:50
OperationImplementationDialog::pick_vlog_init_
wxFilePickerCtrl * pick_vlog_init_
Definition: OperationImplementationDialog.hh:66
HDB::OperationImplementationResource
Definition: OperationImplementationResource.hh:38
OperationImplementationDialog
Definition: OperationImplementationDialog.hh:41
OperationImplementationDialog::pick21_
wxFilePickerCtrl * pick21_
Definition: OperationImplementationDialog.hh:64
Operation
Definition: Operation.hh:59
HDB::OperationImplementation::resources
std::vector< OperationImplementationResource > resources
Definition: OperationImplementation.hh:58
HDB::OperationImplementation::vhdlVariables
std::vector< Variable > vhdlVariables
Definition: OperationImplementation.hh:59
EVT_FILEPICKER_CHANGED
EVT_FILEPICKER_CHANGED(BUTTON_MODEL_VHDL, OperationImplementationDialog::onAddVhdlImplFile) EVT_FILEPICKER_CHANGED(BUTTON_MODEL_VERILOG
HDB::OperationImplementation::absBusDefFile
std::string absBusDefFile
Definition: OperationImplementation.hh:57
HDB::HDBManager::fileName
std::string fileName() const
Definition: HDBManager.cc:612
BlockImplementationFile.hh
OperationImplementationDialog::onAddListItem
void onAddListItem(wxCommandEvent &)
Definition: OperationImplementationDialog.cc:331
HDB::OperationImplementationResource::name
std::string name
Definition: OperationImplementationResource.hh:41
OperationImplementationDialog::onOK
void onOK(wxCommandEvent &)
Definition: OperationImplementationDialog.cc:233
OperationImplementationDialog::onAddVhdlImplFile
void onAddVhdlImplFile(wxFileDirPickerEvent &)
Definition: OperationImplementationDialog.cc:299
OperationImplementationDialog::sanitize
std::string sanitize(const wxString &path)
Definition: OperationImplementationDialog.cc:218
OperationImplementationDialog::latencyWheel_
wxSpinCtrl * latencyWheel_
Definition: OperationImplementationDialog.hh:68
HDBManager.hh
OperationImplementation.hh
OperationImplementationDialog::onAddVHDLVariable
void onAddVHDLVariable(wxCommandEvent &)
Definition: OperationImplementationDialog.cc:305
END_EVENT_TABLE
END_EVENT_TABLE() using namespace IDF
OperationImplementationDialog::addedVariableList_
wxListCtrl * addedVariableList_
Definition: OperationImplementationDialog.hh:59
HDB::OperationImplementation
Definition: OperationImplementation.hh:47
HDB::OperationImplementation::implFileVhdl
std::string implFileVhdl
Definition: OperationImplementation.hh:51