OpenASIP  2.0
Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
BlockImplementationFileDialog Class Reference

#include <BlockImplementationFileDialog.hh>

Inheritance diagram for BlockImplementationFileDialog:
Inheritance graph
Collaboration diagram for BlockImplementationFileDialog:
Collaboration graph

Public Member Functions

 BlockImplementationFileDialog (wxWindow *parent, wxWindowID id, HDB::BlockImplementationFile &file)
 
virtual ~BlockImplementationFileDialog ()
 

Private Types

enum  {
  ID_LABEL_PATH = 10000, ID_PATH, ID_LABEL_FORMAT, ID_FORMAT,
  ID_BROWSE, ID_LINE
}
 Enumerated IDs for dialog widgets. More...
 

Private Member Functions

void onBrowse (wxCommandEvent &event)
 
void onOK (wxCommandEvent &event)
 
wxSizer * createContents (wxWindow *parent, bool call_fit, bool set_sizer)
 Creates the dialog contents. More...
 

Private Attributes

HDB::BlockImplementationFilefile_
 BlockImplementationFile object to modify. More...
 
wxString path_
 Block implementation file path. More...
 
int format_
 Selected implementation file type. More...
 

Detailed Description

Dialog for editing BlockImplementationFile objects.

Definition at line 44 of file BlockImplementationFileDialog.hh.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
private

Enumerated IDs for dialog widgets.

Enumerator
ID_LABEL_PATH 
ID_PATH 
ID_LABEL_FORMAT 
ID_FORMAT 
ID_BROWSE 
ID_LINE 

Definition at line 56 of file BlockImplementationFileDialog.hh.

56  {
57  ID_LABEL_PATH = 10000,
58  ID_PATH,
60  ID_FORMAT,
61  ID_BROWSE,
62  ID_LINE
63  };

Constructor & Destructor Documentation

◆ BlockImplementationFileDialog()

BlockImplementationFileDialog::BlockImplementationFileDialog ( wxWindow *  parent,
wxWindowID  id,
HDB::BlockImplementationFile file 
)

The Constructor.

Parameters
parentParent window of the dialog.
idWindow identifier for the dialog window.
fileBlockImplementationFile object to modify.

Definition at line 64 of file BlockImplementationFileDialog.cc.

65  :
66  wxDialog(parent, id, _T("Parameter")),
67  file_(file) {
68 
69  createContents(this, true, true);
70 
72  format_ = file_.format();
73 
74  FindWindow(ID_PATH)->SetValidator(wxTextValidator(wxFILTER_ASCII, &path_));
75  FindWindow(ID_FORMAT)->SetValidator(wxGenericValidator(&format_));
76 
77  TransferDataToWindow();
78 }

References WxConversion::toWxString().

Here is the call graph for this function:

◆ ~BlockImplementationFileDialog()

BlockImplementationFileDialog::~BlockImplementationFileDialog ( )
virtual

The Destructor.

Definition at line 84 of file BlockImplementationFileDialog.cc.

84  {
85 }

Member Function Documentation

◆ createContents()

wxSizer * BlockImplementationFileDialog::createContents ( wxWindow *  parent,
bool  call_fit,
bool  set_sizer 
)
private

Creates the dialog contents.

Creates the dialog contents.

Definition at line 185 of file BlockImplementationFileDialog.cc.

