OpenASIP
2.0
src
codesign
osal
OSEd
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
"
40
#include "
OSEdOptionsSerializer.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
51
using
std::cerr;
52
using
std::endl;
53
using
std::string;
54
using
std::vector;
55
using
boost::format;
56
57
IMPLEMENT_APP(
OSEd
)
58
59
/**
60
* Constructor.
61
*/
62
OSEd
::
OSEd
() : mainFrame_(NULL), options_(NULL) {
63
}
64
65
/**
66
* Destructor.
67
*/
68
OSEd::~OSEd
() {
69
}
70
71
/**
72
* Initializes the application.
73
*
74
* Creates mainframe as well as reads the configure file.
75
*
76
* @return True.
77
*/
78
bool
79
OSEd::OnInit
() {
80
81
Application::initialize
(argc,
WxConversion::toCStringArray
(argc, argv));
82
83
mainFrame_
=
new
OSEdMainFrame
(_T(
"Operation Set Editor"
),
84
wxPoint(50, 50), wxSize(900, 500));
85
86
mainFrame_
->
updateMenuBar
();
87
88
options_
=
new
OSEdOptions
();
89
OSEdOptionsSerializer
serializer;
90
91
string
confFile =
Environment::confPath
(
OSEdConstants::CONF_FILE_NAME
);
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;
102
createDefaultOptions
();
103
}
104
105
OSEdTextGenerator
& texts =
OSEdTextGenerator::instance
();
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) {
112
format fmt = texts.
text
(
OSEdTextGenerator::TXT_XML_RESULT_DIALOG_TITLE
);
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
*/
130
int
131
OSEd::OnExit
() {
132
OSEdTextGenerator::destroy
();
133
OperationContainer::destroy
();
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
*/
144
OSEdMainFrame
*
145
OSEd::mainFrame
()
const
{
146
return
mainFrame_
;
147
}
148
149
/**
150
* Returns the options of the application.
151
*
152
* @return The options of the application.
153
*/
154
OSEdOptions
*
155
OSEd::options
()
const
{
156
return
options_
;
157
}
158
159
/**
160
* Creates the default options and writes them to the file.
161
*/
162
void
163
OSEd::createDefaultOptions
() {
164
options_
->
setEditor
(
OSEdConstants::DEFAULT_EDITOR
);
165
OSEdOptionsSerializer
serializer;
166
string
confFile =
167
Environment::userConfPath
(
OSEdConstants::CONF_FILE_NAME
);
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
OSEdOptions::setEditor
void setEditor(const std::string &editor)
Definition:
OSEdOptions.cc:69
FileSystem.hh
OSEdOptionsSerializer::writeState
virtual void writeState(const ObjectState *state)
Definition:
OSEdOptionsSerializer.cc:55
OSEdOptions::saveState
ObjectState * saveState() const
Definition:
OSEdOptions.cc:100
OSEd::mainFrame
OSEdMainFrame * mainFrame() const
Definition:
OSEd.cc:145
OSEdTextGenerator::TXT_XML_RESULT_DIALOG_TITLE
@ TXT_XML_RESULT_DIALOG_TITLE
XML result dialog title.
Definition:
OSEdTextGenerator.hh:117
OSEdTextGenerator::destroy
static void destroy()
Definition:
OSEdTextGenerator.cc:225
OSEd.hh
Texts::TextGenerator::text
virtual boost::format text(int textId)
Definition:
TextGenerator.cc:94
OSEdMainFrame::treeView
OSEdTreeView * treeView() const
Definition:
OSEdMainFrame.cc:241
ResultDialog.hh
OSEdConstants.hh
Environment::userConfPath
static TCEString userConfPath(const std::string &fileName)
Definition:
Environment.cc:303
OSEd
Definition:
OSEd.hh:47
OSEdOptionsSerializer::readState
virtual ObjectState * readState()
Definition:
OSEdOptionsSerializer.cc:71
OSEdTreeView
Definition:
OSEdTreeView.hh:54
OSEdConstants::DEFAULT_EDITOR
static const std::string DEFAULT_EDITOR
Default editor name.
Definition:
OSEdConstants.hh:85
OSEd::OnInit
virtual bool OnInit()
Definition:
OSEd.cc:79
Application.hh
OperationContainer::destroy
static void destroy()
Definition:
OperationContainer.cc:280
OSEd::options
OSEdOptions * options() const
Definition:
OSEd.cc:155
ResultDialog
Definition:
ResultDialog.hh:44
Environment.hh
OSEdOptionsSerializer::setDestinationFile
void setDestinationFile(const std::string &fileName)
Definition:
OSEdOptionsSerializer.cc:99
OSEdOptionsSerializer
Definition:
OSEdOptionsSerializer.hh:44
Exception
Definition:
Exception.hh:54
OSEd::mainFrame_
OSEdMainFrame * mainFrame_
Main window of the application.
Definition:
OSEd.hh:67
OSEd::OnExit
virtual int OnExit()
Definition:
OSEd.cc:131
Exception::errorMessage
std::string errorMessage() const
Definition:
Exception.cc:123
OSEd::~OSEd
virtual ~OSEd()
Definition:
OSEd.cc:68
OSEdTreeView.hh
OSEdMainFrame
Definition:
OSEdMainFrame.hh:49
Environment::confPath
static TCEString confPath(const std::string &fileName)
Definition:
Environment.cc:277
OSEdOptions::loadState
virtual void loadState(const ObjectState *state)
Definition:
OSEdOptions.cc:79
OSEd::options_
OSEdOptions * options_
Options of the application.
Definition:
OSEd.hh:69
Application::initialize
static void initialize()
Definition:
Application.cc:99
OSEdOptionsSerializer::setSourceFile
void setSourceFile(const std::string &fileName)
Definition:
OSEdOptionsSerializer.cc:89
OSEdOptionsSerializer.hh
OSEdTextGenerator::instance
static OSEdTextGenerator & instance()
Definition:
OSEdTextGenerator.cc:214
OSEdTextGenerator
Definition:
OSEdTextGenerator.hh:42
OSEdTreeView::constructTree
std::vector< std::string > constructTree()
Definition:
OSEdTreeView.cc:90
WxConversion.hh
OSEdOptions.hh
OSEdOptions
Definition:
OSEdOptions.hh:46
OSEdTextGenerator.hh
OSEdMainFrame::updateMenuBar
void updateMenuBar()
Definition:
OSEdMainFrame.cc:279
OSEdConstants::CONF_FILE_NAME
static const std::string CONF_FILE_NAME
Configuration file name.
Definition:
OSEdConstants.hh:78
OSEd::createDefaultOptions
void createDefaultOptions()
Definition:
OSEd.cc:163
OperationContainer.hh
WxConversion::toCStringArray
static char ** toCStringArray(size_t elements, wxChar **source)
Definition:
WxConversion.cc:123
Generated by
1.8.17