OpenASIP 2.2
Loading...
Searching...
No Matches
OSEdRemoveOperationCmd.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 OSEdRemoveOperationCmd.cc
26 *
27 * Definition of OSEdRemoveOperationCmd 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
36#include "OSEdConstants.hh"
37#include "OSEdTextGenerator.hh"
38#include "OperationContainer.hh"
39#include "ConfirmDialog.hh"
40#include "WxConversion.hh"
41#include "ErrorDialog.hh"
42#include "OSEd.hh"
43#include "OperationModule.hh"
45#include "OSEdTreeView.hh"
46#include "Operation.hh"
47#include "OperationIndex.hh"
48#include "OSEdInfoView.hh"
49#include "TCEString.hh"
50#include "ObjectState.hh"
51
52using std::string;
53using boost::format;
54
55/**
56 * Constructor.
57 */
59 GUICommand(OSEdConstants::CMD_NAME_REMOVE_OPERATION, NULL) {
60}
61
62/**
63 * Destructor.
64 */
67
68/**
69 * Returns the id of the command.
70 *
71 * @return The id of the command.
72 */
73int
77
78/**
79 * Creates a new command.
80 *
81 * @return New command.
82 */
87
88/**
89 * Executes the command.
90 *
91 * @return True if execution is successful.
92 */
93bool
95
97 OSEdTreeView* treeView = wxGetApp().mainFrame()->treeView();
98 Operation* op = treeView->selectedOperation();
99 wxTreeItemId opId = treeView->selectedOperationId();
100 string modName = treeView->moduleOfOperation(opId);
101 wxTreeItemId modId = treeView->moduleIdOfOperation(opId);
102 string pathName = treeView->pathOfModule(modId);
103
104 OperationModule& module = OperationContainer::module(pathName, modName);
105
107 fmt % op->name();
109
110 if (dialog.ShowModal() == wxID_YES) {
111 OperationSerializer& serializer =
113
114 serializer.setSourceFile(module.propertiesModule());
115 ObjectState* root = NULL;
116 try {
117 root = serializer.readState();
118 for (int i = 0; i < root->childCount(); i++) {
119 ObjectState* child = root->child(i);
120 if (child->stringAttribute("name") == op->name()) {
121 delete child;
122 break;
123 }
124 }
125 serializer.setDestinationFile(module.propertiesModule());
126 serializer.writeState(root);
127 delete root;
128 } catch (const Exception& e) {
129 fmt = texts.text(
131
132 fmt % op->name();
133 ErrorDialog error(
135 error.ShowModal();
136 delete root;
137 delete op;
138 return false;
139 }
140
142 index.refreshModule(pathName, modName);
143 treeView->removeItem(opId);
144 treeView->infoView()->operationView(pathName, modName);
145 }
146 delete op;
147 return true;
148}
149
150/**
151 * Returns true if command is enabled, otherwise false.
152 *
153 * Command is enabled when the path of the operation is writable.
154 *
155 * @return True if command is enabled, otherwise false.
156 */
157bool
159 OSEdTreeView* treeView = wxGetApp().mainFrame()->treeView();
160 if (treeView->isOperationSelected()) {
161 wxTreeItemId opId = treeView->selectedOperationId();
162 wxTreeItemId modId = treeView->moduleIdOfOperation(opId);
163 string path = treeView->pathOfModule(modId);
164 if (FileSystem::fileIsWritable(path)) {
165 return true;
166 } else {
167 return false;
168 }
169 } else {
170 return false;
171 }
172}
173
174/**
175 * Returns the icon of the command.
176 *
177 * @return Empty string (icons not used).
178 */
179string
181 return "";
182}
static bool fileIsWritable(const std::string fileName)
wxWindow * parentWindow() const
Definition GUICommand.cc:75
@ CMD_REMOVE_OPERATION
Remove operation command id.
void operationView(const std::string &path, const std::string &mod)
virtual GUICommand * create() const
virtual std::string icon() const
static OSEdTextGenerator & instance()
@ TXT_QUESTION_REMOVE_OPERATION
Remove operation question.
@ TXT_ERROR_CAN_NOT_REMOVE_OPERATION
Error when operation can not be removed.
std::string pathOfModule(wxTreeItemId id)
bool isOperationSelected() const
wxTreeItemId selectedOperationId()
Operation * selectedOperation()
OSEdInfoView * infoView() const
void removeItem(wxTreeItemId id)
wxTreeItemId moduleIdOfOperation(wxTreeItemId id)
std::string moduleOfOperation(wxTreeItemId id)
ObjectState * child(int index) const
std::string stringAttribute(const std::string &name) const
int childCount() const
static OperationSerializer & operationSerializer()
static OperationIndex & operationIndex()
void refreshModule(const std::string &path, const std::string &modName)
void setSourceFile(const std::string &filename)
virtual void writeState(const ObjectState *state)
void setDestinationFile(const std::string &filename)
virtual ObjectState * readState()
virtual TCEString name() const
Definition Operation.cc:93
virtual boost::format text(int textId)
static wxString toWxString(const std::string &source)