186  {
187 
188  wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL );
189 
190  wxFlexGridSizer *item1 = new wxFlexGridSizer( 3, 0, 0 );
191 
192  wxStaticText *item2 = new wxStaticText( parent, ID_LABEL_PATH, wxT("Path:"), wxDefaultPosition, wxDefaultSize, 0 );
193  item1->Add( item2, 0, wxALIGN_RIGHT|wxALL, 5 );
194 
195  wxTextCtrl *item3 = new wxTextCtrl( parent, ID_PATH, wxT(""), wxDefaultPosition, wxSize(200,-1), 0 );
196  item1->Add( item3, 0, wxALIGN_CENTER|wxALL, 5 );
197 
198  wxButton *item4 = new wxButton( parent, ID_BROWSE, wxT("Browse..."), wxDefaultPosition, wxDefaultSize, 0 );
199  item1->Add( item4, 0, wxALIGN_CENTER|wxALL, 5 );
200 
201  wxStaticText *item5 = new wxStaticText( parent, ID_LABEL_FORMAT, wxT("Format:"), wxDefaultPosition, wxDefaultSize, 0 );
202  item1->Add( item5, 0, wxALIGN_RIGHT|wxALL, 5 );
203 
204  wxString strs6[] =
205  {
206  wxT("VHDL"),
207  wxT("Verilog")
208  };
209  wxChoice *item6 = new wxChoice( parent, ID_FORMAT, wxDefaultPosition, wxSize(100,-1), 2, strs6, 0 );
210  item1->Add( item6, 0, wxGROW|wxALL, 5 );
211 
212  item0->Add( item1, 0, wxALIGN_CENTER|wxALL, 5 );
213 
214  wxStaticLine *item7 = new wxStaticLine( parent, ID_LINE, wxDefaultPosition, wxSize(20,-1), wxLI_HORIZONTAL );
215  item0->Add( item7, 0, wxGROW|wxALL, 5 );
216 
217  wxBoxSizer *item8 = new wxBoxSizer( wxHORIZONTAL );
218 
219  wxButton *item9 = new wxButton( parent, wxID_CANCEL, wxT("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
220  item8->Add( item9, 0, wxALL, 5 );
221 
222  wxButton *item10 = new wxButton( parent, wxID_OK, wxT("&OK"), wxDefaultPosition, wxDefaultSize, 0 );
223  item8->Add( item10, 0, wxALIGN_CENTER|wxALL, 5 );
224 
225  item0->Add( item8, 0, wxALIGN_CENTER|wxALL, 5 );
226 
227  if (set_sizer)
228  {
229  parent->SetSizer( item0 );
230  if (call_fit)
231  item0->SetSizeHints( parent );
232  }
233 
234  return item0;
235 }

◆ onBrowse()

void BlockImplementationFileDialog::onBrowse ( wxCommandEvent &  event)
private

Event handler for the Browse-button.

Displays a wxFileDialog for selecting the implementation file.

Definition at line 93 of file BlockImplementationFileDialog.cc.

93  {
94 
95  const HDBManager& manager = *wxGetApp().mainFrame().hdbManager();
96  std::string hdbPath = manager.fileName();
97  wxString defaultDir = WxConversion::toWxString(
98  FileSystem::directoryOfPath(manager.fileName()).c_str());
99 
100  wxFileDialog dialog(
101  this, _T("Choose a file"), defaultDir, _T(""),
102  _T("VHDL files (*.vhd;*.vhdl)|*.vhd;*.vhdl|Verilog files (*.v)|*.v| All files (*.*)|*.*"),
103  (wxOPEN | wxFILE_MUST_EXIST));
104 
105  wxChoice *hdl_type = (wxChoice *)FindWindow(ID_FORMAT);
106  dialog.SetFilterIndex(hdl_type->GetCurrentSelection());
107 
108  if (dialog.ShowModal() == wxID_OK) {
109 
110  std::string filename = WxConversion::toString(dialog.GetPath());
111  std::string vhdlPath = FileSystem::directoryOfPath(filename);
112  std::vector<std::string> vhdlPaths = Environment::vhdlPaths(hdbPath);
113 
114  for (std::vector<std::string>::iterator it = vhdlPaths.begin();
115  it != vhdlPaths.end(); ++it) {
116  // check if VHDL path is relative to one of the search paths.
117  if (vhdlPath.substr(0, (*it).length()) == *it) {
118 
119  filename = filename.substr((*it).length() + 1);
120  break;
121  }
122  }
123 
124  path_ = WxConversion::toWxString(filename);
125  TransferDataToWindow();
126  }
127 }

References FileSystem::directoryOfPath(), HDB::HDBManager::fileName(), WxConversion::toString(), WxConversion::toWxString(), and Environment::vhdlPaths().

Here is the call graph for this function:

◆ onOK()

void BlockImplementationFileDialog::onOK ( wxCommandEvent &  event)
private

Event handler for the dialog OK-button.

Definition at line 134 of file BlockImplementationFileDialog.cc.

134  {
135 
136  TransferDataFromWindow();
137 
138  path_ = path_.Trim(true).Trim(false);
139 
140  if (path_.IsEmpty()) {
141  wxString message = _T("Path field must not be empty.");
142  ErrorDialog dialog(this, message);
143  dialog.ShowModal();
144  return;
145  }
146 
147  // Attempt to find the file in search paths
148  const HDBManager& manager = *wxGetApp().mainFrame().hdbManager();
149 
150  std::string hdbPath = manager.fileName();
151  std::vector<std::string> vhdlPaths =
152  Environment::vhdlPaths(hdbPath);
153  try {
154  std::string filename =
156  vhdlPaths, WxConversion::toString(path_));
157 
158  for (std::vector<std::string>::iterator it = vhdlPaths.begin();
159  it != vhdlPaths.end(); ++it) {
160  if (filename.substr(0, (*it).length()) == *it) {
162  << filename << " in search path " << *it << std::endl;
163  filename = filename.substr((*it).length() + 1);
164  path_ = WxConversion::toWxString(filename);
165  break;
166  }
167  }
168  } catch (FileNotFound f) {
169  wxString message = _T("File not found from the VHDL search paths.");
170  ErrorDialog dialog(this, message);
171  dialog.ShowModal();
172  return;
173  }
174 
177 
178  EndModal(wxID_OK);
179 }

