OpenASIP  2.0
OperationImplementationResourceDialog.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 FUGENResourceDialog.cc
26  *
27  * Implementation of FUGENResourceDialog.
28  *
29  * @author Lasse Lehtonen 2017 (lasse.lehtonen-no.spam-tut.fi)
30  */
31 
33 #include "HDBEditor.hh"
34 #include "HDBManager.hh"
36 #include "HDBBrowserWindow.hh"
38 
39 
40 wxDEFINE_EVENT(BUTTON_SYN_VHDL, wxFileDirPickerEvent);
41 wxDEFINE_EVENT(BUTTON_SIM_VHDL, wxFileDirPickerEvent);
42 wxDEFINE_EVENT(BUTTON_SYN_VERILOG, wxFileDirPickerEvent);
43 wxDEFINE_EVENT(BUTTON_SIM_VERILOG, wxFileDirPickerEvent);
44 wxDEFINE_EVENT(BUTTON_IPXACT, wxFileDirPickerEvent);
45 wxDEFINE_EVENT(BUTTON_DEL, wxCommandEvent);
46 
47 BEGIN_EVENT_TABLE(OperationImplementationResourceDialog, wxDialog)
49  EVT_FILEPICKER_CHANGED(BUTTON_SYN_VHDL,
51  EVT_FILEPICKER_CHANGED(BUTTON_SIM_VHDL,
53  EVT_FILEPICKER_CHANGED(BUTTON_SYN_VERILOG,
55  EVT_FILEPICKER_CHANGED(BUTTON_SIM_VERILOG,
57  EVT_BUTTON(wxID_DELETE,
58  OperationImplementationResourceDialog::onDeleteListItem)
60 
61 /// Constructor
64  : wxDialog(NULL, -1, "Add Operation Implementation Resource",
65  wxDefaultPosition, wxSize(600, 480))
66 {
67  wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL);
68  wxBoxSizer *hbox1 = new wxBoxSizer(wxHORIZONTAL);
69 
70  wxButton *okButton = new wxButton(this, wxID_OK, wxT("Ok"),
71  wxDefaultPosition, wxSize(70, 30));
72  wxButton *closeButton = new wxButton(this, wxID_CANCEL, wxT("Cancel"),
73  wxDefaultPosition, wxSize(70, 30));
74 
75  wxButton *delButton = new wxButton(this , wxID_DELETE, wxT(""));
76 
77  hbox1->Add(okButton, 1);
78  hbox1->Add(closeButton, 1, wxLEFT, 5);
79 
80  wxFlexGridSizer *flex1 = new wxFlexGridSizer(7, 2, 9, 25);
81 
82  wxStaticText *title1 = new wxStaticText(
83  this, -1, wxT("Name"));
84  wxStaticText *title2 = new wxStaticText(
85  this, -1, wxT("VHDL Synthesis file"));
86  wxStaticText *title3 = new wxStaticText(
87  this, -1, wxT("VHDL Simulation file"));
88  wxStaticText *title4 = new wxStaticText(
89  this, -1, wxT("Verilog Synthesis file"));
90  wxStaticText *title5 = new wxStaticText(
91  this, -1, wxT("Verilog Simulation file"));
92  wxStaticText *title7 = new wxStaticText(
93  this, -1, wxT("IP-XACT component file"));
94  wxStaticText *title6 = new wxStaticText(
95  this, -1, wxT("Selected files"));
96 
97  nameCtrl_ = new wxTextCtrl(this, -1);
98 
99  wxFilePickerCtrl *pick1 = new wxFilePickerCtrl(this, BUTTON_SYN_VHDL,
100  "", "Select VHDL Synthesis File", "*.vhd;*.vhdl",
101  wxDefaultPosition, wxDefaultSize,
102  wxFLP_OPEN | wxFLP_FILE_MUST_EXIST | wxFLP_SMALL);
103  wxFilePickerCtrl *pick2 = new wxFilePickerCtrl(this, BUTTON_SIM_VHDL,
104  "", "Select VHDL Simulation File", "*.vhd;*.vhdl",
105  wxDefaultPosition, wxDefaultSize,
106  wxFLP_OPEN | wxFLP_FILE_MUST_EXIST | wxFLP_SMALL);
107  wxFilePickerCtrl *pick3 = new wxFilePickerCtrl(this, BUTTON_SYN_VERILOG,
108  "", "Select Verilog Synthesis File", "*.vh;*.v",
109  wxDefaultPosition, wxDefaultSize,
110  wxFLP_OPEN | wxFLP_FILE_MUST_EXIST | wxFLP_SMALL);
111  wxFilePickerCtrl *pick4 = new wxFilePickerCtrl(this, BUTTON_SIM_VERILOG,
112  "", "Select Verilog Simulation File", "*.vh;*.v",
113  wxDefaultPosition, wxDefaultSize,
114  wxFLP_OPEN | wxFLP_FILE_MUST_EXIST | wxFLP_SMALL);
115  ipxactPick_ = new wxFilePickerCtrl(this, BUTTON_IPXACT,
116  "", "Select IP-XACT component File", "*.xml",
117  wxDefaultPosition, wxDefaultSize,
118  wxFLP_OPEN | wxFLP_FILE_MUST_EXIST | wxFLP_SMALL);
119 
120  flex1->Add(title1);
121  flex1->Add(nameCtrl_, 1, wxEXPAND);
122  flex1->Add(title2);
123  flex1->Add(pick1, 1, wxEXPAND);
124  flex1->Add(title3);
125  flex1->Add(pick2, 1, wxEXPAND);
126  flex1->Add(title4);
127  flex1->Add(pick3, 1, wxEXPAND);
128  flex1->Add(title5);
129  flex1->Add(pick4, 1, wxEXPAND);
130  flex1->Add(title7);
131  flex1->Add(ipxactPick_, 1, wxEXPAND);
132  flex1->Add(title6);
133  flex1->Add(delButton, 1, wxEXPAND);
134 
135 
136  fileList1_ = new wxListCtrl(this, -1,
137  wxDefaultPosition, wxDefaultSize, wxLC_REPORT);
138  fileList1_->AppendColumn("File", wxLIST_FORMAT_LEFT, 400);
139  fileList1_->AppendColumn("Type", wxLIST_FORMAT_LEFT, 150);
140 
141  vbox->Add(flex1, 1, wxALL | wxEXPAND, 15);
142  vbox->Add(fileList1_, 1, wxALL | wxEXPAND, 15);
143  vbox->Add(hbox1, 0, wxALIGN_CENTER | wxTOP | wxBOTTOM, 10);
144 
145  SetSizer(vbox);
146  Centre();
147  ShowModal();
148  Destroy();
149 }
150 
151 void
154  HDB::HDBManager* manager = wxGetApp().mainFrame().hdbManager();
155 
156  resource.name = nameCtrl_->GetLineText(0);
157  if (resource.name.length() < 1) {
158  wxMessageBox( wxT("Give the resource a name."),
159  wxT("Error"), wxICON_ERROR);
160  return;
161  }
162 
163  long items = fileList1_->GetItemCount();
164  for (int i = 0; i < items; ++i) {
165  std::string file = fileList1_->GetItemText(i, 0).ToStdString();
166  std::string type = fileList1_->GetItemText(i, 1).ToStdString();
167  if (type == manager->formatString(
169  resource.synFiles.emplace_back(file);
170  resource.synFormats.emplace_back(type);
171  } else if (type == manager->formatString(
173  resource.simFiles.emplace_back(file);
174  resource.simFormats.emplace_back(type);
175  }
176  else if (type == manager->formatString(
178  resource.synFiles.emplace_back(file);
179  resource.synFormats.emplace_back(type);
180  }
181  else if (type == manager->formatString(
183  resource.simFiles.emplace_back(file);
184  resource.simFormats.emplace_back(type);
185  } else {
186  wxMessageBox( wxT("Unknown file type."),
187  wxT("Error"), wxICON_ERROR);
188  return;
189  }
190  }
191 
192  resource.ipxact = sanitize(ipxactPick_->GetPath());
193  if (resource.ipxact.length() < 1) {
194  wxMessageBox(wxT("Give the IP-XACT component file."),
195  wxT("Error"), wxICON_ERROR);
196  return;
197  }
198 
199  manager->addOperationImplementationResource(resource);
200  wxGetApp().mainFrame().browser()->update();
201  EndModal(wxID_OK);
202 }
203 
204 std::string
206  HDB::HDBManager* manager = wxGetApp().mainFrame().hdbManager();
207  std::string es(path);
208  std::string s(manager->fileName());
209  size_t i = s.rfind('/', s.length());
210  if (i != std::string::npos) {
211  s = s.substr(0, i+1);
212  if (es.find(s) == 0) {
213  return es.substr(s.length());
214  }
215  }
216  return es;
217 }
218 
219 
220 void
222  wxFileDirPickerEvent& e) {
223  HDB::HDBManager* manager = wxGetApp().mainFrame().hdbManager();
224  int idx = fileList1_->GetItemCount();
225  fileList1_->InsertItem(idx, sanitize(e.GetPath()));
226  fileList1_->SetItem(idx, 1, manager->formatString(
228 }
229 
230 void
232  wxFileDirPickerEvent& e) {
233  HDB::HDBManager* manager = wxGetApp().mainFrame().hdbManager();
234  int idx = fileList1_->GetItemCount();
235  fileList1_->InsertItem(idx, sanitize(e.GetPath()));
236  fileList1_->SetItem(idx, 1, manager->formatString(
238 }
239 
240 void
242  wxFileDirPickerEvent& e) {
243  HDB::HDBManager* manager = wxGetApp().mainFrame().hdbManager();
244  int idx = fileList1_->GetItemCount();
245  fileList1_->InsertItem(idx, sanitize(e.GetPath()));
246  fileList1_->SetItem(idx, 1, manager->formatString(
248 }
249 
250 void
252  wxFileDirPickerEvent& e) {
253  HDB::HDBManager* manager = wxGetApp().mainFrame().hdbManager();
254  int idx = fileList1_->GetItemCount();
255  fileList1_->InsertItem(idx, sanitize(e.GetPath()));
256  fileList1_->SetItem(idx, 1, manager->formatString(
258 }
259 
260 void
262  long item = -1;
263 
264  for (;;)
265  {
266  item = fileList1_->GetNextItem(
267  item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
268  if (item == -1)
269  break;
270  fileList1_->DeleteItem(item);
271  if (fileList1_->GetItemCount() == 0 ||
272  item == fileList1_->GetItemCount())
273  break;
274  }
275 }
HDB::HDBManager::formatString
static std::string formatString(BlockImplementationFile::Format format)
Definition: HDBManager.cc:5737
HDBBrowserWindow.hh
HDBEditor.hh
HDB::BlockImplementationFile::VHDL
@ VHDL
VHDL file.
Definition: BlockImplementationFile.hh:48
OperationImplementationResourceDialog::onAddVerilogSynFile
void onAddVerilogSynFile(wxFileDirPickerEvent &)
Definition: OperationImplementationResourceDialog.cc:241
OperationImplementationResourceDialog::onAddVhdlSimFile
void onAddVhdlSimFile(wxFileDirPickerEvent &)
Definition: OperationImplementationResourceDialog.cc:231
OperationImplementationResourceDialog::ipxactPick_
wxFilePickerCtrl * ipxactPick_
Definition: OperationImplementationResourceDialog.hh:60
HDB::OperationImplementationResource::ipxact
std::string ipxact
Definition: OperationImplementationResource.hh:42
OperationImplementationResourceDialog::onOK
void onOK(wxCommandEvent &)
Definition: OperationImplementationResourceDialog.cc:152
OperationImplementationResourceDialog::fileList1_
wxListCtrl * fileList1_
Definition: OperationImplementationResourceDialog.hh:58
HDB::OperationImplementationResource::synFiles
std::vector< std::string > synFiles
Definition: OperationImplementationResource.hh:45
HDB::HDBManager::addOperationImplementationResource
void addOperationImplementationResource(const OperationImplementationResource &resource)
Definition: HDBManager.cc:2482
HDB::OperationImplementationResource::simFormats
std::vector< std::string > simFormats
Definition: OperationImplementationResource.hh:44
OperationImplementationResourceDialog.hh
HDB::OperationImplementationResource::simFiles
std::vector< std::string > simFiles
Definition: OperationImplementationResource.hh:46
OperationImplementationResourceDialog::onAddVhdlSynFile
void onAddVhdlSynFile(wxFileDirPickerEvent &)
Definition: OperationImplementationResourceDialog.cc:221
HDB::HDBManager
Definition: HDBManager.hh:82
HDB::OperationImplementationResource
Definition: OperationImplementationResource.hh:38
HDB::BlockImplementationFile::Verilog
@ Verilog
Verilog file.
Definition: BlockImplementationFile.hh:49
Operation
Definition: Operation.hh:59
HDB::HDBManager::fileName
std::string fileName() const
Definition: HDBManager.cc:612
BlockImplementationFile.hh
HDB::BlockImplementationFile::Verilogsim
@ Verilogsim
Verilog simulation file.
Definition: BlockImplementationFile.hh:51
EVT_BUTTON
OperationImplementationResourceDialog::onAddVhdlSimFile OperationImplementationResourceDialog::onAddVerilogSimFile EVT_BUTTON(wxID_DELETE, OperationImplementationResourceDialog::onDeleteListItem) OperationImplementationResourceDialog
Constructor.
Definition: OperationImplementationResourceDialog.cc:57
wxDEFINE_EVENT
wxDEFINE_EVENT(BUTTON_SYN_VHDL, wxFileDirPickerEvent)
OperationImplementationResourceDialog
Definition: OperationImplementationResourceDialog.hh:44
EVT_FILEPICKER_CHANGED
EVT_FILEPICKER_CHANGED(BUTTON_SYN_VHDL, OperationImplementationResourceDialog::onAddVhdlSynFile) EVT_FILEPICKER_CHANGED(BUTTON_SIM_VHDL
HDB::OperationImplementationResource::name
std::string name
Definition: OperationImplementationResource.hh:41
OperationImplementationResource.hh
OperationImplementationResourceDialog::nameCtrl_
wxTextCtrl * nameCtrl_
Definition: OperationImplementationResourceDialog.hh:59
OperationImplementationResourceDialog::onAddVerilogSimFile
void onAddVerilogSimFile(wxFileDirPickerEvent &)
Definition: OperationImplementationResourceDialog.cc:251
HDBManager.hh
OperationImplementationResourceDialog::onDeleteListItem
void onDeleteListItem(wxCommandEvent &)
Definition: OperationImplementationResourceDialog.cc:261
OperationImplementationResourceDialog::sanitize
std::string sanitize(const wxString &path)
Definition: OperationImplementationResourceDialog.cc:205
END_EVENT_TABLE
END_EVENT_TABLE() using namespace IDF
HDB::OperationImplementationResource::synFormats
std::vector< std::string > synFormats
Definition: OperationImplementationResource.hh:43
HDB::BlockImplementationFile::VHDLsim
@ VHDLsim
VHDL simulation file.
Definition: BlockImplementationFile.hh:50