OpenASIP 2.2
Loading...
Searching...
No Matches
OSEdAddOperationCmd.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 OSEdAddOperationCmd.cc
26 *
27 * Definition of OSEdAddOperationCmd class.
28 *
29 * @author Jussi Nykänen 2004 (nykanen-no.spam-cs.tut.fi)
30 * @note rating: red
31 */
32
33#include <string>
34
36#include "OSEdConstants.hh"
37#include "OSEd.hh"
38#include "ErrorDialog.hh"
39#include "OperationContainer.hh"
40#include "WxConversion.hh"
41#include "OSEdTextGenerator.hh"
42#include "OperationBehavior.hh"
44#include "OSEdTreeView.hh"
46#include "OperationIndex.hh"
47#include "OperationModule.hh"
48#include "Operation.hh"
49#include "TCEString.hh"
50#include "ObjectState.hh"
51
52using std::string;
53
54/**
55 * Constructor.
56 */
58 GUICommand(OSEdConstants::CMD_NAME_ADD_OPERATION, NULL) {
59}
60
61/**
62 * Destructor.
63 */
66
67/**
68 * Returns the id of the command.
69 *
70 * @return The id of the command.
71 */
72int
76
77/**
78 * Creates a new command.
79 *
80 * @return New command.
81 */
84 return new OSEdAddOperationCmd();
85}
86
87/**
88 * Executes the command.
89 */
90bool
92
93 OSEdMainFrame* mainFrame = wxGetApp().mainFrame();
94 OSEdTreeView* treeView = mainFrame->treeView();
95 string modName = treeView->selectedModule();
96
97 wxTreeItemId modId = treeView->selectedModuleId();
98 string pathName = treeView->pathOfModule(modId);
100 OperationModule& module = OperationContainer::module(pathName, modName);
101
103
104 OperationPropertyDialog dialog(parentWindow(), NULL, module, pathName);
105
106 if (dialog.ShowModal() == wxID_OK) {
107 Operation* op = dialog.operation();
108
109 OperationSerializer& serializer =
111 serializer.setDestinationFile(module.propertiesModule());
112 ObjectState* root = new ObjectState("");
113
114 for (int k = 0; k < index.operationCount(module); k++) {
115
116 string opName = index.operationName(k, module);
118 pathName, modName, opName);
119
120 root->addChild(oper->saveState());
121 delete oper;
122 }
123
124 root->addChild(op->saveState());
125
126 try {
127 serializer.writeState(root);
128 delete root;
129 } catch (const SerializerException& s) {
130 wxString msg = WxConversion::toWxString(s.errorMessage());
131 ErrorDialog eDialog(parentWindow(), msg);
132 eDialog.ShowModal();
133 delete root;
134 delete op;
135 return false;
136 }
137
138 index.refreshModule(pathName, modName);
139 treeView->addItem(modId, op->name());
140 treeView->update();
141 }
142
143 return true;
144}
145
146/**
147 * Returns true, if command is enabled.
148 *
149 * Operation can be added, if path is writable.
150 *
151 * @return True if command is enabled.
152 */
153bool
155 OSEdTreeView* treeView = wxGetApp().mainFrame()->treeView();
156 string modName = treeView->selectedModule();
157 if (modName != "") {
158 wxTreeItemId modId = treeView->selectedModuleId();
159 string pathName = treeView->pathOfModule(modId);
160 string tempFile = pathName + FileSystem::DIRECTORY_SEPARATOR +
161 "temp12341";
162 if (FileSystem::createFile(tempFile)) {
164 return true;
165 } else {
166 return false;
167 }
168 }
169 return false;
170}
171
172/**
173 * Returns the icon path.
174 *
175 * @return Empty string (no icons used).
176 */
177string
179 return "";
180}
#define assert(condition)
std::string errorMessage() const
Definition Exception.cc:123
static bool createFile(const std::string &file)
static bool removeFileOrDirectory(const std::string &path)
static const std::string DIRECTORY_SEPARATOR
wxWindow * parentWindow() const
Definition GUICommand.cc:75
static NullOperationModule & instance()
virtual GUICommand * create() const
virtual std::string icon() const
virtual int id() const
@ CMD_ADD_OPERATION
Add operation command id.
OSEdTreeView * treeView() const
wxTreeItemId selectedModuleId()
std::string pathOfModule(wxTreeItemId id)
void addItem(wxTreeItemId parent, std::string item)
std::string selectedModule()
void addChild(ObjectState *child)
static OperationSerializer & operationSerializer()
static Operation * operation(const std::string &path, const std::string &module, const std::string &oper)
static OperationIndex & operationIndex()
std::string operationName(int i, const OperationModule &om)
int operationCount(const OperationModule &om)
void refreshModule(const std::string &path, const std::string &modName)
virtual void writeState(const ObjectState *state)
void setDestinationFile(const std::string &filename)
virtual TCEString name() const
Definition Operation.cc:93
virtual ObjectState * saveState() const
Definition Operation.cc:490
static wxString toWxString(const std::string &source)