References HDB::HDBManager::fileName(), FileSystem::findFileInSearchPaths(), Application::logStream(), WxConversion::toString(), WxConversion::toWxString(), and Environment::vhdlPaths().

Here is the call graph for this function:

Member Data Documentation

◆ file_

HDB::BlockImplementationFile& BlockImplementationFileDialog::file_
private

BlockImplementationFile object to modify.

Definition at line 69 of file BlockImplementationFileDialog.hh.

◆ format_

int BlockImplementationFileDialog::format_
private

Selected implementation file type.

Definition at line 74 of file BlockImplementationFileDialog.hh.

◆ path_

wxString BlockImplementationFileDialog::path_
private

Block implementation file path.

Definition at line 72 of file BlockImplementationFileDialog.hh.


The documentation for this class was generated from the following files:
BlockImplementationFileDialog::ID_LABEL_FORMAT
@ ID_LABEL_FORMAT
Definition: BlockImplementationFileDialog.hh:59
WxConversion::toWxString
static wxString toWxString(const std::string &source)
FileNotFound
Definition: Exception.hh:224
HDB::BlockImplementationFile::setFormat
void setFormat(Format format)
Definition: BlockImplementationFile.cc:92
HDB::BlockImplementationFile::Format
Format
Format of the file.
Definition: BlockImplementationFile.hh:47
FindWindow
Definition: FindWindow.hh:49
Application::logStream
static std::ostream & logStream()
Definition: Application.cc:155
ErrorDialog
Definition: ErrorDialog.hh:42
BlockImplementationFileDialog::createContents
wxSizer * createContents(wxWindow *parent, bool call_fit, bool set_sizer)
Creates the dialog contents.
Definition: BlockImplementationFileDialog.cc:185
BlockImplementationFileDialog::file_
HDB::BlockImplementationFile & file_
BlockImplementationFile object to modify.
Definition: BlockImplementationFileDialog.hh:69
FileSystem::directoryOfPath
static std::string directoryOfPath(const std::string fileName)
Definition: FileSystem.cc:79
HDB::HDBManager
Definition: HDBManager.hh:82
BlockImplementationFileDialog::ID_PATH
@ ID_PATH
Definition: BlockImplementationFileDialog.hh:58
BlockImplementationFileDialog::ID_LINE
@ ID_LINE
Definition: BlockImplementationFileDialog.hh:62
HDB::BlockImplementationFile::pathToFile
std::string pathToFile() const
Definition: BlockImplementationFile.cc:61
BlockImplementationFileDialog::format_
int format_
Selected implementation file type.
Definition: BlockImplementationFileDialog.hh:74
BlockImplementationFileDialog::ID_BROWSE
@ ID_BROWSE
Definition: BlockImplementationFileDialog.hh:61
BlockImplementationFileDialog::ID_LABEL_PATH
@ ID_LABEL_PATH
Definition: BlockImplementationFileDialog.hh:57
HDB::HDBManager::fileName
std::string fileName() const
Definition: HDBManager.cc:612
Environment::vhdlPaths
static std::vector< std::string > vhdlPaths(const std::string &hdbPath)
Definition: Environment.cc:760
BlockImplementationFileDialog::path_
wxString path_
Block implementation file path.
Definition: BlockImplementationFileDialog.hh:72
HDB::BlockImplementationFile::format
Format format() const
Definition: BlockImplementationFile.cc:70
BlockImplementationFileDialog::ID_FORMAT
@ ID_FORMAT
Definition: BlockImplementationFileDialog.hh:60
HDB::BlockImplementationFile::setPathToFile
void setPathToFile(const std::string &pathToFile)
Definition: BlockImplementationFile.cc:81
FileSystem::findFileInSearchPaths
static std::string findFileInSearchPaths(const std::vector< std::string > &searchPaths, const std::string &file)
Definition: FileSystem.cc:562
WxConversion::toString
static std::string toString(const wxString &source)