OpenASIP  2.0
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"
48 #include "OSEdAddOperationCmd.hh"
49 #include "OSEdOptionsCmd.hh"
50 #include "OSEdSimulateCmd.hh"
51 #include "OSEdBuildCmd.hh"
52 #include "OSEdBuildAllCmd.hh"
53 #include "UserManualCmd.hh"
54 #include "OSEdRemoveModuleCmd.hh"
55 #include "OSEdModifyBehaviorCmd.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 
67 using boost::format;
68 using std::string;
69 
70 BEGIN_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 =
93  logoPath += FileSystem::DIRECTORY_SEPARATOR +
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  */
220 void
221 OSEdMainFrame::onCommandEvent(wxCommandEvent& event) {
222  GUICommand* command = registry_->createCommand(event.GetId());
223  if (command == NULL) {
225  format fmt = texts.text(OSEdTextGenerator::TXT_ERROR_NO_HANDLER);
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  */
270 wxStatusBar*
272  return statusBar_;
273 }
274 
275 /**
276  * Updates the menu bar disabled/enabled states.
277  */
278 void
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 }
OSEdMainFrame::informer
OSEdInformer * informer() const
Definition: OSEdMainFrame.cc:261
GUICommand::setParentWindow
void setParentWindow(wxWindow *view)
Definition: GUICommand.cc:64
OSEdTextGenerator::TXT_MENU_USER_MANUAL
@ TXT_MENU_USER_MANUAL
User manual menu label.
Definition: OSEdTextGenerator.hh:176
OSEdConstants::CMD_QUIT
@ CMD_QUIT
Quit command id.
Definition: OSEdConstants.hh:91
OSEdConstants::APPLICATION_NAME
static const wxString APPLICATION_NAME
The name of the application.
Definition: OSEdConstants.hh:110
FileSystem.hh
OSEdQuitCmd
Definition: OSEdQuitCmd.hh:43
WxConversion::toWxString
static wxString toWxString(const std::string &source)
GUICommand::isEnabled
virtual bool isEnabled()=0
OSEdConstants::CMD_ADD_OPERATION
@ CMD_ADD_OPERATION
Add operation command id.
Definition: OSEdConstants.hh:93
OSEdOptionsCmd
Definition: OSEdOptionsCmd.hh:43
OSEdAboutCmd
Definition: OSEdAboutCmd.hh:43
OSEdAboutCmd.hh
CommandRegistry.hh
OSEdConstants::CMD_MEMORY
@ CMD_MEMORY
Memory command id.
Definition: OSEdConstants.hh:104
OSEdAddModuleCmd
Definition: OSEdAddModuleCmd.hh:43
OSEdConstants::CMD_BUILD
@ CMD_BUILD
Build command id.
Definition: OSEdConstants.hh:98
OSEdConstants::CMD_REMOVE_OPERATION
@ CMD_REMOVE_OPERATION
Remove operation command id.
Definition: OSEdConstants.hh:96
OSEdMainFrame::~OSEdMainFrame
virtual ~OSEdMainFrame()
Definition: OSEdMainFrame.cc:208
OSEdPropertiesCmd.hh
OSEdOptionsCmd.hh
OSEdBuildAllCmd
Definition: OSEdBuildAllCmd.hh:43
OSEdModifyBehaviorCmd.hh
OSEd.hh
OSEdMemoryCmd.hh
OSEdConstants::CMD_PROPERTIES
@ CMD_PROPERTIES
Operation properties command id.
Definition: OSEdConstants.hh:94
OSEdMainFrame::onCommandEvent
void onCommandEvent(wxCommandEvent &event)
Definition: OSEdMainFrame.cc:221
Texts::TextGenerator::text
virtual boost::format text(int textId)
Definition: TextGenerator.cc:94
OSEdInfoView.hh
GUICommand::Do
virtual bool Do()=0
OSEdMainFrame::treeView
OSEdTreeView * treeView() const
Definition: OSEdMainFrame.cc:241
OSEdConstants.hh
CommandRegistry::createCommand
GUICommand * createCommand(const int id)
Definition: CommandRegistry.cc:69
OSEdConstants::CMD_SIMULATE
@ CMD_SIMULATE
Simulate command id.
Definition: OSEdConstants.hh:100
Environment::bitmapsDirPath
static std::string bitmapsDirPath(const std::string &prog)
Definition: Environment.cc:201
GUICommand.hh
OSEdBuildAllCmd.hh
OSEdMainFrame::informer_
OSEdInformer * informer_
Informs listener classes for events that occurs.
Definition: OSEdMainFrame.hh:77
OSEdInformer.hh
OSEdTextGenerator::TXT_MENU_FILE
@ TXT_MENU_FILE
File menu label.
Definition: OSEdTextGenerator.hh:166
GUICommand
Definition: GUICommand.hh:43
OSEdAddModuleCmd.hh
ErrorDialog
Definition: ErrorDialog.hh:42
OSEdSimulateCmd.hh
OSEdConstants::CMD_REMOVE_MODULE
@ CMD_REMOVE_MODULE
Remove module command id.
Definition: OSEdConstants.hh:95
OSEdRemoveOperationCmd
Definition: OSEdRemoveOperationCmd.hh:43
OSEdTreeView
Definition: OSEdTreeView.hh:54
ErrorDialog.hh
EVT_MENU_RANGE
EVT_MENU_RANGE(ProximConstants::COMMAND_FIRST, ProximConstants::COMMAND_LAST, ProximMainFrame::onCommandEvent) EVT_MENU_RANGE(ProximConstants
Definition: ProximMainFrame.cc:91
OSEdRemoveOperationCmd.hh
OSEdTextGenerator::TXT_MENU_MODIFY_PROPERTIES
@ TXT_MENU_MODIFY_PROPERTIES
Modify properties menu label.
Definition: OSEdTextGenerator.hh:170
OSEdMainFrame.hh
Application.hh
OSEdRemoveModuleCmd
Definition: OSEdRemoveModuleCmd.hh:43
OSEdBuildCmd
Definition: OSEdBuildCmd.hh:43
CommandRegistry
Definition: CommandRegistry.hh:47
OSEdInfoView
Definition: OSEdInfoView.hh:47
OSEdTextGenerator::TXT_MENU_ADD_OPERATION
@ TXT_MENU_ADD_OPERATION
Add operation menu label.
Definition: OSEdTextGenerator.hh:167
UserManualCmd
Definition: UserManualCmd.hh:40
Environment.hh
OSEdConstants::CMD_OPTIONS
@ CMD_OPTIONS
Option command id.
Definition: OSEdConstants.hh:102
OSEdTextGenerator::TXT_MENU_ADD_MODULE
@ TXT_MENU_ADD_MODULE
Add module menu label.
Definition: OSEdTextGenerator.hh:169
OSEdModifyBehaviorCmd
Definition: OSEdModifyBehaviorCmd.hh:43
OSEdMainFrame::registry
CommandRegistry * registry() const
Definition: OSEdMainFrame.cc:251
OSEdMainFrame::treeView_
OSEdTreeView * treeView_
Tree view.
Definition: OSEdMainFrame.hh:75
OSEdQuitCmd.hh
OSEdTextGenerator::TXT_MENU_OPTIONS
@ TXT_MENU_OPTIONS
Option menu label.
Definition: OSEdTextGenerator.hh:164
CommandRegistry::nextCommand
GUICommand * nextCommand()
Definition: CommandRegistry.cc:120
OSEdConstants::CMD_ADD_MODULE
@ CMD_ADD_MODULE
Add module command id.
Definition: OSEdConstants.hh:92
FileSystem::DIRECTORY_SEPARATOR
static const std::string DIRECTORY_SEPARATOR
Definition: FileSystem.hh:189
OSEdTextGenerator::TXT_ERROR_NO_HANDLER
@ TXT_ERROR_NO_HANDLER
Error when custom command handler is not found.
Definition: OSEdTextGenerator.hh:153
OSEdTreeView.hh
OSEdMainFrame
Definition: OSEdMainFrame.hh:49
OSEdTextGenerator::TXT_MENU_QUIT
@ TXT_MENU_QUIT
Quit menu label.
Definition: OSEdTextGenerator.hh:165
OSEdTextGenerator::TXT_MENU_TOOLS
@ TXT_MENU_TOOLS
Tools menu label.
Definition: OSEdTextGenerator.hh:174
OSEdTextGenerator::TXT_MENU_HELP
@ TXT_MENU_HELP
Help menu label.
Definition: OSEdTextGenerator.hh:177
OSEdTextGenerator::TXT_MENU_BUILD_ALL
@ TXT_MENU_BUILD_ALL
Build all menu label.
Definition: OSEdTextGenerator.hh:172
OSEdConstants::CMD_ABOUT
@ CMD_ABOUT
About command id.
Definition: OSEdConstants.hh:101
UserManualCmd::COMMAND_ID
static const int COMMAND_ID
Command ID.
Definition: UserManualCmd.hh:58
OSEdTextGenerator::TXT_MENU_REMOVE_MODULE
@ TXT_MENU_REMOVE_MODULE
Remove module menu label.
Definition: OSEdTextGenerator.hh:178
OSEdTextGenerator::instance
static OSEdTextGenerator & instance()
Definition: OSEdTextGenerator.cc:214
OSEdTextGenerator::TXT_MENU_MODIFY_BEHAVIOR
@ TXT_MENU_MODIFY_BEHAVIOR
Modify behavior menu label.
Definition: OSEdTextGenerator.hh:179
OSEdConstants::CMD_BUILD_ALL
@ CMD_BUILD_ALL
Build all command id.
Definition: OSEdConstants.hh:99
OSEdTextGenerator
Definition: OSEdTextGenerator.hh:42
OSEdTextGenerator::TXT_MENU_REMOVE_OPERATION
@ TXT_MENU_REMOVE_OPERATION
Remove operation menu label.
Definition: OSEdTextGenerator.hh:168
WxConversion.hh
GUICommand::id
virtual int id() const =0
CommandRegistry::firstCommand
GUICommand * firstCommand()
Definition: CommandRegistry.cc:104
OSEdBuildCmd.hh
OSEdConstants::LOGO_NAME
static const std::string LOGO_NAME
Name of the logo.
Definition: OSEdConstants.hh:116
OSEdTextGenerator::TXT_MENU_ABOUT
@ TXT_MENU_ABOUT
About menu label.
Definition: OSEdTextGenerator.hh:175
OSEdInformer
Definition: OSEdInformer.hh:47
OSEdRemoveModuleCmd.hh
OSEdAddOperationCmd.hh
OSEdTextGenerator::TXT_MENU_MEMORY
@ TXT_MENU_MEMORY
Memory menu label.
Definition: OSEdTextGenerator.hh:180
OSEdMainFrame::statusBar_
wxStatusBar * statusBar_
Status bar of the main window.
Definition: OSEdMainFrame.hh:79
WxConversion::toString
static std::string toString(const wxString &source)
OSEdTextGenerator.hh
OSEdMainFrame::statusBar
wxStatusBar * statusBar() const
Definition: OSEdMainFrame.cc:271
OSEdMainFrame::updateMenuBar
void updateMenuBar()
Definition: OSEdMainFrame.cc:279
UserManualCmd.hh
OSEdTextGenerator::TXT_MENU_SIMULATE
@ TXT_MENU_SIMULATE
Simulate menu label.
Definition: OSEdTextGenerator.hh:173
OSEdMainFrame::registry_
CommandRegistry * registry_
Command registry.
Definition: OSEdMainFrame.hh:73
OSEdTextGenerator::TXT_MENU_BUILD
@ TXT_MENU_BUILD
Build menu label.
Definition: OSEdTextGenerator.hh:171
END_EVENT_TABLE
END_EVENT_TABLE() using namespace IDF
OSEdConstants::CMD_MODIFY_BEHAVIOR
@ CMD_MODIFY_BEHAVIOR
Modify operation behavior command id.
Definition: OSEdConstants.hh:97
OSEdSimulateCmd
Definition: OSEdSimulateCmd.hh:43
OSEdAddOperationCmd
Definition: OSEdAddOperationCmd.hh:43
OSEdPropertiesCmd
Definition: OSEdPropertiesCmd.hh:43
OSEdMemoryCmd
Definition: OSEdMemoryCmd.hh:43