OpenASIP 2.2
Loading...
Searching...
No Matches
OSEd.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 OSEd.cc
26 *
27 * Definition of OSEd class.
28 *
29 * @author Jussi Nykänen 2004 (nykanen-no.spam-cs.tut.fi)
30 * @note rating: red
31 */
32
33#include <iostream>
34#include <string>
35#include <vector>
36#include <boost/format.hpp>
37
38#include "OSEd.hh"
39#include "OSEdConstants.hh"
41#include "WxConversion.hh"
42#include "ResultDialog.hh"
43#include "OSEdTextGenerator.hh"
44#include "OperationContainer.hh"
45#include "Environment.hh"
46#include "OSEdTreeView.hh"
47#include "FileSystem.hh"
48#include "Application.hh"
49#include "OSEdOptions.hh"
50
51using std::cerr;
52using std::endl;
53using std::string;
54using std::vector;
55using boost::format;
56
57IMPLEMENT_APP(OSEd)
58
59/**
60 * Constructor.
61 */
62OSEd::OSEd() : mainFrame_(NULL), options_(NULL) {
63}
64
65/**
66 * Destructor.
67 */
70
71/**
72 * Initializes the application.
73 *
74 * Creates mainframe as well as reads the configure file.
75 *
76 * @return True.
77 */
78bool
80
82
83 mainFrame_ = new OSEdMainFrame(_T("Operation Set Editor"),
84 wxPoint(50, 50), wxSize(900, 500));
85
87
88 options_ = new OSEdOptions();
89 OSEdOptionsSerializer serializer;
90
92 serializer.setSourceFile(confFile);
93
94 try {
95 options_->loadState(serializer.readState());
96 } catch (const Exception& e) {
97 cerr << "Config file not found, default options will be used." << endl
98 << "OseD may use the editor in your $VISUAL"
99 << " environmental variable." << endl
100 << "If this points to some non-graphical editor, "
101 << "please change the editor from settings." << endl;
103 }
104
106
107 OSEdTreeView* treeView = mainFrame_->treeView();
108 vector<string> results = treeView->constructTree();
109 // if some errors occurred while buildin the tree view, error message is
110 // shown
111 if (results.size() > 0) {
113 ResultDialog result(mainFrame_, results, fmt.str());
114 result.ShowModal();
115 }
116
117 mainFrame_->Show(true);
118 SetTopWindow(mainFrame_);
119
120 return true;
121}
122
123/**
124 * Deletes the application level dynamic objects not handled by wxWindows.
125 *
126 * This function is called when application is about to exit.
127 *
128 * @return 0.
129 */
130int
134 delete options_;
135 options_ = NULL;
136 return 0;
137}
138
139/**
140 * Returns the main frame of the application.
141 *
142 * @return The main frame of the application.
143 */
146 return mainFrame_;
147}
148
149/**
150 * Returns the options of the application.
151 *
152 * @return The options of the application.
153 */
156 return options_;
157}
158
159/**
160 * Creates the default options and writes them to the file.
161 */
162void
165 OSEdOptionsSerializer serializer;
166 string confFile =
168 serializer.setDestinationFile(confFile);
169 try {
170 serializer.writeState(options_->saveState());
171 } catch (const Exception& e) {
172 cerr << "Writing options failed: " << e.errorMessage() << endl;
173 }
174}
175
static void initialize()
static TCEString userConfPath(const std::string &fileName)
static TCEString confPath(const std::string &fileName)
std::string errorMessage() const
Definition Exception.cc:123
static const std::string DEFAULT_EDITOR
Default editor name.
static const std::string CONF_FILE_NAME
Configuration file name.
OSEdTreeView * treeView() const
virtual ObjectState * readState()
void setSourceFile(const std::string &fileName)
virtual void writeState(const ObjectState *state)
void setDestinationFile(const std::string &fileName)
void setEditor(const std::string &editor)
virtual void loadState(const ObjectState *state)
ObjectState * saveState() const
static OSEdTextGenerator & instance()
@ TXT_XML_RESULT_DIALOG_TITLE
XML result dialog title.
std::vector< std::string > constructTree()
Definition OSEd.hh:47
OSEdMainFrame * mainFrame_
Main window of the application.
Definition OSEd.hh:67
virtual int OnExit()
Definition OSEd.cc:131
void createDefaultOptions()
Definition OSEd.cc:163
OSEdOptions * options() const
Definition OSEd.cc:155
OSEdMainFrame * mainFrame() const
Definition OSEd.cc:145
OSEdOptions * options_
Options of the application.
Definition OSEd.hh:69
virtual bool OnInit()
Definition OSEd.cc:79
virtual ~OSEd()
Definition OSEd.cc:68
virtual boost::format text(int textId)
static char ** toCStringArray(size_t elements, wxChar **source)