OpenASIP 2.2
Loading...
Searching...
No Matches
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"
53#include "HDBEditorQuitCmd.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
69BEGIN_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 */
201
202
203
204/**
205 * Handles menu and toolbar events.
206 *
207 * @param event Event to handle.
208 */
209void
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 */
230void
231HDBEditorMainFrame::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 */
251bool
252HDBEditorMainFrame::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 */
282bool
283HDBEditorMainFrame::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 */
318
319
320/**
321 * Updates the HDB window.
322 */
323void
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}
END_EVENT_TABLE() using namespace IDF
GUICommand * createCommand(const int id)
std::string errorMessage() const
Definition Exception.cc:123
static std::string fileOfPath(const std::string pathName)
virtual bool Do()=0
void setParentWindow(wxWindow *view)
Definition GUICommand.cc:64
virtual bool isEnabled()=0
void setHDBManager(HDB::CachedHDBManager &manager)
HDB::HDBManager * hdbManager()
CommandRegistry * commandRegistry_
Command registry.
void onCommandEvent(wxCommandEvent &event)
bool setHDB(const std::string &hdbFile)
bool createHDB(const std::string &filePath)
HDB::CachedHDBManager * hdb_
HDBBrowserWindow * browser() const
void onUpdateUI(wxUpdateUIEvent &event)
HDBBrowserWindow * browser_
static CachedHDBManager & createNew(const std::string &fileName)
static HDBRegistry & instance()
CachedHDBManager & hdb(const std::string fileName)
static const int COMMAND_ID
Command ID.
static wxString toWxString(const std::string &source)