OpenASIP  2.0
HDBEditorMainFrame.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 HDBEditorMainFrame.cc
26  *
27  * Definition of HDBEditorMainFrame class.
28  *
29  * @author Veli-Pekka Jääskeläinen 2006 (vjaaskel-no.spam-cs.tut.fi)
30  * @note rating: red
31  */
32 
33 
34 #include <wx/sizer.h>
35 #include <wx/statusbr.h>
36 
37 #include "HDBEditorMainFrame.hh"
38 #include "CommandRegistry.hh"
39 #include "WxConversion.hh"
40 #include "ErrorDialog.hh"
41 
42 #include "HDBEditorConstants.hh"
43 #include "GUICommand.hh"
44 #include "CachedHDBManager.hh"
45 #include "HDBRegistry.hh"
46 #include "HDBBrowserWindow.hh"
47 
48 #include "OpenHDBCmd.hh"
49 #include "CreateHDBCmd.hh"
50 #include "HDBEditorDeleteCmd.hh"
51 #include "HDBEditorModifyCmd.hh"
52 #include "AddFUArchFromADFCmd.hh"
53 #include "HDBEditorQuitCmd.hh"
55 #include "AddRFArchitectureCmd.hh"
58 #include "AddFUEntryCmd.hh"
59 #include "AddRFEntryCmd.hh"
60 #include "AddBusEntryCmd.hh"
61 #include "AddSocketEntryCmd.hh"
63 #include "HDBEditorAboutCmd.hh"
64 #include "UserManualCmd.hh"
65 #include "FileSystem.hh"
68 
69 BEGIN_EVENT_TABLE(HDBEditorMainFrame, wxFrame)
70  // EVT_KEY_DOWN(MainFrame::onKeyEvent)
72  EVT_UPDATE_UI(-1, HDBEditorMainFrame::onUpdateUI)
74 
75 
76 /**
77  * The Constructor.
78  *
79  * @param title Title of the MainFrame.
80  * @param position Position of the MainFrame on the screen.
81  * @param size Size of the MainFrame on the screen.
82  */
84  const wxString& title,
85  const wxPoint& position,
86  const wxSize& size):
87  wxFrame(NULL, -1, title, position, size),
88  hdb_(NULL) {
89 
90  commandRegistry_ = new CommandRegistry();
91 
92  wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL);
93  browser_ = new HDBBrowserWindow(this, -1);
94  sizer->Add(browser_, 1, wxGROW);
95  Fit();
96 
97  // Create the default menubar.
98  wxMenu* fileMenu = new wxMenu;
99  fileMenu->Append(HDBEditorConstants::COMMAND_OPEN_HDB, _T("&Open HDB..."));
100  fileMenu->Append(
101  HDBEditorConstants::COMMAND_CREATE_HDB, _T("&Create HDB..."));
102  fileMenu->AppendSeparator();
103  fileMenu->Append(HDBEditorConstants::COMMAND_QUIT, _T("&Quit"));
104 
105  wxMenu* editMenu = new wxMenu;
106  wxMenu* addSubMenu = new wxMenu;
107 
108  addSubMenu->Append(
110  _T("FU Architecture From ADF..."));
111  addSubMenu->Append(
113  _T("RF Architecture..."));
114  addSubMenu->AppendSeparator();
115 
116  addSubMenu->Append(
118  _T("Operation Implementation Resource..."));
119  addSubMenu->Append(
121  _T("Operation Implementation..."));
122  addSubMenu->AppendSeparator();
123 
124  addSubMenu->Append(
126  _T("FU Entry Implementation..."));
127  addSubMenu->Append(
129  _T("RF Entry Implementation..."));
130 
131  addSubMenu->AppendSeparator();
132  addSubMenu->Append(
134 
135  addSubMenu->Append(
137  addSubMenu->Append(
139 
140  addSubMenu->Append(
142 
143  addSubMenu->AppendSeparator();
144  addSubMenu->Append(
146  _T("Cost Function Plugin..."));
147  editMenu->Append(-1, _T("Add"), addSubMenu);
148  editMenu->AppendSeparator();
149  editMenu->Append(
151  _T("Set Cost Function Plugin"));
152 
153  editMenu->AppendSeparator();
154  editMenu->Append(HDBEditorConstants::COMMAND_DELETE, _T("Delete"));
155  editMenu->Append(HDBEditorConstants::COMMAND_MODIFY, _T("Modify..."));
156 
157  wxMenu* helpMenu = new wxMenu;
158 
159  helpMenu->Append(UserManualCmd::COMMAND_ID, _T("User Manual..."));
160  helpMenu->Append(HDBEditorConstants::COMMAND_ABOUT, _T("About..."));
161 
162  wxMenuBar* menuBar = new wxMenuBar;
163  menuBar->Append(fileMenu, _T("&File"));
164  menuBar->Append(editMenu, _T("&Edit"));
165  menuBar->Append(helpMenu, _T("&Help"));
166  SetMenuBar(menuBar);
167 
168  CreateStatusBar();
169  SetSizer(sizer);
170 
171  commandRegistry_->addCommand(new OpenHDBCmd());
172  commandRegistry_->addCommand(new CreateHDBCmd());
173  commandRegistry_->addCommand(new HDBEditorDeleteCmd());
174  commandRegistry_->addCommand(new HDBEditorModifyCmd());
175  commandRegistry_->addCommand(new AddFUArchFromADFCmd());
176  commandRegistry_->addCommand(new HDBEditorQuitCmd());
177  commandRegistry_->addCommand(new AddFUImplementationCmd());
178  commandRegistry_->addCommand(new AddRFArchitectureCmd());
179  commandRegistry_->addCommand(new AddRFImplementationCmd());
180  commandRegistry_->addCommand(new AddFUEntryCmd());
181  commandRegistry_->addCommand(new AddRFEntryCmd());
182  commandRegistry_->addCommand(new AddBusEntryCmd());
183  commandRegistry_->addCommand(new AddSocketEntryCmd());
184  commandRegistry_->addCommand(new AddCostFunctionPluginCmd());
185  commandRegistry_->addCommand(new SetCostFunctionPluginCmd());
186  commandRegistry_->addCommand(new HDBEditorAboutCmd());
187  commandRegistry_->addCommand(new UserManualCmd());
188  commandRegistry_->addCommand(new AddOperationImplementationCmd());
189  commandRegistry_->addCommand(new AddOperationImplementationResourceCmd());
190 
191  SetSizeHints(400,300);
192  SetSize(600, 400);
193 }
194 
195 
196 /**
197  * The Destructor.
198  */
200 }
201 
202 
203 
204 /**
205  * Handles menu and toolbar events.
206  *
207  * @param event Event to handle.
208  */
209 void
210 HDBEditorMainFrame::onCommandEvent(wxCommandEvent& event) {
211 
212  GUICommand* command = commandRegistry_->createCommand(event.GetId());
213 
214  if (command == NULL) {
215  ErrorDialog dialog(
216  this, _T("No handler found for the command event!"));
217  dialog.ShowModal();
218  return;
219  }
220 
221  command->setParentWindow(this);
222  command->Do();
223 }
224 
225 /**
226  * Updates toolbar and menubar item enabled/disabled states.
227  *
228  * @param event Update event for the menu or toolbar item to be updated.
229  */
230 void
231 HDBEditorMainFrame::onUpdateUI(wxUpdateUIEvent& event) {
232 
233  GUICommand* command = commandRegistry_->createCommand(event.GetId());
234 
235  if (command == NULL || command->isEnabled()) {
236  event.Enable(true);
237  } else {
238  event.Enable(false);
239  }
240 
241  delete command;
242 }
243 
244 
245 /**
246  * Sets the HDB to be displayed and modified with the main frame.
247  *
248  * @param HDB to be opened in the main frame.
249  * @return True, if the HDB was succesfully opened, false if not.
250  */
251 bool
252 HDBEditorMainFrame::setHDB(const std::string& hdbFile) {
253 
254  if (hdb_ != NULL) {
255  hdb_ = NULL;
256  }
257 
258  try {
259  hdb_ = &HDB::HDBRegistry::instance().hdb(hdbFile);
260  } catch (Exception& e) {
261  wxString message = _T("Error opening HDB ");
262  message.Append(WxConversion::toWxString(hdbFile));
263  message.Append(_T(":\n\n"));
264  message.Append(WxConversion::toWxString(e.errorMessage()));
265  ErrorDialog dialog(this, message);
266  dialog.ShowModal();
267  return false;
268  }
269 
271  std::string title = "HDB Editor - " + FileSystem::fileOfPath(hdbFile);
272  SetTitle(WxConversion::toWxString(title));
273  return true;
274 }
275 
276 /**
277  * Creates a new HDB and opens it in the main frame.
278  *
279  * @param filePath Full path of the HDB to be created.
280  * @return True, if the HDB was succesfully created and opened, false if not.
281  */
282 bool
283 HDBEditorMainFrame::createHDB(const std::string& filePath) {
284 
285  if (hdb_ != NULL) {
286  hdb_ = NULL;
287  }
288 
289  try {
291  } catch (Exception& e) {
292  wxString message = _T("Error creating HDB ");
293  message.Append(WxConversion::toWxString(filePath));
294  message.Append(_T(":\n\n"));
295  message.Append(WxConversion::toWxString(e.errorMessage()));
296  ErrorDialog dialog(this, message);
297  dialog.ShowModal();
298  return false;
299  }
300 
302  std::string title = "HDB Editor - " + FileSystem::fileOfPath(filePath);
303  SetTitle(WxConversion::toWxString(title));
304 
305  return true;
306 
307 }
308 
309 /**
310  * Returns pointer to the HDBManager managing the current HDB.
311  *
312  * @return Pointer to the HDBManager of the main frame.
313  */
316  return hdb_;
317 }
318 
319 
320 /**
321  * Updates the HDB window.
322  */
323 void
325  browser_->update();
326 }
327 
328 
329 /**
330  * Returns pointer to the HDB browser window.
331  *
332  * @return HDB Browser window of the application.
333  */
336  return browser_;
337 }
OpenHDBCmd.hh
HDBBrowserWindow::update
void update()
Definition: HDBBrowserWindow.cc:109
GUICommand::setParentWindow
void setParentWindow(wxWindow *view)
Definition: GUICommand.cc:64
AddSocketEntryCmd.hh
FileSystem.hh
WxConversion::toWxString
static wxString toWxString(const std::string &source)
GUICommand::isEnabled
virtual bool isEnabled()=0
HDBEditorAboutCmd.hh
HDBEditorConstants::COMMAND_SET_COST_PLUGIN
@ COMMAND_SET_COST_PLUGIN
Definition: HDBEditorConstants.hh:58
HDBBrowserWindow.hh
CommandRegistry.hh
AddSocketEntryCmd
Definition: AddSocketEntryCmd.hh:41
HDBBrowserWindow
Definition: HDBBrowserWindow.hh:59
HDBEditorConstants::COMMAND_ADD_RF_ENTRY
@ COMMAND_ADD_RF_ENTRY
Definition: HDBEditorConstants.hh:54
HDBEditorMainFrame::hdbManager
HDB::HDBManager * hdbManager()
Definition: HDBEditorMainFrame.cc:315
OpenHDBCmd
Definition: OpenHDBCmd.hh:43
HDBEditorMainFrame::createHDB
bool createHDB(const std::string &filePath)
Definition: HDBEditorMainFrame.cc:283
AddFUArchFromADFCmd.hh
AddBusEntryCmd.hh
HDBEditorQuitCmd.hh
AddRFArchitectureCmd
Definition: AddRFArchitectureCmd.hh:41
HDBEditorConstants.hh
HDBEditorModifyCmd
Definition: HDBEditorModifyCmd.hh:41
AddRFImplementationCmd
Definition: AddRFImplementationCmd.hh:41
HDBEditorConstants::COMMAND_OPEN_HDB
@ COMMAND_OPEN_HDB
Definition: HDBEditorConstants.hh:45
AddFUArchFromADFCmd
Definition: AddFUArchFromADFCmd.hh:41
HDBEditorConstants::COMMAND_ADD_OPERATION_IMPLEMENTATION_RESOURCE
@ COMMAND_ADD_OPERATION_IMPLEMENTATION_RESOURCE
Definition: HDBEditorConstants.hh:63
HDBEditorConstants::COMMAND_CREATE_HDB
@ COMMAND_CREATE_HDB
Definition: HDBEditorConstants.hh:46
HDBEditorMainFrame::onUpdateUI
void onUpdateUI(wxUpdateUIEvent &event)
Definition: HDBEditorMainFrame.cc:231
HDB::HDBRegistry::hdb
CachedHDBManager & hdb(const std::string fileName)
Definition: HDBRegistry.cc:80
AddRFImplementationCmd.hh
AddFUImplementationCmd.hh
HDBEditorModifyCmd.hh
HDB::CachedHDBManager::createNew
static CachedHDBManager & createNew(const std::string &fileName)
Definition: CachedHDBManager.cc:105
FileSystem::fileOfPath
static std::string fileOfPath(const std::string pathName)
Definition: FileSystem.cc:101
GUICommand::Do
virtual bool Do()=0
HDBEditorMainFrame::setHDB
bool setHDB(const std::string &hdbFile)
Definition: HDBEditorMainFrame.cc:252
CommandRegistry::createCommand
GUICommand * createCommand(const int id)
Definition: CommandRegistry.cc:69
AddFUEntryCmd
Definition: AddFUEntryCmd.hh:41
GUICommand.hh
AddOperationImplementationCmd.hh
AddFUImplementationCmd
Definition: AddFUImplementationCmd.hh:41
HDBEditorConstants::COMMAND_ADD_BUS_ENTRY
@ COMMAND_ADD_BUS_ENTRY
Definition: HDBEditorConstants.hh:55
GUICommand
Definition: GUICommand.hh:43
HDBEditorConstants::COMMAND_MODIFY
@ COMMAND_MODIFY
Definition: HDBEditorConstants.hh:59
HDBEditorDeleteCmd.hh
ErrorDialog
Definition: ErrorDialog.hh:42
AddCostFunctionPluginCmd.hh
AddFUEntryCmd.hh
ErrorDialog.hh
HDBEditorMainFrame.hh
HDBEditorConstants::COMMAND_ADD_FU_IMPLEMENTATION
@ COMMAND_ADD_FU_IMPLEMENTATION
Definition: HDBEditorConstants.hh:51
HDBEditorConstants::COMMAND_ABOUT
@ COMMAND_ABOUT
Definition: HDBEditorConstants.hh:62
CommandRegistry
Definition: CommandRegistry.hh:47
HDBEditorDeleteCmd
Definition: HDBEditorDeleteCmd.hh:41
HDBEditorConstants::COMMAND_ADD_RF_IMPLEMENTATION
@ COMMAND_ADD_RF_IMPLEMENTATION
Definition: HDBEditorConstants.hh:52
HDBEditorConstants::COMMAND_ADD_COST_PLUGIN
@ COMMAND_ADD_COST_PLUGIN
Definition: HDBEditorConstants.hh:57
HDB::HDBManager
Definition: HDBManager.hh:82
AddOperationImplementationCmd
Definition: AddOperationImplementationCmd.hh:35
UserManualCmd
Definition: UserManualCmd.hh:40
Exception
Definition: Exception.hh:54
SetCostFunctionPluginCmd
Definition: SetCostFunctionPluginCmd.hh:41
AddRFEntryCmd.hh
HDBEditorMainFrame::commandRegistry_
CommandRegistry * commandRegistry_
Command registry.
Definition: HDBEditorMainFrame.hh:69
CreateHDBCmd
Definition: CreateHDBCmd.hh:43
Exception::errorMessage
std::string errorMessage() const
Definition: Exception.cc:123
AddBusEntryCmd
Definition: AddBusEntryCmd.hh:41
HDBEditorAboutCmd
Definition: HDBEditorAboutCmd.hh:42
CachedHDBManager.hh
HDBEditorMainFrame
Definition: HDBEditorMainFrame.hh:50
HDBEditorConstants::COMMAND_ADD_FU_FROM_ADF
@ COMMAND_ADD_FU_FROM_ADF
Definition: HDBEditorConstants.hh:47
UserManualCmd::COMMAND_ID
static const int COMMAND_ID
Command ID.
Definition: UserManualCmd.hh:58
HDBEditorConstants::COMMAND_ADD_RF_ARCHITECTURE
@ COMMAND_ADD_RF_ARCHITECTURE
Definition: HDBEditorConstants.hh:48
HDBEditorMainFrame::browser_
HDBBrowserWindow * browser_
Definition: HDBEditorMainFrame.hh:72
CreateHDBCmd.hh
HDBEditorConstants::COMMAND_ADD_OPERATION_IMPLEMENTATION
@ COMMAND_ADD_OPERATION_IMPLEMENTATION
Definition: HDBEditorConstants.hh:64
AddOperationImplementationResourceCmd.hh
AddOperationImplementationResourceCmd
Definition: AddOperationImplementationResourceCmd.hh:35
HDBEditorMainFrame::~HDBEditorMainFrame
virtual ~HDBEditorMainFrame()
Definition: HDBEditorMainFrame.cc:199
HDBEditorConstants::COMMAND_DELETE
@ COMMAND_DELETE
Definition: HDBEditorConstants.hh:60
HDBEditorQuitCmd
Definition: HDBEditorQuitCmd.hh:41
HDBEditorConstants::COMMAND_ADD_FU_ENTRY
@ COMMAND_ADD_FU_ENTRY
Definition: HDBEditorConstants.hh:53
WxConversion.hh
SetCostFunctionPluginCmd.hh
AddRFEntryCmd
Definition: AddRFEntryCmd.hh:41
HDBEditorConstants::COMMAND_QUIT
@ COMMAND_QUIT
Definition: HDBEditorConstants.hh:61
HDBEditorConstants::COMMAND_ADD_SOCKET_ENTRY
@ COMMAND_ADD_SOCKET_ENTRY
Definition: HDBEditorConstants.hh:56
HDBEditorMainFrame::browser
HDBBrowserWindow * browser() const
Definition: HDBEditorMainFrame.cc:335
HDBRegistry.hh
HDBBrowserWindow::setHDBManager
void setHDBManager(HDB::CachedHDBManager &manager)
Definition: HDBBrowserWindow.cc:99
UserManualCmd.hh
HDBEditorMainFrame::onCommandEvent
void onCommandEvent(wxCommandEvent &event)
Definition: HDBEditorMainFrame.cc:210
END_EVENT_TABLE
END_EVENT_TABLE() using namespace IDF
AddRFArchitectureCmd.hh
AddCostFunctionPluginCmd
Definition: AddCostFunctionPluginCmd.hh:41
HDBEditorMainFrame::update
void update()
Definition: HDBEditorMainFrame.cc:324
HDB::HDBRegistry::instance
static HDBRegistry & instance()
Definition: HDBRegistry.cc:62
HDBEditorMainFrame::hdb_
HDB::CachedHDBManager * hdb_
Definition: HDBEditorMainFrame.hh:71