OpenASIP
2.0
src
codesign
osal
OSEd
OSEdAddModuleCmd.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 OSEdAddModuleCmd.cc
26
*
27
* Definition of OSEdAddModuleCmd class.
28
*
29
* @author Jussi Nykänen 2004 (nykanen-no.spam-cs.tut.fi)
30
* @note rating: red
31
*/
32
33
#include <boost/format.hpp>
34
35
#include "
OSEdAddModuleCmd.hh
"
36
#include "
OSEdConstants.hh
"
37
#include "
OSEd.hh
"
38
#include "
ErrorDialog.hh
"
39
#include "
OperationContainer.hh
"
40
#include "
Application.hh
"
41
#include "
AddModuleDialog.hh
"
42
#include "
OSEdTextGenerator.hh
"
43
#include "
WxConversion.hh
"
44
#include "
FileSystem.hh
"
45
#include "
OSEdTreeView.hh
"
46
#include "
OperationSerializer.hh
"
47
#include "
OperationIndex.hh
"
48
#include "
OperationModule.hh
"
49
#include "
ObjectState.hh
"
50
51
using
std::string;
52
using
boost::format;
53
54
/**
55
* Constructor.
56
*/
57
OSEdAddModuleCmd::OSEdAddModuleCmd
() :
58
GUICommand
(
OSEdConstants
::CMD_NAME_ADD_MODULE, NULL) {
59
}
60
61
/**
62
* Destructor.
63
*/
64
OSEdAddModuleCmd::~OSEdAddModuleCmd
() {
65
}
66
67
/**
68
* Returns the id of the command.
69
*
70
* @return The id of the command.
71
*/
72
int
73
OSEdAddModuleCmd::id
()
const
{
74
return
OSEdConstants::CMD_ADD_MODULE
;
75
}
76
77
/**
78
* Creates a new command.
79
*
80
* @return New command.
81
*/
82
GUICommand
*
83
OSEdAddModuleCmd::create
()
const
{
84
return
new
OSEdAddModuleCmd
();
85
}
86
87
/**
88
* Executes the command.
89
*
90
* @return True if execution is successful.
91
*/
92
bool
93
OSEdAddModuleCmd::Do
() {
94
95
OSEdMainFrame
* mainFrame = wxGetApp().mainFrame();
96
OSEdTreeView
* treeView = mainFrame->
treeView
();
97
string
path = treeView->
selectedPath
();
98
OSEdTextGenerator
& texts =
OSEdTextGenerator::instance
();
99
wxTreeItemId pathId = treeView->
selectedPathId
();
100
OperationIndex
& index =
OperationContainer::operationIndex
();
101
102
if
(!
FileSystem::fileExists
(path)) {
103
if
(!
FileSystem::createDirectory
(path)) {
104
format fmt =
105
texts.
text
(
OSEdTextGenerator::TXT_ERROR_CAN_NOT_CREATE_MOD
);
106
ErrorDialog
error(
107
parentWindow
(),
WxConversion::toWxString
(fmt.str()));
108
error.ShowModal();
109
return
false
;
110
}
111
index.
addPath
(path);
112
treeView->SetItemBold(pathId);
113
}
114
115
AddModuleDialog
dialog(
parentWindow
(), path);
116
if
(dialog.ShowModal() == wxID_OK) {
117
118
OperationModule
* module =
new
OperationModule
(dialog.
name
(), path);
119
OperationSerializer
& serializer =
120
OperationContainer::operationSerializer
();
121
serializer.
setDestinationFile
(module->
propertiesModule
());
122
ObjectState
* root =
new
ObjectState
(
"osal"
);
123
try
{
124
serializer.
writeState
(root);
125
}
catch
(
const
Exception
& e) {
126
format fmt = texts.
text
(
127
OSEdTextGenerator::TXT_ERROR_CAN_NOT_CREATE_MOD
);
128
129
ErrorDialog
error(
parentWindow
(),
130
WxConversion::toWxString
(fmt.str()));
131
error.ShowModal();
132
delete
root;
133
return
false
;
134
}
135
delete
root;
136
index.
addModule
(module, path);
137
treeView->
addItem
(pathId, module->
name
());
138
treeView->
update
();
139
}
140
141
return
true
;
142
}
143
144
/**
145
* Returns true if command is enabled.
146
*
147
* @return True if command is enabled.
148
*/
149
bool
150
OSEdAddModuleCmd::isEnabled
() {
151
OSEdTreeView
* treeView = wxGetApp().mainFrame()->treeView();
152
string
path = treeView->
selectedPath
();
153
if
(path !=
""
) {
154
if
(
FileSystem::fileExists
(path)) {
155
string
dumbFile = path +
FileSystem::DIRECTORY_SEPARATOR
+
156
"dumb12234"
;
157
if
(
FileSystem::createFile
(dumbFile)) {
158
FileSystem::removeFileOrDirectory
(dumbFile);
159
return
true
;
160
}
else
{
161
return
false
;
162
}
163
}
else
{
164
if
(
FileSystem::createDirectory
(path)) {
165
FileSystem::removeFileOrDirectory
(path);
166
return
true
;
167
}
else
{
168
return
false
;
169
}
170
}
171
}
172
return
false
;
173
}
174
175
/**
176
* Return icon path.
177
*
178
* @return Empty string (no icons used).
179
*/
180
string
181
OSEdAddModuleCmd::icon
()
const
{
182
return
""
;
183
}
OperationIndex::addPath
void addPath(const std::string &path)
Definition:
OperationIndex.cc:82
FileSystem.hh
OSEdAddModuleCmd::create
virtual GUICommand * create() const
Definition:
OSEdAddModuleCmd.cc:83
WxConversion::toWxString
static wxString toWxString(const std::string &source)
FileSystem::removeFileOrDirectory
static bool removeFileOrDirectory(const std::string &path)
Definition:
FileSystem.cc:493
FileSystem::createDirectory
static bool createDirectory(const std::string &path)
Definition:
FileSystem.cc:400
AddModuleDialog.hh
OperationSerializer::writeState
virtual void writeState(const ObjectState *state)
Definition:
OperationSerializer.cc:96
OperationContainer::operationSerializer
static OperationSerializer & operationSerializer()
Definition:
OperationContainer.cc:111
OperationSerializer::setDestinationFile
void setDestinationFile(const std::string &filename)
Definition:
OperationSerializer.cc:546
OSEdTreeView::addItem
void addItem(wxTreeItemId parent, std::string item)
Definition:
OSEdTreeView.cc:573
OSEdAddModuleCmd::OSEdAddModuleCmd
OSEdAddModuleCmd()
Definition:
OSEdAddModuleCmd.cc:57
OSEdTreeView::selectedPathId
wxTreeItemId selectedPathId()
Definition:
OSEdTreeView.cc:480
ObjectState
Definition:
ObjectState.hh:59
OSEd.hh
Texts::TextGenerator::text
virtual boost::format text(int textId)
Definition:
TextGenerator.cc:94
OSEdMainFrame::treeView
OSEdTreeView * treeView() const
Definition:
OSEdMainFrame.cc:241
OSEdConstants.hh
OSEdAddModuleCmd::~OSEdAddModuleCmd
virtual ~OSEdAddModuleCmd()
Definition:
OSEdAddModuleCmd.cc:64
OperationModule::propertiesModule
virtual std::string propertiesModule() const
Definition:
OperationModule.cc:121
GUICommand
Definition:
GUICommand.hh:43
OSEdAddModuleCmd.hh
OSEdTextGenerator::TXT_ERROR_CAN_NOT_CREATE_MOD
@ TXT_ERROR_CAN_NOT_CREATE_MOD
Error when can not create module.
Definition:
OSEdTextGenerator.hh:134
ErrorDialog
Definition:
ErrorDialog.hh:42
OperationIndex::addModule
void addModule(OperationModule *module, const std::string &path)
Definition:
OperationIndex.cc:193
OSEdTreeView
Definition:
OSEdTreeView.hh:54
ErrorDialog.hh
OSEdTreeView::selectedPath
std::string selectedPath()
Definition:
OSEdTreeView.cc:456
OperationIndex.hh
Application.hh
OSEdConstants
Definition:
OSEdConstants.hh:45
ObjectState.hh
OperationSerializer.hh
AddModuleDialog::name
std::string name() const
Definition:
AddModuleDialog.cc:158
OperationSerializer
Definition:
OperationSerializer.hh:49
AddModuleDialog
Definition:
AddModuleDialog.hh:42
Exception
Definition:
Exception.hh:54
FileSystem::createFile
static bool createFile(const std::string &file)
Definition:
FileSystem.cc:468
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
OSEdAddModuleCmd::icon
virtual std::string icon() const
Definition:
OSEdAddModuleCmd.cc:181
OSEdTreeView.hh
OSEdMainFrame
Definition:
OSEdMainFrame.hh:49
OSEdAddModuleCmd::Do
virtual bool Do()
Definition:
OSEdAddModuleCmd.cc:93
FileSystem::fileExists
static bool fileExists(const std::string fileName)
OperationModule
Definition:
OperationModule.hh:46
OSEdTreeView::update
void update()
Definition:
OSEdTreeView.cc:670
OSEdAddModuleCmd::id
virtual int id() const
Definition:
OSEdAddModuleCmd.cc:73
OperationIndex
Definition:
OperationIndex.hh:58
OSEdTextGenerator::instance
static OSEdTextGenerator & instance()
Definition:
OSEdTextGenerator.cc:214
OSEdTextGenerator
Definition:
OSEdTextGenerator.hh:42
WxConversion.hh
OSEdAddModuleCmd::isEnabled
virtual bool isEnabled()
Definition:
OSEdAddModuleCmd.cc:150
OperationModule::name
virtual std::string name() const
Definition:
OperationModule.cc:160
OSEdTextGenerator.hh
OperationContainer::operationIndex
static OperationIndex & operationIndex()
Definition:
OperationContainer.cc:94
GUICommand::parentWindow
wxWindow * parentWindow() const
Definition:
GUICommand.cc:75
OperationModule.hh
OperationContainer.hh
Generated by
1.8.17