OpenASIP  2.0
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"
44 #include "OperationSerializer.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 
52 using std::string;
53 using boost::format;
54 
55 /**
56  * Constructor.
57  */
59  GUICommand(OSEdConstants::CMD_NAME_REMOVE_OPERATION, NULL) {
60 }
61 
62 /**
63  * Destructor.
64  */
66 }
67 
68 /**
69  * Returns the id of the command.
70  *
71  * @return The id of the command.
72  */
73 int
76 }
77 
78 /**
79  * Creates a new command.
80  *
81  * @return New command.
82  */
85  return new OSEdRemoveOperationCmd();
86 }
87 
88 /**
89  * Executes the command.
90  *
91  * @return True if execution is successful.
92  */
93 bool
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(
134  parentWindow(), WxConversion::toWxString(fmt.str()));
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  */
157 bool
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  */
179 string
181  return "";
182 }
OSEdInfoView::operationView
void operationView(const std::string &path, const std::string &mod)
Definition: OSEdInfoView.cc:161
OperationIndex::refreshModule
void refreshModule(const std::string &path, const std::string &modName)
Definition: OperationIndex.cc:272
OSEdRemoveOperationCmd::create
virtual GUICommand * create() const
Definition: OSEdRemoveOperationCmd.cc:84
OSEdTextGenerator::TXT_QUESTION_REMOVE_OPERATION
@ TXT_QUESTION_REMOVE_OPERATION
Remove operation question.
Definition: OSEdTextGenerator.hh:211
WxConversion::toWxString
static wxString toWxString(const std::string &source)
OSEdTreeView::removeItem
void removeItem(wxTreeItemId id)
Definition: OSEdTreeView.cc:622
OSEdTreeView::pathOfModule
std::string pathOfModule(wxTreeItemId id)
Definition: OSEdTreeView.cc:431
ObjectState::stringAttribute
std::string stringAttribute(const std::string &name) const
Definition: ObjectState.cc:249
OSEdRemoveOperationCmd::OSEdRemoveOperationCmd
OSEdRemoveOperationCmd()
Definition: OSEdRemoveOperationCmd.cc:58
OperationSerializer::writeState
virtual void writeState(const ObjectState *state)
Definition: OperationSerializer.cc:96
OperationContainer::operationSerializer
static OperationSerializer & operationSerializer()
Definition: OperationContainer.cc:111
OSEdTreeView::moduleIdOfOperation
wxTreeItemId moduleIdOfOperation(wxTreeItemId id)
Definition: OSEdTreeView.cc:420
OperationSerializer::setDestinationFile
void setDestinationFile(const std::string &filename)
Definition: OperationSerializer.cc:546
OperationContainer::module
static OperationModule & module(const std::string &path, const std::string &mod)
Definition: OperationContainer.cc:148
OSEdConstants::CMD_REMOVE_OPERATION
@ CMD_REMOVE_OPERATION
Remove operation command id.
Definition: OSEdConstants.hh:96
OSEdTextGenerator::TXT_ERROR_CAN_NOT_REMOVE_OPERATION
@ TXT_ERROR_CAN_NOT_REMOVE_OPERATION
Error when operation can not be removed.
Definition: OSEdTextGenerator.hh:148
ObjectState
Definition: ObjectState.hh:59
OSEd.hh
OSEdTreeView::infoView
OSEdInfoView * infoView() const
Definition: OSEdTreeView.cc:662
Texts::TextGenerator::text
virtual boost::format text(int textId)
Definition: TextGenerator.cc:94
OSEdInfoView.hh
Operation::name
virtual TCEString name() const
Definition: Operation.cc:93
OSEdConstants.hh
TCEString.hh
OSEdRemoveOperationCmd::Do
virtual bool Do()
Definition: OSEdRemoveOperationCmd.cc:94
OperationModule::propertiesModule
virtual std::string propertiesModule() const
Definition: OperationModule.cc:121
GUICommand
Definition: GUICommand.hh:43
OSEdRemoveOperationCmd::isEnabled
virtual bool isEnabled()
Definition: OSEdRemoveOperationCmd.cc:158
ErrorDialog
Definition: ErrorDialog.hh:42
FileSystem::fileIsWritable
static bool fileIsWritable(const std::string fileName)
OSEdTreeView
Definition: OSEdTreeView.hh:54
ErrorDialog.hh
OSEdRemoveOperationCmd.hh
OperationIndex.hh
OperationSerializer::readState
virtual ObjectState * readState()
Definition: OperationSerializer.cc:118
ConfirmDialog.hh
OSEdTreeView::moduleOfOperation
std::string moduleOfOperation(wxTreeItemId id)
Definition: OSEdTreeView.cc:407
OSEdConstants
Definition: OSEdConstants.hh:45
OSEdRemoveOperationCmd::icon
virtual std::string icon() const
Definition: OSEdRemoveOperationCmd.cc:180
OSEdTreeView::isOperationSelected
bool isOperationSelected() const
Definition: OSEdTreeView.cc:745
ObjectState.hh
OperationSerializer.hh
OperationSerializer
Definition: OperationSerializer.hh:49
ObjectState::child
ObjectState * child(int index) const
Definition: ObjectState.cc:471
Operation.hh
OSEdTreeView::selectedOperation
Operation * selectedOperation()
Definition: OSEdTreeView.cc:328
ObjectState::childCount
int childCount() const
OperationSerializer::setSourceFile
void setSourceFile(const std::string &filename)
Definition: OperationSerializer.cc:536
Exception
Definition: Exception.hh:54
ConfirmDialog
Definition: ConfirmDialog.hh:41
Operation
Definition: Operation.hh:59
OSEdTreeView.hh
OperationModule
Definition: OperationModule.hh:46
OperationIndex
Definition: OperationIndex.hh:58
OSEdTextGenerator::instance
static OSEdTextGenerator & instance()
Definition: OSEdTextGenerator.cc:214
OSEdTreeView::selectedOperationId
wxTreeItemId selectedOperationId()
Definition: OSEdTreeView.cc:379
OSEdRemoveOperationCmd::id
virtual int id() const
Definition: OSEdRemoveOperationCmd.cc:74
OSEdTextGenerator
Definition: OSEdTextGenerator.hh:42
WxConversion.hh
OSEdTextGenerator.hh
OperationContainer::operationIndex
static OperationIndex & operationIndex()
Definition: OperationContainer.cc:94
OSEdRemoveOperationCmd::~OSEdRemoveOperationCmd
virtual ~OSEdRemoveOperationCmd()
Definition: OSEdRemoveOperationCmd.cc:65
GUICommand::parentWindow
wxWindow * parentWindow() const
Definition: GUICommand.cc:75
OperationModule.hh
OperationContainer.hh