OpenASIP 2.2
Loading...
Searching...
No Matches
OSEdMainFrame.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 OSEdMainFrame.cc
26 *
27 * Definition of OSEdMainFrame class.
28 *
29 * @author Jussi Nykänen 2004 (nykanen-no.spam-cs.tut.fi)
30 * @note rating: red
31 */
32
33#include <wx/bitmap.h>
34#include <wx/imagpng.h>
35#include <boost/format.hpp>
36#include <string>
37
38#include "OSEdMainFrame.hh"
39#include "OSEdTreeView.hh"
40#include "OSEdInfoView.hh"
41#include "OSEdInformer.hh"
42#include "OSEdConstants.hh"
43#include "GUICommand.hh"
44#include "OSEdQuitCmd.hh"
45#include "OSEdAboutCmd.hh"
46#include "OSEdPropertiesCmd.hh"
47#include "OSEdAddModuleCmd.hh"
49#include "OSEdOptionsCmd.hh"
50#include "OSEdSimulateCmd.hh"
51#include "OSEdBuildCmd.hh"
52#include "OSEdBuildAllCmd.hh"
53#include "UserManualCmd.hh"
57#include "OSEdMemoryCmd.hh"
58#include "OSEd.hh"
59#include "ErrorDialog.hh"
60#include "Application.hh"
61#include "OSEdTextGenerator.hh"
62#include "WxConversion.hh"
63#include "CommandRegistry.hh"
64#include "Environment.hh"
65#include "FileSystem.hh"
66
67using boost::format;
68using std::string;
69
70BEGIN_EVENT_TABLE(OSEdMainFrame, wxFrame)
74
75/**
76 * Constructor.
77 *
78 * @param title Window title.
79 * @param pos Window position.
80 * @param size Window size.
81 */
83 const wxString& title,
84 const wxPoint& pos,
85 const wxSize& size) : wxFrame((wxFrame *)NULL, -1, title, pos, size),
86 registry_(NULL), treeView_(NULL), informer_(NULL) {
87
88 wxImage::AddHandler(new wxPNGHandler);
89 // set logo
90 string logoPath =
95 wxBitmap bmp;
96 bmp.LoadFile(WxConversion::toWxString(logoPath), wxBITMAP_TYPE_PNG);
97 wxIcon logo;
98 logo.CopyFromBitmap(bmp);
99 SetIcon(logo);
100
102
103 // create default menu bar
104 wxMenu* menu = new wxMenu;
105 format fmt = texts.text(OSEdTextGenerator::TXT_MENU_OPTIONS);
106 menu->Append(
109 menu->Append(OSEdConstants::CMD_QUIT, WxConversion::toWxString(fmt.str()));
110
111 wxMenuBar* menuBar = new wxMenuBar;
113 menuBar->Append(menu, WxConversion::toWxString(fmt.str()));
114
115 menu = new wxMenu;
117 menu->Append(
119
121 menu->Append(
123 WxConversion::toWxString(fmt.str()));
124
126 menu->Append(
128
130 menu->Append(
132
134 menu->Append(
136
138 menu->Append(
140 WxConversion::toWxString(fmt.str()));
141
143 menu->Append(
145
147 menu->Append(
149
151 menu->Append(
153
155 menu->Append(
157
159 menuBar->Append(menu, WxConversion::toWxString(fmt.str()));
160
161 menu = new wxMenu;
163 menu->Append(
165
167 menu->Append(
169
171 menuBar->Append(menu, WxConversion::toWxString(fmt.str()));
172
173 SetMenuBar(menuBar);
174 statusBar_ = CreateStatusBar();
175
176 // add all custom commands to command registry
177 registry_ = new CommandRegistry();
178 registry_->addCommand(new OSEdQuitCmd());
179 registry_->addCommand(new OSEdAboutCmd());
180 registry_->addCommand(new OSEdPropertiesCmd());
181 registry_->addCommand(new OSEdAddModuleCmd());
182 registry_->addCommand(new OSEdAddOperationCmd());
183 registry_->addCommand(new OSEdSimulateCmd());
184 registry_->addCommand(new OSEdOptionsCmd());
185 registry_->addCommand(new OSEdBuildCmd());
186 registry_->addCommand(new OSEdBuildAllCmd());
187 registry_->addCommand(new UserManualCmd());
188 registry_->addCommand(new OSEdRemoveModuleCmd());
189 registry_->addCommand(new OSEdModifyBehaviorCmd());
190 registry_->addCommand(new OSEdRemoveOperationCmd());
191 registry_->addCommand(new OSEdMemoryCmd());
192
193 // create splitted window
194 wxSplitterWindow* splitter = new wxSplitterWindow(
195 this, -1, wxPoint(0, 0), wxSize(900, 500), wxSP_3D);
196
197 OSEdInfoView* infoView = new OSEdInfoView(splitter);
198 treeView_ = new OSEdTreeView(splitter, infoView);
199
200 splitter->SplitVertically(treeView_, infoView);
201
202 informer_ = new OSEdInformer();
203}
204
205/**
206 * Destructor.
207 */
209 delete registry_;
210 registry_ = NULL;
211 delete informer_;
212 informer_ = NULL;
213}
214
215/**
216 * Handles menu events.
217 *
218 * @param event Event to be handled.
219 */
220void
221OSEdMainFrame::onCommandEvent(wxCommandEvent& event) {
222 GUICommand* command = registry_->createCommand(event.GetId());
223 if (command == NULL) {
226 ErrorDialog dialog(this, WxConversion::toWxString(fmt.str()));
227 dialog.ShowModal();
228 return;
229 }
230 command->setParentWindow(this);
231 command->Do();
232 delete command;
233}
234
235/**
236 * Returns pointer to the tree view.
237 *
238 * @return Pointer to the tree view.
239 */
242 return treeView_;
243}
244
245/**
246 * Returns the command registry.
247 *
248 * @return the command registry.
249 */
252 return registry_;
253}
254
255/**
256 * Returns informer instance.
257 *
258 * @return The informer instance.
259 */
262 return informer_;
263}
264
265/**
266 * Returns status bar of the frame.
267 *
268 * @return Status bar.
269 */
270wxStatusBar*
272 return statusBar_;
273}
274
275/**
276 * Updates the menu bar disabled/enabled states.
277 */
278void
280 wxMenuBar* menubar = GetMenuBar();
281 GUICommand* command = registry_->firstCommand();
282 while (command != NULL) {
283 if (menubar->FindItem(command->id()) != NULL) {
284 if (command->isEnabled()) {
285 menubar->Enable(command->id(), true);
286 } else {
287 menubar->Enable(command->id(), false);
288 }
289 }
290 command = registry_->nextCommand();
291 }
292}
END_EVENT_TABLE() using namespace IDF
EVT_MENU_RANGE(ProximConstants::COMMAND_FIRST, ProximConstants::COMMAND_LAST, ProximMainFrame::onCommandEvent) EVT_MENU_RANGE(ProximConstants
GUICommand * firstCommand()
GUICommand * nextCommand()
GUICommand * createCommand(const int id)
static std::string bitmapsDirPath(const std::string &prog)
static const std::string DIRECTORY_SEPARATOR
virtual bool Do()=0
void setParentWindow(wxWindow *view)
Definition GUICommand.cc:64
virtual int id() const =0
virtual bool isEnabled()=0
static const std::string LOGO_NAME
Name of the logo.
static const wxString APPLICATION_NAME
The name of the application.
@ CMD_MODIFY_BEHAVIOR
Modify operation behavior command id.
@ CMD_REMOVE_MODULE
Remove module command id.
@ CMD_OPTIONS
Option command id.
@ CMD_PROPERTIES
Operation properties command id.
@ CMD_ADD_OPERATION
Add operation command id.
@ CMD_ABOUT
About command id.
@ CMD_BUILD_ALL
Build all command id.
@ CMD_MEMORY
Memory command id.
@ CMD_BUILD
Build command id.
@ CMD_SIMULATE
Simulate command id.
@ CMD_ADD_MODULE
Add module command id.
@ CMD_REMOVE_OPERATION
Remove operation command id.
@ CMD_QUIT
Quit command id.
OSEdTreeView * treeView_
Tree view.
OSEdInformer * informer() const
CommandRegistry * registry_
Command registry.
wxStatusBar * statusBar_
Status bar of the main window.
virtual ~OSEdMainFrame()
void onCommandEvent(wxCommandEvent &event)
OSEdTreeView * treeView() const
OSEdInformer * informer_
Informs listener classes for events that occurs.
CommandRegistry * registry() const
wxStatusBar * statusBar() const
static OSEdTextGenerator & instance()
@ TXT_MENU_HELP
Help menu label.
@ TXT_MENU_SIMULATE
Simulate menu label.
@ TXT_MENU_OPTIONS
Option menu label.
@ TXT_MENU_TOOLS
Tools menu label.
@ TXT_MENU_USER_MANUAL
User manual menu label.
@ TXT_MENU_REMOVE_OPERATION
Remove operation menu label.
@ TXT_MENU_BUILD
Build menu label.
@ TXT_MENU_MEMORY
Memory menu label.
@ TXT_MENU_ADD_OPERATION
Add operation menu label.
@ TXT_MENU_ADD_MODULE
Add module menu label.
@ TXT_MENU_BUILD_ALL
Build all menu label.
@ TXT_MENU_MODIFY_PROPERTIES
Modify properties menu label.
@ TXT_MENU_REMOVE_MODULE
Remove module menu label.
@ TXT_MENU_MODIFY_BEHAVIOR
Modify behavior menu label.
@ TXT_ERROR_NO_HANDLER
Error when custom command handler is not found.
@ TXT_MENU_ABOUT
About menu label.
@ TXT_MENU_QUIT
Quit menu label.
@ TXT_MENU_FILE
File menu label.
virtual boost::format text(int textId)
static const int COMMAND_ID
Command ID.
static wxString toWxString(const std::string &source)
static std::string toString(const wxString &source)