OpenASIP 2.2
Loading...
Searching...
No Matches
OSEdPropertiesCmd.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 OSEdPropertiesCmd.cc
26 *
27 * Definition of OSEdPropertiesCmd 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#include <iostream>
35
36#include "OSEdPropertiesCmd.hh"
37#include "OSEdConstants.hh"
39#include "OSEd.hh"
40#include "Application.hh"
41#include "ErrorDialog.hh"
42#include "OperationContainer.hh"
43#include "FileSystem.hh"
44#include "WxConversion.hh"
45#include "OSEdTextGenerator.hh"
46#include "OSEdTreeView.hh"
48#include "OperationIndex.hh"
49#include "Operation.hh"
50#include "OperationModule.hh"
51#include "TCEString.hh"
52#include "ObjectState.hh"
53
54using boost::format;
55using std::string;
56using std::cout;
57using std::endl;
58
59/**
60 * Constructor.
61 */
63 GUICommand(OSEdConstants::CMD_NAME_PROPERTIES, NULL) {
64}
65
66/**
67 * Destructor.
68 */
71
72/**
73 * Returns the id of the command.
74 *
75 * @return The id of the command.
76 */
77int
81
82/**
83 * Creates a new command.
84 *
85 * @return The created command.
86 */
89 return new OSEdPropertiesCmd();
90}
91
92/**
93 * Executes the command.
94 *
95 * @return True if execution is successful, false otherwise.
96 */
97bool
99
101 OSEdMainFrame* mainFrame = wxGetApp().mainFrame();
102 OSEdTreeView* treeView = mainFrame->treeView();
103 Operation* op = treeView->selectedOperation();
104 string opName = op->name();
105 wxTreeItemId opId = treeView->selectedOperationId();
106 string modName = treeView->moduleOfOperation(opId);
107 wxTreeItemId modId = treeView->moduleIdOfOperation(opId);
108 string pathName = treeView->pathOfModule(modId);
109 OperationModule& module = OperationContainer::module(pathName, modName);
110
112
113 if (!FileSystem::fileIsWritable(module.propertiesModule())) {
116 error.ShowModal();
117 delete op;
118 return false;
119 } else {
120 OperationPropertyDialog dialog(parentWindow(), op, module, pathName);
121 ObjectState* orig = op->saveState();
122 if (dialog.ShowModal() == wxID_OK) {
123
124 ObjectState* mod = op->saveState();
125 if (*mod != *orig) {
126 // write operation properties to file
127 OperationSerializer& serializer =
129 serializer.setSourceFile(module.propertiesModule());
130 ObjectState* root = NULL;
131 try {
132 root = serializer.readState();
133 for (int i = 0; i < root->childCount(); i++) {
134 ObjectState* child = root->child(i);
135 if (child->stringAttribute("name") == opName) {
136 root->replaceChild(child, op->saveState());
137 break;
138 }
139 }
140 serializer.setDestinationFile(module.propertiesModule());
141 serializer.writeState(root);
142 } catch (const Exception& s) {
143 format fmt =
145 ErrorDialog eDialog(
147 eDialog.ShowModal();
148 }
149 delete root;
150
151 // update the tree.
152 if (opName != op->name()) {
154 index.refreshModule(pathName, modName);
155 treeView->changeText(opId, op->name());
156 }
157
158 treeView->update();
159 }
160 delete mod;
161 }
162 delete orig;
163 delete op;
164 return true;
165 }
166
167 assert(false);
168 return false;
169}
170
171/**
172 * Returns true, if command is enabled.
173 *
174 * @return True, if command is enabled.
175 */
176bool
178 OSEdTreeView* treeView = wxGetApp().mainFrame()->treeView();
179 Operation* op = treeView->selectedOperation();
180 if (op != NULL) {
181 delete op;
182 return true;
183 } else {
184 return false;
185 }
186}
187
188/**
189 * Returns the icon path.
190 *
191 * @return Empty string (icons not used).
192 */
193string
195 return "";
196}
#define assert(condition)
static bool fileIsWritable(const std::string fileName)
wxWindow * parentWindow() const
Definition GUICommand.cc:75
static NullOperationModule & instance()
@ CMD_PROPERTIES
Operation properties command id.
OSEdTreeView * treeView() const
virtual std::string icon() const
virtual int id() const
virtual bool isEnabled()
virtual GUICommand * create() const
static OSEdTextGenerator & instance()
@ TXT_ERROR_CAN_NOT_MODIFY
Error when can not modify.
std::string pathOfModule(wxTreeItemId id)
void changeText(wxTreeItemId id, const std::string &text)
wxTreeItemId selectedOperationId()
Operation * selectedOperation()
wxTreeItemId moduleIdOfOperation(wxTreeItemId id)
std::string moduleOfOperation(wxTreeItemId id)
ObjectState * child(int index) const
std::string stringAttribute(const std::string &name) const
void replaceChild(ObjectState *old, ObjectState *newChild)
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 ObjectState * saveState() const
Definition Operation.cc:490
virtual boost::format text(int textId)
static wxString toWxString(const std::string &source)