OpenASIP 2.2
Loading...
Searching...
No Matches
ProDe.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 ProDe.cc
26 *
27 * Implementation of the ProDe class.
28 *
29 * @author Veli-Pekka Jääskeläinen (vjaaskel-no.spam-cs.tut.fi)
30 * @note rating: red
31 */
32
33#include <iostream>
34#include <string>
35#include <wx/docmdi.h>
36#include <wx/mdi.h>
37#include <wx/docview.h>
38#include <wx/cmdline.h>
39#include <wx/imagpng.h>
40#include <wx/splash.h>
41#include <boost/format.hpp>
42
43#include "ProDe.hh"
44#include "KeyboardShortcut.hh"
45#include "ToolbarButton.hh"
46#include "ProDeOptions.hh"
47#include "MDFView.hh"
48#include "MDFDocument.hh"
49#include "MainFrame.hh"
50#include "CommandRegistry.hh"
51#include "ProDeConstants.hh"
52#include "Conversion.hh"
54#include "WxConversion.hh"
55#include "ErrorDialog.hh"
56#include "FileSystem.hh"
57#include "Environment.hh"
58#include "ProDeClipboard.hh"
59#include "ProDeTextGenerator.hh"
60#include "UserManualCmd.hh"
61#include "ObjectState.hh"
62
63using std::string;
64using std::cerr;
65using std::endl;
66
67IMPLEMENT_APP(ProDe)
68
69/**
70 * The constructor.
71 */
72ProDe::ProDe(): docManager_((wxDocManager*)NULL), options_(NULL) {
73}
74
75
76
77/**
78 * Parses the command line and initializes the editor accordingly.
79 *
80 * Called only once by wxWindows when the program is executed. Command
81 * line is parsed using wxCmdLineParser class. If no script is provided
82 * with a "-s" option, main frame is created and set as the main
83 * window. An instance of the wxDocManager will be created to handle
84 * document templates, if the editor is ran in interactive mode.
85 *
86 * @return true if application was succesfully initialized, false otherwise.
87 */
88bool
90
92
93 // parse command line
94 static const wxCmdLineEntryDesc cmdLineDesc[] = {
95
96#if wxCHECK_VERSION(3, 0, 0)
97 { wxCMD_LINE_PARAM, "", "", "file", wxCMD_LINE_VAL_STRING,
98 wxCMD_LINE_PARAM_OPTIONAL | wxCMD_LINE_PARAM_MULTIPLE },
99
100 { wxCMD_LINE_NONE, "", "", "", wxCMD_LINE_VAL_STRING, 0}
101#else
102 { wxCMD_LINE_PARAM, _T(""), _T(""), _T("file"), wxCMD_LINE_VAL_STRING,
103 wxCMD_LINE_PARAM_OPTIONAL | wxCMD_LINE_PARAM_MULTIPLE },
104
105 { wxCMD_LINE_NONE, _T(""), _T(""), _T(""), wxCMD_LINE_VAL_STRING, 0}
106#endif
107
108 };
109
110 wxCmdLineParser parser(cmdLineDesc, argc, argv);
111 int parserStatus = parser.Parse();
112 if (parserStatus != 0) {
113 return false;
114 }
115
116 // create a document template for ADF files.
117 docManager_ = new wxDocManager;
118 (void) new wxDocTemplate((wxDocManager*) docManager_,
119 _T("Architecture Definition"),
120 _T("*.adf;*.xml;*.cfg"), _T(""),
121 _T("adf"), _T("Architecture Definition File"),
122 _T("ADF View"), CLASSINFO(MDFDocument),
123 CLASSINFO(MDFView));
124
125 // Dummy doc template for cfgs.
126 // Older versions of wxWidgets don't handle the *.adf;*.cfg file filter
127 // correctly and .cfgs don't get associated to the correct document class
128 // without this invisble template.
129 (void) new wxDocTemplate((wxDocManager*) docManager_,
130 _T("Processor Configuration"),
131 _T("*.cfg"), _T(""),
132 _T("cfg"), _T("Architecture Definition File"),
133 _T("ADF View"), CLASSINFO(MDFDocument),
134 CLASSINFO(MDFView), wxTEMPLATE_INVISIBLE);
135
136 // Dummy doc template for xmls.
137 (void) new wxDocTemplate((wxDocManager*) docManager_,
138 _T("Architecture Definition File"),
139 _T("*.xml"), _T(""),
140 _T("xml"), _T("Architecture Definition File"),
141 _T("ADF View"), CLASSINFO(MDFDocument),
142 CLASSINFO(MDFView), wxTEMPLATE_INVISIBLE);
143
144 // create a registry of commands
146
147 // load image handler for pngs
148 wxImage::AddHandler(new wxPNGHandler);
149
150 // set configurations
151 string configFile = Environment::confPath("ProDe.conf");
152
153 // Name of the XML Schema for options file.
154 string schemaFile =
156 FileSystem::DIRECTORY_SEPARATOR + "confschema.xsd";
157
159 reader.setSourceFile(configFile);
160 reader.setSchemaFile(schemaFile);
161 reader.setUseSchema(true);
162 bool erroneousOptions = false;
163 try {
164 ObjectState* optionsState = reader.readState();
165 options_ = new ProDeOptions(optionsState);
166 delete optionsState;
168 options_->setFileName(configFile);
169 } catch (Exception& e) {
170 cerr << e.errorMessage() << endl
171 << "Default options will be used." << endl;
172 erroneousOptions = true;
173 }
174
175 if (erroneousOptions) {
177 } else {
179 }
180
181 // create the main frame window
182 mainFrame_ =
183 new MainFrame((wxDocManager*) docManager_, (wxFrame*) NULL,
185 wxPoint(options_->xPosition(), options_->yPosition()),
186 wxSize(options_->windowWidth(),
188 wxDEFAULT_FRAME_STYLE | wxNO_FULL_REPAINT_ON_RESIZE);
189
190 mainFrame_->Show(TRUE);
191 SetTopWindow(mainFrame_);
192
193 // open documents given in command line
194 for (unsigned int i = 0; i < parser.GetParamCount(); i++) {
195 wxString file = parser.GetParam(i);
196 wxDocument* doc = docManager_->CreateDocument(file, wxDOC_SILENT);
197 if (doc == NULL) {
198 string fileName = WxConversion::toString(file);
199 if (FileSystem::fileExists(fileName)) {
200 std::cerr << "Improper file '"
201 << fileName
202 << "' couldn't be opened."
203 << std::endl;
204 } else {
205 std::cerr << "Cannot open file '"
206 << fileName
207 << "'."
208 << std::endl;
209 }
210 }
211 }
212
213 //mainFrame_->updateMenubar();
214 //mainFrame_->updateToolbar();
215
216 return true;
217}
218
219
220/**
221 * Deletes the application level dynamic objects not handled by wxWindows.
222 *
223 * Called when the editor is about to exit, and all application
224 * windows are already destroyed.
225 */
226int
230 delete docManager_;
231 delete options_;
232 return 0;
233}
234
235
236/**
237 * Returns pointer to the main frame of the editor.
238 *
239 * @return Pointer to the main frame of the editor.
240 */
243 return mainFrame_;
244}
245
246
247/**
248 * Returns editor options.
249 *
250 * @return Current editor options.
251 */
254 return options_;
255}
256
257
258/**
259 * Sets the editor options, and deletes old options.
260 *
261 * @param options ProDeOptions to set as new options.
262 */
263void
265 if (options_ != NULL) {
266 delete options_;
267 }
270}
271
272
273/**
274 * Creates default options.
275 */
276void
278
279 // kb shortcut: ctrl-N = New Document
281 ProDeConstants::CMD_NAME_NEW_DOC, 0, true, false, int('N'));
282
283 // kb shortcut: ctrl-O = Open Document
285 ProDeConstants::CMD_NAME_OPEN_DOC, 0, true, false, int('O'));
286
287 // kb shortcut: ctrl-S = Save Document
289 ProDeConstants::CMD_NAME_SAVE_DOC, 0, true, false, int('S'));
290
291 // kb shortcut: ctrl-W = close document
292 KeyboardShortcut* scClose = new KeyboardShortcut(
293 ProDeConstants::CMD_NAME_CLOSE_DOC, 0, true, false, int('W'));
294
295 // kb shortcut: ctrl-P = print document
296 KeyboardShortcut* scPrint = new KeyboardShortcut(
297 ProDeConstants::CMD_NAME_PRINT, 0, true, false, int('P'));
298
299 // kb shortcut: ctrl-Q = quit
301 ProDeConstants::CMD_NAME_QUIT, 0, true, false, int('Q'));
302
303
304 // kb shortcut: ctrl-C = copy
306 ProDeConstants::CMD_NAME_COPY, 0, true, false, int('C'));
307
308 // kb shortcut: ctrl-X = cut
310 ProDeConstants::CMD_NAME_CUT, 0, true, false, int('X'));
311
312 // kb shortcut: ctrl-V = paste
313 KeyboardShortcut* scPaste = new KeyboardShortcut(
314 ProDeConstants::CMD_NAME_PASTE, 0, true, false, int('V'));
315
316 // kb shortcut: ctrl-Z = undo
318 ProDeConstants::CMD_NAME_UNDO, 0, true, false, int('Z'));
319
320 // kb shortcut: ctrl-Y = redo
322 ProDeConstants::CMD_NAME_REDO, 0, true, false, int('Y'));
323
324 // kb shortcut: F1 = Help
325 KeyboardShortcut* scUserManual = new KeyboardShortcut(
326 UserManualCmd::COMMAND_NAME, 1, false, false, 0);
327
328 // toolbar buttons
329 ToolbarButton* buttonNew = new ToolbarButton(
331
332 ToolbarButton* buttonOpen = new ToolbarButton(
334
335 ToolbarButton* buttonSave = new ToolbarButton(
337
338 ToolbarButton* buttonDelete = new ToolbarButton(
340
341 ToolbarButton* buttonModify = new ToolbarButton(
343
344 ToolbarButton* buttonZoomIn = new ToolbarButton(
346
347 ToolbarButton* buttonZoomOut = new ToolbarButton(
349
350 ToolbarButton* buttonZoomFit = new ToolbarButton(
352
353 ToolbarButton* buttonOptions = new ToolbarButton(
355
356 ToolbarButton* buttonHelp = new ToolbarButton(
358
359 options_ = new ProDeOptions();
360
372 options_->addKeyboardShortcut(scUserManual);
373
374 options_->addToolbarButton(buttonNew);
375 options_->addToolbarButton(buttonOpen);
376 options_->addToolbarButton(buttonSave);
377 options_->addToolbarButton(buttonDelete);
378 options_->addToolbarButton(buttonModify);
379 options_->addToolbarButton(buttonZoomIn);
380 options_->addToolbarButton(buttonZoomOut);
381 options_->addToolbarButton(buttonZoomFit);
382 options_->addToolbarButton(buttonOptions);
383 options_->addToolbarButton(buttonHelp);
387
388 // default toolbar layout and visibility
391
392 // default undo levels
394
395 // set MainFrame size and position
396 options_->setFullScreen(false);
397 options_->setWindowSize(600, 500);
398 options_->setWindowPosition(100, 50);
399}
400
401
402/**
403 * Returns command registry of the editor.
404 */
407 return commandRegistry_;
408}
409
410
411
412/**
413 * Returns document manager of the editor.
414 */
415wxDocManager*
417 return docManager_;
418}
419
420
421/**
422 * Returns path of toolbar icon files.
423 *
424 * @return ProDe icon files path.
425 */
426string
428 string path = Environment::bitmapsDirPath("ProDe") +
430 return path;
431}
const string TRUE
Value used for true in attribute and element values.
static MachInfoCmdLineOptions options
Definition MachInfo.cc:46
static void initialize()
static std::string bitmapsDirPath(const std::string &prog)
static std::string dataDirPath(const std::string &prog)
static TCEString confPath(const std::string &fileName)
std::string errorMessage() const
Definition Exception.cc:123
static const std::string DIRECTORY_SEPARATOR
static bool fileExists(const std::string fileName)
int windowWidth() const
void addKeyboardShortcut(KeyboardShortcut *shortcut)
void setToolbarVisibility(bool visible)
void addToolbarButton(ToolbarButton *button)
void setFullScreen(bool fullScreen)
void setWindowPosition(int x, int y)
int yPosition() const
void addSeparator(int position)
int xPosition() const
virtual void validate() const
int windowHeight() const
void clearModified()
@ BOTH
Buttons contains text and icon.
Definition GUIOptions.hh:67
void setFileName(const std::string &fileName)
void setToolbarLayout(ToolbarLayout layout)
void setWindowSize(int width, int height)
void createToolbar()
Definition MainFrame.cc:746
static void destroy()
static const std::string CMD_NAME_REDO
Command name for the "Redo" command.
static const std::string CMD_NAME_EDIT_OPTIONS
Command name for the "Edit Options" command.
static const std::string CMD_NAME_OPEN_DOC
Command name for the "Open Document" command.
static const std::string CMD_NAME_NEW_DOC
Command name for the "New Document" command.
static const wxString EDITOR_NAME
Full name of the Editor.
static const std::string CMD_NAME_SAVE_DOC
Command name for the "Save Document" command.
static const std::string CMD_NAME_UNDO
Command name for the "Undo" command.
static const std::string CMD_NAME_ZOOM_FIT_WIN
Command name for the "Fit Window" command.
static const std::string CMD_NAME_COPY
Command name for the "Copy" command.
static const std::string CMD_NAME_ZOOM_OUT
Command name for the "Zoom Out" command.
static const std::string CMD_NAME_PASTE
Command name for the "Paste" command.
static const std::string CMD_NAME_ZOOM_IN
Command name for the "Zoom In" command.
static const std::string CMD_NAME_QUIT
Command name for the "Quit" command.
static const std::string CMD_NAME_CUT
Command name for the "Cut" command.
static const std::string CMD_NAME_CLOSE_DOC
Command name for the "Close Document" command.
static const std::string CMD_NAME_MODIFY_COMP
Command name for the "Modify Component" command.
static const std::string CMD_NAME_PRINT
Command name for the "Print" command.
static const std::string CMD_NAME_DELETE_COMP
Command name for the "Delete Component" command.
void setUndoStackSize(int size)
Definition ProDe.hh:54
int OnExit()
Definition ProDe.cc:227
void createDefaultOptions()
Definition ProDe.cc:277
MainFrame * mainFrame() const
Definition ProDe.cc:242
ProDeOptions * options_
editor options
Definition ProDe.hh:74
wxDocManager * docManager() const
Definition ProDe.cc:416
wxDocManager * docManager_
Manages multiple documents.
Definition ProDe.hh:70
MainFrame * mainFrame_
Main frame of the application.
Definition ProDe.hh:72
void setOptions(ProDeOptions *options)
Definition ProDe.cc:264
CommandRegistry * commandRegistry_
editor command registry
Definition ProDe.hh:76
static std::string bitmapsDirPath()
Definition ProDe.cc:427
bool OnInit()
Definition ProDe.cc:89
CommandRegistry * commandRegistry() const
Definition ProDe.cc:406
ProDeOptions * options() const
Definition ProDe.cc:253
static const std::string COMMAND_NAME
Command name string.
static char ** toCStringArray(size_t elements, wxChar **source)
static std::string toString(const wxString &source)
void setUseSchema(bool useSchema)
void setSchemaFile(const std::string &fileName)
void setSourceFile(const std::string &fileName)